Fixed issue #19: placing lilypads results in a crash.
This commit is contained in:
@@ -19,6 +19,7 @@ import net.minecraftforge.event.entity.player.PlayerEvent;
|
||||
import net.minecraftforge.event.world.BlockEvent;
|
||||
import net.minecraftforge.fml.client.event.ConfigChangedEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.eventhandler.Event;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import nl.requios.effortlessbuilding.buildmode.BuildModes;
|
||||
import nl.requios.effortlessbuilding.buildmode.ModeSettingsManager;
|
||||
@@ -77,8 +78,10 @@ public class EventHandler
|
||||
// }
|
||||
|
||||
@SubscribeEvent
|
||||
//Only called serverside
|
||||
//Only called serverside (except with lilypads...)
|
||||
public static void onBlockPlaced(BlockEvent.PlaceEvent event) {
|
||||
if (event.getWorld().isRemote) return;
|
||||
|
||||
//Cancel event if necessary
|
||||
EntityPlayer player = event.getPlayer();
|
||||
BuildModes.BuildModeEnum buildMode = ModeSettingsManager.getModeSettings(player).getBuildMode();
|
||||
@@ -97,6 +100,8 @@ public class EventHandler
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onBlockBroken(BlockEvent.BreakEvent event) {
|
||||
if (event.getWorld().isRemote) return;
|
||||
|
||||
//Cancel event if necessary
|
||||
//If cant break far then dont cancel event ever
|
||||
BuildModes.BuildModeEnum buildMode = ModeSettingsManager.getModeSettings(event.getPlayer()).getBuildMode();
|
||||
@@ -105,7 +110,8 @@ public class EventHandler
|
||||
} else {
|
||||
//Normal mode, let vanilla handle block breaking
|
||||
//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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -125,11 +125,11 @@ public class BuildModes {
|
||||
!CompatHelper.chiselsAndBitsProxy.isHoldingChiselTool(EnumHand.MAIN_HAND)) {
|
||||
|
||||
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
|
||||
Dictionary<EntityPlayer, Boolean> currentlyBreaking = player.world.isRemote ? currentlyBreakingClient : currentlyBreakingServer;
|
||||
@@ -156,7 +156,7 @@ public class BuildModes {
|
||||
}
|
||||
|
||||
//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
|
||||
//No intermediate blocks allowed
|
||||
|
||||
@@ -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;
|
||||
|
||||
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;
|
||||
|
||||
//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 (!onlyInstaBreaking || world.getBlockState(coordinate).getBlockHardness(world, coordinate) == 0f) {
|
||||
SurvivalHelper.breakBlock(world, player, coordinate);
|
||||
|
||||
Reference in New Issue
Block a user