use of net.minecraft.tileentity.TileEntityBanner in project SpongeCommon by SpongePowered.
the class SpongeBannerBuilder method buildContent.
@Override
protected Optional<Banner> buildContent(DataView container) throws InvalidDataException {
return super.buildContent(container).flatMap(banner1 -> {
if (!container.contains(DataQueries.BASE) || !container.contains(DataQueries.PATTERNS)) {
((TileEntity) banner1).invalidate();
return Optional.empty();
}
// TODO when banner data is implemented.
final BannerData bannerData = new SpongeBannerData();
String dyeColorId = container.getString(DataQueries.BASE).get();
Optional<DyeColor> colorOptional = Sponge.getRegistry().getType(DyeColor.class, dyeColorId);
if (!colorOptional.isPresent()) {
throw new InvalidDataException("The provided container has an invalid dye color entry!");
}
bannerData.set(Keys.BANNER_BASE_COLOR, colorOptional.get());
// Now we have to get the patterns list
final List<PatternLayer> patternsList = container.getSerializableList(DataQueries.PATTERNS, PatternLayer.class).get();
final ListValue<PatternLayer> patternLayers = bannerData.patternsList();
patternsList.forEach(patternLayers::add);
bannerData.set(patternLayers);
banner1.offer(bannerData);
((TileEntityBanner) banner1).validate();
return Optional.of(banner1);
});
}
use of net.minecraft.tileentity.TileEntityBanner 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