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;
}
Aggregations