Skip to content

Commit

Permalink
Fixed weird interactions with certain blocks and added range decrease…
Browse files Browse the repository at this point in the history
… feature
  • Loading branch information
JackyyTV committed Jan 6, 2018
1 parent d869daa commit 0b5fe78
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/main/java/jackyy/exchangers/handler/ExchangerHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,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 != ItemStack.EMPTY) {
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 +161,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 +225,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 +237,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 0b5fe78

Please sign in to comment.