Files
Purpur/patches/server/0014-Add-regen-effect-to-campfires.patch
William Blake Galbreath 18ebfc0366 Update to 1.15
2019-12-13 15:11:37 -06:00

188 lines
9.9 KiB
Diff

From 2a405bf3462278e4dfaf7f34e5bc79de1afbf9d3 Mon Sep 17 00:00:00 2001
From: William Blake Galbreath <blake.galbreath@gmail.com>
Date: Sun, 19 May 2019 18:11:53 -0500
Subject: [PATCH] Add regen effect to campfires
---
.../net/minecraft/server/EntityLiving.java | 15 ++++++++--
.../net/minecraft/server/EntityPotion.java | 26 ++++++++++++++++
.../minecraft/server/TileEntityCampfire.java | 30 +++++++++++++++++++
.../net/pl3x/purpur/PurpurWorldConfig.java | 23 ++++++++++++++
4 files changed, 91 insertions(+), 3 deletions(-)
diff --git a/src/main/java/net/minecraft/server/EntityLiving.java b/src/main/java/net/minecraft/server/EntityLiving.java
index 969a77c597..50c494503e 100644
--- a/src/main/java/net/minecraft/server/EntityLiving.java
+++ b/src/main/java/net/minecraft/server/EntityLiving.java
@@ -2779,10 +2779,19 @@ public abstract class EntityLiving extends Entity {
}
public boolean hasLineOfSight(Entity entity) {
- Vec3D vec3d = new Vec3D(this.locX(), this.getHeadY(), this.locZ());
- Vec3D vec3d1 = new Vec3D(entity.locX(), entity.getHeadY(), entity.locZ());
+ // Purpur start
+ return hasLineOfSight(entity.locX(), entity.getHeadY(), entity.locZ());
+ }
+
+ public boolean hasLineOfSight(TileEntity te) {
+ return hasLineOfSight(te.position.x + 0.5, te.position.y + 0.5, te.position.z + 0.5);
+ }
- return this.world.rayTrace(new RayTrace(vec3d, vec3d1, RayTrace.BlockCollisionOption.COLLIDER, RayTrace.FluidCollisionOption.NONE, this)).getType() == MovingObjectPosition.EnumMovingObjectType.MISS;
+ public boolean hasLineOfSight(double x, double y, double z) {
+ Vec3D start = new Vec3D(locX(), getHeadY(), locZ());
+ Vec3D end = new Vec3D(x, y, z);
+ return this.world.rayTrace(new RayTrace(start, end, RayTrace.BlockCollisionOption.COLLIDER, RayTrace.FluidCollisionOption.NONE, this)).getType() == MovingObjectPosition.EnumMovingObjectType.MISS;
+ // Purpur end
}
@Override
diff --git a/src/main/java/net/minecraft/server/EntityPotion.java b/src/main/java/net/minecraft/server/EntityPotion.java
index 2f9a73ea33..9c9131d8d4 100644
--- a/src/main/java/net/minecraft/server/EntityPotion.java
+++ b/src/main/java/net/minecraft/server/EntityPotion.java
@@ -91,6 +91,7 @@ public class EntityPotion extends EntityProjectile {
} else {
this.a(list, movingobjectposition.getType() == MovingObjectPosition.EnumMovingObjectType.ENTITY ? ((MovingObjectPositionEntity) movingobjectposition).getEntity() : null);
}
+ splashCampfires(list); // Purpur
}
int i = potionregistry.b() ? 2007 : 2002;
@@ -100,6 +101,31 @@ public class EntityPotion extends EntityProjectile {
}
}
+ // Purpur start
+ private void splashCampfires(List<MobEffect> list) {
+ AxisAlignedBB aabb = getBoundingBox().grow(4.0D, 2.0D, 4.0D);
+ for (int x = (int) aabb.minX; x <= aabb.maxX; x++) {
+ for (int z = (int) aabb.minZ; z <= aabb.maxZ; z++) {
+ for (int y = (int) aabb.minY; y <= aabb.maxY; y++) {
+ BlockPosition pos = new BlockPosition(x, y, z);
+ TileEntity te = world.getTileEntity(pos);
+ if (te instanceof TileEntityCampfire) {
+ for (MobEffect effect : list) {
+ if (effect.getMobEffect() == MobEffects.REGENERATION) {
+ for (int i = 0; i < 6 ; i++) {
+ ((WorldServer) world).sendParticles(((WorldServer) world).players, null, Particles.HEART, te.position.x, te.position.y + 1, te.position.z, 1, 0.5, 0.5, 0.5, 0, true);
+ }
+ ((TileEntityCampfire) te).splashed = true;
+ break;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ // Purpur end
+
private void splash() {
AxisAlignedBB axisalignedbb = this.getBoundingBox().grow(4.0D, 2.0D, 4.0D);
List<EntityLiving> list = this.world.a(EntityLiving.class, axisalignedbb, EntityPotion.e);
diff --git a/src/main/java/net/minecraft/server/TileEntityCampfire.java b/src/main/java/net/minecraft/server/TileEntityCampfire.java
index a1580b8c6d..3a44454ed7 100644
--- a/src/main/java/net/minecraft/server/TileEntityCampfire.java
+++ b/src/main/java/net/minecraft/server/TileEntityCampfire.java
@@ -14,6 +14,7 @@ public class TileEntityCampfire extends TileEntity implements Clearable, ITickab
private final NonNullList<ItemStack> items;
public final int[] cookingTimes;
public final int[] cookingTotalTimes;
+ public boolean splashed = false; // Purpur
public TileEntityCampfire() {
super(TileEntityTypes.CAMPFIRE);
@@ -34,6 +35,27 @@ public class TileEntityCampfire extends TileEntity implements Clearable, ITickab
} else {
if (flag) {
+ // Purpur start
+ if ((splashed || !world.purpurConfig.campfireRequireRegenPotion) && world.purpurConfig.campfireRegenInterval > 0 && world.getTime() % world.purpurConfig.campfireRegenInterval == 0L) {
+ boolean signalBoost = getBlock().get(BlockCampfire.c);
+ int duration = signalBoost ? world.purpurConfig.campfireRegenBoostDuration : world.purpurConfig.campfireRegenDuration;
+ byte amp = (byte) (signalBoost ? world.purpurConfig.campfireRegenBoostAmp : world.purpurConfig.campfireRegenAmp);
+ int range = signalBoost ? world.purpurConfig.campfireRegenBoostRange : world.purpurConfig.campfireRegenRange;
+ MobEffect regeneration = new MobEffect(MobEffects.REGENERATION, duration, amp, true, true);
+ world.a(EntityHuman.class, new AxisAlignedBB(position).g(range)).forEach(entityhuman -> {
+ boolean noLineOfSign = true;
+ if (!signalBoost && world.purpurConfig.campfireRegenRequireLineOfSight) {
+ noLineOfSign = false;
+ }
+ if (signalBoost && world.purpurConfig.campfireRegenBoostRequireLineOfSight) {
+ noLineOfSign = false;
+ }
+ if (noLineOfSign || entityhuman.hasLineOfSight(this)) {
+ entityhuman.addEffect(regeneration);
+ }
+ });
+ }
+ // Purpur end
this.h();
} else {
for (int i = 0; i < this.items.size(); ++i) {
@@ -41,6 +63,7 @@ public class TileEntityCampfire extends TileEntity implements Clearable, ITickab
this.cookingTimes[i] = MathHelper.clamp(this.cookingTimes[i] - 2, 0, this.cookingTotalTimes[i]);
}
}
+ splashed = false; // Purpur
}
}
@@ -137,6 +160,12 @@ public class TileEntityCampfire extends TileEntity implements Clearable, ITickab
System.arraycopy(aint, 0, this.cookingTotalTimes, 0, Math.min(this.cookingTotalTimes.length, aint.length));
}
+ // Purpur start
+ if (nbttagcompound.hasKey("Purpur.splashed")) {
+ splashed = nbttagcompound.getBoolean("Purpur.splashed");
+ }
+ // Purpur end
+
}
@Override
@@ -144,6 +173,7 @@ public class TileEntityCampfire extends TileEntity implements Clearable, ITickab
this.d(nbttagcompound);
nbttagcompound.setIntArray("CookingTimes", this.cookingTimes);
nbttagcompound.setIntArray("CookingTotalTimes", this.cookingTotalTimes);
+ nbttagcompound.setBoolean("Purpur.splashed", splashed); // Purpur
return nbttagcompound;
}
diff --git a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
index 30f11fe261..314fd584b8 100644
--- a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
+++ b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
@@ -60,4 +60,27 @@ public class PurpurWorldConfig {
config.addDefault("world-settings.default." + path, def);
return config.getString("world-settings." + worldName + "." + path, config.getString("world-settings.default." + path));
}
+
+ public int campfireRegenInterval = 40;
+ public int campfireRegenDuration = 80;
+ public int campfireRegenRange = 5;
+ public int campfireRegenAmp = 0;
+ public boolean campfireRegenRequireLineOfSight = true;
+ public int campfireRegenBoostDuration = 80;
+ public int campfireRegenBoostRange = 10;
+ public int campfireRegenBoostAmp = 1;
+ public boolean campfireRegenBoostRequireLineOfSight = false;
+ public boolean campfireRequireRegenPotion = true;
+ private void campfireRegenSettings() {
+ campfireRegenInterval = getInt("campfire-regen.interval", campfireRegenInterval);
+ campfireRegenDuration = getInt("campfire-regen.duration", campfireRegenDuration);
+ campfireRegenRange = getInt("campfire-regen.range", campfireRegenRange);
+ campfireRegenAmp = getInt("campfire-regen.amplifier", campfireRegenAmp);
+ campfireRegenRequireLineOfSight = getBoolean("campfire-regen.require-line-of-sight", campfireRegenRequireLineOfSight);
+ campfireRegenBoostDuration = getInt("campfire-regen.boost-duration", campfireRegenBoostDuration);
+ campfireRegenBoostRange = getInt("campfire-regen.boost-range", campfireRegenBoostRange);
+ campfireRegenBoostAmp = getInt("campfire-regen.boost-amplifier", campfireRegenBoostAmp);
+ campfireRegenBoostRequireLineOfSight = getBoolean("campfire-regen.boost-require-line-of-sight", campfireRegenBoostRequireLineOfSight);
+ campfireRequireRegenPotion = getBoolean("campfire-regen.requires-regen-potion-to-activate", campfireRequireRegenPotion);
+ }
}
--
2.24.0.rc1