From ef2801006bcaeab3d67c10a64461823cfce892e4 Mon Sep 17 00:00:00 2001 From: William Blake Galbreath Date: Tue, 30 Apr 2019 19:17:21 -0500 Subject: [PATCH] Integrate ridables --- .../java/net/minecraft/server/BiomeBase.java | 1 + .../java/net/minecraft/server/Biomes.java | 23 ++ .../server/ControllerLookDolphin.java | 4 +- .../java/net/minecraft/server/Entity.java | 15 +- .../net/minecraft/server/EntityChicken.java | 17 +- .../java/net/minecraft/server/EntityCow.java | 20 +- .../net/minecraft/server/EntityCreeper.java | 14 ++ .../net/minecraft/server/EntityDolphin.java | 27 ++- .../net/minecraft/server/EntityDrowned.java | 7 +- .../minecraft/server/EntityEnderCrystal.java | 49 ++++ .../net/minecraft/server/EntityEnderman.java | 15 ++ .../net/minecraft/server/EntityEndermite.java | 17 +- .../java/net/minecraft/server/EntityFish.java | 33 ++- .../minecraft/server/EntityGiantZombie.java | 35 ++- .../net/minecraft/server/EntityGuardian.java | 37 ++- .../net/minecraft/server/EntityHorse.java | 10 +- .../minecraft/server/EntityHorseAbstract.java | 4 +- .../server/EntityHorseChestedAbstract.java | 18 +- .../minecraft/server/EntityHorseDonkey.java | 3 + .../net/minecraft/server/EntityHorseMule.java | 3 + .../minecraft/server/EntityHorseSkeleton.java | 15 +- .../minecraft/server/EntityHorseZombie.java | 12 +- .../net/minecraft/server/EntityHuman.java | 14 +- .../minecraft/server/EntityInsentient.java | 39 ++++ .../net/minecraft/server/EntityIronGolem.java | 15 ++ .../net/minecraft/server/EntityLiving.java | 28 ++- .../net/minecraft/server/EntityLlama.java | 37 ++- .../minecraft/server/EntityMushroomCow.java | 14 ++ .../net/minecraft/server/EntityOcelot.java | 14 ++ .../net/minecraft/server/EntityPhantom.java | 216 +++++++++++++++++- .../java/net/minecraft/server/EntityPig.java | 25 ++ .../net/minecraft/server/EntityPolarBear.java | 15 ++ .../net/minecraft/server/EntityRabbit.java | 2 +- .../net/minecraft/server/EntitySheep.java | 14 ++ .../minecraft/server/EntitySilverfish.java | 15 ++ .../server/EntitySkeletonAbstract.java | 15 ++ .../net/minecraft/server/EntitySlime.java | 2 +- .../net/minecraft/server/EntitySnowman.java | 15 ++ .../net/minecraft/server/EntitySpider.java | 15 ++ .../net/minecraft/server/EntitySquid.java | 57 +++++ .../server/EntityTameableAnimal.java | 6 + .../net/minecraft/server/EntityTypes.java | 6 + .../java/net/minecraft/server/EntityWolf.java | 14 ++ .../net/minecraft/server/EntityZombie.java | 15 ++ .../purpur/controller/ControllerLookWASD.java | 46 ++++ .../purpur/controller/ControllerMoveWASD.java | 77 +++++++ .../controller/ControllerMoveWASDFlying.java | 58 +++++ .../controller/ControllerMoveWASDWater.java | 42 ++++ .../craftbukkit/entity/CraftLivingEntity.java | 10 + 49 files changed, 1137 insertions(+), 68 deletions(-) create mode 100644 src/main/java/net/pl3x/purpur/controller/ControllerLookWASD.java create mode 100644 src/main/java/net/pl3x/purpur/controller/ControllerMoveWASD.java create mode 100644 src/main/java/net/pl3x/purpur/controller/ControllerMoveWASDFlying.java create mode 100644 src/main/java/net/pl3x/purpur/controller/ControllerMoveWASDWater.java diff --git a/src/main/java/net/minecraft/server/BiomeBase.java b/src/main/java/net/minecraft/server/BiomeBase.java index 72eb669c5..f1500f7a0 100644 --- a/src/main/java/net/minecraft/server/BiomeBase.java +++ b/src/main/java/net/minecraft/server/BiomeBase.java @@ -97,6 +97,7 @@ public abstract class BiomeBase { return this.m != null; } + protected void addMobSpawn(EnumCreatureType creaturetype, BiomeBase.BiomeMeta biomemeta) { a(creaturetype, biomemeta); } // Purpur - OBFHELPER protected void a(EnumCreatureType enumcreaturetype, BiomeBase.BiomeMeta biomebase_biomemeta) { ((List) this.u.get(enumcreaturetype)).add(biomebase_biomemeta); } diff --git a/src/main/java/net/minecraft/server/Biomes.java b/src/main/java/net/minecraft/server/Biomes.java index 317db4b12..69ba98b66 100644 --- a/src/main/java/net/minecraft/server/Biomes.java +++ b/src/main/java/net/minecraft/server/Biomes.java @@ -92,5 +92,28 @@ public abstract class Biomes { static { Collections.addAll(BiomeBase.b, new BiomeBase[] { Biomes.OCEAN, Biomes.PLAINS, Biomes.DESERT, Biomes.MOUNTAINS, Biomes.FOREST, Biomes.TAIGA, Biomes.SWAMP, Biomes.RIVER, Biomes.FROZEN_RIVER, Biomes.SNOWY_TUNDRA, Biomes.SNOWY_MOUNTAINS, Biomes.MUSHROOM_FIELDS, Biomes.MUSHROOM_FIELD_SHORE, Biomes.BEACH, Biomes.DESERT_HILLS, Biomes.WOODED_HILLS, Biomes.TAIGA_HILLS, Biomes.JUNGLE, Biomes.JUNGLE_HILLS, Biomes.JUNGLE_EDGE, Biomes.DEEP_OCEAN, Biomes.STONE_SHORE, Biomes.SNOWY_BEACH, Biomes.BIRCH_FOREST, Biomes.BIRCH_FOREST_HILLS, Biomes.DARK_FOREST, Biomes.SNOWY_TAIGA, Biomes.SNOWY_TAIGA_HILLS, Biomes.GIANT_TREE_TAIGA, Biomes.GIANT_TREE_TAIGA_HILLS, Biomes.WOODED_MOUNTAINS, Biomes.SAVANNA, Biomes.SAVANNA_PLATEAU, Biomes.BADLANDS, Biomes.WOODED_BADLANDS_PLATEAU, Biomes.BADLANDS_PLATEAU}); + + // Purpur start - add natural mob spawns (maybe find a better place for this?) + addSpawn("plains", EnumCreatureType.MONSTER, EntityTypes.GIANT, 5, 1, 1); + addSpawn("sunflower_plains", EnumCreatureType.MONSTER, EntityTypes.GIANT, 5, 1, 1); + addSpawn("desert", EnumCreatureType.MONSTER, EntityTypes.GIANT, 2, 1, 1); + addSpawn("desert_hills", EnumCreatureType.MONSTER, EntityTypes.GIANT, 2, 1, 1); + addSpawn("desert_lakes", EnumCreatureType.MONSTER, EntityTypes.GIANT, 2, 1, 1); + addSpawn("mountains", EnumCreatureType.MONSTER, EntityTypes.GIANT, 5, 1, 1); + addSpawn("gravelly_mountains", EnumCreatureType.MONSTER, EntityTypes.GIANT, 5, 1, 1); + addSpawn("modified_gravelly_mountains", EnumCreatureType.MONSTER, EntityTypes.GIANT, 5, 1, 1); + addSpawn("savanna", EnumCreatureType.MONSTER, EntityTypes.GIANT, 5, 1, 2); + addSpawn("savanna_plateau", EnumCreatureType.MONSTER, EntityTypes.GIANT, 5, 1, 2); + addSpawn("shattered_savanna", EnumCreatureType.MONSTER, EntityTypes.GIANT, 5, 1, 2); + addSpawn("shattered_savanna_plateau", EnumCreatureType.MONSTER, EntityTypes.GIANT, 5, 1, 2); + addSpawn("badlands", EnumCreatureType.MONSTER, EntityTypes.GIANT, 10, 1, 2); + addSpawn("badlands_plateau", EnumCreatureType.MONSTER, EntityTypes.GIANT, 10, 1, 2); + addSpawn("eroded_badlands", EnumCreatureType.MONSTER, EntityTypes.GIANT, 10, 1, 2); + addSpawn("modified_badlands_plateau", EnumCreatureType.MONSTER, EntityTypes.GIANT, 10, 2, 1); + } + + private static void addSpawn(String biome, EnumCreatureType ct, EntityTypes et, int weight, int min_group, int max_group) { + IRegistry.BIOME.get(new MinecraftKey(biome)).addMobSpawn(ct, new BiomeBase.BiomeMeta(et, weight, min_group, max_group)); } + // Purpur end } diff --git a/src/main/java/net/minecraft/server/ControllerLookDolphin.java b/src/main/java/net/minecraft/server/ControllerLookDolphin.java index 454627f65..df3d6cf28 100644 --- a/src/main/java/net/minecraft/server/ControllerLookDolphin.java +++ b/src/main/java/net/minecraft/server/ControllerLookDolphin.java @@ -1,6 +1,6 @@ package net.minecraft.server; -public class ControllerLookDolphin extends ControllerLook { +public class ControllerLookDolphin extends net.pl3x.purpur.controller.ControllerLookWASD { // Purpur private final int h; @@ -10,7 +10,7 @@ public class ControllerLookDolphin extends ControllerLook { } @Override - public void a() { + public void tick() { // Purpur if (this.d) { this.d = false; this.a.aM = this.a(this.a.aM, this.h() + 20.0F, this.b); diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java index 9834a8928..1b38ac55c 100644 --- a/src/main/java/net/minecraft/server/Entity.java +++ b/src/main/java/net/minecraft/server/Entity.java @@ -101,6 +101,7 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke private int id; public boolean i; public final boolean blocksEntitySpawning() { return this.i; } // Paper - OBFHELPER public final List passengers; + private EntityHuman rider; // Purpur protected int j; private Entity vehicle; public boolean attachedToPlayer; @@ -134,7 +135,7 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke public double H; public double I; public double J; - public float K; + public float K; public float getStepHeight() { return K; } public void setStepHeight(float stepHeight) { this.K = stepHeight; } // Purpur - OBFHELPER public boolean noclip; public float M; protected final Random random; @@ -2015,6 +2016,12 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke return this.world.getCubes(this, this.d(entitypose)); } + // Purpur start + public EntityHuman getRider() { + return rider; + } + // Purpur end + public void ejectPassengers() { for (int i = this.passengers.size() - 1; i >= 0; --i) { ((Entity) this.passengers.get(i)).stopRiding(); @@ -2073,6 +2080,7 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke // Spigot end if (!this.world.isClientSide && entity instanceof EntityHuman && !(this.getRidingPassenger() instanceof EntityHuman)) { this.passengers.add(0, entity); + this.rider = (EntityHuman) entity; // Purpur } else { this.passengers.add(entity); } @@ -2111,6 +2119,11 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke return false; } // Spigot end + // Purpur start + if (passengers.get(0) == rider) { + rider = null; + } + // Purpur end this.passengers.remove(entity); entity.j = 60; } diff --git a/src/main/java/net/minecraft/server/EntityChicken.java b/src/main/java/net/minecraft/server/EntityChicken.java index a374c3051..4ab6b4fc4 100644 --- a/src/main/java/net/minecraft/server/EntityChicken.java +++ b/src/main/java/net/minecraft/server/EntityChicken.java @@ -15,6 +15,11 @@ public class EntityChicken extends EntityAnimal { super(entitytypes, world); this.eggLayTime = this.random.nextInt(6000) + 6000; this.a(PathType.WATER, 0.0F); + // Purpur start + this.moveController = new net.pl3x.purpur.controller.ControllerMoveWASD(this); + this.lookController = new net.pl3x.purpur.controller.ControllerLookWASD(this); + this.canBeRiddenInWater = true; + // Purpur end } @Override @@ -65,7 +70,7 @@ public class EntityChicken extends EntityAnimal { } this.bz += this.bE * 2.0F; - if (!this.world.isClientSide && this.isAlive() && !this.isBaby() && !this.isChickenJockey() && --this.eggLayTime <= 0) { + if (this.isAlive() && !this.isBaby() && !this.isChickenJockey() && --this.eggLayTime <= 0 && getRider() == null) { // Purpur this.a(SoundEffects.ENTITY_CHICKEN_EGG, 1.0F, (this.random.nextFloat() - this.random.nextFloat()) * 0.2F + 1.0F); this.forceDrops = true; // CraftBukkit this.a((IMaterial) Items.EGG); @@ -75,6 +80,16 @@ public class EntityChicken extends EntityAnimal { } + // Purpur start - processInteract + @Override + public boolean a(EntityHuman entityhuman, EnumHand enumhand) { + if (super.a(entityhuman, enumhand)) { + return true; // vanilla action handled + } + return tryRide(entityhuman, enumhand); + } + // Purpur end + @Override public void b(float f, float f1) {} diff --git a/src/main/java/net/minecraft/server/EntityCow.java b/src/main/java/net/minecraft/server/EntityCow.java index 0139688c7..4e70a2fc8 100644 --- a/src/main/java/net/minecraft/server/EntityCow.java +++ b/src/main/java/net/minecraft/server/EntityCow.java @@ -9,6 +9,11 @@ public class EntityCow extends EntityAnimal { public EntityCow(EntityTypes entitytypes, World world) { super(entitytypes, world); + // Purpur start + this.moveController = new net.pl3x.purpur.controller.ControllerMoveWASD(this); + this.lookController = new net.pl3x.purpur.controller.ControllerLookWASD(this); + this.canBeRiddenInWater = true; + // Purpur end } @Override @@ -59,6 +64,15 @@ public class EntityCow extends EntityAnimal { @Override public boolean a(EntityHuman entityhuman, EnumHand enumhand) { + // Purpur start - processInteract + if (processInteract(entityhuman, enumhand)) { + return true; // vanilla action handled + } + return tryRide(entityhuman, enumhand); + } + + private boolean processInteract(EntityHuman entityhuman, EnumHand enumhand) { + // Purpur end ItemStack itemstack = entityhuman.b(enumhand); if (itemstack.getItem() == Items.BUCKET && !entityhuman.abilities.canInstantlyBuild && !this.isBaby()) { @@ -99,8 +113,8 @@ public class EntityCow extends EntityAnimal { mooshroom.setHealth(this.getHealth()); mooshroom.setAge(getAge()); mooshroom.u(this); - mooshroom.aQ = this.aQ; - mooshroom.aS = this.aS; + mooshroom.aK = this.aK; + mooshroom.aM = this.aM; mooshroom.lastYaw = this.lastYaw; mooshroom.lastPitch = this.lastPitch; if (this.hasCustomName()) { @@ -116,7 +130,7 @@ public class EntityCow extends EntityAnimal { itemstack.subtract(1); } for (int i = 0; i < 15; ++i) { - ((WorldServer) world).sendParticles(world.players, null, Particles.z, + ((WorldServer) world).sendParticles(((WorldServer) world).players, null, Particles.HAPPY_VILLAGER, locX + random.nextFloat(), locY + (random.nextFloat() * 2), locZ + random.nextFloat(), 1, random.nextGaussian() * 0.05D, random.nextGaussian() * 0.05D, random.nextGaussian() * 0.05D, 0, true); } diff --git a/src/main/java/net/minecraft/server/EntityCreeper.java b/src/main/java/net/minecraft/server/EntityCreeper.java index 0c2c3c730..e0bfe0345 100644 --- a/src/main/java/net/minecraft/server/EntityCreeper.java +++ b/src/main/java/net/minecraft/server/EntityCreeper.java @@ -20,6 +20,11 @@ public class EntityCreeper extends EntityMonster { public EntityCreeper(EntityTypes entitytypes, World world) { super(entitytypes, world); + // Purpur start + this.moveController = new net.pl3x.purpur.controller.ControllerMoveWASD(this); + this.lookController = new net.pl3x.purpur.controller.ControllerLookWASD(this); + this.canBeRiddenInWater = true; + // Purpur end } @Override @@ -184,6 +189,15 @@ public class EntityCreeper extends EntityMonster { @Override protected boolean a(EntityHuman entityhuman, EnumHand enumhand) { + // Purpur start - processInteract + if (processInteract(entityhuman, enumhand)) { + return true; // vanilla action handled + } + return tryRide(entityhuman, enumhand); + } + + private boolean processInteract(EntityHuman entityhuman, EnumHand enumhand) { + // Purpur end ItemStack itemstack = entityhuman.b(enumhand); if (itemstack.getItem() == Items.FLINT_AND_STEEL) { diff --git a/src/main/java/net/minecraft/server/EntityDolphin.java b/src/main/java/net/minecraft/server/EntityDolphin.java index 56394ccdc..07fe13619 100644 --- a/src/main/java/net/minecraft/server/EntityDolphin.java +++ b/src/main/java/net/minecraft/server/EntityDolphin.java @@ -20,6 +20,7 @@ public class EntityDolphin extends EntityWaterAnimal { this.moveController = new EntityDolphin.a(this); this.lookController = new ControllerLookDolphin(this, 10); this.setCanPickupLoot(true); + this.canBeRiddenInWater = true; // Purpur } @Nullable @@ -224,6 +225,15 @@ public class EntityDolphin extends EntityWaterAnimal { @Override protected boolean a(EntityHuman entityhuman, EnumHand enumhand) { + // Purpur start - processInteract + if (processInteract(entityhuman, enumhand)) { + return true; // vanilla action handled + } + return tryRide(entityhuman, enumhand); + } + + protected boolean processInteract(EntityHuman entityhuman, EnumHand enumhand) { + // Purpur end ItemStack itemstack = entityhuman.b(enumhand); if (!itemstack.isEmpty() && itemstack.getItem().a(TagsItem.FISHES)) { @@ -519,7 +529,7 @@ public class EntityDolphin extends EntityWaterAnimal { } } - static class a extends ControllerMove { + static class a extends net.pl3x.purpur.controller.ControllerMoveWASDWater { // Purpur private final EntityDolphin i; @@ -528,8 +538,21 @@ public class EntityDolphin extends EntityWaterAnimal { this.i = entitydolphin; } + // Purpur start + @Override + public void tick(EntityHuman rider) { + if (this.i.getAirTicks() < 150) { + // if drowning override player WASD controls to find air + tick(); + } else { + super.tick(rider); + this.i.setMot(this.i.getMot().add(0.0D, 0.005D, 0.0D)); + } + } + @Override - public void a() { + public void tick() { + // Purpur end if (this.i.isInWater()) { this.i.setMot(this.i.getMot().add(0.0D, 0.005D, 0.0D)); } diff --git a/src/main/java/net/minecraft/server/EntityDrowned.java b/src/main/java/net/minecraft/server/EntityDrowned.java index 449fbee60..482c4ee48 100644 --- a/src/main/java/net/minecraft/server/EntityDrowned.java +++ b/src/main/java/net/minecraft/server/EntityDrowned.java @@ -6,7 +6,7 @@ import javax.annotation.Nullable; public class EntityDrowned extends EntityZombie implements IRangedEntity { - private boolean bz; + private boolean bz; public boolean isSwimmingUp() { return this.bz; } // Purpur - OBFHELPER protected final NavigationGuardian b; protected final Navigation c; @@ -134,6 +134,7 @@ public class EntityDrowned extends EntityZombie implements IRangedEntity { return !this.isSwimming(); } + public boolean isSwimmingUpOrTargetIsInWater() { return eg(); } // Purpur - OBFHELPER private boolean eg() { if (this.bz) { return true; @@ -205,7 +206,7 @@ public class EntityDrowned extends EntityZombie implements IRangedEntity { this.bz = flag; } - static class d extends ControllerMove { + static class d extends net.pl3x.purpur.controller.ControllerMoveWASD { private final EntityDrowned i; @@ -215,7 +216,7 @@ public class EntityDrowned extends EntityZombie implements IRangedEntity { } @Override - public void a() { + public void tick() { EntityLiving entityliving = this.i.getGoalTarget(); if (this.i.eg() && this.i.isInWater()) { diff --git a/src/main/java/net/minecraft/server/EntityEnderCrystal.java b/src/main/java/net/minecraft/server/EntityEnderCrystal.java index 9491cb9de..871c65b88 100644 --- a/src/main/java/net/minecraft/server/EntityEnderCrystal.java +++ b/src/main/java/net/minecraft/server/EntityEnderCrystal.java @@ -13,6 +13,12 @@ public class EntityEnderCrystal extends Entity { private static final DataWatcherObject> c = DataWatcher.a(EntityEnderCrystal.class, DataWatcherRegistry.m); private static final DataWatcherObject d = DataWatcher.a(EntityEnderCrystal.class, DataWatcherRegistry.i); public int b; + // Purpur start + private EntityPhantom targetPhantom; + private int phantomBeamTicks = 0; + private int phantomDamageCooldown = 0; + private int idleCooldown = 0; + // Purpur end public EntityEnderCrystal(EntityTypes entitytypes, World world) { super(entitytypes, world); @@ -54,7 +60,50 @@ public class EntityEnderCrystal extends Entity { } } + // Purpur start + if (--idleCooldown > 0) { + return; // on cooldown + } + + if (targetPhantom == null) { + for (EntityPhantom phantom : world.a(EntityPhantom.class, getBoundingBox().grow(16, 16, 16))) { + if (phantom.hasLineOfSight(this)) { + attackPhantom(phantom); + break; + } + } + } else { + setBeamTarget(new BlockPosition(targetPhantom).add(0, -2, 0)); + if (--phantomBeamTicks > 0 && targetPhantom.isAlive()) { + phantomDamageCooldown--; + if (targetPhantom.hasLineOfSight(this)) { + if (phantomDamageCooldown <= 0) { + phantomDamageCooldown = 20; + targetPhantom.damageEntity(DamageSource.c(this, this), 1.0F); + } + } else { + forgetPhantom(); // no longer in sight + } + } else { + forgetPhantom(); // attacked long enough + } + } + } + + private void attackPhantom(EntityPhantom phantom) { + phantomDamageCooldown = 0; + phantomBeamTicks = 60; + targetPhantom = phantom; + } + + private void forgetPhantom() { + targetPhantom = null; + setBeamTarget(null); + phantomBeamTicks = 0; + phantomDamageCooldown = 0; + idleCooldown = 60; } + // Purpur end @Override protected void b(NBTTagCompound nbttagcompound) { diff --git a/src/main/java/net/minecraft/server/EntityEnderman.java b/src/main/java/net/minecraft/server/EntityEnderman.java index f08f139e9..434ffc0f4 100644 --- a/src/main/java/net/minecraft/server/EntityEnderman.java +++ b/src/main/java/net/minecraft/server/EntityEnderman.java @@ -24,6 +24,11 @@ public class EntityEnderman extends EntityMonster { super(entitytypes, world); this.K = 1.0F; this.a(PathType.WATER, -1.0F); + // Purpur start + this.moveController = new net.pl3x.purpur.controller.ControllerMoveWASD(this); + this.lookController = new net.pl3x.purpur.controller.ControllerLookWASD(this); + this.canBeRiddenInWater = true; + // Purpur end } @Override @@ -256,6 +261,16 @@ public class EntityEnderman extends EntityMonster { } + // Purpur start - processInteract + @Override + public boolean a(EntityHuman entityhuman, EnumHand enumhand) { + if (super.a(entityhuman, enumhand)) { + return true; // vanilla action handled + } + return tryRide(entityhuman, enumhand); + } + // Purpur end + public void setCarried(@Nullable IBlockData iblockdata) { this.datawatcher.set(EntityEnderman.d, Optional.ofNullable(iblockdata)); } diff --git a/src/main/java/net/minecraft/server/EntityEndermite.java b/src/main/java/net/minecraft/server/EntityEndermite.java index 10b0f9653..09c9be025 100644 --- a/src/main/java/net/minecraft/server/EntityEndermite.java +++ b/src/main/java/net/minecraft/server/EntityEndermite.java @@ -9,6 +9,11 @@ public class EntityEndermite extends EntityMonster { public EntityEndermite(EntityTypes entitytypes, World world) { super(entitytypes, world); this.f = 3; + // Purpur start + this.moveController = new net.pl3x.purpur.controller.ControllerMoveWASD(this); + this.lookController = new net.pl3x.purpur.controller.ControllerLookWASD(this); + this.canBeRiddenInWater = true; + // Purpur end } @Override @@ -18,7 +23,7 @@ public class EntityEndermite extends EntityMonster { this.goalSelector.a(3, new PathfinderGoalRandomStrollLand(this, 1.0D)); this.goalSelector.a(7, new PathfinderGoalLookAtPlayer(this, EntityHuman.class, 8.0F)); this.goalSelector.a(8, new PathfinderGoalRandomLookaround(this)); - this.targetSelector.a(1, (new PathfinderGoalHurtByTarget(this, new Class[0])).a()); + this.targetSelector.a(1, (new PathfinderGoalHurtByTarget(this, new Class[0])).a(new Class[0])); // Purpur - decompile error? this.targetSelector.a(2, new PathfinderGoalNearestAttackableTarget<>(this, EntityHuman.class, true)); } @@ -138,4 +143,14 @@ public class EntityEndermite extends EntityMonster { public EnumMonsterType getMonsterType() { return EnumMonsterType.ARTHROPOD; } + + // Purpur start - processInteract + @Override + public boolean a(EntityHuman entityhuman, EnumHand enumhand) { + if (super.a(entityhuman, enumhand)) { + return true; // vanilla action handled + } + return tryRide(entityhuman, enumhand); + } + // Purpur end } diff --git a/src/main/java/net/minecraft/server/EntityFish.java b/src/main/java/net/minecraft/server/EntityFish.java index a28fbdf1e..c014c6f6c 100644 --- a/src/main/java/net/minecraft/server/EntityFish.java +++ b/src/main/java/net/minecraft/server/EntityFish.java @@ -9,6 +9,10 @@ public abstract class EntityFish extends EntityWaterAnimal { public EntityFish(EntityTypes entitytypes, World world) { super(entitytypes, world); this.moveController = new EntityFish.a(this); + // Purpur start + this.lookController = new net.pl3x.purpur.controller.ControllerLookWASD(this); + this.canBeRiddenInWater = true; + // Purpur end } @Override @@ -75,11 +79,7 @@ public abstract class EntityFish extends EntityWaterAnimal { protected void initPathfinder() { super.initPathfinder(); this.goalSelector.a(0, new PathfinderGoalPanic(this, 1.25D)); - PathfinderGoalSelector pathfindergoalselector = this.goalSelector; - Predicate predicate = IEntitySelector.f; - - predicate.getClass(); - pathfindergoalselector.a(2, new PathfinderGoalAvoidTarget<>(this, EntityHuman.class, 8.0F, 1.6D, 1.4D, predicate::test)); + this.goalSelector.a(2, new PathfinderGoalAvoidTarget<>(this, EntityHuman.class, 8.0F, 1.6D, 1.4D, IEntitySelector.f::test)); // Purpur - decompile error? this.goalSelector.a(4, new EntityFish.b(this)); } @@ -91,7 +91,7 @@ public abstract class EntityFish extends EntityWaterAnimal { @Override public void e(Vec3D vec3d) { if (this.de() && this.isInWater()) { - this.a(0.01F, vec3d); + this.a(getRider() == null ? 0.1F : getSpeed(), vec3d); // Purpur this.move(EnumMoveType.SELF, this.getMot()); this.setMot(this.getMot().a(0.9D)); if (this.getGoalTarget() == null) { @@ -117,6 +117,15 @@ public abstract class EntityFish extends EntityWaterAnimal { @Override protected boolean a(EntityHuman entityhuman, EnumHand enumhand) { + // Purpur start - processInteract + if (processInteract(entityhuman, enumhand)) { + return true; // vanilla action handled + } + return tryRide(entityhuman, enumhand); + } + + protected boolean processInteract(EntityHuman entityhuman, EnumHand enumhand) { + // Purpur end ItemStack itemstack = entityhuman.b(enumhand); if (itemstack.getItem() == Items.WATER_BUCKET && this.isAlive()) { @@ -162,7 +171,7 @@ public abstract class EntityFish extends EntityWaterAnimal { return SoundEffects.ENTITY_FISH_SWIM; } - static class a extends ControllerMove { + static class a extends net.pl3x.purpur.controller.ControllerMoveWASDWater { // Purpur private final EntityFish i; @@ -171,8 +180,16 @@ public abstract class EntityFish extends EntityWaterAnimal { this.i = entityfish; } + // Purpur start + @Override + public void tick(EntityHuman rider) { + super.tick(rider); + this.i.setMot(this.i.getMot().add(0.0D, 0.005D, 0.0D)); + } + @Override - public void a() { + public void tick() { + // Purpur end if (this.i.a(TagsFluid.WATER)) { this.i.setMot(this.i.getMot().add(0.0D, 0.005D, 0.0D)); } diff --git a/src/main/java/net/minecraft/server/EntityGiantZombie.java b/src/main/java/net/minecraft/server/EntityGiantZombie.java index bcbade19e..3cfbc5c49 100644 --- a/src/main/java/net/minecraft/server/EntityGiantZombie.java +++ b/src/main/java/net/minecraft/server/EntityGiantZombie.java @@ -5,7 +5,11 @@ public class EntityGiantZombie extends EntityMonster { public EntityGiantZombie(EntityTypes entitytypes, World world) { super(entitytypes, world); // Purpur start + this.moveController = new net.pl3x.purpur.controller.ControllerMoveWASD(this); + this.lookController = new net.pl3x.purpur.controller.ControllerLookWASD(this); + this.canBeRiddenInWater = true; this.safeFallDistance = 10.0F; + setStepHeight(2.0F); // Purpur end } @@ -22,8 +26,37 @@ public class EntityGiantZombie extends EntityMonster { this.getAttributeInstance(GenericAttributes.ATTACK_DAMAGE).setValue(50.0D); } + // Purpur start @Override + protected void initPathfinder() { + this.goalSelector.a(0, new PathfinderGoalFloat(this)); + this.goalSelector.a(2, new PathfinderGoalMeleeAttack(this, 1.0D, false)); + this.goalSelector.a(7, new PathfinderGoalRandomStrollLand(this, 1.0D)); + this.goalSelector.a(8, new PathfinderGoalLookAtPlayer(this, EntityHuman.class, 16.0F)); + this.goalSelector.a(8, new PathfinderGoalRandomLookaround(this)); + this.goalSelector.a(5, new PathfinderGoalMoveTowardsRestriction(this, 1.0D)); + this.targetSelector.a(1, new PathfinderGoalHurtByTarget(this).a(EntityPigZombie.class)); + this.targetSelector.a(2, new PathfinderGoalNearestAttackableTarget<>(this, EntityHuman.class, true)); + this.targetSelector.a(3, new PathfinderGoalNearestAttackableTarget<>(this, EntityVillager.class, false)); + this.targetSelector.a(4, new PathfinderGoalNearestAttackableTarget<>(this, EntityIronGolem.class, true)); + this.targetSelector.a(5, new PathfinderGoalNearestAttackableTarget<>(this, EntityTurtle.class, true)); + } + + @Override + public float cW() { // jump height + return 1.0F; + } + + @Override + public boolean a(EntityHuman entityhuman, EnumHand enumhand) { // processInteract + if (super.a(entityhuman, enumhand)) { + return true; // vanilla action handled + } + return tryRide(entityhuman, enumhand); + } + // Purpur end + public float a(BlockPosition blockposition, IWorldReader iworldreader) { - return iworldreader.w(blockposition) - 0.5F; + return super.a(blockposition, iworldreader); // Purpur - fix light requirements for natural spawns } } diff --git a/src/main/java/net/minecraft/server/EntityGuardian.java b/src/main/java/net/minecraft/server/EntityGuardian.java index 335416d96..6c41730eb 100644 --- a/src/main/java/net/minecraft/server/EntityGuardian.java +++ b/src/main/java/net/minecraft/server/EntityGuardian.java @@ -22,8 +22,15 @@ public class EntityGuardian extends EntityMonster { super(entitytypes, world); this.f = 10; this.moveController = new EntityGuardian.ControllerMoveGuardian(this); - this.c = this.random.nextFloat(); - this.d = this.c; + // Purpur start + this.lookController = new net.pl3x.purpur.controller.ControllerLookWASD(this) { + @Override + public void setYawPitch(float yaw, float pitch) { + super.setYawPitch(yaw, pitch * 0.35F); + } + }; + this.canBeRiddenInWater = true; + // Purpur end } @Override @@ -77,6 +84,7 @@ public class EntityGuardian extends EntityMonster { return (Boolean) this.datawatcher.get(EntityGuardian.b); } + private void setMovingFlag(boolean movingFlag) { r(movingFlag); } // Purpur - OBFHELPER private void r(boolean flag) { this.datawatcher.set(EntityGuardian.b, flag); } @@ -302,7 +310,7 @@ public class EntityGuardian extends EntityMonster { @Override public void e(Vec3D vec3d) { if (this.de() && this.isInWater()) { - this.a(0.1F, vec3d); + this.a(getRider() == null ? 0.1F : getSpeed(), vec3d); // Purpur this.move(EnumMoveType.SELF, this.getMot()); this.setMot(this.getMot().a(0.9D)); if (!this.dY() && this.getGoalTarget() == null) { @@ -314,7 +322,17 @@ public class EntityGuardian extends EntityMonster { } - static class ControllerMoveGuardian extends ControllerMove { + // Purpur start - processInteract + @Override + public boolean a(EntityHuman entityhuman, EnumHand enumhand) { + if (super.a(entityhuman, enumhand)) { + return true; // vanilla action handled + } + return tryRide(entityhuman, enumhand); + } + // Purpur end + + static class ControllerMoveGuardian extends net.pl3x.purpur.controller.ControllerMoveWASDWater { // Purpur private final EntityGuardian i; @@ -324,7 +342,16 @@ public class EntityGuardian extends EntityMonster { } @Override - public void a() { + // Purpur start + public void tick(EntityHuman rider) { + super.tick(rider); + this.i.setMot(this.i.getMot().add(0.0D, 0.005D, 0.0D)); + this.i.setMovingFlag(this.i.getForward() > 0.0F); // control tail speed + } + + @Override + public void tick() { + // Purpur end if (this.h == ControllerMove.Operation.MOVE_TO && !this.i.getNavigation().n()) { Vec3D vec3d = new Vec3D(this.b - this.i.locX, this.c - this.i.locY, this.d - this.i.locZ); double d0 = vec3d.f(); diff --git a/src/main/java/net/minecraft/server/EntityHorse.java b/src/main/java/net/minecraft/server/EntityHorse.java index 401f00561..0e6759303 100644 --- a/src/main/java/net/minecraft/server/EntityHorse.java +++ b/src/main/java/net/minecraft/server/EntityHorse.java @@ -201,12 +201,14 @@ public class EntityHorse extends EntityHorseAbstract { } } - if (this.isBaby()) { - return super.a(entityhuman, enumhand); - } else { + // Purpur start - allow riding babies + //if (this.isBaby()) { + // return super.a(entityhuman, enumhand); + //} else { this.g(entityhuman); return true; - } + //} + // Purpur end } } diff --git a/src/main/java/net/minecraft/server/EntityHorseAbstract.java b/src/main/java/net/minecraft/server/EntityHorseAbstract.java index 686bca4f2..0250a5653 100644 --- a/src/main/java/net/minecraft/server/EntityHorseAbstract.java +++ b/src/main/java/net/minecraft/server/EntityHorseAbstract.java @@ -81,7 +81,7 @@ public abstract class EntityHorseAbstract extends EntityAnimal implements IInven } public boolean isTamed() { - return this.r(2); + return this.r(2) || isBaby(); // Purpur } @Nullable @@ -280,6 +280,7 @@ public abstract class EntityHorseAbstract extends EntityAnimal implements IInven return true; } + public boolean isSaddled() { return eq(); } // Purpur - OBFHELPER public boolean eq() { return this.r(4); } @@ -600,6 +601,7 @@ public abstract class EntityHorseAbstract extends EntityAnimal implements IInven } + public void makeMad() { eu(); } // Purpur - OBFHELPER public void eu() { this.eB(); SoundEffect soundeffect = this.getSoundAngry(); diff --git a/src/main/java/net/minecraft/server/EntityHorseChestedAbstract.java b/src/main/java/net/minecraft/server/EntityHorseChestedAbstract.java index e61d8f07d..371f2dcb9 100644 --- a/src/main/java/net/minecraft/server/EntityHorseChestedAbstract.java +++ b/src/main/java/net/minecraft/server/EntityHorseChestedAbstract.java @@ -152,8 +152,12 @@ public abstract class EntityHorseChestedAbstract extends EntityHorseAbstract { return true; } - this.eu(); - return true; + // Purpur start - don't make babies mad + if (!this.isBaby()) { + this.makeMad(); + return true; + } + // Purpur end } if (!this.isCarryingChest() && itemstack.getItem() == Blocks.CHEST.getItem()) { @@ -178,12 +182,14 @@ public abstract class EntityHorseChestedAbstract extends EntityHorseAbstract { } } - if (this.isBaby()) { - return super.a(entityhuman, enumhand); - } else { + // Purpur start - allow riding babies + //if (this.isBaby()) { + // return super.a(entityhuman, enumhand); + //} else { this.g(entityhuman); return true; - } + //} + // Purpur end } } diff --git a/src/main/java/net/minecraft/server/EntityHorseDonkey.java b/src/main/java/net/minecraft/server/EntityHorseDonkey.java index 46338f0f8..3083269a5 100644 --- a/src/main/java/net/minecraft/server/EntityHorseDonkey.java +++ b/src/main/java/net/minecraft/server/EntityHorseDonkey.java @@ -4,6 +4,9 @@ public class EntityHorseDonkey extends EntityHorseChestedAbstract { public EntityHorseDonkey(EntityTypes entitytypes, World world) { super(entitytypes, world); + // Purpur start + this.canBeRiddenInWater = true; + // Purpur end } @Override diff --git a/src/main/java/net/minecraft/server/EntityHorseMule.java b/src/main/java/net/minecraft/server/EntityHorseMule.java index ef930d194..119ca47d0 100644 --- a/src/main/java/net/minecraft/server/EntityHorseMule.java +++ b/src/main/java/net/minecraft/server/EntityHorseMule.java @@ -4,6 +4,9 @@ public class EntityHorseMule extends EntityHorseChestedAbstract { public EntityHorseMule(EntityTypes entitytypes, World world) { super(entitytypes, world); + // Purpur start + this.canBeRiddenInWater = true; + // Purpur end } @Override diff --git a/src/main/java/net/minecraft/server/EntityHorseSkeleton.java b/src/main/java/net/minecraft/server/EntityHorseSkeleton.java index b96726456..2193f218a 100644 --- a/src/main/java/net/minecraft/server/EntityHorseSkeleton.java +++ b/src/main/java/net/minecraft/server/EntityHorseSkeleton.java @@ -10,6 +10,9 @@ public class EntityHorseSkeleton extends EntityHorseAbstract { public EntityHorseSkeleton(EntityTypes entitytypes, World world) { super(entitytypes, world); + // Purpur start + this.canBeRiddenInWater = true; + // Purpur end } @Override @@ -154,18 +157,20 @@ public class EntityHorseSkeleton extends EntityHorseAbstract { if (itemstack.getItem() instanceof ItemMonsterEgg) { return super.a(entityhuman, enumhand); - } else if (!this.isTamed()) { + // Purpur start - allow riding babies + } else if (!this.isTamed() && !this.isBaby()) { return false; - } else if (this.isBaby()) { - return super.a(entityhuman, enumhand); - } else if (entityhuman.isSneaking()) { + //} else if (this.isBaby()) { + // return super.a(entityhuman, enumhand); + // Purpur end + } else if (entityhuman.isSneaking() && !this.isBaby()) { // Purpur - don't open inventory on babies this.e(entityhuman); return true; } else if (this.isVehicle()) { return super.a(entityhuman, enumhand); } else { if (!itemstack.isEmpty()) { - if (itemstack.getItem() == Items.SADDLE && !this.eq()) { + if (!this.isBaby() && itemstack.getItem() == Items.SADDLE && !this.isSaddled()) { // Purpur - don't open inventory on babies this.e(entityhuman); return true; } diff --git a/src/main/java/net/minecraft/server/EntityHorseZombie.java b/src/main/java/net/minecraft/server/EntityHorseZombie.java index 1160929e1..e25511ef1 100644 --- a/src/main/java/net/minecraft/server/EntityHorseZombie.java +++ b/src/main/java/net/minecraft/server/EntityHorseZombie.java @@ -51,18 +51,20 @@ public class EntityHorseZombie extends EntityHorseAbstract { if (itemstack.getItem() instanceof ItemMonsterEgg) { return super.a(entityhuman, enumhand); - } else if (!this.isTamed()) { + // Purpur start - allow riding babies + } else if (!this.isTamed() && !this.isBaby()) { return false; - } else if (this.isBaby()) { - return super.a(entityhuman, enumhand); - } else if (entityhuman.isSneaking()) { + //} else if (this.isBaby()) { + // return super.a(entityhuman, enumhand); + // Purpur end + } else if (entityhuman.isSneaking() && !this.isBaby()) { // Purpur - don't open inventory on babies this.e(entityhuman); return true; } else if (this.isVehicle()) { return super.a(entityhuman, enumhand); } else { if (!itemstack.isEmpty()) { - if (!this.eq() && itemstack.getItem() == Items.SADDLE) { + if (!this.isBaby() && itemstack.getItem() == Items.SADDLE && !this.isSaddled()) { // Purpur - don't open inventory on babies this.e(entityhuman); return true; } diff --git a/src/main/java/net/minecraft/server/EntityHuman.java b/src/main/java/net/minecraft/server/EntityHuman.java index e811a2917..f25c394e3 100644 --- a/src/main/java/net/minecraft/server/EntityHuman.java +++ b/src/main/java/net/minecraft/server/EntityHuman.java @@ -347,9 +347,21 @@ public abstract class EntityHuman extends EntityLiving { this.activeContainer = this.defaultContainer; } + // Purpur start + boolean mounting = false; + + @Override + public void setSneaking(boolean sneaking) { + if (this.mounting && !sneaking) { + this.mounting = false; + } + super.setSneaking(sneaking); + } + // Purpur end + @Override public void passengerTick() { - if (!this.world.isClientSide && this.isSneaking() && this.isPassenger()) { + if (this.isSneaking() && this.isPassenger() && !this.mounting) { // Purpur this.stopRiding(); this.setSneaking(false); } else { diff --git a/src/main/java/net/minecraft/server/EntityInsentient.java b/src/main/java/net/minecraft/server/EntityInsentient.java index a0c089477..db5284f48 100644 --- a/src/main/java/net/minecraft/server/EntityInsentient.java +++ b/src/main/java/net/minecraft/server/EntityInsentient.java @@ -492,6 +492,7 @@ public abstract class EntityInsentient extends EntityLiving { this.bb = f; } + public void setSpeed(float speed) { o(speed); } // Purpur - OBFHELPER @Override public void o(float f) { super.o(f); @@ -1359,4 +1360,42 @@ public abstract class EntityInsentient extends EntityLiving { public boolean a(Item item) { return this.getItemInMainHand().getItem() == item || this.getItemInOffHand().getItem() == item; } + + // Purpur start + public boolean hasRidePermission(EntityHuman entityhuman) { + return entityhuman.getBukkitEntity().hasPermission("allow.ride." + getEntityType().getName()); + } + + public boolean tryRide(EntityHuman entityhuman, EnumHand enumhand) { + if (enumhand != EnumHand.MAIN_HAND) { + return false; + } + if (!entityhuman.isSneaking()) { + return false; + } + if (!passengers.isEmpty() || entityhuman.isPassenger()) { + return false; + } + if (!hasRidePermission(entityhuman)) { + entityhuman.getBukkitEntity().sendMessage("You cannot mount that mob"); + return false; + } + return mountTo(entityhuman); + } + + public boolean mountTo(EntityHuman entityhuman) { + entityhuman.mounting = true; + entityhuman.yaw = this.yaw; + entityhuman.pitch = this.pitch; + if (entityhuman.startRiding(this)) { + entityhuman.setJumping(false); // fixes jump on mount + return true; + } + return entityhuman.mounting = false; + } + + public boolean onSpacebar() { + return false; + } + // Purpur end } diff --git a/src/main/java/net/minecraft/server/EntityIronGolem.java b/src/main/java/net/minecraft/server/EntityIronGolem.java index 7aebc90af..97a5dcfd0 100644 --- a/src/main/java/net/minecraft/server/EntityIronGolem.java +++ b/src/main/java/net/minecraft/server/EntityIronGolem.java @@ -9,6 +9,11 @@ public class EntityIronGolem extends EntityGolem { public EntityIronGolem(EntityTypes entitytypes, World world) { super(entitytypes, world); this.K = 1.0F; + // Purpur start + this.moveController = new net.pl3x.purpur.controller.ControllerMoveWASD(this); + this.lookController = new net.pl3x.purpur.controller.ControllerLookWASD(this); + this.canBeRiddenInWater = true; + // Purpur end } @Override @@ -175,4 +180,14 @@ public class EntityIronGolem extends EntityGolem { return SpawnerCreature.a((IBlockAccess) iworldreader, blockposition2, iblockdata1, iblockdata1.p()) && SpawnerCreature.a((IBlockAccess) iworldreader, blockposition, iworldreader.getType(blockposition), FluidTypes.EMPTY.i()) && iworldreader.i(this); } } + + // Purpur start - processInteract + @Override + public boolean a(EntityHuman entityhuman, EnumHand enumhand) { + if (super.a(entityhuman, enumhand)) { + return true; // vanilla action handled + } + return tryRide(entityhuman, enumhand); + } + // Purpur end } diff --git a/src/main/java/net/minecraft/server/EntityLiving.java b/src/main/java/net/minecraft/server/EntityLiving.java index b27a9efcc..40264185a 100644 --- a/src/main/java/net/minecraft/server/EntityLiving.java +++ b/src/main/java/net/minecraft/server/EntityLiving.java @@ -88,9 +88,9 @@ public abstract class EntityLiving extends Entity { protected int aY; protected int getKillCount() { return this.aY; } // Paper - OBFHELPER public float lastDamage; protected boolean jumping; - public float bb; - public float bc; - public float bd; + public float bb; public float getStrafe() { return bb; } public void setStrafe(float strafe) { bb = strafe; } // Purpur - OBFHELPER + public float bc; public float getVertical() { return bc; } public void setVertical(float vertical) { bc = vertical; } // Purpur - OBFHELPER + public float bd; public float getForward() { return bd; } public void setForward(float forward) { bd = forward; } // Purpur - OBFHELPER public float be; protected int bf; protected double bg; @@ -369,10 +369,19 @@ public abstract class EntityLiving extends Entity { return this.isBaby() ? 0.5F : 1.0F; } + // Purpur start + protected boolean canBeRiddenInWater = false; + + public void setCanBeRiddenInWater(boolean canBeRiddenInWater) { + this.canBeRiddenInWater = canBeRiddenInWater; + } + + public boolean canBeRiddenInWater() { return be(); } @Override public boolean be() { - return false; + return canBeRiddenInWater; } + // Purpur end protected void cn() { ++this.deathTicks; @@ -2027,7 +2036,7 @@ public abstract class EntityLiving extends Entity { return 0.42F; } - protected void jump() { + public void jump() { // Purpur - protected -> public float f; if (this.hasEffect(MobEffects.JUMP)) { @@ -2256,10 +2265,12 @@ public abstract class EntityLiving extends Entity { return this.onGround ? this.da() * (0.21600002F / (f * f * f)) : this.aO; } + public float getSpeed() { return da(); } // Purpur - OBFHELPER public float da() { return this.bD; } + public void setSpeed(float speed) { o(speed); } // Purpur - OBFHELPER public void o(float f) { this.bD = f; } @@ -2683,6 +2694,12 @@ public abstract class EntityLiving extends Entity { this.fallDistance = 0.0F; } + // Purpur start + public boolean isJumping() { + return jumping; + } + // Purpur end + public void setJumping(boolean flag) { this.jumping = flag; } @@ -2735,6 +2752,7 @@ public abstract class EntityLiving extends Entity { this.aM = f; } + public void setRenderYawOffset(float renderYawOffset) { l(renderYawOffset); } // Purpur - OBFHELPER @Override public void l(float f) { this.aK = f; diff --git a/src/main/java/net/minecraft/server/EntityLlama.java b/src/main/java/net/minecraft/server/EntityLlama.java index f8a8da637..6870fb875 100644 --- a/src/main/java/net/minecraft/server/EntityLlama.java +++ b/src/main/java/net/minecraft/server/EntityLlama.java @@ -16,6 +16,29 @@ public class EntityLlama extends EntityHorseChestedAbstract implements IRangedEn public EntityLlama(EntityTypes entitytypes, World world) { super(entitytypes, world); + // Purpur start + this.moveController = new net.pl3x.purpur.controller.ControllerMoveWASD(this) { + @Override + protected void tick(EntityHuman rider) { + if (EntityLlama.this.isSaddled()) { + super.tick(rider); + } else { + super.tick(); + } + } + }; + this.lookController = new net.pl3x.purpur.controller.ControllerLookWASD(this) { + @Override + protected void tick(EntityHuman rider) { + if (EntityLlama.this.isSaddled()) { + super.tick(rider); + } else { + super.tick(); + } + } + }; + this.canBeRiddenInWater = true; + // Purpur end } public void setStrength(int i) { @@ -371,6 +394,18 @@ public class EntityLlama extends EntityHorseChestedAbstract implements IRangedEn } } + // Purpur start + @Override + public boolean isLeashed() { + return getRider() != null || super.isLeashed(); + } + + @Override + public Entity getLeashHolder() { + return getRider() != null ? getRider() : super.getLeashHolder(); + } + // Purpur end + public void eG() { if (this.bN != null) { this.bN.bO = null; @@ -385,7 +420,7 @@ public class EntityLlama extends EntityHorseChestedAbstract implements IRangedEn } public boolean eH() { - return this.bO != null; + return getRider() != null || this.bO != null; // Purpur } public boolean eI() { diff --git a/src/main/java/net/minecraft/server/EntityMushroomCow.java b/src/main/java/net/minecraft/server/EntityMushroomCow.java index d2de3589a..5c113e35c 100644 --- a/src/main/java/net/minecraft/server/EntityMushroomCow.java +++ b/src/main/java/net/minecraft/server/EntityMushroomCow.java @@ -18,6 +18,11 @@ public class EntityMushroomCow extends EntityCow { public EntityMushroomCow(EntityTypes entitytypes, World world) { super(entitytypes, world); this.bC = Blocks.MYCELIUM; + // Purpur start + this.moveController = new net.pl3x.purpur.controller.ControllerMoveWASD(this); + this.lookController = new net.pl3x.purpur.controller.ControllerLookWASD(this); + this.canBeRiddenInWater = true; + // Purpur end } @Override @@ -40,6 +45,15 @@ public class EntityMushroomCow extends EntityCow { @Override public boolean a(EntityHuman entityhuman, EnumHand enumhand) { + // Purpur start - processInteract + if (processInteract(entityhuman, enumhand)) { + return true; // vanilla action handled + } + return tryRide(entityhuman, enumhand); + } + + public boolean processInteract(EntityHuman entityhuman, EnumHand enumhand) { + // Purpur end ItemStack itemstack = entityhuman.b(enumhand); if (itemstack.getItem() == Items.BOWL && this.getAge() >= 0 && !entityhuman.abilities.canInstantlyBuild) { diff --git a/src/main/java/net/minecraft/server/EntityOcelot.java b/src/main/java/net/minecraft/server/EntityOcelot.java index 1713bead2..21fa1579b 100644 --- a/src/main/java/net/minecraft/server/EntityOcelot.java +++ b/src/main/java/net/minecraft/server/EntityOcelot.java @@ -14,6 +14,11 @@ public class EntityOcelot extends EntityAnimal { public EntityOcelot(EntityTypes entitytypes, World world) { super(entitytypes, world); this.dV(); + // Purpur start + this.moveController = new net.pl3x.purpur.controller.ControllerMoveWASD(this); + this.lookController = new net.pl3x.purpur.controller.ControllerLookWASD(this); + this.canBeRiddenInWater = true; + // Purpur end } private boolean isTrusting() { @@ -127,6 +132,15 @@ public class EntityOcelot extends EntityAnimal { @Override public boolean a(EntityHuman entityhuman, EnumHand enumhand) { + // Purpur start - processInteract + if (processInteract(entityhuman, enumhand)) { + return true; // vanilla action handled + } + return tryRide(entityhuman, enumhand); + } + + public boolean processInteract(EntityHuman entityhuman, EnumHand enumhand) { + // Purpur end ItemStack itemstack = entityhuman.b(enumhand); if ((this.bD == null || this.bD.h()) && !this.isTrusting() && this.i(itemstack) && entityhuman.h((Entity) this) < 9.0D) { diff --git a/src/main/java/net/minecraft/server/EntityPhantom.java b/src/main/java/net/minecraft/server/EntityPhantom.java index e5d032d02..7201b3a39 100644 --- a/src/main/java/net/minecraft/server/EntityPhantom.java +++ b/src/main/java/net/minecraft/server/EntityPhantom.java @@ -1,5 +1,6 @@ package net.minecraft.server; +import java.util.Comparator; import java.util.EnumSet; import java.util.Iterator; import java.util.List; @@ -8,9 +9,10 @@ import javax.annotation.Nullable; public class EntityPhantom extends EntityFlying implements IMonster { private static final DataWatcherObject b = DataWatcher.a(EntityPhantom.class, DataWatcherRegistry.b); - private Vec3D c; - private BlockPosition d; - private EntityPhantom.AttackPhase bz; + private Vec3D c; public Vec3D getOrbitOffset() { return this.c; } public void setOrbitOffset(Vec3D offset) { this.c = offset; } // Purpur - OBFHELPER + private BlockPosition d; public BlockPosition getOrbitPosition() { return this.d; } public void setOrbitPosition(BlockPosition position) { this.d = position; } // Purpur - OBFHELPER + private EntityPhantom.AttackPhase bz; public AttackPhase getPhase() { return this.bz; } public void setPhase(AttackPhase phase) { this.bz = phase; } // Purpur - OBFHELPER + private BlockPosition totemPosition; public BlockPosition getTotemPosition() { return this.totemPosition; } public void setTotemPosition(BlockPosition position) { this.totemPosition = position; } // Purpur public EntityPhantom(EntityTypes entitytypes, World world) { super(entitytypes, world); @@ -20,6 +22,7 @@ public class EntityPhantom extends EntityFlying implements IMonster { this.f = 5; this.moveController = new EntityPhantom.g(this); this.lookController = new EntityPhantom.f(this); + this.canBeRiddenInWater = false; // Purpur } @Override @@ -29,8 +32,10 @@ public class EntityPhantom extends EntityFlying implements IMonster { @Override protected void initPathfinder() { + this.goalSelector.a(0, new FindTotemGoal(this)); // Purpur this.goalSelector.a(1, new EntityPhantom.c()); this.goalSelector.a(2, new EntityPhantom.i()); + this.goalSelector.a(3, new OrbitTotemGoal(this)); // Purpur this.goalSelector.a(3, new EntityPhantom.e()); this.targetSelector.a(1, new EntityPhantom.b()); } @@ -102,7 +107,7 @@ public class EntityPhantom extends EntityFlying implements IMonster { @Override public void movementTick() { - if (this.isAlive() && this.dS()) { + if (this.isAlive() && getRider() == null && this.dS()) { // Purpur - do not set fire if being ridden this.setOnFire(8); } @@ -114,6 +119,26 @@ public class EntityPhantom extends EntityFlying implements IMonster { super.mobTick(); } + // Purpur start + @Override + protected LootTableInfo.Builder a(boolean wasRecentlyHit, DamageSource damagesource) { // dropLoot + boolean dropped = false; + if (killer == null && damagesource.getEntity() instanceof EntityEnderCrystal) { + if (random.nextInt(5) < 1) { // 1 out of 5 chance (20%) + dropped = a(new ItemStack(Items.PHANTOM_MEMBRANE)) != null; + } + } + if (!dropped) { + return super.a(wasRecentlyHit, damagesource); // dropLoot + } + return new LootTableInfo.Builder((WorldServer) world); + } + + public boolean isCirclingTotem() { + return totemPosition != null; + } + // Purpur end + @Override public GroupDataEntity prepare(GeneratorAccess generatoraccess, DifficultyDamageScaler difficultydamagescaler, EnumMobSpawn enummobspawn, @Nullable GroupDataEntity groupdataentity, @Nullable NBTTagCompound nbttagcompound) { this.d = (new BlockPosition(this)).up(5); @@ -202,6 +227,150 @@ public class EntityPhantom extends EntityFlying implements IMonster { } // Paper end + // Purpur start - processInteract + @Override + public boolean a(EntityHuman entityhuman, EnumHand enumhand) { + if (super.a(entityhuman, enumhand)) { + return true; // vanilla action handled + } + return tryRide(entityhuman, enumhand); + } + + class FindTotemGoal extends PathfinderGoal { + private final EntityPhantom phantom; + private EntityEnderCrystal totem; + private Comparator comparator; + + FindTotemGoal(EntityPhantom phantom) { + this.phantom = phantom; + comparator = Comparator.comparingDouble(phantom::h); + } + + @Override + public boolean a() { // shouldExecute + if (phantom.getRider() != null) { + return false; + } + double range = maxTargetRange(); + List crystals = world.a(EntityEnderCrystal.class, phantom.getBoundingBox().grow(range, range, range)); + if (crystals.isEmpty()) { + return false; + } + crystals.sort(comparator); + totem = crystals.get(0); + if (phantom.h(totem) > range * range) { + totem = null; + return false; + } + return true; + } + + @Override + public boolean b() { // shouldContinueExecuting + if (phantom.getRider() != null) { + return false; + } + if (totem == null || !totem.isAlive()) { + return false; + } + double range = maxTargetRange(); + return phantom.h(totem) <= (range * range) * 2; + } + + @Override + public void c() { // startExecuting + phantom.setTotemPosition(new BlockPosition(totem).add(0, phantom.getRandom().nextInt(10) + 10, 0)); + } + + @Override + public void d() { // resetTask + totem = null; + phantom.setTotemPosition(null); + super.d(); + } + + private double maxTargetRange() { + AttributeInstance range = phantom.getAttributeInstance(GenericAttributes.FOLLOW_RANGE); + return range == null ? 16.0D : range.getValue(); + } + + class DistanceComparator implements Comparator { + private final Entity entity; + + public DistanceComparator(Entity entity) { + this.entity = entity; + } + + public int compare(Entity entity1, Entity entity2) { + return Double.compare(entity.h(entity1), entity.h(entity2)); + } + } + } + + class OrbitTotemGoal extends PathfinderGoal { + private final EntityPhantom phantom; + private float c; + private float radius; + private float verticalChange; + private float direction; + + OrbitTotemGoal(EntityPhantom phantom) { + this.phantom = phantom; + this.a(EnumSet.of(PathfinderGoal.Type.MOVE)); + } + + @Override + public boolean a() { // shouldExecute + return phantom.getRider() == null && phantom.isCirclingTotem(); + } + + @Override + public void c() { // startExecuting + this.radius = 5.0F + phantom.random.nextFloat() * 10.0F; + this.verticalChange = -4.0F + phantom.random.nextFloat() * 9.0F; + this.direction = phantom.random.nextBoolean() ? 1.0F : -1.0F; + updateOffset(); + } + + @Override + public void e() { // tick + if (phantom.random.nextInt(350) == 0) { + this.verticalChange = -4.0F + phantom.random.nextFloat() * 9.0F; + } + if (phantom.random.nextInt(250) == 0) { + ++this.radius; + if (this.radius > 15.0F) { + this.radius = 5.0F; + this.direction = -this.direction; + } + } + if (phantom.random.nextInt(450) == 0) { + this.c = phantom.random.nextFloat() * 2.0F * 3.1415927F; + updateOffset(); + } + if (phantom.c.c(phantom.locX, phantom.locY, phantom.locZ) < 4.0D) { + updateOffset(); + } + if (phantom.c.y < phantom.locY && !phantom.world.isEmpty((new BlockPosition(phantom)).down(1))) { + this.verticalChange = Math.max(1.0F, this.verticalChange); + updateOffset(); + } + if (phantom.c.y > phantom.locY && !phantom.world.isEmpty((new BlockPosition(phantom)).up(1))) { + this.verticalChange = Math.min(-1.0F, this.verticalChange); + updateOffset(); + } + } + + private void updateOffset() { + this.c += this.direction * 15.0F * 0.017453292F; + phantom.setOrbitOffset(new Vec3D(phantom.totemPosition).add( + (double) (this.radius * MathHelper.cos(this.c)), + (double) (-4.0F + this.verticalChange), + (double) (this.radius * MathHelper.sin(this.c)))); + } + } + // Purpur end + class b extends PathfinderGoal { private final PathfinderTargetCondition b; @@ -259,7 +428,7 @@ public class EntityPhantom extends EntityFlying implements IMonster { public boolean a() { EntityLiving entityliving = EntityPhantom.this.getGoalTarget(); - return entityliving != null ? EntityPhantom.this.a(EntityPhantom.this.getGoalTarget(), PathfinderTargetCondition.a) : false; + return !isCirclingTotem() && entityliving != null && EntityPhantom.this.a(EntityPhantom.this.getGoalTarget(), PathfinderTargetCondition.a); // Purpur } @Override @@ -305,11 +474,16 @@ public class EntityPhantom extends EntityFlying implements IMonster { @Override public boolean a() { - return EntityPhantom.this.getGoalTarget() != null && EntityPhantom.this.bz == EntityPhantom.AttackPhase.SWOOP; + return !isCirclingTotem() && EntityPhantom.this.getGoalTarget() != null && EntityPhantom.this.bz == EntityPhantom.AttackPhase.SWOOP; // Purpur } @Override public boolean b() { + // Purpur start + if (isCirclingTotem()) { + return false; + } + // Purpur end EntityLiving entityliving = EntityPhantom.this.getGoalTarget(); if (entityliving == null) { @@ -379,7 +553,7 @@ public class EntityPhantom extends EntityFlying implements IMonster { @Override public boolean a() { - return EntityPhantom.this.getGoalTarget() == null || EntityPhantom.this.bz == EntityPhantom.AttackPhase.CIRCLE; + return !isCirclingTotem() && EntityPhantom.this.getGoalTarget() == null || EntityPhantom.this.bz == EntityPhantom.AttackPhase.CIRCLE; // Purpur } @Override @@ -446,14 +620,23 @@ public class EntityPhantom extends EntityFlying implements IMonster { } } - class f extends ControllerLook { + class f extends net.pl3x.purpur.controller.ControllerLookWASD { // Purpur public f(EntityInsentient entityinsentient) { super(entityinsentient); } @Override - public void a() {} + // Purpur start + public void tick(EntityHuman rider) { + setYawPitch(rider.yaw, -rider.pitch * 0.75F); + } + + @Override + public void tick() { + // do nothing + } + // Purpur end } class d extends EntityAIBodyControl { @@ -469,7 +652,7 @@ public class EntityPhantom extends EntityFlying implements IMonster { } } - class g extends ControllerMove { + class g extends net.pl3x.purpur.controller.ControllerMoveWASDFlying { // Purpur private float j = 0.1F; @@ -477,8 +660,19 @@ public class EntityPhantom extends EntityFlying implements IMonster { super(entityinsentient); } + // Purpur start @Override - public void a() { + public void tick(EntityHuman rider) { + if (!EntityPhantom.this.onGround) { + // phantom is always in motion when flying + // TODO - FIX THIS - rider.setForward(1.0F); + } + super.tick(rider); + } + + @Override + public void tick() { + // Purpur end if (EntityPhantom.this.positionChanged) { EntityPhantom.this.yaw += 180.0F; this.j = 0.1F; diff --git a/src/main/java/net/minecraft/server/EntityPig.java b/src/main/java/net/minecraft/server/EntityPig.java index 616075569..f44bbfcb3 100644 --- a/src/main/java/net/minecraft/server/EntityPig.java +++ b/src/main/java/net/minecraft/server/EntityPig.java @@ -18,6 +18,11 @@ public class EntityPig extends EntityAnimal { public EntityPig(EntityTypes entitytypes, World world) { super(entitytypes, world); + // Purpur start + this.moveController = new net.pl3x.purpur.controller.ControllerMoveWASD(this); + this.lookController = new net.pl3x.purpur.controller.ControllerLookWASD(this); + this.canBeRiddenInWater = true; + // Purpur end } @Override @@ -111,6 +116,15 @@ public class EntityPig extends EntityAnimal { @Override public boolean a(EntityHuman entityhuman, EnumHand enumhand) { + // Purpur start - processInteract + if (processInteract(entityhuman, enumhand)) { + return true; // vanilla action handled + } + return tryRide(entityhuman, enumhand); + } + + public boolean processInteract(EntityHuman entityhuman, EnumHand enumhand) { + // Purpur end if (!super.a(entityhuman, enumhand)) { ItemStack itemstack = entityhuman.b(enumhand); @@ -126,6 +140,17 @@ public class EntityPig extends EntityAnimal { } else if (itemstack.getItem() == Items.SADDLE) { itemstack.a(entityhuman, (EntityLiving) this, enumhand); return true; + // Purpur start - get saddle back + } else if (hasSaddle() && entityhuman.isSneaking() && itemstack.getItem() == Items.AIR) { + setSaddle(false); + if (!entityhuman.abilities.canInstantlyBuild) { + ItemStack saddle = new ItemStack(Items.SADDLE); + if (!entityhuman.inventory.pickup(saddle)) { + entityhuman.drop(saddle, false); + } + } + return true; + // Purpur end } else { return false; } diff --git a/src/main/java/net/minecraft/server/EntityPolarBear.java b/src/main/java/net/minecraft/server/EntityPolarBear.java index 182a3195e..94f561a9d 100644 --- a/src/main/java/net/minecraft/server/EntityPolarBear.java +++ b/src/main/java/net/minecraft/server/EntityPolarBear.java @@ -14,6 +14,11 @@ public class EntityPolarBear extends EntityAnimal { public EntityPolarBear(EntityTypes entitytypes, World world) { super(entitytypes, world); + // Purpur start + this.moveController = new net.pl3x.purpur.controller.ControllerMoveWASD(this); + this.lookController = new net.pl3x.purpur.controller.ControllerLookWASD(this); + this.canBeRiddenInWater = true; + // Purpur end } @Override @@ -154,6 +159,16 @@ public class EntityPolarBear extends EntityAnimal { return 0.98F; } + // Purpur start - processInteract + @Override + public boolean a(EntityHuman entityhuman, EnumHand enumhand) { + if (super.a(entityhuman, enumhand)) { + return true; // vanilla action handled + } + return tryRide(entityhuman, enumhand); + } + // Purpur end + @Override public GroupDataEntity prepare(GeneratorAccess generatoraccess, DifficultyDamageScaler difficultydamagescaler, EnumMobSpawn enummobspawn, @Nullable GroupDataEntity groupdataentity, @Nullable NBTTagCompound nbttagcompound) { if (groupdataentity instanceof EntityPolarBear.b) { diff --git a/src/main/java/net/minecraft/server/EntityRabbit.java b/src/main/java/net/minecraft/server/EntityRabbit.java index f6fa87158..bd0679e74 100644 --- a/src/main/java/net/minecraft/server/EntityRabbit.java +++ b/src/main/java/net/minecraft/server/EntityRabbit.java @@ -59,7 +59,7 @@ public class EntityRabbit extends EntityAnimal { } @Override - protected void jump() { + public void jump() { // Purpur - protected -> public super.jump(); double d0 = this.moveController.c(); diff --git a/src/main/java/net/minecraft/server/EntitySheep.java b/src/main/java/net/minecraft/server/EntitySheep.java index f0cd951ac..311cdb58b 100644 --- a/src/main/java/net/minecraft/server/EntitySheep.java +++ b/src/main/java/net/minecraft/server/EntitySheep.java @@ -55,6 +55,11 @@ public class EntitySheep extends EntityAnimal { public EntitySheep(EntityTypes entitytypes, World world) { super(entitytypes, world); + // Purpur start + this.moveController = new net.pl3x.purpur.controller.ControllerMoveWASD(this); + this.lookController = new net.pl3x.purpur.controller.ControllerLookWASD(this); + this.canBeRiddenInWater = true; + // Purpur end } @Override @@ -144,6 +149,15 @@ public class EntitySheep extends EntityAnimal { @Override public boolean a(EntityHuman entityhuman, EnumHand enumhand) { + // Purpur start - processInteract + if (processInteract(entityhuman, enumhand)) { + return true; // vanilla action handled + } + return tryRide(entityhuman, enumhand); + } + + public boolean processInteract(EntityHuman entityhuman, EnumHand enumhand) { + // Purpur end ItemStack itemstack = entityhuman.b(enumhand); if (itemstack.getItem() == Items.SHEARS && !this.isSheared() && !this.isBaby()) { diff --git a/src/main/java/net/minecraft/server/EntitySilverfish.java b/src/main/java/net/minecraft/server/EntitySilverfish.java index d823c6b6d..4bc91b19f 100644 --- a/src/main/java/net/minecraft/server/EntitySilverfish.java +++ b/src/main/java/net/minecraft/server/EntitySilverfish.java @@ -10,6 +10,11 @@ public class EntitySilverfish extends EntityMonster { public EntitySilverfish(EntityTypes entitytypes, World world) { super(entitytypes, world); + // Purpur start + this.moveController = new net.pl3x.purpur.controller.ControllerMoveWASD(this); + this.lookController = new net.pl3x.purpur.controller.ControllerLookWASD(this); + this.canBeRiddenInWater = true; + // Purpur end } @Override @@ -117,6 +122,16 @@ public class EntitySilverfish extends EntityMonster { return EnumMonsterType.ARTHROPOD; } + // Purpur start - processInteract + @Override + public boolean a(EntityHuman entityhuman, EnumHand enumhand) { + if (super.a(entityhuman, enumhand)) { + return true; // vanilla action handled + } + return tryRide(entityhuman, enumhand); + } + // Purpur end + static class PathfinderGoalSilverfishHideInBlock extends PathfinderGoalRandomStroll { private EnumDirection h; diff --git a/src/main/java/net/minecraft/server/EntitySkeletonAbstract.java b/src/main/java/net/minecraft/server/EntitySkeletonAbstract.java index 85157e80d..94dca9e48 100644 --- a/src/main/java/net/minecraft/server/EntitySkeletonAbstract.java +++ b/src/main/java/net/minecraft/server/EntitySkeletonAbstract.java @@ -24,6 +24,11 @@ public abstract class EntitySkeletonAbstract extends EntityMonster implements IR protected EntitySkeletonAbstract(EntityTypes entitytypes, World world) { super(entitytypes, world); this.dV(); + // Purpur start + this.moveController = new net.pl3x.purpur.controller.ControllerMoveWASD(this); + this.lookController = new net.pl3x.purpur.controller.ControllerLookWASD(this); + this.canBeRiddenInWater = true; + // Purpur end } @Override @@ -199,4 +204,14 @@ public abstract class EntitySkeletonAbstract extends EntityMonster implements IR public double aN() { return -0.6D; } + + // Purpur start - processInteract + @Override + public boolean a(EntityHuman entityhuman, EnumHand enumhand) { + if (super.a(entityhuman, enumhand)) { + return true; // vanilla action handled + } + return tryRide(entityhuman, enumhand); + } + // Purpur end } diff --git a/src/main/java/net/minecraft/server/EntitySlime.java b/src/main/java/net/minecraft/server/EntitySlime.java index d720d0fae..e4f7797ed 100644 --- a/src/main/java/net/minecraft/server/EntitySlime.java +++ b/src/main/java/net/minecraft/server/EntitySlime.java @@ -316,7 +316,7 @@ public class EntitySlime extends EntityInsentient implements IMonster { } @Override - protected void jump() { + public void jump() { // Purpur - protected -> public Vec3D vec3d = this.getMot(); this.setMot(vec3d.x, 0.41999998688697815D, vec3d.z); diff --git a/src/main/java/net/minecraft/server/EntitySnowman.java b/src/main/java/net/minecraft/server/EntitySnowman.java index c13dfc6cc..930b4673e 100644 --- a/src/main/java/net/minecraft/server/EntitySnowman.java +++ b/src/main/java/net/minecraft/server/EntitySnowman.java @@ -13,6 +13,11 @@ public class EntitySnowman extends EntityGolem implements IRangedEntity { public EntitySnowman(EntityTypes entitytypes, World world) { super(entitytypes, world); + // Purpur start + this.moveController = new net.pl3x.purpur.controller.ControllerMoveWASD(this); + this.lookController = new net.pl3x.purpur.controller.ControllerLookWASD(this); + this.canBeRiddenInWater = true; + // Purpur end } @Override @@ -74,6 +79,7 @@ public class EntitySnowman extends EntityGolem implements IRangedEntity { return; } + if (getRider() != null) return; // Purpur - don't leave snow trail when being ridden IBlockData iblockdata = Blocks.SNOW.getBlockData(); for (int l = 0; l < 4; ++l) { @@ -111,6 +117,15 @@ public class EntitySnowman extends EntityGolem implements IRangedEntity { @Override protected boolean a(EntityHuman entityhuman, EnumHand enumhand) { + // Purpur start - processInteract + if (processInteract(entityhuman, enumhand)) { + return true; // vanilla action handled + } + return tryRide(entityhuman, enumhand); + } + + public boolean processInteract(EntityHuman entityhuman, EnumHand enumhand) { + // Purpur end ItemStack itemstack = entityhuman.b(enumhand); if (this.hasPumpkin()) { if (itemstack.getItem() == Items.SHEARS) { // Purpur diff --git a/src/main/java/net/minecraft/server/EntitySpider.java b/src/main/java/net/minecraft/server/EntitySpider.java index b560a8969..41374df4f 100644 --- a/src/main/java/net/minecraft/server/EntitySpider.java +++ b/src/main/java/net/minecraft/server/EntitySpider.java @@ -9,6 +9,11 @@ public class EntitySpider extends EntityMonster { public EntitySpider(EntityTypes entitytypes, World world) { super(entitytypes, world); + // Purpur start + this.moveController = new net.pl3x.purpur.controller.ControllerMoveWASD(this); + this.lookController = new net.pl3x.purpur.controller.ControllerLookWASD(this); + this.canBeRiddenInWater = true; + // Purpur end } @Override @@ -115,6 +120,16 @@ public class EntitySpider extends EntityMonster { this.datawatcher.set(EntitySpider.b, b0); } + // Purpur start - processInteract + @Override + public boolean a(EntityHuman entityhuman, EnumHand enumhand) { + if (super.a(entityhuman, enumhand)) { + return true; // vanilla action handled + } + return tryRide(entityhuman, enumhand); + } + // Purpur end + @Nullable @Override public GroupDataEntity prepare(GeneratorAccess generatoraccess, DifficultyDamageScaler difficultydamagescaler, EnumMobSpawn enummobspawn, @Nullable GroupDataEntity groupdataentity, @Nullable NBTTagCompound nbttagcompound) { diff --git a/src/main/java/net/minecraft/server/EntitySquid.java b/src/main/java/net/minecraft/server/EntitySquid.java index 77c0ed42f..e82d4e643 100644 --- a/src/main/java/net/minecraft/server/EntitySquid.java +++ b/src/main/java/net/minecraft/server/EntitySquid.java @@ -21,6 +21,7 @@ public class EntitySquid extends EntityWaterAnimal { super(entitytypes, world); //this.random.setSeed((long) this.getId()); // Paper this.bF = 1.0F / (this.random.nextFloat() + 1.0F) * 0.2F; + this.canBeRiddenInWater = true; // Purpur } @Override @@ -174,6 +175,7 @@ public class EntitySquid extends EntityWaterAnimal { return this.locY > this.world.spigotConfig.squidSpawnRangeMin && this.locY < maxHeight; // Spigot // Paper } + public void setMovementVector(float x, float y, float z) { a(x, y, z); } // Purpur - OBFHELPER public void a(float f, float f1, float f2) { this.bH = f; this.bI = f1; @@ -184,6 +186,16 @@ public class EntitySquid extends EntityWaterAnimal { return this.bH != 0.0F || this.bI != 0.0F || this.bJ != 0.0F; } + // Purpur start - processInteract + @Override + public boolean a(EntityHuman entityhuman, EnumHand enumhand) { + if (super.a(entityhuman, enumhand)) { + return true; // vanilla action handled + } + return tryRide(entityhuman, enumhand); + } + // Purpur end + class a extends PathfinderGoal { private int b; @@ -258,6 +270,39 @@ public class EntitySquid extends EntityWaterAnimal { @Override public void e() { + // Purpur start + EntityHuman rider = this.b.getRider(); + if (rider != null) { + EntitySquid squid = this.b; + if (rider.isJumping()) { + squid.onSpacebar(); + } + float forward = rider.getForward(); + float strafe = rider.getStrafe(); + float speed = (float) squid.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).getValue() * 5F; + if (forward < 0.0F) { + speed *= -0.5; + } + org.bukkit.util.Vector dir = rider.getBukkitEntity().getEyeLocation().getDirection().normalize().multiply(speed / 20.0F); + if (strafe != 0.0F) { + if (forward == 0.0F) { + dir.setY(0); + rotateVectorAroundY(dir, strafe > 0.0F ? -90 : 90); + } else if (forward < 0.0F) { + rotateVectorAroundY(dir, strafe > 0.0F ? 45 : -45); + } else { + rotateVectorAroundY(dir, strafe > 0.0F ? -45 : 45); + } + } + if (forward != 0.0F || strafe != 0.0F) { + squid.setMovementVector((float) dir.getX(), (float) dir.getY(), (float) dir.getZ()); + } else { + squid.setMovementVector(0.0F, 0.0F, 0.0F); + } + return; + } + // Purpur end + int i = this.b.cv(); if (i > 100) { @@ -272,5 +317,17 @@ public class EntitySquid extends EntityWaterAnimal { } } + + // Purpur start + private void rotateVectorAroundY(org.bukkit.util.Vector vector, double degrees) { + double rad = Math.toRadians(degrees); + double cos = Math.cos(rad); + double sine = Math.sin(rad); + double x = vector.getX(); + double z = vector.getZ(); + vector.setX(cos * x - sine * z); + vector.setZ(sine * x + cos * z); + } + // Purpur end } } diff --git a/src/main/java/net/minecraft/server/EntityTameableAnimal.java b/src/main/java/net/minecraft/server/EntityTameableAnimal.java index 70bf06b94..2f41d8ade 100644 --- a/src/main/java/net/minecraft/server/EntityTameableAnimal.java +++ b/src/main/java/net/minecraft/server/EntityTameableAnimal.java @@ -127,6 +127,12 @@ public abstract class EntityTameableAnimal extends EntityAnimal { this.datawatcher.set(EntityTameableAnimal.bA, Optional.ofNullable(uuid)); } + // Purpur start + public boolean isOwner(EntityHuman entityhuman) { + return entityhuman != null && entityhuman.getUniqueID() == getOwnerUUID(); + } + // Purpur end + public void tame(EntityHuman entityhuman) { this.setTamed(true); this.setOwnerUUID(entityhuman.getUniqueID()); diff --git a/src/main/java/net/minecraft/server/EntityTypes.java b/src/main/java/net/minecraft/server/EntityTypes.java index 483c97692..181e92980 100644 --- a/src/main/java/net/minecraft/server/EntityTypes.java +++ b/src/main/java/net/minecraft/server/EntityTypes.java @@ -255,6 +255,12 @@ public class EntityTypes { return this.ba; } + // Purpur start + public String getName() { + return IRegistry.ENTITY_TYPE.getKey(this).getKey(); + } + // Purpur end + public String e() { if (this.be == null) { this.be = SystemUtils.a("entity", IRegistry.ENTITY_TYPE.getKey(this)); diff --git a/src/main/java/net/minecraft/server/EntityWolf.java b/src/main/java/net/minecraft/server/EntityWolf.java index 4167ce8f8..0222399b4 100644 --- a/src/main/java/net/minecraft/server/EntityWolf.java +++ b/src/main/java/net/minecraft/server/EntityWolf.java @@ -29,6 +29,11 @@ public class EntityWolf extends EntityTameableAnimal { public EntityWolf(EntityTypes entitytypes, World world) { super(entitytypes, world); this.setTamed(false); + // Purpur start + this.moveController = new net.pl3x.purpur.controller.ControllerMoveWASD(this); + this.lookController = new net.pl3x.purpur.controller.ControllerLookWASD(this); + this.canBeRiddenInWater = true; + // Purpur end } @Override @@ -275,6 +280,15 @@ public class EntityWolf extends EntityTameableAnimal { @Override public boolean a(EntityHuman entityhuman, EnumHand enumhand) { + // Purpur start - processInteract + if (processInteract(entityhuman, enumhand)) { + return true; // vanilla action handled + } + return (!isTamed() && isOwner(entityhuman)) || tryRide(entityhuman, enumhand); + } + + public boolean processInteract(EntityHuman entityhuman, EnumHand enumhand) { + // Purpur end ItemStack itemstack = entityhuman.b(enumhand); Item item = itemstack.getItem(); diff --git a/src/main/java/net/minecraft/server/EntityZombie.java b/src/main/java/net/minecraft/server/EntityZombie.java index b06235d46..cff6fb1fb 100644 --- a/src/main/java/net/minecraft/server/EntityZombie.java +++ b/src/main/java/net/minecraft/server/EntityZombie.java @@ -36,6 +36,11 @@ public class EntityZombie extends EntityMonster { public EntityZombie(EntityTypes entitytypes, World world) { super(entitytypes, world); this.bD = new PathfinderGoalBreakDoor(this, EntityZombie.bC); + // Purpur start + this.moveController = new net.pl3x.purpur.controller.ControllerMoveWASD(this); + this.lookController = new net.pl3x.purpur.controller.ControllerLookWASD(this); + this.canBeRiddenInWater = true; + // Purpur end } public EntityZombie(World world) { @@ -460,6 +465,16 @@ public class EntityZombie extends EntityMonster { return itemstack.getItem() == Items.EGG && this.isBaby() && this.isPassenger() ? false : super.g(itemstack); } + // Purpur start - processInteract + @Override + public boolean a(EntityHuman entityhuman, EnumHand enumhand) { + if (super.a(entityhuman, enumhand)) { + return true; // vanilla action handled + } + return tryRide(entityhuman, enumhand); + } + // Purpur end + @Nullable @Override public GroupDataEntity prepare(GeneratorAccess generatoraccess, DifficultyDamageScaler difficultydamagescaler, EnumMobSpawn enummobspawn, @Nullable GroupDataEntity groupdataentity, @Nullable NBTTagCompound nbttagcompound) { diff --git a/src/main/java/net/pl3x/purpur/controller/ControllerLookWASD.java b/src/main/java/net/pl3x/purpur/controller/ControllerLookWASD.java new file mode 100644 index 000000000..851ab80e4 --- /dev/null +++ b/src/main/java/net/pl3x/purpur/controller/ControllerLookWASD.java @@ -0,0 +1,46 @@ +package net.pl3x.purpur.controller; + +import net.minecraft.server.ControllerLook; +import net.minecraft.server.EntityHuman; +import net.minecraft.server.EntityInsentient; + +public class ControllerLookWASD extends ControllerLook { + protected final EntityInsentient entity; + private float yawOffset = 0; + private float pitchOffset = 0; + + public ControllerLookWASD(EntityInsentient entity) { + super(entity); + this.entity = entity; + } + + // tick + @Override + public void a() { + if (entity.getRider() != null) { + tick(entity.getRider()); + } else { + tick(); + } + } + + protected void tick() { + super.a(); // tick + } + + protected void tick(EntityHuman rider) { + setYawPitch(rider.yaw, rider.pitch); + } + + public void setYawPitch(float yaw, float pitch) { + entity.lastYaw = entity.yaw = (yaw + yawOffset) % 360.0F; + entity.setRenderYawOffset(entity.lastYaw); + entity.setHeadRotation(entity.lastYaw); + entity.pitch = (pitch + pitchOffset) % 360.0F; + } + + public void setOffsets(float yaw, float pitch) { + yawOffset = yaw; + pitchOffset = pitch; + } +} diff --git a/src/main/java/net/pl3x/purpur/controller/ControllerMoveWASD.java b/src/main/java/net/pl3x/purpur/controller/ControllerMoveWASD.java new file mode 100644 index 000000000..4f7dec9bc --- /dev/null +++ b/src/main/java/net/pl3x/purpur/controller/ControllerMoveWASD.java @@ -0,0 +1,77 @@ +package net.pl3x.purpur.controller; + +import net.minecraft.server.ControllerMove; +import net.minecraft.server.EntityHuman; +import net.minecraft.server.EntityInsentient; +import net.minecraft.server.GenericAttributes; + +public class ControllerMoveWASD extends ControllerMove { + protected final EntityInsentient entity; + + public ControllerMoveWASD(EntityInsentient entity) { + super(entity); + this.entity = entity; + } + + // isUpdating + @Override + public boolean b() { + return entity.getRider() != null || super.b(); + } + + // tick + @Override + public void a() { + if (entity.getRider() != null) { + tick(entity.getRider()); + } else { + tick(); + } + } + + protected void tick() { + super.a(); // tick + } + + protected void tick(EntityHuman rider) { + float forward = rider.getForward() * 0.5F; + float strafe = rider.getStrafe() * 0.25F; + + if (forward <= 0.0F) { + forward *= 0.5F; + } + + float yaw = rider.yaw; + if (strafe != 0) { + if (forward == 0) { + yaw += strafe > 0 ? -90 : 90; + forward = Math.abs(strafe * 2); + } else { + yaw += strafe > 0 ? -30 : 30; + strafe /= 2; + if (forward < 0) { + yaw += strafe > 0 ? -110 : 110; + forward *= -1; + } + } + } else if (forward < 0) { + yaw -= 180; + forward *= -1; + } + + ((ControllerLookWASD) entity.getControllerLook()).setOffsets(yaw - rider.yaw, 0); + + if (rider.isJumping()) { + //RidableSpacebarEvent event = new RidableSpacebarEvent(entity); + if (/*event.callEvent() && !event.isHandled() &&*/ !entity.onSpacebar() && entity.onGround) { + entity.jump(); + } + } + + entity.setSpeed((float) (e = entity.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).getValue())); + entity.setForward(forward); + + f = entity.getForward(); + g = entity.getStrafe(); + } +} diff --git a/src/main/java/net/pl3x/purpur/controller/ControllerMoveWASDFlying.java b/src/main/java/net/pl3x/purpur/controller/ControllerMoveWASDFlying.java new file mode 100644 index 000000000..1a5a0c04c --- /dev/null +++ b/src/main/java/net/pl3x/purpur/controller/ControllerMoveWASDFlying.java @@ -0,0 +1,58 @@ +package net.pl3x.purpur.controller; + +import net.minecraft.server.EntityHuman; +import net.minecraft.server.EntityInsentient; +import net.minecraft.server.GenericAttributes; + +public class ControllerMoveWASDFlying extends ControllerMoveWASD { + protected final float groundSpeedModifier; + private final double maxY; + private int tooHighCooldown = 0; + + public ControllerMoveWASDFlying(EntityInsentient entity) { + this(entity, 1.0F, 256D); + } + + public ControllerMoveWASDFlying(EntityInsentient entity, float groundSpeedModifier, double maxY) { + super(entity); + this.groundSpeedModifier = groundSpeedModifier; + this.maxY = maxY; + } + + @Override + public void tick(EntityHuman rider) { + float forward = Math.max(0.0F, rider.getForward()); + float vertical = forward == 0.0F ? 0.0F : -(rider.pitch / 45.0F); + float strafe = rider.getStrafe(); + + if (rider.isJumping()) { + //RidableSpacebarEvent event = new RidableSpacebarEvent(ridable); + //Bukkit.getPluginManager().callEvent(event); + //if (!event.isCancelled() && !event.isHandled()) { + entity.onSpacebar(); + //} + } + + if (entity.locY >= maxY || --tooHighCooldown > 0) { + tooHighCooldown = 60; + entity.setMot(entity.getMot().add(0.0D, -0.05D, 0.0D)); + vertical = 0.0F; + } + + float speed = (float) (e = entity.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).getValue()); + + if (entity.onGround) { + speed *= groundSpeedModifier; // TODO = fix this! + } + + entity.setNoGravity(forward > 0); + + entity.setSpeed(speed); + entity.setVertical(vertical); + entity.setStrafe(strafe); + entity.setForward(forward); + + f = entity.getForward(); + g = entity.getStrafe(); + } +} diff --git a/src/main/java/net/pl3x/purpur/controller/ControllerMoveWASDWater.java b/src/main/java/net/pl3x/purpur/controller/ControllerMoveWASDWater.java new file mode 100644 index 000000000..74ff48259 --- /dev/null +++ b/src/main/java/net/pl3x/purpur/controller/ControllerMoveWASDWater.java @@ -0,0 +1,42 @@ +package net.pl3x.purpur.controller; + +import net.minecraft.server.EntityHuman; +import net.minecraft.server.EntityInsentient; +import net.minecraft.server.GenericAttributes; + +public class ControllerMoveWASDWater extends ControllerMoveWASD { + public ControllerMoveWASDWater(EntityInsentient entity) { + super(entity); + } + + @Override + protected void tick(EntityHuman rider) { + float forward = rider.getForward(); + float strafe = rider.getStrafe() * 0.5F; // strafe slower by default + float vertical = -(rider.pitch / 90); + + if (forward == 0.0F) { + // strafe slower if not moving forward + strafe *= 0.5F; + // do not move vertically if not moving forward + vertical = 0.0F; + } else if (forward < 0.0F) { + // water animals can't swim backwards + forward = 0.0F; + vertical = 0.0F; + } + + if (rider.isJumping()) { + entity.onSpacebar(); + } + + entity.setSpeed((float) (e = entity.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).getValue()) * 0.1F); + + entity.setForward(forward); + entity.setStrafe(strafe); + entity.setVertical(vertical); + + f = entity.getForward(); + g = entity.getStrafe(); + } +} diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java index 640faccfd..2390baa75 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java @@ -697,5 +697,15 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity { public void setSafeFallDistance(float safeFallDistance) { getHandle().safeFallDistance = safeFallDistance; } + + @Override + public boolean canBeRiddenInWater() { + return getHandle().canBeRiddenInWater(); + } + + @Override + public void setCanBeRiddenInWater(boolean canBeRiddenInWater) { + getHandle().setCanBeRiddenInWater(canBeRiddenInWater); + } // Purpur end } -- 2.20.1