Jump to content

Recommended Posts

Posted (edited)

Hello! my issue is that I'm trying to make a crystal infuser of sorts, it takes in a diamond, spits out a crystal

And, it works! almost, the player can access the output slot and place items inside it, which I don't think is the way I should go about it

 

Is there any way I can make the output slot only modifiable within this class, as in the player trying to insert an item wouldn't do anything but the player can still extract items from the output slot

I've got my CrystalInfuserTile class below, as this is where the fault is ( I think ), two other classes deal with the block too, the container and main block itself, if needed (or in any way useful) I shall place those in also.

 

Please don't rinse me too hard, this is my first shot at this.

Who am I kidding, rinse away ❤️

 

EDIT** Realised I have a github repo you could just look at...

https://github.com/MistaOmega/Opes/blob/master/src/main/java/mistaomega/opes/TileEntity/CrystalInfuserTile.java

 

Edited by MistaOmega
Added github repo, removed fatty code block spoiler
Posted

You need two item stack handlers, one that's private that the machine can insert to, and one that you expose via getCapability that can only be extracted from (and which wraps around the former).

 

https://github.com/Draco18s/ReasonableRealism/blob/1.14.4/src/main/java/com/draco18s/harderores/entity/SifterTileEntity.java#L51-L52

  • Like 1
  • Thanks 2

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.

Posted (edited)

1. Use a custom slot in your container and override Slot#isItemValid to return false.

2. Create another item handler for the output and override the methods to not allow inserting item into it.

Edited by DavidM
  • Thanks 1

Some tips:

Spoiler

Modder Support:

Spoiler

1. Do not follow tutorials on YouTube, especially TechnoVision (previously called Loremaster) and HarryTalks, due to their promotion of bad practice and usage of outdated code.

2. Always post your code.

3. Never copy and paste code. You won't learn anything from doing that.

4. 

Quote

Programming via Eclipse's hotfixes will get you nowhere

5. Learn to use your IDE, especially the debugger.

6.

Quote

The "picture that's worth 1000 words" only works if there's an obvious problem or a freehand red circle around it.

Support & Bug Reports:

Spoiler

1. Read the EAQ before asking for help. Remember to provide the appropriate log(s).

2. Versions below 1.11 are no longer supported due to their age. Update to a modern version of Minecraft to receive support.

 

 

Posted
7 hours ago, Draco18s said:

You need two item stack handlers, one that's private that the machine can insert to, and one that you expose via getCapability that can only be extracted from (and which wraps around the former).

 

https://github.com/Draco18s/ReasonableRealism/blob/1.14.4/src/main/java/com/draco18s/harderores/entity/SifterTileEntity.java#L51-L52

 

7 hours ago, DavidM said:

1. Use a custom slot in your container and override Slot#isItemValid to return false.

2. Create another item handler for the output and override the methods to not allow inserting item into it.

 

3 hours ago, TheGreyGhost said:

howdy

 

There's a working tutorial example of custom container here (furnace)

https://github.com/TheGreyGhost/MinecraftByExample/tree/master/src/main/java/minecraftbyexample/mbe31_inventory_furnace

It uses a similar method to what David M said, i.e. a custom OutputSlot for the GUI, which stops the player adding but not your code.

 

-TGG

 

Thank you all 3 of you, you've helped me greatly improve my general understanding of what is actually going on here :)

if I may be as crude as to ask, which of the two implementations (adding a custom slot or secondary output handler ) would be considered most programatically correct, from a performance standpoint. I do like to try and do more efficient things, of course I'm just learning at the moment, but good practise is good practise ❤️

Posted
27 minutes ago, MistaOmega said:

if I may be as crude as to ask, which of the two implementations (adding a custom slot or secondary output handler ) would be considered most programatically correct, from a performance standpoint.

You should do both.

The custom slot (smoothly) prevents the player from inserting into the slot in the container, while the custom item handler capability prevents other tile entities from inserting item into the slot.

  • Thanks 1

Some tips:

Spoiler

Modder Support:

Spoiler

1. Do not follow tutorials on YouTube, especially TechnoVision (previously called Loremaster) and HarryTalks, due to their promotion of bad practice and usage of outdated code.

2. Always post your code.

3. Never copy and paste code. You won't learn anything from doing that.

4. 

Quote

Programming via Eclipse's hotfixes will get you nowhere

5. Learn to use your IDE, especially the debugger.

6.

Quote

The "picture that's worth 1000 words" only works if there's an obvious problem or a freehand red circle around it.

Support & Bug Reports:

Spoiler

1. Read the EAQ before asking for help. Remember to provide the appropriate log(s).

2. Versions below 1.11 are no longer supported due to their age. Update to a modern version of Minecraft to receive support.

 

 

Posted
9 minutes ago, DavidM said:

You should do both.

The custom slot (smoothly) prevents the player from inserting into the slot in the container, while the custom item handler capability prevents other tile entities from inserting item into the slot.

Alright, got it, thank you again for the help ❤️

Posted
11 hours ago, diesieben07 said:

SlotItemHandler#isItemValid already calls IItemHandler#isItemValid. No need to duplicate the logic and no need for a custom slot class. You can just put the logic in IItemHandler and the slot will respect it.

So make an outputSlotHandler, extend the itemstack handler, and utilise the isItemValid method to just return false? rather than having an outputSlot class that extends the SlotItemHandler and handling the isItemValid in there?

 

just to make sure I'm not being a proper idiot

Sorry if all that sounded like garbage, I only learnt Java the past year for my degree, I'm by no means an expert in this :D

Posted
3 hours ago, MistaOmega said:

So make an outputSlotHandler, extend the itemstack handler, and utilise the isItemValid method to just return false? rather than having an outputSlot class that extends the SlotItemHandler and handling the isItemValid in there?

With the SlotItemHandler it would be a bit different.

Since SlotItemHandler checks whether the inserted item can be accepted into the item handler, there is no need to add checks to the slot. Instead, you only need to create another IItemHandler capability for the output slot that does not accept the inserting of items (the SlotItemHandler will respect the isItemValid check).

  • Thanks 1

Some tips:

Spoiler

Modder Support:

Spoiler

1. Do not follow tutorials on YouTube, especially TechnoVision (previously called Loremaster) and HarryTalks, due to their promotion of bad practice and usage of outdated code.

2. Always post your code.

3. Never copy and paste code. You won't learn anything from doing that.

4. 

Quote

Programming via Eclipse's hotfixes will get you nowhere

5. Learn to use your IDE, especially the debugger.

6.

Quote

The "picture that's worth 1000 words" only works if there's an obvious problem or a freehand red circle around it.

Support & Bug Reports:

Spoiler

1. Read the EAQ before asking for help. Remember to provide the appropriate log(s).

2. Versions below 1.11 are no longer supported due to their age. Update to a modern version of Minecraft to receive support.

 

 

Posted
8 hours ago, DavidM said:

With the SlotItemHandler it would be a bit different.

Since SlotItemHandler checks whether the inserted item can be accepted into the item handler, there is no need to add checks to the slot. Instead, you only need to create another IItemHandler capability for the output slot that does not accept the inserting of items (the SlotItemHandler will respect the isItemValid check).

Ah, okay that makes sense

 

Thank you all again ❤️

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.

Announcements



×
×
  • Create New...

Important Information

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