mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-22 21:20:04 +00:00
Added IProjectile and its events.
This commit is contained in:
1 parent
19e14983aa
commit
46d668f44c
8 files changed
+192
-5
No files matched your search
@@ -54,6 +54,7 @@ import noppes.npcs.controllers.data.FramePart;
|
||||
import noppes.npcs.controllers.data.SkinOverlay;
|
||||
import noppes.npcs.entity.EntityCustomNpc;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
import noppes.npcs.entity.EntityProjectile;
|
||||
import noppes.npcs.items.ItemScripted;
|
||||
import noppes.npcs.scripted.entity.*;
|
||||
import noppes.npcs.scripted.gui.ScriptGui;
|
||||
@@ -202,6 +203,8 @@ public class NpcAPI extends AbstractNpcAPI {
|
||||
data = new ScriptEntityData(new ScriptLiving<>((EntityLiving) entity));
|
||||
else if(entity instanceof EntityLivingBase)
|
||||
data = new ScriptEntityData(new ScriptLivingBase<>((EntityLivingBase)entity));
|
||||
else if(entity instanceof EntityProjectile)
|
||||
data = new ScriptEntityData(new ScriptProjectile<>((EntityProjectile)entity));
|
||||
else
|
||||
data = new ScriptEntityData(new ScriptEntity<>(entity));
|
||||
entity.registerExtendedProperties("ScriptedObject", data);
|
||||
|
||||
@@ -7,4 +7,6 @@ public class EntityType {
|
||||
public static final int MONSTER = 3;
|
||||
public static final int ANIMAL = 4;
|
||||
public static final int LIVING = 5;
|
||||
public static final int ITEM = 6;
|
||||
public static final int PROJECTILE = 7;
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
package noppes.npcs.scripted.entity;
|
||||
|
||||
import net.minecraft.util.MathHelper;
|
||||
import noppes.npcs.api.entity.IEntity;
|
||||
import noppes.npcs.api.entity.IProjectile;
|
||||
import noppes.npcs.api.item.IItemStack;
|
||||
import noppes.npcs.controllers.ScriptContainer;
|
||||
import noppes.npcs.entity.EntityProjectile;
|
||||
import noppes.npcs.scripted.CustomNPCsException;
|
||||
import noppes.npcs.scripted.NpcAPI;
|
||||
import noppes.npcs.scripted.constants.EntityType;
|
||||
|
||||
public class ScriptProjectile<T extends EntityProjectile> extends ScriptEntity<T> implements IProjectile {
|
||||
protected T entity;
|
||||
|
||||
public ScriptProjectile(T entity) {
|
||||
super(entity);
|
||||
this.entity = entity;
|
||||
}
|
||||
|
||||
public IItemStack getItem() {
|
||||
return NpcAPI.Instance().getIItemStack(entity.getItemDisplay());
|
||||
}
|
||||
|
||||
public void setItem(IItemStack item) {
|
||||
if(item == null)
|
||||
entity.setThrownItem(null);
|
||||
else
|
||||
entity.setThrownItem(item.getMCItemStack());
|
||||
}
|
||||
|
||||
public boolean getHasGravity() {
|
||||
return entity.hasGravity();
|
||||
}
|
||||
|
||||
public void setHasGravity(boolean bo) {
|
||||
entity.setHasGravity(bo);
|
||||
}
|
||||
|
||||
public int getAccuracy() {
|
||||
return entity.accuracy;
|
||||
}
|
||||
|
||||
public void setAccuracy(int accuracy) {
|
||||
entity.accuracy = accuracy;
|
||||
}
|
||||
|
||||
public void setHeading(IEntity entity) {
|
||||
setHeading(entity.getX(), entity.getMCEntity().boundingBox.minY + (double)(entity.getHeight() / 2.0F), entity.getZ());
|
||||
}
|
||||
|
||||
public void setHeading(double x, double y, double z) {
|
||||
x = x - entity.posX;
|
||||
y = y - entity.posY;
|
||||
z = z - entity.posZ;
|
||||
float varF = entity.hasGravity() ? (float) Math.sqrt(x * x + z * z) : 0.0F;
|
||||
float angle = entity.getAngleForXYZ(x, y, z, varF, false);
|
||||
float acc = (float) (20.0F - Math.floor(entity.accuracy / 5.0F));
|
||||
entity.setThrowableHeading(x, y, z, angle, acc);
|
||||
}
|
||||
|
||||
public void setHeading(float yaw, float pitch) {
|
||||
entity.prevRotationYaw = entity.rotationYaw = yaw;
|
||||
entity.prevRotationPitch = entity.rotationPitch = pitch;
|
||||
|
||||
double varX = (double)(-MathHelper.sin(yaw / 180.0F * (float)Math.PI) * MathHelper.cos(pitch / 180.0F * (float)Math.PI));
|
||||
double varZ = (double)(MathHelper.cos(yaw / 180.0F * (float)Math.PI) * MathHelper.cos(pitch / 180.0F * (float)Math.PI));
|
||||
double varY = (double)(-MathHelper.sin(pitch / 180.0F * (float)Math.PI));
|
||||
|
||||
float acc = (float) (20.0F - Math.floor(entity.accuracy / 5.0F));
|
||||
entity.setThrowableHeading(varX, varY, varZ, -pitch, acc);
|
||||
}
|
||||
|
||||
public int getType() {
|
||||
return EntityType.PROJECTILE;
|
||||
}
|
||||
|
||||
public boolean typeOf(int type){
|
||||
return type == EntityType.PROJECTILE || super.typeOf(type);
|
||||
}
|
||||
|
||||
public void enableEvents() {
|
||||
if(ScriptContainer.Current == null)
|
||||
throw new CustomNPCsException("Can only be called during scripts");
|
||||
|
||||
if(!entity.scripts.contains(ScriptContainer.Current)) {
|
||||
entity.scripts.add(ScriptContainer.Current);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package noppes.npcs.scripted.event;
|
||||
|
||||
import noppes.npcs.api.entity.IProjectile;
|
||||
|
||||
public class ProjectileEvent extends CustomNPCsEvent {
|
||||
public IProjectile projectile;
|
||||
|
||||
public ProjectileEvent(IProjectile projectile) {
|
||||
this.projectile = projectile;
|
||||
}
|
||||
|
||||
/**
|
||||
* projectileTick
|
||||
*/
|
||||
public static class UpdateEvent extends ProjectileEvent {
|
||||
public UpdateEvent(IProjectile projectile) {
|
||||
super(projectile);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* projectileImpact
|
||||
*/
|
||||
public static class ImpactEvent extends ProjectileEvent {
|
||||
/**
|
||||
* 0:entity, 1:block
|
||||
*/
|
||||
public final int type;
|
||||
public final Object target;
|
||||
|
||||
public ImpactEvent(IProjectile projectile, int type, Object target) {
|
||||
super(projectile);
|
||||
this.type = type;
|
||||
this.target = target;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user