Skip to content

Commit

Permalink
Wood family manager - Just an idea
Browse files Browse the repository at this point in the history
  • Loading branch information
quat1024 committed Nov 11, 2023
1 parent a5223e1 commit 382676c
Showing 1 changed file with 104 additions and 0 deletions.
104 changes: 104 additions & 0 deletions src/main/java/org/violetmoon/zeta/util/WoodFamilyManager.java
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);
}

0 comments on commit 382676c

Please sign in to comment.