Skip to content

Commit

Permalink
Finish 1.20.1 port
Browse files Browse the repository at this point in the history
  • Loading branch information
Su5eD committed Jul 9, 2023
1 parent 0888c51 commit b909fbe
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
@Mixin(ServerPlayerEntity.class)
abstract class ServerPlayerEntityMixin extends LivingEntityMixin {
@Shadow
public abstract ServerWorld method_51469();
public abstract ServerWorld getServerWorld();

/**
* Minecraft by default does not call Entity#onKilledOther for a ServerPlayerEntity being killed.
Expand All @@ -67,8 +67,8 @@ private void callOnKillForPlayer(DamageSource source, CallbackInfo ci) {

// If the damage source that killed the player was an entity, then fire the event.
if (attacker != null) {
attacker.onKilledOther(this.method_51469(), (ServerPlayerEntity) (Object) this);
ServerEntityCombatEvents.AFTER_KILLED_OTHER_ENTITY.invoker().afterKilledOtherEntity(this.method_51469(), attacker, (ServerPlayerEntity) (Object) this);
attacker.onKilledOther(this.getServerWorld(), (ServerPlayerEntity) (Object) this);
ServerEntityCombatEvents.AFTER_KILLED_OTHER_ENTITY.invoker().afterKilledOtherEntity(this.getServerWorld(), attacker, (ServerPlayerEntity) (Object) this);
}
}

Expand All @@ -83,7 +83,7 @@ private void notifyDeath(DamageSource source, CallbackInfo ci) {
*/
@Inject(method = "worldChanged(Lnet/minecraft/server/world/ServerWorld;)V", at = @At("TAIL"))
private void afterWorldChanged(ServerWorld origin, CallbackInfo ci) {
ServerEntityWorldChangeEvents.AFTER_PLAYER_CHANGE_WORLD.invoker().afterChangeWorld((ServerPlayerEntity) (Object) this, origin, this.method_51469());
ServerEntityWorldChangeEvents.AFTER_PLAYER_CHANGE_WORLD.invoker().afterChangeWorld((ServerPlayerEntity) (Object) this, origin, this.getServerWorld());
}

@Redirect(method = "trySleep", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/BlockState;get(Lnet/minecraft/state/property/Property;)Ljava/lang/Comparable;"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,11 @@

import net.minecraft.block.AbstractBlock;

import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;

public class FabricBlockSettingsTest implements ModInitializer {
@Override
public void onInitialize() {
public class FabricBlockSettingsTest {

public static void onInitialize() {
final List<String> missingMethods = new ArrayList<>();

for (Method method : FabricBlockSettings.class.getMethods()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public ObjectBuilderTestConstants() {
if (FMLLoader.getDist() == Dist.CLIENT) {
bus.addListener(TealSignClientTest::onInitializeClient);
}
FabricBlockSettingsTest.onInitialize();
BlockEntityTypeBuilderTest.onInitialize(bus);
CriterionRegistryTest.init();
TealSignTest.onInitialize(bus);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,28 @@

package net.fabricmc.fabric.test.registry.sync;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicBoolean;

import com.mojang.logging.LogUtils;
import it.unimi.dsi.fastutil.objects.Object2IntMap;
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;

import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
import net.fabricmc.fabric.api.event.registry.DynamicRegistrySetupCallback;
import net.fabricmc.fabric.api.event.registry.FabricRegistryBuilder;
import net.fabricmc.fabric.api.event.registry.RegistryAttribute;
import net.fabricmc.fabric.api.event.registry.RegistryAttributeHolder;
import net.fabricmc.fabric.impl.registry.sync.RegistrySyncManager;
import net.fabricmc.fabric.impl.registry.sync.RemapException;
import net.fabricmc.fabric.impl.registry.sync.packet.DirectRegistryPacketHandler;
import net.fabricmc.fabric.impl.registry.sync.packet.NbtRegistryPacketHandler;
import net.fabricmc.fabric.impl.registry.sync.packet.RegistryPacketHandler;
import net.fabricmc.fabric.test.registry.sync.client.RegistrySyncTestClient;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegisterEvent;
import net.minecraftforge.registries.RegistryObject;
import org.apache.commons.lang3.Validate;
import org.slf4j.Logger;

import net.minecraft.block.AbstractBlock;
import net.minecraft.block.Block;
import net.minecraft.block.Material;
import net.minecraft.item.BlockItem;
import net.minecraft.item.Item;
import net.minecraft.registry.Registries;
Expand All @@ -47,24 +49,14 @@
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Identifier;

import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.fml.loading.FMLLoader;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegisterEvent;
import net.minecraftforge.registries.RegistryObject;
import org.apache.commons.lang3.Validate;
import org.slf4j.Logger;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicBoolean;
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
import net.fabricmc.fabric.api.event.registry.DynamicRegistrySetupCallback;
import net.fabricmc.fabric.api.event.registry.FabricRegistryBuilder;
import net.fabricmc.fabric.api.event.registry.RegistryAttribute;
import net.fabricmc.fabric.api.event.registry.RegistryAttributeHolder;
import net.fabricmc.fabric.impl.registry.sync.RegistrySyncManager;
import net.fabricmc.fabric.impl.registry.sync.RemapException;

@Mod("fabric_registry_sync_v0_v1_testmod")
public class RegistrySyncTest {
Expand All @@ -76,48 +68,25 @@ public class RegistrySyncTest {
public static final boolean REGISTER_BLOCKS = Boolean.parseBoolean(System.getProperty("fabric.registry.sync.test.register.blocks", "true"));
public static final boolean REGISTER_ITEMS = Boolean.parseBoolean(System.getProperty("fabric.registry.sync.test.register.items", "true"));

public static final Identifier PACKET_CHECK_DIRECT = new Identifier("fabric-registry-sync-v0-v1-testmod:packet_check/direct");
public static final RegistryPacketHandler DIRECT_PACKET_HANDLER = new DirectRegistryPacketHandler() {
@Override
public Identifier getPacketId() {
return PACKET_CHECK_DIRECT;
}
};

public static final Identifier PACKET_CHECK_NBT = new Identifier("fabric-registry-sync-v0-v1-testmod:packet_check/nbt");
public static final RegistryPacketHandler NBT_PACKET_HANDLER = new NbtRegistryPacketHandler() {
@Override
public Identifier getPacketId() {
return PACKET_CHECK_NBT;
}
};

public static final Identifier PACKET_CHECK_COMPARE = new Identifier("fabric-registry-sync-v0-v1-testmod:packet_check/compare");

@Override
public void onInitialize() {
ServerPlayConnectionEvents.JOIN.register((handler, sender, server) -> {
Map<Identifier, Object2IntMap<Identifier>> map = RegistrySyncManager.createAndPopulateRegistryMap(true, null);
NBT_PACKET_HANDLER.sendPacket(handler.player, map);
DIRECT_PACKET_HANDLER.sendPacket(handler.player, map);
sender.sendPacket(PACKET_CHECK_COMPARE, PacketByteBufs.empty());
});
private static final List<DeferredRegister<?>> REGISTERS = new ArrayList<>();
private static final RegistryKey<Registry<String>> FABRIC_REGISTRY_KEY = RegistryKey.ofRegistry(new Identifier("registry_sync", "fabric_registry"));
private static SimpleRegistry<String> fabricRegistry;

static {
if (REGISTER_BLOCKS) {
// For checking raw id bulk in direct registry packet, make registry_sync namespace have two bulks.
registerBlocks("registry_sync", 5, 0);
registerBlocks("registry_sync2", 50, 0);
registerBlocks("registry_sync", 2, 5);

Validate.isTrue(RegistryAttributeHolder.get(Registries.BLOCK).hasAttribute(RegistryAttribute.MODDED), "Modded block was registered but registry not marked as modded");

if (REGISTER_ITEMS) {
Validate.isTrue(RegistryAttributeHolder.get(Registries.ITEM).hasAttribute(RegistryAttribute.MODDED), "Modded item was registered but registry not marked as modded");
}
}
}

RegistryKey<Registry<String>> fabricRegistryKey = RegistryKey.ofRegistry(new Identifier("registry_sync", "fabric_registry"));
SimpleRegistry<String> fabricRegistry = FabricRegistryBuilder.createSimple(fabricRegistryKey)
public RegistrySyncTest() {
IEventBus bus = FMLJavaModLoadingContext.get().getModEventBus();
REGISTERS.forEach(r -> r.register(bus));
bus.addListener(RegistrySyncTest::onCommonSetup);
bus.addListener(RegistrySyncTest::onRegister);
fabricRegistry = FabricRegistryBuilder.createSimple(FABRIC_REGISTRY_KEY)
.attribute(RegistryAttribute.SYNCED)
.buildAndRegister();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ public abstract class BlockModelRendererMixin {
@Unique
private final ThreadLocal<BlockRenderContext> fabric_contexts = ThreadLocal.withInitial(BlockRenderContext::new);

@Inject(at = @At("HEAD"), method = "tesselateBlock(Lnet/minecraft/world/BlockRenderView;Lnet/minecraft/client/render/model/BakedModel;Lnet/minecraft/block/BlockState;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumer;ZLnet/minecraft/util/math/random/Random;JILnet/minecraftforge/client/model/data/ModelData;Lnet/minecraft/client/render/RenderLayer;Z)V", cancellable = true)
private void hookRender(BlockRenderView blockView, BakedModel model, BlockState state, BlockPos pos, MatrixStack matrix, VertexConsumer buffer, boolean cull, Random rand, long seed, int overlay, ModelData modelData, RenderLayer renderType, boolean queryModelSpecificData, CallbackInfo ci) {
@Inject(at = @At("HEAD"), method = "tesselateBlock(Lnet/minecraft/world/BlockRenderView;Lnet/minecraft/client/render/model/BakedModel;Lnet/minecraft/block/BlockState;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumer;ZLnet/minecraft/util/math/random/Random;JILnet/minecraftforge/client/model/data/ModelData;Lnet/minecraft/client/render/RenderLayer;)V", cancellable = true)
private void hookRender(BlockRenderView blockView, BakedModel model, BlockState state, BlockPos pos, MatrixStack matrix, VertexConsumer buffer, boolean cull, Random rand, long seed, int overlay, ModelData modelData, RenderLayer renderType, CallbackInfo ci) {
if (!model.isVanillaAdapter()) {
BlockRenderContext context = fabric_contexts.get();
context.render(blockView, model, state, pos, matrix, buffer, cull, rand, seed, overlay);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ private void hookChunkBuild(float cameraX, float cameraY, float cameraZ,
* driven off of render type. (Not recommended or encouraged, but also not prevented.)
*/
@Redirect(method = "render", require = 1, at = @At(value = "INVOKE",
target = "Lnet/minecraft/client/render/block/BlockRenderManager;renderBatched(Lnet/minecraft/block/BlockState;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/world/BlockRenderView;Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumer;ZLnet/minecraft/util/math/random/Random;Lnet/minecraftforge/client/model/data/ModelData;Lnet/minecraft/client/render/RenderLayer;Z)V"))
private void hookChunkBuildTesselate(BlockRenderManager renderManager, BlockState blockState, BlockPos blockPos, BlockRenderView blockView, MatrixStack matrix, VertexConsumer bufferBuilder, boolean checkSides, Random random, ModelData modelData, RenderLayer renderLayer, boolean queryModelSpecificData) {
target = "Lnet/minecraft/client/render/block/BlockRenderManager;renderBatched(Lnet/minecraft/block/BlockState;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/world/BlockRenderView;Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumer;ZLnet/minecraft/util/math/random/Random;Lnet/minecraftforge/client/model/data/ModelData;Lnet/minecraft/client/render/RenderLayer;)V"))
private void hookChunkBuildTesselate(BlockRenderManager renderManager, BlockState blockState, BlockPos blockPos, BlockRenderView blockView, MatrixStack matrix, VertexConsumer bufferBuilder, boolean checkSides, Random random, ModelData modelData, RenderLayer renderLayer) {
if (blockState.getRenderType() == BlockRenderType.MODEL) {
final BakedModel model = renderManager.getModel(blockState);

Expand All @@ -113,7 +113,7 @@ private void hookChunkBuildTesselate(BlockRenderManager renderManager, BlockStat
}
}

renderManager.renderBatched(blockState, blockPos, blockView, matrix, bufferBuilder, checkSides, random, modelData, renderLayer, queryModelSpecificData);
renderManager.renderBatched(blockState, blockPos, blockView, matrix, bufferBuilder, checkSides, random, modelData, renderLayer);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ private void onScreenRemoveBecauseStopping(CallbackInfo ci) {

// Synthetic method in `tick`
// These two injections should be caught by "Screen#wrapScreenError" if anything fails in an event and then rethrown in the crash report
@Inject(method = { "m_231445_", "lambda$tick$40()V" }, at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/Screen;tick()V"), require = 1)
@Inject(method = { "m_231445_", "lambda$tick$42()V" }, at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/Screen;tick()V"), require = 1)
private void beforeScreenTick(CallbackInfo ci) {
// Store the screen in a variable in case someone tries to change the screen during this before tick event.
// If someone changes the screen, the after tick event will likely have class cast exceptions or an NPE.
Expand All @@ -66,7 +66,7 @@ private void beforeScreenTick(CallbackInfo ci) {
}

// Synthetic method in `tick`
@Inject(method = { "m_231445_", "lambda$tick$40()V" }, at = @At("TAIL"), require = 1, remap = false)
@Inject(method = { "m_231445_", "lambda$tick$42()V" }, at = @At("TAIL"), require = 1, remap = false)
private void afterScreenTick(CallbackInfo ci) {
ScreenEvents.afterTick(this.tickingScreen).invoker().afterTick(this.tickingScreen);
// Finally set the currently ticking screen to null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import net.minecraft.block.Block;
import net.minecraft.block.BlockEntityProvider;
import net.minecraft.block.BlockState;
import net.minecraft.block.Material;
import net.minecraft.block.ShapeContext;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.BlockEntityTicker;
Expand All @@ -39,7 +38,7 @@

public class ItemChuteBlock extends Block implements BlockEntityProvider {
public ItemChuteBlock() {
super(Settings.of(Material.METAL));
super(Settings.create());
}

private static final VoxelShape SHAPE = VoxelShapes.cuboid(
Expand Down
1 change: 0 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,5 @@ fabric-client-tags-api-v1-version=1.1.0
# FFAPI Properties
loom.platform=forge
forge_version=1.20.1-47.1.0
server_data_pack_format=12
pack_format=15
forgified_version=1.3.0
5 changes: 0 additions & 5 deletions gradle/ffapi-setup.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ allprojects {
outputDir = file("src/generated/$sourceSetName/resources")
loaderVersionString = rootProject.forge_version.tokenize('-')[1].tokenize('.')[0]
minecraftVersionString = rootProject.minecraft_version
dataPackFormat = rootProject.server_data_pack_format.toInteger()
packFormat = rootProject.pack_format.toInteger()
addMixinConfigs = sourceSet.name.startsWith("test")
accessWidener = loom.accessWidenerPath
Expand Down Expand Up @@ -307,9 +306,6 @@ abstract class GenerateForgeModMetadata extends DefaultTask {
@Input
final Property<String> minecraftVersionString = project.objects.property(String)

@Input
final Property<Integer> dataPackFormat = project.objects.property(Integer)

@Input
final Property<Integer> packFormat = project.objects.property(Integer)

Expand Down Expand Up @@ -446,7 +442,6 @@ abstract class GenerateForgeModMetadata extends DefaultTask {
description {
text "$normalModid resources"
}
"forge:server_data_pack_format" dataPackFormat.get()
pack_format packFormat.get()
}
}
Expand Down

0 comments on commit b909fbe

Please sign in to comment.