Working Title: Giving form to a snow cube
This tutorial was written around 1.12.2, and things may/have changed in 1.13. Being clear about the version here because I can't stand finding information that doesn't work and you have no clue why and it turns out things drastically changed. Ahem. I'm ok, let's carry on
I like this seed -8968754462810568592
Want to make it clear from the (almost beginning) that I plan to copy Minecraft's native classes and modify what I need. It's saner that way.
Right now we have a large white square that thinks it's a polar bear. Progress!
Will document what I did after sleep when I know what I did. :D
insert gif of the sun coming up, rooster crowing, programming yawning and blinking, etc
Morning! Ok, so where were we? Oh yes. Large white square that thinks it's a polar bear. Right. I know you want a picture, but let's start with some code!
One thing I forgot last night was documenting how I added the entity. Since (for now) the panda is a clone of the polar bear, the Entity class is the same. The important part is how you register this class. That code is likely to change (it's already gone in 1.3.x), so here is the code, with comments and links
@Mod.EventBusSubscriber
public class MyForgeEventHandler {
/**
* Register the EntityPanda class using the EntityEntryBuilder
* Some details are here: https://github.com/MinecraftForge/MinecraftForge/pull/4408
* The class is here: https://github.com/MinecraftForge/MinecraftForge/blob/1.12.x/src/main/java/net/minecraftforge/fml/common/registry/EntityEntryBuilder.java
* It's already gone in 1.13.x
* @param event
*/
@SubscribeEvent
public static void entityRegistration(RegistryEvent.Register<EntityEntry> event) {
event.getRegistry().register(EntityEntryBuilder.create().entity(EntityPanda.class)
.id(new ResourceLocation("pandas", "panda"), 33).name("Panda").tracker(160, 2, false)
.egg(0x4c3e30, 0xf0f0f)
.spawn(EnumCreatureType.AMBIENT, 10, 8, 8, ForgeRegistries.BIOMES.getValuesCollection()).build());
System.out.println("Entries registered");
}
}
Anyway. It seems we need a model.
This is going to be the src/main/java/com/drazisil/pandas/model/ModelPanda.java
class.
Again, a clone of the ModelPolarBear class from Minecraft currently, so let's focus on the registration part.
This code goes in your preInit
event handler (at least in 1.12). If you are using the proxy pattern (client/server/common (and there is no reason you shouldn't)) it will go in client side, since servers don't render anything, don't know how, and generally will throw fits if asked to. Since I'm not there yet, I'm doing a check to make sure this only runs client-side.
if (event.getSide() == Side.CLIENT) {
System.out.println("preInit: Client");
RenderingRegistry.registerEntityRenderingHandler(EntityPanda.class, RenderPanda::new);
}
So close. Let's copy over the polar bear texture and call it panda.
src/main/resources/assets/pandas/textures/entity/panda.png
That looks like version 0.2.0 to me. In case anyone was wondering how I was spawning these, I'm going with the very high-tech method of giving myself a spawn egg for them when I break dirt. Which, I was going to skip, but it took some time to figure out so I'll cover it briefly
This code goes in my event handler class
/**
* Create an instance of a spawn egg, use
* ItemMonsterPlacer.applyEntityIdToItemStack to appy the metadata of the
* EntityPanda to it, and give it to the player on the EntityItemPickup event.
* Make sure this only happens server-side
*
* @param event
*/
@SubscribeEvent
public static void pickupItem(EntityItemPickupEvent event) {
EntityPlayer player = event.getEntityPlayer();
if (!event.getEntityPlayer().getEntityWorld().isRemote) {
ItemStack pandaEggStack = new ItemStack(Items.SPAWN_EGG);
ResourceLocation pandaResource = new ResourceLocation("pandas", "panda");
System.out.println(pandaResource);
ItemMonsterPlacer.applyEntityIdToItemStack(pandaEggStack, pandaResource);
player.inventory.addItemStackToInventory(pandaEggStack);
}
System.out.println(event.getItem().getName() + " picked up by " + event.getEntityPlayer().getName());
}
I'm doing a check here to make sure this only handles server-side, since you don't want to give items to players on the client or the server will never know. The ItemMonsterPlacer.applyEntityIdToItemStack()
is the interesting part here, this is what applies the panda as the "contents" of the spawn egg.
Next steps are to give the panda a localized name and see about textures and behaviors. Pandas and Bamboo are coming in 1.14, but I picked up the Panda as part of the Minecraft Chinese Mythology Series 14 Mini-Figure Blind Box and really wanted to use it as an excuse to get modding again. Think of this as a backport, I guess?
This post was created as part of the README for my Panda's mod. Part 1 discussed setting up a dev environment in VSCode. Thoughts and feedback welcome.
Top comments (0)