Jump to content

Recommended Posts

Posted

How do I move an item in inventory from cell X to cell Y?
How do I move an item from Inventory X to Box Y of an open chest?
I'm thinking of using the Robot class, i.e. Simulate clicking the mouse buttons, but then you need to know the coordinates of the cells. I do not know how to get them.

I tried to understand the source code of the Inventory Tweaks mod, but I did not understand how it works. It seems, too, with the help of simulation

Posted

Please clarify: What exactly are you trying to acheive. What do you mean by "move an item in inventory". Are you making a custom inventory, an addon for inventory tweaks or perhaps even something totally different?

Posted

Example:
I have potatoes in the inventory in cell X.
My task is to move the potatoes from cell X to cell Y.
The inventory is standard, you just need to move items in it. From one cell to another.

 

It is important that all actions should take place only on the client side

 

Posted

get the stack in slot X with inventory#getStackInSlot(X);

COPY THE STACK

set the stack with inventory#setStackInSlot(Y, copyOfX);

clear the old stack in slot X with inventory#setStackInSlot(X, ItemStack.EMPTY.copy())

 

Make sure to do additional checking king to make sure the itemstack can fit/is allowed to be in that slot etc.

Take a look at Container#transferStackInSlot

About Me

  Reveal hidden contents

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Posted

You don't need to clone the empty stack.

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 10/1/2018 at 3:59 AM, Draco18s said:

You don't need to clone the empty stack.

Expand  

What if some code modifys that stack? Like merges it with a stack that isn’t empty? Won’t that modify ItemStack.EMPTY then?

About Me

  Reveal hidden contents

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Posted
  On 10/1/2018 at 4:02 AM, Cadiboo said:

What if some code modifys that stack? Like merges it with a stack that isn’t empty? Won’t that modify ItemStack.EMPTY then?

Expand  

You can't. ItemStack.EMPTY is meant to be immutable. That's why its a static reference and named the way its named.

 

Its item is Air (and you can't change a stack's item) and Air is always empty.

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 10/1/2018 at 4:08 AM, Draco18s said:

You can't. ItemStack.EMPTY is meant to be immutable. That's why its a static reference and named the way its named.

 

Its item is Air (and you can't change a stack's item) and Air is always empty.

Expand  

Isn’t it’s item null? Point taken that you can’t change the item though

About Me

  Reveal hidden contents

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Posted
  On 10/1/2018 at 4:58 AM, Cadiboo said:

Isn’t it’s item null?

Expand  

That it is, but null has always been Minecraft's air. Block.AIR was null at one point too.

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 10/1/2018 at 3:40 AM, Cadiboo said:

get the stack in slot X with inventory#getStackInSlot(X);

COPY THE STACK

set the stack with inventory#setStackInSlot(Y, copyOfX);

clear the old stack in slot X with inventory#setStackInSlot(X, ItemStack.EMPTY.copy())

Expand  

 

As I understand it, this will not work?

Posted
  On 10/1/2018 at 2:23 PM, NoName_ said:

As I understand it, this will not work?

Expand  

And why do you think that?

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)
    Minecraft.getMinecraft().player.inventory.setInventorySlotContents(0, Minecraft.getMinecraft().player.inventory.getStackInSlot(i).copy());
    Minecraft.getMinecraft().player.inventory.setInventorySlotContents(i, ItemStack.EMPTY);

It does not work on a server. A server does not know that I moved the item. I understand me need to use the exchange of packages?

 

Edited by NoName_
Posted
  On 10/1/2018 at 7:03 PM, NoName_ said:
    Minecraft.getMinecraft().player.inventory.setInventorySlotContents(0, Minecraft.getMinecraft().player.inventory.getStackInSlot(i).copy());
    Minecraft.getMinecraft().player.inventory.setInventorySlotContents(i, ItemStack.EMPTY);
Expand  

That's because your using client-side only code.

 

  On 10/1/2018 at 7:03 PM, NoName_ said:

need to use the exchange of packages?

Expand  

What is "exchange of packets"?

From a user perspective, when do you want this to happen in the inventory? 

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Posted
  On 10/1/2018 at 7:10 PM, larsgerrits said:

What is "exchange of packets"?

Expand  

Packets? I do not know how to properly call it. (NetHandlerPlayClient  and NetHandlerPlayServer)

  On 10/1/2018 at 7:10 PM, larsgerrits said:

From a user perspective, when do you want this to happen in the inventory? 

Expand  

I need a method that changes the place of an item in the inventory.
I do with the example of a hoe. I'm looking for a hoe in the inventory, when I found it, I move it to the first location of the inventory.

 

for (int i = 1; i < 36; i++) {
    if(Minecraft.getMinecraft().player.inventory.getStackInSlot(i).getItem() instanceof ItemHoe){
        Minecraft.getMinecraft().player.inventory.setInventorySlotContents(0, Minecraft.getMinecraft().player.inventory.getStackInSlot(i).copy());
        Minecraft.getMinecraft().player.inventory.setInventorySlotContents(i, ItemStack.EMPTY);
        break;
    }
}
Posted

I recommend placing some breakpoints, manually doing this & seeing what methods get called. Some breakpoints in CPackets and the CLIENTSIDE containers (as your making a client side mod) would be a good place to start. Make sure that your not looking at the servers handling when debugging

About Me

  Reveal hidden contents

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Posted

And with "from a user perspective" I meant: what should the user to do run this action? For example: the user presses a key or clicks a button in a GUI.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Posted

What are the circumstances

About Me

  Reveal hidden contents

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Posted
  On 10/3/2018 at 2:04 PM, NoName_ said:

For example, if the tool breaks. 
Why is it important?

Expand  

What version are you doing this for? And is this only for the client?

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.

Posted
  On 10/3/2018 at 2:15 PM, NoName_ said:

1.12.2 

Yes, only on the client, because it is necessary for the mod to work on other servers

Expand  

And why not just use Inventory Tweaks? It has the same feature you are requesting from us.

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.

Posted
  On 10/3/2018 at 2:19 PM, Animefan8888 said:

And why not just use Inventory Tweaks? It has the same feature you are requesting from us.

Expand  

I do not understand how it works. This is not good. Besides, why add the whole mod if I need one function. In addition, it would not be bad to understand this issue.

Posted
  On 10/3/2018 at 2:22 PM, NoName_ said:

I do not understand how it works. This is not good. In addition, it would not be bad to understand this issue.

Expand  

What you need to do from your original implementation is let the server know that you changed them.

 

  On 10/3/2018 at 2:22 PM, NoName_ said:

Besides, why add the whole mod if I need one function. 

Expand  

Because that one function is already done and the inventory sorting function is a god send.

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.

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Different problem now. https://paste.ee/p/iDo8lS35
    • I would like to have a BoP sapling drop from my block if it is also installed. I think I have done everything and I cannot pinpoint the problem, which is the error in the logs that appears when joining a world:   [Worker-Main-11/ERROR] [ne.mi.co.ForgeHooks/]: Couldn't parse element loot_tables:grasses:blocks/leaves_block com.google.gson.JsonSyntaxException: Expected name to be an item, was unknown string 'biomesoplenty:magic_sapling' My code:   LootItemConditions.CONDITIONS.register(modEventBus); public class LootItemConditions { public static final DeferredRegister<LootItemConditionType> CONDITIONS = DeferredRegister.create(Registries.LOOT_CONDITION_TYPE, Grasses.MOD_ID); public static final RegistryObject<LootItemConditionType> IS_MOD_LOADED = CONDITIONS.register("is_mod_loaded", () -> new LootItemConditionType(new IsModLoaded.ConditionSerializer())); } public class IsModLoaded implements LootItemCondition { private final boolean exists; private final String modID; public IsModLoaded(String modID) { this.exists = ModList.get().isLoaded(modID); this.modID = modID; } @Override public LootItemConditionType getType() { return LootItemConditions.IS_MOD_LOADED.get(); } @Override public boolean test(LootContext context) { return this.exists; } public static LootItemCondition.Builder builder(String modid) { return () -> new IsModLoaded(modid); } public static class ConditionSerializer implements Serializer<IsModLoaded> { @Override public void serialize(JsonObject json, IsModLoaded instance, JsonSerializationContext ctx) { json.addProperty("modid", instance.modID); } @Override public IsModLoaded deserialize(JsonObject json, JsonDeserializationContext ctx) { return new IsModLoaded(GsonHelper.getAsString(json, "modid")); } } } protected LootTable.Builder createLeavesDropsWithModIDCheck(Block selfBlock, Item sapling, Property<?>[] properties, String modIDToCheck, float... chances) { CopyBlockState.Builder blockStateCopyBuilder = CopyBlockState.copyState(selfBlock); for(Property<?> property : properties) { blockStateCopyBuilder.copy(property); } return LootTable.lootTable() .withPool(LootPool.lootPool().setRolls(ConstantValue.exactly(1.0F)) .add(LootItem.lootTableItem(selfBlock) .when(HAS_SHEARS_OR_SILK_TOUCH) .apply(blockStateCopyBuilder))) .withPool(LootPool.lootPool().setRolls(ConstantValue.exactly(1.0F)) .add(this.applyExplosionCondition(selfBlock, LootItem.lootTableItem(sapling)) .when(IsModLoaded.builder(modIDToCheck))) .when(BonusLevelTableCondition.bonusLevelFlatChance(Enchantments.BLOCK_FORTUNE, chances)) .when(HAS_NO_SHEARS_OR_SILK_TOUCH)) .withPool(LootPool.lootPool().name("sticks").setRolls(ConstantValue.exactly(1.0F)) .add(this.applyExplosionDecay(selfBlock, LootItem.lootTableItem(Items.STICK). apply(SetItemCountFunction.setCount(UniformGenerator.between(1.0F, 2.0F)))) .when(BonusLevelTableCondition.bonusLevelFlatChance(Enchantments.BLOCK_FORTUNE, NORMAL_LEAVES_STICK_CHANCES)) .when(HAS_NO_SHEARS_OR_SILK_TOUCH))); } I don't know. Am I making a mistake somewhere? Am I forgetting something? Should there be something else?
  • Topics

×
×
  • Create New...

Important Information

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