Implemented pushing upgrade

This commit is contained in:
Buuz135 2021-12-24 14:17:31 +01:00
parent fd2258b690
commit fd7bed0ebb
2 changed files with 22 additions and 1 deletions

View File

@ -136,6 +136,27 @@ public abstract class ControllableDrawerTile<T extends ControllableDrawerTile<T>
});
});
}
if (item.equals(FunctionalStorage.PUSHING_UPGRADE.get())){
Direction direction = Direction.byName(stack.getOrCreateTag().getString("Direction"));
TileUtil.getTileEntity(level, pos.relative(direction)).ifPresent(blockEntity1 -> {
blockEntity1.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, direction.getOpposite()).ifPresent(otherHandler -> {
for (int otherSlot = 0; otherSlot < getStorage().getSlots(); otherSlot++) {
ItemStack pulledStack = getStorage().extractItem(otherSlot, 2, true);
if (pulledStack.isEmpty()) continue;
boolean hasWorked = false;
for (int ourSlot = 0; ourSlot < otherHandler.getSlots(); ourSlot++) {
ItemStack simulated = otherHandler.insertItem(ourSlot, pulledStack, true);
if (simulated.getCount() != pulledStack.getCount()){
otherHandler.insertItem(ourSlot, getStorage().extractItem(otherSlot, pulledStack.getCount() - simulated.getCount(), false), false );
hasWorked = true;
break;
}
}
if (hasWorked) break;
}
});
});
}
}
}
}

View File

@ -77,7 +77,7 @@ public class DrawerRenderer implements BlockEntityRenderer<DrawerTile> {
public static void renderUpgrades(PoseStack matrixStack, MultiBufferSource bufferIn, int combinedLightIn, int combinedOverlayIn, ControllableDrawerTile<?> tile){
matrixStack.pushPose();
matrixStack.translate(0.031,0.031f,0.469/16D);
matrixStack.translate(0.031,0.031f,0.472/16D);
float scale = 0.0625f;
for (int i = 0; i < tile.getStorageUpgrades().getSlots(); i++) {
ItemStack stack = tile.getStorageUpgrades().getStackInSlot(i);