Search in sources :

Example 1 with IAdvancedSilkyRemovable

use of com.bluepowermod.api.block.IAdvancedSilkyRemovable in project BluePower by Qmunity.

the class BluePowerAPI method loadSilkySettings.

@Override
public void loadSilkySettings(World world, int x, int y, int z, ItemStack stack) {
    TileEntity te = world.getTileEntity(x, y, z);
    Block b = world.getBlock(x, y, z);
    if (te == null)
        throw new IllegalStateException("This block doesn't have a tile entity?!");
    if (stack == null)
        throw new IllegalArgumentException("ItemStack is null!");
    if (stack.hasTagCompound()) {
        NBTTagCompound tag = stack.getTagCompound();
        if (tag.hasKey("tileData")) {
            if (te instanceof IAdvancedSilkyRemovable) {
                ((IAdvancedSilkyRemovable) te).readSilkyData(world, x, y, z, tag.getCompoundTag("tileData"));
            } else if (b instanceof IAdvancedSilkyRemovable) {
                ((IAdvancedSilkyRemovable) b).readSilkyData(world, x, y, z, tag.getCompoundTag("tileData"));
            } else {
                NBTTagCompound tileTag = tag.getCompoundTag("tileData");
                tileTag.setInteger("x", x);
                tileTag.setInteger("y", y);
                tileTag.setInteger("z", z);
                te.readFromNBT(tileTag);
            }
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IAdvancedSilkyRemovable(com.bluepowermod.api.block.IAdvancedSilkyRemovable) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Block(net.minecraft.block.Block)

Example 2 with IAdvancedSilkyRemovable

use of com.bluepowermod.api.block.IAdvancedSilkyRemovable in project BluePower by Qmunity.

the class BluePowerAPI method loadSilkySettings.

@Override
public void loadSilkySettings(IPart part, ItemStack stack) {
    if (stack == null)
        throw new IllegalArgumentException("ItemStack is null!");
    if (stack.hasTagCompound()) {
        NBTTagCompound tag = stack.getTagCompound();
        if (tag.hasKey("tileData")) {
            NBTTagCompound tileTag = tag.getCompoundTag("tileData");
            boolean err = false;
            if (part instanceof IAdvancedSilkyRemovable) {
                try {
                    part.getWorld();
                    part.getX();
                    part.getY();
                    part.getZ();
                } catch (Exception ex) {
                    err = true;
                }
                if (err) {
                    ((IAdvancedSilkyRemovable) part).readSilkyData(null, 0, 0, 0, tileTag);
                } else {
                    ((IAdvancedSilkyRemovable) part).readSilkyData(part.getWorld(), part.getX(), part.getY(), part.getZ(), tileTag);
                }
            } else {
                part.readFromNBT(tileTag);
            }
        }
    }
}
Also used : IAdvancedSilkyRemovable(com.bluepowermod.api.block.IAdvancedSilkyRemovable) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Example 3 with IAdvancedSilkyRemovable

use of com.bluepowermod.api.block.IAdvancedSilkyRemovable in project BluePower by Qmunity.

the class GateBase method renderItem.

@Override
@SideOnly(Side.CLIENT)
public void renderItem(ItemRenderType type, ItemStack item, Object... data) {
    if (this instanceof ISilkyRemovable) {
        if (this instanceof IAdvancedSilkyRemovable) {
            ((IAdvancedSilkyRemovable) this).readSilkyData(null, 0, 0, 0, item.hasTagCompound() ? item.getTagCompound().getCompoundTag("tileData") : new NBTTagCompound());
        } else {
            readFromNBT(item.hasTagCompound() ? item.getTagCompound().getCompoundTag("tileData") : new NBTTagCompound());
        }
    }
    GL11.glPushMatrix();
    {
        RenderHelper rh = RenderHelper.instance;
        rh.reset();
        if (type == ItemRenderType.EQUIPPED_FIRST_PERSON) {
            GL11.glTranslated(-0.25, 0.75, 0.25);
        }
        if (type == ItemRenderType.ENTITY && item.getItemFrame() != null) {
            GL11.glTranslated(19 / 32D, 8 / 16D, 1);
            GL11.glRotated(-90, 0, 0, 1);
            GL11.glRotated(90, 0, 1, 0);
        }
        if (type == ItemRenderType.INVENTORY && BluePower.proxy.isSneakingInGui()) {
            GuiScreen gui = Minecraft.getMinecraft().currentScreen;
            if (gui != null && gui instanceof GuiContainer) {
                GL11.glRotatef(90F, 0.0F, 1.0F, 0.0F);
                GL11.glRotatef(-45F, 0.0F, 1.0F, 0.0F);
                GL11.glRotatef(-210F, 1.0F, 0.0F, 0.0F);
                GL11.glScaled(1.5, 1.5, 1.5);
                GL11.glTranslated(-0.5, 0, 0);
                GL11.glTranslated(0, -0.5, 0);
                GL11.glRotated(-90, 1, 0, 0);
                GL11.glTranslated(0, 0.5, 0);
            }
        }
        Tessellator.instance.startDrawingQuads();
        if (shouldRenderOnPass(0))
            renderStatic(new Vec3i(0, 0, 0), rh, RenderBlocks.getInstance(), 0);
        rh.reset();
        if (shouldRenderOnPass(1))
            renderStatic(new Vec3i(0, 0, 0), rh, RenderBlocks.getInstance(), 1);
        rh.reset();
        Tessellator.instance.draw();
        if (shouldRenderOnPass(0))
            renderDynamic(new Vec3d(0, 0, 0), 0, 0);
        if (shouldRenderOnPass(1))
            renderDynamic(new Vec3d(0, 0, 0), 0, 1);
    }
    GL11.glPopMatrix();
}
Also used : Vec3i(uk.co.qmunity.lib.vec.Vec3i) RenderHelper(uk.co.qmunity.lib.client.render.RenderHelper) IAdvancedSilkyRemovable(com.bluepowermod.api.block.IAdvancedSilkyRemovable) ISilkyRemovable(com.bluepowermod.api.block.ISilkyRemovable) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) GuiScreen(net.minecraft.client.gui.GuiScreen) GuiContainer(net.minecraft.client.gui.inventory.GuiContainer) Vec3d(uk.co.qmunity.lib.vec.Vec3d) SideOnly(cpw.mods.fml.relauncher.SideOnly)

Example 4 with IAdvancedSilkyRemovable

use of com.bluepowermod.api.block.IAdvancedSilkyRemovable in project BluePower by Qmunity.

the class ItemSilkyScrewdriver method onItemUseFirst.

@Override
public boolean onItemUseFirst(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) {
    Block block = world.getBlock(x, y, z);
    TileEntity te = world.getTileEntity(x, y, z);
    ITilePartHolder h = MultipartCompatibility.getPartHolder(world, x, y, z);
    if (h != null) {
        QMovingObjectPosition mop = h.rayTrace(RayTracer.instance().getStartVector(player), RayTracer.instance().getEndVector(player));
        if (mop != null) {
            IPart p = mop.getPart();
            if (p instanceof ISilkyRemovable && !world.isRemote) {
                if (p instanceof IAdvancedSilkyRemovable && !((IAdvancedSilkyRemovable) p).preSilkyRemoval(world, x, y, z))
                    return false;
                NBTTagCompound tag = new NBTTagCompound();
                boolean hideTooltip = false;
                if (p instanceof IAdvancedSilkyRemovable) {
                    hideTooltip = ((IAdvancedSilkyRemovable) p).writeSilkyData(world, x, y, z, tag);
                } else {
                    p.writeToNBT(tag);
                }
                ItemStack droppedStack = p.getItem();
                NBTTagCompound stackTag = droppedStack.getTagCompound();
                if (stackTag == null) {
                    stackTag = new NBTTagCompound();
                    droppedStack.setTagCompound(stackTag);
                }
                stackTag.setTag("tileData", tag);
                stackTag.setBoolean("hideSilkyTooltip", hideTooltip);
                world.spawnEntityInWorld(new EntityItem(world, x + 0.5, y + 0.5, z + 0.5, droppedStack));
                h.removePart(p);
                if (p instanceof IAdvancedSilkyRemovable)
                    ((IAdvancedSilkyRemovable) p).postSilkyRemoval(world, x, y, z);
                stack.damageItem(1, player);
                return true;
            }
        }
        return false;
    }
    if (block instanceof ISilkyRemovable && !world.isRemote) {
        if (block instanceof IAdvancedSilkyRemovable && !((IAdvancedSilkyRemovable) block).preSilkyRemoval(world, x, y, z))
            return false;
        if (te == null)
            throw new IllegalStateException("Block doesn't have a TileEntity?! Implementers of ISilkyRemovable should have one. Offender: " + block.getUnlocalizedName());
        NBTTagCompound tag = new NBTTagCompound();
        te.writeToNBT(tag);
        int metadata = world.getBlockMetadata(x, y, z);
        Item item = block.getItemDropped(metadata, itemRand, 0);
        if (item == null)
            throw new NullPointerException("Block returns null for getItemDropped(meta, rand, fortune)! Offender: " + block.getUnlocalizedName());
        ItemStack droppedStack = new ItemStack(item, 1, block.damageDropped(metadata));
        NBTTagCompound stackTag = droppedStack.getTagCompound();
        if (stackTag == null) {
            stackTag = new NBTTagCompound();
            droppedStack.setTagCompound(stackTag);
        }
        stackTag.setTag("tileData", tag);
        world.spawnEntityInWorld(new EntityItem(world, x + 0.5, y + 0.5, z + 0.5, droppedStack));
        world.setBlockToAir(x, y, z);
        if (block instanceof IAdvancedSilkyRemovable)
            ((IAdvancedSilkyRemovable) block).postSilkyRemoval(world, x, y, z);
        stack.damageItem(1, player);
        return true;
    }
    return false;
}
Also used : IAdvancedSilkyRemovable(com.bluepowermod.api.block.IAdvancedSilkyRemovable) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) QMovingObjectPosition(uk.co.qmunity.lib.raytrace.QMovingObjectPosition) TileEntity(net.minecraft.tileentity.TileEntity) ITilePartHolder(uk.co.qmunity.lib.part.ITilePartHolder) EntityItem(net.minecraft.entity.item.EntityItem) Item(net.minecraft.item.Item) IPart(uk.co.qmunity.lib.part.IPart) ISilkyRemovable(com.bluepowermod.api.block.ISilkyRemovable) Block(net.minecraft.block.Block) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem)

Aggregations

IAdvancedSilkyRemovable (com.bluepowermod.api.block.IAdvancedSilkyRemovable)4 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)4 ISilkyRemovable (com.bluepowermod.api.block.ISilkyRemovable)2 Block (net.minecraft.block.Block)2 TileEntity (net.minecraft.tileentity.TileEntity)2 SideOnly (cpw.mods.fml.relauncher.SideOnly)1 GuiScreen (net.minecraft.client.gui.GuiScreen)1 GuiContainer (net.minecraft.client.gui.inventory.GuiContainer)1 EntityItem (net.minecraft.entity.item.EntityItem)1 Item (net.minecraft.item.Item)1 ItemStack (net.minecraft.item.ItemStack)1 RenderHelper (uk.co.qmunity.lib.client.render.RenderHelper)1 IPart (uk.co.qmunity.lib.part.IPart)1 ITilePartHolder (uk.co.qmunity.lib.part.ITilePartHolder)1 QMovingObjectPosition (uk.co.qmunity.lib.raytrace.QMovingObjectPosition)1 Vec3d (uk.co.qmunity.lib.vec.Vec3d)1 Vec3i (uk.co.qmunity.lib.vec.Vec3i)1