diff --git a/patches/minecraft/net/minecraft/core/Direction.java.patch b/patches/minecraft/net/minecraft/core/Direction.java.patch index d0dabc7787..1213925f35 100644 --- a/patches/minecraft/net/minecraft/core/Direction.java.patch +++ b/patches/minecraft/net/minecraft/core/Direction.java.patch @@ -1,12 +1,17 @@ --- a/net/minecraft/core/Direction.java +++ b/net/minecraft/core/Direction.java -@@ -49,6 +_,10 @@ +@@ -49,6 +_,15 @@ private final Vec3i normal; private final Vec3 normalVec3; private static final Direction[] VALUES = values(); + private static final List VALUES_VIEW = java.util.Collections.unmodifiableList(Arrays.asList(VALUES)); + public static final List valuesView() { + return VALUES_VIEW; ++ } ++ // In vanilla updates are notified only on the horizontal plane, in Forge we also notify up and down ++ private static final List UPDATE_ORDER = java.util.Collections.unmodifiableList(Stream.concat(Plane.HORIZONTAL.stream(), Plane.VERTICAL.stream()).toList()); ++ public static final List getUpdateOrder() { ++ return UPDATE_ORDER; + } private static final Direction[] BY_3D_DATA = Arrays.stream(VALUES) .sorted(Comparator.comparingInt(p_235687_ -> p_235687_.data3d)) diff --git a/patches/minecraft/net/minecraft/world/level/Level.java.patch b/patches/minecraft/net/minecraft/world/level/Level.java.patch index c03ff89364..0bb8617c6f 100644 --- a/patches/minecraft/net/minecraft/world/level/Level.java.patch +++ b/patches/minecraft/net/minecraft/world/level/Level.java.patch @@ -163,7 +163,7 @@ public void updateNeighbourForOutputSignal(BlockPos p_46718_, Block p_46719_) { - for (Direction direction : Direction.Plane.HORIZONTAL) { -+ for (Direction direction : Direction.valuesView()) { ++ for (Direction direction : Direction.getUpdateOrder()) { BlockPos blockpos = p_46718_.relative(direction); if (this.hasChunkAt(blockpos)) { BlockState blockstate = this.getBlockState(blockpos); diff --git a/src/test/java/net/minecraftforge/debug/gameplay/redstone/UpdateOrder.java b/src/test/java/net/minecraftforge/debug/gameplay/redstone/UpdateOrder.java new file mode 100644 index 0000000000..5f8ce55ab6 --- /dev/null +++ b/src/test/java/net/minecraftforge/debug/gameplay/redstone/UpdateOrder.java @@ -0,0 +1,91 @@ +/* + * Copyright (c) Forge Development LLC and contributors + * SPDX-License-Identifier: LGPL-2.1-only + */ + +package net.minecraftforge.debug.gameplay.redstone; + +import net.minecraft.core.BlockPos; +import net.minecraft.gametest.framework.GameTest; +import net.minecraft.gametest.framework.GameTestHelper; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.Items; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.entity.ChestBlockEntity; +import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; +import net.minecraftforge.test.BaseTestMod; +import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.gametest.GameTestHolder; + +/** + * Redstone update orders are important in many contraptions as there are pistons and other things that could conflict with each other. + * These tests verify just that, two pistons pushing the same block. + * + * Partial verification/fix for https://github.com/MinecraftForge/MinecraftForge/issues/9973 + */ +@Mod(UpdateOrder.MODID) +@GameTestHolder("forge." + UpdateOrder.MODID) +public class UpdateOrder extends BaseTestMod { + public static final String MODID = "update_order"; + private static final int PISTON_DELAY = 4; + + public UpdateOrder(FMLJavaModLoadingContext context) { + super(context); + } + + @GameTest(template = "update_order:update_order", rotationSteps = 0) + public static void south(GameTestHelper helper) { + var chestPos = new BlockPos(0, 1, 0); + helper.assertBlockPresent(Blocks.CHEST, chestPos); + var chest = helper.getBlockEntity(chestPos); + chest.setItem(0, new ItemStack(Items.DIRT)); + + helper.runAfterDelay(PISTON_DELAY, () -> { + var expectedPos = new BlockPos(2, 1, 3); + helper.assertBlockPresent(Blocks.WHITE_WOOL, expectedPos); + helper.succeed(); + }); + } + + @GameTest(template = "update_order:update_order", rotationSteps = 1) + public static void west(GameTestHelper helper) { + var chestPos = new BlockPos(0, 1, 0); + helper.assertBlockPresent(Blocks.CHEST, chestPos); + var chest = helper.getBlockEntity(chestPos); + chest.setItem(0, new ItemStack(Items.DIRT)); + + helper.runAfterDelay(PISTON_DELAY, () -> { + var expectedPos = new BlockPos(2, 1, 3); + helper.assertBlockPresent(Blocks.WHITE_WOOL, expectedPos); + helper.succeed(); + }); + } + + @GameTest(template = "update_order:update_order", rotationSteps = 2) + public static void north(GameTestHelper helper) { + var chestPos = new BlockPos(0, 1, 0); + helper.assertBlockPresent(Blocks.CHEST, chestPos); + var chest = helper.getBlockEntity(chestPos); + chest.setItem(0, new ItemStack(Items.DIRT)); + + helper.runAfterDelay(4, () -> { + var expectedPos = new BlockPos(3, 1, 2); + helper.assertBlockPresent(Blocks.WHITE_WOOL, expectedPos); + helper.succeed(); + }); + } + + @GameTest(template = "update_order:update_order", rotationSteps = 3) + public static void east(GameTestHelper helper) { + var chestPos = new BlockPos(0, 1, 0); + helper.assertBlockPresent(Blocks.CHEST, chestPos); + var chest = helper.getBlockEntity(chestPos); + chest.setItem(0, new ItemStack(Items.DIRT)); + + helper.runAfterDelay(PISTON_DELAY, () -> { + var expectedPos = new BlockPos(2, 1, 3); + helper.assertBlockPresent(Blocks.WHITE_WOOL, expectedPos); + helper.succeed(); + }); + } +} \ No newline at end of file diff --git a/src/test/resources/update_order/data/update_order/structure/update_order.nbt b/src/test/resources/update_order/data/update_order/structure/update_order.nbt new file mode 100644 index 0000000000..7a10f54b94 Binary files /dev/null and b/src/test/resources/update_order/data/update_order/structure/update_order.nbt differ