Search in sources :

Example 1 with TileEntityShaderBanner

use of blusunrize.immersiveengineering.common.blocks.cloth.TileEntityShaderBanner in project ImmersiveEngineering by BluSunrize.

the class ItemShader method onItemUse.

@Nonnull
@Override
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
    String name = getShaderName(player.getHeldItem(hand));
    if (ShaderRegistry.shaderRegistry.containsKey(name)) {
        IBlockState blockState = world.getBlockState(pos);
        TileEntity tile = world.getTileEntity(pos);
        if (tile instanceof TileEntityBanner) {
            ShaderCase sCase = ShaderRegistry.shaderRegistry.get(name).getCase("immersiveengineering:banner");
            if (sCase != null) {
                boolean wall = blockState.getBlock() == Blocks.WALL_BANNER;
                int orientation = wall ? blockState.getValue(BlockBanner.FACING).getIndex() : blockState.getValue(BlockBanner.ROTATION);
                world.setBlockState(pos, IEContent.blockClothDevice.getStateFromMeta(BlockTypes_ClothDevice.SHADER_BANNER.getMeta()).withProperty(IEProperties.FACING_ALL, EnumFacing.SOUTH));
                tile = world.getTileEntity(pos);
                if (tile instanceof TileEntityShaderBanner) {
                    ((TileEntityShaderBanner) tile).wall = wall;
                    ((TileEntityShaderBanner) tile).orientation = (byte) orientation;
                    ((TileEntityShaderBanner) tile).shader.setShaderItem(Utils.copyStackWithAmount(player.getHeldItem(hand), 1));
                    tile.markDirty();
                    return EnumActionResult.SUCCESS;
                }
            }
        } else if (tile instanceof TileEntityShaderBanner) {
            ItemStack current = ((TileEntityShaderBanner) tile).shader.getShaderItem();
            if (!current.isEmpty() && !world.isRemote && !player.capabilities.isCreativeMode) {
                double dx = pos.getX() + .5 + side.getXOffset();
                double dy = pos.getY() + .5 + side.getYOffset();
                double dz = pos.getZ() + .5 + side.getZOffset();
                EntityItem entityitem = new EntityItem(world, dx, dy, dz, current.copy());
                entityitem.setDefaultPickupDelay();
                world.spawnEntity(entityitem);
            }
            ((TileEntityShaderBanner) tile).shader.setShaderItem(Utils.copyStackWithAmount(player.getHeldItem(hand), 1));
            tile.markDirty();
            return EnumActionResult.SUCCESS;
        }
    }
    return EnumActionResult.FAIL;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IBlockState(net.minecraft.block.state.IBlockState) TileEntityShaderBanner(blusunrize.immersiveengineering.common.blocks.cloth.TileEntityShaderBanner) TileEntityBanner(net.minecraft.tileentity.TileEntityBanner) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem) Nonnull(javax.annotation.Nonnull) ITextureOverride(blusunrize.immersiveengineering.common.items.IEItemInterfaces.ITextureOverride)

Aggregations

TileEntityShaderBanner (blusunrize.immersiveengineering.common.blocks.cloth.TileEntityShaderBanner)1 ITextureOverride (blusunrize.immersiveengineering.common.items.IEItemInterfaces.ITextureOverride)1 Nonnull (javax.annotation.Nonnull)1 IBlockState (net.minecraft.block.state.IBlockState)1 EntityItem (net.minecraft.entity.item.EntityItem)1 ItemStack (net.minecraft.item.ItemStack)1 TileEntity (net.minecraft.tileentity.TileEntity)1 TileEntityBanner (net.minecraft.tileentity.TileEntityBanner)1