diff --git a/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockControllerBase.java b/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockControllerBase.java index e3069d43a9a..fc88d3ce62a 100644 --- a/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockControllerBase.java +++ b/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockControllerBase.java @@ -234,58 +234,69 @@ public static TraceabilityPredicate metaTileEntities(MetaTileEntity... metaTileE ResourceLocation[] ids = Arrays.stream(metaTileEntities).filter(Objects::nonNull) .map(tile -> tile.metaTileEntityId).toArray(ResourceLocation[]::new); return tilePredicate((state, tile) -> ArrayUtils.contains(ids, tile.metaTileEntityId), - getCandidates(metaTileEntities)); + getCandidates(() -> EnumFacing.NORTH, metaTileEntities)); } @SafeVarargs - public static TraceabilityPredicate tieredMTEs(BiPredicate, T> pred, T... metaTileEntities) { + public static < + T extends MetaTileEntity & ITieredMetaTileEntity> TraceabilityPredicate tieredMTEs(BiPredicate, T> pred, + T... metaTileEntities) { ResourceLocation[] ids = Arrays.stream(metaTileEntities).filter(Objects::nonNull) .map(tile -> tile.metaTileEntityId).toArray(ResourceLocation[]::new); return tilePredicate((state, tile) -> ArrayUtils.contains(ids, tile.metaTileEntityId), getCandidates(pred, metaTileEntities)); } - private static Function, BlockInfo[]> getCandidates(MetaTileEntity... metaTileEntities) { + public static Function, BlockInfo[]> getCandidates(Supplier facing, + MetaTileEntity... metaTileEntities) { return map -> Arrays.stream(metaTileEntities).filter(Objects::nonNull).map(tile -> { MetaTileEntityHolder holder = new MetaTileEntityHolder(); holder.setMetaTileEntity(tile); holder.getMetaTileEntity().onPlacement(); - holder.getMetaTileEntity().setFrontFacing(EnumFacing.SOUTH); + holder.getMetaTileEntity().setFrontFacing(facing.get()); return new BlockInfo(tile.getBlock().getDefaultState(), holder); }).toArray(BlockInfo[]::new); } // generic hell @SafeVarargs - public static Function, BlockInfo[]> getCandidates(BiPredicate, T> pred, T... metaTileEntities) { + public static < + T extends MetaTileEntity & ITieredMetaTileEntity> Function, BlockInfo[]> getCandidates(BiPredicate, T> pred, + T... metaTileEntities) { return map -> Arrays.stream(metaTileEntities).filter(Objects::nonNull) - .filter(i -> pred.test(map, i)) - .map(tile -> { - MetaTileEntityHolder holder = new MetaTileEntityHolder(); - holder.setMetaTileEntity(tile); - holder.getMetaTileEntity().onPlacement(); - holder.getMetaTileEntity().setFrontFacing(EnumFacing.SOUTH); - return new BlockInfo(tile.getBlock().getDefaultState(), holder); - }).toArray(BlockInfo[]::new); + .filter(i -> pred.test(map, i)) + .map(tile -> { + MetaTileEntityHolder holder = new MetaTileEntityHolder(); + holder.setMetaTileEntity(tile); + holder.getMetaTileEntity().onPlacement(); + holder.getMetaTileEntity().setFrontFacing(EnumFacing.SOUTH); + return new BlockInfo(tile.getBlock().getDefaultState(), holder); + }).toArray(BlockInfo[]::new); } - private static Function, BlockInfo[]> getCandidates(String key, IBlockState... allowedStates) { + public static Function, BlockInfo[]> getCandidates(String key, IBlockState... allowedStates) { return map -> { if (map.containsKey(key)) { - return new BlockInfo[] { new BlockInfo(allowedStates[MathHelper.clamp(GTUtility.parseInt(map.get(key)), 0, allowedStates.length - 1)]) }; + return new BlockInfo[] { new BlockInfo(allowedStates[MathHelper.clamp(GTUtility.parseInt(map.get(key)), + 0, allowedStates.length - 1)]) }; } return Arrays.stream(allowedStates).map(BlockInfo::new).toArray(BlockInfo[]::new); }; } - public static TraceabilityPredicate abilities(MultiblockAbility... allowedAbilities) { + public static TraceabilityPredicate abilities(Supplier facing, + MultiblockAbility... allowedAbilities) { return tilePredicate((state, tile) -> tile instanceof IMultiblockAbilityPart && ArrayUtils.contains(allowedAbilities, ((IMultiblockAbilityPart) tile).getAbility()), - getCandidates(Arrays.stream(allowedAbilities) + getCandidates(facing, Arrays.stream(allowedAbilities) .flatMap(ability -> MultiblockAbility.REGISTRY.get(ability).stream()) .toArray(MetaTileEntity[]::new))); } + public static TraceabilityPredicate abilities(MultiblockAbility... allowedAbilities) { + return abilities(() -> EnumFacing.NORTH, allowedAbilities); + } + public static TraceabilityPredicate states(IBlockState... allowedStates) { return states(null, allowedStates); } @@ -596,6 +607,7 @@ public void invalidateStructure(String name) { // i am sorry Object[] added = { null }; List dummyList = new ArrayList<>() { + @Override public boolean add(Object e) { added[0] = e; @@ -606,7 +618,7 @@ public boolean add(Object e) { multiblockParts.removeIf(part -> { if (name.equals(part.getSubstructureName())) { if (part instanceof IMultiblockAbilityPart) { - //noinspection unchecked + // noinspection unchecked IMultiblockAbilityPart ability = (IMultiblockAbilityPart) part; added[0] = null; ability.registerAbilities(dummyList); @@ -871,7 +883,8 @@ public void autoBuild(EntityPlayer player, Map map, String subst } /** - * Autobuild the multiblock, this is like {@link MultiblockControllerBase#autoBuild(EntityPlayer, Map, String)} but if + * Autobuild the multiblock, this is like {@link MultiblockControllerBase#autoBuild(EntityPlayer, Map, String)} but + * if * you have the predicate map for other uses. This does mutate the map passed in. */ public void autoBuild(EntityPlayer player, Map map, @@ -898,6 +911,7 @@ public void autoBuild(EntityPlayer player, Map map, MetaTileEntityHolder newHolder = new MetaTileEntityHolder(); newHolder.setMetaTileEntity(holder.getMetaTileEntity()); newHolder.getMetaTileEntity().onPlacement(); + newHolder.getMetaTileEntity().setFrontFacing(holder.getMetaTileEntity().getFrontFacing()); if (removed.hasTagCompound()) newHolder.getMetaTileEntity().initFromItemStackData(removed.getTagCompound()); @@ -931,7 +945,6 @@ public void autoBuild(EntityPlayer player, Map map, }; for (Long2ObjectMap.Entry entry : predicates.long2ObjectEntrySet()) { - // todo add autobuild key params here, also remove layer stuff from rest of the code elsewhere TraceabilityPredicate pred = entry.getValue(); if (simpleIndex.getInt(pred) >= pred.simple.size()) continue; diff --git a/src/main/java/gregtech/api/pattern/TraceabilityPredicate.java b/src/main/java/gregtech/api/pattern/TraceabilityPredicate.java index 0f24c13ff6a..3c390bbc77c 100644 --- a/src/main/java/gregtech/api/pattern/TraceabilityPredicate.java +++ b/src/main/java/gregtech/api/pattern/TraceabilityPredicate.java @@ -1,26 +1,18 @@ package gregtech.api.pattern; -import com.google.common.collect.Iterators; - import gregtech.api.GregTechAPI; -import gregtech.api.metatileentity.MetaTileEntity; -import gregtech.api.metatileentity.interfaces.IGregTechTileEntity; import gregtech.api.metatileentity.multiblock.MultiblockControllerBase; import gregtech.api.util.BlockInfo; - import gregtech.api.util.GTUtility; -import net.minecraft.block.state.IBlockState; import net.minecraft.client.resources.I18n; import net.minecraft.init.Blocks; -import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraftforge.fml.common.FMLCommonHandler; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; import it.unimi.dsi.fastutil.objects.Object2IntMap; -import org.jetbrains.annotations.Nullable; import java.util.*; import java.util.function.Function; @@ -41,12 +33,13 @@ public class TraceabilityPredicate { worldState -> GregTechAPI.HEATING_COILS.containsKey(worldState.getBlockState()) ? null : PatternError.PLACEHOLDER, map -> GregTechAPI.HEATING_COILS.entrySet().stream() - .filter(e -> e.getValue().getTier() == GTUtility.parseInt(map.get("coilTier"), 1)) + .filter(e -> !map.containsKey("coilTier") || + e.getValue().getTier() == GTUtility.parseInt(map.get("coilTier"), 1)) // sort to make autogenerated jei previews not pick random coils each game load .sorted(Comparator.comparingInt(entry -> entry.getValue().getTier())) .map(entry -> new BlockInfo(entry.getKey(), null)) .toArray(BlockInfo[]::new)) - .addTooltips("gregtech.multiblock.pattern.error.coils"); + .addTooltips("gregtech.multiblock.pattern.error.coils"); public final List simple = new ArrayList<>(); protected boolean isCenter; @@ -283,18 +276,19 @@ public PatternError testRaw(BlockWorldState worldState) { public PatternError testLimited(BlockWorldState worldState, Object2IntMap globalCache, Object2IntMap layerCache) { - PatternError error = testGlobal(worldState, globalCache); + PatternError error = testGlobal(worldState, globalCache, layerCache); if (error != null) return error; return testLayer(worldState, layerCache); } - public PatternError testGlobal(BlockWorldState worldState, Object2IntMap cache) { + public PatternError testGlobal(BlockWorldState worldState, Object2IntMap global, + Object2IntMap layer) { PatternError result = predicate.apply(worldState); - if (cache != null && !cache.containsKey(this)) cache.put(this, 0); - if ((minGlobalCount == -1 && maxGlobalCount == -1) || cache == null || result != null) return result; + if (!global.containsKey(this)) global.put(this, 0); + if ((minGlobalCount == -1 && maxGlobalCount == -1) || result != null || layer == null) return result; - int count = cache.put(this, cache.getInt(this) + 1) + 1; + int count = layer.put(this, layer.getInt(this) + 1) + 1 + global.getInt(this); if (maxGlobalCount == -1 || count <= maxGlobalCount) return null; return new SinglePredicateError(this, 0); @@ -303,27 +297,19 @@ public PatternError testGlobal(BlockWorldState worldState, Object2IntMap cache) { PatternError result = predicate.apply(worldState); - if ((minLayerCount == -1 && maxLayerCount == -1) || cache == null || result != null) return result; + if ((minLayerCount == -1 && maxLayerCount == -1) || result != null) return result; - int count = cache.put(this, cache.getInt(this) + 1) + 1; - if (maxLayerCount == -1 || count <= maxLayerCount) return null; + if (maxLayerCount == -1 || cache.getInt(this) <= maxLayerCount) return null; return new SinglePredicateError(this, 2); } public List getCandidates() { - return candidates == null ? Collections.emptyList() : Arrays.stream(this.candidates.apply(Collections.emptyMap())) - .filter(info -> info.getBlockState().getBlock() != Blocks.AIR).map(info -> { - IBlockState blockState = info.getBlockState(); - MetaTileEntity metaTileEntity = info.getTileEntity() instanceof IGregTechTileEntity ? - ((IGregTechTileEntity) info.getTileEntity()).getMetaTileEntity() : null; - if (metaTileEntity != null) { - return metaTileEntity.getStackForm(); - } else { - return new ItemStack(Item.getItemFromBlock(blockState.getBlock()), 1, - blockState.getBlock().damageDropped(blockState)); - } - }).collect(Collectors.toList()); + return candidates == null ? Collections.emptyList() : + Arrays.stream(this.candidates.apply(Collections.emptyMap())) + .filter(info -> info.getBlockState().getBlock() != Blocks.AIR) + .map(BlockInfo::toItem) + .collect(Collectors.toList()); } } diff --git a/src/main/java/gregtech/api/pattern/pattern/BlockPattern.java b/src/main/java/gregtech/api/pattern/pattern/BlockPattern.java index d6e52ec5b0c..351d435b3c0 100644 --- a/src/main/java/gregtech/api/pattern/pattern/BlockPattern.java +++ b/src/main/java/gregtech/api/pattern/pattern/BlockPattern.java @@ -8,7 +8,6 @@ import gregtech.api.pattern.PatternError; import gregtech.api.pattern.TraceabilityPredicate; import gregtech.api.util.BlockInfo; -import gregtech.api.util.GTLog; import gregtech.api.util.RelativeDirection; import net.minecraft.block.state.IBlockState; @@ -254,15 +253,20 @@ public boolean checkAisle(GreggyBlockPos controllerPos, EnumFacing frontFacing, // offset the string start once after every string stringStart.offset(absoluteString); charPos.from(stringStart); + } - // layer minimum checks - for (Object2IntMap.Entry entry : layerCount.object2IntEntrySet()) { - if (entry.getIntValue() < entry.getKey().minLayerCount) { - state.setError(new TraceabilityPredicate.SinglePredicateError(entry.getKey(), 3)); - return false; - } + // layer minimum checks + for (Object2IntMap.Entry entry : layerCount.object2IntEntrySet()) { + if (entry.getIntValue() < entry.getKey().minLayerCount) { + state.setError(new TraceabilityPredicate.SinglePredicateError(entry.getKey(), 3)); + return false; } } + + for (Object2IntMap.Entry entry : layerCount.object2IntEntrySet()) { + globalCount.put(entry.getKey(), globalCount.getInt(entry.getKey()) + entry.getIntValue()); + } + return true; } diff --git a/src/main/java/gregtech/api/pattern/pattern/ExpandablePattern.java b/src/main/java/gregtech/api/pattern/pattern/ExpandablePattern.java index 3c13457d77e..e20bb02046a 100644 --- a/src/main/java/gregtech/api/pattern/pattern/ExpandablePattern.java +++ b/src/main/java/gregtech/api/pattern/pattern/ExpandablePattern.java @@ -11,8 +11,6 @@ import gregtech.api.util.RelativeDirection; import gregtech.api.util.function.QuadFunction; -import it.unimi.dsi.fastutil.longs.Long2ObjectRBTreeMap; - import net.minecraft.block.state.IBlockState; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.EnumFacing; @@ -21,6 +19,7 @@ import it.unimi.dsi.fastutil.longs.Long2ObjectMap; import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; +import it.unimi.dsi.fastutil.longs.Long2ObjectRBTreeMap; import it.unimi.dsi.fastutil.longs.Long2ObjectSortedMap; import it.unimi.dsi.fastutil.longs.Long2ObjectSortedMaps; import it.unimi.dsi.fastutil.objects.Object2IntMap; @@ -156,7 +155,6 @@ public boolean checkPatternAt(World world, BlockPos centerPos, EnumFacing frontF // this basically reshuffles the coordinates into absolute form from relative form pos.zero().offset(absolutes[0], arr[0]).offset(absolutes[1], arr[1]).offset(absolutes[2], arr[2]); // translate from the origin to the center - // set the pos with world coordinates worldState.setPos(pos.add(translation)); if (predicate != TraceabilityPredicate.ANY) { @@ -213,7 +211,8 @@ public Long2ObjectSortedMap getDefaultShape(MultiblockCon TraceabilityPredicate predicate = predicateFunction.apply(pos, bounds); int[] arr = pos.getAll(); - pos.zero().offset(absolutes[0], arr[0]).offset(absolutes[1], arr[1]).offset(absolutes[2], arr[2]).add(translation); + pos.zero().offset(absolutes[0], arr[0]).offset(absolutes[1], arr[1]).offset(absolutes[2], arr[2]) + .add(translation); if (predicate != TraceabilityPredicate.ANY && predicate != TraceabilityPredicate.AIR) { predicates.put(pos.toLong(), predicate); diff --git a/src/main/java/gregtech/api/util/BlockInfo.java b/src/main/java/gregtech/api/util/BlockInfo.java index 79f23df05b1..9b3a4bd730b 100644 --- a/src/main/java/gregtech/api/util/BlockInfo.java +++ b/src/main/java/gregtech/api/util/BlockInfo.java @@ -1,8 +1,12 @@ package gregtech.api.util; +import gregtech.api.metatileentity.MetaTileEntity; +import gregtech.api.metatileentity.interfaces.IGregTechTileEntity; + import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import com.google.common.base.Preconditions; @@ -36,6 +40,16 @@ public BlockInfo(IBlockState blockState, TileEntity tileEntity) { "Cannot create block info with tile entity for block not having it"); } + public ItemStack toItem() { + MetaTileEntity metaTileEntity = tileEntity instanceof IGregTechTileEntity igtte ? igtte.getMetaTileEntity() : + null; + if (metaTileEntity != null) { + return metaTileEntity.getStackForm(); + } else { + return GTUtility.toItem(blockState); + } + } + public IBlockState getBlockState() { return blockState; } diff --git a/src/main/java/gregtech/common/items/behaviors/MultiblockBuilderBehavior.java b/src/main/java/gregtech/common/items/behaviors/MultiblockBuilderBehavior.java index 742fbeaafbd..3ec73cbb82c 100644 --- a/src/main/java/gregtech/common/items/behaviors/MultiblockBuilderBehavior.java +++ b/src/main/java/gregtech/common/items/behaviors/MultiblockBuilderBehavior.java @@ -9,10 +9,9 @@ import gregtech.api.mui.GTGuis; import gregtech.api.mui.factory.MetaItemGuiFactory; import gregtech.api.pattern.PatternError; -import gregtech.api.pattern.pattern.IBlockPattern; import gregtech.api.util.GTUtility; +import gregtech.client.renderer.handler.BlockPosHighlightRenderer; -import net.minecraft.block.state.IBlockState; import net.minecraft.client.resources.I18n; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; @@ -45,7 +44,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Set; import java.util.stream.Collectors; import java.util.stream.IntStream; @@ -195,6 +193,7 @@ public EnumActionResult onItemUseFirst(EntityPlayer player, World world, BlockPo player.sendMessage( new TextComponentTranslation("gregtech.multiblock.pattern.error_message_header")); player.sendMessage(new TextComponentString(error.getErrorInfo())); + if (error.getPos() != null) BlockPosHighlightRenderer.renderBlockBoxHighLight(error.getPos(), 5000); return EnumActionResult.SUCCESS; } } diff --git a/src/main/java/gregtech/common/metatileentities/multi/electric/MetaTileEntityCleanroom.java b/src/main/java/gregtech/common/metatileentities/multi/electric/MetaTileEntityCleanroom.java index fafd7d07c17..19b7b8c2c94 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/electric/MetaTileEntityCleanroom.java +++ b/src/main/java/gregtech/common/metatileentities/multi/electric/MetaTileEntityCleanroom.java @@ -3,7 +3,6 @@ import gregtech.api.GTValues; import gregtech.api.GregTechAPI; import gregtech.api.block.ICleanroomFilter; -import gregtech.api.block.IHeatingCoilBlockStats; import gregtech.api.capability.GregtechDataCodes; import gregtech.api.capability.GregtechTileCapabilities; import gregtech.api.capability.IEnergyContainer; @@ -25,7 +24,6 @@ import gregtech.api.metatileentity.multiblock.MultiblockDisplayText; import gregtech.api.metatileentity.multiblock.MultiblockWithDisplayBase; import gregtech.api.pattern.GreggyBlockPos; -import gregtech.api.pattern.MultiblockShapeInfo; import gregtech.api.pattern.PatternError; import gregtech.api.pattern.TraceabilityPredicate; import gregtech.api.pattern.pattern.FactoryExpandablePattern; @@ -43,7 +41,6 @@ import gregtech.common.blocks.BlockCleanroomCasing; import gregtech.common.blocks.BlockGlassCasing; import gregtech.common.blocks.MetaBlocks; -import gregtech.common.metatileentities.MetaTileEntities; import gregtech.common.metatileentities.multi.MetaTileEntityCokeOven; import gregtech.common.metatileentities.multi.MetaTileEntityPrimitiveBlastFurnace; import gregtech.common.metatileentities.multi.MetaTileEntityPrimitiveWaterPump; @@ -54,7 +51,6 @@ import net.minecraft.block.state.IBlockState; import net.minecraft.client.resources.I18n; import net.minecraft.creativetab.CreativeTabs; -import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.PacketBuffer; @@ -81,13 +77,11 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.Comparator; import java.util.EnumMap; -import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.List; @@ -283,7 +277,8 @@ protected TraceabilityPredicate filterPredicate() { PatternError.PLACEHOLDER, map -> GregTechAPI.CLEANROOM_FILTERS.entrySet().stream() .filter(e -> e.getValue().getCleanroomType() != null) - .filter(e -> e.getValue().getCleanroomType() == CleanroomType.getByName(map.get("cleanroomType"))) + .filter(e -> !map.containsKey("cleanroomType") || + e.getValue().getCleanroomType() == CleanroomType.getByName(map.get("cleanroomType"))) .sorted(Comparator.comparingInt(e -> e.getValue().getTier())) .map(e -> new BlockInfo(e.getKey(), null)) .toArray(BlockInfo[]::new)) @@ -407,7 +402,8 @@ protected void addDisplayText(List textList) { tl.add(getWithButton(EnumFacing.EAST)); tl.add(getWithButton(EnumFacing.DOWN)); - tl.add(withButton(new TextComponentTranslation("gregtech.multiblock.render." + renderingAABB), "render:" + renderingAABB)); + tl.add(withButton(new TextComponentTranslation("gregtech.multiblock.render." + renderingAABB), + "render:" + renderingAABB)); }) .addEnergyUsageExactLine(isClean() ? 4 : GTValues.VA[getEnergyTier()]) .addWorkingStatusLine() diff --git a/src/main/java/gregtech/common/metatileentities/multi/electric/MetaTileEntityElectricBlastFurnace.java b/src/main/java/gregtech/common/metatileentities/multi/electric/MetaTileEntityElectricBlastFurnace.java index d2d82693d36..6948688894c 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/electric/MetaTileEntityElectricBlastFurnace.java +++ b/src/main/java/gregtech/common/metatileentities/multi/electric/MetaTileEntityElectricBlastFurnace.java @@ -11,7 +11,6 @@ import gregtech.api.metatileentity.multiblock.MultiblockAbility; import gregtech.api.metatileentity.multiblock.MultiblockDisplayText; import gregtech.api.metatileentity.multiblock.RecipeMapMultiblockController; -import gregtech.api.pattern.MultiblockShapeInfo; import gregtech.api.pattern.pattern.BlockPattern; import gregtech.api.pattern.pattern.FactoryBlockPattern; import gregtech.api.recipes.Recipe; @@ -22,17 +21,13 @@ import gregtech.api.util.TextFormattingUtil; import gregtech.client.renderer.ICubeRenderer; import gregtech.client.renderer.texture.Textures; -import gregtech.common.ConfigHolder; import gregtech.common.blocks.BlockMetalCasing.MetalCasingType; import gregtech.common.blocks.MetaBlocks; -import gregtech.common.metatileentities.MetaTileEntities; import gregtech.core.sound.GTSoundEvents; import net.minecraft.block.state.IBlockState; import net.minecraft.client.resources.I18n; -import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; -import net.minecraft.util.EnumFacing; import net.minecraft.util.ResourceLocation; import net.minecraft.util.SoundEvent; import net.minecraft.util.text.ITextComponent; @@ -46,13 +41,10 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.ArrayList; import java.util.Collections; -import java.util.IntSummaryStatistics; import java.util.Iterator; import java.util.List; import java.util.Map; -import java.util.stream.IntStream; import static gregtech.api.util.RelativeDirection.*; diff --git a/src/main/java/gregtech/common/metatileentities/multi/electric/MetaTileEntityFusionReactor.java b/src/main/java/gregtech/common/metatileentities/multi/electric/MetaTileEntityFusionReactor.java index 77d5832d276..0477c884f2c 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/electric/MetaTileEntityFusionReactor.java +++ b/src/main/java/gregtech/common/metatileentities/multi/electric/MetaTileEntityFusionReactor.java @@ -1,8 +1,6 @@ package gregtech.common.metatileentities.multi.electric; import gregtech.api.GTValues; -import gregtech.api.GregTechAPI; -import gregtech.api.block.IHeatingCoilBlockStats; import gregtech.api.capability.GregtechDataCodes; import gregtech.api.capability.IEnergyContainer; import gregtech.api.capability.impl.EnergyContainerHandler; @@ -25,7 +23,6 @@ import gregtech.api.metatileentity.multiblock.MultiblockDisplayText; import gregtech.api.metatileentity.multiblock.MultiblockWithDisplayBase; import gregtech.api.metatileentity.multiblock.RecipeMapMultiblockController; -import gregtech.api.pattern.MultiblockShapeInfo; import gregtech.api.pattern.pattern.BlockPattern; import gregtech.api.pattern.pattern.FactoryBlockPattern; import gregtech.api.recipes.Recipe; @@ -61,7 +58,6 @@ import net.minecraft.client.renderer.vertex.DefaultVertexFormats; import net.minecraft.client.resources.I18n; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.PacketBuffer; @@ -80,8 +76,6 @@ import org.jetbrains.annotations.Nullable; import org.lwjgl.opengl.GL11; -import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.Iterator; import java.util.List; @@ -150,8 +144,9 @@ protected BlockPattern createStructurePattern() { .where('G', states("fusionGlass", getCasingState(), getGlassState())) .where('E', states("fusionGlass", getCasingState(), getGlassState()) - .or(tieredMTEs((map, mte) -> tier <= mte.getTier() && mte.getTier() <= GTValues.UV, MetaTileEntities.ENERGY_INPUT_HATCH) - .setMinGlobalLimited(1).setPreviewCount(16))) + .or(tieredMTEs((map, mte) -> tier <= mte.getTier() && mte.getTier() <= GTValues.UV, + MetaTileEntities.ENERGY_INPUT_HATCH) + .setMinGlobalLimited(1).setPreviewCount(16))) .where('C', states(getCasingState())) .where('K', states(getCoilState())) .where('O', states(getCasingState(), getGlassState()).or(abilities(MultiblockAbility.EXPORT_FLUIDS))) diff --git a/src/main/java/gregtech/common/metatileentities/multi/electric/MetaTileEntityHPCA.java b/src/main/java/gregtech/common/metatileentities/multi/electric/MetaTileEntityHPCA.java index 9dfe5939489..a6a9f6694d0 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/electric/MetaTileEntityHPCA.java +++ b/src/main/java/gregtech/common/metatileentities/multi/electric/MetaTileEntityHPCA.java @@ -70,17 +70,14 @@ public class MetaTileEntityHPCA extends MultiblockWithDisplayBase private static final double IDLE_TEMPERATURE = 200; private static final double DAMAGE_TEMPERATURE = 1000; - private IEnergyContainer energyContainer; private IFluidHandler coolantHandler; private final HPCAGridHandler hpcaHandler; - private boolean isActive; private boolean isWorkingEnabled = true; private boolean hasNotEnoughEnergy; private double temperature = IDLE_TEMPERATURE; // start at idle temperature - private final ProgressWidget.TimedProgressSupplier progressSupplier; public MetaTileEntityHPCA(ResourceLocation metaTileEntityId) { @@ -206,7 +203,9 @@ private void consumeEnergy() { .where('S', selfPredicate()) .where('A', states(getAdvancedState())) .where('V', states(getVentState())) - .where('X', abilities(MultiblockAbility.HPCA_COMPONENT)) + .where('X', + abilities(() -> RIGHT.getRelativeFacing(frontFacing, upwardsFacing), + MultiblockAbility.HPCA_COMPONENT)) .where('C', states(getCasingState()).setMinGlobalLimited(5) .or(maintenancePredicate()) .or(abilities(MultiblockAbility.INPUT_ENERGY).setMinGlobalLimited(1)) diff --git a/src/main/java/gregtech/common/metatileentities/multi/electric/MetaTileEntityPowerSubstation.java b/src/main/java/gregtech/common/metatileentities/multi/electric/MetaTileEntityPowerSubstation.java index 87746bfc024..58ff589be56 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/electric/MetaTileEntityPowerSubstation.java +++ b/src/main/java/gregtech/common/metatileentities/multi/electric/MetaTileEntityPowerSubstation.java @@ -2,7 +2,6 @@ import gregtech.api.GTValues; import gregtech.api.GregTechAPI; -import gregtech.api.block.IHeatingCoilBlockStats; import gregtech.api.capability.GregtechDataCodes; import gregtech.api.capability.GregtechTileCapabilities; import gregtech.api.capability.IControllable; @@ -24,9 +23,7 @@ import gregtech.common.ConfigHolder; import gregtech.common.blocks.BlockGlassCasing; import gregtech.common.blocks.BlockMetalCasing; -import gregtech.common.blocks.BlockMetalCasing.MetalCasingType; import gregtech.common.blocks.MetaBlocks; -import gregtech.common.metatileentities.MetaTileEntities; import net.minecraft.block.state.IBlockState; import net.minecraft.client.resources.I18n; @@ -54,7 +51,6 @@ import java.time.Duration; import java.util.*; import java.util.function.Supplier; -import java.util.stream.IntStream; import static gregtech.api.util.RelativeDirection.*; @@ -275,7 +271,8 @@ protected IBlockState getGlassState() { worldState -> GregTechAPI.PSS_BATTERIES.containsKey(worldState.getBlockState()) ? null : PatternError.PLACEHOLDER, map -> GregTechAPI.PSS_BATTERIES.entrySet().stream() - .filter(e -> e.getValue().getTier() == GTUtility.parseInt(map.get("batteryTier"), GTValues.EV)) + .filter(e -> !map.containsKey("batteryTier") || + e.getValue().getTier() == GTUtility.parseInt(map.get("batteryTier"), GTValues.EV)) .sorted(Comparator.comparingInt(entry -> entry.getValue().getTier())) .map(entry -> new BlockInfo(entry.getKey(), null)) .toArray(BlockInfo[]::new)) diff --git a/src/main/java/gregtech/common/metatileentities/multi/electric/MetaTileEntityResearchStation.java b/src/main/java/gregtech/common/metatileentities/multi/electric/MetaTileEntityResearchStation.java index 5cbf781795b..c115bc1db33 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/electric/MetaTileEntityResearchStation.java +++ b/src/main/java/gregtech/common/metatileentities/multi/electric/MetaTileEntityResearchStation.java @@ -14,7 +14,6 @@ import gregtech.api.metatileentity.multiblock.MultiblockDisplayText; import gregtech.api.metatileentity.multiblock.RecipeMapMultiblockController; import gregtech.api.pattern.MultiblockShapeInfo; -import gregtech.api.pattern.TraceabilityPredicate; import gregtech.api.pattern.pattern.BlockPattern; import gregtech.api.pattern.pattern.FactoryBlockPattern; import gregtech.api.recipes.Recipe; @@ -45,8 +44,6 @@ import java.util.Collections; import java.util.List; -import static gregtech.api.util.RelativeDirection.*; - public class MetaTileEntityResearchStation extends RecipeMapMultiblockController implements IOpticalComputationReceiver { @@ -139,7 +136,7 @@ protected BlockPattern createStructurePattern() { .or(abilities(MultiblockAbility.INPUT_ENERGY).setMinGlobalLimited(1)) .or(maintenancePredicate()) .or(abilities(MultiblockAbility.COMPUTATION_DATA_RECEPTION).setExactLimit(1))) - .where('H', abilities(MultiblockAbility.OBJECT_HOLDER)) + .where('H', abilities(() -> getFrontFacing().getOpposite(), MultiblockAbility.OBJECT_HOLDER)) .build(); } diff --git a/src/main/java/gregtech/common/metatileentities/primitive/MetaTileEntityCharcoalPileIgniter.java b/src/main/java/gregtech/common/metatileentities/primitive/MetaTileEntityCharcoalPileIgniter.java index 777701d67b3..2cf862b0d88 100644 --- a/src/main/java/gregtech/common/metatileentities/primitive/MetaTileEntityCharcoalPileIgniter.java +++ b/src/main/java/gregtech/common/metatileentities/primitive/MetaTileEntityCharcoalPileIgniter.java @@ -11,7 +11,6 @@ import gregtech.api.metatileentity.interfaces.IGregTechTileEntity; import gregtech.api.metatileentity.multiblock.IMultiblockPart; import gregtech.api.metatileentity.multiblock.MultiblockControllerBase; -import gregtech.api.pattern.MultiblockShapeInfo; import gregtech.api.pattern.PatternError; import gregtech.api.pattern.TraceabilityPredicate; import gregtech.api.pattern.pattern.FactoryExpandablePattern; @@ -23,7 +22,6 @@ import gregtech.client.utils.TooltipHelper; import gregtech.common.blocks.MetaBlocks; import gregtech.common.items.behaviors.LighterBehaviour; -import gregtech.common.metatileentities.MetaTileEntities; import net.minecraft.block.Block; import net.minecraft.client.resources.I18n; @@ -42,7 +40,6 @@ import net.minecraft.util.ResourceLocation; import net.minecraft.util.SoundCategory; import net.minecraft.util.math.BlockPos; -import net.minecraft.util.text.TextComponentString; import net.minecraft.util.text.TextComponentTranslation; import net.minecraft.world.World; import net.minecraftforge.common.MinecraftForge; @@ -60,7 +57,6 @@ import crafttweaker.annotations.ZenRegister; import crafttweaker.api.block.IBlock; import crafttweaker.api.minecraft.CraftTweakerMC; -import it.unimi.dsi.fastutil.objects.ObjectArrayList; import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -68,12 +64,14 @@ import stanhebben.zenscript.annotations.ZenMethod; import java.util.Collection; +import java.util.Collections; import java.util.EnumMap; -import java.util.HashMap; +import java.util.Iterator; import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Set; +import java.util.stream.IntStream; @ZenClass("mods.gregtech.machines.CharcoalPileIgniter") @ZenRegister @@ -150,14 +148,13 @@ protected void formStructure(String name) { @Override protected IBlockPattern createStructurePattern() { TraceabilityPredicate floorPredicate = blocks(Blocks.BRICK_BLOCK); - TraceabilityPredicate wallPredicate = blocks(WALL_BLOCKS.toArray(new Block[0])); + TraceabilityPredicate wallPredicate = blocks("walls", WALL_BLOCKS.toArray(new Block[0])); TraceabilityPredicate logPredicate = logPredicate(); // basically cleanroom code return FactoryExpandablePattern.start(RelativeDirection.UP, RelativeDirection.RIGHT, RelativeDirection.FRONT) .boundsFunction((w, c, f, u) -> bounds) .predicateFunction((c, b) -> { - // controller always at origin if (c.origin()) return selfPredicate(); int intersects = 0; @@ -173,23 +170,26 @@ protected IBlockPattern createStructurePattern() { // char dir is front, so its bounds[4] and bounds[5] if (c.z() == b[4] || c.z() == -b[5]) intersects++; - // GTLog.logger.info(intersects + " intersects at " + c); - - // more than or equal to 2 intersects means it is an edge if (intersects >= 2) return any(); - // 1 intersect means it is a face if (intersects == 1) { if (botAisle) return floorPredicate; return wallPredicate; } - // intersects == 0, so its not a face return logPredicate; }) .build(); } + @NotNull + @Override + public Iterator> getPreviewBuilds() { + return IntStream.range(0, WALL_BLOCKS.size()) + .mapToObj(i -> Collections.singletonMap("walls", Integer.toString(i))) + .iterator(); + } + @NotNull private TraceabilityPredicate logPredicate() { return new TraceabilityPredicate( @@ -270,7 +270,8 @@ public boolean onScrewdriverClick(EntityPlayer playerIn, EnumHand hand, EnumFaci playerIn.sendMessage( new TextComponentTranslation("gregtech.direction." + facing.name().toLowerCase(Locale.ROOT)) .appendText(" ") - .appendSibling(new TextComponentTranslation("gregtech.machine.miner.radius", bounds[dir.ordinal()]))); + .appendSibling(new TextComponentTranslation("gregtech.machine.miner.radius", + bounds[dir.ordinal()]))); getSubstructure("MAIN").clearCache(); return true; } @@ -308,26 +309,6 @@ public void addInformation(ItemStack stack, @Nullable World player, @NotNull Lis } } - @Override - public List getMatchingShapes() { - List shapeInfos = new ObjectArrayList<>(); - for (Block block : WALL_BLOCKS) { - shapeInfos.add(MultiblockShapeInfo.builder() - .aisle(" ", " XXX ", " XXX ", " XXX ", " ") - .aisle(" BBB ", "XCCCX", "XCCCX", "XCCCX", " DDD ") - .aisle(" BBB ", "XCCCX", "XCCCX", "XCCCX", " DSD ") - .aisle(" BBB ", "XCCCX", "XCCCX", "XCCCX", " DDD ") - .aisle(" ", " XXX ", " XXX ", " XXX ", " ") - .where('S', MetaTileEntities.CHARCOAL_PILE_IGNITER, EnumFacing.NORTH) - .where('B', Blocks.BRICK_BLOCK.getDefaultState()) - .where('X', block.getDefaultState()) - .where('D', block.getDefaultState()) - .where('C', Blocks.LOG.getDefaultState()) - .build()); - } - return shapeInfos; - } - @Override public NBTTagCompound writeToNBT(NBTTagCompound data) { super.writeToNBT(data); diff --git a/src/main/java/gregtech/integration/jei/multiblock/MultiblockInfoRecipeWrapper.java b/src/main/java/gregtech/integration/jei/multiblock/MultiblockInfoRecipeWrapper.java index 5f1105fbee1..59a3610a532 100644 --- a/src/main/java/gregtech/integration/jei/multiblock/MultiblockInfoRecipeWrapper.java +++ b/src/main/java/gregtech/integration/jei/multiblock/MultiblockInfoRecipeWrapper.java @@ -489,7 +489,7 @@ private MBPattern initializePattern(@NotNull MultiblockControllerBase src, @NotN Set structures = src.trySubstructure(map); Long2ObjectMap copy = new Long2ObjectOpenHashMap<>(); - for (String structure : structures) { + for (String structure : structures) { Long2ObjectMap predicates = ((MultiblockControllerBase) holder.getMetaTileEntity()) .getSubstructure(structure) .getDefaultShape((MultiblockControllerBase) holder.getMetaTileEntity(), map); diff --git a/src/test/java/gregtech/api/util/TierByVoltageTest.java b/src/test/java/gregtech/api/util/TierByVoltageTest.java index d0f6fdc75a5..fafe266f771 100644 --- a/src/test/java/gregtech/api/util/TierByVoltageTest.java +++ b/src/test/java/gregtech/api/util/TierByVoltageTest.java @@ -1,15 +1,13 @@ package gregtech.api.util; -import net.minecraft.util.math.BlockPos; - import org.junit.jupiter.api.Test; import static gregtech.api.GTValues.*; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.jupiter.api.Assertions.assertEquals; public class TierByVoltageTest { + @Test public void testV() { expectTier(V[ULV], ULV, ULV);