Disk drive drops
This commit is contained in:
@@ -67,6 +67,7 @@ public final class RS {
|
|||||||
FMLJavaModLoadingContext.get().getModEventBus().addGenericListener(Item.class, this::onRegisterItems);
|
FMLJavaModLoadingContext.get().getModEventBus().addGenericListener(Item.class, this::onRegisterItems);
|
||||||
FMLJavaModLoadingContext.get().getModEventBus().addGenericListener(IRecipeSerializer.class, this::onRegisterRecipeSerializers);
|
FMLJavaModLoadingContext.get().getModEventBus().addGenericListener(IRecipeSerializer.class, this::onRegisterRecipeSerializers);
|
||||||
FMLJavaModLoadingContext.get().getModEventBus().addGenericListener(ContainerType.class, this::onRegisterContainers);
|
FMLJavaModLoadingContext.get().getModEventBus().addGenericListener(ContainerType.class, this::onRegisterContainers);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
|
|||||||
@@ -21,8 +21,6 @@ import net.minecraftforge.fml.network.NetworkHooks;
|
|||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
public class DiskDriveBlock extends NodeBlock {
|
public class DiskDriveBlock extends NodeBlock {
|
||||||
// TODO public static final PropertyObject<Integer[]> DISK_STATE = new PropertyObject<>("disk_state", Integer[].class);
|
|
||||||
|
|
||||||
public DiskDriveBlock() {
|
public DiskDriveBlock() {
|
||||||
super(BlockUtils.DEFAULT_ROCK_PROPERTIES);
|
super(BlockUtils.DEFAULT_ROCK_PROPERTIES);
|
||||||
|
|
||||||
@@ -63,27 +61,9 @@ public class DiskDriveBlock extends NodeBlock {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO
|
/* TODO
|
||||||
@Override
|
@Override
|
||||||
public boolean onBlockActivated(World world, BlockPos pos, BlockState state, PlayerEntity player, EnumHand hand, Direction side, float hitX, float hitY, float hitZ) {
|
public boolean onBlockActivated(World world, BlockPos pos, BlockState state, PlayerEntity player, EnumHand hand, Direction side, float hitX, float hitY, float hitZ) {
|
||||||
return openNetworkGui(RSGui.DISK_DRIVE, player, world, pos, side);
|
return openNetworkGui(RSGui.DISK_DRIVE, player, world, pos, side);
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected BlockStateContainer.Builder createBlockStateBuilder() {
|
|
||||||
return super.createBlockStateBuilder().add(DISK_STATE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public BlockState getExtendedState(BlockState state, IBlockAccess world, BlockPos pos) {
|
|
||||||
BlockState s = super.getExtendedState(state, world, pos);
|
|
||||||
|
|
||||||
TileEntity tile = world.getTileEntity(pos);
|
|
||||||
|
|
||||||
if (tile instanceof TileDiskDrive) {
|
|
||||||
s = ((IExtendedBlockState) s).withProperty(DISK_STATE, ((TileDiskDrive) tile).getDiskState());
|
|
||||||
}
|
|
||||||
|
|
||||||
return s;
|
|
||||||
}*/
|
}*/
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,13 +4,20 @@ import com.raoulvdberge.refinedstorage.api.network.node.INetworkNode;
|
|||||||
import com.raoulvdberge.refinedstorage.api.network.node.INetworkNodeManager;
|
import com.raoulvdberge.refinedstorage.api.network.node.INetworkNodeManager;
|
||||||
import com.raoulvdberge.refinedstorage.api.util.Action;
|
import com.raoulvdberge.refinedstorage.api.util.Action;
|
||||||
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
||||||
|
import com.raoulvdberge.refinedstorage.tile.NetworkNodeTile;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
|
import net.minecraft.inventory.InventoryHelper;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.state.BooleanProperty;
|
import net.minecraft.state.BooleanProperty;
|
||||||
import net.minecraft.state.StateContainer;
|
import net.minecraft.state.StateContainer;
|
||||||
|
import net.minecraft.tileentity.TileEntity;
|
||||||
|
import net.minecraft.util.NonNullList;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.IWorld;
|
import net.minecraft.world.IWorld;
|
||||||
|
import net.minecraft.world.World;
|
||||||
import net.minecraft.world.server.ServerWorld;
|
import net.minecraft.world.server.ServerWorld;
|
||||||
|
import net.minecraftforge.items.IItemHandler;
|
||||||
|
|
||||||
public abstract class NodeBlock extends BaseBlock {
|
public abstract class NodeBlock extends BaseBlock {
|
||||||
public static final BooleanProperty CONNECTED = BooleanProperty.create("connected");
|
public static final BooleanProperty CONNECTED = BooleanProperty.create("connected");
|
||||||
@@ -37,6 +44,29 @@ public abstract class NodeBlock extends BaseBlock {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onReplaced(BlockState state, World worldIn, BlockPos pos, BlockState newState, boolean isMoving) {
|
||||||
|
if (state.getBlock() != newState.getBlock()) {
|
||||||
|
TileEntity tile = worldIn.getTileEntity(pos);
|
||||||
|
|
||||||
|
if (tile instanceof NetworkNodeTile) {
|
||||||
|
IItemHandler handler = ((NetworkNodeTile) tile).getNode().getDrops();
|
||||||
|
|
||||||
|
if (handler != null) {
|
||||||
|
NonNullList<ItemStack> drops = NonNullList.create();
|
||||||
|
|
||||||
|
for (int i = 0; i < handler.getSlots(); ++i) {
|
||||||
|
drops.add(handler.getStackInSlot(i));
|
||||||
|
}
|
||||||
|
|
||||||
|
InventoryHelper.dropItems(worldIn, pos, drops);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
super.onReplaced(state, worldIn, pos, newState, isMoving);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder) {
|
protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder) {
|
||||||
super.fillStateContainer(builder);
|
super.fillStateContainer(builder);
|
||||||
|
|||||||
@@ -11,14 +11,20 @@ import com.raoulvdberge.refinedstorage.util.WorldUtils;
|
|||||||
import net.minecraft.nbt.CompoundNBT;
|
import net.minecraft.nbt.CompoundNBT;
|
||||||
import net.minecraft.nbt.IntNBT;
|
import net.minecraft.nbt.IntNBT;
|
||||||
import net.minecraft.nbt.ListNBT;
|
import net.minecraft.nbt.ListNBT;
|
||||||
|
import net.minecraft.util.Direction;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.client.model.data.IModelData;
|
import net.minecraftforge.client.model.data.IModelData;
|
||||||
import net.minecraftforge.client.model.data.ModelDataMap;
|
import net.minecraftforge.client.model.data.ModelDataMap;
|
||||||
import net.minecraftforge.client.model.data.ModelProperty;
|
import net.minecraftforge.client.model.data.ModelProperty;
|
||||||
|
import net.minecraftforge.common.capabilities.Capability;
|
||||||
import net.minecraftforge.common.util.Constants;
|
import net.minecraftforge.common.util.Constants;
|
||||||
|
import net.minecraftforge.common.util.LazyOptional;
|
||||||
|
import net.minecraftforge.items.CapabilityItemHandler;
|
||||||
|
import net.minecraftforge.items.IItemHandler;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
public class DiskDriveTile extends NetworkNodeTile<DiskDriveNetworkNode> {
|
public class DiskDriveTile extends NetworkNodeTile<DiskDriveNetworkNode> {
|
||||||
@@ -73,6 +79,8 @@ public class DiskDriveTile extends NetworkNodeTile<DiskDriveNetworkNode> {
|
|||||||
private static final String NBT_DISK_STATE = "DiskStates";
|
private static final String NBT_DISK_STATE = "DiskStates";
|
||||||
public static final ModelProperty<DiskDriveNetworkNode.DiskState[]> DISK_STATE_PROPERTY = new ModelProperty<>();
|
public static final ModelProperty<DiskDriveNetworkNode.DiskState[]> DISK_STATE_PROPERTY = new ModelProperty<>();
|
||||||
|
|
||||||
|
private LazyOptional<IItemHandler> diskCapability = LazyOptional.of(() -> getNode().getDisks());
|
||||||
|
|
||||||
private DiskDriveNetworkNode.DiskState[] diskState = new DiskDriveNetworkNode.DiskState[8];
|
private DiskDriveNetworkNode.DiskState[] diskState = new DiskDriveNetworkNode.DiskState[8];
|
||||||
|
|
||||||
public DiskDriveTile() {
|
public DiskDriveTile() {
|
||||||
@@ -125,20 +133,15 @@ public class DiskDriveTile extends NetworkNodeTile<DiskDriveNetworkNode> {
|
|||||||
return new ModelDataMap.Builder().withInitial(DISK_STATE_PROPERTY, diskState).build();
|
return new ModelDataMap.Builder().withInitial(DISK_STATE_PROPERTY, diskState).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable Direction facing) {
|
public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap, @Nullable Direction direction) {
|
||||||
return capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY || super.hasCapability(capability, facing);
|
if (cap == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) {
|
||||||
}
|
return diskCapability.cast();
|
||||||
|
|
||||||
@Override
|
|
||||||
public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable Direction facing) {
|
|
||||||
if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) {
|
|
||||||
return CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.cast(getNode().getDisks());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return super.getCapability(capability, facing);
|
return super.getCapability(cap, direction);
|
||||||
}*/
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Nonnull
|
@Nonnull
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
{
|
||||||
|
"type": "minecraft:block",
|
||||||
|
"pools": [
|
||||||
|
{
|
||||||
|
"rolls": 1,
|
||||||
|
"entries": [
|
||||||
|
{
|
||||||
|
"type": "minecraft:item",
|
||||||
|
"name": "refinedstorage:disk_drive"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"conditions": [
|
||||||
|
{
|
||||||
|
"condition": "minecraft:survives_explosion"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user