Skip to content

Commit

Permalink
renamed BlockInfo to UniqueBlock
Browse files Browse the repository at this point in the history
  • Loading branch information
fr1kin committed Oct 14, 2018
1 parent 85bff5c commit ba5c16c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 27 deletions.
32 changes: 16 additions & 16 deletions src/main/java/com/matt/forgehax/mods/AutoPlace.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import com.matt.forgehax.mods.managers.PositionRotationManager;
import com.matt.forgehax.mods.managers.PositionRotationManager.RotationState.Local;
import com.matt.forgehax.util.BlockHelper;
import com.matt.forgehax.util.BlockHelper.BlockInfo;
import com.matt.forgehax.util.BlockHelper.UniqueBlock;
import com.matt.forgehax.util.BlockHelper.BlockTraceInfo;
import com.matt.forgehax.util.Utils;
import com.matt.forgehax.util.color.Colors;
Expand Down Expand Up @@ -159,7 +159,7 @@ enum Stage {
private final AtomicBoolean printToggle = new AtomicBoolean(false);
private final AtomicBoolean resetToggle = new AtomicBoolean(false);

private final List<BlockInfo> targets = Lists.newArrayList();
private final List<UniqueBlock> targets = Lists.newArrayList();

private ItemStack selectedItem = null;

Expand Down Expand Up @@ -191,13 +191,13 @@ private void reset() {
}
}

private boolean isValidBlock(BlockInfo info) {
private boolean isValidBlock(UniqueBlock info) {
return whitelist.get()
? targets.stream().anyMatch(info::equals)
: targets.stream().noneMatch(info::equals);
}

private boolean isClickable(BlockInfo info) {
private boolean isClickable(UniqueBlock info) {
return sides
.stream()
.map(FacingEntry::getFacing)
Expand Down Expand Up @@ -239,7 +239,7 @@ private void showInfo(String filter) {
if ("targets".startsWith(filter))
printInform(
"Targets: %s",
this.targets.stream().map(BlockInfo::toString).collect(Collectors.joining(", ")));
this.targets.stream().map(UniqueBlock::toString).collect(Collectors.joining(", ")));

if ("sides".startsWith(filter))
printInform(
Expand Down Expand Up @@ -582,7 +582,7 @@ public void onUpdate(LocalPlayerUpdateEvent event) {
RayTraceResult tr = LocalPlayerUtils.getMouseOverBlockTrace();
if (tr == null) return;

BlockInfo info = BlockHelper.newBlockInfo(tr.getBlockPos());
UniqueBlock info = BlockHelper.newUniqueBlock(tr.getBlockPos());

if (info.isInvalid()) {
printWarning("Invalid block %s", info.toString());
Expand Down Expand Up @@ -707,10 +707,10 @@ public void onLocalPlayerMovementUpdate(Local state) {
final Vec3d eyes = EntityUtils.getEyePos(getLocalPlayer());
final Vec3d dir = LocalPlayerUtils.getViewAngles().getDirectionVector();

List<BlockInfo> blocks =
List<UniqueBlock> blocks =
BlockHelper.getBlocksInRadius(eyes, getPlayerController().getBlockReachDistance())
.stream()
.map(BlockHelper::newBlockInfo)
.map(BlockHelper::newUniqueBlock)
.filter(this::isValidBlock)
.filter(this::isClickable)
.sorted(
Expand All @@ -725,7 +725,7 @@ public void onLocalPlayerMovementUpdate(Local state) {
if (render.get()) {
currentRenderingTarget = null;
renderingBlocks.clear();
renderingBlocks.addAll(blocks.stream().map(BlockInfo::getPos).collect(Collectors.toSet()));
renderingBlocks.addAll(blocks.stream().map(UniqueBlock::getPos).collect(Collectors.toSet()));
}

// find a block that can be placed
Expand All @@ -734,7 +734,7 @@ public void onLocalPlayerMovementUpdate(Local state) {
do {
if (index >= blocks.size()) break;

final BlockInfo at = blocks.get(index++);
final UniqueBlock at = blocks.get(index++);
if (use.get()) {
info =
sides
Expand Down Expand Up @@ -799,7 +799,7 @@ public void onLocalPlayerMovementUpdate(Local state) {
private static class PlaceConfigEntry implements ISerializableJson {
private final String name;

private final List<BlockInfo> targets = Lists.newArrayList();
private final List<UniqueBlock> targets = Lists.newArrayList();
private final List<EnumFacing> sides = Lists.newArrayList();
private ItemStack selection = ItemStack.EMPTY;
private boolean use = false;
Expand All @@ -814,11 +814,11 @@ public String getName() {
return name;
}

public List<BlockInfo> getTargets() {
public List<UniqueBlock> getTargets() {
return Collections.unmodifiableList(targets);
}

public void setTargets(Collection<BlockInfo> list) {
public void setTargets(Collection<UniqueBlock> list) {
targets.clear();
targets.addAll(
list.stream()
Expand Down Expand Up @@ -880,7 +880,7 @@ public void serialize(JsonWriter writer) throws IOException {
writer.name("targets");
writer.beginArray();
{
for (BlockInfo info : getTargets()) {
for (UniqueBlock info : getTargets()) {
writer.beginObject();

writer.name("block");
Expand Down Expand Up @@ -935,7 +935,7 @@ public void deserialize(JsonReader reader) throws IOException {
{
reader.beginArray();

List<BlockInfo> blocks = Lists.newArrayList();
List<UniqueBlock> blocks = Lists.newArrayList();
while (reader.hasNext()) {
reader.beginObject();

Expand All @@ -947,7 +947,7 @@ public void deserialize(JsonReader reader) throws IOException {
reader.nextName();
int meta = reader.nextInt();

blocks.add(BlockHelper.newBlockInfo(block, meta));
blocks.add(BlockHelper.newUniqueBlock(block, meta));

reader.endObject();
}
Expand Down
22 changes: 11 additions & 11 deletions src/main/java/com/matt/forgehax/util/BlockHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@
import net.minecraft.util.math.Vec3d;

public class BlockHelper {
public static BlockInfo newBlockInfo(Block block, int metadata, BlockPos pos) {
return new BlockInfo(block, metadata, pos);
public static UniqueBlock newUniqueBlock(Block block, int metadata, BlockPos pos) {
return new UniqueBlock(block, metadata, pos);
}

public static BlockInfo newBlockInfo(Block block, int metadata) {
return newBlockInfo(block, metadata, BlockPos.ORIGIN);
public static UniqueBlock newUniqueBlock(Block block, int metadata) {
return newUniqueBlock(block, metadata, BlockPos.ORIGIN);
}

public static BlockInfo newBlockInfo(BlockPos pos) {
public static UniqueBlock newUniqueBlock(BlockPos pos) {
IBlockState state = getWorld().getBlockState(pos);
Block block = state.getBlock();
return newBlockInfo(block, block.getMetaFromState(state), pos);
return newUniqueBlock(block, block.getMetaFromState(state), pos);
}

public static BlockTraceInfo newBlockTrace(BlockPos pos, EnumFacing side) {
Expand Down Expand Up @@ -127,12 +127,12 @@ public IBlockState getBlockState() {
}
}

public static class BlockInfo {
public static class UniqueBlock {
private final Block block;
private final int metadata;
private final BlockPos pos;

private BlockInfo(Block block, int metadata, BlockPos pos) {
private UniqueBlock(Block block, int metadata, BlockPos pos) {
this.block = block;
this.metadata = metadata;
this.pos = pos;
Expand Down Expand Up @@ -171,9 +171,9 @@ public boolean isEqual(BlockPos pos) {
@Override
public boolean equals(Object obj) {
return this == obj
|| (obj instanceof BlockInfo
&& getBlock().equals(((BlockInfo) obj).getBlock())
&& getMetadata() == ((BlockInfo) obj).getMetadata());
|| (obj instanceof UniqueBlock
&& getBlock().equals(((UniqueBlock) obj).getBlock())
&& getMetadata() == ((UniqueBlock) obj).getMetadata());
}

@Override
Expand Down

0 comments on commit ba5c16c

Please sign in to comment.