Jump to content

Recommended Posts

Posted

I ran into a weird problem while testing my mod, the code to spawn the entity have always stayed the same while I added on a yaml check for the entity. To clarify every the mod is to keep the player infomation online when they log off so I spawn an entity into the location of the player as they log off and everything worked fine until today.

This is my code to spawn the entity (it have remain unchanged since I add the yaml checking code):

	@SubscribeEvent
public void playerLogOff(PlayerLoggedOutEvent e) {
	EntityPlayer player = e.player;
	World world = player.getEntityWorld();
	EntityOfflinePlayer offline = new EntityOfflinePlayer(player.getEntityWorld(), player.posX, player.posY, player.posZ);// <-- set the position and world

//			
//			//change player to config
	offline.setCustomNameTag(player.getDisplayNameString());
	offline.setHealth(player.getHealth());	
	offline.setCurrentItemOrArmor(0, player.getHeldItem());

	world.spawnEntityInWorld(offline);// <--- should spawn the entity
	System.out.println(player + ", " + player.posX + ", " + player.posY + ", " + player.posZ);
	System.out.println(offline + ", " + offline.posX + ", " + offline.posY + ", " + offline.posZ );

	try {
		data.createFile(player.getUniqueID());
		data.savePlayerInfo(player);
		System.out.println("Loaded");
	} catch (IOException e1) {
		e1.printStackTrace();
	}
}

Result of sysout:

[23:36:19] [server thread/INFO] [sTDOUT]: [com.pandaism.NLO.events.PlayerLoggingHandler:playerLogOff:77]: EntityPlayerMP['Player890'/7111, l='New World', x=-243.50, y=72.00, z=6.50], -243.5, 72.0, 6.5
[23:36:19] [server thread/INFO] [sTDOUT]: [com.pandaism.NLO.events.PlayerLoggingHandler:playerLogOff:78]: EntityOfflinePlayer['Player890'/9920, l='New World', x=-243.50, y=72.00, z=6.50], -243.5, 72.0, 6.5 

Posted

When I check with

if(world.loadedEntityList.contains(offline)) {
		System.out.println("Success");

	} else {
		System.out.println("Failed");
	}

sysout will always print "Success" but the entity is nowhere to be found

Posted

Renderer:

package com.pandaism.NLO.mobs.graphics;

import net.minecraft.client.Minecraft;
import net.minecraft.client.model.ModelBiped;
import net.minecraft.client.renderer.entity.RenderBiped;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLiving;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

@SideOnly(Side.CLIENT)
public class RenderOfflinePlayer extends RenderBiped {
private ResourceLocation texture;

public RenderOfflinePlayer(ModelBiped model, float shadowSize, String string) {
	super(Minecraft.getMinecraft().getRenderManager(), model, shadowSize);
	this.texture = new ResourceLocation("nlo", string);
}

protected ResourceLocation getEntityTexture(EntityLiving entity) {
	return this.texture;
}
}

register:

package com.pandaism.NLO;

import com.pandaism.NLO.mobs.entity.EntityOfflinePlayer;
import com.pandaism.NLO.mobs.graphics.RenderOfflinePlayer;

import net.minecraft.client.Minecraft;
import net.minecraft.client.model.ModelBiped;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraftforge.fml.client.registry.RenderingRegistry;
import net.minecraftforge.fml.common.registry.EntityRegistry;

public class ClientProxy extends ServerProxy {
public void registerRenders() {
	RenderingRegistry.registerEntityRenderingHandler(EntityOfflinePlayer.class, new RenderOfflinePlayer(new ModelBiped(), 0.5F, "textures/entity/offlineplayer.png"));
}
}

main:

package com.pandaism.NLO;

import java.io.File;
import java.io.IOException;

import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.SidedProxy;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;

import com.pandaism.NLO.events.OfflinePlayerDropsHandler;
import com.pandaism.NLO.events.PlayerLoggingHandler;
import com.pandaism.NLO.handlers.EntityHandler;
import com.pandaism.NLO.mobs.entity.EntityOfflinePlayer;

@Mod(modid = RefString.MODID, name = RefString.NAME, version = RefString.VERSION)
public class NeverLogOff {
PlayerLoggingHandler logging;

@Mod.Instance
public static NeverLogOff instance;

@SidedProxy(clientSide = RefString.CLIENT, serverSide = RefString.SERVER)
public static ServerProxy proxy;

@EventHandler
public void preLoad(FMLPreInitializationEvent e) {

}

@EventHandler
public void Load(FMLInitializationEvent e) {
	FMLCommonHandler.instance().bus().register(new PlayerLoggingHandler());
	MinecraftForge.EVENT_BUS.register(new OfflinePlayerDropsHandler());
	EntityHandler.RegisterMobs(EntityOfflinePlayer.class, "Offline Player");
	proxy.registerRenders();
}

}

Posted

package com.pandaism.NLO.handlers;

import java.util.Random;

import com.pandaism.NLO.NeverLogOff;
import com.pandaism.NLO.RefString;

import net.minecraft.entity.EntityList;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.common.registry.EntityRegistry;

public class EntityHandler {
public static void RegisterMobs(Class entityClass, String name) {
	int entityID = EntityRegistry.findGlobalUniqueEntityId();
	long x = name.hashCode();
	Random ran = new Random(x);
	int mainColor = ran.nextInt() * 16777215;
	int subColor = ran.nextInt() * 16777215;

	EntityRegistry.registerGlobalEntityID(entityClass, name, entityID);
	EntityRegistry.registerModEntity(entityClass, name, entityID, NeverLogOff.instance, 64, 1, false);
	EntityList.entityEggs.put(Integer.valueOf(entityID), new EntityList.EntityEggInfo(entityID, mainColor, subColor));
}
}

This is the entity on SMP http://prntscr.com/7ru9v7

which spawns properly

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

    • logs too big for one pastebin https://pastebin.com/ZjUGHu3u  https://pastebin.com/RqCUZf3X  https://pastebin.com/6ZPS99nD
    • You probably used jd-gui to open it, didn't you? Nothing wrong with that, I also made that mistake, except that Notch was a smart guy and he obfuscated the code. That's why you only see files called "a", "b", "c" and then a file that combines them all. As I said, use RetroMCP to deobfuscate the code so that you will 100% understand it and be able to navigate it.
    • Decompiling minecraft indev, infdev, alpha, beta or whichever legacy version is really easy. I'm not a plug, I just also got interested in modding legacy versions (Infdev to be specific). Use https://github.com/MCPHackers/RetroMCP-Java Once you install their client and the Zulu Architecture that they say they recommend (or use your own Java). I encountered some problems, so I run it with: "java -jar RetroMCP-Java-CLI.jar". You should run it in a seperate folder (not in downloads), otherwise the files and folders will go all over the place. How to use RetroMCP: Type setup (every time you want change version), copy-paste the version number from their list (they support indev), write "decompile" and done! The code will now be deobfuscated and filenames will be normal, instead of "a", "b" and "c"! Hope I helped you, but I don't expect you to reply, as this discussion is 9 years old! What a piece of history!  
    • I know that this may be a basic question, but I am very new to modding. I am trying to have it so that I can create modified Vanilla loot tables that use a custom enchantment as a condition (i.e. enchantment present = item). However, I am having trouble trying to implement this; the LootItemRandomChanceWithEnchantedBonusCondition constructor needs a Holder<Enchantment> and I am unable to use the getOrThrow() method on the custom enchantment declared in my mod's enchantments class. Here is what I have so far in the GLM:   protected void start(HolderLookup.Provider registries) { HolderLookup.RegistryLookup<Enchantment> registrylookup = registries.lookupOrThrow(Registries.ENCHANTMENT); LootItemRandomChanceWithEnchantedBonusCondition lootItemRandomChanceWithEnchantedBonusCondition = new LootItemRandomChanceWithEnchantedBonusCondition(0.0f, LevelBasedValue.perLevel(0.07f), registrylookup.getOrThrow(*enchantment here*)); this.add("nebu_from_deepslate", new AddItemModifier(new LootItemCondition[]{ LootItemBlockStatePropertyCondition.hasBlockStateProperties(Blocks.DEEPSLATE).build(), LootItemRandomChanceCondition.randomChance(0.25f).build(), lootItemRandomChanceWithEnchantedBonusCondition }, OrichalcumItems.NEBU.get())); }   Inserting Enchantments.[vanilla enchantment here] actually works but trying to declare an enchantment from my custom enchantments class as [mod enchantment class].[custom enchantment] does not work even though they are both a ResourceKey and are registered in Registries.ENCHANTMENT. Basically, how would I go about making it so that a custom enchantment declared as a ResourceKey<Enchantment> of value ResourceKey.create(Registries.ENCHANTMENT, ResourceLocation.fromNamespaceAndPath([modid], [name])), declared in a seperate enchantments class, can be used in the LootItemRandomChanceWithEnchantedBonusCondition constructor as a Holder? I can't use getOrThrow() because there is no level or block entity/entity in the start() method and it is running as datagen. It's driving me nuts.
  • Topics

×
×
  • Create New...

Important Information

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