forked from FabricMC/fabric
more cleanup
This commit is contained in:
parent
6ea76ea07d
commit
6b7848bea0
13 changed files with 24 additions and 60 deletions
|
@ -26,10 +26,10 @@ import net.minecraft.util.Identifier;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
public interface SpriteRegistrationCallback {
|
public interface ClientSpriteRegistryCallback {
|
||||||
public static final Event<SpriteRegistrationCallback> EVENT = EventFactory.arrayBacked(SpriteRegistrationCallback.class,
|
public static final Event<ClientSpriteRegistryCallback> EVENT = EventFactory.arrayBacked(ClientSpriteRegistryCallback.class,
|
||||||
(listeners) -> (atlasTexture, registry) -> {
|
(listeners) -> (atlasTexture, registry) -> {
|
||||||
for (SpriteRegistrationCallback callback : listeners) {
|
for (ClientSpriteRegistryCallback callback : listeners) {
|
||||||
callback.registerSprites(atlasTexture, registry);
|
callback.registerSprites(atlasTexture, registry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@ public interface SpriteRegistrationCallback {
|
||||||
|
|
||||||
void registerSprites(SpriteAtlasTexture atlasTexture, Registry registry);
|
void registerSprites(SpriteAtlasTexture atlasTexture, Registry registry);
|
||||||
|
|
||||||
static void registerBlockAtlas(SpriteRegistrationCallback callback) {
|
static void registerBlockAtlas(ClientSpriteRegistryCallback callback) {
|
||||||
EVENT.register((atlasTexture, registry) -> {
|
EVENT.register((atlasTexture, registry) -> {
|
||||||
if (atlasTexture == MinecraftClient.getInstance().getSpriteAtlas()) {
|
if (atlasTexture == MinecraftClient.getInstance().getSpriteAtlas()) {
|
||||||
callback.registerSprites(atlasTexture, registry);
|
callback.registerSprites(atlasTexture, registry);
|
|
@ -27,6 +27,7 @@ import net.minecraft.world.World;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Callback for left-clicking ("attacking") a block.
|
* 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:
|
* Upon return:
|
||||||
* - SUCCESS cancels further processing and, on the client, sends a packet to the server.
|
* - SUCCESS cancels further processing and, on the client, sends a packet to the server.
|
||||||
|
|
|
@ -27,6 +27,7 @@ import net.minecraft.world.World;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Callback for left-clicking ("attacking") an entity.
|
* 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:
|
* Upon return:
|
||||||
* - SUCCESS cancels further processing and, on the client, sends a packet to the server.
|
* - SUCCESS cancels further processing and, on the client, sends a packet to the server.
|
||||||
|
|
|
@ -28,6 +28,7 @@ import net.minecraft.world.World;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Callback for right-clicking ("using") a block.
|
* 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:
|
* Upon return:
|
||||||
* - SUCCESS cancels further processing and, on the client, sends a packet to the server.
|
* - SUCCESS cancels further processing and, on the client, sends a packet to the server.
|
||||||
|
|
|
@ -27,6 +27,7 @@ import net.minecraft.world.World;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Callback for right-clicking ("using") an entity.
|
* 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:
|
* Upon return:
|
||||||
* - SUCCESS cancels further processing and, on the client, sends a packet to the server.
|
* - SUCCESS cancels further processing and, on the client, sends a packet to the server.
|
||||||
|
|
|
@ -25,6 +25,7 @@ import net.minecraft.world.World;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Callback for right-clicking ("using") an item.
|
* 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:
|
* Upon return:
|
||||||
* - SUCCESS cancels further processing and, on the client, sends a packet to the server.
|
* - SUCCESS cancels further processing and, on the client, sends a packet to the server.
|
||||||
|
|
|
@ -20,10 +20,10 @@ import net.fabricmc.fabric.api.event.Event;
|
||||||
import net.fabricmc.fabric.api.event.EventFactory;
|
import net.fabricmc.fabric.api.event.EventFactory;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
|
|
||||||
public interface BlockBuildingCallback {
|
public interface BlockConstructedCallback {
|
||||||
public static Event<BlockBuildingCallback> EVENT = EventFactory.arrayBacked(BlockBuildingCallback.class,
|
public static Event<BlockConstructedCallback> EVENT = EventFactory.arrayBacked(BlockConstructedCallback.class,
|
||||||
(listeners) -> (settings, builtBlock) -> {
|
(listeners) -> (settings, builtBlock) -> {
|
||||||
for (BlockBuildingCallback callback : listeners) {
|
for (BlockConstructedCallback callback : listeners) {
|
||||||
callback.building(settings, builtBlock);
|
callback.building(settings, builtBlock);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -20,10 +20,10 @@ import net.fabricmc.fabric.api.event.Event;
|
||||||
import net.fabricmc.fabric.api.event.EventFactory;
|
import net.fabricmc.fabric.api.event.EventFactory;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
|
|
||||||
public interface ItemBuildingCallback {
|
public interface ItemConstructedCallback {
|
||||||
public static Event<ItemBuildingCallback> EVENT = EventFactory.arrayBacked(ItemBuildingCallback.class,
|
public static Event<ItemConstructedCallback> EVENT = EventFactory.arrayBacked(ItemConstructedCallback.class,
|
||||||
(listeners) -> (settings, builtItem) -> {
|
(listeners) -> (settings, builtItem) -> {
|
||||||
for (ItemBuildingCallback callback : listeners) {
|
for (ItemConstructedCallback callback : listeners) {
|
||||||
callback.building(settings, builtItem);
|
callback.building(settings, builtItem);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -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 {
|
|
||||||
}
|
|
|
@ -16,7 +16,7 @@
|
||||||
|
|
||||||
package net.fabricmc.fabric.impl.tools;
|
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.block.FabricBlockSettings;
|
||||||
import net.fabricmc.fabric.api.util.TriState;
|
import net.fabricmc.fabric.api.util.TriState;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
|
@ -75,7 +75,7 @@ public final class ToolManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
static {
|
static {
|
||||||
BlockBuildingCallback.EVENT.register(ToolManager::onBlockRegistered);
|
BlockConstructedCallback.EVENT.register(ToolManager::onBlockRegistered);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void onBlockRegistered(Block.Settings settings, Block block) {
|
private static void onBlockRegistered(Block.Settings settings, Block block) {
|
||||||
|
|
|
@ -18,7 +18,7 @@ package net.fabricmc.fabric.mixin.client.texture;
|
||||||
|
|
||||||
import com.google.common.base.Joiner;
|
import com.google.common.base.Joiner;
|
||||||
import net.fabricmc.fabric.api.client.texture.*;
|
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.fabricmc.fabric.impl.client.texture.FabricSprite;
|
||||||
import net.minecraft.class_1050;
|
import net.minecraft.class_1050;
|
||||||
import net.minecraft.client.resource.metadata.AnimationResourceMetadata;
|
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.CrashReport;
|
||||||
import net.minecraft.util.crash.CrashReportSection;
|
import net.minecraft.util.crash.CrashReportSection;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.spongepowered.asm.mixin.Final;
|
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.Mutable;
|
|
||||||
import org.spongepowered.asm.mixin.Shadow;
|
import org.spongepowered.asm.mixin.Shadow;
|
||||||
import org.spongepowered.asm.mixin.injection.*;
|
import org.spongepowered.asm.mixin.injection.*;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||||
|
|
||||||
import java.io.IOException;
|
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")
|
@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<Identifier> setHook(Set<Identifier> set) {
|
public Set<Identifier> setHook(Set<Identifier> set) {
|
||||||
fabric_injectedSprites = new HashMap<>();
|
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
|
//noinspection ConstantConditions
|
||||||
SpriteRegistrationCallback.EVENT.invoker().registerSprites((SpriteAtlasTexture) (Object) this, registry);
|
ClientSpriteRegistryCallback.EVENT.invoker().registerSprites((SpriteAtlasTexture) (Object) this, registry);
|
||||||
|
|
||||||
// TODO: Unoptimized.
|
// TODO: Unoptimized.
|
||||||
Set<DependentSprite> dependentSprites = new HashSet<>();
|
Set<DependentSprite> dependentSprites = new HashSet<>();
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
|
|
||||||
package net.fabricmc.fabric.mixin.events.objectbuilder;
|
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 net.minecraft.block.Block;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
@ -27,6 +27,6 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
public class MixinBlock {
|
public class MixinBlock {
|
||||||
@Inject(method = "<init>(Lnet/minecraft/block/Block$Settings;)V", at = @At("RETURN"))
|
@Inject(method = "<init>(Lnet/minecraft/block/Block$Settings;)V", at = @At("RETURN"))
|
||||||
public void init(Block.Settings builder, CallbackInfo info) {
|
public void init(Block.Settings builder, CallbackInfo info) {
|
||||||
BlockBuildingCallback.EVENT.invoker().building(builder, (Block) (Object) this);
|
BlockConstructedCallback.EVENT.invoker().building(builder, (Block) (Object) this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
|
|
||||||
package net.fabricmc.fabric.mixin.events.objectbuilder;
|
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 net.minecraft.item.Item;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
@ -27,6 +27,6 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
public class MixinItem {
|
public class MixinItem {
|
||||||
@Inject(method = "<init>(Lnet/minecraft/item/Item$Settings;)V", at = @At("RETURN"))
|
@Inject(method = "<init>(Lnet/minecraft/item/Item$Settings;)V", at = @At("RETURN"))
|
||||||
public void init(Item.Settings builder, CallbackInfo info) {
|
public void init(Item.Settings builder, CallbackInfo info) {
|
||||||
ItemBuildingCallback.EVENT.invoker().building(builder, (Item) (Object) this);
|
ItemConstructedCallback.EVENT.invoker().building(builder, (Item) (Object) this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue