mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-12-22 19:39:24 +01:00
Added inventory dropping on tile break
This commit is contained in:
parent
87deb66cce
commit
03eba1564e
2 changed files with 21 additions and 10 deletions
|
@ -12,16 +12,12 @@ import net.minecraft.client.renderer.IRenderTypeBuffer;
|
||||||
import net.minecraft.client.renderer.model.ItemCameraTransforms;
|
import net.minecraft.client.renderer.model.ItemCameraTransforms;
|
||||||
import net.minecraft.client.renderer.tileentity.TileEntityRenderer;
|
import net.minecraft.client.renderer.tileentity.TileEntityRenderer;
|
||||||
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
|
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
|
||||||
import net.minecraft.client.resources.I18n;
|
|
||||||
import net.minecraft.item.BlockItem;
|
import net.minecraft.item.BlockItem;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.util.Util;
|
import net.minecraft.util.Util;
|
||||||
import net.minecraft.util.math.vector.Quaternion;
|
|
||||||
import net.minecraft.util.math.vector.Vector3f;
|
import net.minecraft.util.math.vector.Vector3f;
|
||||||
import net.minecraftforge.energy.CapabilityEnergy;
|
import net.minecraftforge.energy.CapabilityEnergy;
|
||||||
|
|
||||||
import java.text.NumberFormat;
|
|
||||||
|
|
||||||
public class BatteryBoxTileRender extends TileEntityRenderer<BatteryBoxTile> {
|
public class BatteryBoxTileRender extends TileEntityRenderer<BatteryBoxTile> {
|
||||||
public BatteryBoxTileRender(TileEntityRendererDispatcher rendererDispatcherIn) {
|
public BatteryBoxTileRender(TileEntityRendererDispatcher rendererDispatcherIn) {
|
||||||
super(rendererDispatcherIn);
|
super(rendererDispatcherIn);
|
||||||
|
|
|
@ -15,8 +15,11 @@ import net.minecraftforge.energy.CapabilityEnergy;
|
||||||
import net.minecraftforge.energy.IEnergyStorage;
|
import net.minecraftforge.energy.IEnergyStorage;
|
||||||
import net.minecraftforge.items.CapabilityItemHandler;
|
import net.minecraftforge.items.CapabilityItemHandler;
|
||||||
import net.minecraftforge.items.IItemHandler;
|
import net.minecraftforge.items.IItemHandler;
|
||||||
|
import net.minecraftforge.items.wrapper.InvWrapper;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
import java.io.Console;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -74,13 +77,25 @@ public abstract class FunctionalBlock extends ActuallyBlock {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onReplaced(BlockState state, World worldIn, BlockPos pos, BlockState newState, boolean isMoving) {
|
public void onReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean isMoving) {
|
||||||
super.onReplaced(state, worldIn, pos, newState, isMoving);
|
if (newState.getBlock() != this && this.dropsInventory(world, pos)) {
|
||||||
System.out.println("Hello");
|
this.getTile(world, pos).ifPresent(tile -> tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY).ifPresent(inv -> {
|
||||||
|
for (int i = 0; i < inv.getSlots(); i++) {
|
||||||
if (newState != state && this.dropsInventory(worldIn, pos)) {
|
net.minecraft.inventory.InventoryHelper.spawnItemStack(world, pos.getX(), pos.getY(), pos.getZ(), inv.getStackInSlot(i));
|
||||||
System.out.println("Should have dropped");
|
}
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 {
|
public static class ActivatedContext {
|
||||||
|
|
Loading…
Reference in a new issue