Jump to content

[1.10.2] Adding item from belt in chest


Egietje

Recommended Posts

Hello, I have a belt block (well 2 but) and I want to make it so if the belt runs directly into a chest it will put the item in the chest, it works but only if there allready is at least one of that item as a seperate stack (and not a full stack) but how can I make it so if there is not an available place in the chest it will just put it an empty slot? My code so far (just the onEntityCollidedWithBlock method):

@Override
public void onEntityCollidedWithBlock(World worldIn, BlockPos pos, IBlockState state, Entity entityIn) {
	EnumFacing enumfacing = (EnumFacing)state.getValue(FACING);

	switch (enumfacing) {
            case WEST:
            	if(entityIn instanceof EntityLivingBase || entityIn instanceof EntityItem) {
        			entityIn.motionX = -1.25;
        			entityIn.motionZ *= 0.2;
        		}
            	if(entityIn instanceof EntityItem) {
            		IBlockState westState = worldIn.getBlockState(pos.west());
            		Block westBlock = westState.getBlock();
            		EntityItem entityItem = (EntityItem) entityIn;
            		if(westBlock.equals(Blocks.CHEST)) {
            			BlockChest chestWest = (BlockChest) westBlock;
                		ILockableContainer container = chestWest.getContainer(worldIn, pos.west(), false);
            			for (int i = 0;i < container.getSizeInventory();i++) {
            				if (container.getStackInSlot(i) != null) {
            					if (container.getStackInSlot(i).getItem().equals(entityItem.getEntityItem().getItem())) {
                    				if (container.getStackInSlot(i).stackSize < 64) {
                    					container.getStackInSlot(i).stackSize++;
                    					entityItem.attackEntityFrom(DamageSource.fall, 500);
                    				}
                    			}
                			} else {
                			}
            			}
            		}
            	}
                break;
            case EAST:
            	if(entityIn instanceof EntityLivingBase || entityIn instanceof EntityItem) {
        			entityIn.motionX = 1.25;
        			entityIn.motionZ *= 0.2;
        		}
                break;
            case NORTH:
            	if(entityIn instanceof EntityLivingBase || entityIn instanceof EntityItem) {
        			entityIn.motionZ = -1.25;
        			entityIn.motionX *= 0.2;
        		}
                break;
            case SOUTH:
            	if(entityIn instanceof EntityLivingBase || entityIn instanceof EntityItem) {
        			entityIn.motionZ = 1.25;
        			entityIn.motionX *= 0.2;
        		}
            	break;
	case DOWN:
		break;
	case UP:
		break;
	default:
		break;
        }
}

Link to comment
Share on other sites

I know, but how can I make it so if there is nothing in a slot it will put the item from the belt there?

setInventorySlotContents(...)

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

mostly pseudo code, don't have access to my IDE atm.

//Checking each possible slot
for(i = 0; i < slots; i++){
   //If one is null
   if(getSlot(i) == null){
      //change the slot from null, to new itemstack
      setInventorySlotContents(...);
      break;
   }
}

Also previously known as eAndPi.

"Pi, is there a station coming up where we can board your train of thought?" -Kronnn

Published Mods: Underworld

Handy links: Vic_'s Forge events Own WIP Tutorials.

Link to comment
Share on other sites

But how would I check if there isn't an item?

// A check if there is an Item
if (container.getStackInSlot(i) != null) {
} else // Check if there is not an item.

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

ah, I needed to add a break; to the else

Still doesn't work, I now have this:

	public void addItemToChest(BlockPos pos, World worldIn, Entity entityIn) {
	IBlockState state = worldIn.getBlockState(pos);
	Block block = state.getBlock();
	EntityItem entityItem = (EntityItem) entityIn;
	if(block.equals(Blocks.CHEST)) {
		BlockChest chest = (BlockChest) block;
    		ILockableContainer container = chest.getContainer(worldIn, pos, false);
		for (int i = 0;i < container.getSizeInventory();i++) {
			if (container.getStackInSlot(i) != null) {
				if (container.getStackInSlot(i).getItem().equals(entityItem.getEntityItem().getItem())) {
        				if (container.getStackInSlot(i).stackSize < 64) {
        					container.getStackInSlot(i).stackSize++;
        					entityItem.attackEntityFrom(DamageSource.fall, 500);
        				}
        			}
    			} else {
    				container.setInventorySlotContents(i, entityItem.getEntityItem());
    				break;
    			}
		}
	}
}

But when I put an item on it it put 2 stacks in there with 3 items..?

Link to comment
Share on other sites

ah, I needed to add a break; to the else

Still doesn't work, I now have this:

	public void addItemToChest(BlockPos pos, World worldIn, Entity entityIn) {
	IBlockState state = worldIn.getBlockState(pos);
	Block block = state.getBlock();
	EntityItem entityItem = (EntityItem) entityIn;
	if(block.equals(Blocks.CHEST)) {
		BlockChest chest = (BlockChest) block;
    		ILockableContainer container = chest.getContainer(worldIn, pos, false);
		for (int i = 0;i < container.getSizeInventory();i++) {
			if (container.getStackInSlot(i) != null) {
				if (container.getStackInSlot(i).getItem().equals(entityItem.getEntityItem().getItem())) {
        				if (container.getStackInSlot(i).stackSize < 64) {
        					container.getStackInSlot(i).stackSize++;
        					entityItem.attackEntityFrom(DamageSource.fall, 500);
        				}
        			}
    			} else {
    				container.setInventorySlotContents(i, entityItem.getEntityItem());
    				break;
    			}
		}
	}
}

But when I put an item on it it put 2 stacks in there with 3 items..?

Try wrapping it in a !world.isRemote

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

Still does the same

You never kill the entity when the itemstack is null also instead of attacking the EntityItem with a damage source just call setDead().

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

Guest
This topic is now closed to further replies.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • So i know for a fact this has been asked before but Render stuff troubles me a little and i didnt find any answer for recent version. I have a custom nausea effect. Currently i add both my nausea effect and the vanilla one for the effect. But the problem is that when I open the inventory, both are listed, while I'd only want mine to show up (both in the inv and on the GUI)   I've arrived to the GameRender (on joined/net/minecraft/client) and also found shaders on client-extra/assets/minecraft/shaders/post and client-extra/assets/minecraft/shaders/program but I'm lost. I understand that its like a regular screen, where I'd render stuff "over" the game depending on data on the server, but If someone could point to the right client and server classes that i can read to see how i can manage this or any tip would be apreciated
    • Let me try and help you with love spells, traditional healing, native healing, fortune telling, witchcraft, psychic readings, black magic, voodoo, herbalist healing, or any other service your may desire within the realm of african native healing, the spirits and the ancestors. I am a sangoma and healer. I could help you to connect with the ancestors , interpret dreams, diagnose illness through divination with bones, and help you heal both physical and spiritual illness. We facilitate the deepening of your relationship to the spirit world and the ancestors. Working in partnership with one\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’s ancestors is a gift representing a close link with the spirit realm as a mediator between the worlds.*   Witchdoctors, or sorcerers, are often purveyors of mutis and charms that cause harm to people. we believe that we are here for only one purpose, to heal through love and compassion.*   African people share a common understanding of the importance of ancestors in daily life. When they have lost touch with their ancestors, illness may result or bad luck. Then a traditional healer, or sangoma, is sought out who may prescribe herbs, changes in lifestyle, a career change, or changes in relationships. The client may also be told to perform a ceremony or purification ritual to appease the ancestors.*   Let us solve your problems using powerful African traditional methods. We believe that our ancestors and spirits give us enlightenment, wisdom, divine guidance, enabling us to overcome obstacles holding your life back. Our knowledge has been passed down through centuries, being refined along the way from generation to generation. We believe in the occult, the paranormal, the spirit world, the mystic world.*   The services here are based on the African Tradition Value system/religion,where we believe the ancestors and spirits play a very important role in society. The ancestors and spirits give guidance and counsel in society. They could enable us to see into the future and give solutions to the problems affecting us. We use rituals, divination, spells, chants and prayers to enable us tackle the task before us.*   I have experience in helping and guiding many people from all over the world. My psychic abilities may help you answer and resolve many unanswered questions
    • Let me try and help you with love spells, traditional healing, native healing, fortune telling, witchcraft, psychic readings, black magic, voodoo, herbalist healing, or any other service your may desire within the realm of african native healing, the spirits and the ancestors. I am a sangoma and healer. I could help you to connect with the ancestors , interpret dreams, diagnose illness through divination with bones, and help you heal both physical and spiritual illness. We facilitate the deepening of your relationship to the spirit world and the ancestors. Working in partnership with one\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’s ancestors is a gift representing a close link with the spirit realm as a mediator between the worlds.*   Witchdoctors, or sorcerers, are often purveyors of mutis and charms that cause harm to people. we believe that we are here for only one purpose, to heal through love and compassion.*   African people share a common understanding of the importance of ancestors in daily life. When they have lost touch with their ancestors, illness may result or bad luck. Then a traditional healer, or sangoma, is sought out who may prescribe herbs, changes in lifestyle, a career change, or changes in relationships. The client may also be told to perform a ceremony or purification ritual to appease the ancestors.*   Let us solve your problems using powerful African traditional methods. We believe that our ancestors and spirits give us enlightenment, wisdom, divine guidance, enabling us to overcome obstacles holding your life back. Our knowledge has been passed down through centuries, being refined along the way from generation to generation. We believe in the occult, the paranormal, the spirit world, the mystic world.*   The services here are based on the African Tradition Value system/religion,where we believe the ancestors and spirits play a very important role in society. The ancestors and spirits give guidance and counsel in society. They could enable us to see into the future and give solutions to the problems affecting us. We use rituals, divination, spells, chants and prayers to enable us tackle the task before us.*   I have experience in helping and guiding many people from all over the world. My psychic abilities may help you answer and resolve many unanswered questions
    • Let me try and help you with love spells, traditional healing, native healing, fortune telling, witchcraft, psychic readings, black magic, voodoo, herbalist healing, or any other service your may desire within the realm of african native healing, the spirits and the ancestors. I am a sangoma and healer. I could help you to connect with the ancestors , interpret dreams, diagnose illness through divination with bones, and help you heal both physical and spiritual illness. We facilitate the deepening of your relationship to the spirit world and the ancestors. Working in partnership with one\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’s ancestors is a gift representing a close link with the spirit realm as a mediator between the worlds.*   Witchdoctors, or sorcerers, are often purveyors of mutis and charms that cause harm to people. we believe that we are here for only one purpose, to heal through love and compassion.*   African people share a common understanding of the importance of ancestors in daily life. When they have lost touch with their ancestors, illness may result or bad luck. Then a traditional healer, or sangoma, is sought out who may prescribe herbs, changes in lifestyle, a career change, or changes in relationships. The client may also be told to perform a ceremony or purification ritual to appease the ancestors.*   Let us solve your problems using powerful African traditional methods. We believe that our ancestors and spirits give us enlightenment, wisdom, divine guidance, enabling us to overcome obstacles holding your life back. Our knowledge has been passed down through centuries, being refined along the way from generation to generation. We believe in the occult, the paranormal, the spirit world, the mystic world.*   The services here are based on the African Tradition Value system/religion,where we believe the ancestors and spirits play a very important role in society. The ancestors and spirits give guidance and counsel in society. They could enable us to see into the future and give solutions to the problems affecting us. We use rituals, divination, spells, chants and prayers to enable us tackle the task before us.*   I have experience in helping and guiding many people from all over the world. My psychic abilities may help you answer and resolve many unanswered questions
    • Let me try and help you with love spells, traditional healing, native healing, fortune telling, witchcraft, psychic readings, black magic, voodoo, herbalist healing, or any other service your may desire within the realm of african native healing, the spirits and the ancestors. I am a sangoma and healer. I could help you to connect with the ancestors , interpret dreams, diagnose illness through divination with bones, and help you heal both physical and spiritual illness. We facilitate the deepening of your relationship to the spirit world and the ancestors. Working in partnership with one\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’s ancestors is a gift representing a close link with the spirit realm as a mediator between the worlds.*   Witchdoctors, or sorcerers, are often purveyors of mutis and charms that cause harm to people. we believe that we are here for only one purpose, to heal through love and compassion.*   African people share a common understanding of the importance of ancestors in daily life. When they have lost touch with their ancestors, illness may result or bad luck. Then a traditional healer, or sangoma, is sought out who may prescribe herbs, changes in lifestyle, a career change, or changes in relationships. The client may also be told to perform a ceremony or purification ritual to appease the ancestors.*   Let us solve your problems using powerful African traditional methods. We believe that our ancestors and spirits give us enlightenment, wisdom, divine guidance, enabling us to overcome obstacles holding your life back. Our knowledge has been passed down through centuries, being refined along the way from generation to generation. We believe in the occult, the paranormal, the spirit world, the mystic world.*   The services here are based on the African Tradition Value system/religion,where we believe the ancestors and spirits play a very important role in society. The ancestors and spirits give guidance and counsel in society. They could enable us to see into the future and give solutions to the problems affecting us. We use rituals, divination, spells, chants and prayers to enable us tackle the task before us.*   I have experience in helping and guiding many people from all over the world. My psychic abilities may help you answer and resolve many unanswered questions
  • Topics

×
×
  • Create New...

Important Information

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