Added inventory dropping on tile break

This commit is contained in:
Michael Hillcox 2021-01-17 14:04:42 +00:00
parent 87deb66cce
commit 03eba1564e
2 changed files with 21 additions and 10 deletions

View file

@ -12,16 +12,12 @@ import net.minecraft.client.renderer.IRenderTypeBuffer;
import net.minecraft.client.renderer.model.ItemCameraTransforms;
import net.minecraft.client.renderer.tileentity.TileEntityRenderer;
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
import net.minecraft.client.resources.I18n;
import net.minecraft.item.BlockItem;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Util;
import net.minecraft.util.math.vector.Quaternion;
import net.minecraft.util.math.vector.Vector3f;
import net.minecraftforge.energy.CapabilityEnergy;
import java.text.NumberFormat;
public class BatteryBoxTileRender extends TileEntityRenderer<BatteryBoxTile> {
public BatteryBoxTileRender(TileEntityRendererDispatcher rendererDispatcherIn) {
super(rendererDispatcherIn);

View file

@ -15,8 +15,11 @@ import net.minecraftforge.energy.CapabilityEnergy;
import net.minecraftforge.energy.IEnergyStorage;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.wrapper.InvWrapper;
import javax.annotation.Nullable;
import java.io.Console;
import java.util.Optional;
import java.util.function.Supplier;
/**
@ -74,13 +77,25 @@ public abstract class FunctionalBlock extends ActuallyBlock {
}
@Override
public void onReplaced(BlockState state, World worldIn, BlockPos pos, BlockState newState, boolean isMoving) {
super.onReplaced(state, worldIn, pos, newState, isMoving);
System.out.println("Hello");
if (newState != state && this.dropsInventory(worldIn, pos)) {
System.out.println("Should have dropped");
public void onReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean isMoving) {
if (newState.getBlock() != this && this.dropsInventory(world, pos)) {
this.getTile(world, pos).ifPresent(tile -> tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY).ifPresent(inv -> {
for (int i = 0; i < inv.getSlots(); i++) {
net.minecraft.inventory.InventoryHelper.spawnItemStack(world, pos.getX(), pos.getY(), pos.getZ(), inv.getStackInSlot(i));
}
}));
}
super.onReplaced(state, world, pos, newState, isMoving);
}
public Optional<TileEntity> getTile(World world, BlockPos pos) {
TileEntity entity = world.getTileEntity(pos);
if (entity == null) {
return Optional.empty();
}
return Optional.of(entity);
}
public static class ActivatedContext {