Skip to content

Commit

Permalink
Added option to disable generated Waystone drops (fixes #156) (#183)
Browse files Browse the repository at this point in the history
  • Loading branch information
WesCook authored and BlayTheNinth committed Oct 5, 2019
1 parent 7d322a1 commit f197d56
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/main/java/net/blay09/mods/waystones/WaystoneConfig.java
Expand Up @@ -99,6 +99,10 @@ public static class General {
@Config.Comment("Whether generated waystones should not be breakable by players.")
public boolean disallowBreakingGenerated = false;

@Config.Name("Drop Item From Generated")
@Config.Comment("Whether generated waystones drop their item form when broken by players.")
public boolean dropGenerated = true;

@Config.Name("Warp Stone Use Time")
@Config.Comment("The time it takes to use a warp stone in ticks. This is the charge-up time when holding right-click.")
@Config.RangeInt(min = 1, max = 127)
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/net/blay09/mods/waystones/block/BlockWaystone.java
Expand Up @@ -156,6 +156,15 @@ public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, Entity
public void breakBlock(World world, BlockPos pos, IBlockState state) {
TileWaystone tileWaystone = getTileWaystone(world, pos);
if (tileWaystone != null) {

// We're copying the wasGenerated flag to the top half of the TE so it can be accessed in harvestBlock().
// That function will only return the TE from the block which was broken, and the TE is removed from the world by then.
// As such, we need to copy it from the base (parent) to the top (dummy) before harvesting.
TileWaystone tileWaystoneExact = (TileWaystone) world.getTileEntity(pos);
if (tileWaystoneExact != null && tileWaystoneExact.isDummy()) {
tileWaystoneExact.setWasGenerated(tileWaystone.wasGenerated());
}

WaystoneEntry entry = new WaystoneEntry(tileWaystone);
if (tileWaystone.isGlobal()) {
GlobalWaystones.get(world).removeGlobalWaystone(entry);
Expand All @@ -175,6 +184,15 @@ public void breakBlock(World world, BlockPos pos, IBlockState state) {
}
}

@Override
public void harvestBlock(World world, EntityPlayer player, BlockPos pos, IBlockState state, @Nullable TileEntity te, ItemStack stack) {
TileWaystone tileWaystone = (TileWaystone) te;
if (tileWaystone != null && tileWaystone.wasGenerated() && !WaystoneConfig.general.dropGenerated) {
return;
}
super.harvestBlock(world, player, pos, state, te, stack);
}

@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
if (player.isSneaking() && (player.capabilities.isCreativeMode || !WaystoneConfig.general.creativeModeOnly)) {
Expand Down
Expand Up @@ -145,6 +145,10 @@ public boolean isGlobal() {
return isGlobal;
}

public boolean isDummy() {
return isDummy;
}

public void setGlobal(boolean isGlobal) {
this.isGlobal = isGlobal;
markDirty();
Expand Down

0 comments on commit f197d56

Please sign in to comment.