Fix JukeboxPoint (#7040)

This commit is contained in:
IThundxr 2025-01-10 11:53:59 -05:00 committed by GitHub
parent d48a504486
commit d97f01add8
Failed to generate hash of commit

View file

@ -646,45 +646,30 @@ public class AllArmInteractionPointTypes {
@Override @Override
public ItemStack insert(ItemStack stack, boolean simulate) { public ItemStack insert(ItemStack stack, boolean simulate) {
Item item = stack.getItem(); if (!(stack.getItem() instanceof RecordItem))
if (!(item instanceof RecordItem))
return stack; return stack;
if (cachedState.getOptionalValue(JukeboxBlock.HAS_RECORD) if (cachedState.getOptionalValue(JukeboxBlock.HAS_RECORD).orElse(true))
.orElse(true))
return stack; return stack;
BlockEntity blockEntity = level.getBlockEntity(pos); if (!(level.getBlockEntity(pos) instanceof JukeboxBlockEntity jukeboxBE))
if (!(blockEntity instanceof JukeboxBlockEntity jukeboxBE))
return stack; return stack;
if (!jukeboxBE.getFirstItem() if (!jukeboxBE.getFirstItem().isEmpty())
.isEmpty())
return stack; return stack;
ItemStack remainder = stack.copy(); ItemStack remainder = stack.copy();
ItemStack toInsert = remainder.split(1); ItemStack toInsert = remainder.split(1);
if (!simulate) { if (!simulate)
jukeboxBE.setFirstItem(toInsert); jukeboxBE.setItem(0, toInsert);
level.setBlock(pos, cachedState.setValue(JukeboxBlock.HAS_RECORD, true), 2);
level.levelEvent(null, 1010, pos, Item.getId(item));
}
return remainder; return remainder;
} }
@Override @Override
public ItemStack extract(int slot, int amount, boolean simulate) { public ItemStack extract(int slot, int amount, boolean simulate) {
if (!cachedState.getOptionalValue(JukeboxBlock.HAS_RECORD) if (!cachedState.getOptionalValue(JukeboxBlock.HAS_RECORD).orElse(false))
.orElse(false))
return ItemStack.EMPTY; return ItemStack.EMPTY;
BlockEntity blockEntity = level.getBlockEntity(pos); if (!(level.getBlockEntity(pos) instanceof JukeboxBlockEntity jukeboxBE))
if (!(blockEntity instanceof JukeboxBlockEntity jukeboxBE))
return ItemStack.EMPTY; return ItemStack.EMPTY;
ItemStack record = jukeboxBE.getFirstItem(); if (!simulate)
if (record.isEmpty()) return jukeboxBE.removeItem(slot, amount);
return ItemStack.EMPTY; return jukeboxBE.getFirstItem();
if (!simulate) {
level.levelEvent(1010, pos, 0);
jukeboxBE.clearContent();
level.setBlock(pos, cachedState.setValue(JukeboxBlock.HAS_RECORD, false), 2);
}
return record;
} }
} }