Skip to content

Commit 5a4a191

Browse files
committed
a bunch more 1.20.4 work
1 parent 9010b97 commit 5a4a191

30 files changed

+230
-276
lines changed

src/main/java/de/ellpeck/naturesaura/Helper.java

+10-11
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
import net.minecraft.client.gui.GuiGraphics;
1616
import net.minecraft.core.BlockPos;
1717
import net.minecraft.core.Direction;
18+
import net.minecraft.core.Registry;
19+
import net.minecraft.core.registries.BuiltInRegistries;
1820
import net.minecraft.resources.ResourceLocation;
1921
import net.minecraft.server.level.ServerChunkCache;
2022
import net.minecraft.server.level.ServerPlayer;
@@ -42,12 +44,9 @@
4244
import net.minecraft.world.phys.Vec3;
4345
import net.neoforged.api.distmarker.Dist;
4446
import net.neoforged.api.distmarker.OnlyIn;
45-
import net.neoforged.neoforge.common.capabilities.Capability;
46-
import net.neoforged.neoforge.common.util.LazyOptional;
47+
import net.neoforged.neoforge.capabilities.Capabilities;
4748
import net.neoforged.neoforge.items.IItemHandler;
48-
import net.neoforged.neoforge.registries.ForgeRegistries;
49-
import net.neoforged.neoforge.registries.IForgeRegistry;
50-
import net.neoforged.neoforge.common.capabilities.ICapabilityProvider;
49+
import net.neoforged.neoforge.items.IItemHandlerModifiable;
5150
import top.theillusivec4.curios.api.CuriosApi;
5251
import top.theillusivec4.curios.api.SlotResult;
5352

@@ -167,7 +166,7 @@ public static void renderWeirdBox(VertexConsumer buffer, double x, double y, dou
167166
public static InteractionResult putStackOnTile(Player player, InteractionHand hand, BlockPos pos, int slot, boolean sound) {
168167
var tile = player.level().getBlockEntity(pos);
169168
if (tile instanceof BlockEntityImpl) {
170-
var handler = ((BlockEntityImpl) tile).getItemHandler();
169+
var handler = (IItemHandlerModifiable) tile.getLevel().getCapability(Capabilities.ItemHandler.BLOCK, tile.getBlockPos(), tile.getBlockState(), tile, null);
171170
if (handler != null) {
172171
var handStack = player.getItemInHand(hand);
173172
if (!handStack.isEmpty()) {
@@ -230,7 +229,7 @@ public static boolean rechargeAuraItem(ItemStack stack, IAuraContainer container
230229

231230
public static BlockState getStateFromString(String raw) {
232231
var split = raw.split("\\[");
233-
var block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(split[0]));
232+
var block = BuiltInRegistries.BLOCK.get(new ResourceLocation(split[0]));
234233
if (block != null) {
235234
var state = block.defaultBlockState();
236235
if (split.length > 1) {
@@ -261,7 +260,7 @@ private static <T extends Comparable<T>> BlockState findProperty(BlockState stat
261260
public static void addAdvancement(Player player, ResourceLocation advancement, String criterion) {
262261
if (!(player instanceof ServerPlayer playerMp))
263262
return;
264-
var adv = playerMp.level().getServer().getAdvancements().getAdvancement(advancement);
263+
var adv = playerMp.level().getServer().getAdvancements().get(advancement);
265264
if (adv != null)
266265
playerMp.getAdvancements().award(adv, criterion);
267266
}
@@ -295,17 +294,17 @@ public static AABB aabb(Vec3 pos) {
295294
}
296295

297296
// This is how @ObjectHolder SHOULD work...
298-
public static <T> void populateObjectHolders(Class<?> clazz, IForgeRegistry<T> registry) {
297+
public static <T> void populateObjectHolders(Class<?> clazz, Registry<T> registry) {
299298
for (var entry : clazz.getFields()) {
300299
if (!Modifier.isStatic(entry.getModifiers()))
301300
continue;
302301
var location = new ResourceLocation(NaturesAura.MOD_ID, entry.getName().toLowerCase(Locale.ROOT));
303302
if (!registry.containsKey(location)) {
304-
NaturesAura.LOGGER.fatal("Couldn't find entry named " + location + " in registry " + registry.getRegistryName());
303+
NaturesAura.LOGGER.fatal("Couldn't find entry named " + location + " in registry");
305304
continue;
306305
}
307306
try {
308-
entry.set(null, registry.getValue(location));
307+
entry.set(null, registry.get(location));
309308
} catch (IllegalAccessException e) {
310309
NaturesAura.LOGGER.error(e);
311310
}

src/main/java/de/ellpeck/naturesaura/InternalHooks.java

+19-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import de.ellpeck.naturesaura.misc.LevelData;
99
import net.minecraft.core.BlockPos;
1010
import net.minecraft.resources.ResourceLocation;
11+
import net.minecraft.server.level.ServerLevel;
1112
import net.minecraft.util.Tuple;
1213
import net.minecraft.world.entity.player.Player;
1314
import net.minecraft.world.level.Level;
@@ -37,9 +38,9 @@ public boolean insertAuraIntoPlayer(Player player, int amount, boolean simulate)
3738
private boolean auraPlayerInteraction(Player player, int amount, boolean extract, boolean simulate) {
3839
if (extract && player.isCreative())
3940
return true;
40-
var stack = Helper.getEquippedItem(s -> s.getCapability(NaturesAuraAPI.CAP_AURA_CONTAINER).isPresent(), player, false);
41+
var stack = Helper.getEquippedItem(s -> s.getCapability(NaturesAuraAPI.AURA_CONTAINER_CAPABILITY) != null, player, false);
4142
if (!stack.isEmpty()) {
42-
var container = stack.getCapability(NaturesAuraAPI.CAP_AURA_CONTAINER).orElse(null);
43+
var container = stack.getCapability(NaturesAuraAPI.AURA_CONTAINER_CAPABILITY);
4344
if (extract) {
4445
return container.drainAura(amount, simulate) > 0;
4546
} else {
@@ -182,4 +183,20 @@ public BlockPos getHighestAuraDrainSpot(Level level, BlockPos pos, int radius, B
182183
return highest;
183184
}
184185

186+
@Override
187+
public ILevelData getLevelData(Level level) {
188+
if (level instanceof ServerLevel server) {
189+
var ret = server.getDataStorage().computeIfAbsent(LevelData.FACTORY, "level_data");
190+
if (ret.level == null)
191+
ret.level = level;
192+
return ret;
193+
} else {
194+
if (LevelData.client == null || LevelData.client.level != level) {
195+
LevelData.client = new LevelData();
196+
LevelData.client.level = level;
197+
}
198+
return LevelData.client;
199+
}
200+
}
201+
185202
}

src/main/java/de/ellpeck/naturesaura/ModConfig.java

+6-5
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
import de.ellpeck.naturesaura.api.misc.WeightedOre;
66
import de.ellpeck.naturesaura.chunk.effect.OreSpawnEffect;
77
import de.ellpeck.naturesaura.chunk.effect.PlantBoostEffect;
8+
import net.minecraft.core.registries.BuiltInRegistries;
89
import net.minecraft.resources.ResourceLocation;
910
import net.neoforged.neoforge.common.ModConfigSpec;
1011
import net.neoforged.neoforge.common.ModConfigSpec.ConfigValue;
11-
import net.neoforged.neoforge.registries.ForgeRegistries;
1212

1313
import java.util.Collections;
1414
import java.util.List;
@@ -239,23 +239,24 @@ public void apply() {
239239
}
240240

241241
try {
242-
for (String s : this.plantBoostExceptions.get())
243-
PlantBoostEffect.EXCEPTIONS.add(Objects.requireNonNull(ForgeRegistries.BLOCKS.getValue(new ResourceLocation(s))));
242+
for (var s : this.plantBoostExceptions.get())
243+
PlantBoostEffect.EXCEPTIONS.add(Objects.requireNonNull(BuiltInRegistries.BLOCK.get(new ResourceLocation(s))));
244244
} catch (Exception e) {
245245
NaturesAura.LOGGER.warn("Error parsing plantBoostExceptions", e);
246246

247247
}
248248

249249
try {
250-
for (String s : this.additionalProjectiles.get()) {
250+
for (var s : this.additionalProjectiles.get()) {
251251
var split = s.split("->");
252252
var name = new ResourceLocation(split[0]);
253-
var type = Objects.requireNonNull(ForgeRegistries.ENTITY_TYPES.getValue(name));
253+
var type = Objects.requireNonNull(BuiltInRegistries.ENTITY_TYPE.get(name));
254254
var amount = Integer.parseInt(split[1]);
255255
NaturesAuraAPI.PROJECTILE_GENERATIONS.put(type, amount);
256256
}
257257
} catch (Exception e) {
258258
NaturesAura.LOGGER.warn("Error parsing additionalProjectiles", e);
259259
}
260260
}
261+
261262
}

src/main/java/de/ellpeck/naturesaura/NaturesAura.java

+9-11
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,17 @@
66
import de.ellpeck.naturesaura.chunk.effect.DrainSpotEffects;
77
import de.ellpeck.naturesaura.compat.Compat;
88
import de.ellpeck.naturesaura.events.CommonEvents;
9-
import de.ellpeck.naturesaura.packet.PacketHandler;
109
import de.ellpeck.naturesaura.proxy.ClientProxy;
1110
import de.ellpeck.naturesaura.proxy.IProxy;
1211
import de.ellpeck.naturesaura.proxy.ServerProxy;
1312
import de.ellpeck.naturesaura.recipes.ModRecipes;
14-
import net.neoforged.neoforge.common.ModConfigSpec;
15-
import net.neoforged.neoforge.common.NeoForge;
16-
import net.neoforged.fml.DistExecutor;
13+
import net.neoforged.bus.api.IEventBus;
1714
import net.neoforged.fml.ModLoadingContext;
1815
import net.neoforged.fml.common.Mod;
1916
import net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent;
20-
import net.neoforged.fml.javafmlmod.FMLJavaModLoadingContext;
17+
import net.neoforged.fml.loading.FMLEnvironment;
18+
import net.neoforged.neoforge.common.ModConfigSpec;
19+
import net.neoforged.neoforge.common.NeoForge;
2120
import org.apache.logging.log4j.LogManager;
2221
import org.apache.logging.log4j.Logger;
2322

@@ -29,13 +28,13 @@ public final class NaturesAura {
2928

3029
public static final Logger LOGGER = LogManager.getLogger(NaturesAura.MOD_NAME);
3130
public static NaturesAura instance;
32-
// this causes a classloading issue if it's not wrapped like this
33-
@SuppressWarnings("Convert2MethodRef")
34-
public static IProxy proxy = DistExecutor.unsafeRunForDist(() -> () -> new ClientProxy(), () -> () -> new ServerProxy());
31+
public static IProxy proxy;
3532

36-
public NaturesAura() {
33+
public NaturesAura(IEventBus eventBus) {
3734
NaturesAura.instance = this;
38-
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
35+
NaturesAura.proxy = FMLEnvironment.dist.isClient() ? new ClientProxy() : new ServerProxy();
36+
37+
eventBus.addListener(this::setup);
3938

4039
var builder = new ModConfigSpec.Builder();
4140
ModConfig.instance = new ModConfig(builder);
@@ -50,7 +49,6 @@ public void setup(FMLCommonSetupEvent event) {
5049

5150
private void preInit(FMLCommonSetupEvent event) {
5251
Compat.setup(event);
53-
PacketHandler.init();
5452
new Multiblocks();
5553

5654
NeoForge.EVENT_BUS.register(new CommonEvents());

src/main/java/de/ellpeck/naturesaura/api/NaturesAuraAPI.java

+8-15
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,8 @@
2323
import net.minecraft.world.level.block.state.BlockState;
2424
import net.minecraft.world.phys.AABB;
2525
import net.minecraft.world.phys.Vec3;
26-
import net.neoforged.neoforge.common.capabilities.*;
27-
import net.neoforged.neoforge.common.capabilities.CapabilityToken;
28-
import net.neoforged.neoforge.common.capabilities.Capability;
29-
import net.neoforged.neoforge.common.capabilities.CapabilityManager;
26+
import net.neoforged.neoforge.attachment.AttachmentType;
27+
import net.neoforged.neoforge.capabilities.ItemCapability;
3028
import org.apache.commons.lang3.tuple.Pair;
3129

3230
import java.util.ArrayList;
@@ -86,23 +84,15 @@ public final class NaturesAuraAPI {
8684
/**
8785
* The capability for any item or block that stores Aura in the form of an {@link IAuraContainer}
8886
*/
89-
public static final Capability<IAuraContainer> CAP_AURA_CONTAINER = CapabilityManager.get(new CapabilityToken<>() {
90-
});
87+
public static final ItemCapability<IAuraContainer, Void> AURA_CONTAINER_CAPABILITY = ItemCapability.createVoid(new ResourceLocation(NaturesAuraAPI.MOD_ID, "aura_container"), IAuraContainer.class);
9188
/**
9289
* The capability for any item that can be recharged from an Aura storage container like the Aura Cache in the form of {@link IAuraRecharge} by a player holding it in their hand
9390
*/
94-
public static final Capability<IAuraRecharge> CAP_AURA_RECHARGE = CapabilityManager.get(new CapabilityToken<>() {
95-
});
91+
public static final ItemCapability<IAuraRecharge, Void> AURA_RECHARGE_CAPABILITY = ItemCapability.createVoid(new ResourceLocation(NaturesAuraAPI.MOD_ID, "aura_recharge"), IAuraRecharge.class);
9692
/**
9793
* The capability that any chunk in a level has to store Aura in it. As this is only applicable to chunks and all chunks in the level automatically get assigned this capability, using it directly is not necessary for addon developers. To retrieve this capability from any chunk, use the helper method {@link IAuraChunk#getAuraChunk(net.minecraft.world.level.Level, BlockPos)}.
9894
*/
99-
public static final Capability<IAuraChunk> CAP_AURA_CHUNK = CapabilityManager.get(new CapabilityToken<>() {
100-
});
101-
/**
102-
* The capability that any level has to store Nature's Aura specific data in it. To retrieve this capability from any level, use the helper methods {@link ILevelData#getLevelData(net.minecraft.world.level.Level)} or {@link ILevelData#getOverworldData(net.minecraft.world.level.Level)}.
103-
*/
104-
public static final Capability<ILevelData> CAP_LEVEL_DATA = CapabilityManager.get(new CapabilityToken<>() {
105-
});
95+
public static final AttachmentType<IAuraChunk> AURA_CHUNK_ATTACHMENT = AttachmentType.serializable(() -> (IAuraChunk) null).build();
10696
private static final IInternalHooks INSTANCE;
10797

10898
static {
@@ -260,6 +250,9 @@ public interface IInternalHooks {
260250
* @see IAuraChunk#getHighestSpot(Level, BlockPos, int, BlockPos)
261251
*/
262252
BlockPos getHighestAuraDrainSpot(Level level, BlockPos pos, int radius, BlockPos defaultSpot);
253+
254+
ILevelData getLevelData(Level level);
255+
263256
}
264257

265258
}

src/main/java/de/ellpeck/naturesaura/api/aura/chunk/IAuraChunk.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public interface IAuraChunk extends INBTSerializable<CompoundTag> {
3333
*/
3434
static IAuraChunk getAuraChunk(Level level, BlockPos pos) {
3535
var chunk = (LevelChunk) level.getChunk(pos);
36-
return chunk.getCapability(NaturesAuraAPI.CAP_AURA_CHUNK, null).orElse(null);
36+
return chunk.getData(NaturesAuraAPI.AURA_CHUNK_ATTACHMENT);
3737
}
3838

3939
/**
@@ -159,4 +159,5 @@ static BlockPos getHighestSpot(Level level, BlockPos pos, int radius, BlockPos d
159159
IAuraType getType();
160160

161161
void markDirty();
162+
162163
}
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
package de.ellpeck.naturesaura.api.misc;
22

33
import de.ellpeck.naturesaura.api.NaturesAuraAPI;
4-
import net.minecraft.nbt.CompoundTag;
54
import net.minecraft.world.level.Level;
6-
import net.neoforged.neoforge.common.util.INBTSerializable;
75
import net.neoforged.neoforge.items.IItemHandlerModifiable;
8-
import net.neoforged.neoforge.common.capabilities.ICapabilityProvider;
96

10-
public interface ILevelData extends ICapabilityProvider, INBTSerializable<CompoundTag> {
7+
public interface ILevelData {
118

129
static ILevelData getLevelData(Level level) {
13-
return level.getCapability(NaturesAuraAPI.CAP_LEVEL_DATA, null).orElse(null);
10+
return NaturesAuraAPI.instance().getLevelData(level);
1411
}
1512

1613
static ILevelData getOverworldData(Level level) {
@@ -22,4 +19,5 @@ static ILevelData getOverworldData(Level level) {
2219
IItemHandlerModifiable getEnderStorage(String name);
2320

2421
boolean isEnderStorageLocked(String name);
22+
2523
}

src/main/java/de/ellpeck/naturesaura/blocks/BlockContainerImpl.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,11 @@ public List<ItemStack> getDrops(BlockState state, LootParams.Builder builder) {
129129
}
130130

131131
@Override
132-
public void playerWillDestroy(Level level, BlockPos pos, BlockState state, Player player) {
132+
public BlockState playerWillDestroy(Level level, BlockPos pos, BlockState state, Player player) {
133133
var tile = level.getBlockEntity(pos);
134134
if (tile instanceof BlockEntityImpl impl)
135135
impl.dropInventory();
136-
super.playerWillDestroy(level, pos, state, player);
136+
return super.playerWillDestroy(level, pos, state, player);
137137
}
138138

139139
@Override
@@ -181,4 +181,5 @@ private BlockEntity createBlockEntity(BlockPos pos, BlockState state) {
181181
throw new IllegalStateException("Cannot construct block entity from class " + this.tileClass, e);
182182
}
183183
}
184+
184185
}

src/main/java/de/ellpeck/naturesaura/blocks/BlockEnderCrate.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
import net.neoforged.neoforge.common.NeoForge;
3434
import net.neoforged.neoforge.event.AnvilUpdateEvent;
3535
import net.neoforged.bus.api.SubscribeEvent;
36-
import net.neoforged.neoforge.network.NetworkHooks;
3736

3837
import javax.annotation.Nullable;
3938
import java.util.List;
@@ -92,7 +91,7 @@ public InteractionResult use(BlockState state, Level levelIn, BlockPos pos, Play
9291
var tile = levelIn.getBlockEntity(pos);
9392
if (tile instanceof BlockEntityEnderCrate crate && crate.canOpen() && crate.canUseRightNow(2500)) {
9493
crate.drainAura(2500);
95-
NetworkHooks.openScreen((ServerPlayer) player, crate, pos);
94+
player.openMenu(crate, pos);
9695
}
9796
}
9897
return InteractionResult.SUCCESS;
@@ -132,4 +131,5 @@ public void generateCustomBlockState(BlockStateGenerator generator) {
132131
public void registerTESR() {
133132
BlockEntityRenderers.register(ModBlockEntities.ENDER_CRATE, RenderEnderCrate::new);
134133
}
134+
135135
}

src/main/java/de/ellpeck/naturesaura/blocks/BlockFlowerPot.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
import de.ellpeck.naturesaura.reg.IModItem;
66
import de.ellpeck.naturesaura.reg.INoItemBlock;
77
import de.ellpeck.naturesaura.reg.ModRegistry;
8+
import net.minecraft.core.registries.BuiltInRegistries;
89
import net.minecraft.world.level.block.Block;
910
import net.minecraft.world.level.block.FlowerPotBlock;
10-
import net.neoforged.neoforge.registries.ForgeRegistries;
1111

1212
import java.util.function.Supplier;
1313

@@ -20,12 +20,12 @@ public BlockFlowerPot(Supplier<FlowerPotBlock> emptyPot, Supplier<? extends Bloc
2020

2121
@Override
2222
public void generateCustomBlockState(BlockStateGenerator generator) {
23-
generator.simpleBlock(this, generator.models().withExistingParent(this.getBaseName(), "block/flower_pot_cross").texture("plant", "block/" + ForgeRegistries.BLOCKS.getKey(this.getContent()).getPath()).renderType("cutout"));
23+
generator.simpleBlock(this, generator.models().withExistingParent(this.getBaseName(), "block/flower_pot_cross").texture("plant", "block/" + BuiltInRegistries.BLOCK.getKey(this.getPotted()).getPath()).renderType("cutout"));
2424
}
2525

2626
@Override
2727
public String getBaseName() {
28-
return "potted_" + ForgeRegistries.BLOCKS.getKey(this.getContent()).getPath();
28+
return "potted_" + BuiltInRegistries.BLOCK.getKey(this.getPotted()).getPath();
2929
}
3030

3131
}

src/main/java/de/ellpeck/naturesaura/blocks/multi/Multiblocks.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public final class Multiblocks {
4242
// try-catch to prevent blocks that need to have been placed crashing here
4343
try {
4444
var stack = new ItemStack(state.getBlock());
45-
return !stack.isEmpty() && level.getRecipeManager().getRecipesFor(ModRecipes.TREE_RITUAL_TYPE, null, level).stream().anyMatch(r -> r.saplingType.test(stack));
45+
return !stack.isEmpty() && level.getRecipeManager().getRecipesFor(ModRecipes.TREE_RITUAL_TYPE, null, level).stream().anyMatch(r -> r.value().saplingType.test(stack));
4646
} catch (Exception e) {
4747
return false;
4848
}
@@ -99,4 +99,5 @@ public final class Multiblocks {
9999
'R', Blocks.REDSTONE_BLOCK,
100100
'0', ModBlocks.RF_CONVERTER,
101101
' ', Matcher.any());
102+
102103
}

0 commit comments

Comments
 (0)