mirror of
https://github.com/PurpurMC/Purpur.git
synced 2026-02-18 08:57:44 +01:00
104 lines
5.9 KiB
Diff
104 lines
5.9 KiB
Diff
From c95c100ac2d6d0ca91afced8929e903d894bb2c0 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 ++++++++++---
|
|
.../minecraft/server/TileEntityCampfire.java | 21 +++++++++++++++++++
|
|
.../net/pl3x/purpur/PurpurWorldConfig.java | 21 +++++++++++++++++++
|
|
3 files changed, 54 insertions(+), 3 deletions(-)
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/EntityLiving.java b/src/main/java/net/minecraft/server/EntityLiving.java
|
|
index 27375059f..a64639aeb 100644
|
|
--- a/src/main/java/net/minecraft/server/EntityLiving.java
|
|
+++ b/src/main/java/net/minecraft/server/EntityLiving.java
|
|
@@ -2706,10 +2706,19 @@ public abstract class EntityLiving extends Entity {
|
|
}
|
|
|
|
public boolean hasLineOfSight(Entity entity) {
|
|
- Vec3D vec3d = new Vec3D(this.locX, this.locY + (double) this.getHeadHeight(), this.locZ);
|
|
- Vec3D vec3d1 = new Vec3D(entity.locX, entity.locY + (double) entity.getHeadHeight(), entity.locZ);
|
|
+ // Purpur start
|
|
+ return hasLineOfSight(entity.locX, entity.locY + (double) entity.getHeadHeight(), 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, locY + (double) getHeadHeight(), 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/TileEntityCampfire.java b/src/main/java/net/minecraft/server/TileEntityCampfire.java
|
|
index 3a97a6571..e93ecc7b5 100644
|
|
--- a/src/main/java/net/minecraft/server/TileEntityCampfire.java
|
|
+++ b/src/main/java/net/minecraft/server/TileEntityCampfire.java
|
|
@@ -34,6 +34,27 @@ public class TileEntityCampfire extends TileEntity implements Clearable, ITickab
|
|
|
|
} else {
|
|
if (flag) {
|
|
+ // Purpur start
|
|
+ if (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.f();
|
|
} else {
|
|
for (int i = 0; i < this.items.size(); ++i) {
|
|
diff --git a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
|
|
index 30f11fe26..5e9c633ac 100644
|
|
--- a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
|
|
+++ b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
|
|
@@ -60,4 +60,25 @@ 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;
|
|
+ private void campireRegenSettings() {
|
|
+ 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);
|
|
+ }
|
|
}
|
|
--
|
|
2.20.1
|
|
|