Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package redsword.mub.blocks;
- import redsword.mub.Reference;
- import redsword.mub.handlers.MubSoundHandler;
- import redsword.mub.init.ModBlocks;
- import net.minecraft.block.Block;
- import net.minecraft.block.BlockDoor;
- import net.minecraft.block.material.Material;
- import net.minecraft.block.state.IBlockState;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.item.ItemStack;
- import net.minecraft.util.EnumFacing;
- import net.minecraft.util.EnumHand;
- import net.minecraft.util.ResourceLocation;
- import net.minecraft.util.SoundCategory;
- import net.minecraft.util.math.BlockPos;
- import net.minecraft.world.World;
- public class BlockSandstoneDoor extends BlockDoor {
- public BlockSandstoneDoor(String unlocalizedName) {
- super(Material.ROCK);
- this.setUnlocalizedName(unlocalizedName);
- this.setRegistryName(new ResourceLocation(Reference.MODID, unlocalizedName));
- this.setHardness(3);
- this.setResistance(20);
- }
- @Override
- public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
- if (this.blockMaterial == Material.IRON) {
- return false; //Allow items to interact with the door
- }
- else {
- BlockPos blockpos = state.getValue(HALF) == BlockDoor.EnumDoorHalf.LOWER ? pos : pos.down();
- IBlockState iblockstate = pos.equals(blockpos) ? state : worldIn.getBlockState(blockpos);
- if (iblockstate.getBlock() != this) {
- return false;
- }
- else {
- state = iblockstate.cycleProperty(OPEN);
- worldIn.setBlockState(blockpos, state, 10);
- worldIn.markBlockRangeForRenderUpdate(blockpos, pos);
- worldIn.playSound(playerIn, blockpos, ((Boolean)state.getValue(OPEN)).booleanValue() ? MubSoundHandler.SANDSTONE_DOOR_OPEN : MubSoundHandler.SANDSTONE_DOOR_CLOSE, SoundCategory.BLOCKS, 1.0F, 1.0F);
- return true;
- }
- }
- }
- @Override
- public void toggleDoor(World worldIn, BlockPos pos, boolean open) {
- IBlockState iblockstate = worldIn.getBlockState(pos);
- if (iblockstate.getBlock() == this) {
- BlockPos blockpos = iblockstate.getValue(HALF) == BlockDoor.EnumDoorHalf.LOWER ? pos : pos.down();
- IBlockState iblockstate1 = pos == blockpos ? iblockstate : worldIn.getBlockState(blockpos);
- if (iblockstate1.getBlock() == this && ((Boolean)iblockstate1.getValue(OPEN)).booleanValue() != open) {
- worldIn.setBlockState(blockpos, iblockstate1.withProperty(OPEN, Boolean.valueOf(open)), 10);
- worldIn.markBlockRangeForRenderUpdate(blockpos, pos);
- worldIn.playSound((EntityPlayer)null, blockpos, open ? MubSoundHandler.SANDSTONE_DOOR_OPEN : MubSoundHandler.SANDSTONE_DOOR_CLOSE, SoundCategory.BLOCKS, 1.0F, 1.0F);
- }
- }
- }
- @Override
- public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos) {
- if (state.getValue(HALF) == BlockDoor.EnumDoorHalf.UPPER) {
- BlockPos blockpos = pos.down();
- IBlockState iblockstate = worldIn.getBlockState(blockpos);
- if (iblockstate.getBlock() != this) {
- worldIn.setBlockToAir(pos);
- }
- else if (blockIn != this) {
- iblockstate.neighborChanged(worldIn, blockpos, blockIn, fromPos);
- }
- }
- else {
- boolean flag1 = false;
- BlockPos blockpos1 = pos.up();
- IBlockState iblockstate1 = worldIn.getBlockState(blockpos1);
- if (iblockstate1.getBlock() != this) {
- worldIn.setBlockToAir(pos);
- flag1 = true;
- }
- if (!worldIn.getBlockState(pos.down()).isSideSolid(worldIn, pos.down(), EnumFacing.UP)) {
- worldIn.setBlockToAir(pos);
- flag1 = true;
- if (iblockstate1.getBlock() == this) {
- worldIn.setBlockToAir(blockpos1);
- }
- }
- if (flag1) {
- if (!worldIn.isRemote) {
- this.dropBlockAsItem(worldIn, pos, state, 0);
- }
- }
- else {
- boolean flag = worldIn.isBlockPowered(pos) || worldIn.isBlockPowered(blockpos1);
- if (blockIn != this && (flag || blockIn.getDefaultState().canProvidePower()) && flag != ((Boolean)iblockstate1.getValue(POWERED)).booleanValue()) {
- worldIn.setBlockState(blockpos1, iblockstate1.withProperty(POWERED, Boolean.valueOf(flag)), 2);
- if (flag != ((Boolean)state.getValue(OPEN)).booleanValue()){
- worldIn.setBlockState(pos, state.withProperty(OPEN, Boolean.valueOf(flag)), 2);
- worldIn.markBlockRangeForRenderUpdate(pos, pos);
- worldIn.playSound((EntityPlayer)null, pos, flag ? MubSoundHandler.SANDSTONE_DOOR_OPEN : MubSoundHandler.SANDSTONE_DOOR_CLOSE, SoundCategory.BLOCKS, 1.0F, 1.0F);
- }
- }
- }
- }
- }
- @Override
- public ItemStack getItem(World worldIn, BlockPos pos, IBlockState state) {
- return new ItemStack(ModBlocks.sandstoneDoor);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment