Skip to content

Commit e6d6a87

Browse files
authored
Merge pull request #239 from SNWCreations/sync/1.20.1
Sync with upstream for MC 1.20.1
2 parents 9c4ce0c + 6980020 commit e6d6a87

File tree

17 files changed

+190
-95
lines changed

17 files changed

+190
-95
lines changed

fabric-block-view-api-v2/src/main/resources/fabric-block-view-api-v2.mixins.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"compatibilityLevel": "JAVA_17",
55
"mixins": [
66
"BlockEntityMixin",
7-
"BlockViewMixin"
7+
"BlockViewMixin",
8+
"WorldViewMixin"
89
],
910
"injectors": {
1011
"defaultRequire": 1
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
archivesBaseName = "fabric-events-interaction-v0"
22
version = getSubprojectVersion(project)
33

4-
moduleDependencies(project, ['fabric-api-base'])
4+
moduleDependencies(project, ['fabric-api-base', 'fabric-networking-api-v1'])
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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.mixin.event.interaction;
18+
19+
import org.spongepowered.asm.mixin.Mixin;
20+
21+
import net.fabricmc.fabric.impl.networking.UntrackedNetworkHandler;
22+
23+
// Connector: This class exists to implement UntrackedNetworkHandler for Forge's FakePlayerNetHandler
24+
// to ensure Fabric's instanceof check would work
25+
@SuppressWarnings("UnstableApiUsage")
26+
@Mixin(targets = "net.minecraftforge.common.util.FakePlayer$FakePlayerNetHandler")
27+
public class FakePlayerNetHandlerMixin implements UntrackedNetworkHandler {
28+
}

fabric-events-interaction-v0/src/main/resources/fabric-events-interaction-v0.mixins.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"package": "net.fabricmc.fabric.mixin.event.interaction",
44
"compatibilityLevel": "JAVA_16",
55
"mixins": [
6+
"FakePlayerNetHandlerMixin",
67
"ServerPlayerInteractionManagerMixin"
78
],
89
"injectors": {

fabric-events-interaction-v0/src/main/resources/fabric.mod.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"depends": {
1919
"fabricloader": ">=0.4.0",
2020
"fabric-api-base": "*",
21+
"fabric-networking-api-v1": "*",
2122
"minecraft": ">=1.15-alpha.19.37.a"
2223
},
2324
"entrypoints": {
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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.impl.networking;
18+
19+
// An internal marker interface used by the fake player API to prevent the network addon from being tracked.
20+
public interface UntrackedNetworkHandler {
21+
}

fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/impl/networking/server/ServerPlayNetworkAddon.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import net.fabricmc.fabric.impl.networking.AbstractChanneledNetworkAddon;
3434
import net.fabricmc.fabric.impl.networking.ChannelInfoHolder;
3535
import net.fabricmc.fabric.impl.networking.NetworkingImpl;
36+
import net.fabricmc.fabric.impl.networking.UntrackedNetworkHandler;
3637
import net.fabricmc.fabric.mixin.networking.accessor.CustomPayloadC2SPacketAccessor;
3738
import net.fabricmc.fabric.mixin.networking.accessor.ServerPlayNetworkHandlerAccessor;
3839

@@ -49,8 +50,10 @@ public ServerPlayNetworkAddon(ServerPlayNetworkHandler handler, MinecraftServer
4950
// Must register pending channels via lateinit
5051
this.registerPendingChannels((ChannelInfoHolder) this.connection);
5152

52-
// Register global receivers and attach to session
53-
this.receiver.startSession(this);
53+
if (!(handler instanceof UntrackedNetworkHandler)) {
54+
// Register global receivers and attach to session
55+
this.receiver.startSession(this);
56+
}
5457
}
5558

5659
@Override

fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/mixin/networking/ServerPlayNetworkHandlerMixin.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434

3535
import net.fabricmc.fabric.impl.networking.DisconnectPacketSource;
3636
import net.fabricmc.fabric.impl.networking.NetworkHandlerExtensions;
37+
import net.fabricmc.fabric.impl.networking.UntrackedNetworkHandler;
3738
import net.fabricmc.fabric.impl.networking.server.ServerPlayNetworkAddon;
3839

3940
// We want to apply a bit earlier than other mods which may not use us in order to prevent refCount issues
@@ -52,8 +53,11 @@ abstract class ServerPlayNetworkHandlerMixin implements NetworkHandlerExtensions
5253
@Inject(method = "<init>", at = @At("RETURN"))
5354
private void initAddon(CallbackInfo ci) {
5455
this.addon = new ServerPlayNetworkAddon((ServerPlayNetworkHandler) (Object) this, this.server);
55-
// A bit of a hack but it allows the field above to be set in case someone registers handlers during INIT event which refers to said field
56-
this.addon.lateInit();
56+
57+
if (!(this instanceof UntrackedNetworkHandler)) {
58+
// A bit of a hack but it allows the field above to be set in case someone registers handlers during INIT event which refers to said field
59+
this.addon.lateInit();
60+
}
5761
}
5862

5963
@Inject(method = "onCustomPayload", at = @At("HEAD"), cancellable = true)

fabric-object-builder-api-v1/src/main/java/net/fabricmc/fabric/mixin/object/builder/TradeOffersTypeAwareBuyForOneEmeraldFactoryMixin.java

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,43 +16,30 @@
1616

1717
package net.fabricmc.fabric.mixin.object.builder;
1818

19-
import java.util.stream.Stream;
20-
19+
import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
20+
import com.llamalad7.mixinextras.sugar.Cancellable;
2121
import org.spongepowered.asm.mixin.Mixin;
2222
import org.spongepowered.asm.mixin.injection.At;
23-
import org.spongepowered.asm.mixin.injection.Inject;
24-
import org.spongepowered.asm.mixin.injection.Redirect;
2523
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
26-
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
2724

28-
import net.minecraft.entity.Entity;
29-
import net.minecraft.item.ItemStack;
30-
import net.minecraft.util.math.random.Random;
31-
import net.minecraft.registry.DefaultedRegistry;
3225
import net.minecraft.village.TradeOffer;
3326
import net.minecraft.village.TradeOffers;
34-
import net.minecraft.village.VillagerType;
3527

3628
@Mixin(TradeOffers.TypeAwareBuyForOneEmeraldFactory.class)
3729
public abstract class TradeOffersTypeAwareBuyForOneEmeraldFactoryMixin {
3830
/**
39-
* Vanilla will check the "VillagerType -> Item" map in the stream and throw an exception for villager types not specified in the map.
40-
* This breaks any and all custom villager types.
41-
* We want to prevent this default logic so modded villager types will work.
42-
* So we return an empty stream so an exception is never thrown.
43-
*/
44-
@Redirect(method = "<init>", at = @At(value = "INVOKE", target = "Lnet/minecraft/registry/DefaultedRegistry;stream()Ljava/util/stream/Stream;"), require = 0)
45-
private <T> Stream<T> disableVanillaCheck(DefaultedRegistry<VillagerType> instance) {
46-
return Stream.empty();
47-
}
48-
49-
/**
50-
* To prevent "item" -> "air" trades, if the result of a type aware trade is air, make sure no offer is created.
31+
* To prevent crashes due to passing a {@code null} item to a {@link TradeOffer}, return a {@code null} trade offer
32+
* early before {@code null} is passed to the constructor.
5133
*/
52-
@Inject(method = "create", at = @At(value = "NEW", target = "net/minecraft/village/TradeOffer"), locals = LocalCapture.CAPTURE_FAILEXCEPTION, cancellable = true, require = 0)
53-
private void failOnNullItem(Entity entity, Random random, CallbackInfoReturnable<TradeOffer> cir, ItemStack buyingItem) {
54-
if (buyingItem.isEmpty()) { // Will return true for an "empty" item stack that had null passed in the ctor
55-
cir.setReturnValue(null); // Return null to prevent creation of empty trades
34+
@ModifyExpressionValue(
35+
method = "create",
36+
at = @At(value = "INVOKE", target = "Ljava/util/Map;get(Ljava/lang/Object;)Ljava/lang/Object;")
37+
)
38+
private Object failOnNullItem(Object item, @Cancellable CallbackInfoReturnable<TradeOffer> cir) {
39+
if (item == null) {
40+
cir.setReturnValue(null);
5641
}
42+
43+
return item;
5744
}
5845
}

fabric-object-builder-api-v1/src/main/resources/fabric.mod.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"FabricMC"
1717
],
1818
"depends": {
19-
"fabricloader": ">=0.8.2",
19+
"fabricloader": ">=0.16.10",
2020
"fabric-api-base": "*"
2121
},
2222
"description": "Builders for objects vanilla has locked down.",

0 commit comments

Comments
 (0)