fixed mixin, speeding up algorithm still not working

This commit is contained in:
loenaaaa committed 2025-12-24 22:47:23 +08:00
1 parent 5e4cf098d5
commit f0701fbd14
6 files changed
+50 -26

No files matched your search

+1 -1
View File
@@ -41,7 +41,7 @@ developmentEnvironmentUserName = Developer
# Enables using modern Java syntax (up to version 17) via Jabel, while still targeting JVM 8.
# See https://github.com/bsideup/jabel for details on how this works.
enableModernJavaSyntax = false
enableModernJavaSyntax = true
# Enables injecting missing generics into the decompiled source code for a better coding experience.
# Turns most publicly visible List, Map, etc. into proper List<E>, Map<K, V> types.
@@ -514,6 +514,9 @@ public class BlockDrawers extends BlockContainer implements IExtendedBlockClickH
}
TileEntityDrawers tileDrawers = getTileEntitySafe(world, x, y, z);
tileDrawers.clickedOnPreviousTick = true;
Minecraft.getMinecraft().playerController.curBlockDamageMP = 0.0F;
if (tileDrawers.getDirection() != side) return;
if (tileDrawers.isSealed()) return;
@@ -5,6 +5,7 @@ import java.util.UUID;
import javax.annotation.Nullable;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.ItemStack;
@@ -68,6 +69,10 @@ public abstract class TileEntityDrawers extends BaseTileEntity implements IDrawe
private boolean hideUpgrade = false;
private boolean downgraded = false;
private int ticksClickedInARow = 10000;
private int itemsOutputInARow = 0;
public boolean clickedOnPreviousTick = false;
private UUID owner;
private String securityKey;
@@ -84,6 +89,17 @@ public abstract class TileEntityDrawers extends BaseTileEntity implements IDrawe
private ItemStack materialFront;
private ItemStack materialTrim;
@Override
public void updateEntity() {
if (clickedOnPreviousTick) {
ticksClickedInARow++;
} else {
ticksClickedInARow = 10000; // set high so that it always registers on first click!
itemsOutputInARow = 0;
}
clickedOnPreviousTick = false;
}
protected TileEntityDrawers(int drawerCount) {
initWithDrawerCount(drawerCount);
}
@@ -541,6 +557,20 @@ public abstract class TileEntityDrawers extends BaseTileEntity implements IDrawe
ItemStack stack = getItemsFromSlot(slot, count);
if (stack == null) return null;
int ticksConsecutiveClickRequirement = 50 / (itemsOutputInARow + 5);
if (ticksClickedInARow < ticksConsecutiveClickRequirement) return null;
System.out.println(
"Reached tick goal of " + ticksConsecutiveClickRequirement
+ "and outputted "
+ itemsOutputInARow
+ " items. Current player block break progress is at "
+ Minecraft.getMinecraft().playerController.curBlockDamageMP);
ticksClickedInARow = 0;
itemsOutputInARow++;
IDrawer drawer = drawers[slot];
drawer.setStoredItemCount(drawer.getStoredItemCount() - stack.stackSize);
@@ -780,11 +810,6 @@ public abstract class TileEntityDrawers extends BaseTileEntity implements IDrawe
}
}
@Override
public boolean canUpdate() {
return false;
}
@Override
public void markDirty() {
inventory.markDirty();
@@ -4,7 +4,6 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import com.gtnewhorizon.gtnhlib.mixins.Mixins;
import com.gtnewhorizon.gtnhmixins.IEarlyMixinLoader;
import com.gtnewhorizon.gtnhmixins.builders.IMixins;
@@ -11,7 +11,7 @@ public enum Mixins implements IMixins {
// You should declare all of your mixins early and late in this same enum
EXAMPLE(new MixinBuilder().setPhase(Phase.EARLY).addClientMixins("MixinPlayerControllerMP"));
MIXIN_PLAYER_CONTROLLER(new MixinBuilder().setPhase(Phase.EARLY).addClientMixins("MixinPlayerControllerMP"));
private final MixinBuilder builder;
@@ -6,34 +6,31 @@ import net.minecraft.client.multiplayer.PlayerControllerMP;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import com.jaquadro.minecraft.storagedrawers.block.BlockDrawers;
import com.jaquadro.minecraft.storagedrawers.block.tile.TileEntityDrawers;
import com.llamalad7.mixinextras.expression.Definition;
import com.llamalad7.mixinextras.expression.Expression;
import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import com.llamalad7.mixinextras.sugar.Local;
@Mixin(PlayerControllerMP.class)
public abstract class MixinPlayerControllerMP {
@Shadow
private float curBlockDamageMP;
private Minecraft mc;
@Definition(
id = "curBlockDamageMP",
field = "Lnet/minecraft/client/multiplayer/PlayerControllerMP;curBlockDamageMP:F")
@Expression("this.curBlockDamageMP == 0.0")
@ModifyExpressionValue(method = "clickBlock", at = @At(value = "MIXINEXTRAS:EXPRESSION"))
private boolean withClickOnDrawer(boolean original, @Local Minecraft mc, @Local int x, @Local int y, @Local int z,
@Local int side) {
if (mc.theWorld.getTileEntity(x, y, z) instanceof TileEntityDrawers) {
TileEntityDrawers ted = (TileEntityDrawers) mc.theWorld.getTileEntity(x, y, z);
@Inject(
method = "onPlayerDamageBlock",
at = @At(
value = "INVOKE_ASSIGN",
target = "Lnet/minecraft/block/Block;getPlayerRelativeBlockHardness(Lnet/minecraft/entity/player/EntityPlayer;Lnet/minecraft/world/World;III)F"))
private void mixin(int x, int y, int z, int side, CallbackInfo ci) { // cancels block break progress and fires a
// click
// block event on the TileEntityDrawer if applicable
if (mc.theWorld.getTileEntity(x, y, z) instanceof TileEntityDrawers ted
&& mc.theWorld.getBlock(x, y, z) instanceof BlockDrawers bd) {
if (ted.getDirection() == side) {
curBlockDamageMP = 0.0F;
return true;
bd.onBlockClicked(mc.theWorld, x, y, z, mc.thePlayer);
}
}
return original;
}
}