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

Commit 861e5d9

Browse files
committed
update to 1.21
1 parent 8557f29 commit 861e5d9

27 files changed

+331
-100
lines changed

gradle.properties

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ org.gradle.jvmargs=-Xmx1G
44
loom.platform=neoforge
55

66
# Base properties
7-
minecraft_version=1.20.6
8-
neoforge_version=20.6.113-beta
9-
yarn_mappings=1.20.6+build.1
10-
yarn_patch=1.20.5+build.3
7+
minecraft_version=1.21
8+
neoforge_version=21.0.21-beta
9+
yarn_mappings=1.21+build.2
10+
yarn_patch=1.21+build.4
1111

1212
# Mod Properties
1313
mod_version=0.1.1

src/main/java/net/fabricmc/fabric/api/client/networking/v1/ClientConfigurationNetworking.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.jetbrains.annotations.ApiStatus;
2323
import org.jetbrains.annotations.Nullable;
2424

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

274276
@ApiStatus.NonExtendable
275277
public interface Context {
278+
/**
279+
* @return The MinecraftClient instance
280+
*/
281+
MinecraftClient client();
282+
276283
/**
277284
* @return The packet sender
278285
*/

src/main/java/net/fabricmc/fabric/api/client/networking/v1/ClientPlayNetworking.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,9 +266,9 @@ public interface PlayPayloadHandler<T extends CustomPayload> {
266266
*
267267
* <p>An example usage of this is to display an overlay message:
268268
* <pre>{@code
269-
* // See FabricPacket for creating the payload
270-
* ClientPlayNetworking.registerReceiver(OVERLAY_PACKET_TYPE, (player, payload, responseSender) -> {
271-
* MinecraftClient.getInstance().inGameHud.setOverlayMessage(payload.message(), true);
269+
* // use PayloadTypeRegistry for registering the payload
270+
* ClientPlayNetworking.registerReceiver(OVERLAY_PACKET_TYPE, (payload, context) -> {
271+
* context.client().inGameHud.setOverlayMessage(payload.message(), true);
272272
* });
273273
* }</pre>
274274
*
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright (c) 2016, 2017, 2018, 2019 FabricMC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package net.fabricmc.fabric.api.event;
18+
19+
import java.lang.annotation.Documented;
20+
import java.lang.annotation.ElementType;
21+
import java.lang.annotation.Retention;
22+
import java.lang.annotation.RetentionPolicy;
23+
import java.lang.annotation.Target;
24+
25+
/**
26+
* Indicates that this {@link Event} is auto-invoking:
27+
* it calls the event callback implemented by a context parameter type automatically and without registration.
28+
*
29+
* <p>This means that this event can be listened to in two ways:
30+
* <ul>
31+
* <li>If the consumer is the context parameter and it implements the callback, it will be automatically invoked, don't register manually.
32+
* <li>Otherwise, there is no invocation and the listener needs manual registration as usual.
33+
* </ul>
34+
*
35+
* <p>Do note that there may be more than one context parameter.
36+
*
37+
* <p>A typical use case is feature augmentation, for example to expose raw clicks to slots.
38+
* The event callback has a slot parameter - the context parameter - and the event itself is carrying this annotation.
39+
* All the slot needs to receive slot clicks is to implement {@code SlotClickCallback} on itself.
40+
* It shouldn't do any explicit event registration like {@code SLOT_CLICK_EVENT.register(this::onSlotClick)},
41+
* otherwise it will see extraneous callback invocations.
42+
*
43+
* <p>In general, an auto-invoking event bridges the gap between the flexibility of an event with global reach,
44+
* and the convenience of implementing an interface that gets detected automatically.
45+
*
46+
* <p>This is a documentation-only annotation, the event factory has to implement the functionality explicitly by checking the parameter type and invoking it.
47+
* On top of adding this annotation, the event field or method should document which parameters are context parameters,
48+
* and under which circumstances they are invoked.
49+
*/
50+
// TODO: explore enforcing that auto-invoked listeners don't register themselves.
51+
@Documented
52+
@Retention(RetentionPolicy.RUNTIME)
53+
@Target({ ElementType.FIELD, ElementType.METHOD })
54+
public @interface AutoInvokingEvent {
55+
}

src/main/java/net/fabricmc/fabric/api/event/Event.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public final T invoker() {
6060
* The identifier of the default phase.
6161
* Have a look at {@link EventFactory#createWithPhases} for an explanation of event phases.
6262
*/
63-
public static final Identifier DEFAULT_PHASE = new Identifier("fabric", "default");
63+
public static final Identifier DEFAULT_PHASE = Identifier.of("fabric", "default");
6464

6565
/**
6666
* Register a listener to the event for the specified phase.

src/main/java/net/fabricmc/fabric/api/networking/v1/PlayerLookup.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,17 @@
2626
import net.minecraft.server.MinecraftServer;
2727
import net.minecraft.server.network.PlayerAssociatedNetworkHandler;
2828
import net.minecraft.server.network.ServerPlayerEntity;
29+
import net.minecraft.server.world.ServerChunkLoadingManager;
2930
import net.minecraft.server.world.ServerChunkManager;
3031
import net.minecraft.server.world.ServerWorld;
31-
import net.minecraft.server.world.ThreadedAnvilChunkStorage;
3232
import net.minecraft.util.math.BlockPos;
3333
import net.minecraft.util.math.ChunkPos;
3434
import net.minecraft.util.math.Vec3d;
3535
import net.minecraft.util.math.Vec3i;
3636
import net.minecraft.world.chunk.ChunkManager;
3737

3838
import net.fabricmc.fabric.mixin.networking.accessor.EntityTrackerAccessor;
39-
import net.fabricmc.fabric.mixin.networking.accessor.ThreadedAnvilChunkStorageAccessor;
39+
import net.fabricmc.fabric.mixin.networking.accessor.ServerChunkLoadingManagerAccessor;
4040

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

94-
return world.getChunkManager().threadedAnvilChunkStorage.getPlayersWatchingChunk(pos, false);
94+
return world.getChunkManager().chunkLoadingManager.getPlayersWatchingChunk(pos, false);
9595
}
9696

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

114114
if (manager instanceof ServerChunkManager) {
115-
ThreadedAnvilChunkStorage storage = ((ServerChunkManager) manager).threadedAnvilChunkStorage;
116-
EntityTrackerAccessor tracker = ((ThreadedAnvilChunkStorageAccessor) storage).getEntityTrackers().get(entity.getId());
115+
ServerChunkLoadingManager chunkLoadingManager = ((ServerChunkManager) manager).chunkLoadingManager;
116+
EntityTrackerAccessor tracker = ((ServerChunkLoadingManagerAccessor) chunkLoadingManager).getEntityTrackers().get(entity.getId());
117117

118118
// return an immutable collection to guard against accidental removals.
119119
if (tracker != null) {

src/main/java/net/fabricmc/fabric/api/networking/v1/ServerConfigurationNetworking.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,8 @@ public interface ConfigurationPacketHandler<T extends CustomPayload> {
252252
*
253253
* <p>An example usage of this:
254254
* <pre>{@code
255-
* // See FabricPacket for creating the packet
256-
* ServerConfigurationNetworking.registerReceiver(BOOM_PACKET_TYPE, (packet, responseSender) -> {
255+
* // use PayloadTypeRegistry for registering the payload
256+
* ServerConfigurationNetworking.registerReceiver(BOOM_PACKET_TYPE, (payload, context) -> {
257257
*
258258
* });
259259
* }</pre>
@@ -268,6 +268,11 @@ public interface ConfigurationPacketHandler<T extends CustomPayload> {
268268

269269
@ApiStatus.NonExtendable
270270
public interface Context {
271+
/**
272+
* @return The MinecraftServer instance
273+
*/
274+
MinecraftServer server();
275+
271276
/**
272277
* @return The ServerConfigurationNetworkHandler instance
273278
*/

src/main/java/net/fabricmc/fabric/api/networking/v1/ServerPlayNetworking.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import net.minecraft.network.listener.ClientCommonPacketListener;
2626
import net.minecraft.network.packet.CustomPayload;
2727
import net.minecraft.network.packet.Packet;
28+
import net.minecraft.server.MinecraftServer;
2829
import net.minecraft.server.network.ServerPlayNetworkHandler;
2930
import net.minecraft.server.network.ServerPlayerEntity;
3031
import net.minecraft.util.Identifier;
@@ -308,13 +309,12 @@ public interface PlayPayloadHandler<T extends CustomPayload> {
308309
* <p>An example usage of this is to create an explosion where the player is looking:
309310
* <pre>{@code
310311
* // use PayloadTypeRegistry for registering the payload
311-
* ServerPlayNetworking.registerReceiver(BoomPayload.ID, (payload, player, responseSender) -> {
312-
* ModPacketHandler.createExplosion(player, payload.fire());
312+
* ServerPlayNetworking.registerReceiver(BoomPayload.ID, (payload, context) -> {
313+
* ModPacketHandler.createExplosion(context.player(), payload.fire());
313314
* });
314315
* }</pre>
315316
*
316-
* <p>The server and the network handler can be accessed via {@link ServerPlayerEntity#server}
317-
* and {@link ServerPlayerEntity#networkHandler}, respectively.
317+
* <p>The network handler can be accessed via {@link ServerPlayerEntity#networkHandler}.
318318
*
319319
* @param payload the packet payload
320320
* @param context the play networking context
@@ -325,6 +325,11 @@ public interface PlayPayloadHandler<T extends CustomPayload> {
325325

326326
@ApiStatus.NonExtendable
327327
public interface Context {
328+
/**
329+
* @return The MinecraftServer instance
330+
*/
331+
MinecraftServer server();
332+
328333
/**
329334
* @return The player that received the packet
330335
*/

src/main/java/net/fabricmc/fabric/impl/networking/DisconnectPacketSource.java renamed to src/main/java/net/fabricmc/fabric/api/util/BooleanFunction.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,20 @@
1414
* limitations under the License.
1515
*/
1616

17-
package net.fabricmc.fabric.impl.networking;
17+
package net.fabricmc.fabric.api.util;
1818

19-
import net.minecraft.network.packet.Packet;
20-
import net.minecraft.text.Text;
21-
22-
public interface DisconnectPacketSource {
23-
Packet<?> createDisconnectPacket(Text message);
19+
/**
20+
* Represents a function that accepts a boolean-valued argument and produces a result.
21+
*
22+
* <p>This is the {@code boolean}-consuming primitive specialization for {@link java.util.function.Function}.
23+
*/
24+
@FunctionalInterface
25+
public interface BooleanFunction<R> {
26+
/**
27+
* Applies this function to the given argument.
28+
*
29+
* @param value the function argument
30+
* @return the function result
31+
*/
32+
R apply(boolean value);
2433
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright (c) 2016, 2017, 2018, 2019 FabricMC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package net.fabricmc.fabric.api.util;
18+
19+
import net.minecraft.nbt.NbtCompound;
20+
import net.minecraft.nbt.NbtElement;
21+
22+
/**
23+
* NBT type ID constants. Useful for filtering by value type in a few cases.
24+
*
25+
* <p>For the current list of types, check with {@link NbtElement}.
26+
*
27+
* @see NbtCompound#contains(String, int)
28+
* @see net.minecraft.nbt.NbtTypes#byId(int)
29+
* @deprecated Use the constants in {@link NbtElement} instead.
30+
*/
31+
@Deprecated
32+
public final class NbtType {
33+
public static final int END = 0;
34+
public static final int BYTE = 1;
35+
public static final int SHORT = 2;
36+
public static final int INT = 3;
37+
public static final int LONG = 4;
38+
public static final int FLOAT = 5;
39+
public static final int DOUBLE = 6;
40+
public static final int BYTE_ARRAY = 7;
41+
public static final int STRING = 8;
42+
public static final int LIST = 9;
43+
public static final int COMPOUND = 10;
44+
public static final int INT_ARRAY = 11;
45+
public static final int LONG_ARRAY = 12;
46+
47+
/**
48+
* Any numeric value: byte, short, int, long, float, double.
49+
*
50+
* @see NbtCompound#contains(String, int)
51+
*/
52+
public static final int NUMBER = 99;
53+
54+
private NbtType() { }
55+
}

0 commit comments

Comments
 (0)