From 382d677663064dcd49708def5acdff81599f4079 Mon Sep 17 00:00:00 2001 From: Max Date: Thu, 11 Feb 2021 19:11:38 +0100 Subject: [PATCH 01/44] Mark old sided register methods for removal (1.6) --- .../shedaniel/architectury/networking/NetworkChannel.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/common/src/main/java/me/shedaniel/architectury/networking/NetworkChannel.java b/common/src/main/java/me/shedaniel/architectury/networking/NetworkChannel.java index 75d8c282..101db7ff 100644 --- a/common/src/main/java/me/shedaniel/architectury/networking/NetworkChannel.java +++ b/common/src/main/java/me/shedaniel/architectury/networking/NetworkChannel.java @@ -32,7 +32,7 @@ import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.protocol.Packet; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerPlayer; -import org.apache.commons.lang3.StringUtils; +import org.jetbrains.annotations.ApiStatus; import java.util.Map; import java.util.Objects; @@ -57,11 +57,13 @@ public final class NetworkChannel { } @Deprecated + @ApiStatus.ScheduledForRemoval(inVersion = "1.6") public void register(NetworkManager.Side side, Class type, BiConsumer encoder, Function decoder, BiConsumer> messageConsumer) { register(type, encoder, decoder, messageConsumer); } @Deprecated + @ApiStatus.ScheduledForRemoval(inVersion = "1.6") public void register(Optional side, Class type, BiConsumer encoder, Function decoder, BiConsumer> messageConsumer) { register(type, encoder, decoder, messageConsumer); } @@ -90,16 +92,19 @@ public final class NetworkChannel { } @Deprecated + @ApiStatus.ScheduledForRemoval(inVersion = "1.6") public void register(int id, Class type, BiConsumer encoder, Function decoder, BiConsumer> messageConsumer) { register(type, encoder, decoder, messageConsumer); } @Deprecated + @ApiStatus.ScheduledForRemoval(inVersion = "1.6") public void register(NetworkManager.Side side, int id, Class type, BiConsumer encoder, Function decoder, BiConsumer> messageConsumer) { register(type, encoder, decoder, messageConsumer); } @Deprecated + @ApiStatus.ScheduledForRemoval(inVersion = "1.6") public void register(Optional side, int id, Class type, BiConsumer encoder, Function decoder, BiConsumer> messageConsumer) { register(type, encoder, decoder, messageConsumer); } From 54650b3e2e62c0293b6d234d242a053cd5bd4c6c Mon Sep 17 00:00:00 2001 From: Max Date: Thu, 11 Feb 2021 19:11:47 +0100 Subject: [PATCH 02/44] Mark old @ExpectPlatform for removal (2.0) --- .../main/java/me/shedaniel/architectury/ExpectPlatform.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/common/src/main/java/me/shedaniel/architectury/ExpectPlatform.java b/common/src/main/java/me/shedaniel/architectury/ExpectPlatform.java index 5e19c317..0cb81338 100644 --- a/common/src/main/java/me/shedaniel/architectury/ExpectPlatform.java +++ b/common/src/main/java/me/shedaniel/architectury/ExpectPlatform.java @@ -19,6 +19,8 @@ package me.shedaniel.architectury; +import org.jetbrains.annotations.ApiStatus; + import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -30,5 +32,6 @@ import java.lang.annotation.Target; @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) @Deprecated +@ApiStatus.ScheduledForRemoval(inVersion = "2.0") public @interface ExpectPlatform { -} \ No newline at end of file +} From 2d1a9791f66f91ff2aa7bad2707a67e6018a7ec6 Mon Sep 17 00:00:00 2001 From: Max Date: Thu, 11 Feb 2021 19:10:57 +0100 Subject: [PATCH 03/44] Remove collisions from packet ids --- .../architectury/networking/NetworkChannel.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/common/src/main/java/me/shedaniel/architectury/networking/NetworkChannel.java b/common/src/main/java/me/shedaniel/architectury/networking/NetworkChannel.java index 101db7ff..249fab01 100644 --- a/common/src/main/java/me/shedaniel/architectury/networking/NetworkChannel.java +++ b/common/src/main/java/me/shedaniel/architectury/networking/NetworkChannel.java @@ -34,9 +34,11 @@ import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerPlayer; import org.jetbrains.annotations.ApiStatus; +import java.nio.charset.StandardCharsets; import java.util.Map; import java.util.Objects; import java.util.Optional; +import java.util.UUID; import java.util.function.BiConsumer; import java.util.function.Function; import java.util.function.Supplier; @@ -69,16 +71,16 @@ public final class NetworkChannel { } public void register(Class type, BiConsumer encoder, Function decoder, BiConsumer> messageConsumer) { - String s = StringUtils.leftPad(String.valueOf(hashCodeString(type.toString())), 10, '0'); - if (s.length() > 10) s = s.substring(0, 10); - MessageInfo info = new MessageInfo<>(new ResourceLocation(id + "_" + s), encoder, decoder, messageConsumer); + // TODO: this is pretty wasteful; add a way to specify custom or numeric ids + String s = UUID.nameUUIDFromBytes(type.getName().getBytes(StandardCharsets.UTF_8)).toString().replace("-", ""); + MessageInfo info = new MessageInfo<>(new ResourceLocation(id + "/" + s), encoder, decoder, messageConsumer); encoders.put(type, info); NetworkManager.NetworkReceiver receiver = (buf, context) -> { info.messageConsumer.accept(info.decoder.apply(buf), () -> context); }; - NetworkManager.registerReceiver(NetworkManager.clientToServer(), info.packetId, receiver); + NetworkManager.registerReceiver(NetworkManager.c2s(), info.packetId, receiver); if (Platform.getEnvironment() == Env.CLIENT) { - NetworkManager.registerReceiver(NetworkManager.serverToClient(), info.packetId, receiver); + NetworkManager.registerReceiver(NetworkManager.s2c(), info.packetId, receiver); } } From 35dfe7ccbcc0ca96ef82612096f28e8c2f272158 Mon Sep 17 00:00:00 2001 From: Max Date: Sun, 14 Feb 2021 17:37:30 +0100 Subject: [PATCH 04/44] [ci skip] Migrate to shedmaven --- settings.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle b/settings.gradle index b1c39389..2d1ff5a9 100644 --- a/settings.gradle +++ b/settings.gradle @@ -2,7 +2,7 @@ pluginManagement { repositories { jcenter() maven { url "https://maven.fabricmc.net/" } - maven { url "https://dl.bintray.com/shedaniel/cloth" } + maven { url "https://maven.shedaniel.me" } maven { url "https://files.minecraftforge.net/maven/" } gradlePluginPortal() } From b78cce58eec14c8004df624d6739a6813d9b993a Mon Sep 17 00:00:00 2001 From: Max Date: Mon, 15 Feb 2021 18:15:03 +0100 Subject: [PATCH 05/44] Add LightningEvent, FallingBlock land, move break/place to BlockEvent --- .../architectury/event/EventHandler.java | 11 +++++ .../architectury/event/events/BlockEvent.java | 44 +++++++++++++++++++ .../event/events/EntityEvent.java | 7 +++ .../event/events/LightningEvent.java | 26 +++++++++++ .../event/events/PlayerEvent.java | 7 +++ .../architectury/mixin/MixinFallingBlock.java | 29 ++++++++++++ .../mixin/MixinLightningBolt.java | 39 ++++++++++++++++ .../resources/architectury-common.mixins.json | 16 +++++++ .../mixin/fabric/MixinBlockItem.java | 6 +-- .../fabric/MixinServerPlayerGameMode.java | 4 +- fabric/src/main/resources/fabric.mod.json | 3 +- forge/build.gradle | 2 +- .../event/forge/EventHandlerImplCommon.java | 11 ++--- .../architectury/test/events/DebugEvents.java | 16 +++---- 14 files changed, 201 insertions(+), 20 deletions(-) create mode 100644 common/src/main/java/me/shedaniel/architectury/event/events/BlockEvent.java create mode 100644 common/src/main/java/me/shedaniel/architectury/event/events/LightningEvent.java create mode 100644 common/src/main/java/me/shedaniel/architectury/mixin/MixinFallingBlock.java create mode 100644 common/src/main/java/me/shedaniel/architectury/mixin/MixinLightningBolt.java create mode 100644 common/src/main/resources/architectury-common.mixins.json diff --git a/common/src/main/java/me/shedaniel/architectury/event/EventHandler.java b/common/src/main/java/me/shedaniel/architectury/event/EventHandler.java index 8c53ace2..339f005a 100644 --- a/common/src/main/java/me/shedaniel/architectury/event/EventHandler.java +++ b/common/src/main/java/me/shedaniel/architectury/event/EventHandler.java @@ -20,6 +20,9 @@ package me.shedaniel.architectury.event; import me.shedaniel.architectury.annotations.ExpectPlatform; +import me.shedaniel.architectury.event.events.BlockEvent; +import me.shedaniel.architectury.event.events.EntityEvent; +import me.shedaniel.architectury.event.events.PlayerEvent; import me.shedaniel.architectury.platform.Platform; import me.shedaniel.architectury.utils.Env; import net.fabricmc.api.EnvType; @@ -38,6 +41,8 @@ public final class EventHandler { registerCommon(); if (Platform.getEnvironment() == Env.SERVER) registerServer(); + + registerDelegates(); } @ExpectPlatform @@ -56,4 +61,10 @@ public final class EventHandler { private static void registerServer() { throw new AssertionError(); } + + @SuppressWarnings("deprecation") + private static void registerDelegates() { + BlockEvent.PLACE.register((EntityEvent.PLACE_BLOCK.invoker()::placeBlock)); + BlockEvent.BREAK.register((PlayerEvent.BREAK_BLOCK.invoker()::breakBlock)); + } } diff --git a/common/src/main/java/me/shedaniel/architectury/event/events/BlockEvent.java b/common/src/main/java/me/shedaniel/architectury/event/events/BlockEvent.java new file mode 100644 index 00000000..484b9ea9 --- /dev/null +++ b/common/src/main/java/me/shedaniel/architectury/event/events/BlockEvent.java @@ -0,0 +1,44 @@ +package me.shedaniel.architectury.event.events; + +import me.shedaniel.architectury.event.Event; +import me.shedaniel.architectury.event.EventFactory; +import me.shedaniel.architectury.utils.IntValue; +import net.minecraft.core.BlockPos; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.item.FallingBlockEntity; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.state.BlockState; +import org.jetbrains.annotations.Nullable; + +public interface BlockEvent { + + // Block interaction events + /** + * Called when a player breaks a block. + */ + Event BREAK = EventFactory.createInteractionResult(); + /** + * Called when a block is placed in the world by an entity. + */ + Event PLACE = EventFactory.createInteractionResult(); + + /** + * Called when a falling block (sand, anvil, etc.) is about to land. + * Use fallState#getBlock to get the type of block for more granular control. + */ + Event FALLING_LAND = EventFactory.createLoop(); + + interface Break { + InteractionResult breakBlock(Level world, BlockPos pos, BlockState state, ServerPlayer player, @Nullable IntValue xp); + } + + interface Place { + InteractionResult placeBlock(Level world, BlockPos pos, BlockState state, @Nullable Entity placer); + } + + interface FallingLand { + void onLand(Level level, BlockPos pos, BlockState fallState, BlockState landOn, FallingBlockEntity entity); + } +} diff --git a/common/src/main/java/me/shedaniel/architectury/event/events/EntityEvent.java b/common/src/main/java/me/shedaniel/architectury/event/events/EntityEvent.java index 82b5c629..9bafe120 100644 --- a/common/src/main/java/me/shedaniel/architectury/event/events/EntityEvent.java +++ b/common/src/main/java/me/shedaniel/architectury/event/events/EntityEvent.java @@ -28,6 +28,7 @@ import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.state.BlockState; +import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; public interface EntityEvent { @@ -43,6 +44,12 @@ public interface EntityEvent { * Invoked before entity is added to a world, equivalent to forge's {@code EntityJoinWorldEvent}. */ Event ADD = EventFactory.createInteractionResult(); + + /** + * @deprecated use {@link BlockEvent#PLACE} + */ + @Deprecated + @ApiStatus.ScheduledForRemoval(inVersion = "2.0") Event PLACE_BLOCK = EventFactory.createInteractionResult(); interface LivingDeath { diff --git a/common/src/main/java/me/shedaniel/architectury/event/events/LightningEvent.java b/common/src/main/java/me/shedaniel/architectury/event/events/LightningEvent.java new file mode 100644 index 00000000..034db226 --- /dev/null +++ b/common/src/main/java/me/shedaniel/architectury/event/events/LightningEvent.java @@ -0,0 +1,26 @@ +package me.shedaniel.architectury.event.events; + +import me.shedaniel.architectury.event.Event; +import me.shedaniel.architectury.event.EventFactory; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.LightningBolt; +import net.minecraft.world.level.Level; +import net.minecraft.world.phys.Vec3; + +import java.util.List; + +public interface LightningEvent { + + // TODO Pre - Called before a lightning bolt entity is added to the world. (cancellable) + /** + * Invoked after the lightning has gathered a list of entities to strike. + * Remove entities from the list to stop them from being hit. + */ + Event STRIKE = EventFactory.createLoop(); + // TODO Post - Called before a lightning bolt entity is removed from the world. + + interface Strike { + void onStrike(LightningBolt bolt, Level level, Vec3 pos, List toStrike); + } + +} diff --git a/common/src/main/java/me/shedaniel/architectury/event/events/PlayerEvent.java b/common/src/main/java/me/shedaniel/architectury/event/events/PlayerEvent.java index 451bf92d..b86aae90 100644 --- a/common/src/main/java/me/shedaniel/architectury/event/events/PlayerEvent.java +++ b/common/src/main/java/me/shedaniel/architectury/event/events/PlayerEvent.java @@ -34,6 +34,7 @@ import net.minecraft.world.inventory.AbstractContainerMenu; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.state.BlockState; +import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; public interface PlayerEvent { @@ -50,6 +51,12 @@ public interface PlayerEvent { Event DROP_ITEM = EventFactory.createLoop(); Event OPEN_MENU = EventFactory.createLoop(); Event CLOSE_MENU = EventFactory.createLoop(); + + /** + * @deprecated use {@link BlockEvent#BREAK} + */ + @Deprecated + @ApiStatus.ScheduledForRemoval(inVersion = "2.0") Event BREAK_BLOCK = EventFactory.createInteractionResult(); interface PlayerJoin { diff --git a/common/src/main/java/me/shedaniel/architectury/mixin/MixinFallingBlock.java b/common/src/main/java/me/shedaniel/architectury/mixin/MixinFallingBlock.java new file mode 100644 index 00000000..db2f3cb4 --- /dev/null +++ b/common/src/main/java/me/shedaniel/architectury/mixin/MixinFallingBlock.java @@ -0,0 +1,29 @@ +package me.shedaniel.architectury.mixin; + +import me.shedaniel.architectury.event.events.BlockEvent; +import net.minecraft.core.BlockPos; +import net.minecraft.world.entity.item.FallingBlockEntity; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.FallingBlock; +import net.minecraft.world.level.block.state.BlockState; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.LocalCapture; + +@Mixin(FallingBlock.class) +public abstract class MixinFallingBlock extends Block { + + public MixinFallingBlock(Properties properties) { + super(properties); + throw new IllegalStateException(); + } + + @Inject(method = "onLand", at = @At("RETURN"), locals = LocalCapture.CAPTURE_FAILHARD) + public void handleLand(Level level, BlockPos pos, BlockState fallState, BlockState landOn, FallingBlockEntity entity, CallbackInfo ci) { + BlockEvent.FALLING_LAND.invoker().onLand(level, pos, fallState, landOn, entity); + } + +} diff --git a/common/src/main/java/me/shedaniel/architectury/mixin/MixinLightningBolt.java b/common/src/main/java/me/shedaniel/architectury/mixin/MixinLightningBolt.java new file mode 100644 index 00000000..b2743063 --- /dev/null +++ b/common/src/main/java/me/shedaniel/architectury/mixin/MixinLightningBolt.java @@ -0,0 +1,39 @@ +package me.shedaniel.architectury.mixin; + +import me.shedaniel.architectury.event.events.LightningEvent; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.LightningBolt; +import net.minecraft.world.level.Level; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.LocalCapture; + +import java.util.List; + +@Mixin(LightningBolt.class) +public abstract class MixinLightningBolt extends Entity { + + public MixinLightningBolt(EntityType type, Level level) { + super(type, level); + throw new IllegalStateException(); + } + + @Inject(method = "tick", at = @At( + value = "INVOKE_ASSIGN", + target = "Lnet/minecraft/world/level/Level;getEntities(Lnet/minecraft/world/entity/Entity;Lnet/minecraft/world/phys/AABB;Ljava/util/function/Predicate;)Ljava/util/List;", + ordinal = 0, + shift = At.Shift.BY, + by = 1 + ), locals = LocalCapture.CAPTURE_FAILHARD) + public void handleLightning(CallbackInfo ci, double d0, List list) { + if (this.removed || this.level.isClientSide) { + return; + } + + LightningEvent.STRIKE.invoker().onStrike((LightningBolt) (Object) this, this.level, this.position(), list); + } + +} diff --git a/common/src/main/resources/architectury-common.mixins.json b/common/src/main/resources/architectury-common.mixins.json new file mode 100644 index 00000000..eeee889c --- /dev/null +++ b/common/src/main/resources/architectury-common.mixins.json @@ -0,0 +1,16 @@ +{ + "required": true, + "package": "me.shedaniel.architectury.mixin", + "compatibilityLevel": "JAVA_8", + "minVersion": "0.7.11", + "client": [ + ], + "mixins": [ + "MixinFallingBlock", + "MixinLightningBolt" + ], + "injectors": { + "maxShiftBy": 5, + "defaultRequire": 1 + } +} diff --git a/fabric/src/main/java/me/shedaniel/architectury/mixin/fabric/MixinBlockItem.java b/fabric/src/main/java/me/shedaniel/architectury/mixin/fabric/MixinBlockItem.java index 7634ef14..73fb715f 100644 --- a/fabric/src/main/java/me/shedaniel/architectury/mixin/fabric/MixinBlockItem.java +++ b/fabric/src/main/java/me/shedaniel/architectury/mixin/fabric/MixinBlockItem.java @@ -19,7 +19,7 @@ package me.shedaniel.architectury.mixin.fabric; -import me.shedaniel.architectury.event.events.EntityEvent; +import me.shedaniel.architectury.event.events.BlockEvent; import net.minecraft.world.InteractionResult; import net.minecraft.world.item.BlockItem; import net.minecraft.world.item.context.BlockPlaceContext; @@ -35,9 +35,9 @@ public abstract class MixinBlockItem { target = "Lnet/minecraft/world/item/context/BlockPlaceContext;getClickedPos()Lnet/minecraft/core/BlockPos;"), cancellable = true) private void place(BlockPlaceContext context, CallbackInfoReturnable cir) { - InteractionResult result = EntityEvent.PLACE_BLOCK.invoker().placeBlock(context.getLevel(), context.getClickedPos(), context.getLevel().getBlockState(context.getClickedPos()), context.getPlayer()); + InteractionResult result = BlockEvent.PLACE.invoker().placeBlock(context.getLevel(), context.getClickedPos(), context.getLevel().getBlockState(context.getClickedPos()), context.getPlayer()); if (result != InteractionResult.PASS) { cir.setReturnValue(result); } } -} \ No newline at end of file +} diff --git a/fabric/src/main/java/me/shedaniel/architectury/mixin/fabric/MixinServerPlayerGameMode.java b/fabric/src/main/java/me/shedaniel/architectury/mixin/fabric/MixinServerPlayerGameMode.java index c85b7a3f..57a0f97a 100644 --- a/fabric/src/main/java/me/shedaniel/architectury/mixin/fabric/MixinServerPlayerGameMode.java +++ b/fabric/src/main/java/me/shedaniel/architectury/mixin/fabric/MixinServerPlayerGameMode.java @@ -19,7 +19,7 @@ package me.shedaniel.architectury.mixin.fabric; -import me.shedaniel.architectury.event.events.PlayerEvent; +import me.shedaniel.architectury.event.events.BlockEvent; import net.minecraft.core.BlockPos; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; @@ -44,7 +44,7 @@ public class MixinServerPlayerGameMode { ordinal = 0), locals = LocalCapture.CAPTURE_FAILHARD, cancellable = true) private void onBreak(BlockPos blockPos, CallbackInfoReturnable cir, BlockState state) { - if (PlayerEvent.BREAK_BLOCK.invoker().breakBlock(this.level, blockPos, state, this.player, null) == InteractionResult.FAIL) { + if (BlockEvent.BREAK.invoker().breakBlock(this.level, blockPos, state, this.player, null) == InteractionResult.FAIL) { cir.setReturnValue(false); } } diff --git a/fabric/src/main/resources/fabric.mod.json b/fabric/src/main/resources/fabric.mod.json index e4476b10..13ff4d36 100644 --- a/fabric/src/main/resources/fabric.mod.json +++ b/fabric/src/main/resources/fabric.mod.json @@ -10,6 +10,7 @@ "license": "LGPL-3", "environment": "*", "mixins": [ + "architectury-common.mixins.json", "architectury.mixins.json" ], "entrypoints": { @@ -30,4 +31,4 @@ "custom": { "modmenu:api": true } -} \ No newline at end of file +} diff --git a/forge/build.gradle b/forge/build.gradle index 4b219c52..af9fcdd8 100644 --- a/forge/build.gradle +++ b/forge/build.gradle @@ -4,7 +4,7 @@ plugins { } loom { - mixinConfig = "architectury.mixins.json" + mixinConfigs = ["architectury.mixins.json", "architectury-common.mixins.json"] } configurations { diff --git a/forge/src/main/java/me/shedaniel/architectury/event/forge/EventHandlerImplCommon.java b/forge/src/main/java/me/shedaniel/architectury/event/forge/EventHandlerImplCommon.java index 72309483..33c3c019 100644 --- a/forge/src/main/java/me/shedaniel/architectury/event/forge/EventHandlerImplCommon.java +++ b/forge/src/main/java/me/shedaniel/architectury/event/forge/EventHandlerImplCommon.java @@ -44,7 +44,8 @@ import net.minecraftforge.event.entity.player.EntityItemPickupEvent; import net.minecraftforge.event.entity.player.PlayerContainerEvent; import net.minecraftforge.event.entity.player.PlayerEvent.*; import net.minecraftforge.event.entity.player.PlayerInteractEvent; -import net.minecraftforge.event.world.BlockEvent; +import net.minecraftforge.event.world.BlockEvent.BreakEvent; +import net.minecraftforge.event.world.BlockEvent.EntityPlaceEvent; import net.minecraftforge.event.world.ExplosionEvent.Detonate; import net.minecraftforge.event.world.ExplosionEvent.Start; import net.minecraftforge.event.world.WorldEvent; @@ -288,9 +289,9 @@ public class EventHandlerImplCommon { } @SubscribeEvent - public static void event(BlockEvent.BreakEvent event) { + public static void event(BreakEvent event) { if (event.getPlayer() instanceof ServerPlayer && event.getWorld() instanceof Level) { - InteractionResult result = PlayerEvent.BREAK_BLOCK.invoker().breakBlock((Level) event.getWorld(), event.getPos(), event.getState(), (ServerPlayer) event.getPlayer(), new IntValue() { + InteractionResult result = BlockEvent.BREAK.invoker().breakBlock((Level) event.getWorld(), event.getPos(), event.getState(), (ServerPlayer) event.getPlayer(), new IntValue() { @Override public int getAsInt() { return event.getExpToDrop(); @@ -308,9 +309,9 @@ public class EventHandlerImplCommon { } @SubscribeEvent - public static void event(BlockEvent.EntityPlaceEvent event) { + public static void event(EntityPlaceEvent event) { if (event.getWorld() instanceof Level) { - InteractionResult result = EntityEvent.PLACE_BLOCK.invoker().placeBlock((Level) event.getWorld(), event.getPos(), event.getState(), event.getEntity()); + InteractionResult result = BlockEvent.PLACE.invoker().placeBlock((Level) event.getWorld(), event.getPos(), event.getState(), event.getEntity()); if (result != InteractionResult.PASS) { event.setCanceled(true); } diff --git a/testmod-common/src/main/java/me/shedaniel/architectury/test/events/DebugEvents.java b/testmod-common/src/main/java/me/shedaniel/architectury/test/events/DebugEvents.java index 31bd02a9..752c1c07 100644 --- a/testmod-common/src/main/java/me/shedaniel/architectury/test/events/DebugEvents.java +++ b/testmod-common/src/main/java/me/shedaniel/architectury/test/events/DebugEvents.java @@ -49,6 +49,14 @@ public class DebugEvents { } public static void debugEvents() { + BlockEvent.BREAK.register((world, pos, state, player, xp) -> { + SINK.accept(player.getScoreboardName() + " breaks " + toShortString(pos) + logSide(player.level)); + return InteractionResult.PASS; + }); + BlockEvent.PLACE.register((world, pos, state, placer) -> { + SINK.accept(Optional.ofNullable(placer).map(Entity::getScoreboardName).orElse("null") + " places block at " + toShortString(pos) + logSide(world)); + return InteractionResult.PASS; + }); ChatEvent.SERVER.register((player, message, component) -> { SINK.accept("Server chat received: " + message); return InteractionResultHolder.pass(component); @@ -78,10 +86,6 @@ public class DebugEvents { } return InteractionResult.PASS; }); - EntityEvent.PLACE_BLOCK.register((world, pos, state, placer) -> { - SINK.accept(Optional.ofNullable(placer).map(Entity::getScoreboardName).orElse("null") + " places block at " + toShortString(pos) + logSide(world)); - return InteractionResult.PASS; - }); ExplosionEvent.DETONATE.register((world, explosion, affectedEntities) -> { SINK.accept(world.dimension().location() + " explodes at " + toShortString(ExplosionHooks.getPosition(explosion)) + logSide(world)); }); @@ -155,10 +159,6 @@ public class DebugEvents { SINK.accept(player.getScoreboardName() + " drops " + new TranslatableComponent(entity.getItem().getDescriptionId()).getString() + logSide(player.level)); return InteractionResult.PASS; }); - PlayerEvent.BREAK_BLOCK.register((world, pos, state, player, xp) -> { - SINK.accept(player.getScoreboardName() + " breaks " + toShortString(pos) + logSide(player.level)); - return InteractionResult.PASS; - }); PlayerEvent.OPEN_MENU.register((player, menu) -> { SINK.accept(player.getScoreboardName() + " opens " + toSimpleName(menu) + logSide(player.level)); }); From 1918ec11320a3065a5d1d55c9cff94983ea2c7b6 Mon Sep 17 00:00:00 2001 From: Max Date: Mon, 15 Feb 2021 19:45:28 +0100 Subject: [PATCH 06/44] =?UTF-8?q?Delay=20the=20breakage=20of=20ALL=20THE?= =?UTF-8?q?=20THINGS=E2=84=A2=20until=201.17=20You're=20safe,=20NetworkCha?= =?UTF-8?q?nnel...=20for=20now?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../architectury/networking/NetworkChannel.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/common/src/main/java/me/shedaniel/architectury/networking/NetworkChannel.java b/common/src/main/java/me/shedaniel/architectury/networking/NetworkChannel.java index 249fab01..f49f227c 100644 --- a/common/src/main/java/me/shedaniel/architectury/networking/NetworkChannel.java +++ b/common/src/main/java/me/shedaniel/architectury/networking/NetworkChannel.java @@ -59,13 +59,13 @@ public final class NetworkChannel { } @Deprecated - @ApiStatus.ScheduledForRemoval(inVersion = "1.6") + @ApiStatus.ScheduledForRemoval(inVersion = "2.0") public void register(NetworkManager.Side side, Class type, BiConsumer encoder, Function decoder, BiConsumer> messageConsumer) { register(type, encoder, decoder, messageConsumer); } @Deprecated - @ApiStatus.ScheduledForRemoval(inVersion = "1.6") + @ApiStatus.ScheduledForRemoval(inVersion = "2.0") public void register(Optional side, Class type, BiConsumer encoder, Function decoder, BiConsumer> messageConsumer) { register(type, encoder, decoder, messageConsumer); } @@ -94,19 +94,19 @@ public final class NetworkChannel { } @Deprecated - @ApiStatus.ScheduledForRemoval(inVersion = "1.6") + @ApiStatus.ScheduledForRemoval(inVersion = "2.0") public void register(int id, Class type, BiConsumer encoder, Function decoder, BiConsumer> messageConsumer) { register(type, encoder, decoder, messageConsumer); } @Deprecated - @ApiStatus.ScheduledForRemoval(inVersion = "1.6") + @ApiStatus.ScheduledForRemoval(inVersion = "2.0") public void register(NetworkManager.Side side, int id, Class type, BiConsumer encoder, Function decoder, BiConsumer> messageConsumer) { register(type, encoder, decoder, messageConsumer); } @Deprecated - @ApiStatus.ScheduledForRemoval(inVersion = "1.6") + @ApiStatus.ScheduledForRemoval(inVersion = "2.0") public void register(Optional side, int id, Class type, BiConsumer encoder, Function decoder, BiConsumer> messageConsumer) { register(type, encoder, decoder, messageConsumer); } From 0ec068cc1eadaa3c6fc98680d0596808bd97e0d5 Mon Sep 17 00:00:00 2001 From: Max Date: Mon, 15 Feb 2021 19:50:19 +0100 Subject: [PATCH 07/44] Fix falling block land event to handle all (vanilla) blocks correctly (Modded blocks need to have super.onLand(...) and then they'll be fine too) --- ...nFallingBlock.java => BlockLandingInvoker.java} | 14 ++++---------- .../main/resources/architectury-common.mixins.json | 2 +- 2 files changed, 5 insertions(+), 11 deletions(-) rename common/src/main/java/me/shedaniel/architectury/mixin/{MixinFallingBlock.java => BlockLandingInvoker.java} (77%) diff --git a/common/src/main/java/me/shedaniel/architectury/mixin/MixinFallingBlock.java b/common/src/main/java/me/shedaniel/architectury/mixin/BlockLandingInvoker.java similarity index 77% rename from common/src/main/java/me/shedaniel/architectury/mixin/MixinFallingBlock.java rename to common/src/main/java/me/shedaniel/architectury/mixin/BlockLandingInvoker.java index db2f3cb4..aead19c7 100644 --- a/common/src/main/java/me/shedaniel/architectury/mixin/MixinFallingBlock.java +++ b/common/src/main/java/me/shedaniel/architectury/mixin/BlockLandingInvoker.java @@ -4,7 +4,8 @@ import me.shedaniel.architectury.event.events.BlockEvent; import net.minecraft.core.BlockPos; import net.minecraft.world.entity.item.FallingBlockEntity; import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.AnvilBlock; +import net.minecraft.world.level.block.ConcretePowderBlock; import net.minecraft.world.level.block.FallingBlock; import net.minecraft.world.level.block.state.BlockState; import org.spongepowered.asm.mixin.Mixin; @@ -13,17 +14,10 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.LocalCapture; -@Mixin(FallingBlock.class) -public abstract class MixinFallingBlock extends Block { - - public MixinFallingBlock(Properties properties) { - super(properties); - throw new IllegalStateException(); - } - +@Mixin({FallingBlock.class, AnvilBlock.class, ConcretePowderBlock.class}) +public abstract class BlockLandingInvoker { @Inject(method = "onLand", at = @At("RETURN"), locals = LocalCapture.CAPTURE_FAILHARD) public void handleLand(Level level, BlockPos pos, BlockState fallState, BlockState landOn, FallingBlockEntity entity, CallbackInfo ci) { BlockEvent.FALLING_LAND.invoker().onLand(level, pos, fallState, landOn, entity); } - } diff --git a/common/src/main/resources/architectury-common.mixins.json b/common/src/main/resources/architectury-common.mixins.json index eeee889c..f7f31de0 100644 --- a/common/src/main/resources/architectury-common.mixins.json +++ b/common/src/main/resources/architectury-common.mixins.json @@ -6,7 +6,7 @@ "client": [ ], "mixins": [ - "MixinFallingBlock", + "BlockLandingInvoker", "MixinLightningBolt" ], "injectors": { From cd9c1926a90b902eccfd632e695a6b1a7d45ab30 Mon Sep 17 00:00:00 2001 From: Max Date: Mon, 15 Feb 2021 19:50:49 +0100 Subject: [PATCH 08/44] (Retroactively) bump version to 1.6 --- gradle.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gradle.properties b/gradle.properties index dd9b88ff..ef0b40af 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,11 +6,11 @@ supported_version=1.16.4/5 archives_base_name=architectury archives_base_name_snapshot=architectury-snapshot -base_version=1.5 +base_version=1.6 maven_group=me.shedaniel fabric_loader_version=0.10.8 fabric_api_version=0.29.3+1.16 mod_menu_version=1.14.6+ -forge_version=35.1.36 \ No newline at end of file +forge_version=35.1.36 From 2656e522219a0a2b8ff742cfb29ae9ef9a7e8cc6 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Wed, 17 Feb 2021 14:51:31 +0800 Subject: [PATCH 09/44] Publish the platform specific jars on a different artifact id to resolve issues with transitive dependencies. --- fabric/build.gradle | 3 ++- forge/build.gradle | 3 ++- gradle.properties | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/fabric/build.gradle b/fabric/build.gradle index 8c1f49a6..d9bf440a 100644 --- a/fabric/build.gradle +++ b/fabric/build.gradle @@ -68,9 +68,10 @@ remapJar { publishing { publications { mavenFabric(MavenPublication) { + artifactId = rootProject.archives_base_name + "-fabric" artifact(remapJar.archivePath) { builtBy build - classifier "fabric" + classifier null } } } diff --git a/forge/build.gradle b/forge/build.gradle index af9fcdd8..4f2dbe69 100644 --- a/forge/build.gradle +++ b/forge/build.gradle @@ -63,9 +63,10 @@ remapJar { publishing { publications { mavenForge(MavenPublication) { + artifactId = rootProject.archives_base_name + "-fabric" artifact(remapJar.archivePath) { builtBy build - classifier "forge" + classifier null } } } diff --git a/gradle.properties b/gradle.properties index ef0b40af..401abfbd 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,7 +6,7 @@ supported_version=1.16.4/5 archives_base_name=architectury archives_base_name_snapshot=architectury-snapshot -base_version=1.6 +base_version=1.7 maven_group=me.shedaniel fabric_loader_version=0.10.8 From 0c705fa3bae590955547690314bf121a26025e3e Mon Sep 17 00:00:00 2001 From: shedaniel Date: Thu, 18 Feb 2021 14:55:55 +0800 Subject: [PATCH 10/44] Update README.md --- README.md | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 9d536685..0ce54cff 100644 --- a/README.md +++ b/README.md @@ -1,21 +1,26 @@ -# Architectury +# Architectury API Talk to us on [Discord](https://discord.gg/C2RdJDpRBP)! An intermediary api aimed to ease developing multiplatform mods. -### What is Architectury -Architectury is an api to abstract calls to fabric api and forge api as both loader has different implementations of what can be perceived as the same thing. +### What is Architectury API +Architectury API is an api to abstract calls to fabric api and forge api as both loader has different implementations of what can be perceived as the same thing. -Architectury updates regularly, with new hooks and features. Currently contains over **60** events hooks, networking abstraction, loader calls abstraction, game registry abstraction and an easy to use @ExpectPlatform annotation (Only works on static methods). +Architectury API updates regularly, with new hooks and features. Currently contains over **90** events hooks, networking abstraction, loader calls abstraction, game registry abstraction and an easy to use @ExpectPlatform annotation (Only works on static methods). + +### Do I really need this API? +Architectury API is only one part of the architectury ecosystem, **Architectury Plugin** is the gradle plugin enabling all this multiplatform actions. + +Architectury API is optional for projects built on architectury, you may create your architectury project with just Architectury Plugin. ### Advantages of Architectury - Open sourced - Less boilerplate for your multiplatform mod ### Getting started with making multiplatform mods -Gradle Plugin: https://github.com/architectury/architect-plugin +Gradle Plugin: https://github.com/architectury/architectury-plugin -Example Mod: https://github.com/architectury/architect-example-mod +Example Mod: https://github.com/architectury/architectury-example-mod ### Credits This library bundles typetools, which you can find its license [here](https://github.com/jhalterman/typetools/blob/master/LICENSE.txt "") From 78043a3109cb14fa3b668438ab42e68478740bcb Mon Sep 17 00:00:00 2001 From: shedaniel Date: Fri, 19 Feb 2021 02:11:13 +0800 Subject: [PATCH 11/44] Migrate to Arch Plugin 3 --- build.gradle | 4 ++-- fabric/build.gradle | 5 +++-- forge/build.gradle | 5 +++-- gradle.properties | 8 ++++---- testmod-fabric/build.gradle | 9 +++++---- testmod-forge/build.gradle | 11 ++++++----- 6 files changed, 23 insertions(+), 19 deletions(-) diff --git a/build.gradle b/build.gradle index 4fcac77a..13e5f950 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,6 @@ plugins { - id "architectury-plugin" version "2.0.65" - id "forgified-fabric-loom" version "0.6.54" apply false + id "architectury-plugin" version "3.0.79" + id "forgified-fabric-loom" version "0.6.67" apply false id "org.cadixdev.licenser" version "0.5.0" id "com.matthewprenger.cursegradle" version "1.4.0" apply false id "maven-publish" diff --git a/fabric/build.gradle b/fabric/build.gradle index d9bf440a..71b9f0df 100644 --- a/fabric/build.gradle +++ b/fabric/build.gradle @@ -24,6 +24,7 @@ artifacts { architectury { platformSetupLoomIde() + fabric() } dependencies { @@ -35,10 +36,10 @@ dependencies { implementation "net.jodah:typetools:0.6.2" shadow "net.jodah:typetools:0.6.2" - compileOnly(project(path: ":common")) { + implementation(project(path: ":common")) { transitive = false } - runtimeOnly(project(path: ":common", configuration: "transformDevelopmentFabric")) { + developmentFabric(project(path: ":common")) { transitive = false } shadow(project(path: ":common", configuration: "transformProductionFabric")) { diff --git a/forge/build.gradle b/forge/build.gradle index 4f2dbe69..4bab989a 100644 --- a/forge/build.gradle +++ b/forge/build.gradle @@ -18,6 +18,7 @@ artifacts { architectury { platformSetupLoomIde() + forge() } dependencies { @@ -27,10 +28,10 @@ dependencies { implementation "net.jodah:typetools:0.6.2" shadow "net.jodah:typetools:0.6.2" - compileOnly(project(path: ":common")) { + implementation(project(path: ":common")) { transitive = false } - runtimeOnly(project(path: ":common", configuration: "transformDevelopmentForge")) { + developmentForge(project(path: ":common")) { transitive = false } shadow(project(path: ":common", configuration: "transformProductionForge")) { diff --git a/gradle.properties b/gradle.properties index 401abfbd..53290270 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,7 +1,7 @@ org.gradle.jvmargs=-Xmx3G org.gradle.daemon=false -minecraft_version=1.16.4 +minecraft_version=1.16.5 supported_version=1.16.4/5 archives_base_name=architectury @@ -9,8 +9,8 @@ archives_base_name_snapshot=architectury-snapshot base_version=1.7 maven_group=me.shedaniel -fabric_loader_version=0.10.8 -fabric_api_version=0.29.3+1.16 +fabric_loader_version=0.11.1 +fabric_api_version=0.30.3+1.16 mod_menu_version=1.14.6+ -forge_version=35.1.36 +forge_version=36.0.42 diff --git a/testmod-fabric/build.gradle b/testmod-fabric/build.gradle index 88aa6105..13a31909 100644 --- a/testmod-fabric/build.gradle +++ b/testmod-fabric/build.gradle @@ -5,6 +5,7 @@ plugins { architectury { platformSetupLoomIde() + fabric() } dependencies { @@ -15,16 +16,16 @@ dependencies { modCompileOnly "io.github.prospector:modmenu:${rootProject.mod_menu_version}" implementation project(path: ":fabric", configuration: "dev") - compileOnly(project(path: ":common")) { + implementation(project(path: ":common")) { transitive = false } - runtimeOnly(project(path: ":common", configuration: "transformDevelopmentFabric")) { + developmentFabric(project(path: ":common")) { transitive = false } - compileOnly(project(path: ":testmod-common")) { + implementation(project(path: ":testmod-common")) { transitive = false } - runtimeOnly(project(path: ":testmod-common", configuration: "transformDevelopmentFabric")) { + developmentFabric(project(path: ":testmod-common")) { transitive = false } } diff --git a/testmod-forge/build.gradle b/testmod-forge/build.gradle index 7008ff10..b8eb8568 100644 --- a/testmod-forge/build.gradle +++ b/testmod-forge/build.gradle @@ -4,7 +4,7 @@ plugins { } loom { - mixinConfig = "architectury.mixins.json" + mixinConfig "architectury.mixins.json" localMods { it.add(project(":forge").sourceSets.main) @@ -13,6 +13,7 @@ loom { architectury { platformSetupLoomIde() + forge() } dependencies { @@ -21,16 +22,16 @@ dependencies { forge "net.minecraftforge:forge:${gradle.rootProject.architectury.minecraft}-${rootProject.forge_version}" implementation project(path: ":forge", configuration: "dev") - compileOnly(project(path: ":common")) { + implementation(project(path: ":common")) { transitive = false } - runtimeOnly(project(path: ":common", configuration: "transformDevelopmentForge")) { + developmentForge(project(path: ":common")) { transitive = false } - compileOnly(project(path: ":testmod-common")) { + implementation(project(path: ":testmod-common")) { transitive = false } - runtimeOnly(project(path: ":testmod-common", configuration: "transformDevelopmentForge")) { + developmentForge(project(path: ":testmod-common")) { transitive = false } } From 5613937011735b206710c34c76eb628baad56842 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Fri, 19 Feb 2021 02:19:38 +0800 Subject: [PATCH 12/44] Fix forge publishing as fabric --- forge/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/forge/build.gradle b/forge/build.gradle index 4bab989a..49a7ddfe 100644 --- a/forge/build.gradle +++ b/forge/build.gradle @@ -64,7 +64,7 @@ remapJar { publishing { publications { mavenForge(MavenPublication) { - artifactId = rootProject.archives_base_name + "-fabric" + artifactId = rootProject.archives_base_name + "-forge" artifact(remapJar.archivePath) { builtBy build classifier null From 7e743dcb640418a32410b5892cc88b31d498ef55 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Tue, 23 Feb 2021 00:16:26 +0800 Subject: [PATCH 13/44] Add licenses and implement optional tags, requires some testing. --- build.gradle | 4 +- common/build.gradle | 11 ---- .../architectury/event/events/BlockEvent.java | 19 ++++++ .../event/events/LightningEvent.java | 19 ++++++ .../architectury/hooks/TagHooks.java | 56 +++++++++++++++++ .../mixin/BlockLandingInvoker.java | 19 ++++++ .../architectury/mixin/FluidTagsAccessor.java | 34 ++++++++++ .../mixin/MixinLightningBolt.java | 19 ++++++ .../resources/architectury-common.mixins.json | 25 ++++---- fabric/build.gradle | 6 -- .../hooks/fabric/TagHooksImpl.java | 33 ++++++++++ .../fabric/ArchitecturyMixinPlugin.java | 19 ++++++ .../mixin/forge/TagHooksImpl.java | 63 +++++++++++++++++++ 13 files changed, 294 insertions(+), 33 deletions(-) create mode 100644 common/src/main/java/me/shedaniel/architectury/hooks/TagHooks.java create mode 100644 common/src/main/java/me/shedaniel/architectury/mixin/FluidTagsAccessor.java create mode 100644 fabric/src/main/java/me/shedaniel/architectury/hooks/fabric/TagHooksImpl.java create mode 100644 forge/src/main/java/me/shedaniel/architectury/mixin/forge/TagHooksImpl.java diff --git a/build.gradle b/build.gradle index 13e5f950..6814500c 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,6 @@ plugins { - id "architectury-plugin" version "3.0.79" - id "forgified-fabric-loom" version "0.6.67" apply false + id "architectury-plugin" version "3.0.85" + id "forgified-fabric-loom" version "0.6.70" apply false id "org.cadixdev.licenser" version "0.5.0" id "com.matthewprenger.cursegradle" version "1.4.0" apply false id "maven-publish" diff --git a/common/build.gradle b/common/build.gradle index 6afb50d7..85ea3d18 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -20,16 +20,6 @@ task sourcesJar(type: Jar, dependsOn: classes) { from sourceSets.main.allSource } -task javadocs(type: Javadoc) { - source = sourceSets.main.allJava -} - -task javadocsJar(type: Jar, dependsOn: javadocs) { - archiveClassifier.set("javadocs") - javadocs.failOnError false - from javadocs.destinationDir -} - publishing { publications { mavenCommon(MavenPublication) { @@ -39,7 +29,6 @@ publishing { artifact(sourcesJar) { builtBy remapSourcesJar } - artifact javadocsJar } } diff --git a/common/src/main/java/me/shedaniel/architectury/event/events/BlockEvent.java b/common/src/main/java/me/shedaniel/architectury/event/events/BlockEvent.java index 484b9ea9..4c783f1b 100644 --- a/common/src/main/java/me/shedaniel/architectury/event/events/BlockEvent.java +++ b/common/src/main/java/me/shedaniel/architectury/event/events/BlockEvent.java @@ -1,3 +1,22 @@ +/* + * This file is part of architectury. + * Copyright (C) 2020, 2021 shedaniel + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + package me.shedaniel.architectury.event.events; import me.shedaniel.architectury.event.Event; diff --git a/common/src/main/java/me/shedaniel/architectury/event/events/LightningEvent.java b/common/src/main/java/me/shedaniel/architectury/event/events/LightningEvent.java index 034db226..f1fac890 100644 --- a/common/src/main/java/me/shedaniel/architectury/event/events/LightningEvent.java +++ b/common/src/main/java/me/shedaniel/architectury/event/events/LightningEvent.java @@ -1,3 +1,22 @@ +/* + * This file is part of architectury. + * Copyright (C) 2020, 2021 shedaniel + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + package me.shedaniel.architectury.event.events; import me.shedaniel.architectury.event.Event; diff --git a/common/src/main/java/me/shedaniel/architectury/hooks/TagHooks.java b/common/src/main/java/me/shedaniel/architectury/hooks/TagHooks.java new file mode 100644 index 00000000..c596fcf0 --- /dev/null +++ b/common/src/main/java/me/shedaniel/architectury/hooks/TagHooks.java @@ -0,0 +1,56 @@ +/* + * This file is part of architectury. + * Copyright (C) 2020, 2021 shedaniel + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +package me.shedaniel.architectury.hooks; + +import me.shedaniel.architectury.annotations.ExpectPlatform; +import me.shedaniel.architectury.mixin.FluidTagsAccessor; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.tags.*; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.item.Item; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.material.Fluid; + +import java.util.function.Supplier; + +public final class TagHooks { + private TagHooks() {} + + @ExpectPlatform + public static Tag.Named getOptional(ResourceLocation id, Supplier> collection) { + throw new AssertionError(); + } + + public static Tag.Named getItemOptional(ResourceLocation id) { + return getOptional(id, ItemTags::getAllTags); + } + + public static Tag.Named getBlockOptional(ResourceLocation id) { + return getOptional(id, BlockTags::getAllTags); + } + + public static Tag.Named getFluidOptional(ResourceLocation id) { + return getOptional(id, FluidTagsAccessor.getHelper()::getAllTags); + } + + public static Tag.Named> getEntityTypeOptional(ResourceLocation id) { + return getOptional(id, EntityTypeTags::getAllTags); + } +} diff --git a/common/src/main/java/me/shedaniel/architectury/mixin/BlockLandingInvoker.java b/common/src/main/java/me/shedaniel/architectury/mixin/BlockLandingInvoker.java index aead19c7..36996dce 100644 --- a/common/src/main/java/me/shedaniel/architectury/mixin/BlockLandingInvoker.java +++ b/common/src/main/java/me/shedaniel/architectury/mixin/BlockLandingInvoker.java @@ -1,3 +1,22 @@ +/* + * This file is part of architectury. + * Copyright (C) 2020, 2021 shedaniel + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + package me.shedaniel.architectury.mixin; import me.shedaniel.architectury.event.events.BlockEvent; diff --git a/common/src/main/java/me/shedaniel/architectury/mixin/FluidTagsAccessor.java b/common/src/main/java/me/shedaniel/architectury/mixin/FluidTagsAccessor.java new file mode 100644 index 00000000..f095c06e --- /dev/null +++ b/common/src/main/java/me/shedaniel/architectury/mixin/FluidTagsAccessor.java @@ -0,0 +1,34 @@ +/* + * This file is part of architectury. + * Copyright (C) 2020, 2021 shedaniel + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +package me.shedaniel.architectury.mixin; + +import net.minecraft.tags.FluidTags; +import net.minecraft.tags.StaticTagHelper; +import net.minecraft.world.level.material.Fluid; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +@Mixin(FluidTags.class) +public interface FluidTagsAccessor { + @Accessor("HELPER") + static StaticTagHelper getHelper() { + throw new AssertionError(); + } +} diff --git a/common/src/main/java/me/shedaniel/architectury/mixin/MixinLightningBolt.java b/common/src/main/java/me/shedaniel/architectury/mixin/MixinLightningBolt.java index b2743063..eb9ed20d 100644 --- a/common/src/main/java/me/shedaniel/architectury/mixin/MixinLightningBolt.java +++ b/common/src/main/java/me/shedaniel/architectury/mixin/MixinLightningBolt.java @@ -1,3 +1,22 @@ +/* + * This file is part of architectury. + * Copyright (C) 2020, 2021 shedaniel + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + package me.shedaniel.architectury.mixin; import me.shedaniel.architectury.event.events.LightningEvent; diff --git a/common/src/main/resources/architectury-common.mixins.json b/common/src/main/resources/architectury-common.mixins.json index f7f31de0..e8e55db3 100644 --- a/common/src/main/resources/architectury-common.mixins.json +++ b/common/src/main/resources/architectury-common.mixins.json @@ -1,16 +1,13 @@ { - "required": true, - "package": "me.shedaniel.architectury.mixin", - "compatibilityLevel": "JAVA_8", - "minVersion": "0.7.11", - "client": [ - ], - "mixins": [ - "BlockLandingInvoker", - "MixinLightningBolt" - ], - "injectors": { - "maxShiftBy": 5, - "defaultRequire": 1 - } + "required": true, + "package": "me.shedaniel.architectury.mixin", + "compatibilityLevel": "JAVA_8", + "minVersion": "0.7.11", + "client": [ + ], + "mixins": ["BlockLandingInvoker", "FluidTagsAccessor", "MixinLightningBolt"], + "injectors": { + "maxShiftBy": 5, + "defaultRequire": 1 + } } diff --git a/fabric/build.gradle b/fabric/build.gradle index 71b9f0df..523ca587 100644 --- a/fabric/build.gradle +++ b/fabric/build.gradle @@ -1,9 +1,3 @@ -import com.github.jengelman.gradle.plugins.shadow.transformers.Transformer -import com.github.jengelman.gradle.plugins.shadow.transformers.TransformerContext -import shadow.org.apache.tools.zip.ZipEntry -import shadow.org.apache.tools.zip.ZipOutputStream -import shadow.org.codehaus.plexus.util.IOUtil - plugins { id "com.github.johnrengelman.shadow" version "5.0.0" id "com.matthewprenger.cursegradle" diff --git a/fabric/src/main/java/me/shedaniel/architectury/hooks/fabric/TagHooksImpl.java b/fabric/src/main/java/me/shedaniel/architectury/hooks/fabric/TagHooksImpl.java new file mode 100644 index 00000000..378405c8 --- /dev/null +++ b/fabric/src/main/java/me/shedaniel/architectury/hooks/fabric/TagHooksImpl.java @@ -0,0 +1,33 @@ +/* + * This file is part of architectury. + * Copyright (C) 2020, 2021 shedaniel + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +package me.shedaniel.architectury.hooks.fabric; + +import net.fabricmc.fabric.api.tag.TagRegistry; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.tags.Tag; +import net.minecraft.tags.TagCollection; + +import java.util.function.Supplier; + +public class TagHooksImpl { + public static Tag.Named getOptional(ResourceLocation id, Supplier> collection) { + return TagRegistry.create(id, collection); + } +} diff --git a/fabric/src/main/java/me/shedaniel/architectury/plugin/fabric/ArchitecturyMixinPlugin.java b/fabric/src/main/java/me/shedaniel/architectury/plugin/fabric/ArchitecturyMixinPlugin.java index a97f2c28..bde86bc3 100644 --- a/fabric/src/main/java/me/shedaniel/architectury/plugin/fabric/ArchitecturyMixinPlugin.java +++ b/fabric/src/main/java/me/shedaniel/architectury/plugin/fabric/ArchitecturyMixinPlugin.java @@ -1,3 +1,22 @@ +/* + * This file is part of architectury. + * Copyright (C) 2020, 2021 shedaniel + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + package me.shedaniel.architectury.plugin.fabric; import net.fabricmc.loader.api.FabricLoader; diff --git a/forge/src/main/java/me/shedaniel/architectury/mixin/forge/TagHooksImpl.java b/forge/src/main/java/me/shedaniel/architectury/mixin/forge/TagHooksImpl.java new file mode 100644 index 00000000..78da2d03 --- /dev/null +++ b/forge/src/main/java/me/shedaniel/architectury/mixin/forge/TagHooksImpl.java @@ -0,0 +1,63 @@ +/* + * This file is part of architectury. + * Copyright (C) 2020, 2021 shedaniel + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +package me.shedaniel.architectury.mixin.forge; + +import net.minecraft.resources.ResourceLocation; +import net.minecraft.tags.Tag; +import net.minecraft.tags.TagCollection; + +import java.lang.ref.WeakReference; +import java.util.List; +import java.util.function.Supplier; + +public class TagHooksImpl { + public static Tag.Named getOptional(ResourceLocation id, Supplier> collection) { + return new Tag.Named() { + private volatile Tag backend; + private volatile WeakReference> backendCollection; + + @Override + public ResourceLocation getName() { + return id; + } + + @Override + public boolean contains(T object) { + return getBackend().contains(object); + } + + @Override + public List getValues() { + return getBackend().getValues(); + } + + private Tag getBackend() { + TagCollection currentCollection = collection.get(); + + if (backend == null || backendCollection == null || backendCollection.get() != currentCollection) { // If not initialized or was tag changed. + backendCollection = new WeakReference<>(currentCollection); + return backend = currentCollection.getTagOrEmpty(id); + } else { + return backend; + } + } + }; + } +} From 4f333f7ec780ce990722870d08f2e278af2a9f44 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Tue, 23 Feb 2021 00:56:50 +0800 Subject: [PATCH 14/44] Add test mod and fix game rules on forge --- .../{mixin => hooks}/forge/TagHooksImpl.java | 2 +- .../mixin/forge/GameRulesAccessor.java | 46 +++++++++++++++++++ .../registry/forge/GameRuleFactoryImpl.java | 17 +++---- .../resources/META-INF/accesstransformer.cfg | 4 -- .../main/resources/architectury.mixins.json | 2 +- .../shedaniel/architectury/test/TestMod.java | 2 + .../architectury/test/tags/TestTags.java | 28 +++++++++++ .../tags/blocks/heart_particles2.json | 6 +++ 8 files changed, 93 insertions(+), 14 deletions(-) rename forge/src/main/java/me/shedaniel/architectury/{mixin => hooks}/forge/TagHooksImpl.java (97%) create mode 100644 forge/src/main/java/me/shedaniel/architectury/mixin/forge/GameRulesAccessor.java create mode 100644 testmod-common/src/main/java/me/shedaniel/architectury/test/tags/TestTags.java create mode 100644 testmod-common/src/main/resources/data/architectury-test/tags/blocks/heart_particles2.json diff --git a/forge/src/main/java/me/shedaniel/architectury/mixin/forge/TagHooksImpl.java b/forge/src/main/java/me/shedaniel/architectury/hooks/forge/TagHooksImpl.java similarity index 97% rename from forge/src/main/java/me/shedaniel/architectury/mixin/forge/TagHooksImpl.java rename to forge/src/main/java/me/shedaniel/architectury/hooks/forge/TagHooksImpl.java index 78da2d03..a1618276 100644 --- a/forge/src/main/java/me/shedaniel/architectury/mixin/forge/TagHooksImpl.java +++ b/forge/src/main/java/me/shedaniel/architectury/hooks/forge/TagHooksImpl.java @@ -17,7 +17,7 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -package me.shedaniel.architectury.mixin.forge; +package me.shedaniel.architectury.hooks.forge; import net.minecraft.resources.ResourceLocation; import net.minecraft.tags.Tag; diff --git a/forge/src/main/java/me/shedaniel/architectury/mixin/forge/GameRulesAccessor.java b/forge/src/main/java/me/shedaniel/architectury/mixin/forge/GameRulesAccessor.java new file mode 100644 index 00000000..30e6f6de --- /dev/null +++ b/forge/src/main/java/me/shedaniel/architectury/mixin/forge/GameRulesAccessor.java @@ -0,0 +1,46 @@ +package me.shedaniel.architectury.mixin.forge; + +import net.minecraft.server.MinecraftServer; +import net.minecraft.world.level.GameRules; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Invoker; + +import java.util.function.BiConsumer; + +@Mixin(GameRules.class) +public interface GameRulesAccessor { + /** + * Spliting simple classes because mixin can't handle refmap using the same name + */ + @Mixin(GameRules.BooleanValue.class) + interface BooleanValue { + @Invoker("create") + static GameRules.Type invokeCreateArchitectury(boolean value, BiConsumer biConsumer) { + throw new AssertionError(); + } + } + + @Mixin(GameRules.BooleanValue.class) + interface BooleanValueSimple { + @Invoker("create") + static GameRules.Type invokeCreateArchitectury(boolean value) { + throw new AssertionError(); + } + } + + @Mixin(GameRules.IntegerValue.class) + interface IntegerValue { + @Invoker("create") + static GameRules.Type invokeCreateArchitectury(int value, BiConsumer biConsumer) { + throw new AssertionError(); + } + } + + @Mixin(GameRules.IntegerValue.class) + interface IntegerValueSimple { + @Invoker("create") + static GameRules.Type invokeCreateArchitectury(int value) { + throw new AssertionError(); + } + } +} diff --git a/forge/src/main/java/me/shedaniel/architectury/registry/forge/GameRuleFactoryImpl.java b/forge/src/main/java/me/shedaniel/architectury/registry/forge/GameRuleFactoryImpl.java index c925bf5f..bec7c989 100644 --- a/forge/src/main/java/me/shedaniel/architectury/registry/forge/GameRuleFactoryImpl.java +++ b/forge/src/main/java/me/shedaniel/architectury/registry/forge/GameRuleFactoryImpl.java @@ -19,6 +19,7 @@ package me.shedaniel.architectury.registry.forge; +import me.shedaniel.architectury.mixin.forge.GameRulesAccessor; import net.minecraft.server.MinecraftServer; import net.minecraft.world.level.GameRules; @@ -26,20 +27,20 @@ import java.util.function.BiConsumer; public class GameRuleFactoryImpl { private GameRuleFactoryImpl() {} - + public static GameRules.Type createBooleanRule(boolean defaultValue) { - return GameRules.BooleanValue.create(defaultValue); + return GameRulesAccessor.BooleanValueSimple.invokeCreateArchitectury(defaultValue); } - + public static GameRules.Type createBooleanRule(boolean defaultValue, BiConsumer changedCallback) { - return GameRules.BooleanValue.create(defaultValue, changedCallback); + return GameRulesAccessor.BooleanValue.invokeCreateArchitectury(defaultValue, changedCallback); } - + public static GameRules.Type createIntRule(int defaultValue) { - return GameRules.IntegerValue.create(defaultValue); + return GameRulesAccessor.IntegerValueSimple.invokeCreateArchitectury(defaultValue); } - + public static GameRules.Type createIntRule(int defaultValue, BiConsumer changedCallback) { - return GameRules.IntegerValue.create(defaultValue, changedCallback); + return GameRulesAccessor.IntegerValue.invokeCreateArchitectury(defaultValue, changedCallback); } } diff --git a/forge/src/main/resources/META-INF/accesstransformer.cfg b/forge/src/main/resources/META-INF/accesstransformer.cfg index 523978ec..b4afaea4 100644 --- a/forge/src/main/resources/META-INF/accesstransformer.cfg +++ b/forge/src/main/resources/META-INF/accesstransformer.cfg @@ -33,7 +33,3 @@ public-f net.minecraft.world.biome.BiomeAmbience field_242524_f # foliageColor public-f net.minecraft.world.biome.BiomeAmbience field_242525_g # grassColor public-f net.minecraft.world.biome.BiomeAmbience field_242526_h # grassColorModifier public net.minecraft.world.storage.FolderName (Ljava/lang/String;)V -public net.minecraft.world.GameRules$BooleanValue func_223567_b(ZLjava/util/function/BiConsumer;)Lnet/minecraft/world/GameRules$RuleType; # create -public net.minecraft.world.GameRules$BooleanValue func_223568_b(Z)Lnet/minecraft/world/GameRules$RuleType; # create -public net.minecraft.world.GameRules$IntegerValue func_223564_a(ILjava/util/function/BiConsumer;)Lnet/minecraft/world/GameRules$RuleType; # create -public net.minecraft.world.GameRules$IntegerValue func_223559_b(I)Lnet/minecraft/world/GameRules$RuleType; # create diff --git a/forge/src/main/resources/architectury.mixins.json b/forge/src/main/resources/architectury.mixins.json index af3e3799..383b59e3 100644 --- a/forge/src/main/resources/architectury.mixins.json +++ b/forge/src/main/resources/architectury.mixins.json @@ -8,7 +8,7 @@ ], "mixins": [ "BiomeGenerationSettingsBuilderAccessor", "MixinRegistryEntry", "MixinBlockEntity", "MixinBlockEntityExtension", - "MobSpawnSettingsBuilderAccessor" + "MobSpawnSettingsBuilderAccessor", "GameRulesAccessor", "GameRulesAccessor$BooleanValue", "GameRulesAccessor$BooleanValueSimple", "GameRulesAccessor$IntegerValue", "GameRulesAccessor$IntegerValueSimple" ], "injectors": { "defaultRequire": 1 diff --git a/testmod-common/src/main/java/me/shedaniel/architectury/test/TestMod.java b/testmod-common/src/main/java/me/shedaniel/architectury/test/TestMod.java index 7a53cd3c..fe9fcce0 100644 --- a/testmod-common/src/main/java/me/shedaniel/architectury/test/TestMod.java +++ b/testmod-common/src/main/java/me/shedaniel/architectury/test/TestMod.java @@ -27,6 +27,7 @@ import me.shedaniel.architectury.test.debug.client.ClientOverlayMessageSink; import me.shedaniel.architectury.test.gamerule.TestGameRules; import me.shedaniel.architectury.test.registry.TestRegistries; import me.shedaniel.architectury.test.registry.client.TestKeybinds; +import me.shedaniel.architectury.test.tags.TestTags; import me.shedaniel.architectury.utils.Env; import me.shedaniel.architectury.utils.EnvExecutor; @@ -38,6 +39,7 @@ public class TestMod { DebugEvents.initialize(); TestRegistries.initialize(); TestGameRules.init(); + TestTags.initialize(); if (Platform.getEnvironment() == Env.CLIENT) TestKeybinds.initialize(); } diff --git a/testmod-common/src/main/java/me/shedaniel/architectury/test/tags/TestTags.java b/testmod-common/src/main/java/me/shedaniel/architectury/test/tags/TestTags.java new file mode 100644 index 00000000..dbbd9b10 --- /dev/null +++ b/testmod-common/src/main/java/me/shedaniel/architectury/test/tags/TestTags.java @@ -0,0 +1,28 @@ +package me.shedaniel.architectury.test.tags; + +import me.shedaniel.architectury.event.events.BlockEvent; +import me.shedaniel.architectury.hooks.TagHooks; +import me.shedaniel.architectury.test.TestMod; +import net.minecraft.core.particles.ParticleTypes; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.tags.Tag; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.level.block.Block; + +public class TestTags { + public static void initialize() { + // This will not be present, but it should return an empty tag + Tag.Named heartParticles = TagHooks.getBlockOptional(new ResourceLocation(TestMod.MOD_ID, "heart_particles")); + // This will act like a normal tag, we have emerald block here + Tag.Named heartParticles2 = TagHooks.getBlockOptional(new ResourceLocation(TestMod.MOD_ID, "heart_particles2")); + + BlockEvent.BREAK.register((world, pos, state, player, xp) -> { + if (player != null && !world.isClientSide() && (state.is(heartParticles) || state.is(heartParticles2))) { + ((ServerLevel) world).sendParticles(player, ParticleTypes.HEART, false, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, 10, 0.0, 0.0, 0.0, 0.0); + } + + return InteractionResult.PASS; + }); + } +} diff --git a/testmod-common/src/main/resources/data/architectury-test/tags/blocks/heart_particles2.json b/testmod-common/src/main/resources/data/architectury-test/tags/blocks/heart_particles2.json new file mode 100644 index 00000000..434965a2 --- /dev/null +++ b/testmod-common/src/main/resources/data/architectury-test/tags/blocks/heart_particles2.json @@ -0,0 +1,6 @@ +{ + "replace": false, + "values": [ + "minecraft:emerald_block" + ] +} From a7a98aa19f426c4a0c949e5f24c83031d22c127d Mon Sep 17 00:00:00 2001 From: shedaniel Date: Tue, 23 Feb 2021 00:58:04 +0800 Subject: [PATCH 15/44] Add license --- .../mixin/forge/GameRulesAccessor.java | 19 +++++++++++++++++++ .../architectury/test/tags/TestTags.java | 19 +++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/forge/src/main/java/me/shedaniel/architectury/mixin/forge/GameRulesAccessor.java b/forge/src/main/java/me/shedaniel/architectury/mixin/forge/GameRulesAccessor.java index 30e6f6de..03713b65 100644 --- a/forge/src/main/java/me/shedaniel/architectury/mixin/forge/GameRulesAccessor.java +++ b/forge/src/main/java/me/shedaniel/architectury/mixin/forge/GameRulesAccessor.java @@ -1,3 +1,22 @@ +/* + * This file is part of architectury. + * Copyright (C) 2020, 2021 shedaniel + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + package me.shedaniel.architectury.mixin.forge; import net.minecraft.server.MinecraftServer; diff --git a/testmod-common/src/main/java/me/shedaniel/architectury/test/tags/TestTags.java b/testmod-common/src/main/java/me/shedaniel/architectury/test/tags/TestTags.java index dbbd9b10..ec25be88 100644 --- a/testmod-common/src/main/java/me/shedaniel/architectury/test/tags/TestTags.java +++ b/testmod-common/src/main/java/me/shedaniel/architectury/test/tags/TestTags.java @@ -1,3 +1,22 @@ +/* + * This file is part of architectury. + * Copyright (C) 2020, 2021 shedaniel + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + package me.shedaniel.architectury.test.tags; import me.shedaniel.architectury.event.events.BlockEvent; From 189f1e211cb21df84176f92bfb57f9b0c9d27bf7 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Tue, 23 Feb 2021 01:03:06 +0800 Subject: [PATCH 16/44] Implement Tag#equals and Tag#hashCode on forge because forge is nice --- .../hooks/forge/TagHooksImpl.java | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/forge/src/main/java/me/shedaniel/architectury/hooks/forge/TagHooksImpl.java b/forge/src/main/java/me/shedaniel/architectury/hooks/forge/TagHooksImpl.java index a1618276..079ec9d2 100644 --- a/forge/src/main/java/me/shedaniel/architectury/hooks/forge/TagHooksImpl.java +++ b/forge/src/main/java/me/shedaniel/architectury/hooks/forge/TagHooksImpl.java @@ -25,6 +25,7 @@ import net.minecraft.tags.TagCollection; import java.lang.ref.WeakReference; import java.util.List; +import java.util.Objects; import java.util.function.Supplier; public class TagHooksImpl { @@ -37,12 +38,12 @@ public class TagHooksImpl { public ResourceLocation getName() { return id; } - + @Override public boolean contains(T object) { return getBackend().contains(object); } - + @Override public List getValues() { return getBackend().getValues(); @@ -50,7 +51,7 @@ public class TagHooksImpl { private Tag getBackend() { TagCollection currentCollection = collection.get(); - + if (backend == null || backendCollection == null || backendCollection.get() != currentCollection) { // If not initialized or was tag changed. backendCollection = new WeakReference<>(currentCollection); return backend = currentCollection.getTagOrEmpty(id); @@ -58,6 +59,21 @@ public class TagHooksImpl { return backend; } } + + @Override + public String toString() { + return "OptionalNamedTag[" + getName().toString() + ']'; + } + + @Override + public boolean equals(Object o) { + return o == this || o instanceof Named && Objects.equals(getName(), ((Named) o).getName()); + } + + @Override + public int hashCode() { + return getName().hashCode(); + } }; } } From c0c496007eb29ebed9070b79c2aceb8bf5ba97bb Mon Sep 17 00:00:00 2001 From: shedaniel Date: Tue, 23 Feb 2021 23:08:38 +0800 Subject: [PATCH 17/44] Fix block entity without position --- .../architectury/mixin/fabric/MixinBlockEntityExtension.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fabric/src/main/java/me/shedaniel/architectury/mixin/fabric/MixinBlockEntityExtension.java b/fabric/src/main/java/me/shedaniel/architectury/mixin/fabric/MixinBlockEntityExtension.java index 0fb45747..495398ca 100644 --- a/fabric/src/main/java/me/shedaniel/architectury/mixin/fabric/MixinBlockEntityExtension.java +++ b/fabric/src/main/java/me/shedaniel/architectury/mixin/fabric/MixinBlockEntityExtension.java @@ -42,7 +42,9 @@ public interface MixinBlockEntityExtension extends BlockEntityClientSerializable default void fromClientTag(CompoundTag tag) { BlockEntity entity = (BlockEntity) this; if (entity.hasLevel()) { - entity.setLevelAndPosition(entity.getLevel(), new BlockPos(tag.getInt("x"), tag.getInt("y"), tag.getInt("z"))); + if (tag.contains("x") && tag.contains("y") && tag.contains("z")) { + entity.setLevelAndPosition(entity.getLevel(), new BlockPos(tag.getInt("x"), tag.getInt("y"), tag.getInt("z"))); + } loadClientData(entity.getBlockState(), tag); } } From 186d9bc517afe02a13c3dd5a86ee8d372a94cb11 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Tue, 23 Feb 2021 23:11:00 +0800 Subject: [PATCH 18/44] Bump to 1.8 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 53290270..f925bb87 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,7 +6,7 @@ supported_version=1.16.4/5 archives_base_name=architectury archives_base_name_snapshot=architectury-snapshot -base_version=1.7 +base_version=1.8 maven_group=me.shedaniel fabric_loader_version=0.11.1 From 4288ba88f5f4ae64b04f356414a723c31dd12765 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Tue, 23 Feb 2021 23:17:07 +0800 Subject: [PATCH 19/44] Remove jcenter from settings.gradle --- settings.gradle | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/settings.gradle b/settings.gradle index 2d1ff5a9..f54332be 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,8 +1,7 @@ pluginManagement { repositories { - jcenter() maven { url "https://maven.fabricmc.net/" } - maven { url "https://maven.shedaniel.me" } + maven { url "https://maven.shedaniel.me/" } maven { url "https://files.minecraftforge.net/maven/" } gradlePluginPortal() } From b93cb04b6f11d8f31865b54588b5a536667fbda1 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Thu, 25 Feb 2021 15:00:34 +0800 Subject: [PATCH 20/44] Add null checks to networking for better errors. --- .../networking/NetworkChannel.java | 22 +++++++++---------- .../networking/NetworkManager.java | 14 ++++++++---- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/common/src/main/java/me/shedaniel/architectury/networking/NetworkChannel.java b/common/src/main/java/me/shedaniel/architectury/networking/NetworkChannel.java index f49f227c..b2c203a3 100644 --- a/common/src/main/java/me/shedaniel/architectury/networking/NetworkChannel.java +++ b/common/src/main/java/me/shedaniel/architectury/networking/NetworkChannel.java @@ -20,7 +20,6 @@ package me.shedaniel.architectury.networking; import com.google.common.collect.Maps; -import com.mojang.datafixers.util.Pair; import io.netty.buffer.Unpooled; import me.shedaniel.architectury.networking.NetworkManager.PacketContext; import me.shedaniel.architectury.platform.Platform; @@ -111,32 +110,31 @@ public final class NetworkChannel { register(type, encoder, decoder, messageConsumer); } - private Pair, FriendlyByteBuf> encode(T message) { - MessageInfo messageInfo = (MessageInfo) Objects.requireNonNull(encoders.get(message.getClass())); + public Packet toPacket(NetworkManager.Side side, T message) { + MessageInfo messageInfo = (MessageInfo) Objects.requireNonNull(encoders.get(message.getClass()), "Unknown message type! " + message); FriendlyByteBuf buf = new FriendlyByteBuf(Unpooled.buffer()); messageInfo.encoder.accept(message, buf); - return new Pair<>(messageInfo, buf); - } - - public Packet toPacket(NetworkManager.Side side, T message) { - Pair, FriendlyByteBuf> encoded = encode(message); - return NetworkManager.toPacket(side, encoded.getFirst().packetId, encoded.getSecond()); + return NetworkManager.toPacket(side, messageInfo.packetId, buf); } public void sendToPlayer(ServerPlayer player, T message) { - player.connection.send(toPacket(NetworkManager.s2c(), message)); + Objects.requireNonNull(player, "Unable to send packet to a 'null' player!").connection.send(toPacket(NetworkManager.s2c(), message)); } public void sendToPlayers(Iterable players, T message) { Packet packet = toPacket(NetworkManager.s2c(), message); for (ServerPlayer player : players) { - player.connection.send(packet); + Objects.requireNonNull(player, "Unable to send packet to a 'null' player!").connection.send(packet); } } @Environment(EnvType.CLIENT) public void sendToServer(T message) { - Minecraft.getInstance().getConnection().send(toPacket(NetworkManager.c2s(), message)); + if (Minecraft.getInstance().getConnection() != null) { + Minecraft.getInstance().getConnection().send(toPacket(NetworkManager.c2s(), message)); + } else { + throw new IllegalStateException("Unable to send packet to the server while not in game!"); + } } @Environment(EnvType.CLIENT) diff --git a/common/src/main/java/me/shedaniel/architectury/networking/NetworkManager.java b/common/src/main/java/me/shedaniel/architectury/networking/NetworkManager.java index 135b49e0..51a74cd1 100644 --- a/common/src/main/java/me/shedaniel/architectury/networking/NetworkManager.java +++ b/common/src/main/java/me/shedaniel/architectury/networking/NetworkManager.java @@ -30,6 +30,8 @@ import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.player.Player; +import java.util.Objects; + public final class NetworkManager { @ExpectPlatform public static void registerReceiver(Side side, ResourceLocation id, NetworkReceiver receiver) { @@ -42,19 +44,23 @@ public final class NetworkManager { } public static void sendToPlayer(ServerPlayer player, ResourceLocation id, FriendlyByteBuf buf) { - player.connection.send(toPacket(serverToClient(), id, buf)); + Objects.requireNonNull(player, "Unable to send packet to a 'null' player!").connection.send(toPacket(serverToClient(), id, buf)); } public static void sendToPlayers(Iterable players, ResourceLocation id, FriendlyByteBuf buf) { Packet packet = toPacket(serverToClient(), id, buf); for (ServerPlayer player : players) { - player.connection.send(packet); + Objects.requireNonNull(player, "Unable to send packet to a 'null' player!").connection.send(packet); } } @Environment(EnvType.CLIENT) public static void sendToServer(ResourceLocation id, FriendlyByteBuf buf) { - Minecraft.getInstance().getConnection().send(toPacket(clientToServer(), id, buf)); + if (Minecraft.getInstance().getConnection() != null) { + Minecraft.getInstance().getConnection().send(toPacket(clientToServer(), id, buf)); + } else { + throw new IllegalStateException("Unable to send packet to the server while not in game!"); + } } @Environment(EnvType.CLIENT) @@ -77,7 +83,7 @@ public final class NetworkManager { Player getPlayer(); void queue(Runnable runnable); - + Env getEnvironment(); default EnvType getEnv() { From 5dc01b0a19462a45ad2bb2102c7e5147958c67c7 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Fri, 26 Feb 2021 00:36:06 +0800 Subject: [PATCH 21/44] Implement onDataPacket (#48) --- common/build.gradle | 1 + fabric/build.gradle | 2 +- forge/build.gradle | 2 +- .../mixin/forge/MixinBlockEntityExtension.java | 8 ++++++++ 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/common/build.gradle b/common/build.gradle index 85ea3d18..dfacb2c5 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -23,6 +23,7 @@ task sourcesJar(type: Jar, dependsOn: classes) { publishing { publications { mavenCommon(MavenPublication) { + artifactId = rootProject.archivesBaseName artifact(file("${project.buildDir}/libs/${project.archivesBaseName}-${project.version}.jar")) { builtBy build } diff --git a/fabric/build.gradle b/fabric/build.gradle index 523ca587..48e4e110 100644 --- a/fabric/build.gradle +++ b/fabric/build.gradle @@ -63,7 +63,7 @@ remapJar { publishing { publications { mavenFabric(MavenPublication) { - artifactId = rootProject.archives_base_name + "-fabric" + artifactId = rootProject.archivesBaseName + "-fabric" artifact(remapJar.archivePath) { builtBy build classifier null diff --git a/forge/build.gradle b/forge/build.gradle index 49a7ddfe..a09ce537 100644 --- a/forge/build.gradle +++ b/forge/build.gradle @@ -64,7 +64,7 @@ remapJar { publishing { publications { mavenForge(MavenPublication) { - artifactId = rootProject.archives_base_name + "-forge" + artifactId = rootProject.archivesBaseName + "-forge" artifact(remapJar.archivePath) { builtBy build classifier null diff --git a/forge/src/main/java/me/shedaniel/architectury/mixin/forge/MixinBlockEntityExtension.java b/forge/src/main/java/me/shedaniel/architectury/mixin/forge/MixinBlockEntityExtension.java index fea8725e..c24dacbb 100644 --- a/forge/src/main/java/me/shedaniel/architectury/mixin/forge/MixinBlockEntityExtension.java +++ b/forge/src/main/java/me/shedaniel/architectury/mixin/forge/MixinBlockEntityExtension.java @@ -21,6 +21,9 @@ package me.shedaniel.architectury.mixin.forge; import me.shedaniel.architectury.extensions.BlockEntityExtension; import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.Connection; +import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket; +import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; import net.minecraftforge.common.extensions.IForgeTileEntity; import org.jetbrains.annotations.NotNull; @@ -36,4 +39,9 @@ public interface MixinBlockEntityExtension extends IForgeTileEntity { default void handleUpdateTag(BlockState state, CompoundTag tag) { loadClientData(state, tag); } + + @Override + default void onDataPacket(Connection connection, ClientboundBlockEntityDataPacket packet) { + loadClientData(((BlockEntity) this).getBlockState(), packet.getTag()); + } } From c8aeff08238768196751f675b5e2f7f1047b68dc Mon Sep 17 00:00:00 2001 From: shedaniel Date: Fri, 26 Feb 2021 02:11:44 +0800 Subject: [PATCH 22/44] Update architectury-plugin to 3.0.88 --- build.gradle | 10 +++++++++- .../java/me/shedaniel/architectury/test/TestMod.java | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 6814500c..5ead8335 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ plugins { - id "architectury-plugin" version "3.0.85" + id "architectury-plugin" version "3.0.88" id "forgified-fabric-loom" version "0.6.70" apply false id "org.cadixdev.licenser" version "0.5.0" id "com.matthewprenger.cursegradle" version "1.4.0" apply false @@ -28,6 +28,14 @@ allprojects { isSnapshot = System.getenv("PR_NUM") != null } + architectury { + transformerVersion = "2.0.9999" + } + + repositories { + mavenLocal() + } + def runNumber = (System.getenv("GITHUB_RUN_NUMBER") == null ? "9999" : System.getenv("GITHUB_RUN_NUMBER")) if (!ext.isSnapshot) { diff --git a/testmod-common/src/main/java/me/shedaniel/architectury/test/TestMod.java b/testmod-common/src/main/java/me/shedaniel/architectury/test/TestMod.java index fe9fcce0..2d7a2905 100644 --- a/testmod-common/src/main/java/me/shedaniel/architectury/test/TestMod.java +++ b/testmod-common/src/main/java/me/shedaniel/architectury/test/TestMod.java @@ -21,9 +21,9 @@ package me.shedaniel.architectury.test; import me.shedaniel.architectury.platform.Platform; import me.shedaniel.architectury.test.debug.ConsoleMessageSink; -import me.shedaniel.architectury.test.events.DebugEvents; import me.shedaniel.architectury.test.debug.MessageSink; import me.shedaniel.architectury.test.debug.client.ClientOverlayMessageSink; +import me.shedaniel.architectury.test.events.DebugEvents; import me.shedaniel.architectury.test.gamerule.TestGameRules; import me.shedaniel.architectury.test.registry.TestRegistries; import me.shedaniel.architectury.test.registry.client.TestKeybinds; From 0eb7bd5b1e17ae1ee58db14695102a7f34a92d92 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Fri, 26 Feb 2021 02:16:10 +0800 Subject: [PATCH 23/44] Remove locals requirements from BlockLandingInvoker --- .../me/shedaniel/architectury/mixin/BlockLandingInvoker.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/common/src/main/java/me/shedaniel/architectury/mixin/BlockLandingInvoker.java b/common/src/main/java/me/shedaniel/architectury/mixin/BlockLandingInvoker.java index 36996dce..71df8a51 100644 --- a/common/src/main/java/me/shedaniel/architectury/mixin/BlockLandingInvoker.java +++ b/common/src/main/java/me/shedaniel/architectury/mixin/BlockLandingInvoker.java @@ -31,11 +31,10 @@ import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.LocalCapture; @Mixin({FallingBlock.class, AnvilBlock.class, ConcretePowderBlock.class}) public abstract class BlockLandingInvoker { - @Inject(method = "onLand", at = @At("RETURN"), locals = LocalCapture.CAPTURE_FAILHARD) + @Inject(method = "onLand", at = @At("RETURN")) public void handleLand(Level level, BlockPos pos, BlockState fallState, BlockState landOn, FallingBlockEntity entity, CallbackInfo ci) { BlockEvent.FALLING_LAND.invoker().onLand(level, pos, fallState, landOn, entity); } From 60cc189d600222d301c0089048d5f14edbda3c84 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Fri, 26 Feb 2021 02:18:05 +0800 Subject: [PATCH 24/44] Remove local testing build of transformer --- build.gradle | 8 -------- 1 file changed, 8 deletions(-) diff --git a/build.gradle b/build.gradle index 5ead8335..87d99a7c 100644 --- a/build.gradle +++ b/build.gradle @@ -28,14 +28,6 @@ allprojects { isSnapshot = System.getenv("PR_NUM") != null } - architectury { - transformerVersion = "2.0.9999" - } - - repositories { - mavenLocal() - } - def runNumber = (System.getenv("GITHUB_RUN_NUMBER") == null ? "9999" : System.getenv("GITHUB_RUN_NUMBER")) if (!ext.isSnapshot) { From 927bd08f8c96135f2e4cb66b95c15053fd0fe734 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Fri, 26 Feb 2021 03:47:23 +0800 Subject: [PATCH 25/44] Revert "Remove locals requirements from BlockLandingInvoker" This reverts commit 0eb7bd5b --- .../me/shedaniel/architectury/mixin/BlockLandingInvoker.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/common/src/main/java/me/shedaniel/architectury/mixin/BlockLandingInvoker.java b/common/src/main/java/me/shedaniel/architectury/mixin/BlockLandingInvoker.java index 71df8a51..36996dce 100644 --- a/common/src/main/java/me/shedaniel/architectury/mixin/BlockLandingInvoker.java +++ b/common/src/main/java/me/shedaniel/architectury/mixin/BlockLandingInvoker.java @@ -31,10 +31,11 @@ import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.LocalCapture; @Mixin({FallingBlock.class, AnvilBlock.class, ConcretePowderBlock.class}) public abstract class BlockLandingInvoker { - @Inject(method = "onLand", at = @At("RETURN")) + @Inject(method = "onLand", at = @At("RETURN"), locals = LocalCapture.CAPTURE_FAILHARD) public void handleLand(Level level, BlockPos pos, BlockState fallState, BlockState landOn, FallingBlockEntity entity, CallbackInfo ci) { BlockEvent.FALLING_LAND.invoker().onLand(level, pos, fallState, landOn, entity); } From 568f6244672cdfb45742b7a00ce3f1d9a978341e Mon Sep 17 00:00:00 2001 From: shedaniel Date: Fri, 26 Feb 2021 20:36:32 +0800 Subject: [PATCH 26/44] Update architectury-plugin to 3.0.89 and fix #51 --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 87d99a7c..7b9fe970 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ plugins { - id "architectury-plugin" version "3.0.88" + id "architectury-plugin" version "3.0.89" id "forgified-fabric-loom" version "0.6.70" apply false id "org.cadixdev.licenser" version "0.5.0" id "com.matthewprenger.cursegradle" version "1.4.0" apply false From 89ce4c7c5876ce02d3dac3af6eb1baa8749d8d73 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Sat, 27 Feb 2021 17:48:34 +0800 Subject: [PATCH 27/44] Fix BlockEntityExtension @Shadow remapping --- build.gradle | 2 +- .../mixin/fabric/MixinBlockEntityExtension.java | 14 ++------------ .../mixin/forge/MixinBlockEntityExtension.java | 9 ++------- 3 files changed, 5 insertions(+), 20 deletions(-) diff --git a/build.gradle b/build.gradle index 7b9fe970..31979dfd 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,6 @@ plugins { id "architectury-plugin" version "3.0.89" - id "forgified-fabric-loom" version "0.6.70" apply false + id "forgified-fabric-loom" version "0.6.71" apply false id "org.cadixdev.licenser" version "0.5.0" id "com.matthewprenger.cursegradle" version "1.4.0" apply false id "maven-publish" diff --git a/fabric/src/main/java/me/shedaniel/architectury/mixin/fabric/MixinBlockEntityExtension.java b/fabric/src/main/java/me/shedaniel/architectury/mixin/fabric/MixinBlockEntityExtension.java index 495398ca..8d4e04df 100644 --- a/fabric/src/main/java/me/shedaniel/architectury/mixin/fabric/MixinBlockEntityExtension.java +++ b/fabric/src/main/java/me/shedaniel/architectury/mixin/fabric/MixinBlockEntityExtension.java @@ -24,20 +24,10 @@ import net.fabricmc.fabric.api.block.entity.BlockEntityClientSerializable; import net.minecraft.core.BlockPos; import net.minecraft.nbt.CompoundTag; import net.minecraft.world.level.block.entity.BlockEntity; -import net.minecraft.world.level.block.state.BlockState; -import org.jetbrains.annotations.NotNull; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; @Mixin(BlockEntityExtension.class) public interface MixinBlockEntityExtension extends BlockEntityClientSerializable { - @Shadow(remap = false) - @NotNull - CompoundTag saveClientData(@NotNull CompoundTag tag); - - @Shadow(remap = false) - void loadClientData(@NotNull BlockState pos, @NotNull CompoundTag tag); - @Override default void fromClientTag(CompoundTag tag) { BlockEntity entity = (BlockEntity) this; @@ -45,12 +35,12 @@ public interface MixinBlockEntityExtension extends BlockEntityClientSerializable if (tag.contains("x") && tag.contains("y") && tag.contains("z")) { entity.setLevelAndPosition(entity.getLevel(), new BlockPos(tag.getInt("x"), tag.getInt("y"), tag.getInt("z"))); } - loadClientData(entity.getBlockState(), tag); + ((BlockEntityExtension) this).loadClientData(entity.getBlockState(), tag); } } @Override default CompoundTag toClientTag(CompoundTag tag) { - return saveClientData(tag); + return ((BlockEntityExtension) this).saveClientData(tag); } } diff --git a/forge/src/main/java/me/shedaniel/architectury/mixin/forge/MixinBlockEntityExtension.java b/forge/src/main/java/me/shedaniel/architectury/mixin/forge/MixinBlockEntityExtension.java index c24dacbb..02dd3e41 100644 --- a/forge/src/main/java/me/shedaniel/architectury/mixin/forge/MixinBlockEntityExtension.java +++ b/forge/src/main/java/me/shedaniel/architectury/mixin/forge/MixinBlockEntityExtension.java @@ -26,22 +26,17 @@ import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; import net.minecraftforge.common.extensions.IForgeTileEntity; -import org.jetbrains.annotations.NotNull; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; @Mixin(BlockEntityExtension.class) public interface MixinBlockEntityExtension extends IForgeTileEntity { - @Shadow(remap = false) - void loadClientData(@NotNull BlockState pos, @NotNull CompoundTag tag); - @Override default void handleUpdateTag(BlockState state, CompoundTag tag) { - loadClientData(state, tag); + ((BlockEntityExtension) this).loadClientData(state, tag); } @Override default void onDataPacket(Connection connection, ClientboundBlockEntityDataPacket packet) { - loadClientData(((BlockEntity) this).getBlockState(), packet.getTag()); + ((BlockEntityExtension) this).loadClientData(((BlockEntity) this).getBlockState(), packet.getTag()); } } From d9b43e71e608748b2b6a36fc8586616a81d1dec6 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Sat, 27 Feb 2021 17:48:51 +0800 Subject: [PATCH 28/44] Add EntityRenderers (#52) Close #45 --- .../registry/entity/EntityRenderers.java | 21 +++++++++++++++++++ .../entity/fabric/EntityRenderersImpl.java | 15 +++++++++++++ .../entity/forge/EntityRenderersImpl.java | 15 +++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 common/src/main/java/me/shedaniel/architectury/registry/entity/EntityRenderers.java create mode 100644 fabric/src/main/java/me/shedaniel/architectury/registry/entity/fabric/EntityRenderersImpl.java create mode 100644 forge/src/main/java/me/shedaniel/architectury/registry/entity/forge/EntityRenderersImpl.java diff --git a/common/src/main/java/me/shedaniel/architectury/registry/entity/EntityRenderers.java b/common/src/main/java/me/shedaniel/architectury/registry/entity/EntityRenderers.java new file mode 100644 index 00000000..336d3dc4 --- /dev/null +++ b/common/src/main/java/me/shedaniel/architectury/registry/entity/EntityRenderers.java @@ -0,0 +1,21 @@ +package me.shedaniel.architectury.registry.entity; + +import me.shedaniel.architectury.annotations.ExpectPlatform; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.client.renderer.entity.EntityRenderDispatcher; +import net.minecraft.client.renderer.entity.EntityRenderer; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EntityType; + +import java.util.function.Function; + +@Environment(EnvType.CLIENT) +public final class EntityRenderers { + private EntityRenderers() {} + + @ExpectPlatform + public static void register(EntityType type, Function> factory) { + throw new AssertionError(); + } +} diff --git a/fabric/src/main/java/me/shedaniel/architectury/registry/entity/fabric/EntityRenderersImpl.java b/fabric/src/main/java/me/shedaniel/architectury/registry/entity/fabric/EntityRenderersImpl.java new file mode 100644 index 00000000..96830f6c --- /dev/null +++ b/fabric/src/main/java/me/shedaniel/architectury/registry/entity/fabric/EntityRenderersImpl.java @@ -0,0 +1,15 @@ +package me.shedaniel.architectury.registry.entity.fabric; + +import net.fabricmc.fabric.api.client.rendereregistry.v1.EntityRendererRegistry; +import net.minecraft.client.renderer.entity.EntityRenderDispatcher; +import net.minecraft.client.renderer.entity.EntityRenderer; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EntityType; + +import java.util.function.Function; + +public class EntityRenderersImpl { + public static void register(EntityType type, Function> factory) { + EntityRendererRegistry.INSTANCE.register(type, (manager, context) -> factory.apply(manager)); + } +} diff --git a/forge/src/main/java/me/shedaniel/architectury/registry/entity/forge/EntityRenderersImpl.java b/forge/src/main/java/me/shedaniel/architectury/registry/entity/forge/EntityRenderersImpl.java new file mode 100644 index 00000000..8be995d3 --- /dev/null +++ b/forge/src/main/java/me/shedaniel/architectury/registry/entity/forge/EntityRenderersImpl.java @@ -0,0 +1,15 @@ +package me.shedaniel.architectury.registry.entity.forge; + +import net.minecraft.client.renderer.entity.EntityRenderDispatcher; +import net.minecraft.client.renderer.entity.EntityRenderer; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EntityType; +import net.minecraftforge.fml.client.registry.RenderingRegistry; + +import java.util.function.Function; + +public class EntityRenderersImpl { + public static void register(EntityType type, Function> factory) { + RenderingRegistry.registerEntityRenderingHandler(type, factory::apply); + } +} From bf9efc708fc73ae530a5aba7a8fff8553b1d16c9 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Mon, 1 Mar 2021 21:30:24 +0800 Subject: [PATCH 29/44] Update plugins --- build.gradle | 4 ++-- fabric/build.gradle | 8 ++++---- forge/build.gradle | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/build.gradle b/build.gradle index 31979dfd..cab645b8 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,6 @@ plugins { - id "architectury-plugin" version "3.0.89" - id "forgified-fabric-loom" version "0.6.71" apply false + id "architectury-plugin" version "3.0.91" + id "forgified-fabric-loom" version "0.6.72" apply false id "org.cadixdev.licenser" version "0.5.0" id "com.matthewprenger.cursegradle" version "1.4.0" apply false id "maven-publish" diff --git a/fabric/build.gradle b/fabric/build.gradle index 48e4e110..05cc5d2e 100644 --- a/fabric/build.gradle +++ b/fabric/build.gradle @@ -8,7 +8,7 @@ loom { } configurations { - shadow + shadowCommon dev } @@ -28,7 +28,7 @@ dependencies { modImplementation "net.fabricmc.fabric-api:fabric-api:${rootProject.fabric_api_version}" modCompileOnly "io.github.prospector:modmenu:${rootProject.mod_menu_version}" implementation "net.jodah:typetools:0.6.2" - shadow "net.jodah:typetools:0.6.2" + shadowCommon "net.jodah:typetools:0.6.2" implementation(project(path: ":common")) { transitive = false @@ -36,7 +36,7 @@ dependencies { developmentFabric(project(path: ":common")) { transitive = false } - shadow(project(path: ":common", configuration: "transformProductionFabric")) { + shadowCommon(project(path: ":common", configuration: "transformProductionFabric")) { transitive = false } } @@ -50,7 +50,7 @@ processResources { shadowJar { relocate "net.jodah.typetools", "me.shedaniel.architectury.shadowed.impl.net.jodah.typetools" - configurations = [project.configurations.shadow] + configurations = [project.configurations.shadowCommon] classifier "shadow" } diff --git a/forge/build.gradle b/forge/build.gradle index a09ce537..3e5f3f88 100644 --- a/forge/build.gradle +++ b/forge/build.gradle @@ -8,7 +8,7 @@ loom { } configurations { - shadow + shadowCommon dev } @@ -26,7 +26,7 @@ dependencies { mappings loom.officialMojangMappings() forge "net.minecraftforge:forge:${rootProject.architectury.minecraft}-${rootProject.forge_version}" implementation "net.jodah:typetools:0.6.2" - shadow "net.jodah:typetools:0.6.2" + shadowCommon "net.jodah:typetools:0.6.2" implementation(project(path: ":common")) { transitive = false @@ -34,7 +34,7 @@ dependencies { developmentForge(project(path: ":common")) { transitive = false } - shadow(project(path: ":common", configuration: "transformProductionForge")) { + shadowCommon(project(path: ":common", configuration: "transformProductionForge")) { transitive = false } } @@ -51,7 +51,7 @@ shadowJar { exclude "fabric.mod.json" exclude "architectury-common.accessWidener" - configurations = [project.configurations.shadow] + configurations = [project.configurations.shadowCommon] classifier "shadow" } From 0dbf72667d3720959e19ace1f936d1fbd94ed166 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Mon, 1 Mar 2021 23:46:34 +0800 Subject: [PATCH 30/44] Update plugin --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index cab645b8..963b33f7 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ plugins { - id "architectury-plugin" version "3.0.91" + id "architectury-plugin" version "3.0.93" id "forgified-fabric-loom" version "0.6.72" apply false id "org.cadixdev.licenser" version "0.5.0" id "com.matthewprenger.cursegradle" version "1.4.0" apply false From 6cbafd06a758b9aa9d788224c9b0d799f0379fe4 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Sun, 7 Mar 2021 21:10:48 +0800 Subject: [PATCH 31/44] Add lightning strikes to the debug mod --- .../me/shedaniel/architectury/test/events/DebugEvents.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/testmod-common/src/main/java/me/shedaniel/architectury/test/events/DebugEvents.java b/testmod-common/src/main/java/me/shedaniel/architectury/test/events/DebugEvents.java index 752c1c07..fd391068 100644 --- a/testmod-common/src/main/java/me/shedaniel/architectury/test/events/DebugEvents.java +++ b/testmod-common/src/main/java/me/shedaniel/architectury/test/events/DebugEvents.java @@ -168,6 +168,9 @@ public class DebugEvents { PlayerEvent.CHANGE_DIMENSION.register((player, oldLevel, newLevel) -> { SINK.accept(player.getScoreboardName() + " switched from " + oldLevel.location() + " to " + newLevel.location() + logSide(player.level)); }); + LightningEvent.STRIKE.register((bolt, level, pos, toStrike) -> { + SINK.accept(bolt.getScoreboardName() + " struck at " + toShortString(pos) + logSide(level)); + }); } public static String toShortString(Vec3i pos) { From db1237448a718c5aa1acebef8f6f852c968ee79d Mon Sep 17 00:00:00 2001 From: shedaniel Date: Mon, 8 Mar 2021 01:16:37 +0800 Subject: [PATCH 32/44] Update plugins --- build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 963b33f7..b62d4c3d 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,6 @@ plugins { - id "architectury-plugin" version "3.0.93" - id "forgified-fabric-loom" version "0.6.72" apply false + id "architectury-plugin" version "3.0.97" + id "forgified-fabric-loom" version "0.6.78" apply false id "org.cadixdev.licenser" version "0.5.0" id "com.matthewprenger.cursegradle" version "1.4.0" apply false id "maven-publish" From 833d6014ea0a6bdaaacad604a4dd397613856856 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Thu, 11 Mar 2021 21:09:22 +0800 Subject: [PATCH 33/44] Rewrite the GuiEvent.SET_SCREEN mixin to fix #35 --- .../mixin/fabric/client/MixinMinecraft.java | 83 +++++-------------- .../architectury/test/events/DebugEvents.java | 13 ++- 2 files changed, 32 insertions(+), 64 deletions(-) diff --git a/fabric/src/main/java/me/shedaniel/architectury/mixin/fabric/client/MixinMinecraft.java b/fabric/src/main/java/me/shedaniel/architectury/mixin/fabric/client/MixinMinecraft.java index b1c5dd28..5e23ad17 100644 --- a/fabric/src/main/java/me/shedaniel/architectury/mixin/fabric/client/MixinMinecraft.java +++ b/fabric/src/main/java/me/shedaniel/architectury/mixin/fabric/client/MixinMinecraft.java @@ -23,40 +23,35 @@ import me.shedaniel.architectury.event.events.GuiEvent; import me.shedaniel.architectury.event.events.InteractionEvent; import me.shedaniel.architectury.event.events.client.ClientPlayerEvent; import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.screens.ConnectScreen; import net.minecraft.client.gui.screens.Screen; -import net.minecraft.client.gui.screens.TitleScreen; -import net.minecraft.client.main.GameConfig; import net.minecraft.client.player.LocalPlayer; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResultHolder; import net.minecraft.world.item.ItemStack; import net.minecraft.world.phys.HitResult; import org.jetbrains.annotations.Nullable; +import org.objectweb.asm.Opcodes; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Unique; -import org.spongepowered.asm.mixin.injection.*; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.ModifyVariable; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.LocalCapture; -import java.io.File; - @Unique @Mixin(Minecraft.class) public abstract class MixinMinecraft { - // @formatter:off @Shadow @Nullable public LocalPlayer player; - + @Shadow @Nullable public HitResult hitResult; - - @Shadow public abstract void setScreen(@Nullable Screen screen); - - private boolean setScreenCancelled; - - private String hostname; - private int port; - // @formatter:on + + @Shadow + public abstract void setScreen(@Nullable Screen screen); + + @Unique + private ThreadLocal setScreenCancelled = new ThreadLocal<>(); @Inject(method = "clearLevel(Lnet/minecraft/client/gui/screens/Screen;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/chat/NarratorChatListener;clear()V")) @@ -80,9 +75,9 @@ public abstract class MixinMinecraft { @ModifyVariable( method = "setScreen", at = @At(value = "INVOKE", - target = "Lnet/minecraft/client/player/LocalPlayer;respawn()V", - shift = At.Shift.BY, - by = 2), + target = "Lnet/minecraft/client/player/LocalPlayer;respawn()V", + shift = At.Shift.BY, + by = 2), argsOnly = true ) public Screen modifyScreen(Screen screen) { @@ -90,7 +85,7 @@ public abstract class MixinMinecraft { InteractionResultHolder event = GuiEvent.SET_SCREEN.invoker().modifyScreen(screen); switch (event.getResult()) { case FAIL: - setScreenCancelled = true; + setScreenCancelled.set(true); return old; case SUCCESS: screen = event.getObject(); @@ -98,56 +93,24 @@ public abstract class MixinMinecraft { old.removed(); } default: - setScreenCancelled = false; + setScreenCancelled.set(false); return screen; } } @Inject( method = "setScreen", - at = @At(value = "INVOKE", - target = "Lnet/minecraft/client/player/LocalPlayer;respawn()V", - shift = At.Shift.BY, - by = 3), + at = @At(value = "FIELD", + opcode = Opcodes.PUTFIELD, + target = "Lnet/minecraft/client/Minecraft;screen:Lnet/minecraft/client/gui/screens/Screen;", + shift = At.Shift.BY, + by = -1), cancellable = true ) public void cancelSetScreen(@Nullable Screen screen, CallbackInfo ci) { - if (setScreenCancelled) { + if (setScreenCancelled.get()) { ci.cancel(); - } - } - - @Redirect( - method = "", - at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Minecraft;setScreen(Lnet/minecraft/client/gui/screens/Screen;)V"), - slice = @Slice( - from = @At(value = "INVOKE", target = "Lnet/minecraft/client/Minecraft;resizeDisplay()V"), - to = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screens/LoadingOverlay;registerTextures(Lnet/minecraft/client/Minecraft;)V") - ) - ) - public void minecraftWhy(Minecraft mc, Screen screen) { - } - - @Inject( - method = "", - at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Minecraft;resizeDisplay()V"), - locals = LocalCapture.CAPTURE_FAILHARD - ) - public void saveLocals(GameConfig gc, CallbackInfo ci, File f, String string2, int j) { - hostname = string2; - port = j; - } - - @SuppressWarnings({"UnresolvedMixinReference", "ConstantConditions"}) - @Inject( - method = {"method_29338", "lambda$null$1"}, // .lambda$null$1 - at = @At("RETURN") - ) - public void registerMainScreens(CallbackInfo ci) { - if (hostname != null) { - setScreen(new ConnectScreen(new TitleScreen(), (Minecraft) ((Object) this), hostname, port)); - } else { - setScreen(new TitleScreen(true)); + setScreenCancelled.set(false); } } } diff --git a/testmod-common/src/main/java/me/shedaniel/architectury/test/events/DebugEvents.java b/testmod-common/src/main/java/me/shedaniel/architectury/test/events/DebugEvents.java index fd391068..8626510c 100644 --- a/testmod-common/src/main/java/me/shedaniel/architectury/test/events/DebugEvents.java +++ b/testmod-common/src/main/java/me/shedaniel/architectury/test/events/DebugEvents.java @@ -27,6 +27,7 @@ import me.shedaniel.architectury.platform.Platform; import me.shedaniel.architectury.utils.Env; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; +import net.minecraft.client.gui.screens.ChatScreen; import net.minecraft.core.Position; import net.minecraft.core.Vec3i; import net.minecraft.network.chat.TranslatableComponent; @@ -211,10 +212,6 @@ public class DebugEvents { ClientPlayerEvent.CLIENT_PLAYER_RESPAWN.register((oldPlayer, newPlayer) -> { SINK.accept(newPlayer.getScoreboardName() + " respawned (client)"); }); - GuiEvent.SET_SCREEN.register((screen -> { - SINK.accept("Screen has been changed to " + toSimpleName(screen)); - return InteractionResultHolder.pass(screen); - })); GuiEvent.INIT_PRE.register((screen, widgets, children) -> { SINK.accept(toSimpleName(screen) + " initializes"); return InteractionResult.PASS; @@ -271,6 +268,14 @@ public class DebugEvents { SINK.accept("Raw Key pressed: " + InputConstants.getKey(keyCode, scanCode).getDisplayName().getString()); return InteractionResult.PASS; }); + GuiEvent.SET_SCREEN.register(screen -> { + if (screen instanceof ChatScreen) { + return InteractionResultHolder.fail(screen); + } + + SINK.accept("Screen has been changed to " + toSimpleName(screen)); + return InteractionResultHolder.pass(screen); + }); } private static String toSimpleName(Object o) { From 389034e1ff6d2d1c1e8a46b2888de9d61d1ad485 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Thu, 11 Mar 2021 21:11:43 +0800 Subject: [PATCH 34/44] Change at --- .../architectury/mixin/fabric/client/MixinMinecraft.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/fabric/src/main/java/me/shedaniel/architectury/mixin/fabric/client/MixinMinecraft.java b/fabric/src/main/java/me/shedaniel/architectury/mixin/fabric/client/MixinMinecraft.java index 5e23ad17..a83c8f4c 100644 --- a/fabric/src/main/java/me/shedaniel/architectury/mixin/fabric/client/MixinMinecraft.java +++ b/fabric/src/main/java/me/shedaniel/architectury/mixin/fabric/client/MixinMinecraft.java @@ -74,10 +74,11 @@ public abstract class MixinMinecraft { @ModifyVariable( method = "setScreen", - at = @At(value = "INVOKE", - target = "Lnet/minecraft/client/player/LocalPlayer;respawn()V", + at = @At(value = "FIELD", + opcode = Opcodes.PUTFIELD, + target = "Lnet/minecraft/client/Minecraft;screen:Lnet/minecraft/client/gui/screens/Screen;", shift = At.Shift.BY, - by = 2), + by = -1), argsOnly = true ) public Screen modifyScreen(Screen screen) { From 47da69c510b3afc06dd78d59bcadde5e5a059849 Mon Sep 17 00:00:00 2001 From: Max Date: Tue, 16 Mar 2021 16:51:01 +0100 Subject: [PATCH 35/44] Bump to 1.9 This is to indicate possibly changed mod behaviour (e.g. with KubeJS UI) --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index f925bb87..9a08d0d1 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,7 +6,7 @@ supported_version=1.16.4/5 archives_base_name=architectury archives_base_name_snapshot=architectury-snapshot -base_version=1.8 +base_version=1.9 maven_group=me.shedaniel fabric_loader_version=0.11.1 From dd8c78c4482b782ab6b43342fc919812f77f14cb Mon Sep 17 00:00:00 2001 From: Max Date: Thu, 18 Mar 2021 15:41:22 +0100 Subject: [PATCH 36/44] Fix CLIENT_WORLD_LOAD on Forge --- .../architectury/event/forge/EventHandlerImplClient.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/forge/src/main/java/me/shedaniel/architectury/event/forge/EventHandlerImplClient.java b/forge/src/main/java/me/shedaniel/architectury/event/forge/EventHandlerImplClient.java index ac3eefc1..e353a385 100644 --- a/forge/src/main/java/me/shedaniel/architectury/event/forge/EventHandlerImplClient.java +++ b/forge/src/main/java/me/shedaniel/architectury/event/forge/EventHandlerImplClient.java @@ -118,8 +118,8 @@ public class EventHandlerImplClient { } @SubscribeEvent - public static void event(WorldEvent.Save event) { - if (event.getWorld() instanceof ClientLevel) { + public static void event(WorldEvent.Load event) { + if (event.getWorld().isClientSide()) { ClientLevel world = (ClientLevel) event.getWorld(); ClientLifecycleEvent.CLIENT_WORLD_LOAD.invoker().act(world); } From c8dd9061dbca7812ac128ca09a2d221498674bae Mon Sep 17 00:00:00 2001 From: Max Date: Thu, 18 Mar 2021 15:43:48 +0100 Subject: [PATCH 37/44] Migrate Forge ReloadListeners events to annotations --- .../registry/forge/ReloadListenersImpl.java | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/forge/src/main/java/me/shedaniel/architectury/registry/forge/ReloadListenersImpl.java b/forge/src/main/java/me/shedaniel/architectury/registry/forge/ReloadListenersImpl.java index 3a0a76f0..b1bc82b1 100644 --- a/forge/src/main/java/me/shedaniel/architectury/registry/forge/ReloadListenersImpl.java +++ b/forge/src/main/java/me/shedaniel/architectury/registry/forge/ReloadListenersImpl.java @@ -20,38 +20,40 @@ package me.shedaniel.architectury.registry.forge; import com.google.common.collect.Lists; +import me.shedaniel.architectury.forge.ArchitecturyForge; import net.minecraft.client.Minecraft; import net.minecraft.server.packs.PackType; import net.minecraft.server.packs.resources.PreparableReloadListener; import net.minecraft.server.packs.resources.ReloadableResourceManager; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; -import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.AddReloadListenerEvent; +import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.fml.common.Mod; import java.util.List; +@Mod.EventBusSubscriber(modid = ArchitecturyForge.MOD_ID) public class ReloadListenersImpl { private static List serverDataReloadListeners = Lists.newArrayList(); - static { - MinecraftForge.EVENT_BUS.addListener(event -> { - for (PreparableReloadListener listener : serverDataReloadListeners) { - event.addListener(listener); - } - }); - } - public static void registerReloadListener(PackType type, PreparableReloadListener listener) { if (type == PackType.SERVER_DATA) { serverDataReloadListeners.add(listener); } else if (type == PackType.CLIENT_RESOURCES) { - reloadClientReloadListener(listener); + registerClientReloadListener(listener); } } @OnlyIn(Dist.CLIENT) - private static void reloadClientReloadListener(PreparableReloadListener listener) { + private static void registerClientReloadListener(PreparableReloadListener listener) { ((ReloadableResourceManager) Minecraft.getInstance().getResourceManager()).registerReloadListener(listener); } + + @SubscribeEvent + public static void addReloadListeners(AddReloadListenerEvent event) { + for (PreparableReloadListener listener : serverDataReloadListeners) { + event.addListener(listener); + } + } } From e1cff1567b2ef0cbc776b157f7196a956eae90d7 Mon Sep 17 00:00:00 2001 From: Max Date: Thu, 18 Mar 2021 15:49:03 +0100 Subject: [PATCH 38/44] More annotation event migration --- .../forge/ClientNetworkingManager.java | 10 ++++- .../networking/forge/NetworkManagerImpl.java | 17 ++++++-- .../forge/BiomeModificationsImpl.java | 42 ++++++++++--------- 3 files changed, 44 insertions(+), 25 deletions(-) diff --git a/forge/src/main/java/me/shedaniel/architectury/networking/forge/ClientNetworkingManager.java b/forge/src/main/java/me/shedaniel/architectury/networking/forge/ClientNetworkingManager.java index a167beb5..e7ce2d31 100644 --- a/forge/src/main/java/me/shedaniel/architectury/networking/forge/ClientNetworkingManager.java +++ b/forge/src/main/java/me/shedaniel/architectury/networking/forge/ClientNetworkingManager.java @@ -27,6 +27,7 @@ import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.client.event.ClientPlayerNetworkEvent; import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.network.NetworkEvent; import java.util.Set; @@ -38,7 +39,7 @@ import static me.shedaniel.architectury.networking.forge.NetworkManagerImpl.SYNC public class ClientNetworkingManager { public static void initClient() { NetworkManagerImpl.CHANNEL.addListener(NetworkManagerImpl.createPacketHandler(NetworkEvent.ServerCustomPayloadEvent.class, NetworkManagerImpl.S2C)); - MinecraftForge.EVENT_BUS.addListener(event -> NetworkManagerImpl.serverReceivables.clear()); + MinecraftForge.EVENT_BUS.register(ClientNetworkingManager.class); NetworkManagerImpl.registerS2CReceiver(SYNC_IDS, (buffer, context) -> { Set receivables = NetworkManagerImpl.serverReceivables; @@ -54,4 +55,9 @@ public class ClientNetworkingManager { public static Player getClientPlayer() { return Minecraft.getInstance().player; } -} \ No newline at end of file + + @SubscribeEvent + public static void loggedOut(ClientPlayerNetworkEvent.LoggedOutEvent event) { + NetworkManagerImpl.serverReceivables.clear(); + } +} diff --git a/forge/src/main/java/me/shedaniel/architectury/networking/forge/NetworkManagerImpl.java b/forge/src/main/java/me/shedaniel/architectury/networking/forge/NetworkManagerImpl.java index b04c85db..54fe4ea8 100644 --- a/forge/src/main/java/me/shedaniel/architectury/networking/forge/NetworkManagerImpl.java +++ b/forge/src/main/java/me/shedaniel/architectury/networking/forge/NetworkManagerImpl.java @@ -22,6 +22,7 @@ package me.shedaniel.architectury.networking.forge; import com.google.common.collect.*; import io.netty.buffer.Unpooled; +import me.shedaniel.architectury.forge.ArchitecturyForge; import me.shedaniel.architectury.networking.NetworkManager; import me.shedaniel.architectury.networking.NetworkManager.NetworkReceiver; import me.shedaniel.architectury.utils.Env; @@ -34,8 +35,10 @@ import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.entity.player.PlayerEvent; +import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.DistExecutor; import net.minecraftforge.fml.LogicalSide; +import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.network.NetworkDirection; import net.minecraftforge.fml.network.NetworkEvent; import net.minecraftforge.fml.network.NetworkRegistry; @@ -49,6 +52,7 @@ import java.util.Map; import java.util.Set; import java.util.function.Consumer; +@Mod.EventBusSubscriber(modid = ArchitecturyForge.MOD_ID) public class NetworkManagerImpl { public static void registerReceiver(NetworkManager.Side side, ResourceLocation id, NetworkReceiver receiver) { if (side == NetworkManager.Side.C2S) { @@ -79,9 +83,6 @@ public class NetworkManagerImpl { DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> ClientNetworkingManager::initClient); - MinecraftForge.EVENT_BUS.addListener(event -> NetworkManager.sendToPlayer((ServerPlayer) event.getPlayer(), SYNC_IDS, sendSyncPacket(C2S))); - MinecraftForge.EVENT_BUS.addListener(event -> clientReceivables.removeAll(event.getPlayer())); - registerC2SReceiver(SYNC_IDS, (buffer, context) -> { Set receivables = (Set) clientReceivables.get(context.getPlayer()); int size = buffer.readInt(); @@ -157,4 +158,14 @@ public class NetworkManagerImpl { } return packetBuffer; } + + @SubscribeEvent + public static void loggedIn(PlayerEvent.PlayerLoggedInEvent event) { + NetworkManager.sendToPlayer((ServerPlayer) event.getPlayer(), SYNC_IDS, sendSyncPacket(C2S)); + } + + @SubscribeEvent + public static void loggedOut(PlayerEvent.PlayerLoggedOutEvent event) { + clientReceivables.removeAll(event.getPlayer()); + } } diff --git a/forge/src/main/java/me/shedaniel/architectury/registry/forge/BiomeModificationsImpl.java b/forge/src/main/java/me/shedaniel/architectury/registry/forge/BiomeModificationsImpl.java index a5891b66..95c68bba 100644 --- a/forge/src/main/java/me/shedaniel/architectury/registry/forge/BiomeModificationsImpl.java +++ b/forge/src/main/java/me/shedaniel/architectury/registry/forge/BiomeModificationsImpl.java @@ -20,6 +20,7 @@ package me.shedaniel.architectury.registry.forge; import com.google.common.collect.Lists; +import me.shedaniel.architectury.forge.ArchitecturyForge; import me.shedaniel.architectury.hooks.biome.*; import me.shedaniel.architectury.mixin.forge.BiomeGenerationSettingsBuilderAccessor; import me.shedaniel.architectury.mixin.forge.MobSpawnSettingsBuilderAccessor; @@ -34,10 +35,11 @@ import net.minecraft.world.level.levelgen.carver.ConfiguredWorldCarver; import net.minecraft.world.level.levelgen.feature.ConfiguredFeature; import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature; import net.minecraft.world.level.levelgen.surfacebuilders.ConfiguredSurfaceBuilder; -import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.world.BiomeGenerationSettingsBuilder; import net.minecraftforge.common.world.MobSpawnInfoBuilder; import net.minecraftforge.event.world.BiomeLoadingEvent; +import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.fml.common.Mod; import org.apache.commons.lang3.tuple.Pair; import org.jetbrains.annotations.NotNull; @@ -49,6 +51,7 @@ import java.util.function.BiPredicate; import java.util.function.Predicate; import java.util.function.Supplier; +@Mod.EventBusSubscriber(modid = ArchitecturyForge.MOD_ID) public class BiomeModificationsImpl { private static final List, BiConsumer>> MODIFICATIONS = Lists.newArrayList(); @@ -68,25 +71,6 @@ public class BiomeModificationsImpl { MODIFICATIONS.add(Pair.of(predicate, modifier)); } - static { - MinecraftForge.EVENT_BUS.addListener(event -> { - BiomeContext biomeContext = wrapSelectionContext(event); - BiomeProperties.Mutable mutableBiome = new MutableBiomeWrapped(event); - for (Pair, BiConsumer> pair : MODIFICATIONS) { - if (pair.getLeft().test(biomeContext)) { - pair.getRight().accept(biomeContext, mutableBiome); - } - } - MutableClimatePropertiesWrapped climateProperties = (MutableClimatePropertiesWrapped) mutableBiome.getClimateProperties(); - if (climateProperties.dirty) { - event.setClimate(new Biome.ClimateSettings(climateProperties.precipitation, - climateProperties.temperature, - climateProperties.temperatureModifier, - climateProperties.downfall)); - } - }); - } - private static BiomeContext wrapSelectionContext(BiomeLoadingEvent event) { return new BiomeContext() { BiomeProperties properties = new BiomeWrapped(event); @@ -446,4 +430,22 @@ public class BiomeModificationsImpl { return this; } } + + @SubscribeEvent + public static void onBiomeLoading(BiomeLoadingEvent event) { + BiomeContext biomeContext = wrapSelectionContext(event); + BiomeProperties.Mutable mutableBiome = new MutableBiomeWrapped(event); + for (Pair, BiConsumer> pair : MODIFICATIONS) { + if (pair.getLeft().test(biomeContext)) { + pair.getRight().accept(biomeContext, mutableBiome); + } + } + MutableClimatePropertiesWrapped climateProperties = (MutableClimatePropertiesWrapped) mutableBiome.getClimateProperties(); + if (climateProperties.dirty) { + event.setClimate(new Biome.ClimateSettings(climateProperties.precipitation, + climateProperties.temperature, + climateProperties.temperatureModifier, + climateProperties.downfall)); + } + } } From 3dcad1e8a1525a60fa16d84256191d7bc6590719 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Sat, 20 Mar 2021 15:10:43 +0800 Subject: [PATCH 39/44] Fix Forge Screen Events to be consistent with the fabric implementation: InteractionResult.SUCCESS should also indicate that the event should be cancelled. --- .../event/forge/EventHandlerImplClient.java | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/forge/src/main/java/me/shedaniel/architectury/event/forge/EventHandlerImplClient.java b/forge/src/main/java/me/shedaniel/architectury/event/forge/EventHandlerImplClient.java index e353a385..f78f6867 100644 --- a/forge/src/main/java/me/shedaniel/architectury/event/forge/EventHandlerImplClient.java +++ b/forge/src/main/java/me/shedaniel/architectury/event/forge/EventHandlerImplClient.java @@ -81,7 +81,7 @@ public class EventHandlerImplClient { @SubscribeEvent public static void event(GuiScreenEvent.InitGuiEvent.Pre event) { - if (GuiEvent.INIT_PRE.invoker().init(event.getGui(), event.getWidgetList(), (List) event.getGui().children()) == InteractionResult.FAIL) { + if (GuiEvent.INIT_PRE.invoker().init(event.getGui(), event.getWidgetList(), (List) event.getGui().children()) != InteractionResult.PASS) { event.setCanceled(true); } } @@ -139,7 +139,7 @@ public class EventHandlerImplClient { @SubscribeEvent public static void event(GuiScreenEvent.DrawScreenEvent.Pre event) { - if (GuiEvent.RENDER_PRE.invoker().render(event.getGui(), event.getMatrixStack(), event.getMouseX(), event.getMouseY(), event.getRenderPartialTicks()) == InteractionResult.FAIL) { + if (GuiEvent.RENDER_PRE.invoker().render(event.getGui(), event.getMatrixStack(), event.getMouseX(), event.getMouseY(), event.getRenderPartialTicks()) != InteractionResult.PASS) { event.setCanceled(true); } } @@ -196,7 +196,7 @@ public class EventHandlerImplClient { @SubscribeEvent public static void event(GuiScreenEvent.MouseScrollEvent.Pre event) { - if (ClientScreenInputEvent.MOUSE_SCROLLED_PRE.invoker().mouseScrolled(Minecraft.getInstance(), event.getGui(), event.getMouseX(), event.getMouseY(), event.getScrollDelta()) == InteractionResult.FAIL) { + if (ClientScreenInputEvent.MOUSE_SCROLLED_PRE.invoker().mouseScrolled(Minecraft.getInstance(), event.getGui(), event.getMouseX(), event.getMouseY(), event.getScrollDelta()) != InteractionResult.PASS) { event.setCanceled(true); } } @@ -208,7 +208,7 @@ public class EventHandlerImplClient { @SubscribeEvent public static void event(GuiScreenEvent.MouseClickedEvent.Pre event) { - if (ClientScreenInputEvent.MOUSE_CLICKED_PRE.invoker().mouseClicked(Minecraft.getInstance(), event.getGui(), event.getMouseX(), event.getMouseY(), event.getButton()) == InteractionResult.FAIL) { + if (ClientScreenInputEvent.MOUSE_CLICKED_PRE.invoker().mouseClicked(Minecraft.getInstance(), event.getGui(), event.getMouseX(), event.getMouseY(), event.getButton()) != InteractionResult.PASS) { event.setCanceled(true); } } @@ -220,7 +220,7 @@ public class EventHandlerImplClient { @SubscribeEvent public static void event(GuiScreenEvent.MouseDragEvent.Pre event) { - if (ClientScreenInputEvent.MOUSE_DRAGGED_PRE.invoker().mouseDragged(Minecraft.getInstance(), event.getGui(), event.getMouseX(), event.getMouseY(), event.getMouseButton(), event.getDragX(), event.getDragY()) == InteractionResult.FAIL) { + if (ClientScreenInputEvent.MOUSE_DRAGGED_PRE.invoker().mouseDragged(Minecraft.getInstance(), event.getGui(), event.getMouseX(), event.getMouseY(), event.getMouseButton(), event.getDragX(), event.getDragY()) != InteractionResult.PASS) { event.setCanceled(true); } } @@ -232,7 +232,7 @@ public class EventHandlerImplClient { @SubscribeEvent public static void event(GuiScreenEvent.MouseReleasedEvent.Pre event) { - if (ClientScreenInputEvent.MOUSE_RELEASED_PRE.invoker().mouseReleased(Minecraft.getInstance(), event.getGui(), event.getMouseX(), event.getMouseY(), event.getButton()) == InteractionResult.FAIL) { + if (ClientScreenInputEvent.MOUSE_RELEASED_PRE.invoker().mouseReleased(Minecraft.getInstance(), event.getGui(), event.getMouseX(), event.getMouseY(), event.getButton()) != InteractionResult.PASS) { event.setCanceled(true); } } @@ -244,7 +244,7 @@ public class EventHandlerImplClient { @SubscribeEvent public static void event(GuiScreenEvent.KeyboardCharTypedEvent.Pre event) { - if (ClientScreenInputEvent.CHAR_TYPED_PRE.invoker().charTyped(Minecraft.getInstance(), event.getGui(), event.getCodePoint(), event.getModifiers()) == InteractionResult.FAIL) { + if (ClientScreenInputEvent.CHAR_TYPED_PRE.invoker().charTyped(Minecraft.getInstance(), event.getGui(), event.getCodePoint(), event.getModifiers()) != InteractionResult.PASS) { event.setCanceled(true); } } @@ -256,7 +256,7 @@ public class EventHandlerImplClient { @SubscribeEvent public static void event(GuiScreenEvent.KeyboardKeyPressedEvent.Pre event) { - if (ClientScreenInputEvent.KEY_PRESSED_PRE.invoker().keyPressed(Minecraft.getInstance(), event.getGui(), event.getKeyCode(), event.getScanCode(), event.getModifiers()) == InteractionResult.FAIL) { + if (ClientScreenInputEvent.KEY_PRESSED_PRE.invoker().keyPressed(Minecraft.getInstance(), event.getGui(), event.getKeyCode(), event.getScanCode(), event.getModifiers()) != InteractionResult.PASS) { event.setCanceled(true); } } @@ -268,7 +268,7 @@ public class EventHandlerImplClient { @SubscribeEvent public static void event(GuiScreenEvent.KeyboardKeyReleasedEvent.Pre event) { - if (ClientScreenInputEvent.KEY_RELEASED_PRE.invoker().keyReleased(Minecraft.getInstance(), event.getGui(), event.getKeyCode(), event.getScanCode(), event.getModifiers()) == InteractionResult.FAIL) { + if (ClientScreenInputEvent.KEY_RELEASED_PRE.invoker().keyReleased(Minecraft.getInstance(), event.getGui(), event.getKeyCode(), event.getScanCode(), event.getModifiers()) != InteractionResult.PASS) { event.setCanceled(true); } } @@ -280,14 +280,14 @@ public class EventHandlerImplClient { @SubscribeEvent public static void event(InputEvent.MouseScrollEvent event) { - if (ClientRawInputEvent.MOUSE_SCROLLED.invoker().mouseScrolled(Minecraft.getInstance(), event.getScrollDelta()) == InteractionResult.FAIL) { + if (ClientRawInputEvent.MOUSE_SCROLLED.invoker().mouseScrolled(Minecraft.getInstance(), event.getScrollDelta()) != InteractionResult.PASS) { event.setCanceled(true); } } @SubscribeEvent public static void event(InputEvent.RawMouseEvent event) { - if (ClientRawInputEvent.MOUSE_CLICKED_PRE.invoker().mouseClicked(Minecraft.getInstance(), event.getButton(), event.getAction(), event.getMods()) == InteractionResult.FAIL) { + if (ClientRawInputEvent.MOUSE_CLICKED_PRE.invoker().mouseClicked(Minecraft.getInstance(), event.getButton(), event.getAction(), event.getMods()) != InteractionResult.PASS) { event.setCanceled(true); } } From aee0af27f401b9cf4257cdf02fe8d58b57d77f4c Mon Sep 17 00:00:00 2001 From: shedaniel Date: Thu, 18 Mar 2021 23:33:26 +0800 Subject: [PATCH 40/44] Remove addListener from ColorHandlersImpl --- .../registry/forge/ColorHandlersImpl.java | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/forge/src/main/java/me/shedaniel/architectury/registry/forge/ColorHandlersImpl.java b/forge/src/main/java/me/shedaniel/architectury/registry/forge/ColorHandlersImpl.java index 44dfa3d2..0abb94a4 100644 --- a/forge/src/main/java/me/shedaniel/architectury/registry/forge/ColorHandlersImpl.java +++ b/forge/src/main/java/me/shedaniel/architectury/registry/forge/ColorHandlersImpl.java @@ -40,19 +40,22 @@ public class ColorHandlersImpl { static { EventBuses.onRegistered(ArchitecturyForge.MOD_ID, bus -> { - bus.addListener(event -> { - for (Pair[]> pair : ITEM_COLORS) { - event.getItemColors().register(pair.getLeft(), unpackItems(pair.getRight())); - } - }); - bus.addListener(event -> { - for (Pair[]> pair : BLOCK_COLORS) { - event.getBlockColors().register(pair.getLeft(), unpackBlocks(pair.getRight())); - } - }); + bus.register(ColorHandlersImpl.class); }); } + public static void onItemColorEvent(ColorHandlerEvent.Item event) { + for (Pair[]> pair : ITEM_COLORS) { + event.getItemColors().register(pair.getLeft(), unpackItems(pair.getRight())); + } + } + + public static void onBlockColorEvent(ColorHandlerEvent.Block event) { + for (Pair[]> pair : BLOCK_COLORS) { + event.getBlockColors().register(pair.getLeft(), unpackBlocks(pair.getRight())); + } + } + @SafeVarargs public static void registerItemColors(ItemColor itemColor, Supplier... items) { Objects.requireNonNull(itemColor, "color is null!"); From f904c1de2e1c7a73a5eaf23e1b44c448715f19a7 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Sat, 20 Mar 2021 15:42:00 +0800 Subject: [PATCH 41/44] Add @SubscribeEvent to ColorHandlersImpl --- .../architectury/registry/forge/ColorHandlersImpl.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/forge/src/main/java/me/shedaniel/architectury/registry/forge/ColorHandlersImpl.java b/forge/src/main/java/me/shedaniel/architectury/registry/forge/ColorHandlersImpl.java index 0abb94a4..2e234347 100644 --- a/forge/src/main/java/me/shedaniel/architectury/registry/forge/ColorHandlersImpl.java +++ b/forge/src/main/java/me/shedaniel/architectury/registry/forge/ColorHandlersImpl.java @@ -28,6 +28,7 @@ import net.minecraft.client.color.item.ItemColor; import net.minecraft.world.level.ItemLike; import net.minecraft.world.level.block.Block; import net.minecraftforge.client.event.ColorHandlerEvent; +import net.minecraftforge.eventbus.api.SubscribeEvent; import org.apache.commons.lang3.tuple.Pair; import java.util.List; @@ -44,12 +45,14 @@ public class ColorHandlersImpl { }); } + @SubscribeEvent public static void onItemColorEvent(ColorHandlerEvent.Item event) { for (Pair[]> pair : ITEM_COLORS) { event.getItemColors().register(pair.getLeft(), unpackItems(pair.getRight())); } } + @SubscribeEvent public static void onBlockColorEvent(ColorHandlerEvent.Block event) { for (Pair[]> pair : BLOCK_COLORS) { event.getBlockColors().register(pair.getLeft(), unpackBlocks(pair.getRight())); From 28d986a3ccb0df54aab9e8bf0b791e757d9e54c8 Mon Sep 17 00:00:00 2001 From: Max Date: Sun, 21 Mar 2021 20:20:25 +0100 Subject: [PATCH 42/44] Add EntityHooks.fromCollision to retrieve an entity from block collision (#64) --- .../architectury/hooks/EntityHooks.java | 8 ++ .../hooks/fabric/EntityHooksImpl.java | 14 +++ .../mixin/fabric/MixinCollisionContext.java | 9 ++ .../fabric/MixinEntityCollisionContext.java | 32 +++++++ .../main/resources/architectury.mixins.json | 88 ++++++++++--------- .../hooks/forge/EntityHooksImpl.java | 7 ++ gradle.properties | 2 +- .../test/registry/TestRegistries.java | 19 ++++ 8 files changed, 135 insertions(+), 44 deletions(-) create mode 100644 fabric/src/main/java/me/shedaniel/architectury/mixin/fabric/MixinCollisionContext.java create mode 100644 fabric/src/main/java/me/shedaniel/architectury/mixin/fabric/MixinEntityCollisionContext.java diff --git a/common/src/main/java/me/shedaniel/architectury/hooks/EntityHooks.java b/common/src/main/java/me/shedaniel/architectury/hooks/EntityHooks.java index b28c74cd..96dcff38 100644 --- a/common/src/main/java/me/shedaniel/architectury/hooks/EntityHooks.java +++ b/common/src/main/java/me/shedaniel/architectury/hooks/EntityHooks.java @@ -21,6 +21,8 @@ package me.shedaniel.architectury.hooks; import me.shedaniel.architectury.annotations.ExpectPlatform; import net.minecraft.world.entity.Entity; +import net.minecraft.world.phys.shapes.CollisionContext; +import org.jetbrains.annotations.Nullable; public final class EntityHooks { private EntityHooks() {} @@ -29,4 +31,10 @@ public final class EntityHooks { public static String getEncodeId(Entity entity) { throw new AssertionError(); } + + @Nullable + @ExpectPlatform + public static Entity fromCollision(CollisionContext ctx) { + throw new AssertionError(); + } } diff --git a/fabric/src/main/java/me/shedaniel/architectury/hooks/fabric/EntityHooksImpl.java b/fabric/src/main/java/me/shedaniel/architectury/hooks/fabric/EntityHooksImpl.java index dffe86af..39739848 100644 --- a/fabric/src/main/java/me/shedaniel/architectury/hooks/fabric/EntityHooksImpl.java +++ b/fabric/src/main/java/me/shedaniel/architectury/hooks/fabric/EntityHooksImpl.java @@ -20,9 +20,23 @@ package me.shedaniel.architectury.hooks.fabric; import net.minecraft.world.entity.Entity; +import net.minecraft.world.phys.shapes.CollisionContext; +import org.jetbrains.annotations.Nullable; public class EntityHooksImpl { public static String getEncodeId(Entity entity) { return entity.getEncodeId(); } + + @Nullable + public static Entity fromCollision(CollisionContext ctx) { + return ((CollisionContextExtension) ctx).getEntity(); + } + + public interface CollisionContextExtension { + @Nullable + default Entity getEntity() { + return null; + } + } } diff --git a/fabric/src/main/java/me/shedaniel/architectury/mixin/fabric/MixinCollisionContext.java b/fabric/src/main/java/me/shedaniel/architectury/mixin/fabric/MixinCollisionContext.java new file mode 100644 index 00000000..cb79fb48 --- /dev/null +++ b/fabric/src/main/java/me/shedaniel/architectury/mixin/fabric/MixinCollisionContext.java @@ -0,0 +1,9 @@ +package me.shedaniel.architectury.mixin.fabric; + +import me.shedaniel.architectury.hooks.fabric.EntityHooksImpl; +import net.minecraft.world.phys.shapes.CollisionContext; +import org.spongepowered.asm.mixin.Mixin; + +@Mixin(CollisionContext.class) +public interface MixinCollisionContext extends EntityHooksImpl.CollisionContextExtension { +} diff --git a/fabric/src/main/java/me/shedaniel/architectury/mixin/fabric/MixinEntityCollisionContext.java b/fabric/src/main/java/me/shedaniel/architectury/mixin/fabric/MixinEntityCollisionContext.java new file mode 100644 index 00000000..ed51c31c --- /dev/null +++ b/fabric/src/main/java/me/shedaniel/architectury/mixin/fabric/MixinEntityCollisionContext.java @@ -0,0 +1,32 @@ +package me.shedaniel.architectury.mixin.fabric; + +import me.shedaniel.architectury.hooks.fabric.EntityHooksImpl; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.phys.shapes.CollisionContext; +import net.minecraft.world.phys.shapes.EntityCollisionContext; +import org.jetbrains.annotations.Nullable; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(EntityCollisionContext.class) +public abstract class MixinEntityCollisionContext implements CollisionContext, EntityHooksImpl.CollisionContextExtension { + + @Unique + private Entity entity = null; + + @Inject(method = "(Lnet/minecraft/world/entity/Entity;)V", + at = @At("RETURN")) + public void saveEntity(Entity entity, CallbackInfo ci) { + this.entity = entity; + } + + @Nullable + @Override + public Entity getEntity() { + return entity; + } + +} diff --git a/fabric/src/main/resources/architectury.mixins.json b/fabric/src/main/resources/architectury.mixins.json index 09801fd6..f7607c32 100644 --- a/fabric/src/main/resources/architectury.mixins.json +++ b/fabric/src/main/resources/architectury.mixins.json @@ -1,46 +1,48 @@ { - "required": true, - "package": "me.shedaniel.architectury.mixin.fabric", - "plugin": "me.shedaniel.architectury.plugin.fabric.ArchitecturyMixinPlugin", - "compatibilityLevel": "JAVA_8", - "minVersion": "0.7.11", - "client": [ - "client.MixinClientLevel", - "client.MixinClientPacketListener", - "client.MixinDebugScreenOverlay", - "client.MixinEffectInstance", - "client.MixinGameRenderer", - "client.MixinIntegratedServer", - "client.MixinKeyboardHandler", - "client.MixinMinecraft", - "client.MixinMouseHandler", - "client.MixinMultiPlayerGameMode", - "client.MixinScreen", - "client.MixinTextureAtlas" - ], - "mixins": [ - "ExplosionPreInvoker", - "LivingDeathInvoker", - "MixinBlockEntityExtension", - "MixinBlockItem", - "MixinCommands", - "MixinDedicatedServer", - "MixinExplosion", - "MixinFurnaceResultSlot", - "MixinItemEntity", - "MixinLivingEntity", - "MixinPlayer", - "MixinPlayerAdvancements", - "MixinPlayerList", - "MixinResultSlot", - "MixinServerGamePacketListenerImpl", - "MixinServerLevel", - "MixinServerPlayer", - "MixinServerPlayerGameMode", - "PlayerAttackInvoker" - ], - "injectors": { - "maxShiftBy": 5, - "defaultRequire": 1 + "required": true, + "package": "me.shedaniel.architectury.mixin.fabric", + "plugin": "me.shedaniel.architectury.plugin.fabric.ArchitecturyMixinPlugin", + "compatibilityLevel": "JAVA_8", + "minVersion": "0.7.11", + "client": [ + "client.MixinClientLevel", + "client.MixinClientPacketListener", + "client.MixinDebugScreenOverlay", + "client.MixinEffectInstance", + "client.MixinGameRenderer", + "client.MixinIntegratedServer", + "client.MixinKeyboardHandler", + "client.MixinMinecraft", + "client.MixinMouseHandler", + "client.MixinMultiPlayerGameMode", + "client.MixinScreen", + "client.MixinTextureAtlas" + ], + "mixins": [ + "ExplosionPreInvoker", + "LivingDeathInvoker", + "MixinBlockEntityExtension", + "MixinBlockItem", + "MixinCollisionContext", + "MixinCommands", + "MixinDedicatedServer", + "MixinEntityCollisionContext", + "MixinExplosion", + "MixinFurnaceResultSlot", + "MixinItemEntity", + "MixinLivingEntity", + "MixinPlayer", + "MixinPlayerAdvancements", + "MixinPlayerList", + "MixinResultSlot", + "MixinServerGamePacketListenerImpl", + "MixinServerLevel", + "MixinServerPlayer", + "MixinServerPlayerGameMode", + "PlayerAttackInvoker" + ], + "injectors": { + "maxShiftBy": 5, + "defaultRequire": 1 } } diff --git a/forge/src/main/java/me/shedaniel/architectury/hooks/forge/EntityHooksImpl.java b/forge/src/main/java/me/shedaniel/architectury/hooks/forge/EntityHooksImpl.java index 469894a6..def8695c 100644 --- a/forge/src/main/java/me/shedaniel/architectury/hooks/forge/EntityHooksImpl.java +++ b/forge/src/main/java/me/shedaniel/architectury/hooks/forge/EntityHooksImpl.java @@ -20,9 +20,16 @@ package me.shedaniel.architectury.hooks.forge; import net.minecraft.world.entity.Entity; +import net.minecraft.world.phys.shapes.CollisionContext; +import org.jetbrains.annotations.Nullable; public class EntityHooksImpl { public static String getEncodeId(Entity entity) { return entity.getEncodeId(); } + + @Nullable + public static Entity fromCollision(CollisionContext ctx) { + return ctx.getEntity(); + } } diff --git a/gradle.properties b/gradle.properties index 9a08d0d1..3883f2a8 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,7 +6,7 @@ supported_version=1.16.4/5 archives_base_name=architectury archives_base_name_snapshot=architectury-snapshot -base_version=1.9 +base_version=1.10 maven_group=me.shedaniel fabric_loader_version=0.11.1 diff --git a/testmod-common/src/main/java/me/shedaniel/architectury/test/registry/TestRegistries.java b/testmod-common/src/main/java/me/shedaniel/architectury/test/registry/TestRegistries.java index 57a817d7..a0d789c6 100644 --- a/testmod-common/src/main/java/me/shedaniel/architectury/test/registry/TestRegistries.java +++ b/testmod-common/src/main/java/me/shedaniel/architectury/test/registry/TestRegistries.java @@ -19,16 +19,24 @@ package me.shedaniel.architectury.test.registry; +import me.shedaniel.architectury.hooks.EntityHooks; import me.shedaniel.architectury.registry.BlockProperties; import me.shedaniel.architectury.registry.DeferredRegister; import me.shedaniel.architectury.registry.RegistrySupplier; import me.shedaniel.architectury.test.TestMod; import me.shedaniel.architectury.test.tab.TestCreativeTabs; +import net.minecraft.core.BlockPos; import net.minecraft.core.Registry; import net.minecraft.world.item.BlockItem; import net.minecraft.world.item.Item; +import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.phys.shapes.CollisionContext; +import net.minecraft.world.phys.shapes.VoxelShape; + +import static me.shedaniel.architectury.test.TestMod.SINK; public class TestRegistries { public static final DeferredRegister ITEMS = DeferredRegister.create(TestMod.MOD_ID, Registry.ITEM_REGISTRY); @@ -39,8 +47,19 @@ public class TestRegistries { public static final RegistrySupplier TEST_BLOCK = BLOCKS.register("test_block", () -> new Block(BlockProperties.copy(Blocks.STONE))); + public static final RegistrySupplier COLLISION_BLOCK = BLOCKS.register("collision_block", () -> + new Block(BlockProperties.copy(Blocks.STONE)) { + @Override + public VoxelShape getCollisionShape(BlockState state, BlockGetter bg, BlockPos pos, CollisionContext ctx) { + SINK.accept(EntityHooks.fromCollision(ctx) + " is colliding with " + state); + return super.getCollisionShape(state, bg, pos, ctx); + } + }); + public static final RegistrySupplier TEST_BLOCK_ITEM = ITEMS.register("test_block", () -> new BlockItem(TEST_BLOCK.get(), new Item.Properties().tab(TestCreativeTabs.TEST_TAB))); + public static final RegistrySupplier COLLISION_BLOCK_ITEM = ITEMS.register("collision_block", () -> + new BlockItem(COLLISION_BLOCK.get(), new Item.Properties().tab(TestCreativeTabs.TEST_TAB))); public static void initialize() { BLOCKS.register(); From 9fb19f96051be4b18f94352fd5ec434fddeab8ee Mon Sep 17 00:00:00 2001 From: Max Date: Mon, 22 Mar 2021 22:24:32 +0100 Subject: [PATCH 43/44] Bump forge event priority to HIGH My reasoning for this lies in the quirk that Forge by default cancels all following event listeners when one of them fails with an Exception. Because we are an API that mods need to be able to rely on, and this may cause cascading issues with mods that depend on us down the line (see https://github.com/KubeJS-Mods/KubeJS/issues/101), I think we should act on HIGH priority by default to reduce the risk of this happening --- .../event/forge/EventHandlerImplClient.java | 83 ++++++++++--------- .../event/forge/EventHandlerImplCommon.java | 77 ++++++++--------- 2 files changed, 81 insertions(+), 79 deletions(-) diff --git a/forge/src/main/java/me/shedaniel/architectury/event/forge/EventHandlerImplClient.java b/forge/src/main/java/me/shedaniel/architectury/event/forge/EventHandlerImplClient.java index f78f6867..76627c45 100644 --- a/forge/src/main/java/me/shedaniel/architectury/event/forge/EventHandlerImplClient.java +++ b/forge/src/main/java/me/shedaniel/architectury/event/forge/EventHandlerImplClient.java @@ -38,6 +38,7 @@ import net.minecraftforge.client.event.*; import net.minecraftforge.event.entity.player.ItemTooltipEvent; import net.minecraftforge.event.entity.player.PlayerInteractEvent; import net.minecraftforge.event.world.WorldEvent; +import net.minecraftforge.eventbus.api.EventPriority; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; @@ -45,12 +46,12 @@ import java.util.List; @OnlyIn(Dist.CLIENT) public class EventHandlerImplClient { - @SubscribeEvent + @SubscribeEvent(priority = EventPriority.HIGH) public static void event(ItemTooltipEvent event) { TooltipEvent.ITEM.invoker().append(event.getItemStack(), event.getToolTip(), event.getFlags()); } - @SubscribeEvent + @SubscribeEvent(priority = EventPriority.HIGH) public static void event(net.minecraftforge.event.TickEvent.ClientTickEvent event) { if (event.phase == net.minecraftforge.event.TickEvent.Phase.START) ClientTickEvent.CLIENT_PRE.invoker().tick(Minecraft.getInstance()); @@ -58,40 +59,40 @@ public class EventHandlerImplClient { ClientTickEvent.CLIENT_POST.invoker().tick(Minecraft.getInstance()); } - @SubscribeEvent + @SubscribeEvent(priority = EventPriority.HIGH) public static void event(RenderGameOverlayEvent.Post event) { if (event.getType() == RenderGameOverlayEvent.ElementType.ALL) GuiEvent.RENDER_HUD.invoker().renderHud(event.getMatrixStack(), event.getPartialTicks()); } - @SubscribeEvent + @SubscribeEvent(priority = EventPriority.HIGH) public static void event(ClientPlayerNetworkEvent.LoggedInEvent event) { ClientPlayerEvent.CLIENT_PLAYER_JOIN.invoker().join(event.getPlayer()); } - @SubscribeEvent + @SubscribeEvent(priority = EventPriority.HIGH) public static void event(ClientPlayerNetworkEvent.LoggedOutEvent event) { ClientPlayerEvent.CLIENT_PLAYER_QUIT.invoker().quit(event.getPlayer()); } - @SubscribeEvent + @SubscribeEvent(priority = EventPriority.HIGH) public static void event(ClientPlayerNetworkEvent.RespawnEvent event) { ClientPlayerEvent.CLIENT_PLAYER_RESPAWN.invoker().respawn(event.getOldPlayer(), event.getNewPlayer()); } - @SubscribeEvent + @SubscribeEvent(priority = EventPriority.HIGH) public static void event(GuiScreenEvent.InitGuiEvent.Pre event) { if (GuiEvent.INIT_PRE.invoker().init(event.getGui(), event.getWidgetList(), (List) event.getGui().children()) != InteractionResult.PASS) { event.setCanceled(true); } } - @SubscribeEvent + @SubscribeEvent(priority = EventPriority.HIGH) public static void event(GuiScreenEvent.InitGuiEvent.Post event) { GuiEvent.INIT_POST.invoker().init(event.getGui(), event.getWidgetList(), (List) event.getGui().children()); } - @SubscribeEvent + @SubscribeEvent(priority = EventPriority.HIGH) public static void event(RenderGameOverlayEvent.Text event) { if (Minecraft.getInstance().options.renderDebug) { GuiEvent.DEBUG_TEXT_LEFT.invoker().gatherText(event.getLeft()); @@ -99,7 +100,7 @@ public class EventHandlerImplClient { } } - @SubscribeEvent + @SubscribeEvent(priority = EventPriority.HIGH) public static void event(net.minecraftforge.client.event.ClientChatEvent event) { InteractionResultHolder process = ClientChatEvent.CLIENT.invoker().process(event.getMessage()); if (process.getObject() != null) @@ -108,7 +109,7 @@ public class EventHandlerImplClient { event.setCanceled(true); } - @SubscribeEvent + @SubscribeEvent(priority = EventPriority.HIGH) public static void event(ClientChatReceivedEvent event) { InteractionResultHolder process = ClientChatEvent.CLIENT_RECEIVED.invoker().process(event.getType(), event.getMessage(), event.getSenderUUID()); if (process.getObject() != null) @@ -117,7 +118,7 @@ public class EventHandlerImplClient { event.setCanceled(true); } - @SubscribeEvent + @SubscribeEvent(priority = EventPriority.HIGH) public static void event(WorldEvent.Load event) { if (event.getWorld().isClientSide()) { ClientLevel world = (ClientLevel) event.getWorld(); @@ -125,7 +126,7 @@ public class EventHandlerImplClient { } } - @SubscribeEvent + @SubscribeEvent(priority = EventPriority.HIGH) public static void event(GuiOpenEvent event) { InteractionResultHolder result = GuiEvent.SET_SCREEN.invoker().modifyScreen(event.getGui()); switch (result.getResult()) { @@ -137,29 +138,29 @@ public class EventHandlerImplClient { } } - @SubscribeEvent + @SubscribeEvent(priority = EventPriority.HIGH) public static void event(GuiScreenEvent.DrawScreenEvent.Pre event) { if (GuiEvent.RENDER_PRE.invoker().render(event.getGui(), event.getMatrixStack(), event.getMouseX(), event.getMouseY(), event.getRenderPartialTicks()) != InteractionResult.PASS) { event.setCanceled(true); } } - @SubscribeEvent + @SubscribeEvent(priority = EventPriority.HIGH) public static void event(GuiScreenEvent.DrawScreenEvent.Post event) { GuiEvent.RENDER_POST.invoker().render(event.getGui(), event.getMatrixStack(), event.getMouseX(), event.getMouseY(), event.getRenderPartialTicks()); } - @SubscribeEvent + @SubscribeEvent(priority = EventPriority.HIGH) public static void event(PlayerInteractEvent.RightClickEmpty event) { InteractionEvent.CLIENT_RIGHT_CLICK_AIR.invoker().click(event.getPlayer(), event.getHand()); } - @SubscribeEvent + @SubscribeEvent(priority = EventPriority.HIGH) public static void event(PlayerInteractEvent.LeftClickEmpty event) { InteractionEvent.CLIENT_LEFT_CLICK_AIR.invoker().click(event.getPlayer(), event.getHand()); } - @SubscribeEvent + @SubscribeEvent(priority = EventPriority.HIGH) public static void event(RecipesUpdatedEvent event) { RecipeUpdateEvent.EVENT.invoker().update(event.getRecipeManager()); } @@ -167,7 +168,7 @@ public class EventHandlerImplClient { private static final ThreadLocal tooltipColorContext = ThreadLocal.withInitial(TooltipEventColorContextImpl::new); private static final ThreadLocal tooltipPositionContext = ThreadLocal.withInitial(TooltipEventPositionContextImpl::new); - @SubscribeEvent + @SubscribeEvent(priority = EventPriority.HIGH) public static void event(RenderTooltipEvent.Pre event) { if (TooltipEvent.RENDER_FORGE_PRE.invoker().renderTooltip(event.getMatrixStack(), event.getLines(), event.getX(), event.getY()) == InteractionResult.FAIL) { event.setCanceled(true); @@ -181,7 +182,7 @@ public class EventHandlerImplClient { event.setY(positionContext.getTooltipY()); } - @SubscribeEvent + @SubscribeEvent(priority = EventPriority.HIGH) public static void event(RenderTooltipEvent.Color event) { TooltipEventColorContextImpl colorContext = tooltipColorContext.get(); colorContext.reset(); @@ -194,127 +195,127 @@ public class EventHandlerImplClient { event.setBorderStart(colorContext.getOutlineGradientTopColor()); } - @SubscribeEvent + @SubscribeEvent(priority = EventPriority.HIGH) public static void event(GuiScreenEvent.MouseScrollEvent.Pre event) { if (ClientScreenInputEvent.MOUSE_SCROLLED_PRE.invoker().mouseScrolled(Minecraft.getInstance(), event.getGui(), event.getMouseX(), event.getMouseY(), event.getScrollDelta()) != InteractionResult.PASS) { event.setCanceled(true); } } - @SubscribeEvent + @SubscribeEvent(priority = EventPriority.HIGH) public static void event(GuiScreenEvent.MouseScrollEvent.Post event) { ClientScreenInputEvent.MOUSE_SCROLLED_POST.invoker().mouseScrolled(Minecraft.getInstance(), event.getGui(), event.getMouseX(), event.getMouseY(), event.getScrollDelta()); } - @SubscribeEvent + @SubscribeEvent(priority = EventPriority.HIGH) public static void event(GuiScreenEvent.MouseClickedEvent.Pre event) { if (ClientScreenInputEvent.MOUSE_CLICKED_PRE.invoker().mouseClicked(Minecraft.getInstance(), event.getGui(), event.getMouseX(), event.getMouseY(), event.getButton()) != InteractionResult.PASS) { event.setCanceled(true); } } - @SubscribeEvent + @SubscribeEvent(priority = EventPriority.HIGH) public static void event(GuiScreenEvent.MouseClickedEvent.Post event) { ClientScreenInputEvent.MOUSE_CLICKED_POST.invoker().mouseClicked(Minecraft.getInstance(), event.getGui(), event.getMouseX(), event.getMouseY(), event.getButton()); } - @SubscribeEvent + @SubscribeEvent(priority = EventPriority.HIGH) public static void event(GuiScreenEvent.MouseDragEvent.Pre event) { if (ClientScreenInputEvent.MOUSE_DRAGGED_PRE.invoker().mouseDragged(Minecraft.getInstance(), event.getGui(), event.getMouseX(), event.getMouseY(), event.getMouseButton(), event.getDragX(), event.getDragY()) != InteractionResult.PASS) { event.setCanceled(true); } } - @SubscribeEvent + @SubscribeEvent(priority = EventPriority.HIGH) public static void event(GuiScreenEvent.MouseDragEvent.Post event) { ClientScreenInputEvent.MOUSE_DRAGGED_POST.invoker().mouseDragged(Minecraft.getInstance(), event.getGui(), event.getMouseX(), event.getMouseY(), event.getMouseButton(), event.getDragX(), event.getDragY()); } - @SubscribeEvent + @SubscribeEvent(priority = EventPriority.HIGH) public static void event(GuiScreenEvent.MouseReleasedEvent.Pre event) { if (ClientScreenInputEvent.MOUSE_RELEASED_PRE.invoker().mouseReleased(Minecraft.getInstance(), event.getGui(), event.getMouseX(), event.getMouseY(), event.getButton()) != InteractionResult.PASS) { event.setCanceled(true); } } - @SubscribeEvent + @SubscribeEvent(priority = EventPriority.HIGH) public static void event(GuiScreenEvent.MouseReleasedEvent.Post event) { ClientScreenInputEvent.MOUSE_RELEASED_PRE.invoker().mouseReleased(Minecraft.getInstance(), event.getGui(), event.getMouseX(), event.getMouseY(), event.getButton()); } - @SubscribeEvent + @SubscribeEvent(priority = EventPriority.HIGH) public static void event(GuiScreenEvent.KeyboardCharTypedEvent.Pre event) { if (ClientScreenInputEvent.CHAR_TYPED_PRE.invoker().charTyped(Minecraft.getInstance(), event.getGui(), event.getCodePoint(), event.getModifiers()) != InteractionResult.PASS) { event.setCanceled(true); } } - @SubscribeEvent + @SubscribeEvent(priority = EventPriority.HIGH) public static void event(GuiScreenEvent.KeyboardCharTypedEvent.Post event) { ClientScreenInputEvent.CHAR_TYPED_POST.invoker().charTyped(Minecraft.getInstance(), event.getGui(), event.getCodePoint(), event.getModifiers()); } - @SubscribeEvent + @SubscribeEvent(priority = EventPriority.HIGH) public static void event(GuiScreenEvent.KeyboardKeyPressedEvent.Pre event) { if (ClientScreenInputEvent.KEY_PRESSED_PRE.invoker().keyPressed(Minecraft.getInstance(), event.getGui(), event.getKeyCode(), event.getScanCode(), event.getModifiers()) != InteractionResult.PASS) { event.setCanceled(true); } } - @SubscribeEvent + @SubscribeEvent(priority = EventPriority.HIGH) public static void event(GuiScreenEvent.KeyboardKeyPressedEvent.Post event) { ClientScreenInputEvent.KEY_PRESSED_POST.invoker().keyPressed(Minecraft.getInstance(), event.getGui(), event.getKeyCode(), event.getScanCode(), event.getModifiers()); } - @SubscribeEvent + @SubscribeEvent(priority = EventPriority.HIGH) public static void event(GuiScreenEvent.KeyboardKeyReleasedEvent.Pre event) { if (ClientScreenInputEvent.KEY_RELEASED_PRE.invoker().keyReleased(Minecraft.getInstance(), event.getGui(), event.getKeyCode(), event.getScanCode(), event.getModifiers()) != InteractionResult.PASS) { event.setCanceled(true); } } - @SubscribeEvent + @SubscribeEvent(priority = EventPriority.HIGH) public static void event(GuiScreenEvent.KeyboardKeyReleasedEvent.Post event) { ClientScreenInputEvent.KEY_RELEASED_POST.invoker().keyReleased(Minecraft.getInstance(), event.getGui(), event.getKeyCode(), event.getScanCode(), event.getModifiers()); } - @SubscribeEvent + @SubscribeEvent(priority = EventPriority.HIGH) public static void event(InputEvent.MouseScrollEvent event) { if (ClientRawInputEvent.MOUSE_SCROLLED.invoker().mouseScrolled(Minecraft.getInstance(), event.getScrollDelta()) != InteractionResult.PASS) { event.setCanceled(true); } } - @SubscribeEvent + @SubscribeEvent(priority = EventPriority.HIGH) public static void event(InputEvent.RawMouseEvent event) { if (ClientRawInputEvent.MOUSE_CLICKED_PRE.invoker().mouseClicked(Minecraft.getInstance(), event.getButton(), event.getAction(), event.getMods()) != InteractionResult.PASS) { event.setCanceled(true); } } - @SubscribeEvent + @SubscribeEvent(priority = EventPriority.HIGH) public static void event(InputEvent.MouseInputEvent event) { ClientRawInputEvent.MOUSE_CLICKED_POST.invoker().mouseClicked(Minecraft.getInstance(), event.getButton(), event.getAction(), event.getMods()); } - @SubscribeEvent + @SubscribeEvent(priority = EventPriority.HIGH) public static void event(InputEvent.KeyInputEvent event) { ClientRawInputEvent.KEY_PRESSED.invoker().keyPressed(Minecraft.getInstance(), event.getKey(), event.getScanCode(), event.getAction(), event.getModifiers()); } @OnlyIn(Dist.CLIENT) public static class ModBasedEventHandler { - @SubscribeEvent + @SubscribeEvent(priority = EventPriority.HIGH) public static void event(net.minecraftforge.client.event.TextureStitchEvent.Pre event) { TextureStitchEvent.PRE.invoker().stitch(event.getMap(), event::addSprite); } - @SubscribeEvent + @SubscribeEvent(priority = EventPriority.HIGH) public static void event(net.minecraftforge.client.event.TextureStitchEvent.Post event) { TextureStitchEvent.POST.invoker().stitch(event.getMap()); } - @SubscribeEvent + @SubscribeEvent(priority = EventPriority.HIGH) public static void event(FMLClientSetupEvent event) { ClientLifecycleEvent.CLIENT_SETUP.invoker().stateChanged(event.getMinecraftSupplier().get()); } diff --git a/forge/src/main/java/me/shedaniel/architectury/event/forge/EventHandlerImplCommon.java b/forge/src/main/java/me/shedaniel/architectury/event/forge/EventHandlerImplCommon.java index 33c3c019..e3c98f7f 100644 --- a/forge/src/main/java/me/shedaniel/architectury/event/forge/EventHandlerImplCommon.java +++ b/forge/src/main/java/me/shedaniel/architectury/event/forge/EventHandlerImplCommon.java @@ -50,13 +50,14 @@ import net.minecraftforge.event.world.ExplosionEvent.Detonate; import net.minecraftforge.event.world.ExplosionEvent.Start; import net.minecraftforge.event.world.WorldEvent; import net.minecraftforge.eventbus.api.Event; +import net.minecraftforge.eventbus.api.EventPriority; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.LogicalSide; import net.minecraftforge.fml.event.server.*; import net.minecraftforge.fml.server.ServerLifecycleHooks; public class EventHandlerImplCommon { - @SubscribeEvent + @SubscribeEvent(priority = EventPriority.HIGH) public static void event(ServerTickEvent event) { if (event.phase == Phase.START) TickEvent.SERVER_PRE.invoker().tick(ServerLifecycleHooks.getCurrentServer()); @@ -64,7 +65,7 @@ public class EventHandlerImplCommon { TickEvent.SERVER_POST.invoker().tick(ServerLifecycleHooks.getCurrentServer()); } - @SubscribeEvent + @SubscribeEvent(priority = EventPriority.HIGH) public static void event(WorldTickEvent event) { if (event.side == LogicalSide.SERVER) { if (event.phase == Phase.START) @@ -74,47 +75,47 @@ public class EventHandlerImplCommon { } } - @SubscribeEvent + @SubscribeEvent(priority = EventPriority.HIGH) public static void event(FMLServerStartingEvent event) { LifecycleEvent.SERVER_STARTING.invoker().stateChanged(event.getServer()); } - @SubscribeEvent + @SubscribeEvent(priority = EventPriority.HIGH) public static void event(FMLServerStartedEvent event) { LifecycleEvent.SERVER_STARTED.invoker().stateChanged(event.getServer()); } - @SubscribeEvent + @SubscribeEvent(priority = EventPriority.HIGH) public static void event(FMLServerStoppingEvent event) { LifecycleEvent.SERVER_STOPPING.invoker().stateChanged(event.getServer()); } - @SubscribeEvent + @SubscribeEvent(priority = EventPriority.HIGH) public static void event(FMLServerStoppedEvent event) { LifecycleEvent.SERVER_STOPPED.invoker().stateChanged(event.getServer()); } - @SubscribeEvent + @SubscribeEvent(priority = EventPriority.HIGH) public static void event(RegisterCommandsEvent event) { CommandRegistrationEvent.EVENT.invoker().register(event.getDispatcher(), event.getEnvironment()); } - @SubscribeEvent + @SubscribeEvent(priority = EventPriority.HIGH) public static void event(PlayerLoggedInEvent event) { PlayerEvent.PLAYER_JOIN.invoker().join((ServerPlayer) event.getPlayer()); } - @SubscribeEvent + @SubscribeEvent(priority = EventPriority.HIGH) public static void event(PlayerLoggedOutEvent event) { PlayerEvent.PLAYER_QUIT.invoker().quit((ServerPlayer) event.getPlayer()); } - @SubscribeEvent + @SubscribeEvent(priority = EventPriority.HIGH) public static void event(PlayerRespawnEvent event) { PlayerEvent.PLAYER_RESPAWN.invoker().respawn((ServerPlayer) event.getPlayer(), event.isEndConquered()); } - @SubscribeEvent + @SubscribeEvent(priority = EventPriority.HIGH) public static void event(CommandEvent event) { CommandPerformEvent performEvent = new CommandPerformEvent(event.getParseResults(), event.getException()); if (CommandPerformEvent.EVENT.invoker().act(performEvent) == InteractionResult.FAIL) { @@ -124,7 +125,7 @@ public class EventHandlerImplCommon { event.setException(performEvent.getThrowable()); } - @SubscribeEvent + @SubscribeEvent(priority = EventPriority.HIGH) public static void event(PlayerTickEvent event) { if (event.phase == Phase.START) { TickEvent.PLAYER_PRE.invoker().tick(event.player); @@ -133,7 +134,7 @@ public class EventHandlerImplCommon { } } - @SubscribeEvent + @SubscribeEvent(priority = EventPriority.HIGH) public static void event(ServerChatEvent event) { InteractionResultHolder process = ChatEvent.SERVER.invoker().process(event.getPlayer(), event.getMessage(), event.getComponent()); if (process.getObject() != null) @@ -142,7 +143,7 @@ public class EventHandlerImplCommon { event.setCanceled(true); } - @SubscribeEvent + @SubscribeEvent(priority = EventPriority.HIGH) public static void event(WorldEvent.Load event) { if (event.getWorld() instanceof ServerLevel) { ServerLevel world = (ServerLevel) event.getWorld(); @@ -150,7 +151,7 @@ public class EventHandlerImplCommon { } } - @SubscribeEvent + @SubscribeEvent(priority = EventPriority.HIGH) public static void event(WorldEvent.Unload event) { if (event.getWorld() instanceof ServerLevel) { ServerLevel world = (ServerLevel) event.getWorld(); @@ -158,7 +159,7 @@ public class EventHandlerImplCommon { } } - @SubscribeEvent + @SubscribeEvent(priority = EventPriority.HIGH) public static void event(WorldEvent.Save event) { if (event.getWorld() instanceof ServerLevel) { ServerLevel world = (ServerLevel) event.getWorld(); @@ -166,89 +167,89 @@ public class EventHandlerImplCommon { } } - @SubscribeEvent + @SubscribeEvent(priority = EventPriority.HIGH) public static void event(LivingDeathEvent event) { if (EntityEvent.LIVING_DEATH.invoker().die(event.getEntityLiving(), event.getSource()) == InteractionResult.FAIL) { event.setCanceled(true); } } - @SubscribeEvent + @SubscribeEvent(priority = EventPriority.HIGH) public static void event(AdvancementEvent event) { if (event.getPlayer() instanceof ServerPlayer) { PlayerEvent.PLAYER_ADVANCEMENT.invoker().award((ServerPlayer) event.getPlayer(), event.getAdvancement()); } } - @SubscribeEvent + @SubscribeEvent(priority = EventPriority.HIGH) public static void event(Clone event) { if (event.getOriginal() instanceof ServerPlayer && event.getPlayer() instanceof ServerPlayer) { PlayerEvent.PLAYER_CLONE.invoker().clone((ServerPlayer) event.getOriginal(), (ServerPlayer) event.getPlayer(), !event.isWasDeath()); } } - @SubscribeEvent + @SubscribeEvent(priority = EventPriority.HIGH) public static void event(Start event) { if (ExplosionEvent.PRE.invoker().explode(event.getWorld(), event.getExplosion()) == InteractionResult.FAIL) { event.setCanceled(true); } } - @SubscribeEvent + @SubscribeEvent(priority = EventPriority.HIGH) public static void event(Detonate event) { ExplosionEvent.DETONATE.invoker().explode(event.getWorld(), event.getExplosion(), event.getAffectedEntities()); } - @SubscribeEvent + @SubscribeEvent(priority = EventPriority.HIGH) public static void event(LivingAttackEvent event) { if (EntityEvent.LIVING_ATTACK.invoker().attack(event.getEntityLiving(), event.getSource(), event.getAmount()) == InteractionResult.FAIL) { event.setCanceled(true); } } - @SubscribeEvent + @SubscribeEvent(priority = EventPriority.HIGH) public static void event(EntityJoinWorldEvent event) { if (EntityEvent.ADD.invoker().add(event.getEntity(), event.getWorld()) == InteractionResult.FAIL) { event.setCanceled(true); } } - @SubscribeEvent + @SubscribeEvent(priority = EventPriority.HIGH) public static void event(ItemCraftedEvent event) { PlayerEvent.CRAFT_ITEM.invoker().craft(event.getPlayer(), event.getCrafting(), event.getInventory()); } - @SubscribeEvent + @SubscribeEvent(priority = EventPriority.HIGH) public static void event(ItemSmeltedEvent event) { PlayerEvent.SMELT_ITEM.invoker().smelt(event.getPlayer(), event.getSmelting()); } - @SubscribeEvent + @SubscribeEvent(priority = EventPriority.HIGH) public static void event(EntityItemPickupEvent event) { PlayerEvent.PICKUP_ITEM_PRE.invoker().canPickup(event.getPlayer(), event.getItem(), event.getItem().getItem()); } - @SubscribeEvent + @SubscribeEvent(priority = EventPriority.HIGH) public static void event(ItemPickupEvent event) { PlayerEvent.PICKUP_ITEM_POST.invoker().pickup(event.getPlayer(), event.getOriginalEntity(), event.getStack()); } - @SubscribeEvent + @SubscribeEvent(priority = EventPriority.HIGH) public static void event(ItemTossEvent event) { PlayerEvent.DROP_ITEM.invoker().drop(event.getPlayer(), event.getEntityItem()); } - @SubscribeEvent + @SubscribeEvent(priority = EventPriority.HIGH) public static void event(PlayerContainerEvent.Open event) { PlayerEvent.OPEN_MENU.invoker().open(event.getPlayer(), event.getContainer()); } - @SubscribeEvent + @SubscribeEvent(priority = EventPriority.HIGH) public static void event(PlayerContainerEvent.Close event) { PlayerEvent.CLOSE_MENU.invoker().close(event.getPlayer(), event.getContainer()); } - @SubscribeEvent + @SubscribeEvent(priority = EventPriority.HIGH) public static void event(PlayerInteractEvent.RightClickItem event) { InteractionResultHolder result = InteractionEvent.RIGHT_CLICK_ITEM.invoker().click(event.getPlayer(), event.getHand()); if (result.getResult() != InteractionResult.PASS) { @@ -257,7 +258,7 @@ public class EventHandlerImplCommon { } } - @SubscribeEvent + @SubscribeEvent(priority = EventPriority.HIGH) public static void event(PlayerInteractEvent.RightClickBlock event) { InteractionResult result = InteractionEvent.RIGHT_CLICK_BLOCK.invoker().click(event.getPlayer(), event.getHand(), event.getPos(), event.getFace()); if (result != InteractionResult.PASS) { @@ -268,7 +269,7 @@ public class EventHandlerImplCommon { } } - @SubscribeEvent + @SubscribeEvent(priority = EventPriority.HIGH) public static void event(PlayerInteractEvent.EntityInteract event) { InteractionResult result = InteractionEvent.INTERACT_ENTITY.invoker().interact(event.getPlayer(), event.getTarget(), event.getHand()); if (result != InteractionResult.PASS) { @@ -277,7 +278,7 @@ public class EventHandlerImplCommon { } } - @SubscribeEvent + @SubscribeEvent(priority = EventPriority.HIGH) public static void event(PlayerInteractEvent.LeftClickBlock event) { InteractionResult result = InteractionEvent.LEFT_CLICK_BLOCK.invoker().click(event.getPlayer(), event.getHand(), event.getPos(), event.getFace()); if (result != InteractionResult.PASS) { @@ -288,7 +289,7 @@ public class EventHandlerImplCommon { } } - @SubscribeEvent + @SubscribeEvent(priority = EventPriority.HIGH) public static void event(BreakEvent event) { if (event.getPlayer() instanceof ServerPlayer && event.getWorld() instanceof Level) { InteractionResult result = BlockEvent.BREAK.invoker().breakBlock((Level) event.getWorld(), event.getPos(), event.getState(), (ServerPlayer) event.getPlayer(), new IntValue() { @@ -308,7 +309,7 @@ public class EventHandlerImplCommon { } } - @SubscribeEvent + @SubscribeEvent(priority = EventPriority.HIGH) public static void event(EntityPlaceEvent event) { if (event.getWorld() instanceof Level) { InteractionResult result = BlockEvent.PLACE.invoker().placeBlock((Level) event.getWorld(), event.getPos(), event.getState(), event.getEntity()); @@ -318,12 +319,12 @@ public class EventHandlerImplCommon { } } - @SubscribeEvent + @SubscribeEvent(priority = EventPriority.HIGH) public static void event(FMLServerAboutToStartEvent event) { LifecycleEvent.SERVER_BEFORE_START.invoker().stateChanged(event.getServer()); } - @SubscribeEvent + @SubscribeEvent(priority = EventPriority.HIGH) public static void event(PlayerChangedDimensionEvent event) { if (event.getPlayer() instanceof ServerPlayer) { PlayerEvent.CHANGE_DIMENSION.invoker().change((ServerPlayer) event.getPlayer(), event.getFrom(), event.getTo()); From 2af34feb2a49a5ab00d9b5cd8e3997c99bae53d8 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Tue, 30 Mar 2021 01:19:43 +0800 Subject: [PATCH 44/44] Fix invalid events --- .../java/me/shedaniel/architectury/event/EventFactory.java | 2 +- .../shedaniel/architectury/event/events/ExplosionEvent.java | 2 +- .../java/me/shedaniel/architectury/event/events/GuiEvent.java | 2 +- .../me/shedaniel/architectury/event/events/TooltipEvent.java | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/common/src/main/java/me/shedaniel/architectury/event/EventFactory.java b/common/src/main/java/me/shedaniel/architectury/event/EventFactory.java index e054b55c..fca87718 100644 --- a/common/src/main/java/me/shedaniel/architectury/event/EventFactory.java +++ b/common/src/main/java/me/shedaniel/architectury/event/EventFactory.java @@ -89,7 +89,7 @@ public final class EventFactory { @Override protected Object handleInvocation(@NotNull Object proxy, @NotNull Method method, Object @NotNull [] args) throws Throwable { for (T listener : listeners) { - InteractionResult result = (InteractionResult) method.invoke(listener, args); + InteractionResult result = (InteractionResult) Objects.requireNonNull(method.invoke(listener, args)); if (result != InteractionResult.PASS) { return result; } diff --git a/common/src/main/java/me/shedaniel/architectury/event/events/ExplosionEvent.java b/common/src/main/java/me/shedaniel/architectury/event/events/ExplosionEvent.java index 38bc9e9c..9a2699bc 100644 --- a/common/src/main/java/me/shedaniel/architectury/event/events/ExplosionEvent.java +++ b/common/src/main/java/me/shedaniel/architectury/event/events/ExplosionEvent.java @@ -30,7 +30,7 @@ import java.util.List; public interface ExplosionEvent { Event
 PRE = EventFactory.createInteractionResult();
-    Event DETONATE = EventFactory.createInteractionResult();
+    Event DETONATE = EventFactory.createLoop();
     
     interface Pre {
         InteractionResult explode(Level world, Explosion explosion);
diff --git a/common/src/main/java/me/shedaniel/architectury/event/events/GuiEvent.java b/common/src/main/java/me/shedaniel/architectury/event/events/GuiEvent.java
index e8a61a92..9a7863f5 100644
--- a/common/src/main/java/me/shedaniel/architectury/event/events/GuiEvent.java
+++ b/common/src/main/java/me/shedaniel/architectury/event/events/GuiEvent.java
@@ -49,7 +49,7 @@ public interface GuiEvent {
      */
     Event INIT_POST = EventFactory.createLoop();
     Event RENDER_PRE = EventFactory.createInteractionResult();
-    Event RENDER_POST = EventFactory.createInteractionResult();
+    Event RENDER_POST = EventFactory.createLoop();
     
     /**
      * Invoked during Minecraft#setScreen, equivalent to forge's {@code GuiOpenEvent}.
diff --git a/common/src/main/java/me/shedaniel/architectury/event/events/TooltipEvent.java b/common/src/main/java/me/shedaniel/architectury/event/events/TooltipEvent.java
index 673994e0..8a492439 100644
--- a/common/src/main/java/me/shedaniel/architectury/event/events/TooltipEvent.java
+++ b/common/src/main/java/me/shedaniel/architectury/event/events/TooltipEvent.java
@@ -44,8 +44,8 @@ public interface TooltipEvent {
      * Render forge events are only invoked on the forge side.
      */
     Event RENDER_FORGE_PRE = EventFactory.createInteractionResult();
-    Event RENDER_MODIFY_POSITION = EventFactory.createInteractionResult();
-    Event RENDER_MODIFY_COLOR = EventFactory.createInteractionResult();
+    Event RENDER_MODIFY_POSITION = EventFactory.createLoop();
+    Event RENDER_MODIFY_COLOR = EventFactory.createLoop();
     
     @Environment(EnvType.CLIENT)
     interface Item {