mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-20 18:09:44 +00:00
Add mount role for NPCs with rider controls
This commit is contained in:
1 parent
082d22ba6e
commit
11e326de48
23 files changed
+476
-6
No files matched your search
@@ -0,0 +1,112 @@
|
||||
package noppes.npcs.roles;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
import noppes.npcs.util.ValueUtil;
|
||||
|
||||
public class RoleMount extends RoleInterface {
|
||||
|
||||
private float offsetX;
|
||||
private float offsetY;
|
||||
private float offsetZ;
|
||||
private boolean storedReturnToStart;
|
||||
|
||||
public RoleMount(EntityNPCInterface npc) {
|
||||
super(npc);
|
||||
this.storedReturnToStart = npc.ais.returnToStart;
|
||||
npc.ais.returnToStart = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
|
||||
compound.setFloat("MountOffsetX", offsetX);
|
||||
compound.setFloat("MountOffsetY", offsetY);
|
||||
compound.setFloat("MountOffsetZ", offsetZ);
|
||||
compound.setBoolean("MountReturnFlag", storedReturnToStart);
|
||||
return compound;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound compound) {
|
||||
setOffsetX(compound.getFloat("MountOffsetX"));
|
||||
setOffsetY(compound.getFloat("MountOffsetY"));
|
||||
setOffsetZ(compound.getFloat("MountOffsetZ"));
|
||||
if (compound.hasKey("MountReturnFlag")) {
|
||||
storedReturnToStart = compound.getBoolean("MountReturnFlag");
|
||||
} else {
|
||||
storedReturnToStart = npc.ais.returnToStart;
|
||||
}
|
||||
npc.ais.returnToStart = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void interact(EntityPlayer player) {
|
||||
if (player == null || npc.worldObj.isRemote) {
|
||||
return;
|
||||
}
|
||||
if (npc.riddenByEntity != null && npc.riddenByEntity != player) {
|
||||
return;
|
||||
}
|
||||
if (player.ridingEntity != null && player.ridingEntity != npc) {
|
||||
player.mountEntity(null);
|
||||
}
|
||||
player.fallDistance = 0.0F;
|
||||
npc.fallDistance = 0.0F;
|
||||
player.mountEntity(npc);
|
||||
npc.getNavigator().clearPathEntity();
|
||||
npc.setAttackTarget(null);
|
||||
npc.setRevengeTarget(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean aiShouldExecute() {
|
||||
if (npc.ais.returnToStart) {
|
||||
npc.ais.returnToStart = false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setOffsetX(float value) {
|
||||
this.offsetX = clamp(value);
|
||||
}
|
||||
|
||||
public void setOffsetY(float value) {
|
||||
this.offsetY = clamp(value);
|
||||
}
|
||||
|
||||
public void setOffsetZ(float value) {
|
||||
this.offsetZ = clamp(value);
|
||||
}
|
||||
|
||||
public float getOffsetX() {
|
||||
return offsetX;
|
||||
}
|
||||
|
||||
public float getOffsetY() {
|
||||
return offsetY;
|
||||
}
|
||||
|
||||
public float getOffsetZ() {
|
||||
return offsetZ;
|
||||
}
|
||||
|
||||
private float clamp(float value) {
|
||||
return ValueUtil.clamp(value, -5.0F, 5.0F);
|
||||
}
|
||||
|
||||
public void resetOffsets() {
|
||||
offsetX = 0.0F;
|
||||
offsetY = 0.0F;
|
||||
offsetZ = 0.0F;
|
||||
}
|
||||
|
||||
public void onDisable() {
|
||||
npc.ais.returnToStart = storedReturnToStart;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete() {
|
||||
onDisable();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user