Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package exokem.exkva.objects.blocks.ElectricalCable;
- import com.google.common.collect.Maps;
- import exokem.exkva.common.Exkva;
- import exokem.exkva.objects.bases.mach.Machine;
- import net.minecraft.block.Block;
- import net.minecraft.block.SoundType;
- import net.minecraft.block.material.Material;
- import net.minecraft.block.properties.PropertyBool;
- import net.minecraft.block.state.BlockStateContainer;
- import net.minecraft.block.state.IBlockState;
- import net.minecraft.client.renderer.block.model.ModelResourceLocation;
- import net.minecraft.entity.Entity;
- import net.minecraft.entity.EntityLivingBase;
- import net.minecraft.item.Item;
- import net.minecraft.item.ItemStack;
- import net.minecraft.tileentity.TileEntity;
- import net.minecraft.util.EnumFacing;
- import net.minecraft.util.ResourceLocation;
- import net.minecraft.util.math.AxisAlignedBB;
- import net.minecraft.util.math.BlockPos;
- import net.minecraft.util.math.Vec3d;
- import net.minecraft.world.IBlockAccess;
- import net.minecraft.world.World;
- import net.minecraftforge.client.model.ModelLoader;
- import javax.annotation.Nullable;
- import java.util.List;
- import java.util.Map;
- import java.util.function.Function;
- import java.util.stream.Stream;
- public class BlockCable extends Block {
- private static final Map<EnumFacing, PropertyBool> SIDES = Stream.of(EnumFacing.VALUES)
- .collect(Maps.toImmutableEnumMap(Function.identity(), f -> PropertyBool.create(f.getName())));
- private static final AxisAlignedBB BOUNDING_BOX = new AxisAlignedBB(0.3125D, 0, 0.3125D, 0.6875D, 0.1875D, 0.6875D);
- private static final Map<EnumFacing, AxisAlignedBB> BOUNDING_BOXES = Stream.of(EnumFacing.VALUES)
- .collect(Maps.toImmutableEnumMap(Function.identity(), f -> {
- final Vec3d min = new Vec3d(0.3125D, 0, 0.000);
- final Vec3d max = new Vec3d(0.625, 0.1875D, 0.3125D);
- switch (f) {
- case DOWN: return BOUNDING_BOX;
- case UP: return BOUNDING_BOX;
- case NORTH: return new AxisAlignedBB(min.x, min.y, min.z, max.x, max.y, max.z);
- case SOUTH: return new AxisAlignedBB(1 - max.x, min.y, 1 - max.z, 1 - min.x, max.y, 1 - min.z);
- case WEST: return new AxisAlignedBB(min.z, min.y, 1 - max.x, max.z, max.y, 1 - min.x);
- case EAST: return new AxisAlignedBB(1 - max.z, min.y, min.x, 1 - min.z, max.y, max.x);
- default: throw new IllegalArgumentException("Not a recognized facing: " + f);
- }
- }));
- public BlockCable() {
- super(Material.CIRCUITS);
- setUnlocalizedName(Exkva.MODID + ".electrical_cable");
- setRegistryName(new ResourceLocation(Exkva.MODID, "electrical_cable"));
- IBlockState defaultState = this.getDefaultState();
- for (final PropertyBool property : BlockCable.SIDES.values()) {
- defaultState = defaultState.withProperty(property, true);
- }
- this.setDefaultState(defaultState);
- this.setSoundType(SoundType.METAL);
- this.setHardness(0.25F);
- this.setLightOpacity(0);
- }
- @Override
- public boolean isFullCube(IBlockState state) {
- return false;
- }
- @Override
- public boolean isOpaqueCube(IBlockState state) {
- return false;
- }
- @Override
- public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) {
- final IBlockState actualState = state.getActualState(source, pos);
- AxisAlignedBB box = BlockCable.BOUNDING_BOX;
- for (final Map.Entry<EnumFacing, PropertyBool> e : BlockCable.SIDES.entrySet()) {
- if (actualState.getValue(e.getValue())) {
- box = box.union(BlockCable.BOUNDING_BOXES.get(e.getKey()));
- }
- }
- return box;
- }
- @Override
- public void addCollisionBoxToList(IBlockState state, World world, BlockPos pos, AxisAlignedBB entityBox, List<AxisAlignedBB> boxes, @Nullable Entity entityIn, boolean isActualState) {
- final IBlockState actualState = isActualState ? state : state.getActualState(world, pos);
- Block.addCollisionBoxToList(pos, entityBox, boxes, BlockCable.BOUNDING_BOX);
- for (final Map.Entry<EnumFacing, PropertyBool> e : BlockCable.SIDES.entrySet()) {
- if (actualState.getValue(e.getValue())) {
- final AxisAlignedBB box = BlockCable.BOUNDING_BOXES.get(e.getKey());
- Block.addCollisionBoxToList(pos, entityBox, boxes, box);
- }
- }
- }
- @Override
- protected BlockStateContainer createBlockState() {
- final BlockStateContainer.Builder builder = new BlockStateContainer.Builder(this);
- for (final PropertyBool property : BlockCable.SIDES.values()) {
- builder.add(property);
- }
- return builder.build();
- }
- @Override
- public boolean doesSideBlockRendering(final IBlockState state, final IBlockAccess access, final BlockPos pos, final EnumFacing side) {
- return this.canConnectTo(state, access, pos, side);
- }
- private boolean canConnectTo(final IBlockState state, final IBlockAccess access, final BlockPos pos, final EnumFacing side) {
- final BlockPos offset = pos.offset(side);
- final IBlockState other = access.getBlockState(offset);
- final Block block = other.getBlock();
- if(side == EnumFacing.DOWN || side == EnumFacing.UP) {
- return false;
- }
- return this == block || block instanceof Machine;
- }
- @Override
- @Deprecated
- public IBlockState getStateFromMeta(final int meta) {
- return this.getDefaultState();
- }
- @Override
- public int getMetaFromState(IBlockState state) {
- return 0;
- }
- @Override
- @Deprecated
- public IBlockState getActualState(final IBlockState state, final IBlockAccess access, final BlockPos pos) {
- IBlockState actualState = state;
- for (final Map.Entry<EnumFacing, PropertyBool> e : BlockCable.SIDES.entrySet()) {
- actualState = actualState.withProperty(e.getValue(), this.canConnectTo(state, access, pos, e.getKey()));
- }
- return actualState;
- }
- @Override
- public boolean hasTileEntity(IBlockState state) {
- return true;
- }
- @Nullable
- @Override
- public TileEntity createTileEntity(World world, IBlockState state) {
- return new TileCable();
- }
- public void initModel() {
- ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(this), 0, new ModelResourceLocation(getRegistryName(), "inventory"));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement