2020-08-11 17:38:17 +02:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
|
From: MrIvanPlays <ivan@mrivanplays.com>
|
2020-08-13 17:53:32 +02:00
|
|
|
Date: Thu, 13 Aug 2020 15:14:36 +0300
|
2020-08-11 17:38:17 +02:00
|
|
|
Subject: [PATCH] Per entity (type) collision settings
|
|
|
|
|
|
|
|
Base patch was the only player collisions patch, the original author of was tr7zw <tr7zw@live.de>
|
|
|
|
but pretty much the whole implementation changed.
|
|
|
|
|
|
|
|
This patch implements per entity (type) collision settings with 100% compatibility with bukkit api and
|
|
|
|
vanilla.
|
|
|
|
|
|
|
|
The whole code is based around 1 class, the EntityFilter class. Whole filtering logic is there.
|
|
|
|
|
|
|
|
Co-authored-by: tr7zw <tr7zw@live.de>
|
|
|
|
|
|
|
|
diff --git a/src/main/java/de/minebench/origami/OrigamiConfig.java b/src/main/java/de/minebench/origami/OrigamiConfig.java
|
2021-01-21 11:58:52 +01:00
|
|
|
index f452cc575adf9137f3b9f1eef1904f8116c7a7ec..15aa603a771c327879a4088609850fb86c6347bd 100644
|
2020-08-11 17:38:17 +02:00
|
|
|
--- a/src/main/java/de/minebench/origami/OrigamiConfig.java
|
|
|
|
+++ b/src/main/java/de/minebench/origami/OrigamiConfig.java
|
2021-01-21 11:58:52 +01:00
|
|
|
@@ -136,6 +136,39 @@ public final class OrigamiConfig {
|
|
|
|
private void pigmenDontTargetUnlessHit() {
|
|
|
|
pigmenDontTargetUnlessHit = getBoolean("pigmen.dont-target-unless-hit", pigmenDontTargetUnlessHit);
|
2020-08-11 17:38:17 +02:00
|
|
|
}
|
2020-08-11 20:40:29 +02:00
|
|
|
+
|
2020-08-15 18:18:36 +02:00
|
|
|
+ // Yatopia start
|
2020-08-11 17:38:17 +02:00
|
|
|
+ public boolean playerCollisions = true;
|
|
|
|
+ public boolean animalCollisions = true;
|
|
|
|
+ public boolean ambientCollisions = true;
|
|
|
|
+ public boolean monsterCollisions = true;
|
|
|
|
+ public boolean villagerCollisions = true;
|
|
|
|
+ public boolean pillagerCollisions = true;
|
|
|
|
+ public boolean ironGolemCollisions = true;
|
|
|
|
+ public boolean miscCollisions = true;
|
|
|
|
+ public boolean itemCollisions = true;
|
|
|
|
+ public boolean waterCreatureCollisions = true;
|
|
|
|
+ public boolean waterAmbientCollisions = true;
|
|
|
|
+ public boolean allCollisionsEnabled = false;
|
|
|
|
+ private void specificCollisionSettings() {
|
|
|
|
+ playerCollisions = getBoolean("collisions.players", playerCollisions);
|
|
|
|
+ animalCollisions = getBoolean("collisions.animals", animalCollisions);
|
|
|
|
+ ambientCollisions = getBoolean("collisions.ambient", ambientCollisions);
|
|
|
|
+ monsterCollisions = getBoolean("collisions.monsters", monsterCollisions);
|
|
|
|
+ villagerCollisions = getBoolean("collisions.villagers", villagerCollisions);
|
|
|
|
+ pillagerCollisions = getBoolean("collisions.pillagers", pillagerCollisions);
|
|
|
|
+ ironGolemCollisions = getBoolean("collisions.iron-golems", ironGolemCollisions);
|
|
|
|
+ miscCollisions = getBoolean("collisions.misc", miscCollisions);
|
|
|
|
+ itemCollisions = getBoolean("collisions.items", itemCollisions);
|
|
|
|
+ waterCreatureCollisions = getBoolean("collisions.water-creature", waterCreatureCollisions);
|
|
|
|
+ waterAmbientCollisions = getBoolean("collisions.water-ambient", waterAmbientCollisions);
|
|
|
|
+
|
|
|
|
+ allCollisionsEnabled =
|
|
|
|
+ playerCollisions && animalCollisions && ambientCollisions && monsterCollisions && villagerCollisions
|
|
|
|
+ && pillagerCollisions && ironGolemCollisions && miscCollisions && itemCollisions
|
|
|
|
+ && waterCreatureCollisions && waterAmbientCollisions;
|
|
|
|
+ }
|
2020-08-15 18:18:36 +02:00
|
|
|
+ // Yatopia end
|
2020-08-11 17:38:17 +02:00
|
|
|
}
|
|
|
|
|
2020-08-15 18:18:36 +02:00
|
|
|
}
|
|
|
|
\ No newline at end of file
|
2020-09-01 08:38:17 +02:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/EntityLiving.java b/src/main/java/net/minecraft/server/EntityLiving.java
|
2021-02-05 17:57:30 +01:00
|
|
|
index 39280197902b330dd3d39c721cdef744a15b0550..04623e988ea1f908087b75b729aa1076fb76d8fb 100644
|
2020-09-01 08:38:17 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/EntityLiving.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/EntityLiving.java
|
2021-02-05 17:57:30 +01:00
|
|
|
@@ -2940,7 +2940,7 @@ public abstract class EntityLiving extends Entity {
|
2020-09-01 08:38:17 +02:00
|
|
|
// Paper - end don't run getEntities if we're not going to use its result
|
|
|
|
// Tuinity start - reduce memory allocation from collideNearby
|
|
|
|
List<Entity> list = com.tuinity.tuinity.util.CachedLists.getTempGetEntitiesList();
|
2020-12-13 16:18:57 +01:00
|
|
|
- this.world.getEntities(this, this.getBoundingBox(), IEntitySelector.pushable(this, world.paperConfig.fixClimbingBypassingCrammingRule), list); // Paper - fix climbing bypassing cramming rule
|
|
|
|
+ this.world.getEntities(this, this.getBoundingBox(), org.yatopiamc.yatopia.server.EntityFilter.getFilter(this, world.paperConfig.fixClimbingBypassingCrammingRule), list); // Paper - fix climbing bypassing cramming rule // Yatopia
|
2020-09-01 08:38:17 +02:00
|
|
|
try {
|
|
|
|
// Tuinity end - reduce memory allocation from collideNearby
|
|
|
|
|
2020-12-02 07:35:11 +01:00
|
|
|
diff --git a/src/main/java/org/yatopiamc/yatopia/server/EntityFilter.java b/src/main/java/org/yatopiamc/yatopia/server/EntityFilter.java
|
2020-08-11 17:38:17 +02:00
|
|
|
new file mode 100644
|
2020-12-04 07:34:51 +01:00
|
|
|
index 0000000000000000000000000000000000000000..cb6bab603dcb20521868a482c872f65dd5733c15
|
2020-08-11 17:38:17 +02:00
|
|
|
--- /dev/null
|
2020-12-02 07:35:11 +01:00
|
|
|
+++ b/src/main/java/org/yatopiamc/yatopia/server/EntityFilter.java
|
2020-09-13 11:27:38 +02:00
|
|
|
@@ -0,0 +1,145 @@
|
2020-12-02 07:35:11 +01:00
|
|
|
+package org.yatopiamc.yatopia.server;
|
2020-08-17 20:39:05 +02:00
|
|
|
+
|
|
|
|
+import de.minebench.origami.OrigamiConfig;
|
|
|
|
+import java.util.function.Predicate;
|
|
|
|
+import net.minecraft.server.Entity;
|
|
|
|
+import net.minecraft.server.EntityTypes;
|
|
|
|
+import net.minecraft.server.EnumCreatureType;
|
|
|
|
+import net.minecraft.server.IEntitySelector;
|
|
|
|
+import net.minecraft.server.ScoreboardTeamBase;
|
|
|
|
+
|
|
|
|
+public class EntityFilter {
|
|
|
|
+
|
2020-12-04 07:34:51 +01:00
|
|
|
+ public static Predicate<Entity> getFilter(Entity entity, boolean ignoreClimbing) {
|
2020-08-17 20:39:05 +02:00
|
|
|
+ OrigamiConfig.WorldConfig config = entity.world.origamiConfig;
|
|
|
|
+ if (config.allCollisionsEnabled) {
|
2020-12-04 07:34:51 +01:00
|
|
|
+ return IEntitySelector.pushable(entity, ignoreClimbing);
|
2020-08-17 20:39:05 +02:00
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ ScoreboardTeamBase entityTeam = entity.getScoreboardTeam();
|
|
|
|
+ ScoreboardTeamBase.EnumTeamPush entityTeamPush =
|
|
|
|
+ entityTeam == null ?
|
|
|
|
+ ScoreboardTeamBase.EnumTeamPush.ALWAYS :
|
|
|
|
+ entityTeam.getCollisionRule();
|
|
|
|
+
|
|
|
|
+ if (entityTeamPush == ScoreboardTeamBase.EnumTeamPush.NEVER || entity.world.isClientSide
|
|
|
|
+ || entity.isSpectator()) {
|
2020-08-21 14:44:47 +02:00
|
|
|
+ return tested -> false;
|
2020-08-17 20:39:05 +02:00
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Predicate<Entity> ret = (tested) -> {
|
2020-12-04 07:34:51 +01:00
|
|
|
+ if (!tested.isCollidable(ignoreClimbing) || !tested.canCollideWith(entity) || !entity.canCollideWith(tested)) {
|
2020-08-17 20:39:05 +02:00
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ ScoreboardTeamBase testedTeam = tested.getScoreboardTeam();
|
|
|
|
+ ScoreboardTeamBase.EnumTeamPush testedPush =
|
|
|
|
+ testedTeam == null ?
|
|
|
|
+ ScoreboardTeamBase.EnumTeamPush.ALWAYS :
|
|
|
|
+ testedTeam.getCollisionRule();
|
|
|
|
+
|
|
|
|
+ if (testedPush == ScoreboardTeamBase.EnumTeamPush.NEVER) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ if (testedTeam != null && entityTeam != null) {
|
|
|
|
+ // see IEntitySelector#a(Entity)
|
|
|
|
+ // copied from there, although for me this logic doesn't seem quite right
|
|
|
|
+ boolean ally = entityTeam.isAlly(testedTeam);
|
|
|
|
+
|
|
|
|
+ if ((entityTeamPush == ScoreboardTeamBase.EnumTeamPush.PUSH_OWN_TEAM ||
|
|
|
|
+ testedPush == ScoreboardTeamBase.EnumTeamPush.PUSH_OWN_TEAM) && ally) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ return (entityTeamPush != ScoreboardTeamBase.EnumTeamPush.PUSH_OTHER_TEAMS
|
|
|
|
+ && testedPush != ScoreboardTeamBase.EnumTeamPush.PUSH_OTHER_TEAMS) || ally;
|
|
|
|
+ } else {
|
|
|
|
+ return testedPush == ScoreboardTeamBase.EnumTeamPush.ALWAYS &&
|
|
|
|
+ entityTeamPush == ScoreboardTeamBase.EnumTeamPush.ALWAYS;
|
|
|
|
+ }
|
|
|
|
+ };
|
|
|
|
+
|
2020-08-22 13:01:52 +02:00
|
|
|
+ ret = ret.and((tested) -> {
|
|
|
|
+ if (tested.getEntityType() == EntityTypes.PLAYER && config.playerCollisions) {
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ if (tested.getEntityType().getEnumCreatureType() == EnumCreatureType.CREATURE && config.animalCollisions) {
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ if (tested.getEntityType().getEnumCreatureType() == EnumCreatureType.AMBIENT && config.ambientCollisions) {
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ if (tested.getEntityType().getEnumCreatureType() == EnumCreatureType.MONSTER) {
|
|
|
|
+ if (config.monsterCollisions) {
|
|
|
|
+ if (config.pillagerCollisions) {
|
|
|
|
+ return true;
|
|
|
|
+ } else {
|
|
|
|
+ return tested.getEntityType() != EntityTypes.PILLAGER;
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ if (config.pillagerCollisions) {
|
|
|
|
+ return tested.getEntityType() == EntityTypes.PILLAGER;
|
|
|
|
+ } else {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (tested.getEntityType().getEnumCreatureType() == EnumCreatureType.MISC) {
|
|
|
|
+ if (config.miscCollisions) {
|
2020-09-13 11:27:38 +02:00
|
|
|
+ if (config.villagerCollisions && config.ironGolemCollisions && config.itemCollisions) {
|
|
|
|
+ return true;
|
|
|
|
+ }
|
2020-08-22 13:01:52 +02:00
|
|
|
+ if (!config.villagerCollisions) {
|
2020-09-13 11:27:38 +02:00
|
|
|
+ if (tested.getEntityType() == EntityTypes.VILLAGER) {
|
|
|
|
+ return false;
|
2020-08-22 13:01:52 +02:00
|
|
|
+ }
|
|
|
|
+ }
|
2020-09-13 11:27:38 +02:00
|
|
|
+ if (!config.ironGolemCollisions) {
|
|
|
|
+ if (tested.getEntityType() == EntityTypes.IRON_GOLEM) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (!config.itemCollisions) {
|
|
|
|
+ if (tested.getEntityType() == EntityTypes.ITEM) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return true;
|
2020-08-22 13:01:52 +02:00
|
|
|
+ } else {
|
2020-09-13 11:27:38 +02:00
|
|
|
+ if (config.villagerCollisions && config.ironGolemCollisions && config.itemCollisions) {
|
|
|
|
+ if (tested.getEntityType() == EntityTypes.VILLAGER) {
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ if (tested.getEntityType() == EntityTypes.IRON_GOLEM) {
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ if (tested.getEntityType() == EntityTypes.ITEM) {
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (config.villagerCollisions && config.ironGolemCollisions) {
|
|
|
|
+ if (tested.getEntityType() == EntityTypes.VILLAGER) {
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ if (tested.getEntityType() == EntityTypes.IRON_GOLEM) {
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ }
|
2020-08-22 13:01:52 +02:00
|
|
|
+ if (config.villagerCollisions) {
|
2020-09-13 11:27:38 +02:00
|
|
|
+ if (tested.getEntityType() == EntityTypes.VILLAGER) {
|
|
|
|
+ return true;
|
2020-08-22 13:01:52 +02:00
|
|
|
+ }
|
|
|
|
+ }
|
2020-09-13 11:27:38 +02:00
|
|
|
+ return false;
|
2020-08-22 13:01:52 +02:00
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (tested.getEntityType().getEnumCreatureType() == EnumCreatureType.WATER_CREATURE && config.waterCreatureCollisions) {
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ if (tested.getEntityType().getEnumCreatureType() == EnumCreatureType.WATER_AMBIENT && config.waterAmbientCollisions) {
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ return false;
|
|
|
|
+ });
|
2020-08-17 20:39:05 +02:00
|
|
|
+
|
|
|
|
+ return ret;
|
|
|
|
+ }
|
|
|
|
+}
|