Jump to content

Entity doesn't spawn


Farianit

Recommended Posts

Hello. I'm working with SimpleNetworkWrapper and my mod should spawn entity when it receives message. Message receiving works great, but when i'm trying to spawn enitity, it doesn't do it.

Here's my Message.java:

import cpw.mods.fml.common.network.ByteBufUtils;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
import io.netty.buffer.ByteBuf;
import net.minecraft.world.WorldServer;
import net.minecraftforge.common.DimensionManager;

public class Message implements IMessage{

private String text;

public Message() { }

public Message(String text) {
        this.text = text;
    }

@Override
public void fromBytes(ByteBuf buf) {
	text = ByteBufUtils.readUTF8String(buf);
}

@Override
public void toBytes(ByteBuf buf) {
	ByteBufUtils.writeUTF8String(buf, text);
}

 public static class Handler implements IMessageHandler<Message, IMessage> {
        
        @Override
        public IMessage onMessage(Message message, MessageContext ctx) {
            String[] action = message.text.split(" ");
            System.out.println(String.format("Recieved message %s.", message.text));
            if (action[0].equals("spawn")) {
            	
            	WorldServer world = null;
            	double x, y, z;
            	
            	for(WorldServer _world : DimensionManager.getWorlds()) {
            		if (_world.getWorldInfo().getWorldName().equals(action[1])) {
            			world = _world;
            		}
            		
        		CrystallEntity crystall = new CrystallEntity(world);

            		x = Double.valueOf(action[2]);
            		y = Double.valueOf(action[3]);
            		z = Double.valueOf(action[4]);
            		
            		crystall.setLocationAndAngles(x, y, z, 0.0F, 0.0F);
            		
            		System.out.println(String.format("Trying to spawn a Crystall at %d %d %d", x, y, z));
            		
            		world.spawnEntityInWorld(crystall);
            	}
            }
        	return null; // no response in this case
        }
        
 }
}

Link to comment
Share on other sites

You cannot interact with the main Minecraft threads from the networking thread. See the warning at mcforge.readthedocs.org for more information.

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/

Link to comment
Share on other sites

Also don't implement IMessage and IMessageHandler in the same class file, you'll invariably mess something up.

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

Also don't implement IMessage and IMessageHandler in the same class file, you'll invariably mess something up.

 

I don't really agree with this. Implementing them both on a single class is a bad idea and can lead to confusion (which instance is the handler and which is the message?), but implementing one in a nested class of the other (like the OP has done) isn't likely to cause much confusion. You've still got two separate classes, but they're grouped together in one file instead of two.

 

To the OP: 1.7.10 is no longer supported here. You should update to 1.10.2.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

I don't really agree with this. Implementing them both on a single class is a bad idea and can lead to confusion (which instance is the handler and which is the message?), but implementing one in a nested class of the other (like the OP has done) isn't likely to cause much confusion. You've still got two separate classes, but they're grouped together in one file instead of two.

 

Personally, I still think it helps to have the classes in different files.  There was another poster about a week ago who'd used the nested class structure and was having an issue that as soon as I suggested he use separate files he found and fixed his problem.

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

Guest
This topic is now closed to further replies.


  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Hello all, I recently tried to upgrade my Minecraft mod to version 1.21.3, and I seem to have a problem with the `RenderSystem#setShaderColor` method. Here is how the screen is usually supposed to look like: Here is how it looks at present: To further explain, the note labels atop of the note buttons are colored cyan (here) using `RenderSystem#setShaderColor`. The note buttons and labels get their colors from their native texture - white. This means that even though I set the coloring to apply to the label (top), it is applied to the button (bottom). What I conclude is happening then, in essence, is that this method (at least for my case) does not color the blit after - but rather the blit before..?  This also blocks me from later resetting the shader, as I need to set it back to white before the blitting is done, and not when it's done. So like... what? I've tested this further with other components that require this method, and this preceding-like behavior seems to be pretty consistent for them too.   I should mention that all the snippets I am about to show have all worked in past versions. In my class `ClientUtil`, the following methods are defined: public static void setShaderColor(final Color color, final float alpha) { RenderSystem.setShaderColor( color.getRed() / 255f, color.getGreen() / 255f, color.getBlue() / 255f, alpha ); } public static void setShaderColor(final Color color) { setShaderColor(color, 1); } public static void resetShaderColor() { setShaderColor(Color.WHITE); } //... public static RenderType guiRT(final ResourceLocation loc) { return RenderType.guiTextured(loc); } And here is the snippet from `NoteButtonRenderer#renderNote` using it: // "Note" here refers to those symbols in the middle of a note button protected void renderNote(final GuiGraphics gui, final InstrumentThemeLoader themeLoader) { final int noteWidth = noteButton.getWidth()/2, noteHeight = noteButton.getHeight()/2; ClientUtil.setShaderColor((noteButton.isPlaying() && !foreignPlaying) ? themeLoader.notePressed() : themeLoader.noteReleased() ); gui.blit(ClientUtil::guiRT, noteTextureProvider.get(), noteButton.getX() + noteWidth/2, noteButton.getY() + noteHeight/2, 0, 0, noteWidth, noteHeight, noteWidth, noteButton.getHeight()/2 ); ClientUtil.resetShaderColor(); } You may find the full source here. The odd thing is that Minecraft does seem to use this method the regular way I showed, for instance `SkyRenderer#renderSkyDisc` (not sure if I'l allowed to paste it). Could it be that I'm doing something wrong that leads to this issue..? I'm really stumped on this one.  I couldn't really find any change logs or documentation for this rendering API (even in this Fabric blog post), so I'm sorry if this seems obvious or anything.  Either way, any help would be appreciated.
    • This did work. rip Quark Thank you
    • It says Quark Requires zeta. do i just remove Quark? https://mclo.gs/cq799kI
    • It refers to the mod elenaidodge Backup the world and make a test without it
    • Remove the mod Zeta   If you have further issues, add the new crash-report with sites like https://mclo.gs/ and paste the link to it here
  • Topics

×
×
  • Create New...

Important Information

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