Restarted the repo with a modern GTNH modding template

This commit is contained in:
Goodbird committed 2024-01-23 23:33:47 +03:00
1 parent 27e8c91e08
commit 29158fa566
43 files changed
+3024 -912

No files matched your search

@@ -1,7 +0,0 @@
package noppes.npcs;
public class CommonGeckoProxy {
public void load(){}
}
@@ -1,36 +0,0 @@
package noppes.npcs;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.*;
import cpw.mods.fml.common.registry.EntityRegistry;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityList;
import noppes.npcs.entity.*;
@Mod(modid = "customnpcsgecko",
name = "CustomNPC+ Gecko",
version = "1.0",
dependencies = "required-after:customnpcs;")
public class CustomNpcsGecko {
@SidedProxy(clientSide = "noppes.npcs.client.ClientGeckoProxy", serverSide = "noppes.npcs.CommonGeckoProxy")
public static CommonGeckoProxy proxy;
private static int NewEntityStartId = 0;
public CustomNpcsGecko() {}
@EventHandler
public void load(FMLPreInitializationEvent ev) {
proxy.load();
registerCustomModel(EntityCustomModel.class, "CustomModel");
}
public void registerCustomModel(Class<? extends Entity> cl, String name) {
EntityRegistry.registerModEntity(cl, name, NewEntityStartId++, this, 64, 10, false);
EntityList.stringToClassMapping.put(name, cl);
}
}
-82
View File
@@ -1,82 +0,0 @@
package noppes.npcs;
import kamkeel.addon.DataDisplaySupport;
import net.minecraft.nbt.NBTTagCompound;
public class DataGecko {
private String model = "geckolib3:geo/npc.geo.json";
private String animFile = "custom:geo_npc.animation.json";
private String idleAnim = "";
private String walkAnim = "";
private String attackAnim = "";
private String hurtAnim = "";
public NBTTagCompound writeToNBT(NBTTagCompound nbttagcompound) {
nbttagcompound.setString("Model", model);
nbttagcompound.setString("AnimFile", animFile);
nbttagcompound.setString("IdleAnim", idleAnim);
nbttagcompound.setString("WalkAnim", walkAnim);
nbttagcompound.setString("AttackAnim", attackAnim);
nbttagcompound.setString("HurtAnim", hurtAnim);
return nbttagcompound;
}
public void readFromNBT(NBTTagCompound nbttagcompound) {
if(nbttagcompound.hasKey("Model")) {
model = nbttagcompound.getString("Model");
animFile = nbttagcompound.getString("AnimFile");
idleAnim = nbttagcompound.getString("IdleAnim");
walkAnim = nbttagcompound.getString("WalkAnim");
hurtAnim = nbttagcompound.getString("HurtAnim");
attackAnim = nbttagcompound.getString("AttackAnim");
}
}
public String getModel() {
return model;
}
public void setModel(String model) {
this.model = model;
}
public String getAnimFile() {
return animFile;
}
public void setAnimFile(String animFile) {
this.animFile = animFile;
}
public String getIdleAnim() {
return idleAnim;
}
public void setIdleAnim(String idleAnim) {
this.idleAnim = idleAnim;
}
public String getWalkAnim() {
return walkAnim;
}
public void setWalkAnim(String walkAnim) {
this.walkAnim = walkAnim;
}
public String getAttackAnim() {
return attackAnim;
}
public void setAttackAnim(String attackAnim) {
this.attackAnim = attackAnim;
}
public String getHurtAnim() {
return hurtAnim;
}
public void setHurtAnim(String hurtAnim) {
this.hurtAnim = hurtAnim;
}
}
@@ -1,15 +0,0 @@
package noppes.npcs.client;
import cpw.mods.fml.client.registry.RenderingRegistry;
import noppes.npcs.CommonGeckoProxy;
import noppes.npcs.client.renderer.RenderCustomModel;
import noppes.npcs.entity.EntityCustomModel;
public class ClientGeckoProxy extends CommonGeckoProxy {
@Override
public void load() {
RenderingRegistry.registerEntityRenderingHandler(EntityCustomModel.class, new RenderCustomModel());
}
}
@@ -1,80 +0,0 @@
package noppes.npcs.client.gui.model.custom;
import kamkeel.addon.DataDisplaySupport;
import kamkeel.addon.GeckoAddonSupport;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.util.ResourceLocation;
import noppes.npcs.DataGecko;
import noppes.npcs.client.NoppesUtil;
import noppes.npcs.client.gui.util.GuiNPCInterface;
import noppes.npcs.client.gui.util.GuiNPCStringSlot;
import noppes.npcs.client.gui.util.GuiNpcButton;
import noppes.npcs.client.gui.util.GuiNpcLabel;
import noppes.npcs.entity.EntityNPCInterface;
import software.bernie.geckolib3.resource.GeckoLibCache;
import java.util.Collections;
import java.util.Vector;
import static kamkeel.addon.GeckoAddonSupport.getGeckoData;
public class GuiCustomAnimFileSelection extends GuiNPCInterface {
public GuiNPCStringSlot slot;
public GuiScreen parent;
public GuiCustomAnimFileSelection(EntityNPCInterface npc, GuiScreen parent){
super(npc);
drawDefaultBackground = false;
title = "";
this.parent = parent;
}
@Override
public void initGui(){
super.initGui();
String ss = "Selecting geckolib animation file:";
addLabel(new GuiNpcLabel(0,ss, width / 2 - (this.fontRendererObj.getStringWidth(ss)/2), 20, 0xffffff));
Vector<String> list = new Vector<String>();
for(ResourceLocation resLoc : GeckoLibCache.getInstance().getAnimations().keySet()){
list.add(resLoc.toString());
}
Collections.sort(list,String.CASE_INSENSITIVE_ORDER);
slot = new GuiNPCStringSlot(list,this,false,18);
slot.registerScrollButtons(4, 5);
this.addButton(new GuiNpcButton(2, width / 2 - 100, height - 44,98, 20, "gui.back"));
}
@Override
public void drawScreen(int i, int j, float f)
{
slot.drawScreen(i, j, f);
super.drawScreen(i, j, f);
}
@Override
public void elementClicked(){
}
@Override
public void doubleClicked(){
DataGecko geckoData = (DataGecko) getGeckoData(npc);
GeckoAddonSupport.putGeckoData(npc, geckoData);
close();
NoppesUtil.openGUI(player, parent);
}
@Override
protected void actionPerformed(GuiButton guibutton){
int id = guibutton.id;
if(id == 2){
close();
NoppesUtil.openGUI(player, parent);
}
}
@Override
public void save() {
}
}
@@ -1,89 +0,0 @@
package noppes.npcs.client.gui.model.custom;
import kamkeel.addon.DataDisplaySupport;
import kamkeel.addon.GeckoAddonSupport;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.util.ResourceLocation;
import noppes.npcs.DataGecko;
import noppes.npcs.client.NoppesUtil;
import noppes.npcs.client.gui.util.GuiNPCInterface;
import noppes.npcs.client.gui.util.GuiNPCStringSlot;
import noppes.npcs.client.gui.util.GuiNpcButton;
import noppes.npcs.client.gui.util.GuiNpcLabel;
import noppes.npcs.entity.EntityNPCInterface;
import software.bernie.geckolib3.core.builder.Animation;
import software.bernie.geckolib3.file.AnimationFile;
import software.bernie.geckolib3.resource.GeckoLibCache;
import java.util.Collections;
import java.util.Vector;
import java.util.function.Consumer;
import static kamkeel.addon.GeckoAddonSupport.getGeckoData;
public class GuiCustomAnimationSelection extends GuiNPCInterface {
public GuiNPCStringSlot slot;
public GuiScreen parent;
public Consumer<String> action;
public GuiCustomAnimationSelection(EntityNPCInterface npc, GuiScreen parent, Consumer<String> action){
super(npc);
drawDefaultBackground = false;
title = "";
this.parent = parent;
this.action=action;
}
@Override
public void initGui(){
super.initGui();
String ss = "Selecting geckolib animation:";
addLabel(new GuiNpcLabel(0,ss, width / 2 - (this.fontRendererObj.getStringWidth(ss)/2), 20, 0xffffff));
Vector<String> list = new Vector<String>();
DataGecko geckoData = (DataGecko) getGeckoData(npc);
AnimationFile file = GeckoLibCache.getInstance().getAnimations().get(new ResourceLocation(geckoData.animFile));
if(file!=null) {
for (Animation anim : file.getAllAnimations()) {
list.add(anim.animationName);
}
}
Collections.sort(list,String.CASE_INSENSITIVE_ORDER);
slot = new GuiNPCStringSlot(list,this,false,18);
slot.registerScrollButtons(4, 5);
this.addButton(new GuiNpcButton(2, width / 2 - 100, height - 44,98, 20, "gui.back"));
}
@Override
public void drawScreen(int i, int j, float f)
{
slot.drawScreen(i, j, f);
super.drawScreen(i, j, f);
}
@Override
public void elementClicked(){
}
@Override
public void doubleClicked(){
action.accept(slot.selected);
close();
NoppesUtil.openGUI(player, parent);
}
@Override
protected void actionPerformed(GuiButton guibutton){
int id = guibutton.id;
if(id == 2){
close();
NoppesUtil.openGUI(player, parent);
}
}
@Override
public void save() {
}
}
@@ -1,82 +0,0 @@
package noppes.npcs.client.gui.model.custom;
import kamkeel.addon.DataDisplaySupport;
import kamkeel.addon.GeckoAddonSupport;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.util.ResourceLocation;
import noppes.npcs.DataGecko;
import noppes.npcs.client.NoppesUtil;
import noppes.npcs.client.gui.util.GuiNPCInterface;
import noppes.npcs.client.gui.util.GuiNPCStringSlot;
import noppes.npcs.client.gui.util.GuiNpcButton;
import noppes.npcs.client.gui.util.GuiNpcLabel;
import noppes.npcs.entity.EntityNPCInterface;
import software.bernie.geckolib3.resource.GeckoLibCache;
import java.util.Collections;
import java.util.Vector;
import static kamkeel.addon.GeckoAddonSupport.getGeckoData;
public class GuiCustomModelSelection extends GuiNPCInterface {
public GuiNPCStringSlot slot;
public GuiScreen parent;
public GuiCustomModelSelection(EntityNPCInterface npc, GuiScreen parent){
super(npc);
drawDefaultBackground = false;
title = "";
this.parent = parent;
}
@Override
public void initGui(){
super.initGui();
String ss = "Selecting geckolib model:";
addLabel(new GuiNpcLabel(0,ss, width / 2 - (this.fontRendererObj.getStringWidth(ss)/2), 20, 0xffffff));
Vector<String> list = new Vector<String>();
for(ResourceLocation resLoc : GeckoLibCache.getInstance().getGeoModels().keySet()){
list.add(resLoc.toString());
}
Collections.sort(list,String.CASE_INSENSITIVE_ORDER);
slot = new GuiNPCStringSlot(list,this,false,18);
slot.registerScrollButtons(4, 5);
this.addButton(new GuiNpcButton(2, width / 2 - 100, height - 44,98, 20, "gui.back"));
}
@Override
public void drawScreen(int i, int j, float f)
{
slot.drawScreen(i, j, f);
super.drawScreen(i, j, f);
}
@Override
public void elementClicked(){
}
@Override
public void doubleClicked(){
DataGecko geckoData = (DataGecko) getGeckoData(npc);
geckoData.model=slot.selected;
GeckoAddonSupport.putGeckoData(npc, geckoData);
close();
NoppesUtil.openGUI(player, parent);
}
@Override
protected void actionPerformed(GuiButton guibutton){
int id = guibutton.id;
if(id == 2){
close();
NoppesUtil.openGUI(player, parent);
}
}
@Override
public void save() {
}
}
@@ -1,22 +0,0 @@
package noppes.npcs.client.model;
import net.minecraft.util.ResourceLocation;
import noppes.npcs.entity.EntityCustomModel;
import software.bernie.geckolib3.model.AnimatedGeoModel;
public class ModelCustom extends AnimatedGeoModel<EntityCustomModel> {
@Override
public ResourceLocation getAnimationFileLocation(EntityCustomModel entity) {
return entity.animResLoc;//new ResourceLocation(GeckoLib.ModID, "animations/bike.animation.json");
}
@Override
public ResourceLocation getModelLocation(EntityCustomModel entity) {
return entity.modelResLoc;//new ResourceLocation(GeckoLib.ModID, "geo/bike.geo.json");
}
@Override
public ResourceLocation getTextureLocation(EntityCustomModel entity) {
return entity.textureResLoc;//new ResourceLocation(GeckoLib.ModID, "textures/model/entity/bike.png");
}
}
@@ -1,65 +0,0 @@
package noppes.npcs.client.renderer;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.item.ItemStack;
import net.minecraftforge.client.IItemRenderer;
import noppes.npcs.client.model.ModelCustom;
import noppes.npcs.entity.EntityCustomModel;
import org.lwjgl.opengl.GL11;
import software.bernie.geckolib3.geo.render.built.GeoBone;
import software.bernie.geckolib3.geo.render.built.GeoModel;
import software.bernie.geckolib3.renderers.geo.GeoEntityRenderer;
import java.util.ArrayList;
public class RenderCustomModel extends GeoEntityRenderer<EntityCustomModel> {
public RenderCustomModel() {
super(new ModelCustom());
}
public void renderAfter(GeoModel model, EntityCustomModel animatable, float ticks, float red, float green, float blue, float alpha) {
super.renderAfter(model, animatable, ticks, red, green, blue, alpha);
if (model.getBone("held_item").isPresent() && animatable.getHeldItem() != null) {
GeoBone bone = model.getBone("held_item").get();
this.renderItem(animatable, bone, ticks);
}
}
public GeoBone[] getPathFromRoot(GeoBone bone) {
ArrayList bones;
for(bones = new ArrayList(); bone != null; bone = bone.parent) {
bones.add(0, bone);
}
return (GeoBone[])bones.toArray(new GeoBone[0]);
}
public void renderItem(EntityCustomModel animatable, GeoBone locator, float ticks) {
GL11.glPushMatrix();
float scale = 0.5F;
GL11.glScaled(scale, scale, scale);
GeoBone[] bonePath = this.getPathFromRoot(locator);
for(int i = 0; i < bonePath.length; ++i) {
GeoBone b = bonePath[i];
GL11.glTranslatef(b.getPositionX() / (16.0F * scale), b.getPositionY() / (16.0F * scale), b.getPositionZ() / (16.0F * scale));
GL11.glTranslatef(b.getPivotX() / (16.0F * scale), b.getPivotY() / (16.0F * scale), b.getPivotZ() / (16.0F * scale));
GL11.glRotated((double)b.getRotationZ() / Math.PI * 180.0, 0.0, 0.0, 1.0);
GL11.glRotated((double)b.getRotationY() / Math.PI * 180.0, 0.0, 1.0, 0.0);
GL11.glRotated((double)b.getRotationX() / Math.PI * 180.0, 1.0, 0.0, 0.0);
GL11.glScalef(b.getScaleX(), b.getScaleY(), b.getScaleZ());
GL11.glTranslatef(-b.getPivotX() / (16.0F * scale), -b.getPivotY() / (16.0F * scale), -b.getPivotZ() / (16.0F * scale));
}
GL11.glRotatef(250.0F, 1.0F, 0.0F, 0.0F);
GL11.glRotatef(40.0F, 0.0F, 1.0F, 0.0F);
GL11.glTranslatef(-0.4F, -0.55F, 1.7F);
ItemStack stack = animatable.getHeldItem();
RenderManager.instance.itemRenderer.renderItem(animatable, stack, 0, IItemRenderer.ItemRenderType.INVENTORY);
GL11.glPopMatrix();
}
public boolean isBoneRenderOverriden(EntityCustomModel entity, GeoBone bone) {
return bone.name.equals("held_item");
}
}
@@ -1,104 +0,0 @@
package noppes.npcs.entity;
import net.minecraft.entity.EntityCreature;
import net.minecraft.entity.ai.EntityAIWatchClosest;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import software.bernie.geckolib3.core.AnimationState;
import software.bernie.geckolib3.core.IAnimatable;
import software.bernie.geckolib3.core.IAnimationTickable;
import software.bernie.geckolib3.core.PlayState;
import software.bernie.geckolib3.core.builder.AnimationBuilder;
import software.bernie.geckolib3.core.controller.AnimationController;
import software.bernie.geckolib3.core.event.predicate.AnimationEvent;
import software.bernie.geckolib3.core.manager.AnimationData;
import software.bernie.geckolib3.core.manager.AnimationFactory;
import java.util.Objects;
public class EntityCustomModel extends EntityCreature implements IAnimatable, IAnimationTickable {
private AnimationFactory factory = new AnimationFactory(this);
public ResourceLocation modelResLoc = new ResourceLocation("geckolib3", "geo/npc.geo.json");
public ResourceLocation animResLoc = new ResourceLocation("custom", "geo_npc.animation.json");
public ResourceLocation textureResLoc = new ResourceLocation("geckolib3", "textures/model/entity/geo_npc.png");
public String idleAnim = "";
public String walkAnim = "";
public String hurtAnim = "";
public String attackAnim = "";
public AnimationBuilder dialogAnim = null;
public AnimationBuilder manualAnim = null;
public ItemStack leftHeldItem;
private <E extends IAnimatable> PlayState predicateMovement(AnimationEvent<E> event) {
if (manualAnim != null) {
if (event.getController().getAnimationState() == AnimationState.Stopped) {
manualAnim = null;
} else {
if (event.getController().currentAnimationBuilder != manualAnim) {
event.getController().markNeedsReload();
}
event.getController().setAnimation(manualAnim);
return PlayState.CONTINUE;
}
}
if (dialogAnim != null) {
if (event.getController().getAnimationState() == AnimationState.Stopped) {
dialogAnim = null;
} else {
if (event.getController().currentAnimationBuilder != dialogAnim) {
event.getController().markNeedsReload();
}
event.getController().setAnimation(dialogAnim);
return PlayState.CONTINUE;
}
}
if (!event.isMoving() || walkAnim.isEmpty()) {
if (!idleAnim.isEmpty()) {
event.getController().setAnimation(new AnimationBuilder().loop(idleAnim));
} else {
return PlayState.STOP;
}
} else {
event.getController().setAnimation(new AnimationBuilder().loop(walkAnim));
}
return PlayState.CONTINUE;
}
private <E extends IAnimatable> PlayState predicateAttack(AnimationEvent<E> event) {
return PlayState.CONTINUE;
}
public void setDialogAnim(String name) {
dialogAnim = new AnimationBuilder().playOnce(name);
}
public EntityCustomModel(World worldIn) {
super(worldIn);
this.ignoreFrustumCheck = true;
this.tasks.addTask(6, new EntityAIWatchClosest(this, EntityPlayer.class, 8.0F));
this.setSize(0.7F, 2F);
}
@Override
public void registerControllers(AnimationData data) {
data.addAnimationController(new AnimationController<>(this, "movement", 10, this::predicateMovement));
data.addAnimationController(new AnimationController<>(this, "attack", 10, this::predicateAttack));
}
@Override
public AnimationFactory getFactory() {
return this.factory;
}
@Override
public int tickTimer() {
return ticksExisted;
}
@Override
public void tick() {
super.onUpdate();
}
}
@@ -1,30 +0,0 @@
package noppes.npcs.util;
import net.minecraft.util.ResourceLocation;
import software.bernie.geckolib3.core.builder.Animation;
import software.bernie.geckolib3.file.AnimationFile;
import software.bernie.geckolib3.resource.GeckoLibCache;
import java.util.List;
import java.util.Vector;
public class AnimationFileUtil {
public static List<String> getAnimationList(String animFileName) {
Vector<String> list = new Vector<>();
AnimationFile file = GeckoLibCache.getInstance().getAnimations().get(new ResourceLocation(animFileName));
if (file != null) {
for (Animation anim : file.getAllAnimations()) {
list.add(anim.animationName);
}
}
return list;
}
public static List<String> getAnimationFileList() {
Vector<String> list = new Vector<>();
for (ResourceLocation resLoc : GeckoLibCache.getInstance().getAnimations().keySet()) {
list.add(resLoc.toString());
}
return list;
}
}