diff --git a/src/main/java/com/raoulvdberge/refinedstorage/RSBlocks.java b/src/main/java/com/raoulvdberge/refinedstorage/RSBlocks.java index 180ce7ffe..4c1ac8288 100755 --- a/src/main/java/com/raoulvdberge/refinedstorage/RSBlocks.java +++ b/src/main/java/com/raoulvdberge/refinedstorage/RSBlocks.java @@ -4,7 +4,7 @@ import com.raoulvdberge.refinedstorage.block.*; import net.minecraftforge.registries.ObjectHolder; public final class RSBlocks { - public static final BlockExternalStorage EXTERNAL_STORAGE = new BlockExternalStorage(); + public static final ExternalStorageBlock EXTERNAL_STORAGE = new ExternalStorageBlock(); public static final BlockImporter IMPORTER = new BlockImporter(); public static final BlockExporter EXPORTER = new BlockExporter(); public static final BlockDetector DETECTOR = new BlockDetector(); diff --git a/src/main/java/com/raoulvdberge/refinedstorage/block/BlockExternalStorage.java b/src/main/java/com/raoulvdberge/refinedstorage/block/BlockExternalStorage.java deleted file mode 100755 index cde51fc59..000000000 --- a/src/main/java/com/raoulvdberge/refinedstorage/block/BlockExternalStorage.java +++ /dev/null @@ -1,83 +0,0 @@ -package com.raoulvdberge.refinedstorage.block; - -public class BlockExternalStorage extends CableBlock { - /* TODO - public BlockExternalStorage() { - super(createBuilder("external_storage").tileEntity(TileExternalStorage::new).create()); - } - - @Override - @OnlyIn(Dist.CLIENT) - public void registerModels(IModelRegistration modelRegistration) { - modelRegistration.setModel(this, 0, new ModelResourceLocation(info.getId(), "direction=north,down=false,east=true,north=false,south=false,up=false,west=true")); - - registerCover(modelRegistration); - } - - @Override - @Nullable - public BlockDirection getDirection() { - return BlockDirection.ANY; - } - - @Override - public List getCollisions(TileEntity tile, BlockState state) { - List groups = super.getCollisions(tile, state); - - switch (state.getValue(getDirection().getProperty())) { - case NORTH: - groups.add(ConstantsCable.HOLDER_NORTH); - groups.add(ConstantsExternalStorage.HEAD_NORTH); - break; - case EAST: - groups.add(ConstantsCable.HOLDER_EAST); - groups.add(ConstantsExternalStorage.HEAD_EAST); - break; - case SOUTH: - groups.add(ConstantsCable.HOLDER_SOUTH); - groups.add(ConstantsExternalStorage.HEAD_SOUTH); - break; - case WEST: - groups.add(ConstantsCable.HOLDER_WEST); - groups.add(ConstantsExternalStorage.HEAD_WEST); - break; - case UP: - groups.add(ConstantsCable.HOLDER_UP); - groups.add(ConstantsExternalStorage.HEAD_UP); - break; - case DOWN: - groups.add(ConstantsCable.HOLDER_DOWN); - groups.add(ConstantsExternalStorage.HEAD_DOWN); - break; - } - - return groups; - } - - @Override - public boolean onBlockActivated(World world, BlockPos pos, BlockState state, PlayerEntity player, EnumHand hand, Direction side, float hitX, float hitY, float hitZ) { - if (!canAccessGui(state, world, pos, hitX, hitY, hitZ)) { - return false; - } - - return openNetworkGui(RSGui.EXTERNAL_STORAGE, player, world, pos, side); - } - - @Override - @SuppressWarnings("deprecation") - public void neighborChanged(BlockState state, World world, BlockPos pos, Block block, BlockPos fromPos) { - super.neighborChanged(state, world, pos, block, fromPos); - - if (!world.isRemote) { - TileEntity tile = world.getTileEntity(pos); - - if (tile instanceof TileExternalStorage) { - NetworkNodeExternalStorage externalStorage = ((TileExternalStorage) tile).getNode(); - - if (externalStorage.getNetwork() != null) { - externalStorage.updateStorage(externalStorage.getNetwork()); - } - } - } - }*/ -} diff --git a/src/main/java/com/raoulvdberge/refinedstorage/block/CableBlock.java b/src/main/java/com/raoulvdberge/refinedstorage/block/CableBlock.java index 59ffe095a..b147ae984 100644 --- a/src/main/java/com/raoulvdberge/refinedstorage/block/CableBlock.java +++ b/src/main/java/com/raoulvdberge/refinedstorage/block/CableBlock.java @@ -3,10 +3,9 @@ package com.raoulvdberge.refinedstorage.block; import com.raoulvdberge.refinedstorage.RS; import com.raoulvdberge.refinedstorage.capability.NetworkNodeProxyCapability; import com.raoulvdberge.refinedstorage.tile.CableTile; +import com.raoulvdberge.refinedstorage.util.BlockUtils; import net.minecraft.block.Block; import net.minecraft.block.BlockState; -import net.minecraft.block.SoundType; -import net.minecraft.block.material.Material; import net.minecraft.item.BlockItemUseContext; import net.minecraft.state.BooleanProperty; import net.minecraft.state.StateContainer; @@ -23,20 +22,12 @@ import net.minecraft.world.World; import javax.annotation.Nullable; public class CableBlock extends NodeBlock { - /* TODO - public static final PropertyObject COVER_NORTH = new PropertyObject<>("cover_north", Cover.class); - public static final PropertyObject COVER_EAST = new PropertyObject<>("cover_east", Cover.class); - public static final PropertyObject COVER_SOUTH = new PropertyObject<>("cover_south", Cover.class); - public static final PropertyObject COVER_WEST = new PropertyObject<>("cover_west", Cover.class); - public static final PropertyObject COVER_UP = new PropertyObject<>("cover_up", Cover.class); - public static final PropertyObject COVER_DOWN = new PropertyObject<>("cover_down", Cover.class);*/ - - private static final BooleanProperty NORTH = BooleanProperty.create("north"); - private static final BooleanProperty EAST = BooleanProperty.create("east"); - private static final BooleanProperty SOUTH = BooleanProperty.create("south"); - private static final BooleanProperty WEST = BooleanProperty.create("west"); - private static final BooleanProperty UP = BooleanProperty.create("up"); - private static final BooleanProperty DOWN = BooleanProperty.create("down"); + protected static final BooleanProperty NORTH = BooleanProperty.create("north"); + protected static final BooleanProperty EAST = BooleanProperty.create("east"); + protected static final BooleanProperty SOUTH = BooleanProperty.create("south"); + protected static final BooleanProperty WEST = BooleanProperty.create("west"); + protected static final BooleanProperty UP = BooleanProperty.create("up"); + protected static final BooleanProperty DOWN = BooleanProperty.create("down"); private static final VoxelShape SHAPE_CORE = makeCuboidShape(6, 6, 6, 10, 10, 10); private static final VoxelShape SHAPE_NORTH = makeCuboidShape(6, 6, 0, 10, 10, 6); @@ -46,8 +37,12 @@ public class CableBlock extends NodeBlock { private static final VoxelShape SHAPE_UP = makeCuboidShape(6, 10, 6, 10, 16, 10); private static final VoxelShape SHAPE_DOWN = makeCuboidShape(6, 0, 6, 10, 6, 10); + public CableBlock(Properties props) { + super(props); + } + public CableBlock() { - super(Block.Properties.create(Material.GLASS).sound(SoundType.GLASS).hardnessAndResistance(0.35F)); + super(BlockUtils.DEFAULT_GLASS_PROPERTIES); this.setRegistryName(RS.ID, "cable"); this.setDefaultState(getDefaultState().with(NORTH, false).with(EAST, false).with(SOUTH, false).with(WEST, false).with(UP, false).with(DOWN, false)); @@ -136,25 +131,6 @@ public class CableBlock extends NodeBlock { return new CableTile(); } - /* TODO - @OnlyIn(Dist.CLIENT) - void registerCover(IModelRegistration modelRegistration) { - modelRegistration.addBakedModelOverride(info.getId(), BakedModelCableCover::new); - } - - @OnlyIn(Dist.CLIENT) - void registerCoverAndFullbright(IModelRegistration modelRegistration, ResourceLocation... textures) { - modelRegistration.addBakedModelOverride(info.getId(), base -> new BakedModelCableCover(new BakedModelFullbright(base, textures))); - } - - @Override - @OnlyIn(Dist.CLIENT) - public void registerModels(IModelRegistration modelRegistration) { - modelRegistration.setModel(this, 0, new ModelResourceLocation(info.getId(), "down=false,east=true,north=false,south=false,up=false,west=true")); - - registerCover(modelRegistration); - }*/ - @Override protected void fillStateContainer(StateContainer.Builder builder) { super.fillStateContainer(builder); @@ -162,182 +138,6 @@ public class CableBlock extends NodeBlock { builder.add(NORTH, EAST, SOUTH, WEST, UP, DOWN); } - /* TODO - @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 TileNode && ((TileNode) tile).getNode() instanceof ICoverable) { - s = ((IExtendedBlockState) s).withProperty(COVER_NORTH, ((ICoverable) ((TileNode) tile).getNode()).getCoverManager().getCover(Direction.NORTH)); - s = ((IExtendedBlockState) s).withProperty(COVER_EAST, ((ICoverable) ((TileNode) tile).getNode()).getCoverManager().getCover(Direction.EAST)); - s = ((IExtendedBlockState) s).withProperty(COVER_SOUTH, ((ICoverable) ((TileNode) tile).getNode()).getCoverManager().getCover(Direction.SOUTH)); - s = ((IExtendedBlockState) s).withProperty(COVER_WEST, ((ICoverable) ((TileNode) tile).getNode()).getCoverManager().getCover(Direction.WEST)); - s = ((IExtendedBlockState) s).withProperty(COVER_UP, ((ICoverable) ((TileNode) tile).getNode()).getCoverManager().getCover(Direction.UP)); - s = ((IExtendedBlockState) s).withProperty(COVER_DOWN, ((ICoverable) ((TileNode) tile).getNode()).getCoverManager().getCover(Direction.DOWN)); - } - - return s; - }*/ - - /* TODO - private static boolean hasConnectionWith(World world, BlockPos pos, BlockBase block, TileEntity tile, Direction direction) { - if (!(tile instanceof TileNode)) { - return false; - } - - INetworkNode node = ((TileNode) tile).getNode(); - - if (node instanceof ICoverable) { - Cover cover = ((ICoverable) node).getCoverManager().getCover(direction); - - if (cover != null && cover.getType() != CoverType.HOLLOW) { - return false; - } - } - - TileEntity otherTile = world.getTileEntity(pos.offset(direction)); - - if (otherTile instanceof TileNode && ((TileNode) otherTile).getNode() instanceof ICoverable) { - Cover cover = ((ICoverable) ((TileNode) otherTile).getNode()).getCoverManager().getCover(direction.getOpposite()); - - if (cover != null && cover.getType() != CoverType.HOLLOW) { - return false; - } - } - - if (otherTile != null && otherTile.hasCapability(CapabilityNetworkNodeProxy.NETWORK_NODE_PROXY_CAPABILITY, direction.getOpposite())) { - // Prevent the block adding connections in itself - // For example: importer cable connection on the importer face - if (block.getDirection() != null && ((TileBase) tile).getDirection() == direction) { - return false; - } - - return true; - } - - return false; - }*/ - - /* TODO - @Override - public List getCollisions(TileEntity tile, BlockState state) { - List groups = getCoverCollisions(tile); - - groups.add(ConstantsCable.CORE); - - if (state.getValue(NORTH)) { - groups.add(ConstantsCable.NORTH); - } - - if (state.getValue(EAST)) { - groups.add(ConstantsCable.EAST); - } - - if (state.getValue(SOUTH)) { - groups.add(ConstantsCable.SOUTH); - } - - if (state.getValue(WEST)) { - groups.add(ConstantsCable.WEST); - } - - if (state.getValue(UP)) { - groups.add(ConstantsCable.UP); - } - - if (state.getValue(DOWN)) { - groups.add(ConstantsCable.DOWN); - } - - return groups; - }*/ - - /* TODO - private List getCoverCollisions(TileEntity tile) { - List groups = new ArrayList<>(); - - if (tile instanceof TileNode && ((TileNode) tile).getNode() instanceof ICoverable) { - CoverManager coverManager = ((ICoverable) ((TileNode) tile).getNode()).getCoverManager(); - - Cover coverNorth = coverManager.getCover(Direction.NORTH); - Cover coverEast = coverManager.getCover(Direction.EAST); - Cover coverSouth = coverManager.getCover(Direction.SOUTH); - Cover coverWest = coverManager.getCover(Direction.WEST); - Cover coverUp = coverManager.getCover(Direction.UP); - Cover coverDown = coverManager.getCover(Direction.DOWN); - - if (coverNorth != null) { - groups.add(new CollisionGroup().addItem(CollisionUtils.getBounds( - coverWest != null ? 2 : 0, coverDown != null ? 2 : 0, 0, - coverEast != null ? 14 : 16, coverUp != null ? 14 : 16, 2 - )).setDirection(Direction.NORTH)); - - if (coverNorth.getType() != CoverType.HOLLOW) { - groups.add(ConstantsCable.HOLDER_NORTH); - } - } - - if (coverEast != null) { - groups.add(new CollisionGroup().addItem(CollisionUtils.getBounds( - 14, coverDown != null ? 2 : 0, 0, - 16, coverUp != null ? 14 : 16, 16 - )).setDirection(Direction.EAST)); - - if (coverEast.getType() != CoverType.HOLLOW) { - groups.add(ConstantsCable.HOLDER_EAST); - } - } - - if (coverSouth != null) { - groups.add(new CollisionGroup().addItem(CollisionUtils.getBounds( - coverEast != null ? 14 : 16, coverDown != null ? 2 : 0, 16, - coverWest != null ? 2 : 0, coverUp != null ? 14 : 16, 14 - )).setDirection(Direction.SOUTH)); - - if (coverSouth.getType() != CoverType.HOLLOW) { - groups.add(ConstantsCable.HOLDER_SOUTH); - } - } - - if (coverWest != null) { - groups.add(new CollisionGroup().addItem(CollisionUtils.getBounds( - 0, coverDown != null ? 2 : 0, 0, - 2, coverUp != null ? 14 : 16, 16 - )).setDirection(Direction.WEST)); - - if (coverWest.getType() != CoverType.HOLLOW) { - groups.add(ConstantsCable.HOLDER_WEST); - } - } - - if (coverUp != null) { - groups.add(new CollisionGroup().addItem(CollisionUtils.getBounds( - 0, 14, 0, - 16, 16, 16 - )).setDirection(Direction.UP)); - - if (coverUp.getType() != CoverType.HOLLOW) { - groups.add(ConstantsCable.HOLDER_UP); - } - } - - if (coverDown != null) { - groups.add(new CollisionGroup().addItem(CollisionUtils.getBounds( - 0, 0, 0, - 16, 2, 16 - )).setDirection(Direction.DOWN)); - - if (coverDown.getType() != CoverType.HOLLOW) { - groups.add(ConstantsCable.HOLDER_DOWN); - } - } - } - - return groups; - }*/ - @Override public BlockRenderLayer getRenderLayer() { return BlockRenderLayer.CUTOUT; diff --git a/src/main/java/com/raoulvdberge/refinedstorage/block/ExternalStorageBlock.java b/src/main/java/com/raoulvdberge/refinedstorage/block/ExternalStorageBlock.java new file mode 100644 index 000000000..3b529ce28 --- /dev/null +++ b/src/main/java/com/raoulvdberge/refinedstorage/block/ExternalStorageBlock.java @@ -0,0 +1,90 @@ +package com.raoulvdberge.refinedstorage.block; + +import com.raoulvdberge.refinedstorage.RS; +import com.raoulvdberge.refinedstorage.block.info.BlockDirection; +import com.raoulvdberge.refinedstorage.util.BlockUtils; +import net.minecraft.block.BlockState; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.shapes.ISelectionContext; +import net.minecraft.util.math.shapes.VoxelShape; +import net.minecraft.util.math.shapes.VoxelShapes; +import net.minecraft.world.IBlockReader; + +public class ExternalStorageBlock extends CableBlock { + private static final VoxelShape HEAD_NORTH = makeCuboidShape(3, 3, 0, 13, 13, 2); + private static final VoxelShape HEAD_EAST = makeCuboidShape(14, 3, 3, 16, 13, 13); + private static final VoxelShape HEAD_SOUTH = makeCuboidShape(3, 3, 14, 13, 13, 16); + private static final VoxelShape HEAD_WEST = makeCuboidShape(0, 3, 3, 2, 13, 13); + private static final VoxelShape HEAD_UP = makeCuboidShape(3, 14, 3, 13, 16, 13); + private static final VoxelShape HEAD_DOWN = makeCuboidShape(3, 0, 3, 13, 2, 13); + + public ExternalStorageBlock() { + super(BlockUtils.DEFAULT_GLASS_PROPERTIES); + + this.setRegistryName(RS.ID, "external_storage"); + } + + @Override + public BlockDirection getDirection() { + return BlockDirection.ANY; + } + + @Override + public VoxelShape getShape(BlockState state, IBlockReader world, BlockPos pos, ISelectionContext ctx) { + VoxelShape shape = super.getShape(state, world, pos, ctx); + + if (state.get(NORTH)) { + shape = VoxelShapes.or(shape, HEAD_NORTH); + } + + if (state.get(EAST)) { + shape = VoxelShapes.or(shape, HEAD_EAST); + } + + if (state.get(SOUTH)) { + shape = VoxelShapes.or(shape, HEAD_SOUTH); + } + + if (state.get(WEST)) { + shape = VoxelShapes.or(shape, HEAD_WEST); + } + + if (state.get(UP)) { + shape = VoxelShapes.or(shape, HEAD_UP); + } + + if (state.get(DOWN)) { + shape = VoxelShapes.or(shape, HEAD_DOWN); + } + + return shape; + } + + /* TODO + @Override + public boolean onBlockActivated(World world, BlockPos pos, BlockState state, PlayerEntity player, EnumHand hand, Direction side, float hitX, float hitY, float hitZ) { + if (!canAccessGui(state, world, pos, hitX, hitY, hitZ)) { + return false; + } + + return openNetworkGui(RSGui.EXTERNAL_STORAGE, player, world, pos, side); + } + + @Override + @SuppressWarnings("deprecation") + public void neighborChanged(BlockState state, World world, BlockPos pos, Block block, BlockPos fromPos) { + super.neighborChanged(state, world, pos, block, fromPos); + + if (!world.isRemote) { + TileEntity tile = world.getTileEntity(pos); + + if (tile instanceof TileExternalStorage) { + NetworkNodeExternalStorage externalStorage = ((TileExternalStorage) tile).getNode(); + + if (externalStorage.getNetwork() != null) { + externalStorage.updateStorage(externalStorage.getNetwork()); + } + } + } + }*/ +} diff --git a/src/main/java/com/raoulvdberge/refinedstorage/render/constants/ConstantsCable.java b/src/main/java/com/raoulvdberge/refinedstorage/render/constants/ConstantsCable.java deleted file mode 100644 index 50db4e257..000000000 --- a/src/main/java/com/raoulvdberge/refinedstorage/render/constants/ConstantsCable.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.raoulvdberge.refinedstorage.render.constants; - -import com.raoulvdberge.refinedstorage.render.collision.CollisionGroup; -import com.raoulvdberge.refinedstorage.util.CollisionUtils; -import net.minecraft.util.Direction; -import net.minecraft.util.math.AxisAlignedBB; - -import javax.annotation.Nonnull; - -public final class ConstantsCable { - public static final CollisionGroup HOLDER_NORTH = new CollisionGroup().addItem(getHolderBounds(Direction.NORTH)); - public static final CollisionGroup HOLDER_EAST = new CollisionGroup().addItem(getHolderBounds(Direction.EAST)); - public static final CollisionGroup HOLDER_SOUTH = new CollisionGroup().addItem(getHolderBounds(Direction.SOUTH)); - public static final CollisionGroup HOLDER_WEST = new CollisionGroup().addItem(getHolderBounds(Direction.WEST)); - public static final CollisionGroup HOLDER_UP = new CollisionGroup().addItem(getHolderBounds(Direction.UP)); - public static final CollisionGroup HOLDER_DOWN = new CollisionGroup().addItem(getHolderBounds(Direction.DOWN)); - - @Nonnull - public static AxisAlignedBB getCoverBounds(Direction side) { - switch (side) { - case DOWN: - return CollisionUtils.getBounds(0, 0, 0, 16, 2, 16); - case UP: - return CollisionUtils.getBounds(0, 14, 0, 16, 16, 16); - case NORTH: - return CollisionUtils.getBounds(0, 0, 0, 16, 16, 2); - case SOUTH: - return CollisionUtils.getBounds(0, 0, 14, 16, 16, 16); - case WEST: - return CollisionUtils.getBounds(0, 0, 0, 2, 16, 16); - case EAST: - return CollisionUtils.getBounds(14, 0, 0, 16, 16, 16); - default: - return null; - } - } - - @Nonnull - public static AxisAlignedBB getHolderBounds(Direction side) { - switch (side) { - case DOWN: - return CollisionUtils.getBounds(7, 2, 7, 9, 6, 9); - case UP: - return CollisionUtils.getBounds(7, 10, 7, 9, 14, 9); - case NORTH: - return CollisionUtils.getBounds(7, 7, 2, 9, 9, 6); - case SOUTH: - return CollisionUtils.getBounds(7, 7, 10, 9, 9, 14); - case WEST: - return CollisionUtils.getBounds(2, 7, 7, 6, 9, 9); - case EAST: - return CollisionUtils.getBounds(10, 7, 7, 14, 9, 9); - default: - return null; - } - } -} diff --git a/src/main/java/com/raoulvdberge/refinedstorage/render/constants/ConstantsExternalStorage.java b/src/main/java/com/raoulvdberge/refinedstorage/render/constants/ConstantsExternalStorage.java deleted file mode 100644 index 68c1412d2..000000000 --- a/src/main/java/com/raoulvdberge/refinedstorage/render/constants/ConstantsExternalStorage.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.raoulvdberge.refinedstorage.render.constants; - -import com.raoulvdberge.refinedstorage.render.collision.CollisionGroup; -import com.raoulvdberge.refinedstorage.util.CollisionUtils; - -public final class ConstantsExternalStorage { - public static final CollisionGroup HEAD_NORTH = new CollisionGroup().addItem(CollisionUtils.getBounds(3, 3, 0, 13, 13, 2)).setCanAccessGui(true); - public static final CollisionGroup HEAD_EAST = new CollisionGroup().addItem(CollisionUtils.getBounds(14, 3, 3, 16, 13, 13)).setCanAccessGui(true); - public static final CollisionGroup HEAD_SOUTH = new CollisionGroup().addItem(CollisionUtils.getBounds(3, 3, 14, 13, 13, 16)).setCanAccessGui(true); - public static final CollisionGroup HEAD_WEST = new CollisionGroup().addItem(CollisionUtils.getBounds(0, 3, 3, 2, 13, 13)).setCanAccessGui(true); - public static final CollisionGroup HEAD_UP = new CollisionGroup().addItem(CollisionUtils.getBounds(3, 14, 3, 13, 16, 13)).setCanAccessGui(true); - public static final CollisionGroup HEAD_DOWN = new CollisionGroup().addItem(CollisionUtils.getBounds(3, 0, 3, 13, 2, 13)).setCanAccessGui(true); -} diff --git a/src/main/java/com/raoulvdberge/refinedstorage/util/BlockUtils.java b/src/main/java/com/raoulvdberge/refinedstorage/util/BlockUtils.java index 2ba6c7a77..bb2c586bd 100644 --- a/src/main/java/com/raoulvdberge/refinedstorage/util/BlockUtils.java +++ b/src/main/java/com/raoulvdberge/refinedstorage/util/BlockUtils.java @@ -11,6 +11,7 @@ import net.minecraft.item.Item; public class BlockUtils { public static final Block.Properties DEFAULT_ROCK_PROPERTIES = Block.Properties.create(Material.ROCK).hardnessAndResistance(1.9F).sound(SoundType.STONE); + public static final Block.Properties DEFAULT_GLASS_PROPERTIES = Block.Properties.create(Material.GLASS).sound(SoundType.GLASS).hardnessAndResistance(0.35F); public static BlockItem createBlockItemFor(BaseBlock block) { BaseBlockItem blockItem = new BaseBlockItem(block, new Item.Properties().group(RS.MAIN_GROUP));