Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

grand_mind1

Members
  • Posts

    122
  • Joined

  • Last visited

Posts posted by grand_mind1

  1. Hey, thanks for the reply. I tried that, but I must be doing something wrong. The game doesn't seem to recognize the recipe.

    GameRegistry.addShapedRecipe(new ItemStack(ModBlocks.BlockPoweredAnvil), " c ", "iai", 'c', new ItemStack(GameRegistry.findItem("ThermalExpansion", "blockCell")), 'i', new ItemStack(Items.iron_ingot), 'a', new ItemStack(Blocks.anvil));
    

  2. Oh, that's a great idea! I looked into it and got it working! Thanks! If anyone wants to know how I did it, I took this code from EntityThrowable(the class ender pearl extends):

    this.motionX = (double)(-MathHelper.sin(this.rotationYaw / 180.0F * (float)Math.PI) * MathHelper.cos(this.rotationPitch / 180.0F * (float)Math.PI) * f);
    this.motionZ = (double)(MathHelper.cos(this.rotationYaw / 180.0F * (float)Math.PI) * MathHelper.cos(this.rotationPitch / 180.0F * (float)Math.PI) * f);
    this.motionY = (double)(-MathHelper.sin((this.rotationPitch + this.func_70183_g()) / 180.0F * (float)Math.PI) * f);
    

    If I read it correctly, this is how the game sets the motion of any entity that is being thrown. Then, all I had to do was change it up to work with my own code:

    double motionX = (double)(-MathHelper.sin(entityPlayer.rotationYaw / 180.0F * (float)Math.PI) * MathHelper.cos(entityPlayer.rotationPitch / 180.0F * (float)Math.PI) * 1.5F);
    double motionZ = (double)(MathHelper.cos(entityPlayer.rotationYaw / 180.0F * (float)Math.PI) * MathHelper.cos(entityPlayer.rotationPitch / 180.0F * (float)Math.PI) * 1.5F);
    double motionY = (double)(-MathHelper.sin((entityPlayer.rotationPitch + 0F) / 180.0F * (float)Math.PI) * 1.5F);
    
    entityPlayer.addVelocity(motionX, motionY, motionZ);
    

    Using a multiplier of 0.4, like in the original ender pearl code, wasn't quite enough to get the boost I liked, so I chaned it to 1.5. Thanks!

  3. Thanks for your help, but I I've done something wrong. My items are now named "Unnamed" with the following code in my ItemBlock class:

    @Override
        public String getItemStackDisplayName(ItemStack itemStack)
        {
            return itemStack.getDisplayName().replace("@", StatCollector.translateToLocal("pandm.color" + itemStack.getItemDamage()));
        }
    

    This is my lang file:

     

     

    tile.pandm:BlockModWool.name=Special @ Wool
    
    pandm.color.0=Black
    pandm.color.1=Blue
    pandm.color.2=Brown
    pandm.color.3=Cyan
    pandm.color.4=Grey
    pandm.color.5=Green
    pandm.color.6=Light Blue
    pandm.color.7=Lime
    pandm.color.8=Magenta
    pandm.color.9=Orange
    pandm.color.10=Pink
    pandm.color.11=Purple
    pandm.color.12=Red
    pandm.color.13=Silver
    pandm.color.14=White
    pandm.color.15=Yellow
    

     

     

  4. Hi, I'm trying to add some extra wool into the game. I want to set the ItemBlock and Block's name based on what color it is (e.g. Black Wool instead of just Wool). The only way I can think of doing this is to have different unlocalized names for each color, but this seems quite inefficient. Is there a better way I can do this?

    Thanks!

  5. Um no, I have both. The TileEntitySpecialRenderer is used to render the block in the world and ItemRender is used to render it in an inventory, right? I've included that second class in my previous reply if you need to look at it.

     

    EDIT: What do you mean by overriding the whole render code in IItemRenderer?

  6. Thanks for your reply! I tried this, but I think I either implemented it incorrectly or I need extra code for it to work with my ItemRenderer for the block. My game crashes with the following report:

    http://pastebin.com/b1V6yaU8

    This is that class:

     

    package com.darichey.PandM.item.itemRenderer;
    
    import net.minecraft.client.renderer.ItemRenderer;
    import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
    import net.minecraft.item.ItemStack;
    import net.minecraft.tileentity.TileEntity;
    import net.minecraftforge.client.IItemRenderer;
    import net.minecraftforge.common.util.ForgeDirection;
    import org.lwjgl.opengl.GL11;
    
    public class ItemRendererPoweredAnvil implements IItemRenderer
    {
        private TileEntity tileEntity;
        private TileEntitySpecialRenderer renderer;
    
        public ItemRendererPoweredAnvil(TileEntitySpecialRenderer renderer, TileEntity tileEntity)
        {
            this.tileEntity = tileEntity;
            this.renderer = renderer;
        }
    
        @Override
        public boolean handleRenderType(ItemStack item, ItemRenderType type)
        {
            return true;
        }
    
        @Override
        public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item, ItemRendererHelper helper)
        {
            return true;
        }
    
        @Override
        public void renderItem(ItemRenderType type, ItemStack item, Object... data)
        {
            if (type == IItemRenderer.ItemRenderType.ENTITY)
            {
                GL11.glTranslatef(-0.5F, 0.0F, -0.5F);
            }
            this.tileEntity.blockMetadata = 0;
            this.renderer.renderTileEntityAt(this.tileEntity, 0.0D, 0.0D, 0.0D, 0.0F);
        }
    }
    
    

     

     

     

    package com.darichey.PandM.tileEntity.specialRenderer;
    
    import com.darichey.PandM.model.ModelPoweredAnvil;
    import com.darichey.PandM.reference.ResourceLocations;
    import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
    import net.minecraft.tileentity.TileEntity;
    import net.minecraft.world.World;
    import net.minecraftforge.common.util.ForgeDirection;
    import org.lwjgl.opengl.GL11;
    
    public class RenderPoweredAnvil extends TileEntitySpecialRenderer
    {
        private ModelPoweredAnvil modelPoweredAnvil;
    
        public RenderPoweredAnvil()
        {
            this.modelPoweredAnvil = new ModelPoweredAnvil();
        }
    
        private void RotateModelBasedOnMeta(World world, int x, int y, int z)
        {
            int meta = world.getBlockMetadata(x, y, z);
    
            if (meta == 0)
            {
                GL11.glRotatef(-180F, 0.0F, 1.0F, 0.0F);
            }
    
            if (meta % 2 != 0)
            {
                GL11.glRotatef(meta * (-90F), 0.0F, 1.0F, 0.0F);
            }
    
            if (meta % 2 == 0)
            {
                GL11.glRotatef(meta * (-180F), 0.0F, 1.0F, 0.0F);
            }
        }
    
        @Override
        public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float f)
        {
            GL11.glPushMatrix();
            GL11.glTranslatef((float) x + 0.5F, (float) y - 0.5F, (float) z + 0.5F);
            RotateModelBasedOnMeta(tileEntity.getWorldObj(), tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord);
            this.bindTexture(ResourceLocations.PoweredAnvilModelTexture);
            GL11.glPushMatrix();
            this.modelPoweredAnvil.renderModel(0.0625F);
            GL11.glPopMatrix();
            GL11.glPopMatrix();
        }
    }
    
    

     

  7. Hi, I'm trying to make my block with a TileEntitySpecialRenderer face the player when he places it. I've looked into the furnace and anvil code to try to replicate it. At the moment, I'm not sure if it's the actual block not facing the correct direction or the model. I think it is probably the model, because the bounding box seems to change the correct orientation even when the model does not.

     

    My Block Class:

     

    public class BlockPoweredAnvil extends BlockContainer implements ITileEntityProvider
    {
        private Random rand = new Random();
    
        public IIcon[] icons = new IIcon[2];
    
        public BlockPoweredAnvil()
        {
            super(Material.rock);
            this.setCreativeTab(CreativeTabPandM.PANDM_TAB);
            this.setBlockName(Names.POWERED_ANVIL);
            this.setBlockTextureName(this.getUnwrappedUnlocalizedName(this.getUnlocalizedName()));
        }
    
        @Override
        public boolean renderAsNormalBlock()
        {
            return false;
        }
    
        @Override
        public boolean isOpaqueCube()
        {
            return false;
        }
    
        @Override
        public int getRenderType()
        {
            return -1;
        }
    
        @Override
        public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entityLivingBase, ItemStack itemStack)
        {
            LogHelper.info("Block Placed");
            int l = MathHelper.floor_double((double)(entityLivingBase.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
            int i1 = world.getBlockMetadata(x, y, z) >> 2;
            ++l;
            l %= 4;
    
            if (l == 0)
            {
                LogHelper.info("0");
                world.setBlockMetadataWithNotify(x, y, z, 2 | i1 << 2, 2);
            }
    
            if (l == 1)
            {
                LogHelper.info("1");
                world.setBlockMetadataWithNotify(x, y, z, 3 | i1 << 2, 2);
            }
    
            if (l == 2)
            {
                LogHelper.info("2");
                world.setBlockMetadataWithNotify(x, y, z, 0 | i1 << 2, 2);
            }
    
            if (l == 3)
            {
                LogHelper.info("3");
                world.setBlockMetadataWithNotify(x, y, z, 1 | i1 << 2, 2);
            }
        }
    
        public void setBlockBoundsBasedOnState(IBlockAccess iBlockAccess, int x, int y, int z)
        {
            int l = iBlockAccess.getBlockMetadata(x, y, z) & 3;
    
            if (l != 3 && l != 1)
            {
                this.setBlockBounds(0.125F, 0.0F, 0.0F, 0.875F, 1.0F, 1.0F);
            }
            else
            {
                this.setBlockBounds(0.0F, 0.0F, 0.125F, 1.0F, 1.0F, 0.875F);
            }
        }
    
        @Override
        public void registerBlockIcons(IIconRegister iconRegister)
        {
            for (int i = 0; i < 2; i ++)
            {
                this.icons[i] = iconRegister.registerIcon(this.textureName + i);
            }
        }
    
        @Override
        public IIcon getIcon(int side, int meta)
        {
            if (side == 1)
            {
                return icons[0];
            }
            return icons[1];
        }
    
        @Override
        public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int meta, float hitX, float hitY, float hitZ)
        {
            if (!world.isRemote && world.getTileEntity(x, y, z) instanceof TileEntityPoweredAnvil)
            {
                entityPlayer.openGui(PandM.instance, GUIs.POWERED_ANVIL.ordinal(), world, x, y, z);
            }
            return true;
        }
    
        @Override
        public void breakBlock(World world, int x, int y, int z, Block block, int meta)
        {
            TileEntityPoweredAnvil poweredAnvil = (TileEntityPoweredAnvil) world.getTileEntity(x, y, z);
            if (poweredAnvil != null)
            {
                for (int i = 0; i < poweredAnvil.getSizeInventory(); i++)
                {
                    ItemStack itemStack = poweredAnvil.getStackInSlot(i);
                    if (itemStack != null)
                    {
                        float f = this.rand.nextFloat() * 0.8F + 0.1F;
                        float f1 = this.rand.nextFloat() * 0.8F + 0.1F;
                        float f2 = this.rand.nextFloat() * 0.8F + 0.1F;
    
                        while (itemStack.stackSize > 0)
                        {
                            int j = this.rand.nextInt(21) + 10;
    
                            if (j > itemStack.stackSize)
                            {
                                j = itemStack.stackSize;
                            }
                            itemStack.stackSize -= j;
                            EntityItem entityitem = new EntityItem(world, (double) ((float) x + f), (double) ((float) y + f1), (double) ((float) z + f2), new ItemStack(itemStack.getItem(), j, itemStack.getItemDamage()));
    
                            if (itemStack.hasTagCompound())
                            {
                                entityitem.getEntityItem().setTagCompound((NBTTagCompound) itemStack.getTagCompound().copy());
                            }
    
                            float f3 = 0.05F;
                            entityitem.motionX = (double) ((float) this.rand.nextGaussian() * f3);
                            entityitem.motionY = (double) ((float) this.rand.nextGaussian() * f3 + 0.2F);
                            entityitem.motionZ = (double) ((float) this.rand.nextGaussian() * f3);
                            world.spawnEntityInWorld(entityitem);
                        }
                    }
                }
                world.func_147453_f(x, y, z, block);
            }
            super.breakBlock(world, x, y, z, block, meta);
        }
    
        @Override
        public TileEntity createNewTileEntity(World world, int meta)
        {
            return new TileEntityPoweredAnvil();
        }
    
        @Override
        public String getUnlocalizedName()
        {
            return String.format("tile.%s%s", Reference.MOD_ID.toLowerCase() + ":", getUnwrappedUnlocalizedName(super.getUnlocalizedName()));
        }
    
        protected String getUnwrappedUnlocalizedName(String unlocalizedName)
        {
            return unlocalizedName.substring(unlocalizedName.indexOf(".") + 1);
        }
    }
    

     

     

    Some screenshots to hopefully better explain what I'm talking about:

    http://puu.sh/eI4Zr/e42a09109e.jpg

    http://puu.sh/eI52X/7306221137.jpg

    The models on both are facing the same direction, however the bounding box is different depending on which direction I was facing when I placed it.

    If you need to see any other classes, I can provide the code for them.

    Any help is appreciated!

    Thanks!

  8. Thanks so much! I'm a bit confused on how to get the old fluidstack and copy it. I tried this:

     

    private FluidStack oldWater = coffeeMaker.getWaterTank().getFluid().copy();

    but it crashed with this error:

    Ticking memory connection
    
    java.lang.NullPointerException: Ticking memory connection
    at com.darichey.ACOJ.tileentity.containers.ContainerCofffeeMaker.<init>(ContainerCofffeeMaker.java:105)
    at com.darichey.ACOJ.handler.GuiHandler.getServerGuiElement(GuiHandler.java:18)
    at cpw.mods.fml.common.network.NetworkRegistry.getRemoteGuiContainer(NetworkRegistry.java:241)
    at cpw.mods.fml.common.network.internal.FMLNetworkHandler.openGui(FMLNetworkHandler.java:75)
    at net.minecraft.entity.player.EntityPlayer.openGui(EntityPlayer.java:2501)
    at com.darichey.ACOJ.block.BlockCoffeeMaker.onBlockActivated(BlockCoffeeMaker.java:45)
    at net.minecraft.server.management.ItemInWorldManager.activateBlockOrUseItem(ItemInWorldManager.java:409)
    at net.minecraft.network.NetHandlerPlayServer.processPlayerBlockPlacement(NetHandlerPlayServer.java:593)
    at net.minecraft.network.play.client.C08PacketPlayerBlockPlacement.processPacket(C08PacketPlayerBlockPlacement.java:74)
    at net.minecraft.network.play.client.C08PacketPlayerBlockPlacement.processPacket(C08PacketPlayerBlockPlacement.java:122)
    at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:241)
    at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:182)
    at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:726)
    at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:614)
    at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118)
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:485)
    at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:752)
    

     

    I'm sure I just misunderstood something.

  9. Ah ok, sorry. Man do I feel dumb, saw the mistake in my writeToNBT method right away :/

    Thanks for the help with that. So now back to the original question...

     

    In order to sync my fluid amounts, I should override detectAndSendChanges() and addCraftingToCrafters() in my Container class. Would you mind explaining how to use these a bit more? I didn't really understand what you meant with the lastTick field. I've also not done anything with packets whatsoever. Do you know of a good tutorial I could read to gain an understanding of how to use them? Thanks!

  10. But I want my $200! D: I thought I could get around that problem by returning a new instance of the tile entity in createNewTileEntity(). Suppose not.

    So now I have two questions:

     

    1) So without the instance, how can I get the current instance of the tile entity for getDrops()?

    2) Removing the instance, did not allow for the tile entity to sync properly. The items still do not appear to save in the container. Is there something else I must do?

  11. Again, I'm going off the of the GUI so I assumed it was a problem with syncing again. If I understand you correctly, I open it just by right-clicking. This is the block class where I do that:

     

    public class BlockCoffeeMaker extends BlockContainer implements ITileEntityProvider
    {
        TileEntityCoffeeMaker instance;
    
        public BlockCoffeeMaker()
        {
            super(Material.rock);
            this.setCreativeTab(CreativeTabACOJ.ACOJ_TAB);
            this.setBlockName(Names.COFFEE_MAKER);
        }
    
        @Override
        public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int meta, float hitX, float hitY, float hitZ)
        {
            if (!world.isRemote && world.getTileEntity(x, y, z) instanceof TileEntityCoffeeMaker)
            {
                entityPlayer.openGui(ACOJ.instance, GUIs.COFFEE_MAKER.ordinal(), world, x, y, z);
            }
            return true;
        }
    
        @Override
        public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int metadata, int fortune)
        {
            ArrayList<ItemStack> itemStacks = Lists.newArrayList();
            ItemStack itemStack = new ItemStack(ModBlocks.BlockCoffeeMaker, 1, metadata);
            itemStacks.add(itemStack);
            TileEntityCoffeeMaker coffeeMaker = getInstance();
            if (coffeeMaker.getStackInSlot(0) != null) itemStacks.add(coffeeMaker.getStackInSlot(0));
            if (coffeeMaker.getStackInSlot(1) != null) itemStacks.add(coffeeMaker.getStackInSlot(1));
            if (coffeeMaker.getStackInSlot(2) != null) itemStacks.add(coffeeMaker.getStackInSlot(2));
            if (coffeeMaker.getStackInSlot(3) != null) itemStacks.add(coffeeMaker.getStackInSlot(3));
            return itemStacks;
        }
    
        @Override
        public TileEntity createNewTileEntity(World world, int meta)
        {
            instance = new TileEntityCoffeeMaker();
            return instance;
        }
    
        @Override
        public boolean hasTileEntity()
        {
            return true;
        }
        public TileEntityCoffeeMaker getInstance()
        {
            return instance;
        }
    
        @Override
        public String getUnlocalizedName()
        {
            return String.format("tile.%s%s", Reference.MOD_ID.toLowerCase() + ":", getUnwrappedUnlocalizedName(super.getUnlocalizedName()));
        }
    
        protected String getUnwrappedUnlocalizedName(String unlocalizedName)
        {
            return unlocalizedName.substring(unlocalizedName.indexOf(".") + 1);
        }
    }
    

     

    It has pahimar's name code that I know you love :P Haven't gotten around to fixing that yet.

  12. Yeah, that's what I thought. Would you mind taking a look at my container class?

     

     

    public class ContainerCofffeeMaker extends Container

    {

        private EntityPlayer entityPlayer;

        private IInventory inv;

     

        private final int bucketSlotX = 10;

        private final int bucketSlotY = 59;

     

        private final int coffeeSlotX = 80;

        private final int coffeeSlotY = 12;

     

        private final int filterSlotX = 80;

        private final int filterSlotY = 52;

     

        private final int mugSlotX = 151;

        private final int mugSlotY = 59;

     

        public ContainerCofffeeMaker(EntityPlayer entityPlayer, IInventory inv, int xSize, int ySize)

        {

            this.entityPlayer = entityPlayer;

            this.inv = inv;

            inv.openInventory();

            layout(xSize, ySize);

        }

     

        protected void layout(int xSize, int ySize)

        {

            addSlotToContainer(new Slot(inv, 0, bucketSlotX, bucketSlotY));

            addSlotToContainer(new Slot(inv, 1, coffeeSlotX, coffeeSlotY));

            addSlotToContainer(new Slot(inv, 2, filterSlotX, filterSlotY));

            addSlotToContainer(new Slot(inv, 3, mugSlotX, mugSlotY));

     

            int leftCol = (xSize - 162) / 2 + 1;

            for (int playerInvRow = 0; playerInvRow < 3; playerInvRow++)

            {

                for (int playerInvCol = 0; playerInvCol < 9; playerInvCol++)

                {

                    addSlotToContainer(new Slot(entityPlayer.inventory, playerInvCol + playerInvRow * 9 + 9, leftCol + playerInvCol * 18, ySize - (4 - playerInvRow) * 18 - 11));

                }

            }

            for (int hotbarSlot = 0; hotbarSlot < 9; hotbarSlot++)

            {

                addSlotToContainer(new Slot(entityPlayer.inventory, hotbarSlot, leftCol + hotbarSlot * 18, ySize - 25));

            }

        }

     

        @Override

        public ItemStack transferStackInSlot(EntityPlayer entityPlayer, int slot)

        {

            ItemStack var2 = null;

            Slot var3 = (Slot) this.inventorySlots.get(slot);

     

            if (var3 != null && var3.getHasStack())

            {

                ItemStack var4 = var3.getStack();

                var2 = var4.copy();

     

                if (slot < 4)

                {

                    if (!this.mergeItemStack(var4, 1, this.inventorySlots.size(), true))

                    {

                        return null;

                    }

                } else if (!this.mergeItemStack(var4, 0, 1, false)) return null;

     

                if (var4.stackSize == 0) var3.putStack((ItemStack) null);

                else var3.onSlotChanged();

            }

     

            return var2;

        }

     

        @Override

        public boolean canInteractWith(EntityPlayer entityPlayer)

        {

            return inv.isUseableByPlayer(entityPlayer);

        }

    }

     

     

  13. Hey, thanks for the solution. After doing a bit of research on your suggestion, I found that I could properly sync my tank data by using getDescriptionPacket() and onDataPacket(). However, I believe I still need your solution for the actual container. I have a couple questions, if you don't mind. While looking at the code for detectAndSendChanges() and addCraftingToCrafters(), I saw that the default methods in the Container class already should do what I want them to. That is, of course, if I understand the methods fully. Is there a reason why these don't seem to be working?

×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.