-
Notifications
You must be signed in to change notification settings - Fork 290
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
104 additions
and
0 deletions.
There are no files selected for viewing
104 changes: 104 additions & 0 deletions
104
src/main/java/org/violetmoon/zeta/util/WoodFamilyManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
package org.violetmoon.zeta.util; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collection; | ||
import java.util.HashMap; | ||
import java.util.HashSet; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
import net.minecraft.world.item.Item; | ||
import net.minecraft.world.level.block.Block; | ||
import net.minecraft.world.level.block.state.properties.WoodType; | ||
import net.minecraft.world.level.material.MaterialColor; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
import org.violetmoon.quark.base.block.QuarkPillarBlock; | ||
import org.violetmoon.zeta.module.ZetaModule; | ||
|
||
//TODO: vanilla block variants? (BlockFamily) | ||
//TODO: generalize beyond wood? (already partly there) | ||
//TODO: integration with the Variant Selector? (kindof a different goal) | ||
public abstract class WoodFamilyManager { | ||
@SuppressWarnings("unused") | ||
public record Variant<T>(String name) { } | ||
|
||
public static final Variant<Block> LOG = new Variant<>("log"); | ||
public static final Variant<Block> WOOD = new Variant<>("wood"); | ||
public static final Variant<Block> PLANKS = new Variant<>("planks"); | ||
public static final Variant<Block> STRIPPED_LOG = new Variant<>("stripped_log"); | ||
public static final Variant<Block> STRIPPED_WOOD = new Variant<>("stripped_wood"); | ||
public static final Variant<Block> SLAB = new Variant<>("slab"); | ||
public static final Variant<Block> STAIRS = new Variant<>("stairs"); | ||
public static final Variant<Block> FENCE = new Variant<>("fence"); | ||
public static final Variant<Block> FENCE_GATE = new Variant<>("fence_gate"); | ||
public static final Variant<Block> DOOR = new Variant<>("door"); | ||
public static final Variant<Block> TRAPDOOR = new Variant<>("trapdoor"); | ||
public static final Variant<Block> BUTTON = new Variant<>("button"); | ||
public static final Variant<Block> PRESSURE_PLATE = new Variant<>("pressure_plate"); | ||
public static final Variant<Block> SIGN = new Variant<>("sign"); | ||
public static final Variant<Block> WALL_SIGN = new Variant<>("wall_sign"); | ||
|
||
public static final Variant<Item> BOAT = new Variant<>("boat"); | ||
public static final Variant<Item> CHEST_BOAT = new Variant<>("chest_boat"); | ||
|
||
public static final Variant<WoodType> WOOD_TYPE = new Variant<>("wood_type"); | ||
|
||
private final Map<Object, WoodFamily> families = new HashMap<>(); | ||
|
||
//non-static | ||
public class WoodFamily { | ||
private final Map<Variant<?>, Object> variants = new HashMap<>(); | ||
private final WoodType root; | ||
|
||
public WoodFamily(WoodType root) { | ||
this.root = root; | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
public <T> @Nullable T get(Variant<T> key) { | ||
return (T) variants.get(key); | ||
} | ||
|
||
private <T> void put(Variant<T> key, @NotNull T value) { | ||
variants.put(key, value); | ||
families.put(value, this); // <- allows getFamily to work | ||
} | ||
|
||
public Collection<Object> entries() { | ||
return variants.values(); | ||
} | ||
} | ||
|
||
/** | ||
* Create a new wood family w/ this at the root. | ||
*/ | ||
public WoodFamily getOrCreateFamily(WoodType root) { | ||
return families.computeIfAbsent(root, __ -> new WoodFamily(root)); | ||
} | ||
|
||
/** | ||
* Given any object in the family, return the rest of the family. | ||
*/ | ||
public @Nullable WoodFamily getFamily(Object member) { | ||
return families.get(member); | ||
} | ||
|
||
/** | ||
* Given any object in the family, return an object of a different variant. | ||
*/ | ||
public <T> @Nullable T get(Object otherMember, Variant<T> variant) { | ||
WoodFamily family = families.get(otherMember); | ||
return family == null ? null : family.get(variant); | ||
} | ||
|
||
//TODO: make into a builder-style api | ||
public void makeWoodFamily(ZetaModule module, String name, MaterialColor color, MaterialColor barkColor, boolean hasLog, boolean hasBoat, boolean flammable) { | ||
WoodType woodType = registerWoodType(module.zeta.registry.newResourceLocation(name).toString()); | ||
WoodFamily family = getOrCreateFamily(woodType); | ||
|
||
//TODO: everything | ||
} | ||
|
||
public abstract WoodType registerWoodType(String name); | ||
} |