Skip to content
This repository has been archived by the owner on Jul 6, 2024. It is now read-only.

Commit

Permalink
update to 1.21
Browse files Browse the repository at this point in the history
  • Loading branch information
TexBlock committed Jun 22, 2024
1 parent 8557f29 commit 861e5d9
Show file tree
Hide file tree
Showing 27 changed files with 331 additions and 100 deletions.
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ org.gradle.jvmargs=-Xmx1G
loom.platform=neoforge

# Base properties
minecraft_version=1.20.6
neoforge_version=20.6.113-beta
yarn_mappings=1.20.6+build.1
yarn_patch=1.20.5+build.3
minecraft_version=1.21
neoforge_version=21.0.21-beta
yarn_mappings=1.21+build.2
yarn_patch=1.21+build.4

# Mod Properties
mod_version=0.1.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;

import net.minecraft.client.MinecraftClient;
import net.minecraft.network.packet.CustomPayload;
import net.minecraft.util.Identifier;
import net.minecraft.util.thread.ThreadExecutor;
Expand Down Expand Up @@ -257,10 +258,11 @@ public interface ConfigurationPayloadHandler<T extends CustomPayload> {
* <p>Unlike {@link ClientPlayNetworking.PlayPayloadHandler} this method is executed on {@linkplain io.netty.channel.EventLoop netty's event loops}.
* Modification to the game should be {@linkplain ThreadExecutor#submit(Runnable) scheduled}.
*
* <p>An example usage of this is to display an overlay message:
* <p>An example usage of this:
* <pre>{@code
* // See FabricPacket for creating the packet
* ClientConfigurationNetworking.registerReceiver(OVERLAY_PACKET_TYPE, (packet, responseSender) -> {
* // use PayloadTypeRegistry for registering the payload
* ClientConfigurationNetworking.registerReceiver(OVERLAY_PACKET_TYPE, (payload, context) -> {
*
* });
* }</pre>
*
Expand All @@ -273,6 +275,11 @@ public interface ConfigurationPayloadHandler<T extends CustomPayload> {

@ApiStatus.NonExtendable
public interface Context {
/**
* @return The MinecraftClient instance
*/
MinecraftClient client();

/**
* @return The packet sender
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,9 @@ public interface PlayPayloadHandler<T extends CustomPayload> {
*
* <p>An example usage of this is to display an overlay message:
* <pre>{@code
* // See FabricPacket for creating the payload
* ClientPlayNetworking.registerReceiver(OVERLAY_PACKET_TYPE, (player, payload, responseSender) -> {
* MinecraftClient.getInstance().inGameHud.setOverlayMessage(payload.message(), true);
* // use PayloadTypeRegistry for registering the payload
* ClientPlayNetworking.registerReceiver(OVERLAY_PACKET_TYPE, (payload, context) -> {
* context.client().inGameHud.setOverlayMessage(payload.message(), true);
* });
* }</pre>
*
Expand Down
55 changes: 55 additions & 0 deletions src/main/java/net/fabricmc/fabric/api/event/AutoInvokingEvent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright (c) 2016, 2017, 2018, 2019 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.event;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* Indicates that this {@link Event} is auto-invoking:
* it calls the event callback implemented by a context parameter type automatically and without registration.
*
* <p>This means that this event can be listened to in two ways:
* <ul>
* <li>If the consumer is the context parameter and it implements the callback, it will be automatically invoked, don't register manually.
* <li>Otherwise, there is no invocation and the listener needs manual registration as usual.
* </ul>
*
* <p>Do note that there may be more than one context parameter.
*
* <p>A typical use case is feature augmentation, for example to expose raw clicks to slots.
* The event callback has a slot parameter - the context parameter - and the event itself is carrying this annotation.
* All the slot needs to receive slot clicks is to implement {@code SlotClickCallback} on itself.
* It shouldn't do any explicit event registration like {@code SLOT_CLICK_EVENT.register(this::onSlotClick)},
* otherwise it will see extraneous callback invocations.
*
* <p>In general, an auto-invoking event bridges the gap between the flexibility of an event with global reach,
* and the convenience of implementing an interface that gets detected automatically.
*
* <p>This is a documentation-only annotation, the event factory has to implement the functionality explicitly by checking the parameter type and invoking it.
* On top of adding this annotation, the event field or method should document which parameters are context parameters,
* and under which circumstances they are invoked.
*/
// TODO: explore enforcing that auto-invoked listeners don't register themselves.
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.FIELD, ElementType.METHOD })
public @interface AutoInvokingEvent {
}
2 changes: 1 addition & 1 deletion src/main/java/net/fabricmc/fabric/api/event/Event.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public final T invoker() {
* The identifier of the default phase.
* Have a look at {@link EventFactory#createWithPhases} for an explanation of event phases.
*/
public static final Identifier DEFAULT_PHASE = new Identifier("fabric", "default");
public static final Identifier DEFAULT_PHASE = Identifier.of("fabric", "default");

/**
* Register a listener to the event for the specified phase.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.PlayerAssociatedNetworkHandler;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerChunkLoadingManager;
import net.minecraft.server.world.ServerChunkManager;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.server.world.ThreadedAnvilChunkStorage;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.math.Vec3i;
import net.minecraft.world.chunk.ChunkManager;

import net.fabricmc.fabric.mixin.networking.accessor.EntityTrackerAccessor;
import net.fabricmc.fabric.mixin.networking.accessor.ThreadedAnvilChunkStorageAccessor;
import net.fabricmc.fabric.mixin.networking.accessor.ServerChunkLoadingManagerAccessor;

/**
* Helper methods to lookup players in a server.
Expand Down Expand Up @@ -91,7 +91,7 @@ public static Collection<ServerPlayerEntity> tracking(ServerWorld world, ChunkPo
Objects.requireNonNull(world, "The world cannot be null");
Objects.requireNonNull(pos, "The chunk pos cannot be null");

return world.getChunkManager().threadedAnvilChunkStorage.getPlayersWatchingChunk(pos, false);
return world.getChunkManager().chunkLoadingManager.getPlayersWatchingChunk(pos, false);
}

/**
Expand All @@ -112,8 +112,8 @@ public static Collection<ServerPlayerEntity> tracking(Entity entity) {
ChunkManager manager = entity.getWorld().getChunkManager();

if (manager instanceof ServerChunkManager) {
ThreadedAnvilChunkStorage storage = ((ServerChunkManager) manager).threadedAnvilChunkStorage;
EntityTrackerAccessor tracker = ((ThreadedAnvilChunkStorageAccessor) storage).getEntityTrackers().get(entity.getId());
ServerChunkLoadingManager chunkLoadingManager = ((ServerChunkManager) manager).chunkLoadingManager;
EntityTrackerAccessor tracker = ((ServerChunkLoadingManagerAccessor) chunkLoadingManager).getEntityTrackers().get(entity.getId());

// return an immutable collection to guard against accidental removals.
if (tracker != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,8 @@ public interface ConfigurationPacketHandler<T extends CustomPayload> {
*
* <p>An example usage of this:
* <pre>{@code
* // See FabricPacket for creating the packet
* ServerConfigurationNetworking.registerReceiver(BOOM_PACKET_TYPE, (packet, responseSender) -> {
* // use PayloadTypeRegistry for registering the payload
* ServerConfigurationNetworking.registerReceiver(BOOM_PACKET_TYPE, (payload, context) -> {
*
* });
* }</pre>
Expand All @@ -268,6 +268,11 @@ public interface ConfigurationPacketHandler<T extends CustomPayload> {

@ApiStatus.NonExtendable
public interface Context {
/**
* @return The MinecraftServer instance
*/
MinecraftServer server();

/**
* @return The ServerConfigurationNetworkHandler instance
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import net.minecraft.network.listener.ClientCommonPacketListener;
import net.minecraft.network.packet.CustomPayload;
import net.minecraft.network.packet.Packet;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayNetworkHandler;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Identifier;
Expand Down Expand Up @@ -308,13 +309,12 @@ public interface PlayPayloadHandler<T extends CustomPayload> {
* <p>An example usage of this is to create an explosion where the player is looking:
* <pre>{@code
* // use PayloadTypeRegistry for registering the payload
* ServerPlayNetworking.registerReceiver(BoomPayload.ID, (payload, player, responseSender) -> {
* ModPacketHandler.createExplosion(player, payload.fire());
* ServerPlayNetworking.registerReceiver(BoomPayload.ID, (payload, context) -> {
* ModPacketHandler.createExplosion(context.player(), payload.fire());
* });
* }</pre>
*
* <p>The server and the network handler can be accessed via {@link ServerPlayerEntity#server}
* and {@link ServerPlayerEntity#networkHandler}, respectively.
* <p>The network handler can be accessed via {@link ServerPlayerEntity#networkHandler}.
*
* @param payload the packet payload
* @param context the play networking context
Expand All @@ -325,6 +325,11 @@ public interface PlayPayloadHandler<T extends CustomPayload> {

@ApiStatus.NonExtendable
public interface Context {
/**
* @return The MinecraftServer instance
*/
MinecraftServer server();

/**
* @return The player that received the packet
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,20 @@
* limitations under the License.
*/

package net.fabricmc.fabric.impl.networking;
package net.fabricmc.fabric.api.util;

import net.minecraft.network.packet.Packet;
import net.minecraft.text.Text;

public interface DisconnectPacketSource {
Packet<?> createDisconnectPacket(Text message);
/**
* Represents a function that accepts a boolean-valued argument and produces a result.
*
* <p>This is the {@code boolean}-consuming primitive specialization for {@link java.util.function.Function}.
*/
@FunctionalInterface
public interface BooleanFunction<R> {
/**
* Applies this function to the given argument.
*
* @param value the function argument
* @return the function result
*/
R apply(boolean value);
}
55 changes: 55 additions & 0 deletions src/main/java/net/fabricmc/fabric/api/util/NbtType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright (c) 2016, 2017, 2018, 2019 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.util;

import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtElement;

/**
* NBT type ID constants. Useful for filtering by value type in a few cases.
*
* <p>For the current list of types, check with {@link NbtElement}.
*
* @see NbtCompound#contains(String, int)
* @see net.minecraft.nbt.NbtTypes#byId(int)
* @deprecated Use the constants in {@link NbtElement} instead.
*/
@Deprecated
public final class NbtType {
public static final int END = 0;
public static final int BYTE = 1;
public static final int SHORT = 2;
public static final int INT = 3;
public static final int LONG = 4;
public static final int FLOAT = 5;
public static final int DOUBLE = 6;
public static final int BYTE_ARRAY = 7;
public static final int STRING = 8;
public static final int LIST = 9;
public static final int COMPOUND = 10;
public static final int INT_ARRAY = 11;
public static final int LONG_ARRAY = 12;

/**
* Any numeric value: byte, short, int, long, float, double.
*
* @see NbtCompound#contains(String, int)
*/
public static final int NUMBER = 99;

private NbtType() { }
}
Loading

0 comments on commit 861e5d9

Please sign in to comment.