Fixed QuickReplace in normal mode not placing any blocks.

This commit is contained in:
Christian Knaapen
2019-07-08 22:54:33 +02:00
parent 4ce8b1e927
commit 11cd20c3d3
3 changed files with 21 additions and 7 deletions

View File

@@ -55,7 +55,7 @@ public class BuildConfig {
@Comment({"Determines what blocks can be replaced in survival.",
"-1: only blocks that can be harvested by hand (default)",
"0: blocks that can be harvested with wooden oref gold tools",
"0: blocks that can be harvested with wooden or gold tools",
"1: blocks that can be harvested with stone tools",
"2: blocks that can be harvested with iron tools",
"3: blocks that can be harvested with diamond tools",

View File

@@ -91,14 +91,18 @@ public class EventHandler
BuildModes.BuildModeEnum buildMode = ModeSettingsManager.getModeSettings(player).getBuildMode();
ModifierSettingsManager.ModifierSettings modifierSettings = ModifierSettingsManager.getModifierSettings(player);
if (buildMode != BuildModes.BuildModeEnum.NORMAL || modifierSettings.doQuickReplace()) {
if (buildMode != BuildModes.BuildModeEnum.NORMAL) {
event.setCanceled(true);
} else if (modifierSettings.doQuickReplace()) {
//Cancel event and send message if QuickReplace
event.setCanceled(true);
EffortlessBuilding.packetHandler.sendTo(new RequestLookAtMessage(event.getPos(), event.getBlockSnapshot().getReplacedBlock(), event.getState(), true), (EntityPlayerMP) player);
} else {
//NORMAL mode, let vanilla handle block placing
//But modifiers and QuickReplace should still work
//But modifiers should still work
//Send message to client, which sends message back with raytrace info
EffortlessBuilding.packetHandler.sendTo(new RequestLookAtMessage(event.getPos(), event.getBlockSnapshot().getReplacedBlock(), event.getState()), (EntityPlayerMP) player);
EffortlessBuilding.packetHandler.sendTo(new RequestLookAtMessage(event.getPos(), event.getBlockSnapshot().getReplacedBlock(), event.getState(), false), (EntityPlayerMP) player);
}
}

View File

@@ -25,17 +25,20 @@ public class RequestLookAtMessage implements IMessage {
private BlockPos coordinate;
private IBlockState previousBlockState;
private IBlockState newBlockState;
private boolean placeStartPos;
public RequestLookAtMessage() {
coordinate = BlockPos.ORIGIN;
previousBlockState = null;
newBlockState = null;
placeStartPos = false;
}
public RequestLookAtMessage(BlockPos coordinate, IBlockState previousBlockState, IBlockState newBlockState) {
public RequestLookAtMessage(BlockPos coordinate, IBlockState previousBlockState, IBlockState newBlockState, boolean placeStartPos) {
this.coordinate = coordinate;
this.previousBlockState = previousBlockState;
this.newBlockState = newBlockState;
this.placeStartPos = placeStartPos;
}
public BlockPos getCoordinate() {
@@ -50,6 +53,10 @@ public class RequestLookAtMessage implements IMessage {
return newBlockState;
}
public boolean getPlaceStartPos() {
return placeStartPos;
}
@Override
public void toBytes(ByteBuf buf) {
buf.writeInt(this.coordinate.getX());
@@ -57,6 +64,7 @@ public class RequestLookAtMessage implements IMessage {
buf.writeInt(this.coordinate.getZ());
buf.writeInt(Block.getStateId(this.previousBlockState));
buf.writeInt(Block.getStateId(this.newBlockState));
buf.writeBoolean(this.placeStartPos);
}
@Override
@@ -64,6 +72,7 @@ public class RequestLookAtMessage implements IMessage {
coordinate = new BlockPos(buf.readInt(), buf.readInt(), buf.readInt());
previousBlockState = Block.getStateById(buf.readInt());
newBlockState = Block.getStateById(buf.readInt());
placeStartPos = buf.readBoolean();
}
// The params of the IMessageHandler are <REQ, REPLY>
@@ -90,8 +99,9 @@ public class RequestLookAtMessage implements IMessage {
message.getCoordinate(), message.getCoordinate()));
});
//Prevent double placing in normal mode with placeStartPos false
return new BlockPlacedMessage(ClientProxy.previousLookAt, false);
//Prevent double placing in normal mode with placeStartPos false.
//Unless QuickReplace is on, then we do need to place start pos.
return new BlockPlacedMessage(ClientProxy.previousLookAt, message.getPlaceStartPos());
}
return null;
}