| 1 | package net.minecraft.data;
|
| 2 |
|
| 3 | import com.google.common.collect.Maps;
|
| 4 | import java.util.Map;
|
| 5 | import java.util.Optional;
|
| 6 | import net.minecraft.util.StringUtil;
|
| 7 | import net.minecraft.world.level.block.Block;
|
| 8 | import org.jspecify.annotations.Nullable;
|
| 9 |
|
| 10 | public class BlockFamily {
|
| 11 | private final Block baseBlock;
|
| 12 | private final Map<BlockFamily.Variant, Block> variants = Maps.newHashMap();
|
| 13 | private boolean generateModel = true;
|
| 14 | private boolean generateCraftingRecipe = true;
|
| 15 | private boolean generateSmeltingRecipe = true;
|
| 16 | private boolean generateStonecutterRecipe = false;
|
| 17 | private @Nullable String recipeGroupPrefix;
|
| 18 | private @Nullable String recipeUnlockedBy;
|
| 19 |
|
| 20 | private BlockFamily(final Block baseBlock) {
|
| 21 | this.baseBlock = baseBlock;
|
| 22 | }
|
| 23 |
|
| 24 | public Block getBaseBlock() {
|
| 25 | return this.baseBlock;
|
| 26 | }
|
| 27 |
|
| 28 | public Map<BlockFamily.Variant, Block> getVariants() {
|
| 29 | return this.variants;
|
| 30 | }
|
| 31 |
|
| 32 | public Block get(final BlockFamily.Variant variant) {
|
| 33 | return this.variants.get(variant);
|
| 34 | }
|
| 35 |
|
| 36 | public boolean shouldGenerateModel() {
|
| 37 | return this.generateModel;
|
| 38 | }
|
| 39 |
|
| 40 | public boolean shouldGenerateCraftingRecipe() {
|
| 41 | return this.generateCraftingRecipe;
|
| 42 | }
|
| 43 |
|
| 44 | public boolean shouldGenerateSmeltingRecipe() {
|
| 45 | return this.generateSmeltingRecipe;
|
| 46 | }
|
| 47 |
|
| 48 | public boolean shouldGenerateStonecutterRecipe() {
|
| 49 | return this.generateStonecutterRecipe;
|
| 50 | }
|
| 51 |
|
| 52 | public Optional<String> getRecipeGroupPrefix() {
|
| 53 | return StringUtil.isBlank(this.recipeGroupPrefix) ? Optional.empty() : Optional.of(this.recipeGroupPrefix);
|
| 54 | }
|
| 55 |
|
| 56 | public Optional<String> getRecipeUnlockedBy() {
|
| 57 | return StringUtil.isBlank(this.recipeUnlockedBy) ? Optional.empty() : Optional.of(this.recipeUnlockedBy);
|
| 58 | }
|
| 59 |
|
| 60 | public static class Builder {
|
| 61 | private final BlockFamily family;
|
| 62 |
|
| 63 | public Builder(final Block baseBlock) {
|
| 64 | this.family = new BlockFamily(baseBlock);
|
| 65 | }
|
| 66 |
|
| 67 | public BlockFamily getFamily() {
|
| 68 | return this.family;
|
| 69 | }
|
| 70 |
|
| 71 | public BlockFamily.Builder button(final Block button) {
|
| 72 | this.family.variants.put(BlockFamily.Variant.BUTTON, button);
|
| 73 | return this;
|
| 74 | }
|
| 75 |
|
| 76 | public BlockFamily.Builder carpet(final Block carpet) {
|
| 77 | this.family.variants.put(BlockFamily.Variant.CARPET, carpet);
|
| 78 | return this;
|
| 79 | }
|
| 80 |
|
| 81 | public BlockFamily.Builder chiseled(final Block chiseled) {
|
| 82 | this.family.variants.put(BlockFamily.Variant.CHISELED, chiseled);
|
| 83 | return this;
|
| 84 | }
|
| 85 |
|
| 86 | public BlockFamily.Builder mosaic(final Block mosaic) {
|
| 87 | this.family.variants.put(BlockFamily.Variant.MOSAIC, mosaic);
|
| 88 | return this;
|
| 89 | }
|
| 90 |
|
| 91 | public BlockFamily.Builder cracked(final Block cracked) {
|
| 92 | this.family.variants.put(BlockFamily.Variant.CRACKED, cracked);
|
| 93 | return this;
|
| 94 | }
|
| 95 |
|
| 96 | public BlockFamily.Builder tiles(final Block tiles) {
|
| 97 | this.family.variants.put(BlockFamily.Variant.TILES, tiles);
|
| 98 | return this;
|
| 99 | }
|
| 100 |
|
| 101 | public BlockFamily.Builder pillar(final Block pillar) {
|
| 102 | this.family.variants.put(BlockFamily.Variant.PILLAR, pillar);
|
| 103 | return this;
|
| 104 | }
|
| 105 |
|
| 106 | public BlockFamily.Builder cut(final Block cut) {
|
| 107 | this.family.variants.put(BlockFamily.Variant.CUT, cut);
|
| 108 | return this;
|
| 109 | }
|
| 110 |
|
| 111 | public BlockFamily.Builder door(final Block door) {
|
| 112 | this.family.variants.put(BlockFamily.Variant.DOOR, door);
|
| 113 | return this;
|
| 114 | }
|
| 115 |
|
| 116 | public BlockFamily.Builder customFence(final Block fence) {
|
| 117 | this.family.variants.put(BlockFamily.Variant.CUSTOM_FENCE, fence);
|
| 118 | return this;
|
| 119 | }
|
| 120 |
|
| 121 | public BlockFamily.Builder fence(final Block fence) {
|
| 122 | this.family.variants.put(BlockFamily.Variant.FENCE, fence);
|
| 123 | return this;
|
| 124 | }
|
| 125 |
|
| 126 | public BlockFamily.Builder customFenceGate(final Block fenceGate) {
|
| 127 | this.family.variants.put(BlockFamily.Variant.CUSTOM_FENCE_GATE, fenceGate);
|
| 128 | return this;
|
| 129 | }
|
| 130 |
|
| 131 | public BlockFamily.Builder fenceGate(final Block fenceGate) {
|
| 132 | this.family.variants.put(BlockFamily.Variant.FENCE_GATE, fenceGate);
|
| 133 | return this;
|
| 134 | }
|
| 135 |
|
| 136 | public BlockFamily.Builder sign(final Block sign, final Block wallSign) {
|
| 137 | this.family.variants.put(BlockFamily.Variant.SIGN, sign);
|
| 138 | this.family.variants.put(BlockFamily.Variant.WALL_SIGN, wallSign);
|
| 139 | return this;
|
| 140 | }
|
| 141 |
|
| 142 | public BlockFamily.Builder customHangingSign(final Block sign, final Block wallSign) {
|
| 143 | this.family.variants.put(BlockFamily.Variant.CUSTOM_HANGING_SIGN, sign);
|
| 144 | this.family.variants.put(BlockFamily.Variant.CUSTOM_WALL_HANGING_SIGN, wallSign);
|
| 145 | return this;
|
| 146 | }
|
| 147 |
|
| 148 | public BlockFamily.Builder hangingSign(final Block sign, final Block wallSign) {
|
| 149 | this.family.variants.put(BlockFamily.Variant.HANGING_SIGN, sign);
|
| 150 | this.family.variants.put(BlockFamily.Variant.WALL_HANGING_SIGN, wallSign);
|
| 151 | return this;
|
| 152 | }
|
| 153 |
|
| 154 | public BlockFamily.Builder log(final Block log) {
|
| 155 | this.family.variants.put(BlockFamily.Variant.LOG, log);
|
| 156 | return this;
|
| 157 | }
|
| 158 |
|
| 159 | public BlockFamily.Builder strippedLog(final Block strippedLog) {
|
| 160 | this.family.variants.put(BlockFamily.Variant.STRIPPED_LOG, strippedLog);
|
| 161 | return this;
|
| 162 | }
|
| 163 |
|
| 164 | public BlockFamily.Builder slab(final Block slab) {
|
| 165 | this.family.variants.put(BlockFamily.Variant.SLAB, slab);
|
| 166 | return this;
|
| 167 | }
|
| 168 |
|
| 169 | public BlockFamily.Builder stairs(final Block stairs) {
|
| 170 | this.family.variants.put(BlockFamily.Variant.STAIRS, stairs);
|
| 171 | return this;
|
| 172 | }
|
| 173 |
|
| 174 | public BlockFamily.Builder pressurePlate(final Block pressurePlate) {
|
| 175 | this.family.variants.put(BlockFamily.Variant.PRESSURE_PLATE, pressurePlate);
|
| 176 | return this;
|
| 177 | }
|
| 178 |
|
| 179 | public BlockFamily.Builder polished(final Block polished) {
|
| 180 | this.family.variants.put(BlockFamily.Variant.POLISHED, polished);
|
| 181 | return this;
|
| 182 | }
|
| 183 |
|
| 184 | public BlockFamily.Builder trapdoor(final Block trapdoor) {
|
| 185 | this.family.variants.put(BlockFamily.Variant.TRAPDOOR, trapdoor);
|
| 186 | return this;
|
| 187 | }
|
| 188 |
|
| 189 | public BlockFamily.Builder wall(final Block wall) {
|
| 190 | this.family.variants.put(BlockFamily.Variant.WALL, wall);
|
| 191 | return this;
|
| 192 | }
|
| 193 |
|
| 194 | public BlockFamily.Builder cobbled(final Block cobble) {
|
| 195 | this.family.variants.put(BlockFamily.Variant.COBBLED, cobble);
|
| 196 | return this;
|
| 197 | }
|
| 198 |
|
| 199 | public BlockFamily.Builder bricks(final Block bricks) {
|
| 200 | this.family.variants.put(BlockFamily.Variant.BRICKS, bricks);
|
| 201 | return this;
|
| 202 | }
|
| 203 |
|
| 204 | public BlockFamily.Builder dontGenerateModel() {
|
| 205 | this.family.generateModel = false;
|
| 206 | return this;
|
| 207 | }
|
| 208 |
|
| 209 | public BlockFamily.Builder dontGenerateCraftingRecipe() {
|
| 210 | this.family.generateCraftingRecipe = false;
|
| 211 | return this;
|
| 212 | }
|
| 213 |
|
| 214 | public BlockFamily.Builder dontGenerateSmeltingRecipe() {
|
| 215 | this.family.generateSmeltingRecipe = false;
|
| 216 | return this;
|
| 217 | }
|
| 218 |
|
| 219 | public BlockFamily.Builder generateStonecutterRecipe() {
|
| 220 | this.family.generateStonecutterRecipe = true;
|
| 221 | return this;
|
| 222 | }
|
| 223 |
|
| 224 | public BlockFamily.Builder recipeGroupPrefix(final String recipeGroupPrefix) {
|
| 225 | this.family.recipeGroupPrefix = recipeGroupPrefix;
|
| 226 | return this;
|
| 227 | }
|
| 228 |
|
| 229 | public BlockFamily.Builder recipeUnlockedBy(final String recipeUnlockedBy) {
|
| 230 | this.family.recipeUnlockedBy = recipeUnlockedBy;
|
| 231 | return this;
|
| 232 | }
|
| 233 | }
|
| 234 |
|
| 235 | public enum Variant {
|
| 236 | BUTTON("button"),
|
| 237 | CARPET("carpet"),
|
| 238 | CHISELED("chiseled") {
|
| 239 | @Override
|
| 240 | public BlockFamily.Variant getBaseVariantForCrafting() {
|
| 241 | return SLAB;
|
| 242 | }
|
| 243 | },
|
| 244 | CRACKED("cracked"),
|
| 245 | CUT("cut") {
|
| 246 | @Override
|
| 247 | public String getPrefixedRecipeGroup(final String prefix) {
|
| 248 | return prefix;
|
| 249 | }
|
| 250 | },
|
| 251 | DOOR("door"),
|
| 252 | CUSTOM_FENCE("fence"),
|
| 253 | FENCE("fence"),
|
| 254 | CUSTOM_FENCE_GATE("fence_gate"),
|
| 255 | FENCE_GATE("fence_gate"),
|
| 256 | CUSTOM_HANGING_SIGN("hanging_sign") {
|
| 257 | @Override
|
| 258 | public BlockFamily.Variant getBaseVariantForCrafting() {
|
| 259 | return STRIPPED_LOG;
|
| 260 | }
|
| 261 | },
|
| 262 | HANGING_SIGN("hanging_sign") {
|
| 263 | @Override
|
| 264 | public BlockFamily.Variant getBaseVariantForCrafting() {
|
| 265 | return STRIPPED_LOG;
|
| 266 | }
|
| 267 | },
|
| 268 | LOG("log"),
|
| 269 | STRIPPED_LOG("stripped_log"),
|
| 270 | MOSAIC("mosaic"),
|
| 271 | SIGN("sign"),
|
| 272 | SLAB("slab"),
|
| 273 | STAIRS("stairs"),
|
| 274 | PRESSURE_PLATE("pressure_plate"),
|
| 275 | POLISHED("polished"),
|
| 276 | TRAPDOOR("trapdoor"),
|
| 277 | WALL("wall"),
|
| 278 | WALL_SIGN("wall_sign"),
|
| 279 | CUSTOM_WALL_HANGING_SIGN("wall_hanging_sign"),
|
| 280 | WALL_HANGING_SIGN("wall_hanging_sign"),
|
| 281 | BRICKS("bricks"),
|
| 282 | COBBLED("cobbled"),
|
| 283 | TILES("tiles"),
|
| 284 | PILLAR("pillar");
|
| 285 |
|
| 286 | private final String recipeGroup;
|
| 287 |
|
| 288 | Variant(final String recipeGroup) {
|
| 289 | this.recipeGroup = recipeGroup;
|
| 290 | }
|
| 291 |
|
| 292 | public String getRecipeGroup() {
|
| 293 | return this.recipeGroup;
|
| 294 | }
|
| 295 |
|
| 296 | public String getPrefixedRecipeGroup(final String prefix) {
|
| 297 | return prefix + "_" + this.getRecipeGroup();
|
| 298 | }
|
| 299 |
|
| 300 | public BlockFamily.@Nullable Variant getBaseVariantForCrafting() {
|
| 301 | return null;
|
| 302 | }
|
| 303 | }
|
| 304 | }
|
| 305 |
|