Jump to content

[1.12.2] Prevent all Inventory interaction server-side


Recommended Posts

Posted (edited)

Should probably start with that I've read multiple posts and checked various github repos / tutorials about this, but most of them seem under the impression that a client-side plugin is involved too, which isn't for me the case.
Since it's server-side, there simply has to be a way to prevent a user from grabbing the item, as the server stores the data and not the client (else you could just spawn in items with a hacked client too).

Currently I have a custom IInventory with this method:

@Override
public ItemStack removeStackFromSlot(int i)
{
	return ItemStack.EMPTY;
}

 

Assign custom slots, albeit a bit of a hackish way, since I cannot find the "addSlotToContainer" method anywhere, via:
 

List<Slot> c = fakePlayer.get().inventoryContainer.inventorySlots;
  
//this is inside a for-loop with variable: i
c.set(i, new MyCustomSlot(inventory, i, 0, 0));
inventory.setInventorySlotContents(i, itemStack);

 

Where the MyCustomSlot class contains:
 

@Override
public ItemStack onTake(EntityPlayer thePlayer, ItemStack stack)
{
    return ItemStack.EMPTY;
}

/**
 * Return whether this slot's stack can be taken from this slot.
 */
@Override
public boolean canTakeStack(EntityPlayer playerIn)
{
    return false;
}

/**
 * Returns if this slot contains a stack.
 */
@Override
public boolean getHasStack()
{
    return false;
}
    
/**
 * Helper method to put a stack in the slot.
 */
@Override
public void putStack(ItemStack stack)
{
    //DO nothing.
}

 

This prevents the click events so far, but shift-click still works (as well as putting items into the inventory, which I dont want to happen either).

And this is the point where I'm stuck, since I have no idea how I can make my fakeplayer use my Custom Container to override the "transferStackInSlot" method which would prevent the shift-click.

It's really frustrating to have everything working, but that a simple InventoryInteractEvent or something similar just isn't implemented, so I'm really hoping someone can help me on the right track here.
Feel like it's worth noting that I don't mind a hackish way if that's required. It's not a mod thats going to be published, it's for private use only.

Edited by xorinzor
Posted

You will probably need a custom ItemStackHandler class that prevents the extraction.

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)

After multiple different attempts I haven't really gotten a single step further unfortunately.

I did change my code where I extend the FakePlayerFactory, FakePlayer and it's PlayerInventory and InventoryContainer (with subsequent Slot's) classes, but overriding all methods relating to getting, setting and transferring ItemStacks didn't seem to prevent the shift+click either. Regular grabbing still gets prevented though, inserting items unfortunately is still possible too.

EDIT: changed the title of the topic too, as I feel this may better reflect the goal.

EDIT 2: The classes that I currently have

CustomFakePlayer and CustomFakePlayerFactory

  Reveal hidden contents

 

CustomInventory

  Reveal hidden contents

 

CustomContainerPlayer
 

  Reveal hidden contents


CustomSlot
 

  Reveal hidden contents

 

Edited by xorinzor
Posted
  On 1/15/2018 at 11:14 AM, xorinzor said:

Interesting, haven't seen any of the resources I've read use such a class. I'll look into that. Thanks.

Expand  

It's a Capability. Vanilla doesn't use it, but there are wrappers around all of the IInventory implementations that return an ItemStackHandler.

Not sure how you'd go about making it do its thing in this case, though.

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
  On 1/15/2018 at 4:48 PM, Draco18s said:

It's a Capability. Vanilla doesn't use it, but there are wrappers around all of the IInventory implementations that return an ItemStackHandler.

Not sure how you'd go about making it do its thing in this case, though.

Expand  

I havent found any references to the ItemStackHandler yet though, and the examples and tutorials about Capabilities that I've seen on Capabilities are really confusing :/ 
 

Posted

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.

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.