Advertisement
Earthcomputer

BlockRedstoneWire.java

Oct 7th, 2018
314
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 22.83 KB | None | 0 0
  1. package net.minecraft.block;
  2.  
  3. import com.google.common.collect.ImmutableMap;
  4. import com.google.common.collect.Lists;
  5. import com.google.common.collect.Maps;
  6. import com.google.common.collect.Sets;
  7. import java.util.EnumSet;
  8. import java.util.List;
  9. import java.util.Map;
  10. import java.util.Random;
  11. import java.util.Set;
  12. import javax.annotation.Nullable;
  13. import net.minecraft.block.state.BlockFaceShape;
  14. import net.minecraft.block.state.IBlockState;
  15. import net.minecraft.init.Blocks;
  16. import net.minecraft.item.BlockItemUseContext;
  17. import net.minecraft.particles.RedstoneParticleData;
  18. import net.minecraft.state.EnumProperty;
  19. import net.minecraft.state.IntegerProperty;
  20. import net.minecraft.state.StateContainer;
  21. import net.minecraft.state.properties.BlockStateProperties;
  22. import net.minecraft.state.properties.RedstoneSide;
  23. import net.minecraft.util.BlockRenderLayer;
  24. import net.minecraft.util.EnumFacing;
  25. import net.minecraft.util.Mirror;
  26. import net.minecraft.util.Rotation;
  27. import net.minecraft.util.math.BlockPos;
  28. import net.minecraft.util.math.MathHelper;
  29. import net.minecraft.util.math.shapes.VoxelShape;
  30. import net.minecraft.world.IBlockReader;
  31. import net.minecraft.world.IWorld;
  32. import net.minecraft.world.IWorldReaderBase;
  33. import net.minecraft.world.World;
  34. import net.minecraftforge.api.distmarker.Dist;
  35. import net.minecraftforge.api.distmarker.OnlyIn;
  36.  
  37. public class BlockRedstoneWire extends Block
  38. {
  39.     public static final EnumProperty<RedstoneSide> NORTH = BlockStateProperties.REDSTONE_NORTH;
  40.     public static final EnumProperty<RedstoneSide> EAST = BlockStateProperties.REDSTONE_EAST;
  41.     public static final EnumProperty<RedstoneSide> SOUTH = BlockStateProperties.REDSTONE_SOUTH;
  42.     public static final EnumProperty<RedstoneSide> WEST = BlockStateProperties.REDSTONE_WEST;
  43.     public static final IntegerProperty POWER = BlockStateProperties.POWER_0_15;
  44.     public static final Map<EnumFacing, EnumProperty<RedstoneSide>> FACING_PROPERTY_MAP = Maps.newEnumMap(ImmutableMap.of(EnumFacing.NORTH, NORTH, EnumFacing.EAST, EAST, EnumFacing.SOUTH, SOUTH, EnumFacing.WEST, WEST));
  45.     protected static final VoxelShape[] SHAPES = new VoxelShape[] {Block.makeCuboidShape(3.0D, 0.0D, 3.0D, 13.0D, 1.0D, 13.0D), Block.makeCuboidShape(3.0D, 0.0D, 3.0D, 13.0D, 1.0D, 16.0D), Block.makeCuboidShape(0.0D, 0.0D, 3.0D, 13.0D, 1.0D, 13.0D), Block.makeCuboidShape(0.0D, 0.0D, 3.0D, 13.0D, 1.0D, 16.0D), Block.makeCuboidShape(3.0D, 0.0D, 0.0D, 13.0D, 1.0D, 13.0D), Block.makeCuboidShape(3.0D, 0.0D, 0.0D, 13.0D, 1.0D, 16.0D), Block.makeCuboidShape(0.0D, 0.0D, 0.0D, 13.0D, 1.0D, 13.0D), Block.makeCuboidShape(0.0D, 0.0D, 0.0D, 13.0D, 1.0D, 16.0D), Block.makeCuboidShape(3.0D, 0.0D, 3.0D, 16.0D, 1.0D, 13.0D), Block.makeCuboidShape(3.0D, 0.0D, 3.0D, 16.0D, 1.0D, 16.0D), Block.makeCuboidShape(0.0D, 0.0D, 3.0D, 16.0D, 1.0D, 13.0D), Block.makeCuboidShape(0.0D, 0.0D, 3.0D, 16.0D, 1.0D, 16.0D), Block.makeCuboidShape(3.0D, 0.0D, 0.0D, 16.0D, 1.0D, 13.0D), Block.makeCuboidShape(3.0D, 0.0D, 0.0D, 16.0D, 1.0D, 16.0D), Block.makeCuboidShape(0.0D, 0.0D, 0.0D, 16.0D, 1.0D, 13.0D), Block.makeCuboidShape(0.0D, 0.0D, 0.0D, 16.0D, 1.0D, 16.0D)};
  46.     private boolean canProvidePower = true;
  47.     //CM changed to access for fast redstone
  48.     public void setCanProvidePower(boolean v) { canProvidePower = v; }
  49.     private final Set<BlockPos> blocksNeedingUpdate = Sets.<BlockPos>newHashSet();
  50.  
  51.     public BlockRedstoneWire(Block.Properties builder)
  52.     {
  53.         super(builder);
  54.         this.setDefaultState((IBlockState)((IBlockState)((IBlockState)((IBlockState)((IBlockState)(this.stateContainer.getBaseState()).with(NORTH, RedstoneSide.NONE)).with(EAST, RedstoneSide.NONE)).with(SOUTH, RedstoneSide.NONE)).with(WEST, RedstoneSide.NONE)).with(POWER, Integer.valueOf(0)));
  55.     }
  56.  
  57.     public VoxelShape getShape(IBlockState state, IBlockReader worldIn, BlockPos pos)
  58.     {
  59.         return SHAPES[getAABBIndex(state)];
  60.     }
  61.  
  62.     private static int getAABBIndex(IBlockState state)
  63.     {
  64.         int i = 0;
  65.         boolean flag = state.get(NORTH) != RedstoneSide.NONE;
  66.         boolean flag1 = state.get(EAST) != RedstoneSide.NONE;
  67.         boolean flag2 = state.get(SOUTH) != RedstoneSide.NONE;
  68.         boolean flag3 = state.get(WEST) != RedstoneSide.NONE;
  69.  
  70.         if (flag || flag2 && !flag && !flag1 && !flag3)
  71.         {
  72.             i |= 1 << EnumFacing.NORTH.getHorizontalIndex();
  73.         }
  74.  
  75.         if (flag1 || flag3 && !flag && !flag1 && !flag2)
  76.         {
  77.             i |= 1 << EnumFacing.EAST.getHorizontalIndex();
  78.         }
  79.  
  80.         if (flag2 || flag && !flag1 && !flag2 && !flag3)
  81.         {
  82.             i |= 1 << EnumFacing.SOUTH.getHorizontalIndex();
  83.         }
  84.  
  85.         if (flag3 || flag1 && !flag && !flag2 && !flag3)
  86.         {
  87.             i |= 1 << EnumFacing.WEST.getHorizontalIndex();
  88.         }
  89.  
  90.         return i;
  91.     }
  92.  
  93.     public IBlockState getStateForPlacement(BlockItemUseContext context)
  94.     {
  95.         IBlockReader iblockreader = context.getWorld();
  96.         BlockPos blockpos = context.getPos();
  97.         return (IBlockState)((IBlockState)((IBlockState)((IBlockState)this.getDefaultState().with(WEST, this.getSide(iblockreader, blockpos, EnumFacing.WEST))).with(EAST, this.getSide(iblockreader, blockpos, EnumFacing.EAST))).with(NORTH, this.getSide(iblockreader, blockpos, EnumFacing.NORTH))).with(SOUTH, this.getSide(iblockreader, blockpos, EnumFacing.SOUTH));
  98.     }
  99.  
  100.     public IBlockState updatePostPlacement(IBlockState stateIn, EnumFacing facing, IBlockState facingState, IWorld worldIn, BlockPos currentPos, BlockPos facingPos)
  101.     {
  102.         if (facing == EnumFacing.DOWN)
  103.         {
  104.             return stateIn;
  105.         }
  106.         else
  107.         {
  108.             return facing == EnumFacing.UP ? (IBlockState)((IBlockState)((IBlockState)((IBlockState)stateIn.with(WEST, this.getSide(worldIn, currentPos, EnumFacing.WEST))).with(EAST, this.getSide(worldIn, currentPos, EnumFacing.EAST))).with(NORTH, this.getSide(worldIn, currentPos, EnumFacing.NORTH))).with(SOUTH, this.getSide(worldIn, currentPos, EnumFacing.SOUTH)) : (IBlockState)stateIn.with(FACING_PROPERTY_MAP.get(facing), this.getSide(worldIn, currentPos, facing));
  109.         }
  110.     }
  111.  
  112.     public void updateDiagonalNeighbors(IBlockState state, IWorld worldIn, BlockPos pos, int flags)
  113.     {
  114.         try (BlockPos.PooledMutableBlockPos blockpos$pooledmutableblockpos = BlockPos.PooledMutableBlockPos.retain())
  115.         {
  116.             for (EnumFacing enumfacing : EnumFacing.Plane.HORIZONTAL)
  117.             {
  118.                 RedstoneSide redstoneside = (RedstoneSide)state.get(FACING_PROPERTY_MAP.get(enumfacing));
  119.  
  120.                 if (redstoneside != RedstoneSide.NONE && worldIn.getBlockState(blockpos$pooledmutableblockpos.setPos(pos).move(enumfacing)).getBlock() != this)
  121.                 {
  122.                     blockpos$pooledmutableblockpos.move(EnumFacing.DOWN);
  123.                     IBlockState iblockstate = worldIn.getBlockState(blockpos$pooledmutableblockpos);
  124.  
  125.                     if (iblockstate.getBlock() != Blocks.OBSERVER)
  126.                     {
  127.                         BlockPos blockpos = blockpos$pooledmutableblockpos.offset(enumfacing.getOpposite());
  128.                         IBlockState iblockstate1 = iblockstate.updatePostPlacement(enumfacing.getOpposite(), worldIn.getBlockState(blockpos), worldIn, blockpos$pooledmutableblockpos, blockpos);
  129.                         replaceBlock(iblockstate, iblockstate1, worldIn, blockpos$pooledmutableblockpos, flags);
  130.                     }
  131.  
  132.                     blockpos$pooledmutableblockpos.setPos(pos).move(enumfacing).move(EnumFacing.UP);
  133.                     IBlockState iblockstate3 = worldIn.getBlockState(blockpos$pooledmutableblockpos);
  134.  
  135.                     if (iblockstate3.getBlock() != Blocks.OBSERVER)
  136.                     {
  137.                         BlockPos blockpos1 = blockpos$pooledmutableblockpos.offset(enumfacing.getOpposite());
  138.                         IBlockState iblockstate2 = iblockstate3.updatePostPlacement(enumfacing.getOpposite(), worldIn.getBlockState(blockpos1), worldIn, blockpos$pooledmutableblockpos, blockpos1);
  139.                         replaceBlock(iblockstate3, iblockstate2, worldIn, blockpos$pooledmutableblockpos, flags);
  140.                     }
  141.                 }
  142.             }
  143.         }
  144.     }
  145.  
  146.     private RedstoneSide getSide(IBlockReader worldIn, BlockPos pos, EnumFacing face)
  147.     {
  148.         BlockPos blockpos = pos.offset(face);
  149.         IBlockState iblockstate = worldIn.getBlockState(pos.offset(face));
  150.         IBlockState iblockstate1 = worldIn.getBlockState(pos.up());
  151.  
  152.         if (!iblockstate1.isNormalCube())
  153.         {
  154.             boolean flag = worldIn.getBlockState(blockpos).isTopSolid() || worldIn.getBlockState(blockpos).getBlock() == Blocks.GLOWSTONE;
  155.  
  156.             if (flag && canConnectUpwardsTo(worldIn.getBlockState(blockpos.up())))
  157.             {
  158.                 if (iblockstate.isBlockNormalCube())
  159.                 {
  160.                     return RedstoneSide.UP;
  161.                 }
  162.  
  163.                 return RedstoneSide.SIDE;
  164.             }
  165.         }
  166.  
  167.         return !canConnectTo(worldIn.getBlockState(blockpos), face) && (iblockstate.isNormalCube() || !canConnectUpwardsTo(worldIn.getBlockState(blockpos.down()))) ? RedstoneSide.NONE : RedstoneSide.SIDE;
  168.     }
  169.  
  170.     public boolean isFullCube(IBlockState state)
  171.     {
  172.         return false;
  173.     }
  174.  
  175.     public boolean isValidPosition(IBlockState state, IWorldReaderBase worldIn, BlockPos pos)
  176.     {
  177.         IBlockState iblockstate = worldIn.getBlockState(pos.down());
  178.         return iblockstate.isTopSolid() || iblockstate.getBlock() == Blocks.GLOWSTONE;
  179.     }
  180.  
  181.     private IBlockState updateSurroundingRedstone(World worldIn, BlockPos pos, IBlockState state)
  182.     {
  183.         state = this.func_212568_b(worldIn, pos, state);
  184.         List<BlockPos> list = Lists.newArrayList(this.blocksNeedingUpdate);
  185.         this.blocksNeedingUpdate.clear();
  186.  
  187.         for (BlockPos blockpos : list)
  188.         {
  189.             worldIn.notifyNeighborsOfStateChange(blockpos, this);
  190.         }
  191.  
  192.         return state;
  193.     }
  194.  
  195.     //CM changed access for fast redstone wire
  196.     public IBlockState func_212568_b(World p_212568_1_, BlockPos p_212568_2_, IBlockState p_212568_3_)
  197.     {
  198.         IBlockState iblockstate = p_212568_3_;
  199.         int i = p_212568_3_.get(POWER);
  200.         int j = 0;
  201.         j = this.func_212567_a(j, p_212568_3_);
  202.         this.canProvidePower = false;
  203.         int k = p_212568_1_.getRedstonePowerFromNeighbors(p_212568_2_);
  204.         this.canProvidePower = true;
  205.  
  206.         if (k > 0 && k > j - 1)
  207.         {
  208.             j = k;
  209.         }
  210.  
  211.         int l = 0;
  212.  
  213.         for (EnumFacing enumfacing : EnumFacing.Plane.HORIZONTAL)
  214.         {
  215.             BlockPos blockpos = p_212568_2_.offset(enumfacing);
  216.             boolean flag = blockpos.getX() != p_212568_2_.getX() || blockpos.getZ() != p_212568_2_.getZ();
  217.             IBlockState iblockstate1 = p_212568_1_.getBlockState(blockpos);
  218.  
  219.             if (flag)
  220.             {
  221.                 l = this.func_212567_a(l, iblockstate1);
  222.             }
  223.  
  224.             if (iblockstate1.isNormalCube() && !p_212568_1_.getBlockState(p_212568_2_.up()).isNormalCube())
  225.             {
  226.                 if (flag && p_212568_2_.getY() >= p_212568_2_.getY())
  227.                 {
  228.                     l = this.func_212567_a(l, p_212568_1_.getBlockState(blockpos.up()));
  229.                 }
  230.             }
  231.             else if (!iblockstate1.isNormalCube() && flag && p_212568_2_.getY() <= p_212568_2_.getY())
  232.             {
  233.                 l = this.func_212567_a(l, p_212568_1_.getBlockState(blockpos.down()));
  234.             }
  235.         }
  236.  
  237.         if (l > j)
  238.         {
  239.             j = l - 1;
  240.         }
  241.         else if (j > 0)
  242.         {
  243.             --j;
  244.         }
  245.         else
  246.         {
  247.             j = 0;
  248.         }
  249.  
  250.         if (k > j - 1)
  251.         {
  252.             j = k;
  253.         }
  254.  
  255.         if (i != j)
  256.         {
  257.             p_212568_3_ = (IBlockState)p_212568_3_.with(POWER, Integer.valueOf(j));
  258.  
  259.             if (p_212568_1_.getBlockState(p_212568_2_) == iblockstate)
  260.             {
  261.                 p_212568_1_.setBlockState(p_212568_2_, p_212568_3_, 2);
  262.             }
  263.  
  264.             this.blocksNeedingUpdate.add(p_212568_2_);
  265.  
  266.             for (EnumFacing enumfacing1 : EnumFacing.values())
  267.             {
  268.                 this.blocksNeedingUpdate.add(p_212568_2_.offset(enumfacing1));
  269.             }
  270.         }
  271.  
  272.         return p_212568_3_;
  273.     }
  274.  
  275.     private void notifyWireNeighborsOfStateChange(World worldIn, BlockPos pos)
  276.     {
  277.         if (worldIn.getBlockState(pos).getBlock() == this)
  278.         {
  279.             worldIn.notifyNeighborsOfStateChange(pos, this);
  280.  
  281.             for (EnumFacing enumfacing : EnumFacing.values())
  282.             {
  283.                 worldIn.notifyNeighborsOfStateChange(pos.offset(enumfacing), this);
  284.             }
  285.         }
  286.     }
  287.  
  288.     public void onBlockAdded(IBlockState state, World worldIn, BlockPos pos, IBlockState oldState)
  289.     {
  290.         if (oldState.getBlock() != state.getBlock() && !worldIn.isRemote)
  291.         {
  292.             this.updateSurroundingRedstone(worldIn, pos, state);
  293.  
  294.             for (EnumFacing enumfacing : EnumFacing.Plane.VERTICAL)
  295.             {
  296.                 worldIn.notifyNeighborsOfStateChange(pos.offset(enumfacing), this);
  297.             }
  298.  
  299.             for (EnumFacing enumfacing1 : EnumFacing.Plane.HORIZONTAL)
  300.             {
  301.                 this.notifyWireNeighborsOfStateChange(worldIn, pos.offset(enumfacing1));
  302.             }
  303.  
  304.             for (EnumFacing enumfacing2 : EnumFacing.Plane.HORIZONTAL)
  305.             {
  306.                 BlockPos blockpos = pos.offset(enumfacing2);
  307.  
  308.                 if (worldIn.getBlockState(blockpos).isNormalCube())
  309.                 {
  310.                     this.notifyWireNeighborsOfStateChange(worldIn, blockpos.up());
  311.                 }
  312.                 else
  313.                 {
  314.                     this.notifyWireNeighborsOfStateChange(worldIn, blockpos.down());
  315.                 }
  316.             }
  317.         }
  318.     }
  319.  
  320.     public void onReplaced(IBlockState state, World worldIn, BlockPos pos, IBlockState newState, boolean isMoving)
  321.     {
  322.         if (!isMoving && state.getBlock() != newState.getBlock())
  323.         {
  324.             super.onReplaced(state, worldIn, pos, newState, isMoving);
  325.  
  326.             if (!worldIn.isRemote)
  327.             {
  328.                 for (EnumFacing enumfacing : EnumFacing.values())
  329.                 {
  330.                     worldIn.notifyNeighborsOfStateChange(pos.offset(enumfacing), this);
  331.                 }
  332.  
  333.                 this.updateSurroundingRedstone(worldIn, pos, state);
  334.  
  335.                 for (EnumFacing enumfacing1 : EnumFacing.Plane.HORIZONTAL)
  336.                 {
  337.                     this.notifyWireNeighborsOfStateChange(worldIn, pos.offset(enumfacing1));
  338.                 }
  339.  
  340.                 for (EnumFacing enumfacing2 : EnumFacing.Plane.HORIZONTAL)
  341.                 {
  342.                     BlockPos blockpos = pos.offset(enumfacing2);
  343.  
  344.                     if (worldIn.getBlockState(blockpos).isNormalCube())
  345.                     {
  346.                         this.notifyWireNeighborsOfStateChange(worldIn, blockpos.up());
  347.                     }
  348.                     else
  349.                     {
  350.                         this.notifyWireNeighborsOfStateChange(worldIn, blockpos.down());
  351.                     }
  352.                 }
  353.             }
  354.         }
  355.     }
  356.  
  357.     private int func_212567_a(int p_212567_1_, IBlockState p_212567_2_)
  358.     {
  359.         if (p_212567_2_.getBlock() != this)
  360.         {
  361.             return p_212567_1_;
  362.         }
  363.         else
  364.         {
  365.             int i = p_212567_2_.get(POWER);
  366.             return i > p_212567_1_ ? i : p_212567_1_;
  367.         }
  368.     }
  369.  
  370.     public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos)
  371.     {
  372.         if (!worldIn.isRemote)
  373.         {
  374.             if (state.isValidPosition(worldIn, pos))
  375.             {
  376.                 this.updateSurroundingRedstone(worldIn, pos, state);
  377.             }
  378.             else
  379.             {
  380.                 state.dropBlockAsItem(worldIn, pos, 0);
  381.                 worldIn.removeBlock(pos);
  382.             }
  383.         }
  384.     }
  385.  
  386.     public int getStrongPower(IBlockState blockState, IBlockReader blockAccess, BlockPos pos, EnumFacing side)
  387.     {
  388.         return !this.canProvidePower ? 0 : blockState.getWeakPower(blockAccess, pos, side);
  389.     }
  390.  
  391.     public int getWeakPower(IBlockState blockState, IBlockReader blockAccess, BlockPos pos, EnumFacing side)
  392.     {
  393.         if (!this.canProvidePower)
  394.         {
  395.             return 0;
  396.         }
  397.         else
  398.         {
  399.             int i = blockState.get(POWER);
  400.  
  401.             if (i == 0)
  402.             {
  403.                 return 0;
  404.             }
  405.             else if (side == EnumFacing.UP)
  406.             {
  407.                 return i;
  408.             }
  409.             else
  410.             {
  411.                 EnumSet<EnumFacing> enumset = EnumSet.<EnumFacing>noneOf(EnumFacing.class);
  412.  
  413.                 for (EnumFacing enumfacing : EnumFacing.Plane.HORIZONTAL)
  414.                 {
  415.                     if (this.isPowerSourceAt(blockAccess, pos, enumfacing))
  416.                     {
  417.                         enumset.add(enumfacing);
  418.                     }
  419.                 }
  420.  
  421.                 if (side.getAxis().isHorizontal() && enumset.isEmpty())
  422.                 {
  423.                     return i;
  424.                 }
  425.                 else if (enumset.contains(side) && !enumset.contains(side.rotateYCCW()) && !enumset.contains(side.rotateY()))
  426.                 {
  427.                     return i;
  428.                 }
  429.                 else
  430.                 {
  431.                     return 0;
  432.                 }
  433.             }
  434.         }
  435.     }
  436.  
  437.     private boolean isPowerSourceAt(IBlockReader worldIn, BlockPos pos, EnumFacing side)
  438.     {
  439.         BlockPos blockpos = pos.offset(side);
  440.         IBlockState iblockstate = worldIn.getBlockState(blockpos);
  441.         boolean flag = iblockstate.isNormalCube();
  442.         boolean flag1 = worldIn.getBlockState(pos.up()).isNormalCube();
  443.  
  444.         if (!flag1 && flag && canConnectUpwardsTo(worldIn, blockpos.up()))
  445.         {
  446.             return true;
  447.         }
  448.         else if (canConnectTo(iblockstate, side))
  449.         {
  450.             return true;
  451.         }
  452.         else if (iblockstate.getBlock() == Blocks.REPEATER && iblockstate.get(BlockRedstoneDiode.POWERED) && iblockstate.get(BlockRedstoneDiode.HORIZONTAL_FACING) == side)
  453.         {
  454.             return true;
  455.         }
  456.         else
  457.         {
  458.             return !flag && canConnectUpwardsTo(worldIn, blockpos.down());
  459.         }
  460.     }
  461.  
  462.     protected static boolean canConnectUpwardsTo(IBlockReader worldIn, BlockPos pos)
  463.     {
  464.         return canConnectUpwardsTo(worldIn.getBlockState(pos));
  465.     }
  466.  
  467.     protected static boolean canConnectUpwardsTo(IBlockState state)
  468.     {
  469.         return canConnectTo(state, (EnumFacing)null);
  470.     }
  471.  
  472.     protected static boolean canConnectTo(IBlockState blockState, @Nullable EnumFacing side)
  473.     {
  474.         Block block = blockState.getBlock();
  475.  
  476.         if (block == Blocks.REDSTONE_WIRE)
  477.         {
  478.             return true;
  479.         }
  480.         else if (blockState.getBlock() == Blocks.REPEATER)
  481.         {
  482.             EnumFacing enumfacing = (EnumFacing)blockState.get(BlockRedstoneRepeater.HORIZONTAL_FACING);
  483.             return enumfacing == side || enumfacing.getOpposite() == side;
  484.         }
  485.         else if (Blocks.OBSERVER == blockState.getBlock())
  486.         {
  487.             return side == blockState.get(BlockObserver.FACING);
  488.         }
  489.         else
  490.         {
  491.             return blockState.canProvidePower() && side != null;
  492.         }
  493.     }
  494.  
  495.     public boolean canProvidePower(IBlockState state)
  496.     {
  497.         return this.canProvidePower;
  498.     }
  499.  
  500.     @OnlyIn(Dist.CLIENT)
  501.     public static int colorMultiplier(int p_176337_0_)
  502.     {
  503.         float f = (float)p_176337_0_ / 15.0F;
  504.         float f1 = f * 0.6F + 0.4F;
  505.  
  506.         if (p_176337_0_ == 0)
  507.         {
  508.             f1 = 0.3F;
  509.         }
  510.  
  511.         float f2 = f * f * 0.7F - 0.5F;
  512.         float f3 = f * f * 0.6F - 0.7F;
  513.  
  514.         if (f2 < 0.0F)
  515.         {
  516.             f2 = 0.0F;
  517.         }
  518.  
  519.         if (f3 < 0.0F)
  520.         {
  521.             f3 = 0.0F;
  522.         }
  523.  
  524.         int i = MathHelper.clamp((int)(f1 * 255.0F), 0, 255);
  525.         int j = MathHelper.clamp((int)(f2 * 255.0F), 0, 255);
  526.         int k = MathHelper.clamp((int)(f3 * 255.0F), 0, 255);
  527.         return -16777216 | i << 16 | j << 8 | k;
  528.     }
  529.  
  530.     @OnlyIn(Dist.CLIENT)
  531.     public void animateTick(IBlockState stateIn, World worldIn, BlockPos pos, Random rand)
  532.     {
  533.         int i = stateIn.get(POWER);
  534.  
  535.         if (i != 0)
  536.         {
  537.             double d0 = (double)pos.getX() + 0.5D + ((double)rand.nextFloat() - 0.5D) * 0.2D;
  538.             double d1 = (double)((float)pos.getY() + 0.0625F);
  539.             double d2 = (double)pos.getZ() + 0.5D + ((double)rand.nextFloat() - 0.5D) * 0.2D;
  540.             float f = (float)i / 15.0F;
  541.             float f1 = f * 0.6F + 0.4F;
  542.             float f2 = Math.max(0.0F, f * f * 0.7F - 0.5F);
  543.             float f3 = Math.max(0.0F, f * f * 0.6F - 0.7F);
  544.             worldIn.spawnParticle(new RedstoneParticleData(f1, f2, f3, 1.0F), d0, d1, d2, 0.0D, 0.0D, 0.0D);
  545.         }
  546.     }
  547.  
  548.     public BlockRenderLayer getRenderLayer()
  549.     {
  550.         return BlockRenderLayer.CUTOUT;
  551.     }
  552.  
  553.     public IBlockState rotate(IBlockState state, Rotation rot)
  554.     {
  555.         switch (rot)
  556.         {
  557.             case CLOCKWISE_180:
  558.                 return (IBlockState)((IBlockState)((IBlockState)((IBlockState)state.with(NORTH, state.get(SOUTH))).with(EAST, state.get(WEST))).with(SOUTH, state.get(NORTH))).with(WEST, state.get(EAST));
  559.             case COUNTERCLOCKWISE_90:
  560.                 return (IBlockState)((IBlockState)((IBlockState)((IBlockState)state.with(NORTH, state.get(EAST))).with(EAST, state.get(SOUTH))).with(SOUTH, state.get(WEST))).with(WEST, state.get(NORTH));
  561.             case CLOCKWISE_90:
  562.                 return (IBlockState)((IBlockState)((IBlockState)((IBlockState)state.with(NORTH, state.get(WEST))).with(EAST, state.get(NORTH))).with(SOUTH, state.get(EAST))).with(WEST, state.get(SOUTH));
  563.             default:
  564.                 return state;
  565.         }
  566.     }
  567.  
  568.     public IBlockState mirror(IBlockState state, Mirror mirrorIn)
  569.     {
  570.         switch (mirrorIn)
  571.         {
  572.             case LEFT_RIGHT:
  573.                 return (IBlockState)((IBlockState)state.with(NORTH, state.get(SOUTH))).with(SOUTH, state.get(NORTH));
  574.             case FRONT_BACK:
  575.                 return (IBlockState)((IBlockState)state.with(EAST, state.get(WEST))).with(WEST, state.get(EAST));
  576.             default:
  577.                 return super.mirror(state, mirrorIn);
  578.         }
  579.     }
  580.  
  581.     protected void fillStateContainer(StateContainer.Builder<Block, IBlockState> builder)
  582.     {
  583.         builder.add(NORTH, EAST, SOUTH, WEST, POWER);
  584.     }
  585.  
  586.     public BlockFaceShape getBlockFaceShape(IBlockReader worldIn, IBlockState state, BlockPos pos, EnumFacing face)
  587.     {
  588.         return BlockFaceShape.UNDEFINED;
  589.     }
  590. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement