aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/com/github/bartimaeusnek/bartworks/API/BorosilicateGlass.java141
-rw-r--r--src/main/java/com/github/bartimaeusnek/bartworks/common/tileentities/multis/GT_TileEntity_ElectricImplosionCompressor.java25
-rw-r--r--src/main/java/com/github/bartimaeusnek/bartworks/common/tileentities/multis/mega/GT_TileEntity_MegaMultiBlockBase.java23
3 files changed, 112 insertions, 77 deletions
diff --git a/src/main/java/com/github/bartimaeusnek/bartworks/API/BorosilicateGlass.java b/src/main/java/com/github/bartimaeusnek/bartworks/API/BorosilicateGlass.java
index 1e5946b78d..35b6bb8f82 100644
--- a/src/main/java/com/github/bartimaeusnek/bartworks/API/BorosilicateGlass.java
+++ b/src/main/java/com/github/bartimaeusnek/bartworks/API/BorosilicateGlass.java
@@ -2,12 +2,17 @@ package com.github.bartimaeusnek.bartworks.API;
import static com.gtnewhorizon.structurelib.structure.StructureUtility.*;
-import com.github.bartimaeusnek.bartworks.common.blocks.BW_GlasBlocks;
-import com.github.bartimaeusnek.bartworks.common.blocks.BW_GlasBlocks2;
+import com.google.common.collect.HashBasedTable;
+import com.google.common.collect.LinkedHashMultimap;
+import com.google.common.collect.SetMultimap;
+import com.google.common.collect.Table;
import com.gtnewhorizon.structurelib.structure.IStructureElement;
+import cpw.mods.fml.common.Loader;
+import cpw.mods.fml.common.LoaderState;
import cpw.mods.fml.common.registry.GameRegistry;
import java.util.ArrayList;
import java.util.List;
+import java.util.PriorityQueue;
import java.util.function.BiConsumer;
import java.util.function.Function;
import java.util.stream.Collectors;
@@ -20,40 +25,66 @@ import org.apache.commons.lang3.tuple.Pair;
* You might have noticed this API does not expose any Block instance, but only IStructureElements. This is in case we
* add more glass blocks later, and we run out of meta id for only one block.
* <p>
- * IStructureElements returned from this class should not have its methods called before the game start.
+ * IStructureElements returned from this class <b>SHOULD NOT</b> have its methods called before post init, or else
+ * you might end up with wrong autoplace hints.
*/
public class BorosilicateGlass {
- private static Block block;
+ private static Block block, block2;
private static List<Pair<Block, Integer>> representatives;
+ private static SetMultimap<Byte, Pair<Block, Integer>> allLevels;
+ private static final Table<Block, Integer, Byte> allLevelsReverse = HashBasedTable.create();
+
+ private static boolean isValidTier(int tier) {
+ return tier > 0 && tier <= Byte.MAX_VALUE;
+ }
private static Block getGlassBlock() {
- if (block == null || !(block instanceof BW_GlasBlocks))
- block = GameRegistry.findBlock("bartworks", "BW_GlasBlocks");
+ if (block == null) block = GameRegistry.findBlock("bartworks", "BW_GlasBlocks");
return block;
}
private static Block getGlassBlock2() {
- if (block == null || !(block instanceof BW_GlasBlocks2))
- block = GameRegistry.findBlock("bartworks", "BW_GlasBlocks2");
- return block;
+ if (block2 == null) block2 = GameRegistry.findBlock("bartworks", "BW_GlasBlocks2");
+ return block2;
+ }
+
+ private static void doRegister(
+ byte level, Block block, int meta, SetMultimap<Byte, Pair<Block, Integer>> allLevels) {
+ allLevels.put(level, Pair.of(block, meta));
+ allLevelsReverse.put(block, meta, level);
+ }
+
+ private static SetMultimap<Byte, Pair<Block, Integer>> getAllLevels() {
+ if (allLevels == null) {
+ SetMultimap<Byte, Pair<Block, Integer>> ret = LinkedHashMultimap.create();
+ Block block = getGlassBlock();
+ doRegister((byte) 3, block, 0, ret);
+ doRegister((byte) 4, block, 1, ret);
+ doRegister((byte) 5, block, 2, ret);
+ doRegister((byte) 6, block, 3, ret);
+ doRegister((byte) 7, block, 4, ret);
+ doRegister((byte) 8, block, 5, ret);
+ for (int i = 6; i < 13; i++) {
+ doRegister((byte) 3, block, i, ret);
+ }
+ doRegister((byte) 9, block, 13, ret);
+ doRegister((byte) 10, block, 14, ret);
+ doRegister((byte) 11, block, 15, ret);
+ block = getGlassBlock2();
+ doRegister((byte) 12, block, 0, ret);
+ allLevels = ret;
+ }
+ return allLevels;
}
private static List<Pair<Block, Integer>> getRepresentatives() {
if (representatives == null) {
+ SetMultimap<Byte, Pair<Block, Integer>> allLevels = getAllLevels();
ArrayList<Pair<Block, Integer>> ret = new ArrayList<>();
- Block block = getGlassBlock();
- ret.add(Pair.of(block, 0));
- ret.add(Pair.of(block, 1));
- ret.add(Pair.of(block, 2));
- ret.add(Pair.of(block, 3));
- ret.add(Pair.of(block, 4));
- ret.add(Pair.of(block, 5));
- ret.add(Pair.of(block, 13));
- ret.add(Pair.of(block, 14));
- ret.add(Pair.of(block, 15));
- block = getGlassBlock2();
- ret.add(Pair.of(block, 0));
+ for (Byte level : new PriorityQueue<>(allLevels.keySet())) {
+ ret.add(allLevels.get(level).iterator().next());
+ }
representatives = ret;
}
return representatives;
@@ -64,14 +95,31 @@ public class BorosilicateGlass {
}
/**
+ * Register a new block as valid borosilicate glass with given tier (even if it doesn't contain boron at all)
+ *
+ * Does not support matching by more complex stuff like tile entity!
+ *
+ * Can only be called at INIT stage.
+ */
+ public static void registerGlass(Block block, int meta, byte tier) {
+ if (Loader.instance().hasReachedState(LoaderState.POSTINITIALIZATION))
+ throw new IllegalStateException("register too late!");
+ if (!Loader.instance().hasReachedState(LoaderState.INITIALIZATION))
+ throw new IllegalStateException("register too early!");
+ if (!isValidTier(tier)) throw new IllegalArgumentException("not a valid tier: " + tier);
+ doRegister(tier, block, meta, getAllLevels());
+ }
+
+ /**
* Check if there is at least one type of boroglass in that tier.
*/
public static boolean hasGlassInTier(int tier) {
- return tier >= 3 && tier <= 12;
+ return getAllLevels().containsKey((byte) tier);
}
/**
* Get a structure element for a certain tier of <b>borosilicate</b> glass. DOES NOT accept other glass like reinforced glass, magic mirror, vanilla glass, etc.
+ * unless these glass are explicitly registered as a borosilicate glass.
* <p>
* Use this if you just want boroglass here and doesn't care what tier it is.
*/
@@ -85,6 +133,7 @@ public class BorosilicateGlass {
/**
* Get a structure element for any kind of <b>borosilicate</b> glass. DOES NOT accept other glass like reinforced glass, magic mirror, vanilla glass, etc.
+ * unless these glass are explicitly registered as a borosilicate glass.
* <p>
* Use this if you just want boroglass here and doesn't care what tier it is.
*/
@@ -94,6 +143,7 @@ public class BorosilicateGlass {
/**
* Get a structure element for <b>borosilicate</b> glass. DOES NOT accept other glass like reinforced glass, magic mirror, vanilla glass, etc.
+ * unless these glass are explicitly registered as a borosilicate glass.
* <p>
* This assumes you want all glass used to be of the same tier.
* <p>
@@ -109,6 +159,7 @@ public class BorosilicateGlass {
/**
* Get a structure element for <b>borosilicate</b> glass. DOES NOT accept other glass like reinforced glass, magic mirror, vanilla glass, etc.
+ * unless these glass are explicitly registered as a borosilicate glass.
*
* @param initialValue the value set before structure check started
* @param minTier minimal accepted tier. inclusive. must be greater than 0.
@@ -130,48 +181,12 @@ public class BorosilicateGlass {
/**
* Get the tier of this <b>borosilicate</b> glass. DOES NOT consider other glass like reinforced glass, magic mirror, vanilla glass, etc.
+ * unless these glass are explicitly registered as a borosilicate glass.
+ *
+ * @return glass tier, or -1 if is not a borosilicate glass
*/
public static byte getTier(Block block, int meta) {
- byte ret;
- if (block instanceof BW_GlasBlocks2) meta += 16;
- switch (meta) {
- case 1:
- ret = 4;
- break;
- case 2:
- case 12:
- ret = 5;
- break;
- case 3:
- ret = 6;
- break;
- case 4:
- ret = 7;
- break;
- case 5:
- ret = 8;
- break;
- case 13:
- ret = 9;
- break;
- case 14:
- ret = 10;
- break;
- case 15:
- ret = 11;
- break;
- case 16:
- ret = 12;
- break;
- default:
- ret = 3;
- }
- if (block instanceof BW_GlasBlocks) {
- return block == getGlassBlock() ? ret : -1;
- }
- if (block instanceof BW_GlasBlocks2) {
- return block == getGlassBlock2() ? ret : -1;
- }
- return -1;
+ Byte ret = allLevelsReverse.get(block, meta);
+ return ret == null ? -1 : ret;
}
}
diff --git a/src/main/java/com/github/bartimaeusnek/bartworks/common/tileentities/multis/GT_TileEntity_ElectricImplosionCompressor.java b/src/main/java/com/github/bartimaeusnek/bartworks/common/tileentities/multis/GT_TileEntity_ElectricImplosionCompressor.java
index 2f937f1c2d..c643b3c23d 100644
--- a/src/main/java/com/github/bartimaeusnek/bartworks/common/tileentities/multis/GT_TileEntity_ElectricImplosionCompressor.java
+++ b/src/main/java/com/github/bartimaeusnek/bartworks/common/tileentities/multis/GT_TileEntity_ElectricImplosionCompressor.java
@@ -33,6 +33,7 @@ import com.github.bartimaeusnek.bartworks.common.configs.ConfigHandler;
import com.gtnewhorizon.structurelib.StructureLibAPI;
import com.gtnewhorizon.structurelib.alignment.IAlignmentLimits;
import com.gtnewhorizon.structurelib.alignment.enumerable.ExtendedFacing;
+import com.gtnewhorizon.structurelib.structure.AutoPlaceEnvironment;
import com.gtnewhorizon.structurelib.structure.IStructureDefinition;
import com.gtnewhorizon.structurelib.structure.IStructureElement;
import com.gtnewhorizon.structurelib.structure.StructureDefinition;
@@ -151,6 +152,30 @@ public class GT_TileEntity_ElectricImplosionCompressor
else world.setBlockToAir(x, y, z);
return true;
}
+
+ @Override
+ public BlocksToPlace getBlocksToPlace(
+ GT_TileEntity_ElectricImplosionCompressor t,
+ World world,
+ int x,
+ int y,
+ int z,
+ ItemStack trigger,
+ AutoPlaceEnvironment env) {
+ return BlocksToPlace.createEmpty();
+ }
+
+ @Override
+ public PlaceResult survivalPlaceBlock(
+ GT_TileEntity_ElectricImplosionCompressor t,
+ World world,
+ int x,
+ int y,
+ int z,
+ ItemStack trigger,
+ AutoPlaceEnvironment env) {
+ return isAir().survivalPlaceBlock(t, world, x, y, z, trigger, env);
+ }
})
.build();
diff --git a/src/main/java/com/github/bartimaeusnek/bartworks/common/tileentities/multis/mega/GT_TileEntity_MegaMultiBlockBase.java b/src/main/java/com/github/bartimaeusnek/bartworks/common/tileentities/multis/mega/GT_TileEntity_MegaMultiBlockBase.java
index 7cd9595d00..a985814a2d 100644
--- a/src/main/java/com/github/bartimaeusnek/bartworks/common/tileentities/multis/mega/GT_TileEntity_MegaMultiBlockBase.java
+++ b/src/main/java/com/github/bartimaeusnek/bartworks/common/tileentities/multis/mega/GT_TileEntity_MegaMultiBlockBase.java
@@ -13,7 +13,7 @@ import com.github.bartimaeusnek.crossmod.tectech.tileentites.tiered.LowPowerLase
import com.github.technus.tectech.thing.metaTileEntity.hatch.GT_MetaTileEntity_Hatch_EnergyMulti;
import com.google.common.collect.ImmutableList;
import com.gtnewhorizon.structurelib.StructureLibAPI;
-import com.gtnewhorizon.structurelib.structure.IItemSource;
+import com.gtnewhorizon.structurelib.structure.AutoPlaceEnvironment;
import com.gtnewhorizon.structurelib.structure.IStructureElement;
import cpw.mods.fml.common.Optional;
import gregtech.api.interfaces.IHatchElement;
@@ -25,13 +25,10 @@ import gregtech.api.util.IGT_HatchAdder;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
-import java.util.function.Consumer;
-import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumChatFormatting;
-import net.minecraft.util.IChatComponent;
import net.minecraft.util.StatCollector;
import net.minecraft.world.World;
@@ -373,18 +370,16 @@ public abstract class GT_TileEntity_MegaMultiBlockBase<T extends GT_TileEntity_M
}
@Override
+ public BlocksToPlace getBlocksToPlace(
+ T t, World world, int x, int y, int z, ItemStack trigger, AutoPlaceEnvironment env) {
+ return BlocksToPlace.createEmpty();
+ }
+
+ @Override
public PlaceResult survivalPlaceBlock(
- T o,
- World world,
- int x,
- int y,
- int z,
- ItemStack trigger,
- IItemSource s,
- EntityPlayerMP actor,
- Consumer<IChatComponent> chatter) {
+ T o, World world, int x, int y, int z, ItemStack trigger, AutoPlaceEnvironment env) {
if (check(o, world, x, y, z)) return PlaceResult.SKIP;
- if (!StructureLibAPI.isBlockTriviallyReplaceable(world, x, y, z, actor)) return PlaceResult.REJECT;
+ if (!StructureLibAPI.isBlockTriviallyReplaceable(world, x, y, z, env.getActor())) return PlaceResult.REJECT;
world.setBlock(x, y, z, Blocks.air, 0, 2);
return PlaceResult.ACCEPT;
}