Fixed disassembling blocks with the Create Wrench duplicating the item when a build mode other than Normal is used. Disabled break outlines in survival, because breaking multiple blocks in survival is deprecated.

This commit is contained in:
Christian Knaapen
2022-10-25 21:52:14 +02:00
parent 14460c2c01
commit 5e6c42d372
8 changed files with 93 additions and 42 deletions

View File

@@ -1,5 +1,8 @@
package nl.requios.effortlessbuilding;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player;
@@ -19,6 +22,7 @@ import nl.requios.effortlessbuilding.buildmodifier.ModifierSettingsManager;
import nl.requios.effortlessbuilding.buildmodifier.UndoRedo;
import nl.requios.effortlessbuilding.capability.ModeCapabilityManager;
import nl.requios.effortlessbuilding.capability.ModifierCapabilityManager;
import nl.requios.effortlessbuilding.compatibility.CompatHelper;
import nl.requios.effortlessbuilding.helper.ReachHelper;
import nl.requios.effortlessbuilding.network.AddUndoMessage;
import nl.requios.effortlessbuilding.network.ClearUndoMessage;
@@ -51,7 +55,15 @@ public class EventHandler {
ModifierSettingsManager.ModifierSettings modifierSettings = ModifierSettingsManager.getModifierSettings(player);
if (buildMode != BuildModes.BuildModeEnum.NORMAL) {
event.setCanceled(true);
//Only cancel if itemblock in hand
//Fixed issue with e.g. Create Wrench shift-rightclick disassembling being cancelled.
ItemStack currentItemStack = player.getItemInHand(InteractionHand.MAIN_HAND);
if (currentItemStack.getItem() instanceof BlockItem ||
(CompatHelper.isItemBlockProxy(currentItemStack) && !player.isShiftKeyDown())) {
event.setCanceled(true);
}
} else if (modifierSettings.doQuickReplace()) {
//Cancel event and send message if QuickReplace
event.setCanceled(true);

View File

@@ -53,7 +53,6 @@ public class BuildModes {
startPos = message.getBlockPos();
//Offset in direction of sidehit if not quickreplace and not replaceable
//TODO 1.13 replaceable
boolean replaceable = player.level.getBlockState(startPos).getMaterial().isReplaceable();
boolean becomesDoubleSlab = SurvivalHelper.doesBecomeDoubleSlab(player, startPos, message.getSideHit());
if (!modifierSettings.doQuickReplace() && !replaceable && !becomesDoubleSlab) {
@@ -99,7 +98,6 @@ public class BuildModes {
//Only works when finishing a buildmode is equal to placing some blocks
//No intermediate blocks allowed
currentlyBreaking.remove(player);
}
//Use a network message to break blocks in the distance using clientside mouse input

View File

@@ -187,7 +187,7 @@ public class PlayerSettingsGui extends Screen {
return right - 6;
}
//From AbstractList, disabled parts
//From AbstractSelectionList, disabled parts
@Override
public void render(PoseStack ms, int p_render_1_, int p_render_2_, float p_render_3_) {
this.renderBackground(ms);
@@ -212,7 +212,7 @@ public class PlayerSettingsGui extends Screen {
this.renderHeader(ms, k, l, tessellator);
}
this.renderList(ms, k, l, p_render_1_, p_render_2_, p_render_3_);
this.renderList(ms, p_render_1_, p_render_2_, p_render_3_);
RenderSystem.disableDepthTest();
// this.renderHoleBackground(0, this.y0, 255, 255);
// this.renderHoleBackground(this.y1, this.height, 255, 255);

View File

@@ -121,7 +121,7 @@ public class ClientProxy implements IProxy {
if (player == null) return;
BuildModes.BuildModeEnum buildMode = ModeSettingsManager.getModeSettings(player).getBuildMode();
if (Minecraft.getInstance().screen != null ||
if (mc.screen != null ||
buildMode == BuildModes.BuildModeEnum.NORMAL ||
RadialMenu.instance.isVisible()) {
return;

View File

@@ -76,7 +76,7 @@ public class BlockPreviewRenderer {
lookingAt = Minecraft.getInstance().hitResult;
ItemStack mainhand = player.getMainHandItem();
boolean toolInHand = !(!mainhand.isEmpty() && CompatHelper.isItemBlockProxy(mainhand));
boolean noBlockInHand = !(!mainhand.isEmpty() && CompatHelper.isItemBlockProxy(mainhand));
BlockPos startPos = null;
Direction sideHit = null;
@@ -91,12 +91,12 @@ public class BlockPreviewRenderer {
//TODO 1.13 replaceable
boolean replaceable = player.level.getBlockState(startPos).getMaterial().isReplaceable();
boolean becomesDoubleSlab = SurvivalHelper.doesBecomeDoubleSlab(player, startPos, blockLookingAt.getDirection());
if (!modifierSettings.doQuickReplace() && !toolInHand && !replaceable && !becomesDoubleSlab) {
if (!modifierSettings.doQuickReplace() && !noBlockInHand && !replaceable && !becomesDoubleSlab) {
startPos = startPos.relative(blockLookingAt.getDirection());
}
//Get under tall grass and other replaceable blocks
if (modifierSettings.doQuickReplace() && !toolInHand && replaceable) {
if (modifierSettings.doQuickReplace() && !noBlockInHand && replaceable) {
startPos = startPos.below();
}
@@ -236,12 +236,13 @@ public class BlockPreviewRenderer {
}
VertexConsumer buffer = RenderHandler.beginLines(renderTypeBuffer);
//Draw outlines if tool in hand
//Draw outlines if no block in hand
//Find proper raytrace: either normal range or increased range depending on canBreakFar
VertexConsumer buffer = RenderHandler.beginLines(renderTypeBuffer);
HitResult objectMouseOver = Minecraft.getInstance().hitResult;
HitResult breakingRaytrace = ReachHelper.canBreakFar(player) ? lookingAt : objectMouseOver;
if (toolInHand && breakingRaytrace != null && breakingRaytrace.getType() == HitResult.Type.BLOCK) {
if (player.isCreative() && noBlockInHand && breakingRaytrace != null && breakingRaytrace.getType() == HitResult.Type.BLOCK) {
BlockHitResult blockBreakingRaytrace = (BlockHitResult) breakingRaytrace;
List<BlockPos> breakCoordinates = BuildModifiers.findCoordinates(player, blockBreakingRaytrace.getBlockPos());