net.minecraft.block.BlockAnvil Java Examples

The following examples show how to use net.minecraft.block.BlockAnvil. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MixinBlockAnvil.java    From LiquidBounce with GNU General Public License v3.0 5 votes vote down vote up
@Inject(method = "onBlockPlaced", cancellable = true, at = @At("HEAD"))
private void injectAnvilCrashFix(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer, CallbackInfoReturnable<IBlockState> cir) {
    if (((meta >> 2) & ~0x3) != 0) {
        cir.setReturnValue(super.onBlockPlaced(worldIn, pos, facing, hitX, hitY, hitZ, meta, placer).withProperty(BlockAnvil.FACING, placer.getHorizontalFacing().rotateY()).withProperty(BlockAnvil.DAMAGE, 2));
        cir.cancel();
    }
}
 
Example #2
Source File: MixinBlockAnvil.java    From LiquidBounce with GNU General Public License v3.0 5 votes vote down vote up
@Inject(method = "onBlockPlaced", cancellable = true, at = @At("HEAD"))
private void injectAnvilCrashFix(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer, CallbackInfoReturnable<IBlockState> cir) {
    if (((meta >> 2) & ~0x3) != 0) {
        cir.setReturnValue(super.onBlockPlaced(worldIn, pos, facing, hitX, hitY, hitZ, meta, placer).withProperty(BlockAnvil.FACING, placer.getHorizontalFacing().rotateY()).withProperty(BlockAnvil.DAMAGE, 2));
        cir.cancel();
    }
}
 
Example #3
Source File: EntityFallingBlockEU.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void fall(float distance, float damageMultiplier)
{
    Block block = this.blockState.getBlock();

    if (this.hurtEntities)
    {
        int i = MathHelper.ceil(distance - 1.0F);

        if (i > 0)
        {
            boolean isAnvil = block == Blocks.ANVIL;
            List<Entity> list = Lists.newArrayList(this.getEntityWorld().getEntitiesWithinAABBExcludingEntity(this, this.getEntityBoundingBox()));
            DamageSource damageSource = isAnvil ? DamageSource.ANVIL : DamageSource.FALLING_BLOCK;

            for (Entity entity : list)
            {
                entity.attackEntityFrom(damageSource, Math.min(MathHelper.floor(i * this.fallHurtAmount), this.fallHurtMax));
            }

            if (isAnvil && this.rand.nextFloat() < 0.05D + i * 0.05D)
            {
                int j = this.blockState.getValue(BlockAnvil.DAMAGE).intValue() + 1;

                if (j > 2)
                {
                    this.canSetAsBlock = false;
                }
                else
                {
                    this.blockState = this.blockState.withProperty(BlockAnvil.DAMAGE, Integer.valueOf(j));
                }
            }
        }
    }
}
 
Example #4
Source File: CraftHumanEntity.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
public InventoryView openInventory(Inventory inventory) {
    if (!(getHandle() instanceof EntityPlayerMP)) return null;
    EntityPlayerMP player = (EntityPlayerMP) getHandle();
    InventoryType type = inventory.getType();
    Container formerContainer = getHandle().inventoryContainer;

    IInventory iinventory = (inventory instanceof CraftInventory) ? ((CraftInventory) inventory).getInventory() : new org.bukkit.craftbukkit.inventory.InventoryWrapper(inventory);

    switch (type) {
        case PLAYER:
        case CHEST:
        case ENDER_CHEST:
            getHandle().displayGUIChest(iinventory);
            break;
        case DISPENSER:
            if (iinventory instanceof TileEntityDispenser) {
                getHandle().displayGUIChest((TileEntityDispenser) iinventory);
            } else {
                openCustomInventory(inventory, player, "minecraft:dispenser");
            }
            break;
        case DROPPER:
            if (iinventory instanceof TileEntityDropper) {
                getHandle().displayGUIChest((TileEntityDropper) iinventory);
            } else {
                openCustomInventory(inventory, player, "minecraft:dropper");
            }
            break;
        case FURNACE:
            if (iinventory instanceof TileEntityFurnace) {
                getHandle().displayGUIChest((TileEntityFurnace) iinventory);
            } else {
                openCustomInventory(inventory, player, "minecraft:furnace");
            }
            break;
        case WORKBENCH:
            openCustomInventory(inventory, player, "minecraft:crafting_table");
            break;
        case BREWING:
            if (iinventory instanceof TileEntityBrewingStand) {
                getHandle().displayGUIChest((TileEntityBrewingStand) iinventory);
            } else {
                openCustomInventory(inventory, player, "minecraft:brewing_stand");
            }
            break;
        case ENCHANTING:
            openCustomInventory(inventory, player, "minecraft:enchanting_table");
            break;
        case HOPPER:
            if (iinventory instanceof TileEntityHopper) {
                getHandle().displayGUIChest((TileEntityHopper) iinventory);
            } else if (iinventory instanceof EntityMinecartHopper) {
                getHandle().displayGUIChest((EntityMinecartHopper) iinventory);
            } else {
                openCustomInventory(inventory, player, "minecraft:hopper");
            }
            break;
        case BEACON:
            if (iinventory instanceof TileEntityBeacon) {
                getHandle().displayGUIChest((TileEntityBeacon) iinventory);
            } else {
                openCustomInventory(inventory, player, "minecraft:beacon");
            }
            break;
        case ANVIL:
            if (iinventory instanceof BlockAnvil.Anvil) {
                getHandle().displayGui((BlockAnvil.Anvil) iinventory);
            } else {
                openCustomInventory(inventory, player, "minecraft:anvil");
            }
            break;
        case SHULKER_BOX:
            if (iinventory instanceof TileEntityShulkerBox) {
                getHandle().displayGUIChest((TileEntityShulkerBox) iinventory);
            } else {
                openCustomInventory(inventory, player, "minecraft:shulker_box");
            }
            break;
        case CREATIVE:
        case CRAFTING:
            throw new IllegalArgumentException("Can't open a " + type + " inventory!");
    }
    if (getHandle().inventoryContainer == formerContainer) {
        return null;
    }
    getHandle().inventoryContainer.checkReachable = false;
    return getHandle().inventoryContainer.getBukkitView();
}