Skip to content

Commit 6525ff5

Browse files
committed
some work on the port
1 parent 0d638e9 commit 6525ff5

19 files changed

+553
-629
lines changed

Diff for: src/main/java/de/ellpeck/naturesaura/Helper.java

+39-40
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import net.minecraft.sounds.SoundEvents;
2222
import net.minecraft.sounds.SoundSource;
2323
import net.minecraft.world.InteractionHand;
24-
import net.minecraft.world.InteractionResult;
24+
import net.minecraft.world.ItemInteractionResult;
2525
import net.minecraft.world.entity.decoration.ItemFrame;
2626
import net.minecraft.world.entity.item.ItemEntity;
2727
import net.minecraft.world.entity.player.Player;
@@ -37,7 +37,7 @@
3737
import net.minecraft.world.level.block.state.BlockState;
3838
import net.minecraft.world.level.block.state.properties.Property;
3939
import net.minecraft.world.level.chunk.ChunkAccess;
40-
import net.minecraft.world.level.chunk.ChunkStatus;
40+
import net.minecraft.world.level.chunk.status.ChunkStatus;
4141
import net.minecraft.world.phys.AABB;
4242
import net.minecraft.world.phys.Vec3;
4343
import net.neoforged.api.distmarker.Dist;
@@ -46,8 +46,6 @@
4646
import net.neoforged.neoforge.capabilities.ICapabilityProvider;
4747
import net.neoforged.neoforge.items.IItemHandler;
4848
import net.neoforged.neoforge.items.IItemHandlerModifiable;
49-
import top.theillusivec4.curios.api.CuriosApi;
50-
import top.theillusivec4.curios.api.SlotResult;
5149

5250
import java.lang.reflect.Modifier;
5351
import java.util.List;
@@ -116,7 +114,7 @@ public static int blendColors(int c1, int c2, float ratio) {
116114
}
117115

118116
public static boolean areItemsEqual(ItemStack first, ItemStack second, boolean nbt) {
119-
return nbt ? ItemStack.isSameItemSameTags(first, second) : ItemStack.isSameItem(first, second);
117+
return nbt ? ItemStack.isSameItemSameComponents(first, second) : ItemStack.isSameItem(first, second);
120118
}
121119

122120
@OnlyIn(Dist.CLIENT)
@@ -132,34 +130,34 @@ public static void renderItemInGui(GuiGraphics graphics, ItemStack stack, int x,
132130
}
133131

134132
@OnlyIn(Dist.CLIENT)
135-
public static void renderWeirdBox(VertexConsumer buffer, double x, double y, double z, double width, double height, double depth, float r, float g, float b, float a) {
136-
buffer.vertex(x, y + height, z).color(r, g, b, a).endVertex();
137-
buffer.vertex(x + width, y + height, z).color(r, g, b, a).endVertex();
138-
buffer.vertex(x + width, y, z).color(r, g, b, a).endVertex();
139-
buffer.vertex(x, y, z).color(r, g, b, a).endVertex();
140-
buffer.vertex(x + width, y, z + depth).color(r, g, b, a).endVertex();
141-
buffer.vertex(x + width, y, z).color(r, g, b, a).endVertex();
142-
buffer.vertex(x + width, y + height, z).color(r, g, b, a).endVertex();
143-
buffer.vertex(x + width, y + height, z + depth).color(r, g, b, a).endVertex();
144-
buffer.vertex(x + width, y + height, z + depth).color(r, g, b, a).endVertex();
145-
buffer.vertex(x, y + height, z + depth).color(r, g, b, a).endVertex();
146-
buffer.vertex(x, y, z + depth).color(r, g, b, a).endVertex();
147-
buffer.vertex(x + width, y, z + depth).color(r, g, b, a).endVertex();
148-
buffer.vertex(x, y + height, z + depth).color(r, g, b, a).endVertex();
149-
buffer.vertex(x, y + height, z).color(r, g, b, a).endVertex();
150-
buffer.vertex(x, y, z).color(r, g, b, a).endVertex();
151-
buffer.vertex(x, y, z + depth).color(r, g, b, a).endVertex();
152-
buffer.vertex(x, y + height, z).color(r, g, b, a).endVertex();
153-
buffer.vertex(x, y + height, z + depth).color(r, g, b, a).endVertex();
154-
buffer.vertex(x + width, y + height, z + depth).color(r, g, b, a).endVertex();
155-
buffer.vertex(x + width, y + height, z).color(r, g, b, a).endVertex();
156-
buffer.vertex(x + width, y, z).color(r, g, b, a).endVertex();
157-
buffer.vertex(x + width, y, z + depth).color(r, g, b, a).endVertex();
158-
buffer.vertex(x, y, z + depth).color(r, g, b, a).endVertex();
159-
buffer.vertex(x, y, z).color(r, g, b, a).endVertex();
133+
public static void renderWeirdBox(VertexConsumer buffer, float x, float y, float z, float width, float height, float depth, float r, float g, float b, float a) {
134+
buffer.addVertex(x, y + height, z).setColor(r, g, b, a);
135+
buffer.addVertex(x + width, y + height, z).setColor(r, g, b, a);
136+
buffer.addVertex(x + width, y, z).setColor(r, g, b, a);
137+
buffer.addVertex(x, y, z).setColor(r, g, b, a);
138+
buffer.addVertex(x + width, y, z + depth).setColor(r, g, b, a);
139+
buffer.addVertex(x + width, y, z).setColor(r, g, b, a);
140+
buffer.addVertex(x + width, y + height, z).setColor(r, g, b, a);
141+
buffer.addVertex(x + width, y + height, z + depth).setColor(r, g, b, a);
142+
buffer.addVertex(x + width, y + height, z + depth).setColor(r, g, b, a);
143+
buffer.addVertex(x, y + height, z + depth).setColor(r, g, b, a);
144+
buffer.addVertex(x, y, z + depth).setColor(r, g, b, a);
145+
buffer.addVertex(x + width, y, z + depth).setColor(r, g, b, a);
146+
buffer.addVertex(x, y + height, z + depth).setColor(r, g, b, a);
147+
buffer.addVertex(x, y + height, z).setColor(r, g, b, a);
148+
buffer.addVertex(x, y, z).setColor(r, g, b, a);
149+
buffer.addVertex(x, y, z + depth).setColor(r, g, b, a);
150+
buffer.addVertex(x, y + height, z).setColor(r, g, b, a);
151+
buffer.addVertex(x, y + height, z + depth).setColor(r, g, b, a);
152+
buffer.addVertex(x + width, y + height, z + depth).setColor(r, g, b, a);
153+
buffer.addVertex(x + width, y + height, z).setColor(r, g, b, a);
154+
buffer.addVertex(x + width, y, z).setColor(r, g, b, a);
155+
buffer.addVertex(x + width, y, z + depth).setColor(r, g, b, a);
156+
buffer.addVertex(x, y, z + depth).setColor(r, g, b, a);
157+
buffer.addVertex(x, y, z).setColor(r, g, b, a);
160158
}
161159

162-
public static InteractionResult putStackOnTile(Player player, InteractionHand hand, BlockPos pos, int slot, boolean sound) {
160+
public static ItemInteractionResult putStackOnTile(Player player, InteractionHand hand, BlockPos pos, int slot, boolean sound) {
163161
var tile = player.level().getBlockEntity(pos);
164162
if (tile instanceof BlockEntityImpl) {
165163
var handler = (IItemHandlerModifiable) tile.getLevel().getCapability(Capabilities.ItemHandler.BLOCK, tile.getBlockPos(), tile.getBlockState(), tile, null);
@@ -170,17 +168,17 @@ public static InteractionResult putStackOnTile(Player player, InteractionHand ha
170168
if (!ItemStack.matches(remain, handStack)) {
171169
if (sound)
172170
player.level().playSound(player, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5,
173-
SoundEvents.ITEM_FRAME_ADD_ITEM, SoundSource.PLAYERS, 0.75F, 1F);
171+
SoundEvents.ITEM_FRAME_ADD_ITEM, SoundSource.PLAYERS, 0.75F, 1F);
174172
if (!player.level().isClientSide)
175173
player.setItemInHand(hand, remain);
176-
return InteractionResult.SUCCESS;
174+
return ItemInteractionResult.SUCCESS;
177175
}
178176
}
179177

180178
if (!handler.getStackInSlot(slot).isEmpty()) {
181179
if (sound)
182180
player.level().playSound(player, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5,
183-
SoundEvents.ITEM_FRAME_REMOVE_ITEM, SoundSource.PLAYERS, 0.75F, 1F);
181+
SoundEvents.ITEM_FRAME_REMOVE_ITEM, SoundSource.PLAYERS, 0.75F, 1F);
184182
if (!player.level().isClientSide) {
185183
var stack = handler.getStackInSlot(slot);
186184
if (!player.addItem(stack)) {
@@ -189,11 +187,11 @@ public static InteractionResult putStackOnTile(Player player, InteractionHand ha
189187
}
190188
handler.setStackInSlot(slot, ItemStack.EMPTY);
191189
}
192-
return InteractionResult.SUCCESS;
190+
return ItemInteractionResult.SUCCESS;
193191
}
194192
}
195193
}
196-
return InteractionResult.CONSUME;
194+
return ItemInteractionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION;
197195
}
198196

199197
public static ICapabilityProvider<ItemStack, Void, IAuraRecharge> makeRechargeProvider(boolean needsSelected) {
@@ -215,7 +213,7 @@ public static boolean rechargeAuraItem(ItemStack stack, IAuraContainer container
215213

216214
public static BlockState getStateFromString(String raw) {
217215
var split = raw.split("\\[");
218-
var block = BuiltInRegistries.BLOCK.get(new ResourceLocation(split[0]));
216+
var block = BuiltInRegistries.BLOCK.get(ResourceLocation.parse(split[0]));
219217
if (block != null) {
220218
var state = block.defaultBlockState();
221219
if (split.length > 1) {
@@ -284,7 +282,7 @@ public static <T> void populateObjectHolders(Class<?> clazz, Registry<T> registr
284282
for (var entry : clazz.getFields()) {
285283
if (!Modifier.isStatic(entry.getModifiers()))
286284
continue;
287-
var location = new ResourceLocation(NaturesAura.MOD_ID, entry.getName().toLowerCase(Locale.ROOT));
285+
var location = ResourceLocation.fromNamespaceAndPath(NaturesAura.MOD_ID, entry.getName().toLowerCase(Locale.ROOT));
288286
if (!registry.containsKey(location)) {
289287
NaturesAura.LOGGER.fatal("Couldn't find entry named " + location + " in registry");
290288
continue;
@@ -298,14 +296,15 @@ public static <T> void populateObjectHolders(Class<?> clazz, Registry<T> registr
298296
}
299297

300298
public static ItemStack getEquippedItem(Predicate<ItemStack> predicate, Player player, boolean hotbarOnly) {
301-
if (Compat.hasCompat("curios")) {
299+
// TODO curios?
300+
/* if (Compat.hasCompat("curios")) {
302301
var inventory = CuriosApi.getCuriosInventory(player);
303302
if (inventory.isPresent()) {
304303
var stack = inventory.get().findFirstCurio(predicate).map(SlotResult::stack);
305304
if (stack.isPresent())
306305
return stack.get();
307306
}
308-
}
307+
}*/
309308
var invSize = hotbarOnly ? 9 : player.getInventory().getContainerSize();
310309
for (var i = 0; i < invSize; i++) {
311310
var slot = player.getInventory().getItem(i);

Diff for: src/main/java/de/ellpeck/naturesaura/api/NaturesAuraAPI.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ public final class NaturesAuraAPI {
5252
* A map of all {@link IAuraType} instances which are types of Aura present in different types of levels. {@link BasicAuraType} instances can be easily registered using {@link BasicAuraType#register()}.
5353
*/
5454
public static final Map<ResourceLocation, IAuraType> AURA_TYPES = new HashMap<>();
55-
public static final BasicAuraType TYPE_OVERWORLD = new BasicAuraType(new ResourceLocation(NaturesAuraAPI.MOD_ID, "overworld"), Level.OVERWORLD, 0x89cc37, 0).register();
56-
public static final BasicAuraType TYPE_NETHER = new BasicAuraType(new ResourceLocation(NaturesAuraAPI.MOD_ID, "nether"), Level.NETHER, 0x871c0c, 0).register();
57-
public static final BasicAuraType TYPE_END = new BasicAuraType(new ResourceLocation(NaturesAuraAPI.MOD_ID, "end"), Level.END, 0x302624, 0).register();
58-
public static final BasicAuraType TYPE_OTHER = new BasicAuraType(new ResourceLocation(NaturesAuraAPI.MOD_ID, "other"), null, 0x2fa8a0, Integer.MIN_VALUE).register();
55+
public static final BasicAuraType TYPE_OVERWORLD = new BasicAuraType(ResourceLocation.fromNamespaceAndPath(NaturesAuraAPI.MOD_ID, "overworld"), Level.OVERWORLD, 0x89cc37, 0).register();
56+
public static final BasicAuraType TYPE_NETHER = new BasicAuraType(ResourceLocation.fromNamespaceAndPath(NaturesAuraAPI.MOD_ID, "nether"), Level.NETHER, 0x871c0c, 0).register();
57+
public static final BasicAuraType TYPE_END = new BasicAuraType(ResourceLocation.fromNamespaceAndPath(NaturesAuraAPI.MOD_ID, "end"), Level.END, 0x302624, 0).register();
58+
public static final BasicAuraType TYPE_OTHER = new BasicAuraType(ResourceLocation.fromNamespaceAndPath(NaturesAuraAPI.MOD_ID, "other"), null, 0x2fa8a0, Integer.MIN_VALUE).register();
5959
/**
6060
* A map of all {@link IDrainSpotEffect} suppliers which are effects that happen passively at every spot that Aura has been drained from in the level. These effects include things like vegetational increase and natural decay. To register your own drain spot effects, just add a supplier for them to this map, and they will automatically be executed once a second for every drain spot currently loaded.
6161
*/
@@ -87,15 +87,15 @@ public final class NaturesAuraAPI {
8787
/**
8888
* The capability for any item that stores Aura in the form of an {@link IAuraContainer}
8989
*/
90-
public static final ItemCapability<IAuraContainer, Void> AURA_CONTAINER_ITEM_CAPABILITY = ItemCapability.createVoid(new ResourceLocation(NaturesAuraAPI.MOD_ID, "aura_container_item"), IAuraContainer.class);
90+
public static final ItemCapability<IAuraContainer, Void> AURA_CONTAINER_ITEM_CAPABILITY = ItemCapability.createVoid(ResourceLocation.fromNamespaceAndPath(NaturesAuraAPI.MOD_ID, "aura_container_item"), IAuraContainer.class);
9191
/**
9292
* The capability for any block that stores Aura in the form of an {@link IAuraContainer}
9393
*/
94-
public static final BlockCapability<IAuraContainer, Direction> AURA_CONTAINER_BLOCK_CAPABILITY = BlockCapability.create(new ResourceLocation(NaturesAuraAPI.MOD_ID, "aura_container_block"), IAuraContainer.class, Direction.class);
94+
public static final BlockCapability<IAuraContainer, Direction> AURA_CONTAINER_BLOCK_CAPABILITY = BlockCapability.create(ResourceLocation.fromNamespaceAndPath(NaturesAuraAPI.MOD_ID, "aura_container_block"), IAuraContainer.class, Direction.class);
9595
/**
9696
* 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
9797
*/
98-
public static final ItemCapability<IAuraRecharge, Void> AURA_RECHARGE_CAPABILITY = ItemCapability.createVoid(new ResourceLocation(NaturesAuraAPI.MOD_ID, "aura_recharge"), IAuraRecharge.class);
98+
public static final ItemCapability<IAuraRecharge, Void> AURA_RECHARGE_CAPABILITY = ItemCapability.createVoid(ResourceLocation.fromNamespaceAndPath(NaturesAuraAPI.MOD_ID, "aura_recharge"), IAuraRecharge.class);
9999
/**
100100
* 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)}.
101101
*/

Diff for: src/main/java/de/ellpeck/naturesaura/blocks/BlockDimensionRail.java

+12-25
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@
2020
import net.minecraft.sounds.SoundSource;
2121
import net.minecraft.world.InteractionHand;
2222
import net.minecraft.world.InteractionResult;
23+
import net.minecraft.world.ItemInteractionResult;
2324
import net.minecraft.world.entity.Entity;
2425
import net.minecraft.world.entity.player.Player;
2526
import net.minecraft.world.entity.vehicle.AbstractMinecart;
27+
import net.minecraft.world.item.ItemStack;
2628
import net.minecraft.world.level.BlockGetter;
2729
import net.minecraft.world.level.Level;
2830
import net.minecraft.world.level.block.BaseRailBlock;
@@ -35,10 +37,8 @@
3537
import net.minecraft.world.level.block.state.properties.Property;
3638
import net.minecraft.world.level.block.state.properties.RailShape;
3739
import net.minecraft.world.level.levelgen.Heightmap;
40+
import net.minecraft.world.level.portal.DimensionTransition;
3841
import net.minecraft.world.phys.BlockHitResult;
39-
import net.neoforged.neoforge.common.util.ITeleporter;
40-
41-
import java.util.function.Function;
4242

4343
public class BlockDimensionRail extends BaseRailBlock implements IModItem, ICustomBlockState, ICustomItemModel {
4444

@@ -66,20 +66,18 @@ private boolean canUseHere(ResourceKey<Level> dimension) {
6666
}
6767

6868
@Override
69-
@SuppressWarnings("deprecation")
70-
public InteractionResult use(BlockState state, Level levelIn, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) {
71-
var stack = player.getItemInHand(hand);
69+
protected ItemInteractionResult useItemOn(ItemStack stack, BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hitResult) {
7270
if (stack.getItem() == ModItems.RANGE_VISUALIZER) {
73-
if (!levelIn.isClientSide) {
74-
var goalPos = this.getGoalCoords(levelIn, pos);
71+
if (!level.isClientSide) {
72+
var goalPos = this.getGoalCoords(level, pos);
7573
var data = new CompoundTag();
7674
data.putString("dim", this.goalDim.location().toString());
7775
data.putLong("pos", goalPos.asLong());
7876
PacketHandler.sendTo(player, new PacketClient(0, data));
7977
}
80-
return InteractionResult.SUCCESS;
78+
return ItemInteractionResult.SUCCESS;
8179
}
82-
return InteractionResult.FAIL;
80+
return ItemInteractionResult.FAIL;
8381
}
8482

8583
@Override
@@ -95,21 +93,9 @@ public void onMinecartPass(BlockState state, Level level, BlockPos pos, Abstract
9593
PacketHandler.sendToAllAround(level, pos, 32, new PacketParticles((float) box.minX, (float) box.minY, (float) box.minZ, PacketParticles.Type.DIMENSION_RAIL, (int) ((box.maxX - box.minX) * 100F), (int) ((box.maxY - box.minY) * 100F), (int) ((box.maxZ - box.minZ) * 100F)));
9694
level.playSound(null, pos, SoundEvents.ENDERMAN_TELEPORT, SoundSource.BLOCKS, 1F, 1F);
9795

98-
var goalCoords = this.getGoalCoords(level, pos);
99-
cart.changeDimension(level.getServer().getLevel(this.goalDim), new ITeleporter() {
100-
@Override
101-
public Entity placeEntity(Entity entity, ServerLevel currentLevel, ServerLevel destLevel, float yaw, Function<Boolean, Entity> repositionEntity) {
102-
// repositionEntity always causes a NPE because why wouldn't it, so this is a fixed copy
103-
entity.level().getProfiler().popPush("reloading");
104-
var result = entity.getType().create(destLevel);
105-
if (result != null) {
106-
result.restoreFrom(entity);
107-
destLevel.addDuringTeleport(result);
108-
result.moveTo(goalCoords, yaw, result.getXRot());
109-
}
110-
return result;
111-
}
112-
});
96+
// TODO test if this new dimension change works!
97+
var goalCoords = this.getGoalCoords(level, pos).getCenter();
98+
cart.changeDimension(new DimensionTransition(level.getServer().getLevel(this.goalDim), goalCoords, cart.getDeltaMovement(), cart.getYRot(), cart.getXRot(), DimensionTransition.PLAY_PORTAL_SOUND));
11399

114100
var spot = IAuraChunk.getHighestSpot(level, pos, 35, pos);
115101
IAuraChunk.getAuraChunk(level, spot).drainAura(spot, 50000);
@@ -177,4 +163,5 @@ public void generateCustomBlockState(BlockStateGenerator generator) {
177163
public void generateCustomItemModel(ItemModelGenerator generator) {
178164
generator.withExistingParent(this.getBaseName(), "item/generated").texture("layer0", "block/" + this.getBaseName());
179165
}
166+
180167
}

Diff for: src/main/java/de/ellpeck/naturesaura/blocks/BlockEndFlower.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import net.neoforged.neoforge.common.NeoForge;
3030
import net.neoforged.neoforge.event.entity.living.LivingEvent;
3131
import net.neoforged.bus.api.SubscribeEvent;
32+
import net.neoforged.neoforge.event.tick.EntityTickEvent;
3233

3334
import javax.annotation.Nullable;
3435
import java.util.List;
@@ -52,7 +53,7 @@ public VoxelShape getShape(BlockState state, BlockGetter levelIn, BlockPos pos,
5253
}
5354

5455
@SubscribeEvent
55-
public void onDragonTick(LivingEvent.LivingTickEvent event) {
56+
public void onDragonTick(EntityTickEvent.Pre event) {
5657
var living = event.getEntity();
5758
if (living.level().isClientSide || !(living instanceof EnderDragon dragon))
5859
return;

0 commit comments

Comments
 (0)