Fixed issue #16 and #17: breaking blocks with Tinkers Hammer and Veinminer.

Fixed issue #19: placing lilypads results in a crash.
This commit is contained in:
Christian Knaapen
2019-02-22 21:09:28 +01:00
parent 9a3fef218e
commit 4cd2973264
3 changed files with 14 additions and 7 deletions

View File

@@ -19,6 +19,7 @@ import net.minecraftforge.event.entity.player.PlayerEvent;
import net.minecraftforge.event.world.BlockEvent; import net.minecraftforge.event.world.BlockEvent;
import net.minecraftforge.fml.client.event.ConfigChangedEvent; import net.minecraftforge.fml.client.event.ConfigChangedEvent;
import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.eventhandler.Event;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import nl.requios.effortlessbuilding.buildmode.BuildModes; import nl.requios.effortlessbuilding.buildmode.BuildModes;
import nl.requios.effortlessbuilding.buildmode.ModeSettingsManager; import nl.requios.effortlessbuilding.buildmode.ModeSettingsManager;
@@ -77,8 +78,10 @@ public class EventHandler
// } // }
@SubscribeEvent @SubscribeEvent
//Only called serverside //Only called serverside (except with lilypads...)
public static void onBlockPlaced(BlockEvent.PlaceEvent event) { public static void onBlockPlaced(BlockEvent.PlaceEvent event) {
if (event.getWorld().isRemote) return;
//Cancel event if necessary //Cancel event if necessary
EntityPlayer player = event.getPlayer(); EntityPlayer player = event.getPlayer();
BuildModes.BuildModeEnum buildMode = ModeSettingsManager.getModeSettings(player).getBuildMode(); BuildModes.BuildModeEnum buildMode = ModeSettingsManager.getModeSettings(player).getBuildMode();
@@ -97,6 +100,8 @@ public class EventHandler
@SubscribeEvent @SubscribeEvent
public static void onBlockBroken(BlockEvent.BreakEvent event) { public static void onBlockBroken(BlockEvent.BreakEvent event) {
if (event.getWorld().isRemote) return;
//Cancel event if necessary //Cancel event if necessary
//If cant break far then dont cancel event ever //If cant break far then dont cancel event ever
BuildModes.BuildModeEnum buildMode = ModeSettingsManager.getModeSettings(event.getPlayer()).getBuildMode(); BuildModes.BuildModeEnum buildMode = ModeSettingsManager.getModeSettings(event.getPlayer()).getBuildMode();
@@ -105,7 +110,8 @@ public class EventHandler
} else { } else {
//Normal mode, let vanilla handle block breaking //Normal mode, let vanilla handle block breaking
//But modifiers and QuickReplace should still work //But modifiers and QuickReplace should still work
BuildModes.onBlockBroken(event.getPlayer(), event.getPos()); //Dont break the original block yourself, otherwise Tinkers Hammer and Veinminer won't work
BuildModes.onBlockBroken(event.getPlayer(), event.getPos(), false);
} }
} }

View File

@@ -125,11 +125,11 @@ public class BuildModes {
!CompatHelper.chiselsAndBitsProxy.isHoldingChiselTool(EnumHand.MAIN_HAND)) { !CompatHelper.chiselsAndBitsProxy.isHoldingChiselTool(EnumHand.MAIN_HAND)) {
BlockPos startPos = message.isBlockHit() ? message.getBlockPos() : null; BlockPos startPos = message.isBlockHit() ? message.getBlockPos() : null;
onBlockBroken(player, startPos); onBlockBroken(player, startPos, true);
} }
} }
public static void onBlockBroken(EntityPlayer player, BlockPos startPos) { public static void onBlockBroken(EntityPlayer player, BlockPos startPos, boolean breakStartPos) {
//Check if not in the middle of placing //Check if not in the middle of placing
Dictionary<EntityPlayer, Boolean> currentlyBreaking = player.world.isRemote ? currentlyBreakingClient : currentlyBreakingServer; Dictionary<EntityPlayer, Boolean> currentlyBreaking = player.world.isRemote ? currentlyBreakingClient : currentlyBreakingServer;
@@ -156,7 +156,7 @@ public class BuildModes {
} }
//Let buildmodifiers break blocks //Let buildmodifiers break blocks
BuildModifiers.onBlockBroken(player, coordinates); BuildModifiers.onBlockBroken(player, coordinates, breakStartPos);
//Only works when finishing a buildmode is equal to breaking some blocks //Only works when finishing a buildmode is equal to breaking some blocks
//No intermediate blocks allowed //No intermediate blocks allowed

View File

@@ -60,7 +60,7 @@ public class BuildModifiers {
} }
public static void onBlockBroken(EntityPlayer player, List<BlockPos> posList) { public static void onBlockBroken(EntityPlayer player, List<BlockPos> posList, boolean breakStartPos) {
World world = player.world; World world = player.world;
List<BlockPos> coordinates = findCoordinates(player, posList); List<BlockPos> coordinates = findCoordinates(player, posList);
@@ -76,7 +76,8 @@ public class BuildModifiers {
boolean onlyInstaBreaking = world.getBlockState(posList.get(0)).getBlockHardness(world, posList.get(0)) == 0f; boolean onlyInstaBreaking = world.getBlockState(posList.get(0)).getBlockHardness(world, posList.get(0)) == 0f;
//break all those blocks //break all those blocks
for (BlockPos coordinate : coordinates) { for (int i = breakStartPos ? 0 : 1; i < coordinates.size(); i++) {
BlockPos coordinate = coordinates.get(i);
if (world.isBlockLoaded(coordinate, false)) { if (world.isBlockLoaded(coordinate, false)) {
if (!onlyInstaBreaking || world.getBlockState(coordinate).getBlockHardness(world, coordinate) == 0f) { if (!onlyInstaBreaking || world.getBlockState(coordinate).getBlockHardness(world, coordinate) == 0f) {
SurvivalHelper.breakBlock(world, player, coordinate); SurvivalHelper.breakBlock(world, player, coordinate);