mirror of
https://github.com/KAMKEEL/CustomNPC-Gecko-Addon.git
synced 2026-11-19 04:59:06 +00:00
Added classes for custom modeled tile entity, its model and renderer
This commit is contained in:
1 parent
642884f379
commit
b5736ed74f
3 files changed
+116
No files matched your search
@@ -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<TileEntityCustomModel> {
|
||||
@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;
|
||||
}
|
||||
}
|
||||
@@ -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<TileEntityCustomModel> {
|
||||
public RenderTileCustomModel() {
|
||||
super(new TileModelCustom());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 <E extends TileEntity & IAnimatable> PlayState predicate(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 (!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");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user