Skip to content

Commit

Permalink
Update for NeoForge 1.21.2
Browse files Browse the repository at this point in the history
  • Loading branch information
shedaniel committed Oct 22, 2024
1 parent b6299b2 commit 2a31c75
Show file tree
Hide file tree
Showing 29 changed files with 330 additions and 246 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,16 @@
import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.chunk.ChunkAccess;
import net.minecraft.world.level.chunk.storage.SerializableChunkData;
import org.jetbrains.annotations.Nullable;

public interface ChunkEvent {
/**
* @see SaveData#save(ChunkAccess, ServerLevel)
* @see SaveData#save(ChunkAccess, ServerLevel, SerializableChunkData)
*/
Event<SaveData> SAVE_DATA = EventFactory.createLoop();
/**
* @see LoadData#load(ChunkAccess, ServerLevel)
* @see LoadData#load(ChunkAccess, ServerLevel, SerializableChunkData)
*/
Event<LoadData> LOAD_DATA = EventFactory.createLoop();

Expand All @@ -44,8 +45,9 @@ interface SaveData {
*
* @param chunk The chunk that is saved.
* @param level The level the chunk is in.
* @param data The data.
*/
void save(ChunkAccess chunk, ServerLevel level);
void save(ChunkAccess chunk, ServerLevel level, SerializableChunkData data);
}

interface LoadData {
Expand All @@ -56,7 +58,8 @@ interface LoadData {
*
* @param chunk The chunk that is loaded.
* @param level The level the chunk is in, may be {@code null}.
* @param data The data.
*/
void load(ChunkAccess chunk, @Nullable ServerLevel level);
void load(ChunkAccess chunk, @Nullable ServerLevel level, SerializableChunkData data);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@

package dev.architectury.registry.fuel;

import dev.architectury.injectables.annotations.ExpectPlatform;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.RecipeType;
import net.minecraft.world.level.ItemLike;
import net.minecraft.world.level.block.entity.FuelValues;
import org.jetbrains.annotations.Nullable;

public final class FuelRegistry {
private FuelRegistry() {
Expand All @@ -32,19 +37,19 @@ private FuelRegistry() {
* and {@code -1} to use vanilla logic
* @param items the array of items to register for
*/
/*@ExpectPlatform
@ExpectPlatform
public static void register(int time, ItemLike... items) {
throw new AssertionError();
}*/
}

/**
* Returns the burn time of an {@link ItemStack}.
*
* @param stack the stack
* @return the burn time of the stack, returns {@code 0} if not a fuel
*/
/*@ExpectPlatform
public static int get(ItemStack stack) {
@ExpectPlatform
public static int get(ItemStack stack, @Nullable RecipeType<?> recipeType, FuelValues fuelValues) {
throw new AssertionError();
}*/
}
}
3 changes: 2 additions & 1 deletion common/src/main/resources/architectury.accessWidener
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ mutable field net/minecraft/world/level/block/state/BlockBehaviour$Properties em
accessible field net/minecraft/world/level/block/state/BlockBehaviour$Properties dynamicShape Z
mutable field net/minecraft/world/level/block/state/BlockBehaviour$Properties dynamicShape Z
accessible method net/minecraft/world/level/block/state/BlockBehaviour$Properties <init> ()V
accessible field net/minecraft/world/level/block/entity/FuelValues$Builder values Lit/unimi/dsi/fastutil/objects/Object2IntSortedMap;
transitive-accessible method net/minecraft/world/entity/player/Player closeContainer ()V
transitive-accessible method net/minecraft/advancements/CriteriaTriggers register (Ljava/lang/String;Lnet/minecraft/advancements/CriterionTrigger;)Lnet/minecraft/advancements/CriterionTrigger;
transitive-accessible method net/minecraft/world/inventory/MenuType <init> (Lnet/minecraft/world/inventory/MenuType$MenuSupplier;Lnet/minecraft/world/flag/FeatureFlagSet;)V
Expand Down Expand Up @@ -237,7 +238,6 @@ transitive-accessible method net/minecraft/world/level/block/WitherWallSkullBloc
transitive-accessible method net/minecraft/world/level/block/WoolCarpetBlock <init> (Lnet/minecraft/world/item/DyeColor;Lnet/minecraft/world/level/block/state/BlockBehaviour$Properties;)V

# RenderStateShard fields
transitive-accessible field net/minecraft/client/renderer/RenderStateShard VIEW_SCALE_Z_EPSILON F
transitive-accessible field net/minecraft/client/renderer/RenderStateShard NO_TRANSPARENCY Lnet/minecraft/client/renderer/RenderStateShard$TransparencyStateShard;
transitive-accessible field net/minecraft/client/renderer/RenderStateShard ADDITIVE_TRANSPARENCY Lnet/minecraft/client/renderer/RenderStateShard$TransparencyStateShard;
transitive-accessible field net/minecraft/client/renderer/RenderStateShard LIGHTNING_TRANSPARENCY Lnet/minecraft/client/renderer/RenderStateShard$TransparencyStateShard;
Expand All @@ -261,6 +261,7 @@ transitive-accessible field net/minecraft/client/renderer/RenderStateShard RENDE
transitive-accessible field net/minecraft/client/renderer/RenderStateShard RENDERTYPE_TRANSLUCENT_SHADER Lnet/minecraft/client/renderer/RenderStateShard$ShaderStateShard;
transitive-accessible field net/minecraft/client/renderer/RenderStateShard RENDERTYPE_TRANSLUCENT_MOVING_BLOCK_SHADER Lnet/minecraft/client/renderer/RenderStateShard$ShaderStateShard;
transitive-accessible field net/minecraft/client/renderer/RenderStateShard RENDERTYPE_ARMOR_CUTOUT_NO_CULL_SHADER Lnet/minecraft/client/renderer/RenderStateShard$ShaderStateShard;
transitive-accessible field net/minecraft/client/renderer/RenderStateShard RENDERTYPE_ARMOR_TRANSLUCENT_SHADER Lnet/minecraft/client/renderer/RenderStateShard$ShaderStateShard;
transitive-accessible field net/minecraft/client/renderer/RenderStateShard RENDERTYPE_ENTITY_SOLID_SHADER Lnet/minecraft/client/renderer/RenderStateShard$ShaderStateShard;
transitive-accessible field net/minecraft/client/renderer/RenderStateShard RENDERTYPE_ENTITY_CUTOUT_SHADER Lnet/minecraft/client/renderer/RenderStateShard$ShaderStateShard;
transitive-accessible field net/minecraft/client/renderer/RenderStateShard RENDERTYPE_ENTITY_CUTOUT_NO_CULL_SHADER Lnet/minecraft/client/renderer/RenderStateShard$ShaderStateShard;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,18 @@

package dev.architectury.mixin.fabric;

import com.llamalad7.mixinextras.sugar.Local;
import dev.architectury.event.events.common.ChunkEvent;
import net.minecraft.server.level.ChunkMap;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.chunk.ChunkAccess;
import net.minecraft.world.level.chunk.storage.SerializableChunkData;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;

@Mixin(ChunkMap.class)
public class MixinChunkMap {
Expand All @@ -39,10 +40,9 @@ public class MixinChunkMap {

@Inject(
method = "save",
at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ChunkMap;write(Lnet/minecraft/world/level/ChunkPos;Ljava/util/function/Supplier;)Ljava/util/concurrent/CompletableFuture;", ordinal = 0),
locals = LocalCapture.CAPTURE_FAILHARD
at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ChunkMap;write(Lnet/minecraft/world/level/ChunkPos;Ljava/util/function/Supplier;)Ljava/util/concurrent/CompletableFuture;", ordinal = 0)
)
private void save(ChunkAccess chunkAccess, CallbackInfoReturnable<Boolean> cir) {
ChunkEvent.SAVE_DATA.invoker().save(chunkAccess, this.level);
private void save(ChunkAccess chunkAccess, CallbackInfoReturnable<Boolean> cir, @Local SerializableChunkData data) {
ChunkEvent.SAVE_DATA.invoker().save(chunkAccess, this.level, data);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public class MixinSerializableChunkData {
private void load(ServerLevel serverLevel, PoiManager poiManager, RegionStorageInfo regionStorageInfo, ChunkPos chunkPos,
CallbackInfoReturnable<ProtoChunk> cir,
@Local ChunkAccess chunkAccess) {
// TODO: Get the CompoundTag from constructor somewhere
ChunkEvent.LOAD_DATA.invoker().load(chunkAccess, serverLevel);
ChunkEvent.LOAD_DATA.invoker().load(chunkAccess, serverLevel, (SerializableChunkData) (Object) this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,24 +50,18 @@ public class MixinMouseHandler {
@Shadow
private double ypos;

@Inject(method = "onScroll",
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screens/Screen;mouseScrolled(DDDD)Z",
ordinal = 0), cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD)
public void onMouseScrolled(long handle, double xOffset, double yOffset, CallbackInfo info, boolean discreteMouseScroll, double mouseWheelSensitivity, double amountX, double amountY, double x, double y) {
if (!info.isCancelled()) {
var result = ClientScreenInputEvent.MOUSE_SCROLLED_PRE.invoker().mouseScrolled(minecraft, minecraft.screen, x, y, amountX, amountY);
if (result.isPresent())
info.cancel();
@WrapOperation(method = "onScroll", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screens/Screen;mouseScrolled(DDDD)Z", ordinal = 0))
private boolean onGuiMouseClicked(Screen instance, double mouseX, double mouseY, double amountX, double amountY, Operation<Boolean> original) {
var minecraft = Minecraft.getInstance();
var result = ClientScreenInputEvent.MOUSE_SCROLLED_PRE.invoker().mouseScrolled(minecraft, minecraft.screen, mouseX, mouseY, amountX, amountY);
if (result.isPresent()) {
return true;
}
}

@Inject(method = "onScroll",
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screens/Screen;mouseScrolled(DDDD)Z",
ordinal = 0, shift = At.Shift.AFTER), cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD)
public void onMouseScrolledPost(long handle, double xOffset, double yOffset, CallbackInfo info, boolean discreteMouseScroll, double mouseWheelSensitivity, double amountX, double amountY, double x, double y) {
if (!info.isCancelled()) {
var result = ClientScreenInputEvent.MOUSE_SCROLLED_POST.invoker().mouseScrolled(minecraft, minecraft.screen, x, y, amountX, amountY);
if (original.call(instance, mouseX, mouseY, amountX, amountY)) {
return true;
}
result = ClientScreenInputEvent.MOUSE_SCROLLED_POST.invoker().mouseScrolled(minecraft, minecraft.screen, mouseX, mouseY, amountX, amountY);
return result.isPresent();
}

@Inject(method = "onScroll",
Expand All @@ -81,28 +75,18 @@ public void onRawMouseScrolled(long handle, double xOffset, double yOffset, Call
}
}

@Inject(method = "onPress", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screens/Screen;mouseClicked(DDI)Z", ordinal = 0), cancellable = true)
private void onGuiMouseClicked(long window, int button, int action, int mods, CallbackInfo info,
@Local(ordinal = 0) double mouseX, @Local(ordinal = 1) double mouseY, @Local(ordinal = 3) int b) {
@WrapOperation(method = "onPress", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screens/Screen;mouseClicked(DDI)Z", ordinal = 0))
private boolean onGuiMouseClicked(Screen instance, double mouseX, double mouseY, int b, Operation<Boolean> original) {
var minecraft = Minecraft.getInstance();
if (!info.isCancelled()) {
var result = ClientScreenInputEvent.MOUSE_CLICKED_PRE.invoker().mouseClicked(minecraft, minecraft.screen, mouseX, mouseY, b);
if (result.isPresent()) {
info.cancel();
}
var result = ClientScreenInputEvent.MOUSE_CLICKED_PRE.invoker().mouseClicked(minecraft, minecraft.screen, mouseX, mouseY, b);
if (result.isPresent()) {
return true;
}
}

@Inject(method = "onPress", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screens/Screen;mouseClicked(DDI)Z", ordinal = 0, shift = At.Shift.AFTER), cancellable = true)
private void onGuiMouseClickedPost(long window, int button, int action, int mods, CallbackInfo info,
@Local(ordinal = 0) double mouseX, @Local(ordinal = 1) double mouseY, @Local(ordinal = 3) int b) {
var minecraft = Minecraft.getInstance();
if (!info.isCancelled()) {
var result = ClientScreenInputEvent.MOUSE_CLICKED_POST.invoker().mouseClicked(minecraft, minecraft.screen, mouseX, mouseY, b);
if (result.isPresent()) {
info.cancel();
}
if (original.call(instance, mouseX, mouseY, b)) {
return true;
}
result = ClientScreenInputEvent.MOUSE_CLICKED_POST.invoker().mouseClicked(minecraft, minecraft.screen, mouseX, mouseY, b);
return result.isPresent();
}

@Inject(method = "onPress", at = @At(value = "INVOKE",
Expand All @@ -125,28 +109,18 @@ public void onRawMouseClickedPost(long handle, int button, int action, int mods,
}
}

@Inject(method = "onPress", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screens/Screen;mouseReleased(DDI)Z", ordinal = 0), cancellable = true)
private void onGuiMouseReleased(long window, int button, int action, int mods, CallbackInfo info,
@Local(ordinal = 0) double mouseX, @Local(ordinal = 1) double mouseY, @Local(ordinal = 3) int b) {
@WrapOperation(method = "onPress", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screens/Screen;mouseReleased(DDI)Z", ordinal = 0))
private boolean onGuiMouseReleased(Screen instance, double mouseX, double mouseY, int b, Operation<Boolean> original) {
var minecraft = Minecraft.getInstance();
if (!info.isCancelled()) {
var result = ClientScreenInputEvent.MOUSE_RELEASED_PRE.invoker().mouseReleased(minecraft, minecraft.screen, mouseX, mouseY, b);
if (result.isPresent()) {
info.cancel();
}
var result = ClientScreenInputEvent.MOUSE_RELEASED_PRE.invoker().mouseReleased(minecraft, minecraft.screen, mouseX, mouseY, b);
if (result.isPresent()) {
return true;
}
}

@Inject(method = "onPress", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screens/Screen;mouseReleased(DDI)Z", ordinal = 0, shift = At.Shift.AFTER), cancellable = true)
private void onGuiMouseReleasedPost(long window, int button, int action, int mods, CallbackInfo info,
@Local(ordinal = 0) double mouseX, @Local(ordinal = 1) double mouseY, @Local(ordinal = 3) int b) {
var minecraft = Minecraft.getInstance();
if (!info.isCancelled()) {
var result = ClientScreenInputEvent.MOUSE_RELEASED_POST.invoker().mouseReleased(minecraft, minecraft.screen, mouseX, mouseY, b);
if (result.isPresent()) {
info.cancel();
}
if (original.call(instance, mouseX, mouseY, b)) {
return true;
}
result = ClientScreenInputEvent.MOUSE_RELEASED_POST.invoker().mouseReleased(minecraft, minecraft.screen, mouseX, mouseY, b);
return result.isPresent();
}

@Inject(method = "handleAccumulatedMovement", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screens/Screen;mouseDragged(DDIDD)Z", ordinal = 0), cancellable = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,51 @@

package dev.architectury.registry.fuel.fabric;

import net.fabricmc.fabric.api.registry.FuelRegistryEvents;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.RecipeType;
import net.minecraft.world.level.ItemLike;
import net.minecraft.world.level.block.entity.FuelValues;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.List;

public class FuelRegistryImpl {
private static final List<FuelRegistryEvents.BuildCallback> CALLBACKS = new ArrayList<>();
private static final List<FuelRegistryEvents.ExclusionsCallback> EXCLUSIONS_CALLBACKS = new ArrayList<>();

public static void register(int time, ItemLike... items) {
/*for (var item : items) {
if (time >= 0) {
FuelRegistry.INSTANCE.add(item, time);
} else {
FuelRegistry.INSTANCE.remove(item);
CALLBACKS.add((builder, context) -> {
for (var item : items) {
if (time >= 0) {
builder.add(item, time);
}
}
}*/
});
EXCLUSIONS_CALLBACKS.add((builder, context) -> {
for (var item : items) {
if (time < 0) {
builder.values.keySet().remove(item.asItem());
}
}
});
}

public static int get(ItemStack stack) {
/*var time = FuelRegistry.INSTANCE.get(stack.getItem());
return time == null ? 0 : time;*/
return 0;
public static int get(ItemStack stack, @Nullable RecipeType<?> recipeType, FuelValues fuelValues) {
return fuelValues.burnDuration(stack);
}

static {
FuelRegistryEvents.BUILD.register((builder, context) -> {
for (var callback : CALLBACKS) {
callback.build(builder, context);
}
});
FuelRegistryEvents.EXCLUSIONS.register((builder, context) -> {
for (var callback : EXCLUSIONS_CALLBACKS) {
callback.buildExclusions(builder, context);
}
});
}
}
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
org.gradle.jvmargs=-Xmx6G
org.gradle.daemon=false

platforms=fabric
platforms=fabric,neoforge

minecraft_version=1.21.2
supported_version=1.21.2
Expand All @@ -19,7 +19,7 @@ fabric_api_version=0.106.1+1.21.2
mod_menu_version=11.0.1

forge_version=51.0.0
neoforge_version=21.0.114-beta
neoforge_version=21.2.0-beta

# Set to empty if not snapshots
neoforge_pr=
Expand Down
2 changes: 1 addition & 1 deletion neoforge/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ unifiedPublishing {
displayName = "[NeoForge $rootProject.supported_version] v$project.version"
releaseType = "$rootProject.artifact_type"
changelog = releaseChangelog()
gameVersions = ["1.21"]
gameVersions = ["1.21.2"]
gameLoaders = ["neoforge"]
mainPublication renameJarForPublication

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
import dev.architectury.core.fluid.ArchitecturyFluidAttributes;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.block.Block;
Expand Down Expand Up @@ -82,7 +82,7 @@ public Fluid getSource() {
}

@Override
protected boolean canConvertToSource(Level level) {
protected boolean canConvertToSource(ServerLevel level) {
return attributes.canConvertToSource();
}

Expand Down
Loading

0 comments on commit 2a31c75

Please sign in to comment.