forked from FabricMC/fabric
port to 19w07a
This commit is contained in:
parent
0c62493b3f
commit
377a882f62
23 changed files with 188 additions and 90 deletions
|
@ -31,7 +31,7 @@ import java.util.Collections;
|
|||
*
|
||||
* {@link ResourceReloadListenerKeys}
|
||||
*/
|
||||
public interface IdentifiableResourceReloadListener<T> extends ResourceReloadListener<T> {
|
||||
public interface IdentifiableResourceReloadListener extends ResourceReloadListener {
|
||||
/**
|
||||
* @return The unique identifier of this listener.
|
||||
*/
|
||||
|
@ -39,7 +39,8 @@ public interface IdentifiableResourceReloadListener<T> extends ResourceReloadLis
|
|||
|
||||
/**
|
||||
* @return The identifiers of listeners this listener expects to have been
|
||||
* executed before itself.
|
||||
* executed before itself. Please keep in mind that this only takes effect
|
||||
* during the application stage!
|
||||
*/
|
||||
default Collection<Identifier> getFabricDependencies() {
|
||||
return Collections.emptyList();
|
||||
|
|
|
@ -27,8 +27,18 @@ public interface ResourceManagerHelper {
|
|||
/**
|
||||
* Add a resource reload listener for a given registry.
|
||||
* @param listener The resource reload listener.
|
||||
* @deprecated Use {@link ResourceManagerHelper#registerReloadListener(IdentifiableResourceReloadListener)}
|
||||
*/
|
||||
void addReloadListener(IdentifiableResourceReloadListener<?> listener);
|
||||
@Deprecated
|
||||
default void addReloadListener(IdentifiableResourceReloadListener listener) {
|
||||
registerReloadListener(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a resource reload listener for a given resource manager type.
|
||||
* @param listener The resource reload listener.
|
||||
*/
|
||||
void registerReloadListener(IdentifiableResourceReloadListener listener);
|
||||
|
||||
/**
|
||||
* Get the ResourceManagerHelper instance for a given resource type.
|
||||
|
|
|
@ -0,0 +1,73 @@
|
|||
/*
|
||||
* 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.api.resource;
|
||||
|
||||
import net.minecraft.resource.ResourceManager;
|
||||
import net.minecraft.resource.ResourceReloadListener;
|
||||
import net.minecraft.resource.SynchronousResourceReloadListener;
|
||||
import net.minecraft.util.profiler.Profiler;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
/**
|
||||
* A simplified version of the "resource reload listener" interface, hiding the
|
||||
* peculiarities of the API.
|
||||
*
|
||||
* In essence, there are two stages:
|
||||
*
|
||||
* - load: create an instance of your data object containing all loaded and
|
||||
* processed information,
|
||||
* - apply: apply the information from the data object to the game instance.
|
||||
*
|
||||
* The load stage should be self-contained as it can run on any thread! However,
|
||||
* the apply stage is guaranteed to run on the game thread.
|
||||
*
|
||||
* For a fully synchronous alternative, consider using
|
||||
* {@link SynchronousResourceReloadListener} in conjunction with
|
||||
* {@link IdentifiableResourceReloadListener}.
|
||||
*
|
||||
* @param <T> The data object.
|
||||
*/
|
||||
public interface SimpleResourceReloadListener<T> extends IdentifiableResourceReloadListener {
|
||||
default CompletableFuture<Void> apply(ResourceReloadListener.Helper helper, ResourceManager manager, Profiler loadProfiler, Profiler applyProfiler, Executor loadExecutor, Executor applyExecutor) {
|
||||
return load(manager, loadProfiler, loadExecutor).thenCompose(helper::waitForAll).thenCompose(
|
||||
(o) -> apply(o, manager, applyProfiler, applyExecutor)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asynchronously process and load resource-based data. The code
|
||||
* must be thread-safe and not modify game state!
|
||||
*
|
||||
* @param manager The resource manager used during reloading.
|
||||
* @param profiler The profiler which may be used for this stage.
|
||||
* @param executor The executor which should be used for this stage.
|
||||
* @return A CompletableFuture representing the "data loading" stage.
|
||||
*/
|
||||
CompletableFuture<T> load(ResourceManager manager, Profiler profiler, Executor executor);
|
||||
|
||||
/**
|
||||
* Synchronously apply loaded data to the game state.
|
||||
*
|
||||
* @param manager The resource manager used during reloading.
|
||||
* @param profiler The profiler which may be used for this stage.
|
||||
* @param executor The executor which should be used for this stage.
|
||||
* @return A CompletableFuture representing the "data applying" stage.
|
||||
*/
|
||||
CompletableFuture<Void> apply(T data, ResourceManager manager, Profiler profiler, Executor executor);
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
/*
|
||||
* 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.api.resource;
|
||||
|
||||
import net.minecraft.resource.SynchronousResourceReloadListener;
|
||||
|
||||
/**
|
||||
* A simplified version of the "resource reload listener" interface, hiding the
|
||||
* peculiarities of the API and ensuring all data is loaded on the main thread.
|
||||
*/
|
||||
public interface SimpleSynchronousResourceReloadListener extends IdentifiableResourceReloadListener, SynchronousResourceReloadListener {
|
||||
}
|
|
@ -20,7 +20,7 @@ import io.netty.buffer.Unpooled;
|
|||
import net.fabricmc.fabric.api.container.ContainerFactory;
|
||||
import net.fabricmc.fabric.api.container.ContainerProviderRegistry;
|
||||
import net.fabricmc.fabric.impl.network.PacketTypes;
|
||||
import net.minecraft.client.network.packet.CustomPayloadClientPacket;
|
||||
import net.minecraft.client.network.packet.CustomPayloadS2CPacket;
|
||||
import net.minecraft.container.Container;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
|
@ -71,7 +71,7 @@ public class ContainerProviderImpl implements ContainerProviderRegistry {
|
|||
buf.writeByte(syncId);
|
||||
|
||||
writer.accept(buf);
|
||||
player.networkHandler.sendPacket(new CustomPayloadClientPacket(PacketTypes.OPEN_CONTAINER, buf));
|
||||
player.networkHandler.sendPacket(new CustomPayloadS2CPacket(PacketTypes.OPEN_CONTAINER, buf));
|
||||
|
||||
PacketByteBuf clonedBuf = new PacketByteBuf(buf.duplicate());
|
||||
clonedBuf.readIdentifier();
|
||||
|
|
|
@ -24,7 +24,7 @@ import net.fabricmc.fabric.api.network.PacketContext;
|
|||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.network.ClientPlayNetworkHandler;
|
||||
import net.minecraft.network.Packet;
|
||||
import net.minecraft.server.network.packet.CustomPayloadServerPacket;
|
||||
import net.minecraft.server.network.packet.CustomPayloadC2SPacket;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.PacketByteBuf;
|
||||
|
||||
|
@ -61,7 +61,7 @@ public class ClientSidePacketRegistryImpl extends PacketRegistryImpl implements
|
|||
|
||||
@Override
|
||||
public Packet<?> toPacket(Identifier id, PacketByteBuf buf) {
|
||||
return new CustomPayloadServerPacket(id, buf);
|
||||
return new CustomPayloadC2SPacket(id, buf);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -23,7 +23,7 @@ import net.fabricmc.fabric.api.network.PacketContext;
|
|||
import net.fabricmc.fabric.api.network.ServerSidePacketRegistry;
|
||||
import net.fabricmc.fabric.api.server.PlayerStream;
|
||||
import net.fabricmc.loader.FabricLoader;
|
||||
import net.minecraft.client.network.packet.CustomPayloadClientPacket;
|
||||
import net.minecraft.client.network.packet.CustomPayloadS2CPacket;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.network.Packet;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
|
@ -60,7 +60,7 @@ public class ServerSidePacketRegistryImpl extends PacketRegistryImpl implements
|
|||
|
||||
@Override
|
||||
public Packet<?> toPacket(Identifier id, PacketByteBuf buf) {
|
||||
return new CustomPayloadClientPacket(id, buf);
|
||||
return new CustomPayloadS2CPacket(id, buf);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -22,6 +22,7 @@ import net.fabricmc.fabric.api.registry.FlammableBlockRegistry;
|
|||
import net.fabricmc.fabric.api.resource.IdentifiableResourceReloadListener;
|
||||
import net.fabricmc.fabric.api.resource.ResourceManagerHelper;
|
||||
import net.fabricmc.fabric.api.resource.ResourceReloadListenerKeys;
|
||||
import net.fabricmc.fabric.api.resource.SimpleSynchronousResourceReloadListener;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.resource.ResourceManager;
|
||||
import net.minecraft.resource.ResourceType;
|
||||
|
@ -35,7 +36,7 @@ import java.util.HashMap;
|
|||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class FlammableBlockRegistryImpl implements FlammableBlockRegistry, IdentifiableResourceReloadListener<Void> {
|
||||
public class FlammableBlockRegistryImpl implements FlammableBlockRegistry, SimpleSynchronousResourceReloadListener {
|
||||
private static final FlammableBlockRegistry.Entry REMOVED = new FlammableBlockRegistry.Entry(0, 0);
|
||||
private static final Map<Block, FlammableBlockRegistryImpl> REGISTRIES = new HashMap<>();
|
||||
private static final Collection<Identifier> RELOAD_DEPS = Collections.singletonList(ResourceReloadListenerKeys.TAGS);
|
||||
|
@ -49,19 +50,14 @@ public class FlammableBlockRegistryImpl implements FlammableBlockRegistry, Ident
|
|||
private boolean tagsPresent = false;
|
||||
|
||||
private FlammableBlockRegistryImpl(Block key) {
|
||||
ResourceManagerHelper.get(ResourceType.DATA).addReloadListener(this);
|
||||
ResourceManagerHelper.get(ResourceType.DATA).registerReloadListener(this);
|
||||
this.id = new Identifier("fabric:private/fire_registry_" + (++idCounter));
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture prepare(ResourceManager var1, Profiler var2) {
|
||||
return CompletableFuture.completedFuture(null);
|
||||
}
|
||||
|
||||
// TODO: Asynchronous?
|
||||
@Override
|
||||
public void apply(ResourceManager var1, Void var2, Profiler var3) {
|
||||
public void apply(ResourceManager var1) {
|
||||
reload();
|
||||
tagsPresent = true;
|
||||
}
|
||||
|
|
|
@ -31,20 +31,20 @@ public class ResourceManagerHelperImpl implements ResourceManagerHelper {
|
|||
private static final Map<ResourceType, ResourceManagerHelperImpl> registryMap = new HashMap<>();
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
|
||||
private final List<IdentifiableResourceReloadListener<?>> addedListeners = new ArrayList<>();
|
||||
private final List<IdentifiableResourceReloadListener> addedListeners = new ArrayList<>();
|
||||
|
||||
public static ResourceManagerHelper get(ResourceType type) {
|
||||
return registryMap.computeIfAbsent(type, (t) -> new ResourceManagerHelperImpl());
|
||||
}
|
||||
|
||||
public static void sort(ResourceType type, List<ResourceReloadListener<?>> listeners) {
|
||||
public static void sort(ResourceType type, List<ResourceReloadListener> listeners) {
|
||||
ResourceManagerHelperImpl instance = registryMap.get(type);
|
||||
if (instance != null) {
|
||||
instance.sort(listeners);
|
||||
}
|
||||
}
|
||||
|
||||
protected void sort(List<ResourceReloadListener<?>> listeners) {
|
||||
protected void sort(List<ResourceReloadListener> listeners) {
|
||||
listeners.removeAll(addedListeners);
|
||||
|
||||
// General rules:
|
||||
|
@ -53,7 +53,7 @@ public class ResourceManagerHelperImpl implements ResourceManagerHelper {
|
|||
// trust them 100%. Only code doesn't lie.
|
||||
// - We addReloadListener all custom listeners after vanilla listeners. Same reasons.
|
||||
|
||||
List<IdentifiableResourceReloadListener<?>> listenersToAdd = Lists.newArrayList(addedListeners);
|
||||
List<IdentifiableResourceReloadListener> listenersToAdd = Lists.newArrayList(addedListeners);
|
||||
Set<Identifier> resolvedIds = new HashSet<>();
|
||||
for (ResourceReloadListener listener : listeners) {
|
||||
if (listener instanceof IdentifiableResourceReloadListener) {
|
||||
|
@ -65,7 +65,7 @@ public class ResourceManagerHelperImpl implements ResourceManagerHelper {
|
|||
while (listeners.size() != lastSize) {
|
||||
lastSize = listeners.size();
|
||||
|
||||
Iterator<IdentifiableResourceReloadListener<?>> it = listenersToAdd.iterator();
|
||||
Iterator<IdentifiableResourceReloadListener> it = listenersToAdd.iterator();
|
||||
while (it.hasNext()) {
|
||||
IdentifiableResourceReloadListener listener = it.next();
|
||||
if (resolvedIds.containsAll(listener.getFabricDependencies())) {
|
||||
|
@ -82,7 +82,7 @@ public class ResourceManagerHelperImpl implements ResourceManagerHelper {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void addReloadListener(IdentifiableResourceReloadListener<?> listener) {
|
||||
public void registerReloadListener(IdentifiableResourceReloadListener listener) {
|
||||
addedListeners.add(listener);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ package net.fabricmc.fabric.mixin.block.entity;
|
|||
import net.fabricmc.fabric.api.block.entity.BlockEntityClientSerializable;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.block.entity.BlockEntityType;
|
||||
import net.minecraft.client.network.packet.BlockEntityUpdateClientPacket;
|
||||
import net.minecraft.client.network.packet.BlockEntityUpdateS2CPacket;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
@ -38,7 +38,7 @@ public abstract class MixinBlockEntity {
|
|||
public abstract BlockPos getPos();
|
||||
|
||||
@Inject(at = @At("HEAD"), method = "toUpdatePacket", cancellable = true)
|
||||
public void toUpdatePacket(CallbackInfoReturnable<BlockEntityUpdateClientPacket> info) {
|
||||
public void toUpdatePacket(CallbackInfoReturnable<BlockEntityUpdateS2CPacket> info) {
|
||||
Object self = (Object) this;
|
||||
|
||||
if (self instanceof BlockEntityClientSerializable) {
|
||||
|
@ -56,7 +56,7 @@ public abstract class MixinBlockEntity {
|
|||
|
||||
tag.putString("id", entityId.toString());
|
||||
tag = ((BlockEntityClientSerializable) self).toClientTag(tag);
|
||||
info.setReturnValue(new BlockEntityUpdateClientPacket(getPos(), 127, tag));
|
||||
info.setReturnValue(new BlockEntityUpdateS2CPacket(getPos(), 127, tag));
|
||||
info.cancel();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ import net.fabricmc.fabric.api.block.entity.BlockEntityClientSerializable;
|
|||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.block.entity.BlockEntityType;
|
||||
import net.minecraft.client.network.ClientPlayNetworkHandler;
|
||||
import net.minecraft.client.network.packet.BlockEntityUpdateClientPacket;
|
||||
import net.minecraft.client.network.packet.BlockEntityUpdateS2CPacket;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.util.Identifier;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
@ -37,8 +37,8 @@ public class MixinClientPlayNetworkHandler {
|
|||
@Shadow
|
||||
private static Logger LOGGER;
|
||||
|
||||
@Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/packet/BlockEntityUpdateClientPacket;getActionId()I", ordinal = 0), method = "onBlockEntityUpdate", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD)
|
||||
public void onBlockEntityUpdate(BlockEntityUpdateClientPacket packet, CallbackInfo info, BlockEntity entity) {
|
||||
@Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/packet/BlockEntityUpdateS2CPacket;getActionId()I", ordinal = 0), method = "onBlockEntityUpdate", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD)
|
||||
public void onBlockEntityUpdate(BlockEntityUpdateS2CPacket packet, CallbackInfo info, BlockEntity entity) {
|
||||
if (entity instanceof BlockEntityClientSerializable) {
|
||||
if (packet.getActionId() == 127) {
|
||||
BlockEntityClientSerializable serializable = (BlockEntityClientSerializable) entity;
|
||||
|
|
|
@ -68,7 +68,7 @@ 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 = "stitch")
|
||||
public Set<Identifier> setHook(Set<Identifier> set) {
|
||||
fabric_injectedSprites = new HashMap<>();
|
||||
ClientSpriteRegistryCallback.Registry registry = new ClientSpriteRegistryCallback.Registry(fabric_injectedSprites, set::add);
|
||||
|
|
|
@ -24,9 +24,9 @@ import net.minecraft.client.network.ClientPlayerInteractionManager;
|
|||
import net.minecraft.client.world.ClientWorld;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.server.network.packet.PlayerInteractBlockServerPacket;
|
||||
import net.minecraft.server.network.packet.PlayerInteractEntityServerPacket;
|
||||
import net.minecraft.server.network.packet.PlayerInteractItemServerPacket;
|
||||
import net.minecraft.server.network.packet.PlayerInteractBlockC2SPacket;
|
||||
import net.minecraft.server.network.packet.PlayerInteractEntityC2SPacket;
|
||||
import net.minecraft.server.network.packet.PlayerInteractItemC2SPacket;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
|
@ -79,7 +79,7 @@ public class MixinClientPlayerInteractionManager {
|
|||
ActionResult result = UseBlockCallback.EVENT.invoker().interact(player, world, hand, blockHitResult);
|
||||
if (result != ActionResult.PASS) {
|
||||
if (result == ActionResult.SUCCESS) {
|
||||
this.networkHandler.sendPacket(new PlayerInteractBlockServerPacket(hand, blockHitResult));
|
||||
this.networkHandler.sendPacket(new PlayerInteractBlockC2SPacket(hand, blockHitResult));
|
||||
}
|
||||
info.setReturnValue(result);
|
||||
info.cancel();
|
||||
|
@ -91,7 +91,7 @@ public class MixinClientPlayerInteractionManager {
|
|||
ActionResult result = UseItemCallback.EVENT.invoker().interact(player, world, hand);
|
||||
if (result != ActionResult.PASS) {
|
||||
if (result == ActionResult.SUCCESS) {
|
||||
this.networkHandler.sendPacket(new PlayerInteractItemServerPacket(hand));
|
||||
this.networkHandler.sendPacket(new PlayerInteractItemC2SPacket(hand));
|
||||
}
|
||||
info.setReturnValue(result);
|
||||
info.cancel();
|
||||
|
@ -104,7 +104,7 @@ public class MixinClientPlayerInteractionManager {
|
|||
ActionResult result = AttackEntityCallback.EVENT.invoker().interact(player, player.getEntityWorld(), Hand.MAIN /* TODO */, entity, null);
|
||||
if (result != ActionResult.PASS) {
|
||||
if (result == ActionResult.SUCCESS) {
|
||||
this.networkHandler.sendPacket(new PlayerInteractEntityServerPacket(entity));
|
||||
this.networkHandler.sendPacket(new PlayerInteractEntityC2SPacket(entity));
|
||||
}
|
||||
info.cancel();
|
||||
}
|
||||
|
@ -116,7 +116,7 @@ public class MixinClientPlayerInteractionManager {
|
|||
if (result != ActionResult.PASS) {
|
||||
if (result == ActionResult.SUCCESS) {
|
||||
Vec3d hitVec = hitResult.getPos().subtract(entity.x, entity.y, entity.z);
|
||||
this.networkHandler.sendPacket(new PlayerInteractEntityServerPacket(entity, hand, hitVec));
|
||||
this.networkHandler.sendPacket(new PlayerInteractEntityC2SPacket(entity, hand, hitVec));
|
||||
}
|
||||
info.setReturnValue(result);
|
||||
info.cancel();
|
||||
|
|
|
@ -40,7 +40,7 @@ public abstract class MixinMinecraftClient {
|
|||
private boolean fabric_itemPickSucceeded;
|
||||
private boolean fabric_itemPickCancelled;
|
||||
|
||||
@Redirect(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/MinecraftClient;doItemPick()V"), method = "method_1508")
|
||||
@Redirect(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/MinecraftClient;doItemPick()V"), method = "handleInputEvents")
|
||||
private void sillyRedirection() {
|
||||
fabric_doItemPickWrapper();
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ import net.fabricmc.fabric.api.event.player.UseEntityCallback;
|
|||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.server.network.ServerPlayNetworkHandler;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.network.packet.PlayerInteractEntityServerPacket;
|
||||
import net.minecraft.server.network.packet.PlayerInteractEntityC2SPacket;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.hit.EntityHitResult;
|
||||
import net.minecraft.world.World;
|
||||
|
@ -36,7 +36,7 @@ public class MixinServerPlayNetworkHandler {
|
|||
public ServerPlayerEntity player;
|
||||
|
||||
@Inject(method = "onPlayerInteractEntity", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;interactAt(Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/util/math/Vec3d;Lnet/minecraft/util/Hand;)Lnet/minecraft/util/ActionResult;"), cancellable = true)
|
||||
public void onPlayerInteractEntity(PlayerInteractEntityServerPacket packet, CallbackInfo info) {
|
||||
public void onPlayerInteractEntity(PlayerInteractEntityC2SPacket packet, CallbackInfo info) {
|
||||
World world = player.getEntityWorld();
|
||||
Entity entity = packet.getEntity(world);
|
||||
if (entity != null) {
|
||||
|
|
|
@ -19,7 +19,7 @@ package net.fabricmc.fabric.mixin.events.playerinteraction;
|
|||
import net.fabricmc.fabric.api.event.player.AttackBlockCallback;
|
||||
import net.fabricmc.fabric.api.event.player.UseBlockCallback;
|
||||
import net.fabricmc.fabric.api.event.player.UseItemCallback;
|
||||
import net.minecraft.client.network.packet.BlockUpdateClientPacket;
|
||||
import net.minecraft.client.network.packet.BlockUpdateS2CPacket;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
|
@ -50,7 +50,7 @@ public class MixinServerPlayerInteractionManager {
|
|||
ActionResult result = AttackBlockCallback.EVENT.invoker().interact(player, world, Hand.MAIN, pos, direction);
|
||||
if (result != ActionResult.PASS) {
|
||||
// The client might have broken the block on its side, so make sure to let it know.
|
||||
this.player.networkHandler.sendPacket(new BlockUpdateClientPacket(world, pos));
|
||||
this.player.networkHandler.sendPacket(new BlockUpdateS2CPacket(world, pos));
|
||||
info.cancel();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,8 +27,8 @@ import net.minecraft.class_2901;
|
|||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.gui.Screen;
|
||||
import net.minecraft.client.network.ClientPlayNetworkHandler;
|
||||
import net.minecraft.client.network.packet.CustomPayloadClientPacket;
|
||||
import net.minecraft.client.network.packet.GameJoinClientPacket;
|
||||
import net.minecraft.client.network.packet.CustomPayloadS2CPacket;
|
||||
import net.minecraft.client.network.packet.GameJoinS2CPacket;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.network.ClientConnection;
|
||||
import net.minecraft.network.Packet;
|
||||
|
@ -50,20 +50,20 @@ public abstract class MixinClientPlayNetworkHandler implements PacketContext {
|
|||
public abstract void sendPacket(Packet<?> var1);
|
||||
|
||||
@Inject(at = @At("RETURN"), method = "onGameJoin")
|
||||
public void onGameJoin(GameJoinClientPacket packet, CallbackInfo info) {
|
||||
public void onGameJoin(GameJoinS2CPacket packet, CallbackInfo info) {
|
||||
sendPacket(PacketRegistryImpl.createInitialRegisterPacket(ClientSidePacketRegistry.INSTANCE));
|
||||
}
|
||||
|
||||
// Optional hook: it only removes a warning message.
|
||||
@Inject(method = "onCustomPayload", at = @At(value = "CONSTANT", args = "stringValue=Unknown custom packed identifier: {}"), cancellable = true, require = 0)
|
||||
public void onCustomPayloadNotFound(CustomPayloadClientPacket packet, CallbackInfo info) {
|
||||
public void onCustomPayloadNotFound(CustomPayloadS2CPacket packet, CallbackInfo info) {
|
||||
if (packet.getChannel().equals(PacketTypes.REGISTER) || packet.getChannel().equals(PacketTypes.UNREGISTER)) {
|
||||
info.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "onCustomPayload", at = @At("HEAD"), cancellable = true)
|
||||
public void onCustomPayload(CustomPayloadClientPacket packet, CallbackInfo info) {
|
||||
public void onCustomPayload(CustomPayloadS2CPacket packet, CallbackInfo info) {
|
||||
if (((ClientSidePacketRegistryImpl) ClientSidePacketRegistry.INSTANCE).accept(packet.getChannel(), this, packet.getData())) {
|
||||
info.cancel();
|
||||
}
|
||||
|
|
|
@ -17,13 +17,13 @@
|
|||
package net.fabricmc.fabric.mixin.networking;
|
||||
|
||||
import net.fabricmc.fabric.impl.network.CustomPayloadC2SPacketAccessor;
|
||||
import net.minecraft.server.network.packet.CustomPayloadServerPacket;
|
||||
import net.minecraft.server.network.packet.CustomPayloadC2SPacket;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.PacketByteBuf;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
||||
@Mixin(CustomPayloadServerPacket.class)
|
||||
@Mixin(CustomPayloadC2SPacket.class)
|
||||
public class MixinCustomPayloadC2SPacket implements CustomPayloadC2SPacketAccessor {
|
||||
@Shadow
|
||||
private Identifier channel;
|
||||
|
|
|
@ -25,7 +25,7 @@ import net.minecraft.entity.player.PlayerEntity;
|
|||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.network.ServerPlayNetworkHandler;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.network.packet.CustomPayloadServerPacket;
|
||||
import net.minecraft.server.network.packet.CustomPayloadC2SPacket;
|
||||
import net.minecraft.util.ThreadTaskQueue;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
@ -41,7 +41,7 @@ public class MixinServerPlayNetworkHandler implements PacketContext {
|
|||
private ServerPlayerEntity player;
|
||||
|
||||
@Inject(method = "onCustomPayload", at = @At("HEAD"), cancellable = true)
|
||||
public void onCustomPayload(CustomPayloadServerPacket packet, CallbackInfo info) {
|
||||
public void onCustomPayload(CustomPayloadC2SPacket packet, CallbackInfo info) {
|
||||
CustomPayloadC2SPacketAccessor accessor = ((CustomPayloadC2SPacketAccessor) packet);
|
||||
|
||||
if (((ServerSidePacketRegistryImpl) ServerSidePacketRegistry.INSTANCE).accept(accessor.getChannel(), this, accessor.getData())) {
|
||||
|
|
|
@ -20,7 +20,7 @@ import net.fabricmc.fabric.impl.registry.RegistrySyncManager;
|
|||
import net.fabricmc.fabric.impl.registry.RemapException;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.NbtIo;
|
||||
import net.minecraft.world.OldWorldSaveHandler;
|
||||
import net.minecraft.world.WorldSaveHandler;
|
||||
import net.minecraft.world.level.LevelProperties;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
|
@ -34,7 +34,7 @@ import java.io.FileInputStream;
|
|||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
@Mixin(value = OldWorldSaveHandler.class)
|
||||
@Mixin(WorldSaveHandler.class)
|
||||
public class MixinWorldSaveHandler {
|
||||
private static final int ID_REGISTRY_BACKUPS = 3;
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ public class MixinMinecraftGame {
|
|||
@Shadow
|
||||
private ReloadableResourceManager resourceManager;
|
||||
|
||||
@Inject(method = "reloadResources()V", at = @At(value = "INVOKE", target = "Lnet/minecraft/resource/ReloadableResourceManager;reload(Ljava/util/List;)V", ordinal = 0), locals = LocalCapture.CAPTURE_FAILHARD)
|
||||
@Inject(method = "reloadResources()V", at = @At(value = "INVOKE", target = "Lnet/minecraft/resource/ReloadableResourceManager;reload(Ljava/util/concurrent/Executor;Ljava/util/concurrent/Executor;Ljava/util/List;Ljava/util/concurrent/CompletableFuture;)Ljava/util/concurrent/CompletableFuture;", ordinal = 0), locals = LocalCapture.CAPTURE_FAILHARD)
|
||||
public void reloadResources(CallbackInfo info, List<ResourcePack> list) {
|
||||
List<ResourcePack> oldList = Lists.newArrayList(list);
|
||||
list.clear();
|
||||
|
|
|
@ -24,20 +24,23 @@ import org.spongepowered.asm.mixin.Shadow;
|
|||
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.CallbackInfoReturnable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
@Mixin(ReloadableResourceManagerImpl.class)
|
||||
public class MixinReloadableResourceManagerImpl {
|
||||
@Shadow
|
||||
private List<ResourceReloadListener<?>> field_17935;
|
||||
private List<ResourceReloadListener> field_17935;
|
||||
@Shadow
|
||||
private List<ResourceReloadListener<?>> field_17936;
|
||||
private List<ResourceReloadListener> field_17936;
|
||||
@Shadow
|
||||
private ResourceType type;
|
||||
|
||||
@Inject(at = @At("HEAD"), method = "reload")
|
||||
public void reload(List<ResourcePack> packs, CallbackInfo info) {
|
||||
public void reload(Executor var1, Executor var2, List<ResourcePack> packs, CompletableFuture future, CallbackInfoReturnable<CompletableFuture> info) {
|
||||
ResourceManagerHelperImpl.sort(type, field_17935);
|
||||
ResourceManagerHelperImpl.sort(type, field_17936);
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ package net.fabricmc.fabric.resources;
|
|||
import net.fabricmc.api.ClientModInitializer;
|
||||
import net.fabricmc.fabric.api.resource.IdentifiableResourceReloadListener;
|
||||
import net.fabricmc.fabric.api.resource.ResourceManagerHelper;
|
||||
import net.fabricmc.fabric.api.resource.SimpleSynchronousResourceReloadListener;
|
||||
import net.minecraft.resource.ResourceManager;
|
||||
import net.minecraft.resource.ResourceType;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
@ -31,46 +32,39 @@ import java.util.concurrent.CompletableFuture;
|
|||
public class ResourceReloadModClient implements ClientModInitializer {
|
||||
@Override
|
||||
public void onInitializeClient() {
|
||||
ResourceManagerHelper.get(ResourceType.ASSETS).addReloadListener(new IdentifiableResourceReloadListener<Void>() {
|
||||
@Override
|
||||
public CompletableFuture<Void> prepare(ResourceManager var1, Profiler var2) {
|
||||
return null;
|
||||
}
|
||||
for (int i = 64; i >= 2; i--) {
|
||||
final int _i = i;
|
||||
ResourceManagerHelper.get(ResourceType.ASSETS).registerReloadListener(new SimpleSynchronousResourceReloadListener() {
|
||||
@Override
|
||||
public void apply(ResourceManager var1) {
|
||||
System.out.println("Reloading (should run as #" + _i + ")");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(ResourceManager var1, Void var2, Profiler var3) {
|
||||
System.out.println("Reloading (should run as #2)");
|
||||
}
|
||||
@Override
|
||||
public Identifier getFabricId() {
|
||||
return new Identifier("fabric:rrmc" + _i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Identifier getFabricId() {
|
||||
return new Identifier("fabric:rrmc2");
|
||||
}
|
||||
@Override
|
||||
public Collection<Identifier> getFabricDependencies() {
|
||||
return Collections.singletonList(new Identifier("fabric:rrmc" + (_i - 1)));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Identifier> getFabricDependencies() {
|
||||
return Collections.singletonList(new Identifier("fabric:rrmc1"));
|
||||
}
|
||||
});
|
||||
|
||||
ResourceManagerHelper.get(ResourceType.ASSETS).addReloadListener(new IdentifiableResourceReloadListener<Void>() {
|
||||
ResourceManagerHelper.get(ResourceType.ASSETS).registerReloadListener(new SimpleSynchronousResourceReloadListener() {
|
||||
@Override
|
||||
public Identifier getFabricId() {
|
||||
return new Identifier("fabric:rrmc1");
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> prepare(ResourceManager var1, Profiler var2) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(ResourceManager var1, Void var2, Profiler var3) {
|
||||
public void apply(ResourceManager var1) {
|
||||
System.out.println("Reloading (should run as #1)");
|
||||
}
|
||||
});
|
||||
|
||||
ResourceManagerHelper.get(ResourceType.ASSETS).addReloadListener(new IdentifiableResourceReloadListener<Void>() {
|
||||
ResourceManagerHelper.get(ResourceType.ASSETS).registerReloadListener(new SimpleSynchronousResourceReloadListener() {
|
||||
@Override
|
||||
public Identifier getFabricId() {
|
||||
return new Identifier("fabric:rrmc_should_not_resolve");
|
||||
|
@ -82,12 +76,7 @@ public class ResourceReloadModClient implements ClientModInitializer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> prepare(ResourceManager var1, Profiler var2) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(ResourceManager var1, Void var2, Profiler var3) {
|
||||
public void apply(ResourceManager var1) {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue