mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-26 15:03:04 +00:00
Redstone updates and gametests structure fixes (#10422)
Fix game test structure rotations being inconsistent (#10391) Fix redstone update order not matching vanilla. (#10392) Fix redstone updates for comparators going up/down incorrectly. Related: #9973 Make block pos assertions in GameTestHelper behave like in 1.21.3, thus fixing rotated tests functionality. This can be disabled in the Forge config if you have old tests that this breaks. Tho it is recommended you update your tests. --------- Co-authored-by: LexManos <[email protected]>
This commit is contained in:
1 parent
ee14c0c911
commit
c86172db31
12 files changed
+279
-3
No files matched your search
@@ -0,0 +1,14 @@
|
||||
--- a/net/minecraft/core/Direction.java
|
||||
+++ b/net/minecraft/core/Direction.java
|
||||
@@ -47,6 +_,11 @@
|
||||
private final Direction.AxisDirection axisDirection;
|
||||
private final Vec3i normal;
|
||||
private static final Direction[] VALUES = values();
|
||||
+ // In vanilla updates are notified only on the horizontal plane, in Forge we also notify up and down
|
||||
+ private static final List<Direction> UPDATE_ORDER = java.util.Collections.unmodifiableList(Stream.concat(Plane.HORIZONTAL.stream(), Plane.VERTICAL.stream()).toList());
|
||||
+ public static final List<Direction> getUpdateOrder() {
|
||||
+ return UPDATE_ORDER;
|
||||
+ }
|
||||
private static final Direction[] BY_3D_DATA = Arrays.stream(VALUES)
|
||||
.sorted(Comparator.comparingInt(p_235687_ -> p_235687_.data3d))
|
||||
.toArray(Direction[]::new);
|
||||
@@ -9,6 +9,43 @@
|
||||
private final GameTestInfo testInfo;
|
||||
private boolean finalCheckAdded;
|
||||
|
||||
@@ -870,26 +_,30 @@
|
||||
}
|
||||
|
||||
public BlockPos absolutePos(BlockPos p_177450_) {
|
||||
- BlockPos blockpos = this.testInfo.getStructureBlockPos();
|
||||
+ // Forge: Use IForgeGameTestInfo#getTestOrigin to account for rotations and to mimic 1.21.3 behavior
|
||||
+ BlockPos blockpos = this.testInfo.getTestOrigin();
|
||||
BlockPos blockpos1 = blockpos.offset(p_177450_);
|
||||
return StructureTemplate.transform(blockpos1, Mirror.NONE, this.testInfo.getRotation(), blockpos);
|
||||
}
|
||||
|
||||
public BlockPos relativePos(BlockPos p_177453_) {
|
||||
- BlockPos blockpos = this.testInfo.getStructureBlockPos();
|
||||
+ // Forge: Use IForgeGameTestInfo#getTestOrigin to account for rotations and to mimic 1.21.3 behavior
|
||||
+ BlockPos blockpos = this.testInfo.getTestOrigin();
|
||||
Rotation rotation = this.testInfo.getRotation().getRotated(Rotation.CLOCKWISE_180);
|
||||
BlockPos blockpos1 = StructureTemplate.transform(p_177453_, Mirror.NONE, rotation, blockpos);
|
||||
return blockpos1.subtract(blockpos);
|
||||
}
|
||||
|
||||
public Vec3 absoluteVec(Vec3 p_177228_) {
|
||||
- Vec3 vec3 = Vec3.atLowerCornerOf(this.testInfo.getStructureBlockPos());
|
||||
- return StructureTemplate.transform(vec3.add(p_177228_), Mirror.NONE, this.testInfo.getRotation(), this.testInfo.getStructureBlockPos());
|
||||
+ // Forge: Use IForgeGameTestInfo#getTestOrigin to account for rotations and to mimic 1.21.3 behavior
|
||||
+ Vec3 vec3 = Vec3.atLowerCornerOf(this.testInfo.getTestOrigin());
|
||||
+ return StructureTemplate.transform(vec3.add(p_177228_), Mirror.NONE, this.testInfo.getRotation(), this.testInfo.getTestOrigin());
|
||||
}
|
||||
|
||||
public Vec3 relativeVec(Vec3 p_251543_) {
|
||||
- Vec3 vec3 = Vec3.atLowerCornerOf(this.testInfo.getStructureBlockPos());
|
||||
- return StructureTemplate.transform(p_251543_.subtract(vec3), Mirror.NONE, this.testInfo.getRotation(), this.testInfo.getStructureBlockPos());
|
||||
+ // Forge: Use IForgeGameTestInfo#getTestOrigin to account for rotations and to mimic 1.21.3 behavior
|
||||
+ Vec3 vec3 = Vec3.atLowerCornerOf(this.testInfo.getTestOrigin());
|
||||
+ return StructureTemplate.transform(p_251543_.subtract(vec3), Mirror.NONE, this.testInfo.getRotation(), this.testInfo.getTestOrigin());
|
||||
}
|
||||
|
||||
public Rotation getTestRotation() {
|
||||
@@ -954,5 +_,25 @@
|
||||
if (either.right().isPresent()) {
|
||||
this.fail("Failed to set biome for test");
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
--- a/net/minecraft/gametest/framework/GameTestInfo.java
|
||||
+++ b/net/minecraft/gametest/framework/GameTestInfo.java
|
||||
@@ -261,7 +_,7 @@
|
||||
BlockPos blockpos = this.getOrCalculateNorthwestCorner();
|
||||
this.structureBlockEntity = StructureUtils.prepareTestStructure(this, blockpos, this.getRotation(), this.level);
|
||||
this.structureBlockPos = this.structureBlockEntity.getBlockPos();
|
||||
- StructureUtils.addCommandBlockAndButtonToStartTest(this.structureBlockPos, new BlockPos(1, 0, -1), this.getRotation(), this.level);
|
||||
+ StructureUtils.addCommandBlockAndButtonToStartTest(this.structureBlockPos, new BlockPos(1, 0, -1), Rotation.NONE, this.level); // Forge: The control blocks are always in the North West Corner
|
||||
StructureUtils.encaseStructure(this.getStructureBounds(), this.level, !this.testFunction.skyAccess());
|
||||
this.listeners.forEach(p_127630_ -> p_127630_.testStructureLoaded(this));
|
||||
return this;
|
||||
@@ -345,5 +_,25 @@
|
||||
|
||||
public void setNorthWestCorner(BlockPos p_328918_) {
|
||||
this.northWestCorner = p_328918_;
|
||||
+ }
|
||||
+
|
||||
+
|
||||
+ // FORGE START
|
||||
+
|
||||
+ private final boolean useTestOrigin = net.minecraftforge.common.ForgeConfig.COMMON.fixGameTestBlockPosAsserts.get();
|
||||
+
|
||||
+ /**
|
||||
+ * Forge: Gets the origin of the test structure based on the
|
||||
+ * {@linkplain #getStructureBlockEntity() structure block entity}.
|
||||
+ * <p>
|
||||
+ * This is a backported method from 1.21.3 to fix how block positions are asserted.
|
||||
+ *
|
||||
+ * @return The origin of the test structure
|
||||
+ *
|
||||
+ * @see net.minecraftforge.common.ForgeConfig.Common#fixGameTestBlockPosAsserts
|
||||
+ */
|
||||
+ @SuppressWarnings("DataFlowIssue") // Nullability moment
|
||||
+ public BlockPos getTestOrigin() {
|
||||
+ return this.useTestOrigin ? StructureUtils.getStructureOrigin(this.getStructureBlockEntity()) : this.getStructureBlockPos();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
--- a/net/minecraft/gametest/framework/ReportGameListener.java
|
||||
+++ b/net/minecraft/gametest/framework/ReportGameListener.java
|
||||
@@ -151,7 +_,7 @@
|
||||
private static BlockPos getBeaconPos(GameTestInfo p_344999_) {
|
||||
BlockPos blockpos = p_344999_.getStructureBlockPos();
|
||||
BlockPos blockpos1 = new BlockPos(-1, -2, -1);
|
||||
- return StructureTemplate.transform(blockpos.offset(blockpos1), Mirror.NONE, p_344999_.getRotation(), blockpos);
|
||||
+ return blockpos.offset(blockpos1); // Forge: The control blocks are always in the North West Corner
|
||||
}
|
||||
|
||||
private static void updateBeaconGlass(GameTestInfo p_343978_, Block p_344076_) {
|
||||
@@ -167,8 +_,8 @@
|
||||
ServerLevel serverlevel = p_177739_.getLevel();
|
||||
BlockPos blockpos = p_177739_.getStructureBlockPos();
|
||||
BlockPos blockpos1 = new BlockPos(-1, 0, -1);
|
||||
- BlockPos blockpos2 = StructureTemplate.transform(blockpos.offset(blockpos1), Mirror.NONE, p_177739_.getRotation(), blockpos);
|
||||
- serverlevel.setBlockAndUpdate(blockpos2, Blocks.LECTERN.defaultBlockState().rotate(p_177739_.getRotation()));
|
||||
+ BlockPos blockpos2 = blockpos.offset(blockpos1); // Forge: The control blocks are always in the North West Corner
|
||||
+ serverlevel.setBlockAndUpdate(blockpos2, Blocks.LECTERN.defaultBlockState());
|
||||
BlockState blockstate = serverlevel.getBlockState(blockpos2);
|
||||
ItemStack itemstack = createBook(p_177739_.getTestName(), p_177739_.isRequired(), p_177740_);
|
||||
LecternBlock.tryPlaceBook(null, serverlevel, blockpos2, blockstate, itemstack);
|
||||
@@ -0,0 +1,27 @@
|
||||
--- a/net/minecraft/gametest/framework/StructureUtils.java
|
||||
+++ b/net/minecraft/gametest/framework/StructureUtils.java
|
||||
@@ -109,7 +_,8 @@
|
||||
.getSize();
|
||||
BoundingBox boundingbox = getStructureBoundingBox(p_311042_, vec3i, p_310584_);
|
||||
BlockPos blockpos;
|
||||
- if (p_310584_ == Rotation.NONE) {
|
||||
+ // Forge: The control blocks are always in the North West Corner
|
||||
+ if (true || p_310584_ == Rotation.NONE) {
|
||||
blockpos = p_311042_;
|
||||
} else if (p_310584_ == Rotation.CLOCKWISE_90) {
|
||||
blockpos = p_311042_.offset(vec3i.getZ() - 1, 0, 0);
|
||||
@@ -125,7 +_,13 @@
|
||||
|
||||
forceLoadChunks(boundingbox, p_312330_);
|
||||
clearSpaceForStructure(boundingbox, p_312330_);
|
||||
- return createStructureBlock(p_311701_, blockpos.below(), p_310584_, p_312330_);
|
||||
+ var entity = createStructureBlock(p_311701_, blockpos.below(), p_310584_, p_312330_);
|
||||
+ //Forge: We need to offset the structure so that it will load within bounds.
|
||||
+ if (p_310584_ != Rotation.NONE) {
|
||||
+ var rotated = StructureTemplate.getZeroPositionWithTransform(BlockPos.ZERO, Mirror.NONE, p_310584_, entity.getStructureSize().getX(), entity.getStructureSize().getZ());
|
||||
+ entity.setStructurePos(rotated.offset(new BlockPos(0, 1, 0)));
|
||||
+ }
|
||||
+ return entity;
|
||||
}
|
||||
|
||||
public static void encaseStructure(AABB p_330422_, ServerLevel p_331249_, boolean p_328180_) {
|
||||
@@ -0,0 +1,15 @@
|
||||
--- a/net/minecraft/gametest/framework/TestCommand.java
|
||||
+++ b/net/minecraft/gametest/framework/TestCommand.java
|
||||
@@ -311,7 +_,11 @@
|
||||
return Optional.empty();
|
||||
} else {
|
||||
TestFunction testfunction = optional.get();
|
||||
- GameTestInfo gametestinfo = new GameTestInfo(testfunction, structureblockentity.getRotation(), p_328153_, p_330368_);
|
||||
+ // Forge: The rotation is stored in the structure block, and added in the GameTestInfo constructor.
|
||||
+ // So reverse it to find the manually specified rotation so the test runs the same every time.
|
||||
+ var steps = StructureUtils.getRotationStepsForRotation(structureblockentity.getRotation()) - StructureUtils.getRotationStepsForRotation(testfunction.rotation());
|
||||
+ if (steps < 0) steps += 4;
|
||||
+ GameTestInfo gametestinfo = new GameTestInfo(testfunction, StructureUtils.getRotationForRotationSteps(steps), p_328153_, p_330368_);
|
||||
gametestinfo.setStructureBlockPos(p_332856_);
|
||||
return !verifyStructureExists(p_328153_, gametestinfo.getStructureName()) ? Optional.empty() : Optional.of(gametestinfo);
|
||||
}
|
||||
@@ -188,12 +188,12 @@
|
||||
T t = p_261885_.tryCast(enderdragonpart);
|
||||
if (t != null && p_261688_.test(t)) {
|
||||
p_262071_.add(t);
|
||||
@@ -972,16 +_,15 @@
|
||||
@@ -972,17 +_,17 @@
|
||||
public abstract Scoreboard getScoreboard();
|
||||
|
||||
public void updateNeighbourForOutputSignal(BlockPos p_46718_, Block p_46719_) {
|
||||
- for (Direction direction : Direction.Plane.HORIZONTAL) {
|
||||
+ for (Direction direction : Direction.values()) {
|
||||
+ for (Direction direction : Direction.getUpdateOrder()) {
|
||||
BlockPos blockpos = p_46718_.relative(direction);
|
||||
if (this.hasChunkAt(blockpos)) {
|
||||
BlockState blockstate = this.getBlockState(blockpos);
|
||||
@@ -205,10 +205,13 @@
|
||||
blockpos = blockpos.relative(direction);
|
||||
blockstate = this.getBlockState(blockpos);
|
||||
- if (blockstate.is(Blocks.COMPARATOR)) {
|
||||
- this.neighborChanged(blockstate, blockpos, p_46719_, p_46718_, false);
|
||||
+ if (blockstate.getWeakChanges(this, blockpos)) {
|
||||
this.neighborChanged(blockstate, blockpos, p_46719_, p_46718_, false);
|
||||
+ // Forge: Use IForgeBlockState#onNeighborChange, the default impl redirects to Level#neighborChanged
|
||||
+ blockstate.onNeighborChange(this, blockpos, p_46718_);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1092,6 +_,20 @@
|
||||
}
|
||||
|
||||
|
||||
@@ -88,6 +88,8 @@ public class ForgeConfig {
|
||||
|
||||
public final ForgeConfigSpec.EnumValue<MigrationHelperMode> migrationHelperMode;
|
||||
|
||||
public final ForgeConfigSpec.BooleanValue fixGameTestBlockPosAsserts;
|
||||
|
||||
Common(ForgeConfigSpec.Builder builder) {
|
||||
builder.comment("General configuration settings")
|
||||
.push("general");
|
||||
@@ -97,6 +99,13 @@ public class ForgeConfig {
|
||||
.translation("forge.configgui.migrationHelperMode")
|
||||
.defineEnum("logLegacyTagWarnings", MigrationHelperMode.OFF);
|
||||
|
||||
fixGameTestBlockPosAsserts = builder
|
||||
.comment("""
|
||||
Set this to true to fix BlockPos assertions in game tests to account for rotations and generally behave as they would in 1.21.3.
|
||||
This is kept in the common config so that development environments that rely on old behavior do not need to continuously set this in a server config.""")
|
||||
.translation("forge.configgui.fixGameTestBlockPosAsserts")
|
||||
.define("fixGameTestBlockPosAsserts", true);
|
||||
|
||||
builder.pop();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -170,6 +170,8 @@
|
||||
"forge.configgui.forceSystemNanoTime": "Force System.nanoTime",
|
||||
"forge.configgui.useItemWithDurationZero": "Allow Use Item with Duration of 0",
|
||||
"forge.configgui.useItemWithDurationZero.tooltip": "Set this to true to enable living entities to use items with durations of 0. Fixes being able to use Eyes of Ender repeatedly by holding down the use button. Disabled by default as it could change interactions with items of existing mods.",
|
||||
"forge.configgui.fixGameTestBlockPosAsserts": "Fix GameTest BlockPos Asserts",
|
||||
"forge.configgui.fixGameTestBlockPosAsserts.tooltip": "Set this to true to fix BlockPos assertions in game tests to account for rotations and generally behave as they would in 1.21.3.\nThis is kept in the common config so that development environments that rely on old behavior do not need to continuously set this in a server config.",
|
||||
|
||||
"forge.configgui.zoomInMissingModelTextInGui.tooltip": "Toggle off to make missing model text in the gui fit inside the slot.",
|
||||
"forge.configgui.zoomInMissingModelTextInGui": "Zoom in Missing model text in the GUI",
|
||||
|
||||
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
* 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.BarrelBlockEntity;
|
||||
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.<ChestBlockEntity>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.<ChestBlockEntity>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.<ChestBlockEntity>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.<ChestBlockEntity>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:upward_update")
|
||||
public static void up(GameTestHelper helper) {
|
||||
var chestPos = new BlockPos(0, 1, 2);
|
||||
var expectedPos = new BlockPos(2, 1, 0);
|
||||
var unexpectedPos = new BlockPos(0, 4, 0);
|
||||
helper.assertBlockPresent(Blocks.BARREL, chestPos);
|
||||
helper.assertBlockPresent(Blocks.AIR, expectedPos);
|
||||
helper.assertBlockPresent(Blocks.AIR, unexpectedPos);
|
||||
var chest = helper.<BarrelBlockEntity>getBlockEntity(chestPos);
|
||||
chest.setItem(0, new ItemStack(Items.DIRT));
|
||||
|
||||
helper.runAfterDelay(10, () -> { // There are a lot of things happening, give it a few ticks
|
||||
helper.assertBlockNotPresent(Blocks.WHITE_WOOL, unexpectedPos);
|
||||
helper.assertBlockPresent(Blocks.WHITE_WOOL, expectedPos);
|
||||
helper.succeed();
|
||||
});
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Reference in new issue
Block a user