Fix #231 #207 for 1.20.1

This commit is contained in:
stop-x13
2025-08-19 22:10:09 +08:00
parent 251a8a9465
commit b051b3532b
3 changed files with 67 additions and 23 deletions

View File

@@ -6,9 +6,11 @@ import com.simibubi.create.content.kinetics.base.KineticBlock;
import com.simibubi.create.foundation.block.IBE;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.Containers;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelReader;
@@ -44,26 +46,58 @@ public class IndustrialMixerBlock extends KineticBlock implements IBE<Industrial
}
@Override
public InteractionResult use(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult result) {
if(hand == InteractionHand.OFF_HAND)
public InteractionResult use(BlockState state, Level level, BlockPos pos,
Player player, InteractionHand hand, BlockHitResult hit) {
if (hand == InteractionHand.OFF_HAND)
return InteractionResult.PASS;
if(level.getBlockEntity(pos) instanceof IndustrialMixerBlockEntity be) {
ItemStack stack = player.getItemInHand(hand);
MixerMode mixerMode = be.mixerMode;
ItemStack stackInside = mixerMode.item;
if(stack.is(stackInside.getItem()))
return InteractionResult.PASS;
if(be.setMixerMode(stack, true)) {
if (!(level.getBlockEntity(pos) instanceof IndustrialMixerBlockEntity be))
return InteractionResult.PASS;
player.setItemInHand(hand, mixerMode.item);
be.setMixerMode(stack, false);
return InteractionResult.SUCCESS;
ItemStack held = player.getItemInHand(hand);
MixerMode current = be.mixerMode;
Item installedItem = current.item;
if (held.isEmpty() && installedItem != null) {
if (!level.isClientSide) {
ItemStack refund = new ItemStack(installedItem);
if (!player.addItem(refund)) {
Containers.dropItemStack(level, player.getX(), player.getY(), player.getZ(), refund);
}
be.setMixerMode("none", false);
}
return InteractionResult.sidedSuccess(level.isClientSide);
}
return InteractionResult.PASS;
if (held.isEmpty())
return InteractionResult.PASS;
if (installedItem != null && held.getItem() == installedItem)
return InteractionResult.PASS;
if (!be.setMixerMode(held, true))
return InteractionResult.PASS;
if (!level.isClientSide) {
if (installedItem != null) {
ItemStack prev = new ItemStack(installedItem);
if (!player.addItem(prev)) {
Containers.dropItemStack(level, player.getX(), player.getY(), player.getZ(), prev);
}
}
ItemStack toInstall = held.copy();
toInstall.setCount(1);
be.setMixerMode(toInstall, false);
held.shrink(1);
}
return InteractionResult.sidedSuccess(level.isClientSide);
}
@Override
public void onPlace(BlockState state, Level pLevel, BlockPos pPos, BlockState pOldState, boolean pIsMoving) {
VatBlock.updateVatState(state, pLevel, pPos.relative(Direction.DOWN));

View File

@@ -23,6 +23,7 @@ import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.Containers;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
@@ -71,8 +72,9 @@ public class IndustrialMixerBlockEntity extends KineticBlockEntity implements IV
}
public void destroy() {
ItemStack mixerItem = mixerMode.item;
Containers.dropItemStack(getLevel(), getBlockPos().getX(), getBlockPos().getY(), getBlockPos().getZ(), mixerItem);
ItemStack toDrop = mixerMode.newStack(); // fresh instance every time
if (!toDrop.isEmpty())
Containers.dropItemStack(getLevel(), worldPosition.getX(), worldPosition.getY(), worldPosition.getZ(), toDrop);
}
@@ -120,7 +122,7 @@ public class IndustrialMixerBlockEntity extends KineticBlockEntity implements IV
public boolean setMixerMode(ItemStack modeItem, boolean simulate) {
for (MixerMode mode : MixerMode.values()) {
if (mode.item.is(modeItem.getItem())) {
if (mode.item != null && mode.item == modeItem.getItem()) {
if (!simulate) {
mixerMode = mode;
} else return true;
@@ -163,15 +165,19 @@ public class IndustrialMixerBlockEntity extends KineticBlockEntity implements IV
}
enum MixerMode {
NONE("none", ItemStack.EMPTY),
MIXING("mixing", TFMGItems.MIXER_BLADE.asStack()),
CENTRIFUGE("centrifuge", TFMGItems.CENTRIFUGE.asStack());
NONE("none", null),
MIXING("mixing", TFMGItems.MIXER_BLADE.get()),
CENTRIFUGE("centrifuge", TFMGItems.CENTRIFUGE.get());
public final String name;
public final ItemStack item;
public final Item item;
MixerMode(String name, ItemStack stack) {
MixerMode(String name, Item item) {
this.name = name;
this.item = stack;
this.item = item;
}
public ItemStack newStack() {
return item == null ? ItemStack.EMPTY : new ItemStack(item);
}
}
}

View File

@@ -63,7 +63,11 @@ public class GoggleOverlayRendererMixin {
Minecraft mc = Minecraft.getInstance();
ClientLevel world = mc.level;
HitResult objectMouseOver = mc.hitResult;
BlockHitResult result = (BlockHitResult) objectMouseOver;
if (!(objectMouseOver instanceof BlockHitResult result)) {
tfmg$lastHovered = null;
tfmg$hoverTicks = 0;
return;
}
BlockPos pos = result.getBlockPos();