Search in sources :

Example 1 with TileEntityBanner

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);
    });
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) SpongeBannerData(org.spongepowered.common.data.manipulator.mutable.tileentity.SpongeBannerData) PatternLayer(org.spongepowered.api.data.meta.PatternLayer) InvalidDataException(org.spongepowered.api.data.persistence.InvalidDataException) SpongeBannerData(org.spongepowered.common.data.manipulator.mutable.tileentity.SpongeBannerData) BannerData(org.spongepowered.api.data.manipulator.mutable.tileentity.BannerData) DyeColor(org.spongepowered.api.data.type.DyeColor) TileEntityBanner(net.minecraft.tileentity.TileEntityBanner)

Example 2 with TileEntityBanner

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

TileEntity (net.minecraft.tileentity.TileEntity)2 TileEntityBanner (net.minecraft.tileentity.TileEntityBanner)2 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 BannerData (org.spongepowered.api.data.manipulator.mutable.tileentity.BannerData)1 PatternLayer (org.spongepowered.api.data.meta.PatternLayer)1 InvalidDataException (org.spongepowered.api.data.persistence.InvalidDataException)1 DyeColor (org.spongepowered.api.data.type.DyeColor)1 SpongeBannerData (org.spongepowered.common.data.manipulator.mutable.tileentity.SpongeBannerData)1