Skip to content

Commit

Permalink
Fixed weird interactions with leaves or maybe other blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
JackyyTV committed Jan 6, 2018
1 parent 721428a commit f41a856
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/main/java/jackyy/exchangers/handler/ExchangerHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public void addInformation(ItemStack stack, EntityPlayer player, List<String> to
Block block = Block.getBlockFromName(id);
int meta = compound.getInteger("meta");
tooltip.add(StringHelper.localize("tooltip.selected_block") + " " + getBlockName(block, meta));
/* DEBUG */ tooltip.add("Metadata: " + meta);
tooltip.add(StringHelper.localize("tooltip.current_range") + " " + modeSwitchList[compound.getInteger("mode")]);
tooltip.add(StringHelper.localize("tooltip.max_range") + " " + modeSwitchList[getMaxRange()]);
}
Expand Down Expand Up @@ -118,13 +119,21 @@ public void switchMode(EntityPlayer player, ItemStack stack) {
setDefaultTagCompound(stack);

int modeSwitch = stack.getTagCompound().getInteger("mode");
modeSwitch++;

if (player.isSneaking()) {
modeSwitch--;
} else {
modeSwitch++;
}

ItemStack heldItem = player.getHeldItemMainhand();

if (heldItem != null) {
if (modeSwitch > getMaxRange())
if (modeSwitch > getMaxRange()) {
modeSwitch = MODE_1X1;
} else if (modeSwitch < MODE_1X1) {
modeSwitch = getMaxRange();
}
}

stack.getTagCompound().setInteger("mode", modeSwitch);
Expand Down Expand Up @@ -153,7 +162,6 @@ private boolean isWhitelisted(World world, BlockPos pos) {

private boolean isSpecial(Block block) {
return block instanceof BlockLog
|| block instanceof BlockLeaves
|| block instanceof BlockRedstoneOre
|| block instanceof BlockTrapDoor
|| block instanceof BlockDoor
Expand Down Expand Up @@ -218,6 +226,9 @@ private void placeBlock(ItemStack stack, EntityPlayer player, World world, Block
world.playSound(null, coordinate.getX(), coordinate.getY(), coordinate.getZ(),
SoundEvents.ENTITY_ENDERMEN_TELEPORT, SoundCategory.BLOCKS, 0.1F, 1F);
} else {
world.restoringBlockSnapshots = true;
event.getBlockSnapshot().restore(true);
world.restoringBlockSnapshots = false;
notEnough = true;
}
} else {
Expand All @@ -227,10 +238,10 @@ private void placeBlock(ItemStack stack, EntityPlayer player, World world, Block
ChatHelper.msgPlayer(player, "error.event_cancelled");
}
}
world.captureBlockSnapshots = true;
if (notEnough) {
ChatHelper.msgPlayer(player, "error.out_of_block");
}
world.captureBlockSnapshots = true;
}

@SuppressWarnings("deprecation")
Expand Down

0 comments on commit f41a856

Please sign in to comment.