Jump to content

[1.7.10] Duplicate item entity is spawning when it shouldn't


TrekkieCub314

Recommended Posts

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) {
}

}

 

 

Link to comment
Share on other sites

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.

It is mostly done, if not it is complete.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

Is Forge for 1.10 complete?

 

Has been for months.

There's always updates, yes, but it's fully functional.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • हथियार व्यापारियों की चमक आज के समय में भारत और दुनिया के विभिन्न हिस्सों में तेजी से बढ़ रही है। स्वीडन की स्थित संस्था सिपरी की नवीनतम रिपोर्ट के अनुसार, विश्व भर में विभिन्न देश अब पूर्व कभी नहीं देखे गए हथियारों और सैन्य सामग्रियों पर धन का व्यय कर रहे हैं। वैश्विक संघर्षों के बढ़ते संकेतों के कारण, विश्व के कई हिस्सों में युद्ध की संभावनाएं बढ़ रही हैं। पश्चिमी एशिया में युद्ध की आग फैल रही है, जबकि दक्षिण चीन सागर और ताइवान में भी तनाव बढ़ रहा है। भारत-चीन सीमा पर भी स्थिति चिंताजनक है। इन घटनाओं के परिणामस्वरूप, विभिन्न देशों की प्राथमिकताएं बदल रही हैं, और हथियार व्यापारियों का धंधा आजकल चमक उठा है। सिपरी की रिपोर्ट के अनुसार, 2023 में वैश्विक सैन्य खर्च एक नया रिकॉर्ड स्थापित किया गया है। 2022 की तुलना में, 2023 में सैन्य खर्च 6.8 फीसदी बढ़कर 24.4 ट्रिलियन डॉलर पर पहुंच गया। इसके पीछे कुछ विशेष कारण हैं, जिनमें दुनिया भर में तनाव बढ़ना और अद्यतित सैन्य तैयारियों की आवश्यकता शामिल है। इस वृद्धि में, भारत जैसे देशों का योगदान भी अधिक है। भारत ने भी अपने सैन्य खर्चों में वृद्धि की है, और यह दुनिया के सबसे बड़े और सबसे प्रभावशाली राष्ट्रों में एक बन गया है। इसके अलावा, अमेरिका, चीन, और रूस भी सैन्य खर्च में वृद्धि की हैं, जिससे विश्व सुरक्षा में नए दायरे खुले हैं। संभावनाओं के इस नए मंच पर, दुनिया के सक्षम देश अब अपने सैन्य तैयारियों में ज्यादा ध्यान दे रहे हैं। यह वृद्धि विकास और प्रगति के बजट पर भी प्रभाव डाल रही है, जिससे विभिन्न देशों के आर्थिक प्रगति में बदलाव आ सकता है।   https://www.nayaindia.com/editorial-column/editorial1/arms-sales-increased-in-the-world-454072.html
    • Hello, Hi and I am making a forge 1.12.2 mod and also trying to get a custom model helmet item (I made a joker mask) and exported it to .json format and put it in the ~/namespace/models/item folder. Though, I'm struggling to get the item to render what I want it to be rendered like as I've positioned it in the 'head' window view in blockbench. How did you render out your model? I checked your code and it looks like no references to the actual model are being made. I'm new to this forge modding stuff (was a fabric modder) and I desperately need some help. Is there a way to standardly render out armor models made using blockbench? any methods that one can use? My model in JSON: ```json { "credit": "Made with Blockbench", "texture_size": [160, 160], "textures": { "0": "ydyrn:items/joker_mask_texture", "particle": "ydyrn:items/joker_mask_texture" }, "elements": [ { "from": [0, 0, 0], "to": [16, 16, 1], "faces": { "north": {"uv": [0, 1.7, 16, 14.2], "texture": "#0"}, "east": {"uv": [0, 4, 0.9, 5.6], "texture": "#0"}, "south": {"uv": [0, 5.8, 1.6, 7.4], "texture": "#0"}, "west": {"uv": [0, 1.9, 1.3, 3.5], "texture": "#0"}, "up": {"uv": [0, 3.4, 1.6, 4.2], "texture": "#0"}, "down": {"uv": [0, 9, 1.6, 9.7], "texture": "#0"} } }, { "from": [15.8, 11, 0.5], "to": [16.2, 13, 15], "faces": { "north": {"uv": [7.9, 7.9, 7.94, 8.1], "texture": "#0"}, "east": {"uv": [7.9, 7.9, 9.35, 8.1], "texture": "#0"}, "south": {"uv": [7.9, 7.9, 7.94, 8.1], "texture": "#0"}, "west": {"uv": [7.9, 7.9, 9.35, 8.1], "texture": "#0"}, "up": {"uv": [7.9, 7.9, 7.94, 9.35], "texture": "#0"}, "down": {"uv": [7.9, 7.9, 7.94, 9.35], "texture": "#0"} } }, { "from": [0.2, 11, 14.6], "to": [15.8, 13, 15], "faces": { "north": {"uv": [7.9, 7.9, 9.46, 8.1], "texture": "#0"}, "east": {"uv": [7.9, 7.9, 7.94, 8.1], "texture": "#0"}, "south": {"uv": [7.9, 7.9, 9.46, 8.1], "texture": "#0"}, "west": {"uv": [7.9, 7.9, 7.94, 8.1], "texture": "#0"}, "up": {"uv": [7.9, 7.9, 9.46, 7.94], "texture": "#0"}, "down": {"uv": [7.9, 7.9, 9.46, 7.94], "texture": "#0"} } }, { "from": [-0.2, 11, 0.5], "to": [0.2, 13, 15], "faces": { "north": {"uv": [7.9, 7.9, 7.94, 8.1], "texture": "#0"}, "east": {"uv": [7.9, 7.9, 9.35, 8.1], "texture": "#0"}, "south": {"uv": [7.9, 7.9, 7.94, 8.1], "texture": "#0"}, "west": {"uv": [7.9, 7.9, 9.35, 8.1], "texture": "#0"}, "up": {"uv": [7.9, 7.9, 7.94, 9.35], "texture": "#0"}, "down": {"uv": [7.9, 7.9, 7.94, 9.35], "texture": "#0"} } } ], "display": { "thirdperson_righthand": { "translation": [-0.25, -2.75, 0], "scale": [0.3, 0.3, 0.3] }, "thirdperson_lefthand": { "translation": [-0.25, -2.75, 0], "scale": [0.3, 0.3, 0.3] }, "firstperson_righthand": { "rotation": [-9, 115, 15], "translation": [0, 1.25, -1.75], "scale": [0.5, 0.5, 0.5] }, "firstperson_lefthand": { "rotation": [-9, 115, 15], "translation": [0, 1.25, -1.75], "scale": [0.5, 0.5, 0.5] }, "ground": { "rotation": [40, 0, 0], "translation": [0, -2.5, 0], "scale": [0.5, 0.5, 0.5] }, "gui": { "rotation": [0, 180, 0] }, "head": { "translation": [0, 0, 0.25], "scale": [0.82773, 0.73594, 0.9] }, "fixed": { "translation": [0, 0, 8.75] } }, "groups": [ 0, { "name": "straps", "origin": [0, 0, 0], "color": 0, "children": [1, 2, 3] } ] } ```
    • Add the crash-report or latest.log (logs-folder) with sites like https://paste.ee/ and paste the link to it here  
    • In your config folder, delete the sophisticatedcore-common.toml file and test it again
    • Add the crash-report or latest.log (logs-folder) with sites like https://paste.ee/ and paste the link to it here  
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.