forked from FabricMC/fabric
name changes
This commit is contained in:
parent
8bda86f21d
commit
9dffeebaf1
17 changed files with 31 additions and 33 deletions
|
@ -17,7 +17,6 @@
|
||||||
package net.fabricmc.fabric.api.event;
|
package net.fabricmc.fabric.api.event;
|
||||||
|
|
||||||
import net.fabricmc.fabric.impl.event.EventFactoryImpl;
|
import net.fabricmc.fabric.impl.event.EventFactoryImpl;
|
||||||
import net.fabricmc.loader.launch.common.FabricLauncherBase;
|
|
||||||
|
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
@ -36,11 +35,15 @@ public final class EventFactory {
|
||||||
EventFactoryImpl.invalidate();
|
EventFactoryImpl.invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T> Event<T> arrayBacked(Class<T> type, Function<T[], T> joiner) {
|
public static <T> Event<T> createArrayBacked(Class<T> type, Function<T[], T> joiner) {
|
||||||
return EventFactoryImpl.arrayBacked(type, joiner);
|
return EventFactoryImpl.createArrayBacked(type, joiner);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T> Event<T> arrayBacked(Class<T> type, T emptyInvoker, Function<T[], T> joiner) {
|
public static <T> Event<T> createArrayBacked(Class<T> type, T emptyInvoker, Function<T[], T> joiner) {
|
||||||
return EventFactoryImpl.arrayBacked(type, emptyInvoker, joiner);
|
return EventFactoryImpl.createArrayBacked(type, emptyInvoker, joiner);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getHandlerName(Object event) {
|
||||||
|
return event.getClass().getName();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@ import java.util.Map;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
public interface ClientSpriteRegistryCallback {
|
public interface ClientSpriteRegistryCallback {
|
||||||
public static final Event<ClientSpriteRegistryCallback> EVENT = EventFactory.arrayBacked(ClientSpriteRegistryCallback.class,
|
public static final Event<ClientSpriteRegistryCallback> EVENT = EventFactory.createArrayBacked(ClientSpriteRegistryCallback.class,
|
||||||
(listeners) -> (atlasTexture, registry) -> {
|
(listeners) -> (atlasTexture, registry) -> {
|
||||||
for (ClientSpriteRegistryCallback callback : listeners) {
|
for (ClientSpriteRegistryCallback callback : listeners) {
|
||||||
callback.registerSprites(atlasTexture, registry);
|
callback.registerSprites(atlasTexture, registry);
|
||||||
|
|
|
@ -18,18 +18,16 @@ package net.fabricmc.fabric.api.event.client;
|
||||||
|
|
||||||
import net.fabricmc.fabric.api.event.Event;
|
import net.fabricmc.fabric.api.event.Event;
|
||||||
import net.fabricmc.fabric.api.event.EventFactory;
|
import net.fabricmc.fabric.api.event.EventFactory;
|
||||||
import net.fabricmc.fabric.api.event.player.AttackBlockCallback;
|
|
||||||
import net.minecraft.client.MinecraftClient;
|
import net.minecraft.client.MinecraftClient;
|
||||||
import net.minecraft.util.ActionResult;
|
|
||||||
|
|
||||||
public interface ClientTickCallback {
|
public interface ClientTickCallback {
|
||||||
public static final Event<ClientTickCallback> EVENT = EventFactory.arrayBacked(ClientTickCallback.class,
|
public static final Event<ClientTickCallback> EVENT = EventFactory.createArrayBacked(ClientTickCallback.class,
|
||||||
(listeners) -> {
|
(listeners) -> {
|
||||||
if (EventFactory.isProfilingEnabled()) {
|
if (EventFactory.isProfilingEnabled()) {
|
||||||
return (client) -> {
|
return (client) -> {
|
||||||
client.getProfiler().push("fabricClientTick");
|
client.getProfiler().push("fabricClientTick");
|
||||||
for (ClientTickCallback event : listeners) {
|
for (ClientTickCallback event : listeners) {
|
||||||
client.getProfiler().push(event.getClass().getName());
|
client.getProfiler().push(EventFactory.getHandlerName(event));
|
||||||
event.tick(client);
|
event.tick(client);
|
||||||
client.getProfiler().pop();
|
client.getProfiler().pop();
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,7 @@ import net.minecraft.world.World;
|
||||||
* ATTACK_BLOCK does not let you control the packet sending process yet.
|
* ATTACK_BLOCK does not let you control the packet sending process yet.
|
||||||
*/
|
*/
|
||||||
public interface AttackBlockCallback {
|
public interface AttackBlockCallback {
|
||||||
public static final Event<AttackBlockCallback> EVENT = EventFactory.arrayBacked(AttackBlockCallback.class,
|
public static final Event<AttackBlockCallback> EVENT = EventFactory.createArrayBacked(AttackBlockCallback.class,
|
||||||
(listeners) -> (player, world, hand, pos, direction) -> {
|
(listeners) -> (player, world, hand, pos, direction) -> {
|
||||||
for (AttackBlockCallback event : listeners) {
|
for (AttackBlockCallback event : listeners) {
|
||||||
ActionResult result = event.interact(player, world, hand, pos, direction);
|
ActionResult result = event.interact(player, world, hand, pos, direction);
|
||||||
|
|
|
@ -35,7 +35,7 @@ import net.minecraft.world.World;
|
||||||
* - FAIL cancels further processing and does not send a packet to the server.
|
* - FAIL cancels further processing and does not send a packet to the server.
|
||||||
*/
|
*/
|
||||||
public interface AttackEntityCallback {
|
public interface AttackEntityCallback {
|
||||||
public static final Event<AttackEntityCallback> EVENT = EventFactory.arrayBacked(AttackEntityCallback.class,
|
public static final Event<AttackEntityCallback> EVENT = EventFactory.createArrayBacked(AttackEntityCallback.class,
|
||||||
(listeners) -> (player, world, hand, entity, hitResult) -> {
|
(listeners) -> (player, world, hand, entity, hitResult) -> {
|
||||||
for (AttackEntityCallback event : listeners) {
|
for (AttackEntityCallback event : listeners) {
|
||||||
ActionResult result = event.interact(player, world, hand, entity, hitResult);
|
ActionResult result = event.interact(player, world, hand, entity, hitResult);
|
||||||
|
|
|
@ -22,8 +22,6 @@ import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.util.ActionResult;
|
import net.minecraft.util.ActionResult;
|
||||||
import net.minecraft.util.Hand;
|
import net.minecraft.util.Hand;
|
||||||
import net.minecraft.util.hit.BlockHitResult;
|
import net.minecraft.util.hit.BlockHitResult;
|
||||||
import net.minecraft.util.math.BlockPos;
|
|
||||||
import net.minecraft.util.math.Direction;
|
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -36,7 +34,7 @@ import net.minecraft.world.World;
|
||||||
* - FAIL cancels further processing and does not send a packet to the server.
|
* - FAIL cancels further processing and does not send a packet to the server.
|
||||||
*/
|
*/
|
||||||
public interface UseBlockCallback {
|
public interface UseBlockCallback {
|
||||||
public static final Event<UseBlockCallback> EVENT = EventFactory.arrayBacked(UseBlockCallback.class,
|
public static final Event<UseBlockCallback> EVENT = EventFactory.createArrayBacked(UseBlockCallback.class,
|
||||||
(listeners) -> (player, world, hand, hitResult) -> {
|
(listeners) -> (player, world, hand, hitResult) -> {
|
||||||
for (UseBlockCallback event : listeners) {
|
for (UseBlockCallback event : listeners) {
|
||||||
ActionResult result = event.interact(player, world, hand, hitResult);
|
ActionResult result = event.interact(player, world, hand, hitResult);
|
||||||
|
|
|
@ -35,7 +35,7 @@ import net.minecraft.world.World;
|
||||||
* - FAIL cancels further processing and does not send a packet to the server.
|
* - FAIL cancels further processing and does not send a packet to the server.
|
||||||
*/
|
*/
|
||||||
public interface UseEntityCallback {
|
public interface UseEntityCallback {
|
||||||
public static final Event<UseEntityCallback> EVENT = EventFactory.arrayBacked(UseEntityCallback.class,
|
public static final Event<UseEntityCallback> EVENT = EventFactory.createArrayBacked(UseEntityCallback.class,
|
||||||
(listeners) -> (player, world, hand, entity, hitResult) -> {
|
(listeners) -> (player, world, hand, entity, hitResult) -> {
|
||||||
for (UseEntityCallback event : listeners) {
|
for (UseEntityCallback event : listeners) {
|
||||||
ActionResult result = event.interact(player, world, hand, entity, hitResult);
|
ActionResult result = event.interact(player, world, hand, entity, hitResult);
|
||||||
|
|
|
@ -33,7 +33,7 @@ import net.minecraft.world.World;
|
||||||
* - FAIL cancels further processing and does not send a packet to the server.
|
* - FAIL cancels further processing and does not send a packet to the server.
|
||||||
*/
|
*/
|
||||||
public interface UseItemCallback {
|
public interface UseItemCallback {
|
||||||
public static final Event<UseItemCallback> EVENT = EventFactory.arrayBacked(UseItemCallback.class,
|
public static final Event<UseItemCallback> EVENT = EventFactory.createArrayBacked(UseItemCallback.class,
|
||||||
(listeners) -> (player, world, hand) -> {
|
(listeners) -> (player, world, hand) -> {
|
||||||
for (UseItemCallback event : listeners) {
|
for (UseItemCallback event : listeners) {
|
||||||
ActionResult result = event.interact(player, world, hand);
|
ActionResult result = event.interact(player, world, hand);
|
||||||
|
|
|
@ -21,7 +21,7 @@ import net.fabricmc.fabric.api.event.EventFactory;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
|
|
||||||
public interface BlockConstructedCallback {
|
public interface BlockConstructedCallback {
|
||||||
public static Event<BlockConstructedCallback> EVENT = EventFactory.arrayBacked(BlockConstructedCallback.class,
|
public static Event<BlockConstructedCallback> EVENT = EventFactory.createArrayBacked(BlockConstructedCallback.class,
|
||||||
(listeners) -> (settings, builtBlock) -> {
|
(listeners) -> (settings, builtBlock) -> {
|
||||||
for (BlockConstructedCallback callback : listeners) {
|
for (BlockConstructedCallback callback : listeners) {
|
||||||
callback.building(settings, builtBlock);
|
callback.building(settings, builtBlock);
|
||||||
|
|
|
@ -21,7 +21,7 @@ import net.fabricmc.fabric.api.event.EventFactory;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
|
|
||||||
public interface ItemConstructedCallback {
|
public interface ItemConstructedCallback {
|
||||||
public static Event<ItemConstructedCallback> EVENT = EventFactory.arrayBacked(ItemConstructedCallback.class,
|
public static Event<ItemConstructedCallback> EVENT = EventFactory.createArrayBacked(ItemConstructedCallback.class,
|
||||||
(listeners) -> (settings, builtItem) -> {
|
(listeners) -> (settings, builtItem) -> {
|
||||||
for (ItemConstructedCallback callback : listeners) {
|
for (ItemConstructedCallback callback : listeners) {
|
||||||
callback.building(settings, builtItem);
|
callback.building(settings, builtItem);
|
||||||
|
|
|
@ -21,7 +21,7 @@ import net.fabricmc.fabric.api.event.EventFactory;
|
||||||
import net.minecraft.server.MinecraftServer;
|
import net.minecraft.server.MinecraftServer;
|
||||||
|
|
||||||
public interface ServerStartCallback {
|
public interface ServerStartCallback {
|
||||||
public static final Event<ServerStartCallback> EVENT = EventFactory.arrayBacked(ServerStartCallback.class,
|
public static final Event<ServerStartCallback> EVENT = EventFactory.createArrayBacked(ServerStartCallback.class,
|
||||||
(listeners) -> (server) -> {
|
(listeners) -> (server) -> {
|
||||||
for (ServerStartCallback event : listeners) {
|
for (ServerStartCallback event : listeners) {
|
||||||
event.onStartServer(server);
|
event.onStartServer(server);
|
||||||
|
|
|
@ -21,7 +21,7 @@ import net.fabricmc.fabric.api.event.EventFactory;
|
||||||
import net.minecraft.server.MinecraftServer;
|
import net.minecraft.server.MinecraftServer;
|
||||||
|
|
||||||
public interface ServerStopCallback {
|
public interface ServerStopCallback {
|
||||||
public static final Event<ServerStopCallback> EVENT = EventFactory.arrayBacked(ServerStopCallback.class,
|
public static final Event<ServerStopCallback> EVENT = EventFactory.createArrayBacked(ServerStopCallback.class,
|
||||||
(listeners) -> (server) -> {
|
(listeners) -> (server) -> {
|
||||||
for (ServerStopCallback event : listeners) {
|
for (ServerStopCallback event : listeners) {
|
||||||
event.onStopServer(server);
|
event.onStopServer(server);
|
||||||
|
|
|
@ -21,13 +21,13 @@ import net.fabricmc.fabric.api.event.EventFactory;
|
||||||
import net.minecraft.server.MinecraftServer;
|
import net.minecraft.server.MinecraftServer;
|
||||||
|
|
||||||
public interface ServerTickCallback {
|
public interface ServerTickCallback {
|
||||||
public static final Event<ServerTickCallback> EVENT = EventFactory.arrayBacked(ServerTickCallback.class,
|
public static final Event<ServerTickCallback> EVENT = EventFactory.createArrayBacked(ServerTickCallback.class,
|
||||||
(listeners) -> {
|
(listeners) -> {
|
||||||
if (EventFactory.isProfilingEnabled()) {
|
if (EventFactory.isProfilingEnabled()) {
|
||||||
return (server) -> {
|
return (server) -> {
|
||||||
server.getProfiler().push("fabricServerTick");
|
server.getProfiler().push("fabricServerTick");
|
||||||
for (ServerTickCallback event : listeners) {
|
for (ServerTickCallback event : listeners) {
|
||||||
server.getProfiler().push(event.getClass().getName());
|
server.getProfiler().push(EventFactory.getHandlerName(event));
|
||||||
event.tick(server);
|
event.tick(server);
|
||||||
server.getProfiler().pop();
|
server.getProfiler().pop();
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,13 +21,13 @@ import net.fabricmc.fabric.api.event.EventFactory;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
public interface WorldTickCallback {
|
public interface WorldTickCallback {
|
||||||
public static final Event<WorldTickCallback> EVENT = EventFactory.arrayBacked(WorldTickCallback.class,
|
public static final Event<WorldTickCallback> EVENT = EventFactory.createArrayBacked(WorldTickCallback.class,
|
||||||
(listeners) -> {
|
(listeners) -> {
|
||||||
if (EventFactory.isProfilingEnabled()) {
|
if (EventFactory.isProfilingEnabled()) {
|
||||||
return (world) -> {
|
return (world) -> {
|
||||||
world.getProfiler().push("fabricWorldTick");
|
world.getProfiler().push("fabricWorldTick");
|
||||||
for (WorldTickCallback event : listeners) {
|
for (WorldTickCallback event : listeners) {
|
||||||
world.getProfiler().push(event.getClass().getName());
|
world.getProfiler().push(EventFactory.getHandlerName(event));
|
||||||
event.tick(world);
|
event.tick(world);
|
||||||
world.getProfiler().pop();
|
world.getProfiler().pop();
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,9 @@ package net.fabricmc.fabric.api.network;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
import net.minecraft.util.PacketByteBuf;
|
import net.minecraft.util.PacketByteBuf;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
|
|
||||||
|
@ -34,7 +36,7 @@ public class CustomPayloadPacketRegistry {
|
||||||
protected final Map<Identifier, BiConsumer<PacketContext, PacketByteBuf>> consumerMap;
|
protected final Map<Identifier, BiConsumer<PacketContext, PacketByteBuf>> consumerMap;
|
||||||
|
|
||||||
protected CustomPayloadPacketRegistry() {
|
protected CustomPayloadPacketRegistry() {
|
||||||
consumerMap = new HashMap<>();
|
consumerMap = new LinkedHashMap<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -19,7 +19,6 @@ package net.fabricmc.fabric.impl.event;
|
||||||
import net.fabricmc.fabric.api.event.Event;
|
import net.fabricmc.fabric.api.event.Event;
|
||||||
|
|
||||||
import java.lang.invoke.MethodHandle;
|
import java.lang.invoke.MethodHandle;
|
||||||
import java.lang.invoke.MethodHandleProxies;
|
|
||||||
import java.lang.invoke.MethodHandles;
|
import java.lang.invoke.MethodHandles;
|
||||||
import java.lang.invoke.MethodType;
|
import java.lang.invoke.MethodType;
|
||||||
import java.lang.reflect.*;
|
import java.lang.reflect.*;
|
||||||
|
@ -38,11 +37,11 @@ public final class EventFactoryImpl {
|
||||||
ARRAY_BACKED_EVENTS.forEach(ArrayBackedEvent::update);
|
ARRAY_BACKED_EVENTS.forEach(ArrayBackedEvent::update);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T> Event<T> arrayBacked(Class<T> type, Function<T[], T> joiner) {
|
public static <T> Event<T> createArrayBacked(Class<T> type, Function<T[], T> joiner) {
|
||||||
return arrayBacked(type, null /* buildEmptyInvoker(type, joiner) */, joiner);
|
return createArrayBacked(type, null /* buildEmptyInvoker(type, joiner) */, joiner);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T> Event<T> arrayBacked(Class<T> type, T emptyInvoker, Function<T[], T> joiner) {
|
public static <T> Event<T> createArrayBacked(Class<T> type, T emptyInvoker, Function<T[], T> joiner) {
|
||||||
ArrayBackedEvent<T> event = new ArrayBackedEvent<>(type, emptyInvoker, joiner);
|
ArrayBackedEvent<T> event = new ArrayBackedEvent<>(type, emptyInvoker, joiner);
|
||||||
ARRAY_BACKED_EVENTS.add(event);
|
ARRAY_BACKED_EVENTS.add(event);
|
||||||
return event;
|
return event;
|
||||||
|
|
|
@ -35,9 +35,7 @@ public abstract class MixinServerPlayNetworkHandler {
|
||||||
|
|
||||||
@Inject(method = "<init>", at = @At("RETURN"))
|
@Inject(method = "<init>", at = @At("RETURN"))
|
||||||
public void init(MinecraftServer server, ClientConnection connection, ServerPlayerEntity player, CallbackInfo info) {
|
public void init(MinecraftServer server, ClientConnection connection, ServerPlayerEntity player, CallbackInfo info) {
|
||||||
//if (server.isDedicated()) {
|
// TODO: If integrated and local, don't send the packet (it's ignored)
|
||||||
// TODO: If integrated and local, don't send the packet
|
|
||||||
sendPacket(RegistrySyncManager.createPacket());
|
sendPacket(RegistrySyncManager.createPacket());
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue