Repository navigation
Expand file tree
/
Copy pathGameTestAddon.java
More file actions
145 lines (124 loc) · 5.71 KB
/
Copy pathGameTestAddon.java
File metadata and controls
145 lines (124 loc) · 5.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
package org.cyclops.colossalchests2.gametest;
import net.minecraft.core.BlockPos;
import net.minecraft.resources.Identifier;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.state.BlockState;
import org.cyclops.colossalchests2.api.ChestMaterial;
import org.cyclops.colossalchests2.api.ColossalChestsApi;
import org.cyclops.colossalchests2.api.IChest;
import org.cyclops.colossalchests2.api.block.ChestMemberBlock;
import org.cyclops.colossalchests2.api.upgrade.ChestUpgrade;
import org.cyclops.cyclopscore.config.extendedconfig.BlockConfigCommon;
import org.cyclops.cyclopscore.config.extendedconfig.ItemConfigCommon;
import org.cyclops.cyclopscore.gametest.GameTestLoaderHelpers;
import org.cyclops.cyclopscore.init.IModBase;
import java.util.concurrent.atomic.AtomicInteger;
/**
* Content registered like an addon would, only on game test servers, to test the extension points.
* It only uses the api package.
* @author rubensworks
*/
public final class GameTestAddon {
/**
* Defined by data/colossalchests2test/colossalchests2/material/test_addon.json: after gold, with its depth limit set
* by the material instead of the upgrade. That file does nothing outside game tests, as the blocks are missing.
* Its namespace differs from its blocks', like a material of another mod.
*/
public static final ChestMaterial MATERIAL = new ChestMaterial(Identifier.fromNamespaceAndPath(ColossalChestsApi.MOD_ID + "test", "test_addon"));
/**
* Refuses dirt, and adds a cobblestone every second. Defined by data/colossalchests2/colossalchests2/upgrade/test_addon.json,
* which does nothing outside game tests, as the upgrade is missing.
*/
public static final ChestUpgrade UPGRADE = new ChestUpgrade(Identifier.fromNamespaceAndPath(ColossalChestsApi.MOD_ID, "test_addon")) {
@Override
public boolean canInsert(IChest chest, ItemStack type, int count) {
return !type.is(Items.DIRT);
}
@Override
public void tick(IChest chest, int count) {
if (chest.getLevel().getGameTime() % 20 == 0) {
chest.insert(new ItemStack(Items.COBBLESTONE), count, false);
}
}
};
/**
* The id of the wall, registered by {@link WallConfig}.
*/
public static final Identifier WALL = Identifier.fromNamespaceAndPath(ColossalChestsApi.MOD_ID, "test_addon_wall");
private GameTestAddon() {
}
/**
* @return If this is a game test server of any loader, or game tests are enabled for all Cyclops mods, as in production pack tests.
*/
public static boolean isEnabled() {
return Boolean.getBoolean("neoforge.gameTestServer") || Boolean.getBoolean("forge.gameTestServer")
|| System.getProperty("fabric-api.gametest") != null || GameTestLoaderHelpers.areGameTestsGloballyEnabled();
}
/**
* Register the addon upgrade, after which the caller registers the configs.
*/
public static void register() {
ColossalChestsApi.get().registerUpgrade(UPGRADE);
}
/**
* @return New properties for a wall or core of the test material.
*/
public static Block.Properties createProperties(Block.Properties properties) {
return properties.strength(2.5F, 6.0F).sound(SoundType.AMETHYST);
}
/**
* Config for the plain wall of the {@link #MATERIAL}.
*/
public static class MaterialWallConfig<M extends IModBase> extends BlockConfigCommon<M> {
public MaterialWallConfig(M mod) {
super(mod, "chest_wall_" + MATERIAL.getName(), (eConfig, props) -> ColossalChestsApi.get().createWall(createProperties(props), MATERIAL),
(eConfig, block) -> ColossalChestsApi.get().createMemberItem(block, eConfig.createDefaultItemProperties()));
}
}
/**
* Config for the core of the {@link #MATERIAL}.
*/
public static class MaterialCoreConfig<M extends IModBase> extends BlockConfigCommon<M> {
public MaterialCoreConfig(M mod) {
super(mod, "chest_core_" + MATERIAL.getName(), (eConfig, props) -> ColossalChestsApi.get().createCore(createProperties(props), MATERIAL),
(eConfig, block) -> ColossalChestsApi.get().createMemberItem(block, eConfig.createDefaultItemProperties()));
}
}
/**
* Config for the item of the {@link #UPGRADE}.
*/
public static class UpgradeConfig<M extends IModBase> extends ItemConfigCommon<M> {
public UpgradeConfig(M mod) {
super(mod, "upgrade_" + UPGRADE.getId().getPath(),
(eConfig, props) -> ColossalChestsApi.get().createUpgradeItem(props.stacksTo(16), UPGRADE));
}
}
/**
* A functional wall that counts how often the contents of its chest changed.
*/
public static class Wall extends ChestMemberBlock {
private final AtomicInteger contentsChanges = new AtomicInteger();
public Wall(Properties properties) {
super(properties);
}
public int getContentsChanges() {
return contentsChanges.get();
}
@Override
public void onChestContentsChanged(BlockState state, Level level, BlockPos pos, IChest chest) {
contentsChanges.incrementAndGet();
}
}
/**
* Config for the {@link Wall}.
*/
public static class WallConfig<M extends IModBase> extends BlockConfigCommon<M> {
public WallConfig(M mod) {
super(mod, WALL.getPath(), (eConfig, props) -> new Wall(props.strength(2.5F)), getDefaultItemConstructor(mod));
}
}
}