diff --git a/src/main/java/com/goodbird/npcgecko/client/model/TileModelCustom.java b/src/main/java/com/goodbird/npcgecko/client/model/TileModelCustom.java new file mode 100644 index 0000000..8c011c1 --- /dev/null +++ b/src/main/java/com/goodbird/npcgecko/client/model/TileModelCustom.java @@ -0,0 +1,22 @@ +package com.goodbird.npcgecko.client.model; + +import com.goodbird.npcgecko.tile.TileEntityCustomModel; +import net.minecraft.util.ResourceLocation; +import software.bernie.geckolib3.model.AnimatedGeoModel; + +public class TileModelCustom extends AnimatedGeoModel { + @Override + public ResourceLocation getAnimationFileLocation(TileEntityCustomModel entity) { + return entity.animResLoc; + } + + @Override + public ResourceLocation getModelLocation(TileEntityCustomModel animatable) { + return animatable.modelResLoc; + } + + @Override + public ResourceLocation getTextureLocation(TileEntityCustomModel entity) { + return entity.textureResLoc; + } +} diff --git a/src/main/java/com/goodbird/npcgecko/client/renderer/RenderTileCustomModel.java b/src/main/java/com/goodbird/npcgecko/client/renderer/RenderTileCustomModel.java new file mode 100644 index 0000000..c10f567 --- /dev/null +++ b/src/main/java/com/goodbird/npcgecko/client/renderer/RenderTileCustomModel.java @@ -0,0 +1,13 @@ +package com.goodbird.npcgecko.client.renderer; + +import com.goodbird.npcgecko.client.model.TileModelCustom; +import com.goodbird.npcgecko.tile.TileEntityCustomModel; +import software.bernie.example.client.model.tile.BotariumModel; +import software.bernie.geckolib3.renderers.geo.GeoBlockRenderer; + +public class RenderTileCustomModel extends GeoBlockRenderer { + public RenderTileCustomModel() { + super(new TileModelCustom()); + } +} + diff --git a/src/main/java/com/goodbird/npcgecko/tile/TileEntityCustomModel.java b/src/main/java/com/goodbird/npcgecko/tile/TileEntityCustomModel.java new file mode 100644 index 0000000..600dee3 --- /dev/null +++ b/src/main/java/com/goodbird/npcgecko/tile/TileEntityCustomModel.java @@ -0,0 +1,81 @@ +package com.goodbird.npcgecko.tile; + +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.ResourceLocation; +import software.bernie.geckolib3.GeckoLib; +import software.bernie.geckolib3.core.AnimationState; +import software.bernie.geckolib3.core.IAnimatable; +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; + +public class TileEntityCustomModel extends TileEntity implements IAnimatable { + private final AnimationFactory factory = new AnimationFactory(this); + public ResourceLocation modelResLoc = new ResourceLocation(GeckoLib.ModID, "geo/botarium.geo.json"); + public ResourceLocation animResLoc = new ResourceLocation(GeckoLib.ModID, "animations/botarium.animation.json"); + public ResourceLocation textureResLoc = new ResourceLocation(GeckoLib.ModID, "textures/block/botarium.png"); + public String idleAnimName = ""; + public AnimationBuilder manualAnim = null; + + public TileEntityCustomModel(){ + + } + public TileEntityCustomModel(TileEntity other){ + setWorldObj(other.getWorldObj()); + xCoord = other.xCoord; + yCoord = other.yCoord; + zCoord = other.zCoord; + } + + private PlayState predicate(AnimationEvent 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 (!idleAnimName.isEmpty()) { + event.getController().setAnimation(new AnimationBuilder().loop(idleAnimName)); + } else { + return PlayState.STOP; + } + return PlayState.CONTINUE; + } + + @Override + public void registerControllers(AnimationData data) { + data.addAnimationController(new AnimationController<>(this, "controller", 0, this::predicate)); + } + + @Override + public AnimationFactory getFactory() { + return factory; + } + + @Override + public void writeToNBT(NBTTagCompound compound) { + super.writeToNBT(compound); + compound.setString("modelResLoc", modelResLoc.toString()); + compound.setString("animResLoc", animResLoc.toString()); + compound.setString("textureResLoc", textureResLoc.toString()); + compound.setString("idleAnimName", idleAnimName); + } + + @Override + public void readFromNBT(NBTTagCompound compound) { + super.readFromNBT(compound); + modelResLoc = new ResourceLocation(compound.getString("modelResLoc")); + animResLoc = new ResourceLocation(compound.getString("animResLoc")); + textureResLoc = new ResourceLocation(compound.getString("textureResLoc")); + idleAnimName = compound.getString("idleAnimName"); + } +}