Jump to content

[1.10] transferstackinslot! Help!!


JakeNelson1999

Recommended Posts

Hi There, I'm Jake.

 

At the moment I'm trying to work on a mod which lets you transfer all items from the currently open chest to inventory.

 

After looking on the forums for a few hours I found the function transferstackinslot

 

The current code looks like this:

 

 

player.openConainer.transferStackInSlot(player, 1);
player.openContainer.detectAndSendChanges();
player.inventoryContainer.detectAndSendChanges();

 

The only issue is the items aren't actually moved, it's only client sided, so once it's updated the items disappear.

 

Help would be greatly appreciated!!

 

Jake.

 

Link to comment
Share on other sites

Hi There, I'm Jake.

 

At the moment I'm trying to work on a mod which lets you transfer all items from the currently open chest to inventory.

 

After looking on the forums for a few hours I found the function transferstackinslot

 

The current code looks like this:

 

 

player.openConainer.transferStackInSlot(player, 1);
player.openContainer.detectAndSendChanges();
player.inventoryContainer.detectAndSendChanges();

 

The only issue is the items aren't actually moved, it's only client sided, so once it's updated the items disappear.

 

Help would be greatly appreciated!!

 

Jake.

Where are you running the code at?

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

 

It'll probably be easier if you have the full code.

 

package com.jakenelson1999.mods.cmds;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
import net.minecraft.client.Minecraft;
import net.minecraft.client.network.NetworkPlayerInfo;
import net.minecraft.client.settings.KeyBinding;
import net.minecraft.command.CommandException;
import net.minecraft.command.ICommand;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.util.text.TextFormatting;
import net.minecraftforge.client.settings.KeyBindingMap;
import net.minecraftforge.fml.client.FMLClientHandler;

public class TestPluginCommand implements ICommand {

@Override
public int compareTo(ICommand o) {
	return 0;
}

@Override
public String getCommandName() {
	return "jakeplugin";
}

@Override
public String getCommandUsage(ICommandSender sender) {
	return "/jakeplugin help";
}

@Override
public List<String> getCommandAliases() {
	return null;
}

@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {

	if(args[0].equalsIgnoreCase("debug")){

                            // The following code scans in a 10 block range around the player for a chest.
		    
		    int range = 10;
		    
		    double playerx = MathHelper.floor_double(Minecraft.getMinecraft().thePlayer.posX);
		    double playery = MathHelper.floor_double(Minecraft.getMinecraft().thePlayer.posY);
		    double playerz = MathHelper.floor_double(Minecraft.getMinecraft().thePlayer.posZ);
		    
		    double chestx = 0;
		    double chesty = 0;
		    double chestz = 0;
		    
		    for (double x = playerx - range; x < playerx+range; x++){
		    	for (double y = playery - range; y < playery+range; y++){
		    		for (double z = playerz - range; z < playerz+range; z++){
		    			
		    			if(Minecraft.getMinecraft().thePlayer.getEntityWorld().getBlockState(new BlockPos(x, y, z)).toString().toLowerCase().contains("chest")){
		    				System.out.println(x+" "+y+" "+z);
		    				chestx = x;
		    				chesty = y;
		    				chestz = z;
		    			}
				    	
				    	
				    }
			    	
			    }
		    	
		    }
		    
		    
		// The pitch and yaw values are calculated using mathsey stuff.

	        double xDiff = chestx - playerx;
	        double yDiff = chesty - 1 - playery;
	        double zDiff = chestz - playerz;

	        double DistanceXZ = Math.sqrt(xDiff * xDiff + zDiff * zDiff);
	        double DistanceY = Math.sqrt(DistanceXZ * DistanceXZ + yDiff * yDiff);
	        double newYaw = Math.acos(xDiff / DistanceXZ) * 180 / Math.PI;
	        double newPitch = Math.acos(yDiff / DistanceY) * 180 / Math.PI - 90;
	        if (zDiff < 0.0)
	            newYaw = newYaw + Math.abs(180 - newYaw) * 2;
	        newYaw = (newYaw - 90);

	        float yaw = (float) newYaw;
	        float pitch = (float) newPitch;
	        float headyaw = (float) newYaw;
		    
		    
		    // The player looks perfectly at the chest. So this works!
		    
		    Minecraft.getMinecraft().thePlayer.setAngles(yaw, pitch);
		    Minecraft.getMinecraft().thePlayer.setLocationAndAngles(Minecraft.getMinecraft().thePlayer.posX, Minecraft.getMinecraft().thePlayer.posY, Minecraft.getMinecraft().thePlayer.posZ, yaw, pitch);
		    
		    
		    // A New thread is started
		    // (I don't want to sleep the main thread or the game would pause)
		    
		    final Thread thread = new Thread(){
		        public void run(){
		          try {this.sleep(500);} catch (InterruptedException e) {}
		          // Make the player right click and open the chest
		          // This works perfectly fine 
		          KeyBinding.onTick(Minecraft.getMinecraft().gameSettings.keyBindUseItem.getKeyCode());
		          
		          try {this.sleep(500);} catch (InterruptedException e) {}
		          




		          //This is where the problem lies. When taking items out the chest, they are only moved
		          // temporarily. Thanks to whoever is reading this for taking the time to help me!

		          // Save the player as 'player'
                                  EntityPlayer player = FMLClientHandler.instance().getClient().thePlayer;

		          //Transfer the item in slot 1 to the player?
		          player.openContainer.transferStackInSlot(player, 1);
		          

		          // Give the action time to settle
		          try {this.sleep(100);} catch (InterruptedException e) {}
		          
		          // Update the changes
		          
		          player.openContainer.detectAndSendChanges();
		          try {this.sleep(100);} catch (InterruptedException e) {}
		          player.inventoryContainer.detectAndSendChanges();
		          
		          
		  		
		  		
		          
		        }
		      };

		      // Start the thread.

		      thread.start();
		      
		      
		}

	}
}


}

@Override
public boolean checkPermission(MinecraftServer server, ICommandSender sender) {
	return true;
}

@Override
public List<String> getTabCompletionOptions(MinecraftServer server, ICommandSender sender, String[] args,
		BlockPos pos) {
	return null;
}

@Override
public boolean isUsernameIndex(String[] args, int index) {
	return false;
}

}

Link to comment
Share on other sites

I believe that code is executed on the client side of things so you will want to send a packet with as little information as possible to get this done then do it in the packet.

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

That sounds like an incredibly daunting task  :o

This is my first mod, So any further help would be appreciated haha.

 

Thanks, Jake.

Read this

http://www.minecraftforge.net/forum/index.php?topic=20135.0

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

Hey sorry for bugging you guys but i feel completely out of my depth.

 

So I get the basic idea of packets

 

- Packets are used by server and client to send information

 

- Theres a different id and piece of data recieved by the server for each action in minecraft.

 

- Theres a particular id for transfering items from the chest to player's inventory

 

My questions are:

 

- Is there a list of packet ids I could use?

 

- Is there a non-packet way to do this, packets seem very scary.

 

 

 

 

Link to comment
Share on other sites

Hey sorry for bugging you guys but i feel completely out of my depth.

 

So I get the basic idea of packets

 

- Packets are used by server and client to send information

 

- Theres a different id and piece of data recieved by the server for each action in minecraft.

 

- Theres a particular id for transfering items from the chest to player's inventory

 

My questions are:

 

- Is there a list of packet ids I could use?

 

- Is there a non-packet way to do this, packets seem very scary.

There is not a non packet way to do this as you need to communicate with the server from the client and packets are the only way to do this. You could instead of using a command use something else like an Item right click. And I believe the id's for mods are mod specific. Then converted to universal later.

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

"Item right click"

 

Sorry bro i don't think you understand what im trying to do

 

I just want a mod that will put all the items in a chest into the players inventory. It should be very simple to do but now I've got a headache and have drank 10 cups of coffee so far.

 

If anyone else has a simple solution please feel free to post it before i die inside.

 

 

Thanks, Jake!

Link to comment
Share on other sites

"Item right click"

 

Sorry bro i don't think you understand what im trying to do

 

I just want a mod that will put all the items in a chest into the players inventory. It should be very simple to do but now I've got a headache and have drank 10 cups of coffee so far.

 

If anyone else has a simple solution please feel free to post it before i die inside.

 

 

Thanks, Jake!

"Item Right Click" is when you right click while holding 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

I think the packet idea is how I would go through with it.

 

That would be correct.

 

The problem is I haven't got the ability to code in raw packets.

 

Packets are easy.

 

https://github.com/Draco18s/ReasonableRealism/blob/master/src/main/java/com/draco18s/industry/network/CtoSMessage.java

https://github.com/Draco18s/ReasonableRealism/blob/master/src/main/java/com/draco18s/industry/network/PacketHandlerServer.java

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.

Link to comment
Share on other sites

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.



×
×
  • Create New...

Important Information

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