Jump to content

xorinzor

Members
  • Posts

    15
  • Joined

  • Last visited

xorinzor's Achievements

Tree Puncher

Tree Puncher (2/8)

1

Reputation

  1. 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
  2. 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 CustomInventory CustomContainerPlayer CustomSlot
  3. Awesome. That's exactly the kind of method I was looking for.
  4. Interesting, haven't seen any of the resources I've read use such a class. I'll look into that. Thanks.
  5. No that's not required, you can use ItemStack.EMPTY safely.
  6. Like Kitten said, you will need to modify their AI Pathfinding since that code still assumes leaves are a solid block and as such won't stop to reach their PathPoint until achieved (resulting in the jumping behaviour).
  7. 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.
  8. No, I meant in the literal way Not counting the old-school beeping of the motherboard here
  9. Oh, right, I did read the documentation, but misinterpreted the client/server side way. Should've figured since servers can't play sounds. derp. I don't check client or server side, since my mod is just a customization for the experience on my server. Good feedback on the SoundEvent though, that definitely helps!
  10. I'm trying to play a sound-effect for a player, via server-side code. However, none of these seem to trigger the sound effect, leaving me wondering if vanilla sounds use a different notation: ResourceLocation location = new ResourceLocation("minecraft:block.note.hat"); ResourceLocation location = new ResourceLocation("minecraft", "block.note.hat"); ResourceLocation location = new ResourceLocation("block.note.hat"); and using them with: player.world.playSound(player, player.getPosition(), new SoundEvent(location), SoundCategory.MASTER, 1, 1); What's going wrong here?
  11. haha oh boy, I'd rather not This seems to work, so I'll just go with it. public void someMethod() { checkFreeSlot: { for(int i=0; i < 36; i++) { if(player.inventory.getStackInSlot(i).equals(ItemStack.EMPTY)) { break checkFreeSlot; } } //Failed check return; } //Check passed, do something. }
  12. Yea, all it needs to do is just check for a empty spot. Was hoping a iterator wouldn't be necessary, but I guess not haha.
  13. So, maybe I'm just trying to cut corners here, but none of these IF-statements seem to be returning true, despite the inventory definitely having empty slots. if(player.inventory.hasItemStack(ItemStack.EMPTY)) { //Do something } if(player.inventory.hasItemStack(new ItemStack(Items.AIR))) { //Do something } if(player.inventory.hasItemStack(new ItemStack(Blocks.AIR))) { //Do something } Am I really going to have to add the code to iterate over all slots in the inventory? or is there a much simpler way that I'm just not seeing here? (something along the lines of, less = more. Especially when it comes to readability). EDIT: Probably worth noting, this is server-side code.
  14. Hi, I've been trying to make a server-side mod to open up a regular chest inventory screen on a client and display some items, but for some reason the screen either flashes very briefly, or just doesnt open at all. I thought maybe it was something to do with setting Inventory slot contents, but after commenting out that code, the problem persisted. This is the class that opens up the inventory as well as updates it (haven't gotten to that part yet though.) public class RandOMat { private final EntityPlayerMP target; private final EntiyPlayerMP fakePlayer; private int stepCounter = 0; private int counterMax = 5; public RandOMat(OxideForgeVotifier plugin, EntityPlayerMP target) { this.target = target; //Create a fake player for our GUI //This method basically just returns FakePlayerFactory.get(world, new GameProfile(UUID.randomUUID(), "MyFakePlayer")); fakePlayer = plugin.getFakePlayerManager().getFakePlayer(target.getServerWorld()); ItemStack filler = new ItemStack(Blocks.GLASS_PANE, 1, 0); /*for(int i=0; i < 9*5; i++) { this.inventory.setInventorySlotContents(i, filler); } */ //Show the GUI to the player target.displayGUIChest(fakePlayer.inventory); } private void updateInventory() { //Do some things here. //Show the GUI to the player (Doing this makes the inventory flash very briefly every so often, before instantly closing again) //target.displayGUIChest(fakePlayer.inventory); ResourceLocation location = new ResourceLocation("minecraft", "block.note.hat"); this.target.world.playSound(this.target, this.target.getPosition(), new SoundEvent(location), SoundCategory.MASTER, 1, 1); } public void doTick() { if(stepCounter >= counterMax) { updateInventory(); stepCounter = 0; } stepCounter++; } } I read about fakeplayers not being able to do a lot of things, but didn't see anything about them not having an inventory. Was this perhaps just a part missing from the documentation? Or am I missing something else here? EDIT: nevermind, looking again at the code from https://github.com/LatvianModder/FTBUtilities/blob/master/src/main/java/com/feed_the_beast/ftbutilities/cmd/InvSeeInventory.java I realized that I messed it up by setting the method "isUsableByPlayer" to return false. Not quite sure why I did that either. (It's not shown in my example here that I use that extra class to wrap the inventory in because when posting here I thought it was obsolete. Mainly since in Spigot/Sponge development, it wasnt required) Problem solved anyway!
×
×
  • Create New...

Important Information

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