Guest User

Untitled

a guest
Dec 18th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.29 KB | None | 0 0
  1. package com.ktposey.simplelogicgates.block;
  2.  
  3. import org.apache.logging.log4j.LogManager;
  4. import org.apache.logging.log4j.Logger;
  5.  
  6. import com.ktposey.simplelogicgates.SimpleLogicGates;
  7.  
  8. import net.minecraft.block.Block;
  9. import net.minecraft.block.BlockHorizontal;
  10. import net.minecraft.block.SoundType;
  11. import net.minecraft.block.material.Material;
  12. import net.minecraft.block.properties.IProperty;
  13. import net.minecraft.block.properties.PropertyDirection;
  14. import net.minecraft.block.state.BlockStateContainer;
  15. import net.minecraft.block.state.IBlockState;
  16. import net.minecraft.creativetab.CreativeTabs;
  17. import net.minecraft.entity.EntityLivingBase;
  18. import net.minecraft.util.EnumFacing;
  19. import net.minecraft.util.math.AxisAlignedBB;
  20. import net.minecraft.util.math.BlockPos;
  21. import net.minecraft.world.IBlockAccess;
  22. import net.minecraft.world.World;
  23.  
  24. public class AndGateBlock extends Block{
  25.  
  26.     public static final PropertyDirection FACING = PropertyDirection.create("facing", EnumFacing.Plane.HORIZONTAL);
  27.     public static final AxisAlignedBB AND_GATE_AABB = new AxisAlignedBB(0, 0, 0, 1, 0.125D, 1);
  28.     public static final Logger LOGGER = LogManager.getLogger(SimpleLogicGates.MOD_ID);
  29.    
  30.     public AndGateBlock() {
  31.        
  32.         super(Material.CIRCUITS);
  33.         setCreativeTab(CreativeTabs.MISC);
  34.         setSoundType(SoundType.METAL);
  35.         setCreativeTab(SimpleLogicGates.SLG_TAB);
  36.      
  37.        
  38.     }
  39.    
  40.  
  41.    
  42.     @Override
  43.     public boolean isOpaqueCube(IBlockState state) {
  44.        
  45.         return false;
  46.        
  47.     }
  48.    
  49.     @Override
  50.     public boolean isFullCube(IBlockState state) {
  51.        
  52.         return false;
  53.        
  54.     }
  55.    
  56.     @Override
  57.     protected BlockStateContainer createBlockState() {
  58.        
  59.         return new BlockStateContainer(this, new IProperty[] {BlockHorizontal.FACING});
  60.        
  61.     }
  62.    
  63.     @Override
  64.     public IBlockState getStateFromMeta(int meta) {
  65.         return this.getDefaultState().withProperty(BlockHorizontal.FACING, EnumFacing.getHorizontal(meta));
  66.     }
  67.  
  68.     @Override
  69.     public int getMetaFromState(IBlockState state) {
  70.         return state.getValue(BlockHorizontal.FACING).getHorizontalIndex()&1;
  71.     }
  72.    
  73.    
  74.    
  75.     @Override
  76.     public IBlockState getStateForPlacement(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer) {
  77.         EnumFacing face = placer.getHorizontalFacing();
  78.         return this.getDefaultState().withProperty(BlockHorizontal.FACING, face);
  79.     }
  80.  
  81.     @Override
  82.     public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos)
  83.     {
  84.         return AND_GATE_AABB;
  85.     }
  86.    
  87.     @Override
  88.     public boolean canProvidePower(IBlockState state) {
  89.         return true;
  90.     }
  91.    
  92.    
  93.    
  94.     private boolean isOn;
  95.    
  96.     @Override
  97.     public void onNeighborChange(IBlockAccess world, BlockPos pos, BlockPos neighbor) {
  98.         IBlockState neighborstate = world.getBlockState(neighbor);
  99.         EnumFacing face = neighborstate.getValue(FACING);
  100.        
  101.         LOGGER.info("Face = " + face);
  102.        
  103.         if (neighborstate.getWeakPower(world, pos, EnumFacing.WEST) > 0) {
  104.             isOn = true;
  105.         }
  106.     }
  107.    
  108. public int getWeakPower(IBlockState state, IBlockAccess blockAccess, BlockPos pos, EnumFacing side) {
  109.        
  110.         LOGGER.info("isOn = " + isOn);
  111.    
  112.         if (side == (EnumFacing.NORTH) && isOn == true)
  113.             return 15;
  114.         else
  115.             return 0;
  116.        
  117.     }
  118.    
  119. }
Advertisement
Add Comment
Please, Sign In to add comment