Skip to content

Commit 2cbe7f4

Browse files
committed
Split simple and literal member types so they are loaded differently
1 parent 3c7e690 commit 2cbe7f4

File tree

5 files changed

+64
-12
lines changed

5 files changed

+64
-12
lines changed

src/main/java/aztech/modern_industrialization/machines/multiblocks/structure/member/HatchStructureMember.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,10 @@ public void save(CompoundTag tag) {
107107
}
108108

109109
@Override
110-
public Optional<Pair<BlockState, FastBlockEntity>> asStructureBlock(BlockPos pos, boolean attempt) {
110+
public Optional<Pair<BlockState, FastBlockEntity>> asStructureBlock(BlockPos pos, boolean required) {
111111
assertLoaded();
112112

113-
if (attempt) {
113+
if (required) {
114114
var state = MIBlock.STRUCTURE_MULTIBLOCK_MEMBER.asBlock().defaultBlockState();
115115
state = state.setValue(StructureMultiblockMemberBlock.MODE, StructureMemberMode.HATCH);
116116
var be = MIBlock.STRUCTURE_MULTIBLOCK_MEMBER.get().newBlockEntity(pos, state);
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* MIT License
3+
*
4+
* Copyright (c) 2020 Azercoco & Technici4n
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
package aztech.modern_industrialization.machines.multiblocks.structure.member;
25+
26+
import aztech.modern_industrialization.blocks.FastBlockEntity;
27+
import aztech.modern_industrialization.machines.multiblocks.structure.member.test.StateStructureMemberTest;
28+
import com.mojang.datafixers.util.Pair;
29+
import java.util.List;
30+
import java.util.Optional;
31+
import java.util.function.Supplier;
32+
import net.minecraft.core.BlockPos;
33+
import net.minecraft.world.level.block.state.BlockState;
34+
35+
public class LiteralStructureMember extends SimpleStructureMember {
36+
public LiteralStructureMember(Supplier<BlockState> blockState) {
37+
super(blockState, List.of(new StateStructureMemberTest(blockState)));
38+
}
39+
40+
public LiteralStructureMember() {
41+
}
42+
43+
@Override
44+
public String typeId() {
45+
return "literal";
46+
}
47+
48+
@Override
49+
public Optional<Pair<BlockState, FastBlockEntity>> asStructureBlock(BlockPos pos, boolean required) {
50+
return Optional.empty();
51+
}
52+
}

src/main/java/aztech/modern_industrialization/machines/multiblocks/structure/member/SimpleStructureMember.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ public class SimpleStructureMember extends StructureMember {
5151

5252
private BlockState preview;
5353

54-
public SimpleStructureMember(Supplier<BlockState> previewSupplier, List<StructureMemberTest> tests) {
55-
Objects.requireNonNull(previewSupplier);
54+
public SimpleStructureMember(Supplier<BlockState> preview, List<StructureMemberTest> tests) {
55+
Objects.requireNonNull(preview);
5656
Objects.requireNonNull(tests);
57-
this.previewSupplier = previewSupplier;
57+
this.previewSupplier = preview;
5858
this.tests = tests;
5959
}
6060

@@ -120,10 +120,10 @@ public void save(CompoundTag tag) {
120120
}
121121

122122
@Override
123-
public Optional<Pair<BlockState, FastBlockEntity>> asStructureBlock(BlockPos pos, boolean attempt) {
123+
public Optional<Pair<BlockState, FastBlockEntity>> asStructureBlock(BlockPos pos, boolean required) {
124124
assertLoaded();
125125

126-
if (attempt && tests.size() > 1) {
126+
if (required) {
127127
var state = MIBlock.STRUCTURE_MULTIBLOCK_MEMBER.asBlock().defaultBlockState();
128128
state = state.setValue(StructureMultiblockMemberBlock.MODE, StructureMemberMode.SIMPLE);
129129
var be = MIBlock.STRUCTURE_MULTIBLOCK_MEMBER.get().newBlockEntity(pos, state);

src/main/java/aztech/modern_industrialization/machines/multiblocks/structure/member/StructureMember.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import aztech.modern_industrialization.machines.models.MachineCasing;
2828
import aztech.modern_industrialization.machines.multiblocks.HatchFlags;
2929
import aztech.modern_industrialization.machines.multiblocks.SimpleMember;
30-
import aztech.modern_industrialization.machines.multiblocks.structure.member.test.StateStructureMemberTest;
3130
import aztech.modern_industrialization.machines.multiblocks.structure.member.test.StructureMemberTest;
3231
import com.mojang.datafixers.util.Pair;
3332
import java.util.List;
@@ -58,14 +57,14 @@ public void save(CompoundTag tag) {
5857
assertLoaded();
5958
}
6059

61-
public abstract Optional<Pair<BlockState, FastBlockEntity>> asStructureBlock(BlockPos pos, boolean attempt);
60+
public abstract Optional<Pair<BlockState, FastBlockEntity>> asStructureBlock(BlockPos pos, boolean required);
6261

6362
public static SimpleStructureMember simple(Supplier<BlockState> preview, List<StructureMemberTest> tests) {
6463
return new SimpleStructureMember(preview, tests);
6564
}
6665

67-
public static SimpleStructureMember literal(Supplier<BlockState> blockState) {
68-
return simple(blockState, List.of(new StateStructureMemberTest(blockState)));
66+
public static LiteralStructureMember literal(Supplier<BlockState> blockState) {
67+
return new LiteralStructureMember(blockState);
6968
}
7069

7170
public static HatchStructureMember hatch(Supplier<BlockState> preview, List<StructureMemberTest> tests, MachineCasing casing,
@@ -85,6 +84,7 @@ public static StructureMember from(CompoundTag tag) {
8584
String type = tag.getString("type");
8685
StructureMember member = switch (type) {
8786
case "simple" -> new SimpleStructureMember();
87+
case "literal" -> new LiteralStructureMember();
8888
case "hatch" -> new HatchStructureMember();
8989
case "variable" -> new VariableStructureMember();
9090
default -> throw new IllegalStateException("Unexpected type: " + type);

src/main/java/aztech/modern_industrialization/machines/multiblocks/structure/member/VariableStructureMember.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public void save(CompoundTag tag) {
8282
}
8383

8484
@Override
85-
public Optional<Pair<BlockState, FastBlockEntity>> asStructureBlock(BlockPos pos, boolean attempt) {
85+
public Optional<Pair<BlockState, FastBlockEntity>> asStructureBlock(BlockPos pos, boolean required) {
8686
assertLoaded();
8787

8888
var state = MIBlock.STRUCTURE_MULTIBLOCK_MEMBER.asBlock().defaultBlockState();

0 commit comments

Comments
 (0)