Merge pull request #22 from c0508383/master

Added collision options for CNPCs.
This commit is contained in:
Kamron Vaswani authored and GitHub committed 2022-01-14 21:51:16 -05:00
commit aba9dd250a
5 files changed
+88 -6

No files matched your search

@@ -52,6 +52,9 @@ public class DataDisplay {
public ArrayList<UUID> invisibleToList = new ArrayList<>();
//0 - Yes, 1 - No, 2 - Only NPCs, 3 - Only Players, 4 - NPCs and Players
public int collidesWith = 1;
public DataDisplay(EntityNPCInterface npc){
this.npc = npc;
markovGeneratorId = new Random().nextInt(CustomNpcs.MARKOV_GENERATOR.length-1);
@@ -89,6 +92,8 @@ public class DataDisplay {
nbttagcompound.setBoolean("NoLivingAnimation", disableLivingAnimation);
nbttagcompound.setByte("BossBar", showBossBar);
nbttagcompound.setInteger("CollidesWith",collidesWith);
NBTTagList list = new NBTTagList();
for(UUID uuid : invisibleToList){
list.appendTag(new NBTTagString(uuid.toString()));
@@ -148,6 +153,11 @@ public class DataDisplay {
invisibleToList = new ArrayList<>();
}
if(nbttagcompound.hasKey("CollidesWith"))
collidesWith = nbttagcompound.getInteger("CollidesWith");
else
collidesWith = 1;
if(prevSkinType != skinType || !texture.equals(prevTexture))
npc.textureLocation = null;
npc.textureGlowLocation = null;
@@ -82,6 +82,9 @@ public class GuiNpcDisplay extends GuiNPCInterface2 implements ITextfieldListene
addLabel(new GuiNpcLabel(5,"display.livingAnimation", guiLeft + 5, y + 5));
this.addButton(new GuiNpcButton(5, guiLeft + 120, y, 50, 20, new String[]{"gui.yes","gui.no"}, display.disableLivingAnimation?1:0));
addLabel(new GuiNpcLabel(6,"Collides With Entities", guiLeft + 185, y + 5));
this.addButton(new GuiNpcButton(6, guiLeft + 300, y, 100, 20, new String[]{"gui.yes","gui.no","Only CNPCs","Only Players","CNPCs & Players"}, display.collidesWith));
y+=23;
addLabel(new GuiNpcLabel(7,"display.visible", guiLeft + 5, y + 5));
this.addButton(new GuiNpcButton(7, guiLeft + 120, y, 50, 20, new String[]{"gui.yes","gui.no","gui.partly"}, display.visible));
@@ -155,6 +158,9 @@ public class GuiNpcDisplay extends GuiNPCInterface2 implements ITextfieldListene
else if(button.id == 5){
display.disableLivingAnimation = button.getValue() == 1;
}
else if(button.id == 6){
display.collidesWith = button.getValue();
}
else if(button.id == 7){
display.visible = button.getValue();
}
@@ -1604,17 +1604,72 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti
// obviously we dont want this
@Override
public boolean canBePushed() {
return false;
return this.display.collidesWith == 0;
}
// checks for any entity within a certain boundingbox, eg minecarts
@Override
protected void collideWithNearbyEntities() {
if(this.display.collidesWith != 1) {
List list = this.worldObj.getEntitiesWithinAABBExcludingEntity(this, this.boundingBox.expand(0.20000000298023224D, 0.0D, 0.20000000298023224D));
if (list != null && !list.isEmpty()) {
for (int i = 0; i < list.size(); ++i) {
Entity entity = (Entity) list.get(i);
if (this.canBePushed() ||
(entity instanceof EntityNPCInterface && (this.display.collidesWith == 2 || this.display.collidesWith == 4)) ||
(entity instanceof EntityPlayerMP && (this.display.collidesWith == 3 || this.display.collidesWith == 4))
) {
super.collideWithEntity(entity);
}
}
}
}
}
public void applyEntityCollision(Entity entity)
{
if (entity.riddenByEntity != this && entity.ridingEntity != this)
{
double d0 = entity.posX - this.posX;
double d1 = entity.posZ - this.posZ;
double d2 = MathHelper.abs_max(d0, d1);
if (d2 >= 0.009999999776482582D)
{
d2 = (double)MathHelper.sqrt_double(d2);
d0 /= d2;
d1 /= d2;
double d3 = 1.0D / d2;
if (d3 > 1.0D)
{
d3 = 1.0D;
}
d0 *= d3;
d1 *= d3;
d0 *= 0.05000000074505806D;
d1 *= 0.05000000074505806D;
d0 *= (double)(1.0F - this.entityCollisionReduction);
d1 *= (double)(1.0F - this.entityCollisionReduction);
if (this.canBePushed() ||
(entity instanceof EntityNPCInterface && (this.display.collidesWith == 2 || this.display.collidesWith == 4)) ||
(entity instanceof EntityPlayerMP && (this.display.collidesWith == 3 || this.display.collidesWith == 4))
)
this.addVelocity(-d0, 0.0D, -d1);
entity.addVelocity(d0, 0.0D, d1);
}
}
}
// not any entity can collide. if you want projectiles to still be
// effective, you will have to handle those yourself
@Override
protected void collideWithEntity(Entity p_82167_1_) {}
protected void collideWithEntity(Entity p_82167_1_) {
// checks for any entity within a certain boundingbox, eg minecarts
@Override
protected void collideWithNearbyEntities() {}
}
public boolean canFly(){
return false;
@@ -1105,5 +1105,12 @@ public class ScriptNpc<T extends EntityNPCInterface> extends ScriptLiving<T> imp
return npc.display.glowTexture;
}
public void updateClient() { this.npc.updateClient(); };
public void setCollisionType(int type){
npc.display.collidesWith = type;
}
public int getCollisionType(){
return npc.display.collidesWith;
}
public void updateClient() { this.npc.updateClient(); }
}
@@ -729,5 +729,9 @@ public interface ICustomNpc<T extends EntityCreature> extends IEntityLiving<T> {
public String getOverlayTexture();
public void setCollisionType(int type);
public int getCollisionType();
public void updateClient();
}