
TrekkieCub314
Members-
Posts
68 -
Joined
-
Last visited
Everything posted by TrekkieCub314
-
[1.10.02] Entity constructor not working correctly
TrekkieCub314 replied to TrekkieCub314's topic in Modder Support
At the moment, in the renderer. The renderer is working perfectly, as it switches over if I change the orientation value manually in the entity class. -
[1.10.02] Entity constructor not working correctly
TrekkieCub314 replied to TrekkieCub314's topic in Modder Support
I'm sure. I've updated my post to include the onUpdate() portion of the tile entity that spawns said entity. -
I have a custom entity class that has a constructor that doesn't seem to be working. The entity is designed to die when it hits certain kinds of blocks, and it's correctly done so. The problem was, the block it was sent from can be the same kind as it can die on, so I wanted to store the source block's blockPos in the entity class so I can make sure it doesn't die on the source block. I also have an orientation variable that changes the color of the entity depending on its value. The problem is I tried to set these in a constructor, but said constructor doesn't seem to be setting these values. I found a work-around for the position part, but the orientation part I can't seem to fix. Can anyone see what might be going wrong? [spoiler=entity class] package com.trekkiecub.oddsandends.entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.projectile.EntityThrowable; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; import com.trekkiecub.oddsandends.blocks.Block_Sceptre_Top; import com.trekkiecub.oddsandends.util.OAE_Func; public class Entity_PowerOrb extends EntityThrowable { private int initX = -1; private int initY = -1; private int initZ = -1; private int lifeTimer = 0; private int orientation = 0; private int timerMax = 300; private int texFrames = 3; public Entity_PowerOrb(World worldIn) { super(worldIn); this.setSize(0.25F, 0.25F); } public Entity_PowerOrb(World worldIn, double d, double e, double f, int orientation) { super(worldIn, d, e, f); this.initX = MathHelper.floor_double(d); this.initY = MathHelper.floor_double(e); this.initZ = MathHelper.floor_double(f); this.setSize(0.25F, 0.25F); this.orientation = orientation; } public void setOrientation(int o) { this.orientation = o; } public int getOrientation() {return orientation;} public Entity_PowerOrb(World worldIn, EntityLivingBase throwerIn) { super(worldIn, throwerIn); } @Override protected void entityInit() { // TODO Auto-generated method stub } public void readEntityFromNBT(NBTTagCompound compound) { super.readEntityFromNBT(compound); this.orientation = compound.getInteger("orientation"); this.lifeTimer = compound.getInteger("lifeTimer"); this.initX = compound.getInteger("initX"); this.initY = compound.getInteger("initY"); this.initZ = compound.getInteger("initZ"); } public void writeEntityToNBT(NBTTagCompound compound) { super.writeEntityToNBT(compound); compound.setInteger("orientation", this.orientation); compound.setInteger("lifeTimer", this.lifeTimer); compound.setInteger("posX", this.initX); compound.setInteger("posY", this.initY); compound.setInteger("posZ", this.initZ); } public void onUpdate() { // Kill entity if too old lifeTimer++; if (lifeTimer > timerMax) { this.kill(); } this.lastTickPosX = this.posX; this.lastTickPosY = this.posY; this.lastTickPosZ = this.posZ; // Ray Tracing Vec3d vec3d = new Vec3d(this.posX, this.posY, this.posZ); Vec3d vec3d1 = new Vec3d(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ); RayTraceResult raytraceresult = this.worldObj.rayTraceBlocks(vec3d, vec3d1); vec3d = new Vec3d(this.posX, this.posY, this.posZ); vec3d1 = new Vec3d(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ); if (raytraceresult != null) { vec3d1 = new Vec3d(raytraceresult.hitVec.xCoord, raytraceresult.hitVec.yCoord, raytraceresult.hitVec.zCoord); } if (raytraceresult != null) { this.onImpact(raytraceresult); } // Update Initial Position if (this.initY < 0) { this.initX = MathHelper.floor_double(this.posX); this.initY = MathHelper.floor_double(this.posY); this.initZ = MathHelper.floor_double(this.posZ); } BlockPos source = new BlockPos(this.initX, this.initY, this.initZ); if (!source.equals(this.getPosition())) { if (this.worldObj.getBlockState(this.getPosition()).getBlock() instanceof Block_Sceptre_Top) { Vec3d currentCenter = OAE_Func.blockCenter(this.getPosition()); if (vec3d.distanceTo(currentCenter) < 0.25D) { this.kill(); } } } this.posX += this.motionX; this.posY += this.motionY; this.posZ += this.motionZ; this.setPosition(this.posX, this.posY, this.posZ); } @Override public boolean func_189652_ae() { return true; } @SideOnly(Side.CLIENT) public boolean isInRangeToRenderDist(double distance) { double d0 = this.getEntityBoundingBox().getAverageEdgeLength() * 4.0D; if (Double.isNaN(d0)) { d0 = 4.0D; } d0 = d0 * 64.0D; return distance < d0 * d0; } public int getTexByLifetime() { if (lifeTimer%(2*texFrames) < texFrames) { return lifeTimer%texFrames; } else { return texFrames - 1 - (lifeTimer%texFrames); } } protected void onImpact(RayTraceResult result) { if (result.typeOfHit == RayTraceResult.Type.BLOCK && !(this.worldObj.getBlockState(result.getBlockPos()).getBlock() instanceof Block_Sceptre_Top)) { this.orientation = 1 - this.orientation; } else if (result.typeOfHit == RayTraceResult.Type.ENTITY && result.entityHit instanceof Entity_PowerOrb) { this.kill(); } } } [spoiler=tile entity onUpdate] public void updateEntity() { if (!this.worldObj.isRemote) { cooldown++; cooldown = cooldown%maxCooldown; if (cooldown == 0 && destinations.size() != 0) { BlockPos targetPos; for (int i = 0; i < destinations.size(); i++) { targetPos = destinations.get(i).getBlockPos(); Entity_PowerOrb entity = new Entity_PowerOrb(this.worldObj, this.pos.getX()+.5, this.pos.getY()+.375, this.pos.getZ()+.5, this.worldObj.rand.nextInt(2)); entity.setThrowableHeading(targetPos.getX() + .5 - entity.posX, targetPos.getY() + .375 - entity.posY, targetPos.getZ() + .5 - entity.posZ, 0.05F, 0); this.worldObj.spawnEntityInWorld(entity); } } markDirty(); } } [spoiler=Renderer] package com.trekkiecub.oddsandends.render; import com.trekkiecub.oddsandends.entity.Entity_PowerOrb; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.OpenGlHelper; import net.minecraft.client.renderer.RenderHelper; import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.VertexBuffer; import net.minecraft.client.renderer.entity.Render; import net.minecraft.client.renderer.entity.RenderManager; import net.minecraft.client.renderer.vertex.DefaultVertexFormats; import net.minecraft.entity.item.EntityXPOrb; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.MathHelper; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; @SideOnly(Side.CLIENT) public class RenderPowerOrb extends Render<Entity_PowerOrb>{ private static final ResourceLocation EXPERIENCE_ORB_TEXTURES = new ResourceLocation("textures/entity/experience_orb.png"); public RenderPowerOrb(RenderManager renderManager) { super(renderManager); this.shadowSize = 0.15F; this.shadowOpaque = 0.75F; } /** * Renders the desired {@code T} type Entity. */ @Override public void doRender(Entity_PowerOrb entity, double x, double y, double z, float entityYaw, float partialTicks) { if (!this.renderOutlines) { GlStateManager.pushMatrix(); GlStateManager.translate((float)x, (float)y, (float)z); this.bindEntityTexture(entity); RenderHelper.enableStandardItemLighting(); int i = entity.getTexByLifetime(); float f = (float)(i % 4 * 16 + 0) / 64.0F; float f1 = (float)(i % 4 * 16 + 16) / 64.0F; float f2 = (float)(i / 4 * 16 + 0) / 64.0F; float f3 = (float)(i / 4 * 16 + 16) / 64.0F; float f4 = 1.0F; float f5 = 0.5F; float f6 = 0.25F; int j = entity.getBrightnessForRender(partialTicks); int k = j % 65536; int l = j / 65536; OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, (float)k, (float)l); GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); float f8 = 255.0F; float f9 = ((float)entity.getOrientation() * 100 + partialTicks) / 2.0F; l = (int)((MathHelper.sin(f9 + 0.0F) + 1.0F) * 0.5F * 255.0F); int i1 = 255; int j1 = (int)((MathHelper.sin(f9 + 4.1887903F) + 1.0F) * 0.1F * 255.0F); GlStateManager.translate(0.0F, 0.1F, 0.0F); GlStateManager.rotate(180.0F - this.renderManager.playerViewY, 0.0F, 1.0F, 0.0F); GlStateManager.rotate((float)(this.renderManager.options.thirdPersonView == 2 ? -1 : 1) * -this.renderManager.playerViewX, 1.0F, 0.0F, 0.0F); float f7 = 0.3F; GlStateManager.scale(0.3F, 0.3F, 0.3F); Tessellator tessellator = Tessellator.getInstance(); VertexBuffer vertexbuffer = tessellator.getBuffer(); vertexbuffer.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR_NORMAL); double redMult = entity.getOrientation(); double greenMult = 0.2 + 0.3*(1 - entity.getOrientation()); double blueMult = 1 - entity.getOrientation(); int red = (int) (255 * redMult); int green = (int) (255 * greenMult); int blue = (int) (255 * blueMult); vertexbuffer.pos(-0.5D, -0.25D, 0.0D).tex((double)f, (double)f3).color(red, green, blue, 128).normal(0.0F, 1.0F, 0.0F).endVertex(); vertexbuffer.pos(0.5D, -0.25D, 0.0D).tex((double)f1, (double)f3).color(red, green, blue, 128).normal(0.0F, 1.0F, 0.0F).endVertex(); vertexbuffer.pos(0.5D, 0.75D, 0.0D).tex((double)f1, (double)f2).color(red, green, blue, 128).normal(0.0F, 1.0F, 0.0F).endVertex(); vertexbuffer.pos(-0.5D, 0.75D, 0.0D).tex((double)f, (double)f2).color(red, green, blue, 128).normal(0.0F, 1.0F, 0.0F).endVertex(); tessellator.draw(); GlStateManager.disableBlend(); GlStateManager.disableRescaleNormal(); GlStateManager.popMatrix(); super.doRender(entity, x, y, z, entityYaw, partialTicks); } } @Override protected ResourceLocation getEntityTexture(Entity_PowerOrb entity) { // TODO Auto-generated method stub return EXPERIENCE_ORB_TEXTURES; } }
-
[1.10] Adding a new entity to the game
TrekkieCub314 replied to TrekkieCub314's topic in Modder Support
I've got the entity spawning now, but now I'm wondering how to get the entity to travel in a straight line from its spawn point to a pre-defined BlockPos. -
I have a tile entity that should send an entity from itself to a set of coordinates specified in the tile entity. The entity it sends is what I'm trying to make. I want it to look similar to the XP orb (I can change some stuff around later), but I have no idea how to get new entities to show up in Minecraft beyond 1.7. Does anyone know what I should do or know of any good updated tutorials?
-
I have an item that stores coordinates when right-clicked on a block and sends a chat message to the wielding player what the coordinates are. The problem I've encountered is when I click on a block, the chat message is posted multiple times. I think this is due to the onItemUse() function being called in rapid succession while the right-mouse button is held down, and a basic click is enough to get it to trigger at least twice. Is there any way, aside from making the item tickable and storing a delay on the item, to either bypass the rapid right-click functionality or create a delay? I've tried using onPlayerStoppedUsing() but it didn't work for me.
-
I'm following along on a tutorial made for 1.8 that makes an item that stores the coordinates of a block it's used on. EnumChatFormatting is what's used in the tutorial, but eclipse can't find this class in 1.10. Can someone tell me if I'm doing something wrong or if there is an updated way to do what I'm wanting?
-
[1.7.10] Duplicate item entity is spawning when it shouldn't
TrekkieCub314 replied to TrekkieCub314's topic in Modder Support
Is Forge for 1.10 complete? I ask because when I tried to update to 1.8, Forge wasn't sufficiently complete to allow new villagers, at the very least. -
So I have an item that places a block that can store one item inside it. If I right-click on the block with the correct type of item and the block is empty, said item is deposited. If I right-click on the block while the block is full, the item should drop from the block. The problem I'm having is somehow I'm spawning two item entities. I'm able to pick up one of these entities, but the other one doesn't do anything if I walk over it. I changed the normal item drop code for my tile entity (I pulled it from another tile entity from a previous version of the project) to prevent any upward motion of the item when it's dropped. The item that I can't pick up has no upward motion when spawned, but the one I can pick up drops like a normal item. Only one entity drops when I break the block. Can anyone tell me what I'm doing wrong that's causing the second item entity to spawn? [spoiler=Block] package com.trekkiecub.oddsandends.block; import java.util.Random; import com.trekkiecub.oddsandends.init.BlockInit; import com.trekkiecub.oddsandends.init.ItemInit; import com.trekkiecub.oddsandends.item.Item_HealingCrystal; import com.trekkiecub.oddsandends.tileentity.TileEntity_HarpFiber; import com.trekkiecub.oddsandends.tileentity.TileEntity_Sceptre; import net.minecraft.block.Block; import net.minecraft.block.BlockContainer; import net.minecraft.block.material.Material; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.inventory.IInventory; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; public class Block_Sceptre_Top extends BlockContainer{ public Block_Sceptre_Top(Material p_i45386_1_) { super(p_i45386_1_); // TODO Auto-generated constructor stub } @Override public TileEntity createNewTileEntity(World p_149915_1_, int p_149915_2_) { // TODO Auto-generated method stub return new TileEntity_Sceptre(); } @Override public void breakBlock(World world, int x, int y, int z, Block block, int par6) { Random rand = new Random(); dropItems(world, x, y, z); float randX = rand.nextFloat() * 0.8F + 0.1F; float randY = rand.nextFloat() * 0.8F + 0.1F; float randZ = rand.nextFloat() * 0.8F + 0.1F; ItemStack item = new ItemStack(ItemInit.Sceptre, 1, 0); EntityItem entityItem = new EntityItem(world, x+randX, y+randY, z+randZ, item.copy()); /* if (item.hasTagCompound()) { entityItem.getEntityItem().setTagCompound((NBTTagCompound) item.getTagCompound().copy()); } */ float factor = 0.05F; entityItem.motionX = rand.nextGaussian() * factor; entityItem.motionY = 0; entityItem.motionZ = rand.nextGaussian() * factor; world.spawnEntityInWorld(entityItem); super.breakBlock(world, x, y, z, block, par6); } private void dropItems(World world, int x, int y, int z) { Random rand = new Random(); TileEntity tileEntity = world.getTileEntity(x, y, z); if (!(tileEntity instanceof IInventory)) { return; } IInventory inventory = (IInventory) tileEntity; for (int i = 0; i < inventory.getSizeInventory(); i++) { ItemStack item = inventory.getStackInSlot(i); if (item != null && item.stackSize > 0) { float randX = rand.nextFloat() * 0.8F + 0.1F; float randY = rand.nextFloat() * 0.8F + 0.1F; float randZ = rand.nextFloat() * 0.8F + 0.1F; EntityItem entityItem = new EntityItem(world, x+randX, y+randY, z+randZ, new ItemStack(item.getItem(), item.stackSize, item.getItemDamage())); if (item.hasTagCompound()) { entityItem.getEntityItem().setTagCompound((NBTTagCompound) item.getTagCompound().copy()); } float factor = 0.05F; entityItem.motionX = rand.nextGaussian() * factor; entityItem.motionY = 0; entityItem.motionZ = rand.nextGaussian() * factor; world.spawnEntityInWorld(entityItem); } inventory.setInventorySlotContents(i, null); } } public boolean isOpaqueCube() { return false; } public boolean renderAsNormalBlock() { return false; } public int getRenderType() { return 1; } public void onNeighborBlockChange(World world, int x, int y, int z, Block block) { Random rand = new Random(); if (!this.canBlockStay(world, x, y, z)) { world.setBlockToAir(x, y, z); } } public boolean canBlockStay(World world, int x, int y, int z) { if (world.getBlock(x, y-1, z) == BlockInit.Sceptre_Bottom) { return true; } return false; } public Item getItemDropped(int p_149650_1_, Random p_149650_2_, int p_149650_3_) { return ItemInit.Sceptre; } @Override public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int p_149727_6_, float p_149727_7_, float p_149727_8_, float p_149727_9_) { TileEntity_Sceptre thisTile = (TileEntity_Sceptre) world.getTileEntity(x, y, z); if (thisTile != null) { ItemStack heldItem = player.getHeldItem(); if (heldItem != null && heldItem.stackSize > 0) { if (heldItem.getItem() instanceof Item_HealingCrystal) { if (thisTile.canAddPartial(heldItem)) { player.setCurrentItemOrArmor(0, thisTile.mergeStack(heldItem)); return true; } else { this.dropItems(world, x, y, z); } } else { this.dropItems(world, x, y, z); } } else { this.dropItems(world, x, y, z); } } return false; } } [spoiler=Tile Entity] package com.trekkiecub.oddsandends.tileentity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.network.NetworkManager; import net.minecraft.network.Packet; import net.minecraft.network.play.server.S35PacketUpdateTileEntity; import net.minecraft.tileentity.TileEntity; public class TileEntity_Sceptre extends TileEntity implements IInventory{ private ItemStack itemStacks[]; private int cooldown = 0; public TileEntity_Sceptre() { itemStacks = new ItemStack[1]; } @Override public int getSizeInventory() { // TODO Auto-generated method stub return itemStacks.length; } @Override public ItemStack getStackInSlot(int slot) { if (slot < 0 || slot >= this.getSizeInventory()) return null; return this.itemStacks[slot]; } @Override public ItemStack decrStackSize(int slot, int amount) { ItemStack stack = getStackInSlot(slot); if (stack != null) { if (stack.stackSize <= amount) { setInventorySlotContents(slot, null); markDirty(); } else { stack = stack.splitStack(amount); if(stack.stackSize == 0) { setInventorySlotContents(slot, null); } this.markDirty(); } } return stack; } public void updateEntity() { if (!this.worldObj.isRemote) { } super.updateEntity(); } // // Merge the given item stack with the inventory slots either // until the stack is empty or the inventory runs out. public ItemStack mergeStack(ItemStack stack) { ItemStack returnThisStack = stack.copy(); boolean addedItem = false; for (int i = 0; i < getSizeInventory() && returnThisStack.stackSize > 0; i++) { // This is the maximum amount we can deposit into each slot // based on both this tile entity and the number of items // Number of items can't go above the item's max stack size // Will never be zero: First is hard-coded, second breaks loop int maxPossibleStackSize = Math.min(this.getInventoryStackLimit(), returnThisStack.stackSize); if (itemStacks[i] == null) { setInventorySlotContents(i, returnThisStack.splitStack(maxPossibleStackSize)); addedItem = true; } else if (itemStacks[i].getItem() == returnThisStack.getItem() && returnThisStack.isStackable()) { if (itemStacks[i].getItemDamage() == returnThisStack.getItemDamage()) { // Get max of both inventory limit and item stack limit, subtract current items // Current items can't be greater than stack limit since it's the same item maxPossibleStackSize = Math.min(this.getInventoryStackLimit(), returnThisStack.stackSize) - itemStacks[i].stackSize; if (maxPossibleStackSize > 0) { itemStacks[i].stackSize += maxPossibleStackSize; returnThisStack.splitStack(maxPossibleStackSize); addedItem = true; } } } } if (returnThisStack.stackSize == 0) { returnThisStack = null; } if (addedItem) { markDirty(); } return returnThisStack; } public boolean canAddItem(ItemStack stack) { for (int i = 0; i < getSizeInventory(); i++) { if (itemStacks[i] == null) { return true; } } return false; } public boolean canAddPartial(ItemStack stack) { for (int i = 0; i < getSizeInventory(); i++) { if (itemStacks[i] == null) { return true; } } return false; } @Override public ItemStack getStackInSlotOnClosing(int slot) { ItemStack stack = getStackInSlot(slot); if (stack != null) { setInventorySlotContents(slot, null); } return stack; } @Override public void setInventorySlotContents(int slot, ItemStack stack) { itemStacks[slot] = stack; if (slot < 0 || slot >= this.getSizeInventory()) { return; } if (stack != null && stack.stackSize > getInventoryStackLimit()) { stack.stackSize = getInventoryStackLimit(); } if (stack != null && stack.stackSize == 0) { stack = null; } this.itemStacks[slot] = stack; this.markDirty(); } @Override public String getInventoryName() { // TODO Auto-generated method stub return null; } @Override public boolean hasCustomInventoryName() { // TODO Auto-generated method stub return false; } @Override public int getInventoryStackLimit() { // TODO Auto-generated method stub return 1; } @Override public boolean isUseableByPlayer(EntityPlayer p_70300_1_) { // TODO Auto-generated method stub return false; } @Override public void openInventory() { // TODO Auto-generated method stub } @Override public void closeInventory() { // TODO Auto-generated method stub } @Override public boolean isItemValidForSlot(int p_94041_1_, ItemStack p_94041_2_) { // TODO Auto-generated method stub return false; } @Override public void readFromNBT(NBTTagCompound tag) { super.readFromNBT(tag); NBTTagList nbttaglist = tag.getTagList("Items", 10); for (int i = 0; i < nbttaglist.tagCount(); ++i) { NBTTagCompound tag1 = nbttaglist.getCompoundTagAt(i); int j = tag1.getByte("Slot") & 255; setInventorySlotContents(j, ItemStack.loadItemStackFromNBT(tag1)); } } @Override public void writeToNBT(NBTTagCompound tag) { super.writeToNBT(tag); NBTTagList nbttaglist = new NBTTagList(); for (int i = 0; i < getSizeInventory(); ++i) { if (getStackInSlot(i) != null) { NBTTagCompound nbttagcompound1 = new NBTTagCompound(); nbttagcompound1.setByte("Slot", (byte)i); getStackInSlot(i).writeToNBT(nbttagcompound1); nbttaglist.appendTag(nbttagcompound1); } } tag.setTag("Items", nbttaglist); } @Override public Packet getDescriptionPacket() { return null; } @Override public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity packet) { } }
-
I'm using some functions to streamline coding for crafting recipes that don't involve overloading fifty trillion functions. I'm also storing nuggets and ingots in arrays to make adding nuggets/ingots/other metal items quickly. What I'm wanting to do is specify the ore dictionary names for the craftStorage function so I can craft both ingots and nuggets using the ore dictionary in one line. Is there a way to retrieve the ore dictionary name from a specified item or your mod's item from the ore dictionary name? private void addCrafting() { craftStorage(ItemInit.ingot_copper, ItemInit.nugget_copper, 9); } private void craftStorage(Object container, Object component, int quantity) { craftOneToX(container, component, quantity); craftXToOne(container, component, quantity); } private void craftOneToX(Object container, Object component, int quantity) { // Convert Object types to ItemStacks ItemStack newContainer = TCOAE_Functions.ObjToStack(container); ItemStack newComponent = TCOAE_Functions.ObjToStack(component); GameRegistry.addShapelessRecipe(TCOAE_Functions.stack(newComponent, quantity), newContainer); } private void craftXToOne(Object container, Object component, int quantity) { ItemStack newContainer = TCOAE_Functions.ObjToStack(container); ItemStack newComponent = TCOAE_Functions.ObjToStack(component); // Create array list to dynamically add shapeless items of same type ArrayList recipe = new ArrayList(); for (int i = 0; i < quantity; i++) { recipe.add(newComponent); } // Convert to object array for use in shapeless recipe Object[] objectRecipe = new Object[quantity]; objectRecipe = recipe.toArray(); GameRegistry.addShapelessRecipe(newContainer, recipe.toArray()); } public static ItemStack stack(Object item, int quantity, int damage) { ItemStack returnThis; if (item instanceof Item) { returnThis = new ItemStack((Item)item, quantity, damage); } else if (item instanceof Block) { returnThis = new ItemStack((Block)item, quantity, damage); } else { returnThis = ((ItemStack) item).copy(); returnThis.stackSize = quantity; returnThis.setItemDamage(damage); } return returnThis; } // Makes a stack with specified object and quantity, default damage public static ItemStack stack(Object item, int quantity) { if (item instanceof ItemStack) { ItemStack returnThis = ((ItemStack) item).copy(); returnThis.stackSize = quantity; return returnThis; } return stack(item, quantity, 0); } // Makes a stack with specified object, default quantity and damage public static ItemStack stack(Object item) { if (item instanceof ItemStack) { return (ItemStack) item; } return stack(item, 1); } public static ItemStack ObjToStack(Object input) { return (input instanceof Block ? new ItemStack((Block) input) : (input instanceof Item ? new ItemStack((Item) input) : (ItemStack) input)); }
-
[1.7.10] Custom Log Blocks Not Burning
TrekkieCub314 replied to TrekkieCub314's topic in Modder Support
How do the encouragement and flammability values of that function work? Also, does this need to happen before or after the custom blocks are registered? -
I've added some custom wood blocks whose class inherits from BlockLog, and for whatever reason, I can't get them to burn like normal wood. I can set the top face of the block on fire, but I can't set the sides on fire like I can with regular wood, and the custom wood blocks don't burn up. The only things the BlockOldLog and BlockNewLog classes do that the BlockLog class does not is specify the vanilla wood types, so I don't believe that's the issue. The Block_RawLog class has a tick event, but I don't know if that would change things. Can anyone see if I'm missing something or doing something wrong? Here's the code for the custom wood blocks: public class Block_RawLog extends BlockLog { public Block_RawLog() { this.setTickRandomly(true); } @SideOnly(Side.CLIENT) public void registerBlockIcons(IIconRegister register) { this.field_150167_a = new IIcon[1]; this.field_150167_a[0] = register.registerIcon(this.getTextureName() + "_" + "side"); this.field_150166_b = new IIcon[1]; this.field_150166_b[0] = register.registerIcon(this.getTextureName() + "_" + "top"); } public void updateTick(World world, int x, int y, int z, Random random) { boolean debug = true; int meta_orig = world.getBlockMetadata(x, y, z); int meta_rot = meta_orig & 3; // 12D = 0011B, isolates bottom bits int meta_dir = meta_orig - meta_rot; if (meta_rot == 3 || (debug && meta_rot >= 1)) { world.setBlock(x, y, z, BlockInit.Raw_Log_Dead, meta_dir, 2); } else { meta_rot++; world.setBlockMetadataWithNotify(x, y, z, meta_rot+meta_dir, 2); } } } How I'm instantiating the blocks themselves, in case there's something different I need to do here: Raw_Log_Birch = new Block_RawLog().setBlockName("raw_log_birch").setCreativeTab(mod_TrekkieCubOddsAndEnds.tab_usefulthings).setBlockTextureName(TCOAE_Const.PRE_USE + "raw_log_birch");
-
[1.7.10] [SOLVED] Custom Block Renderer Not Updating Block
TrekkieCub314 replied to TrekkieCub314's topic in Modder Support
Solved it. I wasn't marking the block for an update when I read from NBT. Now that I am, it's working perfectly. -
[1.7.10] [SOLVED] Custom Block Renderer Not Updating Block
TrekkieCub314 replied to TrekkieCub314's topic in Modder Support
I've looked into this a little, and made a few changes to my tile entity class, but they don't seem to be working and I'm not sure what I'm doing wrong. The issue I mentioned persists. The major changes I've made are the bottom four functions. package com.trekkiecub.hodgepodge.init; import java.util.HashMap; import java.util.Map; import java.util.Random; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Items; import net.minecraft.inventory.IInventory; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.network.NetworkManager; import net.minecraft.network.Packet; import net.minecraft.network.play.server.S35PacketUpdateTileEntity; import net.minecraft.tileentity.TileEntity; public class TileEntity_Slicer extends TileEntity implements IInventory{ private ItemStack[] itemStacks; private Map recipeList = new HashMap(); public int processTime; public final int TICKS_DONE = 100; class recipeEntry { Item output_one, output_two; double quantity; public recipeEntry(Item output_one, Item output_two, double quantity) { this.output_one = output_one; this.output_two = output_two; this.quantity = quantity; } public void setQuantity(double quant) { this.quantity = quant; } } public TileEntity_Slicer() { itemStacks = new ItemStack[3]; recipeList.put(Items.gold_ingot, new recipeEntry(ItemInit.Half_Ingot_Gold, ItemInit.Half_Ingot_Gold, 1)); recipeList.put(Items.iron_ingot, new recipeEntry(ItemInit.Half_Ingot_Iron, ItemInit.Half_Ingot_Iron, 1)); recipeList.put(ItemInit.Half_Ingot_Gold, new recipeEntry(ItemInit.Quarter_Ingot_Gold, ItemInit.Quarter_Ingot_Gold, 1)); recipeList.put(ItemInit.Half_Ingot_Iron, new recipeEntry(ItemInit.Quarter_Ingot_Iron, ItemInit.Quarter_Ingot_Iron, 1)); } @Override public int getSizeInventory() { return itemStacks.length; } @Override public ItemStack getStackInSlot(int slot) { if (slot < 0 || slot >= this.getSizeInventory()) return null; return this.itemStacks[slot]; } @Override public ItemStack decrStackSize(int slot, int amount) { ItemStack stack = getStackInSlot(slot); if (stack != null) { if (stack.stackSize <= amount) { setInventorySlotContents(slot, null); markDirty(); } else { stack = stack.splitStack(amount); if(stack.stackSize == 0) { setInventorySlotContents(slot, null); } this.markDirty(); } } return stack; } @Override public ItemStack getStackInSlotOnClosing(int slot) { ItemStack stack = getStackInSlot(slot); if (stack != null) { setInventorySlotContents(slot, null); } return stack; } @Override public void setInventorySlotContents(int slot, ItemStack stack) { itemStacks[slot] = stack; if (slot < 0 || slot >= this.getSizeInventory()) { return; } if (stack != null && stack.stackSize > getInventoryStackLimit()) { stack.stackSize = getInventoryStackLimit(); } if (stack != null && stack.stackSize == 0) { stack = null; } this.itemStacks[slot] = stack; this.markDirty(); } @Override public String getInventoryName() { return null; } @Override public boolean hasCustomInventoryName() { // TODO Auto-generated method stub return false; } @Override public int getInventoryStackLimit() { return 64; } @Override public boolean isUseableByPlayer(EntityPlayer player) { return worldObj.getTileEntity(xCoord, yCoord, zCoord) == this && player.getDistanceSq(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5) < 64; } @Override public void openInventory() { // TODO Auto-generated method stub } @Override public void closeInventory() { // TODO Auto-generated method stub } @Override public boolean isItemValidForSlot(int slot, ItemStack stack) { switch (slot) { case 0: { return (recipeList.get(stack.getItem()) != null); } default: return false; } } @SideOnly(Side.CLIENT) public int getProgressScaled(int somenum) { return this.processTime * somenum / TICKS_DONE; } public boolean isWorking() {return this.processTime > 0;} public void updateEntity() { if (!this.worldObj.isRemote) { if (this.canProcess()) { this.processTime++; if (this.processTime >= TICKS_DONE) { this.processTime = 0; this.processItem(); } worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord); markDirty(); } else { this.processTime = 0; worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord); markDirty(); } } super.updateEntity(); } private boolean canProcess() { if (this.itemStacks[0] == null) { return false; } else { // Get the crushEntry for the corresponding item in the input slot recipeEntry resultEntry = (recipeEntry) recipeList.get(this.itemStacks[0].getItem()); // Return can't crush if the item doesn't have a recipe if (resultEntry == null) return false; boolean firstPasses, secondPasses, thirdPasses; if (this.itemStacks[1] == null || resultEntry.output_two == null) { firstPasses = true; } else if (this.itemStacks[1].getItem() == resultEntry.output_two && this.itemStacks[1].stackSize + 1 <= this.itemStacks[1].getMaxStackSize()) { firstPasses = true; } else { return false; } if (this.itemStacks[2] == null || resultEntry.output_two == null) { secondPasses = true; } else if (this.itemStacks[2].getItem() == resultEntry.output_two && 1 + this.itemStacks[2].stackSize <= this.itemStacks[2].getMaxStackSize()) { secondPasses = true; } else { return false; } return firstPasses && secondPasses; } } public void processItem() { if (this.canProcess()) { Random rand = new Random(); // Get the crush entry for the corresponding item in the input slot recipeEntry result = ((recipeEntry) recipeList.get(this.itemStacks[0].getItem())); if (result.output_one != null) { if (this.itemStacks[1] == null) { this.itemStacks[1] = new ItemStack(result.output_one, 1); } else { this.itemStacks[1].stackSize += 1; } } if (result.output_two != null) { if (this.itemStacks[2] == null) { this.itemStacks[2] = new ItemStack(result.output_two, 1); } else { this.itemStacks[2].stackSize += 1; } } this.itemStacks[0].stackSize--; if (this.itemStacks[0].stackSize <= 0) { this.itemStacks[0] = null; } } } @Override public void readFromNBT(NBTTagCompound tag) { super.readFromNBT(tag); NBTTagList nbttaglist = tag.getTagList("Items", 10); this.processTime = tag.getInteger("progress"); for (int i = 0; i < nbttaglist.tagCount(); ++i) { NBTTagCompound tag1 = nbttaglist.getCompoundTagAt(i); int j = tag1.getByte("Slot") & 255; setInventorySlotContents(j, ItemStack.loadItemStackFromNBT(tag1)); } } @Override public void writeToNBT(NBTTagCompound tag) { super.writeToNBT(tag); tag.setInteger("progress", this.processTime); NBTTagList nbttaglist = new NBTTagList(); for (int i = 0; i < getSizeInventory(); ++i) { if (getStackInSlot(i) != null) { NBTTagCompound nbttagcompound1 = new NBTTagCompound(); nbttagcompound1.setByte("Slot", (byte)i); getStackInSlot(i).writeToNBT(nbttagcompound1); nbttaglist.appendTag(nbttagcompound1); } } tag.setTag("Items", nbttaglist); } public void writeNBTSync(NBTTagCompound tag) { tag.setInteger("progress", this.processTime); } public void readNBTSync(NBTTagCompound tag) { this.processTime = tag.getInteger("progress"); } @Override public Packet getDescriptionPacket() { NBTTagCompound tagCompound = new NBTTagCompound(); writeNBTSync(tagCompound); return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 1, tagCompound); } @Override public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) { readNBTSync(pkt.func_148857_g()); } } -
So I have a machine block that has textures for when the machine is running and when it is not. Rather than use two separate blocks to represent these states like the vanilla furnace does, I use a custom block renderer that checks an integer in the block's corresponding tile entity to accomplish this. It works for the most part, except that the block's texture won't update unless I break a different block (tall grass, dirt, etc). It seems like it's a really basic fix, but I'm not sure what I need to add. I've included all the classes relevant to the block in case any of them need to be modified. package com.trekkiecub.hodgepodge.init; import com.trekkiecub.hodgepodge.mod_TrekkieCubHodgePodge; import com.trekkiecub.hodgepodge.proxy.Proxy_Client; import net.minecraft.block.BlockContainer; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.IIcon; import net.minecraft.world.World; public class Block_Slicer extends Block_Machine{ protected Block_Slicer(Material p_i45386_1_) { super(p_i45386_1_); // TODO Auto-generated constructor stub } @Override public int getRenderType() { return Proxy_Client.renderType_Slicer; } @Override public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int metadata, float a, float b, float c) { TileEntity tileEntity = world.getTileEntity(x, y, z); if (tileEntity == null || player.isSneaking()) return false; player.openGui(mod_TrekkieCubHodgePodge.MODID, 0, world, x, y, z); return true; } @Override public TileEntity createNewTileEntity(World p_149915_1_, int p_149915_2_) { // TODO Auto-generated method stub return new TileEntity_Slicer(); } } package com.trekkiecub.hodgepodge.init; import java.util.Random; import com.trekkiecub.hodgepodge.proxy.Proxy_Client; import net.minecraft.block.Block; import net.minecraft.block.BlockContainer; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.item.EntityItem; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.IIcon; import net.minecraft.util.MathHelper; import net.minecraft.world.World; public class Block_Machine extends BlockContainer { public IIcon front_on, front_off, front, top, side; @Override public void registerBlockIcons(IIconRegister reg) { this.front_on = reg.registerIcon(this.textureName + "_front_on"); this.front_off = reg.registerIcon(this.textureName + "_front_off"); this.front = reg.registerIcon("trekkiecub_techythings:invisible"); this.top = reg.registerIcon(this.textureName + "_top"); this.side = reg.registerIcon(this.textureName + "_side"); } @Override public boolean renderAsNormalBlock() { return false; } @Override public boolean canRenderInPass(int pass) { Proxy_Client.renderPass = pass; return true; } @Override public void onBlockAdded(World world, int xcoord, int ycoord, int zcoord) { super.onBlockAdded(world, xcoord, ycoord, zcoord); setRotatedMetadata(world, xcoord, ycoord, zcoord); System.out.println("X: " + xcoord + ", Y: " + ycoord + ", Z: " + zcoord); } public void onBlockPlacedBy(World world, int xcoord, int ycoord, int zcoord, EntityLivingBase player, ItemStack theBlock) { int direction = MathHelper.floor_double((double)(player.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3; switch (direction) { case 0: world.setBlockMetadataWithNotify(xcoord, ycoord, zcoord, 2, 2); break; case 1: world.setBlockMetadataWithNotify(xcoord, ycoord, zcoord, 5, 2); break; case 2: world.setBlockMetadataWithNotify(xcoord, ycoord, zcoord, 3, 2); break; case 3: world.setBlockMetadataWithNotify(xcoord, ycoord, zcoord, 4, 2); break; } } private void setRotatedMetadata(World world, int xcoord, int ycoord, int zcoord) { if (!world.isRemote) { Block north = world.getBlock(xcoord, ycoord, zcoord-1); Block south = world.getBlock(xcoord, ycoord, zcoord+1); Block east = world.getBlock(xcoord-1, ycoord, zcoord); Block west = world.getBlock(xcoord+1, ycoord, zcoord); byte newMeta = 3; if (north.func_149730_j() && !south.func_149730_j()) { newMeta = 3; } if (south.func_149730_j() && !north.func_149730_j()) { newMeta = 2; } if (east.func_149730_j() && !west.func_149730_j()) { newMeta = 5; } if (west.func_149730_j() && !east.func_149730_j()) { newMeta = 4; } world.setBlockMetadataWithNotify(xcoord, ycoord, zcoord, newMeta, 2); } } @Override public IIcon getIcon(int dir, int meta) { if (meta > 5) meta = 5; if (dir == 4 && meta == 0) { return this.front; } else if (meta == -1) { return this.front_off; } else if (meta == -2) { return this.front_on; } if (dir == 1) return this.top; if (dir == meta) { return this.front; } return this.side; } @Override public int getRenderBlockPass() {return 1;} protected Block_Machine(Material p_i45386_1_) { super(p_i45386_1_); // TODO Auto-generated constructor stub } @Override public void breakBlock(World world, int x, int y, int z, Block block, int par6) { dropItems(world, x, y, z); super.breakBlock(world, x, y, z, block, par6); } private void dropItems(World world, int x, int y, int z) { Random rand = new Random(); TileEntity tileEntity = world.getTileEntity(x, y, z); if (!(tileEntity instanceof IInventory)) { return; } IInventory inventory = (IInventory) tileEntity; for (int i = 0; i < inventory.getSizeInventory(); i++) { ItemStack item = inventory.getStackInSlot(i); if (item != null && item.stackSize > 0) { float randX = rand.nextFloat() * 0.8F + 0.1F; float randY = rand.nextFloat() * 0.8F + 0.1F; float randZ = rand.nextFloat() * 0.8F + 0.1F; EntityItem entityItem = new EntityItem(world, x+randX, y+randY, z+randZ, new ItemStack(item.getItem(), item.stackSize, item.getItemDamage())); if (item.hasTagCompound()) { entityItem.getEntityItem().setTagCompound((NBTTagCompound) item.getTagCompound().copy()); } float factor = 0.05F; entityItem.motionX = rand.nextGaussian() * factor; entityItem.motionY = rand.nextGaussian() * factor + 0.2F; entityItem.motionZ = rand.nextGaussian() * factor; world.spawnEntityInWorld(entityItem); item.stackSize = 0; } } } @Override public TileEntity createNewTileEntity(World p_149915_1_, int p_149915_2_) { // TODO Auto-generated method stub return null; } } package com.trekkiecub.hodgepodge.init; import java.util.HashMap; import java.util.Map; import java.util.Random; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Items; import net.minecraft.inventory.IInventory; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.network.NetworkManager; import net.minecraft.network.Packet; import net.minecraft.network.play.server.S35PacketUpdateTileEntity; import net.minecraft.tileentity.TileEntity; public class TileEntity_Slicer extends TileEntity implements IInventory{ private ItemStack[] itemStacks; private Map recipeList = new HashMap(); public int processTime; public final int TICKS_DONE = 100; class recipeEntry { Item output_one, output_two; double quantity; public recipeEntry(Item output_one, Item output_two, double quantity) { this.output_one = output_one; this.output_two = output_two; this.quantity = quantity; } public void setQuantity(double quant) { this.quantity = quant; } } public TileEntity_Slicer() { itemStacks = new ItemStack[3]; recipeList.put(Items.iron_ingot, new recipeEntry(ItemInit.Half_Ingot_Iron, ItemInit.Half_Ingot_Iron, 1)); recipeList.put(ItemInit.Half_Ingot_Iron, new recipeEntry(ItemInit.Quarter_Ingot_Iron, ItemInit.Quarter_Ingot_Iron, 1)); } @Override public int getSizeInventory() { return itemStacks.length; } @Override public ItemStack getStackInSlot(int slot) { if (slot < 0 || slot >= this.getSizeInventory()) return null; return this.itemStacks[slot]; } @Override public ItemStack decrStackSize(int slot, int amount) { ItemStack stack = getStackInSlot(slot); if (stack != null) { if (stack.stackSize <= amount) { setInventorySlotContents(slot, null); markDirty(); } else { stack = stack.splitStack(amount); if(stack.stackSize == 0) { setInventorySlotContents(slot, null); } this.markDirty(); } } return stack; } @Override public ItemStack getStackInSlotOnClosing(int slot) { ItemStack stack = getStackInSlot(slot); if (stack != null) { setInventorySlotContents(slot, null); } return stack; } @Override public void setInventorySlotContents(int slot, ItemStack stack) { itemStacks[slot] = stack; if (slot < 0 || slot >= this.getSizeInventory()) { return; } if (stack != null && stack.stackSize > getInventoryStackLimit()) { stack.stackSize = getInventoryStackLimit(); } if (stack != null && stack.stackSize == 0) { stack = null; } this.itemStacks[slot] = stack; this.markDirty(); } @Override public String getInventoryName() { return null; } @Override public boolean hasCustomInventoryName() { // TODO Auto-generated method stub return false; } @Override public int getInventoryStackLimit() { return 64; } @Override public boolean isUseableByPlayer(EntityPlayer player) { return worldObj.getTileEntity(xCoord, yCoord, zCoord) == this && player.getDistanceSq(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5) < 64; } @Override public void openInventory() { // TODO Auto-generated method stub } @Override public void closeInventory() { // TODO Auto-generated method stub } @Override public boolean isItemValidForSlot(int slot, ItemStack stack) { switch (slot) { case 0: { return (recipeList.get(stack.getItem()) != null); } default: return false; } } @SideOnly(Side.CLIENT) public int getProgressScaled(int somenum) { return this.processTime * somenum / TICKS_DONE; } public boolean isWorking() {return this.processTime > 0;} public void updateEntity() { if (!this.worldObj.isRemote) { if (this.canProcess()) { this.processTime++; if (this.processTime >= TICKS_DONE) { this.processTime = 0; this.processItem(); } worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord); markDirty(); } else { this.processTime = 0; worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord); markDirty(); } } super.updateEntity(); } private boolean canProcess() { if (this.itemStacks[0] == null) { return false; } else { // Get the crushEntry for the corresponding item in the input slot recipeEntry resultEntry = (recipeEntry) recipeList.get(this.itemStacks[0].getItem()); // Return can't crush if the item doesn't have a recipe if (resultEntry == null) return false; boolean firstPasses, secondPasses, thirdPasses; if (this.itemStacks[1] == null || resultEntry.output_two == null) { firstPasses = true; } else if (this.itemStacks[1].getItem() == resultEntry.output_two && this.itemStacks[1].stackSize + 1 <= this.itemStacks[1].getMaxStackSize()) { firstPasses = true; } else { return false; } if (this.itemStacks[2] == null || resultEntry.output_two == null) { secondPasses = true; } else if (this.itemStacks[2].getItem() == resultEntry.output_two && 1 + this.itemStacks[2].stackSize <= this.itemStacks[2].getMaxStackSize()) { secondPasses = true; } else { return false; } return firstPasses && secondPasses; } } public void processItem() { if (this.canProcess()) { Random rand = new Random(); // Get the crush entry for the corresponding item in the input slot recipeEntry result = ((recipeEntry) recipeList.get(this.itemStacks[0].getItem())); if (result.output_one != null) { if (this.itemStacks[1] == null) { this.itemStacks[1] = new ItemStack(result.output_one, 1); } else { this.itemStacks[1].stackSize += 1; } } if (result.output_two != null) { if (this.itemStacks[2] == null) { this.itemStacks[2] = new ItemStack(result.output_two, 1); } else { this.itemStacks[2].stackSize += 1; } } this.itemStacks[0].stackSize--; if (this.itemStacks[0].stackSize <= 0) { this.itemStacks[0] = null; } } } @Override public void readFromNBT(NBTTagCompound tag) { super.readFromNBT(tag); NBTTagList nbttaglist = tag.getTagList("Items", 10); this.processTime = tag.getInteger("progress"); for (int i = 0; i < nbttaglist.tagCount(); ++i) { NBTTagCompound tag1 = nbttaglist.getCompoundTagAt(i); int j = tag1.getByte("Slot") & 255; setInventorySlotContents(j, ItemStack.loadItemStackFromNBT(tag1)); } } @Override public void writeToNBT(NBTTagCompound tag) { super.writeToNBT(tag); tag.setInteger("progress", this.processTime); NBTTagList nbttaglist = new NBTTagList(); for (int i = 0; i < getSizeInventory(); ++i) { if (getStackInSlot(i) != null) { NBTTagCompound nbttagcompound1 = new NBTTagCompound(); nbttagcompound1.setByte("Slot", (byte)i); getStackInSlot(i).writeToNBT(nbttagcompound1); nbttaglist.appendTag(nbttagcompound1); } } tag.setTag("Items", nbttaglist); } @Override public Packet getDescriptionPacket() { return null; } @Override public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) { } } package com.trekkiecub.hodgepodge.rendering; import org.lwjgl.opengl.GL11; import com.trekkiecub.hodgepodge.init.BlockInit; import com.trekkiecub.hodgepodge.init.Block_Slicer; import com.trekkiecub.hodgepodge.init.TileEntity_Slicer; import com.trekkiecub.hodgepodge.proxy.Proxy_Client; import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler; import net.minecraft.block.Block; import net.minecraft.client.renderer.RenderBlocks; import net.minecraft.client.renderer.Tessellator; import net.minecraft.util.IIcon; import net.minecraft.world.IBlockAccess; public class Render_Slicer implements ISimpleBlockRenderingHandler { @Override public void renderInventoryBlock(Block block, int metadata, int modelId, RenderBlocks renderer) { Tessellator tessellator = Tessellator.instance; block.setBlockBoundsForItemRender(); renderer.setRenderBoundsFromBlock(block); GL11.glRotatef(90.0F, 0.0F, 1.0F, 0.0F); GL11.glTranslatef(-0.5F, -0.5F, -0.5F); tessellator.startDrawingQuads(); tessellator.setNormal(0.0F, -1.0F, 0.0F); renderer.renderFaceYNeg(block, 0.0D, 0.0D, 0.0D, renderer.getBlockIconFromSideAndMetadata(block, 0, 3)); tessellator.draw(); tessellator.startDrawingQuads(); tessellator.setNormal(0.0F, 1.0F, 0.0F); renderer.renderFaceYPos(block, 0.0D, 0.0D, 0.0D, renderer.getBlockIconFromSideAndMetadata(block, 1, 3)); tessellator.draw(); tessellator.startDrawingQuads(); tessellator.setNormal(0.0F, 0.0F, -1.0F); renderer.renderFaceZNeg(block, 0.0D, 0.0D, 0.0D, renderer.getBlockIconFromSideAndMetadata(block, 2, 3)); tessellator.draw(); tessellator.startDrawingQuads(); tessellator.setNormal(0.0F, 0.0F, 1.0F); renderer.renderFaceZPos(block, 0.0D, 0.0D, 0.0D, renderer.getBlockIconFromSideAndMetadata(block, 3, 0)); tessellator.draw(); tessellator.startDrawingQuads(); tessellator.setNormal(-1.0F, 0.0F, 0.0F); renderer.renderFaceXNeg(block, 0.0D, 0.0D, 0.0D, renderer.getBlockIconFromSideAndMetadata(block, 4, -1)); tessellator.draw(); tessellator.startDrawingQuads(); tessellator.setNormal(1.0F, 0.0F, 0.0F); renderer.renderFaceXPos(block, 0.0D, 0.0D, 0.0D, renderer.getBlockIconFromSideAndMetadata(block, 5, 3)); tessellator.draw(); GL11.glTranslatef(0.5F, 0.5F, 0.5F); } @Override public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) { if (Proxy_Client.renderPass == 0) { TileEntity_Slicer tileEnt = (TileEntity_Slicer) world.getTileEntity(x, y, z); IIcon newIcon; if (tileEnt.processTime > 0) { newIcon = ((Block_Slicer) block).front_on; } else newIcon = ((Block_Slicer) block).front_off; GL11.glColor3f(1.0F,1.0F,1.0F); Tessellator tess = Tessellator.instance; tess.setColorOpaque_F(1.0F, 1.0F, 1.0F); renderer.renderFaceXNeg(block, x, y, z, newIcon); renderer.renderFaceXPos(block, x, y, z, newIcon); renderer.renderFaceZNeg(block, x, y, z, newIcon); renderer.renderFaceZPos(block, x, y, z, newIcon); renderer.renderFaceYNeg(block, x, y, z, newIcon); renderer.renderFaceYPos(block, x, y, z, newIcon); //renderer.renderStandardBlock(Blocks.flowing_water, x, y, z); } else { renderer.renderStandardBlock(BlockInit.Machine_Slicer, x, y, z); } return true; } @Override public boolean shouldRender3DInInventory(int modelId) { return true; } @Override public int getRenderId() { return Proxy_Client.renderType_Slicer; } } package com.trekkiecub.hodgepodge.rendering; import com.trekkiecub.hodgepodge.init.TileEntity_Slicer; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.Container; import net.minecraft.inventory.ICrafting; import net.minecraft.inventory.Slot; import net.minecraft.inventory.SlotFurnace; import net.minecraft.item.ItemStack; public class Container_Slicer extends Container{ protected TileEntity_Slicer tileEntity; int prevProcessTime = 0; public Container_Slicer(InventoryPlayer inventoryPlayer, TileEntity_Slicer rcE) { tileEntity = rcE; addSlotToContainer(new Slot(tileEntity, 0, 56, 35)); addSlotToContainer(new SlotFurnace(inventoryPlayer.player, tileEntity, 1, 116, 26)); addSlotToContainer(new SlotFurnace(inventoryPlayer.player, tileEntity, 2, 116, 44)); bindPlayerInventory(inventoryPlayer); } @Override public void addCraftingToCrafters(ICrafting craftingThing) { super.addCraftingToCrafters(craftingThing); craftingThing.sendProgressBarUpdate(this, 0, this.tileEntity.processTime); } @Override public void detectAndSendChanges() { super.detectAndSendChanges(); for (int i = 0; i < this.crafters.size(); ++i) { ICrafting icrafting = (ICrafting)this.crafters.get(i); if (this.prevProcessTime != this.tileEntity.processTime) { icrafting.sendProgressBarUpdate(this, 0, this.tileEntity.processTime); } } this.prevProcessTime = this.tileEntity.processTime; } @SideOnly(Side.CLIENT) public void updateProgressBar(int par1, int par2) { this.tileEntity.processTime = par2; } @Override public boolean canInteractWith(EntityPlayer player) { return tileEntity.isUseableByPlayer(player); } protected void bindPlayerInventory(InventoryPlayer invPlayer) { for (int i = 0; i < 3; i++) { for (int j = 0; j < 9; j++) { addSlotToContainer(new Slot(invPlayer, j + i * 9 + 9, 8 + j * 18, 84 + i * 18)); } } for (int i = 0; i < 9; i++) { addSlotToContainer(new Slot(invPlayer, i, 8+i*18, 142)); } } @Override public ItemStack transferStackInSlot(EntityPlayer player, int fromslot) { ItemStack previous = null; Slot slot = (Slot) this.inventorySlots.get(fromslot); if (slot != null && slot.getHasStack()) { ItemStack current = slot.getStack(); previous = current.copy(); if (fromslot < 3) { if (!this.mergeItemStack(current, 3, 39, true)) { return null; } } else { if (!this.mergeItemStack(current, 0, 3, false)) { return null; } } if (current.stackSize == 0) { slot.putStack(null); } // Custom Shit if (current.stackSize == previous.stackSize) { return null; } slot.onPickupFromSlot(player, current); } return previous; } } package com.trekkiecub.hodgepodge.rendering; import com.trekkiecub.hodgepodge.init.TileEntity_Slicer; import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.Container; import net.minecraft.util.ResourceLocation; import net.minecraft.util.StatCollector; public class Gui_Slicer extends GuiContainer{ private TileEntity_Slicer tile_slicer; public Gui_Slicer(InventoryPlayer inventoryPlayer, TileEntity_Slicer tile_slicer) { super(new Container_Slicer(inventoryPlayer, tile_slicer)); this.tile_slicer = tile_slicer; } @Override protected void drawGuiContainerForegroundLayer(int param1, int param2) { fontRendererObj.drawString("Slicer", 8, 6, 4210752); fontRendererObj.drawString(StatCollector.translateToLocal("container.inventory"), 8, ySize-96+2, 4210752); } @Override protected void drawGuiContainerBackgroundLayer(float p_146976_1_, int p_146976_2_, int p_146976_3_) { this.mc.renderEngine.bindTexture(new ResourceLocation("trekkiecub_techythings:textures/gui/slicer.png")); int x = (this.width - this.xSize)/2; int y = (this.height - this.ySize)/2; this.drawTexturedModalRect(x, y, 0, 0, this.xSize, this.ySize); int i1 = this.tile_slicer.getProgressScaled(24); this.drawTexturedModalRect(x + 79, y + 34, 176, 14, i1 + 1, 16); } }
-
Sorry, I didn't include the rest of the items with that bag that are available. The enchanted book is only one possibility, and I have other items that can be generated by the bag. Also, I've now got a new problem: where to get the Random for that method from. I could make a new one, but I'm hesitant to do so. This is the code I have. I haven't added the modified book to the chest hook yet I'd like to include a pre-made Random variable where I'm making the new one, but not sure where to get it from. @EventHandler public void preInit(FMLPreInitializationEvent event) { ItemInit.init(); ItemInit.register(); ChestHooks.init(); } public class ChestHooks { static ChestGenHooks loot_bag_common = ChestGenHooks.getInfo(VenturyThings.LOOT_BAG_COMMON); static ChestGenHooks loot_bag_uncommon = ChestGenHooks.getInfo(VenturyThings.LOOT_BAG_UNCOMMON); static ChestGenHooks loot_bag_rare = ChestGenHooks.getInfo(VenturyThings.LOOT_BAG_RARE); static ChestGenHooks loot_bag_epic = ChestGenHooks.getInfo(VenturyThings.LOOT_BAG_EPIC); static ChestGenHooks loot_bag_mythical = ChestGenHooks.getInfo(VenturyThings.LOOT_BAG_MYTHICAL); static ChestGenHooks loot_bag_trash = ChestGenHooks.getInfo(VenturyThings.LOOT_BAG_TRASH); static ChestGenHooks loot_trader = ChestGenHooks.getInfo(VenturyThings.LOOT_TRADER); public static void init() { // Loot Bag - Rare ItemStack lowbook = new ItemStack(Items.book, 1, 0); EnchantmentHelper.addRandomEnchantment(new Random(), lowbook, 10); loot_bag_rare.addItem(new WeightedRandomChestContent(new ItemStack(Item.getItemFromBlock(Blocks.anvil)), 1, 3, 20)); loot_bag_rare.addItem(new WeightedRandomChestContent(new ItemStack(Item.getItemFromBlock(Blocks.coal_block)), 1, 3, 20)); loot_bag_rare.addItem(new WeightedRandomChestContent(new ItemStack(Item.getItemFromBlock(Blocks.redstone_block)), 1, 3, 20)); loot_bag_rare.addItem(new WeightedRandomChestContent(new ItemStack(Items.golden_boots), 1, 1, 20)); loot_bag_rare.addItem(new WeightedRandomChestContent(new ItemStack(Items.golden_chestplate), 1, 1, 20)); loot_bag_rare.addItem(new WeightedRandomChestContent(new ItemStack(Items.golden_leggings), 1, 1, 20)); loot_bag_rare.addItem(new WeightedRandomChestContent(new ItemStack(Items.golden_helmet), 1, 1, 20)); loot_bag_rare.addItem(new WeightedRandomChestContent(new ItemStack(Items.iron_boots), 1, 1, 20)); loot_bag_rare.addItem(new WeightedRandomChestContent(new ItemStack(Items.iron_chestplate), 1, 1, 20)); loot_bag_rare.addItem(new WeightedRandomChestContent(new ItemStack(Items.iron_leggings), 1, 1, 20)); loot_bag_rare.addItem(new WeightedRandomChestContent(new ItemStack(Items.iron_helmet), 1, 1, 20)); loot_bag_rare.addItem(new WeightedRandomChestContent(new ItemStack(Items.ender_pearl), 1, 4, 20)); loot_bag_rare.addItem(new WeightedRandomChestContent(new ItemStack(Items.glowstone_dust), 3, 7, 20)); loot_bag_rare.addItem(new WeightedRandomChestContent(new ItemStack(Items.iron_axe), 1, 1, 20)); loot_bag_rare.addItem(new WeightedRandomChestContent(new ItemStack(Items.iron_shovel), 1, 1, 20)); loot_bag_rare.addItem(new WeightedRandomChestContent(new ItemStack(Items.iron_sword), 1, 1, 20)); loot_bag_rare.addItem(new WeightedRandomChestContent(new ItemStack(Items.iron_pickaxe), 1, 1, 20)); loot_bag_rare.addItem(new WeightedRandomChestContent(new ItemStack(Items.iron_hoe), 1, 1, 20)); loot_bag_rare.addItem(new WeightedRandomChestContent(new ItemStack(Items.golden_axe), 1, 1, 20)); loot_bag_rare.addItem(new WeightedRandomChestContent(new ItemStack(Items.golden_shovel), 1, 1, 20)); loot_bag_rare.addItem(new WeightedRandomChestContent(new ItemStack(Items.golden_sword), 1, 1, 20)); loot_bag_rare.addItem(new WeightedRandomChestContent(new ItemStack(Items.golden_pickaxe), 1, 1, 20)); loot_bag_rare.addItem(new WeightedRandomChestContent(new ItemStack(Items.golden_hoe), 1, 1, 20)); loot_bag_rare.setMin(1); loot_bag_rare.setMax(4); } []
-
I have some items that function as loot bags, where the bag, when used, gives random items to the player. The bags come in tiers, with different items for each tier of bag. I'm using ChestGenHooks for the bag content. I'd like to add enchanted books whose level increases with the tier of loot bag. I've got a bag generating enchanted books, but the enchantments on the book are random. Here's the code I'm using. The top two lines are taken directly from the ChestGenHooks file and are used for adding randomly enchanted books to various generated chests. I'd like to control the level of the enchantments, but I'm not sure how to do this. Does anyone know how to do this, if it's possible? ItemStack book = new ItemStack(Items.enchanted_book, 1, 0); WeightedRandomChestContent tmp = new WeightedRandomChestContent(book, 1, 1, 1); loot_bag_rare.addItem(tmp);
-
Anyone? If one of these can be resolved by digging a little deeper (aka me being either lazy or stupid) please go ahead and tell me so I can try to get these resolved.
-
I'm having a few problems when trying to create a custom building in a village. 1) I'm trying to make the structure out of Polished Andesite. Unfortunately, some of the blocks are being replaced with ores, gravel, other stone types, etc. I think the problem is the order in which certain items are created in the world, with ores being generated after villages and the ore generation replacing some stone blocks, regardless of block state. Is there a workaround for this that doesn't involve modification of vanilla files? 2) Some of the blocks within the building are not rotating correctly with the building. Some, like stairs and torches, are rotating correctly, but chests and trapdoors aren't. Considering furnaces and chests in vanilla village buildings aren't consistently rotating either, this looks like a problem with vanilla Minecraft itself. Has anyone found a workaround? 3) How do I change which blocks are being used to construct the building depending on the current biome? I'm not sure how to find the current position in the world where the structure is being spawned. If I knew how to do that, I could probably find the local biome with the World object. I know vanilla villages, at some point, had a method where all of the various materials in a village would be replaced with their desert counterparts if the village was in a desert, but I forgot where that was located and don't know how to make it change my building. If anyone can help with these issues I'd greatly appreciate it!
-
I think you have to create a new BlockPos based on the x and z values passed into the generateOverworld function. Granted, using these values as-is will only generate your blocks in the corner of the chunk closest to the origin, so you have to add some randomness to the position you use for the generate() function if you don't want this result. Also, you have to find the height you want to generate at and include that in the BlockPos. I haven't worked with 1.8 yet, but it seems that not a lot has changed between 1.7 and 1.8 when it comes to determining a location in Minecraft. Try looking at some tutorials for 1.7 and see if you can adapt them to 1.8
-
So I'm wondering what went through the collective minds over at Mojang regarding how materials are balanced. The number of uses an item has seems to be roughly proportional to their real-life counterparts' Mohs hardness, as is their strength against an entity. However, I'm trying to figure out how they balanced Efficiency, as well as Enchantability. Enchantability seems to be a rough approximation of how much magic-related myth surrounds a material (although I would expect diamond to be higher than iron, which is not the case), but Efficiency isn't making much sense to me. Wood is 2.0, Stone is 4.0, Iron 6, Diamond 8, Gold 12. Did they just increment the numbers by two based on the hardness of the material and then decide to make Gold max just to make gold tools useful, or is there a reason based on real-life materials? I ask, of course, because I'm looking to add custom tools and I'm trying to figure out balancing.