From 5e7bab6b9e4e5a7ddfa40bd55f50f7317f6d1f2e Mon Sep 17 00:00:00 2001 From: gnembon Date: Sat, 9 Jan 2021 04:57:06 -0400 Subject: [PATCH 1/3] events triggered for all players even for player specific events. Fixes #651 --- .../java/carpet/script/CarpetEventServer.java | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/main/java/carpet/script/CarpetEventServer.java b/src/main/java/carpet/script/CarpetEventServer.java index 7bcab974..3c35ed5a 100644 --- a/src/main/java/carpet/script/CarpetEventServer.java +++ b/src/main/java/carpet/script/CarpetEventServer.java @@ -182,23 +182,38 @@ public class CarpetEventServer public final List callList; public final int reqArgs; + final boolean isSystem; + final boolean isGlobalOnly; + final boolean perPlayerDistribution; - public CallbackList(int reqArgs) + public CallbackList(int reqArgs, boolean isSystem, boolean isGlobalOnly) { this.callList = new ArrayList<>(); this.reqArgs = reqArgs; + this.isSystem = isSystem; + this.isGlobalOnly = isGlobalOnly; + perPlayerDistribution = isSystem && !isGlobalOnly; } + /** + * Handles only built-in events from the events system + * @param argumentSupplier + * @param cmdSourceSupplier + */ public void call(Supplier> argumentSupplier, Supplier cmdSourceSupplier) { if (callList.size() > 0) { List argv = argumentSupplier.get(); // empty for onTickDone ServerCommandSource source = cmdSourceSupplier.get(); + String nameCheck = perPlayerDistribution?source.getName():null; assert argv.size() == reqArgs; List fails = new ArrayList<>(); for (Callback call: callList) { + // supressing calls where target player hosts simply don't match + // handling global hosts with player targets is left to when the host is resolved (few calls deeper). + if (nameCheck != null && call.optionalTarget != null && !nameCheck.equals(call.optionalTarget)) continue; if (!call.execute(source, argv)) fails.add(call); } for (Callback call : fails) callList.remove(call); @@ -876,7 +891,7 @@ public class CarpetEventServer public Event(String name, int reqArgs, boolean isGlobalOnly, boolean isPublic) { this.name = name; - this.handler = new CallbackList(reqArgs); + this.handler = new CallbackList(reqArgs, true, isGlobalOnly); this.globalOnly = isGlobalOnly; this.isPublic = isPublic; byName.put(name, this); @@ -924,7 +939,7 @@ public class CarpetEventServer private Event(String name, CarpetScriptServer server) { this.name = name; - this.handler = new CallbackList(1); + this.handler = new CallbackList(1, false, false); this.globalOnly = false; this.isPublic = true; server.events.customEvents.put(name, this); From 0f90328e53f2c4b3a445ec198d9f60509d595c40 Mon Sep 17 00:00:00 2001 From: Mitchell Skaggs Date: Tue, 12 Jan 2021 03:27:08 -0600 Subject: [PATCH 2/3] Modify mixin signature to match 1.16 signature --- src/main/java/carpet/mixins/VillagerEntity_aiMixin.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/carpet/mixins/VillagerEntity_aiMixin.java b/src/main/java/carpet/mixins/VillagerEntity_aiMixin.java index b0e76355..37a403a7 100644 --- a/src/main/java/carpet/mixins/VillagerEntity_aiMixin.java +++ b/src/main/java/carpet/mixins/VillagerEntity_aiMixin.java @@ -19,6 +19,7 @@ import net.minecraft.item.Items; import net.minecraft.particle.ParticleTypes; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.world.ServerWorld; +import net.minecraft.util.ActionResult; import net.minecraft.util.dynamic.GlobalPos; import net.minecraft.util.Hand; import net.minecraft.util.math.BlockPos; @@ -113,7 +114,7 @@ public abstract class VillagerEntity_aiMixin extends MerchantEntity } @Inject(method = "interactMob", at = @At("HEAD"), cancellable = true) - private void onInteract(PlayerEntity playerEntity_1, Hand hand_1, CallbackInfoReturnable cir) + private void onInteract(PlayerEntity playerEntity_1, Hand hand_1, CallbackInfoReturnable cir) { if (MobAI.isTracking(this, MobAI.TrackingType.VILLAGER_BREEDING)) { @@ -121,7 +122,7 @@ public abstract class VillagerEntity_aiMixin extends MerchantEntity if (itemStack_1.getItem() == Items.EMERALD) { GlobalPos bedPos = this.brain.getOptionalMemory(MemoryModuleType.HOME).orElse(null); - if (bedPos == null || bedPos.getDimension() != world.getRegistryKey()) // get DImension + if (bedPos == null || bedPos.getDimension() != world.getRegistryKey()) // get Dimension { sayNo(); ((ServerWorld) getEntityWorld()).spawnParticles(ParticleTypes.BARRIER, getX(), getY() + getStandingEyeHeight() + 1, getZ(), 1, 0.1, 0.1, 0.1, 0.0); @@ -162,7 +163,7 @@ public abstract class VillagerEntity_aiMixin extends MerchantEntity 1, 0.1, 0.1, 0.1, 0.0); } } - cir.setReturnValue(false); + cir.setReturnValue(ActionResult.FAIL); cir.cancel(); } } From b362c460567b9eb7327954f729daf902bb5d8657 Mon Sep 17 00:00:00 2001 From: gnembon Date: Wed, 13 Jan 2021 18:18:11 -0400 Subject: [PATCH 3/3] 1.4.22, proven support for 1.16.5-pre1 --- gradle.properties | 6 +++--- src/main/java/carpet/CarpetSettings.java | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/gradle.properties b/gradle.properties index 83348ba8..b401c753 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,11 +5,11 @@ org.gradle.jvmargs=-Xmx1G # check these on https://fabricmc.net/use # or better: https://modmuss50.me/fabric.html minecraft_version=1.16.4 - yarn_mappings=1.16.4+build.7 - loader_version=0.10.8 + yarn_mappings=1.16.4+build.9 + loader_version=0.11.0 # Mod Properties - mod_version = 1.4.21 + mod_version = 1.4.22 maven_group = carpet archives_base_name = fabric-carpet diff --git a/src/main/java/carpet/CarpetSettings.java b/src/main/java/carpet/CarpetSettings.java index 172a3cb8..a202e209 100644 --- a/src/main/java/carpet/CarpetSettings.java +++ b/src/main/java/carpet/CarpetSettings.java @@ -36,7 +36,7 @@ import static carpet.settings.RuleCategory.CLIENT; @SuppressWarnings("CanBeFinal") public class CarpetSettings { - public static final String carpetVersion = "1.4.21+v201216"; + public static final String carpetVersion = "1.4.22+v210113"; public static final Logger LOG = LogManager.getLogger("carpet"); public static boolean skipGenerationChecks = false; public static boolean impendingFillSkipUpdates = false;