Skip to content

Commit

Permalink
feature: Blocks in configs can handle * declaration
Browse files Browse the repository at this point in the history
Reference #86
  • Loading branch information
ROMVoid95 committed Jul 21, 2023
1 parent 11f4714 commit d7a41a1
Show file tree
Hide file tree
Showing 8 changed files with 358 additions and 158 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
package micdoodle8.mods.galacticraft.core.fluid;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.List;

import net.minecraft.block.Block;
import net.minecraft.block.BlockEnchantmentTable;
Expand All @@ -29,53 +28,56 @@
import net.minecraft.world.World;

import micdoodle8.mods.galacticraft.api.block.IPartialSealableBlock;
import micdoodle8.mods.galacticraft.api.vector.BlockTuple;
import micdoodle8.mods.galacticraft.core.GalacticraftCore;
import micdoodle8.mods.galacticraft.core.tick.TickHandlerServer;
import micdoodle8.mods.galacticraft.core.tile.TileEntityOxygenSealer;
import micdoodle8.mods.galacticraft.core.util.BlockUtil;
import micdoodle8.mods.galacticraft.core.util.BlockUtil.MultiBlockStateHolder;
import micdoodle8.mods.galacticraft.core.util.ConfigManagerCore;
import micdoodle8.mods.galacticraft.core.util.GCCoreUtil;

public class OxygenPressureProtocol
{

public final static Map<Block, ArrayList<Integer>> nonPermeableBlocks = new HashMap<Block, ArrayList<Integer>>();

//public final static Map<Block, ArrayList<Integer>> nonPermeableBlocks = new HashMap<>();
public final static List<MultiBlockStateHolder> newNonPermeableBlockStateList = new ArrayList<>();
public final static List<Block> nonPermeableBlockList = new ArrayList<>();
static
{
for (final String s : ConfigManagerCore.sealableIDs)
{
try
{
BlockTuple bt = ConfigManagerCore.stringToBlock(s, "External Sealable IDs", true);
if (bt == null)
{
continue;
}

int meta = bt.meta;

if (OxygenPressureProtocol.nonPermeableBlocks.containsKey(bt.block))
{
final ArrayList<Integer> list = OxygenPressureProtocol.nonPermeableBlocks.get(bt.block);
if (!list.contains(meta))
{
list.add(meta);
} else
{
GalacticraftCore.logger.info("[config] External Sealable IDs: skipping duplicate entry '" + s + "'.");
}
} else
{
final ArrayList<Integer> list = new ArrayList<Integer>();
list.add(meta);
OxygenPressureProtocol.nonPermeableBlocks.put(bt.block, list);
}
} catch (final Exception e)
{
GalacticraftCore.logger.error("[config] External Sealable IDs: error parsing '" + s + "'. Must be in the form Blockname or BlockName:metadata");
}
}
BlockUtil.getBlockStateHolderList(BlockUtil.getListFromStringArray(ConfigManagerCore.sealableIDs)).forEach(mbsh -> newNonPermeableBlockStateList.add(mbsh));
newNonPermeableBlockStateList.forEach(mbsh -> nonPermeableBlockList.add(mbsh.getBlock()));
// for (final String s : ConfigManagerCore.sealableIDs)
// {
// try
// {
// BlockTuple bt = ConfigManagerCore.stringToBlock(s, "External Sealable IDs", true);
// if (bt == null)
// {
// continue;
// }
//
// int meta = bt.meta;
//
// if (OxygenPressureProtocol.nonPermeableBlocks.containsKey(bt.block))
// {
// final ArrayList<Integer> list = OxygenPressureProtocol.nonPermeableBlocks.get(bt.block);
// if (!list.contains(meta))
// {
// list.add(meta);
// } else
// {
// GalacticraftCore.logger.info("[config] External Sealable IDs: skipping duplicate entry '" + s + "'.");
// }
// } else
// {
// final ArrayList<Integer> list = new ArrayList<>();
// list.add(meta);
// OxygenPressureProtocol.nonPermeableBlocks.put(bt.block, list);
// }
// } catch (final Exception e)
// {
// GalacticraftCore.logger.error("[config] External Sealable IDs: error parsing '" + s + "'. Must be in the form Blockname or BlockName:metadata");
// }
// }
}

public static void updateSealerStatus(TileEntityOxygenSealer head)
Expand Down Expand Up @@ -135,22 +137,32 @@ public static boolean canBlockPassAir(World world, IBlockState state, BlockPos p
return false;
}

// Solid but non-opaque blocks, for example special glass
if (OxygenPressureProtocol.nonPermeableBlocks.containsKey(block))
for (MultiBlockStateHolder mbsh : OxygenPressureProtocol.newNonPermeableBlockStateList)
{
ArrayList<Integer> metaList = OxygenPressureProtocol.nonPermeableBlocks.get(block);
if (metaList.contains(Integer.valueOf(-1)) || metaList.contains(state.getBlock().getMetaFromState(state)))
if (mbsh.getBlock().equals(block))
{
return false;
if (mbsh.getBlockstateList().contains(state))
{
return false;
}
}
}
// Solid but non-opaque blocks, for example special glass
// if (OxygenPressureProtocol.nonPermeableBlocks.containsKey(block))
// {
// ArrayList<Integer> metaList = OxygenPressureProtocol.nonPermeableBlocks.get(block);
// if (metaList.contains(Integer.valueOf(-1)) || metaList.contains(state.getBlock().getMetaFromState(state)))
// {
// return false;
// }
// }

// Half slab seals on the top side or the bottom side according to its
// metadata
if (block instanceof BlockSlab)
{
int meta = state.getBlock().getMetaFromState(state);
return !(side == EnumFacing.DOWN && (meta & 8) == 8 || side == EnumFacing.UP && (meta & 8) == 0);
return (((side != EnumFacing.DOWN) || ((meta & 8) != 8)) && ((side != EnumFacing.UP) || ((meta & 8) != 0)));
}

// Farmland etc only seals on the solid underside
Expand All @@ -161,7 +173,7 @@ public static boolean canBlockPassAir(World world, IBlockState state, BlockPos p

if (block instanceof BlockPistonBase)
{
if (((Boolean) state.getValue(BlockPistonBase.EXTENDED)).booleanValue())
if (state.getValue(BlockPistonBase.EXTENDED))
{
EnumFacing facing = state.getValue(BlockPistonBase.FACING);
return side != facing;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import micdoodle8.mods.galacticraft.core.blocks.BlockUnlitTorch;
import micdoodle8.mods.galacticraft.core.tick.TickHandlerServer;
import micdoodle8.mods.galacticraft.core.tile.TileEntityOxygenSealer;
import micdoodle8.mods.galacticraft.core.util.BlockUtil.MultiBlockStateHolder;
import micdoodle8.mods.galacticraft.core.util.ConfigManagerCore;
import micdoodle8.mods.galacticraft.core.util.GCCoreUtil;
import micdoodle8.mods.galacticraft.core.wrappers.ScheduledBlockChange;
Expand Down Expand Up @@ -80,7 +81,7 @@ public class ThreadFindSeal

public ThreadFindSeal(TileEntityOxygenSealer sealer)
{
this(sealer.getWorld(), sealer.getPos().up(), sealer.getFindSealChecks(), new ArrayList<TileEntityOxygenSealer>(Collections.singletonList(sealer)));
this(sealer.getWorld(), sealer.getPos().up(), sealer.getFindSealChecks(), new ArrayList<>(Collections.singletonList(sealer)));
}

public ThreadFindSeal(World world, BlockPos head, int checkCount, List<TileEntityOxygenSealer> sealers)
Expand All @@ -96,7 +97,7 @@ public ThreadFindSeal(World world, BlockPos head, int checkCount, List<TileEntit
this.foundAmbientThermal = false;
checkedClear();
checkedSize = 0;
this.torchesToUpdate = new LinkedList<BlockVec3>();
this.torchesToUpdate = new LinkedList<>();

this.sealersAround = TileEntityOxygenSealer.getSealersAround(world, head, 1024 * 1024);

Expand Down Expand Up @@ -173,11 +174,11 @@ public void check()
TileEntity tile = this.head.getTileEntityOnSide(world, EnumFacing.DOWN);
this.foundAmbientThermal = tile instanceof TileEntityOxygenSealer && ((TileEntityOxygenSealer) tile).thermalControlEnabled();
this.checkedAdd(this.head);
this.currentLayer = new LinkedList<BlockVec3>();
this.airToReplace = new LinkedList<BlockVec3>();
this.airToReplaceBright = new LinkedList<BlockVec3>();
this.ambientThermalTracked = new LinkedList<BlockVec3>();
this.ambientThermalTrackedBright = new LinkedList<BlockVec3>();
this.currentLayer = new LinkedList<>();
this.airToReplace = new LinkedList<>();
this.airToReplaceBright = new LinkedList<>();
this.ambientThermalTracked = new LinkedList<>();
this.ambientThermalTrackedBright = new LinkedList<>();

if (this.checkCount > 0)
{
Expand Down Expand Up @@ -227,10 +228,10 @@ public void check()
{
int checkedSave = checkedSize;
checkedClear();
this.breatheableToReplace = new LinkedList<BlockVec3>();
this.breatheableToReplaceBright = new LinkedList<BlockVec3>();
this.fireToReplace = new LinkedList<BlockVec3>();
this.otherSealers = new LinkedList<TileEntityOxygenSealer>();
this.breatheableToReplace = new LinkedList<>();
this.breatheableToReplaceBright = new LinkedList<>();
this.fireToReplace = new LinkedList<>();
this.otherSealers = new LinkedList<>();
// unseal() will mark breatheableAir blocks for change as it
// finds them, also searches for unchecked sealers
this.currentLayer.clear();
Expand Down Expand Up @@ -262,7 +263,7 @@ public void check()
BlockVec3 newhead = new BlockVec3(otherSealer).translate(0, 1, 0);
this.sealed = true;
this.checkCount = otherSealer.getFindSealChecks();
this.sealers = new LinkedList<TileEntityOxygenSealer>();
this.sealers = new LinkedList<>();
this.sealers.add(otherSealer);
if (otherSealer.thermalControlEnabled())
{
Expand All @@ -273,7 +274,7 @@ public void check()
this.currentLayer.clear();
this.airToReplace.clear();
this.airToReplaceBright.clear();
this.torchesToUpdate = new LinkedList<BlockVec3>();
this.torchesToUpdate = new LinkedList<>();
this.currentLayer.add(newhead.clone());
if (newhead.x < -29990000 || newhead.z < -29990000 || newhead.x >= 29990000 || newhead.z >= 29990000)
{
Expand Down Expand Up @@ -399,7 +400,7 @@ private void makeSealGood(boolean ambientThermal)
{
if (!this.airToReplace.isEmpty() || !this.airToReplaceBright.isEmpty() || !ambientThermalTracked.isEmpty() || !ambientThermalTracked.isEmpty())
{
List<ScheduledBlockChange> changeList = new LinkedList<ScheduledBlockChange>();
List<ScheduledBlockChange> changeList = new LinkedList<>();
Block breatheableAirID = GCBlocks.breatheableAir;
Block breatheableAirIDBright = GCBlocks.brightBreatheableAir;
int metadata = ambientThermal ? 1 : 0;
Expand Down Expand Up @@ -442,7 +443,7 @@ private void makeSealBad()
{
if (!this.breatheableToReplace.isEmpty() || !this.breatheableToReplaceBright.isEmpty())
{
List<ScheduledBlockChange> changeList = new LinkedList<ScheduledBlockChange>();
List<ScheduledBlockChange> changeList = new LinkedList<>();
for (BlockVec3 checkedVec : this.breatheableToReplace)
{
changeList.add(new ScheduledBlockChange(checkedVec.toBlockPos(), Blocks.AIR.getDefaultState(), 0));
Expand Down Expand Up @@ -555,7 +556,7 @@ private void unseal()

// Set up the next layer as current layer for the while loop
this.currentLayer = nextLayer;
nextLayer = new LinkedList<BlockVec3>();
nextLayer = new LinkedList<>();
}
}

Expand Down Expand Up @@ -660,7 +661,7 @@ private void unsealNearMapEdge()

// Set up the next layer as current layer for the while loop
this.currentLayer = nextLayer;
nextLayer = new LinkedList<BlockVec3>();
nextLayer = new LinkedList<>();
}
}

Expand Down Expand Up @@ -791,7 +792,7 @@ private void doLayer()

// Is there a further layer of air/permeable blocks to test?
this.currentLayer = nextLayer;
nextLayer = new LinkedList<BlockVec3>();
nextLayer = new LinkedList<>();
}
}

Expand Down Expand Up @@ -932,7 +933,7 @@ private void doLayerNearMapEdge()

// Is there a further layer of air/permeable blocks to test?
this.currentLayer = nextLayer;
nextLayer = new LinkedList<BlockVec3>();
nextLayer = new LinkedList<>();
}
}

Expand Down Expand Up @@ -1038,7 +1039,7 @@ private static void checkedClear()

public List<BlockPos> checkedAll()
{
List<BlockPos> list = new LinkedList<BlockPos>();
List<BlockPos> list = new LinkedList<>();
int x = head.x;
int z = head.z;
for (int i = 0; i < 256; i++)
Expand Down Expand Up @@ -1172,17 +1173,29 @@ private boolean canBlockPassAirCheck(Block block, BlockVec3 vec, int side)
return false;
}

// Solid but non-opaque blocks, for example special glass
if (OxygenPressureProtocol.nonPermeableBlocks.containsKey(block))
for (MultiBlockStateHolder mbsh : OxygenPressureProtocol.newNonPermeableBlockStateList)
{
ArrayList<Integer> metaList = OxygenPressureProtocol.nonPermeableBlocks.get(block);
if (metaList.contains(Integer.valueOf(-1)) || metaList.contains(vec.getBlockMetadata(this.world)))
if (mbsh.getBlock().equals(block))
{
checkedAdd(vec);
return false;
if (mbsh.getBlockstateList().contains(state))
{
checkedAdd(vec);
return false;
}
}
}

// Solid but non-opaque blocks, for example special glass
// if (OxygenPressureProtocol.nonPermeableBlocks.containsKey(block))
// {
// ArrayList<Integer> metaList = OxygenPressureProtocol.nonPermeableBlocks.get(block);
// if (metaList.contains(Integer.valueOf(-1)) || metaList.contains(vec.getBlockMetadata(this.world)))
// {
// checkedAdd(vec);
// return false;
// }
// }

if (block instanceof BlockUnlitTorch)
{
this.torchesToUpdate.add(vec);
Expand Down Expand Up @@ -1228,9 +1241,9 @@ private boolean canBlockPassAirCheck(Block block, BlockVec3 vec, int side)
if (block instanceof BlockPistonBase)
{
BlockPistonBase piston = (BlockPistonBase) block;
if (state.getValue(BlockPistonBase.EXTENDED).booleanValue())
if (state.getValue(BlockPistonBase.EXTENDED))
{
int facing = ((EnumFacing) state.getValue(BlockPistonBase.FACING)).getIndex();
int facing = state.getValue(BlockPistonBase.FACING).getIndex();
if (side == facing)
{
this.checkCount--;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
import micdoodle8.mods.galacticraft.core.proxy.ClientProxyCore;
import micdoodle8.mods.galacticraft.core.tile.TileEntityOxygenSealer;
import micdoodle8.mods.galacticraft.core.tile.TileEntityScreen;
import micdoodle8.mods.galacticraft.core.util.BlockUtil;
import micdoodle8.mods.galacticraft.core.util.ColorUtil;
import micdoodle8.mods.galacticraft.core.util.ConfigManagerCore;
import micdoodle8.mods.galacticraft.core.util.GCCoreUtil;
Expand Down Expand Up @@ -168,7 +169,7 @@ public void worldUnloadEvent(WorldEvent.Unload event)
}
}

public static HashSet<TileEntityScreen> screenConnectionsUpdateList = new HashSet<TileEntityScreen>();
public static HashSet<TileEntityScreen> screenConnectionsUpdateList = new HashSet<>();

static
{
Expand All @@ -181,7 +182,8 @@ public static void registerDetectableBlocks(boolean logging)

for (final String s : ConfigManagerCore.detectableIDs)
{
BlockTuple bt = ConfigManagerCore.stringToBlock(s, "External Detectable IDs", logging);
//BlockTuple bt = ConfigManagerCore.stringToBlock(s, "External Detectable IDs", logging);
BlockTuple bt = BlockUtil.getBlockTupleFromString(s);
if (bt == null)
{
continue;
Expand Down Expand Up @@ -297,7 +299,7 @@ public void onRenderTick(RenderTickEvent event)
}

if (player.world.provider instanceof IGalacticraftWorldProvider && OxygenUtil.shouldDisplayTankGui(minecraft.currentScreen) && OxygenUtil.noAtmosphericCombustion(player.world.provider)
&& !(playerBaseClient.isCreative() || playerBaseClient.isSpectator()) && !minecraft.gameSettings.showDebugInfo)
&& (!playerBaseClient.isCreative() && !playerBaseClient.isSpectator()) && !minecraft.gameSettings.showDebugInfo)
{
int var6 = (TickHandlerClient.airRemaining - 90) * -1;

Expand All @@ -319,7 +321,7 @@ public void onRenderTick(RenderTickEvent event)
}

if (playerBaseClient != null && player.world.provider instanceof IGalacticraftWorldProvider && !stats.isOxygenSetupValid() && OxygenUtil.noAtmosphericCombustion(player.world.provider)
&& minecraft.currentScreen == null && !minecraft.gameSettings.hideGUI && !(playerBaseClient.isCreative() || playerBaseClient.isSpectator()))
&& minecraft.currentScreen == null && !minecraft.gameSettings.hideGUI && (!playerBaseClient.isCreative() && !playerBaseClient.isSpectator()))
{
OverlayOxygenWarning.renderOxygenWarningOverlay(minecraft, TickHandlerClient.tickCount);
}
Expand Down Expand Up @@ -378,7 +380,7 @@ public void onClientTick(ClientTickEvent event)

if (map.containsKey(Type.SKIN))
{
ClientProxyCore.playerHead = minecraft.getSkinManager().loadSkin((MinecraftProfileTexture) map.get(Type.SKIN), Type.SKIN);
ClientProxyCore.playerHead = minecraft.getSkinManager().loadSkin(map.get(Type.SKIN), Type.SKIN);
} else
{
ClientProxyCore.playerHead = DefaultPlayerSkin.getDefaultSkin(EntityPlayer.getUUID(player.getGameProfile()));
Expand Down
Loading

0 comments on commit d7a41a1

Please sign in to comment.