papermc/Spigot-Server-Patches/0302-Turtle-API.patch

144 lines
6.7 KiB
Diff
Raw Normal View History

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2018-10-11 03:40:49 +00:00
From: BillyGalbreath <Blake.Galbreath@GMail.com>
Date: Sat, 29 Sep 2018 16:08:23 -0500
Subject: [PATCH] Turtle API
diff --git a/src/main/java/net/minecraft/server/EntityTurtle.java b/src/main/java/net/minecraft/server/EntityTurtle.java
index dd745894614982fad6277e77b98bed75fc2a2f55..00827c335e9413e986d7f07d0adbcef0d106a553 100644
2018-10-11 03:40:49 +00:00
--- a/src/main/java/net/minecraft/server/EntityTurtle.java
+++ b/src/main/java/net/minecraft/server/EntityTurtle.java
2020-06-25 14:09:55 +00:00
@@ -27,10 +27,12 @@ public class EntityTurtle extends EntityAnimal {
this.G = 1.0F;
2018-10-11 03:40:49 +00:00
}
2020-06-25 14:09:55 +00:00
+ public final void setHome(BlockPosition pos) { setHomePos(pos); } // Paper - OBFHELPER
public void setHomePos(BlockPosition blockposition) {
this.datawatcher.set(EntityTurtle.bw, blockposition);
2018-10-11 03:40:49 +00:00
}
2020-06-25 14:09:55 +00:00
-
+ // TODO Paper: Obf helpers here can prolly be removed? check that no newer patches use them
+ public final BlockPosition getHome() { return this.getHomePos(); } // Paper - OBFHELPER
private BlockPosition getHomePos() {
return (BlockPosition) this.datawatcher.get(EntityTurtle.bw);
2018-10-11 03:40:49 +00:00
}
@@ -47,31 +49,37 @@ public class EntityTurtle extends EntityAnimal {
return (Boolean) this.datawatcher.get(EntityTurtle.bx);
}
- private void setHasEgg(boolean flag) {
+ public void setHasEgg(boolean flag) { // Paper
2020-06-25 14:09:55 +00:00
this.datawatcher.set(EntityTurtle.bx, flag);
2018-10-11 03:40:49 +00:00
}
2020-06-25 14:09:55 +00:00
+ public final boolean isDigging() { return this.eM(); } // Paper - OBFHELPER
public boolean eM() {
return (Boolean) this.datawatcher.get(EntityTurtle.by);
2018-10-11 03:40:49 +00:00
}
2020-06-25 14:09:55 +00:00
+ public final void setDigging(boolean digging) { this.u(digging); } // Paper - OBFHELPER
private void u(boolean flag) {
this.bC = flag ? 1 : 0;
this.datawatcher.set(EntityTurtle.by, flag);
2018-10-11 03:40:49 +00:00
}
2020-06-25 14:09:55 +00:00
+ public final boolean isGoingHome() { return this.eV(); } // Paper - OBFHELPER
private boolean eV() {
return (Boolean) this.datawatcher.get(EntityTurtle.bA);
2018-10-11 03:40:49 +00:00
}
2020-06-25 14:09:55 +00:00
+ public final void setGoingHome(boolean goingHome) { this.v(goingHome); } // Paper - OBFHELPER
private void v(boolean flag) {
this.datawatcher.set(EntityTurtle.bA, flag);
2018-10-11 03:40:49 +00:00
}
2020-06-25 14:09:55 +00:00
+ public final boolean isTravelling() { return this.eW(); } // Paper - OBFHELPER
private boolean eW() {
return (Boolean) this.datawatcher.get(EntityTurtle.bB);
2018-10-11 03:40:49 +00:00
}
2020-06-25 14:09:55 +00:00
+ public final void setTravelling(boolean travelling) { this.w(travelling); } // Paper - OBFHELPER
private void w(boolean flag) {
this.datawatcher.set(EntityTurtle.bB, flag);
2018-10-11 03:40:49 +00:00
}
2020-06-25 14:09:55 +00:00
@@ -438,14 +446,17 @@ public class EntityTurtle extends EntityAnimal {
2018-10-11 03:40:49 +00:00
2019-05-05 08:33:44 +00:00
if (!this.g.isInWater() && this.k()) {
2020-06-25 14:09:55 +00:00
if (this.g.bC < 1) {
- this.g.u(true);
2019-05-05 08:33:44 +00:00
+ this.g.setDigging(new com.destroystokyo.paper.event.entity.TurtleStartDiggingEvent((org.bukkit.entity.Turtle) this.g.getBukkitEntity(), MCUtil.toLocation(this.g.world, this.e)).callEvent()); // Paper
2020-06-25 14:09:55 +00:00
} else if (this.g.bC > 200) {
2019-05-05 08:33:44 +00:00
World world = this.g.world;
2018-10-11 03:40:49 +00:00
// CraftBukkit start
2019-05-05 08:33:44 +00:00
- if (!org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent(this.g, this.e.up(), (IBlockData) Blocks.TURTLE_EGG.getBlockData().set(BlockTurtleEgg.b, this.g.random.nextInt(4) + 1)).isCancelled()) {
2018-10-11 03:40:49 +00:00
+ // Paper start
2019-05-05 08:33:44 +00:00
+ int eggCount = this.g.random.nextInt(4) + 1;
+ com.destroystokyo.paper.event.entity.TurtleLayEggEvent layEggEvent = new com.destroystokyo.paper.event.entity.TurtleLayEggEvent((org.bukkit.entity.Turtle) this.g.getBukkitEntity(), MCUtil.toLocation(this.g.world, this.e.up()), eggCount);
+ if (layEggEvent.callEvent() && !org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent(this.g, this.e.up(), Blocks.TURTLE_EGG.getBlockData().set(BlockTurtleEgg.b, layEggEvent.getEggCount())).isCancelled()) {
2019-07-20 04:01:24 +00:00
world.playSound((EntityHuman) null, blockposition, SoundEffects.ENTITY_TURTLE_LAY_EGG, SoundCategory.BLOCKS, 0.3F, 0.9F + world.random.nextFloat() * 0.2F);
2019-05-05 08:33:44 +00:00
- world.setTypeAndData(this.e.up(), (IBlockData) Blocks.TURTLE_EGG.getBlockData().set(BlockTurtleEgg.b, this.g.random.nextInt(4) + 1), 3);
+ world.setTypeAndData(this.e.up(), (IBlockData) Blocks.TURTLE_EGG.getBlockData().set(BlockTurtleEgg.b, layEggEvent.getEggCount()), 3);
2018-10-11 03:40:49 +00:00
}
// CraftBukkit end
2020-06-25 14:09:55 +00:00
this.g.setHasEgg(false);
@@ -574,7 +585,7 @@ public class EntityTurtle extends EntityAnimal {
2018-10-11 03:40:49 +00:00
2019-05-05 08:33:44 +00:00
@Override
2018-10-11 03:40:49 +00:00
public boolean a() {
2020-06-25 14:09:55 +00:00
- return this.a.isBaby() ? false : (this.a.hasEgg() ? true : (this.a.getRandom().nextInt(700) != 0 ? false : !this.a.getHomePos().a((IPosition) this.a.getPositionVector(), 64.0D)));
+ return this.a.isBaby() ? false : (this.a.hasEgg() ? true : (this.a.getRandom().nextInt(700) != 0 ? false : !this.a.getHomePos().a((IPosition) this.a.getPositionVector(), 64.0D))) && new com.destroystokyo.paper.event.entity.TurtleGoHomeEvent((org.bukkit.entity.Turtle) this.a.getBukkitEntity()).callEvent(); // Paper
2018-10-11 03:40:49 +00:00
}
2019-05-05 08:33:44 +00:00
@Override
2018-10-11 03:40:49 +00:00
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftTurtle.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftTurtle.java
index 123a2c75cad410d079cfb23223ab509e4b4c63f7..8edcf7af65ec8790fe946020a8f74932b4436d16 100644
2018-10-11 03:40:49 +00:00
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftTurtle.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftTurtle.java
@@ -1,6 +1,8 @@
package org.bukkit.craftbukkit.entity;
import net.minecraft.server.EntityTurtle;
+import net.minecraft.server.MCUtil;
+import org.bukkit.Location;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Turtle;
@@ -25,4 +27,36 @@ public class CraftTurtle extends CraftAnimals implements Turtle {
public EntityType getType() {
return EntityType.TURTLE;
}
+
+ // Paper start
+ @Override
+ public Location getHome() {
+ return MCUtil.toLocation(getHandle().world, getHandle().getHome());
+ }
+
+ @Override
+ public void setHome(Location location) {
+ getHandle().setHome(MCUtil.toBlockPosition(location));
+ }
+
+ @Override
+ public boolean isGoingHome() {
+ return getHandle().isGoingHome();
+ }
+
+ @Override
+ public boolean isDigging() {
+ return getHandle().isDigging();
+ }
+
+ @Override
+ public boolean hasEgg() {
+ return getHandle().hasEgg();
+ }
+
+ @Override
+ public void setHasEgg(boolean hasEgg) {
+ getHandle().setHasEgg(hasEgg);
+ }
+ // Paper end
}