From 6b7848bea0b01c360dba2279bd0ec8eaf4cd5290 Mon Sep 17 00:00:00 2001 From: asie Date: Thu, 7 Feb 2019 10:55:14 +0100 Subject: [PATCH] more cleanup --- ...java => ClientSpriteRegistryCallback.java} | 8 ++-- .../api/event/player/AttackBlockCallback.java | 1 + .../event/player/AttackEntityCallback.java | 1 + .../api/event/player/UseBlockCallback.java | 1 + .../api/event/player/UseEntityCallback.java | 1 + .../api/event/player/UseItemCallback.java | 1 + ...ack.java => BlockConstructedCallback.java} | 6 +-- ...back.java => ItemConstructedCallback.java} | 6 +-- .../fabric/events/PlayerInteractionEvent.java | 38 ------------------- .../fabric/impl/tools/ToolManager.java | 4 +- .../texture/MixinSpriteAtlasTexture.java | 9 ++--- .../events/objectbuilder/MixinBlock.java | 4 +- .../mixin/events/objectbuilder/MixinItem.java | 4 +- 13 files changed, 24 insertions(+), 60 deletions(-) rename src/main/java/net/fabricmc/fabric/api/event/client/{SpriteRegistrationCallback.java => ClientSpriteRegistryCallback.java} (87%) rename src/main/java/net/fabricmc/fabric/api/event/registry/{BlockBuildingCallback.java => BlockConstructedCallback.java} (81%) rename src/main/java/net/fabricmc/fabric/api/event/registry/{ItemBuildingCallback.java => ItemConstructedCallback.java} (81%) delete mode 100644 src/main/java/net/fabricmc/fabric/events/PlayerInteractionEvent.java diff --git a/src/main/java/net/fabricmc/fabric/api/event/client/SpriteRegistrationCallback.java b/src/main/java/net/fabricmc/fabric/api/event/client/ClientSpriteRegistryCallback.java similarity index 87% rename from src/main/java/net/fabricmc/fabric/api/event/client/SpriteRegistrationCallback.java rename to src/main/java/net/fabricmc/fabric/api/event/client/ClientSpriteRegistryCallback.java index ff2a1ad52..ddbef9ce8 100644 --- a/src/main/java/net/fabricmc/fabric/api/event/client/SpriteRegistrationCallback.java +++ b/src/main/java/net/fabricmc/fabric/api/event/client/ClientSpriteRegistryCallback.java @@ -26,10 +26,10 @@ import net.minecraft.util.Identifier; import java.util.Map; import java.util.function.Consumer; -public interface SpriteRegistrationCallback { - public static final Event EVENT = EventFactory.arrayBacked(SpriteRegistrationCallback.class, +public interface ClientSpriteRegistryCallback { + public static final Event EVENT = EventFactory.arrayBacked(ClientSpriteRegistryCallback.class, (listeners) -> (atlasTexture, registry) -> { - for (SpriteRegistrationCallback callback : listeners) { + for (ClientSpriteRegistryCallback callback : listeners) { callback.registerSprites(atlasTexture, registry); } } @@ -37,7 +37,7 @@ public interface SpriteRegistrationCallback { void registerSprites(SpriteAtlasTexture atlasTexture, Registry registry); - static void registerBlockAtlas(SpriteRegistrationCallback callback) { + static void registerBlockAtlas(ClientSpriteRegistryCallback callback) { EVENT.register((atlasTexture, registry) -> { if (atlasTexture == MinecraftClient.getInstance().getSpriteAtlas()) { callback.registerSprites(atlasTexture, registry); diff --git a/src/main/java/net/fabricmc/fabric/api/event/player/AttackBlockCallback.java b/src/main/java/net/fabricmc/fabric/api/event/player/AttackBlockCallback.java index 6a7a5331d..9d91e48f8 100644 --- a/src/main/java/net/fabricmc/fabric/api/event/player/AttackBlockCallback.java +++ b/src/main/java/net/fabricmc/fabric/api/event/player/AttackBlockCallback.java @@ -27,6 +27,7 @@ import net.minecraft.world.World; /** * Callback for left-clicking ("attacking") a block. + * Is hooked in before the spectator check, so make sure to check for the player's game mode as well! * * Upon return: * - SUCCESS cancels further processing and, on the client, sends a packet to the server. diff --git a/src/main/java/net/fabricmc/fabric/api/event/player/AttackEntityCallback.java b/src/main/java/net/fabricmc/fabric/api/event/player/AttackEntityCallback.java index 9605d80d0..e835b3e86 100644 --- a/src/main/java/net/fabricmc/fabric/api/event/player/AttackEntityCallback.java +++ b/src/main/java/net/fabricmc/fabric/api/event/player/AttackEntityCallback.java @@ -27,6 +27,7 @@ import net.minecraft.world.World; /** * Callback for left-clicking ("attacking") an entity. + * Is hooked in before the spectator check, so make sure to check for the player's game mode as well! * * Upon return: * - SUCCESS cancels further processing and, on the client, sends a packet to the server. diff --git a/src/main/java/net/fabricmc/fabric/api/event/player/UseBlockCallback.java b/src/main/java/net/fabricmc/fabric/api/event/player/UseBlockCallback.java index 316822a3e..cb737cdaa 100644 --- a/src/main/java/net/fabricmc/fabric/api/event/player/UseBlockCallback.java +++ b/src/main/java/net/fabricmc/fabric/api/event/player/UseBlockCallback.java @@ -28,6 +28,7 @@ import net.minecraft.world.World; /** * Callback for right-clicking ("using") a block. + * Is hooked in before the spectator check, so make sure to check for the player's game mode as well! * * Upon return: * - SUCCESS cancels further processing and, on the client, sends a packet to the server. diff --git a/src/main/java/net/fabricmc/fabric/api/event/player/UseEntityCallback.java b/src/main/java/net/fabricmc/fabric/api/event/player/UseEntityCallback.java index be7bab648..83f4305c4 100644 --- a/src/main/java/net/fabricmc/fabric/api/event/player/UseEntityCallback.java +++ b/src/main/java/net/fabricmc/fabric/api/event/player/UseEntityCallback.java @@ -27,6 +27,7 @@ import net.minecraft.world.World; /** * Callback for right-clicking ("using") an entity. + * Is hooked in before the spectator check, so make sure to check for the player's game mode as well! * * Upon return: * - SUCCESS cancels further processing and, on the client, sends a packet to the server. diff --git a/src/main/java/net/fabricmc/fabric/api/event/player/UseItemCallback.java b/src/main/java/net/fabricmc/fabric/api/event/player/UseItemCallback.java index 0820f44db..c7a7bb28b 100644 --- a/src/main/java/net/fabricmc/fabric/api/event/player/UseItemCallback.java +++ b/src/main/java/net/fabricmc/fabric/api/event/player/UseItemCallback.java @@ -25,6 +25,7 @@ import net.minecraft.world.World; /** * Callback for right-clicking ("using") an item. + * Is hooked in before the spectator check, so make sure to check for the player's game mode as well! * * Upon return: * - SUCCESS cancels further processing and, on the client, sends a packet to the server. diff --git a/src/main/java/net/fabricmc/fabric/api/event/registry/BlockBuildingCallback.java b/src/main/java/net/fabricmc/fabric/api/event/registry/BlockConstructedCallback.java similarity index 81% rename from src/main/java/net/fabricmc/fabric/api/event/registry/BlockBuildingCallback.java rename to src/main/java/net/fabricmc/fabric/api/event/registry/BlockConstructedCallback.java index 2e19ba5fc..f1b8c5a88 100644 --- a/src/main/java/net/fabricmc/fabric/api/event/registry/BlockBuildingCallback.java +++ b/src/main/java/net/fabricmc/fabric/api/event/registry/BlockConstructedCallback.java @@ -20,10 +20,10 @@ import net.fabricmc.fabric.api.event.Event; import net.fabricmc.fabric.api.event.EventFactory; import net.minecraft.block.Block; -public interface BlockBuildingCallback { - public static Event EVENT = EventFactory.arrayBacked(BlockBuildingCallback.class, +public interface BlockConstructedCallback { + public static Event EVENT = EventFactory.arrayBacked(BlockConstructedCallback.class, (listeners) -> (settings, builtBlock) -> { - for (BlockBuildingCallback callback : listeners) { + for (BlockConstructedCallback callback : listeners) { callback.building(settings, builtBlock); } } diff --git a/src/main/java/net/fabricmc/fabric/api/event/registry/ItemBuildingCallback.java b/src/main/java/net/fabricmc/fabric/api/event/registry/ItemConstructedCallback.java similarity index 81% rename from src/main/java/net/fabricmc/fabric/api/event/registry/ItemBuildingCallback.java rename to src/main/java/net/fabricmc/fabric/api/event/registry/ItemConstructedCallback.java index 0da3b675e..766e81f62 100644 --- a/src/main/java/net/fabricmc/fabric/api/event/registry/ItemBuildingCallback.java +++ b/src/main/java/net/fabricmc/fabric/api/event/registry/ItemConstructedCallback.java @@ -20,10 +20,10 @@ import net.fabricmc.fabric.api.event.Event; import net.fabricmc.fabric.api.event.EventFactory; import net.minecraft.item.Item; -public interface ItemBuildingCallback { - public static Event EVENT = EventFactory.arrayBacked(ItemBuildingCallback.class, +public interface ItemConstructedCallback { + public static Event EVENT = EventFactory.arrayBacked(ItemConstructedCallback.class, (listeners) -> (settings, builtItem) -> { - for (ItemBuildingCallback callback : listeners) { + for (ItemConstructedCallback callback : listeners) { callback.building(settings, builtItem); } } diff --git a/src/main/java/net/fabricmc/fabric/events/PlayerInteractionEvent.java b/src/main/java/net/fabricmc/fabric/events/PlayerInteractionEvent.java deleted file mode 100644 index 89f05655e..000000000 --- a/src/main/java/net/fabricmc/fabric/events/PlayerInteractionEvent.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2016, 2017, 2018 FabricMC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.fabricmc.fabric.events; - -/** - * This is a class for INTERACTION EVENTS (think left-clicking/right-clicking). For block placement/break - * events, look elsewhere - this just handles the player! - * - * These hook in BEFORE the spectator checks, so make sure to check for the player's game mode as well! - * - * In general, the events return an ActionResult with the following side effects: - * - SUCCESS cancels further processing and, on the client, sends a packet to the server. - * - PASS falls back to further processing. - * - FAIL cancels further processing and does not send a packet to the server. - * - * CURRENT LIMITATIONS: - * - * - INTERACT_BLOCK/INTERACT_ITEM do not expect the ItemStack instance in the player's held hand to change! - * If you must do that, consider returning an ActionResult.SUCCESS and re-emitting the event in some manner! - * - ATTACK_BLOCK does not let you control the packet sending process yet. - */ -@Deprecated -public final class PlayerInteractionEvent { -} diff --git a/src/main/java/net/fabricmc/fabric/impl/tools/ToolManager.java b/src/main/java/net/fabricmc/fabric/impl/tools/ToolManager.java index d0ab16b1e..aa05969a6 100644 --- a/src/main/java/net/fabricmc/fabric/impl/tools/ToolManager.java +++ b/src/main/java/net/fabricmc/fabric/impl/tools/ToolManager.java @@ -16,7 +16,7 @@ package net.fabricmc.fabric.impl.tools; -import net.fabricmc.fabric.api.event.registry.BlockBuildingCallback; +import net.fabricmc.fabric.api.event.registry.BlockConstructedCallback; import net.fabricmc.fabric.api.block.FabricBlockSettings; import net.fabricmc.fabric.api.util.TriState; import net.minecraft.block.Block; @@ -75,7 +75,7 @@ public final class ToolManager { } static { - BlockBuildingCallback.EVENT.register(ToolManager::onBlockRegistered); + BlockConstructedCallback.EVENT.register(ToolManager::onBlockRegistered); } private static void onBlockRegistered(Block.Settings settings, Block block) { diff --git a/src/main/java/net/fabricmc/fabric/mixin/client/texture/MixinSpriteAtlasTexture.java b/src/main/java/net/fabricmc/fabric/mixin/client/texture/MixinSpriteAtlasTexture.java index 4cdc85bdf..979e3a632 100644 --- a/src/main/java/net/fabricmc/fabric/mixin/client/texture/MixinSpriteAtlasTexture.java +++ b/src/main/java/net/fabricmc/fabric/mixin/client/texture/MixinSpriteAtlasTexture.java @@ -18,7 +18,7 @@ package net.fabricmc.fabric.mixin.client.texture; import com.google.common.base.Joiner; import net.fabricmc.fabric.api.client.texture.*; -import net.fabricmc.fabric.api.event.client.SpriteRegistrationCallback; +import net.fabricmc.fabric.api.event.client.ClientSpriteRegistryCallback; import net.fabricmc.fabric.impl.client.texture.FabricSprite; import net.minecraft.class_1050; import net.minecraft.client.resource.metadata.AnimationResourceMetadata; @@ -30,12 +30,9 @@ import net.minecraft.util.crash.CrashException; import net.minecraft.util.crash.CrashReport; import net.minecraft.util.crash.CrashReportSection; import org.apache.logging.log4j.Logger; -import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Mutable; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.*; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import java.io.IOException; @@ -74,9 +71,9 @@ public abstract class MixinSpriteAtlasTexture { @ModifyVariable(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/texture/SpriteAtlasTexture;method_18164(Lnet/minecraft/resource/ResourceManager;Ljava/util/Set;)Ljava/util/Collection;"), method = "method_18163") public Set setHook(Set set) { fabric_injectedSprites = new HashMap<>(); - SpriteRegistrationCallback.Registry registry = new SpriteRegistrationCallback.Registry(fabric_injectedSprites, set::add); + ClientSpriteRegistryCallback.Registry registry = new ClientSpriteRegistryCallback.Registry(fabric_injectedSprites, set::add); //noinspection ConstantConditions - SpriteRegistrationCallback.EVENT.invoker().registerSprites((SpriteAtlasTexture) (Object) this, registry); + ClientSpriteRegistryCallback.EVENT.invoker().registerSprites((SpriteAtlasTexture) (Object) this, registry); // TODO: Unoptimized. Set dependentSprites = new HashSet<>(); diff --git a/src/main/java/net/fabricmc/fabric/mixin/events/objectbuilder/MixinBlock.java b/src/main/java/net/fabricmc/fabric/mixin/events/objectbuilder/MixinBlock.java index 74e578929..2c4209d1c 100644 --- a/src/main/java/net/fabricmc/fabric/mixin/events/objectbuilder/MixinBlock.java +++ b/src/main/java/net/fabricmc/fabric/mixin/events/objectbuilder/MixinBlock.java @@ -16,7 +16,7 @@ package net.fabricmc.fabric.mixin.events.objectbuilder; -import net.fabricmc.fabric.api.event.registry.BlockBuildingCallback; +import net.fabricmc.fabric.api.event.registry.BlockConstructedCallback; import net.minecraft.block.Block; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -27,6 +27,6 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; public class MixinBlock { @Inject(method = "(Lnet/minecraft/block/Block$Settings;)V", at = @At("RETURN")) public void init(Block.Settings builder, CallbackInfo info) { - BlockBuildingCallback.EVENT.invoker().building(builder, (Block) (Object) this); + BlockConstructedCallback.EVENT.invoker().building(builder, (Block) (Object) this); } } diff --git a/src/main/java/net/fabricmc/fabric/mixin/events/objectbuilder/MixinItem.java b/src/main/java/net/fabricmc/fabric/mixin/events/objectbuilder/MixinItem.java index a493b0cf4..ddd1b9422 100644 --- a/src/main/java/net/fabricmc/fabric/mixin/events/objectbuilder/MixinItem.java +++ b/src/main/java/net/fabricmc/fabric/mixin/events/objectbuilder/MixinItem.java @@ -16,7 +16,7 @@ package net.fabricmc.fabric.mixin.events.objectbuilder; -import net.fabricmc.fabric.api.event.registry.ItemBuildingCallback; +import net.fabricmc.fabric.api.event.registry.ItemConstructedCallback; import net.minecraft.item.Item; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -27,6 +27,6 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; public class MixinItem { @Inject(method = "(Lnet/minecraft/item/Item$Settings;)V", at = @At("RETURN")) public void init(Item.Settings builder, CallbackInfo info) { - ItemBuildingCallback.EVENT.invoker().building(builder, (Item) (Object) this); + ItemConstructedCallback.EVENT.invoker().building(builder, (Item) (Object) this); } }