mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-29 07:48:53 +01:00
Turtle API (#1509)
This commit is contained in:
parent
14de21393c
commit
fe01fa5641
2 changed files with 427 additions and 0 deletions
269
Spigot-API-Patches/0161-Turtle-API.patch
Normal file
269
Spigot-API-Patches/0161-Turtle-API.patch
Normal file
|
@ -0,0 +1,269 @@
|
|||
From c4faeffafb0e89f4d82a5ab47f7fb2fc33778d6c Mon Sep 17 00:00:00 2001
|
||||
From: BillyGalbreath <Blake.Galbreath@GMail.com>
|
||||
Date: Fri, 28 Sep 2018 17:08:09 -0500
|
||||
Subject: [PATCH] Turtle API
|
||||
|
||||
|
||||
diff --git a/src/main/java/com/destroystokyo/paper/event/entity/TurtleGoHomeEvent.java b/src/main/java/com/destroystokyo/paper/event/entity/TurtleGoHomeEvent.java
|
||||
new file mode 100644
|
||||
index 000000000..11248ee93
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/com/destroystokyo/paper/event/entity/TurtleGoHomeEvent.java
|
||||
@@ -0,0 +1,45 @@
|
||||
+package com.destroystokyo.paper.event.entity;
|
||||
+
|
||||
+import org.bukkit.entity.Turtle;
|
||||
+import org.bukkit.event.Cancellable;
|
||||
+import org.bukkit.event.HandlerList;
|
||||
+import org.bukkit.event.entity.EntityEvent;
|
||||
+
|
||||
+/**
|
||||
+ * Fired when a Turtle decides to go home
|
||||
+ */
|
||||
+public class TurtleGoHomeEvent extends EntityEvent implements Cancellable {
|
||||
+ private static final HandlerList handlers = new HandlerList();
|
||||
+ private boolean cancelled = false;
|
||||
+
|
||||
+ public TurtleGoHomeEvent(Turtle turtle) {
|
||||
+ super(turtle);
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
+ * The turtle going home
|
||||
+ *
|
||||
+ * @return The turtle
|
||||
+ */
|
||||
+ public Turtle getEntity() {
|
||||
+ return (Turtle) entity;
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public boolean isCancelled() {
|
||||
+ return cancelled;
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public void setCancelled(boolean cancel) {
|
||||
+ cancelled = cancel;
|
||||
+ }
|
||||
+
|
||||
+ public HandlerList getHandlers() {
|
||||
+ return handlers;
|
||||
+ }
|
||||
+
|
||||
+ public static HandlerList getHandlerList() {
|
||||
+ return handlers;
|
||||
+ }
|
||||
+}
|
||||
diff --git a/src/main/java/com/destroystokyo/paper/event/entity/TurtleLayEggEvent.java b/src/main/java/com/destroystokyo/paper/event/entity/TurtleLayEggEvent.java
|
||||
new file mode 100644
|
||||
index 000000000..7cb00f78d
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/com/destroystokyo/paper/event/entity/TurtleLayEggEvent.java
|
||||
@@ -0,0 +1,81 @@
|
||||
+package com.destroystokyo.paper.event.entity;
|
||||
+
|
||||
+import org.bukkit.Location;
|
||||
+import org.bukkit.entity.Turtle;
|
||||
+import org.bukkit.event.Cancellable;
|
||||
+import org.bukkit.event.HandlerList;
|
||||
+import org.bukkit.event.entity.EntityEvent;
|
||||
+
|
||||
+/**
|
||||
+ * Fired when a Turtle lays eggs
|
||||
+ */
|
||||
+public class TurtleLayEggEvent extends EntityEvent implements Cancellable {
|
||||
+ private static final HandlerList handlers = new HandlerList();
|
||||
+ private boolean cancelled = false;
|
||||
+ private final Location location;
|
||||
+ private int eggCount;
|
||||
+
|
||||
+ public TurtleLayEggEvent(Turtle turtle, Location location, int eggCount) {
|
||||
+ super(turtle);
|
||||
+ this.location = location;
|
||||
+ this.eggCount = eggCount;
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
+ * The turtle laying the eggs
|
||||
+ *
|
||||
+ * @return The turtle
|
||||
+ */
|
||||
+ public Turtle getEntity() {
|
||||
+ return (Turtle) entity;
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
+ * Get the location where the eggs are being laid
|
||||
+ *
|
||||
+ * @return Location of eggs
|
||||
+ */
|
||||
+ public Location getLocation() {
|
||||
+ return location;
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
+ * Get the number of eggs being laid
|
||||
+ *
|
||||
+ * @return Number of eggs
|
||||
+ */
|
||||
+ public int getEggCount() {
|
||||
+ return eggCount;
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
+ * Set the number of eggs being laid
|
||||
+ *
|
||||
+ * @param eggCount Number of eggs
|
||||
+ */
|
||||
+ public void setEggCount(int eggCount) {
|
||||
+ if (eggCount < 1) {
|
||||
+ cancelled = true;
|
||||
+ return;
|
||||
+ }
|
||||
+ eggCount = Math.min(eggCount, 4);
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public boolean isCancelled() {
|
||||
+ return cancelled;
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public void setCancelled(boolean cancel) {
|
||||
+ cancelled = cancel;
|
||||
+ }
|
||||
+
|
||||
+ public HandlerList getHandlers() {
|
||||
+ return handlers;
|
||||
+ }
|
||||
+
|
||||
+ public static HandlerList getHandlerList() {
|
||||
+ return handlers;
|
||||
+ }
|
||||
+}
|
||||
diff --git a/src/main/java/com/destroystokyo/paper/event/entity/TurtleStartDiggingEvent.java b/src/main/java/com/destroystokyo/paper/event/entity/TurtleStartDiggingEvent.java
|
||||
new file mode 100644
|
||||
index 000000000..5d53ee08b
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/com/destroystokyo/paper/event/entity/TurtleStartDiggingEvent.java
|
||||
@@ -0,0 +1,57 @@
|
||||
+package com.destroystokyo.paper.event.entity;
|
||||
+
|
||||
+import org.bukkit.Location;
|
||||
+import org.bukkit.entity.Turtle;
|
||||
+import org.bukkit.event.Cancellable;
|
||||
+import org.bukkit.event.HandlerList;
|
||||
+import org.bukkit.event.entity.EntityEvent;
|
||||
+
|
||||
+/**
|
||||
+ * Fired when a Turtle starts digging to lay eggs
|
||||
+ */
|
||||
+public class TurtleStartDiggingEvent extends EntityEvent implements Cancellable {
|
||||
+ private static final HandlerList handlers = new HandlerList();
|
||||
+ private boolean cancelled = false;
|
||||
+ private final Location location;
|
||||
+
|
||||
+ public TurtleStartDiggingEvent(Turtle turtle, Location location) {
|
||||
+ super(turtle);
|
||||
+ this.location = location;
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
+ * The turtle digging
|
||||
+ *
|
||||
+ * @return The turtle
|
||||
+ */
|
||||
+ public Turtle getEntity() {
|
||||
+ return (Turtle) entity;
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
+ * Get the location where the turtle is digging
|
||||
+ *
|
||||
+ * @return Location where digging
|
||||
+ */
|
||||
+ public Location getLocation() {
|
||||
+ return location;
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public boolean isCancelled() {
|
||||
+ return cancelled;
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public void setCancelled(boolean cancel) {
|
||||
+ cancelled = cancel;
|
||||
+ }
|
||||
+
|
||||
+ public HandlerList getHandlers() {
|
||||
+ return handlers;
|
||||
+ }
|
||||
+
|
||||
+ public static HandlerList getHandlerList() {
|
||||
+ return handlers;
|
||||
+ }
|
||||
+}
|
||||
diff --git a/src/main/java/org/bukkit/entity/Turtle.java b/src/main/java/org/bukkit/entity/Turtle.java
|
||||
index 0a4cd2993..e547eead4 100644
|
||||
--- a/src/main/java/org/bukkit/entity/Turtle.java
|
||||
+++ b/src/main/java/org/bukkit/entity/Turtle.java
|
||||
@@ -1,6 +1,53 @@
|
||||
package org.bukkit.entity;
|
||||
|
||||
+import org.bukkit.Location;
|
||||
+
|
||||
/**
|
||||
* Represents a turtle.
|
||||
*/
|
||||
-public interface Turtle extends Animals { }
|
||||
+public interface Turtle extends Animals {
|
||||
+ // Paper start
|
||||
+
|
||||
+ /**
|
||||
+ * Get the turtle's home location
|
||||
+ *
|
||||
+ * @return Home location
|
||||
+ */
|
||||
+ Location getHome();
|
||||
+
|
||||
+ /**
|
||||
+ * Set the turtle's home location
|
||||
+ *
|
||||
+ * @param location Home location
|
||||
+ */
|
||||
+ void setHome(Location location);
|
||||
+
|
||||
+ /**
|
||||
+ * Check if turtle is currently pathfinding to it's home
|
||||
+ *
|
||||
+ * @return True if going home
|
||||
+ */
|
||||
+ boolean isGoingHome();
|
||||
+
|
||||
+ /**
|
||||
+ * Get if turtle is digging to lay eggs
|
||||
+ *
|
||||
+ * @return True if digging
|
||||
+ */
|
||||
+ boolean isDigging();
|
||||
+
|
||||
+ /**
|
||||
+ * Get if turtle is carrying egg
|
||||
+ *
|
||||
+ * @return True if carrying egg
|
||||
+ */
|
||||
+ boolean hasEgg();
|
||||
+
|
||||
+ /**
|
||||
+ * Set if turtle is carrying egg
|
||||
+ *
|
||||
+ * @param hasEgg True if carrying egg
|
||||
+ */
|
||||
+ void setHasEgg(boolean hasEgg);
|
||||
+ // Paper end
|
||||
+}
|
||||
--
|
||||
2.19.1
|
||||
|
158
Spigot-Server-Patches/0389-Turtle-API.patch
Normal file
158
Spigot-Server-Patches/0389-Turtle-API.patch
Normal file
|
@ -0,0 +1,158 @@
|
|||
From 46cd5a86127305a559c95969f0a0c5b86074247d Mon Sep 17 00:00:00 2001
|
||||
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 4f5592d1c9..981a025efc 100644
|
||||
--- a/src/main/java/net/minecraft/server/EntityTurtle.java
|
||||
+++ b/src/main/java/net/minecraft/server/EntityTurtle.java
|
||||
@@ -27,51 +27,63 @@ public class EntityTurtle extends EntityAnimal {
|
||||
this.Q = 1.0F;
|
||||
}
|
||||
|
||||
+ public void setHome(BlockPosition pos) { g(pos); } // Paper - OBFHELPER
|
||||
public void g(BlockPosition blockposition) {
|
||||
this.datawatcher.set(EntityTurtle.bD, blockposition);
|
||||
}
|
||||
|
||||
+ public BlockPosition getHome() { return dB(); } // Paper - OBFHELPER
|
||||
private BlockPosition dB() {
|
||||
return (BlockPosition) this.datawatcher.get(EntityTurtle.bD);
|
||||
}
|
||||
|
||||
+ public void setTravelPos(BlockPosition pos) { h(pos); } // Paper - OBFHELPER
|
||||
private void h(BlockPosition blockposition) {
|
||||
this.datawatcher.set(EntityTurtle.bH, blockposition);
|
||||
}
|
||||
|
||||
+ public BlockPosition getTravelPos() { return dC(); } // Paper - OBFHELPER
|
||||
private BlockPosition dC() {
|
||||
return (BlockPosition) this.datawatcher.get(EntityTurtle.bH);
|
||||
}
|
||||
|
||||
+ public boolean hasEgg() { return dy(); } // Paper - OBFHELPER
|
||||
public boolean dy() {
|
||||
return ((Boolean) this.datawatcher.get(EntityTurtle.bE)).booleanValue();
|
||||
}
|
||||
|
||||
+ public void setHasEgg(boolean hasEgg) { s(hasEgg); } // Paper - OBFHELPER
|
||||
private void s(boolean flag) {
|
||||
this.datawatcher.set(EntityTurtle.bE, Boolean.valueOf(flag));
|
||||
}
|
||||
|
||||
+ public boolean isDigging() { return dz(); } // Paper - OBFHELPER
|
||||
public boolean dz() {
|
||||
return ((Boolean) this.datawatcher.get(EntityTurtle.bG)).booleanValue();
|
||||
}
|
||||
|
||||
+ public void setDigging(boolean digging) { t(digging); } // Paper - OBFHELPER
|
||||
private void t(boolean flag) {
|
||||
this.bK = flag ? 1 : 0;
|
||||
this.datawatcher.set(EntityTurtle.bG, Boolean.valueOf(flag));
|
||||
}
|
||||
|
||||
+ public boolean isGoingHome() { return dH(); } // Paper - OBFHELPER
|
||||
private boolean dH() {
|
||||
return ((Boolean) this.datawatcher.get(EntityTurtle.bI)).booleanValue();
|
||||
}
|
||||
|
||||
+ public void setGoingHome(boolean goingHome) { u(goingHome); } // Paper - OBFHELPER
|
||||
private void u(boolean flag) {
|
||||
this.datawatcher.set(EntityTurtle.bI, Boolean.valueOf(flag));
|
||||
}
|
||||
|
||||
+ public boolean isTravelling() { return dI(); } // Paper - OBFHELPER
|
||||
private boolean dI() {
|
||||
return ((Boolean) this.datawatcher.get(EntityTurtle.bJ)).booleanValue();
|
||||
}
|
||||
|
||||
+ public void setTravelling(boolean travelling) { v(travelling); } // Paper - OBFHELPER
|
||||
private void v(boolean flag) {
|
||||
this.datawatcher.set(EntityTurtle.bJ, Boolean.valueOf(flag));
|
||||
}
|
||||
@@ -441,14 +453,18 @@ public class EntityTurtle extends EntityAnimal {
|
||||
|
||||
if (!this.f.isInWater() && this.k()) {
|
||||
if (this.f.bK < 1) {
|
||||
- this.f.t(true);
|
||||
+ this.f.setDigging(new com.destroystokyo.paper.event.entity.TurtleStartDiggingEvent((org.bukkit.entity.Turtle) this.f.getBukkitEntity(), MCUtil.toLocation(this.f.world, this.d)).callEvent()); // Paper
|
||||
} else if (this.f.bK > 200) {
|
||||
World world = this.f.world;
|
||||
|
||||
// CraftBukkit start
|
||||
- if (!org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent(this.f, this.d.up(), Blocks.TURTLE_EGG.getBlockData().set(BlockTurtleEgg.b, Integer.valueOf(this.f.random.nextInt(4) + 1))).isCancelled()) {
|
||||
+ // Paper start
|
||||
+ int eggCount = this.f.random.nextInt(4) + 1;
|
||||
+ com.destroystokyo.paper.event.entity.TurtleLayEggEvent layEggEvent = new com.destroystokyo.paper.event.entity.TurtleLayEggEvent((org.bukkit.entity.Turtle) this.f.getBukkitEntity(), MCUtil.toLocation(this.f.world, this.d.up()), eggCount);
|
||||
+ if (layEggEvent.callEvent() && !org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent(this.f, this.d.up(), Blocks.TURTLE_EGG.getBlockData().set(BlockTurtleEgg.b, layEggEvent.getEggCount())).isCancelled()) {
|
||||
world.a((EntityHuman) null, blockposition, SoundEffects.ENTITY_TURTLE_LAY_EGG, SoundCategory.BLOCKS, 0.3F, 0.9F + world.random.nextFloat() * 0.2F);
|
||||
- world.setTypeAndData(this.d.up(), (IBlockData) Blocks.TURTLE_EGG.getBlockData().set(BlockTurtleEgg.b, Integer.valueOf(this.f.random.nextInt(4) + 1)), 3);
|
||||
+ world.setTypeAndData(this.d.up(), (IBlockData) Blocks.TURTLE_EGG.getBlockData().set(BlockTurtleEgg.b, layEggEvent.getEggCount()), 3);
|
||||
+ // Paper end
|
||||
}
|
||||
// CraftBukkit end
|
||||
this.f.s(false);
|
||||
@@ -574,7 +590,7 @@ public class EntityTurtle extends EntityAnimal {
|
||||
}
|
||||
|
||||
public boolean a() {
|
||||
- return this.a.isBaby() ? false : (this.a.dy() ? true : (this.a.getRandom().nextInt(700) != 0 ? false : this.a.c(this.a.dB()) >= 4096.0D));
|
||||
+ return this.a.isBaby() ? false : (this.a.dy() ? true : (this.a.getRandom().nextInt(700) != 0 ? false : this.a.c(this.a.dB()) >= 4096.0D)) && new com.destroystokyo.paper.event.entity.TurtleGoHomeEvent((org.bukkit.entity.Turtle) this.a.getBukkitEntity()).callEvent(); // Paper
|
||||
}
|
||||
|
||||
public void c() {
|
||||
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftTurtle.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftTurtle.java
|
||||
index 123a2c75ca..8edcf7af65 100644
|
||||
--- 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
|
||||
}
|
||||
--
|
||||
2.19.1
|
||||
|
Loading…
Reference in a new issue