package io.moonman.emergingtechnology.machines.cooker; import java.util.ArrayList; import java.util.List; import javax.annotation.Nullable; import io.moonman.emergingtechnology.EmergingTechnology; import io.moonman.emergingtechnology.config.EmergingTechnologyConfig; import io.moonman.emergingtechnology.gui.enums.ResourceTypeEnum; import io.moonman.emergingtechnology.init.Reference; import io.moonman.emergingtechnology.machines.classes.block.MachineBase; import io.moonman.emergingtechnology.util.KeyBindings; import io.moonman.emergingtechnology.util.Lang; 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.client.util.ITooltipFlag; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumHand; import net.minecraft.util.Mirror; import net.minecraft.util.Rotation; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; import net.minecraft.block.ITileEntityProvider; public class Cooker extends MachineBase implements ITileEntityProvider { protected static final AxisAlignedBB AABB_SLAB_BOTTOM = new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 0.6D, 1.0D); public static final PropertyDirection FACING = PropertyDirection.create("facing"); public Cooker() { super(Material.IRON, "cooker"); this.setSoundType(SoundType.METAL); setDefaultState(blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH)); } @SideOnly(Side.CLIENT) public void addInformation(ItemStack stack, World player, List<String> tooltip, ITooltipFlag advanced) { int loss = EmergingTechnologyConfig.SYNTHETICS_MODULE.COOKER.cookerBaseHeatLoss; int gain = EmergingTechnologyConfig.SYNTHETICS_MODULE.COOKER.cookerBaseHeatGain; int heat = EmergingTechnologyConfig.SYNTHETICS_MODULE.COOKER.cookerRequiredCookingHeat; if (KeyBindings.showExtendedTooltips()) { tooltip.add(Lang.get(Lang.COOKER_DESC)); tooltip.add(Lang.getHeatGainLoss(gain, loss)); tooltip.add(Lang.getRequired(heat, ResourceTypeEnum.HEAT)); } else { tooltip.add(Lang.get(Lang.INTERACT_SHIFT)); } } @Override public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { if (worldIn.isRemote) { return true; } playerIn.openGui(EmergingTechnology.instance, Reference.GUI_COOKER, worldIn, pos.getX(), pos.getY(), pos.getZ()); return true; } @Override public TileEntity createNewTileEntity(World worldIn, int meta) { return new CookerTileEntity(); } @Override protected BlockStateContainer createBlockState() { return new BlockStateContainer(this, new IProperty[] { FACING }); } @Override public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state) { if (!worldIn.isRemote) { IBlockState north = worldIn.getBlockState(pos.north()); IBlockState east = worldIn.getBlockState(pos.east()); IBlockState south = worldIn.getBlockState(pos.south()); IBlockState west = worldIn.getBlockState(pos.west()); EnumFacing face = (EnumFacing) state.getValue(FACING); if (face == EnumFacing.NORTH && north.isFullBlock() && !south.isFullBlock()) { face = EnumFacing.SOUTH; } else if (face == EnumFacing.SOUTH && south.isFullBlock() && !north.isFullBlock()) { face = EnumFacing.NORTH; } else if (face == EnumFacing.EAST && east.isFullBlock() && !west.isFullBlock()) { face = EnumFacing.WEST; } else if (face == EnumFacing.WEST && west.isFullBlock() && !east.isFullBlock()) { face = EnumFacing.EAST; } worldIn.setBlockState(pos, state.withProperty(FACING, face)); } } @Override public IBlockState getStateForPlacement(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer, EnumHand hand) { return this.getDefaultState().withProperty(FACING, placer.getHorizontalFacing().getOpposite()); } @Override public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) { worldIn.setBlockState(pos, this.getDefaultState().withProperty(FACING, placer.getHorizontalFacing().getOpposite())); } @Override public IBlockState withRotation(IBlockState state, Rotation rot) { return state.withProperty(FACING, rot.rotate((EnumFacing) state.getValue(FACING))); } @Override public IBlockState withMirror(IBlockState state, Mirror mirrorIn) { return state.withRotation(mirrorIn.toRotation((EnumFacing) state.getValue(FACING))); } @Override public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos) { // TileEntity tileEntity = worldIn.getTileEntity(pos); // if (tileEntity instanceof CookerTileEntity) { // //CookerTileEntity cookerTileEntity = (CookerTileEntity) tileEntity; // boolean isProcessing = false; // return state.withProperty(PROCESSING, isProcessing); // } return state; } @Override public void addCollisionBoxToList(IBlockState state, World worldIn, BlockPos pos, AxisAlignedBB entityBox, List<AxisAlignedBB> collidingBoxes, @Nullable Entity entityIn, boolean isActualState) { if (!isActualState) { state = this.getActualState(state, worldIn, pos); } for (AxisAlignedBB axisalignedbb : getCollisionBoxList(state)) { addCollisionBoxToList(pos, entityBox, collidingBoxes, axisalignedbb); } } private static List<AxisAlignedBB> getCollisionBoxList(IBlockState state) { List<AxisAlignedBB> list = new ArrayList<AxisAlignedBB>(); list.add(AABB_SLAB_BOTTOM); return list; } @Override public IBlockState getStateFromMeta(int meta) { EnumFacing facing = EnumFacing.getHorizontal(meta); return this.getDefaultState().withProperty(FACING, facing); } @Override public int getMetaFromState(IBlockState state) { return state.getValue(FACING).getIndex(); } }