Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.ktposey.simplelogicgates.block;
- import org.apache.logging.log4j.LogManager;
- import org.apache.logging.log4j.Logger;
- import com.ktposey.simplelogicgates.SimpleLogicGates;
- import net.minecraft.block.Block;
- import net.minecraft.block.BlockHorizontal;
- import net.minecraft.block.SoundType;
- import net.minecraft.block.material.Material;
- import net.minecraft.block.properties.IProperty;
- import net.minecraft.block.properties.PropertyDirection;
- import net.minecraft.block.state.BlockStateContainer;
- import net.minecraft.block.state.IBlockState;
- import net.minecraft.creativetab.CreativeTabs;
- import net.minecraft.entity.EntityLivingBase;
- import net.minecraft.util.EnumFacing;
- import net.minecraft.util.math.AxisAlignedBB;
- import net.minecraft.util.math.BlockPos;
- import net.minecraft.world.IBlockAccess;
- import net.minecraft.world.World;
- public class AndGateBlock extends Block{
- public static final PropertyDirection FACING = PropertyDirection.create("facing", EnumFacing.Plane.HORIZONTAL);
- public static final AxisAlignedBB AND_GATE_AABB = new AxisAlignedBB(0, 0, 0, 1, 0.125D, 1);
- public static final Logger LOGGER = LogManager.getLogger(SimpleLogicGates.MOD_ID);
- public AndGateBlock() {
- super(Material.CIRCUITS);
- setCreativeTab(CreativeTabs.MISC);
- setSoundType(SoundType.METAL);
- setCreativeTab(SimpleLogicGates.SLG_TAB);
- }
- @Override
- public boolean isOpaqueCube(IBlockState state) {
- return false;
- }
- @Override
- public boolean isFullCube(IBlockState state) {
- return false;
- }
- @Override
- protected BlockStateContainer createBlockState() {
- return new BlockStateContainer(this, new IProperty[] {BlockHorizontal.FACING});
- }
- @Override
- public IBlockState getStateFromMeta(int meta) {
- return this.getDefaultState().withProperty(BlockHorizontal.FACING, EnumFacing.getHorizontal(meta));
- }
- @Override
- public int getMetaFromState(IBlockState state) {
- return state.getValue(BlockHorizontal.FACING).getHorizontalIndex()&1;
- }
- @Override
- public IBlockState getStateForPlacement(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer) {
- EnumFacing face = placer.getHorizontalFacing();
- return this.getDefaultState().withProperty(BlockHorizontal.FACING, face);
- }
- @Override
- public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos)
- {
- return AND_GATE_AABB;
- }
- @Override
- public boolean canProvidePower(IBlockState state) {
- return true;
- }
- private boolean isOn;
- @Override
- public void onNeighborChange(IBlockAccess world, BlockPos pos, BlockPos neighbor) {
- IBlockState neighborstate = world.getBlockState(neighbor);
- EnumFacing face = neighborstate.getValue(FACING);
- LOGGER.info("Face = " + face);
- if (neighborstate.getWeakPower(world, pos, EnumFacing.WEST) > 0) {
- isOn = true;
- }
- }
- public int getWeakPower(IBlockState state, IBlockAccess blockAccess, BlockPos pos, EnumFacing side) {
- LOGGER.info("isOn = " + isOn);
- if (side == (EnumFacing.NORTH) && isOn == true)
- return 15;
- else
- return 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment