Skip to content

Commit 889cf7e

Browse files
committed
Merge remote-tracking branch 'origin/master-1.21-lts' into master-26-lts
2 parents 7cdea8d + b4ebddc commit 889cf7e

6 files changed

Lines changed: 79 additions & 30 deletions

File tree

‎loader-common/src/main/java/org/cyclops/colossalchests2/block/DisplayWallInteractions.java‎

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -158,23 +158,19 @@ public static InteractionResult useItemOn(ItemStack stack, Player player, BlockE
158158

159159
/**
160160
* A right-click with an empty hand on a face: right after an insert there it inserts all of the type it shows,
161-
* otherwise it opens the settings. Sneaking does nothing, except on a hidden face, where it is the only way to the
162-
* settings.
161+
* otherwise it opens the settings. Sneaking opens the settings on any face, like on other functional walls.
163162
* @return The result, or null to fall back to the default wall behaviour.
164163
*/
165164
@Nullable
166165
public static InteractionResult useWithoutItem(Player player, BlockEntityChestWall wall, Direction face) {
167-
if (wall.isFaceHidden(face)) {
168-
if (!player.isSecondaryUseActive()) {
169-
return null;
170-
}
166+
if (player.isSecondaryUseActive()) {
171167
if (player instanceof ServerPlayer serverPlayer) {
172168
openSettings(serverPlayer, wall);
173169
}
174170
return InteractionResult.SUCCESS;
175171
}
176-
if (player.isSecondaryUseActive()) {
177-
return InteractionResult.PASS;
172+
if (wall.isFaceHidden(face)) {
173+
return null;
178174
}
179175
// Only the server knows about the previous click, the client lets it decide.
180176
if (player instanceof ServerPlayer serverPlayer) {
@@ -190,7 +186,7 @@ public static InteractionResult useWithoutItem(Player player, BlockEntityChestWa
190186
}
191187

192188
private static void openSettings(ServerPlayer player, BlockEntityChestWall wall) {
193-
IModHelpers.get().getMinecraftHelpers().openMenu(player, wall, buf -> ContainerDisplay.writeOpenData(buf, wall));
189+
IModHelpers.get().getMinecraftHelpers().openMenu(player, wall, ContainerDisplay.openDataWriter(wall));
194190
}
195191

196192
/**

‎loader-common/src/main/java/org/cyclops/colossalchests2/blockentity/BlockEntityChestCore.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ public int getComparatorSignal() {
324324
*/
325325
public void openMenu(ServerPlayer player) {
326326
if (isFormed()) {
327-
IModHelpers.get().getMinecraftHelpers().openMenu(player, this, data -> ContainerChest.writeOpenData(data, this));
327+
IModHelpers.get().getMinecraftHelpers().openMenu(player, this, ContainerChest.openDataWriter(this));
328328
}
329329
}
330330

‎loader-common/src/main/java/org/cyclops/colossalchests2/gametest/GameTestsCommon.java‎

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@
143143
import org.jetbrains.annotations.Nullable;
144144

145145
import java.util.List;
146+
import java.util.function.Consumer;
146147
import java.util.Objects;
147148
import java.util.Optional;
148149
import java.util.Set;
@@ -1888,11 +1889,7 @@ public void testDisplayWallInsertsAndTakes(GameTestHelper helper) {
18881889
helper.assertTrue(player.getInventory().getItem(4).is(Items.DIRT), "Expected the held dirt to stay");
18891890
helper.assertValueEqual(countInInventory(player, Items.STONE), 1, "stone next to the held dirt");
18901891
player.getInventory().setSelectedSlot(0);
1891-
// Sneaking with an empty hand does nothing.
1892-
player.getInventory().clearContent();
1893-
player.setShiftKeyDown(true);
1894-
helper.assertValueEqual(click(helper, player, display), InteractionResult.PASS, "sneaking click");
1895-
helper.assertTrue(wall.getDisplayed(Direction.UP).is(Items.STONE), "Expected stone to stay shown");
1892+
// Sneaking with an empty hand opens the settings. Checked in-game, as NeoForge does not open menus for mock players.
18961893
})
18971894
.thenSucceed();
18981895
}
@@ -1961,6 +1958,32 @@ public void testDisplayWallSettings(GameTestHelper helper) {
19611958
.thenSucceed();
19621959
}
19631960

1961+
@GameTest(template = TEMPLATE_EMPTY)
1962+
public void testDisplayOpenDataReadWhenOpening(GameTestHelper helper) {
1963+
BlockPos corePos = buildChest(helper, MIN_A, 3, ChestMaterial.WOOD);
1964+
BlockPos display = placeWall(helper, MIN_A.offset(1, 2, 1), WallType.DISPLAY);
1965+
List<Consumer<FriendlyByteBuf>> writers = Lists.newArrayList();
1966+
int[] faces = new int[1];
1967+
helper.startSequence()
1968+
.thenWaitUntil(() -> assertFormed(helper, corePos, MIN_A, 3))
1969+
.thenExecute(() -> {
1970+
// Fabric writes open data later, off the server thread, so it must not depend on the chest by then.
1971+
BlockEntityChestWall wall = getWall(helper, display);
1972+
faces[0] = wall.getDisplayFaces().size();
1973+
helper.assertTrue(faces[0] > 0, "Expected faces to show items on");
1974+
writers.add(ContainerDisplay.openDataWriter(wall));
1975+
helper.setBlock(MIN_A, Blocks.AIR);
1976+
})
1977+
.thenWaitUntil(() -> assertDormant(helper, corePos))
1978+
.thenExecute(() -> {
1979+
FriendlyByteBuf data = new FriendlyByteBuf(Unpooled.buffer());
1980+
writers.getFirst().accept(data);
1981+
ContainerDisplay client = new ContainerDisplay(103, makeViewer(helper).getInventory(), data);
1982+
helper.assertValueEqual(client.getFaces().size(), faces[0], "faces on the client");
1983+
})
1984+
.thenSucceed();
1985+
}
1986+
19641987
@GameTest(template = TEMPLATE_EMPTY)
19651988
public void testDisplayWallFaces(GameTestHelper helper) {
19661989
BlockPos corePos = buildChest(helper, MIN_A, 3, ChestMaterial.WOOD);

‎loader-common/src/main/java/org/cyclops/colossalchests2/inventory/ContainerChest.java‎

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.cyclops.colossalchests2.upgrade.UpgradeSet;
3434
import org.jetbrains.annotations.Nullable;
3535

36+
import java.util.function.Consumer;
3637
import java.util.Arrays;
3738
import java.util.BitSet;
3839
import java.util.List;
@@ -124,11 +125,26 @@ private ContainerChest(int id, Inventory inventory, BlockPos corePos, int slotCo
124125
* Write what the client-side constructor reads.
125126
*/
126127
public static void writeOpenData(FriendlyByteBuf data, BlockEntityChestCore core) {
127-
data.writeBlockPos(core.getBlockPos());
128-
data.writeVarInt(core.getStorage().getSlotCount());
129-
data.writeVarInt(core.getUpgrades().getContainerSize());
130-
data.writeVarIntArray(getMaxUpgradeCounts(core));
131-
data.writeVarIntArray(getBetterMaterialTakesMore(core));
128+
openDataWriter(core).accept(data);
129+
}
130+
131+
/**
132+
* Some loaders write open data later, off the server thread, so read the chest now.
133+
* @return A writer of what the client-side constructor reads.
134+
*/
135+
public static Consumer<FriendlyByteBuf> openDataWriter(BlockEntityChestCore core) {
136+
BlockPos pos = core.getBlockPos();
137+
int slotCount = core.getStorage().getSlotCount();
138+
int upgradeSlots = core.getUpgrades().getContainerSize();
139+
int[] maxUpgradeCounts = getMaxUpgradeCounts(core);
140+
int[] betterMaterialTakesMore = getBetterMaterialTakesMore(core);
141+
return data -> {
142+
data.writeBlockPos(pos);
143+
data.writeVarInt(slotCount);
144+
data.writeVarInt(upgradeSlots);
145+
data.writeVarIntArray(maxUpgradeCounts);
146+
data.writeVarIntArray(betterMaterialTakesMore);
147+
};
132148
}
133149

134150
private static int[] getMaxUpgradeCounts(BlockEntityChestCore core) {

‎loader-common/src/main/java/org/cyclops/colossalchests2/inventory/ContainerDisplay.java‎

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.cyclops.colossalchests2.inventory;
22

33
import com.google.common.collect.Lists;
4+
import net.minecraft.core.BlockPos;
45
import net.minecraft.core.Direction;
56
import net.minecraft.network.FriendlyByteBuf;
67
import net.minecraft.world.Container;
@@ -14,6 +15,7 @@
1415
import org.cyclops.colossalchests2.blockentity.DisplayOption;
1516
import org.jetbrains.annotations.Nullable;
1617

18+
import java.util.function.Consumer;
1719
import java.util.List;
1820
import java.util.Locale;
1921

@@ -85,11 +87,23 @@ private static Direction getFront(BlockEntityChestWall wall) {
8587
* Write what the client constructor reads.
8688
*/
8789
public static void writeOpenData(FriendlyByteBuf data, BlockEntityChestWall wall) {
88-
data.writeBlockPos(wall.getBlockPos());
89-
data.writeEnum(getFront(wall));
90-
List<Direction> faces = wall.getDisplayFaces();
91-
data.writeVarInt(faces.size());
92-
faces.forEach(data::writeEnum);
90+
openDataWriter(wall).accept(data);
91+
}
92+
93+
/**
94+
* Some loaders write open data later, off the server thread, so read the wall now.
95+
* @return A writer of what the client constructor reads.
96+
*/
97+
public static Consumer<FriendlyByteBuf> openDataWriter(BlockEntityChestWall wall) {
98+
BlockPos pos = wall.getBlockPos();
99+
Direction front = getFront(wall);
100+
List<Direction> faces = List.copyOf(wall.getDisplayFaces());
101+
return data -> {
102+
data.writeBlockPos(pos);
103+
data.writeEnum(front);
104+
data.writeVarInt(faces.size());
105+
faces.forEach(data::writeEnum);
106+
};
93107
}
94108

95109
private static Direction readFront(FriendlyByteBuf data) {

‎loader-common/src/main/resources/assets/colossalchests2/lang/en_us.json‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,18 @@
88
"block.colossalchests2.chest_core_copper": "Copper Chest Core",
99
"block.colossalchests2.chest_wall_iron": "Iron Chest Wall",
1010
"block.colossalchests2.chest_core_iron": "Iron Chest Core",
11-
"block.colossalchests2.chest_wall_interface": "Chest Interface",
11+
"block.colossalchests2.chest_wall_interface": "Interface Chest Wall",
1212
"block.colossalchests2.chest_wall_interface.info": "A wall for chest external access. Sneak-right-click with empty hand to set filters.",
13-
"block.colossalchests2.chest_wall_void": "Void Chest Interface",
14-
"block.colossalchests2.chest_wall_void.info": "An interface that destroys overflowing items.",
15-
"block.colossalchests2.chest_wall_display": "Chest Display",
13+
"block.colossalchests2.chest_wall_void": "Void Chest Wall",
14+
"block.colossalchests2.chest_wall_void.info": "Like an Interface Chest Wall, but destroys overflowing items.",
15+
"block.colossalchests2.chest_wall_display": "Display Chest Wall",
1616
"block.colossalchests2.chest_wall_magnet": "Magnet Chest Wall",
1717
"block.colossalchests2.chest_wall_magnet.info": "Pulls dropped items around it into the chest. Sneak-right-click with empty hand to set its radius.",
1818
"block.colossalchests2.chest_wall_golem": "Golem Chest Wall",
1919
"block.colossalchests2.chest_wall_golem.info": "Copper golems can take items out of this.",
2020
"block.colossalchests2.chest_wall_redstone": "Redstone Chest Wall",
2121
"block.colossalchests2.chest_wall_redstone.info": "Emits a redstone signal based on how full the chest is.",
22-
"block.colossalchests2.chest_wall_display.info": "Shows an item and its count. Take items with (sneak-)left-click and insert with (double) right-click.",
22+
"block.colossalchests2.chest_wall_display.info": "Shows an item and its count. Take items with (sneak-)left-click and insert with (double) right-click. Sneak-right-click with empty hand to configure.",
2323
"block.colossalchests2.chest_wall_gold": "Golden Chest Wall",
2424
"block.colossalchests2.chest_core_gold": "Golden Chest Core",
2525
"block.colossalchests2.chest_wall_diamond": "Diamond Chest Wall",

0 commit comments

Comments
 (0)