-
Need packet to wait until runnable is executed before returning packet
Thanks you very much for all the help it works perfectly now.
-
Need packet to wait until runnable is executed before returning packet
Okay I understand what you are saying, so set the comparator output on the server. How would I do this the closest method I can find to do this is ctx.getServerHandler().playerEntity.worldObj.updateComparatorOutputLevel(pos, blockIn); Which doesn't set the comparator output it just calls the getComparatorInputOverride method in my block that I overrided. I hope this makes sense.
-
Need packet to wait until runnable is executed before returning packet
Okay now for another problem that I was having related to this which is when I get the packet that I just received I need to wait until it is sent to my block before further action. Basically I have to wait until the packet has set the data then have my block use that data after it is done to set the comparator output. I need to wait for the packet in this code. @Override public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos p_189540_5_) { if (worldIn.isBlockPowered(pos) & previousState != worldIn.isBlockPowered(pos)){ TileEntityDiamondCommand tile = (TileEntityDiamondCommand) Minecraft.getMinecraft().theWorld.getTileEntity(pos); commandblockmod.network.sendToServer(new RunCommandMessage(tile.getCommand(),pos.getX(),pos.getY(),pos.getZ(),"Diamond Command Block")); try { Thread.sleep(50); } catch (InterruptedException e) { e.printStackTrace(); } out = tile.getOut(); System.out.println("Update "+out); if (out > 0){ out = 15; }else{ out = 0; } worldIn.updateComparatorOutputLevel(pos, this); } previousState = worldIn.isBlockPowered(pos); } public boolean hasComparatorInputOverride(IBlockState state) { return true; } public int getComparatorInputOverride(IBlockState blockState, World worldIn, BlockPos pos) { return out; } Thanks for all the help and hope that you can help me figure this out also!
-
Need packet to wait until runnable is executed before returning packet
From what you said I should put it after all my other code in the run() class, correct? Where do I send the packet to because I need to specify a player on the client. Would Minecraft.getMinecraft.thePlayer work? Figured it out had to use ctx.getServerHandler().playerEntity
-
Need packet to wait until runnable is executed before returning packet
Hey, so I was trying to send a packet to the server and get the output and that works the problem is that since I send an addScheduledTask the output from that comes later that the return statement. So basically I have to delay the return statement until my runnable executes on the main thread. Here is some of my code. HandlerRunCommand.java package com.radar.commandblockmod.packages; import net.minecraft.client.Minecraft; import net.minecraft.command.CommandResultStats.Type; import net.minecraft.command.ICommandManager; import net.minecraft.command.ICommandSender; import net.minecraft.entity.Entity; import net.minecraft.server.MinecraftServer; import net.minecraft.util.IThreadListener; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.TextComponentString; import net.minecraft.world.World; import net.minecraft.world.WorldServer; import net.minecraftforge.fml.common.FMLCommonHandler; import net.minecraftforge.fml.common.network.simpleimpl.IMessage; import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; public class HandlerRunCommand implements IMessageHandler <RunCommandMessage, IMessage>{ private MessageContext ctx; private int out; @Override public IMessage onMessage(RunCommandMessage message, final MessageContext ctx) { final String command = message.getCommand(); final int x = message.getxPos(); final int y = message.getyPos(); final int z = message.getzPos(); final String name = message.getName(); IThreadListener mainThread = (WorldServer) ctx.getServerHandler().playerEntity.worldObj; mainThread.addScheduledTask(new Runnable() { @Override public void run() { RunCommands onServer = new RunCommands(command,x,y,z,name); out = onServer.run(); System.out.println("Sent "+out); } class RunCommands implements ICommandSender{ public ICommandSender instance; private int x,y,z; private String nameBlock, command; public RunCommands(String command, int x, int y, int z, String name){ this.x = x; this.y = y; this.z = z; this.command = command; this.nameBlock = name; } public int run (){ ICommandManager icommandmanager = ctx.getServerHandler().playerEntity.worldObj.getMinecraftServer().commandManager; return icommandmanager.executeCommand(this, this.command); } @Override public String getName() { return ctx.getServerHandler().playerEntity.getName(); } @Override public ITextComponent getDisplayName() { ITextComponent name = new TextComponentString(this.nameBlock); return name; } @Override public void addChatMessage(ITextComponent component) { } @Override public boolean canCommandSenderUseCommand(int permLevel, String commandName) { return true; } @Override public BlockPos getPosition() { return new BlockPos(x,y,z); } @Override public Vec3d getPositionVector() { return ctx.getServerHandler().playerEntity.getPositionVector(); } @Override public World getEntityWorld() { return ctx.getServerHandler().playerEntity.worldObj; } @Override public Entity getCommandSenderEntity() { return ctx.getServerHandler().playerEntity; } @Override public boolean sendCommandFeedback() { return true; } @Override public void setCommandStat(Type type, int amount) { } @Override public MinecraftServer getServer() { return ctx.getServerHandler().playerEntity.worldObj.getMinecraftServer(); } } }); return new ReturnCommandOut(x,y,z,out); } } I hope this helps thanks!
-
Referencing Tile Entity through GUI
Solved I have to use ctx.getServerHandler().playerEntity.worldObj.getTileEntity(tilePos); So I have been working on trying to do this with packets, I have made a packet to send to the server and that works, but how do I set the command from the packet handler? Right now I have been trying to set the command by sending the coordinates to the packet handler and having it find the tile entity instance through Minecraft.getMinecraft().theWorld.getTileEntity(pos); But that still seems to get a different instance of the tile entity... I am registering the message through the server side which I believe is correct because I want to get the data to the server, but I just am not sure how else to do this. Thanks for any help. CommandMessage.java package com.radar.spearmod.packages; import com.radar.spearmod.tileentities.TileEntityIronCommand; import io.netty.buffer.ByteBuf; import net.minecraftforge.fml.common.network.ByteBufUtils; import net.minecraftforge.fml.common.network.simpleimpl.IMessage; public class CommandMessage implements IMessage{ int i = 0; private String command; private int xPos, yPos, zPos; public CommandMessage () {} public CommandMessage(String command, int xPos, int yPos, int zPos){ System.out.println(command); this.setCommand(command); this.setxPos(xPos); this.setyPos(yPos); this.setzPos(zPos); } @Override public void fromBytes(ByteBuf buf) { System.out.println("From bytes"); this.command = ByteBufUtils.readUTF8String(buf); System.out.println("Test"); this.xPos = buf.readInt(); this.yPos = buf.readInt(); this.zPos = buf.readInt(); System.out.println(getxPos()+" "+getyPos()+" "+getzPos()); } @Override public void toBytes(ByteBuf buf) { System.out.println("To bytes"); ByteBufUtils.writeUTF8String(buf, this.command); buf.writeInt(xPos); buf.writeInt(yPos); buf.writeInt(zPos); } public String getCommand() { return command; } public void setCommand(String command) { this.command = command; } public int getxPos() { return xPos; } public void setxPos(int xPos) { this.xPos = xPos; } public int getyPos() { return yPos; } public void setyPos(int yPos) { this.yPos = yPos; } public int getzPos() { return zPos; } public void setzPos(int zPos) { this.zPos = zPos; } } MessageHandler.java package com.radar.spearmod.packages; import com.radar.spearmod.tileentities.TileEntityIronCommand; import net.minecraft.client.Minecraft; import net.minecraft.util.IThreadListener; import net.minecraft.util.math.BlockPos; import net.minecraft.world.WorldServer; import net.minecraftforge.fml.common.network.simpleimpl.IMessage; import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; public class MessageHandler implements IMessageHandler <CommandMessage, IMessage>{ @Override public IMessage onMessage(CommandMessage message, MessageContext ctx) { final String command = message.getCommand(); final int x = message.getxPos(); final int y = message.getyPos(); final int z = message.getzPos(); IThreadListener mainThread = (WorldServer) ctx.getServerHandler().playerEntity.worldObj; mainThread.addScheduledTask(new Runnable() { @Override public void run() { System.out.println("What I am sending : "+command+" "+x+" "+y+" "+z); BlockPos tilePos = new BlockPos(x,y,z); TileEntityIronCommand tile = (TileEntityIronCommand) Minecraft.getMinecraft().theWorld.getTileEntity(tilePos); System.out.println(tile.toString()); tile.setCommand(command); } }); return null; } }
-
Referencing Tile Entity through GUI
Sorry about the blank post, I am apparently really bad at using this forum (3rd try at writing this). Anyway I have done what you said Loordgek and have found that it still doesn't work, but I was playing around with it and found a way to do it possibly. So I can get the correct instance of the tile entity by using tileEntity.pos and I can use the Minecraft world to get the tile entity from position. This works for saving the data, but when starting the world the readFromNBT is called before the world is loaded so I get a null pointer because the world isn't created. I don't know how to fix this because I can recall readFromNBT because only Minecraft can do that. I hope this helps, thanks!
-
Referencing Tile Entity through GUI
- Referencing Tile Entity through GUI
This is GUI handler that I have currently. Hope this helps. package com.radar.spearmod.client.gui; import com.radar.spearmod.tileentities.TileEntityIronCommand; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.world.World; import net.minecraftforge.fml.common.network.IGuiHandler; public class ModGuiHandler implements IGuiHandler{ public static final int MOD_TILE_ENTITY_GUI = 0; @Override public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { return null; } @Override public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { if (ID == MOD_TILE_ENTITY_GUI) return new guiCommandBlock(x, y, z); return null; } } Sorry about the downloads, I thought they would show up as text.- Referencing Tile Entity through GUI
So I have just started to create mods and I have run into a large stumbling block, I can't figure out how to reference a tile entity through its' GUI and save it to NBT. The goal of this mod is to create, essentially survival command blocks, so this code should run the command you enter in the GUI by hitting the run button and it should save what you entered. Currently I can type different commands into different blocks and run them, but the NBT won't save correctly. I have found with the way that I have done it that the tile entity is in the correct position, but I seem to get different instances of the tile entity. This is strange to me though because I can see form debugging that they are in the same spot and that there is only single tile entity registered for each block I place. This causes my string called command to equal nothing when I try to write it to NBT. I could be wrong in some of these assumptions, but I hope this helps. Thanks! TileEntityIronCommand.java BlockIronCommand.java guiCommandBlock.java - Referencing Tile Entity through GUI
IPS spam blocked by CleanTalk.
Important Information
By using this site, you agree to our Terms of Use.