Skip to content
Permalink
Browse files

Expose WoodAccess registration to the API

  • Loading branch information
mezz committed Jan 21, 2017
1 parent a13e63c commit cc40bd1cc39e0726dd1ce26b5f29dad72ce5eeb9
@@ -27,4 +27,5 @@

List<IWoodType> getRegisteredWoodTypes();

void register(IWoodType woodType, WoodBlockKind woodBlockKind, boolean fireproof, IBlockState blockState, ItemStack itemStack);
}
@@ -142,7 +142,7 @@ public void setupAPI() {
TreeManager.treeFactory = new TreeFactory();
TreeManager.treeMutationFactory = new TreeMutationFactory();

TreeManager.woodAccess = new WoodAccess();
TreeManager.woodAccess = WoodAccess.getInstance();

// Init tree interface
TreeManager.treeRoot = new TreeRoot();
@@ -161,7 +161,7 @@ public void setupAPI() {

@Override
public void disabledSetupAPI() {
TreeManager.woodAccess = new WoodAccess();
TreeManager.woodAccess = WoodAccess.getInstance();

// Capabilities
CapabilityManager.INSTANCE.register(IArmorNaturalist.class, new NullStorage<>(), () -> ArmorNaturalist.INSTANCE);
@@ -181,27 +181,29 @@ public void preInit() {

BlockRegistryArboriculture blocks = getBlocks();

WoodAccess.registerLogs(blocks.logs);
WoodAccess.registerPlanks(blocks.planks);
WoodAccess.registerSlabs(blocks.slabs);
WoodAccess.registerFences(blocks.fences);
WoodAccess.registerFenceGates(blocks.fenceGates);
WoodAccess.registerStairs(blocks.stairs);
WoodAccess.registerDoors(blocks.doors);

WoodAccess.registerLogs(blocks.logsFireproof);
WoodAccess.registerPlanks(blocks.planksFireproof);
WoodAccess.registerSlabs(blocks.slabsFireproof);
WoodAccess.registerFences(blocks.fencesFireproof);
WoodAccess.registerFenceGates(blocks.fenceGatesFireproof);
WoodAccess.registerStairs(blocks.stairsFireproof);

WoodAccess.registerLogs(blocks.logsVanillaFireproof);
WoodAccess.registerPlanks(blocks.planksVanillaFireproof);
WoodAccess.registerSlabs(blocks.slabsVanillaFireproof);
WoodAccess.registerFences(blocks.fencesVanillaFireproof);
WoodAccess.registerFenceGates(blocks.fenceGatesVanillaFireproof);
WoodAccess.registerStairs(blocks.stairsVanillaFireproof);
WoodAccess woodAccess = WoodAccess.getInstance();

woodAccess.registerLogs(blocks.logs);
woodAccess.registerPlanks(blocks.planks);
woodAccess.registerSlabs(blocks.slabs);
woodAccess.registerFences(blocks.fences);
woodAccess.registerFenceGates(blocks.fenceGates);
woodAccess.registerStairs(blocks.stairs);
woodAccess.registerDoors(blocks.doors);

woodAccess.registerLogs(blocks.logsFireproof);
woodAccess.registerPlanks(blocks.planksFireproof);
woodAccess.registerSlabs(blocks.slabsFireproof);
woodAccess.registerFences(blocks.fencesFireproof);
woodAccess.registerFenceGates(blocks.fenceGatesFireproof);
woodAccess.registerStairs(blocks.stairsFireproof);

woodAccess.registerLogs(blocks.logsVanillaFireproof);
woodAccess.registerPlanks(blocks.planksVanillaFireproof);
woodAccess.registerSlabs(blocks.slabsVanillaFireproof);
woodAccess.registerFences(blocks.fencesVanillaFireproof);
woodAccess.registerFenceGates(blocks.fenceGatesVanillaFireproof);
woodAccess.registerStairs(blocks.stairsVanillaFireproof);

// Init rendering
proxy.initializeModels();
@@ -10,6 +10,7 @@
******************************************************************************/
package forestry.arboriculture;

import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.EnumMap;
@@ -41,87 +42,73 @@
import net.minecraft.item.ItemStack;

public class WoodAccess implements IWoodAccess {
private static final Map<WoodBlockKind, WoodMap> woodMaps = new EnumMap<>(WoodBlockKind.class);
private static final List<IWoodType> registeredWoodTypes = new ArrayList<>();
@Nullable
private static WoodAccess INSTANCE;

static {
for (WoodBlockKind woodBlockKind : WoodBlockKind.values()) {
woodMaps.put(woodBlockKind, new WoodMap(woodBlockKind));
public static WoodAccess getInstance() {
if (INSTANCE == null) {
INSTANCE = new WoodAccess();
}
registerVanilla();
return INSTANCE;
}

private static class WoodMap {
private final Map<IWoodType, ItemStack> normalItems = new HashMap<>();
private final Map<IWoodType, ItemStack> fireproofItems = new HashMap<>();
private final Map<IWoodType, IBlockState> normalBlocks = new HashMap<>();
private final Map<IWoodType, IBlockState> fireproofBlocks = new HashMap<>();
private final WoodBlockKind woodBlockKind;

public WoodMap(WoodBlockKind woodBlockKind) {
this.woodBlockKind = woodBlockKind;
}

public String getName() {
return woodBlockKind.name();
}
private final Map<WoodBlockKind, WoodMap> woodMaps = new EnumMap<>(WoodBlockKind.class);
private final List<IWoodType> registeredWoodTypes = new ArrayList<>();

public Map<IWoodType, ItemStack> getItem(boolean fireproof) {
return fireproof ? this.fireproofItems : this.normalItems;
}

public Map<IWoodType, IBlockState> getBlock(boolean fireproof) {
return fireproof ? this.fireproofBlocks : this.normalBlocks;
private WoodAccess() {
for (WoodBlockKind woodBlockKind : WoodBlockKind.values()) {
woodMaps.put(woodBlockKind, new WoodMap(woodBlockKind));
}
registerVanilla();
}

public static void registerLogs(List<? extends BlockForestryLog> blocks) {
public void registerLogs(List<? extends BlockForestryLog> blocks) {
for (BlockForestryLog block : blocks) {
//noinspection unchecked
registerWithVariants(block, WoodBlockKind.LOG, block.getVariant());
}
}

public static void registerPlanks(List<? extends BlockForestryPlanks> blocks) {
public void registerPlanks(List<? extends BlockForestryPlanks> blocks) {
for (BlockForestryPlanks block : blocks) {
//noinspection unchecked
registerWithVariants(block, WoodBlockKind.PLANKS, block.getVariant());
}
}

public static void registerSlabs(List<? extends BlockForestrySlab> blocks) {
public void registerSlabs(List<? extends BlockForestrySlab> blocks) {
for (BlockForestrySlab block : blocks) {
//noinspection unchecked
registerWithVariants(block, WoodBlockKind.SLAB, block.getVariant());
}
}

public static void registerFences(List<? extends BlockForestryFence> blocks) {
public void registerFences(List<? extends BlockForestryFence> blocks) {
for (BlockForestryFence block : blocks) {
//noinspection unchecked
registerWithVariants(block, WoodBlockKind.FENCE, block.getVariant());
}
}

public static void registerFenceGates(List<BlockForestryFenceGate> blocks) {
public void registerFenceGates(List<BlockForestryFenceGate> blocks) {
for (BlockForestryFenceGate block : blocks) {
registerWithoutVariants(block, WoodBlockKind.FENCE_GATE);
}
}

public static void registerStairs(List<? extends BlockForestryStairs> blocks) {
public void registerStairs(List<? extends BlockForestryStairs> blocks) {
for (BlockForestryStairs block : blocks) {
registerWithoutVariants(block, WoodBlockKind.STAIRS);
}
}

public static void registerDoors(List<BlockArbDoor> blocks) {
public void registerDoors(List<BlockArbDoor> blocks) {
for (BlockArbDoor block : blocks) {
registerWithoutVariants(block, WoodBlockKind.DOOR);
}
}

private static void registerVanilla() {
private void registerVanilla() {
IBlockState defaultLogState = Blocks.LOG.getDefaultState();
List<EnumVanillaWoodType> oldLogTypes = Arrays.asList(EnumVanillaWoodType.OAK, EnumVanillaWoodType.SPRUCE, EnumVanillaWoodType.BIRCH, EnumVanillaWoodType.JUNGLE);
for (EnumVanillaWoodType woodType : oldLogTypes) {
@@ -183,7 +170,7 @@ private static void registerVanilla() {
register(EnumVanillaWoodType.DARK_OAK, WoodBlockKind.DOOR, false, Blocks.DARK_OAK_DOOR.getDefaultState(), new ItemStack(Items.DARK_OAK_DOOR));
}

private static <T extends Block & IWoodTyped, V extends Enum<V> & IWoodType> void registerWithVariants(T woodTyped, WoodBlockKind woodBlockKind, PropertyWoodType<V> property) {
private <T extends Block & IWoodTyped, V extends Enum<V> & IWoodType> void registerWithVariants(T woodTyped, WoodBlockKind woodBlockKind, PropertyWoodType<V> property) {
boolean fireproof = woodTyped.isFireproof();

for (V value : property.getAllowedValues()) {
@@ -201,7 +188,7 @@ private static void registerVanilla() {
/**
* Register wood blocks that have no variant property
*/
private static <T extends Block & IWoodTyped> void registerWithoutVariants(T woodTyped, WoodBlockKind woodBlockKind) {
private <T extends Block & IWoodTyped> void registerWithoutVariants(T woodTyped, WoodBlockKind woodBlockKind) {
boolean fireproof = woodTyped.isFireproof();
IBlockState blockState = woodTyped.getDefaultState();
IWoodType woodType = woodTyped.getWoodType(0);
@@ -212,7 +199,8 @@ private static void registerVanilla() {
register(woodType, woodBlockKind, fireproof, blockState, itemStack);
}

private static void register(IWoodType woodType, WoodBlockKind woodBlockKind, boolean fireproof, IBlockState blockState, ItemStack itemStack) {
@Override
public void register(IWoodType woodType, WoodBlockKind woodBlockKind, boolean fireproof, IBlockState blockState, ItemStack itemStack) {
if (woodBlockKind == WoodBlockKind.DOOR) {
fireproof = true;
}
@@ -257,4 +245,28 @@ public IBlockState getBlock(IWoodType woodType, WoodBlockKind woodBlockKind, boo
public List<IWoodType> getRegisteredWoodTypes() {
return registeredWoodTypes;
}

private static class WoodMap {
private final Map<IWoodType, ItemStack> normalItems = new HashMap<>();
private final Map<IWoodType, ItemStack> fireproofItems = new HashMap<>();
private final Map<IWoodType, IBlockState> normalBlocks = new HashMap<>();
private final Map<IWoodType, IBlockState> fireproofBlocks = new HashMap<>();
private final WoodBlockKind woodBlockKind;

public WoodMap(WoodBlockKind woodBlockKind) {
this.woodBlockKind = woodBlockKind;
}

public String getName() {
return woodBlockKind.name();
}

public Map<IWoodType, ItemStack> getItem(boolean fireproof) {
return fireproof ? this.fireproofItems : this.normalItems;
}

public Map<IWoodType, IBlockState> getBlock(boolean fireproof) {
return fireproof ? this.fireproofBlocks : this.normalBlocks;
}
}
}

0 comments on commit cc40bd1

Please sign in to comment.
You can’t perform that action at this time.