Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,10 @@ allprojects {
testImplementation "net.fabricmc:fabric-loader-junit:${project.loader_version}"
testImplementation sourceSets.testmod.output
testImplementation 'org.mockito:mockito-core:5.4.0'

//Needed for FFAPI to compile even!
compileOnly(annotationProcessor("io.github.llamalad7:mixinextras-common:0.4.1"))
implementation(include("io.github.llamalad7:mixinextras-forge:0.4.1"))
}

test {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"compatibilityLevel": "JAVA_17",
"mixins": [
"BlockEntityMixin",
"BlockViewMixin"
"BlockViewMixin",
"WorldViewMixin"
],
"injectors": {
"defaultRequire": 1
Expand Down
2 changes: 1 addition & 1 deletion fabric-events-interaction-v0/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
archivesBaseName = "fabric-events-interaction-v0"
version = getSubprojectVersion(project)

moduleDependencies(project, ['fabric-api-base'])
moduleDependencies(project, ['fabric-api-base', 'fabric-networking-api-v1'])
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* 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.impl.event.interaction;

import org.jetbrains.annotations.Nullable;

import net.minecraft.network.ClientConnection;
import net.minecraft.network.NetworkSide;
import net.minecraft.network.PacketCallbacks;
import net.minecraft.network.packet.Packet;
import net.minecraft.server.network.ServerPlayNetworkHandler;
import net.minecraft.server.network.ServerPlayerEntity;

import net.fabricmc.fabric.impl.networking.UntrackedNetworkHandler;

public final class FakePlayerNetworkHandler extends ServerPlayNetworkHandler implements UntrackedNetworkHandler {
private static final ClientConnection FAKE_CONNECTION = new ClientConnection(NetworkSide.CLIENTBOUND);

public FakePlayerNetworkHandler(ServerPlayerEntity player) {
super(player.getServer(), FAKE_CONNECTION, player);
}

@Override
public void sendPacket(Packet<?> packet, @Nullable PacketCallbacks callbacks) { }
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"depends": {
"fabricloader": ">=0.4.0",
"fabric-api-base": "*",
"fabric-networking-api-v1": "*",
"minecraft": ">=1.15-alpha.19.37.a"
},
"entrypoints": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* 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.impl.networking;

// An internal marker interface used by the fake player API to prevent the network addon from being tracked.
public interface UntrackedNetworkHandler {
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

import net.fabricmc.fabric.impl.networking.DisconnectPacketSource;
import net.fabricmc.fabric.impl.networking.NetworkHandlerExtensions;
import net.fabricmc.fabric.impl.networking.UntrackedNetworkHandler;
import net.fabricmc.fabric.impl.networking.server.ServerPlayNetworkAddon;

// We want to apply a bit earlier than other mods which may not use us in order to prevent refCount issues
Expand All @@ -52,8 +53,10 @@ abstract class ServerPlayNetworkHandlerMixin implements NetworkHandlerExtensions
@Inject(method = "<init>", at = @At("RETURN"))
private void initAddon(CallbackInfo ci) {
this.addon = new ServerPlayNetworkAddon((ServerPlayNetworkHandler) (Object) this, this.server);
// 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
this.addon.lateInit();
if (!(this instanceof UntrackedNetworkHandler)) {
// 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
this.addon.lateInit();
}
}

@Inject(method = "onCustomPayload", at = @At("HEAD"), cancellable = true)
Expand Down
2 changes: 1 addition & 1 deletion fabric-object-builder-api-v1/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version = getSubprojectVersion(project)

moduleDependencies(project, [
'fabric-api-base',
// 'fabric-resource-loader-v0'
'fabric-resource-loader-v0'
])

testDependencies(project, [':fabric-command-api-v2'])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,13 @@

import java.util.stream.Stream;

import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import com.llamalad7.mixinextras.sugar.Cancellable;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;

import net.minecraft.entity.Entity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.random.Random;
import net.minecraft.registry.DefaultedRegistry;
import net.minecraft.village.TradeOffer;
import net.minecraft.village.TradeOffers;
Expand All @@ -47,12 +44,18 @@ private <T> Stream<T> disableVanillaCheck(DefaultedRegistry<VillagerType> instan
}

/**
* To prevent "item" -> "air" trades, if the result of a type aware trade is air, make sure no offer is created.
* To prevent crashes due to passing a {@code null} item to a {@link TradeOffer}, return a {@code null} trade offer
* early before {@code null} is passed to the constructor.
*/
@Inject(method = "create", at = @At(value = "NEW", target = "net/minecraft/village/TradeOffer"), locals = LocalCapture.CAPTURE_FAILEXCEPTION, cancellable = true, require = 0)
private void failOnNullItem(Entity entity, Random random, CallbackInfoReturnable<TradeOffer> cir, ItemStack buyingItem) {
if (buyingItem.isEmpty()) { // Will return true for an "empty" item stack that had null passed in the ctor
cir.setReturnValue(null); // Return null to prevent creation of empty trades
@ModifyExpressionValue(
method = "create",
at = @At(value = "INVOKE", target = "Ljava/util/Map;get(Ljava/lang/Object;)Ljava/lang/Object;")
)
private Object failOnNullItem(Object item, @Cancellable CallbackInfoReturnable<TradeOffer> cir) {
if (item == null) {
cir.setReturnValue(null);
}

return item;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"FabricMC"
],
"depends": {
"fabricloader": ">=0.8.2",
"fabricloader": ">=0.16.10",
"fabric-api-base": "*"
},
"description": "Builders for objects vanilla has locked down.",
Expand Down
Loading