Skip to content

Commit

Permalink
Port a few modules up to 1.21 (#375)
Browse files Browse the repository at this point in the history
* Move disables to be per module instead of library.

* Migrate some Entity modules

* Migrate Screen API and refactor mixins with Mixin Extras

* Add the rgb parameters to the API.

* Revert "Add the rgb parameters to the API."

This reverts commit d3d5e41.

* Update some block modules.

Leaving disabled since I had to do some hacks to test.

* Working Networking and Command API

* Working Registry API (minus dynamic)

* Get more modules working!

Disabled a bunch of dependencies on res loader, make sure to fix this before merging

* Fix some licenses

* Fix missing Item Setting methods and improve reporting.

* Update Mappings

* Port Resource Loader + Add overlay API

(cherry picked from commit 110d052)

* Fix a license and clean up some other code

(cherry picked from commit 7df0d67)

* Enable everything else! It compiles!

* Revert some accidental find and replaces

* Fix Licenses

* Make game launch!

* Fix broken test command mixin
  • Loading branch information
OroArmor authored Jul 31, 2024
1 parent eda4098 commit ca2f55b
Show file tree
Hide file tree
Showing 268 changed files with 1,969 additions and 1,609 deletions.
2 changes: 1 addition & 1 deletion build-logic/src/main/java/qsl/internal/Versions.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public final class Versions {
/**
* The target Quilt Mappings build.
*/
public static final int MAPPINGS_BUILD = 2;
public static final int MAPPINGS_BUILD = 9;

/**
* The version of Quilt Loader to use.
Expand Down
Empty file removed library/block/DISABLE
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@

import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.network.codec.PacketCodecs;
import net.minecraft.registry.Registries;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.state.property.Properties;
import net.minecraft.util.Identifier;

Expand Down Expand Up @@ -54,9 +56,10 @@ public class BlockContentRegistries {
*/
public static final RegistryEntryAttachment<Block, BlockState> FLATTENABLE = RegistryEntryAttachment
.builder(Registries.BLOCK,
new Identifier(NAMESPACE, "flattenable"),
Identifier.of(NAMESPACE, "flattenable"),
BlockState.class,
BlockState.CODEC)
BlockState.CODEC,
PacketCodecs.entryOf(Block.STATE_IDS).cast())
.build();

/**
Expand All @@ -66,9 +69,10 @@ public class BlockContentRegistries {
*/
public static final RegistryEntryAttachment<Block, ReversibleBlockEntry> OXIDIZABLE = RegistryEntryAttachment
.builder(Registries.BLOCK,
new Identifier(NAMESPACE, "oxidizable"),
Identifier.of(NAMESPACE, "oxidizable"),
ReversibleBlockEntry.class,
ReversibleBlockEntry.CODEC)
ReversibleBlockEntry.CODEC,
ReversibleBlockEntry.PACKET_CODEC)
.build();

/**
Expand All @@ -78,9 +82,10 @@ public class BlockContentRegistries {
*/
public static final RegistryEntryAttachment<Block, ReversibleBlockEntry> WAXABLE = RegistryEntryAttachment
.builder(Registries.BLOCK,
new Identifier(NAMESPACE, "waxable"),
Identifier.of(NAMESPACE, "waxable"),
ReversibleBlockEntry.class,
ReversibleBlockEntry.CODEC)
ReversibleBlockEntry.CODEC,
ReversibleBlockEntry.PACKET_CODEC)
.build();

/**
Expand All @@ -90,7 +95,7 @@ public class BlockContentRegistries {
*/
public static final RegistryEntryAttachment<Block, Block> STRIPPABLE = RegistryEntryAttachment
.builder(Registries.BLOCK,
new Identifier(NAMESPACE, "strippable"),
Identifier.of(NAMESPACE, "strippable"),
Block.class,
Registries.BLOCK.getCodec().flatXmap(block -> {
if (!block.getDefaultState().contains(Properties.AXIS)) {
Expand All @@ -104,7 +109,8 @@ public class BlockContentRegistries {
}

return DataResult.success(block);
}))
}),
PacketCodecs.registryValue(RegistryKeys.BLOCK))
.build();

/**
Expand All @@ -114,9 +120,10 @@ public class BlockContentRegistries {
*/
public static final RegistryEntryAttachment<Block, FlammableBlockEntry> FLAMMABLE = RegistryEntryAttachment
.builder(Registries.BLOCK,
new Identifier(NAMESPACE, "flammable"),
Identifier.of(NAMESPACE, "flammable"),
FlammableBlockEntry.class,
FlammableBlockEntry.CODEC)
FlammableBlockEntry.CODEC,
FlammableBlockEntry.PACKET_CODEC)
.build();

/**
Expand All @@ -126,9 +133,10 @@ public class BlockContentRegistries {
*/
public static final RegistryEntryAttachment<Block, EnchantingBooster> ENCHANTING_BOOSTERS = RegistryEntryAttachment
.builder(Registries.BLOCK,
new Identifier(NAMESPACE, "enchanting_boosters"),
Identifier.of(NAMESPACE, "enchanting_boosters"),
EnchantingBooster.class,
EnchantingBoosters.CODEC)
EnchantingBoosters.CODEC,
EnchantingBoosters.PACKET_CODEC)
.build();
}

Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,25 @@
import com.mojang.serialization.codecs.RecordCodecBuilder;
import org.jetbrains.annotations.Range;

import net.minecraft.network.RegistryByteBuf;
import net.minecraft.network.codec.PacketCodec;
import net.minecraft.network.codec.PacketCodecs;

public record FlammableBlockEntry(@Range(from = 0, to = Integer.MAX_VALUE) int burn, @Range(from = 0, to = Integer.MAX_VALUE) int spread) {
public static final Codec<FlammableBlockEntry> CODEC = RecordCodecBuilder.create(instance -> instance.group(
Codec.intRange(0, Integer.MAX_VALUE).fieldOf("burn").forGetter(FlammableBlockEntry::burn),
Codec.intRange(0, Integer.MAX_VALUE).fieldOf("spread").forGetter(FlammableBlockEntry::spread)
).apply(instance, FlammableBlockEntry::new));
public static final Codec<FlammableBlockEntry> CODEC = RecordCodecBuilder
.create(instance -> instance
.group(
Codec.intRange(0, Integer.MAX_VALUE).fieldOf("burn").forGetter(FlammableBlockEntry::burn),
Codec.intRange(0, Integer.MAX_VALUE).fieldOf("spread").forGetter(FlammableBlockEntry::spread)
).apply(instance, FlammableBlockEntry::new)
);

public static final PacketCodec<RegistryByteBuf, FlammableBlockEntry> PACKET_CODEC = PacketCodec
.tuple(
PacketCodecs.INT.cast(),
FlammableBlockEntry::burn,
PacketCodecs.INT.cast(),
FlammableBlockEntry::spread,
FlammableBlockEntry::new
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@
import com.mojang.serialization.codecs.RecordCodecBuilder;

import net.minecraft.block.Block;
import net.minecraft.network.RegistryByteBuf;
import net.minecraft.network.codec.PacketCodec;
import net.minecraft.network.codec.PacketCodecs;
import net.minecraft.registry.Registries;
import net.minecraft.registry.RegistryKeys;

public record ReversibleBlockEntry(Block block, boolean reversible) {
public static final Codec<ReversibleBlockEntry> CODEC = Codec.either(
Expand All @@ -34,4 +38,13 @@ public record ReversibleBlockEntry(Block block, boolean reversible) {
.xmap(
either -> either.map(entry -> entry, b -> new ReversibleBlockEntry(b, true)),
entry -> entry.reversible ? Either.right(entry.block) : Either.left(entry));

public static final PacketCodec<RegistryByteBuf, ReversibleBlockEntry> PACKET_CODEC = PacketCodec
.tuple(
PacketCodecs.registryValue(RegistryKeys.BLOCK).cast(),
ReversibleBlockEntry::block,
PacketCodecs.BOOL.cast(),
ReversibleBlockEntry::reversible,
ReversibleBlockEntry::new
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
import com.mojang.serialization.MapCodec;

import net.minecraft.block.BlockState;
import net.minecraft.network.RegistryByteBuf;
import net.minecraft.network.codec.PacketCodec;
import net.minecraft.network.codec.PacketCodecs;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
Expand All @@ -31,7 +34,8 @@
*/
public record ConstantBooster(float value) implements EnchantingBooster {
public static final MapCodec<ConstantBooster> CODEC = Codec.FLOAT.fieldOf("value").xmap(ConstantBooster::new, ConstantBooster::value);
public static EnchantingBoosterType TYPE = EnchantingBoosters.register(new Identifier("quilt", "constant"), CODEC);
public static final PacketCodec<RegistryByteBuf, ConstantBooster> PACKET_CODEC = PacketCodecs.FLOAT.map(ConstantBooster::new, ConstantBooster::value).cast();
public static EnchantingBoosterType TYPE = EnchantingBoosters.register(Identifier.of("quilt", "constant"), CODEC, PACKET_CODEC);

@Override
public float getEnchantingBoost(World world, BlockState state, BlockPos pos) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@

import com.mojang.serialization.MapCodec;

import net.minecraft.network.RegistryByteBuf;
import net.minecraft.network.codec.PacketCodec;

/**
* A type to identify booster variations by.
*
* @param codec the codec for the booster
* @param simpleVariant the default version of the booster when only identified by the type id
*/
public record EnchantingBoosterType(MapCodec<? extends EnchantingBooster> codec, Optional<EnchantingBooster> simpleVariant) {}
public record EnchantingBoosterType(MapCodec<? extends EnchantingBooster> codec, PacketCodec<RegistryByteBuf, ? extends EnchantingBooster> packetCodec, Optional<EnchantingBooster> simpleVariant) {}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import com.mojang.serialization.DataResult;
import com.mojang.serialization.MapCodec;

import net.minecraft.network.RegistryByteBuf;
import net.minecraft.network.codec.PacketCodec;
import net.minecraft.util.Identifier;

/**
Expand Down Expand Up @@ -77,15 +79,26 @@ public class EnchantingBoosters {
return DataResult.success(Either.right(enchantingBooster));
});

public static final PacketCodec<RegistryByteBuf, EnchantingBooster> PACKET_CODEC = Identifier
.PACKET_CODEC
.map(
TYPES::get,
type -> TYPES.inverse().get(type)
).<RegistryByteBuf>cast()
.dispatch(
EnchantingBooster::getType,
EnchantingBoosterType::packetCodec
);

/**
* Registers a non-simple booster type.
*
* @param id the booster type id
* @param codec the codec for the booster
* @return the type for the booster
*/
public static EnchantingBoosterType register(Identifier id, MapCodec<? extends EnchantingBooster> codec) {
var type = new EnchantingBoosterType(codec, Optional.empty());
public static EnchantingBoosterType register(Identifier id, MapCodec<? extends EnchantingBooster> codec, PacketCodec<RegistryByteBuf, ? extends EnchantingBooster> packetCodec) {
var type = new EnchantingBoosterType(codec, packetCodec, Optional.empty());
return register(id, type);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import java.util.List;
import java.util.Optional;

import com.mojang.serialization.Codec;
import com.mojang.serialization.MapCodec;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -33,13 +33,15 @@
import net.minecraft.block.PillarBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.network.codec.PacketCodec;
import net.minecraft.registry.Registries;
import net.minecraft.registry.tag.BlockTags;
import net.minecraft.state.property.Properties;
import net.minecraft.test.GameTest;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.GameMode;
import net.minecraft.world.World;

import org.quiltmc.loader.api.ModContainer;
Expand All @@ -65,7 +67,7 @@ public class BlockContentRegistryTest implements ModInitializer, QuiltGameTest {

@Override
public void onInitialize(ModContainer mod) {
RegistryExtensions.register(Registries.BLOCK, new Identifier(MOD_ID, "oxidizable_iron_block"),
RegistryExtensions.register(Registries.BLOCK, Identifier.of(MOD_ID, "oxidizable_iron_block"),
new OxidizableBlock(Oxidizable.OxidizationLevel.UNAFFECTED, AbstractBlock.Settings.copy(Blocks.IRON_BLOCK)),
BlockContentRegistries.OXIDIZABLE, new ReversibleBlockEntry(Blocks.IRON_BLOCK, false));

Expand Down Expand Up @@ -122,8 +124,8 @@ public void strip(QuiltTestContext context) {
}

private record EnchantingBlockStateBooster() implements EnchantingBooster {
public static EnchantingBoosterType TYPE = EnchantingBoosters.register(new Identifier(MOD_ID, "block_state_booster"),
new EnchantingBoosterType(Codec.unit(EnchantingBlockStateBooster::new), Optional.of(new EnchantingBlockStateBooster())));
public static EnchantingBoosterType TYPE = EnchantingBoosters.register(Identifier.of(MOD_ID, "block_state_booster"),
new EnchantingBoosterType(MapCodec.unit(EnchantingBlockStateBooster::new), PacketCodec.unit(new EnchantingBlockStateBooster()), Optional.of(new EnchantingBlockStateBooster())));

@Override
public float getEnchantingBoost(World world, BlockState state, BlockPos pos) {
Expand Down Expand Up @@ -176,7 +178,7 @@ void push(BlockState baseState, BlockState targetState) {
void run(QuiltTestContext context) {
this.entries.forEach(entry -> context.setBlockState(entry.pos(), entry.baseState()));

var player = context.createMockPlayer();
var player = context.createMockPlayer(GameMode.SURVIVAL);
this.entries.forEach(entry -> {
context.useStackOnBlockAt(player, this.tool, entry.pos(), Direction.UP);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
public final class QuiltBlockEntityImpl implements ModInitializer, ServerLifecycleEvents.Starting {
public static final String NAMESPACE = "quilt_block_entity";
public static final String BLOCK_ENTITY_FREEZING_PHASE = "block_entity_freezing";
public static final Identifier BLOCK_ENTITY_FREEZING_PHASE_ID = new Identifier(NAMESPACE, BLOCK_ENTITY_FREEZING_PHASE);
public static final Identifier BLOCK_ENTITY_FREEZING_PHASE_ID = Identifier.of(NAMESPACE, BLOCK_ENTITY_FREEZING_PHASE);
public static final QuiltBlockEntityImpl INSTANCE = new QuiltBlockEntityImpl();
private boolean frozen = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.text.Text;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
Expand All @@ -40,7 +39,7 @@ public AngyBlock(MapColor mapColor) {
}

@Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
protected ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, BlockHitResult hit) {
if (!world.isClient()) {
var blockEntity = BlockEntityTypeTest.COLORFUL_BLOCK_ENTITY_TYPE.get(world, pos);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void onInitialize(ModContainer mod) {
}

private static Identifier id(String path) {
return new Identifier(NAMESPACE, path);
return Identifier.of(NAMESPACE, path);
}

private static <B extends Block> B register(Identifier id, B block) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import net.minecraft.network.listener.ClientPlayPacketListener;
import net.minecraft.network.packet.Packet;
import net.minecraft.network.packet.s2c.play.BlockEntityUpdateS2CPacket;
import net.minecraft.registry.HolderLookup;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkSectionPos;

Expand Down Expand Up @@ -54,8 +55,8 @@ public int getColor() {
/* Serialization */

@Override
public void readNbt(NbtCompound nbt) {
super.readNbt(nbt);
public void method_11014(NbtCompound nbt, HolderLookup.Provider lookupProvider) {
super.method_11014(nbt, lookupProvider);

try {
this.color = Integer.parseInt(nbt.getString("color"), 16);
Expand All @@ -79,14 +80,14 @@ public void refreshRendering() {
}

@Override
public void writeNbt(NbtCompound nbt) {
super.writeNbt(nbt);
public void writeNbt(NbtCompound nbt, HolderLookup.Provider lookupProvider) {
super.writeNbt(nbt, lookupProvider);
nbt.putString("color", Integer.toHexString(this.color));
}

@Override
public NbtCompound toSyncedNbt() {
return this.toNbt();
public NbtCompound toSyncedNbt(HolderLookup.Provider lookupProvider) {
return this.toNbt(lookupProvider);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,8 @@ public QuiltBlockSettings emissiveLighting(AbstractBlock.ContextPredicate predic
}

@Override
public QuiltBlockSettings requiresTool() {
super.requiresTool();
public QuiltBlockSettings toolRequired() {
super.toolRequired();
return this;
}

Expand Down
Loading

0 comments on commit ca2f55b

Please sign in to comment.