Skip to content

Commit

Permalink
Port to 1.20.6 (#7846)
Browse files Browse the repository at this point in the history
Most of the changes come from the breaking changes in some of the 20.5
releases. Also addressed a few terminal deprecations.
  • Loading branch information
Technici4n authored Apr 29, 2024
1 parent 710109d commit 69c8d37
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 95 deletions.
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ artifact_basename=appliedenergistics2-neoforge
# Minecraft Versions #
#########################################################
minecraft_release=1.20
minecraft_version=1.20.5
minecraft_version_range=1.20.5
neoforge_version=20.5.0-beta
neoforge_version_range=[20.5.0-beta,)
minecraft_version=1.20.6
minecraft_version_range=1.20.6
neoforge_version=20.6.1-beta
neoforge_version_range=[20.6.1-beta,)

#########################################################
# Parchment #
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.item.ItemStack;
import net.neoforged.neoforge.capabilities.Capabilities;
import net.neoforged.neoforge.items.ItemHandlerHelper;

import appeng.api.config.Actionable;
import appeng.api.stacks.AEFluidKey;
Expand Down Expand Up @@ -43,7 +42,7 @@ class FluidContainerItemStrategy
@Override
public long extract(Context context, AEFluidKey what, long amount, Actionable mode) {
var stack = context.getStack();
var copy = ItemHandlerHelper.copyStackWithSize(stack, 1);
var copy = stack.copyWithCount(1);
var fluidHandler = copy.getCapability(Capabilities.FluidHandler.ITEM);
if (fluidHandler == null) {
return 0;
Expand All @@ -60,7 +59,7 @@ public long extract(Context context, AEFluidKey what, long amount, Actionable mo
@Override
public long insert(Context context, AEFluidKey what, long amount, Actionable mode) {
var stack = context.getStack();
var copy = ItemHandlerHelper.copyStackWithSize(stack, 1);
var copy = stack.copyWithCount(1);
var fluidHandler = copy.getCapability(Capabilities.FluidHandler.ITEM);
if (fluidHandler == null) {
return 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
import net.neoforged.neoforge.common.CommonHooks;

import appeng.api.config.Actionable;
import appeng.api.inventories.ISegmentedInventory;
Expand Down Expand Up @@ -309,7 +308,7 @@ private void eatFuel() {
}

public static int getBurnTime(ItemStack is) {
return CommonHooks.getBurnTime(is, null);
return is.getBurnTime(null);
}

public static boolean hasBurnTime(ItemStack is) {
Expand Down
12 changes: 5 additions & 7 deletions src/main/java/appeng/client/guidebook/Guide.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@
import net.minecraft.world.level.validation.DirectoryValidator;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.fml.event.lifecycle.FMLClientSetupEvent;
import net.neoforged.neoforge.client.event.ClientTickEvent;
import net.neoforged.neoforge.client.event.RegisterClientReloadListenersEvent;
import net.neoforged.neoforge.client.event.ScreenEvent;
import net.neoforged.neoforge.common.NeoForge;
import net.neoforged.neoforge.event.TickEvent;

import appeng.client.guidebook.compiler.PageCompiler;
import appeng.client.guidebook.compiler.ParsedGuidePage;
Expand Down Expand Up @@ -345,12 +345,10 @@ public String getName() {
private void watchDevelopmentSources() {
var watcher = new GuideSourceWatcher(developmentSourceNamespace, developmentSourceFolder);

NeoForge.EVENT_BUS.addListener((TickEvent.ClientTickEvent evt) -> {
if (evt.phase == TickEvent.Phase.START) {
var changes = watcher.takeChanges();
if (!changes.isEmpty()) {
applyChanges(changes);
}
NeoForge.EVENT_BUS.addListener((ClientTickEvent.Pre evt) -> {
var changes = watcher.takeChanges();
if (!changes.isEmpty()) {
applyChanges(changes);
}
});
Runtime.getRuntime().addShutdownHook(new Thread(watcher::close));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
import net.minecraft.util.Mth;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TooltipFlag;
import net.neoforged.neoforge.client.event.ClientTickEvent;
import net.neoforged.neoforge.client.settings.KeyConflictContext;
import net.neoforged.neoforge.common.NeoForge;
import net.neoforged.neoforge.event.TickEvent;
import net.neoforged.neoforge.event.entity.player.ItemTooltipEvent;

import appeng.client.guidebook.GuidebookText;
Expand Down Expand Up @@ -59,7 +59,7 @@ public static void init() {
if (AEConfig.instance().isGuideHotkeyEnabled()) {
NeoForge.EVENT_BUS.addListener(
(ItemTooltipEvent evt) -> handleTooltip(evt.getItemStack(), evt.getFlags(), evt.getToolTip()));
NeoForge.EVENT_BUS.addListener((TickEvent.ClientTickEvent evt) -> newTick = true);
NeoForge.EVENT_BUS.addListener((ClientTickEvent.Post evt) -> newTick = true);
} else {
LOG.info("AE2 guide hotkey is disabled via config.");
}
Expand Down
16 changes: 6 additions & 10 deletions src/main/java/appeng/core/AppEngClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import net.neoforged.fml.event.lifecycle.FMLClientSetupEvent;
import net.neoforged.fml.loading.FMLLoader;
import net.neoforged.neoforge.client.event.ClientPlayerNetworkEvent;
import net.neoforged.neoforge.client.event.ClientTickEvent;
import net.neoforged.neoforge.client.event.EntityRenderersEvent;
import net.neoforged.neoforge.client.event.InputEvent;
import net.neoforged.neoforge.client.event.ModelEvent;
Expand All @@ -56,7 +57,6 @@
import net.neoforged.neoforge.client.event.RegisterParticleProvidersEvent;
import net.neoforged.neoforge.client.settings.KeyConflictContext;
import net.neoforged.neoforge.common.NeoForge;
import net.neoforged.neoforge.event.TickEvent;
import net.neoforged.neoforge.event.server.ServerStartingEvent;
import net.neoforged.neoforge.network.PacketDistributor;

Expand Down Expand Up @@ -156,10 +156,8 @@ public AppEngClient(IEventBus modEventBus) {
guide = createGuide(modEventBus);
OpenGuideHotkey.init();

NeoForge.EVENT_BUS.addListener(EventPriority.LOWEST, (TickEvent.ClientTickEvent e) -> {
if (e.phase == TickEvent.Phase.START) {
updateCableRenderMode();
}
NeoForge.EVENT_BUS.addListener(EventPriority.LOWEST, (ClientTickEvent.Pre e) -> {
updateCableRenderMode();
});

modEventBus.addListener(this::clientSetup);
Expand All @@ -171,11 +169,9 @@ public AppEngClient(IEventBus modEventBus) {
PinnedKeys.clearPinnedKeys();
});

NeoForge.EVENT_BUS.addListener((TickEvent.ClientTickEvent e) -> {
if (e.phase == TickEvent.Phase.END) {
tickPinnedKeys(Minecraft.getInstance());
Hotkeys.checkHotkeys();
}
NeoForge.EVENT_BUS.addListener((ClientTickEvent.Post e) -> {
tickPinnedKeys(Minecraft.getInstance());
Hotkeys.checkHotkeys();
});
}

Expand Down
16 changes: 8 additions & 8 deletions src/main/java/appeng/core/definitions/AEBlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -202,17 +202,17 @@ private static <T extends Block> BlockDefinition<T> craftingBlock(String english
public static final BlockDefinition<LightDetectorBlock> LIGHT_DETECTOR = block("Light Detecting Fixture", AEBlockIds.LIGHT_DETECTOR, LightDetectorBlock::new);
public static final BlockDefinition<PaintSplotchesBlock> PAINT = block("Paint", AEBlockIds.PAINT, PaintSplotchesBlock::new);

public static final BlockDefinition<StairBlock> SKY_STONE_STAIRS = block("Sky Stone Stairs", AEBlockIds.SKY_STONE_STAIRS, () -> new StairBlock(SKY_STONE_BLOCK.block()::defaultBlockState, SKYSTONE_PROPERTIES));
public static final BlockDefinition<StairBlock> SMOOTH_SKY_STONE_STAIRS = block("Sky Stone Block Stairs", AEBlockIds.SMOOTH_SKY_STONE_STAIRS, () -> new StairBlock(SMOOTH_SKY_STONE_BLOCK.block()::defaultBlockState, SKYSTONE_PROPERTIES));
public static final BlockDefinition<StairBlock> SKY_STONE_BRICK_STAIRS = block("Sky Stone Brick Stairs", AEBlockIds.SKY_STONE_BRICK_STAIRS, () -> new StairBlock(SKY_STONE_BRICK.block()::defaultBlockState, SKYSTONE_PROPERTIES));
public static final BlockDefinition<StairBlock> SKY_STONE_SMALL_BRICK_STAIRS = block("Sky Stone Small Brick Stairs", AEBlockIds.SKY_STONE_SMALL_BRICK_STAIRS, () -> new StairBlock(SKY_STONE_SMALL_BRICK.block()::defaultBlockState, SKYSTONE_PROPERTIES));
public static final BlockDefinition<StairBlock> FLUIX_STAIRS = block("Fluix Stairs", AEBlockIds.FLUIX_STAIRS, () -> new StairBlock(FLUIX_BLOCK.block()::defaultBlockState, QUARTZ_PROPERTIES));
public static final BlockDefinition<StairBlock> QUARTZ_STAIRS = block("Certus Quartz Stairs", AEBlockIds.QUARTZ_STAIRS, () -> new StairBlock(QUARTZ_BLOCK.block()::defaultBlockState, QUARTZ_PROPERTIES));
public static final BlockDefinition<StairBlock> SKY_STONE_STAIRS = block("Sky Stone Stairs", AEBlockIds.SKY_STONE_STAIRS, () -> new StairBlock(SKY_STONE_BLOCK.block().defaultBlockState(), SKYSTONE_PROPERTIES));
public static final BlockDefinition<StairBlock> SMOOTH_SKY_STONE_STAIRS = block("Sky Stone Block Stairs", AEBlockIds.SMOOTH_SKY_STONE_STAIRS, () -> new StairBlock(SMOOTH_SKY_STONE_BLOCK.block().defaultBlockState(), SKYSTONE_PROPERTIES));
public static final BlockDefinition<StairBlock> SKY_STONE_BRICK_STAIRS = block("Sky Stone Brick Stairs", AEBlockIds.SKY_STONE_BRICK_STAIRS, () -> new StairBlock(SKY_STONE_BRICK.block().defaultBlockState(), SKYSTONE_PROPERTIES));
public static final BlockDefinition<StairBlock> SKY_STONE_SMALL_BRICK_STAIRS = block("Sky Stone Small Brick Stairs", AEBlockIds.SKY_STONE_SMALL_BRICK_STAIRS, () -> new StairBlock(SKY_STONE_SMALL_BRICK.block().defaultBlockState(), SKYSTONE_PROPERTIES));
public static final BlockDefinition<StairBlock> FLUIX_STAIRS = block("Fluix Stairs", AEBlockIds.FLUIX_STAIRS, () -> new StairBlock(FLUIX_BLOCK.block().defaultBlockState(), QUARTZ_PROPERTIES));
public static final BlockDefinition<StairBlock> QUARTZ_STAIRS = block("Certus Quartz Stairs", AEBlockIds.QUARTZ_STAIRS, () -> new StairBlock(QUARTZ_BLOCK.block().defaultBlockState(), QUARTZ_PROPERTIES));
public static final BlockDefinition<StairBlock> CUT_QUARTZ_STAIRS = block("Cut Certus Quartz Stairs", AEBlockIds.CUT_QUARTZ_STAIRS, () -> new StairBlock(CUT_QUARTZ_BLOCK.block().defaultBlockState(), QUARTZ_PROPERTIES));
public static final BlockDefinition<StairBlock> SMOOTH_QUARTZ_STAIRS = block("Smooth Certus Quartz Stairs", AEBlockIds.SMOOTH_QUARTZ_STAIRS, () -> new StairBlock(SMOOTH_QUARTZ_BLOCK.block().defaultBlockState(), QUARTZ_PROPERTIES));
public static final BlockDefinition<StairBlock> QUARTZ_BRICK_STAIRS = block("Certus Quartz Brick Stairs", AEBlockIds.QUARTZ_BRICK_STAIRS, () -> new StairBlock(QUARTZ_BRICKS.block().defaultBlockState(), QUARTZ_PROPERTIES));
public static final BlockDefinition<StairBlock> CHISELED_QUARTZ_STAIRS = block("Chiseled Certus Quartz Stairs", AEBlockIds.CHISELED_QUARTZ_STAIRS, () -> new StairBlock(CHISELED_QUARTZ_BLOCK.block()::defaultBlockState, QUARTZ_PROPERTIES));
public static final BlockDefinition<StairBlock> QUARTZ_PILLAR_STAIRS = block("Certus Quartz Pillar Stairs", AEBlockIds.QUARTZ_PILLAR_STAIRS, () -> new StairBlock(QUARTZ_PILLAR.block()::defaultBlockState, QUARTZ_PROPERTIES));
public static final BlockDefinition<StairBlock> CHISELED_QUARTZ_STAIRS = block("Chiseled Certus Quartz Stairs", AEBlockIds.CHISELED_QUARTZ_STAIRS, () -> new StairBlock(CHISELED_QUARTZ_BLOCK.block().defaultBlockState(), QUARTZ_PROPERTIES));
public static final BlockDefinition<StairBlock> QUARTZ_PILLAR_STAIRS = block("Certus Quartz Pillar Stairs", AEBlockIds.QUARTZ_PILLAR_STAIRS, () -> new StairBlock(QUARTZ_PILLAR.block().defaultBlockState(), QUARTZ_PROPERTIES));

public static final BlockDefinition<WallBlock> SKY_STONE_WALL = block("Sky Stone Wall", AEBlockIds.SKY_STONE_WALL, () -> new WallBlock(SKYSTONE_PROPERTIES));
public static final BlockDefinition<WallBlock> SMOOTH_SKY_STONE_WALL = block("Sky Stone Block Wall", AEBlockIds.SMOOTH_SKY_STONE_WALL, () -> new WallBlock(SKYSTONE_PROPERTIES));
Expand Down
56 changes: 15 additions & 41 deletions src/main/java/appeng/hooks/ticking/TickHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,11 @@
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.neoforged.bus.api.EventPriority;
import net.neoforged.fml.LogicalSide;
import net.neoforged.neoforge.common.NeoForge;
import net.neoforged.neoforge.event.TickEvent.LevelTickEvent;
import net.neoforged.neoforge.event.TickEvent.Phase;
import net.neoforged.neoforge.event.TickEvent.ServerTickEvent;
import net.neoforged.neoforge.event.level.ChunkEvent;
import net.neoforged.neoforge.event.level.LevelEvent;
import net.neoforged.neoforge.event.tick.LevelTickEvent;
import net.neoforged.neoforge.event.tick.ServerTickEvent;

import appeng.blockentity.AEBaseBlockEntity;
import appeng.core.AEConfig;
Expand Down Expand Up @@ -96,8 +94,10 @@ private TickHandler() {
}

public void init() {
NeoForge.EVENT_BUS.addListener(this::onServerTick);
NeoForge.EVENT_BUS.addListener(this::onLevelTick);
NeoForge.EVENT_BUS.addListener(this::onServerTickStart);
NeoForge.EVENT_BUS.addListener(this::onServerTickEnd);
NeoForge.EVENT_BUS.addListener(this::onServerLevelTickStart);
NeoForge.EVENT_BUS.addListener(this::onServerLevelTickEnd);
NeoForge.EVENT_BUS.addListener(this::onUnloadChunk);
// Try to go last for level unloads since we use it to clean-up state
NeoForge.EVENT_BUS.addListener(EventPriority.LOWEST, this::onUnloadLevel);
Expand All @@ -113,7 +113,7 @@ public void addCallable(LevelAccessor level, Runnable c) {
* Callbacks on the client are not support.
* <p>
* Using null as level will queue it into the global {@link ServerTickEvent}, otherwise it will be ticked with the
* corresponding {@link WorldTickEvent}.
* corresponding {@link LevelTickEvent}.
*
* @param level null or the specific {@link Level}
* @param c the callback
Expand Down Expand Up @@ -229,28 +229,10 @@ public void onUnloadLevel(final LevelEvent.Unload ev) {
this.callQueue.remove(level);
}

/**
* Tick a single {@link Level}
* <p>
* This can happen multiple times per level, but each level should only be ticked once per minecraft tick.
*/
public void onLevelTick(final LevelTickEvent ev) {
var level = ev.level;

if (!(level instanceof ServerLevel serverLevel) || ev.side != LogicalSide.SERVER) {
// While forge doesn't generate this event for client worlds,
// the event is generic enough that some other mod might be insane enough to do so.
private void onServerLevelTickStart(LevelTickEvent.Pre event) {
if (!(event.getLevel() instanceof ServerLevel level)) {
return;
}

if (ev.phase == Phase.START) {
onServerLevelTickStart(serverLevel);
} else if (ev.phase == Phase.END) {
onServerLevelTickEnd(serverLevel);
}
}

private void onServerLevelTickStart(ServerLevel level) {
var queue = this.callQueue.remove(level);
processQueueElementsRemaining += this.processQueue(queue, level);
var newQueue = this.callQueue.put(level, queue);
Expand All @@ -273,7 +255,10 @@ private void onServerLevelTickStart(ServerLevel level) {
}
}

private void onServerLevelTickEnd(ServerLevel level) {
private void onServerLevelTickEnd(LevelTickEvent.Post event) {
if (!(event.getLevel() instanceof ServerLevel level)) {
return;
}
this.simulateCraftingJobs(level);
this.readyBlockEntities(level);

Expand All @@ -290,18 +275,7 @@ private void onServerLevelTickEnd(ServerLevel level) {
}
}

/**
* Tick everything related to the global server tick once per minecraft tick.
*/
public void onServerTick(final ServerTickEvent ev) {
if (ev.phase == Phase.START) {
onServerTickStart();
} else if (ev.phase == Phase.END) {
onServerTickEnd();
}
}

private void onServerTickStart() {
private void onServerTickStart(ServerTickEvent.Pre event) {
// Reset the stop watch on the start of each server tick.
this.processQueueElementsProcessed = 0;
this.processQueueElementsRemaining = 0;
Expand All @@ -319,7 +293,7 @@ private void onServerTickStart() {
}
}

private void onServerTickEnd() {
private void onServerTickEnd(ServerTickEvent.Post event) {
// tick networks
for (var g : this.grids.getNetworks()) {
try {
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/appeng/server/testplots/P2PTestPlots.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import net.minecraft.world.level.LightLayer;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.material.Fluids;
import net.neoforged.neoforge.fluids.FluidStack;

import appeng.blockentity.networking.EnergyCellBlockEntity;
import appeng.blockentity.storage.SkyStoneTankBlockEntity;
Expand Down Expand Up @@ -89,7 +88,7 @@ public static void fluid(PlotBuilder plot) {
var tank = (SkyStoneTankBlockEntity) helper.getBlockEntity(outputPos);
var storage = tank.getTank();
helper.check(
new FluidStack(Fluids.WATER, 1).isFluidEqual(storage.getFluid()),
storage.getFluid().is(Fluids.WATER),
"No water stored");
helper.check(
storage.getFluidAmount() > 0,
Expand Down
30 changes: 14 additions & 16 deletions src/main/java/appeng/siteexport/SiteExporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@
import net.minecraft.world.level.material.Fluids;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.api.distmarker.OnlyIn;
import net.neoforged.neoforge.client.event.ClientTickEvent;
import net.neoforged.neoforge.client.extensions.common.IClientFluidTypeExtensions;
import net.neoforged.neoforge.common.NeoForge;
import net.neoforged.neoforge.event.TickEvent;
import net.neoforged.neoforge.fluids.FluidStack;

import appeng.api.features.P2PTunnelAttunement;
Expand Down Expand Up @@ -129,22 +129,20 @@ public static void initialize() {
if (Boolean.getBoolean("appeng.runGuideExportAndExit")) {
Path outputFolder = Paths.get(System.getProperty("appeng.guideExportFolder"));

NeoForge.EVENT_BUS.addListener((TickEvent.ClientTickEvent evt) -> {
if (evt.phase == TickEvent.Phase.END) {
var client = Minecraft.getInstance();
if (client.getOverlay() instanceof LoadingOverlay) {
return; // Do nothing while it's loading
}

var guide = AppEngClient.instance().getGuide();
try {
export(client, outputFolder, guide);
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
System.exit(0);
NeoForge.EVENT_BUS.addListener((ClientTickEvent.Post evt) -> {
var client = Minecraft.getInstance();
if (client.getOverlay() instanceof LoadingOverlay) {
return; // Do nothing while it's loading
}

var guide = AppEngClient.instance().getGuide();
try {
export(client, outputFolder, guide);
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
System.exit(0);
});
}
}
Expand Down

0 comments on commit 69c8d37

Please sign in to comment.