Jump to content

[1.10.2] Problems picking up carrots


Dustpuppy

Recommended Posts

Hi,

it sounds silly, if i say that i have problems picking up carrots, but it's real.

I have a farming station. Works like i want, but not with carrots.

Problem is only at pickup of items.

It destroys the block if the crop is in the age to get harvested. Then it picks up all items inside a given box. It works for wheat + seeds, for potatoes, for my custom wheat.

If i plant carrots, it will pick them up and place into the seed slot, but in no other slot. All other crops will work right. First i was thinking, it's because carrots have no extra seeds, like wheat, but potatoes are working too and they also have no extra seed.

 

This is the part of the code, where i pickup the items.

Spoiler

	public void handlePickup() {
		BlockPos centerOfField = getCenterOfField();

		double posX = centerOfField.getX();
		double posY = centerOfField.getY();
		double posZ = centerOfField.getZ();
		if (!worldObj.isRemote) {
			for (Object obj : worldObj.getEntitiesWithinAABBExcludingEntity(null, new AxisAlignedBB(posX - 3, posY - 3, posZ - 3, posX + 3, posY + 3, posZ + 3))) {
				if (obj instanceof EntityItem) 
				{
					EntityItem item = (EntityItem) obj;
					ItemStack pickupItemStack = item.getEntityItem();
					Item pickupItem = pickupItemStack.getItem();

					// go over all output slots
					for (int i = seedSlot; i < slotSize; i++) 
					{
						ItemStack stackSlot = getStackInSlot(i);
						if (stackSlot == null) 
						{
							if (i == seedSlot && (pickupItem == Items.WHEAT_SEEDS	|| pickupItem == Items.CARROT || pickupItem == Items.POTATO || pickupItem == thewizardmod.plants.StartupCommon.wheatSeeds)) 
							{
								setInventorySlotContents(i, pickupItemStack);
								item.setDead();
								break;
							}
							if (i > seedSlot) {
								setInventorySlotContents(i, pickupItemStack);
								item.setDead();
								break;
							}
						} 
						else 
						{
							Item slotItem = stackSlot.getItem();
							if (pickupItem == slotItem) 
							{
								if (stackSlot.stackSize < getInventoryStackLimit()) 
								{
									stackSlot.stackSize += pickupItemStack.stackSize;
									setInventorySlotContents(i, stackSlot);
									item.setDead();
									break;
								}
							}
						}
					}
				}
			}
		}
	}

 

 

Link to comment
Share on other sites

Wait!

The problem is bigger, then expected. It happens with every crop.

If the machine plants carrots, it will pick them up only until the seed slot is full.

If it plants potatoes,  just fills up the seed slot.

Same for wheat and custom wheat.

If i throw what ever on the field, it will be picked up.

 

Edited by Dustpuppy
Link to comment
Share on other sites

I'm getting mad. Changed the position of some variables. Now it's working, but not for potatos.

Spoiler

	public void handlePickup() {
		BlockPos centerOfField = getCenterOfField();

		double posX = centerOfField.getX();
		double posY = centerOfField.getY();
		double posZ = centerOfField.getZ();
		if (!worldObj.isRemote) {
			for (Object obj : worldObj.getEntitiesWithinAABBExcludingEntity(null, new AxisAlignedBB(posX - 3, posY - 3, posZ - 3, posX + 3, posY + 3, posZ + 3))) {
				if (obj instanceof EntityItem) 
				{

					// go over all output slots
					for (int i = seedSlot; i < slotSize; i++) 
					{
						EntityItem item = (EntityItem) obj;
						ItemStack pickupItemStack = item.getEntityItem();
						Item pickupItem = pickupItemStack.getItem();
						ItemStack stackSlot = getStackInSlot(i);
						if (stackSlot == null) 
						{
							if (i == seedSlot && (pickupItem == Items.WHEAT_SEEDS	|| pickupItem == Items.CARROT || pickupItem == Items.POTATO || pickupItem == thewizardmod.plants.StartupCommon.wheatSeeds)) 
							{
								setInventorySlotContents(i, pickupItemStack);
								item.setDead();
								break;
							}
							if (i > seedSlot) {
								setInventorySlotContents(i, pickupItemStack);
								item.setDead();
								break;
							}
						} 
						else 
						{
							Item slotItem = stackSlot.getItem();
							if (pickupItem == slotItem) 
							{
								if (stackSlot.stackSize < getInventoryStackLimit()) 
								{
									stackSlot.stackSize += pickupItemStack.stackSize;
									setInventorySlotContents(i, stackSlot);
									item.setDead();
									break;
								}
							}
						}
					}
				}
			}
		}
	}

 

 

Link to comment
Share on other sites

You do know about getEntitiesWithinAABB(EntityItem.class, AABB) don't you?

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

Your post made no sense. None.

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

On 9/14/2017 at 0:27 PM, Dustpuppy said:

The problem is bigger, then expected. It happens with every crop.

How much time have you spent stepping through your code in the debugger? Invest an hour or two doing that and then come back with your observations (if you even have any remaining bugs).

Edited by jeffryfisher

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...

Important Information

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