Skip to content

Commit

Permalink
fix more 1.21 stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Jab125 committed Jun 10, 2024
1 parent ad5b51a commit 728219b
Show file tree
Hide file tree
Showing 15 changed files with 41 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ interface ScreenRenderPre {
* @return A {@link EventResult} determining the outcome of the event,
* the vanilla render may be cancelled by the result.
*/
EventResult render(Screen screen, GuiGraphics graphics, int mouseX, int mouseY, float delta);
EventResult render(Screen screen, GuiGraphics graphics, int mouseX, int mouseY, DeltaTracker delta);
}

@Environment(EnvType.CLIENT)
Expand All @@ -152,7 +152,7 @@ interface ScreenRenderPost {
* @param mouseY The scaled y-coordinate of the mouse cursor.
* @param delta The current tick delta.
*/
void render(Screen screen, GuiGraphics graphics, int mouseX, int mouseY, float delta);
void render(Screen screen, GuiGraphics graphics, int mouseX, int mouseY, DeltaTracker delta);
}

@Environment(EnvType.CLIENT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public interface PlayerEvent {
*/
Event<PlayerQuit> PLAYER_QUIT = EventFactory.createLoop();
/**
* @see PlayerRespawn#respawn(ServerPlayer, boolean)
* @see PlayerRespawn#respawn(ServerPlayer, boolean, net.minecraft.world.entity.Entity.RemovalReason)
*/
Event<PlayerRespawn> PLAYER_RESPAWN = EventFactory.createLoop();
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
import net.minecraft.network.protocol.game.ClientGamePacketListener;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerEntity;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player;
Expand Down Expand Up @@ -202,7 +203,7 @@ public static boolean canPlayerReceive(ServerPlayer player, CustomPacketPayload.
* @see Entity#getAddEntityPacket()
*/
@ExpectPlatform
public static Packet<ClientGamePacketListener> createAddEntityPacket(Entity entity) {
public static Packet<ClientGamePacketListener> createAddEntityPacket(Entity entity, ServerEntity serverEntity) {
throw new AssertionError();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
import net.minecraft.network.protocol.game.ClientGamePacketListener;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerEntity;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;

Expand All @@ -47,7 +48,7 @@ public class SpawnEntityPacket {
private static final CustomPacketPayload.Type<PacketPayload> PACKET_TYPE = new CustomPacketPayload.Type<>(PACKET_ID);
private static final StreamCodec<RegistryFriendlyByteBuf, PacketPayload> PACKET_CODEC = CustomPacketPayload.codec(PacketPayload::write, PacketPayload::new);

public static Packet<ClientGamePacketListener> create(Entity entity) {
public static Packet<ClientGamePacketListener> create(Entity entity, ServerEntity serverEntity) { // TODO FIX
if (entity.level().isClientSide()) {
throw new IllegalStateException("SpawnPacketUtil.create called on the logical client!");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import net.minecraft.world.level.chunk.*;
import net.minecraft.world.level.chunk.status.ChunkType;
import net.minecraft.world.level.chunk.storage.ChunkSerializer;
import net.minecraft.world.level.chunk.storage.RegionStorageInfo;
import net.minecraft.world.level.levelgen.blending.BlendingData;
import net.minecraft.world.level.lighting.LevelLightEngine;
import org.spongepowered.asm.mixin.Mixin;
Expand All @@ -43,7 +44,7 @@
@Mixin(ChunkSerializer.class)
public class MixinChunkSerializer {
@Inject(method = "read", at = @At("RETURN"), locals = LocalCapture.CAPTURE_FAILHARD)
private static void load(ServerLevel serverLevel, PoiManager poiManager, ChunkPos chunkPos, CompoundTag compoundTag,
private static void load(ServerLevel serverLevel, PoiManager poiManager, RegionStorageInfo regionStorageInfo, ChunkPos chunkPos, CompoundTag compoundTag,
CallbackInfoReturnable<ProtoChunk> cir, ChunkPos chunkPos2, UpgradeData upgradeData,
boolean bl, ListTag listTag, int i, LevelChunkSection[] levelChunkSections, boolean bl2,
ChunkSource chunkSource, LevelLightEngine levelLightEngine, Registry<Biome> registry,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,14 @@ public abstract class MixinGameRenderer {
@Final
private Minecraft minecraft;

@Shadow
public abstract void tick();

@Inject(method = "render(Lnet/minecraft/client/DeltaTracker;Z)V",
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screens/Screen;renderWithTooltip(Lnet/minecraft/client/gui/GuiGraphics;IIF)V",
ordinal = 0), locals = LocalCapture.CAPTURE_FAILEXCEPTION, cancellable = true)
public void renderScreenPre(DeltaTracker tickDelta, boolean tick, CallbackInfo ci, boolean isGameLoadFinished, int mouseX, int mouseY, Window window, Matrix4f matrix, Matrix4fStack matrices, GuiGraphics graphics) {
if (ClientGuiEvent.RENDER_PRE.invoker().render(minecraft.screen, graphics, mouseX, mouseY, tickDelta.getGameTimeDeltaTicks()).isFalse()) {
if (ClientGuiEvent.RENDER_PRE.invoker().render(minecraft.screen, graphics, mouseX, mouseY, tickDelta).isFalse()) {
ci.cancel();
}
}
Expand All @@ -62,7 +65,7 @@ public void renderScreenPre(DeltaTracker tickDelta, boolean tick, CallbackInfo c
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screens/Screen;renderWithTooltip(Lnet/minecraft/client/gui/GuiGraphics;IIF)V",
shift = At.Shift.AFTER, ordinal = 0), locals = LocalCapture.CAPTURE_FAILEXCEPTION)
public void renderScreenPost(DeltaTracker tickDelta, boolean tick, CallbackInfo ci, boolean isGameLoadFinished, int mouseX, int mouseY, Window window, Matrix4f matrix, Matrix4fStack matrices, GuiGraphics graphics) {
ClientGuiEvent.RENDER_POST.invoker().render(minecraft.screen, graphics, mouseX, mouseY, tickDelta.getGameTimeDeltaTicks());
ClientGuiEvent.RENDER_POST.invoker().render(minecraft.screen, graphics, mouseX, mouseY, tickDelta);
}

@Inject(method = "reloadShaders",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
import net.minecraft.network.protocol.game.ClientGamePacketListener;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerEntity;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.util.thread.BlockableEventLoop;
import net.minecraft.world.entity.Entity;
Expand Down Expand Up @@ -132,7 +133,7 @@ public static boolean canPlayerReceive(ServerPlayer player, ResourceLocation id)
return ServerPlayNetworking.canSend(player, id);
}

public static Packet<ClientGamePacketListener> createAddEntityPacket(Entity entity) {
return SpawnEntityPacket.create(entity);
public static Packet<ClientGamePacketListener> createAddEntityPacket(Entity entity, ServerEntity serverEntity) {
return SpawnEntityPacket.create(entity, serverEntity);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
import net.minecraft.client.renderer.entity.CowRenderer;
import net.minecraft.core.component.DataComponents;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
import net.minecraft.data.registries.VanillaRegistries;
import net.minecraft.world.item.CreativeModeTabs;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
Expand Down Expand Up @@ -76,7 +78,7 @@ public static void initialize() {
CreativeTabRegistry.modifyBuiltin(BuiltInRegistries.CREATIVE_MODE_TAB.get(CreativeModeTabs.BUILDING_BLOCKS), (flags, output, canUseGameMasterBlocks) -> {
ItemStack sword = Items.DIAMOND_SWORD.getDefaultInstance();
ItemEnchantments.Mutable mutable = new ItemEnchantments.Mutable(ItemEnchantments.EMPTY);
mutable.set(Enchantments.SHARPNESS, 10);
mutable.set(VanillaRegistries.createLookup().lookup(Registries.ENCHANTMENT).orElseThrow().getOrThrow(Enchantments.SHARPNESS), 10);
sword.set(DataComponents.ENCHANTMENTS, mutable.toImmutable());
output.acceptBefore(new ItemStack(Items.OAK_WOOD), sword);
output.acceptAfter(Blocks.STRIPPED_OAK_LOG, Items.BEDROCK);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.Util;
import net.minecraft.client.DeltaTracker;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.network.chat.Component;
Expand All @@ -40,9 +41,9 @@ public class ClientOverlayMessageSink extends ConsoleMessageSink {

public ClientOverlayMessageSink() {
ClientGuiEvent.RENDER_POST.register((screen, graphics, mouseX, mouseY, delta) -> render(graphics, delta));
ClientGuiEvent.RENDER_HUD.register((graphics, tickDelta) -> {
ClientGuiEvent.RENDER_HUD.register((graphics, delta) -> {
if (Minecraft.getInstance().screen == null && !Minecraft.getInstance().gui.getDebugOverlay().showDebugScreen()) {
render(graphics, tickDelta);
render(graphics, delta);
}
});
}
Expand All @@ -53,7 +54,7 @@ public void accept(String message) {
messages.add(0, new Message(Component.literal(message), Util.getMillis()));
}

public void render(GuiGraphics graphics, float delta) {
public void render(GuiGraphics graphics, DeltaTracker delta) {
graphics.pose().pushPose();
graphics.pose().scale(0.5f, 0.5f, 1f);
var minecraft = Minecraft.getInstance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.ClientGamePacketListener;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerEntity;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.MobCategory;
Expand All @@ -46,8 +47,8 @@ public TestEntity(EntityType<? extends Cow> entityType, Level level) {
}

@Override
public Packet<ClientGamePacketListener> getAddEntityPacket() {
return NetworkManager.createAddEntityPacket(this);
public Packet<ClientGamePacketListener> getAddEntityPacket(ServerEntity entity) {
return NetworkManager.createAddEntityPacket(this, entity);
}

@Override
Expand All @@ -59,7 +60,7 @@ protected void tickDeath() {
compoundTag.putString("DeathCauser", player.getStringUUID());
RegistryFriendlyByteBuf buf = new RegistryFriendlyByteBuf(Unpooled.buffer(), this.registryAccess());
buf.writeNbt(compoundTag);
NetworkManager.sendToPlayer(player, new ResourceLocation("architectury_test", "sync_data"), buf);
NetworkManager.sendToPlayer(player, ResourceLocation.fromNamespaceAndPath("architectury_test", "sync_data"), buf);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public static void debugEvents() {
PlayerEvent.PLAYER_QUIT.register(player -> {
TestMod.SINK.accept(player.getScoreboardName() + " quit" + logSide(player.level()));
});
PlayerEvent.PLAYER_RESPAWN.register((player, conqueredEnd) -> {
PlayerEvent.PLAYER_RESPAWN.register((player, conqueredEnd, removalReason) -> {
if (!conqueredEnd) {
TestMod.SINK.accept(player.getScoreboardName() + " respawns " + logSide(player.level()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ public interface TestModNet {

// An example Server to Client message
MessageType SYNC_DATA = NET.registerS2C("sync_data", SyncDataMessage::new);
ResourceLocation BIG_DATA = new ResourceLocation(TestMod.MOD_ID, "big_data");
ResourceLocation SERVER_TO_CLIENT_TEST = new ResourceLocation(TestMod.MOD_ID, "s2c_test");
CustomPacketPayload.Type<ServerToClientTestPayload> SERVER_TO_CLIENT_TEST_PAYLOAD = new CustomPacketPayload.Type<>(new ResourceLocation(TestMod.MOD_ID, "s2c_test_payload"));
CustomPacketPayload.Type<BigDataPayload> BIG_DATA_PAYLOAD = new CustomPacketPayload.Type<>(new ResourceLocation(TestMod.MOD_ID, "big_data_payload"));
ResourceLocation BIG_DATA = ResourceLocation.fromNamespaceAndPath(TestMod.MOD_ID, "big_data");
ResourceLocation SERVER_TO_CLIENT_TEST = ResourceLocation.fromNamespaceAndPath(TestMod.MOD_ID, "s2c_test");
CustomPacketPayload.Type<ServerToClientTestPayload> SERVER_TO_CLIENT_TEST_PAYLOAD = new CustomPacketPayload.Type<>(ResourceLocation.fromNamespaceAndPath(TestMod.MOD_ID, "s2c_test_payload"));
CustomPacketPayload.Type<BigDataPayload> BIG_DATA_PAYLOAD = new CustomPacketPayload.Type<>(ResourceLocation.fromNamespaceAndPath(TestMod.MOD_ID, "big_data_payload"));
String BIG_STRING = StringUtils.repeat('a', 100000);

static void initialize() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public TestInt(int value) {
}
}

public static final Registrar<TestInt> INTS = RegistrarManager.get(TestMod.MOD_ID).<TestInt>builder(new ResourceLocation(TestMod.MOD_ID, "ints"))
public static final Registrar<TestInt> INTS = RegistrarManager.get(TestMod.MOD_ID).<TestInt>builder(ResourceLocation.fromNamespaceAndPath(TestMod.MOD_ID, "ints"))
.syncToClients()
.build();
public static final DeferredRegister<CreativeModeTab> TABS = DeferredRegister.create(TestMod.MOD_ID, Registries.CREATIVE_MODE_TAB);
Expand All @@ -95,14 +95,14 @@ public TestInt(int value) {

public static final ArchitecturyFluidAttributes TEST_FLUID_ATTRIBUTES = SimpleArchitecturyFluidAttributes.ofSupplier(() -> TestRegistries.TEST_FLUID_FLOWING, () -> TestRegistries.TEST_FLUID)
.convertToSource(true)
.flowingTexture(new ResourceLocation("block/water_flow"))
.sourceTexture(new ResourceLocation("block/water_still"))
.flowingTexture(ResourceLocation.fromNamespaceAndPath("block/water_flow"))
.sourceTexture(ResourceLocation.fromNamespaceAndPath("block/water_still"))
.blockSupplier(() -> TestRegistries.TEST_FLUID_BLOCK)
.bucketItemSupplier(() -> TestRegistries.TEST_FLUID_BUCKET)
.color(0xFF0000);

public static final RegistrySupplier<TestInt> TEST_INT = INTS.register(new ResourceLocation(TestMod.MOD_ID, "test_int"), () -> new TestInt(1));
public static final RegistrySupplier<TestInt> TEST_INT_2 = INTS.register(new ResourceLocation(TestMod.MOD_ID, "test_int_2"), () -> new TestInt(2));
public static final RegistrySupplier<TestInt> TEST_INT = INTS.register(ResourceLocation.fromNamespaceAndPath(TestMod.MOD_ID, "test_int"), () -> new TestInt(1));
public static final RegistrySupplier<TestInt> TEST_INT_2 = INTS.register(ResourceLocation.fromNamespaceAndPath(TestMod.MOD_ID, "test_int_2"), () -> new TestInt(2));

public static final RegistrySupplier<MobEffect> TEST_EFFECT = MOB_EFFECTS.register("test_effect", () ->
new MobEffect(MobEffectCategory.NEUTRAL, 0x123456) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
public class TestTags {
public static void initialize() {
// This will not be present, but it should return an empty tag
var heartParticles = TagKey.create(Registries.BLOCK, new ResourceLocation(TestMod.MOD_ID, "heart_particles"));
var heartParticles = TagKey.create(Registries.BLOCK, ResourceLocation.fromNamespaceAndPath(TestMod.MOD_ID, "heart_particles"));
// This will act like a normal tag, we have emerald block here
var heartParticles2 = TagKey.create(Registries.BLOCK, new ResourceLocation(TestMod.MOD_ID, "heart_particles2"));
var heartParticles2 = TagKey.create(Registries.BLOCK, ResourceLocation.fromNamespaceAndPath(TestMod.MOD_ID, "heart_particles2"));

BlockEvent.BREAK.register((world, pos, state, player, xp) -> {
if (player != null && !world.isClientSide() && (state.is(heartParticles) || state.is(heartParticles2))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static void initialize() {
if (ctx.hasTag(BiomeTags.IS_FOREST)) {
mutable.getGenerationProperties().addFeature(GenerationStep.Decoration.TOP_LAYER_MODIFICATION,
ResourceKey.create(Registries.PLACED_FEATURE,
new ResourceLocation(TestMod.MOD_ID + ":diamond_blocks")));
ResourceLocation.fromNamespaceAndPath(TestMod.MOD_ID, "diamond_blocks")));
}
});
});
Expand Down

0 comments on commit 728219b

Please sign in to comment.