mirror of
https://github.com/PurpurMC/Purpur.git
synced 2026-02-17 08:27:43 +01:00
Conduit behavior configuration
This commit is contained in:
@@ -1,130 +0,0 @@
|
|||||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
||||||
From: Encode42 <me@encode42.dev>
|
|
||||||
Date: Sun, 8 Aug 2021 18:14:31 -0400
|
|
||||||
Subject: [PATCH] Conduit behavior configuration
|
|
||||||
|
|
||||||
|
|
||||||
diff --git a/net/minecraft/world/level/block/entity/ConduitBlockEntity.java b/net/minecraft/world/level/block/entity/ConduitBlockEntity.java
|
|
||||||
index d354c2ad41533ec8d52f7c5f63f8f74a0b1ce235..a43c41a26c1e34a2f4eda1c498a562664a783c77 100644
|
|
||||||
--- a/net/minecraft/world/level/block/entity/ConduitBlockEntity.java
|
|
||||||
+++ b/net/minecraft/world/level/block/entity/ConduitBlockEntity.java
|
|
||||||
@@ -169,7 +169,7 @@ public class ConduitBlockEntity extends BlockEntity {
|
|
||||||
if ((l > 1 || i1 > 1 || j1 > 1) && (i == 0 && (i1 == 2 || j1 == 2) || j == 0 && (l == 2 || j1 == 2) || k == 0 && (l == 2 || i1 == 2))) {
|
|
||||||
BlockPos blockposition2 = pos.offset(i, j, k);
|
|
||||||
BlockState iblockdata = world.getBlockState(blockposition2);
|
|
||||||
- Block[] ablock = ConduitBlockEntity.VALID_BLOCKS;
|
|
||||||
+ Block[] ablock = world.purpurConfig.conduitBlocks; // Purpur
|
|
||||||
int k1 = ablock.length;
|
|
||||||
|
|
||||||
for (int l1 = 0; l1 < k1; ++l1) {
|
|
||||||
@@ -189,13 +189,13 @@ public class ConduitBlockEntity extends BlockEntity {
|
|
||||||
|
|
||||||
private static void applyEffects(Level world, BlockPos pos, List<BlockPos> activatingBlocks) {
|
|
||||||
// CraftBukkit start
|
|
||||||
- ConduitBlockEntity.applyEffects(world, pos, ConduitBlockEntity.getRange(activatingBlocks));
|
|
||||||
+ ConduitBlockEntity.applyEffects(world, pos, ConduitBlockEntity.getRange(activatingBlocks, world)); // Purpur
|
|
||||||
}
|
|
||||||
|
|
||||||
- public static int getRange(List<BlockPos> list) {
|
|
||||||
+ public static int getRange(List<BlockPos> list, Level world) { // Purpur
|
|
||||||
// CraftBukkit end
|
|
||||||
int i = list.size();
|
|
||||||
- int j = i / 7 * 16;
|
|
||||||
+ int j = i / 7 * world.purpurConfig.conduitDistance; // Purpur
|
|
||||||
// CraftBukkit start
|
|
||||||
return j;
|
|
||||||
}
|
|
||||||
@@ -238,20 +238,20 @@ public class ConduitBlockEntity extends BlockEntity {
|
|
||||||
tileentityconduit.destroyTarget = ConduitBlockEntity.findDestroyTarget(world, blockposition, tileentityconduit.destroyTargetUUID);
|
|
||||||
tileentityconduit.destroyTargetUUID = null;
|
|
||||||
} else if (tileentityconduit.destroyTarget == null) {
|
|
||||||
- List<LivingEntity> list1 = world.getEntitiesOfClass(LivingEntity.class, ConduitBlockEntity.getDestroyRangeAABB(blockposition), (entityliving1) -> {
|
|
||||||
+ List<LivingEntity> list1 = world.getEntitiesOfClass(LivingEntity.class, ConduitBlockEntity.getDestroyRangeAABB(blockposition, world), (entityliving1) -> { // Purpur
|
|
||||||
return entityliving1 instanceof Enemy && entityliving1.isInWaterOrRain();
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!list1.isEmpty()) {
|
|
||||||
tileentityconduit.destroyTarget = (LivingEntity) list1.get(world.random.nextInt(list1.size()));
|
|
||||||
}
|
|
||||||
- } else if (!tileentityconduit.destroyTarget.isAlive() || !blockposition.closerThan(tileentityconduit.destroyTarget.blockPosition(), 8.0D)) {
|
|
||||||
+ } else if (!tileentityconduit.destroyTarget.isAlive() || !blockposition.closerThan(tileentityconduit.destroyTarget.blockPosition(), world.purpurConfig.conduitDamageDistance)) { // Purpur
|
|
||||||
tileentityconduit.destroyTarget = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// CraftBukkit start
|
|
||||||
if (damageTarget && tileentityconduit.destroyTarget != null) {
|
|
||||||
- if (tileentityconduit.destroyTarget.hurtServer((ServerLevel) world, world.damageSources().magic().directBlock(world, blockposition), 4.0F)) {
|
|
||||||
+ if (tileentityconduit.destroyTarget.hurtServer((ServerLevel) world, world.damageSources().magic().directBlock(world, blockposition), world.purpurConfig.conduitDamageAmount)) { // Purpur
|
|
||||||
world.playSound(null, tileentityconduit.destroyTarget.getX(), tileentityconduit.destroyTarget.getY(), tileentityconduit.destroyTarget.getZ(), SoundEvents.CONDUIT_ATTACK_TARGET, SoundSource.BLOCKS, 1.0F, 1.0F);
|
|
||||||
}
|
|
||||||
// CraftBukkit end
|
|
||||||
@@ -276,16 +276,22 @@ public class ConduitBlockEntity extends BlockEntity {
|
|
||||||
}
|
|
||||||
|
|
||||||
public static AABB getDestroyRangeAABB(BlockPos pos) {
|
|
||||||
+ // Purpur start
|
|
||||||
+ return getDestroyRangeAABB(pos, null);
|
|
||||||
+ }
|
|
||||||
+
|
|
||||||
+ private static AABB getDestroyRangeAABB(BlockPos pos, Level level) {
|
|
||||||
+ // Purpur end
|
|
||||||
int i = pos.getX();
|
|
||||||
int j = pos.getY();
|
|
||||||
int k = pos.getZ();
|
|
||||||
|
|
||||||
- return (new AABB((double) i, (double) j, (double) k, (double) (i + 1), (double) (j + 1), (double) (k + 1))).inflate(8.0D);
|
|
||||||
+ return (new AABB((double) i, (double) j, (double) k, (double) (i + 1), (double) (j + 1), (double) (k + 1))).inflate(level == null ? 8.0D : level.purpurConfig.conduitDamageDistance); // Purpur
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
private static LivingEntity findDestroyTarget(Level world, BlockPos pos, UUID uuid) {
|
|
||||||
- List<LivingEntity> list = world.getEntitiesOfClass(LivingEntity.class, ConduitBlockEntity.getDestroyRangeAABB(pos), (entityliving) -> {
|
|
||||||
+ List<LivingEntity> list = world.getEntitiesOfClass(LivingEntity.class, ConduitBlockEntity.getDestroyRangeAABB(pos, world), (entityliving) -> { // Purpur
|
|
||||||
return entityliving.getUUID().equals(uuid);
|
|
||||||
});
|
|
||||||
|
|
||||||
diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftConduit.java b/src/main/java/org/bukkit/craftbukkit/block/CraftConduit.java
|
|
||||||
index c1759aeb3e6ad0e4eb66cba3da1b120dd1dce812..1a91bc2e422db0eba65694ac046f1b362c6b0cd6 100644
|
|
||||||
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftConduit.java
|
|
||||||
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftConduit.java
|
|
||||||
@@ -73,7 +73,7 @@ public class CraftConduit extends CraftBlockEntityState<ConduitBlockEntity> impl
|
|
||||||
public int getRange() {
|
|
||||||
this.ensureNoWorldGeneration();
|
|
||||||
ConduitBlockEntity conduit = (ConduitBlockEntity) this.getTileEntityFromWorld();
|
|
||||||
- return (conduit != null) ? ConduitBlockEntity.getRange(conduit.effectBlocks) : 0;
|
|
||||||
+ return (conduit != null) ? ConduitBlockEntity.getRange(conduit.effectBlocks, this.world.getHandle()) : 0; // Purpur
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
diff --git a/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java b/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java
|
|
||||||
index 8f90dbc4395381f712befbbf09b6ae94887843e7..df054975a396856693eb6e70637a50b089836e37 100644
|
|
||||||
--- a/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java
|
|
||||||
+++ b/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java
|
|
||||||
@@ -3039,4 +3039,27 @@ public class PurpurWorldConfig {
|
|
||||||
private void hungerSettings() {
|
|
||||||
hungerStarvationDamage = (float) getDouble("hunger.starvation-damage", hungerStarvationDamage);
|
|
||||||
}
|
|
||||||
+
|
|
||||||
+ public int conduitDistance = 16;
|
|
||||||
+ public double conduitDamageDistance = 8;
|
|
||||||
+ public float conduitDamageAmount = 4;
|
|
||||||
+ public Block[] conduitBlocks;
|
|
||||||
+ private void conduitSettings() {
|
|
||||||
+ conduitDistance = getInt("blocks.conduit.effect-distance", conduitDistance);
|
|
||||||
+ conduitDamageDistance = getDouble("blocks.conduit.mob-damage.distance", conduitDamageDistance);
|
|
||||||
+ conduitDamageAmount = (float) getDouble("blocks.conduit.mob-damage.damage-amount", conduitDamageAmount);
|
|
||||||
+ List<Block> conduitBlockList = new ArrayList<>();
|
|
||||||
+ getList("blocks.conduit.valid-ring-blocks", new ArrayList<String>(){{
|
|
||||||
+ add("minecraft:prismarine");
|
|
||||||
+ add("minecraft:prismarine_bricks");
|
|
||||||
+ add("minecraft:sea_lantern");
|
|
||||||
+ add("minecraft:dark_prismarine");
|
|
||||||
+ }}).forEach(key -> {
|
|
||||||
+ Block block = BuiltInRegistries.BLOCK.getValue(ResourceLocation.parse(key.toString()));
|
|
||||||
+ if (!block.defaultBlockState().isAir()) {
|
|
||||||
+ conduitBlockList.add(block);
|
|
||||||
+ }
|
|
||||||
+ });
|
|
||||||
+ conduitBlocks = conduitBlockList.toArray(Block[]::new);
|
|
||||||
+ }
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,74 @@
|
|||||||
|
--- a/net/minecraft/world/level/block/entity/ConduitBlockEntity.java
|
||||||
|
+++ b/net/minecraft/world/level/block/entity/ConduitBlockEntity.java
|
||||||
|
@@ -155,7 +_,7 @@
|
||||||
|
BlockPos blockPos1 = pos.offset(i, i1, i2x);
|
||||||
|
BlockState blockState = level.getBlockState(blockPos1);
|
||||||
|
|
||||||
|
- for (Block block : VALID_BLOCKS) {
|
||||||
|
+ for (Block block : level.purpurConfig.conduitBlocks) { // Purpur - Conduit behavior configuration
|
||||||
|
if (blockState.is(block)) {
|
||||||
|
positions.add(blockPos1);
|
||||||
|
}
|
||||||
|
@@ -170,13 +_,13 @@
|
||||||
|
|
||||||
|
private static void applyEffects(Level level, BlockPos pos, List<BlockPos> positions) {
|
||||||
|
// CraftBukkit start
|
||||||
|
- ConduitBlockEntity.applyEffects(level, pos, ConduitBlockEntity.getRange(positions));
|
||||||
|
+ ConduitBlockEntity.applyEffects(level, pos, ConduitBlockEntity.getRange(positions, level)); // Purpur - Conduit behavior configuration
|
||||||
|
}
|
||||||
|
|
||||||
|
- public static int getRange(List<BlockPos> positions) {
|
||||||
|
+ public static int getRange(List<BlockPos> positions, Level level) { // Purpur - Conduit behavior configuration
|
||||||
|
// CraftBukkit end
|
||||||
|
int size = positions.size();
|
||||||
|
- int i = size / 7 * 16;
|
||||||
|
+ int i = size / 7 * level.purpurConfig.conduitDistance; // Purpur - Conduit behavior configuration
|
||||||
|
// CraftBukkit start
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
@@ -213,17 +_,17 @@
|
||||||
|
blockEntity.destroyTargetUUID = null;
|
||||||
|
} else if (blockEntity.destroyTarget == null) {
|
||||||
|
List<LivingEntity> entitiesOfClass = level.getEntitiesOfClass(
|
||||||
|
- LivingEntity.class, getDestroyRangeAABB(pos), collidedEntity -> collidedEntity instanceof Enemy && collidedEntity.isInWaterOrRain()
|
||||||
|
+ LivingEntity.class, getDestroyRangeAABB(pos, level), collidedEntity -> collidedEntity instanceof Enemy && collidedEntity.isInWaterOrRain() // Purpur - Conduit behavior configuration
|
||||||
|
);
|
||||||
|
if (!entitiesOfClass.isEmpty()) {
|
||||||
|
blockEntity.destroyTarget = entitiesOfClass.get(level.random.nextInt(entitiesOfClass.size()));
|
||||||
|
}
|
||||||
|
- } else if (!blockEntity.destroyTarget.isAlive() || !pos.closerThan(blockEntity.destroyTarget.blockPosition(), 8.0)) {
|
||||||
|
+ } else if (!blockEntity.destroyTarget.isAlive() || !pos.closerThan(blockEntity.destroyTarget.blockPosition(), level.purpurConfig.conduitDamageDistance)) { // Purpur - Conduit behavior configuration
|
||||||
|
blockEntity.destroyTarget = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (damageTarget && blockEntity.destroyTarget != null) { // CraftBukkit
|
||||||
|
- if (blockEntity.destroyTarget.hurtServer((net.minecraft.server.level.ServerLevel) level, level.damageSources().magic().directBlock(level, pos), 4.0F)) // CraftBukkit
|
||||||
|
+ if (blockEntity.destroyTarget.hurtServer((net.minecraft.server.level.ServerLevel) level, level.damageSources().magic().directBlock(level, pos), level.purpurConfig.conduitDamageAmount)) // CraftBukkit // Purpur - Conduit behavior configuration
|
||||||
|
level.playSound(
|
||||||
|
null,
|
||||||
|
blockEntity.destroyTarget.getX(),
|
||||||
|
@@ -253,16 +_,22 @@
|
||||||
|
}
|
||||||
|
|
||||||
|
public static AABB getDestroyRangeAABB(BlockPos pos) {
|
||||||
|
+ // Purpur start - Conduit behavior configuration
|
||||||
|
+ return getDestroyRangeAABB(pos, null);
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ private static AABB getDestroyRangeAABB(BlockPos pos, Level level) {
|
||||||
|
+ // Purpur end - Conduit behavior configuration
|
||||||
|
int x = pos.getX();
|
||||||
|
int y = pos.getY();
|
||||||
|
int z = pos.getZ();
|
||||||
|
- return new AABB(x, y, z, x + 1, y + 1, z + 1).inflate(8.0);
|
||||||
|
+ return new AABB(x, y, z, x + 1, y + 1, z + 1).inflate(level == null ? 8.0 : level.purpurConfig.conduitDamageDistance); // Purpur - Conduit behavior configuration
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
private static LivingEntity findDestroyTarget(Level level, BlockPos pos, UUID targetId) {
|
||||||
|
List<LivingEntity> entitiesOfClass = level.getEntitiesOfClass(
|
||||||
|
- LivingEntity.class, getDestroyRangeAABB(pos), collidedEntity -> collidedEntity.getUUID().equals(targetId)
|
||||||
|
+ LivingEntity.class, getDestroyRangeAABB(pos, level), collidedEntity -> collidedEntity.getUUID().equals(targetId) // Purpur - Conduit behavior configuration
|
||||||
|
);
|
||||||
|
return entitiesOfClass.size() == 1 ? entitiesOfClass.get(0) : null;
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftConduit.java
|
||||||
|
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftConduit.java
|
||||||
|
@@ -73,7 +_,7 @@
|
||||||
|
public int getRange() {
|
||||||
|
this.ensureNoWorldGeneration();
|
||||||
|
ConduitBlockEntity conduit = (ConduitBlockEntity) this.getTileEntityFromWorld();
|
||||||
|
- return (conduit != null) ? ConduitBlockEntity.getRange(conduit.effectBlocks) : 0;
|
||||||
|
+ return (conduit != null) ? ConduitBlockEntity.getRange(conduit.effectBlocks, this.world.getHandle()) : 0; // Purpur - Conduit behavior configuration
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
@@ -3038,4 +3038,27 @@ public class PurpurWorldConfig {
|
|||||||
private void hungerSettings() {
|
private void hungerSettings() {
|
||||||
hungerStarvationDamage = (float) getDouble("hunger.starvation-damage", hungerStarvationDamage);
|
hungerStarvationDamage = (float) getDouble("hunger.starvation-damage", hungerStarvationDamage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int conduitDistance = 16;
|
||||||
|
public double conduitDamageDistance = 8;
|
||||||
|
public float conduitDamageAmount = 4;
|
||||||
|
public Block[] conduitBlocks;
|
||||||
|
private void conduitSettings() {
|
||||||
|
conduitDistance = getInt("blocks.conduit.effect-distance", conduitDistance);
|
||||||
|
conduitDamageDistance = getDouble("blocks.conduit.mob-damage.distance", conduitDamageDistance);
|
||||||
|
conduitDamageAmount = (float) getDouble("blocks.conduit.mob-damage.damage-amount", conduitDamageAmount);
|
||||||
|
List<Block> conduitBlockList = new ArrayList<>();
|
||||||
|
getList("blocks.conduit.valid-ring-blocks", new ArrayList<String>(){{
|
||||||
|
add("minecraft:prismarine");
|
||||||
|
add("minecraft:prismarine_bricks");
|
||||||
|
add("minecraft:sea_lantern");
|
||||||
|
add("minecraft:dark_prismarine");
|
||||||
|
}}).forEach(key -> {
|
||||||
|
Block block = BuiltInRegistries.BLOCK.getValue(ResourceLocation.parse(key.toString()));
|
||||||
|
if (!block.defaultBlockState().isAir()) {
|
||||||
|
conduitBlockList.add(block);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
conduitBlocks = conduitBlockList.toArray(Block[]::new);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user