mirror of
https://github.com/KAMKEEL/CustomNPC-Gecko-Addon.git
synced 2026-11-19 04:59:06 +00:00
More Gecko Addon API Support
This commit is contained in:
1 parent
40b07df4a5
commit
0f64440e6c
17 files changed
+1490
-34
No files matched your search
@@ -6,7 +6,6 @@ import noppes.npcs.api.block.IBlockScripted;
|
||||
import noppes.npcs.api.entity.ICustomNpc;
|
||||
import noppes.npcs.api.entity.IPlayer;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
import software.bernie.geckolib3.core.builder.AnimationBuilder;
|
||||
|
||||
public abstract class AbstractGeckoAPI {
|
||||
private static AbstractGeckoAPI instance = null;
|
||||
@@ -31,31 +30,202 @@ public abstract class AbstractGeckoAPI {
|
||||
}
|
||||
}
|
||||
|
||||
public abstract AnimationBuilder createAnimationBuilder();
|
||||
// ========================================================================
|
||||
// Animation Builder
|
||||
// ========================================================================
|
||||
|
||||
/**
|
||||
* Create a new animation builder for constructing animation sequences.
|
||||
*
|
||||
* @return A new animation builder
|
||||
*/
|
||||
public abstract IGeckoAnimationBuilder createAnimBuilder();
|
||||
|
||||
/**
|
||||
* Create a new animation builder for constructing animation sequences.
|
||||
*
|
||||
* @return A new animation builder
|
||||
*/
|
||||
public abstract IGeckoAnimationBuilder createAnimationBuilder();
|
||||
|
||||
// ========================================================================
|
||||
// Animatable Access
|
||||
// ========================================================================
|
||||
|
||||
/**
|
||||
* Get the animation configuration interface for an NPC.
|
||||
*
|
||||
* @param npc The NPC to get animation config for
|
||||
* @return The animatable interface for this NPC
|
||||
*/
|
||||
public abstract IGeckoAnimatable getAnimatable(ICustomNpc<EntityNPCInterface> npc);
|
||||
|
||||
/**
|
||||
* Get the animation configuration interface for a scripted block.
|
||||
*
|
||||
* @param scriptedBlock The block to get animation config for
|
||||
* @return The animatable interface for this block
|
||||
*/
|
||||
public abstract IGeckoAnimatable getAnimatable(IBlockScripted scriptedBlock);
|
||||
|
||||
// ========================================================================
|
||||
// Animation Queries
|
||||
// ========================================================================
|
||||
|
||||
/**
|
||||
* Get a list of all animation names in an animation file.
|
||||
*
|
||||
* @param animationFile The animation file resource location (e.g. "npcgecko:animations/geo_npc.animation.json")
|
||||
* @return Array of animation names, or empty array if file not found
|
||||
*/
|
||||
public abstract String[] getAnimationList(String animationFile);
|
||||
|
||||
/**
|
||||
* Get a list of all loaded animation file resource locations.
|
||||
*
|
||||
* @return Array of animation file paths
|
||||
*/
|
||||
public abstract String[] getAnimationFileList();
|
||||
|
||||
/**
|
||||
* Get animation metadata from a loaded animation file.
|
||||
*
|
||||
* @param animationFile The animation file resource location
|
||||
* @param animationName The animation name within the file
|
||||
* @return The animation metadata, or null if not found
|
||||
*/
|
||||
public abstract IGeckoAnimation getAnimation(String animationFile, String animationName);
|
||||
|
||||
// ========================================================================
|
||||
// Color Utilities
|
||||
// ========================================================================
|
||||
|
||||
/**
|
||||
* Create a color from RGB components.
|
||||
*
|
||||
* @param r Red component (0-255)
|
||||
* @param g Green component (0-255)
|
||||
* @param b Blue component (0-255)
|
||||
* @return A new color
|
||||
*/
|
||||
public abstract IGeckoColor colorOfRGB(int r, int g, int b);
|
||||
|
||||
/**
|
||||
* Create a color from RGBA components.
|
||||
*
|
||||
* @param r Red component (0-255)
|
||||
* @param g Green component (0-255)
|
||||
* @param b Blue component (0-255)
|
||||
* @param a Alpha component (0-255)
|
||||
* @return A new color
|
||||
*/
|
||||
public abstract IGeckoColor colorOfRGBA(int r, int g, int b, int a);
|
||||
|
||||
// ========================================================================
|
||||
// NPC Methods
|
||||
// ========================================================================
|
||||
|
||||
/**
|
||||
* Set the geo model resource location for an NPC.
|
||||
*
|
||||
* @param npc The target NPC
|
||||
* @param model The model path (e.g. "geckolib3:geo/npc.geo.json")
|
||||
*/
|
||||
public abstract void setModel(ICustomNpc<EntityNPCInterface> npc, String model);
|
||||
|
||||
/**
|
||||
* Set the texture resource location for an NPC.
|
||||
*
|
||||
* @param npc The target NPC
|
||||
* @param texture The texture path
|
||||
*/
|
||||
public abstract void setTexture(ICustomNpc<EntityNPCInterface> npc, String texture);
|
||||
|
||||
/**
|
||||
* Set the animation file resource location for an NPC.
|
||||
*
|
||||
* @param npc The target NPC
|
||||
* @param animation The animation file path
|
||||
*/
|
||||
public abstract void setAnimationFile(ICustomNpc<EntityNPCInterface> npc, String animation);
|
||||
|
||||
/**
|
||||
* Set the idle animation name for an NPC.
|
||||
*
|
||||
* @param npc The target NPC
|
||||
* @param animation The animation name from the animation file
|
||||
*/
|
||||
public abstract void setIdleAnimation(ICustomNpc<EntityNPCInterface> npc, String animation);
|
||||
|
||||
public abstract void syncAnimForPlayer(ICustomNpc<EntityNPCInterface> npc, AnimationBuilder builder, IPlayer<EntityPlayerMP> player);
|
||||
/**
|
||||
* Sync an animation to a specific player for an NPC.
|
||||
*
|
||||
* @param npc The NPC to play the animation on
|
||||
* @param builder The animation builder with queued animations
|
||||
* @param player The player to send the animation to
|
||||
*/
|
||||
public abstract void syncAnimForPlayer(ICustomNpc<EntityNPCInterface> npc, IGeckoAnimationBuilder builder, IPlayer<EntityPlayerMP> player);
|
||||
|
||||
public abstract void syncAnimForAll(ICustomNpc<EntityNPCInterface> npc, AnimationBuilder builder);
|
||||
/**
|
||||
* Sync an animation to all players for an NPC.
|
||||
*
|
||||
* @param npc The NPC to play the animation on
|
||||
* @param builder The animation builder with queued animations
|
||||
*/
|
||||
public abstract void syncAnimForAll(ICustomNpc<EntityNPCInterface> npc, IGeckoAnimationBuilder builder);
|
||||
|
||||
// ========================================================================
|
||||
// Block Methods
|
||||
// ========================================================================
|
||||
|
||||
/**
|
||||
* Set the geo model resource location for a scripted block.
|
||||
*
|
||||
* @param scriptedBlock The target block
|
||||
* @param model The model path
|
||||
*/
|
||||
public abstract void setModel(IBlockScripted scriptedBlock, String model);
|
||||
|
||||
/**
|
||||
* Set the texture resource location for a scripted block.
|
||||
*
|
||||
* @param scriptedBlock The target block
|
||||
* @param texture The texture path
|
||||
*/
|
||||
public abstract void setTexture(IBlockScripted scriptedBlock, String texture);
|
||||
|
||||
/**
|
||||
* Set the animation file resource location for a scripted block.
|
||||
*
|
||||
* @param scriptedBlock The target block
|
||||
* @param animation The animation file path
|
||||
*/
|
||||
public abstract void setAnimationFile(IBlockScripted scriptedBlock, String animation);
|
||||
|
||||
/**
|
||||
* Set the idle animation name for a scripted block.
|
||||
*
|
||||
* @param scriptedBlock The target block
|
||||
* @param animation The animation name from the animation file
|
||||
*/
|
||||
public abstract void setIdleAnimation(IBlockScripted scriptedBlock, String animation);
|
||||
|
||||
public abstract void syncAnimForPlayer(IBlockScripted scriptedBlock, AnimationBuilder builder, IPlayer<EntityPlayerMP> player);
|
||||
/**
|
||||
* Sync an animation to a specific player for a scripted block.
|
||||
*
|
||||
* @param scriptedBlock The block to play the animation on
|
||||
* @param builder The animation builder with queued animations
|
||||
* @param player The player to send the animation to
|
||||
*/
|
||||
public abstract void syncAnimForPlayer(IBlockScripted scriptedBlock, IGeckoAnimationBuilder builder, IPlayer<EntityPlayerMP> player);
|
||||
|
||||
public abstract void syncAnimForAll(IBlockScripted scriptedBlock, AnimationBuilder builder);
|
||||
/**
|
||||
* Sync an animation to all players for a scripted block.
|
||||
*
|
||||
* @param scriptedBlock The block to play the animation on
|
||||
* @param builder The animation builder with queued animations
|
||||
*/
|
||||
public abstract void syncAnimForAll(IBlockScripted scriptedBlock, IGeckoAnimationBuilder builder);
|
||||
|
||||
// TODO: Fix ScriptCustomItem
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.goodbird.npcgecko.api;
|
||||
|
||||
import com.goodbird.npcgecko.wrapper.*;
|
||||
import com.goodbird.npcgecko.mixin.IDataDisplay;
|
||||
import com.goodbird.npcgecko.network.CPacketSyncManualAnim;
|
||||
import com.goodbird.npcgecko.network.CPacketSyncTileManualAnim;
|
||||
@@ -12,7 +13,11 @@ import noppes.npcs.api.entity.ICustomNpc;
|
||||
import noppes.npcs.api.entity.IPlayer;
|
||||
import noppes.npcs.blocks.tiles.TileScripted;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
import software.bernie.geckolib3.core.builder.Animation;
|
||||
import software.bernie.geckolib3.core.builder.AnimationBuilder;
|
||||
import software.bernie.geckolib3.core.util.Color;
|
||||
import software.bernie.geckolib3.file.AnimationFile;
|
||||
import software.bernie.geckolib3.resource.GeckoLibCache;
|
||||
|
||||
public class GeckoAPI extends AbstractGeckoAPI {
|
||||
private static AbstractGeckoAPI Instance;
|
||||
@@ -27,11 +32,105 @@ public class GeckoAPI extends AbstractGeckoAPI {
|
||||
return Instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AnimationBuilder createAnimationBuilder() {
|
||||
return new AnimationBuilder();
|
||||
// ========================================================================
|
||||
// Internal helper - unwrap IGeckoAnimationBuilder to GeckoLib AnimationBuilder
|
||||
// ========================================================================
|
||||
|
||||
private static AnimationBuilder unwrap(IGeckoAnimationBuilder builder) {
|
||||
return ((GeckoAnimationBuilderWrapper) builder).getBuilder();
|
||||
}
|
||||
|
||||
// ========================================================================
|
||||
// Animation Builder
|
||||
// ========================================================================
|
||||
|
||||
@Override
|
||||
public IGeckoAnimationBuilder createAnimBuilder() {
|
||||
return new GeckoAnimationBuilderWrapper(new AnimationBuilder());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IGeckoAnimationBuilder createAnimationBuilder() {
|
||||
return createAnimBuilder();
|
||||
}
|
||||
|
||||
// ========================================================================
|
||||
// Animatable Access
|
||||
// ========================================================================
|
||||
|
||||
@Override
|
||||
public IGeckoAnimatable getAnimatable(ICustomNpc<EntityNPCInterface> npc) {
|
||||
return new GeckoNpcAnimatable(npc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IGeckoAnimatable getAnimatable(IBlockScripted scriptedBlock) {
|
||||
TileEntityCustomModel tile = getOrCreateTECM(scriptedBlock);
|
||||
return new GeckoBlockAnimatable(scriptedBlock, tile);
|
||||
}
|
||||
|
||||
// ========================================================================
|
||||
// Animation Queries
|
||||
// ========================================================================
|
||||
|
||||
@Override
|
||||
public String[] getAnimationList(String animationFile) {
|
||||
AnimationFile file = GeckoLibCache.getInstance().getAnimations().get(new ResourceLocation(animationFile));
|
||||
if (file == null) {
|
||||
return new String[0];
|
||||
}
|
||||
java.util.Collection<Animation> animations = file.getAllAnimations();
|
||||
String[] names = new String[animations.size()];
|
||||
int i = 0;
|
||||
for (Animation anim : animations) {
|
||||
names[i++] = anim.animationName;
|
||||
}
|
||||
return names;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getAnimationFileList() {
|
||||
java.util.Set<ResourceLocation> keys = GeckoLibCache.getInstance().getAnimations().keySet();
|
||||
String[] result = new String[keys.size()];
|
||||
int i = 0;
|
||||
for (ResourceLocation resLoc : keys) {
|
||||
result[i++] = resLoc.toString();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IGeckoAnimation getAnimation(String animationFile, String animationName) {
|
||||
AnimationFile file = GeckoLibCache.getInstance().getAnimations().get(new ResourceLocation(animationFile));
|
||||
if (file == null) {
|
||||
return null;
|
||||
}
|
||||
for (Animation anim : file.getAllAnimations()) {
|
||||
if (anim.animationName.equals(animationName)) {
|
||||
return new GeckoAnimationWrapper(anim);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// ========================================================================
|
||||
// Color Utilities
|
||||
// ========================================================================
|
||||
|
||||
@Override
|
||||
public IGeckoColor colorOfRGB(int r, int g, int b) {
|
||||
return new GeckoColorWrapper(Color.ofRGB(r, g, b));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IGeckoColor colorOfRGBA(int r, int g, int b, int a) {
|
||||
return new GeckoColorWrapper(Color.ofRGBA(r, g, b, a));
|
||||
}
|
||||
|
||||
// ========================================================================
|
||||
// NPC Methods
|
||||
// ========================================================================
|
||||
|
||||
@Override
|
||||
public void setModel(ICustomNpc<EntityNPCInterface> npc, String model) {
|
||||
((IDataDisplay) npc.getMCEntity().display).getCustomModelData().setModel(model);
|
||||
@@ -57,15 +156,18 @@ public class GeckoAPI extends AbstractGeckoAPI {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void syncAnimForPlayer(ICustomNpc<EntityNPCInterface> npc, AnimationBuilder builder, IPlayer<EntityPlayerMP> player) {
|
||||
NetworkHandler.sendToPlayer(new CPacketSyncManualAnim(npc.getMCEntity(), builder), player.getMCEntity());
|
||||
public void syncAnimForPlayer(ICustomNpc<EntityNPCInterface> npc, IGeckoAnimationBuilder builder, IPlayer<EntityPlayerMP> player) {
|
||||
NetworkHandler.sendToPlayer(new CPacketSyncManualAnim(npc.getMCEntity(), unwrap(builder)), player.getMCEntity());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void syncAnimForAll(ICustomNpc<EntityNPCInterface> npc, AnimationBuilder builder) {
|
||||
NetworkHandler.sendToAll(new CPacketSyncManualAnim(npc.getMCEntity(), builder));
|
||||
public void syncAnimForAll(ICustomNpc<EntityNPCInterface> npc, IGeckoAnimationBuilder builder) {
|
||||
NetworkHandler.sendToAll(new CPacketSyncManualAnim(npc.getMCEntity(), unwrap(builder)));
|
||||
}
|
||||
|
||||
// ========================================================================
|
||||
// Block Methods
|
||||
// ========================================================================
|
||||
|
||||
private TileEntityCustomModel getOrCreateTECM(IBlockScripted scriptedBlock) {
|
||||
TileScripted tile = (TileScripted) scriptedBlock.getMCTileEntity();
|
||||
@@ -104,13 +206,13 @@ public class GeckoAPI extends AbstractGeckoAPI {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void syncAnimForPlayer(IBlockScripted scriptedBlock, AnimationBuilder builder, IPlayer<EntityPlayerMP> player) {
|
||||
NetworkHandler.sendToPlayer(new CPacketSyncTileManualAnim(scriptedBlock.getMCTileEntity(), builder), player.getMCEntity());
|
||||
public void syncAnimForPlayer(IBlockScripted scriptedBlock, IGeckoAnimationBuilder builder, IPlayer<EntityPlayerMP> player) {
|
||||
NetworkHandler.sendToPlayer(new CPacketSyncTileManualAnim(scriptedBlock.getMCTileEntity(), unwrap(builder)), player.getMCEntity());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void syncAnimForAll(IBlockScripted scriptedBlock, AnimationBuilder builder) {
|
||||
NetworkHandler.sendToAll(new CPacketSyncTileManualAnim(scriptedBlock.getMCTileEntity(), builder));
|
||||
public void syncAnimForAll(IBlockScripted scriptedBlock, IGeckoAnimationBuilder builder) {
|
||||
NetworkHandler.sendToAll(new CPacketSyncTileManualAnim(scriptedBlock.getMCTileEntity(), unwrap(builder)));
|
||||
}
|
||||
|
||||
// private CustomItemModelData getOrCreateCIMD(ScriptCustomItem item){
|
||||
|
||||
@@ -0,0 +1,151 @@
|
||||
package com.goodbird.npcgecko.api;
|
||||
|
||||
/**
|
||||
* Interface for accessing and modifying Gecko model configuration on NPCs and scripted blocks.
|
||||
* Provides control over model, texture, animation files, and animation names for each state.
|
||||
*
|
||||
* <p>Obtain via {@link AbstractGeckoAPI#getAnimatable(noppes.npcs.api.entity.ICustomNpc)}
|
||||
* or {@link AbstractGeckoAPI#getAnimatable(noppes.npcs.api.block.IBlockScripted)}.</p>
|
||||
*/
|
||||
public interface IGeckoAnimatable {
|
||||
|
||||
/**
|
||||
* Get the geo model resource location.
|
||||
*
|
||||
* @return The model path (e.g. "geckolib3:geo/npc.geo.json")
|
||||
*/
|
||||
String getModel();
|
||||
|
||||
/**
|
||||
* Set the geo model resource location.
|
||||
*
|
||||
* @param model The model path (e.g. "geckolib3:geo/npc.geo.json")
|
||||
*/
|
||||
void setModel(String model);
|
||||
|
||||
/**
|
||||
* Get the texture resource location.
|
||||
*
|
||||
* @return The texture path
|
||||
*/
|
||||
String getTexture();
|
||||
|
||||
/**
|
||||
* Set the texture resource location.
|
||||
*
|
||||
* @param texture The texture path
|
||||
*/
|
||||
void setTexture(String texture);
|
||||
|
||||
/**
|
||||
* Get the animation file resource location.
|
||||
*
|
||||
* @return The animation file path (e.g. "npcgecko:animations/geo_npc.animation.json")
|
||||
*/
|
||||
String getAnimationFile();
|
||||
|
||||
/**
|
||||
* Set the animation file resource location.
|
||||
*
|
||||
* @param animationFile The animation file path
|
||||
*/
|
||||
void setAnimationFile(String animationFile);
|
||||
|
||||
/**
|
||||
* Get the idle animation name.
|
||||
*
|
||||
* @return The idle animation name, or empty string if none
|
||||
*/
|
||||
String getIdleAnimation();
|
||||
|
||||
/**
|
||||
* Set the idle animation name.
|
||||
*
|
||||
* @param animation The animation name from the animation file
|
||||
*/
|
||||
void setIdleAnimation(String animation);
|
||||
|
||||
/**
|
||||
* Get the walk animation name.
|
||||
*
|
||||
* @return The walk animation name, or empty string if none
|
||||
*/
|
||||
String getWalkAnimation();
|
||||
|
||||
/**
|
||||
* Set the walk animation name.
|
||||
*
|
||||
* @param animation The animation name from the animation file
|
||||
*/
|
||||
void setWalkAnimation(String animation);
|
||||
|
||||
/**
|
||||
* Get the hurt animation name.
|
||||
*
|
||||
* @return The hurt animation name, or empty string if none
|
||||
*/
|
||||
String getHurtAnimation();
|
||||
|
||||
/**
|
||||
* Set the hurt animation name.
|
||||
*
|
||||
* @param animation The animation name from the animation file
|
||||
*/
|
||||
void setHurtAnimation(String animation);
|
||||
|
||||
/**
|
||||
* Get the melee attack animation name.
|
||||
*
|
||||
* @return The melee attack animation name, or empty string if none
|
||||
*/
|
||||
String getMeleeAttackAnimation();
|
||||
|
||||
/**
|
||||
* Set the melee attack animation name.
|
||||
*
|
||||
* @param animation The animation name from the animation file
|
||||
*/
|
||||
void setMeleeAttackAnimation(String animation);
|
||||
|
||||
/**
|
||||
* Get the ranged attack animation name.
|
||||
*
|
||||
* @return The ranged attack animation name, or empty string if none
|
||||
*/
|
||||
String getRangedAttackAnimation();
|
||||
|
||||
/**
|
||||
* Set the ranged attack animation name.
|
||||
*
|
||||
* @param animation The animation name from the animation file
|
||||
*/
|
||||
void setRangedAttackAnimation(String animation);
|
||||
|
||||
/**
|
||||
* Get the bone name used for head tracking/rotation.
|
||||
*
|
||||
* @return The head bone name (default: "head")
|
||||
*/
|
||||
String getHeadBoneName();
|
||||
|
||||
/**
|
||||
* Set the bone name used for head tracking/rotation.
|
||||
*
|
||||
* @param boneName The bone name in the model
|
||||
*/
|
||||
void setHeadBoneName(String boneName);
|
||||
|
||||
/**
|
||||
* Get the transition duration between animations in ticks.
|
||||
*
|
||||
* @return Transition length in ticks (default: 10)
|
||||
*/
|
||||
int getTransitionLengthTicks();
|
||||
|
||||
/**
|
||||
* Set the transition duration between animations in ticks.
|
||||
*
|
||||
* @param ticks Transition length in ticks
|
||||
*/
|
||||
void setTransitionLengthTicks(int ticks);
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package com.goodbird.npcgecko.api;
|
||||
|
||||
/**
|
||||
* Interface for querying animation metadata from a loaded animation file.
|
||||
* Provides read-only access to animation properties defined in Blockbench.
|
||||
*
|
||||
* <p>Obtain via {@link AbstractGeckoAPI#getAnimation(String, String)}.</p>
|
||||
*/
|
||||
public interface IGeckoAnimation {
|
||||
|
||||
/**
|
||||
* Get the animation name as defined in the animation file.
|
||||
*
|
||||
* @return The animation name
|
||||
*/
|
||||
String getName();
|
||||
|
||||
/**
|
||||
* Get the duration of this animation in seconds.
|
||||
*
|
||||
* @return The animation length in seconds
|
||||
*/
|
||||
double getLength();
|
||||
|
||||
/**
|
||||
* Whether this animation loops by default.
|
||||
*
|
||||
* @return True if the animation loops
|
||||
*/
|
||||
boolean isLooping();
|
||||
|
||||
/**
|
||||
* Get the names of all bones that have keyframes in this animation.
|
||||
*
|
||||
* @return Array of bone names with animation data
|
||||
*/
|
||||
String[] getAnimatedBoneNames();
|
||||
|
||||
/**
|
||||
* Get the number of sound keyframes in this animation.
|
||||
*
|
||||
* @return The sound keyframe count
|
||||
*/
|
||||
int getSoundKeyframeCount();
|
||||
|
||||
/**
|
||||
* Get the number of particle keyframes in this animation.
|
||||
*
|
||||
* @return The particle keyframe count
|
||||
*/
|
||||
int getParticleKeyframeCount();
|
||||
|
||||
/**
|
||||
* Get the number of custom instruction keyframes in this animation.
|
||||
*
|
||||
* @return The custom instruction keyframe count
|
||||
*/
|
||||
int getCustomInstructionKeyframeCount();
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package com.goodbird.npcgecko.api;
|
||||
|
||||
/**
|
||||
* Builder interface for constructing animation sequences.
|
||||
* Follows the builder pattern - all methods return the builder for chaining.
|
||||
*
|
||||
* <p>Example usage in scripts:</p>
|
||||
* <pre>
|
||||
* var builder = GeckoAPI.Instance().createAnimationBuilder();
|
||||
* builder.playOnce("attack").loop("idle");
|
||||
* GeckoAPI.Instance().syncAnimForAll(npc, builder);
|
||||
* </pre>
|
||||
*/
|
||||
public interface IGeckoAnimationBuilder {
|
||||
|
||||
/**
|
||||
* Add an animation that plays once then moves to the next in queue.
|
||||
*
|
||||
* @param animationName The animation name matching the Blockbench file
|
||||
* @return This builder for chaining
|
||||
*/
|
||||
IGeckoAnimationBuilder playOnce(String animationName);
|
||||
|
||||
/**
|
||||
* Add an animation that loops indefinitely until replaced.
|
||||
*
|
||||
* @param animationName The animation name matching the Blockbench file
|
||||
* @return This builder for chaining
|
||||
*/
|
||||
IGeckoAnimationBuilder loop(String animationName);
|
||||
|
||||
/**
|
||||
* Add an animation that plays once and holds on the last frame.
|
||||
*
|
||||
* @param animationName The animation name matching the Blockbench file
|
||||
* @return This builder for chaining
|
||||
*/
|
||||
IGeckoAnimationBuilder playAndHold(String animationName);
|
||||
|
||||
/**
|
||||
* Add an animation to the queue with default loop behavior from the animation file.
|
||||
*
|
||||
* @param animationName The animation name matching the Blockbench file
|
||||
* @return This builder for chaining
|
||||
*/
|
||||
IGeckoAnimationBuilder addAnimation(String animationName);
|
||||
|
||||
/**
|
||||
* Add an animation to the queue repeated multiple times.
|
||||
*
|
||||
* @param animationName The animation name matching the Blockbench file
|
||||
* @param timesToRepeat How many times to repeat the animation
|
||||
* @return This builder for chaining
|
||||
*/
|
||||
IGeckoAnimationBuilder addRepeatingAnimation(String animationName, int timesToRepeat);
|
||||
|
||||
/**
|
||||
* Clear all animations currently in the builder.
|
||||
*
|
||||
* @return This builder for chaining
|
||||
*/
|
||||
IGeckoAnimationBuilder clearAnimations();
|
||||
}
|
||||
@@ -0,0 +1,188 @@
|
||||
package com.goodbird.npcgecko.api;
|
||||
|
||||
/**
|
||||
* Interface for querying and modifying bone transforms on a Gecko model at runtime.
|
||||
* Bones represent individual parts of a model (e.g. "head", "left_arm", "held_item").
|
||||
*
|
||||
* <p>Position values are relative offsets from the bone's rest position.
|
||||
* Rotation values are in radians. Scale values are multipliers (1.0 = default).</p>
|
||||
*/
|
||||
public interface IGeckoBone {
|
||||
|
||||
/**
|
||||
* Get the name of this bone as defined in the model file.
|
||||
*
|
||||
* @return The bone name
|
||||
*/
|
||||
String getName();
|
||||
|
||||
/**
|
||||
* @return The X position offset
|
||||
*/
|
||||
float getPositionX();
|
||||
|
||||
/**
|
||||
* @return The Y position offset
|
||||
*/
|
||||
float getPositionY();
|
||||
|
||||
/**
|
||||
* @return The Z position offset
|
||||
*/
|
||||
float getPositionZ();
|
||||
|
||||
/**
|
||||
* Set the X position offset.
|
||||
*
|
||||
* @param value The X position offset
|
||||
*/
|
||||
void setPositionX(float value);
|
||||
|
||||
/**
|
||||
* Set the Y position offset.
|
||||
*
|
||||
* @param value The Y position offset
|
||||
*/
|
||||
void setPositionY(float value);
|
||||
|
||||
/**
|
||||
* Set the Z position offset.
|
||||
*
|
||||
* @param value The Z position offset
|
||||
*/
|
||||
void setPositionZ(float value);
|
||||
|
||||
/**
|
||||
* @return The X rotation in radians
|
||||
*/
|
||||
float getRotationX();
|
||||
|
||||
/**
|
||||
* @return The Y rotation in radians
|
||||
*/
|
||||
float getRotationY();
|
||||
|
||||
/**
|
||||
* @return The Z rotation in radians
|
||||
*/
|
||||
float getRotationZ();
|
||||
|
||||
/**
|
||||
* Set the X rotation in radians.
|
||||
*
|
||||
* @param value The X rotation in radians
|
||||
*/
|
||||
void setRotationX(float value);
|
||||
|
||||
/**
|
||||
* Set the Y rotation in radians.
|
||||
*
|
||||
* @param value The Y rotation in radians
|
||||
*/
|
||||
void setRotationY(float value);
|
||||
|
||||
/**
|
||||
* Set the Z rotation in radians.
|
||||
*
|
||||
* @param value The Z rotation in radians
|
||||
*/
|
||||
void setRotationZ(float value);
|
||||
|
||||
/**
|
||||
* @return The X scale multiplier
|
||||
*/
|
||||
float getScaleX();
|
||||
|
||||
/**
|
||||
* @return The Y scale multiplier
|
||||
*/
|
||||
float getScaleY();
|
||||
|
||||
/**
|
||||
* @return The Z scale multiplier
|
||||
*/
|
||||
float getScaleZ();
|
||||
|
||||
/**
|
||||
* Set the X scale multiplier.
|
||||
*
|
||||
* @param value The X scale multiplier (1.0 = default)
|
||||
*/
|
||||
void setScaleX(float value);
|
||||
|
||||
/**
|
||||
* Set the Y scale multiplier.
|
||||
*
|
||||
* @param value The Y scale multiplier (1.0 = default)
|
||||
*/
|
||||
void setScaleY(float value);
|
||||
|
||||
/**
|
||||
* Set the Z scale multiplier.
|
||||
*
|
||||
* @param value The Z scale multiplier (1.0 = default)
|
||||
*/
|
||||
void setScaleZ(float value);
|
||||
|
||||
/**
|
||||
* @return The X pivot point
|
||||
*/
|
||||
float getPivotX();
|
||||
|
||||
/**
|
||||
* @return The Y pivot point
|
||||
*/
|
||||
float getPivotY();
|
||||
|
||||
/**
|
||||
* @return The Z pivot point
|
||||
*/
|
||||
float getPivotZ();
|
||||
|
||||
/**
|
||||
* Set the X pivot point.
|
||||
*
|
||||
* @param value The X pivot point
|
||||
*/
|
||||
void setPivotX(float value);
|
||||
|
||||
/**
|
||||
* Set the Y pivot point.
|
||||
*
|
||||
* @param value The Y pivot point
|
||||
*/
|
||||
void setPivotY(float value);
|
||||
|
||||
/**
|
||||
* Set the Z pivot point.
|
||||
*
|
||||
* @param value The Z pivot point
|
||||
*/
|
||||
void setPivotZ(float value);
|
||||
|
||||
/**
|
||||
* @return Whether this bone is hidden from rendering
|
||||
*/
|
||||
boolean isHidden();
|
||||
|
||||
/**
|
||||
* Set whether this bone is hidden from rendering.
|
||||
*
|
||||
* @param hidden True to hide this bone
|
||||
*/
|
||||
void setHidden(boolean hidden);
|
||||
|
||||
/**
|
||||
* Get the parent bone, or null if this is a root bone.
|
||||
*
|
||||
* @return The parent bone, or null
|
||||
*/
|
||||
IGeckoBone getParent();
|
||||
|
||||
/**
|
||||
* Get the child bones of this bone.
|
||||
*
|
||||
* @return Array of child bones
|
||||
*/
|
||||
IGeckoBone[] getChildBones();
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package com.goodbird.npcgecko.api;
|
||||
|
||||
/**
|
||||
* Interface for color manipulation. Provides access to RGBA color components
|
||||
* and common color operations.
|
||||
*
|
||||
* <p>Create colors using the factory methods on {@link AbstractGeckoAPI}:</p>
|
||||
* <pre>
|
||||
* var color = GeckoAPI.Instance().colorOfRGB(255, 0, 0); // Red
|
||||
* var alpha = GeckoAPI.Instance().colorOfRGBA(255, 0, 0, 128); // Semi-transparent red
|
||||
* </pre>
|
||||
*/
|
||||
public interface IGeckoColor {
|
||||
|
||||
/**
|
||||
* Get the packed ARGB color value.
|
||||
*
|
||||
* @return The packed color as an integer
|
||||
*/
|
||||
int getColor();
|
||||
|
||||
/**
|
||||
* @return The red component (0-255)
|
||||
*/
|
||||
int getRed();
|
||||
|
||||
/**
|
||||
* @return The green component (0-255)
|
||||
*/
|
||||
int getGreen();
|
||||
|
||||
/**
|
||||
* @return The blue component (0-255)
|
||||
*/
|
||||
int getBlue();
|
||||
|
||||
/**
|
||||
* @return The alpha component (0-255)
|
||||
*/
|
||||
int getAlpha();
|
||||
|
||||
/**
|
||||
* Create a brighter version of this color.
|
||||
*
|
||||
* @param factor How much brighter (0.0 = no change, 1.0 = white)
|
||||
* @return A new brighter color
|
||||
*/
|
||||
IGeckoColor brighter(double factor);
|
||||
|
||||
/**
|
||||
* Create a darker version of this color.
|
||||
*
|
||||
* @param factor How much darker (0.0 = no change, 1.0 = black)
|
||||
* @return A new darker color
|
||||
*/
|
||||
IGeckoColor darker(double factor);
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.goodbird.npcgecko.api;
|
||||
|
||||
/**
|
||||
* Read-only interface for querying the runtime state of a Gecko model.
|
||||
* Allows scripts to inspect model bones and their current transforms.
|
||||
*
|
||||
* <p>This interface provides access to the model's bone hierarchy after
|
||||
* animations have been applied, useful for attaching effects or
|
||||
* querying positions of specific model parts.</p>
|
||||
*/
|
||||
public interface IGeckoModel {
|
||||
|
||||
/**
|
||||
* Get a bone by name.
|
||||
*
|
||||
* @param name The bone name as defined in the model file
|
||||
* @return The bone, or null if not found
|
||||
*/
|
||||
IGeckoBone getBone(String name);
|
||||
|
||||
/**
|
||||
* Get the names of all bones in this model.
|
||||
*
|
||||
* @return Array of bone names
|
||||
*/
|
||||
String[] getBoneNames();
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package com.goodbird.npcgecko.wrapper;
|
||||
|
||||
import com.goodbird.npcgecko.api.IGeckoAnimationBuilder;
|
||||
import software.bernie.geckolib3.core.builder.AnimationBuilder;
|
||||
|
||||
/**
|
||||
* Wrapper around GeckoLib's {@link AnimationBuilder} that implements {@link IGeckoAnimationBuilder}.
|
||||
* This allows the scripting API to work with animation builders without exposing GeckoLib internals.
|
||||
*/
|
||||
public class GeckoAnimationBuilderWrapper implements IGeckoAnimationBuilder {
|
||||
private final AnimationBuilder builder;
|
||||
|
||||
public GeckoAnimationBuilderWrapper(AnimationBuilder builder) {
|
||||
this.builder = builder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IGeckoAnimationBuilder playOnce(String animationName) {
|
||||
builder.playOnce(animationName);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IGeckoAnimationBuilder loop(String animationName) {
|
||||
builder.loop(animationName);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IGeckoAnimationBuilder playAndHold(String animationName) {
|
||||
builder.playAndHold(animationName);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IGeckoAnimationBuilder addAnimation(String animationName) {
|
||||
builder.addAnimation(animationName);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IGeckoAnimationBuilder addRepeatingAnimation(String animationName, int timesToRepeat) {
|
||||
builder.addRepeatingAnimation(animationName, timesToRepeat);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IGeckoAnimationBuilder clearAnimations() {
|
||||
builder.clearAnimations();
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the underlying GeckoLib AnimationBuilder.
|
||||
* Used internally for network sync and animation application.
|
||||
*
|
||||
* @return The wrapped AnimationBuilder
|
||||
*/
|
||||
public AnimationBuilder getBuilder() {
|
||||
return builder;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package com.goodbird.npcgecko.wrapper;
|
||||
|
||||
import com.goodbird.npcgecko.api.IGeckoAnimation;
|
||||
import software.bernie.geckolib3.core.builder.Animation;
|
||||
|
||||
/**
|
||||
* Wrapper around GeckoLib's {@link Animation} that implements {@link IGeckoAnimation}.
|
||||
*/
|
||||
public class GeckoAnimationWrapper implements IGeckoAnimation {
|
||||
private final Animation animation;
|
||||
|
||||
public GeckoAnimationWrapper(Animation animation) {
|
||||
this.animation = animation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return animation.animationName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getLength() {
|
||||
return animation.animationLength != null ? animation.animationLength : 0.0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLooping() {
|
||||
return animation.loop != null && animation.loop.isRepeatingAfterEnd();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getAnimatedBoneNames() {
|
||||
if (animation.boneAnimations == null) {
|
||||
return new String[0];
|
||||
}
|
||||
String[] names = new String[animation.boneAnimations.size()];
|
||||
for (int i = 0; i < animation.boneAnimations.size(); i++) {
|
||||
names[i] = animation.boneAnimations.get(i).boneName;
|
||||
}
|
||||
return names;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSoundKeyframeCount() {
|
||||
return animation.soundKeyFrames != null ? animation.soundKeyFrames.size() : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getParticleKeyframeCount() {
|
||||
return animation.particleKeyFrames != null ? animation.particleKeyFrames.size() : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCustomInstructionKeyframeCount() {
|
||||
return animation.customInstructionKeyframes != null ? animation.customInstructionKeyframes.size() : 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
package com.goodbird.npcgecko.wrapper;
|
||||
|
||||
import com.goodbird.npcgecko.api.IGeckoAnimatable;
|
||||
import com.goodbird.npcgecko.tile.TileEntityCustomModel;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import noppes.npcs.api.block.IBlockScripted;
|
||||
import noppes.npcs.blocks.tiles.TileScripted;
|
||||
|
||||
/**
|
||||
* Implementation of {@link IGeckoAnimatable} that wraps a scripted block's {@link TileEntityCustomModel}.
|
||||
* Changes made through this interface are automatically synced to clients.
|
||||
*
|
||||
* <p>Note: Scripted blocks support a subset of animation features compared to NPCs.
|
||||
* Walk, hurt, melee attack, ranged attack animations, head bone name, and transition length
|
||||
* are not applicable to blocks and will return default/empty values.</p>
|
||||
*/
|
||||
public class GeckoBlockAnimatable implements IGeckoAnimatable {
|
||||
private final IBlockScripted block;
|
||||
private final TileEntityCustomModel tile;
|
||||
|
||||
public GeckoBlockAnimatable(IBlockScripted block, TileEntityCustomModel tile) {
|
||||
this.block = block;
|
||||
this.tile = tile;
|
||||
}
|
||||
|
||||
private void markDirty() {
|
||||
((TileScripted) block.getMCTileEntity()).needsClientUpdate = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getModel() {
|
||||
return tile.modelResLoc.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setModel(String model) {
|
||||
tile.modelResLoc = new ResourceLocation(model);
|
||||
markDirty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTexture() {
|
||||
return tile.textureResLoc.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTexture(String texture) {
|
||||
tile.textureResLoc = new ResourceLocation(texture);
|
||||
markDirty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAnimationFile() {
|
||||
return tile.animResLoc.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAnimationFile(String animationFile) {
|
||||
tile.animResLoc = new ResourceLocation(animationFile);
|
||||
markDirty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdleAnimation() {
|
||||
return tile.idleAnimName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setIdleAnimation(String animation) {
|
||||
tile.idleAnimName = animation;
|
||||
markDirty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getWalkAnimation() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWalkAnimation(String animation) {
|
||||
// Not applicable to blocks
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHurtAnimation() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHurtAnimation(String animation) {
|
||||
// Not applicable to blocks
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMeleeAttackAnimation() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMeleeAttackAnimation(String animation) {
|
||||
// Not applicable to blocks
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRangedAttackAnimation() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRangedAttackAnimation(String animation) {
|
||||
// Not applicable to blocks
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHeadBoneName() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHeadBoneName(String boneName) {
|
||||
// Not applicable to blocks
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTransitionLengthTicks() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTransitionLengthTicks(int ticks) {
|
||||
// Not applicable to blocks
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,170 @@
|
||||
package com.goodbird.npcgecko.wrapper;
|
||||
|
||||
import com.goodbird.npcgecko.api.IGeckoBone;
|
||||
import software.bernie.geckolib3.geo.render.built.GeoBone;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Wrapper around GeckoLib's {@link GeoBone} that implements {@link IGeckoBone}.
|
||||
*/
|
||||
public class GeckoBoneWrapper implements IGeckoBone {
|
||||
private final GeoBone bone;
|
||||
|
||||
public GeckoBoneWrapper(GeoBone bone) {
|
||||
this.bone = bone;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return bone.name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getPositionX() {
|
||||
return bone.getPositionX();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getPositionY() {
|
||||
return bone.getPositionY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getPositionZ() {
|
||||
return bone.getPositionZ();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPositionX(float value) {
|
||||
bone.setPositionX(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPositionY(float value) {
|
||||
bone.setPositionY(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPositionZ(float value) {
|
||||
bone.setPositionZ(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getRotationX() {
|
||||
return bone.getRotationX();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getRotationY() {
|
||||
return bone.getRotationY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getRotationZ() {
|
||||
return bone.getRotationZ();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRotationX(float value) {
|
||||
bone.setRotationX(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRotationY(float value) {
|
||||
bone.setRotationY(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRotationZ(float value) {
|
||||
bone.setRotationZ(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getScaleX() {
|
||||
return bone.getScaleX();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getScaleY() {
|
||||
return bone.getScaleY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getScaleZ() {
|
||||
return bone.getScaleZ();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setScaleX(float value) {
|
||||
bone.setScaleX(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setScaleY(float value) {
|
||||
bone.setScaleY(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setScaleZ(float value) {
|
||||
bone.setScaleZ(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getPivotX() {
|
||||
return bone.getPivotX();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getPivotY() {
|
||||
return bone.getPivotY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getPivotZ() {
|
||||
return bone.getPivotZ();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPivotX(float value) {
|
||||
bone.setPivotX(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPivotY(float value) {
|
||||
bone.setPivotY(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPivotZ(float value) {
|
||||
bone.setPivotZ(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isHidden() {
|
||||
return bone.isHidden();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHidden(boolean hidden) {
|
||||
bone.setHidden(hidden);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IGeckoBone getParent() {
|
||||
if (bone.parent == null) {
|
||||
return null;
|
||||
}
|
||||
return new GeckoBoneWrapper(bone.parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IGeckoBone[] getChildBones() {
|
||||
List<GeoBone> children = bone.childBones;
|
||||
IGeckoBone[] result = new IGeckoBone[children.size()];
|
||||
for (int i = 0; i < children.size(); i++) {
|
||||
result[i] = new GeckoBoneWrapper(children.get(i));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package com.goodbird.npcgecko.wrapper;
|
||||
|
||||
import com.goodbird.npcgecko.api.IGeckoColor;
|
||||
import software.bernie.geckolib3.core.util.Color;
|
||||
|
||||
/**
|
||||
* Wrapper around GeckoLib's {@link Color} that implements {@link IGeckoColor}.
|
||||
*/
|
||||
public class GeckoColorWrapper implements IGeckoColor {
|
||||
private final Color color;
|
||||
|
||||
public GeckoColorWrapper(Color color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getColor() {
|
||||
return color.getColor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRed() {
|
||||
return color.getRed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getGreen() {
|
||||
return color.getGreen();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBlue() {
|
||||
return color.getBlue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAlpha() {
|
||||
return color.getAlpha();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IGeckoColor brighter(double factor) {
|
||||
return new GeckoColorWrapper(color.brighter(factor));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IGeckoColor darker(double factor) {
|
||||
return new GeckoColorWrapper(color.darker(factor));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the underlying GeckoLib Color.
|
||||
*
|
||||
* @return The wrapped Color
|
||||
*/
|
||||
public Color getInternalColor() {
|
||||
return color;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.goodbird.npcgecko.wrapper;
|
||||
|
||||
import com.goodbird.npcgecko.api.IGeckoBone;
|
||||
import com.goodbird.npcgecko.api.IGeckoModel;
|
||||
import software.bernie.geckolib3.geo.render.built.GeoBone;
|
||||
import software.bernie.geckolib3.geo.render.built.GeoModel;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Wrapper around GeckoLib's {@link GeoModel} that implements {@link IGeckoModel}.
|
||||
*/
|
||||
public class GeckoModelWrapper implements IGeckoModel {
|
||||
private final GeoModel model;
|
||||
|
||||
public GeckoModelWrapper(GeoModel model) {
|
||||
this.model = model;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IGeckoBone getBone(String name) {
|
||||
if (model.getBone(name).isPresent()) {
|
||||
return new GeckoBoneWrapper(model.getBone(name).get());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getBoneNames() {
|
||||
List<String> names = new ArrayList<>();
|
||||
collectBoneNames(model.topLevelBones, names);
|
||||
return names.toArray(new String[0]);
|
||||
}
|
||||
|
||||
private void collectBoneNames(List<GeoBone> bones, List<String> names) {
|
||||
for (GeoBone bone : bones) {
|
||||
names.add(bone.name);
|
||||
if (bone.childBones != null && !bone.childBones.isEmpty()) {
|
||||
collectBoneNames(bone.childBones, names);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
package com.goodbird.npcgecko.wrapper;
|
||||
|
||||
import com.goodbird.npcgecko.api.IGeckoAnimatable;
|
||||
import com.goodbird.npcgecko.data.CustomModelData;
|
||||
import com.goodbird.npcgecko.mixin.IDataDisplay;
|
||||
import noppes.npcs.api.entity.ICustomNpc;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
|
||||
/**
|
||||
* Implementation of {@link IGeckoAnimatable} that wraps an NPC's {@link CustomModelData}.
|
||||
* Changes made through this interface are automatically synced to clients.
|
||||
*/
|
||||
public class GeckoNpcAnimatable implements IGeckoAnimatable {
|
||||
private final ICustomNpc<EntityNPCInterface> npc;
|
||||
private final CustomModelData data;
|
||||
|
||||
public GeckoNpcAnimatable(ICustomNpc<EntityNPCInterface> npc) {
|
||||
this.npc = npc;
|
||||
this.data = ((IDataDisplay) npc.getMCEntity().display).getCustomModelData();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getModel() {
|
||||
return data.getModel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setModel(String model) {
|
||||
data.setModel(model);
|
||||
npc.updateClient();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTexture() {
|
||||
return npc.getMCEntity().display.texture;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTexture(String texture) {
|
||||
npc.getMCEntity().display.texture = texture;
|
||||
npc.updateClient();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAnimationFile() {
|
||||
return data.getAnimFile();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAnimationFile(String animationFile) {
|
||||
data.setAnimFile(animationFile);
|
||||
npc.updateClient();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdleAnimation() {
|
||||
return data.getIdleAnim();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setIdleAnimation(String animation) {
|
||||
data.setIdleAnim(animation);
|
||||
npc.updateClient();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getWalkAnimation() {
|
||||
return data.getWalkAnim();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWalkAnimation(String animation) {
|
||||
data.setWalkAnim(animation);
|
||||
npc.updateClient();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHurtAnimation() {
|
||||
return data.getHurtAnim();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHurtAnimation(String animation) {
|
||||
data.setHurtAnim(animation);
|
||||
npc.updateClient();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMeleeAttackAnimation() {
|
||||
return data.getMeleeAttackAnim();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMeleeAttackAnimation(String animation) {
|
||||
data.setMeleeAttackAnim(animation);
|
||||
npc.updateClient();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRangedAttackAnimation() {
|
||||
return data.getRangedAttackAnim();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRangedAttackAnimation(String animation) {
|
||||
data.setRangedAttackAnim(animation);
|
||||
npc.updateClient();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHeadBoneName() {
|
||||
return data.getHeadBoneName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHeadBoneName(String boneName) {
|
||||
data.setHeadBoneName(boneName);
|
||||
npc.updateClient();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTransitionLengthTicks() {
|
||||
return data.getTransitionLengthTicks();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTransitionLengthTicks(int ticks) {
|
||||
data.setTransitionLengthTicks(ticks);
|
||||
npc.updateClient();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user