From c6a3a024a99db959c59c4598e9bf2bafb89b86b8 Mon Sep 17 00:00:00 2001 From: Tictim Date: Sun, 24 Sep 2023 15:00:38 +0900 Subject: [PATCH 01/27] Small refactor --- .../java/gregtech/api/capability/IMiner.java | 23 - .../api/capability/impl/RecipeLogicSteam.java | 53 +- .../api/capability/impl/miner/MinerLogic.java | 750 ------------------ .../impl/miner/MultiblockMinerLogic.java | 154 ---- .../impl/miner/SteamMinerLogic.java | 38 - .../api/unification/OreDictUnifier.java | 30 +- .../unification/stack/ItemAndMetadata.java | 12 +- .../java/gregtech/api/util/BlockUtility.java | 46 +- .../java/gregtech/api/util/GTUtility.java | 65 +- .../metatileentities/MetaTileEntities.java | 20 +- .../common/metatileentities/miner/IMiner.java | 19 + .../MetaTileEntityLargeMiner.java | 417 +++++----- .../MetaTileEntityMiner.java | 114 +-- .../metatileentities/miner/MinerLogic.java | 530 +++++++++++++ .../miner/MultiblockMinerLogic.java | 189 +++++ .../{steam => miner}/SteamMiner.java | 172 ++-- .../miner/SteamMinerLogic.java | 27 + .../electric/MetaTileEntityCleanroom.java | 1 + .../widget/WidgetProspectingMap.java | 60 +- 19 files changed, 1224 insertions(+), 1496 deletions(-) delete mode 100644 src/main/java/gregtech/api/capability/IMiner.java delete mode 100644 src/main/java/gregtech/api/capability/impl/miner/MinerLogic.java delete mode 100644 src/main/java/gregtech/api/capability/impl/miner/MultiblockMinerLogic.java delete mode 100644 src/main/java/gregtech/api/capability/impl/miner/SteamMinerLogic.java create mode 100644 src/main/java/gregtech/common/metatileentities/miner/IMiner.java rename src/main/java/gregtech/common/metatileentities/{multi/electric => miner}/MetaTileEntityLargeMiner.java (50%) rename src/main/java/gregtech/common/metatileentities/{electric => miner}/MetaTileEntityMiner.java (68%) create mode 100644 src/main/java/gregtech/common/metatileentities/miner/MinerLogic.java create mode 100644 src/main/java/gregtech/common/metatileentities/miner/MultiblockMinerLogic.java rename src/main/java/gregtech/common/metatileentities/{steam => miner}/SteamMiner.java (65%) create mode 100644 src/main/java/gregtech/common/metatileentities/miner/SteamMinerLogic.java diff --git a/src/main/java/gregtech/api/capability/IMiner.java b/src/main/java/gregtech/api/capability/IMiner.java deleted file mode 100644 index 5ac4607a31b..00000000000 --- a/src/main/java/gregtech/api/capability/IMiner.java +++ /dev/null @@ -1,23 +0,0 @@ -package gregtech.api.capability; - - -import codechicken.lib.vec.Cuboid6; - -public interface IMiner { - - Cuboid6 PIPE_CUBOID = new Cuboid6(4 / 16.0, 0.0, 4 / 16.0, 12 / 16.0, 1.0, 12 / 16.0); - - boolean drainEnergy(boolean simulate); - - default boolean drainFluid(boolean simulate) { - return true; - } - - boolean isInventoryFull(); - - void setInventoryFull(boolean isFull); - - default int getWorkingArea(int maximumRadius) { - return maximumRadius * 2 + 1; - } -} diff --git a/src/main/java/gregtech/api/capability/impl/RecipeLogicSteam.java b/src/main/java/gregtech/api/capability/impl/RecipeLogicSteam.java index 32738279f6f..927f17b7833 100644 --- a/src/main/java/gregtech/api/capability/impl/RecipeLogicSteam.java +++ b/src/main/java/gregtech/api/capability/impl/RecipeLogicSteam.java @@ -3,27 +3,14 @@ import gregtech.api.GTValues; import gregtech.api.capability.GregtechDataCodes; import gregtech.api.capability.IVentable; -import gregtech.api.damagesources.DamageSources; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.recipes.Recipe; import gregtech.api.recipes.RecipeMap; import gregtech.api.util.GTUtility; import gregtech.common.ConfigHolder; -import gregtech.core.advancement.AdvancementTriggers; -import net.minecraft.block.Block; -import net.minecraft.block.state.IBlockState; -import net.minecraft.entity.EntityLivingBase; -import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.init.SoundEvents; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.PacketBuffer; -import net.minecraft.util.EntitySelectors; import net.minecraft.util.EnumFacing; -import net.minecraft.util.EnumParticleTypes; -import net.minecraft.util.SoundCategory; -import net.minecraft.util.math.AxisAlignedBB; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.WorldServer; import net.minecraftforge.fluids.IFluidTank; import javax.annotation.Nonnull; @@ -124,45 +111,15 @@ public void receiveInitialData(@Nonnull PacketBuffer buf) { @Override public void tryDoVenting() { - BlockPos machinePos = metaTileEntity.getPos(); - EnumFacing ventingSide = getVentingSide(); - BlockPos ventingBlockPos = machinePos.offset(ventingSide); - IBlockState blockOnPos = metaTileEntity.getWorld().getBlockState(ventingBlockPos); - if (blockOnPos.getCollisionBoundingBox(metaTileEntity.getWorld(), ventingBlockPos) == Block.NULL_AABB) { - performVentingAnimation(ventingBlockPos, machinePos); - } else if (GTUtility.tryBreakSnowLayer(metaTileEntity.getWorld(), ventingBlockPos, blockOnPos, false)) { - performVentingAnimation(ventingBlockPos, machinePos); - } else if (!ventingStuck) { + if (GTUtility.tryVenting(metaTileEntity.getWorld(), metaTileEntity.getPos(), getVentingSide(), + this.isHighPressure ? 12 : 6, true, + ConfigHolder.machines.machineSounds && !this.metaTileEntity.isMuffled())) { + setNeedsVenting(false); + } else { setVentingStuck(true); } } - private void performVentingAnimation(BlockPos ventingBlockPos, BlockPos machinePos) { - metaTileEntity.getWorld() - .getEntitiesWithinAABB(EntityLivingBase.class, new AxisAlignedBB(ventingBlockPos), EntitySelectors.CAN_AI_TARGET) - .forEach(entity -> { - entity.attackEntityFrom(DamageSources.getHeatDamage(), this.isHighPressure ? 12.0f : 6.0f); - if (entity instanceof EntityPlayerMP) { - AdvancementTriggers.STEAM_VENT_DEATH.trigger((EntityPlayerMP) entity); - } - }); - WorldServer world = (WorldServer) metaTileEntity.getWorld(); - double posX = machinePos.getX() + 0.5 + ventingSide.getXOffset() * 0.6; - double posY = machinePos.getY() + 0.5 + ventingSide.getYOffset() * 0.6; - double posZ = machinePos.getZ() + 0.5 + ventingSide.getZOffset() * 0.6; - - world.spawnParticle(EnumParticleTypes.CLOUD, posX, posY, posZ, - 7 + world.rand.nextInt(3), - ventingSide.getXOffset() / 2.0, - ventingSide.getYOffset() / 2.0, - ventingSide.getZOffset() / 2.0, 0.1); - if (ConfigHolder.machines.machineSounds && !metaTileEntity.isMuffled()){ - world.playSound(null, posX, posY, posZ, SoundEvents.BLOCK_LAVA_EXTINGUISH, SoundCategory.BLOCKS, 1.0f, 1.0f); - } - setNeedsVenting(false); - - } - @Override public void update() { if (getMetaTileEntity().getWorld().isRemote) diff --git a/src/main/java/gregtech/api/capability/impl/miner/MinerLogic.java b/src/main/java/gregtech/api/capability/impl/miner/MinerLogic.java deleted file mode 100644 index 2ded13ae1a4..00000000000 --- a/src/main/java/gregtech/api/capability/impl/miner/MinerLogic.java +++ /dev/null @@ -1,750 +0,0 @@ -package gregtech.api.capability.impl.miner; - -import codechicken.lib.render.CCRenderState; -import codechicken.lib.render.pipeline.IVertexOperation; -import codechicken.lib.vec.Matrix4; -import gregtech.api.capability.GregtechDataCodes; -import gregtech.api.capability.IMiner; -import gregtech.api.metatileentity.MetaTileEntity; -import gregtech.api.recipes.Recipe; -import gregtech.api.recipes.RecipeMap; -import gregtech.api.unification.OreDictUnifier; -import gregtech.api.unification.ore.OrePrefix; -import gregtech.api.util.GTLog; -import gregtech.api.util.GTTransferUtils; -import gregtech.api.util.GTUtility; -import gregtech.client.renderer.ICubeRenderer; -import gregtech.client.renderer.texture.Textures; -import gregtech.common.ConfigHolder; -import net.minecraft.block.Block; -import net.minecraft.block.state.IBlockState; -import net.minecraft.init.Blocks; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagInt; -import net.minecraft.network.PacketBuffer; -import net.minecraft.util.EnumFacing; -import net.minecraft.util.NonNullList; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import net.minecraft.world.WorldServer; -import net.minecraftforge.fml.relauncher.Side; -import net.minecraftforge.fml.relauncher.SideOnly; -import org.apache.commons.lang3.StringUtils; - -import javax.annotation.Nonnull; -import java.util.Collections; -import java.util.LinkedList; -import java.util.List; -import java.util.Objects; -import java.util.concurrent.atomic.AtomicInteger; - -public class MinerLogic { - - private static final short MAX_SPEED = Short.MAX_VALUE; - private static final byte POWER = 5; - private static final byte TICK_TOLERANCE = 20; - private static final double DIVIDEND = MAX_SPEED * Math.pow(TICK_TOLERANCE, POWER); - - protected final MetaTileEntity metaTileEntity; - protected final IMiner miner; - - private final int fortune; - private final int speed; - private final int maximumRadius; - - private final ICubeRenderer PIPE_TEXTURE; - - private final LinkedList blocksToMine = new LinkedList<>(); - - private final AtomicInteger x = new AtomicInteger(Integer.MAX_VALUE); - private final AtomicInteger y = new AtomicInteger(Integer.MAX_VALUE); - private final AtomicInteger z = new AtomicInteger(Integer.MAX_VALUE); - private final AtomicInteger startX = new AtomicInteger(Integer.MAX_VALUE); - private final AtomicInteger startZ = new AtomicInteger(Integer.MAX_VALUE); - private final AtomicInteger startY = new AtomicInteger(Integer.MAX_VALUE); - private final AtomicInteger pipeY = new AtomicInteger(Integer.MAX_VALUE); - private final AtomicInteger mineX = new AtomicInteger(Integer.MAX_VALUE); - private final AtomicInteger mineZ = new AtomicInteger(Integer.MAX_VALUE); - private final AtomicInteger mineY = new AtomicInteger(Integer.MAX_VALUE); - - private int pipeLength = 0; - private int currentRadius; - private boolean isDone; - private boolean isActive = false; - private boolean isWorkingEnabled = true; - protected boolean wasActiveAndNeedsUpdate; - - private final IBlockState oreReplacementBlock = findMiningReplacementBlock(); - - /** - * Creates the general logic for all in-world ore block miners - * - * @param metaTileEntity the {@link MetaTileEntity} this logic belongs to - * @param fortune the fortune amount to apply when mining ores - * @param speed the speed in ticks per block mined - * @param maximumRadius the maximum radius (square shaped) the miner can mine in - */ - public MinerLogic(@Nonnull MetaTileEntity metaTileEntity, int fortune, int speed, int maximumRadius, ICubeRenderer pipeTexture) { - this.metaTileEntity = metaTileEntity; - this.miner = (IMiner) metaTileEntity; - this.fortune = fortune; - this.speed = speed; - this.currentRadius = maximumRadius; - this.maximumRadius = maximumRadius; - this.isDone = false; - this.PIPE_TEXTURE = pipeTexture; - } - - private static IBlockState findMiningReplacementBlock() { - String[] blockDescription = StringUtils.split(ConfigHolder.machines.replaceMinedBlocksWith, ":"); - Block replacementBlock; - - if (blockDescription.length == 2) { - replacementBlock = Block.getBlockFromName(ConfigHolder.machines.replaceMinedBlocksWith); - } else { - replacementBlock = Block.getBlockFromName(String.format("%s:%s", blockDescription[0], blockDescription[1])); - } - if (replacementBlock == null) { - GTLog.logger.error("Miner Config Replacement block was null, replacing with Cobblestone"); - return Blocks.COBBLESTONE.getDefaultState(); - } - - // check for meta - if (blockDescription.length > 2 && !blockDescription[2].isEmpty()) { - return replacementBlock.getDefaultState().getBlock().getStateFromMeta(Integer.parseInt(blockDescription[2])); - } - - return replacementBlock.getDefaultState(); - } - - /** - * Performs the actual mining in world - * Call this method every tick in update - */ - public void performMining() { - // Needs to be server side - if (metaTileEntity.getWorld().isRemote) - return; - - // Inactive miners do nothing - if (!this.isWorkingEnabled) - return; - - // check if mining is possible - if (!checkCanMine()) - return; - - // if the inventory is not full, drain energy etc. from the miner - // the storages have already been checked earlier - if (!miner.isInventoryFull()) { - // always drain storages when working, even if blocksToMine ends up being empty - drainStorages(false); - - // since energy is being consumed the miner is now active - if (!this.isActive) - setActive(true); - } else { - // the miner cannot drain, therefore it is inactive - if (this.isActive) - setActive(false); - } - - // drill a hole beneath the miner and extend the pipe downwards by one - WorldServer world = (WorldServer) metaTileEntity.getWorld(); - if (mineY.get() < pipeY.get()) { - world.destroyBlock(new BlockPos(metaTileEntity.getPos().getX(), pipeY.get(), metaTileEntity.getPos().getZ()), false); - pipeY.decrementAndGet(); - incrementPipeLength(); - } - - // check if the miner needs new blocks to mine and get them if needed - checkBlocksToMine(); - - // if there are blocks to mine and the correct amount of time has passed, do the mining - if (metaTileEntity.getOffsetTimer() % this.speed == 0 && !blocksToMine.isEmpty()) { - NonNullList blockDrops = NonNullList.create(); - IBlockState blockState = metaTileEntity.getWorld().getBlockState(blocksToMine.getFirst()); - - // check to make sure the ore is still there, - while (!GTUtility.isOre(GTUtility.toItem(blockState))) { - blocksToMine.removeFirst(); - if (blocksToMine.isEmpty()) break; - blockState = metaTileEntity.getWorld().getBlockState(blocksToMine.getFirst()); - } - // When we are here we have an ore to mine! I'm glad we aren't threaded - if (!blocksToMine.isEmpty() & GTUtility.isOre(GTUtility.toItem(blockState))) { - // get the small ore drops, if a small ore - getSmallOreBlockDrops(blockDrops, world, blocksToMine.getFirst(), blockState); - // get the block's drops. - getRegularBlockDrops(blockDrops, world, blocksToMine.getFirst(), blockState); - // try to insert them - mineAndInsertItems(blockDrops, world); - } - - } - - if (blocksToMine.isEmpty()) { - // there were no blocks to mine, so the current position is the previous position - x.set(mineX.get()); - y.set(mineY.get()); - z.set(mineZ.get()); - - // attempt to get more blocks to mine, if there are none, the miner is done mining - blocksToMine.addAll(getBlocksToMine()); - if (blocksToMine.isEmpty()) { - this.isDone = true; - this.wasActiveAndNeedsUpdate = true; - this.setActive(false); - } - } - } - - /** - * @return true if the miner is able to mine, else false - */ - protected boolean checkCanMine() { - // if the miner is finished, the target coordinates are invalid, or it cannot drain storages, stop - if (checkShouldStop()) { - // if the miner is not finished and has invalid coordinates, get new and valid starting coordinates - if (!isDone && checkCoordinatesInvalid(x, y, z)) - initPos(metaTileEntity.getPos(), currentRadius); - - // don't do anything else this time - return false; - } - return true; - } - - protected boolean checkShouldStop() { - return isDone || checkCoordinatesInvalid(x, y, z) || !drainStorages(true); - } - - /** - * Called after each block is mined, used to perform additional actions afterwards - */ - protected void onMineOperation() { - - } - - /** - * called in order to drain anything the miner needs to drain in order to run - * only drains energy by default - */ - protected boolean drainStorages(boolean simulate) { - return miner.drainEnergy(simulate); - } - - /** - * called to handle mining small ores - * - * @param blockDrops the List of items to fill after the operation - * @param world the {@link WorldServer} the miner is in - * @param blockToMine the {@link BlockPos} of the block being mined - * @param blockState the {@link IBlockState} of the block being mined - */ - protected void getSmallOreBlockDrops(NonNullList blockDrops, WorldServer world, BlockPos blockToMine, IBlockState blockState) { - /*small ores - if orePrefix of block in blockPos is small - applyTieredHammerNoRandomDrops... - else - current code... - */ - } - - /** - * called to handle mining regular ores and blocks - * - * @param blockDrops the List of items to fill after the operation - * @param world the {@link WorldServer} the miner is in - * @param blockToMine the {@link BlockPos} of the block being mined - * @param blockState the {@link IBlockState} of the block being mined - */ - protected void getRegularBlockDrops(NonNullList blockDrops, WorldServer world, BlockPos blockToMine, @Nonnull IBlockState blockState) { - blockState.getBlock().getDrops(blockDrops, world, blockToMine, blockState, 0); // regular ores do not get fortune applied - } - - /** - * called in order to insert the mined items into the inventory and actually remove the block in world - * marks the inventory as full if the items cannot fit, and not full if it previously was full and items could fit - * - * @param blockDrops the List of items to insert - * @param world the {@link WorldServer} the miner is in - */ - private void mineAndInsertItems(NonNullList blockDrops, WorldServer world) { - // If the block's drops can fit in the inventory, move the previously mined position to the block - // replace the ore block with cobblestone instead of breaking it to prevent mob spawning - // remove the ore block's position from the mining queue - if (GTTransferUtils.addItemsToItemHandler(metaTileEntity.getExportItems(), true, blockDrops)) { - GTTransferUtils.addItemsToItemHandler(metaTileEntity.getExportItems(), false, blockDrops); - world.setBlockState(blocksToMine.getFirst(), oreReplacementBlock); - mineX.set(blocksToMine.getFirst().getX()); - mineZ.set(blocksToMine.getFirst().getZ()); - mineY.set(blocksToMine.getFirst().getY()); - blocksToMine.removeFirst(); - onMineOperation(); - - // if the inventory was previously considered full, mark it as not since an item was able to fit - if (miner.isInventoryFull()) - miner.setInventoryFull(false); - } else { - // the ore block was not able to fit, so the inventory is considered full - miner.setInventoryFull(true); - } - } - - /** - * This method designates the starting position for mining blocks - * - * @param pos the {@link BlockPos} of the miner itself - * @param currentRadius the currently set mining radius - */ - public void initPos(@Nonnull BlockPos pos, int currentRadius) { - x.set(pos.getX() - currentRadius); - z.set(pos.getZ() - currentRadius); - y.set(pos.getY() - 1); - startX.set(pos.getX() - currentRadius); - startZ.set(pos.getZ() - currentRadius); - startY.set(pos.getY()); - pipeY.set(pos.getY() - 1); - mineX.set(pos.getX() - currentRadius); - mineZ.set(pos.getZ() - currentRadius); - mineY.set(pos.getY() - 1); - } - - /** - * Checks if the current coordinates are invalid - * - * @param x the x coordinate - * @param y the y coordinate - * @param z the z coordinate - * @return {@code true} if the coordinates are invalid, else false - */ - private static boolean checkCoordinatesInvalid(@Nonnull AtomicInteger x, @Nonnull AtomicInteger y, @Nonnull AtomicInteger z) { - return x.get() == Integer.MAX_VALUE && y.get() == Integer.MAX_VALUE && z.get() == Integer.MAX_VALUE; - } - - /** - * Checks whether there are any more blocks to mine, if there are currently none queued - */ - public void checkBlocksToMine() { - if (blocksToMine.isEmpty()) - blocksToMine.addAll(getBlocksToMine()); - } - - /** - * Recalculates the mining area, refills the block list and restarts the miner, if it was done - */ - public void resetArea() { - initPos(metaTileEntity.getPos(), currentRadius); - if (this.isDone) this.setWorkingEnabled(false); - this.isDone = false; - blocksToMine.clear(); - checkBlocksToMine(); - resetPipeLength(); - } - - /** - * Gets the blocks to mine - * - * @return a {@link LinkedList} of {@link BlockPos} for each ore to mine - */ - private LinkedList getBlocksToMine() { - LinkedList blocks = new LinkedList<>(); - - // determine how many blocks to retrieve this time - double quotient = getQuotient(getMeanTickTime(metaTileEntity.getWorld())); - int calcAmount = quotient < 1 ? 1 : (int) (Math.min(quotient, Short.MAX_VALUE)); - int calculated = 0; - - // keep getting blocks until the target amount is reached - while (calculated < calcAmount) { - // moving down the y-axis - if (y.get() > 0) { - // moving across the z-axis - if (z.get() <= startZ.get() + currentRadius * 2) { - // check every block along the x-axis - if (x.get() <= startX.get() + currentRadius * 2) { - BlockPos blockPos = new BlockPos(x.get(), y.get(), z.get()); - IBlockState state = metaTileEntity.getWorld().getBlockState(blockPos); - if (state.getBlock().blockHardness >= 0 && metaTileEntity.getWorld().getTileEntity(blockPos) == null && GTUtility.isOre(GTUtility.toItem(state))) { - blocks.addLast(blockPos); - } - // move to the next x position - x.incrementAndGet(); - } else { - // reset x and move to the next z layer - x.set(startX.get()); - z.incrementAndGet(); - } - } else { - // reset z and move to the next y layer - z.set(startZ.get()); - y.decrementAndGet(); - } - } else - return blocks; - - // only count iterations where blocks were found - if (!blocks.isEmpty()) - calculated++; - } - return blocks; - } - - /** - * @param values to find the mean of - * @return the mean value - */ - private static long mean(@Nonnull long[] values) { - if (values.length == 0L) - return 0L; - - long sum = 0L; - for (long v : values) - sum += v; - return sum / values.length; - } - - /** - * @param world the {@link World} to get the average tick time of - * @return the mean tick time - */ - private static double getMeanTickTime(@Nonnull World world) { - return mean(Objects.requireNonNull(world.getMinecraftServer()).tickTimeArray) * 1.0E-6D; - } - - /** - * gets the quotient for determining the amount of blocks to mine - * - * @param base is a value used for calculation, intended to be the mean tick time of the world the miner is in - * @return the quotient - */ - private static double getQuotient(double base) { - return DIVIDEND / Math.pow(base, POWER); - } - - /** - * Applies a fortune hammer to block drops based on a tier value, intended for small ores - * - * @param blockState the block being mined - * @param drops where the drops are stored to - * @param fortuneLevel the level of fortune used - * @param map the recipemap from which to get the drops - * @param tier the tier at which the operation is performed, used for calculating the chanced output boost - */ - protected static void applyTieredHammerNoRandomDrops(@Nonnull IBlockState blockState, List drops, int fortuneLevel, @Nonnull RecipeMap map, int tier) { - ItemStack itemStack = GTUtility.toItem(blockState); - Recipe recipe = map.findRecipe(Long.MAX_VALUE, Collections.singletonList(itemStack), Collections.emptyList()); - if (recipe != null && !recipe.getOutputs().isEmpty()) { - drops.clear(); - for (ItemStack outputStack : recipe.getResultItemOutputs(GTUtility.getTierByVoltage(recipe.getEUt()), tier, map)) { - outputStack = outputStack.copy(); - if (OreDictUnifier.getPrefix(outputStack) == OrePrefix.crushed) { - if (fortuneLevel > 0) { - outputStack.grow(outputStack.getCount() * fortuneLevel); - } - } - drops.add(outputStack); - } - } - } - - /** - * Increments the pipe rendering length by one, signaling that the miner's y level has moved down by one - */ - private void incrementPipeLength() { - this.pipeLength++; - this.metaTileEntity.writeCustomData(GregtechDataCodes.PUMP_HEAD_LEVEL, b -> b.writeInt(pipeLength)); - this.metaTileEntity.markDirty(); - } - - /** - * Resets the pipe length to zero - */ - private void resetPipeLength() { - this.pipeLength = 0; - this.metaTileEntity.writeCustomData(GregtechDataCodes.PUMP_HEAD_LEVEL, b -> b.writeInt(pipeLength)); - this.metaTileEntity.markDirty(); - } - - /** - * renders the pipe beneath the miner - */ - @SideOnly(Side.CLIENT) - public void renderPipe(CCRenderState renderState, Matrix4 translation, IVertexOperation[] pipeline) { - Textures.PIPE_IN_OVERLAY.renderSided(EnumFacing.DOWN, renderState, translation, pipeline); - for (int i = 0; i < this.pipeLength; i++) { - translation.translate(0.0, -1.0, 0.0); - getPipeTexture().render(renderState, translation, pipeline, IMiner.PIPE_CUBOID); - } - } - - @SideOnly(Side.CLIENT) - protected ICubeRenderer getPipeTexture() { - return PIPE_TEXTURE; - } - - /** - * writes all needed values to NBT - * This MUST be called and returned in the MetaTileEntity's {@link MetaTileEntity#writeToNBT(NBTTagCompound)} method - */ - public NBTTagCompound writeToNBT(@Nonnull NBTTagCompound data) { - data.setTag("xPos", new NBTTagInt(x.get())); - data.setTag("yPos", new NBTTagInt(y.get())); - data.setTag("zPos", new NBTTagInt(z.get())); - data.setTag("mxPos", new NBTTagInt(mineX.get())); - data.setTag("myPos", new NBTTagInt(mineY.get())); - data.setTag("mzPos", new NBTTagInt(mineZ.get())); - data.setTag("sxPos", new NBTTagInt(startX.get())); - data.setTag("syPos", new NBTTagInt(startY.get())); - data.setTag("szPos", new NBTTagInt(startZ.get())); - data.setTag("tempY", new NBTTagInt(pipeY.get())); - data.setTag("isActive", new NBTTagInt(this.isActive ? 1 : 0)); - data.setTag("isWorkingEnabled", new NBTTagInt(this.isWorkingEnabled ? 1 : 0)); - data.setTag("wasActiveAndNeedsUpdate", new NBTTagInt(this.wasActiveAndNeedsUpdate ? 1 : 0)); - data.setTag("pipeLength", new NBTTagInt(pipeLength)); - data.setTag("currentRadius", new NBTTagInt(currentRadius)); - data.setTag("isDone", new NBTTagInt(isDone ? 1 : 0)); - return data; - } - - /** - * reads all needed values from NBT - * This MUST be called and returned in the MetaTileEntity's {@link MetaTileEntity#readFromNBT(NBTTagCompound)} method - */ - public void readFromNBT(@Nonnull NBTTagCompound data) { - x.set(data.getInteger("xPos")); - y.set(data.getInteger("yPos")); - z.set(data.getInteger("zPos")); - mineX.set(data.getInteger("mxPos")); - mineY.set(data.getInteger("myPos")); - mineZ.set(data.getInteger("mzPos")); - startX.set(data.getInteger("sxPos")); - startY.set(data.getInteger("syPos")); - startZ.set(data.getInteger("szPos")); - pipeY.set(data.getInteger("tempY")); - setActive(data.getInteger("isActive") != 0); - setWorkingEnabled(data.getInteger("isWorkingEnabled") != 0); - setWasActiveAndNeedsUpdate(data.getInteger("wasActiveAndNeedsUpdate") != 0); - pipeLength = data.getInteger("pipeLength"); - this.currentRadius = data.getInteger("currentRadius"); - this.isDone = data.getInteger("isDone") != 0; - } - - /** - * writes all needed values to InitialSyncData - * This MUST be called and returned in the MetaTileEntity's {@link MetaTileEntity#writeInitialSyncData(PacketBuffer)} method - */ - public void writeInitialSyncData(@Nonnull PacketBuffer buf) { - buf.writeInt(pipeLength); - buf.writeBoolean(this.isActive); - buf.writeBoolean(this.isWorkingEnabled); - buf.writeBoolean(this.wasActiveAndNeedsUpdate); - } - - /** - * reads all needed values from InitialSyncData - * This MUST be called and returned in the MetaTileEntity's {@link MetaTileEntity#receiveInitialSyncData(PacketBuffer)} method - */ - public void receiveInitialSyncData(@Nonnull PacketBuffer buf) { - this.pipeLength = buf.readInt(); - setActive(buf.readBoolean()); - setWorkingEnabled(buf.readBoolean()); - setWasActiveAndNeedsUpdate(buf.readBoolean()); - } - - /** - * reads all needed values from CustomData - * This MUST be called and returned in the MetaTileEntity's {@link MetaTileEntity#receiveCustomData(int, PacketBuffer)} method - */ - public void receiveCustomData(int dataId, PacketBuffer buf) { - if (dataId == GregtechDataCodes.PUMP_HEAD_LEVEL) { - this.pipeLength = buf.readInt(); - metaTileEntity.scheduleRenderUpdate(); - } else if (dataId == GregtechDataCodes.WORKABLE_ACTIVE) { - this.isActive = buf.readBoolean(); - metaTileEntity.scheduleRenderUpdate(); - } else if (dataId == GregtechDataCodes.WORKING_ENABLED) { - this.isWorkingEnabled = buf.readBoolean(); - metaTileEntity.scheduleRenderUpdate(); - } - } - - /** - * @return the current x value - */ - public AtomicInteger getX() { - return x; - } - - /** - * @return the current y value - */ - public AtomicInteger getY() { - return y; - } - - /** - * @return the current z value - */ - public AtomicInteger getZ() { - return z; - } - - /** - * @return the previously mined x value - */ - public AtomicInteger getMineX() { - return mineX; - } - - /** - * @return the previously mined y value - */ - public AtomicInteger getMineY() { - return mineY; - } - - /** - * @return the previously mined z value - */ - public AtomicInteger getMineZ() { - return mineZ; - } - - /** - * @return the starting x value - */ - public AtomicInteger getStartX() { - return startX; - } - - /** - * @return the starting y value - */ - public AtomicInteger getStartY() { - return startY; - } - - /** - * @return the starting z value - */ - public AtomicInteger getStartZ() { - return startZ; - } - - /** - * @return the pipe y value - */ - public AtomicInteger getPipeY() { - return pipeY; - } - - /** - * @return the miner's maximum radius - */ - public int getMaximumRadius() { - return this.maximumRadius; - } - - /** - * @return the miner's current radius - */ - public int getCurrentRadius() { - return this.currentRadius; - } - - /** - * @param currentRadius the radius to set the miner to use - */ - public void setCurrentRadius(int currentRadius) { - this.currentRadius = currentRadius; - } - - /** - * @return true if the miner is finished working - */ - public boolean isDone() { - return this.isDone; - } - - /** - * @return true if the miner is active - */ - public boolean isActive() { - return this.isActive; - } - - /** - * @param isActive the new state of the miner's activity: true to change to active, else false - */ - public void setActive(boolean isActive) { - if (this.isActive != isActive) { - this.isActive = isActive; - this.metaTileEntity.markDirty(); - if (metaTileEntity.getWorld() != null && !metaTileEntity.getWorld().isRemote) { - this.metaTileEntity.writeCustomData(GregtechDataCodes.WORKABLE_ACTIVE, buf -> buf.writeBoolean(isActive)); - } - } - } - - /** - * @param isWorkingEnabled the new state of the miner's ability to work: true to change to enabled, else false - */ - public void setWorkingEnabled(boolean isWorkingEnabled) { - if (this.isWorkingEnabled != isWorkingEnabled) { - this.isWorkingEnabled = isWorkingEnabled; - metaTileEntity.markDirty(); - if (metaTileEntity.getWorld() != null && !metaTileEntity.getWorld().isRemote) { - if (!isWorkingEnabled) resetArea(); - - this.metaTileEntity.writeCustomData(GregtechDataCodes.WORKING_ENABLED, buf -> buf.writeBoolean(isWorkingEnabled)); - } - } - } - - /** - * @return whether working is enabled for the logic - */ - public boolean isWorkingEnabled() { - return isWorkingEnabled; - } - - /** - * @return whether the miner is currently working - */ - public boolean isWorking() { - return isActive && isWorkingEnabled; - } - - /** - * @return whether the miner was active and needs an update - */ - public boolean wasActiveAndNeedsUpdate() { - return this.wasActiveAndNeedsUpdate; - } - - /** - * set whether the miner was active and needs an update - * - * @param wasActiveAndNeedsUpdate the state to set - */ - public void setWasActiveAndNeedsUpdate(boolean wasActiveAndNeedsUpdate) { - this.wasActiveAndNeedsUpdate = wasActiveAndNeedsUpdate; - } - - /** - * @return the miner's fortune level - */ - public int getFortune() { - return this.fortune; - } - - /** - * @return the miner's speed in ticks - */ - public int getSpeed() { - return this.speed; - } -} diff --git a/src/main/java/gregtech/api/capability/impl/miner/MultiblockMinerLogic.java b/src/main/java/gregtech/api/capability/impl/miner/MultiblockMinerLogic.java deleted file mode 100644 index 5b30ee22606..00000000000 --- a/src/main/java/gregtech/api/capability/impl/miner/MultiblockMinerLogic.java +++ /dev/null @@ -1,154 +0,0 @@ -package gregtech.api.capability.impl.miner; - -import gregtech.api.metatileentity.MetaTileEntity; -import gregtech.api.metatileentity.multiblock.MultiblockControllerBase; -import gregtech.api.recipes.RecipeMap; -import gregtech.client.renderer.ICubeRenderer; -import net.minecraft.block.state.IBlockState; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.network.PacketBuffer; -import net.minecraft.util.NonNullList; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.ChunkPos; -import net.minecraft.world.WorldServer; -import net.minecraft.world.chunk.Chunk; -import net.minecraftforge.fml.relauncher.Side; -import net.minecraftforge.fml.relauncher.SideOnly; - -import javax.annotation.Nonnull; - -public class MultiblockMinerLogic extends MinerLogic { - - private static final int CHUNK_LENGTH = 16; - - private final RecipeMap blockDropRecipeMap; - - private int voltageTier; - private int overclockAmount = 0; - - private boolean isChunkMode; - private boolean isSilkTouchMode; - - /** - * Creates the logic for multiblock ore block miners - * - * @param metaTileEntity the {@link MetaTileEntity} this logic belongs to - * @param fortune the fortune amount to apply when mining ores - * @param speed the speed in ticks per block mined - * @param maximumRadius the maximum radius (square shaped) the miner can mine in - */ - public MultiblockMinerLogic(MetaTileEntity metaTileEntity, int fortune, int speed, int maximumRadius, RecipeMap blockDropRecipeMap) { - super(metaTileEntity, fortune, speed, maximumRadius, null); - this.blockDropRecipeMap = blockDropRecipeMap; - } - - @Override - protected boolean drainStorages(boolean simulate) { - return super.drainStorages(simulate) && miner.drainFluid(simulate); - } - - @Override - protected void getSmallOreBlockDrops(NonNullList blockDrops, WorldServer world, BlockPos blockToMine, IBlockState blockState) { - // Small ores: use (fortune bonus + overclockAmount) value here for fortune, since every overclock increases the yield for small ores - super.getSmallOreBlockDrops(blockDrops, world, blockToMine, blockState); - } - - @Override - protected void getRegularBlockDrops(NonNullList blockDrops, WorldServer world, BlockPos blockToMine, @Nonnull IBlockState blockState) { - if (!isSilkTouchMode) // 3X the ore compared to the single blocks - applyTieredHammerNoRandomDrops(blockState, blockDrops, 3, this.blockDropRecipeMap, this.voltageTier); - else - super.getRegularBlockDrops(blockDrops, world, blockToMine, blockState); - } - - @Override - public void initPos(@Nonnull BlockPos pos, int currentRadius) { - if (!isChunkMode) { - super.initPos(pos, currentRadius); - } else { - WorldServer world = (WorldServer) this.metaTileEntity.getWorld(); - Chunk origin = world.getChunk(this.metaTileEntity.getPos()); - ChunkPos startPos = (world.getChunk(origin.x - currentRadius / CHUNK_LENGTH, origin.z - currentRadius / CHUNK_LENGTH)).getPos(); - getX().set(startPos.getXStart()); - getY().set(this.metaTileEntity.getPos().getY() - 1); - getZ().set(startPos.getZStart()); - getStartX().set(startPos.getXStart()); - getStartY().set(this.metaTileEntity.getPos().getY()); - getStartZ().set(startPos.getZStart()); - getMineX().set(startPos.getXStart()); - getMineY().set(this.metaTileEntity.getPos().getY() - 1); - getMineZ().set(startPos.getZStart()); - getPipeY().set(this.metaTileEntity.getPos().getY() - 1); - } - } - - public void setVoltageTier(int tier) { - this.voltageTier = tier; - } - - public void setOverclockAmount(int amount) { - this.overclockAmount = amount; - } - - public int getOverclockAmount() { - return this.overclockAmount; - } - - public boolean isChunkMode() { - return this.isChunkMode; - } - - public void setChunkMode(boolean isChunkMode) { - if (!isWorking()) { - this.isChunkMode = isChunkMode; - if (!metaTileEntity.getWorld().isRemote) { - resetArea(); - } - } - } - - public boolean isSilkTouchMode() { - return this.isSilkTouchMode; - } - - public void setSilkTouchMode(boolean isSilkTouchMode) { - if (!isWorking()) { - this.isSilkTouchMode = isSilkTouchMode; - } - } - - @SideOnly(Side.CLIENT) - @Override - protected ICubeRenderer getPipeTexture() { - return ((MultiblockControllerBase) metaTileEntity).getBaseTexture(null); - } - - @Override - public NBTTagCompound writeToNBT(@Nonnull NBTTagCompound data) { - data.setBoolean("isChunkMode", isChunkMode); - data.setBoolean("isSilkTouchMode", isSilkTouchMode); - return super.writeToNBT(data); - } - - @Override - public void readFromNBT(@Nonnull NBTTagCompound data) { - this.isChunkMode = data.getBoolean("isChunkMode"); - this.isSilkTouchMode = data.getBoolean("isSilkTouchMode"); - super.readFromNBT(data); - } - - @Override - public void writeInitialSyncData(@Nonnull PacketBuffer buf) { - super.writeInitialSyncData(buf); - buf.writeBoolean(this.isChunkMode); - buf.writeBoolean(this.isSilkTouchMode); - } - - @Override - public void receiveInitialSyncData(@Nonnull PacketBuffer buf) { - super.receiveInitialSyncData(buf); - this.isChunkMode = buf.readBoolean(); - this.isSilkTouchMode = buf.readBoolean(); - } -} diff --git a/src/main/java/gregtech/api/capability/impl/miner/SteamMinerLogic.java b/src/main/java/gregtech/api/capability/impl/miner/SteamMinerLogic.java deleted file mode 100644 index 7557f1fbf63..00000000000 --- a/src/main/java/gregtech/api/capability/impl/miner/SteamMinerLogic.java +++ /dev/null @@ -1,38 +0,0 @@ -package gregtech.api.capability.impl.miner; - -import gregtech.api.capability.IVentable; -import gregtech.api.metatileentity.MetaTileEntity; -import gregtech.client.renderer.ICubeRenderer; - -public class SteamMinerLogic extends MinerLogic { - - /** - * Creates the logic for steam miners - * - * @param metaTileEntity the {@link MetaTileEntity} this logic belongs to - * @param fortune the fortune amount to apply when mining ores - * @param speed the speed in ticks per block mined - * @param maximumRadius the maximum radius (square shaped) the miner can mine in - */ - public SteamMinerLogic(MetaTileEntity metaTileEntity, int fortune, int speed, int maximumRadius, ICubeRenderer pipeTexture) { - super(metaTileEntity, fortune, speed, maximumRadius, pipeTexture); - } - - @Override - protected boolean checkCanMine() { - IVentable machine = (IVentable) metaTileEntity; - if (machine.isNeedsVenting()) { - machine.tryDoVenting(); - if (machine.isVentingStuck()) - return false; - } - - return super.checkCanMine(); - } - - @Override - protected void onMineOperation() { - super.onMineOperation(); - ((IVentable) metaTileEntity).setNeedsVenting(true); - } -} diff --git a/src/main/java/gregtech/api/unification/OreDictUnifier.java b/src/main/java/gregtech/api/unification/OreDictUnifier.java index 5ecea0be0d9..58a048eb812 100644 --- a/src/main/java/gregtech/api/unification/OreDictUnifier.java +++ b/src/main/java/gregtech/api/unification/OreDictUnifier.java @@ -179,11 +179,15 @@ public static void onItemRegistration(OreRegisterEvent event) { @Nonnull public static Set getOreDictionaryNames(@Nonnull ItemStack itemStack) { if (itemStack.isEmpty()) return Collections.emptySet(); - ItemVariantMap> nameEntry = stackOreDictName.get(itemStack.getItem()); + return getOreDictionaryNames(itemStack.getItem(), itemStack.getItemDamage()); + } + + @Nonnull + public static Set getOreDictionaryNames(@Nonnull Item item, int metadata) { + ItemVariantMap> nameEntry = stackOreDictName.get(item); if (nameEntry == null) return Collections.emptySet(); - short itemDamage = (short) itemStack.getItemDamage(); - Set names = nameEntry.get(itemDamage); - Set wildcardNames = itemDamage == GTValues.W ? null : nameEntry.get(GTValues.W); + Set names = nameEntry.get((short) metadata); + Set wildcardNames = metadata == GTValues.W ? null : nameEntry.get(GTValues.W); if (names == null) { return wildcardNames == null ? Collections.emptySet() : Collections.unmodifiableSet(wildcardNames); } else if (wildcardNames == null || names == wildcardNames) { // single variant items have identical entries @@ -232,8 +236,12 @@ public static List getAllWithOreDictionaryName(String oreDictionaryNa @Nullable public static MaterialStack getMaterial(ItemStack itemStack) { - if (itemStack.isEmpty()) return null; - ItemAndMetadata key = new ItemAndMetadata(itemStack); + return itemStack.isEmpty() ? null : getMaterial(itemStack.getItem(), itemStack.getItemDamage()); + } + + @Nullable + public static MaterialStack getMaterial(@Nonnull Item item, int metadata) { + ItemAndMetadata key = new ItemAndMetadata(item, metadata); UnificationEntry entry = getOrWildcard(stackUnificationInfo, key); if (entry != null) { Material entryMaterial = entry.material; @@ -255,9 +263,13 @@ public static ItemMaterialInfo getMaterialInfo(ItemStack itemStack) { } @Nullable - public static OrePrefix getPrefix(ItemStack itemStack) { - if (itemStack.isEmpty()) return null; - UnificationEntry entry = getOrWildcard(stackUnificationInfo, new ItemAndMetadata(itemStack)); + public static OrePrefix getPrefix(@Nonnull ItemStack itemStack) { + return itemStack.isEmpty() ? null : getPrefix(itemStack.getItem(), itemStack.getItemDamage()); + } + + @Nullable + public static OrePrefix getPrefix(@Nonnull Item item, int metadata) { + UnificationEntry entry = getOrWildcard(stackUnificationInfo, new ItemAndMetadata(item, metadata)); return entry != null ? entry.orePrefix : null; } diff --git a/src/main/java/gregtech/api/unification/stack/ItemAndMetadata.java b/src/main/java/gregtech/api/unification/stack/ItemAndMetadata.java index 22880b79cca..4e63caefca9 100644 --- a/src/main/java/gregtech/api/unification/stack/ItemAndMetadata.java +++ b/src/main/java/gregtech/api/unification/stack/ItemAndMetadata.java @@ -43,20 +43,12 @@ public ItemAndMetadata toWildcard() { @Override public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof ItemAndMetadata)) return false; - - ItemAndMetadata that = (ItemAndMetadata) o; - - if (itemDamage != that.itemDamage) return false; - return item.equals(that.item); + return this == o || o instanceof ItemAndMetadata that && itemDamage == that.itemDamage && item.equals(that.item); } @Override public int hashCode() { - int result = item.hashCode(); - result = 31 * result + itemDamage; - return result; + return 31 * item.hashCode() + itemDamage; } @Override diff --git a/src/main/java/gregtech/api/util/BlockUtility.java b/src/main/java/gregtech/api/util/BlockUtility.java index 70a75f0c0dd..27b690361b9 100644 --- a/src/main/java/gregtech/api/util/BlockUtility.java +++ b/src/main/java/gregtech/api/util/BlockUtility.java @@ -1,15 +1,52 @@ package gregtech.api.util; +import gregtech.api.unification.OreDictUnifier; +import gregtech.api.unification.ore.OrePrefix; +import it.unimi.dsi.fastutil.objects.Object2BooleanMap; +import it.unimi.dsi.fastutil.objects.Object2BooleanOpenHashMap; import net.minecraft.block.Block; import net.minecraft.block.material.Material; +import net.minecraft.block.state.IBlockState; +import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.NonNullList; import javax.annotation.Nonnull; +import java.util.Objects; public class BlockUtility { private static final BlockWrapper WRAPPER = new BlockWrapper(); + private static final Object2BooleanMap ORE_CACHE = new Object2BooleanOpenHashMap<>(); + + public static void startCaptureDrops() { + WRAPPER.captureDrops(true); + } + + @Nonnull + public static NonNullList stopCaptureDrops() { + return WRAPPER.captureDrops(false); + } + + public static boolean isOre(@Nonnull IBlockState state) { + return ORE_CACHE.computeIfAbsent(Objects.requireNonNull(state, "state == null"), s -> { + Item item = Item.getItemFromBlock(s.getBlock()); + int meta = s.getBlock().getMetaFromState(s); + OrePrefix orePrefix = OreDictUnifier.getPrefix(item, meta); + return orePrefix != null && orePrefix.name().startsWith("ore"); + }); + } + + /** + * Mark a block state as an ore / not an ore, for miners and prospectors. + * + * @param state A block state + * @param isOre Whether this block state is an ore or not + * @throws NullPointerException if {@code state == null} + */ + public static void markBlockstateAsOre(@Nonnull IBlockState state, boolean isOre) { + ORE_CACHE.put(Objects.requireNonNull(state, "state == null"), isOre); + } private static class BlockWrapper extends Block { @@ -23,13 +60,4 @@ public NonNullList captureDrops(boolean start) { return super.captureDrops(start); } } - - public static void startCaptureDrops() { - WRAPPER.captureDrops(true); - } - - public static NonNullList stopCaptureDrops() { - return WRAPPER.captureDrops(false); - } - } diff --git a/src/main/java/gregtech/api/util/GTUtility.java b/src/main/java/gregtech/api/util/GTUtility.java index 8b4c45cbf20..09a00e0a5b3 100644 --- a/src/main/java/gregtech/api/util/GTUtility.java +++ b/src/main/java/gregtech/api/util/GTUtility.java @@ -6,6 +6,7 @@ import gregtech.api.block.machines.MachineItemBlock; import gregtech.api.capability.IMultipleTankHandler; import gregtech.api.cover.CoverDefinition; +import gregtech.api.damagesources.DamageSources; import gregtech.api.items.metaitem.MetaItem; import gregtech.api.items.metaitem.stats.IItemBehaviour; import gregtech.api.items.toolitem.ToolClasses; @@ -17,12 +18,16 @@ import gregtech.api.unification.OreDictUnifier; import gregtech.api.unification.ore.OrePrefix; import gregtech.common.items.behaviors.CoverPlaceBehavior; +import gregtech.core.advancement.AdvancementTriggers; import it.unimi.dsi.fastutil.objects.ObjectOpenCustomHashSet; +import net.minecraft.block.Block; import net.minecraft.block.BlockRedstoneWire; import net.minecraft.block.BlockSnow; import net.minecraft.block.material.MapColor; import net.minecraft.block.state.IBlockState; import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.init.Blocks; import net.minecraft.init.SoundEvents; import net.minecraft.inventory.Slot; @@ -31,13 +36,12 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.EnumFacing; -import net.minecraft.util.NonNullList; -import net.minecraft.util.ResourceLocation; -import net.minecraft.util.SoundCategory; +import net.minecraft.util.*; +import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; +import net.minecraft.world.WorldServer; import net.minecraft.world.biome.Biome; import net.minecraftforge.common.BiomeDictionary; import net.minecraftforge.common.util.Constants; @@ -606,7 +610,11 @@ public static ItemStack toItem(IBlockState state, int amount) { return new ItemStack(state.getBlock(), amount, state.getBlock().getMetaFromState(state)); } - public static boolean isOre(ItemStack item) { + /** + * @deprecated use {@link BlockUtility#isOre(IBlockState)} or check it yourself + */ + @Deprecated + public static boolean isOre(@Nonnull ItemStack item) { OrePrefix orePrefix = OreDictUnifier.getPrefix(item); return orePrefix != null && orePrefix.name().startsWith("ore"); } @@ -751,6 +759,53 @@ public static boolean isBlockSnowLayer(@Nonnull IBlockState blockState) { return blockState.getBlock() == Blocks.SNOW_LAYER && blockState.getValue(BlockSnow.LAYERS) == 1; } + /** + * Try to vent. Also does venting things (spawning particles, playing sounds, damaging entities etc.) on success. + * + * @param world World + * @param machinePos Position of the machine + * @param ventingSide Venting side + * @param ventingDamage Damage to be applied on entities in the venting block; default value is {@code 6} for + * regular steam machines, and {@code 12} for high-pressure steam machines. + * @param spawnParticle Whether to spawn particles or not + * @param playSound Whether to play sounds or not + * @return {@code true} if vented + */ + public static boolean tryVenting(@Nonnull World world, @Nonnull BlockPos machinePos, + @Nonnull EnumFacing ventingSide, float ventingDamage, + boolean spawnParticle, boolean playSound) { + BlockPos ventingPos = machinePos.offset(ventingSide); + IBlockState ventingState = world.getBlockState(ventingPos); + if (ventingState.getCollisionBoundingBox(world, ventingPos) == Block.NULL_AABB || + tryBreakSnowLayer(world, ventingPos, ventingState, false)) { + if (ventingDamage > 0) { + for (EntityLivingBase entity : world.getEntitiesWithinAABB(EntityLivingBase.class, + new AxisAlignedBB(ventingPos), EntitySelectors.CAN_AI_TARGET)) { + entity.attackEntityFrom(DamageSources.getHeatDamage(), ventingDamage); + if (entity instanceof EntityPlayerMP player) { + AdvancementTriggers.STEAM_VENT_DEATH.trigger(player); + } + } + } + double posX = machinePos.getX() + 0.5 + ventingSide.getXOffset() * 0.6; + double posY = machinePos.getY() + 0.5 + ventingSide.getYOffset() * 0.6; + double posZ = machinePos.getZ() + 0.5 + ventingSide.getZOffset() * 0.6; + + if (spawnParticle && world instanceof WorldServer worldServer) { + worldServer.spawnParticle(EnumParticleTypes.CLOUD, posX, posY, posZ, + 7 + world.rand.nextInt(3), + ventingSide.getXOffset() / 2.0, + ventingSide.getYOffset() / 2.0, + ventingSide.getZOffset() / 2.0, 0.1); + } + if (playSound) { + world.playSound(null, posX, posY, posZ, SoundEvents.BLOCK_LAVA_EXTINGUISH, SoundCategory.BLOCKS, 1.0f, 1.0f); + } + return true; + } + return false; + } + /** * Attempt to break a (single) snow layer at the given BlockPos. * diff --git a/src/main/java/gregtech/common/metatileentities/MetaTileEntities.java b/src/main/java/gregtech/common/metatileentities/MetaTileEntities.java index 86137d601e0..ee5030ce9b5 100644 --- a/src/main/java/gregtech/common/metatileentities/MetaTileEntities.java +++ b/src/main/java/gregtech/common/metatileentities/MetaTileEntities.java @@ -20,6 +20,10 @@ import gregtech.common.blocks.MetaBlocks; import gregtech.common.metatileentities.converter.MetaTileEntityConverter; import gregtech.common.metatileentities.electric.*; +import gregtech.common.metatileentities.miner.MetaTileEntityLargeMiner; +import gregtech.common.metatileentities.miner.MetaTileEntityLargeMiner.LargeMinerType; +import gregtech.common.metatileentities.miner.MetaTileEntityMiner; +import gregtech.common.metatileentities.miner.SteamMiner; import gregtech.common.metatileentities.multi.*; import gregtech.common.metatileentities.multi.electric.*; import gregtech.common.metatileentities.multi.electric.centralmonitor.MetaTileEntityCentralMonitor; @@ -308,7 +312,7 @@ public static void init() { STEAM_ROCK_BREAKER_BRONZE = registerMetaTileEntity(19, new SteamRockBreaker(gregtechId("steam_rock_breaker_bronze"), false)); STEAM_ROCK_BREAKER_STEEL = registerMetaTileEntity(20, new SteamRockBreaker(gregtechId("steam_rock_breaker_steel"), true)); - STEAM_MINER = registerMetaTileEntity(21, new SteamMiner(gregtechId("steam_miner"), 320, 4, 0)); + STEAM_MINER = registerMetaTileEntity(21, new SteamMiner(gregtechId("steam_miner"), 320, 4)); // Electric Furnace, IDs 50-64 registerSimpleMetaTileEntity(ELECTRIC_FURNACE, 50, "electric_furnace", RecipeMaps.FURNACE_RECIPES, Textures.ELECTRIC_FURNACE_OVERLAY, true); @@ -448,9 +452,9 @@ public static void init() { // Chunk Miner, IDs 920-934 - MINER[0] = registerMetaTileEntity(920, new MetaTileEntityMiner(gregtechId("miner.lv"), 1, 160, 8, 1)); - MINER[1] = registerMetaTileEntity(921, new MetaTileEntityMiner(gregtechId("miner.mv"), 2, 80, 16, 2)); - MINER[2] = registerMetaTileEntity(922, new MetaTileEntityMiner(gregtechId("miner.hv"), 3, 40, 24, 3)); + MINER[0] = registerMetaTileEntity(920, new MetaTileEntityMiner(gregtechId("miner.lv"), 1, 160, 17)); + MINER[1] = registerMetaTileEntity(921, new MetaTileEntityMiner(gregtechId("miner.mv"), 2, 80, 33)); + MINER[2] = registerMetaTileEntity(922, new MetaTileEntityMiner(gregtechId("miner.hv"), 3, 40, 49)); // Diesel Generator, IDs 935-949 COMBUSTION_GENERATOR[0] = registerMetaTileEntity(935, new SimpleGeneratorMetaTileEntity(gregtechId("combustion_generator.lv"), RecipeMaps.COMBUSTION_GENERATOR_FUELS, Textures.COMBUSTION_GENERATOR_OVERLAY, 1, GTUtility.genericGeneratorTankSizeFunction)); @@ -516,9 +520,9 @@ public static void init() { STEAM_OVEN = registerMetaTileEntity(1024, new MetaTileEntitySteamOven(gregtechId("steam_oven"))); STEAM_GRINDER = registerMetaTileEntity(1025, new MetaTileEntitySteamGrinder(gregtechId("steam_grinder"))); - BASIC_LARGE_MINER = registerMetaTileEntity(1026, new MetaTileEntityLargeMiner(gregtechId("large_miner.ev"), GTValues.EV, 16, 3, 4, Materials.Steel, 8)); - LARGE_MINER = registerMetaTileEntity(1027, new MetaTileEntityLargeMiner(gregtechId("large_miner.iv"), GTValues.IV, 4, 5, 5, Materials.Titanium, 16)); - ADVANCED_LARGE_MINER = registerMetaTileEntity(1028, new MetaTileEntityLargeMiner(gregtechId("large_miner.luv"), GTValues.LuV, 1, 7, 6, Materials.TungstenSteel, 32)); + BASIC_LARGE_MINER = registerMetaTileEntity(1026, new MetaTileEntityLargeMiner(gregtechId("large_miner.ev"), GTValues.EV, 16, 3, 4, 8, LargeMinerType.STEEL)); + LARGE_MINER = registerMetaTileEntity(1027, new MetaTileEntityLargeMiner(gregtechId("large_miner.iv"), GTValues.IV, 4, 5, 5, 16, LargeMinerType.TITANIUM)); + ADVANCED_LARGE_MINER = registerMetaTileEntity(1028, new MetaTileEntityLargeMiner(gregtechId("large_miner.luv"), GTValues.LuV, 1, 7, 6, 32, LargeMinerType.TUNGSTEN_STEEL)); CENTRAL_MONITOR = registerMetaTileEntity(1029, new MetaTileEntityCentralMonitor(gregtechId("central_monitor"))); @@ -880,7 +884,7 @@ public static void registerMetaTileEntities( } public static T registerMetaTileEntity(int id, T sampleMetaTileEntity) { - if (sampleMetaTileEntity instanceof IMultiblockAbilityPart abilityPart) { + if (sampleMetaTileEntity instanceof IMultiblockAbilityPart abilityPart) { MultiblockAbility.registerMultiblockAbility(abilityPart.getAbility(), sampleMetaTileEntity); } if (sampleMetaTileEntity instanceof MultiblockControllerBase && Loader.isModLoaded(GTValues.MODID_JEI)) { diff --git a/src/main/java/gregtech/common/metatileentities/miner/IMiner.java b/src/main/java/gregtech/common/metatileentities/miner/IMiner.java new file mode 100644 index 00000000000..97e8c936f79 --- /dev/null +++ b/src/main/java/gregtech/common/metatileentities/miner/IMiner.java @@ -0,0 +1,19 @@ +package gregtech.common.metatileentities.miner; + +import gregtech.client.renderer.ICubeRenderer; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +public interface IMiner { + + /** + * Try to drain all mining resources required for one operation. (e.g. energy, mining fluids) + * + * @param simulate Whether this action shouldn't affect the state + * @return Whether the action succeeded + */ + boolean drainMiningResources(boolean simulate); + + @SideOnly(Side.CLIENT) + ICubeRenderer getPipeTexture(); +} diff --git a/src/main/java/gregtech/common/metatileentities/multi/electric/MetaTileEntityLargeMiner.java b/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityLargeMiner.java similarity index 50% rename from src/main/java/gregtech/common/metatileentities/multi/electric/MetaTileEntityLargeMiner.java rename to src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityLargeMiner.java index 299e081aa3c..b640d41fe56 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/electric/MetaTileEntityLargeMiner.java +++ b/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityLargeMiner.java @@ -1,4 +1,4 @@ -package gregtech.common.metatileentities.multi.electric; +package gregtech.common.metatileentities.miner; import codechicken.lib.raytracer.CuboidRayTraceResult; import codechicken.lib.render.CCRenderState; @@ -6,11 +6,13 @@ import codechicken.lib.vec.Matrix4; import com.google.common.collect.Lists; import gregtech.api.GTValues; -import gregtech.api.capability.*; +import gregtech.api.capability.GregtechTileCapabilities; +import gregtech.api.capability.IControllable; +import gregtech.api.capability.IEnergyContainer; +import gregtech.api.capability.IMultipleTankHandler; import gregtech.api.capability.impl.EnergyContainerList; import gregtech.api.capability.impl.FluidTankList; import gregtech.api.capability.impl.ItemHandlerList; -import gregtech.api.capability.impl.miner.MultiblockMinerLogic; import gregtech.api.gui.GuiTextures; import gregtech.api.gui.ModularUI; import gregtech.api.gui.Widget; @@ -27,26 +29,26 @@ import gregtech.api.pattern.PatternMatchContext; import gregtech.api.pattern.TraceabilityPredicate; import gregtech.api.recipes.RecipeMaps; -import gregtech.api.unification.material.Material; import gregtech.api.unification.material.Materials; import gregtech.api.util.GTUtility; import gregtech.client.renderer.ICubeRenderer; import gregtech.client.renderer.texture.Textures; -import gregtech.common.blocks.BlockMetalCasing; +import gregtech.common.blocks.BlockMetalCasing.MetalCasingType; import gregtech.common.blocks.MetaBlocks; import gregtech.core.sound.GTSoundEvents; -import net.minecraft.block.state.IBlockState; import net.minecraft.client.resources.I18n; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagInt; import net.minecraft.network.PacketBuffer; import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumHand; import net.minecraft.util.ResourceLocation; import net.minecraft.util.SoundEvent; -import net.minecraft.util.text.*; +import net.minecraft.util.text.ITextComponent; +import net.minecraft.util.text.Style; +import net.minecraft.util.text.TextComponentTranslation; +import net.minecraft.util.text.TextFormatting; import net.minecraft.world.World; import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.fluids.FluidStack; @@ -54,75 +56,58 @@ import net.minecraftforge.fml.relauncher.SideOnly; import net.minecraftforge.items.IItemHandlerModifiable; import net.minecraftforge.items.ItemStackHandler; -import org.jetbrains.annotations.NotNull; import javax.annotation.Nonnull; import javax.annotation.Nullable; import java.util.Collections; import java.util.List; +import java.util.Objects; import static gregtech.api.unification.material.Materials.DrillingFluid; public class MetaTileEntityLargeMiner extends MultiblockWithDisplayBase implements IMiner, IControllable, IDataInfoProvider { - private static final int CHUNK_LENGTH = 16; - - private final Material material; - private final int tier; + @Nonnull + public final ILargeMinerType type; + public final int tier; + public final int drillingFluidConsumePerTick; + private final MultiblockMinerLogic minerLogic; private IEnergyContainer energyContainer; protected IMultipleTankHandler inputFluidInventory; protected IItemHandlerModifiable outputInventory; - private boolean silkTouch = false; - private boolean chunkMode = false; - - private boolean isInventoryFull = false; - - private final int drillingFluidConsumePerTick; - - private final MultiblockMinerLogic minerLogic; - - public MetaTileEntityLargeMiner(ResourceLocation metaTileEntityId, int tier, int speed, int maximumChunkDiameter, int fortune, Material material, int drillingFluidConsumePerTick) { + public MetaTileEntityLargeMiner(ResourceLocation metaTileEntityId, int tier, int speed, int maxChunkDiameter, + int fortune, int drillingFluidConsumePerTick, @Nonnull ILargeMinerType type) { super(metaTileEntityId); - this.material = material; + this.type = Objects.requireNonNull(type, "type == null"); this.tier = tier; this.drillingFluidConsumePerTick = drillingFluidConsumePerTick; - this.minerLogic = new MultiblockMinerLogic(this, fortune, speed, maximumChunkDiameter * CHUNK_LENGTH / 2, RecipeMaps.MACERATOR_RECIPES); + this.minerLogic = new MultiblockMinerLogic(this, fortune, speed, maxChunkDiameter, RecipeMaps.MACERATOR_RECIPES); } @Override public MetaTileEntity createMetaTileEntity(IGregTechTileEntity tileEntity) { - return new MetaTileEntityLargeMiner(metaTileEntityId, this.tier, this.minerLogic.getSpeed(), this.minerLogic.getMaximumRadius() * 2 / CHUNK_LENGTH, this.minerLogic.getFortune(), getMaterial(), getDrillingFluidConsumePerTick()); + return new MetaTileEntityLargeMiner(metaTileEntityId, this.tier, this.minerLogic.getWorkFrequency(), + this.minerLogic.getMaximumChunkDiameter(), + this.minerLogic.getFortune(), this.drillingFluidConsumePerTick, this.type); } @Override public void invalidateStructure() { super.invalidateStructure(); - resetTileAbilities(); - if (this.minerLogic.isActive()) - this.minerLogic.setActive(false); + this.inputFluidInventory = new FluidTankList(true); + this.outputInventory = new ItemStackHandler(0); + this.energyContainer = new EnergyContainerList(Lists.newArrayList()); } @Override protected void formStructure(PatternMatchContext context) { super.formStructure(context); - initializeAbilities(); - } - - private void initializeAbilities() { this.inputFluidInventory = new FluidTankList(false, getAbilities(MultiblockAbility.IMPORT_FLUIDS)); this.outputInventory = new ItemHandlerList(getAbilities(MultiblockAbility.EXPORT_ITEMS)); this.energyContainer = new EnergyContainerList(getAbilities(MultiblockAbility.INPUT_ENERGY)); - this.minerLogic.setVoltageTier(GTUtility.getTierByVoltage(this.energyContainer.getInputVoltage())); - this.minerLogic.setOverclockAmount(Math.max(1, GTUtility.getTierByVoltage(this.energyContainer.getInputVoltage()) - this.tier)); - this.minerLogic.initPos(getPos(), this.minerLogic.getCurrentRadius()); - } - - private void resetTileAbilities() { - this.inputFluidInventory = new FluidTankList(true); - this.outputInventory = new ItemStackHandler(0); - this.energyContainer = new EnergyContainerList(Lists.newArrayList()); + this.minerLogic.reset(); } public int getEnergyTier() { @@ -131,31 +116,44 @@ public int getEnergyTier() { } @Override - public boolean drainEnergy(boolean simulate) { + public boolean drainMiningResources(boolean simulate) { + if (!drainEnergy(true) || !drainFluid(true)) { + return false; + } + if (!simulate) { + drainEnergy(false); + drainFluid(false); + } + return true; + } + + protected boolean drainEnergy(boolean simulate) { long energyToDrain = GTValues.VA[getEnergyTier()]; long resultEnergy = energyContainer.getEnergyStored() - energyToDrain; if (resultEnergy >= 0L && resultEnergy <= energyContainer.getEnergyCapacity()) { - if (!simulate) + if (!simulate) { energyContainer.changeEnergy(-energyToDrain); + } return true; } return false; } - @Override - public boolean drainFluid(boolean simulate) { - FluidStack drillingFluid = DrillingFluid.getFluid(this.drillingFluidConsumePerTick * this.minerLogic.getOverclockAmount()); - FluidStack fluidStack = inputFluidInventory.getTankAt(0).getFluid(); - if (fluidStack != null && fluidStack.isFluidEqual(DrillingFluid.getFluid(1)) && fluidStack.amount >= drillingFluid.amount) { - if (!simulate) - inputFluidInventory.drain(drillingFluid, true); - return true; - } - return false; + protected boolean drainFluid(boolean simulate) { + int overclockAmount = getEnergyTier() - this.tier; + int amount = this.drillingFluidConsumePerTick * overclockAmount; + FluidStack drained = this.inputFluidInventory.drain(DrillingFluid.getFluid(amount), !simulate); + return drained != null && drained.amount >= amount; } + @Override @SideOnly(Side.CLIENT) + public ICubeRenderer getPipeTexture() { + return getBaseTexture(null); + } + @Override + @SideOnly(Side.CLIENT) public void renderMetaTileEntity(CCRenderState renderState, Matrix4 translation, IVertexOperation[] pipeline) { super.renderMetaTileEntity(renderState, translation, pipeline); this.getFrontOverlay().renderOrientedState(renderState, translation, pipeline, getFrontFacing(), this.minerLogic.isWorking(), this.isWorkingEnabled()); @@ -164,13 +162,10 @@ public void renderMetaTileEntity(CCRenderState renderState, Matrix4 translation, @Override protected void updateFormedValid() { - this.minerLogic.performMining(); - if (!getWorld().isRemote && this.minerLogic.wasActiveAndNeedsUpdate()) { - this.minerLogic.setWasActiveAndNeedsUpdate(false); - this.minerLogic.setActive(false); - } + this.minerLogic.update(); } + @Nonnull @Override protected BlockPattern createStructurePattern() { return FactoryBlockPattern.start() @@ -178,12 +173,12 @@ protected BlockPattern createStructurePattern() { .aisle("XXX", "FCF", "FCF", "FCF", "#F#", "#F#", "#F#") .aisle("XSX", "#F#", "#F#", "#F#", "###", "###", "###") .where('S', selfPredicate()) - .where('X', states(getCasingState()) + .where('X', this.type.getCasing() .or(abilities(MultiblockAbility.EXPORT_ITEMS).setMaxGlobalLimited(1).setPreviewCount(1)) .or(abilities(MultiblockAbility.IMPORT_FLUIDS).setExactLimit(1).setPreviewCount(1)) .or(abilities(MultiblockAbility.INPUT_ENERGY).setMinGlobalLimited(1).setMaxGlobalLimited(3).setPreviewCount(1))) - .where('C', states(getCasingState())) - .where('F', getFramePredicate()) + .where('C', this.type.getCasing()) + .where('F', this.type.getFrame()) .where('#', any()) .build(); } @@ -195,10 +190,10 @@ public String[] getDescription() { @Override public void addInformation(ItemStack stack, @Nullable World player, @Nonnull List tooltip, boolean advanced) { - int workingAreaChunks = this.minerLogic.getCurrentRadius() * 2 / CHUNK_LENGTH; + int workingAreaChunks = this.minerLogic.getMaximumChunkDiameter(); tooltip.add(I18n.format("gregtech.machine.miner.multi.modes")); tooltip.add(I18n.format("gregtech.machine.miner.multi.production")); - tooltip.add(I18n.format("gregtech.machine.miner.fluid_usage", getDrillingFluidConsumePerTick(), DrillingFluid.getLocalizedName())); + tooltip.add(I18n.format("gregtech.machine.miner.fluid_usage", this.drillingFluidConsumePerTick, DrillingFluid.getLocalizedName())); tooltip.add(I18n.format("gregtech.universal.tooltip.working_area_chunks_max", workingAreaChunks, workingAreaChunks)); tooltip.add(I18n.format("gregtech.universal.tooltip.energy_tier_range", GTValues.VNF[this.tier], GTValues.VNF[this.tier + 1])); } @@ -225,34 +220,8 @@ protected void addDisplayText(List textList) { textList.add(new TextComponentTranslation("gregtech.multiblock.max_energy_per_tick", maxVoltage, voltageName)); } - int workingAreaChunks = this.minerLogic.getCurrentRadius() * 2 / CHUNK_LENGTH; - int workingArea = getWorkingArea(minerLogic.getCurrentRadius()); - textList.add(new TextComponentTranslation("gregtech.machine.miner.startx", this.minerLogic.getX().get() == Integer.MAX_VALUE ? 0 : this.minerLogic.getX().get())); - textList.add(new TextComponentTranslation("gregtech.machine.miner.starty", this.minerLogic.getY().get() == Integer.MAX_VALUE ? 0 : this.minerLogic.getY().get())); - textList.add(new TextComponentTranslation("gregtech.machine.miner.startz", this.minerLogic.getZ().get() == Integer.MAX_VALUE ? 0 : this.minerLogic.getZ().get())); - if (this.minerLogic.isChunkMode()) { - textList.add(new TextComponentTranslation("gregtech.machine.miner.working_area_chunks", workingAreaChunks, workingAreaChunks)); - } else { - textList.add(new TextComponentTranslation("gregtech.machine.miner.working_area", workingArea, workingArea)); - } - if (this.minerLogic.isDone()) - textList.add(new TextComponentTranslation("gregtech.machine.miner.done").setStyle(new Style().setColor(TextFormatting.GREEN))); - else if (this.minerLogic.isWorking()) - textList.add(new TextComponentTranslation("gregtech.machine.miner.working").setStyle(new Style().setColor(TextFormatting.GOLD))); - else if (!this.isWorkingEnabled()) - textList.add(new TextComponentTranslation("gregtech.multiblock.work_paused")); - } - } - - private void addDisplayText2(List textList) { - if (this.isStructureFormed()) { - ITextComponent mCoords = new TextComponentString(" ") - .appendSibling(new TextComponentTranslation("gregtech.machine.miner.minex", this.minerLogic.getMineX().get())) - .appendText("\n ") - .appendSibling(new TextComponentTranslation("gregtech.machine.miner.miney", this.minerLogic.getMineY().get())) - .appendText("\n ") - .appendSibling(new TextComponentTranslation("gregtech.machine.miner.minez", this.minerLogic.getMineZ().get())); - textList.add(mCoords); + this.minerLogic.addMinerArea(textList); + this.minerLogic.addMinerWorkStatus(textList); } } @@ -260,9 +229,7 @@ private void addDisplayText2(List textList) { protected void addWarningText(List textList) { super.addWarningText(textList); if (isStructureFormed()) { - if (this.isInventoryFull) { - textList.add(new TextComponentTranslation("gregtech.machine.miner.invfull").setStyle(new Style().setColor(TextFormatting.RED))); - } + this.minerLogic.addInventoryStatus(textList); if (!drainFluid(true)) { textList.add(new TextComponentTranslation("gregtech.machine.miner.multi.needsfluid").setStyle(new Style().setColor(TextFormatting.RED))); } @@ -272,50 +239,18 @@ protected void addWarningText(List textList) { } } - public IBlockState getCasingState() { - if (this.material.equals(Materials.Titanium)) - return MetaBlocks.METAL_CASING.getState(BlockMetalCasing.MetalCasingType.TITANIUM_STABLE); - if (this.material.equals(Materials.TungstenSteel)) - return MetaBlocks.METAL_CASING.getState(BlockMetalCasing.MetalCasingType.TUNGSTENSTEEL_ROBUST); - return MetaBlocks.METAL_CASING.getState(BlockMetalCasing.MetalCasingType.STEEL_SOLID); - } - - @Nonnull - private TraceabilityPredicate getFramePredicate() { - if (this.material.equals(Materials.Titanium)) - return frames(Materials.Titanium); - if (this.material.equals(Materials.TungstenSteel)) - return frames(Materials.TungstenSteel); - return frames(Materials.Steel); - } - - @SideOnly(Side.CLIENT) - @Override - public ICubeRenderer getBaseTexture(IMultiblockPart sourcePart) { - if (this.material.equals(Materials.Titanium)) - return Textures.STABLE_TITANIUM_CASING; - if (this.material.equals(Materials.TungstenSteel)) - return Textures.ROBUST_TUNGSTENSTEEL_CASING; - return Textures.SOLID_STEEL_CASING; - } - @Override public NBTTagCompound writeToNBT(NBTTagCompound data) { super.writeToNBT(data); - data.setTag("chunkMode", new NBTTagInt(chunkMode ? 1 : 0)); - data.setTag("silkTouch", new NBTTagInt(silkTouch ? 1 : 0)); return this.minerLogic.writeToNBT(data); } @Override public void readFromNBT(NBTTagCompound data) { super.readFromNBT(data); - chunkMode = data.getInteger("chunkMode") != 0; - silkTouch = data.getInteger("silkTouch") != 0; this.minerLogic.readFromNBT(data); } - @Override public void writeInitialSyncData(PacketBuffer buf) { super.writeInitialSyncData(buf); @@ -334,107 +269,74 @@ public void receiveCustomData(int dataId, PacketBuffer buf) { this.minerLogic.receiveCustomData(dataId, buf); } + + @Override @SideOnly(Side.CLIENT) + public ICubeRenderer getBaseTexture(@Nullable IMultiblockPart sourcePart) { + return this.type.getBaseTexture(sourcePart); + } + @Nonnull @Override + @SideOnly(Side.CLIENT) protected ICubeRenderer getFrontOverlay() { - if (this.tier == 5) - return Textures.LARGE_MINER_OVERLAY_ADVANCED; - if (this.tier == 6) - return Textures.LARGE_MINER_OVERLAY_ADVANCED_2; - return Textures.LARGE_MINER_OVERLAY_BASIC; - } - - public long getMaxVoltage() { - return GTValues.V[GTUtility.getTierByVoltage(energyContainer.getInputVoltage())]; + return this.type.getFrontOverlay(); } @Override protected ModularUI.Builder createUITemplate(EntityPlayer entityPlayer) { - ModularUI.Builder builder = super.createUITemplate(entityPlayer); - builder.widget(new AdvancedTextWidget(63, 31, this::addDisplayText2, 0xFFFFFF) - .setMaxWidthLimit(68).setClickHandler(this::handleDisplayClick)); - return builder; - } - - // used for UI - private int getCurrentMode() { - // 0 -> not chunk mode, not silk touch mode - if (!minerLogic.isChunkMode() && !minerLogic.isSilkTouchMode()) { - return 0; - } - // 1 -> is chunk mode, not silk touch mode - if (minerLogic.isChunkMode() && !minerLogic.isSilkTouchMode()) { - return 1; - } - // 2 -> not chunk mode, is silk touch mode - if (!minerLogic.isChunkMode() && minerLogic.isSilkTouchMode()) { - return 2; - } - // 3 -> is chunk mode, is silk touch mode - return 3; - } - - // used for UI - private void setCurrentMode(int mode) { - switch (mode) { - case 0 -> { - minerLogic.setChunkMode(false); - minerLogic.setSilkTouchMode(false); - } - case 1 -> { - minerLogic.setChunkMode(true); - minerLogic.setSilkTouchMode(false); - } - case 2 -> { - minerLogic.setChunkMode(false); - minerLogic.setSilkTouchMode(true); - } - default -> { - minerLogic.setChunkMode(true); - minerLogic.setSilkTouchMode(true); - } - } - } - - @Override - protected @NotNull Widget getFlexButton(int x, int y, int width, int height) { - return new ImageCycleButtonWidget(x, y, width, height, GuiTextures.BUTTON_MINER_MODES, 4, this::getCurrentMode, this::setCurrentMode) - .setTooltipHoverString(mode -> switch (mode) { - case 0 -> "gregtech.multiblock.miner.neither_mode"; - case 1 -> "gregtech.multiblock.miner.chunk_mode"; - case 2 -> "gregtech.multiblock.miner.silk_touch_mode"; - default -> "gregtech.multiblock.miner.both_modes"; - }); + return super.createUITemplate(entityPlayer) + .widget(new AdvancedTextWidget(63, 31 + 10, textList -> { + if (this.isStructureFormed()) { + this.minerLogic.addLastMinedBlock(textList); + } + }, 0xFFFFFF) + .setMaxWidthLimit(68 - 10) + .setClickHandler(this::handleDisplayClick)); } + @Nonnull @Override - public boolean onScrewdriverClick(EntityPlayer playerIn, EnumHand hand, EnumFacing facing, CuboidRayTraceResult hitResult) { - if (getWorld().isRemote || !this.isStructureFormed()) + protected Widget getFlexButton(int x, int y, int width, int height) { + return new ImageCycleButtonWidget(x, y, width, height, GuiTextures.BUTTON_MINER_MODES, 4, () -> { + int mode = 0; + if (minerLogic.isChunkMode()) mode |= 1; + if (minerLogic.isSilkTouchMode()) mode |= 2; + return mode; + }, m -> { + minerLogic.setChunkMode((m & 1) != 0); + minerLogic.setSilkTouchMode((m & 2) != 0); + }).setTooltipHoverString(m -> switch (m) { + case 0 -> "gregtech.multiblock.miner.neither_mode"; + case 1 -> "gregtech.multiblock.miner.chunk_mode"; + case 2 -> "gregtech.multiblock.miner.silk_touch_mode"; + default -> "gregtech.multiblock.miner.both_modes"; + }); + } + + @Override + public boolean onScrewdriverClick(EntityPlayer player, EnumHand hand, EnumFacing facing, CuboidRayTraceResult hitResult) { + if (getWorld().isRemote || !this.isStructureFormed()) { return true; + } if (!this.isActive()) { - int currentRadius = this.minerLogic.getCurrentRadius(); if (this.minerLogic.isChunkMode()) { - if (currentRadius - CHUNK_LENGTH <= 0) { - this.minerLogic.setCurrentRadius(this.minerLogic.getMaximumRadius()); - } else { - this.minerLogic.setCurrentRadius(currentRadius - CHUNK_LENGTH); - } - int workingAreaChunks = this.minerLogic.getCurrentRadius() * 2 / CHUNK_LENGTH; - playerIn.sendMessage(new TextComponentTranslation("gregtech.machine.miner.working_area_chunks", workingAreaChunks, workingAreaChunks)); + int currentChunkDiameter = this.minerLogic.getCurrentChunkDiameter(); + this.minerLogic.setCurrentChunkDiameter(currentChunkDiameter <= 1 ? + this.minerLogic.getMaximumChunkDiameter() : currentChunkDiameter - 1); + + int workingAreaChunks = this.minerLogic.getCurrentChunkDiameter(); + player.sendMessage(new TextComponentTranslation("gregtech.machine.miner.working_area_chunks", workingAreaChunks, workingAreaChunks)); } else { - if (currentRadius - CHUNK_LENGTH / 2 <= 0) { - this.minerLogic.setCurrentRadius(this.minerLogic.getMaximumRadius()); - } else { - this.minerLogic.setCurrentRadius(currentRadius - CHUNK_LENGTH / 2); - } - int workingArea = getWorkingArea(minerLogic.getCurrentRadius()); - playerIn.sendMessage(new TextComponentTranslation("gregtech.universal.tooltip.working_area", workingArea, workingArea)); + int diameter = this.minerLogic.getCurrentDiameter() - 8; + if(diameter <= 0) diameter = this.minerLogic.getMaximumDiameter(); + this.minerLogic.setCurrentDiameter(diameter); + + player.sendMessage(new TextComponentTranslation("gregtech.universal.tooltip.working_area", diameter, diameter)); } - this.minerLogic.resetArea(); } else { - playerIn.sendMessage(new TextComponentTranslation("gregtech.machine.miner.errorradius")); + player.sendMessage(new TextComponentTranslation("gregtech.machine.miner.errorradius")); } return true; } @@ -444,28 +346,6 @@ public boolean hasMaintenanceMechanics() { return false; } - @Override - public boolean isInventoryFull() { - return this.isInventoryFull; - } - - @Override - public void setInventoryFull(boolean isFull) { - this.isInventoryFull = isFull; - } - - public Material getMaterial() { - return material; - } - - public int getTier() { - return this.tier; - } - - public int getDrillingFluidConsumePerTick() { - return this.drillingFluidConsumePerTick; - } - @Override public boolean isWorkingEnabled() { return this.minerLogic.isWorkingEnabled(); @@ -476,10 +356,6 @@ public void setWorkingEnabled(boolean isActivationAllowed) { this.minerLogic.setWorkingEnabled(isActivationAllowed); } - public int getMaxChunkRadius() { - return this.minerLogic.getMaximumRadius() / CHUNK_LENGTH; - } - @Override public T getCapability(Capability capability, EnumFacing side) { if (capability == GregtechTileCapabilities.CAPABILITY_CONTROLLABLE) { @@ -500,18 +376,81 @@ public SoundEvent getSound() { @Override public boolean isActive() { - return minerLogic.isActive() && isWorkingEnabled(); + return isStructureFormed()&& minerLogic.isActive(); } @Nonnull @Override public List getDataInfo() { - int workingArea = getWorkingArea(this.minerLogic.getCurrentRadius()); - return Collections.singletonList(new TextComponentTranslation("gregtech.machine.miner.working_area", workingArea, workingArea)); + int diameter = this.minerLogic.getCurrentDiameter(); + return Collections.singletonList(new TextComponentTranslation("gregtech.machine.miner.working_area", diameter, diameter)); } @Override protected boolean shouldShowVoidingModeButton() { return false; } + + public interface ILargeMinerType { + + @Nonnull + TraceabilityPredicate getCasing(); + + @Nonnull + TraceabilityPredicate getFrame(); + + @SideOnly(Side.CLIENT) + @Nonnull + ICubeRenderer getFrontOverlay(); + + @SideOnly(Side.CLIENT) + @Nonnull + ICubeRenderer getBaseTexture(@Nullable IMultiblockPart sourcePart); + } + + public enum LargeMinerType implements ILargeMinerType { + STEEL, + TITANIUM, + TUNGSTEN_STEEL; + + @Nonnull + public TraceabilityPredicate getCasing() { + return states(switch (this) { + case STEEL -> MetaBlocks.METAL_CASING.getState(MetalCasingType.STEEL_SOLID); + case TITANIUM -> MetaBlocks.METAL_CASING.getState(MetalCasingType.TITANIUM_STABLE); + case TUNGSTEN_STEEL -> MetaBlocks.METAL_CASING.getState(MetalCasingType.TUNGSTENSTEEL_ROBUST); + }); + } + + @Nonnull + public TraceabilityPredicate getFrame() { + return frames(switch (this) { + case STEEL -> Materials.Steel; + case TITANIUM -> Materials.Titanium; + case TUNGSTEN_STEEL -> Materials.TungstenSteel; + }); + } + + @Nonnull + @Override + @SideOnly(Side.CLIENT) + public ICubeRenderer getBaseTexture(@Nullable IMultiblockPart sourcePart) { + return switch (this) { + case STEEL -> Textures.SOLID_STEEL_CASING; + case TITANIUM -> Textures.STABLE_TITANIUM_CASING; + case TUNGSTEN_STEEL -> Textures.ROBUST_TUNGSTENSTEEL_CASING; + }; + } + + @Nonnull + @Override + @SideOnly(Side.CLIENT) + public ICubeRenderer getFrontOverlay() { + return switch (this) { + case STEEL -> Textures.LARGE_MINER_OVERLAY_ADVANCED; + case TITANIUM -> Textures.LARGE_MINER_OVERLAY_ADVANCED_2; + case TUNGSTEN_STEEL -> Textures.LARGE_MINER_OVERLAY_BASIC; + }; + } + } } diff --git a/src/main/java/gregtech/common/metatileentities/electric/MetaTileEntityMiner.java b/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityMiner.java similarity index 68% rename from src/main/java/gregtech/common/metatileentities/electric/MetaTileEntityMiner.java rename to src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityMiner.java index 4d85d593ca1..aa167e54660 100644 --- a/src/main/java/gregtech/common/metatileentities/electric/MetaTileEntityMiner.java +++ b/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityMiner.java @@ -1,4 +1,4 @@ -package gregtech.common.metatileentities.electric; +package gregtech.common.metatileentities.miner; import codechicken.lib.raytracer.CuboidRayTraceResult; import codechicken.lib.render.CCRenderState; @@ -7,10 +7,8 @@ import gregtech.api.GTValues; import gregtech.api.capability.GregtechTileCapabilities; import gregtech.api.capability.IControllable; -import gregtech.api.capability.IMiner; import gregtech.api.capability.impl.EnergyContainerHandler; import gregtech.api.capability.impl.NotifiableItemStackHandler; -import gregtech.api.capability.impl.miner.MinerLogic; import gregtech.api.gui.GuiTextures; import gregtech.api.gui.ModularUI; import gregtech.api.gui.widgets.AdvancedTextWidget; @@ -19,6 +17,7 @@ import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.metatileentity.TieredMetaTileEntity; import gregtech.api.metatileentity.interfaces.IGregTechTileEntity; +import gregtech.client.renderer.ICubeRenderer; import gregtech.client.renderer.texture.Textures; import gregtech.core.sound.GTSoundEvents; import net.minecraft.client.resources.I18n; @@ -49,22 +48,21 @@ public class MetaTileEntityMiner extends TieredMetaTileEntity implements IMiner, private final int inventorySize; private final long energyPerTick; - private boolean isInventoryFull = false; - private final MinerLogic minerLogic; + private final MinerLogic minerLogic; - public MetaTileEntityMiner(ResourceLocation metaTileEntityId, int tier, int speed, int maximumRadius, int fortune) { + public MetaTileEntityMiner(@Nonnull ResourceLocation metaTileEntityId, int tier, int workFrequency, int maximumDiameter) { super(metaTileEntityId, tier); this.inventorySize = (tier + 1) * (tier + 1); this.energyPerTick = GTValues.V[tier - 1]; - this.minerLogic = new MinerLogic(this, fortune, speed, maximumRadius, Textures.SOLID_STEEL_CASING); + this.minerLogic = new MinerLogic<>(this, workFrequency, maximumDiameter); this.chargerInventory = new ItemStackHandler(1); initializeInventory(); } @Override public MetaTileEntity createMetaTileEntity(IGregTechTileEntity tileEntity) { - return new MetaTileEntityMiner(metaTileEntityId, getTier(), this.minerLogic.getSpeed(), this.minerLogic.getMaximumRadius(), this.minerLogic.getFortune()); + return new MetaTileEntityMiner(metaTileEntityId, getTier(), this.minerLogic.getWorkFrequency(), this.minerLogic.getMaximumDiameter()); } @Override @@ -119,7 +117,7 @@ protected ModularUI createUI(@Nonnull EntityPlayer entityPlayer) { .label(6, 6, getMetaFullName()); builder.widget(new AdvancedTextWidget(10, 19, this::addDisplayText, 0xFFFFFF) .setMaxWidthLimit(84)); - builder.widget(new AdvancedTextWidget(70, 19, this::addDisplayText2, 0xFFFFFF) + builder.widget(new AdvancedTextWidget(70, 19, this.minerLogic::addLastMinedBlock, 0xFFFFFF) .setMaxWidthLimit(84)); builder.widget(new SlotWidget(chargerInventory, 0, 171, 152) .setBackgroundTexture(GuiTextures.SLOT, GuiTextures.CHARGER_OVERLAY)); @@ -128,38 +126,23 @@ protected ModularUI createUI(@Nonnull EntityPlayer entityPlayer) { } private void addDisplayText(@Nonnull List textList) { - int workingArea = getWorkingArea(minerLogic.getCurrentRadius()); - textList.add(new TextComponentTranslation("gregtech.machine.miner.startx", this.minerLogic.getX().get())); - textList.add(new TextComponentTranslation("gregtech.machine.miner.starty", this.minerLogic.getY().get())); - textList.add(new TextComponentTranslation("gregtech.machine.miner.startz", this.minerLogic.getZ().get())); - textList.add(new TextComponentTranslation("gregtech.machine.miner.working_area", workingArea, workingArea)); - if (this.minerLogic.isDone()) - textList.add(new TextComponentTranslation("gregtech.machine.miner.done").setStyle(new Style().setColor(TextFormatting.GREEN))); - else if (this.minerLogic.isWorking()) - textList.add(new TextComponentTranslation("gregtech.machine.miner.working").setStyle(new Style().setColor(TextFormatting.GOLD))); - else if (!this.isWorkingEnabled()) - textList.add(new TextComponentTranslation("gregtech.multiblock.work_paused")); - if (isInventoryFull) - textList.add(new TextComponentTranslation("gregtech.machine.miner.invfull").setStyle(new Style().setColor(TextFormatting.RED))); - if (!drainEnergy(true)) + this.minerLogic.addMinerArea(textList); + this.minerLogic.addMinerWorkStatus(textList); + this.minerLogic.addInventoryStatus(textList); + if (!drainMiningResources(true)) { textList.add(new TextComponentTranslation("gregtech.machine.miner.needspower").setStyle(new Style().setColor(TextFormatting.RED))); - } - - private void addDisplayText2(@Nonnull List textList) { - textList.add(new TextComponentTranslation("gregtech.machine.miner.minex", this.minerLogic.getMineX().get())); - textList.add(new TextComponentTranslation("gregtech.machine.miner.miney", this.minerLogic.getMineY().get())); - textList.add(new TextComponentTranslation("gregtech.machine.miner.minez", this.minerLogic.getMineZ().get())); + } } @Override public void addInformation(ItemStack stack, @Nullable World player, @Nonnull List tooltip, boolean advanced) { - int currentArea = getWorkingArea(minerLogic.getCurrentRadius()); + int currentArea = minerLogic.getCurrentDiameter(); tooltip.add(I18n.format("gregtech.machine.miner.tooltip", currentArea, currentArea)); tooltip.add(I18n.format("gregtech.universal.tooltip.uses_per_tick", energyPerTick) - + TextFormatting.GRAY + ", " + I18n.format("gregtech.machine.miner.per_block", this.minerLogic.getSpeed() / 20)); + + TextFormatting.GRAY + ", " + I18n.format("gregtech.machine.miner.per_block", this.minerLogic.getWorkFrequency() / 20)); tooltip.add(I18n.format("gregtech.universal.tooltip.voltage_in", energyContainer.getInputVoltage(), GTValues.VNF[getTier()])); tooltip.add(I18n.format("gregtech.universal.tooltip.energy_storage_capacity", energyContainer.getEnergyCapacity())); - int maxArea = getWorkingArea(minerLogic.getMaximumRadius()); + int maxArea = minerLogic.getMaximumDiameter(); tooltip.add(I18n.format("gregtech.universal.tooltip.working_area_max", maxArea, maxArea)); } @@ -172,52 +155,53 @@ public void addToolUsages(ItemStack stack, @Nullable World world, List t } @Override - public boolean drainEnergy(boolean simulate) { + public boolean drainMiningResources(boolean simulate) { long resultEnergy = energyContainer.getEnergyStored() - energyPerTick; - if (resultEnergy >= 0L && resultEnergy <= energyContainer.getEnergyCapacity()) { - if (!simulate) - energyContainer.removeEnergy(energyPerTick); - return true; + if (resultEnergy < 0 || resultEnergy > energyContainer.getEnergyCapacity()) { + return false; } - return false; + if (!simulate) { + energyContainer.removeEnergy(energyPerTick); + } + return true; + } + + @Override + @SideOnly(Side.CLIENT) + public ICubeRenderer getPipeTexture() { + return Textures.SOLID_STEEL_CASING; } @Override public void update() { super.update(); - this.minerLogic.performMining(); + this.minerLogic.update(); if (!getWorld().isRemote) { ((EnergyContainerHandler) this.energyContainer).dischargeOrRechargeEnergyContainers(chargerInventory, 0); if (getOffsetTimer() % 5 == 0) pushItemsIntoNearbyHandlers(getFrontFacing()); - - if (this.minerLogic.wasActiveAndNeedsUpdate()) { - this.minerLogic.setWasActiveAndNeedsUpdate(false); - this.minerLogic.setActive(false); - } } } @Override - public boolean onScrewdriverClick(EntityPlayer playerIn, EnumHand hand, EnumFacing facing, CuboidRayTraceResult hitResult) { + public boolean onScrewdriverClick(EntityPlayer player, EnumHand hand, EnumFacing facing, CuboidRayTraceResult hitResult) { if (getWorld().isRemote) return true; if (!this.isActive()) { - int currentRadius = this.minerLogic.getCurrentRadius(); - if (currentRadius == 1) - this.minerLogic.setCurrentRadius(this.minerLogic.getMaximumRadius()); - else if (playerIn.isSneaking()) - this.minerLogic.setCurrentRadius(Math.max(1, Math.round(currentRadius / 2.0f))); - else - this.minerLogic.setCurrentRadius(Math.max(1, currentRadius - 1)); - - this.minerLogic.resetArea(); - - int workingArea = getWorkingArea(minerLogic.getCurrentRadius()); - playerIn.sendMessage(new TextComponentTranslation("gregtech.machine.miner.working_area", workingArea, workingArea)); + int currentRadius = this.minerLogic.getCurrentDiameter(); + if (currentRadius == 1) { + this.minerLogic.setCurrentDiameter(this.minerLogic.getMaximumDiameter()); + } else if (player.isSneaking()) { + this.minerLogic.setCurrentDiameter(currentRadius / 2 + currentRadius % 2); + } else { + this.minerLogic.setCurrentDiameter(currentRadius - 1); + } + + int diameter = minerLogic.getCurrentDiameter(); + player.sendMessage(new TextComponentTranslation("gregtech.machine.miner.working_area", diameter, diameter)); } else { - playerIn.sendMessage(new TextComponentTranslation("gregtech.machine.miner.errorradius")); + player.sendMessage(new TextComponentTranslation("gregtech.machine.miner.errorradius")); } return true; } @@ -268,16 +252,6 @@ public void clearMachineInventory(NonNullList itemBuffer) { clearInventory(itemBuffer, chargerInventory); } - @Override - public boolean isInventoryFull() { - return isInventoryFull; - } - - @Override - public void setInventoryFull(boolean isFull) { - this.isInventoryFull = isFull; - } - @Override public boolean isWorkingEnabled() { return this.minerLogic.isWorkingEnabled(); @@ -301,7 +275,7 @@ public boolean isActive() { @Nonnull @Override public List getDataInfo() { - int workingArea = getWorkingArea(minerLogic.getCurrentRadius()); - return Collections.singletonList(new TextComponentTranslation("gregtech.machine.miner.working_area", workingArea, workingArea)); + int diameter = minerLogic.getCurrentDiameter(); + return Collections.singletonList(new TextComponentTranslation("gregtech.machine.miner.working_area", diameter, diameter)); } } diff --git a/src/main/java/gregtech/common/metatileentities/miner/MinerLogic.java b/src/main/java/gregtech/common/metatileentities/miner/MinerLogic.java new file mode 100644 index 00000000000..8738f7f7bb2 --- /dev/null +++ b/src/main/java/gregtech/common/metatileentities/miner/MinerLogic.java @@ -0,0 +1,530 @@ +package gregtech.common.metatileentities.miner; + +import codechicken.lib.render.CCRenderState; +import codechicken.lib.render.pipeline.IVertexOperation; +import codechicken.lib.vec.Cuboid6; +import codechicken.lib.vec.Matrix4; +import gregtech.api.capability.GregtechDataCodes; +import gregtech.api.metatileentity.MetaTileEntity; +import gregtech.api.util.BlockUtility; +import gregtech.api.util.GTLog; +import gregtech.api.util.GTTransferUtils; +import gregtech.client.renderer.texture.Textures; +import gregtech.common.ConfigHolder; +import net.minecraft.block.Block; +import net.minecraft.block.state.IBlockState; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.network.PacketBuffer; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.NonNullList; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.BlockPos.MutableBlockPos; +import net.minecraft.util.math.MathHelper; +import net.minecraft.util.text.ITextComponent; +import net.minecraft.util.text.Style; +import net.minecraft.util.text.TextComponentTranslation; +import net.minecraft.util.text.TextFormatting; +import net.minecraft.world.World; +import net.minecraft.world.WorldServer; +import net.minecraftforge.common.util.Constants; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; +import net.minecraftforge.items.IItemHandlerModifiable; +import org.apache.commons.lang3.StringUtils; +import org.jetbrains.annotations.Nullable; + +import javax.annotation.Nonnull; +import java.util.List; +import java.util.Objects; + +public class MinerLogic { + + /** + * Maximum amount of blocks to scan in one tick + */ + private static final int MAX_BLOCK_SCAN = 100; + + private static final Cuboid6 PIPE_CUBOID = new Cuboid6(4 / 16.0, 0.0, 4 / 16.0, 12 / 16.0, 1.0, 12 / 16.0); + + private static String oreReplacementConfigCache; + private static IBlockState oreReplacement; + + @Nonnull + @SuppressWarnings("deprecation") + public static IBlockState getOreReplacement() { + String config = ConfigHolder.machines.replaceMinedBlocksWith; + if (Objects.equals(oreReplacementConfigCache, config)) { + return oreReplacement; + } + + oreReplacementConfigCache = config; + + String[] blockDescription = StringUtils.split(config, ":"); + String blockName = blockDescription.length <= 2 ? config : blockDescription[0] + ":" + blockDescription[1]; + Block block = Block.getBlockFromName(blockName); + + if (block == null) { + GTLog.logger.error("Invalid configuration on entry 'machines/replaceMinedBlocksWith': Cannot find block with name '{}', using cobblestone as fallback.", blockName); + return oreReplacement = Blocks.COBBLESTONE.getDefaultState(); + } else if (blockDescription.length <= 2 || blockDescription[2].isEmpty()) { + return oreReplacement = block.getDefaultState(); + } else { + try { + return oreReplacement = block.getDefaultState().getBlock().getStateFromMeta(Integer.parseInt(blockDescription[2])); + } catch (NumberFormatException ex) { + GTLog.logger.error("Invalid configuration on entry 'machines/replaceMinedBlocksWith': Cannot parse metadata value '{}' as integer, using cobblestone as fallback.", blockDescription[2]); + return oreReplacement = Blocks.COBBLESTONE.getDefaultState(); + } + } + } + + protected final MTE mte; + + private final int workFrequency; + private final int maximumDiameter; + + private final MutableBlockPos mpos = new MutableBlockPos(); + + protected int currentDiameter; + + private boolean done; + private boolean workingEnabled = true; + + protected long nextBlock; + + // last mined ore block + + protected final MutableBlockPos lastMinedOre = new MutableBlockPos(); + protected boolean hasLastMinedOre; + protected int minedOreCount; + + private int pipeLength; + + // transient values below (not saved) + + // flag indicating last insertion to inventory failed + private boolean inventoryFull; + // flag indicating scan area should be rebuilt + protected boolean rebuildScanArea; + // status of the last update; true means miner is working, false means no + private boolean active; + + // scan area; essentially bottomless AABB. + + protected int startX; + protected int startY; + protected int startZ; + protected int endX; + protected int endZ; + + /** + * Creates the general logic for all in-world ore block miners + * + * @param mte the {@link MetaTileEntity} this logic belongs to + * @param workFrequency work frequency in ticks; value of <=1 means the miner operates each tick, 2 means the miner + * operates every other tick and so on + * @param maximumDiameter the maximum diameter of a square the miner can mine in + */ + public MinerLogic(@Nonnull MTE mte, int workFrequency, int maximumDiameter) { + this.mte = mte; + this.workFrequency = workFrequency; + this.currentDiameter = this.maximumDiameter = maximumDiameter; + } + + /** + * @return the miner's speed in ticks + */ + public int getWorkFrequency() { + return this.workFrequency; + } + + /** + * @return the miner's maximum diameter + */ + public int getMaximumDiameter() { + return this.maximumDiameter; + } + + /** + * @return the miner's current diameter + */ + public int getCurrentDiameter() { + return this.currentDiameter; + } + + /** + * @param currentDiameter the radius to set the miner to use + */ + public void setCurrentDiameter(int currentDiameter) { + if (isWorking()) return; + currentDiameter = Math.max(1, Math.min(currentDiameter, getMaximumDiameter())); + if (this.currentDiameter != currentDiameter) { + this.currentDiameter = currentDiameter; + this.rebuildScanArea = true; + this.mte.markDirty(); + } + } + + /** + * @return true if the miner is finished working + */ + public boolean isDone() { + return this.done; + } + + /** + * @return true if the miner is active + */ + public boolean isActive() { + return this.workingEnabled && this.active; + } + + /** + * @return whether working is enabled for the logic + */ + public boolean isWorkingEnabled() { + return this.workingEnabled; + } + + /** + * @param isWorkingEnabled the new state of the miner's ability to work: true to change to enabled, else false + */ + public void setWorkingEnabled(boolean isWorkingEnabled) { + if (this.workingEnabled != isWorkingEnabled) { + this.workingEnabled = isWorkingEnabled; + this.mte.markDirty(); + if (mte.getWorld() != null && !mte.getWorld().isRemote) { + if (!isWorkingEnabled) reset(); + this.mte.writeCustomData(GregtechDataCodes.WORKING_ENABLED, buf -> buf.writeBoolean(isWorkingEnabled)); + } + } + } + + /** + * @return whether the miner is currently working + */ + public boolean isWorking() { + return active && workingEnabled; + } + + /** + * Recalculates the mining area and restarts the miner, if it was done + */ + public void reset() { + this.nextBlock = 0; + this.hasLastMinedOre = false; + this.pipeLength = 0; + + initBoundary(); + + if (this.done) { + this.setWorkingEnabled(false); + this.done = false; + } + resetPipeLength(); + this.mte.markDirty(); + } + + /** + * @return origin position of the miner. Block boundary will be centered around this position, and mining pipes will + * be rendered under this position. + */ + @Nonnull + protected BlockPos getOrigin() { + return mte.getPos(); + } + + /** + * Initialize block boundary for mining, i.e. {@link #startX}, {@link #startY}, {@link #startZ}, {@link #endX} and + * {@link #endZ} + */ + protected void initBoundary() { + BlockPos origin = getOrigin(); + int radius = this.currentDiameter / 2; + this.startX = origin.getX() - radius; + this.startY = origin.getY(); + this.startZ = origin.getZ() - radius; + this.endX = origin.getX() + radius; + this.endZ = origin.getZ() + radius; + } + + /** + * Performs the actual mining in world. Call this method every tick in update. + */ + public void update() { + if (this.mte.getWorld().isRemote || + (this.workFrequency >= 2 && this.mte.getOffsetTimer() % this.workFrequency != 0)) { + return; + } + + boolean active = mine(); + if (this.active != active) { + this.active = active; + this.mte.writeCustomData(GregtechDataCodes.WORKABLE_ACTIVE, buf -> buf.writeBoolean(active)); + } + } + + private boolean mine() { + if (!this.workingEnabled || this.done || !canOperate()) { + return false; + } + + if (this.rebuildScanArea) { + this.rebuildScanArea = false; + reset(); + } + + World world = mte.getWorld(); + for (int i = MAX_BLOCK_SCAN; i > 0; i--) { + BlockPos pos = getBlockPosAt(this.nextBlock); + if (pos == null || !world.isValid(pos)) { + this.done = true; + return false; + } + + IBlockState state = world.getBlockState(pos); + boolean isOrigin = alignsWithOrigin(pos); + + // skip unbreakable block / TE blocks + if (state.getBlockHardness(world, pos) < 0 || state.getBlock().hasTileEntity(state)) { + // center block (where mining pipes goes in) can be skipped by this, it'll probably look kind of janky + // but it's 100x better than voiding bedrock + if (isOrigin) incrementPipeLength(); + this.nextBlock++; + continue; + } + + boolean isOre = BlockUtility.isOre(state); + if (!isOrigin && !isOre) { + this.nextBlock++; + continue; + } + + NonNullList blockDrops = NonNullList.create(); + getRegularBlockDrops(blockDrops, world, pos, state); + + if (isOre) { + IItemHandlerModifiable exportItems = mte.getExportItems(); + if (!GTTransferUtils.addItemsToItemHandler(exportItems, true, blockDrops)) { + this.inventoryFull = true; + return false; + } + GTTransferUtils.addItemsToItemHandler(exportItems, false, blockDrops); + this.inventoryFull = false; + this.lastMinedOre.setPos(pos); + this.minedOreCount++; + } + this.mte.drainMiningResources(false); + world.setBlockState(pos, isOrigin ? Blocks.AIR.getDefaultState() : getOreReplacement()); + + if (isOrigin) incrementPipeLength(); + + this.nextBlock++; + + onMineOperation(pos, isOre, isOrigin); + this.mte.markDirty(); + return true; + } + return true; + } + + @Nullable + protected final BlockPos getBlockPosAt(long index) { + if (index < 0) return null; + int sizeX = this.endX - this.startX; + int sizeZ = this.endZ - this.startZ; + if (sizeX <= 0 || sizeZ <= 0) return null; + + int x = this.startX + (int) (index % sizeX); + index /= sizeX; + int z = this.startZ + (int) (index % sizeZ); + int y = this.startY - (int) (index / sizeZ); + return this.mpos.setPos(x, y, z); + } + + private boolean alignsWithOrigin(@Nonnull BlockPos pos) { + BlockPos origin = getOrigin(); + return pos.getX() == origin.getX() && pos.getZ() == origin.getZ(); + } + + @SuppressWarnings("BooleanMethodIsAlwaysInverted") + protected boolean canOperate() { + return this.mte.drainMiningResources(true); + } + + /** + * Called after each block is mined. + * + * @param pos Position of the block mined + * @param isOre Whether it was ore block + * @param isOrigin Whether it was origin (the block mining pipe goes in) + */ + protected void onMineOperation(@Nonnull BlockPos pos, boolean isOre, boolean isOrigin) {} + + /** + * called to handle mining regular ores and blocks + * + * @param drops the List of items to fill after the operation + * @param world the {@link WorldServer} the miner is in + * @param pos the {@link BlockPos} of the block being mined + * @param state the {@link IBlockState} of the block being mined + */ + protected void getRegularBlockDrops(@Nonnull NonNullList drops, @Nonnull World world, @Nonnull BlockPos pos, @Nonnull IBlockState state) { + state.getBlock().getDrops(drops, world, pos, state, 0); // regular ores do not get fortune applied + } + + private void incrementPipeLength() { + this.pipeLength++; + this.mte.writeCustomData(GregtechDataCodes.PUMP_HEAD_LEVEL, b -> b.writeVarInt(pipeLength)); + } + + private void resetPipeLength() { + if (this.pipeLength == 0) return; + this.pipeLength = 0; + this.mte.writeCustomData(GregtechDataCodes.PUMP_HEAD_LEVEL, b -> b.writeVarInt(pipeLength)); + } + + /** + * renders the pipe beneath the miner + */ + @SideOnly(Side.CLIENT) + public void renderPipe(CCRenderState renderState, Matrix4 translation, IVertexOperation[] pipeline) { + Textures.PIPE_IN_OVERLAY.renderSided(EnumFacing.DOWN, renderState, translation, pipeline); + for (int i = 0; i < this.pipeLength; i++) { + translation.translate(0.0, -1.0, 0.0); + this.mte.getPipeTexture().render(renderState, translation, pipeline, PIPE_CUBOID); + } + } + + /** + * Write states to NBT. Call this method in {@link MetaTileEntity#writeToNBT(NBTTagCompound)}. + */ + @Nonnull + public NBTTagCompound writeToNBT(@Nonnull NBTTagCompound data) { + data.setInteger("currentDiameter", this.currentDiameter); + data.setBoolean("done", this.done); + data.setBoolean("workingEnabled", this.workingEnabled); + data.setLong("nextBlock", this.nextBlock); + + if (this.hasLastMinedOre) { + data.setInteger("lastMinedOreX", this.lastMinedOre.getX()); + data.setInteger("lastMinedOreY", this.lastMinedOre.getY()); + data.setInteger("lastMinedOreZ", this.lastMinedOre.getZ()); + } + + data.setInteger("minedOreCount", this.minedOreCount); + data.setInteger("pipeLength", this.pipeLength); + + return data; + } + + /** + * Read states from NBT. Call this method in {@link MetaTileEntity#readFromNBT(NBTTagCompound)}. + */ + public void readFromNBT(@Nonnull NBTTagCompound data) { + this.inventoryFull = false; + this.active = false; + this.rebuildScanArea = true; + + if (data.hasKey("xPos", Constants.NBT.TAG_INT)) { + // retro save compat + this.currentDiameter = MathHelper.clamp(data.getInteger("currentRadius") * 2 + 1, 1, getMaximumDiameter()); + + this.done = data.getInteger("isDone") != 0; + this.workingEnabled = data.getInteger("isWorkingEnabled") != 0; + this.nextBlock = 0; + + this.hasLastMinedOre = false; + this.minedOreCount = 0; + this.pipeLength = data.getInteger("pipeLength"); + return; + } + + this.currentDiameter = MathHelper.clamp(data.getInteger("currentDiameter"), 1, getMaximumDiameter()); + this.done = data.getBoolean("done"); + this.workingEnabled = data.getBoolean("workingEnabled"); + this.nextBlock = data.getLong("nextBlock"); + + if (data.hasKey("lastMinedOreX", Constants.NBT.TAG_INT)) { + this.lastMinedOre.setPos(data.getInteger("lastMinedOreX"), + data.getInteger("lastMinedOreY"), + data.getInteger("lastMinedOreZ")); + this.hasLastMinedOre = true; + } else { + this.hasLastMinedOre = false; + } + + this.minedOreCount = Math.max(0, data.getInteger("minedOreCount")); + this.pipeLength = Math.max(0, data.getInteger("pipeLength")); + } + + /** + * Write states to packet buffer. Call this method in {@link MetaTileEntity#writeInitialSyncData(PacketBuffer)}. + */ + public void writeInitialSyncData(@Nonnull PacketBuffer buf) { + buf.writeVarInt(this.pipeLength); + buf.writeBoolean(this.workingEnabled); + } + + /** + * Read states from packet buffer. Call this method in {@link MetaTileEntity#receiveInitialSyncData(PacketBuffer)}. + */ + public void receiveInitialSyncData(@Nonnull PacketBuffer buf) { + this.pipeLength = buf.readVarInt(); + this.workingEnabled = buf.readBoolean(); + } + + /** + * Callback for handling custom data packet sent by miner logic. Call this method in {@link MetaTileEntity#receiveCustomData(int, PacketBuffer)}. + */ + public void receiveCustomData(int dataId, @Nonnull PacketBuffer buf) { + switch (dataId) { + case GregtechDataCodes.PUMP_HEAD_LEVEL -> { + this.pipeLength = buf.readVarInt(); + this.mte.scheduleRenderUpdate(); + } + case GregtechDataCodes.WORKABLE_ACTIVE -> { + this.active = buf.readBoolean(); + this.mte.scheduleRenderUpdate(); + } + case GregtechDataCodes.WORKING_ENABLED -> { + this.workingEnabled = buf.readBoolean(); + this.mte.scheduleRenderUpdate(); + } + } + } + + public void addMinerArea(@Nonnull List textList) { + int diameter = getCurrentDiameter(); + // TODO + textList.add(new TextComponentTranslation("gregtech.machine.miner.working_area", diameter, diameter)); + } + + public void addMinerWorkStatus(@Nonnull List textList) { + if (isDone()) { + textList.add(new TextComponentTranslation("gregtech.machine.miner.done") + .setStyle(new Style().setColor(TextFormatting.GREEN))); + } else if (isWorking()) { + textList.add(new TextComponentTranslation("gregtech.machine.miner.working") + .setStyle(new Style().setColor(TextFormatting.GOLD))); + } else if (!isWorkingEnabled()) { + textList.add(new TextComponentTranslation("gregtech.multiblock.work_paused")); + } + } + + public void addInventoryStatus(@Nonnull List textList) { + if (this.inventoryFull) { + textList.add(new TextComponentTranslation("gregtech.machine.miner.invfull") + .setStyle(new Style().setColor(TextFormatting.RED))); + } + } + + public void addLastMinedBlock(@Nonnull List textList) { + if (!this.hasLastMinedOre) return; + textList.add(new TextComponentTranslation("gregtech.machine.miner.minex", this.lastMinedOre.getX())); + textList.add(new TextComponentTranslation("gregtech.machine.miner.miney", this.lastMinedOre.getY())); + textList.add(new TextComponentTranslation("gregtech.machine.miner.minez", this.lastMinedOre.getZ())); + } +} diff --git a/src/main/java/gregtech/common/metatileentities/miner/MultiblockMinerLogic.java b/src/main/java/gregtech/common/metatileentities/miner/MultiblockMinerLogic.java new file mode 100644 index 00000000000..b2fbbfe6864 --- /dev/null +++ b/src/main/java/gregtech/common/metatileentities/miner/MultiblockMinerLogic.java @@ -0,0 +1,189 @@ +package gregtech.common.metatileentities.miner; + +import gregtech.api.GTValues; +import gregtech.api.items.toolitem.ToolHelper; +import gregtech.api.recipes.Recipe; +import gregtech.api.recipes.RecipeMap; +import gregtech.api.unification.OreDictUnifier; +import gregtech.api.unification.ore.OrePrefix; +import gregtech.api.util.GTUtility; +import net.minecraft.block.state.IBlockState; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.NonNullList; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.MathHelper; +import net.minecraft.util.text.ITextComponent; +import net.minecraft.util.text.TextComponentTranslation; +import net.minecraft.world.World; +import net.minecraftforge.common.util.Constants; + +import javax.annotation.Nonnull; +import java.util.Collections; +import java.util.List; + +public class MultiblockMinerLogic extends MinerLogic { + + private final int fortune; + private final RecipeMap blockDropRecipeMap; + private final int maximumChunkDiameter; + + private final BlockPos.MutableBlockPos mpos2 = new BlockPos.MutableBlockPos(); + + private int currentChunkDiameter; + + private boolean chunkMode; + private boolean silkTouchMode; + + public MultiblockMinerLogic(MetaTileEntityLargeMiner largeMiner, int fortune, int workFrequency, int maximumChunkDiameter, + RecipeMap blockDropRecipeMap) { + super(largeMiner, workFrequency, maximumChunkDiameter * 16 / 2); + this.fortune = fortune; + this.blockDropRecipeMap = blockDropRecipeMap; + this.currentChunkDiameter = this.maximumChunkDiameter = maximumChunkDiameter; + } + + @Override + protected void getRegularBlockDrops(@Nonnull NonNullList drops, @Nonnull World world, @Nonnull BlockPos pos, @Nonnull IBlockState state) { + if (this.silkTouchMode) { + drops.add(ToolHelper.getSilkTouchDrop(state)); + } else if (applyTieredHammerDrops(GTUtility.toItem(state), drops) == 0) { // 3X the ore compared to the single blocks + super.getRegularBlockDrops(drops, world, pos, state); // fallback + } + } + + @Override + protected void initBoundary() { + if (!this.chunkMode) { + super.initBoundary(); + return; + } + + BlockPos origin = getOrigin(); + int originChunkX = origin.getX() / 16; + int originChunkZ = origin.getZ() / 16; + + this.startX = (originChunkX - currentChunkDiameter) * 16; + this.startY = origin.getY(); + this.startZ = (originChunkZ - currentChunkDiameter) * 16; + this.endX = (originChunkX + currentChunkDiameter) * 16 + 15; + this.endZ = (originChunkZ + currentChunkDiameter) * 16 + 15; + } + + @Nonnull + @Override + protected BlockPos getOrigin() { + return this.mpos2.setPos(this.mte.getPos()).move(this.mte.getFrontFacing().getOpposite()); + } + + public int getFortune() { + return fortune; + } + + public int getMaximumChunkDiameter() { + return maximumChunkDiameter; + } + + public int getCurrentChunkDiameter() { + return currentChunkDiameter; + } + + public void setCurrentChunkDiameter(int currentChunkDiameter) { + if (isWorking()) return; + currentChunkDiameter = Math.max(1, Math.min(currentChunkDiameter, getMaximumChunkDiameter())); + if (this.currentChunkDiameter != currentChunkDiameter || !this.chunkMode) { + this.chunkMode = true; + this.currentChunkDiameter = currentChunkDiameter; + this.rebuildScanArea = false; + this.mte.markDirty(); + } + } + + @Override + public void setCurrentDiameter(int currentDiameter) { + if (isWorking()) return; + if (this.chunkMode) { + this.chunkMode = false; + this.rebuildScanArea = true; + this.mte.markDirty(); + } + super.setCurrentDiameter(currentDiameter); + } + + public boolean isChunkMode() { + return this.chunkMode; + } + + public void setChunkMode(boolean isChunkMode) { + if (isWorking()) return; + this.chunkMode = isChunkMode; + this.rebuildScanArea = true; + this.mte.markDirty(); + } + + public boolean isSilkTouchMode() { + return this.silkTouchMode; + } + + public void setSilkTouchMode(boolean isSilkTouchMode) { + if (!isWorking()) { + this.silkTouchMode = isSilkTouchMode; + } + } + + @Nonnull + @Override + public NBTTagCompound writeToNBT(@Nonnull NBTTagCompound data) { + data.setBoolean("isChunkMode", chunkMode); + data.setBoolean("isSilkTouchMode", silkTouchMode); + data.setInteger("currentChunkDiameter", currentChunkDiameter); + return super.writeToNBT(data); + } + + @Override + public void readFromNBT(@Nonnull NBTTagCompound data) { + this.chunkMode = data.getBoolean("isChunkMode"); + this.silkTouchMode = data.getBoolean("isSilkTouchMode"); + this.currentChunkDiameter = data.hasKey("currentChunkDiameter", Constants.NBT.TAG_INT) ? + MathHelper.clamp(data.getInteger("currentChunkDiameter"), 1, getMaximumChunkDiameter()) : + getMaximumChunkDiameter(); + super.readFromNBT(data); + } + + @Override + public void addMinerArea(@Nonnull List textList) { + if (isChunkMode()) { + int chunkDiameter = getCurrentChunkDiameter(); + textList.add(new TextComponentTranslation("gregtech.machine.miner.working_area_chunks", chunkDiameter, chunkDiameter)); + } else { + int diameter = getCurrentDiameter(); + textList.add(new TextComponentTranslation("gregtech.machine.miner.working_area", diameter, diameter)); + } + } + + /** + * Applies a fortune hammer to block drops based on a tier value, intended for small ores + * + * @param stack the item stack to check for recipes + * @param drops where the drops are stored to + * @return amount of items inserted to {@code drops} + */ + protected int applyTieredHammerDrops(@Nonnull ItemStack stack, @Nonnull List drops) { + int energyTier = this.mte.getEnergyTier(); + Recipe recipe = this.blockDropRecipeMap.findRecipe( + GTValues.V[energyTier], + Collections.singletonList(stack), + Collections.emptyList()); + if (recipe == null || recipe.getOutputs().isEmpty()) return 0; + int c = 0; + for (ItemStack output : recipe.getResultItemOutputs(GTUtility.getTierByVoltage(recipe.getEUt()), energyTier, this.blockDropRecipeMap)) { + output = output.copy(); + if (this.fortune > 0 && OreDictUnifier.getPrefix(output) == OrePrefix.crushed) { + output.grow(output.getCount() * this.fortune); + } + drops.add(output); + c++; + } + return c; + } +} diff --git a/src/main/java/gregtech/common/metatileentities/steam/SteamMiner.java b/src/main/java/gregtech/common/metatileentities/miner/SteamMiner.java similarity index 65% rename from src/main/java/gregtech/common/metatileentities/steam/SteamMiner.java rename to src/main/java/gregtech/common/metatileentities/miner/SteamMiner.java index 98962ee4b71..297b009b016 100644 --- a/src/main/java/gregtech/common/metatileentities/steam/SteamMiner.java +++ b/src/main/java/gregtech/common/metatileentities/miner/SteamMiner.java @@ -1,17 +1,17 @@ -package gregtech.common.metatileentities.steam; +package gregtech.common.metatileentities.miner; import codechicken.lib.render.CCRenderState; import codechicken.lib.render.pipeline.ColourMultiplier; import codechicken.lib.render.pipeline.IVertexOperation; import codechicken.lib.vec.Matrix4; -import gregtech.api.capability.*; +import gregtech.api.capability.GregtechDataCodes; +import gregtech.api.capability.GregtechTileCapabilities; +import gregtech.api.capability.IControllable; +import gregtech.api.capability.IVentable; import gregtech.api.capability.impl.CommonFluidFilters; import gregtech.api.capability.impl.FilteredFluidHandler; import gregtech.api.capability.impl.FluidTankList; import gregtech.api.capability.impl.NotifiableItemStackHandler; -import gregtech.api.capability.impl.miner.MinerLogic; -import gregtech.api.capability.impl.miner.SteamMinerLogic; -import gregtech.api.damagesources.DamageSources; import gregtech.api.gui.GuiTextures; import gregtech.api.gui.ModularUI; import gregtech.api.gui.widgets.AdvancedTextWidget; @@ -20,28 +20,23 @@ import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.metatileentity.interfaces.IGregTechTileEntity; import gregtech.api.util.GTUtility; +import gregtech.client.renderer.ICubeRenderer; import gregtech.client.renderer.texture.Textures; import gregtech.client.renderer.texture.cube.SimpleSidedCubeRenderer; import gregtech.common.ConfigHolder; -import net.minecraft.block.Block; -import net.minecraft.block.state.IBlockState; import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.client.resources.I18n; -import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.init.SoundEvents; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.PacketBuffer; -import net.minecraft.util.*; -import net.minecraft.util.math.AxisAlignedBB; -import net.minecraft.util.math.BlockPos; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.ResourceLocation; import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.Style; import net.minecraft.util.text.TextComponentTranslation; import net.minecraft.util.text.TextFormatting; import net.minecraft.world.World; -import net.minecraft.world.WorldServer; import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; @@ -61,21 +56,20 @@ public class SteamMiner extends MetaTileEntity implements IMiner, IControllable, private final int inventorySize; private final int energyPerTick; - private boolean isInventoryFull = false; - private final MinerLogic minerLogic; + private final SteamMinerLogic minerLogic; - public SteamMiner(ResourceLocation metaTileEntityId, int speed, int maximumRadius, int fortune) { + public SteamMiner(ResourceLocation metaTileEntityId, int workFrequency, int maximumRadius) { super(metaTileEntityId); this.inventorySize = 4; this.energyPerTick = 16; - this.minerLogic = new SteamMinerLogic(this, fortune, speed, maximumRadius, Textures.BRONZE_PLATED_BRICKS); + this.minerLogic = new SteamMinerLogic(this, workFrequency, maximumRadius); initializeInventory(); } @Override public MetaTileEntity createMetaTileEntity(IGregTechTileEntity tileEntity) { - return new SteamMiner(metaTileEntityId, this.minerLogic.getSpeed(), this.minerLogic.getMaximumRadius(), this.minerLogic.getFortune()); + return new SteamMiner(metaTileEntityId, this.minerLogic.getWorkFrequency(), this.minerLogic.getMaximumDiameter()); } @Override @@ -101,8 +95,9 @@ public void renderMetaTileEntity(CCRenderState renderState, Matrix4 translation, for (EnumFacing renderSide : EnumFacing.HORIZONTALS) { if (renderSide == getFrontFacing()) { Textures.PIPE_OUT_OVERLAY.renderSided(renderSide, renderState, translation, pipeline); - } else + } else { Textures.STEAM_MINER_OVERLAY.renderSided(renderSide, renderState, translation, coloredPipeline); + } } Textures.STEAM_VENT_OVERLAY.renderSided(EnumFacing.UP, renderState, translation, pipeline); Textures.PIPE_IN_OVERLAY.renderSided(EnumFacing.DOWN, renderState, translation, pipeline); @@ -129,45 +124,33 @@ protected ModularUI createUI(EntityPlayer entityPlayer) { .label(6, 6, getMetaFullName()); builder.widget(new AdvancedTextWidget(10, 19, this::addDisplayText, 0xFFFFFF) .setMaxWidthLimit(84)); - builder.widget(new AdvancedTextWidget(70, 19, this::addDisplayText2, 0xFFFFFF) + builder.widget(new AdvancedTextWidget(70, 19, this.minerLogic::addLastMinedBlock, 0xFFFFFF) .setMaxWidthLimit(84)); return builder.build(getHolder(), entityPlayer); } - void addDisplayText(List textList) { - int workingArea = getWorkingArea(minerLogic.getCurrentRadius()); - textList.add(new TextComponentTranslation("gregtech.machine.miner.startx", this.minerLogic.getX().get())); - textList.add(new TextComponentTranslation("gregtech.machine.miner.starty", this.minerLogic.getY().get())); - textList.add(new TextComponentTranslation("gregtech.machine.miner.startz", this.minerLogic.getZ().get())); - textList.add(new TextComponentTranslation("gregtech.machine.miner.working_area", workingArea, workingArea)); - if (this.minerLogic.isDone()) - textList.add(new TextComponentTranslation("gregtech.machine.miner.done").setStyle(new Style().setColor(TextFormatting.GREEN))); - else if (this.minerLogic.isWorking()) - textList.add(new TextComponentTranslation("gregtech.machine.miner.working").setStyle(new Style().setColor(TextFormatting.GOLD))); - else if (!this.isWorkingEnabled()) - textList.add(new TextComponentTranslation("gregtech.multiblock.work_paused")); - if (this.isInventoryFull) - textList.add(new TextComponentTranslation("gregtech.machine.miner.invfull").setStyle(new Style().setColor(TextFormatting.RED))); - if (ventingStuck) - textList.add(new TextComponentTranslation("gregtech.machine.steam_miner.vent").setStyle(new Style().setColor(TextFormatting.RED))); - else if (!drainEnergy(true)) - textList.add(new TextComponentTranslation("gregtech.machine.steam_miner.steam").setStyle(new Style().setColor(TextFormatting.RED))); - } - - void addDisplayText2(List textList) { - textList.add(new TextComponentTranslation("gregtech.machine.miner.minex", this.minerLogic.getMineX().get())); - textList.add(new TextComponentTranslation("gregtech.machine.miner.miney", this.minerLogic.getMineY().get())); - textList.add(new TextComponentTranslation("gregtech.machine.miner.minez", this.minerLogic.getMineZ().get())); + private void addDisplayText(List textList) { + this.minerLogic.addMinerArea(textList); + this.minerLogic.addMinerWorkStatus(textList); + this.minerLogic.addInventoryStatus(textList); + if (this.ventingStuck) { + textList.add(new TextComponentTranslation("gregtech.machine.steam_miner.vent") + .setStyle(new Style().setColor(TextFormatting.RED))); + } else if (!drainMiningResources(true)) { + textList.add(new TextComponentTranslation("gregtech.machine.steam_miner.steam") + .setStyle(new Style().setColor(TextFormatting.RED))); + } } @Override public void addInformation(ItemStack stack, @Nullable World player, List tooltip, boolean advanced) { tooltip.add(I18n.format("gregtech.universal.tooltip.uses_per_tick_steam", energyPerTick) - + TextFormatting.GRAY + ", " + I18n.format("gregtech.machine.miner.per_block", this.minerLogic.getSpeed() / 20)); - int maxArea = getWorkingArea(minerLogic.getMaximumRadius()); - tooltip.add(I18n.format("gregtech.universal.tooltip.working_area", maxArea, maxArea)); + + TextFormatting.GRAY + ", " + + I18n.format("gregtech.machine.miner.per_block", this.minerLogic.getWorkFrequency() / 20)); + int maxDiameter = minerLogic.getMaximumDiameter(); + tooltip.add(I18n.format("gregtech.universal.tooltip.working_area", maxDiameter, maxDiameter)); } @Override @@ -178,7 +161,8 @@ public void addToolUsages(ItemStack stack, @Nullable World world, List t super.addToolUsages(stack, world, tooltip, advanced); } - public boolean drainEnergy(boolean simulate) { + @Override + public boolean drainMiningResources(boolean simulate) { int resultSteam = importFluids.getTankAt(0).getFluidAmount() - energyPerTick; if (!ventingStuck && resultSteam >= 0L && resultSteam <= importFluids.getTankAt(0).getCapacity()) { if (!simulate) @@ -188,18 +172,19 @@ public boolean drainEnergy(boolean simulate) { return false; } + @Override + @SideOnly(Side.CLIENT) + public ICubeRenderer getPipeTexture() { + return Textures.BRONZE_PLATED_BRICKS; + } + @Override public void update() { super.update(); - this.minerLogic.performMining(); + this.minerLogic.update(); if (!getWorld().isRemote) { if (getOffsetTimer() % 5 == 0) pushItemsIntoNearbyHandlers(getFrontFacing()); - - if (this.minerLogic.wasActiveAndNeedsUpdate()) { - this.minerLogic.setWasActiveAndNeedsUpdate(false); - this.minerLogic.setActive(false); - } } } @@ -246,31 +231,12 @@ public void receiveCustomData(int dataId, PacketBuffer buf) { this.minerLogic.receiveCustomData(dataId, buf); } + @Override @SideOnly(Side.CLIENT) public Pair getParticleTexture() { return Pair.of(Textures.STEAM_CASING_BRONZE.getSpriteOnSide(SimpleSidedCubeRenderer.RenderSide.TOP), getPaintingColorForRendering()); } - public void setVentingStuck(boolean ventingStuck) { - this.ventingStuck = ventingStuck; - if (!this.getWorld().isRemote) { - this.markDirty(); - this.writeCustomData(GregtechDataCodes.VENTING_STUCK, (buf) -> buf.writeBoolean(ventingStuck)); - } - } - - @Override - public void setNeedsVenting(boolean needsVenting) { - this.needsVenting = needsVenting; - if (!needsVenting && this.ventingStuck) - this.setVentingStuck(false); - - if (!this.getWorld().isRemote) { - this.markDirty(); - this.writeCustomData(GregtechDataCodes.NEEDS_VENTING, (buf) -> buf.writeBoolean(needsVenting)); - } - } - @Override public T getCapability(Capability capability, EnumFacing side) { if (capability == GregtechTileCapabilities.CAPABILITY_CONTROLLABLE) { @@ -279,16 +245,6 @@ public T getCapability(Capability capability, EnumFacing side) { return super.getCapability(capability, side); } - @Override - public boolean isInventoryFull() { - return isInventoryFull; - } - - @Override - public void setInventoryFull(boolean isFull) { - this.isInventoryFull = isFull; - } - @Override public boolean isWorkingEnabled() { return this.minerLogic.isWorkingEnabled(); @@ -304,25 +260,23 @@ public boolean isNeedsVenting() { return this.needsVenting; } + public void setVentingStuck(boolean ventingStuck) { + if (this.ventingStuck == ventingStuck) return; + this.ventingStuck = ventingStuck; + if (!this.getWorld().isRemote) { + this.markDirty(); + this.writeCustomData(GregtechDataCodes.VENTING_STUCK, (buf) -> buf.writeBoolean(ventingStuck)); + } + } + @Override public void tryDoVenting() { - BlockPos machinePos = this.getPos(); - EnumFacing ventingSide = EnumFacing.UP; - BlockPos ventingBlockPos = machinePos.offset(ventingSide); - IBlockState blockOnPos = this.getWorld().getBlockState(ventingBlockPos); - if (blockOnPos.getCollisionBoundingBox(this.getWorld(), ventingBlockPos) == Block.NULL_AABB) { - this.getWorld().getEntitiesWithinAABB(EntityLivingBase.class, new AxisAlignedBB(ventingBlockPos), EntitySelectors.CAN_AI_TARGET).forEach((entity) -> entity.attackEntityFrom(DamageSources.getHeatDamage(), 6.0F)); - WorldServer world = (WorldServer) this.getWorld(); - double posX = (double) machinePos.getX() + 0.5D + (double) ventingSide.getXOffset() * 0.6D; - double posY = (double) machinePos.getY() + 0.5D + (double) ventingSide.getYOffset() * 0.6D; - double posZ = (double) machinePos.getZ() + 0.5D + (double) ventingSide.getZOffset() * 0.6D; - world.spawnParticle(EnumParticleTypes.SMOKE_LARGE, posX, posY, posZ, 7 + world.rand.nextInt(3), (double) ventingSide.getXOffset() / 2.0D, (double) ventingSide.getYOffset() / 2.0D, (double) ventingSide.getZOffset() / 2.0D, 0.1D); - if (ConfigHolder.machines.machineSounds && !this.isMuffled()) { - world.playSound(null, posX, posY, posZ, SoundEvents.BLOCK_LAVA_EXTINGUISH, SoundCategory.BLOCKS, 1.0F, 1.0F); - } - this.setNeedsVenting(false); - } else if (!this.ventingStuck) { - this.setVentingStuck(true); + if (GTUtility.tryVenting(getWorld(), getPos(), EnumFacing.UP, + 6, true, + ConfigHolder.machines.machineSounds && !this.isMuffled())) { + setNeedsVenting(false); + } else { + setVentingStuck(true); } } @@ -331,10 +285,22 @@ public boolean isVentingStuck() { return ventingStuck; } + @Override + public void setNeedsVenting(boolean needsVenting) { + this.needsVenting = needsVenting; + if (!needsVenting && this.ventingStuck) + this.setVentingStuck(false); + + if (!this.getWorld().isRemote) { + this.markDirty(); + this.writeCustomData(GregtechDataCodes.NEEDS_VENTING, (buf) -> buf.writeBoolean(needsVenting)); + } + } + @Nonnull @Override public List getDataInfo() { - int workingArea = getWorkingArea(this.minerLogic.getCurrentRadius()); - return Collections.singletonList(new TextComponentTranslation("gregtech.machine.miner.working_area", workingArea, workingArea)); + int diameter = this.minerLogic.getCurrentDiameter(); + return Collections.singletonList(new TextComponentTranslation("gregtech.machine.miner.working_area", diameter, diameter)); } } diff --git a/src/main/java/gregtech/common/metatileentities/miner/SteamMinerLogic.java b/src/main/java/gregtech/common/metatileentities/miner/SteamMinerLogic.java new file mode 100644 index 00000000000..fba84a9174e --- /dev/null +++ b/src/main/java/gregtech/common/metatileentities/miner/SteamMinerLogic.java @@ -0,0 +1,27 @@ +package gregtech.common.metatileentities.miner; + +import net.minecraft.util.math.BlockPos; + +import javax.annotation.Nonnull; + +public class SteamMinerLogic extends MinerLogic { + + public SteamMinerLogic(@Nonnull SteamMiner steamMiner, int workFrequency, int maximumRadius) { + super(steamMiner, workFrequency, maximumRadius); + } + + @Override + protected boolean canOperate() { + if (mte.isNeedsVenting()) { + mte.tryDoVenting(); + if (mte.isVentingStuck()) return false; + } + + return super.canOperate(); + } + + @Override + protected void onMineOperation(@Nonnull BlockPos pos, boolean isOre, boolean isOrigin) { + mte.setNeedsVenting(true); + } +} 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 ce6cd351b24..4170c40f832 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/electric/MetaTileEntityCleanroom.java +++ b/src/main/java/gregtech/common/metatileentities/multi/electric/MetaTileEntityCleanroom.java @@ -25,6 +25,7 @@ import gregtech.common.blocks.BlockGlassCasing; import gregtech.common.blocks.MetaBlocks; import gregtech.common.metatileentities.MetaTileEntities; +import gregtech.common.metatileentities.miner.MetaTileEntityLargeMiner; import gregtech.common.metatileentities.multi.MetaTileEntityCokeOven; import gregtech.common.metatileentities.multi.MetaTileEntityPrimitiveBlastFurnace; import gregtech.common.metatileentities.multi.MetaTileEntityPrimitiveWaterPump; diff --git a/src/main/java/gregtech/common/terminal/app/prospector/widget/WidgetProspectingMap.java b/src/main/java/gregtech/common/terminal/app/prospector/widget/WidgetProspectingMap.java index 5fa4256668b..4708a69c87f 100644 --- a/src/main/java/gregtech/common/terminal/app/prospector/widget/WidgetProspectingMap.java +++ b/src/main/java/gregtech/common/terminal/app/prospector/widget/WidgetProspectingMap.java @@ -22,6 +22,7 @@ import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.resources.I18n; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.network.PacketBuffer; import net.minecraft.util.math.BlockPos; @@ -120,7 +121,7 @@ public void detectAndSendChanges() { PacketProspecting packet = new PacketProspecting(playerChunkX + ox, playerChunkZ + oz, playerChunkX, playerChunkZ, (int) player.posX, (int) player.posZ, this.mode); switch (mode) { - case ORE: + case ORE -> { BlockPos.MutableBlockPos pos = new BlockPos.MutableBlockPos(); for (int x = 0; x < 16; x++) { for (int z = 0; z < 16; z++) { @@ -128,41 +129,42 @@ public void detectAndSendChanges() { for (int y = 1; y < ySize; y++) { pos.setPos(x, y, z); IBlockState state = chunk.getBlockState(pos); - ItemStack itemBlock = GTUtility.toItem(state); - if (GTUtility.isOre(itemBlock)) { - boolean added = false; - String oreDictString = OreDictUnifier.getOreDictionaryNames(itemBlock).stream() - .findFirst() - .orElse(""); - OrePrefix prefix = OreDictUnifier.getPrefix(itemBlock); - if (prefix != null) { - for (StoneType type : StoneType.STONE_TYPE_REGISTRY) { - if (type.processingPrefix == prefix && type.shouldBeDroppedAsItem) { - packet.addBlock(x, y, z, oreDictString); + if (!BlockUtility.isOre(state)) continue; + + Item item = Item.getItemFromBlock(state.getBlock()); + int meta = state.getBlock().getMetaFromState(state); + boolean added = false; + String oreDictString = OreDictUnifier.getOreDictionaryNames(item, meta).stream() + .findFirst() + .orElse(""); + OrePrefix prefix = OreDictUnifier.getPrefix(item, meta); + if (prefix != null) { + for (StoneType type : StoneType.STONE_TYPE_REGISTRY) { + if (type.processingPrefix == prefix && type.shouldBeDroppedAsItem) { + packet.addBlock(x, y, z, oreDictString); + added = true; + break; + } else if (type.processingPrefix == prefix) { + MaterialStack materialStack = OreDictUnifier.getMaterial(item, meta); + if (materialStack != null) { + String oreDict = "ore" + oreDictString.replaceFirst(prefix.name(), ""); + packet.addBlock(x, y, z, oreDict); added = true; break; - } else if (type.processingPrefix == prefix) { - MaterialStack materialStack = OreDictUnifier.getMaterial(itemBlock); - if (materialStack != null) { - String oreDict = "ore" + oreDictString.replaceFirst(prefix.name(), ""); - packet.addBlock(x, y, z, oreDict); - added = true; - break; - } } } } - // Probably other mod's ores - if (!added) { - // Fallback - packet.addBlock(x, y, z, oreDictString); - } + } + // Probably other mod's ores + if (!added) { + // Fallback + packet.addBlock(x, y, z, oreDictString); } } } } - break; - case FLUID: + } + case FLUID -> { BedrockFluidVeinHandler.FluidVeinWorldEntry fStack = BedrockFluidVeinHandler.getFluidVeinWorldEntry(world, chunk.x, chunk.z); if (fStack != null && fStack.getDefinition() != null) { packet.addBlock(0, 3, 0, TextFormattingUtil.formatNumbers(100.0 * BedrockFluidVeinHandler.getOperationsRemaining(world, chunk.x, chunk.z) @@ -173,9 +175,7 @@ public void detectAndSendChanges() { packet.addBlock(0, 1, 0, fluid.getName()); } } - break; - default: - break; + } } writeUpdateInfo(2, packet::writePacketData); chunkIndex++; From 6b1b652dcca65c182d48036084ce137db7ec1e12 Mon Sep 17 00:00:00 2001 From: Tictim Date: Sat, 7 Oct 2023 01:02:45 +0900 Subject: [PATCH 02/27] Smaller Refactor --- .../api/capability/GregtechDataCodes.java | 4 +- .../java/gregtech/api/gui/GuiTextures.java | 1 + .../metatileentities/MetaTileEntities.java | 2 +- .../common/metatileentities/miner/IMiner.java | 10 +- .../metatileentities/miner/IMiningArea.java | 81 +++++ .../miner/MetaTileEntityLargeMiner.java | 93 +++-- .../miner/MetaTileEntityMiner.java | 129 ++++--- .../metatileentities/miner/MinerLogic.java | 320 +++++++++--------- .../metatileentities/miner/MinerUtil.java | 88 +++++ .../miner/MultiblockMinerLogic.java | 113 +++++-- .../miner/SimpleMiningArea.java | 224 ++++++++++++ .../metatileentities/miner/SteamMiner.java | 117 ++++--- .../miner/SteamMinerLogic.java | 4 +- .../electric/MetaTileEntityFluidDrill.java | 2 +- .../resources/assets/gregtech/lang/en_us.lang | 45 ++- .../textures/fx/miner_area_preview.png | Bin 0 -> 273 bytes .../gui/widget/button_miner_area_preview.png | Bin 0 -> 314 bytes 17 files changed, 914 insertions(+), 319 deletions(-) create mode 100644 src/main/java/gregtech/common/metatileentities/miner/IMiningArea.java create mode 100644 src/main/java/gregtech/common/metatileentities/miner/MinerUtil.java create mode 100644 src/main/java/gregtech/common/metatileentities/miner/SimpleMiningArea.java create mode 100644 src/main/resources/assets/gregtech/textures/fx/miner_area_preview.png create mode 100644 src/main/resources/assets/gregtech/textures/gui/widget/button_miner_area_preview.png diff --git a/src/main/java/gregtech/api/capability/GregtechDataCodes.java b/src/main/java/gregtech/api/capability/GregtechDataCodes.java index 8a8c0e0d536..4d5974ade04 100644 --- a/src/main/java/gregtech/api/capability/GregtechDataCodes.java +++ b/src/main/java/gregtech/api/capability/GregtechDataCodes.java @@ -40,8 +40,10 @@ public class GregtechDataCodes { public static final int INIT_CLIPBOARD_NBT = 3; public static final int UPDATE_UI = 10; // 10-36 - // Pump + // Pump, Miner public static final int PUMP_HEAD_LEVEL = 200; + // Miner + public static final int MINER_UPDATE_PREVIEW = 201; // Item Collector, Magic Energy Absorber, Large Boiler, Steam Oven public static final int IS_WORKING = 100; diff --git a/src/main/java/gregtech/api/gui/GuiTextures.java b/src/main/java/gregtech/api/gui/GuiTextures.java index 02a8400adfd..69252c1a413 100644 --- a/src/main/java/gregtech/api/gui/GuiTextures.java +++ b/src/main/java/gregtech/api/gui/GuiTextures.java @@ -69,6 +69,7 @@ public class GuiTextures { public static final TextureArea BUTTON_NO_DISTINCT_BUSES = TextureArea.fullImage("textures/gui/widget/button_no_distinct_buses.png"); public static final TextureArea BUTTON_NO_FLEX = TextureArea.fullImage("textures/gui/widget/button_no_flex.png"); public static final TextureArea BUTTON_MULTI_MAP = TextureArea.fullImage("textures/gui/widget/button_multi_map.png"); + public static final TextureArea BUTTON_MINER_AREA_PREVIEW = TextureArea.fullImage("textures/gui/widget/button_miner_area_preview.png"); public static final TextureArea BUTTON_MINER_MODES = TextureArea.fullImage("textures/gui/widget/button_miner_modes.png"); public static final TextureArea BUTTON_THROTTLE_MINUS = TextureArea.fullImage("textures/gui/widget/button_throttle_minus.png"); public static final TextureArea BUTTON_THROTTLE_PLUS = TextureArea.fullImage("textures/gui/widget/button_throttle_plus.png"); diff --git a/src/main/java/gregtech/common/metatileentities/MetaTileEntities.java b/src/main/java/gregtech/common/metatileentities/MetaTileEntities.java index ee5030ce9b5..3d81d0c27e5 100644 --- a/src/main/java/gregtech/common/metatileentities/MetaTileEntities.java +++ b/src/main/java/gregtech/common/metatileentities/MetaTileEntities.java @@ -312,7 +312,7 @@ public static void init() { STEAM_ROCK_BREAKER_BRONZE = registerMetaTileEntity(19, new SteamRockBreaker(gregtechId("steam_rock_breaker_bronze"), false)); STEAM_ROCK_BREAKER_STEEL = registerMetaTileEntity(20, new SteamRockBreaker(gregtechId("steam_rock_breaker_steel"), true)); - STEAM_MINER = registerMetaTileEntity(21, new SteamMiner(gregtechId("steam_miner"), 320, 4)); + STEAM_MINER = registerMetaTileEntity(21, new SteamMiner(gregtechId("steam_miner"), 320, 9)); // Electric Furnace, IDs 50-64 registerSimpleMetaTileEntity(ELECTRIC_FURNACE, 50, "electric_furnace", RecipeMaps.FURNACE_RECIPES, Textures.ELECTRIC_FURNACE_OVERLAY, true); diff --git a/src/main/java/gregtech/common/metatileentities/miner/IMiner.java b/src/main/java/gregtech/common/metatileentities/miner/IMiner.java index 97e8c936f79..38e939ff711 100644 --- a/src/main/java/gregtech/common/metatileentities/miner/IMiner.java +++ b/src/main/java/gregtech/common/metatileentities/miner/IMiner.java @@ -1,8 +1,9 @@ package gregtech.common.metatileentities.miner; -import gregtech.client.renderer.ICubeRenderer; -import net.minecraftforge.fml.relauncher.Side; -import net.minecraftforge.fml.relauncher.SideOnly; +import net.minecraft.util.text.ITextComponent; + +import javax.annotation.Nonnull; +import java.util.List; public interface IMiner { @@ -14,6 +15,5 @@ public interface IMiner { */ boolean drainMiningResources(boolean simulate); - @SideOnly(Side.CLIENT) - ICubeRenderer getPipeTexture(); + default void describeMiningResourceStatus(@Nonnull List textList) {} } diff --git a/src/main/java/gregtech/common/metatileentities/miner/IMiningArea.java b/src/main/java/gregtech/common/metatileentities/miner/IMiningArea.java new file mode 100644 index 00000000000..8dc8d0c8317 --- /dev/null +++ b/src/main/java/gregtech/common/metatileentities/miner/IMiningArea.java @@ -0,0 +1,81 @@ +package gregtech.common.metatileentities.miner; + +import codechicken.lib.render.CCRenderState; +import codechicken.lib.vec.Matrix4; +import gregtech.api.metatileentity.IFastRenderMetaTileEntity; +import gregtech.api.metatileentity.MetaTileEntity; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.network.PacketBuffer; +import net.minecraft.util.math.AxisAlignedBB; +import net.minecraft.util.math.BlockPos.MutableBlockPos; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +import javax.annotation.Nonnull; + +/** + * Object representing operation area of {@link MinerLogic}. + */ +public interface IMiningArea { + + /** + * Get current block position for processing. If this method returns {@code true}, {@code mpos} argument should be + * modified to the block position. Return value of {@code false} indicates there aren't any block left to process. + *
+ * Calling this method does not affect the state. Use {@link #nextBlock()} for advancing to next block. + * + * @param mpos Mutable block position + * @return {@code true} if {@code mpos} is set to current block position for processing, {@code false} otherwise + */ + boolean getCurrentBlockPos(@Nonnull MutableBlockPos mpos); + + /** + * Move on to next block for processing, if it exists. Does nothing if there aren't any block left to process. + * + * @see #getCurrentBlockPos(MutableBlockPos) + */ + void nextBlock(); + + /** + * Reset the cursor to starting point (i.e. re-start iteration from start) + */ + void reset(); + + @SideOnly(Side.CLIENT) + default void renderMetaTileEntityFast(@Nonnull MetaTileEntity mte, @Nonnull CCRenderState renderState, @Nonnull Matrix4 translation, float partialTicks) {} + + @SideOnly(Side.CLIENT) + default void renderMetaTileEntity(@Nonnull MetaTileEntity mte, double x, double y, double z, float partialTicks) {} + + @Nonnull + AxisAlignedBB getRenderBoundingBox(); + + default boolean shouldRenderInPass(int pass) { + return pass == IFastRenderMetaTileEntity.RENDER_PASS_NORMAL; + } + + default boolean isGlobalRenderer() { + return false; + } + + /** + * Write any persistent data here. + * + * @param data NBT data + */ + void write(@Nonnull NBTTagCompound data); + + /** + * Read any persistent data here. + * + * @param data NBT data + */ + void read(@Nonnull NBTTagCompound data); + + /** + * Write data for area preview. + * + * @param buffer Packet buffer + */ + void writePreviewPacket(@Nonnull PacketBuffer buffer); +} diff --git a/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityLargeMiner.java b/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityLargeMiner.java index b640d41fe56..a5bab4d0529 100644 --- a/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityLargeMiner.java +++ b/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityLargeMiner.java @@ -14,11 +14,10 @@ import gregtech.api.capability.impl.FluidTankList; import gregtech.api.capability.impl.ItemHandlerList; import gregtech.api.gui.GuiTextures; -import gregtech.api.gui.ModularUI; import gregtech.api.gui.Widget; -import gregtech.api.gui.widgets.AdvancedTextWidget; import gregtech.api.gui.widgets.ImageCycleButtonWidget; import gregtech.api.metatileentity.IDataInfoProvider; +import gregtech.api.metatileentity.IFastRenderMetaTileEntity; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.metatileentity.interfaces.IGregTechTileEntity; import gregtech.api.metatileentity.multiblock.IMultiblockPart; @@ -45,6 +44,7 @@ import net.minecraft.util.EnumHand; import net.minecraft.util.ResourceLocation; import net.minecraft.util.SoundEvent; +import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.Style; import net.minecraft.util.text.TextComponentTranslation; @@ -65,7 +65,7 @@ import static gregtech.api.unification.material.Materials.DrillingFluid; -public class MetaTileEntityLargeMiner extends MultiblockWithDisplayBase implements IMiner, IControllable, IDataInfoProvider { +public class MetaTileEntityLargeMiner extends MultiblockWithDisplayBase implements IMiner, IControllable, IDataInfoProvider, IFastRenderMetaTileEntity { @Nonnull public final ILargeMinerType type; @@ -146,18 +146,45 @@ protected boolean drainFluid(boolean simulate) { return drained != null && drained.amount >= amount; } - @Override - @SideOnly(Side.CLIENT) - public ICubeRenderer getPipeTexture() { - return getBaseTexture(null); - } - @Override @SideOnly(Side.CLIENT) public void renderMetaTileEntity(CCRenderState renderState, Matrix4 translation, IVertexOperation[] pipeline) { super.renderMetaTileEntity(renderState, translation, pipeline); this.getFrontOverlay().renderOrientedState(renderState, translation, pipeline, getFrontFacing(), this.minerLogic.isWorking(), this.isWorkingEnabled()); - minerLogic.renderPipe(renderState, translation, pipeline); + if (isStructureFormed()) { + EnumFacing back = getFrontFacing().getOpposite(); + MinerUtil.renderPipe(getBaseTexture(null), this.minerLogic.getPipeLength(), renderState, + translation.translate(back.getXOffset(), back.getYOffset(), back.getZOffset()), pipeline); + } + } + + @Override + public void renderMetaTileEntity(double x, double y, double z, float partialTicks) { + IMiningArea previewArea = this.minerLogic.getPreviewArea(); + if (previewArea != null) previewArea.renderMetaTileEntity(this, x, y, z, partialTicks); + } + + @Override + public void renderMetaTileEntityFast(CCRenderState renderState, Matrix4 translation, float partialTicks) { + IMiningArea previewArea = this.minerLogic.getPreviewArea(); + if (previewArea != null) previewArea.renderMetaTileEntityFast(this, renderState, translation, partialTicks); + } + + @Override + public AxisAlignedBB getRenderBoundingBox() { + IMiningArea previewArea = this.minerLogic.getPreviewArea(); + return previewArea != null ? previewArea.getRenderBoundingBox() : MinerUtil.EMPTY_AABB; + } + + @Override + public boolean shouldRenderInPass(int pass) { + IMiningArea previewArea = this.minerLogic.getPreviewArea(); + return previewArea != null && previewArea.shouldRenderInPass(pass); + } + + @Override + public boolean isGlobalRenderer() { + return true; } @Override @@ -219,9 +246,24 @@ protected void addDisplayText(List textList) { String voltageName = GTValues.VNF[energyContainer]; textList.add(new TextComponentTranslation("gregtech.multiblock.max_energy_per_tick", maxVoltage, voltageName)); } + this.minerLogic.addDisplayText(textList); + } + } - this.minerLogic.addMinerArea(textList); - this.minerLogic.addMinerWorkStatus(textList); + @Override + protected void handleDisplayClick(String componentData, Widget.ClickData clickData) { + switch (componentData) { + case MinerUtil.DISPLAY_CLICK_AREA_PREVIEW -> this.minerLogic.setPreviewEnabled(true); + case MinerUtil.DISPLAY_CLICK_AREA_PREVIEW_HIDE -> this.minerLogic.setPreviewEnabled(false); + case MinerUtil.DISPLAY_CLICK_Y_LIMIT_DECR -> this.minerLogic.setYLimit(Math.max(0, + this.minerLogic.getYLimit() - (clickData.isShiftClick ? 5 : 1))); + case MinerUtil.DISPLAY_CLICK_Y_LIMIT_INCR -> { + int yLimit = this.minerLogic.getYLimit() + (clickData.isShiftClick ? 5 : 1); + if (yLimit < 0) yLimit = this.minerLogic.getYLimit() < 0 ? 0 : Integer.MAX_VALUE; + this.minerLogic.setYLimit(yLimit); + } + case MinerUtil.DISPLAY_CLICK_REPEAT_ENABLE -> this.minerLogic.setRepeat(true); + case MinerUtil.DISPLAY_CLICK_REPEAT_DISABLE -> this.minerLogic.setRepeat(false); } } @@ -229,12 +271,17 @@ protected void addDisplayText(List textList) { protected void addWarningText(List textList) { super.addWarningText(textList); if (isStructureFormed()) { - this.minerLogic.addInventoryStatus(textList); + if (this.minerLogic.isInventoryFull()) { + textList.add(new TextComponentTranslation("gregtech.machine.miner.display.inventory_full") + .setStyle(new Style().setColor(TextFormatting.RED))); + } if (!drainFluid(true)) { - textList.add(new TextComponentTranslation("gregtech.machine.miner.multi.needsfluid").setStyle(new Style().setColor(TextFormatting.RED))); + textList.add(new TextComponentTranslation("gregtech.machine.miner.multi.needsfluid") + .setStyle(new Style().setColor(TextFormatting.RED))); } if (!drainEnergy(true)) { - textList.add(new TextComponentTranslation("gregtech.machine.miner.needspower").setStyle(new Style().setColor(TextFormatting.RED))); + textList.add(new TextComponentTranslation("gregtech.multiblock.not_enough_energy") + .setStyle(new Style().setColor(TextFormatting.RED))); } } } @@ -283,18 +330,6 @@ protected ICubeRenderer getFrontOverlay() { return this.type.getFrontOverlay(); } - @Override - protected ModularUI.Builder createUITemplate(EntityPlayer entityPlayer) { - return super.createUITemplate(entityPlayer) - .widget(new AdvancedTextWidget(63, 31 + 10, textList -> { - if (this.isStructureFormed()) { - this.minerLogic.addLastMinedBlock(textList); - } - }, 0xFFFFFF) - .setMaxWidthLimit(68 - 10) - .setClickHandler(this::handleDisplayClick)); - } - @Nonnull @Override protected Widget getFlexButton(int x, int y, int width, int height) { @@ -330,7 +365,7 @@ public boolean onScrewdriverClick(EntityPlayer player, EnumHand hand, EnumFacing player.sendMessage(new TextComponentTranslation("gregtech.machine.miner.working_area_chunks", workingAreaChunks, workingAreaChunks)); } else { int diameter = this.minerLogic.getCurrentDiameter() - 8; - if(diameter <= 0) diameter = this.minerLogic.getMaximumDiameter(); + if (diameter <= 0) diameter = this.minerLogic.getMaximumDiameter(); this.minerLogic.setCurrentDiameter(diameter); player.sendMessage(new TextComponentTranslation("gregtech.universal.tooltip.working_area", diameter, diameter)); @@ -376,7 +411,7 @@ public SoundEvent getSound() { @Override public boolean isActive() { - return isStructureFormed()&& minerLogic.isActive(); + return isStructureFormed() && minerLogic.isActive(); } @Nonnull diff --git a/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityMiner.java b/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityMiner.java index aa167e54660..1721e1ef23f 100644 --- a/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityMiner.java +++ b/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityMiner.java @@ -4,6 +4,7 @@ import codechicken.lib.render.CCRenderState; import codechicken.lib.render.pipeline.IVertexOperation; import codechicken.lib.vec.Matrix4; +import com.google.common.math.IntMath; import gregtech.api.GTValues; import gregtech.api.capability.GregtechTileCapabilities; import gregtech.api.capability.IControllable; @@ -11,13 +12,15 @@ import gregtech.api.capability.impl.NotifiableItemStackHandler; import gregtech.api.gui.GuiTextures; import gregtech.api.gui.ModularUI; -import gregtech.api.gui.widgets.AdvancedTextWidget; +import gregtech.api.gui.widgets.ImageWidget; +import gregtech.api.gui.widgets.ProgressWidget; import gregtech.api.gui.widgets.SlotWidget; +import gregtech.api.gui.widgets.ToggleButtonWidget; import gregtech.api.metatileentity.IDataInfoProvider; +import gregtech.api.metatileentity.IFastRenderMetaTileEntity; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.metatileentity.TieredMetaTileEntity; import gregtech.api.metatileentity.interfaces.IGregTechTileEntity; -import gregtech.client.renderer.ICubeRenderer; import gregtech.client.renderer.texture.Textures; import gregtech.core.sound.GTSoundEvents; import net.minecraft.client.resources.I18n; @@ -26,6 +29,7 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.PacketBuffer; import net.minecraft.util.*; +import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.Style; import net.minecraft.util.text.TextComponentTranslation; @@ -39,10 +43,11 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; +import java.math.RoundingMode; import java.util.Collections; import java.util.List; -public class MetaTileEntityMiner extends TieredMetaTileEntity implements IMiner, IControllable, IDataInfoProvider { +public class MetaTileEntityMiner extends TieredMetaTileEntity implements IMiner, IControllable, IDataInfoProvider, IFastRenderMetaTileEntity { private final ItemStackHandler chargerInventory; @@ -51,6 +56,8 @@ public class MetaTileEntityMiner extends TieredMetaTileEntity implements IMiner, private final MinerLogic minerLogic; + private boolean hasNotEnoughEnergy; + public MetaTileEntityMiner(@Nonnull ResourceLocation metaTileEntityId, int tier, int workFrequency, int maximumDiameter) { super(metaTileEntityId, tier); this.inventorySize = (tier + 1) * (tier + 1); @@ -86,58 +93,94 @@ public void renderMetaTileEntity(CCRenderState renderState, Matrix4 translation, } else Textures.CHUNK_MINER_OVERLAY.renderSided(renderSide, renderState, translation, pipeline); } - minerLogic.renderPipe(renderState, translation, pipeline); + MinerUtil.renderPipe(Textures.SOLID_STEEL_CASING, this.minerLogic.getPipeLength(), renderState, translation, pipeline); + } + + @Override + public void renderMetaTileEntity(double x, double y, double z, float partialTicks) { + IMiningArea previewArea = this.minerLogic.getPreviewArea(); + if (previewArea != null) previewArea.renderMetaTileEntity(this, x, y, z, partialTicks); + } + + @Override + public void renderMetaTileEntityFast(CCRenderState renderState, Matrix4 translation, float partialTicks) { + IMiningArea previewArea = this.minerLogic.getPreviewArea(); + if (previewArea != null) previewArea.renderMetaTileEntityFast(this, renderState, translation, partialTicks); + } + + @Override + public AxisAlignedBB getRenderBoundingBox() { + IMiningArea previewArea = this.minerLogic.getPreviewArea(); + return previewArea != null ? previewArea.getRenderBoundingBox() : MinerUtil.EMPTY_AABB; + } + + @Override + public boolean shouldRenderInPass(int pass) { + IMiningArea previewArea = this.minerLogic.getPreviewArea(); + return previewArea != null && previewArea.shouldRenderInPass(pass); + } + + @Override + public boolean isGlobalRenderer() { + return true; } @Override protected ModularUI createUI(@Nonnull EntityPlayer entityPlayer) { - int rowSize = (int) Math.sqrt(inventorySize); - ModularUI.Builder builder = new ModularUI.Builder(GuiTextures.BACKGROUND, 195, 176); - builder.bindPlayerInventory(entityPlayer.inventory, 94); - - if (getTier() == GTValues.HV) { - for (int y = 0; y < rowSize; y++) { - for (int x = 0; x < rowSize; x++) { - int index = y * rowSize + x; - builder.widget(new SlotWidget(exportItems, index, 151 - rowSize * 9 + x * 18, 18 + y * 18, true, false) - .setBackgroundTexture(GuiTextures.SLOT)); - } - } - } else { - for (int y = 0; y < rowSize; y++) { - for (int x = 0; x < rowSize; x++) { - int index = y * rowSize + x; - builder.widget(new SlotWidget(exportItems, index, 142 - rowSize * 9 + x * 18, 18 + y * 18, true, false) - .setBackgroundTexture(GuiTextures.SLOT)); - } - } + IItemHandlerModifiable exportItems = this.getExportItems(); + int slots = exportItems.getSlots(); + int columns = IntMath.sqrt(slots, RoundingMode.UP); + int xStart = (176 - (18 * columns)) / 2; + int yOffset = Math.max(0, 16 + ((columns + 1) * 18) + 4 - 80); + int yStart = yOffset > 0 ? 16 : 21; + int sideWidgetY = yStart + (columns * 18 - 20) / 2; + + ModularUI.Builder builder = ModularUI.defaultBuilder(yOffset) + .label(5, 5, getMetaFullName()) + .widget(new ToggleButtonWidget(152, 25, 18, 18, + GuiTextures.BUTTON_MINER_AREA_PREVIEW, + this.minerLogic::isPreviewEnabled, this.minerLogic::setPreviewEnabled)) + .widget(new SlotWidget(this.chargerInventory, 0, 79, 62 + yOffset, true, true, false) + .setBackgroundTexture(GuiTextures.SLOT, GuiTextures.CHARGER_OVERLAY) + .setTooltipText("gregtech.gui.charger_slot.tooltip", GTValues.VNF[getTier()], GTValues.VNF[getTier()])); + + for (int i = 0; i < slots; i++) { + builder.slot(exportItems, i, xStart + 18 * (i % columns), yStart + 18 * (i / columns), + true, false, GuiTextures.SLOT); } - builder.image(7, 16, 105, 75, GuiTextures.DISPLAY) - .label(6, 6, getMetaFullName()); - builder.widget(new AdvancedTextWidget(10, 19, this::addDisplayText, 0xFFFFFF) - .setMaxWidthLimit(84)); - builder.widget(new AdvancedTextWidget(70, 19, this.minerLogic::addLastMinedBlock, 0xFFFFFF) - .setMaxWidthLimit(84)); - builder.widget(new SlotWidget(chargerInventory, 0, 171, 152) - .setBackgroundTexture(GuiTextures.SLOT, GuiTextures.CHARGER_OVERLAY)); + builder.widget( + new ProgressWidget(() -> { + if (!this.minerLogic.isWorking()) return 0; + int workFrequency = this.minerLogic.getWorkFrequency(); + return workFrequency < 2 ? 1 : (getOffsetTimer() % workFrequency) / (double) workFrequency; + }, xStart - 4 - 20, sideWidgetY, 20, 20, + GuiTextures.PROGRESS_BAR_MACERATE, ProgressWidget.MoveType.HORIZONTAL) + ).widget( + new ImageWidget(xStart - 4 - 20, sideWidgetY + 20, 18, 18, + GuiTextures.INDICATOR_NO_ENERGY) + .setIgnoreColor(true) + .setPredicate(() -> this.hasNotEnoughEnergy) + ).widget( + new ImageWidget(152, 63 + yOffset, 17, 17, + GTValues.XMAS.get() ? GuiTextures.GREGTECH_LOGO_XMAS : GuiTextures.GREGTECH_LOGO) + .setIgnoreColor(true) + ).bindPlayerInventory(entityPlayer.inventory, GuiTextures.SLOT, yOffset); return builder.build(getHolder(), entityPlayer); } - private void addDisplayText(@Nonnull List textList) { - this.minerLogic.addMinerArea(textList); - this.minerLogic.addMinerWorkStatus(textList); - this.minerLogic.addInventoryStatus(textList); + @Override + public void describeMiningResourceStatus(@Nonnull List textList) { if (!drainMiningResources(true)) { - textList.add(new TextComponentTranslation("gregtech.machine.miner.needspower").setStyle(new Style().setColor(TextFormatting.RED))); + textList.add(new TextComponentTranslation("gregtech.multiblock.not_enough_energy") + .setStyle(new Style().setColor(TextFormatting.RED))); } } @Override public void addInformation(ItemStack stack, @Nullable World player, @Nonnull List tooltip, boolean advanced) { - int currentArea = minerLogic.getCurrentDiameter(); - tooltip.add(I18n.format("gregtech.machine.miner.tooltip", currentArea, currentArea)); + tooltip.add(I18n.format("gregtech.machine.miner.tooltip")); tooltip.add(I18n.format("gregtech.universal.tooltip.uses_per_tick", energyPerTick) + TextFormatting.GRAY + ", " + I18n.format("gregtech.machine.miner.per_block", this.minerLogic.getWorkFrequency() / 20)); tooltip.add(I18n.format("gregtech.universal.tooltip.voltage_in", energyContainer.getInputVoltage(), GTValues.VNF[getTier()])); @@ -158,20 +201,16 @@ public void addToolUsages(ItemStack stack, @Nullable World world, List t public boolean drainMiningResources(boolean simulate) { long resultEnergy = energyContainer.getEnergyStored() - energyPerTick; if (resultEnergy < 0 || resultEnergy > energyContainer.getEnergyCapacity()) { + this.hasNotEnoughEnergy = true; return false; } if (!simulate) { energyContainer.removeEnergy(energyPerTick); } + this.hasNotEnoughEnergy = false; return true; } - @Override - @SideOnly(Side.CLIENT) - public ICubeRenderer getPipeTexture() { - return Textures.SOLID_STEEL_CASING; - } - @Override public void update() { super.update(); diff --git a/src/main/java/gregtech/common/metatileentities/miner/MinerLogic.java b/src/main/java/gregtech/common/metatileentities/miner/MinerLogic.java index 8738f7f7bb2..eb9834628c9 100644 --- a/src/main/java/gregtech/common/metatileentities/miner/MinerLogic.java +++ b/src/main/java/gregtech/common/metatileentities/miner/MinerLogic.java @@ -1,85 +1,29 @@ package gregtech.common.metatileentities.miner; -import codechicken.lib.render.CCRenderState; -import codechicken.lib.render.pipeline.IVertexOperation; -import codechicken.lib.vec.Cuboid6; -import codechicken.lib.vec.Matrix4; import gregtech.api.capability.GregtechDataCodes; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.util.BlockUtility; -import gregtech.api.util.GTLog; import gregtech.api.util.GTTransferUtils; -import gregtech.client.renderer.texture.Textures; -import gregtech.common.ConfigHolder; -import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.PacketBuffer; -import net.minecraft.util.EnumFacing; import net.minecraft.util.NonNullList; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos.MutableBlockPos; import net.minecraft.util.math.MathHelper; -import net.minecraft.util.text.ITextComponent; -import net.minecraft.util.text.Style; -import net.minecraft.util.text.TextComponentTranslation; -import net.minecraft.util.text.TextFormatting; import net.minecraft.world.World; import net.minecraft.world.WorldServer; import net.minecraftforge.common.util.Constants; -import net.minecraftforge.fml.relauncher.Side; -import net.minecraftforge.fml.relauncher.SideOnly; import net.minecraftforge.items.IItemHandlerModifiable; -import org.apache.commons.lang3.StringUtils; import org.jetbrains.annotations.Nullable; import javax.annotation.Nonnull; -import java.util.List; import java.util.Objects; public class MinerLogic { - /** - * Maximum amount of blocks to scan in one tick - */ - private static final int MAX_BLOCK_SCAN = 100; - - private static final Cuboid6 PIPE_CUBOID = new Cuboid6(4 / 16.0, 0.0, 4 / 16.0, 12 / 16.0, 1.0, 12 / 16.0); - - private static String oreReplacementConfigCache; - private static IBlockState oreReplacement; - - @Nonnull - @SuppressWarnings("deprecation") - public static IBlockState getOreReplacement() { - String config = ConfigHolder.machines.replaceMinedBlocksWith; - if (Objects.equals(oreReplacementConfigCache, config)) { - return oreReplacement; - } - - oreReplacementConfigCache = config; - - String[] blockDescription = StringUtils.split(config, ":"); - String blockName = blockDescription.length <= 2 ? config : blockDescription[0] + ":" + blockDescription[1]; - Block block = Block.getBlockFromName(blockName); - - if (block == null) { - GTLog.logger.error("Invalid configuration on entry 'machines/replaceMinedBlocksWith': Cannot find block with name '{}', using cobblestone as fallback.", blockName); - return oreReplacement = Blocks.COBBLESTONE.getDefaultState(); - } else if (blockDescription.length <= 2 || blockDescription[2].isEmpty()) { - return oreReplacement = block.getDefaultState(); - } else { - try { - return oreReplacement = block.getDefaultState().getBlock().getStateFromMeta(Integer.parseInt(blockDescription[2])); - } catch (NumberFormatException ex) { - GTLog.logger.error("Invalid configuration on entry 'machines/replaceMinedBlocksWith': Cannot parse metadata value '{}' as integer, using cobblestone as fallback.", blockDescription[2]); - return oreReplacement = Blocks.COBBLESTONE.getDefaultState(); - } - } - } - protected final MTE mte; private final int workFrequency; @@ -92,18 +36,26 @@ public static IBlockState getOreReplacement() { private boolean done; private boolean workingEnabled = true; - protected long nextBlock; - // last mined ore block - protected final MutableBlockPos lastMinedOre = new MutableBlockPos(); protected boolean hasLastMinedOre; + // number of ores processed so far protected int minedOreCount; + // pipe length used for rendering purposes private int pipeLength; + // non-negative value to limit Y level + private int yLimit; + + // bool config for repeating the operation after finished + private boolean repeat; + // transient values below (not saved) + @Nullable + private IMiningArea miningArea; + // flag indicating last insertion to inventory failed private boolean inventoryFull; // flag indicating scan area should be rebuilt @@ -111,13 +63,11 @@ public static IBlockState getOreReplacement() { // status of the last update; true means miner is working, false means no private boolean active; - // scan area; essentially bottomless AABB. + private boolean preview; - protected int startX; - protected int startY; - protected int startZ; - protected int endX; - protected int endZ; + // remote instance only, contains IMiningArea instances deserialized from packet + @Nullable + private IMiningArea previewArea; /** * Creates the general logic for all in-world ore block miners @@ -188,6 +138,19 @@ public boolean isWorkingEnabled() { return this.workingEnabled; } + public boolean isInventoryFull() { + return this.inventoryFull; + } + + public int getPipeLength() { + return this.pipeLength; + } + + @Nullable + public IMiningArea getPreviewArea() { + return this.previewArea; + } + /** * @param isWorkingEnabled the new state of the miner's ability to work: true to change to enabled, else false */ @@ -202,6 +165,43 @@ public void setWorkingEnabled(boolean isWorkingEnabled) { } } + public int getYLimit() { + return yLimit; + } + + public void setYLimit(int yLimit) { + if (yLimit != this.yLimit) { + this.yLimit = yLimit; + this.rebuildScanArea = true; + this.mte.markDirty(); + if (this.preview) { + updatePreview(); + } + } + } + + public boolean isPreviewEnabled() { + return preview; + } + + public void setPreviewEnabled(boolean previewEnabled) { + if (this.preview != previewEnabled) { + this.preview = previewEnabled; + updatePreview(); + } + } + + public boolean isRepeat() { + return repeat; + } + + public void setRepeat(boolean repeat) { + if (this.repeat != repeat) { + this.repeat = repeat; + this.mte.markDirty(); + } + } + /** * @return whether the miner is currently working */ @@ -213,11 +213,10 @@ public boolean isWorking() { * Recalculates the mining area and restarts the miner, if it was done */ public void reset() { - this.nextBlock = 0; this.hasLastMinedOre = false; this.pipeLength = 0; - initBoundary(); + this.miningArea = Objects.requireNonNull(createMiningArea(), "createMiningArea() returned null!"); if (this.done) { this.setWorkingEnabled(false); @@ -237,17 +236,26 @@ protected BlockPos getOrigin() { } /** - * Initialize block boundary for mining, i.e. {@link #startX}, {@link #startY}, {@link #startZ}, {@link #endX} and - * {@link #endZ} + * Create instance of {@link IMiningArea} based on current state. + * + * @return new {@link IMiningArea} instance */ - protected void initBoundary() { + @Nonnull + protected IMiningArea createMiningArea() { BlockPos origin = getOrigin(); int radius = this.currentDiameter / 2; - this.startX = origin.getX() - radius; - this.startY = origin.getY(); - this.startZ = origin.getZ() - radius; - this.endX = origin.getX() + radius; - this.endZ = origin.getZ() + radius; + int startX = origin.getX() - radius; + int startY = origin.getY() - 1; + int startZ = origin.getZ() - radius; + int endX = startX + this.currentDiameter; + int endY = this.yLimit > 0 ? origin.getY() - this.yLimit : Integer.MIN_VALUE; + int endZ = startZ + this.currentDiameter; + return new SimpleMiningArea(startX, startY, startZ, endX, endY, endZ); + } + + @Nonnull + protected IMiningArea readPreviewArea(@Nonnull PacketBuffer buffer) { + return SimpleMiningArea.readPreview(buffer); } /** @@ -267,38 +275,50 @@ public void update() { } private boolean mine() { - if (!this.workingEnabled || this.done || !canOperate()) { + if (!this.workingEnabled || (!this.repeat && this.done) || !canOperate()) { return false; } - if (this.rebuildScanArea) { + if (this.rebuildScanArea || this.miningArea == null) { this.rebuildScanArea = false; reset(); } + IMiningArea miningArea = Objects.requireNonNull(this.miningArea); + + if (this.repeat && this.done) { + this.done = false; + miningArea.reset(); + } + World world = mte.getWorld(); - for (int i = MAX_BLOCK_SCAN; i > 0; i--) { - BlockPos pos = getBlockPosAt(this.nextBlock); - if (pos == null || !world.isValid(pos)) { - this.done = true; + BlockPos origin = getOrigin(); + for (int i = MinerUtil.MAX_BLOCK_SCAN; i > 0; i--) { + MutableBlockPos pos = this.mpos; + if (!miningArea.getCurrentBlockPos(pos) || !world.isValid(pos) || (this.yLimit > 0 && origin.getY() - yLimit > pos.getY())) { + if (this.repeat) { + miningArea.reset(); + } else { + this.done = true; + } return false; } IBlockState state = world.getBlockState(pos); - boolean isOrigin = alignsWithOrigin(pos); + boolean isOrigin = pos.getX() == origin.getX() && pos.getZ() == origin.getZ(); // skip unbreakable block / TE blocks if (state.getBlockHardness(world, pos) < 0 || state.getBlock().hasTileEntity(state)) { // center block (where mining pipes goes in) can be skipped by this, it'll probably look kind of janky // but it's 100x better than voiding bedrock if (isOrigin) incrementPipeLength(); - this.nextBlock++; + miningArea.nextBlock(); continue; } boolean isOre = BlockUtility.isOre(state); if (!isOrigin && !isOre) { - this.nextBlock++; + miningArea.nextBlock(); continue; } @@ -317,12 +337,9 @@ private boolean mine() { this.minedOreCount++; } this.mte.drainMiningResources(false); - world.setBlockState(pos, isOrigin ? Blocks.AIR.getDefaultState() : getOreReplacement()); - + world.setBlockState(pos, isOrigin ? Blocks.AIR.getDefaultState() : MinerUtil.getOreReplacement()); if (isOrigin) incrementPipeLength(); - - this.nextBlock++; - + miningArea.nextBlock(); onMineOperation(pos, isOre, isOrigin); this.mte.markDirty(); return true; @@ -330,25 +347,6 @@ private boolean mine() { return true; } - @Nullable - protected final BlockPos getBlockPosAt(long index) { - if (index < 0) return null; - int sizeX = this.endX - this.startX; - int sizeZ = this.endZ - this.startZ; - if (sizeX <= 0 || sizeZ <= 0) return null; - - int x = this.startX + (int) (index % sizeX); - index /= sizeX; - int z = this.startZ + (int) (index % sizeZ); - int y = this.startY - (int) (index / sizeZ); - return this.mpos.setPos(x, y, z); - } - - private boolean alignsWithOrigin(@Nonnull BlockPos pos) { - BlockPos origin = getOrigin(); - return pos.getX() == origin.getX() && pos.getZ() == origin.getZ(); - } - @SuppressWarnings("BooleanMethodIsAlwaysInverted") protected boolean canOperate() { return this.mte.drainMiningResources(true); @@ -377,25 +375,52 @@ protected void getRegularBlockDrops(@Nonnull NonNullList drops, @Nonn private void incrementPipeLength() { this.pipeLength++; + this.mte.markDirty(); this.mte.writeCustomData(GregtechDataCodes.PUMP_HEAD_LEVEL, b -> b.writeVarInt(pipeLength)); } private void resetPipeLength() { if (this.pipeLength == 0) return; this.pipeLength = 0; + this.mte.markDirty(); this.mte.writeCustomData(GregtechDataCodes.PUMP_HEAD_LEVEL, b -> b.writeVarInt(pipeLength)); } + private void updatePreview() { + this.mte.writeCustomData(GregtechDataCodes.MINER_UPDATE_PREVIEW, this::writePreviewUpdatePacket); + } + + private void writePreviewUpdatePacket(@Nonnull PacketBuffer buffer) { + if (!this.preview) { + buffer.writeBoolean(false); + return; + } + buffer.writeBoolean(true); + if (this.miningArea == null) { + this.miningArea = Objects.requireNonNull(createMiningArea(), "createMiningArea() returned null!"); + } + this.miningArea.writePreviewPacket(buffer); + buffer.writeVarInt(this.yLimit); + } + + private void readPreviewUpdatePacket(@Nonnull PacketBuffer buffer) { + if (!buffer.readBoolean()) { + this.previewArea = null; + return; + } + this.previewArea = readPreviewArea(buffer); + this.yLimit = buffer.readVarInt(); + } + /** - * renders the pipe beneath the miner + * Get the block currently being mined by this miner. + * + * @param mpos Mutable block position + * @return {@code true} if the block exists (in which the {@code mpos} instance gets modified with the value, or + * {@code false} if it does not exist */ - @SideOnly(Side.CLIENT) - public void renderPipe(CCRenderState renderState, Matrix4 translation, IVertexOperation[] pipeline) { - Textures.PIPE_IN_OVERLAY.renderSided(EnumFacing.DOWN, renderState, translation, pipeline); - for (int i = 0; i < this.pipeLength; i++) { - translation.translate(0.0, -1.0, 0.0); - this.mte.getPipeTexture().render(renderState, translation, pipeline, PIPE_CUBOID); - } + public boolean getCurrentBlock(@Nonnull MutableBlockPos mpos) { + return this.miningArea != null && this.miningArea.getCurrentBlockPos(mpos); } /** @@ -404,9 +429,8 @@ public void renderPipe(CCRenderState renderState, Matrix4 translation, IVertexOp @Nonnull public NBTTagCompound writeToNBT(@Nonnull NBTTagCompound data) { data.setInteger("currentDiameter", this.currentDiameter); - data.setBoolean("done", this.done); - data.setBoolean("workingEnabled", this.workingEnabled); - data.setLong("nextBlock", this.nextBlock); + if (this.done) data.setBoolean("done", true); + if (!this.workingEnabled) data.setBoolean("disabled", true); if (this.hasLastMinedOre) { data.setInteger("lastMinedOreX", this.lastMinedOre.getX()); @@ -417,6 +441,13 @@ public NBTTagCompound writeToNBT(@Nonnull NBTTagCompound data) { data.setInteger("minedOreCount", this.minedOreCount); data.setInteger("pipeLength", this.pipeLength); + if (this.yLimit > 0) data.setInteger("yLimit", this.yLimit); + if (this.repeat) data.setBoolean("repeat", true); + + if (this.miningArea != null) { + this.miningArea.write(data); + } + return data; } @@ -434,7 +465,6 @@ public void readFromNBT(@Nonnull NBTTagCompound data) { this.done = data.getInteger("isDone") != 0; this.workingEnabled = data.getInteger("isWorkingEnabled") != 0; - this.nextBlock = 0; this.hasLastMinedOre = false; this.minedOreCount = 0; @@ -444,8 +474,7 @@ public void readFromNBT(@Nonnull NBTTagCompound data) { this.currentDiameter = MathHelper.clamp(data.getInteger("currentDiameter"), 1, getMaximumDiameter()); this.done = data.getBoolean("done"); - this.workingEnabled = data.getBoolean("workingEnabled"); - this.nextBlock = data.getLong("nextBlock"); + this.workingEnabled = !data.getBoolean("disabled"); if (data.hasKey("lastMinedOreX", Constants.NBT.TAG_INT)) { this.lastMinedOre.setPos(data.getInteger("lastMinedOreX"), @@ -458,6 +487,16 @@ public void readFromNBT(@Nonnull NBTTagCompound data) { this.minedOreCount = Math.max(0, data.getInteger("minedOreCount")); this.pipeLength = Math.max(0, data.getInteger("pipeLength")); + + this.yLimit = Math.max(0, data.getInteger("yLimit")); + this.repeat = data.getBoolean("repeat"); + + this.miningArea = createMiningArea(); + // Shouldn't be a problem but whatever + //noinspection ConstantValue + if (this.miningArea != null) { + this.miningArea.read(data); + } } /** @@ -466,6 +505,7 @@ public void readFromNBT(@Nonnull NBTTagCompound data) { public void writeInitialSyncData(@Nonnull PacketBuffer buf) { buf.writeVarInt(this.pipeLength); buf.writeBoolean(this.workingEnabled); + writePreviewUpdatePacket(buf); } /** @@ -474,6 +514,7 @@ public void writeInitialSyncData(@Nonnull PacketBuffer buf) { public void receiveInitialSyncData(@Nonnull PacketBuffer buf) { this.pipeLength = buf.readVarInt(); this.workingEnabled = buf.readBoolean(); + readPreviewUpdatePacket(buf); } /** @@ -493,38 +534,9 @@ public void receiveCustomData(int dataId, @Nonnull PacketBuffer buf) { this.workingEnabled = buf.readBoolean(); this.mte.scheduleRenderUpdate(); } + case GregtechDataCodes.MINER_UPDATE_PREVIEW -> { + readPreviewUpdatePacket(buf); + } } } - - public void addMinerArea(@Nonnull List textList) { - int diameter = getCurrentDiameter(); - // TODO - textList.add(new TextComponentTranslation("gregtech.machine.miner.working_area", diameter, diameter)); - } - - public void addMinerWorkStatus(@Nonnull List textList) { - if (isDone()) { - textList.add(new TextComponentTranslation("gregtech.machine.miner.done") - .setStyle(new Style().setColor(TextFormatting.GREEN))); - } else if (isWorking()) { - textList.add(new TextComponentTranslation("gregtech.machine.miner.working") - .setStyle(new Style().setColor(TextFormatting.GOLD))); - } else if (!isWorkingEnabled()) { - textList.add(new TextComponentTranslation("gregtech.multiblock.work_paused")); - } - } - - public void addInventoryStatus(@Nonnull List textList) { - if (this.inventoryFull) { - textList.add(new TextComponentTranslation("gregtech.machine.miner.invfull") - .setStyle(new Style().setColor(TextFormatting.RED))); - } - } - - public void addLastMinedBlock(@Nonnull List textList) { - if (!this.hasLastMinedOre) return; - textList.add(new TextComponentTranslation("gregtech.machine.miner.minex", this.lastMinedOre.getX())); - textList.add(new TextComponentTranslation("gregtech.machine.miner.miney", this.lastMinedOre.getY())); - textList.add(new TextComponentTranslation("gregtech.machine.miner.minez", this.lastMinedOre.getZ())); - } } diff --git a/src/main/java/gregtech/common/metatileentities/miner/MinerUtil.java b/src/main/java/gregtech/common/metatileentities/miner/MinerUtil.java new file mode 100644 index 00000000000..0a8ba5a729f --- /dev/null +++ b/src/main/java/gregtech/common/metatileentities/miner/MinerUtil.java @@ -0,0 +1,88 @@ +package gregtech.common.metatileentities.miner; + +import codechicken.lib.render.CCRenderState; +import codechicken.lib.render.pipeline.IVertexOperation; +import codechicken.lib.vec.Cuboid6; +import codechicken.lib.vec.Matrix4; +import gregtech.api.util.GTLog; +import gregtech.api.util.GTUtility; +import gregtech.client.renderer.ICubeRenderer; +import gregtech.client.renderer.texture.Textures; +import gregtech.common.ConfigHolder; +import net.minecraft.block.Block; +import net.minecraft.block.state.IBlockState; +import net.minecraft.init.Blocks; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.math.AxisAlignedBB; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; +import org.apache.commons.lang3.StringUtils; + +import javax.annotation.Nonnull; +import java.util.Objects; + +public class MinerUtil { + + private MinerUtil() {} + + /** + * Maximum amount of blocks individual miners can scan in one tick + */ + public static final int MAX_BLOCK_SCAN = 200; + + public static final String DISPLAY_CLICK_AREA_PREVIEW = "preview_area"; + public static final String DISPLAY_CLICK_AREA_PREVIEW_HIDE = "hide_preview_area"; + public static final String DISPLAY_CLICK_Y_LIMIT_DECR = "decr_y_limit"; + public static final String DISPLAY_CLICK_Y_LIMIT_INCR = "incr_y_limit"; + public static final String DISPLAY_CLICK_REPEAT_ENABLE = "enable_repeat"; + public static final String DISPLAY_CLICK_REPEAT_DISABLE = "disable_repeat"; + + public static final AxisAlignedBB EMPTY_AABB = new AxisAlignedBB(0, 0, 0, 0, 0, 0); + public static final ResourceLocation MINER_AREA_PREVIEW_TEXTURE = GTUtility.gregtechId("textures/fx/miner_area_preview.png"); + + private static final Cuboid6 PIPE_CUBOID = new Cuboid6(4 / 16.0, 0.0, 4 / 16.0, 12 / 16.0, 1.0, 12 / 16.0); + + private static String oreReplacementConfigCache; + private static IBlockState oreReplacement; + + @Nonnull + @SuppressWarnings("deprecation") + public static IBlockState getOreReplacement() { + String config = ConfigHolder.machines.replaceMinedBlocksWith; + if (Objects.equals(oreReplacementConfigCache, config)) { + return oreReplacement; + } + + oreReplacementConfigCache = config; + + String[] blockDescription = StringUtils.split(config, ":"); + String blockName = blockDescription.length <= 2 ? config : blockDescription[0] + ":" + blockDescription[1]; + Block block = Block.getBlockFromName(blockName); + + if (block == null) { + GTLog.logger.error("Invalid configuration on entry 'machines/replaceMinedBlocksWith': Cannot find block with name '{}', using cobblestone as fallback.", blockName); + return oreReplacement = Blocks.COBBLESTONE.getDefaultState(); + } else if (blockDescription.length <= 2 || blockDescription[2].isEmpty()) { + return oreReplacement = block.getDefaultState(); + } else { + try { + return oreReplacement = block.getDefaultState().getBlock().getStateFromMeta(Integer.parseInt(blockDescription[2])); + } catch (NumberFormatException ex) { + GTLog.logger.error("Invalid configuration on entry 'machines/replaceMinedBlocksWith': Cannot parse metadata value '{}' as integer, using cobblestone as fallback.", blockDescription[2]); + return oreReplacement = Blocks.COBBLESTONE.getDefaultState(); + } + } + } + + @SideOnly(Side.CLIENT) + public static void renderPipe(@Nonnull ICubeRenderer pipeRenderer, int pipeLength, + @Nonnull CCRenderState renderState, @Nonnull Matrix4 translation, + @Nonnull IVertexOperation[] pipeline) { + Textures.PIPE_IN_OVERLAY.renderSided(EnumFacing.DOWN, renderState, translation, pipeline); + for (int i = 0; i < pipeLength; i++) { + translation.translate(0.0, -1.0, 0.0); + pipeRenderer.render(renderState, translation, pipeline, PIPE_CUBOID); + } + } +} diff --git a/src/main/java/gregtech/common/metatileentities/miner/MultiblockMinerLogic.java b/src/main/java/gregtech/common/metatileentities/miner/MultiblockMinerLogic.java index b2fbbfe6864..484c468c50b 100644 --- a/src/main/java/gregtech/common/metatileentities/miner/MultiblockMinerLogic.java +++ b/src/main/java/gregtech/common/metatileentities/miner/MultiblockMinerLogic.java @@ -12,9 +12,14 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.NonNullList; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.BlockPos.MutableBlockPos; import net.minecraft.util.math.MathHelper; import net.minecraft.util.text.ITextComponent; +import net.minecraft.util.text.Style; import net.minecraft.util.text.TextComponentTranslation; +import net.minecraft.util.text.TextFormatting; +import net.minecraft.util.text.event.ClickEvent; +import net.minecraft.util.text.event.HoverEvent; import net.minecraft.world.World; import net.minecraftforge.common.util.Constants; @@ -28,7 +33,8 @@ public class MultiblockMinerLogic extends MinerLogic { private final RecipeMap blockDropRecipeMap; private final int maximumChunkDiameter; - private final BlockPos.MutableBlockPos mpos2 = new BlockPos.MutableBlockPos(); + private final MutableBlockPos mpos = new MutableBlockPos(); + private final MutableBlockPos mpos2 = new MutableBlockPos(); private int currentChunkDiameter; @@ -37,7 +43,7 @@ public class MultiblockMinerLogic extends MinerLogic { public MultiblockMinerLogic(MetaTileEntityLargeMiner largeMiner, int fortune, int workFrequency, int maximumChunkDiameter, RecipeMap blockDropRecipeMap) { - super(largeMiner, workFrequency, maximumChunkDiameter * 16 / 2); + super(largeMiner, workFrequency, maximumChunkDiameter * 16); this.fortune = fortune; this.blockDropRecipeMap = blockDropRecipeMap; this.currentChunkDiameter = this.maximumChunkDiameter = maximumChunkDiameter; @@ -52,28 +58,26 @@ protected void getRegularBlockDrops(@Nonnull NonNullList drops, @Nonn } } + @Nonnull @Override - protected void initBoundary() { - if (!this.chunkMode) { - super.initBoundary(); - return; - } - + protected IMiningArea createMiningArea() { + if (!this.chunkMode) return super.createMiningArea(); BlockPos origin = getOrigin(); - int originChunkX = origin.getX() / 16; - int originChunkZ = origin.getZ() / 16; - - this.startX = (originChunkX - currentChunkDiameter) * 16; - this.startY = origin.getY(); - this.startZ = (originChunkZ - currentChunkDiameter) * 16; - this.endX = (originChunkX + currentChunkDiameter) * 16 + 15; - this.endZ = (originChunkZ + currentChunkDiameter) * 16 + 15; + int chunkRadius = this.currentChunkDiameter / 2; + int originChunkX = origin.getX() / 16 - chunkRadius; + int originChunkZ = origin.getZ() / 16 - chunkRadius; + return new SimpleMiningArea((originChunkX) * 16, + origin.getY() - 1, + (originChunkZ) * 16, + (originChunkX + currentChunkDiameter) * 16, + getYLimit() > 0 ? origin.getY() - getYLimit() : Integer.MIN_VALUE, + (originChunkZ + currentChunkDiameter) * 16); } @Nonnull @Override protected BlockPos getOrigin() { - return this.mpos2.setPos(this.mte.getPos()).move(this.mte.getFrontFacing().getOpposite()); + return this.mpos.setPos(this.mte.getPos()).move(this.mte.getFrontFacing().getOpposite()); } public int getFortune() { @@ -150,19 +154,84 @@ public void readFromNBT(@Nonnull NBTTagCompound data) { super.readFromNBT(data); } - @Override - public void addMinerArea(@Nonnull List textList) { + public void addDisplayText(@Nonnull List textList) { if (isChunkMode()) { int chunkDiameter = getCurrentChunkDiameter(); - textList.add(new TextComponentTranslation("gregtech.machine.miner.working_area_chunks", chunkDiameter, chunkDiameter)); + textList.add(new TextComponentTranslation("gregtech.machine.miner.display.working_area.chunks", + chunkDiameter, chunkDiameter, previewWorkingAreaButton())); } else { int diameter = getCurrentDiameter(); - textList.add(new TextComponentTranslation("gregtech.machine.miner.working_area", diameter, diameter)); + textList.add(new TextComponentTranslation("gregtech.machine.miner.display.working_area", + diameter, diameter, previewWorkingAreaButton())); + } + + Object value; + ITextComponent hoverText; + if (this.getYLimit() > 0) { + value = String.format("%,d", this.getYLimit()); + hoverText = new TextComponentTranslation("gregtech.machine.miner.display.y_limit.value_hover_tooltip", value); + } else { + value = new TextComponentTranslation("gregtech.machine.miner.display.y_limit.no_value"); + hoverText = new TextComponentTranslation("gregtech.machine.miner.display.y_limit.value_hover_tooltip.no_value"); + } + textList.add(new TextComponentTranslation("gregtech.machine.miner.display.y_limit", + yLimitButton(false), yLimitButton(true), value) + .setStyle(new Style().setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverText)))); + + textList.add(new TextComponentTranslation("gregtech.machine.miner.display.repeat", + new TextComponentTranslation(this.isRepeat() ? "gregtech.machine.miner.display.repeat.enabled" : + "gregtech.machine.miner.display.repeat.disabled") + .setStyle(new Style().setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, + this.isRepeat() ? "@!" + MinerUtil.DISPLAY_CLICK_REPEAT_DISABLE : + "@!" + MinerUtil.DISPLAY_CLICK_REPEAT_ENABLE))))); + + if (isDone()) { + textList.add(new TextComponentTranslation("gregtech.machine.miner.display.done") + .setStyle(new Style().setColor(TextFormatting.GREEN))); + } else if (isWorking()) { + if (getCurrentBlock(this.mpos2)) { + textList.add(new TextComponentTranslation("gregtech.machine.miner.display.working", + this.mpos2.getX(), this.mpos2.getY(), this.mpos2.getZ()) + .setStyle(new Style().setColor(TextFormatting.GOLD))); + } + } else if (!isWorkingEnabled()) { + textList.add(new TextComponentTranslation("gregtech.multiblock.work_paused")); + } + + textList.add(new TextComponentTranslation("gregtech.machine.miner.display.stats.total_mined", this.minedOreCount)); + if (this.hasLastMinedOre) { + textList.add(new TextComponentTranslation("gregtech.machine.miner.display.stats.last_mined", + this.lastMinedOre.getX(), this.lastMinedOre.getY(), this.lastMinedOre.getZ())); + } + } + + @Nonnull + protected ITextComponent previewWorkingAreaButton() { + return new TextComponentTranslation(this.isPreviewEnabled() ? + "gregtech.machine.miner.display.working_area.hide_preview" : + "gregtech.machine.miner.display.working_area.preview") + .setStyle(new Style().setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, + this.isPreviewEnabled() ? "@!" + MinerUtil.DISPLAY_CLICK_AREA_PREVIEW_HIDE : + "@!" + MinerUtil.DISPLAY_CLICK_AREA_PREVIEW))); + } + + @Nonnull + protected ITextComponent yLimitButton(boolean incr) { + if (incr) { + return this.getYLimit() == Integer.MAX_VALUE ? + new TextComponentTranslation("gregtech.machine.miner.display.y_limit.incr.disabled") : + new TextComponentTranslation("gregtech.machine.miner.display.y_limit.incr") + .setStyle(new Style().setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "@!" + MinerUtil.DISPLAY_CLICK_Y_LIMIT_INCR))); + } else { + return this.getYLimit() <= 0 ? + new TextComponentTranslation("gregtech.machine.miner.display.y_limit.decr.disabled") : + new TextComponentTranslation("gregtech.machine.miner.display.y_limit.decr") + .setStyle(new Style().setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "@!" + MinerUtil.DISPLAY_CLICK_Y_LIMIT_DECR))); } } /** - * Applies a fortune hammer to block drops based on a tier value, intended for small ores + * Applies a fortune hammer to block drops based on a tier value. * * @param stack the item stack to check for recipes * @param drops where the drops are stored to diff --git a/src/main/java/gregtech/common/metatileentities/miner/SimpleMiningArea.java b/src/main/java/gregtech/common/metatileentities/miner/SimpleMiningArea.java new file mode 100644 index 00000000000..5ceab455cc5 --- /dev/null +++ b/src/main/java/gregtech/common/metatileentities/miner/SimpleMiningArea.java @@ -0,0 +1,224 @@ +package gregtech.common.metatileentities.miner; + +import gregtech.api.metatileentity.IFastRenderMetaTileEntity; +import gregtech.api.metatileentity.MetaTileEntity; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.BufferBuilder; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.GlStateManager.DestFactor; +import net.minecraft.client.renderer.GlStateManager.SourceFactor; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.vertex.DefaultVertexFormats; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.network.PacketBuffer; +import net.minecraft.util.math.AxisAlignedBB; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.BlockPos.MutableBlockPos; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; +import org.lwjgl.opengl.GL11; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** + * Simple implementation of {@link IMiningArea}. Defines cube-shaped mining area with simple iteration logic. + */ +public class SimpleMiningArea implements IMiningArea { + + public final int startX; + public final int startY; + public final int startZ; + public final int endX; + public final int endY; + public final int endZ; + + /** + * Index for current block position. This implementation of {@link IMiningArea} operates by first mapping each block + * in given area to non-negative long indices, then processing it by incrementing internal counter starting from 0. + *
+ * The area iterates through X plane first, then Z plane, before moving down one Y block. + */ + private long currentBlock; + + @Nullable + private AxisAlignedBB boundingBoxCache; + + /** + * @param startX Min X position, inclusive + * @param startY Max Y position, inclusive + * @param startZ Min Z position, inclusive + * @param endX Max X position, inclusive + * @param endY Min Y position, inclusive + * @param endZ Max Z position, inclusive + */ + public SimpleMiningArea(int startX, int startY, int startZ, int endX, int endY, int endZ) { + this.startX = startX; + this.startY = startY; + this.startZ = startZ; + this.endX = endX; + this.endY = endY; + this.endZ = endZ; + } + + @Nonnull + public static SimpleMiningArea readPreview(@Nonnull PacketBuffer buffer) { + return new SimpleMiningArea(buffer.readInt(), buffer.readInt(), buffer.readInt(), buffer.readInt(), buffer.readInt(), buffer.readInt()); + } + + @Override + public boolean getCurrentBlockPos(@Nonnull MutableBlockPos mpos) { + long index = this.currentBlock; + if (index < 0) return false; + int sizeX = this.endX - this.startX; + int sizeZ = this.endZ - this.startZ; + if (sizeX <= 0 || sizeZ <= 0) return false; + + int x = this.startX + (int) (index % sizeX); + index /= sizeX; + int z = this.startZ + (int) (index % sizeZ); + int y = this.startY - (int) (index / sizeZ); + + if (y < this.endY) return false; + + mpos.setPos(x, y, z); + return true; + } + + @Override + public void nextBlock() { + this.currentBlock++; + } + + @Override + public void reset() { + this.currentBlock = 0; + } + + @Override + @SideOnly(Side.CLIENT) + public void renderMetaTileEntity(@Nonnull MetaTileEntity mte, double x, double y, double z, float partialTicks) { + // skull emoji + + float texOffset = (System.nanoTime() % 1_000_000_000) / 2_000_000_000f; + // texOffset = (int) (texOffset * 16) * (1 / 16f); + + float t = texOffset * 0.5f; + float ti = (1 - texOffset) * 0.5f; + + BlockPos pos = mte.getPos(); + double minX = this.startX + x - pos.getX() - (1 / 16.0), maxX = this.endX + x - pos.getX() + (1 / 16.0); + double minY = this.endY + y - pos.getY() - (1 / 16.0), maxY = this.startY + y - pos.getY() + (1 / 16.0); + double minZ = this.startZ + z - pos.getZ() - (1 / 16.0), maxZ = this.endZ + z - pos.getZ() + (1 / 16.0); + + double mx = (this.endX - this.startX) * .5f; + double my = (this.startY - this.endY) * .5f; + double mz = (this.endZ - this.startZ) * .5f; + + Minecraft.getMinecraft().getTextureManager().bindTexture(MinerUtil.MINER_AREA_PREVIEW_TEXTURE); + GlStateManager.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_REPEAT); + GlStateManager.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_REPEAT); + GlStateManager.disableLighting(); + GlStateManager.enableBlend(); + GlStateManager.disableCull(); + GlStateManager.tryBlendFuncSeparate(SourceFactor.SRC_ALPHA, DestFactor.ONE_MINUS_SRC_ALPHA, SourceFactor.ONE, DestFactor.ZERO); + GlStateManager.color(1, 1, 1); + + Tessellator tessellator = Tessellator.getInstance(); + BufferBuilder buffer = tessellator.getBuffer(); + buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_LMAP_COLOR); + + // NORTH + v(buffer, minX, maxY, minZ, t, t); + v(buffer, maxX, maxY, minZ, t + mx, t); + v(buffer, maxX, minY, minZ, t + mx, t - my); + v(buffer, minX, minY, minZ, t, t - my); + + // SOUTH + v(buffer, minX, minY, maxZ, t, t); + v(buffer, maxX, minY, maxZ, t + mx, t); + v(buffer, maxX, maxY, maxZ, t + mx, t + my); + v(buffer, minX, maxY, maxZ, t, t + my); + + // DOWN + v(buffer, minX, minY, minZ, t, t); + v(buffer, maxX, minY, minZ, t + mx, t); + v(buffer, maxX, minY, maxZ, t + mx, t + mz); + v(buffer, minX, minY, maxZ, t, t + mz); + + // UP + v(buffer, minX, maxY, maxZ, t, t); + v(buffer, maxX, maxY, maxZ, t + mx, t); + v(buffer, maxX, maxY, minZ, t + mx, t + mz); + v(buffer, minX, maxY, minZ, t, t + mz); + + // WEST + v(buffer, minX, minY, maxZ, t, t); + v(buffer, minX, maxY, maxZ, t + my, t); + v(buffer, minX, maxY, minZ, t + my, t - mz); + v(buffer, minX, minY, minZ, t + my, t - mz); + + // EAST + v(buffer, maxX, minY, minZ, t, t); + v(buffer, maxX, maxY, minZ, t + my, t); + v(buffer, maxX, maxY, maxZ, t + my, t + mz); + v(buffer, maxX, minY, maxZ, t , t + mz); + + tessellator.draw(); + + GlStateManager.enableLighting(); + GlStateManager.enableCull(); + } + + private static void v(BufferBuilder buffer, double x, double y, double z, double u, double v) { + buffer.pos(x, y, z).tex(u, v).lightmap(240, 240).color(255, 255, 255, 255).endVertex(); + } + + @Override + public boolean shouldRenderInPass(int pass) { + return pass == IFastRenderMetaTileEntity.RENDER_PASS_TRANSLUCENT; + } + + @Nonnull + @Override + public AxisAlignedBB getRenderBoundingBox() { + if (this.boundingBoxCache == null) { + return this.boundingBoxCache = new AxisAlignedBB( + startX - (1 / 16.0), endY - (1 / 16.0), startZ - (1 / 16.0), + endX + 1 + (1 / 16.0), startY + 1 + (1 / 16.0), endZ + 1 + (1 / 16.0)); + } + return this.boundingBoxCache; + } + + @Override + public void write(@Nonnull NBTTagCompound data) { + data.setLong("i", this.currentBlock); + } + + @Override + public void read(@Nonnull NBTTagCompound data) { + this.currentBlock = Math.max(0, data.getLong("i")); + } + + @Override + public void writePreviewPacket(@Nonnull PacketBuffer buffer) { + buffer.writeInt(startX); + buffer.writeInt(startY); + buffer.writeInt(startZ); + buffer.writeInt(endX); + buffer.writeInt(endY); + buffer.writeInt(endZ); + } + + @Override + public String toString() { + return "SimpleMiningArea{" + + "startX=" + startX + + ", startY=" + startY + + ", startZ=" + startZ + + ", endX=" + endX + + ", endZ=" + endZ + + ", currentBlock=" + currentBlock + + '}'; + } +} diff --git a/src/main/java/gregtech/common/metatileentities/miner/SteamMiner.java b/src/main/java/gregtech/common/metatileentities/miner/SteamMiner.java index 297b009b016..68a0145aa5a 100644 --- a/src/main/java/gregtech/common/metatileentities/miner/SteamMiner.java +++ b/src/main/java/gregtech/common/metatileentities/miner/SteamMiner.java @@ -14,13 +14,14 @@ import gregtech.api.capability.impl.NotifiableItemStackHandler; import gregtech.api.gui.GuiTextures; import gregtech.api.gui.ModularUI; -import gregtech.api.gui.widgets.AdvancedTextWidget; -import gregtech.api.gui.widgets.SlotWidget; +import gregtech.api.gui.widgets.ImageWidget; +import gregtech.api.gui.widgets.ProgressWidget; +import gregtech.api.gui.widgets.ToggleButtonWidget; import gregtech.api.metatileentity.IDataInfoProvider; +import gregtech.api.metatileentity.IFastRenderMetaTileEntity; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.metatileentity.interfaces.IGregTechTileEntity; import gregtech.api.util.GTUtility; -import gregtech.client.renderer.ICubeRenderer; import gregtech.client.renderer.texture.Textures; import gregtech.client.renderer.texture.cube.SimpleSidedCubeRenderer; import gregtech.common.ConfigHolder; @@ -32,12 +33,14 @@ import net.minecraft.network.PacketBuffer; import net.minecraft.util.EnumFacing; import net.minecraft.util.ResourceLocation; +import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.Style; import net.minecraft.util.text.TextComponentTranslation; import net.minecraft.util.text.TextFormatting; import net.minecraft.world.World; import net.minecraftforge.common.capabilities.Capability; +import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; import net.minecraftforge.items.IItemHandlerModifiable; @@ -49,7 +52,7 @@ import java.util.Collections; import java.util.List; -public class SteamMiner extends MetaTileEntity implements IMiner, IControllable, IVentable, IDataInfoProvider { +public class SteamMiner extends MetaTileEntity implements IMiner, IControllable, IVentable, IDataInfoProvider, IFastRenderMetaTileEntity { private boolean needsVenting = false; private boolean ventingStuck = false; @@ -59,11 +62,13 @@ public class SteamMiner extends MetaTileEntity implements IMiner, IControllable, private final SteamMinerLogic minerLogic; - public SteamMiner(ResourceLocation metaTileEntityId, int workFrequency, int maximumRadius) { + private boolean hasNotEnoughEnergy; + + public SteamMiner(ResourceLocation metaTileEntityId, int workFrequency, int maximumDiameter) { super(metaTileEntityId); this.inventorySize = 4; this.energyPerTick = 16; - this.minerLogic = new SteamMinerLogic(this, workFrequency, maximumRadius); + this.minerLogic = new SteamMinerLogic(this, workFrequency, maximumDiameter); initializeInventory(); } @@ -101,40 +106,76 @@ public void renderMetaTileEntity(CCRenderState renderState, Matrix4 translation, } Textures.STEAM_VENT_OVERLAY.renderSided(EnumFacing.UP, renderState, translation, pipeline); Textures.PIPE_IN_OVERLAY.renderSided(EnumFacing.DOWN, renderState, translation, pipeline); - minerLogic.renderPipe(renderState, translation, pipeline); + MinerUtil.renderPipe(Textures.BRONZE_PLATED_BRICKS, this.minerLogic.getPipeLength(), renderState, translation, pipeline); } @Override - protected ModularUI createUI(EntityPlayer entityPlayer) { - int rowSize = (int) Math.sqrt(inventorySize); + public void renderMetaTileEntity(double x, double y, double z, float partialTicks) { + IMiningArea previewArea = this.minerLogic.getPreviewArea(); + if (previewArea != null) previewArea.renderMetaTileEntity(this, x, y, z, partialTicks); + } - ModularUI.Builder builder = ModularUI.builder(GuiTextures.BACKGROUND_STEAM.get(false), 175, 176); - builder.bindPlayerInventory(entityPlayer.inventory, 94); + @Override + public void renderMetaTileEntityFast(CCRenderState renderState, Matrix4 translation, float partialTicks) { + IMiningArea previewArea = this.minerLogic.getPreviewArea(); + if (previewArea != null) previewArea.renderMetaTileEntityFast(this, renderState, translation, partialTicks); + } - for (int y = 0; y < rowSize; y++) { - for (int x = 0; x < rowSize; x++) { - int index = y * rowSize + x; - builder.widget(new SlotWidget(exportItems, index, 142 - rowSize * 9 + x * 18, 18 + y * 18, true, false) - .setBackgroundTexture(GuiTextures.SLOT_STEAM.get(false))); - } - } - builder.bindPlayerInventory(entityPlayer.inventory, GuiTextures.SLOT_STEAM.get(false), 10); + @Override + public AxisAlignedBB getRenderBoundingBox() { + IMiningArea previewArea = this.minerLogic.getPreviewArea(); + return previewArea != null ? previewArea.getRenderBoundingBox() : MinerUtil.EMPTY_AABB; + } + + @Override + public boolean shouldRenderInPass(int pass) { + IMiningArea previewArea = this.minerLogic.getPreviewArea(); + return previewArea != null && previewArea.shouldRenderInPass(pass); + } - builder.image(7, 16, 105, 75, GuiTextures.DISPLAY_STEAM.get(false)) - .label(6, 6, getMetaFullName()); - builder.widget(new AdvancedTextWidget(10, 19, this::addDisplayText, 0xFFFFFF) - .setMaxWidthLimit(84)); - builder.widget(new AdvancedTextWidget(70, 19, this.minerLogic::addLastMinedBlock, 0xFFFFFF) - .setMaxWidthLimit(84)); + @Override + public boolean isGlobalRenderer() { + return true; + } + + @Override + protected ModularUI createUI(EntityPlayer entityPlayer) { + int columns = 2; + int xStart = (176 - (18 * columns)) / 2; + int yStart = 25; + int sideWidgetY = yStart + (columns * 18 - 18) / 2; + + ModularUI.Builder builder = ModularUI.builder(GuiTextures.BACKGROUND_STEAM.get(false), 176, 166) + .label(6, 6, getMetaFullName()) + .shouldColor(false) + .widget(new ToggleButtonWidget(152, 25, 18, 18, + GuiTextures.BUTTON_MINER_AREA_PREVIEW, + this.minerLogic::isPreviewEnabled, this.minerLogic::setPreviewEnabled)); + + IItemHandlerModifiable exportItems = this.getExportItems(); + for (int i = 0, slots = exportItems.getSlots(); i < slots; i++) { + builder.slot(exportItems, i, xStart + 18 * (i % columns), yStart + 18 * (i / columns), + true, false, GuiTextures.SLOT_STEAM.get(false)); + } + builder.widget( + new ProgressWidget(() -> { + if (!this.minerLogic.isWorking()) return 0; + int workFrequency = this.minerLogic.getWorkFrequency(); + return workFrequency < 2 ? 1 : (getOffsetTimer() % workFrequency) / (double) workFrequency; + }, xStart - 4 - 21, sideWidgetY, 21, 18, + GuiTextures.PROGRESS_BAR_MACERATE_STEAM.get(false), ProgressWidget.MoveType.HORIZONTAL) + ).widget( + new ImageWidget(xStart - 4 - 20, sideWidgetY + 18, 18, 18, + GuiTextures.INDICATOR_NO_STEAM.get(false)) + .setPredicate(() -> this.hasNotEnoughEnergy) + ).bindPlayerInventory(entityPlayer.inventory, GuiTextures.SLOT_STEAM.get(false), 0); return builder.build(getHolder(), entityPlayer); } - private void addDisplayText(List textList) { - this.minerLogic.addMinerArea(textList); - this.minerLogic.addMinerWorkStatus(textList); - this.minerLogic.addInventoryStatus(textList); + @Override + public void describeMiningResourceStatus(@Nonnull List textList) { if (this.ventingStuck) { textList.add(new TextComponentTranslation("gregtech.machine.steam_miner.vent") .setStyle(new Style().setColor(TextFormatting.RED))); @@ -163,19 +204,11 @@ public void addToolUsages(ItemStack stack, @Nullable World world, List t @Override public boolean drainMiningResources(boolean simulate) { - int resultSteam = importFluids.getTankAt(0).getFluidAmount() - energyPerTick; - if (!ventingStuck && resultSteam >= 0L && resultSteam <= importFluids.getTankAt(0).getCapacity()) { - if (!simulate) - importFluids.getTankAt(0).drain(energyPerTick, true); - return true; - } - return false; - } - - @Override - @SideOnly(Side.CLIENT) - public ICubeRenderer getPipeTexture() { - return Textures.BRONZE_PLATED_BRICKS; + if (this.ventingStuck) return false; + FluidStack drained = this.importFluids.drain(energyPerTick, simulate); + boolean result = drained != null && drained.amount >= energyPerTick; + this.hasNotEnoughEnergy = !result; + return result; } @Override diff --git a/src/main/java/gregtech/common/metatileentities/miner/SteamMinerLogic.java b/src/main/java/gregtech/common/metatileentities/miner/SteamMinerLogic.java index fba84a9174e..f67444bc682 100644 --- a/src/main/java/gregtech/common/metatileentities/miner/SteamMinerLogic.java +++ b/src/main/java/gregtech/common/metatileentities/miner/SteamMinerLogic.java @@ -6,8 +6,8 @@ public class SteamMinerLogic extends MinerLogic { - public SteamMinerLogic(@Nonnull SteamMiner steamMiner, int workFrequency, int maximumRadius) { - super(steamMiner, workFrequency, maximumRadius); + public SteamMinerLogic(@Nonnull SteamMiner steamMiner, int workFrequency, int maximumDiameter) { + super(steamMiner, workFrequency, maximumDiameter); } @Override diff --git a/src/main/java/gregtech/common/metatileentities/multi/electric/MetaTileEntityFluidDrill.java b/src/main/java/gregtech/common/metatileentities/multi/electric/MetaTileEntityFluidDrill.java index 54e7dd2857c..cb4fada3e7e 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/electric/MetaTileEntityFluidDrill.java +++ b/src/main/java/gregtech/common/metatileentities/multi/electric/MetaTileEntityFluidDrill.java @@ -187,7 +187,7 @@ protected void addWarningText(List textList) { textList.add(new TextComponentTranslation("gregtech.multiblock.not_enough_energy").setStyle(new Style().setColor(TextFormatting.RED))); } if (minerLogic.isInventoryFull()) { - textList.add(new TextComponentTranslation("gregtech.machine.miner.invfull").setStyle(new Style().setColor(TextFormatting.RED))); + textList.add(new TextComponentTranslation("gregtech.machine.fluid_drilling_rig.inventory_full").setStyle(new Style().setColor(TextFormatting.RED))); } } } diff --git a/src/main/resources/assets/gregtech/lang/en_us.lang b/src/main/resources/assets/gregtech/lang/en_us.lang index 8cbd8656a1a..f2c705dfde7 100644 --- a/src/main/resources/assets/gregtech/lang/en_us.lang +++ b/src/main/resources/assets/gregtech/lang/en_us.lang @@ -4613,7 +4613,7 @@ gregtech.machine.fusion_reactor.overclocking=Overclocks double energy and halve gregtech.machine.miner.lv.name=Basic Miner gregtech.machine.miner.mv.name=Advanced Miner gregtech.machine.miner.hv.name=Advanced Miner II -gregtech.machine.miner.tooltip=Mines ores below the Miner! Starts as §f%sx%s §7area +gregtech.machine.miner.tooltip=Mines ores below the Miner! gregtech.machine.miner.per_block=§7takes §f%,ds §7per Block gregtech.machine.large_miner.ev.name=Basic Ore Drilling Plant @@ -4625,16 +4625,34 @@ gregtech.machine.miner.fluid_usage=Uses §f%,d L/t §7of §f%s§7, doubled per o gregtech.machine.miner.multi.description=A multiblock mining machine that covers a large area and produces huge quantity of ore. gregtech.machine.miner.multi.needsfluid=Needs Drilling Fluid -gregtech.machine.miner.startx=sX: %d -gregtech.machine.miner.starty=sY: %d -gregtech.machine.miner.startz=sZ: %d -gregtech.machine.miner.minex=mX: %d -gregtech.machine.miner.miney=mY: %d -gregtech.machine.miner.minez=mZ: %d -gregtech.machine.miner.radius=Radius: %d gregtech.machine.miner.working_area=Working Area: %dx%d blocks gregtech.machine.miner.working_area_chunks=Working Area: %dx%d chunks -gregtech.machine.miner.chunkradius=Chunk Radius: %d + +gregtech.machine.steam_miner.vent=Venting Blocked! +gregtech.machine.steam_miner.steam=Needs Steam! +gregtech.machine.miner.errorradius=§cCannot change radius while working! + +gregtech.machine.miner.display.working_area=Working Area: %dx%d blocks %s +gregtech.machine.miner.display.working_area.chunks=Working Area: %dx%d chunks %s +gregtech.machine.miner.display.working_area.preview=[§bPreview§r] +gregtech.machine.miner.display.working_area.hide_preview=[§bHide Preview§r] +gregtech.machine.miner.display.y_limit=Y Limit: %s %s %s +gregtech.machine.miner.display.y_limit.decr=[§b-§r] +gregtech.machine.miner.display.y_limit.decr.disabled=[§8-§r] +gregtech.machine.miner.display.y_limit.incr=[§b+§r] +gregtech.machine.miner.display.y_limit.incr.disabled=[§8+§r] +gregtech.machine.miner.display.y_limit.no_value=No limit +gregtech.machine.miner.display.y_limit.value_hover_tooltip=Miner will operate in §6%s§r Y layer(s) before halting. +gregtech.machine.miner.display.y_limit.value_hover_tooltip.no_value=Miner will operate until hitting the bedrock layer. +gregtech.machine.miner.display.repeat=Repeat after finished: %s +gregtech.machine.miner.display.repeat.enabled=[§aOn§r] +gregtech.machine.miner.display.repeat.disabled=[§cOff§r] +gregtech.machine.miner.display.stats.total_mined=Mined %s ores in total +gregtech.machine.miner.display.stats.last_mined=Last Block Mined: [%s %s %s] + +gregtech.machine.miner.display.done=Done! +gregtech.machine.miner.display.working=Mining [%s %s %s] +gregtech.machine.miner.display.inventory_full=Inventory Full! gregtech.machine.fluid_drilling_rig.mv.name=Basic Fluid Drilling Rig gregtech.machine.fluid_drilling_rig.hv.name=Advanced Fluid Drilling Rig @@ -4642,6 +4660,7 @@ gregtech.machine.fluid_drilling_rig.ev.name=Advanced Fluid Drilling Rig II gregtech.machine.fluid_drilling_rig.description=Drills fluids from veins under bedrock. gregtech.machine.fluid_drilling_rig.production=§eProduction Multiplier: §f%dx, %fx overclocked gregtech.machine.fluid_drilling_rig.depletion=§bDepletion Rate: §f%s%% +gregtech.machine.fluid_drilling_rig.inventory_full=Inventory Full! gregtech.machine.cleanroom.name=Cleanroom gregtech.machine.cleanroom.tooltip.1=Place machines inside to run cleanroom recipes. @@ -5294,14 +5313,6 @@ gregtech.multiblock.large_boiler.rate_tooltip=§7Produces §f%d L §7of Steam wi gregtech.multiblock.large_boiler.heat_time_tooltip=§7Takes §f%,d seconds §7to heat up gregtech.multiblock.large_boiler.explosion_tooltip=Will explode if provided Fuel with no Water -gregtech.machine.miner.done=Done! -gregtech.machine.miner.working=Working... -gregtech.machine.miner.invfull=Inventory Full! -gregtech.machine.miner.needspower=Needs Power! -gregtech.machine.steam_miner.vent=Venting Blocked! -gregtech.machine.steam_miner.steam=Needs Steam! -gregtech.machine.miner.errorradius=§cCannot change radius while working! - gregtech.multiblock.miner.neither_mode=Chunk Mode: §cDisabled§r/nSilk Touch Mode: §cDisabled§r/n§7Switching requires an idle machine. gregtech.multiblock.miner.chunk_mode=Chunk Mode: §aEnabled§r/nSilk Touch Mode: §cDisabled§r/n§7Switching requires an idle machine. gregtech.multiblock.miner.silk_touch_mode=Chunk Mode: §cDisabled§r/nSilk Touch Mode: §aEnabled§r/n§7Switching requires an idle machine. diff --git a/src/main/resources/assets/gregtech/textures/fx/miner_area_preview.png b/src/main/resources/assets/gregtech/textures/fx/miner_area_preview.png new file mode 100644 index 0000000000000000000000000000000000000000..2cf00a0e0ca151a497bee1d6a4f040a7b24405d0 GIT binary patch literal 273 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=fdz$r9IylHmNblJdl&R0hYC{G?O` z&)mfH)S%SFl*+=BsWw1Gn>}3|Ln>}1{rUgj{_xwm+xGGB@Jw`A!+m6WW5v!@zaO6E z32^YPT-LZnh9%;HYGZ|QfUwU!@!2+Zhdr;JZ}AqIp0?oi$0)y5b;qKubEXNdo+Px#^hrcPR5*?8)3FYMFc1ddsvTSeCLpmUOm0lR3Xj5D&_}6{;ii+DlS56w3ChBT zLlHa>bGLiTHGldI*Gm^|+cIKFDYHBq>Gsc#- zk<7r5CV$)jLmGX*0){kI`2-AUT+bgfj1f@`7}E54$4KVCw{LsnpDf(&N2AZ>TuP~w znqK`~D`O1RBuT<;Be671yV(xAi?cSSadat)I Date: Tue, 31 Oct 2023 19:59:17 +0900 Subject: [PATCH 03/27] Smallest Refactor --- build.gradle | 8 +- .../api/capability/GregtechDataCodes.java | 3 +- .../client/renderer/texture/Textures.java | 5 +- .../metatileentities/MetaTileEntities.java | 8 +- .../common/metatileentities/miner/IMiner.java | 19 - .../miner/LargeMinerType.java | 27 ++ .../miner/LargeMinerTypes.java | 62 +++ .../miner/MetaTileEntityLargeMiner.java | 119 ++---- .../miner/MetaTileEntityMiner.java | 52 +-- .../common/metatileentities/miner/Miner.java | 66 +++ .../metatileentities/miner/MinerLogic.java | 396 ++++++++---------- .../miner/MinerRenderHelper.java | 389 +++++++++++++++++ .../metatileentities/miner/MinerUtil.java | 53 ++- .../{IMiningArea.java => MiningArea.java} | 158 ++++--- .../miner/MultiblockMinerLogic.java | 165 ++++---- .../miner/SimpleMiningArea.java | 368 +++++++--------- .../metatileentities/miner/SteamMiner.java | 75 ++-- .../miner/SteamMinerLogic.java | 27 -- .../resources/assets/gregtech/lang/en_us.lang | 2 +- .../blocks/machines/miner/overlay_back.png | Bin 0 -> 336 bytes .../machines/miner/overlay_back_active.png | Bin 0 -> 693 bytes .../miner/overlay_back_active.png.mcmeta | 5 + .../miner/overlay_back_active_emissive.png | Bin 0 -> 407 bytes .../overlay_back_active_emissive.png.mcmeta | 5 + .../blocks/machines/miner/overlay_bottom.png | Bin 0 -> 1969 bytes .../machines/miner/overlay_bottom_active.png | Bin 0 -> 1969 bytes .../blocks/machines/miner/overlay_side.png | Bin 0 -> 336 bytes .../machines/miner/overlay_side_active.png | Bin 0 -> 693 bytes .../miner/overlay_side_active.png.mcmeta | 5 + .../miner/overlay_side_active_emissive.png | Bin 0 -> 407 bytes .../overlay_side_active_emissive.png.mcmeta | 5 + .../blocks/machines/miner/overlay_top.png | Bin 0 -> 182 bytes .../machines/miner/overlay_top_active.png | Bin 0 -> 126 bytes .../miner/overlay_top_active_emissive.png | Bin 0 -> 1364 bytes .../overlay_top_active_emissive.png.mcmeta | 5 + .../machines/miner/overlay_top_emissive.png | Bin 0 -> 126 bytes .../overlay/machine/overlay_chunk_miner.png | Bin 677 -> 0 bytes .../overlay/machine/overlay_steam_miner.png | Bin 673 -> 0 bytes .../textures/fx/miner_area_preview.png | Bin 273 -> 202 bytes 39 files changed, 1180 insertions(+), 847 deletions(-) delete mode 100644 src/main/java/gregtech/common/metatileentities/miner/IMiner.java create mode 100644 src/main/java/gregtech/common/metatileentities/miner/LargeMinerType.java create mode 100644 src/main/java/gregtech/common/metatileentities/miner/LargeMinerTypes.java create mode 100644 src/main/java/gregtech/common/metatileentities/miner/Miner.java create mode 100644 src/main/java/gregtech/common/metatileentities/miner/MinerRenderHelper.java rename src/main/java/gregtech/common/metatileentities/miner/{IMiningArea.java => MiningArea.java} (93%) delete mode 100644 src/main/java/gregtech/common/metatileentities/miner/SteamMinerLogic.java create mode 100644 src/main/resources/assets/gregtech/textures/blocks/machines/miner/overlay_back.png create mode 100644 src/main/resources/assets/gregtech/textures/blocks/machines/miner/overlay_back_active.png create mode 100644 src/main/resources/assets/gregtech/textures/blocks/machines/miner/overlay_back_active.png.mcmeta create mode 100644 src/main/resources/assets/gregtech/textures/blocks/machines/miner/overlay_back_active_emissive.png create mode 100644 src/main/resources/assets/gregtech/textures/blocks/machines/miner/overlay_back_active_emissive.png.mcmeta create mode 100644 src/main/resources/assets/gregtech/textures/blocks/machines/miner/overlay_bottom.png create mode 100644 src/main/resources/assets/gregtech/textures/blocks/machines/miner/overlay_bottom_active.png create mode 100644 src/main/resources/assets/gregtech/textures/blocks/machines/miner/overlay_side.png create mode 100644 src/main/resources/assets/gregtech/textures/blocks/machines/miner/overlay_side_active.png create mode 100644 src/main/resources/assets/gregtech/textures/blocks/machines/miner/overlay_side_active.png.mcmeta create mode 100644 src/main/resources/assets/gregtech/textures/blocks/machines/miner/overlay_side_active_emissive.png create mode 100644 src/main/resources/assets/gregtech/textures/blocks/machines/miner/overlay_side_active_emissive.png.mcmeta create mode 100644 src/main/resources/assets/gregtech/textures/blocks/machines/miner/overlay_top.png create mode 100644 src/main/resources/assets/gregtech/textures/blocks/machines/miner/overlay_top_active.png create mode 100644 src/main/resources/assets/gregtech/textures/blocks/machines/miner/overlay_top_active_emissive.png create mode 100644 src/main/resources/assets/gregtech/textures/blocks/machines/miner/overlay_top_active_emissive.png.mcmeta create mode 100644 src/main/resources/assets/gregtech/textures/blocks/machines/miner/overlay_top_emissive.png delete mode 100644 src/main/resources/assets/gregtech/textures/blocks/overlay/machine/overlay_chunk_miner.png delete mode 100644 src/main/resources/assets/gregtech/textures/blocks/overlay/machine/overlay_steam_miner.png diff --git a/build.gradle b/build.gradle index 1cb3142c393..33a6b8fd19c 100644 --- a/build.gradle +++ b/build.gradle @@ -1,4 +1,4 @@ -//version: 1690966774 +//version: 1695527071 /* * DO NOT CHANGE THIS FILE! * Also, you may replace this file at any time if there is an update available. @@ -24,9 +24,9 @@ plugins { id 'eclipse' id 'maven-publish' id 'org.jetbrains.gradle.plugin.idea-ext' version '1.1.7' - id 'com.gtnewhorizons.retrofuturagradle' version '1.3.23' - id 'net.darkhax.curseforgegradle' version '1.0.14' apply false - id 'com.modrinth.minotaur' version '2.8.0' apply false + id 'com.gtnewhorizons.retrofuturagradle' version '1.3.24' + id 'net.darkhax.curseforgegradle' version '1.1.16' apply false + id 'com.modrinth.minotaur' version '2.8.4' apply false id 'com.diffplug.spotless' version '6.13.0' apply false id 'com.palantir.git-version' version '3.0.0' apply false id 'com.github.johnrengelman.shadow' version '8.1.1' apply false diff --git a/src/main/java/gregtech/api/capability/GregtechDataCodes.java b/src/main/java/gregtech/api/capability/GregtechDataCodes.java index 4d5974ade04..22c91b6cddf 100644 --- a/src/main/java/gregtech/api/capability/GregtechDataCodes.java +++ b/src/main/java/gregtech/api/capability/GregtechDataCodes.java @@ -43,7 +43,8 @@ public class GregtechDataCodes { // Pump, Miner public static final int PUMP_HEAD_LEVEL = 200; // Miner - public static final int MINER_UPDATE_PREVIEW = 201; + public static final int MINER_UPDATE_PREVIEW = 51; + public static final int MINER_UPDATE_ACTIVE = 52; // Item Collector, Magic Energy Absorber, Large Boiler, Steam Oven public static final int IS_WORKING = 100; diff --git a/src/main/java/gregtech/client/renderer/texture/Textures.java b/src/main/java/gregtech/client/renderer/texture/Textures.java index d2e26042cce..a57c71d7f91 100644 --- a/src/main/java/gregtech/client/renderer/texture/Textures.java +++ b/src/main/java/gregtech/client/renderer/texture/Textures.java @@ -171,7 +171,8 @@ public class Textures { public static final OrientedOverlayRenderer STEAM_TURBINE_OVERLAY = new OrientedOverlayRenderer("generators/steam_turbine"); public static final OrientedOverlayRenderer WORLD_ACCELERATOR_OVERLAY = new OrientedOverlayRenderer("machines/world_accelerator"); public static final OrientedOverlayRenderer WORLD_ACCELERATOR_TE_OVERLAY = new OrientedOverlayRenderer("machines/world_accelerator_te"); - + public static final OrientedOverlayRenderer MINER_OVERLAY = new OrientedOverlayRenderer("machines/miner"); + public static final OrientedOverlayRenderer STEAM_MINER_OVERLAY = new OrientedOverlayRenderer("machines/steam_miner"); // Simple Overlay Renderers public static final SimpleOverlayRenderer SCREEN = new SimpleOverlayRenderer("overlay/machine/overlay_screen"); @@ -262,8 +263,6 @@ public class Textures { public static final SimpleOverlayRenderer MAINTENANCE_OVERLAY_FULL_AUTO = new SimpleOverlayRenderer("overlay/machine/overlay_maintenance_full_auto"); public static final SimpleOverlayRenderer MAINTENANCE_OVERLAY_CLEANING = new SimpleOverlayRenderer("overlay/machine/overlay_maintenance_cleaning"); public static final SimpleOverlayRenderer MUFFLER_OVERLAY = new SimpleOverlayRenderer("overlay/machine/overlay_muffler"); - public static final SimpleOverlayRenderer STEAM_MINER_OVERLAY = new SimpleOverlayRenderer("overlay/machine/overlay_steam_miner"); - public static final SimpleOverlayRenderer CHUNK_MINER_OVERLAY = new SimpleOverlayRenderer("overlay/machine/overlay_chunk_miner"); public static final SimpleOverlayRenderer BLANK_SCREEN = new SimpleOverlayRenderer("overlay/machine/overlay_blank_screen"); public static final SimpleOverlayRenderer DATA_ACCESS_HATCH = new SimpleOverlayRenderer("overlay/machine/overlay_data_hatch"); public static final SimpleOverlayRenderer CREATIVE_DATA_ACCESS_HATCH = new SimpleOverlayRenderer("overlay/machine/overlay_data_hatch_creative"); diff --git a/src/main/java/gregtech/common/metatileentities/MetaTileEntities.java b/src/main/java/gregtech/common/metatileentities/MetaTileEntities.java index 3d81d0c27e5..00438c7b2fa 100644 --- a/src/main/java/gregtech/common/metatileentities/MetaTileEntities.java +++ b/src/main/java/gregtech/common/metatileentities/MetaTileEntities.java @@ -21,7 +21,7 @@ import gregtech.common.metatileentities.converter.MetaTileEntityConverter; import gregtech.common.metatileentities.electric.*; import gregtech.common.metatileentities.miner.MetaTileEntityLargeMiner; -import gregtech.common.metatileentities.miner.MetaTileEntityLargeMiner.LargeMinerType; +import gregtech.common.metatileentities.miner.LargeMinerTypes; import gregtech.common.metatileentities.miner.MetaTileEntityMiner; import gregtech.common.metatileentities.miner.SteamMiner; import gregtech.common.metatileentities.multi.*; @@ -520,9 +520,9 @@ public static void init() { STEAM_OVEN = registerMetaTileEntity(1024, new MetaTileEntitySteamOven(gregtechId("steam_oven"))); STEAM_GRINDER = registerMetaTileEntity(1025, new MetaTileEntitySteamGrinder(gregtechId("steam_grinder"))); - BASIC_LARGE_MINER = registerMetaTileEntity(1026, new MetaTileEntityLargeMiner(gregtechId("large_miner.ev"), GTValues.EV, 16, 3, 4, 8, LargeMinerType.STEEL)); - LARGE_MINER = registerMetaTileEntity(1027, new MetaTileEntityLargeMiner(gregtechId("large_miner.iv"), GTValues.IV, 4, 5, 5, 16, LargeMinerType.TITANIUM)); - ADVANCED_LARGE_MINER = registerMetaTileEntity(1028, new MetaTileEntityLargeMiner(gregtechId("large_miner.luv"), GTValues.LuV, 1, 7, 6, 32, LargeMinerType.TUNGSTEN_STEEL)); + BASIC_LARGE_MINER = registerMetaTileEntity(1026, new MetaTileEntityLargeMiner(gregtechId("large_miner.ev"), GTValues.EV, 16, 3, 4, 8, LargeMinerTypes.STEEL)); + LARGE_MINER = registerMetaTileEntity(1027, new MetaTileEntityLargeMiner(gregtechId("large_miner.iv"), GTValues.IV, 4, 5, 5, 16, LargeMinerTypes.TITANIUM)); + ADVANCED_LARGE_MINER = registerMetaTileEntity(1028, new MetaTileEntityLargeMiner(gregtechId("large_miner.luv"), GTValues.LuV, 1, 7, 6, 32, LargeMinerTypes.TUNGSTEN_STEEL)); CENTRAL_MONITOR = registerMetaTileEntity(1029, new MetaTileEntityCentralMonitor(gregtechId("central_monitor"))); diff --git a/src/main/java/gregtech/common/metatileentities/miner/IMiner.java b/src/main/java/gregtech/common/metatileentities/miner/IMiner.java deleted file mode 100644 index 38e939ff711..00000000000 --- a/src/main/java/gregtech/common/metatileentities/miner/IMiner.java +++ /dev/null @@ -1,19 +0,0 @@ -package gregtech.common.metatileentities.miner; - -import net.minecraft.util.text.ITextComponent; - -import javax.annotation.Nonnull; -import java.util.List; - -public interface IMiner { - - /** - * Try to drain all mining resources required for one operation. (e.g. energy, mining fluids) - * - * @param simulate Whether this action shouldn't affect the state - * @return Whether the action succeeded - */ - boolean drainMiningResources(boolean simulate); - - default void describeMiningResourceStatus(@Nonnull List textList) {} -} diff --git a/src/main/java/gregtech/common/metatileentities/miner/LargeMinerType.java b/src/main/java/gregtech/common/metatileentities/miner/LargeMinerType.java new file mode 100644 index 00000000000..6df3a2454a5 --- /dev/null +++ b/src/main/java/gregtech/common/metatileentities/miner/LargeMinerType.java @@ -0,0 +1,27 @@ +package gregtech.common.metatileentities.miner; + +import gregtech.api.metatileentity.multiblock.IMultiblockPart; +import gregtech.api.pattern.TraceabilityPredicate; +import gregtech.client.renderer.ICubeRenderer; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +public interface LargeMinerType { + + @Nonnull + TraceabilityPredicate getCasing(); + + @Nonnull + TraceabilityPredicate getFrame(); + + @SideOnly(Side.CLIENT) + @Nonnull + ICubeRenderer getFrontOverlay(); + + @SideOnly(Side.CLIENT) + @Nonnull + ICubeRenderer getBaseTexture(@Nullable IMultiblockPart sourcePart); +} diff --git a/src/main/java/gregtech/common/metatileentities/miner/LargeMinerTypes.java b/src/main/java/gregtech/common/metatileentities/miner/LargeMinerTypes.java new file mode 100644 index 00000000000..7dcde438c0e --- /dev/null +++ b/src/main/java/gregtech/common/metatileentities/miner/LargeMinerTypes.java @@ -0,0 +1,62 @@ +package gregtech.common.metatileentities.miner; + +import gregtech.api.metatileentity.multiblock.IMultiblockPart; +import gregtech.api.metatileentity.multiblock.MultiblockControllerBase; +import gregtech.api.pattern.TraceabilityPredicate; +import gregtech.api.unification.material.Materials; +import gregtech.client.renderer.ICubeRenderer; +import gregtech.client.renderer.texture.Textures; +import gregtech.common.blocks.BlockMetalCasing; +import gregtech.common.blocks.MetaBlocks; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +public enum LargeMinerTypes implements LargeMinerType { + STEEL, + TITANIUM, + TUNGSTEN_STEEL; + + @Nonnull + public TraceabilityPredicate getCasing() { + return MultiblockControllerBase.states(switch (this) { + case STEEL -> MetaBlocks.METAL_CASING.getState(BlockMetalCasing.MetalCasingType.STEEL_SOLID); + case TITANIUM -> MetaBlocks.METAL_CASING.getState(BlockMetalCasing.MetalCasingType.TITANIUM_STABLE); + case TUNGSTEN_STEEL -> + MetaBlocks.METAL_CASING.getState(BlockMetalCasing.MetalCasingType.TUNGSTENSTEEL_ROBUST); + }); + } + + @Nonnull + public TraceabilityPredicate getFrame() { + return MultiblockControllerBase.frames(switch (this) { + case STEEL -> Materials.Steel; + case TITANIUM -> Materials.Titanium; + case TUNGSTEN_STEEL -> Materials.TungstenSteel; + }); + } + + @Nonnull + @Override + @SideOnly(Side.CLIENT) + public ICubeRenderer getBaseTexture(@Nullable IMultiblockPart sourcePart) { + return switch (this) { + case STEEL -> Textures.SOLID_STEEL_CASING; + case TITANIUM -> Textures.STABLE_TITANIUM_CASING; + case TUNGSTEN_STEEL -> Textures.ROBUST_TUNGSTENSTEEL_CASING; + }; + } + + @Nonnull + @Override + @SideOnly(Side.CLIENT) + public ICubeRenderer getFrontOverlay() { + return switch (this) { + case STEEL -> Textures.LARGE_MINER_OVERLAY_ADVANCED; + case TITANIUM -> Textures.LARGE_MINER_OVERLAY_ADVANCED_2; + case TUNGSTEN_STEEL -> Textures.LARGE_MINER_OVERLAY_BASIC; + }; + } +} diff --git a/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityLargeMiner.java b/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityLargeMiner.java index a5bab4d0529..d9fc3506cde 100644 --- a/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityLargeMiner.java +++ b/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityLargeMiner.java @@ -16,6 +16,7 @@ import gregtech.api.gui.GuiTextures; import gregtech.api.gui.Widget; import gregtech.api.gui.widgets.ImageCycleButtonWidget; +import gregtech.api.items.toolitem.ToolHelper; import gregtech.api.metatileentity.IDataInfoProvider; import gregtech.api.metatileentity.IFastRenderMetaTileEntity; import gregtech.api.metatileentity.MetaTileEntity; @@ -26,25 +27,19 @@ import gregtech.api.pattern.BlockPattern; import gregtech.api.pattern.FactoryBlockPattern; import gregtech.api.pattern.PatternMatchContext; -import gregtech.api.pattern.TraceabilityPredicate; import gregtech.api.recipes.RecipeMaps; -import gregtech.api.unification.material.Materials; import gregtech.api.util.GTUtility; import gregtech.client.renderer.ICubeRenderer; -import gregtech.client.renderer.texture.Textures; -import gregtech.common.blocks.BlockMetalCasing.MetalCasingType; -import gregtech.common.blocks.MetaBlocks; import gregtech.core.sound.GTSoundEvents; +import net.minecraft.block.state.IBlockState; import net.minecraft.client.resources.I18n; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.PacketBuffer; -import net.minecraft.util.EnumFacing; -import net.minecraft.util.EnumHand; -import net.minecraft.util.ResourceLocation; -import net.minecraft.util.SoundEvent; +import net.minecraft.util.*; import net.minecraft.util.math.AxisAlignedBB; +import net.minecraft.util.math.BlockPos; import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.Style; import net.minecraft.util.text.TextComponentTranslation; @@ -56,6 +51,7 @@ import net.minecraftforge.fml.relauncher.SideOnly; import net.minecraftforge.items.IItemHandlerModifiable; import net.minecraftforge.items.ItemStackHandler; +import org.jetbrains.annotations.NotNull; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -65,12 +61,14 @@ import static gregtech.api.unification.material.Materials.DrillingFluid; -public class MetaTileEntityLargeMiner extends MultiblockWithDisplayBase implements IMiner, IControllable, IDataInfoProvider, IFastRenderMetaTileEntity { +public class MetaTileEntityLargeMiner extends MultiblockWithDisplayBase implements Miner, IControllable, IDataInfoProvider, IFastRenderMetaTileEntity { @Nonnull - public final ILargeMinerType type; + public final LargeMinerType type; public final int tier; public final int drillingFluidConsumePerTick; + public final int oreMultiplier; + private final MultiblockMinerLogic minerLogic; private IEnergyContainer energyContainer; @@ -78,19 +76,20 @@ public class MetaTileEntityLargeMiner extends MultiblockWithDisplayBase implemen protected IItemHandlerModifiable outputInventory; public MetaTileEntityLargeMiner(ResourceLocation metaTileEntityId, int tier, int speed, int maxChunkDiameter, - int fortune, int drillingFluidConsumePerTick, @Nonnull ILargeMinerType type) { + int oreMultiplier, int drillingFluidConsumePerTick, @Nonnull LargeMinerType type) { super(metaTileEntityId); this.type = Objects.requireNonNull(type, "type == null"); this.tier = tier; this.drillingFluidConsumePerTick = drillingFluidConsumePerTick; - this.minerLogic = new MultiblockMinerLogic(this, fortune, speed, maxChunkDiameter, RecipeMaps.MACERATOR_RECIPES); + this.oreMultiplier = oreMultiplier; + this.minerLogic = new MultiblockMinerLogic(this, speed, maxChunkDiameter); } @Override public MetaTileEntity createMetaTileEntity(IGregTechTileEntity tileEntity) { return new MetaTileEntityLargeMiner(metaTileEntityId, this.tier, this.minerLogic.getWorkFrequency(), this.minerLogic.getMaximumChunkDiameter(), - this.minerLogic.getFortune(), this.drillingFluidConsumePerTick, this.type); + this.oreMultiplier, this.drillingFluidConsumePerTick, this.type); } @Override @@ -116,10 +115,9 @@ public int getEnergyTier() { } @Override - public boolean drainMiningResources(boolean simulate) { - if (!drainEnergy(true) || !drainFluid(true)) { - return false; - } + public boolean drainMiningResources(@NotNull MinedBlockType minedBlockType, boolean pipeExtended, boolean simulate) { + if (minedBlockType == MinedBlockType.NOTHING) return true; + if (!drainEnergy(true) || !drainFluid(true)) return false; if (!simulate) { drainEnergy(false); drainFluid(false); @@ -146,39 +144,49 @@ protected boolean drainFluid(boolean simulate) { return drained != null && drained.amount >= amount; } + @Override + public void getRegularBlockDrops(@Nonnull NonNullList drops, @Nonnull World world, @Nonnull BlockPos pos, @Nonnull IBlockState state) { + if (this.minerLogic.isSilkTouchMode()) { + drops.add(ToolHelper.getSilkTouchDrop(state)); + } else if (MinerUtil.applyTieredHammerDrops(GTUtility.toItem(state), drops, + this.getEnergyTier(), RecipeMaps.MACERATOR_RECIPES, this.oreMultiplier) == 0) { + Miner.super.getRegularBlockDrops(drops, world, pos, state); // fallback + } + } + @Override @SideOnly(Side.CLIENT) public void renderMetaTileEntity(CCRenderState renderState, Matrix4 translation, IVertexOperation[] pipeline) { super.renderMetaTileEntity(renderState, translation, pipeline); - this.getFrontOverlay().renderOrientedState(renderState, translation, pipeline, getFrontFacing(), this.minerLogic.isWorking(), this.isWorkingEnabled()); + this.getFrontOverlay().renderOrientedState(renderState, translation, pipeline, getFrontFacing(), isActive(), isWorkingEnabled()); if (isStructureFormed()) { EnumFacing back = getFrontFacing().getOpposite(); - MinerUtil.renderPipe(getBaseTexture(null), this.minerLogic.getPipeLength(), renderState, + MinerRenderHelper.renderPipe(getBaseTexture(null), this.minerLogic.getPipeLength(), renderState, translation.translate(back.getXOffset(), back.getYOffset(), back.getZOffset()), pipeline); } } @Override public void renderMetaTileEntity(double x, double y, double z, float partialTicks) { - IMiningArea previewArea = this.minerLogic.getPreviewArea(); + MiningArea previewArea = this.minerLogic.getPreviewArea(); if (previewArea != null) previewArea.renderMetaTileEntity(this, x, y, z, partialTicks); } @Override public void renderMetaTileEntityFast(CCRenderState renderState, Matrix4 translation, float partialTicks) { - IMiningArea previewArea = this.minerLogic.getPreviewArea(); + MiningArea previewArea = this.minerLogic.getPreviewArea(); if (previewArea != null) previewArea.renderMetaTileEntityFast(this, renderState, translation, partialTicks); } @Override public AxisAlignedBB getRenderBoundingBox() { - IMiningArea previewArea = this.minerLogic.getPreviewArea(); + MiningArea previewArea = this.minerLogic.getPreviewArea(); return previewArea != null ? previewArea.getRenderBoundingBox() : MinerUtil.EMPTY_AABB; } @Override public boolean shouldRenderInPass(int pass) { - IMiningArea previewArea = this.minerLogic.getPreviewArea(); + MiningArea previewArea = this.minerLogic.getPreviewArea(); return previewArea != null && previewArea.shouldRenderInPass(pass); } @@ -425,67 +433,4 @@ public List getDataInfo() { protected boolean shouldShowVoidingModeButton() { return false; } - - public interface ILargeMinerType { - - @Nonnull - TraceabilityPredicate getCasing(); - - @Nonnull - TraceabilityPredicate getFrame(); - - @SideOnly(Side.CLIENT) - @Nonnull - ICubeRenderer getFrontOverlay(); - - @SideOnly(Side.CLIENT) - @Nonnull - ICubeRenderer getBaseTexture(@Nullable IMultiblockPart sourcePart); - } - - public enum LargeMinerType implements ILargeMinerType { - STEEL, - TITANIUM, - TUNGSTEN_STEEL; - - @Nonnull - public TraceabilityPredicate getCasing() { - return states(switch (this) { - case STEEL -> MetaBlocks.METAL_CASING.getState(MetalCasingType.STEEL_SOLID); - case TITANIUM -> MetaBlocks.METAL_CASING.getState(MetalCasingType.TITANIUM_STABLE); - case TUNGSTEN_STEEL -> MetaBlocks.METAL_CASING.getState(MetalCasingType.TUNGSTENSTEEL_ROBUST); - }); - } - - @Nonnull - public TraceabilityPredicate getFrame() { - return frames(switch (this) { - case STEEL -> Materials.Steel; - case TITANIUM -> Materials.Titanium; - case TUNGSTEN_STEEL -> Materials.TungstenSteel; - }); - } - - @Nonnull - @Override - @SideOnly(Side.CLIENT) - public ICubeRenderer getBaseTexture(@Nullable IMultiblockPart sourcePart) { - return switch (this) { - case STEEL -> Textures.SOLID_STEEL_CASING; - case TITANIUM -> Textures.STABLE_TITANIUM_CASING; - case TUNGSTEN_STEEL -> Textures.ROBUST_TUNGSTENSTEEL_CASING; - }; - } - - @Nonnull - @Override - @SideOnly(Side.CLIENT) - public ICubeRenderer getFrontOverlay() { - return switch (this) { - case STEEL -> Textures.LARGE_MINER_OVERLAY_ADVANCED; - case TITANIUM -> Textures.LARGE_MINER_OVERLAY_ADVANCED_2; - case TUNGSTEN_STEEL -> Textures.LARGE_MINER_OVERLAY_BASIC; - }; - } - } } diff --git a/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityMiner.java b/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityMiner.java index 1721e1ef23f..4bcfe716c8f 100644 --- a/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityMiner.java +++ b/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityMiner.java @@ -31,7 +31,6 @@ import net.minecraft.util.*; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.text.ITextComponent; -import net.minecraft.util.text.Style; import net.minecraft.util.text.TextComponentTranslation; import net.minecraft.util.text.TextFormatting; import net.minecraft.world.World; @@ -40,6 +39,7 @@ import net.minecraftforge.fml.relauncher.SideOnly; import net.minecraftforge.items.IItemHandlerModifiable; import net.minecraftforge.items.ItemStackHandler; +import org.jetbrains.annotations.NotNull; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -47,7 +47,7 @@ import java.util.Collections; import java.util.List; -public class MetaTileEntityMiner extends TieredMetaTileEntity implements IMiner, IControllable, IDataInfoProvider, IFastRenderMetaTileEntity { +public class MetaTileEntityMiner extends TieredMetaTileEntity implements Miner, IControllable, IDataInfoProvider, IFastRenderMetaTileEntity { private final ItemStackHandler chargerInventory; @@ -56,8 +56,6 @@ public class MetaTileEntityMiner extends TieredMetaTileEntity implements IMiner, private final MinerLogic minerLogic; - private boolean hasNotEnoughEnergy; - public MetaTileEntityMiner(@Nonnull ResourceLocation metaTileEntityId, int tier, int workFrequency, int maximumDiameter) { super(metaTileEntityId, tier); this.inventorySize = (tier + 1) * (tier + 1); @@ -86,37 +84,34 @@ protected IItemHandlerModifiable createExportItemHandler() { @SideOnly(Side.CLIENT) public void renderMetaTileEntity(CCRenderState renderState, Matrix4 translation, IVertexOperation[] pipeline) { super.renderMetaTileEntity(renderState, translation, pipeline); - Textures.SCREEN.renderSided(EnumFacing.UP, renderState, translation, pipeline); - for (EnumFacing renderSide : EnumFacing.HORIZONTALS) { - if (renderSide == getFrontFacing()) { - Textures.PIPE_OUT_OVERLAY.renderSided(renderSide, renderState, translation, pipeline); - } else - Textures.CHUNK_MINER_OVERLAY.renderSided(renderSide, renderState, translation, pipeline); + Textures.MINER_OVERLAY.renderOrientedState(renderState, translation, pipeline, getFrontFacing(), minerLogic.isActive(), minerLogic.isWorkingEnabled()); + if (hasFrontFacing()) { + Textures.PIPE_OUT_OVERLAY.renderSided(getFrontFacing(), renderState, translation, pipeline); } - MinerUtil.renderPipe(Textures.SOLID_STEEL_CASING, this.minerLogic.getPipeLength(), renderState, translation, pipeline); + MinerRenderHelper.renderPipe(Textures.SOLID_STEEL_CASING, this.minerLogic.getPipeLength(), renderState, translation, pipeline); } @Override public void renderMetaTileEntity(double x, double y, double z, float partialTicks) { - IMiningArea previewArea = this.minerLogic.getPreviewArea(); + MiningArea previewArea = this.minerLogic.getPreviewArea(); if (previewArea != null) previewArea.renderMetaTileEntity(this, x, y, z, partialTicks); } @Override public void renderMetaTileEntityFast(CCRenderState renderState, Matrix4 translation, float partialTicks) { - IMiningArea previewArea = this.minerLogic.getPreviewArea(); + MiningArea previewArea = this.minerLogic.getPreviewArea(); if (previewArea != null) previewArea.renderMetaTileEntityFast(this, renderState, translation, partialTicks); } @Override public AxisAlignedBB getRenderBoundingBox() { - IMiningArea previewArea = this.minerLogic.getPreviewArea(); + MiningArea previewArea = this.minerLogic.getPreviewArea(); return previewArea != null ? previewArea.getRenderBoundingBox() : MinerUtil.EMPTY_AABB; } @Override public boolean shouldRenderInPass(int pass) { - IMiningArea previewArea = this.minerLogic.getPreviewArea(); + MiningArea previewArea = this.minerLogic.getPreviewArea(); return previewArea != null && previewArea.shouldRenderInPass(pass); } @@ -150,17 +145,13 @@ protected ModularUI createUI(@Nonnull EntityPlayer entityPlayer) { } builder.widget( - new ProgressWidget(() -> { - if (!this.minerLogic.isWorking()) return 0; - int workFrequency = this.minerLogic.getWorkFrequency(); - return workFrequency < 2 ? 1 : (getOffsetTimer() % workFrequency) / (double) workFrequency; - }, xStart - 4 - 20, sideWidgetY, 20, 20, + new ProgressWidget(this.minerLogic::getWorkProgress, xStart - 4 - 20, sideWidgetY, 20, 20, GuiTextures.PROGRESS_BAR_MACERATE, ProgressWidget.MoveType.HORIZONTAL) ).widget( new ImageWidget(xStart - 4 - 20, sideWidgetY + 20, 18, 18, GuiTextures.INDICATOR_NO_ENERGY) .setIgnoreColor(true) - .setPredicate(() -> this.hasNotEnoughEnergy) + .setPredicate(minerLogic::hasNotEnoughEnergy) ).widget( new ImageWidget(152, 63 + yOffset, 17, 17, GTValues.XMAS.get() ? GuiTextures.GREGTECH_LOGO_XMAS : GuiTextures.GREGTECH_LOGO) @@ -170,14 +161,6 @@ protected ModularUI createUI(@Nonnull EntityPlayer entityPlayer) { return builder.build(getHolder(), entityPlayer); } - @Override - public void describeMiningResourceStatus(@Nonnull List textList) { - if (!drainMiningResources(true)) { - textList.add(new TextComponentTranslation("gregtech.multiblock.not_enough_energy") - .setStyle(new Style().setColor(TextFormatting.RED))); - } - } - @Override public void addInformation(ItemStack stack, @Nullable World player, @Nonnull List tooltip, boolean advanced) { tooltip.add(I18n.format("gregtech.machine.miner.tooltip")); @@ -198,16 +181,13 @@ public void addToolUsages(ItemStack stack, @Nullable World world, List t } @Override - public boolean drainMiningResources(boolean simulate) { + public boolean drainMiningResources(@NotNull MinedBlockType minedBlockType, boolean pipeExtended, boolean simulate) { + if (minedBlockType == MinedBlockType.NOTHING) return true; long resultEnergy = energyContainer.getEnergyStored() - energyPerTick; - if (resultEnergy < 0 || resultEnergy > energyContainer.getEnergyCapacity()) { - this.hasNotEnoughEnergy = true; - return false; - } + if (resultEnergy < 0 || resultEnergy > energyContainer.getEnergyCapacity()) return false; if (!simulate) { energyContainer.removeEnergy(energyPerTick); } - this.hasNotEnoughEnergy = false; return true; } @@ -308,7 +288,7 @@ public SoundEvent getSound() { @Override public boolean isActive() { - return minerLogic.isActive() && isWorkingEnabled(); + return minerLogic.isActive(); } @Nonnull diff --git a/src/main/java/gregtech/common/metatileentities/miner/Miner.java b/src/main/java/gregtech/common/metatileentities/miner/Miner.java new file mode 100644 index 00000000000..c65494e0140 --- /dev/null +++ b/src/main/java/gregtech/common/metatileentities/miner/Miner.java @@ -0,0 +1,66 @@ +package gregtech.common.metatileentities.miner; + +import net.minecraft.block.state.IBlockState; +import net.minecraft.item.ItemStack; +import net.minecraft.util.NonNullList; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.minecraft.world.WorldServer; + +import javax.annotation.Nonnull; + +public interface Miner { + + /** + * Try to drain all mining resources required for one operation. (e.g. energy, mining fluids) + * + * @param minedBlockType Type of the block mined + * @param pipeExtended Whether the pipe length got extended + * @param simulate If {@code true}, this action will not affect the state of the game + * @return Whether the action was successful + */ + boolean drainMiningResources(@Nonnull MinedBlockType minedBlockType, boolean pipeExtended, boolean simulate); + + default boolean canOperate() { + return true; + } + + /** + * Called after each block is mined. + * + * @param pos position of the block mined + * @param isOre whether it was ore block + * @param isOrigin whether it was origin (the block mining pipe goes in) + */ + default void onMineOperation(@Nonnull BlockPos pos, boolean isOre, boolean isOrigin) {} + + /** + * Called to handle mining regular ores and blocks + * + * @param drops the List of items to fill after the operation + * @param world the {@link WorldServer} the miner is in + * @param pos the {@link BlockPos} of the block being mined + * @param state the {@link IBlockState} of the block being mined + */ + default void getRegularBlockDrops(@Nonnull NonNullList drops, @Nonnull World world, @Nonnull BlockPos pos, @Nonnull IBlockState state) { + state.getBlock().getDrops(drops, world, pos, state, 0); // regular ores do not get fortune applied + } + + /** + * Type of the block mined. + */ + enum MinedBlockType { + /** + * Mined nothing + */ + NOTHING, + /** + * Mined an ore + */ + ORE, + /** + * Mined a block that isn't an ore, like a block in the center (pipe column). + */ + BLOCK; + } +} diff --git a/src/main/java/gregtech/common/metatileentities/miner/MinerLogic.java b/src/main/java/gregtech/common/metatileentities/miner/MinerLogic.java index eb9834628c9..c27e820ad7a 100644 --- a/src/main/java/gregtech/common/metatileentities/miner/MinerLogic.java +++ b/src/main/java/gregtech/common/metatileentities/miner/MinerLogic.java @@ -4,6 +4,8 @@ import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.util.BlockUtility; import gregtech.api.util.GTTransferUtils; +import gregtech.common.metatileentities.miner.Miner.MinedBlockType; +import net.minecraft.block.material.Material; import net.minecraft.block.state.IBlockState; import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; @@ -14,15 +16,14 @@ import net.minecraft.util.math.BlockPos.MutableBlockPos; import net.minecraft.util.math.MathHelper; import net.minecraft.world.World; -import net.minecraft.world.WorldServer; import net.minecraftforge.common.util.Constants; import net.minecraftforge.items.IItemHandlerModifiable; -import org.jetbrains.annotations.Nullable; import javax.annotation.Nonnull; +import javax.annotation.Nullable; import java.util.Objects; -public class MinerLogic { +public class MinerLogic { protected final MTE mte; @@ -33,8 +34,8 @@ public class MinerLogic { protected int currentDiameter; - private boolean done; - private boolean workingEnabled = true; + // flag indicating the miner has finished its action + protected boolean done; // last mined ore block protected final MutableBlockPos lastMinedOre = new MutableBlockPos(); @@ -42,64 +43,57 @@ public class MinerLogic { // number of ores processed so far protected int minedOreCount; + private boolean workingEnabled = true; + // pipe length used for rendering purposes private int pipeLength; - // non-negative value to limit Y level - private int yLimit; - - // bool config for repeating the operation after finished - private boolean repeat; - - // transient values below (not saved) + // transient fields below (not saved to NBT) @Nullable - private IMiningArea miningArea; + private MiningArea miningArea; + private boolean active; + private int workTick; // flag indicating last insertion to inventory failed private boolean inventoryFull; - // flag indicating scan area should be rebuilt - protected boolean rebuildScanArea; - // status of the last update; true means miner is working, false means no - private boolean active; - + // flag indicating mining area should be rebuilt + protected boolean rebuildMiningArea; + // flag for area preview private boolean preview; - // remote instance only, contains IMiningArea instances deserialized from packet + private boolean hasNotEnoughEnergy; + + // remote instances only, contains MiningArea instances deserialized from packet @Nullable - private IMiningArea previewArea; + private MiningArea previewArea; /** * Creates the general logic for all in-world ore block miners * * @param mte the {@link MetaTileEntity} this logic belongs to - * @param workFrequency work frequency in ticks; value of <=1 means the miner operates each tick, 2 means the miner - * operates every other tick and so on + * @param workFrequency work frequency in ticks. In other words, the miner will operate every + * {@code workFrequency} ticks; once a second in {@code 20}, every other tick in {@code 2}, + * and each tick in {@code 1}. * @param maximumDiameter the maximum diameter of a square the miner can mine in + * @throws IllegalArgumentException if {@code workFrequency <= 0} + * @throws NullPointerException if {@code mte == null} */ public MinerLogic(@Nonnull MTE mte, int workFrequency, int maximumDiameter) { - this.mte = mte; + if (workFrequency <= 0) throw new IllegalArgumentException("workFrequency <= 0"); + this.mte = Objects.requireNonNull(mte, "mte == null"); this.workFrequency = workFrequency; this.currentDiameter = this.maximumDiameter = maximumDiameter; } - /** - * @return the miner's speed in ticks - */ public int getWorkFrequency() { return this.workFrequency; } - /** - * @return the miner's maximum diameter - */ public int getMaximumDiameter() { return this.maximumDiameter; } - /** - * @return the miner's current diameter - */ public int getCurrentDiameter() { return this.currentDiameter; } @@ -112,30 +106,13 @@ public void setCurrentDiameter(int currentDiameter) { currentDiameter = Math.max(1, Math.min(currentDiameter, getMaximumDiameter())); if (this.currentDiameter != currentDiameter) { this.currentDiameter = currentDiameter; - this.rebuildScanArea = true; + this.rebuildMiningArea = true; this.mte.markDirty(); } } - /** - * @return true if the miner is finished working - */ - public boolean isDone() { - return this.done; - } - - /** - * @return true if the miner is active - */ public boolean isActive() { - return this.workingEnabled && this.active; - } - - /** - * @return whether working is enabled for the logic - */ - public boolean isWorkingEnabled() { - return this.workingEnabled; + return this.active; } public boolean isInventoryFull() { @@ -147,10 +124,43 @@ public int getPipeLength() { } @Nullable - public IMiningArea getPreviewArea() { + public MiningArea getPreviewArea() { return this.previewArea; } + public boolean isAtWorkTick() { + if (this.workFrequency == 1) return true; + return this.mte.getOffsetTimer() % this.workFrequency == this.workTick; + } + + /** + *

+ * Set next work tick to {@code workTick} after current tick. When called during {@link #update()}, this method + * essentially sets next operation at {@code workTick} after. If not called, the next update happens + * {@link #workFrequency} ticks after. + *

+ *

+ * If {@code workTick} is greater or equal than {@link #workFrequency}, {@code workTick % workFrequency} will be + * used instead. + *

+ */ + protected void setNextWorkTick(int workTick) { + this.workTick = (this.workTick + workTick) % this.workFrequency; + } + + public double getWorkProgress() { + if (!isWorking()) return 0; + if (getWorkFrequency() < 2) return 1; + return ((mte.getOffsetTimer() + getWorkFrequency() - workTick) % getWorkFrequency()) / (double) getWorkFrequency(); + } + + /** + * @return whether working is enabled for the logic + */ + public boolean isWorkingEnabled() { + return this.workingEnabled; + } + /** * @param isWorkingEnabled the new state of the miner's ability to work: true to change to enabled, else false */ @@ -159,27 +169,11 @@ public void setWorkingEnabled(boolean isWorkingEnabled) { this.workingEnabled = isWorkingEnabled; this.mte.markDirty(); if (mte.getWorld() != null && !mte.getWorld().isRemote) { - if (!isWorkingEnabled) reset(); this.mte.writeCustomData(GregtechDataCodes.WORKING_ENABLED, buf -> buf.writeBoolean(isWorkingEnabled)); } } } - public int getYLimit() { - return yLimit; - } - - public void setYLimit(int yLimit) { - if (yLimit != this.yLimit) { - this.yLimit = yLimit; - this.rebuildScanArea = true; - this.mte.markDirty(); - if (this.preview) { - updatePreview(); - } - } - } - public boolean isPreviewEnabled() { return preview; } @@ -191,39 +185,15 @@ public void setPreviewEnabled(boolean previewEnabled) { } } - public boolean isRepeat() { - return repeat; - } - - public void setRepeat(boolean repeat) { - if (this.repeat != repeat) { - this.repeat = repeat; - this.mte.markDirty(); - } - } - /** * @return whether the miner is currently working */ public boolean isWorking() { - return active && workingEnabled; + return this.miningArea != null && !this.done && isWorkingEnabled() && !hasNotEnoughEnergy(); } - /** - * Recalculates the mining area and restarts the miner, if it was done - */ - public void reset() { - this.hasLastMinedOre = false; - this.pipeLength = 0; - - this.miningArea = Objects.requireNonNull(createMiningArea(), "createMiningArea() returned null!"); - - if (this.done) { - this.setWorkingEnabled(false); - this.done = false; - } - resetPipeLength(); - this.mte.markDirty(); + public boolean hasNotEnoughEnergy() { + return hasNotEnoughEnergy; } /** @@ -235,83 +205,104 @@ protected BlockPos getOrigin() { return mte.getPos(); } + @Nullable + public final MiningArea getMiningArea() { + return this.miningArea; + } + /** - * Create instance of {@link IMiningArea} based on current state. + * Create instance of {@link MiningArea} based on current state. * - * @return new {@link IMiningArea} instance + * @return new {@link MiningArea} instance */ @Nonnull - protected IMiningArea createMiningArea() { + protected MiningArea createMiningArea() { BlockPos origin = getOrigin(); int radius = this.currentDiameter / 2; int startX = origin.getX() - radius; - int startY = origin.getY() - 1; int startZ = origin.getZ() - radius; - int endX = startX + this.currentDiameter; - int endY = this.yLimit > 0 ? origin.getY() - this.yLimit : Integer.MIN_VALUE; - int endZ = startZ + this.currentDiameter; - return new SimpleMiningArea(startX, startY, startZ, endX, endY, endZ); + return new SimpleMiningArea(startX, origin.getY() - 1, startZ, + startX + this.currentDiameter, Integer.MIN_VALUE, startZ + this.currentDiameter); } - @Nonnull - protected IMiningArea readPreviewArea(@Nonnull PacketBuffer buffer) { - return SimpleMiningArea.readPreview(buffer); + /** + * Recalculates the mining area and restarts the miner, if it was done + */ + public void reset() { + this.hasLastMinedOre = false; + setPipeLength(0); + rebuildMiningArea(); + + this.mte.markDirty(); + } + + private void rebuildMiningArea() { + this.rebuildMiningArea = false; + this.miningArea = Objects.requireNonNull(createMiningArea(), "createMiningArea() returned null!"); + if (isPreviewEnabled()) { + updatePreview(); + } + } + + protected void updatePreview() { + this.mte.writeCustomData(GregtechDataCodes.MINER_UPDATE_PREVIEW, this::writePreviewUpdatePacket); } /** * Performs the actual mining in world. Call this method every tick in update. */ public void update() { - if (this.mte.getWorld().isRemote || - (this.workFrequency >= 2 && this.mte.getOffsetTimer() % this.workFrequency != 0)) { + if (this.mte.getWorld().isRemote) return; + + // rebuild scan area every tick regardless of miner status, for accurate preview + if (this.rebuildMiningArea || this.miningArea == null) { + rebuildMiningArea(); + } + + if (this.mte.drainMiningResources(MinedBlockType.ORE, true, true)) { + this.hasNotEnoughEnergy = false; + } else { + this.hasNotEnoughEnergy = true; return; } - boolean active = mine(); + mine(Objects.requireNonNull(this.miningArea)); + boolean active = !this.done; if (this.active != active) { this.active = active; - this.mte.writeCustomData(GregtechDataCodes.WORKABLE_ACTIVE, buf -> buf.writeBoolean(active)); + this.mte.writeCustomData(GregtechDataCodes.MINER_UPDATE_ACTIVE, b -> b.writeBoolean(active)); } } - private boolean mine() { - if (!this.workingEnabled || (!this.repeat && this.done) || !canOperate()) { - return false; - } - - if (this.rebuildScanArea || this.miningArea == null) { - this.rebuildScanArea = false; - reset(); - } - - IMiningArea miningArea = Objects.requireNonNull(this.miningArea); - - if (this.repeat && this.done) { - this.done = false; - miningArea.reset(); + protected void mine(@Nonnull MiningArea miningArea) { + if (this.done || !isAtWorkTick() || !this.workingEnabled || !this.mte.canOperate()) { + return; } - World world = mte.getWorld(); BlockPos origin = getOrigin(); + MutableBlockPos pos = this.mpos; + for (int i = MinerUtil.MAX_BLOCK_SCAN; i > 0; i--) { - MutableBlockPos pos = this.mpos; - if (!miningArea.getCurrentBlockPos(pos) || !world.isValid(pos) || (this.yLimit > 0 && origin.getY() - yLimit > pos.getY())) { - if (this.repeat) { - miningArea.reset(); - } else { - this.done = true; - } - return false; + if (!getCurrentBlock(miningArea, pos)) { + this.done = true; + return; } IBlockState state = world.getBlockState(pos); boolean isOrigin = pos.getX() == origin.getX() && pos.getZ() == origin.getZ(); - // skip unbreakable block / TE blocks - if (state.getBlockHardness(world, pos) < 0 || state.getBlock().hasTileEntity(state)) { - // center block (where mining pipes goes in) can be skipped by this, it'll probably look kind of janky - // but it's 100x better than voiding bedrock - if (isOrigin) incrementPipeLength(); + // skip air, unbreakable blocks & TE blocks + if (state.getMaterial() == Material.AIR || + state.getBlockHardness(world, pos) < 0 || + state.getBlock().hasTileEntity(state)) { + if (isOrigin) { // TODO liquid tile check? + // center block (where mining pipes goes in) can be skipped by this, it'll probably look kind of janky + // but it's 100x better than voiding bedrock + if (!this.mte.drainMiningResources(MinedBlockType.NOTHING, true, false)) { + return; + } + setPipeLength(this.pipeLength + 1); + } miningArea.nextBlock(); continue; } @@ -322,105 +313,76 @@ private boolean mine() { continue; } + if (!this.mte.drainMiningResources(isOre ? MinedBlockType.ORE : MinedBlockType.BLOCK, true, false)) { + return; + } + NonNullList blockDrops = NonNullList.create(); - getRegularBlockDrops(blockDrops, world, pos, state); + this.mte.getRegularBlockDrops(blockDrops, world, pos, state); if (isOre) { IItemHandlerModifiable exportItems = mte.getExportItems(); if (!GTTransferUtils.addItemsToItemHandler(exportItems, true, blockDrops)) { this.inventoryFull = true; - return false; + return; } GTTransferUtils.addItemsToItemHandler(exportItems, false, blockDrops); this.inventoryFull = false; this.lastMinedOre.setPos(pos); this.minedOreCount++; } - this.mte.drainMiningResources(false); - world.setBlockState(pos, isOrigin ? Blocks.AIR.getDefaultState() : MinerUtil.getOreReplacement()); - if (isOrigin) incrementPipeLength(); + world.setBlockState(pos, isOrigin ? Blocks.AIR.getDefaultState() : getOreReplacement()); + if (isOrigin) setPipeLength(this.pipeLength + 1); miningArea.nextBlock(); - onMineOperation(pos, isOre, isOrigin); + this.mte.onMineOperation(pos, isOre, isOrigin); this.mte.markDirty(); - return true; + return; } - return true; + setNextWorkTick(1); // scan next tick } - @SuppressWarnings("BooleanMethodIsAlwaysInverted") - protected boolean canOperate() { - return this.mte.drainMiningResources(true); - } - - /** - * Called after each block is mined. - * - * @param pos Position of the block mined - * @param isOre Whether it was ore block - * @param isOrigin Whether it was origin (the block mining pipe goes in) - */ - protected void onMineOperation(@Nonnull BlockPos pos, boolean isOre, boolean isOrigin) {} - - /** - * called to handle mining regular ores and blocks - * - * @param drops the List of items to fill after the operation - * @param world the {@link WorldServer} the miner is in - * @param pos the {@link BlockPos} of the block being mined - * @param state the {@link IBlockState} of the block being mined - */ - protected void getRegularBlockDrops(@Nonnull NonNullList drops, @Nonnull World world, @Nonnull BlockPos pos, @Nonnull IBlockState state) { - state.getBlock().getDrops(drops, world, pos, state, 0); // regular ores do not get fortune applied - } - - private void incrementPipeLength() { - this.pipeLength++; - this.mte.markDirty(); - this.mte.writeCustomData(GregtechDataCodes.PUMP_HEAD_LEVEL, b -> b.writeVarInt(pipeLength)); + @Nonnull + protected IBlockState getOreReplacement() { + return MinerUtil.getOreReplacement(); } - private void resetPipeLength() { - if (this.pipeLength == 0) return; - this.pipeLength = 0; + private void setPipeLength(int length) { + if (this.pipeLength == length) return; + this.pipeLength = length; this.mte.markDirty(); - this.mte.writeCustomData(GregtechDataCodes.PUMP_HEAD_LEVEL, b -> b.writeVarInt(pipeLength)); + this.mte.writeCustomData(GregtechDataCodes.PUMP_HEAD_LEVEL, b -> b.writeVarInt(length)); } - private void updatePreview() { - this.mte.writeCustomData(GregtechDataCodes.MINER_UPDATE_PREVIEW, this::writePreviewUpdatePacket); + protected void writePreviewUpdatePacket(@Nonnull PacketBuffer buffer) { + if (this.preview) { + MiningArea miningArea = this.miningArea; + if (miningArea != null) { + buffer.writeBoolean(true); + miningArea.writePreviewPacket(buffer); + return; + } + } + buffer.writeBoolean(false); } - private void writePreviewUpdatePacket(@Nonnull PacketBuffer buffer) { - if (!this.preview) { - buffer.writeBoolean(false); - return; - } - buffer.writeBoolean(true); - if (this.miningArea == null) { - this.miningArea = Objects.requireNonNull(createMiningArea(), "createMiningArea() returned null!"); - } - this.miningArea.writePreviewPacket(buffer); - buffer.writeVarInt(this.yLimit); + protected void readPreviewUpdatePacket(@Nonnull PacketBuffer buffer) { + this.previewArea = buffer.readBoolean() ? readPreviewArea(buffer) : null; } - private void readPreviewUpdatePacket(@Nonnull PacketBuffer buffer) { - if (!buffer.readBoolean()) { - this.previewArea = null; - return; - } - this.previewArea = readPreviewArea(buffer); - this.yLimit = buffer.readVarInt(); + @Nonnull + protected MiningArea readPreviewArea(@Nonnull PacketBuffer buffer) { + return SimpleMiningArea.readPreview(buffer); } /** - * Get the block currently being mined by this miner. + * Get the block currently being mined by this miner. This method only works on server environment. * * @param mpos Mutable block position * @return {@code true} if the block exists (in which the {@code mpos} instance gets modified with the value, or * {@code false} if it does not exist */ - public boolean getCurrentBlock(@Nonnull MutableBlockPos mpos) { - return this.miningArea != null && this.miningArea.getCurrentBlockPos(mpos); + public boolean getCurrentBlock(@Nonnull MiningArea miningArea, @Nonnull MutableBlockPos mpos) { + return miningArea.getCurrentBlockPos(mpos) && !mte.getWorld().isOutsideBuildHeight(mpos); } /** @@ -429,8 +391,8 @@ public boolean getCurrentBlock(@Nonnull MutableBlockPos mpos) { @Nonnull public NBTTagCompound writeToNBT(@Nonnull NBTTagCompound data) { data.setInteger("currentDiameter", this.currentDiameter); - if (this.done) data.setBoolean("done", true); if (!this.workingEnabled) data.setBoolean("disabled", true); + if (this.done) data.setBoolean("done", true); if (this.hasLastMinedOre) { data.setInteger("lastMinedOreX", this.lastMinedOre.getX()); @@ -441,9 +403,6 @@ public NBTTagCompound writeToNBT(@Nonnull NBTTagCompound data) { data.setInteger("minedOreCount", this.minedOreCount); data.setInteger("pipeLength", this.pipeLength); - if (this.yLimit > 0) data.setInteger("yLimit", this.yLimit); - if (this.repeat) data.setBoolean("repeat", true); - if (this.miningArea != null) { this.miningArea.write(data); } @@ -456,14 +415,12 @@ public NBTTagCompound writeToNBT(@Nonnull NBTTagCompound data) { */ public void readFromNBT(@Nonnull NBTTagCompound data) { this.inventoryFull = false; - this.active = false; - this.rebuildScanArea = true; + this.rebuildMiningArea = false; if (data.hasKey("xPos", Constants.NBT.TAG_INT)) { // retro save compat this.currentDiameter = MathHelper.clamp(data.getInteger("currentRadius") * 2 + 1, 1, getMaximumDiameter()); - this.done = data.getInteger("isDone") != 0; this.workingEnabled = data.getInteger("isWorkingEnabled") != 0; this.hasLastMinedOre = false; @@ -473,8 +430,8 @@ public void readFromNBT(@Nonnull NBTTagCompound data) { } this.currentDiameter = MathHelper.clamp(data.getInteger("currentDiameter"), 1, getMaximumDiameter()); - this.done = data.getBoolean("done"); this.workingEnabled = !data.getBoolean("disabled"); + this.done = data.getBoolean("done"); if (data.hasKey("lastMinedOreX", Constants.NBT.TAG_INT)) { this.lastMinedOre.setPos(data.getInteger("lastMinedOreX"), @@ -488,9 +445,6 @@ public void readFromNBT(@Nonnull NBTTagCompound data) { this.minedOreCount = Math.max(0, data.getInteger("minedOreCount")); this.pipeLength = Math.max(0, data.getInteger("pipeLength")); - this.yLimit = Math.max(0, data.getInteger("yLimit")); - this.repeat = data.getBoolean("repeat"); - this.miningArea = createMiningArea(); // Shouldn't be a problem but whatever //noinspection ConstantValue @@ -505,6 +459,8 @@ public void readFromNBT(@Nonnull NBTTagCompound data) { public void writeInitialSyncData(@Nonnull PacketBuffer buf) { buf.writeVarInt(this.pipeLength); buf.writeBoolean(this.workingEnabled); + buf.writeBoolean(this.done); + buf.writeBoolean(this.active); writePreviewUpdatePacket(buf); } @@ -514,6 +470,8 @@ public void writeInitialSyncData(@Nonnull PacketBuffer buf) { public void receiveInitialSyncData(@Nonnull PacketBuffer buf) { this.pipeLength = buf.readVarInt(); this.workingEnabled = buf.readBoolean(); + this.done = buf.readBoolean(); + this.active = buf.readBoolean(); readPreviewUpdatePacket(buf); } @@ -526,10 +484,6 @@ public void receiveCustomData(int dataId, @Nonnull PacketBuffer buf) { this.pipeLength = buf.readVarInt(); this.mte.scheduleRenderUpdate(); } - case GregtechDataCodes.WORKABLE_ACTIVE -> { - this.active = buf.readBoolean(); - this.mte.scheduleRenderUpdate(); - } case GregtechDataCodes.WORKING_ENABLED -> { this.workingEnabled = buf.readBoolean(); this.mte.scheduleRenderUpdate(); @@ -537,6 +491,10 @@ public void receiveCustomData(int dataId, @Nonnull PacketBuffer buf) { case GregtechDataCodes.MINER_UPDATE_PREVIEW -> { readPreviewUpdatePacket(buf); } + case GregtechDataCodes.MINER_UPDATE_ACTIVE -> { + this.active = buf.readBoolean(); + this.mte.scheduleRenderUpdate(); + } } } } diff --git a/src/main/java/gregtech/common/metatileentities/miner/MinerRenderHelper.java b/src/main/java/gregtech/common/metatileentities/miner/MinerRenderHelper.java new file mode 100644 index 00000000000..72efcba3464 --- /dev/null +++ b/src/main/java/gregtech/common/metatileentities/miner/MinerRenderHelper.java @@ -0,0 +1,389 @@ +package gregtech.common.metatileentities.miner; + +import codechicken.lib.render.CCRenderState; +import codechicken.lib.render.pipeline.IVertexOperation; +import codechicken.lib.vec.Cuboid6; +import codechicken.lib.vec.Matrix4; +import gregtech.api.util.GTUtility; +import gregtech.client.renderer.ICubeRenderer; +import gregtech.client.renderer.texture.Textures; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.BufferBuilder; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.GlStateManager.DestFactor; +import net.minecraft.client.renderer.GlStateManager.SourceFactor; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.culling.ClippingHelperImpl; +import net.minecraft.client.renderer.vertex.DefaultVertexFormats; +import net.minecraft.entity.Entity; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.math.AxisAlignedBB; +import net.minecraft.util.math.BlockPos; +import org.lwjgl.opengl.GL11; + +import javax.annotation.Nonnull; +import javax.vecmath.Vector3f; + +public class MinerRenderHelper { + + private MinerRenderHelper() {} + + public static final ResourceLocation MINER_AREA_PREVIEW_TEXTURE = GTUtility.gregtechId("textures/fx/miner_area_preview.png"); + private static final Cuboid6 PIPE_CUBOID = new Cuboid6(4 / 16.0, 0.0, 4 / 16.0, 12 / 16.0, 1.0, 12 / 16.0); + + private static final long TEXTURE_WRAP_INTERVAL_NANOSECONDS = 3_000_000_000L; + + private static final ClippingHelperImpl clippingHelper = new ClippingHelperImpl(); + private static final Vector3f[] nearPlaneVectors = { + new Vector3f(), new Vector3f(), new Vector3f(), new Vector3f() + }; + + // 3*4 augmented matrix, last 4 elements are for swap buffer (because im a good progranmer) + private static final float[] mat = new float[16]; + + // reusing static field to prevent heap pollution + private static final SATTestResult sat = new SATTestResult(); + private static final Vector3f vec1 = new Vector3f(), vec2 = new Vector3f(); + + /** + * Draws mining pipe with given length. This method modifies {@code translation} argument's state. + */ + public static void renderPipe(@Nonnull ICubeRenderer pipeRenderer, int pipeLength, + @Nonnull CCRenderState renderState, @Nonnull Matrix4 translation, + @Nonnull IVertexOperation[] pipeline) { + Textures.PIPE_IN_OVERLAY.renderSided(EnumFacing.DOWN, renderState, translation, pipeline); + for (int i = 0; i < pipeLength; i++) { + translation.translate(0.0, -1.0, 0.0); + pipeRenderer.render(renderState, translation, pipeline, PIPE_CUBOID); + } + } + + /** + * Draw an area preview. + * + * @param box area + * @param pos block position + * @param x X position; generally {@code cameraX + blockX} + * @param y Y position; generally {@code cameraY + blockY} + * @param z Z position; generally {@code cameraZ + blockZ} + */ + public static void renderAreaPreview(@Nonnull AxisAlignedBB box, @Nonnull BlockPos pos, + double x, double y, double z) { + // skull emoji + + // positions + double minX = box.minX + x - pos.getX(), maxX = box.maxX + x - pos.getX(); + double minY = Math.max(0, box.minY) + y - pos.getY(), maxY = box.maxY + y - pos.getY(); + double minZ = box.minZ + z - pos.getZ(), maxZ = box.maxZ + z - pos.getZ(); + + // texture UVs + double texOffset = (System.nanoTime() % TEXTURE_WRAP_INTERVAL_NANOSECONDS) / (double) (TEXTURE_WRAP_INTERVAL_NANOSECONDS); + + double dx = (box.maxX - box.minX); + double dy = (box.maxY - Math.max(0, box.minY)); + double dz = (box.maxZ - box.minZ); + + double uMax = texOffset + box.maxX - Math.floor(box.maxX); + double uMax2 = uMax - dy; + double uMin = uMax - dx; + double uMin2 = uMin - dy; + double vMax = texOffset + box.maxZ - Math.floor(box.maxZ); + double vMax2 = vMax - dy; + double vMin = vMax - dz; + double vMin2 = vMin - dy; + double vMin3 = vMin2 + dz; + + Entity renderViewEntity = Minecraft.getMinecraft().getRenderViewEntity(); + double eyeHeight = renderViewEntity != null ? renderViewEntity.getEyeHeight() : 0; // why :((((( + // the check is not perfect, there's a small but noticeable area around outer parts where the algo + // doesn't detect the box clipping through the camera + // but I have already spent significant portion of my live implementing this alone so I'll just eat my loss and + // inflate the box a bit to compensate + final double expand = 3 / 16.0; + boolean isBoxClippingThroughCamera = isBoxClippingThroughCamera( + minX - expand, maxX + expand, + minY - eyeHeight * 2 - expand, maxY - eyeHeight * 2 + expand, + minZ - expand, maxZ + expand); + + GlStateManager.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_REPEAT); + GlStateManager.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_REPEAT); + Minecraft.getMinecraft().getTextureManager().bindTexture(MINER_AREA_PREVIEW_TEXTURE); + GlStateManager.disableLighting(); + GlStateManager.enableBlend(); + GlStateManager.tryBlendFuncSeparate(SourceFactor.SRC_ALPHA, DestFactor.ONE_MINUS_SRC_ALPHA, SourceFactor.ONE, DestFactor.ZERO); + + Tessellator tessellator = Tessellator.getInstance(); + BufferBuilder buffer = tessellator.getBuffer(); + + for (boolean looped = false; ; looped = true) { + int alpha = looped ? 70 : 200; + + if (looped) { + GlStateManager.disableDepth(); + // only draw inner parts of the border when camera is inside it + if (isBoxClippingThroughCamera) { + GlStateManager.disableCull(); + } + } + + buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_LMAP_COLOR); + + // UP + v(buffer, minX, maxY, maxZ, uMin, vMax, alpha); + v(buffer, maxX, maxY, maxZ, uMax, vMax, alpha); + v(buffer, maxX, maxY, minZ, uMax, vMin, alpha); + v(buffer, minX, maxY, minZ, uMin, vMin, alpha); + + // NORTH + v(buffer, minX, maxY, minZ, uMin, vMin, alpha); + v(buffer, maxX, maxY, minZ, uMax, vMin, alpha); + v(buffer, maxX, minY, minZ, uMax, vMin2, alpha); + v(buffer, minX, minY, minZ, uMin, vMin2, alpha); + + // SOUTH + v(buffer, minX, minY, maxZ, uMin, vMax2, alpha); + v(buffer, maxX, minY, maxZ, uMax, vMax2, alpha); + v(buffer, maxX, maxY, maxZ, uMax, vMax, alpha); + v(buffer, minX, maxY, maxZ, uMin, vMax, alpha); + + // WEST + v(buffer, minX, minY, maxZ, uMin2, vMax, alpha); + v(buffer, minX, maxY, maxZ, uMin, vMax, alpha); + v(buffer, minX, maxY, minZ, uMin, vMin, alpha); + v(buffer, minX, minY, minZ, uMin2, vMin, alpha); + + // EAST + v(buffer, maxX, minY, minZ, uMax2, vMin, alpha); + v(buffer, maxX, maxY, minZ, uMax, vMin, alpha); + v(buffer, maxX, maxY, maxZ, uMax, vMax, alpha); + v(buffer, maxX, minY, maxZ, uMax2, vMax, alpha); + + // DOWN + v(buffer, minX, minY, minZ, uMin, vMin2, alpha); + v(buffer, maxX, minY, minZ, uMax, vMin2, alpha); + v(buffer, maxX, minY, maxZ, uMax, vMin3, alpha); + v(buffer, minX, minY, maxZ, uMin, vMin3, alpha); + + tessellator.draw(); + + if (looped) { + GlStateManager.enableDepth(); + if (isBoxClippingThroughCamera) { + GlStateManager.enableCull(); + } + break; + } + } + + GlStateManager.enableLighting(); + } + + private static void v(BufferBuilder buffer, double x, double y, double z, double u, double v, int alpha) { + buffer.pos(x, y, z).tex(u, v).lightmap(240, 240).color(255, 255, 255, alpha).endVertex(); + } + + /** + * Check if given AABB is clipping through camera. + */ + public static boolean isBoxClippingThroughCamera(double minX, double maxX, + double minY, double maxY, + double minZ, double maxZ) { + clippingHelper.init(); + + // obtain 4 vertices of near plane rectangle + // just halt and return false as a fallback, theoretically possible if view matrix got somehow borked + if (!calculateIntersectingPoint(0, 0, 2)) return false; + if (!calculateIntersectingPoint(1, 1, 2)) return false; + if (!calculateIntersectingPoint(2, 1, 3)) return false; + if (!calculateIntersectingPoint(3, 0, 3)) return false; + + // divide the near plane rectangle to 2 triangles, then do some intersection tests + float minXf = (float) minX, maxXf = (float) maxX, + minYf = (float) minY, maxYf = (float) maxY, + minZf = (float) minZ, maxZf = (float) maxZ; + return intersects(0, 1, 2, minXf, maxXf, minYf, maxYf, minZf, maxZf) || + intersects(0, 2, 3, minXf, maxXf, minYf, maxYf, minZf, maxZf); + } + + /** + * Tries to calculate an intersecting point between 2 specified planes and the near plane. If an intersecting point + * can be derived, {@code true} will be returned and the value will be stored in {@code vectorIndex}-th element of + * {@link #nearPlaneVectors}. If planes have no single intersecting point (either because they don't intersect, or + * have infinitely many solutions), {@code false} will be returned. + */ + @SuppressWarnings("BooleanMethodIsAlwaysInverted") + private static boolean calculateIntersectingPoint(int vectorIndex, int plane1, int plane2) { + System.arraycopy(clippingHelper.frustum[5], 0, mat, 0, 4); // near plane + System.arraycopy(clippingHelper.frustum[plane1], 0, mat, 4, 4); + System.arraycopy(clippingHelper.frustum[plane2], 0, mat, 8, 4); + + // shoutouts to wikipedia and gauss and row-echelon or sth idk + for (int i = 0; i < 3; i++) { + // find the k-th pivot + int maxRow = 0; + float maxValue = -1; + for (int r = i; r < 3; r++) { + float abs = Math.abs(getMatrixValue(i, r)); + if (maxValue < abs) { + maxRow = r; + maxValue = abs; + } + } + + // no pivot in this column, this means the system has no one unique solution + // since we don't care about calculating intersections in a form other than a point, we can just halt here + if (maxValue == 0) return false; + + swapRow(i, maxRow); + // do for all rows below pivot + for (int r = i + 1; r < 3; r++) { + float f = getMatrixValue(i, r) / getMatrixValue(i, i); + // fill with zeros the lower part of pivot column + setMatrixValue(i, r, 0); + for (int c = i + 1; c < 4; c++) { + setMatrixValue(c, r, getMatrixValue(c, r) - getMatrixValue(c, i) * f); + } + } + } + + // back substitution???? i guess?????? + float z = getMatrixValue(3, 2) / getMatrixValue(2, 2); + float y = (getMatrixValue(3, 1) - z * getMatrixValue(2, 1)) / getMatrixValue(1, 1); + float x = (getMatrixValue(3, 0) - z * getMatrixValue(2, 0) - y * getMatrixValue(1, 0)) / getMatrixValue(0, 0); + + // idk + if (!Float.isFinite(x) || !Float.isFinite(y) || !Float.isFinite(z)) return false; + nearPlaneVectors[vectorIndex].set(x, y, z); + return true; + } + + /** + * Check if a triangle made of {@code p1}, {@code p2}, and {@code p3}-th element of {@link #nearPlaneVectors} + * intersects with given AABB. (Source) + */ + @SuppressWarnings("SameParameterValue") + private static boolean intersects(int p1, int p2, int p3, + float minX, float maxX, + float minY, float maxY, + float minZ, float maxZ) { + // Test the box normals (x-, y- and z-axes) + for (int i = 0; i < 3; i++) { + sat.projectTriangle(p1, p2, p3, i == 0 ? 1 : 0, i == 1 ? 1 : 0, i == 2 ? 1 : 0); + if (sat.max < switch (i) { + case 0 -> minX; + case 1 -> minY; + default -> minZ; + } || sat.min > switch (i) { + case 0 -> maxX; + case 1 -> maxY; + default -> maxZ; + }) return false; + } + + // Test the triangle normal + vec1.sub(nearPlaneVectors[p2], nearPlaneVectors[p1]); + vec2.sub(nearPlaneVectors[p3], nearPlaneVectors[p1]); + vec1.cross(vec1, vec2); + vec1.normalize(); + double triangleOffset = vec1.dot(nearPlaneVectors[p1]); + sat.projectAABB(minX, maxX, minY, maxY, minZ, maxZ, + vec1.x, vec1.y, vec1.z); + if (sat.max < triangleOffset || sat.min > triangleOffset) return false; + + // Test the nine edge cross-products + for (int i = 0; i < 3; i++) { + // The box normals are the same as it's edge tangents + vec1.sub(nearPlaneVectors[(i) % 3], nearPlaneVectors[(i + 1) % 3]); + for (int j = 0; j < 3; j++) { + vec2.set(j == 0 ? 1 : 0, j == 1 ? 1 : 0, j == 2 ? 1 : 0); + vec2.cross(vec1, vec2); + + sat.projectAABB(minX, maxX, minY, maxY, minZ, maxZ, vec2.x, vec2.y, vec2.z); + float boxMin = sat.min, boxMax = sat.max; + sat.projectTriangle(p1, p2, p3, vec2.x, vec2.y, vec2.z); + if (boxMax <= sat.min || boxMin >= sat.max) return false; + } + } + + // No separating axis found. + return true; + } + + private static float getMatrixValue(int col, int row) { + if (col < 0 || col >= 4) throw new IndexOutOfBoundsException("col == " + col); + if (row < 0 || row >= 3) throw new IndexOutOfBoundsException("row == " + row); + return mat[row * 4 + col]; + } + + private static void setMatrixValue(int col, int row, float val) { + if (col < 0 || col >= 4) throw new IndexOutOfBoundsException("col == " + col); + if (row < 0 || row >= 3) throw new IndexOutOfBoundsException("row == " + row); + mat[row * 4 + col] = val; + } + + private static void swapRow(int r1, int r2) { + if (r1 < 0 || r1 >= 3) throw new IndexOutOfBoundsException("r1 == " + r1); + if (r2 < 0 || r2 >= 3) throw new IndexOutOfBoundsException("r2 == " + r2); + if (r1 == r2) return; + System.arraycopy(mat, r1 * 4, mat, 12, 4); + System.arraycopy(mat, r2 * 4, mat, r1 * 4, 4); + System.arraycopy(mat, 12, mat, r2 * 4, 4); + } + + /* for debug + private static String matrixToString() { + StringBuilder stb = new StringBuilder(); + for (int r = 0; r < 3; r++) { + if (r != 0) stb.append('\n'); + for (int c = 0; c < 4; c++) { + if (c != 0) stb.append('\t'); + float v = getMatrixValue(c, r); + if (v >= 0) stb.append(" "); + stb.append(String.format("%.4f", v)); + } + } + return stb.toString(); + } + */ + + private static final class SATTestResult { + + private float min, max; + + void projectTriangle(int p1, int p2, int p3, + float axisX, float axisY, float axisZ) { + this.min = Float.POSITIVE_INFINITY; + this.max = Float.NEGATIVE_INFINITY; + + Vector3f v = nearPlaneVectors[p1]; + project(v.x, v.y, v.z, axisX, axisY, axisZ); + v = nearPlaneVectors[p2]; + project(v.x, v.y, v.z, axisX, axisY, axisZ); + v = nearPlaneVectors[p3]; + project(v.x, v.y, v.z, axisX, axisY, axisZ); + } + + void projectAABB(float minX, float maxX, + float minY, float maxY, + float minZ, float maxZ, + float axisX, float axisY, float axisZ) { + this.min = Float.POSITIVE_INFINITY; + this.max = Float.NEGATIVE_INFINITY; + + for (int i = 0; i <= 0b111; i++) { + project((i & 0b001) != 0 ? maxX : minX, + (i & 0b010) != 0 ? maxY : minY, + (i & 0b100) != 0 ? maxZ : minZ, + axisX, axisY, axisZ); + } + } + + private void project(float x, float y, float z, + float axisX, float axisY, float axisZ) { + float dot = x * axisX + y * axisY + z * axisZ; + if (dot < this.min) this.min = dot; + if (dot > this.max) this.max = dot; + } + } +} diff --git a/src/main/java/gregtech/common/metatileentities/miner/MinerUtil.java b/src/main/java/gregtech/common/metatileentities/miner/MinerUtil.java index 0a8ba5a729f..8f751ec6fc1 100644 --- a/src/main/java/gregtech/common/metatileentities/miner/MinerUtil.java +++ b/src/main/java/gregtech/common/metatileentities/miner/MinerUtil.java @@ -1,25 +1,23 @@ package gregtech.common.metatileentities.miner; -import codechicken.lib.render.CCRenderState; -import codechicken.lib.render.pipeline.IVertexOperation; -import codechicken.lib.vec.Cuboid6; -import codechicken.lib.vec.Matrix4; +import gregtech.api.GTValues; +import gregtech.api.recipes.Recipe; +import gregtech.api.recipes.RecipeMap; +import gregtech.api.unification.OreDictUnifier; +import gregtech.api.unification.ore.OrePrefix; import gregtech.api.util.GTLog; import gregtech.api.util.GTUtility; -import gregtech.client.renderer.ICubeRenderer; -import gregtech.client.renderer.texture.Textures; import gregtech.common.ConfigHolder; import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; import net.minecraft.init.Blocks; -import net.minecraft.util.EnumFacing; -import net.minecraft.util.ResourceLocation; +import net.minecraft.item.ItemStack; import net.minecraft.util.math.AxisAlignedBB; -import net.minecraftforge.fml.relauncher.Side; -import net.minecraftforge.fml.relauncher.SideOnly; import org.apache.commons.lang3.StringUtils; import javax.annotation.Nonnull; +import java.util.Collections; +import java.util.List; import java.util.Objects; public class MinerUtil { @@ -39,9 +37,6 @@ private MinerUtil() {} public static final String DISPLAY_CLICK_REPEAT_DISABLE = "disable_repeat"; public static final AxisAlignedBB EMPTY_AABB = new AxisAlignedBB(0, 0, 0, 0, 0, 0); - public static final ResourceLocation MINER_AREA_PREVIEW_TEXTURE = GTUtility.gregtechId("textures/fx/miner_area_preview.png"); - - private static final Cuboid6 PIPE_CUBOID = new Cuboid6(4 / 16.0, 0.0, 4 / 16.0, 12 / 16.0, 1.0, 12 / 16.0); private static String oreReplacementConfigCache; private static IBlockState oreReplacement; @@ -75,14 +70,30 @@ public static IBlockState getOreReplacement() { } } - @SideOnly(Side.CLIENT) - public static void renderPipe(@Nonnull ICubeRenderer pipeRenderer, int pipeLength, - @Nonnull CCRenderState renderState, @Nonnull Matrix4 translation, - @Nonnull IVertexOperation[] pipeline) { - Textures.PIPE_IN_OVERLAY.renderSided(EnumFacing.DOWN, renderState, translation, pipeline); - for (int i = 0; i < pipeLength; i++) { - translation.translate(0.0, -1.0, 0.0); - pipeRenderer.render(renderState, translation, pipeline, PIPE_CUBOID); + /** + * Applies a fortune hammer to block drops based on a tier value. + * + * @param stack the item stack to check for recipes + * @param drops where the drops are stored to + * @return amount of items inserted to {@code drops} + */ + public static int applyTieredHammerDrops(@Nonnull ItemStack stack, @Nonnull List drops, + int energyTier, @Nonnull RecipeMap blockDropRecipeMap, + int oreMultiplier) { + Recipe recipe = blockDropRecipeMap.findRecipe( + GTValues.V[energyTier], + Collections.singletonList(stack), + Collections.emptyList()); + if (recipe == null || recipe.getOutputs().isEmpty()) return 0; + int c = 0; + for (ItemStack output : recipe.getResultItemOutputs(GTUtility.getTierByVoltage(recipe.getEUt()), energyTier, blockDropRecipeMap)) { + output = output.copy(); + if (oreMultiplier > 0 && OreDictUnifier.getPrefix(output) == OrePrefix.crushed) { + output.grow(output.getCount() * oreMultiplier); + } + drops.add(output); + c++; } + return c; } } diff --git a/src/main/java/gregtech/common/metatileentities/miner/IMiningArea.java b/src/main/java/gregtech/common/metatileentities/miner/MiningArea.java similarity index 93% rename from src/main/java/gregtech/common/metatileentities/miner/IMiningArea.java rename to src/main/java/gregtech/common/metatileentities/miner/MiningArea.java index 8dc8d0c8317..d0e200a20fb 100644 --- a/src/main/java/gregtech/common/metatileentities/miner/IMiningArea.java +++ b/src/main/java/gregtech/common/metatileentities/miner/MiningArea.java @@ -1,81 +1,77 @@ -package gregtech.common.metatileentities.miner; - -import codechicken.lib.render.CCRenderState; -import codechicken.lib.vec.Matrix4; -import gregtech.api.metatileentity.IFastRenderMetaTileEntity; -import gregtech.api.metatileentity.MetaTileEntity; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.network.PacketBuffer; -import net.minecraft.util.math.AxisAlignedBB; -import net.minecraft.util.math.BlockPos.MutableBlockPos; -import net.minecraftforge.fml.relauncher.Side; -import net.minecraftforge.fml.relauncher.SideOnly; - -import javax.annotation.Nonnull; - -/** - * Object representing operation area of {@link MinerLogic}. - */ -public interface IMiningArea { - - /** - * Get current block position for processing. If this method returns {@code true}, {@code mpos} argument should be - * modified to the block position. Return value of {@code false} indicates there aren't any block left to process. - *
- * Calling this method does not affect the state. Use {@link #nextBlock()} for advancing to next block. - * - * @param mpos Mutable block position - * @return {@code true} if {@code mpos} is set to current block position for processing, {@code false} otherwise - */ - boolean getCurrentBlockPos(@Nonnull MutableBlockPos mpos); - - /** - * Move on to next block for processing, if it exists. Does nothing if there aren't any block left to process. - * - * @see #getCurrentBlockPos(MutableBlockPos) - */ - void nextBlock(); - - /** - * Reset the cursor to starting point (i.e. re-start iteration from start) - */ - void reset(); - - @SideOnly(Side.CLIENT) - default void renderMetaTileEntityFast(@Nonnull MetaTileEntity mte, @Nonnull CCRenderState renderState, @Nonnull Matrix4 translation, float partialTicks) {} - - @SideOnly(Side.CLIENT) - default void renderMetaTileEntity(@Nonnull MetaTileEntity mte, double x, double y, double z, float partialTicks) {} - - @Nonnull - AxisAlignedBB getRenderBoundingBox(); - - default boolean shouldRenderInPass(int pass) { - return pass == IFastRenderMetaTileEntity.RENDER_PASS_NORMAL; - } - - default boolean isGlobalRenderer() { - return false; - } - - /** - * Write any persistent data here. - * - * @param data NBT data - */ - void write(@Nonnull NBTTagCompound data); - - /** - * Read any persistent data here. - * - * @param data NBT data - */ - void read(@Nonnull NBTTagCompound data); - - /** - * Write data for area preview. - * - * @param buffer Packet buffer - */ - void writePreviewPacket(@Nonnull PacketBuffer buffer); -} +package gregtech.common.metatileentities.miner; + +import codechicken.lib.render.CCRenderState; +import codechicken.lib.vec.Matrix4; +import gregtech.api.metatileentity.IFastRenderMetaTileEntity; +import gregtech.api.metatileentity.MetaTileEntity; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.network.PacketBuffer; +import net.minecraft.util.math.AxisAlignedBB; +import net.minecraft.util.math.BlockPos.MutableBlockPos; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +import javax.annotation.Nonnull; + +/** + * Object representing operation area of {@link MinerLogic}. + */ +public interface MiningArea { + + /** + * Get current block position for processing. If this method returns {@code true}, {@code mpos} argument should be + * modified to the block position. Return value of {@code false} indicates there aren't any block left to process. + *
+ * Calling this method does not affect the state. Use {@link #nextBlock()} for advancing to next block. + * + * @param mpos Mutable block position + * @return {@code true} if {@code mpos} is set to current block position for processing, {@code false} otherwise + */ + boolean getCurrentBlockPos(@Nonnull MutableBlockPos mpos); + + /** + * Move on to next block for processing, if it exists. Does nothing if there aren't any block left to process. + * + * @see #getCurrentBlockPos(MutableBlockPos) + */ + void nextBlock(); + + /** + * Reset the cursor to starting point (i.e. re-start iteration from start) + */ + void reset(); + + @SideOnly(Side.CLIENT) + default void renderMetaTileEntityFast(@Nonnull MetaTileEntity mte, @Nonnull CCRenderState renderState, @Nonnull Matrix4 translation, float partialTicks) {} + + @SideOnly(Side.CLIENT) + default void renderMetaTileEntity(@Nonnull MetaTileEntity mte, double x, double y, double z, float partialTicks) {} + + @Nonnull + AxisAlignedBB getRenderBoundingBox(); + + default boolean shouldRenderInPass(int pass) { + return pass == IFastRenderMetaTileEntity.RENDER_PASS_NORMAL; + } + + /** + * Write any persistent data here. + * + * @param data NBT data + */ + void write(@Nonnull NBTTagCompound data); + + /** + * Read any persistent data here. + * + * @param data NBT data + */ + void read(@Nonnull NBTTagCompound data); + + /** + * Write data for area preview. + * + * @param buffer Packet buffer + */ + void writePreviewPacket(@Nonnull PacketBuffer buffer); +} diff --git a/src/main/java/gregtech/common/metatileentities/miner/MultiblockMinerLogic.java b/src/main/java/gregtech/common/metatileentities/miner/MultiblockMinerLogic.java index 484c468c50b..90d6a6bfa66 100644 --- a/src/main/java/gregtech/common/metatileentities/miner/MultiblockMinerLogic.java +++ b/src/main/java/gregtech/common/metatileentities/miner/MultiblockMinerLogic.java @@ -1,16 +1,8 @@ package gregtech.common.metatileentities.miner; -import gregtech.api.GTValues; -import gregtech.api.items.toolitem.ToolHelper; -import gregtech.api.recipes.Recipe; -import gregtech.api.recipes.RecipeMap; -import gregtech.api.unification.OreDictUnifier; -import gregtech.api.unification.ore.OrePrefix; -import gregtech.api.util.GTUtility; import net.minecraft.block.state.IBlockState; -import net.minecraft.item.ItemStack; +import net.minecraft.init.Blocks; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.NonNullList; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos.MutableBlockPos; import net.minecraft.util.math.MathHelper; @@ -20,17 +12,14 @@ import net.minecraft.util.text.TextFormatting; import net.minecraft.util.text.event.ClickEvent; import net.minecraft.util.text.event.HoverEvent; -import net.minecraft.world.World; import net.minecraftforge.common.util.Constants; +import org.jetbrains.annotations.NotNull; import javax.annotation.Nonnull; -import java.util.Collections; import java.util.List; public class MultiblockMinerLogic extends MinerLogic { - private final int fortune; - private final RecipeMap blockDropRecipeMap; private final int maximumChunkDiameter; private final MutableBlockPos mpos = new MutableBlockPos(); @@ -41,37 +30,59 @@ public class MultiblockMinerLogic extends MinerLogic { private boolean chunkMode; private boolean silkTouchMode; - public MultiblockMinerLogic(MetaTileEntityLargeMiner largeMiner, int fortune, int workFrequency, int maximumChunkDiameter, - RecipeMap blockDropRecipeMap) { + // non-negative value to limit Y level + private int yLimit; + + // bool config for repeating the operation after finished + private boolean repeat; + + // flag for disabling ore replacement (if true, ores will be replaced with air instead of whatever block that was specified in the config) + private boolean disableReplacement; + + public MultiblockMinerLogic(@Nonnull MetaTileEntityLargeMiner largeMiner, int workFrequency, int maximumChunkDiameter) { super(largeMiner, workFrequency, maximumChunkDiameter * 16); - this.fortune = fortune; - this.blockDropRecipeMap = blockDropRecipeMap; this.currentChunkDiameter = this.maximumChunkDiameter = maximumChunkDiameter; } @Override - protected void getRegularBlockDrops(@Nonnull NonNullList drops, @Nonnull World world, @Nonnull BlockPos pos, @Nonnull IBlockState state) { - if (this.silkTouchMode) { - drops.add(ToolHelper.getSilkTouchDrop(state)); - } else if (applyTieredHammerDrops(GTUtility.toItem(state), drops) == 0) { // 3X the ore compared to the single blocks - super.getRegularBlockDrops(drops, world, pos, state); // fallback + protected void mine(@NotNull MiningArea miningArea) { + if (this.done && this.repeat) { + miningArea.reset(); + this.done = false; } + super.mine(miningArea); + } + + @NotNull + @Override + protected IBlockState getOreReplacement() { + return this.disableReplacement ? Blocks.AIR.getDefaultState() : super.getOreReplacement(); } @Nonnull @Override - protected IMiningArea createMiningArea() { - if (!this.chunkMode) return super.createMiningArea(); + protected MiningArea createMiningArea() { BlockPos origin = getOrigin(); - int chunkRadius = this.currentChunkDiameter / 2; - int originChunkX = origin.getX() / 16 - chunkRadius; - int originChunkZ = origin.getZ() / 16 - chunkRadius; - return new SimpleMiningArea((originChunkX) * 16, - origin.getY() - 1, - (originChunkZ) * 16, - (originChunkX + currentChunkDiameter) * 16, - getYLimit() > 0 ? origin.getY() - getYLimit() : Integer.MIN_VALUE, - (originChunkZ + currentChunkDiameter) * 16); + if (this.chunkMode) { + int chunkRadius = this.currentChunkDiameter / 2; + int originChunkX = origin.getX() / 16 - chunkRadius; + int originChunkZ = origin.getZ() / 16 - chunkRadius; + return new SimpleMiningArea((originChunkX) * 16, + origin.getY() - 1, + (originChunkZ) * 16, + (originChunkX + currentChunkDiameter) * 16, + getYLimit() > 0 ? origin.getY() - getYLimit() : Integer.MIN_VALUE, + (originChunkZ + currentChunkDiameter) * 16); + } else { + int radius = this.currentDiameter / 2; + int startX = origin.getX() - radius; + int startY = origin.getY() - 1; + int startZ = origin.getZ() - radius; + int endX = startX + this.currentDiameter; + int endY = getYLimit() > 0 ? origin.getY() - getYLimit() : Integer.MIN_VALUE; + int endZ = startZ + this.currentDiameter; + return new SimpleMiningArea(startX, startY, startZ, endX, endY, endZ); + } } @Nonnull @@ -80,10 +91,6 @@ protected BlockPos getOrigin() { return this.mpos.setPos(this.mte.getPos()).move(this.mte.getFrontFacing().getOpposite()); } - public int getFortune() { - return fortune; - } - public int getMaximumChunkDiameter() { return maximumChunkDiameter; } @@ -98,7 +105,7 @@ public void setCurrentChunkDiameter(int currentChunkDiameter) { if (this.currentChunkDiameter != currentChunkDiameter || !this.chunkMode) { this.chunkMode = true; this.currentChunkDiameter = currentChunkDiameter; - this.rebuildScanArea = false; + this.rebuildMiningArea = false; this.mte.markDirty(); } } @@ -108,7 +115,7 @@ public void setCurrentDiameter(int currentDiameter) { if (isWorking()) return; if (this.chunkMode) { this.chunkMode = false; - this.rebuildScanArea = true; + this.rebuildMiningArea = true; this.mte.markDirty(); } super.setCurrentDiameter(currentDiameter); @@ -121,7 +128,7 @@ public boolean isChunkMode() { public void setChunkMode(boolean isChunkMode) { if (isWorking()) return; this.chunkMode = isChunkMode; - this.rebuildScanArea = true; + this.rebuildMiningArea = true; this.mte.markDirty(); } @@ -135,23 +142,55 @@ public void setSilkTouchMode(boolean isSilkTouchMode) { } } + public int getYLimit() { + return yLimit; + } + + public void setYLimit(int yLimit) { + if (yLimit != this.yLimit) { + this.yLimit = yLimit; + this.rebuildMiningArea = true; + this.mte.markDirty(); + if (this.isPreviewEnabled()) { + updatePreview(); + } + } + } + + public boolean isRepeat() { + return repeat; + } + + public void setRepeat(boolean repeat) { + if (this.repeat != repeat) { + this.repeat = repeat; + this.mte.markDirty(); + } + } + @Nonnull @Override public NBTTagCompound writeToNBT(@Nonnull NBTTagCompound data) { - data.setBoolean("isChunkMode", chunkMode); - data.setBoolean("isSilkTouchMode", silkTouchMode); + if (this.chunkMode) data.setBoolean("chunkMode", true); + if (this.silkTouchMode) data.setBoolean("silkTouch", true); data.setInteger("currentChunkDiameter", currentChunkDiameter); + if (this.yLimit > 0) data.setInteger("yLimit", this.yLimit); + if (this.repeat) data.setBoolean("repeat", true); + if (this.disableReplacement) data.setBoolean("disableReplacement", true); return super.writeToNBT(data); } @Override public void readFromNBT(@Nonnull NBTTagCompound data) { - this.chunkMode = data.getBoolean("isChunkMode"); - this.silkTouchMode = data.getBoolean("isSilkTouchMode"); + super.readFromNBT(data); + this.chunkMode = data.getBoolean("chunkMode") || data.getBoolean("isChunkMode"); + this.silkTouchMode = data.getBoolean("silkTouch") || data.getBoolean("isSilkTouchMode"); this.currentChunkDiameter = data.hasKey("currentChunkDiameter", Constants.NBT.TAG_INT) ? MathHelper.clamp(data.getInteger("currentChunkDiameter"), 1, getMaximumChunkDiameter()) : getMaximumChunkDiameter(); - super.readFromNBT(data); + this.yLimit = Math.max(0, data.getInteger("yLimit")); + this.repeat = data.getBoolean("repeat"); + this.disableReplacement = data.getBoolean("disableReplacement"); } public void addDisplayText(@Nonnull List textList) { @@ -185,15 +224,13 @@ public void addDisplayText(@Nonnull List textList) { this.isRepeat() ? "@!" + MinerUtil.DISPLAY_CLICK_REPEAT_DISABLE : "@!" + MinerUtil.DISPLAY_CLICK_REPEAT_ENABLE))))); - if (isDone()) { + if (this.getMiningArea() == null || !getCurrentBlock(this.getMiningArea(), this.mpos2)) { textList.add(new TextComponentTranslation("gregtech.machine.miner.display.done") .setStyle(new Style().setColor(TextFormatting.GREEN))); } else if (isWorking()) { - if (getCurrentBlock(this.mpos2)) { - textList.add(new TextComponentTranslation("gregtech.machine.miner.display.working", - this.mpos2.getX(), this.mpos2.getY(), this.mpos2.getZ()) - .setStyle(new Style().setColor(TextFormatting.GOLD))); - } + textList.add(new TextComponentTranslation("gregtech.machine.miner.display.working", + this.mpos2.getX(), this.mpos2.getY(), this.mpos2.getZ()) + .setStyle(new Style().setColor(TextFormatting.GOLD))); } else if (!isWorkingEnabled()) { textList.add(new TextComponentTranslation("gregtech.multiblock.work_paused")); } @@ -229,30 +266,4 @@ protected ITextComponent yLimitButton(boolean incr) { .setStyle(new Style().setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "@!" + MinerUtil.DISPLAY_CLICK_Y_LIMIT_DECR))); } } - - /** - * Applies a fortune hammer to block drops based on a tier value. - * - * @param stack the item stack to check for recipes - * @param drops where the drops are stored to - * @return amount of items inserted to {@code drops} - */ - protected int applyTieredHammerDrops(@Nonnull ItemStack stack, @Nonnull List drops) { - int energyTier = this.mte.getEnergyTier(); - Recipe recipe = this.blockDropRecipeMap.findRecipe( - GTValues.V[energyTier], - Collections.singletonList(stack), - Collections.emptyList()); - if (recipe == null || recipe.getOutputs().isEmpty()) return 0; - int c = 0; - for (ItemStack output : recipe.getResultItemOutputs(GTUtility.getTierByVoltage(recipe.getEUt()), energyTier, this.blockDropRecipeMap)) { - output = output.copy(); - if (this.fortune > 0 && OreDictUnifier.getPrefix(output) == OrePrefix.crushed) { - output.grow(output.getCount() * this.fortune); - } - drops.add(output); - c++; - } - return c; - } } diff --git a/src/main/java/gregtech/common/metatileentities/miner/SimpleMiningArea.java b/src/main/java/gregtech/common/metatileentities/miner/SimpleMiningArea.java index 5ceab455cc5..bf419cede3e 100644 --- a/src/main/java/gregtech/common/metatileentities/miner/SimpleMiningArea.java +++ b/src/main/java/gregtech/common/metatileentities/miner/SimpleMiningArea.java @@ -1,224 +1,144 @@ -package gregtech.common.metatileentities.miner; - -import gregtech.api.metatileentity.IFastRenderMetaTileEntity; -import gregtech.api.metatileentity.MetaTileEntity; -import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.BufferBuilder; -import net.minecraft.client.renderer.GlStateManager; -import net.minecraft.client.renderer.GlStateManager.DestFactor; -import net.minecraft.client.renderer.GlStateManager.SourceFactor; -import net.minecraft.client.renderer.Tessellator; -import net.minecraft.client.renderer.vertex.DefaultVertexFormats; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.network.PacketBuffer; -import net.minecraft.util.math.AxisAlignedBB; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.BlockPos.MutableBlockPos; -import net.minecraftforge.fml.relauncher.Side; -import net.minecraftforge.fml.relauncher.SideOnly; -import org.lwjgl.opengl.GL11; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - -/** - * Simple implementation of {@link IMiningArea}. Defines cube-shaped mining area with simple iteration logic. - */ -public class SimpleMiningArea implements IMiningArea { - - public final int startX; - public final int startY; - public final int startZ; - public final int endX; - public final int endY; - public final int endZ; - - /** - * Index for current block position. This implementation of {@link IMiningArea} operates by first mapping each block - * in given area to non-negative long indices, then processing it by incrementing internal counter starting from 0. - *
- * The area iterates through X plane first, then Z plane, before moving down one Y block. - */ - private long currentBlock; - - @Nullable - private AxisAlignedBB boundingBoxCache; - - /** - * @param startX Min X position, inclusive - * @param startY Max Y position, inclusive - * @param startZ Min Z position, inclusive - * @param endX Max X position, inclusive - * @param endY Min Y position, inclusive - * @param endZ Max Z position, inclusive - */ - public SimpleMiningArea(int startX, int startY, int startZ, int endX, int endY, int endZ) { - this.startX = startX; - this.startY = startY; - this.startZ = startZ; - this.endX = endX; - this.endY = endY; - this.endZ = endZ; - } - - @Nonnull - public static SimpleMiningArea readPreview(@Nonnull PacketBuffer buffer) { - return new SimpleMiningArea(buffer.readInt(), buffer.readInt(), buffer.readInt(), buffer.readInt(), buffer.readInt(), buffer.readInt()); - } - - @Override - public boolean getCurrentBlockPos(@Nonnull MutableBlockPos mpos) { - long index = this.currentBlock; - if (index < 0) return false; - int sizeX = this.endX - this.startX; - int sizeZ = this.endZ - this.startZ; - if (sizeX <= 0 || sizeZ <= 0) return false; - - int x = this.startX + (int) (index % sizeX); - index /= sizeX; - int z = this.startZ + (int) (index % sizeZ); - int y = this.startY - (int) (index / sizeZ); - - if (y < this.endY) return false; - - mpos.setPos(x, y, z); - return true; - } - - @Override - public void nextBlock() { - this.currentBlock++; - } - - @Override - public void reset() { - this.currentBlock = 0; - } - - @Override - @SideOnly(Side.CLIENT) - public void renderMetaTileEntity(@Nonnull MetaTileEntity mte, double x, double y, double z, float partialTicks) { - // skull emoji - - float texOffset = (System.nanoTime() % 1_000_000_000) / 2_000_000_000f; - // texOffset = (int) (texOffset * 16) * (1 / 16f); - - float t = texOffset * 0.5f; - float ti = (1 - texOffset) * 0.5f; - - BlockPos pos = mte.getPos(); - double minX = this.startX + x - pos.getX() - (1 / 16.0), maxX = this.endX + x - pos.getX() + (1 / 16.0); - double minY = this.endY + y - pos.getY() - (1 / 16.0), maxY = this.startY + y - pos.getY() + (1 / 16.0); - double minZ = this.startZ + z - pos.getZ() - (1 / 16.0), maxZ = this.endZ + z - pos.getZ() + (1 / 16.0); - - double mx = (this.endX - this.startX) * .5f; - double my = (this.startY - this.endY) * .5f; - double mz = (this.endZ - this.startZ) * .5f; - - Minecraft.getMinecraft().getTextureManager().bindTexture(MinerUtil.MINER_AREA_PREVIEW_TEXTURE); - GlStateManager.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_REPEAT); - GlStateManager.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_REPEAT); - GlStateManager.disableLighting(); - GlStateManager.enableBlend(); - GlStateManager.disableCull(); - GlStateManager.tryBlendFuncSeparate(SourceFactor.SRC_ALPHA, DestFactor.ONE_MINUS_SRC_ALPHA, SourceFactor.ONE, DestFactor.ZERO); - GlStateManager.color(1, 1, 1); - - Tessellator tessellator = Tessellator.getInstance(); - BufferBuilder buffer = tessellator.getBuffer(); - buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_LMAP_COLOR); - - // NORTH - v(buffer, minX, maxY, minZ, t, t); - v(buffer, maxX, maxY, minZ, t + mx, t); - v(buffer, maxX, minY, minZ, t + mx, t - my); - v(buffer, minX, minY, minZ, t, t - my); - - // SOUTH - v(buffer, minX, minY, maxZ, t, t); - v(buffer, maxX, minY, maxZ, t + mx, t); - v(buffer, maxX, maxY, maxZ, t + mx, t + my); - v(buffer, minX, maxY, maxZ, t, t + my); - - // DOWN - v(buffer, minX, minY, minZ, t, t); - v(buffer, maxX, minY, minZ, t + mx, t); - v(buffer, maxX, minY, maxZ, t + mx, t + mz); - v(buffer, minX, minY, maxZ, t, t + mz); - - // UP - v(buffer, minX, maxY, maxZ, t, t); - v(buffer, maxX, maxY, maxZ, t + mx, t); - v(buffer, maxX, maxY, minZ, t + mx, t + mz); - v(buffer, minX, maxY, minZ, t, t + mz); - - // WEST - v(buffer, minX, minY, maxZ, t, t); - v(buffer, minX, maxY, maxZ, t + my, t); - v(buffer, minX, maxY, minZ, t + my, t - mz); - v(buffer, minX, minY, minZ, t + my, t - mz); - - // EAST - v(buffer, maxX, minY, minZ, t, t); - v(buffer, maxX, maxY, minZ, t + my, t); - v(buffer, maxX, maxY, maxZ, t + my, t + mz); - v(buffer, maxX, minY, maxZ, t , t + mz); - - tessellator.draw(); - - GlStateManager.enableLighting(); - GlStateManager.enableCull(); - } - - private static void v(BufferBuilder buffer, double x, double y, double z, double u, double v) { - buffer.pos(x, y, z).tex(u, v).lightmap(240, 240).color(255, 255, 255, 255).endVertex(); - } - - @Override - public boolean shouldRenderInPass(int pass) { - return pass == IFastRenderMetaTileEntity.RENDER_PASS_TRANSLUCENT; - } - - @Nonnull - @Override - public AxisAlignedBB getRenderBoundingBox() { - if (this.boundingBoxCache == null) { - return this.boundingBoxCache = new AxisAlignedBB( - startX - (1 / 16.0), endY - (1 / 16.0), startZ - (1 / 16.0), - endX + 1 + (1 / 16.0), startY + 1 + (1 / 16.0), endZ + 1 + (1 / 16.0)); - } - return this.boundingBoxCache; - } - - @Override - public void write(@Nonnull NBTTagCompound data) { - data.setLong("i", this.currentBlock); - } - - @Override - public void read(@Nonnull NBTTagCompound data) { - this.currentBlock = Math.max(0, data.getLong("i")); - } - - @Override - public void writePreviewPacket(@Nonnull PacketBuffer buffer) { - buffer.writeInt(startX); - buffer.writeInt(startY); - buffer.writeInt(startZ); - buffer.writeInt(endX); - buffer.writeInt(endY); - buffer.writeInt(endZ); - } - - @Override - public String toString() { - return "SimpleMiningArea{" + - "startX=" + startX + - ", startY=" + startY + - ", startZ=" + startZ + - ", endX=" + endX + - ", endZ=" + endZ + - ", currentBlock=" + currentBlock + - '}'; - } -} +package gregtech.common.metatileentities.miner; + +import gregtech.api.metatileentity.IFastRenderMetaTileEntity; +import gregtech.api.metatileentity.MetaTileEntity; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.network.PacketBuffer; +import net.minecraft.util.math.AxisAlignedBB; +import net.minecraft.util.math.BlockPos.MutableBlockPos; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** + * Simple implementation of {@link MiningArea}. Defines cube-shaped mining area with simple iteration logic. + */ +public class SimpleMiningArea implements MiningArea { + + private static final double PREVIEW_OFFSET = 1 / 16.0; + + public final int startX; + public final int startY; + public final int startZ; + public final int endX; + public final int endY; + public final int endZ; + + /** + * Index for current block position. This implementation of {@link MiningArea} operates by first mapping each block + * in given area to non-negative long indices, then processing it by incrementing internal counter starting from 0. + *
+ * The area iterates through X plane first, then Z plane, before moving down one Y block. + */ + private long currentBlock; + + @Nullable + private AxisAlignedBB boundingBoxCache; + + /** + * @param startX Min X position, inclusive + * @param startY Max Y position, inclusive + * @param startZ Min Z position, inclusive + * @param endX Max X position, inclusive + * @param endY Min Y position, inclusive + * @param endZ Max Z position, inclusive + */ + public SimpleMiningArea(int startX, int startY, int startZ, int endX, int endY, int endZ) { + this.startX = startX; + this.startY = startY; + this.startZ = startZ; + this.endX = endX; + this.endY = endY; + this.endZ = endZ; + } + + @Nonnull + public static SimpleMiningArea readPreview(@Nonnull PacketBuffer buffer) { + return new SimpleMiningArea(buffer.readInt(), buffer.readInt(), buffer.readInt(), buffer.readInt(), buffer.readInt(), buffer.readInt()); + } + + @Override + public boolean getCurrentBlockPos(@Nonnull MutableBlockPos mpos) { + long index = this.currentBlock; + if (index < 0) return false; + int sizeX = this.endX - this.startX; + int sizeZ = this.endZ - this.startZ; + if (sizeX <= 0 || sizeZ <= 0) return false; + + int x = this.startX + (int) (index % sizeX); + index /= sizeX; + int z = this.startZ + (int) (index % sizeZ); + int y = this.startY - (int) (index / sizeZ); + + if (y < this.endY) return false; + + mpos.setPos(x, y, z); + return true; + } + + @Override + public void nextBlock() { + this.currentBlock++; + } + + @Override + public void reset() { + this.currentBlock = 0; + } + + @Override + @SideOnly(Side.CLIENT) + public void renderMetaTileEntity(@Nonnull MetaTileEntity mte, double x, double y, double z, float partialTicks) { + MinerRenderHelper.renderAreaPreview(this.getRenderBoundingBox(), mte.getPos(), x, y, z); + } + + @Override + public boolean shouldRenderInPass(int pass) { + return pass == IFastRenderMetaTileEntity.RENDER_PASS_TRANSLUCENT; + } + + @Nonnull + @Override + public AxisAlignedBB getRenderBoundingBox() { + if (this.boundingBoxCache == null) { + return this.boundingBoxCache = new AxisAlignedBB( + startX + PREVIEW_OFFSET, endY == Integer.MIN_VALUE ? Double.NEGATIVE_INFINITY : endY + PREVIEW_OFFSET, startZ + PREVIEW_OFFSET, + endX - PREVIEW_OFFSET, startY + 1 - PREVIEW_OFFSET, endZ - PREVIEW_OFFSET); + } + return this.boundingBoxCache; + } + + @Override + public void write(@Nonnull NBTTagCompound data) { + data.setLong("i", this.currentBlock); + } + + @Override + public void read(@Nonnull NBTTagCompound data) { + this.currentBlock = Math.max(0, data.getLong("i")); + } + + @Override + public void writePreviewPacket(@Nonnull PacketBuffer buffer) { + buffer.writeInt(startX); + buffer.writeInt(startY); + buffer.writeInt(startZ); + buffer.writeInt(endX); + buffer.writeInt(endY); + buffer.writeInt(endZ); + } + + @Override + public String toString() { + return "SimpleMiningArea{" + + "startX=" + startX + + ", startY=" + startY + + ", startZ=" + startZ + + ", endX=" + endX + + ", endZ=" + endZ + + ", currentBlock=" + currentBlock + + '}'; + } +} diff --git a/src/main/java/gregtech/common/metatileentities/miner/SteamMiner.java b/src/main/java/gregtech/common/metatileentities/miner/SteamMiner.java index 68a0145aa5a..b2934d97206 100644 --- a/src/main/java/gregtech/common/metatileentities/miner/SteamMiner.java +++ b/src/main/java/gregtech/common/metatileentities/miner/SteamMiner.java @@ -34,8 +34,8 @@ import net.minecraft.util.EnumFacing; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.AxisAlignedBB; +import net.minecraft.util.math.BlockPos; import net.minecraft.util.text.ITextComponent; -import net.minecraft.util.text.Style; import net.minecraft.util.text.TextComponentTranslation; import net.minecraft.util.text.TextFormatting; import net.minecraft.world.World; @@ -46,13 +46,14 @@ import net.minecraftforge.items.IItemHandlerModifiable; import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.tuple.Pair; +import org.jetbrains.annotations.NotNull; import javax.annotation.Nonnull; import javax.annotation.Nullable; import java.util.Collections; import java.util.List; -public class SteamMiner extends MetaTileEntity implements IMiner, IControllable, IVentable, IDataInfoProvider, IFastRenderMetaTileEntity { +public class SteamMiner extends MetaTileEntity implements Miner, IControllable, IVentable, IDataInfoProvider, IFastRenderMetaTileEntity { private boolean needsVenting = false; private boolean ventingStuck = false; @@ -60,15 +61,13 @@ public class SteamMiner extends MetaTileEntity implements IMiner, IControllable, private final int inventorySize; private final int energyPerTick; - private final SteamMinerLogic minerLogic; - - private boolean hasNotEnoughEnergy; + private final MinerLogic minerLogic; public SteamMiner(ResourceLocation metaTileEntityId, int workFrequency, int maximumDiameter) { super(metaTileEntityId); this.inventorySize = 4; this.energyPerTick = 16; - this.minerLogic = new SteamMinerLogic(this, workFrequency, maximumDiameter); + this.minerLogic = new MinerLogic<>(this, workFrequency, maximumDiameter); initializeInventory(); } @@ -94,42 +93,36 @@ protected IItemHandlerModifiable createExportItemHandler() { @Override @SideOnly(Side.CLIENT) public void renderMetaTileEntity(CCRenderState renderState, Matrix4 translation, IVertexOperation[] pipeline) { - ColourMultiplier multiplier = new ColourMultiplier(GTUtility.convertRGBtoOpaqueRGBA_CL(getPaintingColorForRendering())); - IVertexOperation[] coloredPipeline = ArrayUtils.add(pipeline, multiplier); - Textures.STEAM_CASING_BRONZE.render(renderState, translation, coloredPipeline); - for (EnumFacing renderSide : EnumFacing.HORIZONTALS) { - if (renderSide == getFrontFacing()) { - Textures.PIPE_OUT_OVERLAY.renderSided(renderSide, renderState, translation, pipeline); - } else { - Textures.STEAM_MINER_OVERLAY.renderSided(renderSide, renderState, translation, coloredPipeline); - } + IVertexOperation[] colouredPipeline = ArrayUtils.add(pipeline, new ColourMultiplier(GTUtility.convertRGBtoOpaqueRGBA_CL(getPaintingColorForRendering()))); + Textures.STEAM_CASING_BRONZE.render(renderState, translation, colouredPipeline); + Textures.STEAM_MINER_OVERLAY.renderOrientedState(renderState, translation, pipeline, getFrontFacing(), minerLogic.isActive(), minerLogic.isWorkingEnabled()); + if (hasFrontFacing()) { + Textures.PIPE_OUT_OVERLAY.renderSided(getFrontFacing(), renderState, translation, pipeline); } - Textures.STEAM_VENT_OVERLAY.renderSided(EnumFacing.UP, renderState, translation, pipeline); - Textures.PIPE_IN_OVERLAY.renderSided(EnumFacing.DOWN, renderState, translation, pipeline); - MinerUtil.renderPipe(Textures.BRONZE_PLATED_BRICKS, this.minerLogic.getPipeLength(), renderState, translation, pipeline); + MinerRenderHelper.renderPipe(Textures.BRONZE_PLATED_BRICKS, this.minerLogic.getPipeLength(), renderState, translation, pipeline); } @Override public void renderMetaTileEntity(double x, double y, double z, float partialTicks) { - IMiningArea previewArea = this.minerLogic.getPreviewArea(); + MiningArea previewArea = this.minerLogic.getPreviewArea(); if (previewArea != null) previewArea.renderMetaTileEntity(this, x, y, z, partialTicks); } @Override public void renderMetaTileEntityFast(CCRenderState renderState, Matrix4 translation, float partialTicks) { - IMiningArea previewArea = this.minerLogic.getPreviewArea(); + MiningArea previewArea = this.minerLogic.getPreviewArea(); if (previewArea != null) previewArea.renderMetaTileEntityFast(this, renderState, translation, partialTicks); } @Override public AxisAlignedBB getRenderBoundingBox() { - IMiningArea previewArea = this.minerLogic.getPreviewArea(); + MiningArea previewArea = this.minerLogic.getPreviewArea(); return previewArea != null ? previewArea.getRenderBoundingBox() : MinerUtil.EMPTY_AABB; } @Override public boolean shouldRenderInPass(int pass) { - IMiningArea previewArea = this.minerLogic.getPreviewArea(); + MiningArea previewArea = this.minerLogic.getPreviewArea(); return previewArea != null && previewArea.shouldRenderInPass(pass); } @@ -159,32 +152,17 @@ protected ModularUI createUI(EntityPlayer entityPlayer) { } builder.widget( - new ProgressWidget(() -> { - if (!this.minerLogic.isWorking()) return 0; - int workFrequency = this.minerLogic.getWorkFrequency(); - return workFrequency < 2 ? 1 : (getOffsetTimer() % workFrequency) / (double) workFrequency; - }, xStart - 4 - 21, sideWidgetY, 21, 18, + new ProgressWidget(this.minerLogic::getWorkProgress, xStart - 4 - 21, sideWidgetY, 21, 18, GuiTextures.PROGRESS_BAR_MACERATE_STEAM.get(false), ProgressWidget.MoveType.HORIZONTAL) ).widget( new ImageWidget(xStart - 4 - 20, sideWidgetY + 18, 18, 18, GuiTextures.INDICATOR_NO_STEAM.get(false)) - .setPredicate(() -> this.hasNotEnoughEnergy) + .setPredicate(minerLogic::hasNotEnoughEnergy) ).bindPlayerInventory(entityPlayer.inventory, GuiTextures.SLOT_STEAM.get(false), 0); return builder.build(getHolder(), entityPlayer); } - @Override - public void describeMiningResourceStatus(@Nonnull List textList) { - if (this.ventingStuck) { - textList.add(new TextComponentTranslation("gregtech.machine.steam_miner.vent") - .setStyle(new Style().setColor(TextFormatting.RED))); - } else if (!drainMiningResources(true)) { - textList.add(new TextComponentTranslation("gregtech.machine.steam_miner.steam") - .setStyle(new Style().setColor(TextFormatting.RED))); - } - } - @Override public void addInformation(ItemStack stack, @Nullable World player, List tooltip, boolean advanced) { tooltip.add(I18n.format("gregtech.universal.tooltip.uses_per_tick_steam", energyPerTick) @@ -203,12 +181,23 @@ public void addToolUsages(ItemStack stack, @Nullable World world, List t } @Override - public boolean drainMiningResources(boolean simulate) { + public boolean drainMiningResources(@NotNull MinedBlockType minedBlockType, boolean pipeExtended, boolean simulate) { + if (minedBlockType == MinedBlockType.NOTHING) return true; if (this.ventingStuck) return false; FluidStack drained = this.importFluids.drain(energyPerTick, simulate); - boolean result = drained != null && drained.amount >= energyPerTick; - this.hasNotEnoughEnergy = !result; - return result; + return drained != null && drained.amount >= energyPerTick; + } + + @Override + public boolean canOperate() { + if (!isNeedsVenting()) return true; + tryDoVenting(); + return !isVentingStuck(); + } + + @Override + public void onMineOperation(@Nonnull BlockPos pos, boolean isOre, boolean isOrigin) { + setNeedsVenting(true); } @Override diff --git a/src/main/java/gregtech/common/metatileentities/miner/SteamMinerLogic.java b/src/main/java/gregtech/common/metatileentities/miner/SteamMinerLogic.java deleted file mode 100644 index f67444bc682..00000000000 --- a/src/main/java/gregtech/common/metatileentities/miner/SteamMinerLogic.java +++ /dev/null @@ -1,27 +0,0 @@ -package gregtech.common.metatileentities.miner; - -import net.minecraft.util.math.BlockPos; - -import javax.annotation.Nonnull; - -public class SteamMinerLogic extends MinerLogic { - - public SteamMinerLogic(@Nonnull SteamMiner steamMiner, int workFrequency, int maximumDiameter) { - super(steamMiner, workFrequency, maximumDiameter); - } - - @Override - protected boolean canOperate() { - if (mte.isNeedsVenting()) { - mte.tryDoVenting(); - if (mte.isVentingStuck()) return false; - } - - return super.canOperate(); - } - - @Override - protected void onMineOperation(@Nonnull BlockPos pos, boolean isOre, boolean isOrigin) { - mte.setNeedsVenting(true); - } -} diff --git a/src/main/resources/assets/gregtech/lang/en_us.lang b/src/main/resources/assets/gregtech/lang/en_us.lang index f2c705dfde7..79ace6f4ec7 100644 --- a/src/main/resources/assets/gregtech/lang/en_us.lang +++ b/src/main/resources/assets/gregtech/lang/en_us.lang @@ -5062,7 +5062,7 @@ gregtech.universal.tooltip.energy_storage_capacity=§cEnergy Capacity: §f%,d EU gregtech.universal.tooltip.energy_tier_range=§aAllowed Voltage Tiers: §f%s §f- %s gregtech.universal.tooltip.item_storage_capacity=§6Item Slots: §f%,d gregtech.universal.tooltip.item_storage_total=§6Item Capacity: §f%,d items -gregtech.universal.tooltip.item_stored=§dItem Stored: §f%s, %,d items +gregtech.universal.tooltip.item_stored=§dItem Stored: §f%s, %,d itemsa gregtech.universal.tooltip.item_transfer_rate=§bTransfer Rate: §f%,d items/s gregtech.universal.tooltip.item_transfer_rate_stacks=§bTransfer Rate: §f%,d stacks/s gregtech.universal.tooltip.fluid_storage_capacity=§9Fluid Capacity: §f%,d L diff --git a/src/main/resources/assets/gregtech/textures/blocks/machines/miner/overlay_back.png b/src/main/resources/assets/gregtech/textures/blocks/machines/miner/overlay_back.png new file mode 100644 index 0000000000000000000000000000000000000000..f59b9d285945c72ac3c0ca1cdd8f0e9e2dd6e9ca GIT binary patch literal 336 zcmV-W0k8gvP)Px$3Q0skR5*?8k}*rfKoo?(gn*?iR=b78!V$P)TZPeDdj6n#&$=pz`R}8~IUDr70CfDoF*Tf#6LBi!F*KS$WXT1(ru#BofX=X();74UtZx~_?$h@vQvQev&8>pFaY>Nj?v iXS0L<02n*?19$@kIAuz*l^t;a0000Px%Z%IT!R7i>Kmd{HRVI0OkYA=h5$x?@Apz#N}!ICbuv8gLKNDCGDH}o$UboG*l zymYH$2mb~GJJ|>;NF6rI71k~Hu%W?QyyVyp%ZzLXn{fwcVIjK2KBs|s=i&X%`#v8Y z=%~won4OzzwEI!DT4ldn?gF^b{6a6RBSa7C&I5!HD5bcPN>k2Tq`&Xr)LdNmgzDw7 z;G6Dd10j02@#Gm&N|aJu%g$2HTWFfb-pCZaeF7nRLc0kWOh0|e*H=qqRFUDyEI)QX zqG=jZN*u=_784kYFIpQEmKOl1Busvmc2PD=0ofm3s-*IhEIh~qfS&(BjTm4XrKbr+}Rh73Zd;JPPJgM;xLcT*`W z%ffLSJkJZALbHNmjp99%NJzfSdOoa{T2i3vKhDk}w&b%<_42BNXQ-9)!YFSY99&6G$mJ z-rB^rZGh7_4-7DoyMM|9aW#4ezWg{FhJk6C!3a@22<^bn`oVY(T?kUC6l-g1c%H|! zT{`2zV2gj?x+gd_7bzvlWRlg@RXooNh}7XhN3Ha4`ay4>U~goKcsx$b7^Sk62OzQk zzP)~MFrFhGk8>$GL1il+#JO!ANGTb-o}}>RbtnsM^B|*&yn73VVc@!_;R4S3K@$%` z2EHl@6a7y|N~hBt9v(7nmuRdM&#jH@2Y$gYO%uzqf)S$nK_m}S-#(DdX4&4}4t1ms b52E!O_xO3247V`<00000NkvXXu0mjfoa#Dj literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/gregtech/textures/blocks/machines/miner/overlay_back_active.png.mcmeta b/src/main/resources/assets/gregtech/textures/blocks/machines/miner/overlay_back_active.png.mcmeta new file mode 100644 index 00000000000..60af678259b --- /dev/null +++ b/src/main/resources/assets/gregtech/textures/blocks/machines/miner/overlay_back_active.png.mcmeta @@ -0,0 +1,5 @@ +{ + "animation":{ + "frametime":4 + } +} \ No newline at end of file diff --git a/src/main/resources/assets/gregtech/textures/blocks/machines/miner/overlay_back_active_emissive.png b/src/main/resources/assets/gregtech/textures/blocks/machines/miner/overlay_back_active_emissive.png new file mode 100644 index 0000000000000000000000000000000000000000..189f995d104fe07e41f63fbd66864d3178805bf2 GIT binary patch literal 407 zcmV;I0cie-P)Px$QAtEWR7i>KmN8F*KorN{6)&Yt7+4q$8;hU7Z^D8j8*1Wc2W+Co#053d!9f>4 zjx$>aCmkF}pyWbcCn^W;8WK9*f4k$||K0`uKMp`^v{-xK+kl)K@bOc#Zei$}SQY|= zsNwVPf8C^A#JK?{S9j!2tM!J><{UUTq-s2dYF;Jdl*8>E1X;o`u&>ugVVh@&Eu}Fb`BF6c3KtgC^^%^`;ls z$g_~*fz*Kzb+4dNlI5)7ftJ?6MgEy)b54HFfn(sH`++J8qj=Dmba^0k@O6K&E2IqA z*#dqaFQqw>2T7KbM;LrRP?-+qK^I%?4Kxq>+5+1mx$%EaNBIB%002ovPDHLkV1j8e BuGRnm literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/gregtech/textures/blocks/machines/miner/overlay_back_active_emissive.png.mcmeta b/src/main/resources/assets/gregtech/textures/blocks/machines/miner/overlay_back_active_emissive.png.mcmeta new file mode 100644 index 00000000000..60af678259b --- /dev/null +++ b/src/main/resources/assets/gregtech/textures/blocks/machines/miner/overlay_back_active_emissive.png.mcmeta @@ -0,0 +1,5 @@ +{ + "animation":{ + "frametime":4 + } +} \ No newline at end of file diff --git a/src/main/resources/assets/gregtech/textures/blocks/machines/miner/overlay_bottom.png b/src/main/resources/assets/gregtech/textures/blocks/machines/miner/overlay_bottom.png new file mode 100644 index 0000000000000000000000000000000000000000..5bce3b33bfa4b21d707a808e0136d8a3c218fc81 GIT binary patch literal 1969 zcmcgtU1%It6dobQ{7?znfJC9gM5IFR&Yj=g8M8^#-Iy$7ldxH7G!}CA-aETPcIQrJ zX0x04pj29$SA9_{_~cuu=&Phf1q=PbhZdCfML`iku_%addT0MkCHL8h6F)4kekaE_ouz%xVclScxW@HJ_seVPdN3BfL%{u|&(RmzI9}?4l&PBrP2`@-XjbXvLk| z4(RgsLJ@DTV~a>rlj20v<_2msLSnO4^+LOumRfdgK8~klNo+x)^|Uk{I}}&)OJarv zR5TM1U*G+gtRG|uGXvm5R6w`*ftt7?HPvYJJ;@E}kiydG5D=k%`$hT#= z(P$(ZT7m^-S+OijhN`TpfFnS-pmXb|#=GVnLCyYPV2JUCN@W zBvkS6an~cP5k9|X1I?m{rX^lA1;8XwVNo$`-LN$i@Y+GxhUOV@ovnSLmaXb{K)GZH ziqL(*1ltY^YKRBy)=-(szE_sSUK;HTtFnMQ=Ipe+^SMlBDPWFUi}U(1JqJXOo$1wWpwvv z8Lr0~i1)XT17Vok_?KTv*NCI1EMTe_0ZY?0fJ&tlPz(!EgQgrz^{%zWz~v_rRrgwr zSrKkgBT%E17(hi@3P7l1fG9U+q*UF|bw^cFO04^qli`StuXn&;%lw#xrKQlTT}dMkB7aU!asUliF!Ow0q;346>i_;{p#IZcDk6l^5Z+x zLvJ1(>3iY3k8gbQ^YYclp8fFF`P0{?Gx}SHn}cNSz1=APwR!8tEA@}YPMkZ`H-CNi zBwhXLizAIybL`Uhe~zx5yEHL8vh()9(wUnV(wifzM1F2SI*X5f^5|=&Ni zI9NU)=vHdG|hFj literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/gregtech/textures/blocks/machines/miner/overlay_bottom_active.png b/src/main/resources/assets/gregtech/textures/blocks/machines/miner/overlay_bottom_active.png new file mode 100644 index 0000000000000000000000000000000000000000..5bce3b33bfa4b21d707a808e0136d8a3c218fc81 GIT binary patch literal 1969 zcmcgtU1%It6dobQ{7?znfJC9gM5IFR&Yj=g8M8^#-Iy$7ldxH7G!}CA-aETPcIQrJ zX0x04pj29$SA9_{_~cuu=&Phf1q=PbhZdCfML`iku_%addT0MkCHL8h6F)4kekaE_ouz%xVclScxW@HJ_seVPdN3BfL%{u|&(RmzI9}?4l&PBrP2`@-XjbXvLk| z4(RgsLJ@DTV~a>rlj20v<_2msLSnO4^+LOumRfdgK8~klNo+x)^|Uk{I}}&)OJarv zR5TM1U*G+gtRG|uGXvm5R6w`*ftt7?HPvYJJ;@E}kiydG5D=k%`$hT#= z(P$(ZT7m^-S+OijhN`TpfFnS-pmXb|#=GVnLCyYPV2JUCN@W zBvkS6an~cP5k9|X1I?m{rX^lA1;8XwVNo$`-LN$i@Y+GxhUOV@ovnSLmaXb{K)GZH ziqL(*1ltY^YKRBy)=-(szE_sSUK;HTtFnMQ=Ipe+^SMlBDPWFUi}U(1JqJXOo$1wWpwvv z8Lr0~i1)XT17Vok_?KTv*NCI1EMTe_0ZY?0fJ&tlPz(!EgQgrz^{%zWz~v_rRrgwr zSrKkgBT%E17(hi@3P7l1fG9U+q*UF|bw^cFO04^qli`StuXn&;%lw#xrKQlTT}dMkB7aU!asUliF!Ow0q;346>i_;{p#IZcDk6l^5Z+x zLvJ1(>3iY3k8gbQ^YYclp8fFF`P0{?Gx}SHn}cNSz1=APwR!8tEA@}YPMkZ`H-CNi zBwhXLizAIybL`Uhe~zx5yEHL8vh()9(wUnV(wifzM1F2SI*X5f^5|=&Ni zI9NU)=vHdG|hFj literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/gregtech/textures/blocks/machines/miner/overlay_side.png b/src/main/resources/assets/gregtech/textures/blocks/machines/miner/overlay_side.png new file mode 100644 index 0000000000000000000000000000000000000000..f59b9d285945c72ac3c0ca1cdd8f0e9e2dd6e9ca GIT binary patch literal 336 zcmV-W0k8gvP)Px$3Q0skR5*?8k}*rfKoo?(gn*?iR=b78!V$P)TZPeDdj6n#&$=pz`R}8~IUDr70CfDoF*Tf#6LBi!F*KS$WXT1(ru#BofX=X();74UtZx~_?$h@vQvQev&8>pFaY>Nj?v iXS0L<02n*?19$@kIAuz*l^t;a0000Px%Z%IT!R7i>Kmd{HRVI0OkYA=h5$x?@Apz#N}!ICbuv8gLKNDCGDH}o$UboG*l zymYH$2mb~GJJ|>;NF6rI71k~Hu%W?QyyVyp%ZzLXn{fwcVIjK2KBs|s=i&X%`#v8Y z=%~won4OzzwEI!DT4ldn?gF^b{6a6RBSa7C&I5!HD5bcPN>k2Tq`&Xr)LdNmgzDw7 z;G6Dd10j02@#Gm&N|aJu%g$2HTWFfb-pCZaeF7nRLc0kWOh0|e*H=qqRFUDyEI)QX zqG=jZN*u=_784kYFIpQEmKOl1Busvmc2PD=0ofm3s-*IhEIh~qfS&(BjTm4XrKbr+}Rh73Zd;JPPJgM;xLcT*`W z%ffLSJkJZALbHNmjp99%NJzfSdOoa{T2i3vKhDk}w&b%<_42BNXQ-9)!YFSY99&6G$mJ z-rB^rZGh7_4-7DoyMM|9aW#4ezWg{FhJk6C!3a@22<^bn`oVY(T?kUC6l-g1c%H|! zT{`2zV2gj?x+gd_7bzvlWRlg@RXooNh}7XhN3Ha4`ay4>U~goKcsx$b7^Sk62OzQk zzP)~MFrFhGk8>$GL1il+#JO!ANGTb-o}}>RbtnsM^B|*&yn73VVc@!_;R4S3K@$%` z2EHl@6a7y|N~hBt9v(7nmuRdM&#jH@2Y$gYO%uzqf)S$nK_m}S-#(DdX4&4}4t1ms b52E!O_xO3247V`<00000NkvXXu0mjfoa#Dj literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/gregtech/textures/blocks/machines/miner/overlay_side_active.png.mcmeta b/src/main/resources/assets/gregtech/textures/blocks/machines/miner/overlay_side_active.png.mcmeta new file mode 100644 index 00000000000..60af678259b --- /dev/null +++ b/src/main/resources/assets/gregtech/textures/blocks/machines/miner/overlay_side_active.png.mcmeta @@ -0,0 +1,5 @@ +{ + "animation":{ + "frametime":4 + } +} \ No newline at end of file diff --git a/src/main/resources/assets/gregtech/textures/blocks/machines/miner/overlay_side_active_emissive.png b/src/main/resources/assets/gregtech/textures/blocks/machines/miner/overlay_side_active_emissive.png new file mode 100644 index 0000000000000000000000000000000000000000..189f995d104fe07e41f63fbd66864d3178805bf2 GIT binary patch literal 407 zcmV;I0cie-P)Px$QAtEWR7i>KmN8F*KorN{6)&Yt7+4q$8;hU7Z^D8j8*1Wc2W+Co#053d!9f>4 zjx$>aCmkF}pyWbcCn^W;8WK9*f4k$||K0`uKMp`^v{-xK+kl)K@bOc#Zei$}SQY|= zsNwVPf8C^A#JK?{S9j!2tM!J><{UUTq-s2dYF;Jdl*8>E1X;o`u&>ugVVh@&Eu}Fb`BF6c3KtgC^^%^`;ls z$g_~*fz*Kzb+4dNlI5)7ftJ?6MgEy)b54HFfn(sH`++J8qj=Dmba^0k@O6K&E2IqA z*#dqaFQqw>2T7KbM;LrRP?-+qK^I%?4Kxq>+5+1mx$%EaNBIB%002ovPDHLkV1j8e BuGRnm literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/gregtech/textures/blocks/machines/miner/overlay_side_active_emissive.png.mcmeta b/src/main/resources/assets/gregtech/textures/blocks/machines/miner/overlay_side_active_emissive.png.mcmeta new file mode 100644 index 00000000000..60af678259b --- /dev/null +++ b/src/main/resources/assets/gregtech/textures/blocks/machines/miner/overlay_side_active_emissive.png.mcmeta @@ -0,0 +1,5 @@ +{ + "animation":{ + "frametime":4 + } +} \ No newline at end of file diff --git a/src/main/resources/assets/gregtech/textures/blocks/machines/miner/overlay_top.png b/src/main/resources/assets/gregtech/textures/blocks/machines/miner/overlay_top.png new file mode 100644 index 0000000000000000000000000000000000000000..2d111eebad673ed8aa0a1a136f6692e4c101ebe6 GIT binary patch literal 182 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`wVp1HAr-f-PCm$aK!L|~vm3vk z;!(jE?b*x!w#GXNB)?p0YZKxVw`j$TnR^`fY2WZNJg@Ay_N(8Uz0%hbJP#zOoZ8tt zanfGX*<1k=Jy%toHLS{Dm;J9$Y}h^6Y_ilSc= hCOr80Fh1fb!{eyFqt#2EO$9oH!PC{xWt~$(698pGN1^}# literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/gregtech/textures/blocks/machines/miner/overlay_top_active.png b/src/main/resources/assets/gregtech/textures/blocks/machines/miner/overlay_top_active.png new file mode 100644 index 0000000000000000000000000000000000000000..dde5384b499bad0372cf4cf78c81299bd2771364 GIT binary patch literal 126 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`jKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCij$3p^r=85sBugD~Uq{1qucL19l9#}EtuWC_;A2_ijA1_=p3jRFje%Ux=c Pfzk|~u6{1-oD!MPx#1ZP1_K>z@;j|==^1poj532;bRa{vGi!vFvd!vV){sAK>D1nEgcK~z{r?N(h( zTV)u2`bSGkp_Z-)0b&?q44IM?28Fqws)0=b6XVS;(5M&2#F!XwOiaeSP%peN@y5h# z#+${&Xf#Z>GL5>3MMsrvFrx$36Wfu zw~D=w92V^dn@WDl1nxz0Jl?2jnG)h(b(lo0J`MG*8VFiF)D;n=-o~B(2QwC^x}8YA zbGThRuW7;S%~zqX*JDZF2knOwnB3cn;AR@1JAUC_sC)-fa{A2&JH;;&Muavt;lRUq zz!bvsmNSUGG>TFh{=R>M6el?L!hr#peuf?xfUVD zZX=aQ!0YuUGbwxlgxBb&ADYn<+{*EpAz(cPU< zH0WYD6WE6@LpppAnL#|D!O_Nb?srDu9%J9no>+A-sag6$ww4N(uX;- z;0olZj4(VroTvAb-Q#R4%4Y!5O@%1h!i8gY7M#}x5=dYWLl2!FWTLAOTmd3cCM2Zb zyf%=MNh=U&Hl)}JQ8d-u6CjXYq5!2F!FbY~br+#*f&GHt zYpYJLAJ@jbKBdl^br+#zYfoEyMPgziQ{qFSw08qPl_VC{!KLB$`~?yc)%VF!V>BX> zhy$uh#6l^2zfz0&ejWRi3ps+TNK%H>i07t)X#%2kVrC-ObE{R1;$%XKV=1lx=^>Id zFF$5x!h&f7iQb8!-}=VIc=Cnof8s@tC!fa+@j!GHN97*0gr?z|Yr?`G%~*0bLFf7% zPw6A*kcSaaGYysp*8wRr5?7&4J(D=3Qb=f!RyS8?xY*67RY9 z3Am^4(e@8_vLOfk0Z(dT}L2ij71U=_ZmsVo<0g0g?^7Ge|Q^Mv*y#B71&M0{913 W!4%2V^YPRG0000EX>4Tx04R}tkv&MmKorOSrk09S9PA(>lA$_T5EXH>RVYG*P%E_RU~=gfG-*gu zTpR`0f`cE6RR5Z zOeYg!Hn%E@2W*KowO2Ie2?kSJrF2-y5=lvOdYTjaWkw`qp4AUmwAfDN@ z4bJ<-5mu5_;&bA0lO9O?$aTfzH_k<_QpZ2CnqBzuEw1KS{5* zwdfJhzYSbmw>4!CxZD8-pA6ZQT`53IC=`JAGy0|+FmMa>u6c87o#XTY$k41(H^9Lm zFjl16>pp$=bk6PHoYwq)0Qiw|c6|;CIRF3v24YJ`L;yMfIsiKTBBHDS000SaNLh0L z04^f{04^f|c%?sf00007bV*G`2jvA602(w5Utvc8000?uMObu0Z*6U5Zgc=ca%Ew3 zWn>_CX>@2HM@dakSAh-}0001dNkl`>LEyrYq00000 LNkvXXu0mjf+yfJ4 diff --git a/src/main/resources/assets/gregtech/textures/blocks/overlay/machine/overlay_steam_miner.png b/src/main/resources/assets/gregtech/textures/blocks/overlay/machine/overlay_steam_miner.png deleted file mode 100644 index 92452781ee4ff011047f0ead0b0e7abff8a1662d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 673 zcmV;S0$%-zP)EX>4Tx04R}tkv&MmKorOSrk09S9PA(>lA$_T5EXH>RVYG*P%E_RU~=gfG-*gu zTpR`0f`cE6RR5Z zOeYg!Hn%E@2W*KowO2Ie2?kSJrF2-y5=lvOdYTjaWkw`qp4AUmwAfDN@ z4bJ<-5mu5_;&bA0lO9O?$aTfzH_k<_QpZ2CnqBzuEw1KS{5* zwdfJhzYSbmw>4!CxZD8-pA6ZQT`53IC=`JAGy0|+FmMa>u6c87o#XTY$k41(H^9Lm zFjl16>pp$=bk6PHoYwq)0Qiw|c6|;CIRF3v24YJ`L;yMfIsiKTBBHDS000SaNLh0L z04^f{04^f|c%?sf00007bV*G`2jvA600$`NGEo!&000?uMObu0Z*6U5Zgc=ca%Ew3 zWn>_CX>@2HM@dakSAh-}0001ZNkliS3=9k`xD=!> z`2}asjA6rR5DOvAFn)+Qgzf5zY8VqX17^msVc5FnC3Y7u;qxakhTt_|_ilvKae0pk zpJrkLk%^FISfJrDgozl<_`-#W63sZhfK4+|35gVqg9iWrrJN_44Z5+Z00000NkvXX Hu0mjf?JyFq diff --git a/src/main/resources/assets/gregtech/textures/fx/miner_area_preview.png b/src/main/resources/assets/gregtech/textures/fx/miner_area_preview.png index 2cf00a0e0ca151a497bee1d6a4f040a7b24405d0..516a443461c442066eeadc63abf12b4600380646 100644 GIT binary patch literal 202 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`jKx9jP7LeL$-D$|T0C7GLo9mN zUf#&tY#`up@pxybhB1?ADBFn^o(EmC1cQuvE<31js3;wKd)+#=a9z>4WefK{Zj_$) zVs@U-v+rx&IoqnFCoWqU`-}ZpR)x$_YvFs>DmyzXrAS%PihW0^P&l>FVdQ&MBb@05rQz A@c;k- literal 273 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=fdz$r9IylHmNblJdl&R0hYC{G?O` z&)mfH)S%SFl*+=BsWw1Gn>}3|Ln>}1{rUgj{_xwm+xGGB@Jw`A!+m6WW5v!@zaO6E z32^YPT-LZnh9%;HYGZ|QfUwU!@!2+Zhdr;JZ}AqIp0?oi$0)y5b;qKubEXNdo+ Date: Mon, 6 Nov 2023 00:30:09 +0900 Subject: [PATCH 04/27] Actually small this time --- .../miner/MetaTileEntityLargeMiner.java | 218 ++++++++++++++---- .../miner/MetaTileEntityMiner.java | 57 +++-- .../metatileentities/miner/MinerLogic.java | 29 --- .../metatileentities/miner/MinerUtil.java | 4 + .../miner/MultiblockMinerLogic.java | 110 ++------- .../metatileentities/miner/SteamMiner.java | 3 +- .../resources/assets/gregtech/lang/en_us.lang | 21 +- 7 files changed, 235 insertions(+), 207 deletions(-) diff --git a/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityLargeMiner.java b/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityLargeMiner.java index d9fc3506cde..eb8460d6d12 100644 --- a/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityLargeMiner.java +++ b/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityLargeMiner.java @@ -1,6 +1,5 @@ package gregtech.common.metatileentities.miner; -import codechicken.lib.raytracer.CuboidRayTraceResult; import codechicken.lib.render.CCRenderState; import codechicken.lib.render.pipeline.IVertexOperation; import codechicken.lib.vec.Matrix4; @@ -33,25 +32,27 @@ import gregtech.core.sound.GTSoundEvents; import net.minecraft.block.state.IBlockState; import net.minecraft.client.resources.I18n; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.PacketBuffer; -import net.minecraft.util.*; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.NonNullList; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.SoundEvent; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; -import net.minecraft.util.text.ITextComponent; -import net.minecraft.util.text.Style; -import net.minecraft.util.text.TextComponentTranslation; -import net.minecraft.util.text.TextFormatting; +import net.minecraft.util.math.BlockPos.MutableBlockPos; +import net.minecraft.util.text.*; +import net.minecraft.util.text.event.ClickEvent; +import net.minecraft.util.text.event.HoverEvent; import net.minecraft.world.World; import net.minecraftforge.common.capabilities.Capability; +import net.minecraftforge.common.util.Constants; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; import net.minecraftforge.items.IItemHandlerModifiable; import net.minecraftforge.items.ItemStackHandler; -import org.jetbrains.annotations.NotNull; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -75,6 +76,12 @@ public class MetaTileEntityLargeMiner extends MultiblockWithDisplayBase implemen protected IMultipleTankHandler inputFluidInventory; protected IItemHandlerModifiable outputInventory; + // last mined ore block + protected final MutableBlockPos lastMinedOre = new MutableBlockPos(); + protected boolean hasLastMinedOre; + // number of ores processed so far + protected int minedOreCount; + public MetaTileEntityLargeMiner(ResourceLocation metaTileEntityId, int tier, int speed, int maxChunkDiameter, int oreMultiplier, int drillingFluidConsumePerTick, @Nonnull LargeMinerType type) { super(metaTileEntityId); @@ -115,7 +122,7 @@ public int getEnergyTier() { } @Override - public boolean drainMiningResources(@NotNull MinedBlockType minedBlockType, boolean pipeExtended, boolean simulate) { + public boolean drainMiningResources(@Nonnull MinedBlockType minedBlockType, boolean pipeExtended, boolean simulate) { if (minedBlockType == MinedBlockType.NOTHING) return true; if (!drainEnergy(true) || !drainFluid(true)) return false; if (!simulate) { @@ -154,6 +161,15 @@ public void getRegularBlockDrops(@Nonnull NonNullList drops, @Nonnull } } + @Override + public void onMineOperation(@Nonnull BlockPos pos, boolean isOre, boolean isOrigin) { + if (isOre) { + this.lastMinedOre.setPos(pos); + this.hasLastMinedOre = true; + this.minedOreCount++; + } + } + @Override @SideOnly(Side.CLIENT) public void renderMetaTileEntity(CCRenderState renderState, Matrix4 translation, IVertexOperation[] pipeline) { @@ -247,15 +263,116 @@ public void addToolUsages(ItemStack stack, @Nullable World world, List t protected void addDisplayText(List textList) { super.addDisplayText(textList); - if (this.isStructureFormed()) { - if (energyContainer != null && energyContainer.getEnergyCapacity() > 0) { - int energyContainer = getEnergyTier(); - long maxVoltage = GTValues.V[energyContainer]; - String voltageName = GTValues.VNF[energyContainer]; - textList.add(new TextComponentTranslation("gregtech.multiblock.max_energy_per_tick", maxVoltage, voltageName)); - } - this.minerLogic.addDisplayText(textList); + if (!this.isStructureFormed()) return; + + if (energyContainer != null && energyContainer.getEnergyCapacity() > 0) { + int energyContainer = getEnergyTier(); + long maxVoltage = GTValues.V[energyContainer]; + String voltageName = GTValues.VNF[energyContainer]; + textList.add(new TextComponentTranslation("gregtech.multiblock.max_energy_per_tick", maxVoltage, voltageName)); + } + + ITextComponent areaText; + int area, maxArea; + if (this.minerLogic.isChunkMode()) { + area = this.minerLogic.getCurrentChunkDiameter(); + maxArea = this.minerLogic.getMaximumChunkDiameter(); + areaText = new TextComponentTranslation("gregtech.machine.miner.display.working_area.chunks", area, area); + } else { + area = this.minerLogic.getCurrentDiameter(); + maxArea = this.minerLogic.getMaximumDiameter(); + areaText = new TextComponentTranslation("gregtech.machine.miner.display.working_area", area, area); + } + if (!this.minerLogic.isWorking()) { + areaText.appendText(" ").appendSibling(incrButton(area, maxArea, MinerUtil.DISPLAY_CLICK_AREA_INCR)) + .appendText(" ").appendSibling(decrButton(area, 1, MinerUtil.DISPLAY_CLICK_AREA_DECR)); + } + textList.add(areaText.appendText(" ").appendSibling(previewAreaButton(this.minerLogic.isPreviewEnabled()))); + + int yLimit = this.minerLogic.getYLimit(); + ITextComponent value; + ITextComponent hoverText; + if (yLimit > 0) { + value = new TextComponentString(String.format("%,d", yLimit)); + hoverText = new TextComponentTranslation("gregtech.machine.miner.display.y_limit.value_hover_tooltip", value); + } else { + value = new TextComponentTranslation("gregtech.machine.miner.display.y_limit.no_value"); + hoverText = new TextComponentTranslation("gregtech.machine.miner.display.y_limit.value_hover_tooltip.no_value"); } + if (!this.minerLogic.isWorking()) { + value = new TextComponentString("") + .appendSibling(incrButton(yLimit, Integer.MAX_VALUE, MinerUtil.DISPLAY_CLICK_Y_LIMIT_INCR)) + .appendText(" ").appendSibling(decrButton(yLimit, 0, MinerUtil.DISPLAY_CLICK_Y_LIMIT_DECR)) + .appendText(" ").appendSibling(value); + } + textList.add(new TextComponentTranslation("gregtech.machine.miner.display.y_limit", value) + .setStyle(new Style().setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverText)))); + + boolean currentValue = this.minerLogic.isRepeat(); + textList.add(new TextComponentTranslation("gregtech.machine.miner.display.repeat", + this.minerLogic.isWorking() ? + new TextComponentTranslation(this.minerLogic.isRepeat() ? + "gregtech.machine.miner.display.enabled" : + "gregtech.machine.miner.display.disabled") : + new TextComponentTranslation(currentValue ? + "gregtech.machine.miner.display.toggle.enabled" : + "gregtech.machine.miner.display.toggle.disabled") + .setStyle(button(currentValue ? MinerUtil.DISPLAY_CLICK_REPEAT_DISABLE : MinerUtil.DISPLAY_CLICK_REPEAT_ENABLE)))); + + ITextComponent replaceOreText = new TextComponentTranslation(this.minerLogic.getOreReplacement().getBlock().getTranslationKey()+".name"); + if (!this.minerLogic.isWorking()) { + replaceOreText = new TextComponentString("[") + .appendSibling(replaceOreText.setStyle(new Style().setColor(TextFormatting.AQUA))) + .appendText("]").setStyle(button(this.minerLogic.isReplaceOreWithAir() ? + MinerUtil.DISPLAY_CLICK_REPLACE_ORE_DISABLE : MinerUtil.DISPLAY_CLICK_REPLACE_ORE_ENABLE)); + } + + textList.add(new TextComponentTranslation("gregtech.machine.miner.display.replace_ore", replaceOreText)); + + MutableBlockPos mpos = new MutableBlockPos(); + if (this.minerLogic.getMiningArea() == null || !this.minerLogic.getCurrentBlock(this.minerLogic.getMiningArea(), mpos)) { + textList.add(new TextComponentTranslation("gregtech.machine.miner.display.done") + .setStyle(new Style().setColor(TextFormatting.GREEN))); + } else if (this.minerLogic.isWorking()) { + textList.add(new TextComponentTranslation("gregtech.machine.miner.display.working", + mpos.getX(), mpos.getY(), mpos.getZ()) + .setStyle(new Style().setColor(TextFormatting.GOLD))); + } else if (!isWorkingEnabled()) { + textList.add(new TextComponentTranslation("gregtech.multiblock.work_paused")); + } + + textList.add(new TextComponentTranslation("gregtech.machine.miner.display.stats.total_mined", this.minedOreCount)); + if (this.hasLastMinedOre) { + textList.add(new TextComponentTranslation("gregtech.machine.miner.display.stats.last_mined", + this.lastMinedOre.getX(), this.lastMinedOre.getY(), this.lastMinedOre.getZ())); + } + } + + @Nonnull + protected static ITextComponent previewAreaButton(boolean previewEnabled) { + return new TextComponentTranslation(previewEnabled ? + "gregtech.machine.miner.display.working_area.hide_preview" : + "gregtech.machine.miner.display.working_area.preview") + .setStyle(button(previewEnabled ? MinerUtil.DISPLAY_CLICK_AREA_PREVIEW_HIDE : MinerUtil.DISPLAY_CLICK_AREA_PREVIEW)); + } + + @Nonnull + protected static ITextComponent incrButton(int currentValue, int maxValue, @Nonnull String event) { + return currentValue >= maxValue ? + new TextComponentTranslation("gregtech.machine.miner.display.incr.disabled") : + new TextComponentTranslation("gregtech.machine.miner.display.incr").setStyle(button(event)); + } + + @Nonnull + protected static ITextComponent decrButton(int currentValue, int minValue, @Nonnull String event) { + return currentValue <= minValue ? + new TextComponentTranslation("gregtech.machine.miner.display.decr.disabled") : + new TextComponentTranslation("gregtech.machine.miner.display.decr").setStyle(button(event)); + } + + @Nonnull + protected static Style button(@Nonnull String event) { + return new Style().setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "@!" + event)); } @Override @@ -263,6 +380,22 @@ protected void handleDisplayClick(String componentData, Widget.ClickData clickDa switch (componentData) { case MinerUtil.DISPLAY_CLICK_AREA_PREVIEW -> this.minerLogic.setPreviewEnabled(true); case MinerUtil.DISPLAY_CLICK_AREA_PREVIEW_HIDE -> this.minerLogic.setPreviewEnabled(false); + case MinerUtil.DISPLAY_CLICK_AREA_DECR -> { + int diff = clickData.isShiftClick ? 5 : 1; + if (this.minerLogic.isChunkMode()) { + this.minerLogic.setCurrentChunkDiameter(this.minerLogic.getCurrentChunkDiameter() - diff); + } else { + this.minerLogic.setCurrentDiameter(this.minerLogic.getCurrentDiameter() - diff); + } + } + case MinerUtil.DISPLAY_CLICK_AREA_INCR -> { + int diff = clickData.isShiftClick ? 5 : 1; + if (this.minerLogic.isChunkMode()) { + this.minerLogic.setCurrentChunkDiameter(this.minerLogic.getCurrentChunkDiameter() + diff); + } else { + this.minerLogic.setCurrentDiameter(this.minerLogic.getCurrentDiameter() + diff); + } + } case MinerUtil.DISPLAY_CLICK_Y_LIMIT_DECR -> this.minerLogic.setYLimit(Math.max(0, this.minerLogic.getYLimit() - (clickData.isShiftClick ? 5 : 1))); case MinerUtil.DISPLAY_CLICK_Y_LIMIT_INCR -> { @@ -272,6 +405,8 @@ protected void handleDisplayClick(String componentData, Widget.ClickData clickDa } case MinerUtil.DISPLAY_CLICK_REPEAT_ENABLE -> this.minerLogic.setRepeat(true); case MinerUtil.DISPLAY_CLICK_REPEAT_DISABLE -> this.minerLogic.setRepeat(false); + case MinerUtil.DISPLAY_CLICK_REPLACE_ORE_ENABLE -> this.minerLogic.setReplaceOreWithAir(true); + case MinerUtil.DISPLAY_CLICK_REPLACE_ORE_DISABLE -> this.minerLogic.setReplaceOreWithAir(false); } } @@ -297,13 +432,33 @@ protected void addWarningText(List textList) { @Override public NBTTagCompound writeToNBT(NBTTagCompound data) { super.writeToNBT(data); - return this.minerLogic.writeToNBT(data); + this.minerLogic.writeToNBT(data); + + if (this.hasLastMinedOre) { + data.setInteger("lastMinedOreX", this.lastMinedOre.getX()); + data.setInteger("lastMinedOreY", this.lastMinedOre.getY()); + data.setInteger("lastMinedOreZ", this.lastMinedOre.getZ()); + } + + data.setInteger("minedOreCount", this.minedOreCount); + + return data; } @Override public void readFromNBT(NBTTagCompound data) { super.readFromNBT(data); this.minerLogic.readFromNBT(data); + if (data.hasKey("lastMinedOreX", Constants.NBT.TAG_INT)) { + this.lastMinedOre.setPos(data.getInteger("lastMinedOreX"), + data.getInteger("lastMinedOreY"), + data.getInteger("lastMinedOreZ")); + this.hasLastMinedOre = true; + } else { + this.hasLastMinedOre = false; + } + + this.minedOreCount = Math.max(0, data.getInteger("minedOreCount")); } @Override @@ -357,33 +512,6 @@ protected Widget getFlexButton(int x, int y, int width, int height) { }); } - @Override - public boolean onScrewdriverClick(EntityPlayer player, EnumHand hand, EnumFacing facing, CuboidRayTraceResult hitResult) { - if (getWorld().isRemote || !this.isStructureFormed()) { - return true; - } - - if (!this.isActive()) { - if (this.minerLogic.isChunkMode()) { - int currentChunkDiameter = this.minerLogic.getCurrentChunkDiameter(); - this.minerLogic.setCurrentChunkDiameter(currentChunkDiameter <= 1 ? - this.minerLogic.getMaximumChunkDiameter() : currentChunkDiameter - 1); - - int workingAreaChunks = this.minerLogic.getCurrentChunkDiameter(); - player.sendMessage(new TextComponentTranslation("gregtech.machine.miner.working_area_chunks", workingAreaChunks, workingAreaChunks)); - } else { - int diameter = this.minerLogic.getCurrentDiameter() - 8; - if (diameter <= 0) diameter = this.minerLogic.getMaximumDiameter(); - this.minerLogic.setCurrentDiameter(diameter); - - player.sendMessage(new TextComponentTranslation("gregtech.universal.tooltip.working_area", diameter, diameter)); - } - } else { - player.sendMessage(new TextComponentTranslation("gregtech.machine.miner.errorradius")); - } - return true; - } - @Override public boolean hasMaintenanceMechanics() { return false; diff --git a/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityMiner.java b/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityMiner.java index 4bcfe716c8f..5d07808f601 100644 --- a/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityMiner.java +++ b/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityMiner.java @@ -1,6 +1,5 @@ package gregtech.common.metatileentities.miner; -import codechicken.lib.raytracer.CuboidRayTraceResult; import codechicken.lib.render.CCRenderState; import codechicken.lib.render.pipeline.IVertexOperation; import codechicken.lib.vec.Matrix4; @@ -12,15 +11,14 @@ import gregtech.api.capability.impl.NotifiableItemStackHandler; import gregtech.api.gui.GuiTextures; import gregtech.api.gui.ModularUI; -import gregtech.api.gui.widgets.ImageWidget; -import gregtech.api.gui.widgets.ProgressWidget; -import gregtech.api.gui.widgets.SlotWidget; -import gregtech.api.gui.widgets.ToggleButtonWidget; +import gregtech.api.gui.widgets.*; import gregtech.api.metatileentity.IDataInfoProvider; import gregtech.api.metatileentity.IFastRenderMetaTileEntity; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.metatileentity.TieredMetaTileEntity; import gregtech.api.metatileentity.interfaces.IGregTechTileEntity; +import gregtech.api.util.Position; +import gregtech.api.util.Size; import gregtech.client.renderer.texture.Textures; import gregtech.core.sound.GTSoundEvents; import net.minecraft.client.resources.I18n; @@ -28,9 +26,13 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.PacketBuffer; -import net.minecraft.util.*; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.NonNullList; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.SoundEvent; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.text.ITextComponent; +import net.minecraft.util.text.TextComponentString; import net.minecraft.util.text.TextComponentTranslation; import net.minecraft.util.text.TextFormatting; import net.minecraft.world.World; @@ -39,7 +41,6 @@ import net.minecraftforge.fml.relauncher.SideOnly; import net.minecraftforge.items.IItemHandlerModifiable; import net.minecraftforge.items.ItemStackHandler; -import org.jetbrains.annotations.NotNull; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -132,9 +133,25 @@ protected ModularUI createUI(@Nonnull EntityPlayer entityPlayer) { ModularUI.Builder builder = ModularUI.defaultBuilder(yOffset) .label(5, 5, getMetaFullName()) - .widget(new ToggleButtonWidget(152, 25, 18, 18, + .widget(new ToggleButtonWidget(152, yStart, 18, 18, GuiTextures.BUTTON_MINER_AREA_PREVIEW, this.minerLogic::isPreviewEnabled, this.minerLogic::setPreviewEnabled)) + .widget(new ClickButtonWidget(161, yStart + 18 + 2, 9, 9, + "", cd -> this.minerLogic.setCurrentDiameter(this.minerLogic.getCurrentDiameter() + (cd.isShiftClick ? 5 : 1))) + .setButtonTexture(GuiTextures.BUTTON_INT_CIRCUIT_PLUS)) + .widget(new ClickButtonWidget(161, yStart + 18 + 2 + 9, 9, 9, + "", cd -> this.minerLogic.setCurrentDiameter(this.minerLogic.getCurrentDiameter() - (cd.isShiftClick ? 5 : 1))) + .setButtonTexture(GuiTextures.BUTTON_INT_CIRCUIT_MINUS)) + .widget(new AdvancedTextWidget(159, yStart + 18 + 2 + (18 - 11) / 2, list -> { + int currentDiameter = this.minerLogic.getCurrentDiameter(); + list.add(new TextComponentString(currentDiameter + "x" + currentDiameter)); + }, 0x404040) { + @Override + protected void onSizeUpdate() { // >:( + Size size = this.getSize(); + this.setSelfPosition(new Position(159 - size.width, this.getSelfPosition().y)); + } + }) .widget(new SlotWidget(this.chargerInventory, 0, 79, 62 + yOffset, true, true, false) .setBackgroundTexture(GuiTextures.SLOT, GuiTextures.CHARGER_OVERLAY) .setTooltipText("gregtech.gui.charger_slot.tooltip", GTValues.VNF[getTier()], GTValues.VNF[getTier()])); @@ -181,7 +198,7 @@ public void addToolUsages(ItemStack stack, @Nullable World world, List t } @Override - public boolean drainMiningResources(@NotNull MinedBlockType minedBlockType, boolean pipeExtended, boolean simulate) { + public boolean drainMiningResources(@Nonnull MinedBlockType minedBlockType, boolean pipeExtended, boolean simulate) { if (minedBlockType == MinedBlockType.NOTHING) return true; long resultEnergy = energyContainer.getEnergyStored() - energyPerTick; if (resultEnergy < 0 || resultEnergy > energyContainer.getEnergyCapacity()) return false; @@ -203,28 +220,6 @@ public void update() { } } - @Override - public boolean onScrewdriverClick(EntityPlayer player, EnumHand hand, EnumFacing facing, CuboidRayTraceResult hitResult) { - if (getWorld().isRemote) return true; - - if (!this.isActive()) { - int currentRadius = this.minerLogic.getCurrentDiameter(); - if (currentRadius == 1) { - this.minerLogic.setCurrentDiameter(this.minerLogic.getMaximumDiameter()); - } else if (player.isSneaking()) { - this.minerLogic.setCurrentDiameter(currentRadius / 2 + currentRadius % 2); - } else { - this.minerLogic.setCurrentDiameter(currentRadius - 1); - } - - int diameter = minerLogic.getCurrentDiameter(); - player.sendMessage(new TextComponentTranslation("gregtech.machine.miner.working_area", diameter, diameter)); - } else { - player.sendMessage(new TextComponentTranslation("gregtech.machine.miner.errorradius")); - } - return true; - } - @Override public NBTTagCompound writeToNBT(NBTTagCompound data) { super.writeToNBT(data); diff --git a/src/main/java/gregtech/common/metatileentities/miner/MinerLogic.java b/src/main/java/gregtech/common/metatileentities/miner/MinerLogic.java index c27e820ad7a..035e5dbd5cc 100644 --- a/src/main/java/gregtech/common/metatileentities/miner/MinerLogic.java +++ b/src/main/java/gregtech/common/metatileentities/miner/MinerLogic.java @@ -37,12 +37,6 @@ public class MinerLogic { // flag indicating the miner has finished its action protected boolean done; - // last mined ore block - protected final MutableBlockPos lastMinedOre = new MutableBlockPos(); - protected boolean hasLastMinedOre; - // number of ores processed so far - protected int minedOreCount; - private boolean workingEnabled = true; // pipe length used for rendering purposes @@ -229,7 +223,6 @@ protected MiningArea createMiningArea() { * Recalculates the mining area and restarts the miner, if it was done */ public void reset() { - this.hasLastMinedOre = false; setPipeLength(0); rebuildMiningArea(); @@ -328,8 +321,6 @@ protected void mine(@Nonnull MiningArea miningArea) { } GTTransferUtils.addItemsToItemHandler(exportItems, false, blockDrops); this.inventoryFull = false; - this.lastMinedOre.setPos(pos); - this.minedOreCount++; } world.setBlockState(pos, isOrigin ? Blocks.AIR.getDefaultState() : getOreReplacement()); if (isOrigin) setPipeLength(this.pipeLength + 1); @@ -394,13 +385,6 @@ public NBTTagCompound writeToNBT(@Nonnull NBTTagCompound data) { if (!this.workingEnabled) data.setBoolean("disabled", true); if (this.done) data.setBoolean("done", true); - if (this.hasLastMinedOre) { - data.setInteger("lastMinedOreX", this.lastMinedOre.getX()); - data.setInteger("lastMinedOreY", this.lastMinedOre.getY()); - data.setInteger("lastMinedOreZ", this.lastMinedOre.getZ()); - } - - data.setInteger("minedOreCount", this.minedOreCount); data.setInteger("pipeLength", this.pipeLength); if (this.miningArea != null) { @@ -422,9 +406,6 @@ public void readFromNBT(@Nonnull NBTTagCompound data) { this.currentDiameter = MathHelper.clamp(data.getInteger("currentRadius") * 2 + 1, 1, getMaximumDiameter()); this.workingEnabled = data.getInteger("isWorkingEnabled") != 0; - - this.hasLastMinedOre = false; - this.minedOreCount = 0; this.pipeLength = data.getInteger("pipeLength"); return; } @@ -433,16 +414,6 @@ public void readFromNBT(@Nonnull NBTTagCompound data) { this.workingEnabled = !data.getBoolean("disabled"); this.done = data.getBoolean("done"); - if (data.hasKey("lastMinedOreX", Constants.NBT.TAG_INT)) { - this.lastMinedOre.setPos(data.getInteger("lastMinedOreX"), - data.getInteger("lastMinedOreY"), - data.getInteger("lastMinedOreZ")); - this.hasLastMinedOre = true; - } else { - this.hasLastMinedOre = false; - } - - this.minedOreCount = Math.max(0, data.getInteger("minedOreCount")); this.pipeLength = Math.max(0, data.getInteger("pipeLength")); this.miningArea = createMiningArea(); diff --git a/src/main/java/gregtech/common/metatileentities/miner/MinerUtil.java b/src/main/java/gregtech/common/metatileentities/miner/MinerUtil.java index 8f751ec6fc1..8746efa11a1 100644 --- a/src/main/java/gregtech/common/metatileentities/miner/MinerUtil.java +++ b/src/main/java/gregtech/common/metatileentities/miner/MinerUtil.java @@ -31,10 +31,14 @@ private MinerUtil() {} public static final String DISPLAY_CLICK_AREA_PREVIEW = "preview_area"; public static final String DISPLAY_CLICK_AREA_PREVIEW_HIDE = "hide_preview_area"; + public static final String DISPLAY_CLICK_AREA_DECR = "decr_area"; + public static final String DISPLAY_CLICK_AREA_INCR = "incr_area"; public static final String DISPLAY_CLICK_Y_LIMIT_DECR = "decr_y_limit"; public static final String DISPLAY_CLICK_Y_LIMIT_INCR = "incr_y_limit"; public static final String DISPLAY_CLICK_REPEAT_ENABLE = "enable_repeat"; public static final String DISPLAY_CLICK_REPEAT_DISABLE = "disable_repeat"; + public static final String DISPLAY_CLICK_REPLACE_ORE_ENABLE = "enable_replace_ore"; + public static final String DISPLAY_CLICK_REPLACE_ORE_DISABLE = "disable_replace_ore"; public static final AxisAlignedBB EMPTY_AABB = new AxisAlignedBB(0, 0, 0, 0, 0, 0); diff --git a/src/main/java/gregtech/common/metatileentities/miner/MultiblockMinerLogic.java b/src/main/java/gregtech/common/metatileentities/miner/MultiblockMinerLogic.java index 90d6a6bfa66..048ec2bf089 100644 --- a/src/main/java/gregtech/common/metatileentities/miner/MultiblockMinerLogic.java +++ b/src/main/java/gregtech/common/metatileentities/miner/MultiblockMinerLogic.java @@ -6,24 +6,15 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos.MutableBlockPos; import net.minecraft.util.math.MathHelper; -import net.minecraft.util.text.ITextComponent; -import net.minecraft.util.text.Style; -import net.minecraft.util.text.TextComponentTranslation; -import net.minecraft.util.text.TextFormatting; -import net.minecraft.util.text.event.ClickEvent; -import net.minecraft.util.text.event.HoverEvent; import net.minecraftforge.common.util.Constants; -import org.jetbrains.annotations.NotNull; import javax.annotation.Nonnull; -import java.util.List; public class MultiblockMinerLogic extends MinerLogic { private final int maximumChunkDiameter; private final MutableBlockPos mpos = new MutableBlockPos(); - private final MutableBlockPos mpos2 = new MutableBlockPos(); private int currentChunkDiameter; @@ -37,7 +28,7 @@ public class MultiblockMinerLogic extends MinerLogic { private boolean repeat; // flag for disabling ore replacement (if true, ores will be replaced with air instead of whatever block that was specified in the config) - private boolean disableReplacement; + private boolean replaceOreWithAir; public MultiblockMinerLogic(@Nonnull MetaTileEntityLargeMiner largeMiner, int workFrequency, int maximumChunkDiameter) { super(largeMiner, workFrequency, maximumChunkDiameter * 16); @@ -45,7 +36,7 @@ public MultiblockMinerLogic(@Nonnull MetaTileEntityLargeMiner largeMiner, int wo } @Override - protected void mine(@NotNull MiningArea miningArea) { + protected void mine(@Nonnull MiningArea miningArea) { if (this.done && this.repeat) { miningArea.reset(); this.done = false; @@ -53,10 +44,10 @@ protected void mine(@NotNull MiningArea miningArea) { super.mine(miningArea); } - @NotNull + @Nonnull @Override protected IBlockState getOreReplacement() { - return this.disableReplacement ? Blocks.AIR.getDefaultState() : super.getOreReplacement(); + return this.replaceOreWithAir ? Blocks.AIR.getDefaultState() : super.getOreReplacement(); } @Nonnull @@ -65,8 +56,8 @@ protected MiningArea createMiningArea() { BlockPos origin = getOrigin(); if (this.chunkMode) { int chunkRadius = this.currentChunkDiameter / 2; - int originChunkX = origin.getX() / 16 - chunkRadius; - int originChunkZ = origin.getZ() / 16 - chunkRadius; + int originChunkX = (origin.getX() >> 4) - chunkRadius; + int originChunkZ = (origin.getZ() >> 4) - chunkRadius; return new SimpleMiningArea((originChunkX) * 16, origin.getY() - 1, (originChunkZ) * 16, @@ -168,6 +159,17 @@ public void setRepeat(boolean repeat) { } } + public boolean isReplaceOreWithAir() { + return replaceOreWithAir; + } + + public void setReplaceOreWithAir(boolean replaceOreWithAir) { + if (this.replaceOreWithAir != replaceOreWithAir) { + this.replaceOreWithAir = replaceOreWithAir; + this.mte.markDirty(); + } + } + @Nonnull @Override public NBTTagCompound writeToNBT(@Nonnull NBTTagCompound data) { @@ -176,7 +178,7 @@ public NBTTagCompound writeToNBT(@Nonnull NBTTagCompound data) { data.setInteger("currentChunkDiameter", currentChunkDiameter); if (this.yLimit > 0) data.setInteger("yLimit", this.yLimit); if (this.repeat) data.setBoolean("repeat", true); - if (this.disableReplacement) data.setBoolean("disableReplacement", true); + if (this.replaceOreWithAir) data.setBoolean("replaceWithAir", true); return super.writeToNBT(data); } @@ -190,80 +192,6 @@ public void readFromNBT(@Nonnull NBTTagCompound data) { getMaximumChunkDiameter(); this.yLimit = Math.max(0, data.getInteger("yLimit")); this.repeat = data.getBoolean("repeat"); - this.disableReplacement = data.getBoolean("disableReplacement"); - } - - public void addDisplayText(@Nonnull List textList) { - if (isChunkMode()) { - int chunkDiameter = getCurrentChunkDiameter(); - textList.add(new TextComponentTranslation("gregtech.machine.miner.display.working_area.chunks", - chunkDiameter, chunkDiameter, previewWorkingAreaButton())); - } else { - int diameter = getCurrentDiameter(); - textList.add(new TextComponentTranslation("gregtech.machine.miner.display.working_area", - diameter, diameter, previewWorkingAreaButton())); - } - - Object value; - ITextComponent hoverText; - if (this.getYLimit() > 0) { - value = String.format("%,d", this.getYLimit()); - hoverText = new TextComponentTranslation("gregtech.machine.miner.display.y_limit.value_hover_tooltip", value); - } else { - value = new TextComponentTranslation("gregtech.machine.miner.display.y_limit.no_value"); - hoverText = new TextComponentTranslation("gregtech.machine.miner.display.y_limit.value_hover_tooltip.no_value"); - } - textList.add(new TextComponentTranslation("gregtech.machine.miner.display.y_limit", - yLimitButton(false), yLimitButton(true), value) - .setStyle(new Style().setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverText)))); - - textList.add(new TextComponentTranslation("gregtech.machine.miner.display.repeat", - new TextComponentTranslation(this.isRepeat() ? "gregtech.machine.miner.display.repeat.enabled" : - "gregtech.machine.miner.display.repeat.disabled") - .setStyle(new Style().setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, - this.isRepeat() ? "@!" + MinerUtil.DISPLAY_CLICK_REPEAT_DISABLE : - "@!" + MinerUtil.DISPLAY_CLICK_REPEAT_ENABLE))))); - - if (this.getMiningArea() == null || !getCurrentBlock(this.getMiningArea(), this.mpos2)) { - textList.add(new TextComponentTranslation("gregtech.machine.miner.display.done") - .setStyle(new Style().setColor(TextFormatting.GREEN))); - } else if (isWorking()) { - textList.add(new TextComponentTranslation("gregtech.machine.miner.display.working", - this.mpos2.getX(), this.mpos2.getY(), this.mpos2.getZ()) - .setStyle(new Style().setColor(TextFormatting.GOLD))); - } else if (!isWorkingEnabled()) { - textList.add(new TextComponentTranslation("gregtech.multiblock.work_paused")); - } - - textList.add(new TextComponentTranslation("gregtech.machine.miner.display.stats.total_mined", this.minedOreCount)); - if (this.hasLastMinedOre) { - textList.add(new TextComponentTranslation("gregtech.machine.miner.display.stats.last_mined", - this.lastMinedOre.getX(), this.lastMinedOre.getY(), this.lastMinedOre.getZ())); - } - } - - @Nonnull - protected ITextComponent previewWorkingAreaButton() { - return new TextComponentTranslation(this.isPreviewEnabled() ? - "gregtech.machine.miner.display.working_area.hide_preview" : - "gregtech.machine.miner.display.working_area.preview") - .setStyle(new Style().setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, - this.isPreviewEnabled() ? "@!" + MinerUtil.DISPLAY_CLICK_AREA_PREVIEW_HIDE : - "@!" + MinerUtil.DISPLAY_CLICK_AREA_PREVIEW))); - } - - @Nonnull - protected ITextComponent yLimitButton(boolean incr) { - if (incr) { - return this.getYLimit() == Integer.MAX_VALUE ? - new TextComponentTranslation("gregtech.machine.miner.display.y_limit.incr.disabled") : - new TextComponentTranslation("gregtech.machine.miner.display.y_limit.incr") - .setStyle(new Style().setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "@!" + MinerUtil.DISPLAY_CLICK_Y_LIMIT_INCR))); - } else { - return this.getYLimit() <= 0 ? - new TextComponentTranslation("gregtech.machine.miner.display.y_limit.decr.disabled") : - new TextComponentTranslation("gregtech.machine.miner.display.y_limit.decr") - .setStyle(new Style().setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "@!" + MinerUtil.DISPLAY_CLICK_Y_LIMIT_DECR))); - } + this.replaceOreWithAir = data.getBoolean("replaceWithAir"); } } diff --git a/src/main/java/gregtech/common/metatileentities/miner/SteamMiner.java b/src/main/java/gregtech/common/metatileentities/miner/SteamMiner.java index b2934d97206..3d0d18b072f 100644 --- a/src/main/java/gregtech/common/metatileentities/miner/SteamMiner.java +++ b/src/main/java/gregtech/common/metatileentities/miner/SteamMiner.java @@ -46,7 +46,6 @@ import net.minecraftforge.items.IItemHandlerModifiable; import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.tuple.Pair; -import org.jetbrains.annotations.NotNull; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -181,7 +180,7 @@ public void addToolUsages(ItemStack stack, @Nullable World world, List t } @Override - public boolean drainMiningResources(@NotNull MinedBlockType minedBlockType, boolean pipeExtended, boolean simulate) { + public boolean drainMiningResources(@Nonnull MinedBlockType minedBlockType, boolean pipeExtended, boolean simulate) { if (minedBlockType == MinedBlockType.NOTHING) return true; if (this.ventingStuck) return false; FluidStack drained = this.importFluids.drain(energyPerTick, simulate); diff --git a/src/main/resources/assets/gregtech/lang/en_us.lang b/src/main/resources/assets/gregtech/lang/en_us.lang index 79ace6f4ec7..3fa23742557 100644 --- a/src/main/resources/assets/gregtech/lang/en_us.lang +++ b/src/main/resources/assets/gregtech/lang/en_us.lang @@ -4632,21 +4632,24 @@ gregtech.machine.steam_miner.vent=Venting Blocked! gregtech.machine.steam_miner.steam=Needs Steam! gregtech.machine.miner.errorradius=§cCannot change radius while working! -gregtech.machine.miner.display.working_area=Working Area: %dx%d blocks %s -gregtech.machine.miner.display.working_area.chunks=Working Area: %dx%d chunks %s +gregtech.machine.miner.display.working_area=Working Area: %sx%s blocks +gregtech.machine.miner.display.working_area.chunks=Working Area: %sx%s chunks gregtech.machine.miner.display.working_area.preview=[§bPreview§r] gregtech.machine.miner.display.working_area.hide_preview=[§bHide Preview§r] -gregtech.machine.miner.display.y_limit=Y Limit: %s %s %s -gregtech.machine.miner.display.y_limit.decr=[§b-§r] -gregtech.machine.miner.display.y_limit.decr.disabled=[§8-§r] -gregtech.machine.miner.display.y_limit.incr=[§b+§r] -gregtech.machine.miner.display.y_limit.incr.disabled=[§8+§r] +gregtech.machine.miner.display.y_limit=Y Limit: %s gregtech.machine.miner.display.y_limit.no_value=No limit gregtech.machine.miner.display.y_limit.value_hover_tooltip=Miner will operate in §6%s§r Y layer(s) before halting. gregtech.machine.miner.display.y_limit.value_hover_tooltip.no_value=Miner will operate until hitting the bedrock layer. gregtech.machine.miner.display.repeat=Repeat after finished: %s -gregtech.machine.miner.display.repeat.enabled=[§aOn§r] -gregtech.machine.miner.display.repeat.disabled=[§cOff§r] +gregtech.machine.miner.display.replace_ore=Replace mined ore with: %s +gregtech.machine.miner.display.decr=[§b-§r] +gregtech.machine.miner.display.decr.disabled=[§8-§r] +gregtech.machine.miner.display.incr=[§b+§r] +gregtech.machine.miner.display.incr.disabled=[§8+§r] +gregtech.machine.miner.display.enabled=§aOn§r +gregtech.machine.miner.display.disabled=§cOff§r +gregtech.machine.miner.display.toggle.enabled=[§aOn§r] +gregtech.machine.miner.display.toggle.disabled=[§cOff§r] gregtech.machine.miner.display.stats.total_mined=Mined %s ores in total gregtech.machine.miner.display.stats.last_mined=Last Block Mined: [%s %s %s] From 48c0d1d5a71e2904a245b579c7963c28adc4e890 Mon Sep 17 00:00:00 2001 From: Tictim Date: Wed, 8 Nov 2023 20:32:35 +0900 Subject: [PATCH 05/27] Smallester miner retexture --- .../client/renderer/texture/Textures.java | 3 +-- .../miner/MetaTileEntityMiner.java | 3 --- .../metatileentities/miner/SteamMiner.java | 6 ++---- .../blocks/machines/miner/overlay_back.png | Bin 336 -> 438 bytes .../machines/miner/overlay_back_active.png | Bin 693 -> 803 bytes .../miner/overlay_back_active_emissive.png | Bin 407 -> 407 bytes .../blocks/machines/miner/overlay_bottom.png | Bin 1969 -> 429 bytes .../machines/miner/overlay_bottom_active.png | Bin 1969 -> 429 bytes .../blocks/machines/miner/overlay_front.png | Bin 0 -> 329 bytes .../machines/miner/overlay_front_active.png | Bin 0 -> 329 bytes .../blocks/machines/miner/overlay_side.png | Bin 336 -> 438 bytes .../machines/miner/overlay_side_active.png | Bin 693 -> 803 bytes .../miner/overlay_side_active_emissive.png | Bin 407 -> 407 bytes 13 files changed, 3 insertions(+), 9 deletions(-) create mode 100644 src/main/resources/assets/gregtech/textures/blocks/machines/miner/overlay_front.png create mode 100644 src/main/resources/assets/gregtech/textures/blocks/machines/miner/overlay_front_active.png diff --git a/src/main/java/gregtech/client/renderer/texture/Textures.java b/src/main/java/gregtech/client/renderer/texture/Textures.java index a57c71d7f91..06bf9c8bf96 100644 --- a/src/main/java/gregtech/client/renderer/texture/Textures.java +++ b/src/main/java/gregtech/client/renderer/texture/Textures.java @@ -172,7 +172,6 @@ public class Textures { public static final OrientedOverlayRenderer WORLD_ACCELERATOR_OVERLAY = new OrientedOverlayRenderer("machines/world_accelerator"); public static final OrientedOverlayRenderer WORLD_ACCELERATOR_TE_OVERLAY = new OrientedOverlayRenderer("machines/world_accelerator_te"); public static final OrientedOverlayRenderer MINER_OVERLAY = new OrientedOverlayRenderer("machines/miner"); - public static final OrientedOverlayRenderer STEAM_MINER_OVERLAY = new OrientedOverlayRenderer("machines/steam_miner"); // Simple Overlay Renderers public static final SimpleOverlayRenderer SCREEN = new SimpleOverlayRenderer("overlay/machine/overlay_screen"); @@ -302,7 +301,7 @@ public class Textures { public static final SimpleOverlayRenderer ME_INPUT_HATCH = new SimpleOverlayRenderer("overlay/appeng/me_input_hatch"); public static final SimpleOverlayRenderer ME_OUTPUT_BUS = new SimpleOverlayRenderer("overlay/appeng/me_output_bus"); public static final SimpleOverlayRenderer ME_INPUT_BUS = new SimpleOverlayRenderer("overlay/appeng/me_input_bus"); - + public static final ResourceLocation GREGTECH_CAPE_TEXTURE = gregtechId("textures/capes/gregtechcape.png"); public static final ResourceLocation RED_CAPE_TEXTURE = gregtechId("textures/capes/redcape.png"); public static final ResourceLocation YELLOW_CAPE_TEXTURE = gregtechId("textures/capes/yellowcape.png"); diff --git a/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityMiner.java b/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityMiner.java index 5d07808f601..3a4345808ad 100644 --- a/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityMiner.java +++ b/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityMiner.java @@ -86,9 +86,6 @@ protected IItemHandlerModifiable createExportItemHandler() { public void renderMetaTileEntity(CCRenderState renderState, Matrix4 translation, IVertexOperation[] pipeline) { super.renderMetaTileEntity(renderState, translation, pipeline); Textures.MINER_OVERLAY.renderOrientedState(renderState, translation, pipeline, getFrontFacing(), minerLogic.isActive(), minerLogic.isWorkingEnabled()); - if (hasFrontFacing()) { - Textures.PIPE_OUT_OVERLAY.renderSided(getFrontFacing(), renderState, translation, pipeline); - } MinerRenderHelper.renderPipe(Textures.SOLID_STEEL_CASING, this.minerLogic.getPipeLength(), renderState, translation, pipeline); } diff --git a/src/main/java/gregtech/common/metatileentities/miner/SteamMiner.java b/src/main/java/gregtech/common/metatileentities/miner/SteamMiner.java index 3d0d18b072f..c2bbf1652e5 100644 --- a/src/main/java/gregtech/common/metatileentities/miner/SteamMiner.java +++ b/src/main/java/gregtech/common/metatileentities/miner/SteamMiner.java @@ -94,10 +94,8 @@ protected IItemHandlerModifiable createExportItemHandler() { public void renderMetaTileEntity(CCRenderState renderState, Matrix4 translation, IVertexOperation[] pipeline) { IVertexOperation[] colouredPipeline = ArrayUtils.add(pipeline, new ColourMultiplier(GTUtility.convertRGBtoOpaqueRGBA_CL(getPaintingColorForRendering()))); Textures.STEAM_CASING_BRONZE.render(renderState, translation, colouredPipeline); - Textures.STEAM_MINER_OVERLAY.renderOrientedState(renderState, translation, pipeline, getFrontFacing(), minerLogic.isActive(), minerLogic.isWorkingEnabled()); - if (hasFrontFacing()) { - Textures.PIPE_OUT_OVERLAY.renderSided(getFrontFacing(), renderState, translation, pipeline); - } + // TODO replace top with vent, in standalone mod + Textures.MINER_OVERLAY.renderOrientedState(renderState, translation, pipeline, getFrontFacing(), minerLogic.isActive(), minerLogic.isWorkingEnabled()); MinerRenderHelper.renderPipe(Textures.BRONZE_PLATED_BRICKS, this.minerLogic.getPipeLength(), renderState, translation, pipeline); } diff --git a/src/main/resources/assets/gregtech/textures/blocks/machines/miner/overlay_back.png b/src/main/resources/assets/gregtech/textures/blocks/machines/miner/overlay_back.png index f59b9d285945c72ac3c0ca1cdd8f0e9e2dd6e9ca..78888e5ad813949fe23b58800ec414944e119b2c 100644 GIT binary patch delta 399 zcmV;A0dW4%0=5H?F@JDLL_t(Ijn$IBN+VGe#(y&m2;1nO#oiGt1|(u}L5tlY#Reb1 z!qz89Yhj+j2M8jzK7fdYWeN+~W{K5;umc7e!xhHL6q$RDMa*anx`LGlF5L6y`_BD7 zE`0e2#+P3k8~RaDuh-+>)l~oxy=+`(82}G~ZH=B`;cND0 zvx&8qIF6ZLwPY9Plx0bt=ZMJEYbFRw;_iYcZ zv#i=;j3G%9hQlGwIRJicZgFzBPY^|w2U8LNthFRbLQxddYPCwj@j?523FC0iQ4|G@ zMuSeLGa=!>1b<-|lIJ<~dYx{!i!lc09D~7tFr403d5|tIfA}8&l?TDm-irRdyyNok zebuxpbNsLiEPnsS&Fus4^~2AAZ*Ct5*4EZlRq);;s)+Z92;K`K9#KKOAo7%pj%H<4 ti^fG2c^+0lRZ!IluopqRA~HV0BPF=zyB3A(VE_OC00>D%PDHLkV1gUPxi0_! delta 296 zcmV+@0oVSv1JDAHF@Fk4L_t(IjqQ>#OT<7FgujG!GBo zs(9IKJb>WyVq2B~IOot>BZT1SR8y{305nbW?izg1{IBXsl7C=~K?uRg+)%Dp48uTO z*Er`U*X#+TX-bx5SZg^B=R7|>G7JM!O0?DhTwULM-@&#lM;9q2N-6rj$65=(*~KLf z%Uir47(19m05Ha&l%j20!Y~{o+}~wCN7%tyOWU@@aZH})dl7yW@O_`Uu8E?Eq9~A3 uVy&g?I(&cXHz9VQXS0L<02n*?19$@kIAuz*l^t;a0000pMQsQ|MDLtf;NKYc= z_P12ETv=N?y0MzJw^eCypn>9Vq&eT7FA3mKEi3EmW1TEClgU|_luCI0v z64x}+=``cxw8 z7J2g;5{U$kQzI9!;}3S}K?uN)a;HIj+aqN%8P?X;=&O`a&x^n0*7XOz!7vPid_Etv wP|qLK)r0ii_@% delta 656 zcmV;B0&o4J2DJr{F@JAKL_t(YiS3rpOB7)o#y@H=i;Brohi0Jh2f4wLF14|#D>z6C z75O*xFBo+7l83x>t78ZM1_L|U2rEb(Hp>;(E%&gY!CSoK*bd8#YzLch2WMd+y2L)G zfqCcQ{m%P7A0Fta%YT@in`^ZDQMFoSzg+GDxX}DUFRUX(4}a>;1B4JLrMQwxQ_fqY zzwhAGTwM2r>gBQEo9<=Xqv{}$P~SO0wH=ry9pUgKYhv9 zS4(76k>SZKKXyN&X&O>W9LFIR6BvsxS{oFW7XYXvOn#PjQA#1D#Pd8dsz}$PMdb6x ztqpwnBiOdh%zw-bnx^qdzfEIh>D=0ofm3s-*IhEIh~qfS&(BjTm4XrKbr+}Rh73Zd z;JPPJgM;xLcT*`W%ffLSJkJZALbHNmjp99%NJzfSdOoa)12gEDLS(ppq~dp3L%jb0ZYz zC?15uR9Idh786J*Io{gDwrzmZI1dakk-LA&193Ha2fq9`8-{^tn!yNBJP7T;&-%f5 z4qXURsT6B#Yj~c=v|T#m!C;Gj;JPO`H5Vx*$z+n%)m1#t3y9R=K}W6hZ~8%RpI~of zig-Lu%zqfAvXuuQvH!lkesD0JBOZ@)DLFx9D<8zUZ5~J|8N8mP@aA3_oZH~KyfrZhqvG@!8CoDL!p(c*r;w7gsaY2nZIOyWf zab|OH(!qfQBn_#9K`Hn3LSk;~yY=Ji+ZK4A6tH6bLF7RR!SVFovSDKqII6BBq-^p0 z`8RLUZxVuI@8q0Z>HhVL&E^6^aILNx?4RA@?O};DbQNVXoqr1KE^f@{NdiZiCa0mR z4p)~d2^{VDgleXg6(v)T%eA^@P*)O7BaKIB8i~4+T5YF4kg^4;pBFZq-2VzzR@+tN zLB&2Ne`5fMeXb%8<}h_UFlB+_fu=mqH^w;)U3GeWXWZdN9ss~-9+*rh9%ymyvQEW0 z4P8a?K-+rQM<$=}KMBWc(b3y*jvCq}0`++G7|KdSsGUS1_gO`h=-$u%S z9W3y1b*$A$9%MyH9%1zTz+^g_2SaT27qC3og1!Mg&A2w{VkkEN0000-s2dYF;Jdl*8>E1X;o`u&>ugVVh@&Eu}Fb`BF6c3KtgC^^%^`;ls z$g_~*fz*KzbzQHZQIh4X;enRc!A1U=W^+z{&Vgg#p!!`q~29BDwK@PDl9w0000xc3-g(R?0!H& z7DU1p=nl98n*?Rp!ZH9$pm%h_HoO5gM8PJsna#ayEDz0n*?-g;)a3}apka8>H$e(( zA6SM++-@Jp3`7JX0~y)-2t*{lzCK5vU4kaM4BLnd{Cs~SGm%xODr6=q3$O354+8dD zyC%60Dgs&0;H*SuAtFcY7ML~`DOfzjx=Dg`tfqT_3l%j% z5_u2ElTd~!EPw6nGDssLCP-(_hks;_55`y)mbmM0(`0N0v+4{I5z|7An8w=1X&-bK z-rnAkamW2n8#D5>_xR@Ja=BO!M*43(0^3-eHqzrd9@Hd(e=OYRJVlqW+C&<4{WOX4 xDOdx$W86+WjI?{J5r>?C*&W)zJ&ou4U*lHb_`D6elMDa=002ovPDHLkV1g7guygL8h6F)4kekaE_ouz%xVclScxW@HJ_seVPdN3BfL%{u|&(RmzI9}?4l&PBrP2`@-XjbXvLk| z4(RgsLJ@DTV~a>rlj20v<_2msLSnO4^+LOumRfdgK8~klNo+x)^|Uk{I}}&)OJarv zR5TM1U*G+gtRG|uGXvm5R6w`*ftt7?HPvYJJ;@E}kiydG5D=k%`$hT#= z(P$(ZT7m^-S+OijhN`TpfFnS-pmXb|#=GVnLCyYPV2JUCN@W zBvkS6an~cP5k9|X1I?m{rX^lA1;8XwVNo$`-LN$i@Y+GxhUOV@ovnSLmaXb{K)GZH ziqL(*1ltY^YKRBy)=-(szE_sSUK;HTtFnMQ=Ipe+^SMlBDPWFUi}U(1JqJXOo$1wWpwvv z8Lr0~i1)XT17Vok_?KTv*NCI1EMTe_0ZY?0fJ&tlPz(!EgQgrz^{%zWz~v_rRrgwr zSrKkgBT%E17(hi@3P7l1fG9U+q*UF|bw^cFO04^qli`StuXn&;%lw#xrKQlTT}dMkB7aU!asUliF!Ow0q;346>i_;{p#IZcDk6l^5Z+x zLvJ1(>3iY3k8gbQ^YYclp8fFF`P0{?Gx}SHn}cNSz1=APwR!8tEA@}YPMkZ`H-CNi zBwhXLizAIybL`Uhe~zx5yEHL8vh()9(wUnV(wifzM1F2SI*X5f^5|=&Ni zI9NU)=vHdG|hFj diff --git a/src/main/resources/assets/gregtech/textures/blocks/machines/miner/overlay_bottom_active.png b/src/main/resources/assets/gregtech/textures/blocks/machines/miner/overlay_bottom_active.png index 5bce3b33bfa4b21d707a808e0136d8a3c218fc81..efa4dfedd83158dbfbec4e8b87a04a36f26503b0 100644 GIT binary patch delta 403 zcmV;E0c`%U53K``B!2;OQb$4nuFf3k0004JNklxc3-g(R?0!H& z7DU1p=nl98n*?Rp!ZH9$pm%h_HoO5gM8PJsna#ayEDz0n*?-g;)a3}apka8>H$e(( zA6SM++-@Jp3`7JX0~y)-2t*{lzCK5vU4kaM4BLnd{Cs~SGm%xODr6=q3$O354+8dD zyC%60Dgs&0;H*SuAtFcY7ML~`DOfzjx=Dg`tfqT_3l%j% z5_u2ElTd~!EPw6nGDssLCP-(_hks;_55`y)mbmM0(`0N0v+4{I5z|7An8w=1X&-bK z-rnAkamW2n8#D5>_xR@Ja=BO!M*43(0^3-eHqzrd9@Hd(e=OYRJVlqW+C&<4{WOX4 xDOdx$W86+WjI?{J5r>?C*&W)zJ&ou4U*lHb_`D6elMDa=002ovPDHLkV1g7guygL8h6F)4kekaE_ouz%xVclScxW@HJ_seVPdN3BfL%{u|&(RmzI9}?4l&PBrP2`@-XjbXvLk| z4(RgsLJ@DTV~a>rlj20v<_2msLSnO4^+LOumRfdgK8~klNo+x)^|Uk{I}}&)OJarv zR5TM1U*G+gtRG|uGXvm5R6w`*ftt7?HPvYJJ;@E}kiydG5D=k%`$hT#= z(P$(ZT7m^-S+OijhN`TpfFnS-pmXb|#=GVnLCyYPV2JUCN@W zBvkS6an~cP5k9|X1I?m{rX^lA1;8XwVNo$`-LN$i@Y+GxhUOV@ovnSLmaXb{K)GZH ziqL(*1ltY^YKRBy)=-(szE_sSUK;HTtFnMQ=Ipe+^SMlBDPWFUi}U(1JqJXOo$1wWpwvv z8Lr0~i1)XT17Vok_?KTv*NCI1EMTe_0ZY?0fJ&tlPz(!EgQgrz^{%zWz~v_rRrgwr zSrKkgBT%E17(hi@3P7l1fG9U+q*UF|bw^cFO04^qli`StuXn&;%lw#xrKQlTT}dMkB7aU!asUliF!Ow0q;346>i_;{p#IZcDk6l^5Z+x zLvJ1(>3iY3k8gbQ^YYclp8fFF`P0{?Gx}SHn}cNSz1=APwR!8tEA@}YPMkZ`H-CNi zBwhXLizAIybL`Uhe~zx5yEHL8vh()9(wUnV(wifzM1F2SI*X5f^5|=&Ni zI9NU)=vHdG|hFj diff --git a/src/main/resources/assets/gregtech/textures/blocks/machines/miner/overlay_front.png b/src/main/resources/assets/gregtech/textures/blocks/machines/miner/overlay_front.png new file mode 100644 index 0000000000000000000000000000000000000000..f90afa31e033a5b15a235e23e51ec15c2b55389c GIT binary patch literal 329 zcmV-P0k-~$P)Px$14%?dR5*?8kuh!pF%(1xM3pK<3Zz_s3W*eHfZK&4=YSKSoFXMvE`UUlA{Elk ze9up@OJH}S1SxGSS+>W2p2s%u-v(V_z22lmkOW1Ds^=s~VYPZ{c}86TMZ9dckOV~_ zA|MH&z0Ts6$zPx$14%?dR5*?8kuh!pF%(1xM3pK<3Zz_s3W*eHfZK&4=YSKSoFXMvE`UUlA{Elk ze9up@OJH}S1SxGSS+>W2p2s%u-v(V_z22lmkOW1Ds^=s~VYPZ{c}86TMZ9dckOV~_ zA|MH&z0Ts6$z)l~oxy=+`(82}G~ZH=B`;cND0 zvx&8qIF6ZLwPY9Plx0bt=ZMJEYbFRw;_iYcZ zv#i=;j3G%9hQlGwIRJicZgFzBPY^|w2U8LNthFRbLQxddYPCwj@j?523FC0iQ4|G@ zMuSeLGa=!>1b<-|lIJ<~dYx{!i!lc09D~7tFr403d5|tIfA}8&l?TDm-irRdyyNok zebuxpbNsLiEPnsS&Fus4^~2AAZ*Ct5*4EZlRq);;s)+Z92;K`K9#KKOAo7%pj%H<4 ti^fG2c^+0lRZ!IluopqRA~HV0BPF=zyB3A(VE_OC00>D%PDHLkV1gUPxi0_! delta 296 zcmV+@0oVSv1JDAHF@Fk4L_t(IjqQ>#OT<7FgujG!GBo zs(9IKJb>WyVq2B~IOot>BZT1SR8y{305nbW?izg1{IBXsl7C=~K?uRg+)%Dp48uTO z*Er`U*X#+TX-bx5SZg^B=R7|>G7JM!O0?DhTwULM-@&#lM;9q2N-6rj$65=(*~KLf z%Uir47(19m05Ha&l%j20!Y~{o+}~wCN7%tyOWU@@aZH})dl7yW@O_`Uu8E?Eq9~A3 uVy&g?I(&cXHz9VQXS0L<02n*?19$@kIAuz*l^t;a0000pMQsQ|MDLtf;NKYc= z_P12ETv=N?y0MzJw^eCypn>9Vq&eT7FA3mKEi3EmW1TEClgU|_luCI0v z64x}+=``cxw8 z7J2g;5{U$kQzI9!;}3S}K?uN)a;HIj+aqN%8P?X;=&O`a&x^n0*7XOz!7vPid_Etv wP|qLK)r0ii_@% delta 656 zcmV;B0&o4J2DJr{F@JAKL_t(YiS3rpOB7)o#y@H=i;Brohi0Jh2f4wLF14|#D>z6C z75O*xFBo+7l83x>t78ZM1_L|U2rEb(Hp>;(E%&gY!CSoK*bd8#YzLch2WMd+y2L)G zfqCcQ{m%P7A0Fta%YT@in`^ZDQMFoSzg+GDxX}DUFRUX(4}a>;1B4JLrMQwxQ_fqY zzwhAGTwM2r>gBQEo9<=Xqv{}$P~SO0wH=ry9pUgKYhv9 zS4(76k>SZKKXyN&X&O>W9LFIR6BvsxS{oFW7XYXvOn#PjQA#1D#Pd8dsz}$PMdb6x ztqpwnBiOdh%zw-bnx^qdzfEIh>D=0ofm3s-*IhEIh~qfS&(BjTm4XrKbr+}Rh73Zd z;JPPJgM;xLcT*`W%ffLSJkJZALbHNmjp99%NJzfSdOoa)12gEDLS(ppq~dp3L%jb0ZYz zC?15uR9Idh786J*Io{gDwrzmZI1dakk-LA&193Ha2fq9`8-{^tn!yNBJP7T;&-%f5 z4qXURsT6B#Yj~c=v|T#m!C;Gj;JPO`H5Vx*$z+n%)m1#t3y9R=K}W6hZ~8%RpI~of zig-Lu%zqfAvXuuQvH!lkesD0JBOZ@)DLFx9D<8zUZ5~J|8N8mP@aA3_oZH~KyfrZhqvG@!8CoDL!p(c*r;w7gsaY2nZIOyWf zab|OH(!qfQBn_#9K`Hn3LSk;~yY=Ji+ZK4A6tH6bLF7RR!SVFovSDKqII6BBq-^p0 z`8RLUZxVuI@8q0Z>HhVL&E^6^aILNx?4RA@?O};DbQNVXoqr1KE^f@{NdiZiCa0mR z4p)~d2^{VDgleXg6(v)T%eA^@P*)O7BaKIB8i~4+T5YF4kg^4;pBFZq-2VzzR@+tN zLB&2Ne`5fMeXb%8<}h_UFlB+_fu=mqH^w;)U3GeWXWZdN9ss~-9+*rh9%ymyvQEW0 z4P8a?K-+rQM<$=}KMBWc(b3y*jvCq}0`++G7|KdSsGUS1_gO`h=-$u%S z9W3y1b*$A$9%MyH9%1zTz+^g_2SaT27qC3og1!Mg&A2w{VkkEN0000-s2dYF;Jdl*8>E1X;o`u&>ugVVh@&Eu}Fb`BF6c3KtgC^^%^`;ls z$g_~*fz*KzbzQHZQIh4X;enRc!A1U=W^+z{&Vgg#p!!`q~29BDwK@PDl9w0000 Date: Wed, 8 Nov 2023 21:15:11 +0900 Subject: [PATCH 06/27] Smallestest refactor --- .../miner/MetaTileEntityLargeMiner.java | 3 +- .../miner/MultiblockMinerLogic.java | 53 ++++++++----------- 2 files changed, 24 insertions(+), 32 deletions(-) diff --git a/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityLargeMiner.java b/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityLargeMiner.java index eb8460d6d12..3c002cbfcf7 100644 --- a/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityLargeMiner.java +++ b/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityLargeMiner.java @@ -113,7 +113,6 @@ protected void formStructure(PatternMatchContext context) { this.inputFluidInventory = new FluidTankList(false, getAbilities(MultiblockAbility.IMPORT_FLUIDS)); this.outputInventory = new ItemHandlerList(getAbilities(MultiblockAbility.EXPORT_ITEMS)); this.energyContainer = new EnergyContainerList(getAbilities(MultiblockAbility.INPUT_ENERGY)); - this.minerLogic.reset(); } public int getEnergyTier() { @@ -319,7 +318,7 @@ protected void addDisplayText(List textList) { "gregtech.machine.miner.display.toggle.disabled") .setStyle(button(currentValue ? MinerUtil.DISPLAY_CLICK_REPEAT_DISABLE : MinerUtil.DISPLAY_CLICK_REPEAT_ENABLE)))); - ITextComponent replaceOreText = new TextComponentTranslation(this.minerLogic.getOreReplacement().getBlock().getTranslationKey()+".name"); + ITextComponent replaceOreText = new TextComponentTranslation(this.minerLogic.getOreReplacement().getBlock().getTranslationKey() + ".name"); if (!this.minerLogic.isWorking()) { replaceOreText = new TextComponentString("[") .appendSibling(replaceOreText.setStyle(new Style().setColor(TextFormatting.AQUA))) diff --git a/src/main/java/gregtech/common/metatileentities/miner/MultiblockMinerLogic.java b/src/main/java/gregtech/common/metatileentities/miner/MultiblockMinerLogic.java index 048ec2bf089..66b74867195 100644 --- a/src/main/java/gregtech/common/metatileentities/miner/MultiblockMinerLogic.java +++ b/src/main/java/gregtech/common/metatileentities/miner/MultiblockMinerLogic.java @@ -93,10 +93,10 @@ public int getCurrentChunkDiameter() { public void setCurrentChunkDiameter(int currentChunkDiameter) { if (isWorking()) return; currentChunkDiameter = Math.max(1, Math.min(currentChunkDiameter, getMaximumChunkDiameter())); - if (this.currentChunkDiameter != currentChunkDiameter || !this.chunkMode) { - this.chunkMode = true; + setChunkMode(true); + if (this.currentChunkDiameter != currentChunkDiameter) { this.currentChunkDiameter = currentChunkDiameter; - this.rebuildMiningArea = false; + this.rebuildMiningArea = true; this.mte.markDirty(); } } @@ -104,11 +104,7 @@ public void setCurrentChunkDiameter(int currentChunkDiameter) { @Override public void setCurrentDiameter(int currentDiameter) { if (isWorking()) return; - if (this.chunkMode) { - this.chunkMode = false; - this.rebuildMiningArea = true; - this.mte.markDirty(); - } + setChunkMode(false); super.setCurrentDiameter(currentDiameter); } @@ -116,9 +112,9 @@ public boolean isChunkMode() { return this.chunkMode; } - public void setChunkMode(boolean isChunkMode) { - if (isWorking()) return; - this.chunkMode = isChunkMode; + public void setChunkMode(boolean chunkMode) { + if (isWorking() || this.chunkMode == chunkMode) return; + this.chunkMode = chunkMode; this.rebuildMiningArea = true; this.mte.markDirty(); } @@ -127,10 +123,10 @@ public boolean isSilkTouchMode() { return this.silkTouchMode; } - public void setSilkTouchMode(boolean isSilkTouchMode) { - if (!isWorking()) { - this.silkTouchMode = isSilkTouchMode; - } + public void setSilkTouchMode(boolean silkTouchMode) { + if (isWorking() || this.silkTouchMode == silkTouchMode) return; + this.silkTouchMode = silkTouchMode; + this.mte.markDirty(); } public int getYLimit() { @@ -138,13 +134,12 @@ public int getYLimit() { } public void setYLimit(int yLimit) { - if (yLimit != this.yLimit) { - this.yLimit = yLimit; - this.rebuildMiningArea = true; - this.mte.markDirty(); - if (this.isPreviewEnabled()) { - updatePreview(); - } + if (isWorking() || this.yLimit == yLimit) return; + this.yLimit = yLimit; + this.rebuildMiningArea = true; + this.mte.markDirty(); + if (this.isPreviewEnabled()) { + updatePreview(); } } @@ -153,10 +148,9 @@ public boolean isRepeat() { } public void setRepeat(boolean repeat) { - if (this.repeat != repeat) { - this.repeat = repeat; - this.mte.markDirty(); - } + if (isWorking() || this.repeat == repeat) return; + this.repeat = repeat; + this.mte.markDirty(); } public boolean isReplaceOreWithAir() { @@ -164,10 +158,9 @@ public boolean isReplaceOreWithAir() { } public void setReplaceOreWithAir(boolean replaceOreWithAir) { - if (this.replaceOreWithAir != replaceOreWithAir) { - this.replaceOreWithAir = replaceOreWithAir; - this.mte.markDirty(); - } + if (isWorking() || this.replaceOreWithAir == replaceOreWithAir) return; + this.replaceOreWithAir = replaceOreWithAir; + this.mte.markDirty(); } @Nonnull From 22b82ebbab5f2b202b60a62d1b6a7de07acedc45 Mon Sep 17 00:00:00 2001 From: Tictim Date: Mon, 13 Nov 2023 01:30:59 +0900 Subject: [PATCH 07/27] They really should stop doing "Haha small refactor" joke on commit messages, it's not funny, it's rather annoying and doesn't convey any meaningful information to outsiders. Just because you don't understand what you did in last 5 days doesn't mean you are exempted from your duties of explaining your works to your collaborators. Anyways, here's a small refactor. --- .../java/gregtech/client/ClientProxy.java | 2 + .../java/gregtech/common/MetaEntities.java | 14 ++ .../common/entities/MiningPipeEntity.java | 127 ++++++++++++++++++ .../miner/LargeMinerType.java | 4 + .../miner/LargeMinerTypes.java | 10 ++ .../miner/MetaTileEntityLargeMiner.java | 21 ++- .../miner/MetaTileEntityMiner.java | 9 +- .../metatileentities/miner/MinerLogic.java | 69 +++++++++- .../miner/MinerRenderHelper.java | 81 ++++++----- .../metatileentities/miner/MiningArea.java | 2 +- .../miner/MiningPipeModel.java | 112 +++++++++++++++ .../miner/MiningPipeModels.java | 13 ++ .../miner/MultiblockMinerLogic.java | 2 +- .../miner/SimpleMiningArea.java | 13 +- .../metatileentities/miner/SteamMiner.java | 6 +- .../models/block/mining_pipe/base.json | 18 +++ .../models/block/mining_pipe/base_bottom.json | 19 +++ .../models/block/mining_pipe/bronze.json | 6 + .../block/mining_pipe/bronze_bottom.json | 6 + .../models/block/mining_pipe/steel.json | 6 + .../block/mining_pipe/steel_bottom.json | 6 + .../models/block/mining_pipe/titanium.json | 6 + .../block/mining_pipe/titanium_bottom.json | 6 + .../block/mining_pipe/tungsten_steel.json | 6 + .../mining_pipe/tungsten_steel_bottom.json | 6 + 25 files changed, 513 insertions(+), 57 deletions(-) create mode 100644 src/main/java/gregtech/common/entities/MiningPipeEntity.java create mode 100644 src/main/java/gregtech/common/metatileentities/miner/MiningPipeModel.java create mode 100644 src/main/java/gregtech/common/metatileentities/miner/MiningPipeModels.java create mode 100644 src/main/resources/assets/gregtech/models/block/mining_pipe/base.json create mode 100644 src/main/resources/assets/gregtech/models/block/mining_pipe/base_bottom.json create mode 100644 src/main/resources/assets/gregtech/models/block/mining_pipe/bronze.json create mode 100644 src/main/resources/assets/gregtech/models/block/mining_pipe/bronze_bottom.json create mode 100644 src/main/resources/assets/gregtech/models/block/mining_pipe/steel.json create mode 100644 src/main/resources/assets/gregtech/models/block/mining_pipe/steel_bottom.json create mode 100644 src/main/resources/assets/gregtech/models/block/mining_pipe/titanium.json create mode 100644 src/main/resources/assets/gregtech/models/block/mining_pipe/titanium_bottom.json create mode 100644 src/main/resources/assets/gregtech/models/block/mining_pipe/tungsten_steel.json create mode 100644 src/main/resources/assets/gregtech/models/block/mining_pipe/tungsten_steel_bottom.json diff --git a/src/main/java/gregtech/client/ClientProxy.java b/src/main/java/gregtech/client/ClientProxy.java index 1a9c299f2fb..62bf4f09285 100644 --- a/src/main/java/gregtech/client/ClientProxy.java +++ b/src/main/java/gregtech/client/ClientProxy.java @@ -25,6 +25,7 @@ import gregtech.common.blocks.MetaBlocks; import gregtech.common.items.MetaItems; import gregtech.common.items.ToolItems; +import gregtech.common.metatileentities.miner.MiningPipeModels; import net.minecraft.block.Block; import net.minecraft.client.Minecraft; import net.minecraft.client.resources.I18n; @@ -84,6 +85,7 @@ public void onPreLoad() { MetaEntities.initRenderers(); MetaFluids.initIconFluidSprites(); TextureUtils.addIconRegister(MetaFluids::registerSprites); + MiningPipeModels.init(); } @Override diff --git a/src/main/java/gregtech/common/MetaEntities.java b/src/main/java/gregtech/common/MetaEntities.java index 7e09df91d5b..14605588071 100644 --- a/src/main/java/gregtech/common/MetaEntities.java +++ b/src/main/java/gregtech/common/MetaEntities.java @@ -7,19 +7,26 @@ import gregtech.client.renderer.handler.PortalRenderer; import gregtech.common.entities.DynamiteEntity; import gregtech.common.entities.GTBoatEntity; +import gregtech.common.entities.MiningPipeEntity; import gregtech.common.entities.PortalEntity; import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.entity.Render; +import net.minecraft.util.ResourceLocation; import net.minecraftforge.fml.client.registry.RenderingRegistry; import net.minecraftforge.fml.common.registry.EntityRegistry; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + public class MetaEntities { public static void init() { EntityRegistry.registerModEntity(GTUtility.gregtechId("dynamite"), DynamiteEntity.class, "Dynamite", 1, GregTechAPI.instance, 64, 3, true); EntityRegistry.registerModEntity(GTUtility.gregtechId("gtportal"), PortalEntity.class, "GTPortal", 2, GregTechAPI.instance, 64, 5, true); EntityRegistry.registerModEntity(GTUtility.gregtechId("gtboat"), GTBoatEntity.class, "GTBoat", 3, GregTechAPI.instance, 64, 2, true); + EntityRegistry.registerModEntity(GTUtility.gregtechId("mining_pipe"), MiningPipeEntity.class, "MiningPipe", 4, GregTechAPI.instance, 64, 5, false); } @SideOnly(Side.CLIENT) @@ -27,5 +34,12 @@ public static void initRenderers() { RenderingRegistry.registerEntityRenderingHandler(DynamiteEntity.class, manager -> new DynamiteRenderer(manager, Minecraft.getMinecraft().getRenderItem())); RenderingRegistry.registerEntityRenderingHandler(PortalEntity.class, PortalRenderer::new); RenderingRegistry.registerEntityRenderingHandler(GTBoatEntity.class, GTBoatRenderer::new); + RenderingRegistry.registerEntityRenderingHandler(MiningPipeEntity.class, manager -> new Render<>(manager) { + @Nullable + @Override + protected ResourceLocation getEntityTexture(@Nonnull MiningPipeEntity entity) { + return null; + } + }); // TODO test shit please remove } } diff --git a/src/main/java/gregtech/common/entities/MiningPipeEntity.java b/src/main/java/gregtech/common/entities/MiningPipeEntity.java new file mode 100644 index 00000000000..6fb555e4105 --- /dev/null +++ b/src/main/java/gregtech/common/entities/MiningPipeEntity.java @@ -0,0 +1,127 @@ +package gregtech.common.entities; + +import gregtech.api.metatileentity.MetaTileEntity; +import net.minecraft.block.material.EnumPushReaction; +import net.minecraft.entity.Entity; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.network.datasync.DataParameter; +import net.minecraft.network.datasync.DataSerializers; +import net.minecraft.network.datasync.EntityDataManager; +import net.minecraft.util.math.AxisAlignedBB; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ITeleporter; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** + * Section of the mining pipe. The pipe should be divided into multiple segments due to naive algorithm used in AABB + * checks making exceptionally large bounding boxes not work properly + */ +public class MiningPipeEntity extends Entity { + + private static final DataParameter Y = EntityDataManager.createKey(MiningPipeEntity.class, DataSerializers.VARINT); + private static final DataParameter LENGTH = EntityDataManager.createKey(MiningPipeEntity.class, DataSerializers.VARINT); + + @Nullable + private MetaTileEntity mte; + + private int prevLength = -1; + + public MiningPipeEntity(@Nonnull World world) { + super(world); + this.setSize(.5f, 0); + this.setNoGravity(true); + this.noClip = true; + this.preventEntitySpawning = true; + this.setEntityInvulnerable(true); + } + + public MiningPipeEntity(@Nonnull MetaTileEntity mte, BlockPos origin) { + this(mte.getWorld()); + this.mte = mte; + this.setPosition(origin.getX() + .5, origin.getY(), origin.getZ() + .5); + } + + public void setLength(int y, int length) { + this.dataManager.set(Y, y); + this.dataManager.set(LENGTH, length); + } + + @Override + protected void entityInit() { + this.dataManager.register(Y, 0); + this.dataManager.register(LENGTH, 0); + } + + @Override + public void onUpdate() { + if (!this.world.isRemote) { + if (this.mte == null || !this.mte.isValid()) { + setDead(); + return; + } + } + + int length = this.dataManager.get(LENGTH); + if (length != this.prevLength) { + this.prevLength = length; + if (!this.world.isRemote) { + setPosition(this.posX, this.dataManager.get(Y) - length, this.posZ); + } + setSize(.5f, length); + } + + this.firstUpdate = false; + } + + @Override + public boolean doesEntityNotTriggerPressurePlate() { + return true; + } + + @Override + public boolean canRenderOnFire() { + return false; + } + + @Override + public boolean canBeAttackedWithItem() { + return false; + } + + @Nonnull + @Override + public EnumPushReaction getPushReaction() { + return EnumPushReaction.IGNORE; + } + + @Nullable + @Override + public AxisAlignedBB getCollisionBox(@Nonnull Entity entity) { + return entity.getEntityBoundingBox(); // TODO maybe avoiding pushable check on the entity would allow pipes to stop stuffs like arrow? + } + + @Nullable + @Override + public AxisAlignedBB getCollisionBoundingBox() { + return this.getEntityBoundingBox(); + } + + @Override + public Entity changeDimension(int dim, @Nonnull ITeleporter teleporter) { + return this; + } + + @Override + protected void readEntityFromNBT(@Nonnull NBTTagCompound tag) {} + + @Override + protected void writeEntityToNBT(@Nonnull NBTTagCompound tag) {} + + // @Override + // public boolean shouldRenderInPass(int pass) { + // return false; + // } +} diff --git a/src/main/java/gregtech/common/metatileentities/miner/LargeMinerType.java b/src/main/java/gregtech/common/metatileentities/miner/LargeMinerType.java index 6df3a2454a5..816b45e22d6 100644 --- a/src/main/java/gregtech/common/metatileentities/miner/LargeMinerType.java +++ b/src/main/java/gregtech/common/metatileentities/miner/LargeMinerType.java @@ -24,4 +24,8 @@ public interface LargeMinerType { @SideOnly(Side.CLIENT) @Nonnull ICubeRenderer getBaseTexture(@Nullable IMultiblockPart sourcePart); + + @SideOnly(Side.CLIENT) + @Nonnull + MiningPipeModel getMiningPipeModel(); } diff --git a/src/main/java/gregtech/common/metatileentities/miner/LargeMinerTypes.java b/src/main/java/gregtech/common/metatileentities/miner/LargeMinerTypes.java index 7dcde438c0e..07da47a88ef 100644 --- a/src/main/java/gregtech/common/metatileentities/miner/LargeMinerTypes.java +++ b/src/main/java/gregtech/common/metatileentities/miner/LargeMinerTypes.java @@ -49,6 +49,16 @@ public ICubeRenderer getBaseTexture(@Nullable IMultiblockPart sourcePart) { }; } + @Nonnull + @Override + public MiningPipeModel getMiningPipeModel() { + return switch (this) { + case STEEL -> MiningPipeModels.STEEL; + case TITANIUM -> MiningPipeModels.TITANIUM; + case TUNGSTEN_STEEL -> MiningPipeModels.TUNGSTEN_STEEL; + }; + } + @Nonnull @Override @SideOnly(Side.CLIENT) diff --git a/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityLargeMiner.java b/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityLargeMiner.java index 3c002cbfcf7..8e442146635 100644 --- a/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityLargeMiner.java +++ b/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityLargeMiner.java @@ -29,6 +29,7 @@ import gregtech.api.recipes.RecipeMaps; import gregtech.api.util.GTUtility; import gregtech.client.renderer.ICubeRenderer; +import gregtech.client.renderer.texture.Textures; import gregtech.core.sound.GTSoundEvents; import net.minecraft.block.state.IBlockState; import net.minecraft.client.resources.I18n; @@ -46,6 +47,7 @@ import net.minecraft.util.text.event.ClickEvent; import net.minecraft.util.text.event.HoverEvent; import net.minecraft.world.World; +import net.minecraftforge.client.MinecraftForgeClient; import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.util.Constants; import net.minecraftforge.fluids.FluidStack; @@ -144,7 +146,7 @@ protected boolean drainEnergy(boolean simulate) { } protected boolean drainFluid(boolean simulate) { - int overclockAmount = getEnergyTier() - this.tier; + int overclockAmount = getEnergyTier() - this.tier + 1; int amount = this.drillingFluidConsumePerTick * overclockAmount; FluidStack drained = this.inputFluidInventory.drain(DrillingFluid.getFluid(amount), !simulate); return drained != null && drained.amount >= amount; @@ -175,14 +177,19 @@ public void renderMetaTileEntity(CCRenderState renderState, Matrix4 translation, super.renderMetaTileEntity(renderState, translation, pipeline); this.getFrontOverlay().renderOrientedState(renderState, translation, pipeline, getFrontFacing(), isActive(), isWorkingEnabled()); if (isStructureFormed()) { - EnumFacing back = getFrontFacing().getOpposite(); - MinerRenderHelper.renderPipe(getBaseTexture(null), this.minerLogic.getPipeLength(), renderState, - translation.translate(back.getXOffset(), back.getYOffset(), back.getZOffset()), pipeline); + EnumFacing f = getFrontFacing().getOpposite(); + Textures.PIPE_IN_OVERLAY.renderSided(EnumFacing.DOWN, renderState, + translation.copy().translate(f.getXOffset(), 0, f.getZOffset()), pipeline); } } @Override public void renderMetaTileEntity(double x, double y, double z, float partialTicks) { + if (MinecraftForgeClient.getRenderPass() == RENDER_PASS_NORMAL) { + EnumFacing f = getFrontFacing().getOpposite(); + MinerRenderHelper.renderPipe(x + f.getXOffset(), y, z + f.getZOffset(), getWorld(), getPos().offset(f), + this.minerLogic.getPipeLength(), this.type.getMiningPipeModel()); + } MiningArea previewArea = this.minerLogic.getPreviewArea(); if (previewArea != null) previewArea.renderMetaTileEntity(this, x, y, z, partialTicks); } @@ -195,12 +202,12 @@ public void renderMetaTileEntityFast(CCRenderState renderState, Matrix4 translat @Override public AxisAlignedBB getRenderBoundingBox() { - MiningArea previewArea = this.minerLogic.getPreviewArea(); - return previewArea != null ? previewArea.getRenderBoundingBox() : MinerUtil.EMPTY_AABB; + return this.minerLogic.getRenderBoundingBox(); } @Override public boolean shouldRenderInPass(int pass) { + if (pass == RENDER_PASS_NORMAL) return true; MiningArea previewArea = this.minerLogic.getPreviewArea(); return previewArea != null && previewArea.shouldRenderInPass(pass); } @@ -293,7 +300,7 @@ protected void addDisplayText(List textList) { ITextComponent hoverText; if (yLimit > 0) { value = new TextComponentString(String.format("%,d", yLimit)); - hoverText = new TextComponentTranslation("gregtech.machine.miner.display.y_limit.value_hover_tooltip", value); + hoverText = new TextComponentTranslation("gregtech.machine.miner.display.y_limit.value_hover_tooltip", value.createCopy()); } else { value = new TextComponentTranslation("gregtech.machine.miner.display.y_limit.no_value"); hoverText = new TextComponentTranslation("gregtech.machine.miner.display.y_limit.value_hover_tooltip.no_value"); diff --git a/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityMiner.java b/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityMiner.java index 3a4345808ad..63559c406f2 100644 --- a/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityMiner.java +++ b/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityMiner.java @@ -36,6 +36,7 @@ import net.minecraft.util.text.TextComponentTranslation; import net.minecraft.util.text.TextFormatting; import net.minecraft.world.World; +import net.minecraftforge.client.MinecraftForgeClient; import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; @@ -86,11 +87,13 @@ protected IItemHandlerModifiable createExportItemHandler() { public void renderMetaTileEntity(CCRenderState renderState, Matrix4 translation, IVertexOperation[] pipeline) { super.renderMetaTileEntity(renderState, translation, pipeline); Textures.MINER_OVERLAY.renderOrientedState(renderState, translation, pipeline, getFrontFacing(), minerLogic.isActive(), minerLogic.isWorkingEnabled()); - MinerRenderHelper.renderPipe(Textures.SOLID_STEEL_CASING, this.minerLogic.getPipeLength(), renderState, translation, pipeline); } @Override public void renderMetaTileEntity(double x, double y, double z, float partialTicks) { + if (MinecraftForgeClient.getRenderPass() == RENDER_PASS_NORMAL) { + MinerRenderHelper.renderPipe(x, y, z, getWorld(), getPos(), this.minerLogic.getPipeLength(), MiningPipeModels.STEEL); + } MiningArea previewArea = this.minerLogic.getPreviewArea(); if (previewArea != null) previewArea.renderMetaTileEntity(this, x, y, z, partialTicks); } @@ -103,12 +106,12 @@ public void renderMetaTileEntityFast(CCRenderState renderState, Matrix4 translat @Override public AxisAlignedBB getRenderBoundingBox() { - MiningArea previewArea = this.minerLogic.getPreviewArea(); - return previewArea != null ? previewArea.getRenderBoundingBox() : MinerUtil.EMPTY_AABB; + return this.minerLogic.getRenderBoundingBox(); } @Override public boolean shouldRenderInPass(int pass) { + if (pass == RENDER_PASS_NORMAL) return true; MiningArea previewArea = this.minerLogic.getPreviewArea(); return previewArea != null && previewArea.shouldRenderInPass(pass); } diff --git a/src/main/java/gregtech/common/metatileentities/miner/MinerLogic.java b/src/main/java/gregtech/common/metatileentities/miner/MinerLogic.java index 035e5dbd5cc..08da352dc1b 100644 --- a/src/main/java/gregtech/common/metatileentities/miner/MinerLogic.java +++ b/src/main/java/gregtech/common/metatileentities/miner/MinerLogic.java @@ -4,6 +4,7 @@ import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.util.BlockUtility; import gregtech.api.util.GTTransferUtils; +import gregtech.common.entities.MiningPipeEntity; import gregtech.common.metatileentities.miner.Miner.MinedBlockType; import net.minecraft.block.material.Material; import net.minecraft.block.state.IBlockState; @@ -12,6 +13,7 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.PacketBuffer; import net.minecraft.util.NonNullList; +import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos.MutableBlockPos; import net.minecraft.util.math.MathHelper; @@ -21,6 +23,8 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; +import java.util.ArrayList; +import java.util.List; import java.util.Objects; public class MinerLogic { @@ -55,12 +59,17 @@ public class MinerLogic { protected boolean rebuildMiningArea; // flag for area preview private boolean preview; + private int prevPipeLength; private boolean hasNotEnoughEnergy; // remote instances only, contains MiningArea instances deserialized from packet @Nullable private MiningArea previewArea; + @Nullable + private AxisAlignedBB renderBoundingBox; + + private final List pipeEntities = new ArrayList<>(); /** * Creates the general logic for all in-world ore block miners @@ -122,6 +131,20 @@ public MiningArea getPreviewArea() { return this.previewArea; } + @Nonnull + public AxisAlignedBB getRenderBoundingBox() { + if (this.renderBoundingBox == null) { + BlockPos origin = getOrigin(); + this.renderBoundingBox = new AxisAlignedBB( + origin.getX() + .25, origin.getY(), origin.getZ() + .25, + origin.getX() + .75, origin.getY() - pipeLength, origin.getZ() + .75); + if (this.previewArea != null) { + this.renderBoundingBox = this.previewArea.getRenderBoundingBox().union(this.renderBoundingBox); + } + } + return renderBoundingBox; + } + public boolean isAtWorkTick() { if (this.workFrequency == 1) return true; return this.mte.getOffsetTimer() % this.workFrequency == this.workTick; @@ -252,6 +275,40 @@ public void update() { rebuildMiningArea(); } + updateLogic(); + + if (this.prevPipeLength != this.pipeLength) { + this.prevPipeLength = this.pipeLength; + int pipeIndex = 0; + int y = this.getOrigin().getY(); + int yEnd = y - this.pipeLength; + + while (y > yEnd) { // divide segments every 16 blocks, aligned with Y position + int length = y % 16; + if (length == 0) length = 16; + + MiningPipeEntity entity = this.pipeEntities.size() > pipeIndex ? this.pipeEntities.get(pipeIndex) : null; + + if (entity == null || !entity.isEntityAlive()) { + entity = new MiningPipeEntity(this.mte, this.getOrigin()); + if (pipeIndex < this.pipeEntities.size()) this.pipeEntities.set(pipeIndex, entity); + else this.pipeEntities.add(entity); + this.mte.getWorld().spawnEntity(entity); + } + + entity.setLength(y, length); + + y -= length; + pipeIndex++; + } + + for (int i = this.pipeEntities.size() - 1; i >= pipeIndex; i--) { + this.pipeEntities.remove(i).setDead(); + } + } + } + + protected void updateLogic() { if (this.mte.drainMiningResources(MinedBlockType.ORE, true, true)) { this.hasNotEnoughEnergy = false; } else { @@ -284,10 +341,11 @@ protected void mine(@Nonnull MiningArea miningArea) { IBlockState state = world.getBlockState(pos); boolean isOrigin = pos.getX() == origin.getX() && pos.getZ() == origin.getZ(); - // skip air, unbreakable blocks & TE blocks + // skip air, unbreakable blocks, TE blocks & liquids if (state.getMaterial() == Material.AIR || state.getBlockHardness(world, pos) < 0 || - state.getBlock().hasTileEntity(state)) { + state.getBlock().hasTileEntity(state) || + state.getMaterial().isLiquid()) { if (isOrigin) { // TODO liquid tile check? // center block (where mining pipes goes in) can be skipped by this, it'll probably look kind of janky // but it's 100x better than voiding bedrock @@ -295,6 +353,8 @@ protected void mine(@Nonnull MiningArea miningArea) { return; } setPipeLength(this.pipeLength + 1); + // TODO don't spam pipe length packet if it goes down at once + // uhh maybe add some delay, yeah that'd be good } miningArea.nextBlock(); continue; @@ -358,6 +418,7 @@ protected void writePreviewUpdatePacket(@Nonnull PacketBuffer buffer) { protected void readPreviewUpdatePacket(@Nonnull PacketBuffer buffer) { this.previewArea = buffer.readBoolean() ? readPreviewArea(buffer) : null; + this.renderBoundingBox = null; } @Nonnull @@ -444,6 +505,7 @@ public void receiveInitialSyncData(@Nonnull PacketBuffer buf) { this.done = buf.readBoolean(); this.active = buf.readBoolean(); readPreviewUpdatePacket(buf); + this.renderBoundingBox = null; } /** @@ -453,7 +515,7 @@ public void receiveCustomData(int dataId, @Nonnull PacketBuffer buf) { switch (dataId) { case GregtechDataCodes.PUMP_HEAD_LEVEL -> { this.pipeLength = buf.readVarInt(); - this.mte.scheduleRenderUpdate(); + this.renderBoundingBox = null; } case GregtechDataCodes.WORKING_ENABLED -> { this.workingEnabled = buf.readBoolean(); @@ -461,6 +523,7 @@ public void receiveCustomData(int dataId, @Nonnull PacketBuffer buf) { } case GregtechDataCodes.MINER_UPDATE_PREVIEW -> { readPreviewUpdatePacket(buf); + this.renderBoundingBox = null; } case GregtechDataCodes.MINER_UPDATE_ACTIVE -> { this.active = buf.readBoolean(); diff --git a/src/main/java/gregtech/common/metatileentities/miner/MinerRenderHelper.java b/src/main/java/gregtech/common/metatileentities/miner/MinerRenderHelper.java index 72efcba3464..d0d101965a8 100644 --- a/src/main/java/gregtech/common/metatileentities/miner/MinerRenderHelper.java +++ b/src/main/java/gregtech/common/metatileentities/miner/MinerRenderHelper.java @@ -1,12 +1,7 @@ package gregtech.common.metatileentities.miner; -import codechicken.lib.render.CCRenderState; -import codechicken.lib.render.pipeline.IVertexOperation; -import codechicken.lib.vec.Cuboid6; -import codechicken.lib.vec.Matrix4; import gregtech.api.util.GTUtility; -import gregtech.client.renderer.ICubeRenderer; -import gregtech.client.renderer.texture.Textures; +import net.minecraft.block.state.IBlockState; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.BufferBuilder; import net.minecraft.client.renderer.GlStateManager; @@ -15,11 +10,11 @@ import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.culling.ClippingHelperImpl; import net.minecraft.client.renderer.vertex.DefaultVertexFormats; -import net.minecraft.entity.Entity; -import net.minecraft.util.EnumFacing; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.BlockPos.MutableBlockPos; +import net.minecraft.world.World; import org.lwjgl.opengl.GL11; import javax.annotation.Nonnull; @@ -30,11 +25,11 @@ public class MinerRenderHelper { private MinerRenderHelper() {} public static final ResourceLocation MINER_AREA_PREVIEW_TEXTURE = GTUtility.gregtechId("textures/fx/miner_area_preview.png"); - private static final Cuboid6 PIPE_CUBOID = new Cuboid6(4 / 16.0, 0.0, 4 / 16.0, 12 / 16.0, 1.0, 12 / 16.0); private static final long TEXTURE_WRAP_INTERVAL_NANOSECONDS = 3_000_000_000L; private static final ClippingHelperImpl clippingHelper = new ClippingHelperImpl(); + private static final Vector3f[] nearPlaneVectors = { new Vector3f(), new Vector3f(), new Vector3f(), new Vector3f() }; @@ -46,17 +41,49 @@ private MinerRenderHelper() {} private static final SATTestResult sat = new SATTestResult(); private static final Vector3f vec1 = new Vector3f(), vec2 = new Vector3f(); - /** - * Draws mining pipe with given length. This method modifies {@code translation} argument's state. - */ - public static void renderPipe(@Nonnull ICubeRenderer pipeRenderer, int pipeLength, - @Nonnull CCRenderState renderState, @Nonnull Matrix4 translation, - @Nonnull IVertexOperation[] pipeline) { - Textures.PIPE_IN_OVERLAY.renderSided(EnumFacing.DOWN, renderState, translation, pipeline); + private static int prevFrameIndex = -1; + + private static void updateFrustum() { + int index = Minecraft.getMinecraft().frameTimer.getIndex(); + if (prevFrameIndex == index) return; + prevFrameIndex = index; + clippingHelper.init(); + } + + public static void renderPipe(double x, double y, double z, + @Nonnull World world, @Nonnull BlockPos pos, + int pipeLength, @Nonnull MiningPipeModel miningPipeModel) { + if (pipeLength <= 0) return; + updateFrustum(); + + Minecraft mc = Minecraft.getMinecraft(); + MutableBlockPos mpos = new MutableBlockPos(pos); + Tessellator t = Tessellator.getInstance(); + BufferBuilder buffer = t.getBuffer(); + + GlStateManager.disableLighting(); + GlStateManager.shadeModel(Minecraft.isAmbientOcclusionEnabled() ? GL11.GL_SMOOTH : GL11.GL_FLAT); + GlStateManager.bindTexture(mc.getTextureMapBlocks().getGlTextureId()); + buffer.setTranslation(x - pos.getX(), y - pos.getY(), z - pos.getZ()); + mpos.setY(mpos.getY()); + buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK); for (int i = 0; i < pipeLength; i++) { - translation.translate(0.0, -1.0, 0.0); - pipeRenderer.render(renderState, translation, pipeline, PIPE_CUBOID); + mpos.setY(mpos.getY() - 1); + // me epicly dodging AABB allocations by plugging in primitive values directly (very epic) + if (!clippingHelper.isBoxInFrustum( + mpos.getX() + .25 + x - pos.getX(), mpos.getY() + y - pos.getY(), mpos.getZ() + .25 + z - pos.getZ(), + mpos.getX() + .75 + x - pos.getX(), mpos.getY() + 1 + y - pos.getY(), mpos.getZ() + .75 + z - pos.getZ())) { + continue; + } + + IBlockState state = world.getBlockState(mpos); + mc.blockRenderDispatcher.getBlockModelRenderer().renderModel(world, + i == (pipeLength - 1) ? miningPipeModel.getBottomModel() : miningPipeModel.getBaseModel(), + state, mpos, buffer, false); } + buffer.setTranslation(0, 0, 0); + t.draw(); + GlStateManager.enableLighting(); } /** @@ -77,6 +104,8 @@ public static void renderAreaPreview(@Nonnull AxisAlignedBB box, @Nonnull BlockP double minY = Math.max(0, box.minY) + y - pos.getY(), maxY = box.maxY + y - pos.getY(); double minZ = box.minZ + z - pos.getZ(), maxZ = box.maxZ + z - pos.getZ(); + boolean isBoxClippingThroughCamera = isBoxClippingThroughCamera(minX, maxX, minY, maxY, minZ, maxZ); + // texture UVs double texOffset = (System.nanoTime() % TEXTURE_WRAP_INTERVAL_NANOSECONDS) / (double) (TEXTURE_WRAP_INTERVAL_NANOSECONDS); @@ -94,18 +123,6 @@ public static void renderAreaPreview(@Nonnull AxisAlignedBB box, @Nonnull BlockP double vMin2 = vMin - dy; double vMin3 = vMin2 + dz; - Entity renderViewEntity = Minecraft.getMinecraft().getRenderViewEntity(); - double eyeHeight = renderViewEntity != null ? renderViewEntity.getEyeHeight() : 0; // why :((((( - // the check is not perfect, there's a small but noticeable area around outer parts where the algo - // doesn't detect the box clipping through the camera - // but I have already spent significant portion of my live implementing this alone so I'll just eat my loss and - // inflate the box a bit to compensate - final double expand = 3 / 16.0; - boolean isBoxClippingThroughCamera = isBoxClippingThroughCamera( - minX - expand, maxX + expand, - minY - eyeHeight * 2 - expand, maxY - eyeHeight * 2 + expand, - minZ - expand, maxZ + expand); - GlStateManager.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_REPEAT); GlStateManager.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_REPEAT); Minecraft.getMinecraft().getTextureManager().bindTexture(MINER_AREA_PREVIEW_TEXTURE); @@ -189,7 +206,7 @@ private static void v(BufferBuilder buffer, double x, double y, double z, double public static boolean isBoxClippingThroughCamera(double minX, double maxX, double minY, double maxY, double minZ, double maxZ) { - clippingHelper.init(); + updateFrustum(); // obtain 4 vertices of near plane rectangle // just halt and return false as a fallback, theoretically possible if view matrix got somehow borked @@ -254,7 +271,7 @@ private static boolean calculateIntersectingPoint(int vectorIndex, int plane1, i // idk if (!Float.isFinite(x) || !Float.isFinite(y) || !Float.isFinite(z)) return false; - nearPlaneVectors[vectorIndex].set(x, y, z); + nearPlaneVectors[vectorIndex].set(-x, -y, -z); return true; } diff --git a/src/main/java/gregtech/common/metatileentities/miner/MiningArea.java b/src/main/java/gregtech/common/metatileentities/miner/MiningArea.java index d0e200a20fb..f99920d81b4 100644 --- a/src/main/java/gregtech/common/metatileentities/miner/MiningArea.java +++ b/src/main/java/gregtech/common/metatileentities/miner/MiningArea.java @@ -51,7 +51,7 @@ default void renderMetaTileEntity(@Nonnull MetaTileEntity mte, double x, double AxisAlignedBB getRenderBoundingBox(); default boolean shouldRenderInPass(int pass) { - return pass == IFastRenderMetaTileEntity.RENDER_PASS_NORMAL; + return pass == IFastRenderMetaTileEntity.RENDER_PASS_TRANSLUCENT; } /** diff --git a/src/main/java/gregtech/common/metatileentities/miner/MiningPipeModel.java b/src/main/java/gregtech/common/metatileentities/miner/MiningPipeModel.java new file mode 100644 index 00000000000..6be69d2d4cb --- /dev/null +++ b/src/main/java/gregtech/common/metatileentities/miner/MiningPipeModel.java @@ -0,0 +1,112 @@ +package gregtech.common.metatileentities.miner; + +import com.google.common.base.Suppliers; +import gregtech.api.GTValues; +import gregtech.api.util.GTLog; +import gregtech.api.util.GTUtility; +import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; +import net.minecraft.client.renderer.block.model.IBakedModel; +import net.minecraft.client.renderer.vertex.DefaultVertexFormats; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.client.event.ModelBakeEvent; +import net.minecraftforge.client.event.TextureStitchEvent; +import net.minecraftforge.client.model.IModel; +import net.minecraftforge.client.model.ModelLoader; +import net.minecraftforge.client.model.ModelLoaderRegistry; +import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.relauncher.Side; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import java.util.Map; +import java.util.function.Supplier; + +@Mod.EventBusSubscriber(modid = GTValues.MODID, value = Side.CLIENT) +public final class MiningPipeModel { + + private static final Map MINING_PIPE_MODELS = new Object2ObjectOpenHashMap<>(); + private static final Supplier MISSING_MODEL_MEMOIZE = Suppliers.memoize(() -> { + IModel model = ModelLoaderRegistry.getMissingModel(); + return model.bake(model.getDefaultState(), DefaultVertexFormats.ITEM, ModelLoader.defaultTextureGetter()); + }); + + @Nonnull + public static MiningPipeModel register(@Nonnull String type) { + return MINING_PIPE_MODELS.computeIfAbsent(type, MiningPipeModel::new); + } + + @Nonnull + public final String type; + + @Nullable + private IBakedModel baseModel; + @Nullable + private IModel unbakedBaseModel; + @Nullable + private IBakedModel bottomModel; + @Nullable + private IModel unbakedBottomModel; + + private MiningPipeModel(@Nonnull String type) { + this.type = type; + } + + @Nonnull + public IBakedModel getBaseModel() { + return this.baseModel != null ? this.baseModel : MISSING_MODEL_MEMOIZE.get(); + } + + @Nonnull + public IBakedModel getBottomModel() { + return this.bottomModel != null ? this.bottomModel : MISSING_MODEL_MEMOIZE.get(); + } + + @Override + public String toString() { + return "MiningPipeModel{type='" + type + "'}"; + } + + @SubscribeEvent + public static void onTextureStitch(TextureStitchEvent.Pre event) { + for (MiningPipeModel miningPipe : MINING_PIPE_MODELS.values()) { + miningPipe.unbakedBaseModel = loadModel(event, GTUtility.gregtechId("block/mining_pipe/" + miningPipe.type)); + miningPipe.unbakedBottomModel = loadModel(event, GTUtility.gregtechId("block/mining_pipe/" + miningPipe.type + "_bottom")); + } + } + + @Nullable + private static IModel loadModel(TextureStitchEvent.Pre event, ResourceLocation modelLocation) { + IModel model; + try { + model = ModelLoaderRegistry.getModel(modelLocation); + } catch (Exception e) { + GTLog.logger.error("Failed to load material model {}:", modelLocation, e); + return null; + } + for (ResourceLocation texture : model.getTextures()) { + event.getMap().registerSprite(texture); + } + return model; + } + + @SubscribeEvent + public static void onModelBake(ModelBakeEvent event) { + for (MiningPipeModel miningPipe : MINING_PIPE_MODELS.values()) { + if (miningPipe.unbakedBaseModel != null) { + miningPipe.baseModel = miningPipe.unbakedBaseModel.bake( + miningPipe.unbakedBaseModel.getDefaultState(), + DefaultVertexFormats.ITEM, + ModelLoader.defaultTextureGetter()); + miningPipe.unbakedBaseModel = null; + } + if (miningPipe.unbakedBottomModel != null) { + miningPipe.bottomModel = miningPipe.unbakedBottomModel.bake( + miningPipe.unbakedBottomModel.getDefaultState(), + DefaultVertexFormats.ITEM, + ModelLoader.defaultTextureGetter()); + miningPipe.unbakedBottomModel = null; + } + } + } +} diff --git a/src/main/java/gregtech/common/metatileentities/miner/MiningPipeModels.java b/src/main/java/gregtech/common/metatileentities/miner/MiningPipeModels.java new file mode 100644 index 00000000000..8358330fc18 --- /dev/null +++ b/src/main/java/gregtech/common/metatileentities/miner/MiningPipeModels.java @@ -0,0 +1,13 @@ +package gregtech.common.metatileentities.miner; + +public class MiningPipeModels { + + private MiningPipeModels() {} + + public static void init() {} + + public static final MiningPipeModel BRONZE = MiningPipeModel.register("bronze"); + public static final MiningPipeModel STEEL = MiningPipeModel.register("steel"); + public static final MiningPipeModel TITANIUM = MiningPipeModel.register("titanium"); + public static final MiningPipeModel TUNGSTEN_STEEL = MiningPipeModel.register("tungsten_steel"); +} diff --git a/src/main/java/gregtech/common/metatileentities/miner/MultiblockMinerLogic.java b/src/main/java/gregtech/common/metatileentities/miner/MultiblockMinerLogic.java index 66b74867195..d185056be77 100644 --- a/src/main/java/gregtech/common/metatileentities/miner/MultiblockMinerLogic.java +++ b/src/main/java/gregtech/common/metatileentities/miner/MultiblockMinerLogic.java @@ -177,7 +177,6 @@ public NBTTagCompound writeToNBT(@Nonnull NBTTagCompound data) { @Override public void readFromNBT(@Nonnull NBTTagCompound data) { - super.readFromNBT(data); this.chunkMode = data.getBoolean("chunkMode") || data.getBoolean("isChunkMode"); this.silkTouchMode = data.getBoolean("silkTouch") || data.getBoolean("isSilkTouchMode"); this.currentChunkDiameter = data.hasKey("currentChunkDiameter", Constants.NBT.TAG_INT) ? @@ -186,5 +185,6 @@ public void readFromNBT(@Nonnull NBTTagCompound data) { this.yLimit = Math.max(0, data.getInteger("yLimit")); this.repeat = data.getBoolean("repeat"); this.replaceOreWithAir = data.getBoolean("replaceWithAir"); + super.readFromNBT(data); } } diff --git a/src/main/java/gregtech/common/metatileentities/miner/SimpleMiningArea.java b/src/main/java/gregtech/common/metatileentities/miner/SimpleMiningArea.java index bf419cede3e..78d3fa63bd6 100644 --- a/src/main/java/gregtech/common/metatileentities/miner/SimpleMiningArea.java +++ b/src/main/java/gregtech/common/metatileentities/miner/SimpleMiningArea.java @@ -1,17 +1,19 @@ package gregtech.common.metatileentities.miner; -import gregtech.api.metatileentity.IFastRenderMetaTileEntity; import gregtech.api.metatileentity.MetaTileEntity; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.PacketBuffer; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos.MutableBlockPos; +import net.minecraftforge.client.MinecraftForgeClient; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; import javax.annotation.Nonnull; import javax.annotation.Nullable; +import static gregtech.api.metatileentity.IFastRenderMetaTileEntity.RENDER_PASS_TRANSLUCENT; + /** * Simple implementation of {@link MiningArea}. Defines cube-shaped mining area with simple iteration logic. */ @@ -91,12 +93,9 @@ public void reset() { @Override @SideOnly(Side.CLIENT) public void renderMetaTileEntity(@Nonnull MetaTileEntity mte, double x, double y, double z, float partialTicks) { - MinerRenderHelper.renderAreaPreview(this.getRenderBoundingBox(), mte.getPos(), x, y, z); - } - - @Override - public boolean shouldRenderInPass(int pass) { - return pass == IFastRenderMetaTileEntity.RENDER_PASS_TRANSLUCENT; + if (MinecraftForgeClient.getRenderPass() == RENDER_PASS_TRANSLUCENT) { + MinerRenderHelper.renderAreaPreview(this.getRenderBoundingBox(), mte.getPos(), x, y, z); + } } @Nonnull diff --git a/src/main/java/gregtech/common/metatileentities/miner/SteamMiner.java b/src/main/java/gregtech/common/metatileentities/miner/SteamMiner.java index c2bbf1652e5..76214c74e0a 100644 --- a/src/main/java/gregtech/common/metatileentities/miner/SteamMiner.java +++ b/src/main/java/gregtech/common/metatileentities/miner/SteamMiner.java @@ -96,11 +96,11 @@ public void renderMetaTileEntity(CCRenderState renderState, Matrix4 translation, Textures.STEAM_CASING_BRONZE.render(renderState, translation, colouredPipeline); // TODO replace top with vent, in standalone mod Textures.MINER_OVERLAY.renderOrientedState(renderState, translation, pipeline, getFrontFacing(), minerLogic.isActive(), minerLogic.isWorkingEnabled()); - MinerRenderHelper.renderPipe(Textures.BRONZE_PLATED_BRICKS, this.minerLogic.getPipeLength(), renderState, translation, pipeline); } @Override public void renderMetaTileEntity(double x, double y, double z, float partialTicks) { + MinerRenderHelper.renderPipe(x, y, z, getWorld(), getPos(), this.minerLogic.getPipeLength(), MiningPipeModels.BRONZE); MiningArea previewArea = this.minerLogic.getPreviewArea(); if (previewArea != null) previewArea.renderMetaTileEntity(this, x, y, z, partialTicks); } @@ -113,12 +113,12 @@ public void renderMetaTileEntityFast(CCRenderState renderState, Matrix4 translat @Override public AxisAlignedBB getRenderBoundingBox() { - MiningArea previewArea = this.minerLogic.getPreviewArea(); - return previewArea != null ? previewArea.getRenderBoundingBox() : MinerUtil.EMPTY_AABB; + return this.minerLogic.getRenderBoundingBox(); } @Override public boolean shouldRenderInPass(int pass) { + if (pass == RENDER_PASS_NORMAL) return true; MiningArea previewArea = this.minerLogic.getPreviewArea(); return previewArea != null && previewArea.shouldRenderInPass(pass); } diff --git a/src/main/resources/assets/gregtech/models/block/mining_pipe/base.json b/src/main/resources/assets/gregtech/models/block/mining_pipe/base.json new file mode 100644 index 00000000000..51906fa69f2 --- /dev/null +++ b/src/main/resources/assets/gregtech/models/block/mining_pipe/base.json @@ -0,0 +1,18 @@ +{ + "parent": "block/block", + "textures": { + "particle": "#texture" + }, + "elements": [ + { + "from": [ 4, 0, 4], + "to": [12, 16, 12], + "faces": { + "north": { "texture": "#texture", "tintindex": 0 }, + "east": { "texture": "#texture", "tintindex": 0 }, + "south": { "texture": "#texture", "tintindex": 0 }, + "west": { "texture": "#texture", "tintindex": 0 } + } + } + ] +} diff --git a/src/main/resources/assets/gregtech/models/block/mining_pipe/base_bottom.json b/src/main/resources/assets/gregtech/models/block/mining_pipe/base_bottom.json new file mode 100644 index 00000000000..39e4cd64cb7 --- /dev/null +++ b/src/main/resources/assets/gregtech/models/block/mining_pipe/base_bottom.json @@ -0,0 +1,19 @@ +{ + "parent": "block/block", + "textures": { + "particle": "#texture" + }, + "elements": [ + { + "from": [ 4, 0, 4], + "to": [12, 16, 12], + "faces": { + "down": { "texture": "#texture", "tintindex": 0, "cullface": "down" }, + "north": { "texture": "#texture", "tintindex": 0 }, + "east": { "texture": "#texture", "tintindex": 0 }, + "south": { "texture": "#texture", "tintindex": 0 }, + "west": { "texture": "#texture", "tintindex": 0 } + } + } + ] +} diff --git a/src/main/resources/assets/gregtech/models/block/mining_pipe/bronze.json b/src/main/resources/assets/gregtech/models/block/mining_pipe/bronze.json new file mode 100644 index 00000000000..cd6e6c4826e --- /dev/null +++ b/src/main/resources/assets/gregtech/models/block/mining_pipe/bronze.json @@ -0,0 +1,6 @@ +{ + "parent": "gregtech:block/mining_pipe/base", + "textures": { + "texture": "gregtech:blocks/casings/solid/machine_bronze_plated_bricks" + } +} diff --git a/src/main/resources/assets/gregtech/models/block/mining_pipe/bronze_bottom.json b/src/main/resources/assets/gregtech/models/block/mining_pipe/bronze_bottom.json new file mode 100644 index 00000000000..1042660f918 --- /dev/null +++ b/src/main/resources/assets/gregtech/models/block/mining_pipe/bronze_bottom.json @@ -0,0 +1,6 @@ +{ + "parent": "gregtech:block/mining_pipe/base_bottom", + "textures": { + "texture": "gregtech:blocks/casings/solid/machine_bronze_plated_bricks" + } +} diff --git a/src/main/resources/assets/gregtech/models/block/mining_pipe/steel.json b/src/main/resources/assets/gregtech/models/block/mining_pipe/steel.json new file mode 100644 index 00000000000..f4dfd6084ad --- /dev/null +++ b/src/main/resources/assets/gregtech/models/block/mining_pipe/steel.json @@ -0,0 +1,6 @@ +{ + "parent": "gregtech:block/mining_pipe/base", + "textures": { + "texture": "gregtech:blocks/casings/solid/machine_casing_solid_steel" + } +} diff --git a/src/main/resources/assets/gregtech/models/block/mining_pipe/steel_bottom.json b/src/main/resources/assets/gregtech/models/block/mining_pipe/steel_bottom.json new file mode 100644 index 00000000000..bcaa69e6a56 --- /dev/null +++ b/src/main/resources/assets/gregtech/models/block/mining_pipe/steel_bottom.json @@ -0,0 +1,6 @@ +{ + "parent": "gregtech:block/mining_pipe/base_bottom", + "textures": { + "texture": "gregtech:blocks/casings/solid/machine_casing_solid_steel" + } +} diff --git a/src/main/resources/assets/gregtech/models/block/mining_pipe/titanium.json b/src/main/resources/assets/gregtech/models/block/mining_pipe/titanium.json new file mode 100644 index 00000000000..da90a41d088 --- /dev/null +++ b/src/main/resources/assets/gregtech/models/block/mining_pipe/titanium.json @@ -0,0 +1,6 @@ +{ + "parent": "gregtech:block/mining_pipe/base", + "textures": { + "texture": "gregtech:blocks/casings/solid/machine_casing_stable_titanium" + } +} diff --git a/src/main/resources/assets/gregtech/models/block/mining_pipe/titanium_bottom.json b/src/main/resources/assets/gregtech/models/block/mining_pipe/titanium_bottom.json new file mode 100644 index 00000000000..f06256d6ec5 --- /dev/null +++ b/src/main/resources/assets/gregtech/models/block/mining_pipe/titanium_bottom.json @@ -0,0 +1,6 @@ +{ + "parent": "gregtech:block/mining_pipe/base_bottom", + "textures": { + "texture": "gregtech:blocks/casings/solid/machine_casing_stable_titanium" + } +} diff --git a/src/main/resources/assets/gregtech/models/block/mining_pipe/tungsten_steel.json b/src/main/resources/assets/gregtech/models/block/mining_pipe/tungsten_steel.json new file mode 100644 index 00000000000..56c4704db8a --- /dev/null +++ b/src/main/resources/assets/gregtech/models/block/mining_pipe/tungsten_steel.json @@ -0,0 +1,6 @@ +{ + "parent": "gregtech:block/mining_pipe/base", + "textures": { + "texture": "gregtech:blocks/casings/solid/machine_casing_robust_tungstensteel" + } +} diff --git a/src/main/resources/assets/gregtech/models/block/mining_pipe/tungsten_steel_bottom.json b/src/main/resources/assets/gregtech/models/block/mining_pipe/tungsten_steel_bottom.json new file mode 100644 index 00000000000..235af1a2697 --- /dev/null +++ b/src/main/resources/assets/gregtech/models/block/mining_pipe/tungsten_steel_bottom.json @@ -0,0 +1,6 @@ +{ + "parent": "gregtech:block/mining_pipe/base_bottom", + "textures": { + "texture": "gregtech:blocks/casings/solid/machine_casing_robust_tungstensteel" + } +} From fad4158cf245154f3c784241919bd3f06e182f1d Mon Sep 17 00:00:00 2001 From: Tictim Date: Mon, 13 Nov 2023 23:19:50 +0900 Subject: [PATCH 08/27] Medium sized refactor --- .../renderer/handler/MiningPipeRenderer.java | 47 ++++++++ .../java/gregtech/common/MetaEntities.java | 16 +-- .../common/entities/MiningPipeEntity.java | 90 ++++++++------ .../miner/MetaTileEntityLargeMiner.java | 25 ++-- .../miner/MetaTileEntityMiner.java | 15 ++- .../common/metatileentities/miner/Miner.java | 8 +- .../metatileentities/miner/MinerLogic.java | 83 +++---------- .../miner/MinerRenderHelper.java | 42 ++++--- .../miner/MiningPipeModel.java | 104 +--------------- .../miner/MiningPipeModels.java | 8 +- .../miner/SimpleMiningPipeModel.java | 114 ++++++++++++++++++ .../metatileentities/miner/SteamMiner.java | 12 +- 12 files changed, 310 insertions(+), 254 deletions(-) create mode 100644 src/main/java/gregtech/client/renderer/handler/MiningPipeRenderer.java create mode 100644 src/main/java/gregtech/common/metatileentities/miner/SimpleMiningPipeModel.java diff --git a/src/main/java/gregtech/client/renderer/handler/MiningPipeRenderer.java b/src/main/java/gregtech/client/renderer/handler/MiningPipeRenderer.java new file mode 100644 index 00000000000..ae93c9aada3 --- /dev/null +++ b/src/main/java/gregtech/client/renderer/handler/MiningPipeRenderer.java @@ -0,0 +1,47 @@ +package gregtech.client.renderer.handler; + +import gregtech.common.entities.MiningPipeEntity; +import gregtech.common.metatileentities.miner.MinerRenderHelper; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.entity.Render; +import net.minecraft.client.renderer.entity.RenderManager; +import net.minecraft.util.ResourceLocation; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +public class MiningPipeRenderer extends Render> { + + @SuppressWarnings({"unchecked", "rawtypes"}) + public static Render iHateJavaGenerics(RenderManager manager) { + return (Render) (Render) new MiningPipeRenderer(manager); + } + + public MiningPipeRenderer(RenderManager manager) { + super(manager); + + this.shadowSize = 0; + } + + @Override + public void doRender(@Nonnull MiningPipeEntity entity, double x, double y, double z, float entityYaw, float partialTicks) { + boolean renderOutlines = this.renderOutlines; + if (renderOutlines) { + GlStateManager.enableColorMaterial(); + GlStateManager.enableOutlineMode(this.getTeamColor(entity)); + } + + MinerRenderHelper.renderPipe(x, y, z, partialTicks, entity); + + if (renderOutlines) { + GlStateManager.disableOutlineMode(); + GlStateManager.disableColorMaterial(); + } + } + + @Nullable + @Override + protected ResourceLocation getEntityTexture(@Nonnull MiningPipeEntity entity) { + return null; + } +} diff --git a/src/main/java/gregtech/common/MetaEntities.java b/src/main/java/gregtech/common/MetaEntities.java index 14605588071..ebd28274101 100644 --- a/src/main/java/gregtech/common/MetaEntities.java +++ b/src/main/java/gregtech/common/MetaEntities.java @@ -4,29 +4,25 @@ import gregtech.api.util.GTUtility; import gregtech.client.renderer.handler.DynamiteRenderer; import gregtech.client.renderer.handler.GTBoatRenderer; +import gregtech.client.renderer.handler.MiningPipeRenderer; import gregtech.client.renderer.handler.PortalRenderer; import gregtech.common.entities.DynamiteEntity; import gregtech.common.entities.GTBoatEntity; import gregtech.common.entities.MiningPipeEntity; import gregtech.common.entities.PortalEntity; import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.entity.Render; -import net.minecraft.util.ResourceLocation; import net.minecraftforge.fml.client.registry.RenderingRegistry; import net.minecraftforge.fml.common.registry.EntityRegistry; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - public class MetaEntities { public static void init() { EntityRegistry.registerModEntity(GTUtility.gregtechId("dynamite"), DynamiteEntity.class, "Dynamite", 1, GregTechAPI.instance, 64, 3, true); EntityRegistry.registerModEntity(GTUtility.gregtechId("gtportal"), PortalEntity.class, "GTPortal", 2, GregTechAPI.instance, 64, 5, true); EntityRegistry.registerModEntity(GTUtility.gregtechId("gtboat"), GTBoatEntity.class, "GTBoat", 3, GregTechAPI.instance, 64, 2, true); - EntityRegistry.registerModEntity(GTUtility.gregtechId("mining_pipe"), MiningPipeEntity.class, "MiningPipe", 4, GregTechAPI.instance, 64, 5, false); + EntityRegistry.registerModEntity(GTUtility.gregtechId("mining_pipe"), MiningPipeEntity.class, "MiningPipe", 4, GregTechAPI.instance, 0, 2, false); } @SideOnly(Side.CLIENT) @@ -34,12 +30,6 @@ public static void initRenderers() { RenderingRegistry.registerEntityRenderingHandler(DynamiteEntity.class, manager -> new DynamiteRenderer(manager, Minecraft.getMinecraft().getRenderItem())); RenderingRegistry.registerEntityRenderingHandler(PortalEntity.class, PortalRenderer::new); RenderingRegistry.registerEntityRenderingHandler(GTBoatEntity.class, GTBoatRenderer::new); - RenderingRegistry.registerEntityRenderingHandler(MiningPipeEntity.class, manager -> new Render<>(manager) { - @Nullable - @Override - protected ResourceLocation getEntityTexture(@Nonnull MiningPipeEntity entity) { - return null; - } - }); // TODO test shit please remove + RenderingRegistry.registerEntityRenderingHandler(MiningPipeEntity.class, MiningPipeRenderer::iHateJavaGenerics); } } diff --git a/src/main/java/gregtech/common/entities/MiningPipeEntity.java b/src/main/java/gregtech/common/entities/MiningPipeEntity.java index 6fb555e4105..7ea9e3a4fc8 100644 --- a/src/main/java/gregtech/common/entities/MiningPipeEntity.java +++ b/src/main/java/gregtech/common/entities/MiningPipeEntity.java @@ -1,12 +1,10 @@ package gregtech.common.entities; import gregtech.api.metatileentity.MetaTileEntity; +import gregtech.common.metatileentities.miner.Miner; import net.minecraft.block.material.EnumPushReaction; import net.minecraft.entity.Entity; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.network.datasync.DataParameter; -import net.minecraft.network.datasync.DataSerializers; -import net.minecraft.network.datasync.EntityDataManager; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; @@ -16,60 +14,85 @@ import javax.annotation.Nullable; /** - * Section of the mining pipe. The pipe should be divided into multiple segments due to naive algorithm used in AABB + * Section of the mining pipe. The pipe should be divided into multiple segments due to a naive algorithm used in AABB * checks making exceptionally large bounding boxes not work properly */ -public class MiningPipeEntity extends Entity { - - private static final DataParameter Y = EntityDataManager.createKey(MiningPipeEntity.class, DataSerializers.VARINT); - private static final DataParameter LENGTH = EntityDataManager.createKey(MiningPipeEntity.class, DataSerializers.VARINT); +public class MiningPipeEntity extends Entity { @Nullable - private MetaTileEntity mte; + private final MTE mte; + private final BlockPos origin; + + private int y; + private int length; + private boolean end; private int prevLength = -1; - public MiningPipeEntity(@Nonnull World world) { + protected MiningPipeEntity(@Nonnull World world, @Nullable MTE mte, @Nonnull BlockPos origin) { super(world); this.setSize(.5f, 0); this.setNoGravity(true); this.noClip = true; this.preventEntitySpawning = true; this.setEntityInvulnerable(true); - } - public MiningPipeEntity(@Nonnull MetaTileEntity mte, BlockPos origin) { - this(mte.getWorld()); this.mte = mte; - this.setPosition(origin.getX() + .5, origin.getY(), origin.getZ() + .5); + this.origin = origin; } - public void setLength(int y, int length) { - this.dataManager.set(Y, y); - this.dataManager.set(LENGTH, length); + @SuppressWarnings("unused") + public MiningPipeEntity(@Nonnull World world) { + this(world, null, BlockPos.ORIGIN); } - @Override - protected void entityInit() { - this.dataManager.register(Y, 0); - this.dataManager.register(LENGTH, 0); + public MiningPipeEntity(@Nonnull MTE mte, @Nonnull BlockPos origin) { + this(mte.getWorld(), mte, origin.toImmutable()); + this.setPosition(this.origin.getX() + .5, this.origin.getY(), this.origin.getZ() + .5); + } + + @Nullable + public MTE getMTE() { + return mte; + } + + @Nonnull + public BlockPos getOrigin() { + return origin; + } + + public int getY() { + return this.y; + } + + public int getLength() { + return this.length; + } + + public boolean isEnd() { + return end; + } + + public void setProperties(int y, int length, boolean end) { + this.y = y; + this.length = length; + this.end = end; } + @Override + protected void entityInit() {} + @Override public void onUpdate() { - if (!this.world.isRemote) { - if (this.mte == null || !this.mte.isValid()) { - setDead(); - return; - } + if (this.mte == null || !this.mte.isValid()) { + setDead(); + return; } - int length = this.dataManager.get(LENGTH); + int length = this.length; if (length != this.prevLength) { this.prevLength = length; - if (!this.world.isRemote) { - setPosition(this.posX, this.dataManager.get(Y) - length, this.posZ); - } + setPosition(this.posX, getY() - length, this.posZ); setSize(.5f, length); } @@ -100,7 +123,7 @@ public EnumPushReaction getPushReaction() { @Nullable @Override public AxisAlignedBB getCollisionBox(@Nonnull Entity entity) { - return entity.getEntityBoundingBox(); // TODO maybe avoiding pushable check on the entity would allow pipes to stop stuffs like arrow? + return entity.canBePushed() ? entity.getEntityBoundingBox() : null; } @Nullable @@ -119,9 +142,4 @@ protected void readEntityFromNBT(@Nonnull NBTTagCompound tag) {} @Override protected void writeEntityToNBT(@Nonnull NBTTagCompound tag) {} - - // @Override - // public boolean shouldRenderInPass(int pass) { - // return false; - // } } diff --git a/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityLargeMiner.java b/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityLargeMiner.java index 8e442146635..5adf2c056d1 100644 --- a/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityLargeMiner.java +++ b/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityLargeMiner.java @@ -47,7 +47,6 @@ import net.minecraft.util.text.event.ClickEvent; import net.minecraft.util.text.event.HoverEvent; import net.minecraft.world.World; -import net.minecraftforge.client.MinecraftForgeClient; import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.util.Constants; import net.minecraftforge.fluids.FluidStack; @@ -171,6 +170,13 @@ public void onMineOperation(@Nonnull BlockPos pos, boolean isOre, boolean isOrig } } + @Nonnull + @Override + @SideOnly(Side.CLIENT) + public MiningPipeModel getMiningPipeModel() { + return this.type.getMiningPipeModel(); + } + @Override @SideOnly(Side.CLIENT) public void renderMetaTileEntity(CCRenderState renderState, Matrix4 translation, IVertexOperation[] pipeline) { @@ -185,11 +191,6 @@ public void renderMetaTileEntity(CCRenderState renderState, Matrix4 translation, @Override public void renderMetaTileEntity(double x, double y, double z, float partialTicks) { - if (MinecraftForgeClient.getRenderPass() == RENDER_PASS_NORMAL) { - EnumFacing f = getFrontFacing().getOpposite(); - MinerRenderHelper.renderPipe(x + f.getXOffset(), y, z + f.getZOffset(), getWorld(), getPos().offset(f), - this.minerLogic.getPipeLength(), this.type.getMiningPipeModel()); - } MiningArea previewArea = this.minerLogic.getPreviewArea(); if (previewArea != null) previewArea.renderMetaTileEntity(this, x, y, z, partialTicks); } @@ -202,12 +203,12 @@ public void renderMetaTileEntityFast(CCRenderState renderState, Matrix4 translat @Override public AxisAlignedBB getRenderBoundingBox() { - return this.minerLogic.getRenderBoundingBox(); + MiningArea previewArea = this.minerLogic.getPreviewArea(); + return previewArea != null ? previewArea.getRenderBoundingBox() : MinerUtil.EMPTY_AABB; } @Override public boolean shouldRenderInPass(int pass) { - if (pass == RENDER_PASS_NORMAL) return true; MiningArea previewArea = this.minerLogic.getPreviewArea(); return previewArea != null && previewArea.shouldRenderInPass(pass); } @@ -222,6 +223,14 @@ protected void updateFormedValid() { this.minerLogic.update(); } + @Override + public void update() { + super.update(); + if (this.getWorld().isRemote) { + this.minerLogic.update(); + } + } + @Nonnull @Override protected BlockPattern createStructurePattern() { diff --git a/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityMiner.java b/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityMiner.java index 63559c406f2..ec60ed9b690 100644 --- a/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityMiner.java +++ b/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityMiner.java @@ -36,7 +36,6 @@ import net.minecraft.util.text.TextComponentTranslation; import net.minecraft.util.text.TextFormatting; import net.minecraft.world.World; -import net.minecraftforge.client.MinecraftForgeClient; import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; @@ -91,9 +90,6 @@ public void renderMetaTileEntity(CCRenderState renderState, Matrix4 translation, @Override public void renderMetaTileEntity(double x, double y, double z, float partialTicks) { - if (MinecraftForgeClient.getRenderPass() == RENDER_PASS_NORMAL) { - MinerRenderHelper.renderPipe(x, y, z, getWorld(), getPos(), this.minerLogic.getPipeLength(), MiningPipeModels.STEEL); - } MiningArea previewArea = this.minerLogic.getPreviewArea(); if (previewArea != null) previewArea.renderMetaTileEntity(this, x, y, z, partialTicks); } @@ -106,12 +102,12 @@ public void renderMetaTileEntityFast(CCRenderState renderState, Matrix4 translat @Override public AxisAlignedBB getRenderBoundingBox() { - return this.minerLogic.getRenderBoundingBox(); + MiningArea previewArea = this.minerLogic.getPreviewArea(); + return previewArea != null ? previewArea.getRenderBoundingBox() : MinerUtil.EMPTY_AABB; } @Override public boolean shouldRenderInPass(int pass) { - if (pass == RENDER_PASS_NORMAL) return true; MiningArea previewArea = this.minerLogic.getPreviewArea(); return previewArea != null && previewArea.shouldRenderInPass(pass); } @@ -208,6 +204,13 @@ public boolean drainMiningResources(@Nonnull MinedBlockType minedBlockType, bool return true; } + @Nonnull + @Override + @SideOnly(Side.CLIENT) + public MiningPipeModel getMiningPipeModel() { + return MiningPipeModels.STEEL; + } + @Override public void update() { super.update(); diff --git a/src/main/java/gregtech/common/metatileentities/miner/Miner.java b/src/main/java/gregtech/common/metatileentities/miner/Miner.java index c65494e0140..ddcfc1c2a20 100644 --- a/src/main/java/gregtech/common/metatileentities/miner/Miner.java +++ b/src/main/java/gregtech/common/metatileentities/miner/Miner.java @@ -6,6 +6,8 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraft.world.WorldServer; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; import javax.annotation.Nonnull; @@ -21,6 +23,10 @@ public interface Miner { */ boolean drainMiningResources(@Nonnull MinedBlockType minedBlockType, boolean pipeExtended, boolean simulate); + @Nonnull + @SideOnly(Side.CLIENT) + MiningPipeModel getMiningPipeModel(); + default boolean canOperate() { return true; } @@ -61,6 +67,6 @@ enum MinedBlockType { /** * Mined a block that isn't an ore, like a block in the center (pipe column). */ - BLOCK; + BLOCK } } diff --git a/src/main/java/gregtech/common/metatileentities/miner/MinerLogic.java b/src/main/java/gregtech/common/metatileentities/miner/MinerLogic.java index 08da352dc1b..780500866e8 100644 --- a/src/main/java/gregtech/common/metatileentities/miner/MinerLogic.java +++ b/src/main/java/gregtech/common/metatileentities/miner/MinerLogic.java @@ -13,7 +13,6 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.PacketBuffer; import net.minecraft.util.NonNullList; -import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos.MutableBlockPos; import net.minecraft.util.math.MathHelper; @@ -52,7 +51,7 @@ public class MinerLogic { private MiningArea miningArea; private boolean active; - private int workTick; + private int workDelay; // flag indicating last insertion to inventory failed private boolean inventoryFull; // flag indicating mining area should be rebuilt @@ -66,10 +65,8 @@ public class MinerLogic { // remote instances only, contains MiningArea instances deserialized from packet @Nullable private MiningArea previewArea; - @Nullable - private AxisAlignedBB renderBoundingBox; - private final List pipeEntities = new ArrayList<>(); + private final List> pipeEntities = new ArrayList<>(); /** * Creates the general logic for all in-world ore block miners @@ -85,7 +82,7 @@ public class MinerLogic { public MinerLogic(@Nonnull MTE mte, int workFrequency, int maximumDiameter) { if (workFrequency <= 0) throw new IllegalArgumentException("workFrequency <= 0"); this.mte = Objects.requireNonNull(mte, "mte == null"); - this.workFrequency = workFrequency; + this.workDelay = this.workFrequency = workFrequency; this.currentDiameter = this.maximumDiameter = maximumDiameter; } @@ -131,44 +128,10 @@ public MiningArea getPreviewArea() { return this.previewArea; } - @Nonnull - public AxisAlignedBB getRenderBoundingBox() { - if (this.renderBoundingBox == null) { - BlockPos origin = getOrigin(); - this.renderBoundingBox = new AxisAlignedBB( - origin.getX() + .25, origin.getY(), origin.getZ() + .25, - origin.getX() + .75, origin.getY() - pipeLength, origin.getZ() + .75); - if (this.previewArea != null) { - this.renderBoundingBox = this.previewArea.getRenderBoundingBox().union(this.renderBoundingBox); - } - } - return renderBoundingBox; - } - - public boolean isAtWorkTick() { - if (this.workFrequency == 1) return true; - return this.mte.getOffsetTimer() % this.workFrequency == this.workTick; - } - - /** - *

- * Set next work tick to {@code workTick} after current tick. When called during {@link #update()}, this method - * essentially sets next operation at {@code workTick} after. If not called, the next update happens - * {@link #workFrequency} ticks after. - *

- *

- * If {@code workTick} is greater or equal than {@link #workFrequency}, {@code workTick % workFrequency} will be - * used instead. - *

- */ - protected void setNextWorkTick(int workTick) { - this.workTick = (this.workTick + workTick) % this.workFrequency; - } - public double getWorkProgress() { if (!isWorking()) return 0; if (getWorkFrequency() < 2) return 1; - return ((mte.getOffsetTimer() + getWorkFrequency() - workTick) % getWorkFrequency()) / (double) getWorkFrequency(); + return (double) workDelay / getWorkFrequency(); } /** @@ -268,15 +231,15 @@ protected void updatePreview() { * Performs the actual mining in world. Call this method every tick in update. */ public void update() { - if (this.mte.getWorld().isRemote) return; + if (!this.mte.getWorld().isRemote) { + // rebuild scan area every tick regardless of miner status, for accurate preview + if (this.rebuildMiningArea || this.miningArea == null) { + rebuildMiningArea(); + } - // rebuild scan area every tick regardless of miner status, for accurate preview - if (this.rebuildMiningArea || this.miningArea == null) { - rebuildMiningArea(); + updateLogic(); } - updateLogic(); - if (this.prevPipeLength != this.pipeLength) { this.prevPipeLength = this.pipeLength; int pipeIndex = 0; @@ -287,18 +250,16 @@ public void update() { int length = y % 16; if (length == 0) length = 16; - MiningPipeEntity entity = this.pipeEntities.size() > pipeIndex ? this.pipeEntities.get(pipeIndex) : null; + MiningPipeEntity entity = this.pipeEntities.size() > pipeIndex ? this.pipeEntities.get(pipeIndex) : null; if (entity == null || !entity.isEntityAlive()) { - entity = new MiningPipeEntity(this.mte, this.getOrigin()); + entity = new MiningPipeEntity<>(this.mte, this.getOrigin()); if (pipeIndex < this.pipeEntities.size()) this.pipeEntities.set(pipeIndex, entity); else this.pipeEntities.add(entity); this.mte.getWorld().spawnEntity(entity); } - entity.setLength(y, length); - - y -= length; + entity.setProperties(y, length, (y -= length) > yEnd); pipeIndex++; } @@ -325,9 +286,10 @@ protected void updateLogic() { } protected void mine(@Nonnull MiningArea miningArea) { - if (this.done || !isAtWorkTick() || !this.workingEnabled || !this.mte.canOperate()) { - return; - } + if (this.done || --this.workDelay > 0) return; + this.workDelay = this.workFrequency; + if (!this.workingEnabled || !this.mte.canOperate()) return; + World world = mte.getWorld(); BlockPos origin = getOrigin(); MutableBlockPos pos = this.mpos; @@ -346,15 +308,14 @@ protected void mine(@Nonnull MiningArea miningArea) { state.getBlockHardness(world, pos) < 0 || state.getBlock().hasTileEntity(state) || state.getMaterial().isLiquid()) { - if (isOrigin) { // TODO liquid tile check? + if (isOrigin) { // center block (where mining pipes goes in) can be skipped by this, it'll probably look kind of janky // but it's 100x better than voiding bedrock if (!this.mte.drainMiningResources(MinedBlockType.NOTHING, true, false)) { return; } setPipeLength(this.pipeLength + 1); - // TODO don't spam pipe length packet if it goes down at once - // uhh maybe add some delay, yeah that'd be good + this.workDelay /= 2; } miningArea.nextBlock(); continue; @@ -389,7 +350,7 @@ protected void mine(@Nonnull MiningArea miningArea) { this.mte.markDirty(); return; } - setNextWorkTick(1); // scan next tick + this.workDelay = 1; // re-scan next tick } @Nonnull @@ -418,7 +379,6 @@ protected void writePreviewUpdatePacket(@Nonnull PacketBuffer buffer) { protected void readPreviewUpdatePacket(@Nonnull PacketBuffer buffer) { this.previewArea = buffer.readBoolean() ? readPreviewArea(buffer) : null; - this.renderBoundingBox = null; } @Nonnull @@ -505,7 +465,6 @@ public void receiveInitialSyncData(@Nonnull PacketBuffer buf) { this.done = buf.readBoolean(); this.active = buf.readBoolean(); readPreviewUpdatePacket(buf); - this.renderBoundingBox = null; } /** @@ -515,7 +474,6 @@ public void receiveCustomData(int dataId, @Nonnull PacketBuffer buf) { switch (dataId) { case GregtechDataCodes.PUMP_HEAD_LEVEL -> { this.pipeLength = buf.readVarInt(); - this.renderBoundingBox = null; } case GregtechDataCodes.WORKING_ENABLED -> { this.workingEnabled = buf.readBoolean(); @@ -523,7 +481,6 @@ public void receiveCustomData(int dataId, @Nonnull PacketBuffer buf) { } case GregtechDataCodes.MINER_UPDATE_PREVIEW -> { readPreviewUpdatePacket(buf); - this.renderBoundingBox = null; } case GregtechDataCodes.MINER_UPDATE_ACTIVE -> { this.active = buf.readBoolean(); diff --git a/src/main/java/gregtech/common/metatileentities/miner/MinerRenderHelper.java b/src/main/java/gregtech/common/metatileentities/miner/MinerRenderHelper.java index d0d101965a8..0fdf2980d85 100644 --- a/src/main/java/gregtech/common/metatileentities/miner/MinerRenderHelper.java +++ b/src/main/java/gregtech/common/metatileentities/miner/MinerRenderHelper.java @@ -1,12 +1,14 @@ package gregtech.common.metatileentities.miner; +import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.util.GTUtility; -import net.minecraft.block.state.IBlockState; +import gregtech.common.entities.MiningPipeEntity; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.BufferBuilder; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.GlStateManager.DestFactor; import net.minecraft.client.renderer.GlStateManager.SourceFactor; +import net.minecraft.client.renderer.RenderHelper; import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.culling.ClippingHelperImpl; import net.minecraft.client.renderer.vertex.DefaultVertexFormats; @@ -14,7 +16,6 @@ import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos.MutableBlockPos; -import net.minecraft.world.World; import org.lwjgl.opengl.GL11; import javax.annotation.Nonnull; @@ -50,40 +51,43 @@ private static void updateFrustum() { clippingHelper.init(); } - public static void renderPipe(double x, double y, double z, - @Nonnull World world, @Nonnull BlockPos pos, - int pipeLength, @Nonnull MiningPipeModel miningPipeModel) { - if (pipeLength <= 0) return; + public static void renderPipe(double x, double y, double z, float partialTicks, + @Nonnull MiningPipeEntity entity) { + if (entity.getMTE() == null || entity.getLength() <= 0) return; updateFrustum(); + x -= entity.lastTickPosX + (entity.posX - entity.lastTickPosX) * partialTicks; + y -= entity.lastTickPosY + (entity.posY - entity.lastTickPosY) * partialTicks; + z -= entity.lastTickPosZ + (entity.posZ - entity.lastTickPosZ) * partialTicks; + Minecraft mc = Minecraft.getMinecraft(); - MutableBlockPos mpos = new MutableBlockPos(pos); + BlockPos origin = entity.getOrigin(); + MutableBlockPos mpos = new MutableBlockPos(origin); Tessellator t = Tessellator.getInstance(); BufferBuilder buffer = t.getBuffer(); + MiningPipeModel model = entity.getMTE().getMiningPipeModel(); - GlStateManager.disableLighting(); + RenderHelper.disableStandardItemLighting(); GlStateManager.shadeModel(Minecraft.isAmbientOcclusionEnabled() ? GL11.GL_SMOOTH : GL11.GL_FLAT); GlStateManager.bindTexture(mc.getTextureMapBlocks().getGlTextureId()); - buffer.setTranslation(x - pos.getX(), y - pos.getY(), z - pos.getZ()); - mpos.setY(mpos.getY()); + buffer.setTranslation(x, y, z); buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK); - for (int i = 0; i < pipeLength; i++) { - mpos.setY(mpos.getY() - 1); + for (int i = 0, len = entity.getLength(); i < len; i++) { + mpos.setY(entity.getY() - len + i); // me epicly dodging AABB allocations by plugging in primitive values directly (very epic) if (!clippingHelper.isBoxInFrustum( - mpos.getX() + .25 + x - pos.getX(), mpos.getY() + y - pos.getY(), mpos.getZ() + .25 + z - pos.getZ(), - mpos.getX() + .75 + x - pos.getX(), mpos.getY() + 1 + y - pos.getY(), mpos.getZ() + .75 + z - pos.getZ())) { + mpos.getX() + .25 + x, mpos.getY() + y, mpos.getZ() + .25 + z, + mpos.getX() + .75 + x, mpos.getY() + 1 + y, mpos.getZ() + .75 + z)) { continue; } - IBlockState state = world.getBlockState(mpos); - mc.blockRenderDispatcher.getBlockModelRenderer().renderModel(world, - i == (pipeLength - 1) ? miningPipeModel.getBottomModel() : miningPipeModel.getBaseModel(), - state, mpos, buffer, false); + mc.blockRenderDispatcher.getBlockModelRenderer().renderModel(entity.world, + i == (len - 1) && entity.isEnd() ? model.getBottomModel() : model.getBaseModel(), + entity.world.getBlockState(mpos), mpos, buffer, false); } buffer.setTranslation(0, 0, 0); t.draw(); - GlStateManager.enableLighting(); + RenderHelper.enableStandardItemLighting(); } /** diff --git a/src/main/java/gregtech/common/metatileentities/miner/MiningPipeModel.java b/src/main/java/gregtech/common/metatileentities/miner/MiningPipeModel.java index 6be69d2d4cb..2be985f07c1 100644 --- a/src/main/java/gregtech/common/metatileentities/miner/MiningPipeModel.java +++ b/src/main/java/gregtech/common/metatileentities/miner/MiningPipeModel.java @@ -1,112 +1,14 @@ package gregtech.common.metatileentities.miner; -import com.google.common.base.Suppliers; -import gregtech.api.GTValues; -import gregtech.api.util.GTLog; -import gregtech.api.util.GTUtility; -import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import net.minecraft.client.renderer.block.model.IBakedModel; -import net.minecraft.client.renderer.vertex.DefaultVertexFormats; -import net.minecraft.util.ResourceLocation; -import net.minecraftforge.client.event.ModelBakeEvent; -import net.minecraftforge.client.event.TextureStitchEvent; -import net.minecraftforge.client.model.IModel; -import net.minecraftforge.client.model.ModelLoader; -import net.minecraftforge.client.model.ModelLoaderRegistry; -import net.minecraftforge.fml.common.Mod; -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; -import net.minecraftforge.fml.relauncher.Side; import javax.annotation.Nonnull; -import javax.annotation.Nullable; -import java.util.Map; -import java.util.function.Supplier; -@Mod.EventBusSubscriber(modid = GTValues.MODID, value = Side.CLIENT) -public final class MiningPipeModel { - - private static final Map MINING_PIPE_MODELS = new Object2ObjectOpenHashMap<>(); - private static final Supplier MISSING_MODEL_MEMOIZE = Suppliers.memoize(() -> { - IModel model = ModelLoaderRegistry.getMissingModel(); - return model.bake(model.getDefaultState(), DefaultVertexFormats.ITEM, ModelLoader.defaultTextureGetter()); - }); - - @Nonnull - public static MiningPipeModel register(@Nonnull String type) { - return MINING_PIPE_MODELS.computeIfAbsent(type, MiningPipeModel::new); - } +public interface MiningPipeModel { @Nonnull - public final String type; - - @Nullable - private IBakedModel baseModel; - @Nullable - private IModel unbakedBaseModel; - @Nullable - private IBakedModel bottomModel; - @Nullable - private IModel unbakedBottomModel; - - private MiningPipeModel(@Nonnull String type) { - this.type = type; - } + IBakedModel getBaseModel(); @Nonnull - public IBakedModel getBaseModel() { - return this.baseModel != null ? this.baseModel : MISSING_MODEL_MEMOIZE.get(); - } - - @Nonnull - public IBakedModel getBottomModel() { - return this.bottomModel != null ? this.bottomModel : MISSING_MODEL_MEMOIZE.get(); - } - - @Override - public String toString() { - return "MiningPipeModel{type='" + type + "'}"; - } - - @SubscribeEvent - public static void onTextureStitch(TextureStitchEvent.Pre event) { - for (MiningPipeModel miningPipe : MINING_PIPE_MODELS.values()) { - miningPipe.unbakedBaseModel = loadModel(event, GTUtility.gregtechId("block/mining_pipe/" + miningPipe.type)); - miningPipe.unbakedBottomModel = loadModel(event, GTUtility.gregtechId("block/mining_pipe/" + miningPipe.type + "_bottom")); - } - } - - @Nullable - private static IModel loadModel(TextureStitchEvent.Pre event, ResourceLocation modelLocation) { - IModel model; - try { - model = ModelLoaderRegistry.getModel(modelLocation); - } catch (Exception e) { - GTLog.logger.error("Failed to load material model {}:", modelLocation, e); - return null; - } - for (ResourceLocation texture : model.getTextures()) { - event.getMap().registerSprite(texture); - } - return model; - } - - @SubscribeEvent - public static void onModelBake(ModelBakeEvent event) { - for (MiningPipeModel miningPipe : MINING_PIPE_MODELS.values()) { - if (miningPipe.unbakedBaseModel != null) { - miningPipe.baseModel = miningPipe.unbakedBaseModel.bake( - miningPipe.unbakedBaseModel.getDefaultState(), - DefaultVertexFormats.ITEM, - ModelLoader.defaultTextureGetter()); - miningPipe.unbakedBaseModel = null; - } - if (miningPipe.unbakedBottomModel != null) { - miningPipe.bottomModel = miningPipe.unbakedBottomModel.bake( - miningPipe.unbakedBottomModel.getDefaultState(), - DefaultVertexFormats.ITEM, - ModelLoader.defaultTextureGetter()); - miningPipe.unbakedBottomModel = null; - } - } - } + IBakedModel getBottomModel(); } diff --git a/src/main/java/gregtech/common/metatileentities/miner/MiningPipeModels.java b/src/main/java/gregtech/common/metatileentities/miner/MiningPipeModels.java index 8358330fc18..c3fd36fd1ea 100644 --- a/src/main/java/gregtech/common/metatileentities/miner/MiningPipeModels.java +++ b/src/main/java/gregtech/common/metatileentities/miner/MiningPipeModels.java @@ -6,8 +6,8 @@ private MiningPipeModels() {} public static void init() {} - public static final MiningPipeModel BRONZE = MiningPipeModel.register("bronze"); - public static final MiningPipeModel STEEL = MiningPipeModel.register("steel"); - public static final MiningPipeModel TITANIUM = MiningPipeModel.register("titanium"); - public static final MiningPipeModel TUNGSTEN_STEEL = MiningPipeModel.register("tungsten_steel"); + public static final SimpleMiningPipeModel BRONZE = SimpleMiningPipeModel.register("bronze"); + public static final SimpleMiningPipeModel STEEL = SimpleMiningPipeModel.register("steel"); + public static final SimpleMiningPipeModel TITANIUM = SimpleMiningPipeModel.register("titanium"); + public static final SimpleMiningPipeModel TUNGSTEN_STEEL = SimpleMiningPipeModel.register("tungsten_steel"); } diff --git a/src/main/java/gregtech/common/metatileentities/miner/SimpleMiningPipeModel.java b/src/main/java/gregtech/common/metatileentities/miner/SimpleMiningPipeModel.java new file mode 100644 index 00000000000..e3f1769be09 --- /dev/null +++ b/src/main/java/gregtech/common/metatileentities/miner/SimpleMiningPipeModel.java @@ -0,0 +1,114 @@ +package gregtech.common.metatileentities.miner; + +import com.google.common.base.Suppliers; +import gregtech.api.GTValues; +import gregtech.api.util.GTLog; +import gregtech.api.util.GTUtility; +import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; +import net.minecraft.client.renderer.block.model.IBakedModel; +import net.minecraft.client.renderer.vertex.DefaultVertexFormats; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.client.event.ModelBakeEvent; +import net.minecraftforge.client.event.TextureStitchEvent; +import net.minecraftforge.client.model.IModel; +import net.minecraftforge.client.model.ModelLoader; +import net.minecraftforge.client.model.ModelLoaderRegistry; +import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.relauncher.Side; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import java.util.Map; +import java.util.function.Supplier; + +@Mod.EventBusSubscriber(modid = GTValues.MODID, value = Side.CLIENT) +public final class SimpleMiningPipeModel implements MiningPipeModel { + + private static final Map MINING_PIPE_MODELS = new Object2ObjectOpenHashMap<>(); + private static final Supplier MISSING_MODEL_MEMOIZE = Suppliers.memoize(() -> { + IModel model = ModelLoaderRegistry.getMissingModel(); + return model.bake(model.getDefaultState(), DefaultVertexFormats.ITEM, ModelLoader.defaultTextureGetter()); + }); + + @Nonnull + public static SimpleMiningPipeModel register(@Nonnull String type) { + return MINING_PIPE_MODELS.computeIfAbsent(type, SimpleMiningPipeModel::new); + } + + @Nonnull + public final String type; + + @Nullable + private IBakedModel baseModel; + @Nullable + private IModel unbakedBaseModel; + @Nullable + private IBakedModel bottomModel; + @Nullable + private IModel unbakedBottomModel; + + private SimpleMiningPipeModel(@Nonnull String type) { + this.type = type; + } + + @Nonnull + @Override + public IBakedModel getBaseModel() { + return this.baseModel != null ? this.baseModel : MISSING_MODEL_MEMOIZE.get(); + } + + @Nonnull + @Override + public IBakedModel getBottomModel() { + return this.bottomModel != null ? this.bottomModel : MISSING_MODEL_MEMOIZE.get(); + } + + @Override + public String toString() { + return "MiningPipeModel{type='" + type + "'}"; + } + + @SubscribeEvent + public static void onTextureStitch(TextureStitchEvent.Pre event) { + for (SimpleMiningPipeModel miningPipe : MINING_PIPE_MODELS.values()) { + miningPipe.unbakedBaseModel = loadModel(event, GTUtility.gregtechId("block/mining_pipe/" + miningPipe.type)); + miningPipe.unbakedBottomModel = loadModel(event, GTUtility.gregtechId("block/mining_pipe/" + miningPipe.type + "_bottom")); + } + } + + @Nullable + private static IModel loadModel(TextureStitchEvent.Pre event, ResourceLocation modelLocation) { + IModel model; + try { + model = ModelLoaderRegistry.getModel(modelLocation); + } catch (Exception e) { + GTLog.logger.error("Failed to load material model {}:", modelLocation, e); + return null; + } + for (ResourceLocation texture : model.getTextures()) { + event.getMap().registerSprite(texture); + } + return model; + } + + @SubscribeEvent + public static void onModelBake(ModelBakeEvent event) { + for (SimpleMiningPipeModel miningPipe : MINING_PIPE_MODELS.values()) { + if (miningPipe.unbakedBaseModel != null) { + miningPipe.baseModel = miningPipe.unbakedBaseModel.bake( + miningPipe.unbakedBaseModel.getDefaultState(), + DefaultVertexFormats.ITEM, + ModelLoader.defaultTextureGetter()); + miningPipe.unbakedBaseModel = null; + } + if (miningPipe.unbakedBottomModel != null) { + miningPipe.bottomModel = miningPipe.unbakedBottomModel.bake( + miningPipe.unbakedBottomModel.getDefaultState(), + DefaultVertexFormats.ITEM, + ModelLoader.defaultTextureGetter()); + miningPipe.unbakedBottomModel = null; + } + } + } +} diff --git a/src/main/java/gregtech/common/metatileentities/miner/SteamMiner.java b/src/main/java/gregtech/common/metatileentities/miner/SteamMiner.java index 76214c74e0a..f9a22e5512c 100644 --- a/src/main/java/gregtech/common/metatileentities/miner/SteamMiner.java +++ b/src/main/java/gregtech/common/metatileentities/miner/SteamMiner.java @@ -100,7 +100,6 @@ public void renderMetaTileEntity(CCRenderState renderState, Matrix4 translation, @Override public void renderMetaTileEntity(double x, double y, double z, float partialTicks) { - MinerRenderHelper.renderPipe(x, y, z, getWorld(), getPos(), this.minerLogic.getPipeLength(), MiningPipeModels.BRONZE); MiningArea previewArea = this.minerLogic.getPreviewArea(); if (previewArea != null) previewArea.renderMetaTileEntity(this, x, y, z, partialTicks); } @@ -113,12 +112,12 @@ public void renderMetaTileEntityFast(CCRenderState renderState, Matrix4 translat @Override public AxisAlignedBB getRenderBoundingBox() { - return this.minerLogic.getRenderBoundingBox(); + MiningArea previewArea = this.minerLogic.getPreviewArea(); + return previewArea != null ? previewArea.getRenderBoundingBox() : MinerUtil.EMPTY_AABB; } @Override public boolean shouldRenderInPass(int pass) { - if (pass == RENDER_PASS_NORMAL) return true; MiningArea previewArea = this.minerLogic.getPreviewArea(); return previewArea != null && previewArea.shouldRenderInPass(pass); } @@ -185,6 +184,13 @@ public boolean drainMiningResources(@Nonnull MinedBlockType minedBlockType, bool return drained != null && drained.amount >= energyPerTick; } + @Nonnull + @Override + @SideOnly(Side.CLIENT) + public MiningPipeModel getMiningPipeModel() { + return MiningPipeModels.BRONZE; + } + @Override public boolean canOperate() { if (!isNeedsVenting()) return true; From 87f39b9bdbc3b70e99b4fae472fe6cc3b26b1977 Mon Sep 17 00:00:00 2001 From: Tictim Date: Thu, 16 Nov 2023 12:17:04 +0900 Subject: [PATCH 09/27] Suspiciously sized refactor --- .../java/gregtech/api/gui/GuiTextures.java | 1 + .../common/entities/MiningPipeEntity.java | 26 +--- .../metatileentities/MetaTileEntities.java | 6 +- .../miner/MetaTileEntityLargeMiner.java | 145 +++++++++++------- .../miner/MetaTileEntityMiner.java | 16 ++ .../common/metatileentities/miner/Miner.java | 26 ++-- .../metatileentities/miner/MinerLogic.java | 85 ++++------ .../miner/MinerRenderHelper.java | 8 +- .../miner/MultiblockMinerLogic.java | 10 +- .../metatileentities/miner/SteamMiner.java | 16 ++ .../progress_bar_miner_drilling_fluid.png | Bin 0 -> 2834 bytes 11 files changed, 185 insertions(+), 154 deletions(-) create mode 100644 src/main/resources/assets/gregtech/textures/gui/progress_bar/progress_bar_miner_drilling_fluid.png diff --git a/src/main/java/gregtech/api/gui/GuiTextures.java b/src/main/java/gregtech/api/gui/GuiTextures.java index cca8705ebda..73e50345e7c 100644 --- a/src/main/java/gregtech/api/gui/GuiTextures.java +++ b/src/main/java/gregtech/api/gui/GuiTextures.java @@ -237,6 +237,7 @@ public class GuiTextures { public static final TextureArea PROGRESS_BAR_TURBINE_ROTOR_SPEED = TextureArea.fullImage("textures/gui/progress_bar/progress_bar_turbine_rotor_speed.png"); public static final TextureArea PROGRESS_BAR_TURBINE_ROTOR_DURABILITY = TextureArea.fullImage("textures/gui/progress_bar/progress_bar_turbine_rotor_durability.png"); public static final TextureArea PROGRESS_BAR_FLUID_RIG_DEPLETION = TextureArea.fullImage("textures/gui/progress_bar/progress_bar_fluid_rig_depletion.png"); + public static final TextureArea PROGRESS_BAR_MINER_DRILLING_FLUID = TextureArea.fullImage("textures/gui/progress_bar/progress_bar_miner_drilling_fluid.png"); // Fusion reactor diagram progress bar parts public static final TextureArea PROGRESS_BAR_FUSION_REACTOR_DIAGRAM_BL = TextureArea.fullImage("textures/gui/progress_bar/fusion_diagram/bottom_left.png"); diff --git a/src/main/java/gregtech/common/entities/MiningPipeEntity.java b/src/main/java/gregtech/common/entities/MiningPipeEntity.java index 7ea9e3a4fc8..09be325c889 100644 --- a/src/main/java/gregtech/common/entities/MiningPipeEntity.java +++ b/src/main/java/gregtech/common/entities/MiningPipeEntity.java @@ -23,9 +23,9 @@ public class MiningPipeEntity extends Entity private final MTE mte; private final BlockPos origin; - private int y; - private int length; - private boolean end; + public int y; + public int length; + public boolean end; private int prevLength = -1; @@ -61,24 +61,6 @@ public BlockPos getOrigin() { return origin; } - public int getY() { - return this.y; - } - - public int getLength() { - return this.length; - } - - public boolean isEnd() { - return end; - } - - public void setProperties(int y, int length, boolean end) { - this.y = y; - this.length = length; - this.end = end; - } - @Override protected void entityInit() {} @@ -92,7 +74,7 @@ public void onUpdate() { int length = this.length; if (length != this.prevLength) { this.prevLength = length; - setPosition(this.posX, getY() - length, this.posZ); + setPosition(this.posX, this.y - length, this.posZ); setSize(.5f, length); } diff --git a/src/main/java/gregtech/common/metatileentities/MetaTileEntities.java b/src/main/java/gregtech/common/metatileentities/MetaTileEntities.java index 362a43fe14d..ed0213de17d 100644 --- a/src/main/java/gregtech/common/metatileentities/MetaTileEntities.java +++ b/src/main/java/gregtech/common/metatileentities/MetaTileEntities.java @@ -526,9 +526,9 @@ public static void init() { STEAM_OVEN = registerMetaTileEntity(1024, new MetaTileEntitySteamOven(gregtechId("steam_oven"))); STEAM_GRINDER = registerMetaTileEntity(1025, new MetaTileEntitySteamGrinder(gregtechId("steam_grinder"))); - BASIC_LARGE_MINER = registerMetaTileEntity(1026, new MetaTileEntityLargeMiner(gregtechId("large_miner.ev"), GTValues.EV, 16, 3, 4, 8, LargeMinerTypes.STEEL)); - LARGE_MINER = registerMetaTileEntity(1027, new MetaTileEntityLargeMiner(gregtechId("large_miner.iv"), GTValues.IV, 4, 5, 5, 16, LargeMinerTypes.TITANIUM)); - ADVANCED_LARGE_MINER = registerMetaTileEntity(1028, new MetaTileEntityLargeMiner(gregtechId("large_miner.luv"), GTValues.LuV, 1, 7, 6, 32, LargeMinerTypes.TUNGSTEN_STEEL)); + BASIC_LARGE_MINER = registerMetaTileEntity(1026, new MetaTileEntityLargeMiner(gregtechId("large_miner.ev"), GTValues.EV, 16, 3, 8, LargeMinerTypes.STEEL)); + LARGE_MINER = registerMetaTileEntity(1027, new MetaTileEntityLargeMiner(gregtechId("large_miner.iv"), GTValues.IV, 4, 5, 16, LargeMinerTypes.TITANIUM)); + ADVANCED_LARGE_MINER = registerMetaTileEntity(1028, new MetaTileEntityLargeMiner(gregtechId("large_miner.luv"), GTValues.LuV, 1, 7, 32, LargeMinerTypes.TUNGSTEN_STEEL)); CENTRAL_MONITOR = registerMetaTileEntity(1029, new MetaTileEntityCentralMonitor(gregtechId("central_monitor"))); diff --git a/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityLargeMiner.java b/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityLargeMiner.java index 5adf2c056d1..94d0dc4ce2d 100644 --- a/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityLargeMiner.java +++ b/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityLargeMiner.java @@ -9,25 +9,28 @@ import gregtech.api.capability.IControllable; import gregtech.api.capability.IEnergyContainer; import gregtech.api.capability.IMultipleTankHandler; +import gregtech.api.capability.impl.CommonFluidFilters; import gregtech.api.capability.impl.EnergyContainerList; import gregtech.api.capability.impl.FluidTankList; import gregtech.api.capability.impl.ItemHandlerList; import gregtech.api.gui.GuiTextures; import gregtech.api.gui.Widget; +import gregtech.api.gui.resources.TextureArea; import gregtech.api.gui.widgets.ImageCycleButtonWidget; import gregtech.api.items.toolitem.ToolHelper; import gregtech.api.metatileentity.IDataInfoProvider; import gregtech.api.metatileentity.IFastRenderMetaTileEntity; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.metatileentity.interfaces.IGregTechTileEntity; -import gregtech.api.metatileentity.multiblock.IMultiblockPart; -import gregtech.api.metatileentity.multiblock.MultiblockAbility; -import gregtech.api.metatileentity.multiblock.MultiblockWithDisplayBase; +import gregtech.api.metatileentity.multiblock.*; import gregtech.api.pattern.BlockPattern; import gregtech.api.pattern.FactoryBlockPattern; import gregtech.api.pattern.PatternMatchContext; import gregtech.api.recipes.RecipeMaps; +import gregtech.api.unification.material.Materials; +import gregtech.api.util.GTTransferUtils; import gregtech.api.util.GTUtility; +import gregtech.api.util.TextComponentUtil; import gregtech.client.renderer.ICubeRenderer; import gregtech.client.renderer.texture.Textures; import gregtech.core.sound.GTSoundEvents; @@ -63,13 +66,12 @@ import static gregtech.api.unification.material.Materials.DrillingFluid; -public class MetaTileEntityLargeMiner extends MultiblockWithDisplayBase implements Miner, IControllable, IDataInfoProvider, IFastRenderMetaTileEntity { +public class MetaTileEntityLargeMiner extends MultiblockWithDisplayBase implements Miner, IControllable, IDataInfoProvider, IFastRenderMetaTileEntity, IProgressBarMultiblock { @Nonnull public final LargeMinerType type; public final int tier; public final int drillingFluidConsumePerTick; - public final int oreMultiplier; private final MultiblockMinerLogic minerLogic; @@ -83,13 +85,14 @@ public class MetaTileEntityLargeMiner extends MultiblockWithDisplayBase implemen // number of ores processed so far protected int minedOreCount; + private boolean inventoryFull; + public MetaTileEntityLargeMiner(ResourceLocation metaTileEntityId, int tier, int speed, int maxChunkDiameter, - int oreMultiplier, int drillingFluidConsumePerTick, @Nonnull LargeMinerType type) { + int drillingFluidConsumePerTick, @Nonnull LargeMinerType type) { super(metaTileEntityId); this.type = Objects.requireNonNull(type, "type == null"); this.tier = tier; this.drillingFluidConsumePerTick = drillingFluidConsumePerTick; - this.oreMultiplier = oreMultiplier; this.minerLogic = new MultiblockMinerLogic(this, speed, maxChunkDiameter); } @@ -97,7 +100,7 @@ public MetaTileEntityLargeMiner(ResourceLocation metaTileEntityId, int tier, int public MetaTileEntity createMetaTileEntity(IGregTechTileEntity tileEntity) { return new MetaTileEntityLargeMiner(metaTileEntityId, this.tier, this.minerLogic.getWorkFrequency(), this.minerLogic.getMaximumChunkDiameter(), - this.oreMultiplier, this.drillingFluidConsumePerTick, this.type); + this.drillingFluidConsumePerTick, this.type); } @Override @@ -152,13 +155,20 @@ protected boolean drainFluid(boolean simulate) { } @Override - public void getRegularBlockDrops(@Nonnull NonNullList drops, @Nonnull World world, @Nonnull BlockPos pos, @Nonnull IBlockState state) { + public boolean collectBlockDrops(@Nonnull World world, @Nonnull BlockPos pos, @Nonnull IBlockState state) { + NonNullList drops = NonNullList.create(); + IItemHandlerModifiable inventory = this.outputInventory; + if (this.minerLogic.isSilkTouchMode()) { drops.add(ToolHelper.getSilkTouchDrop(state)); } else if (MinerUtil.applyTieredHammerDrops(GTUtility.toItem(state), drops, - this.getEnergyTier(), RecipeMaps.MACERATOR_RECIPES, this.oreMultiplier) == 0) { - Miner.super.getRegularBlockDrops(drops, world, pos, state); // fallback + this.getEnergyTier(), RecipeMaps.MACERATOR_RECIPES, 3) == 0) { + state.getBlock().getDrops(drops, world, pos, state, 0); // fallback } + boolean result = GTTransferUtils.addItemsToItemHandler(inventory, true, drops); + this.inventoryFull = result; + if (result) GTTransferUtils.addItemsToItemHandler(inventory, false, drops); + return result; } @Override @@ -298,10 +308,8 @@ protected void addDisplayText(List textList) { maxArea = this.minerLogic.getMaximumDiameter(); areaText = new TextComponentTranslation("gregtech.machine.miner.display.working_area", area, area); } - if (!this.minerLogic.isWorking()) { - areaText.appendText(" ").appendSibling(incrButton(area, maxArea, MinerUtil.DISPLAY_CLICK_AREA_INCR)) - .appendText(" ").appendSibling(decrButton(area, 1, MinerUtil.DISPLAY_CLICK_AREA_DECR)); - } + areaText.appendText(" ").appendSibling(incrButton(area, maxArea, MinerUtil.DISPLAY_CLICK_AREA_INCR)) + .appendText(" ").appendSibling(decrButton(area, 1, MinerUtil.DISPLAY_CLICK_AREA_DECR)); textList.add(areaText.appendText(" ").appendSibling(previewAreaButton(this.minerLogic.isPreviewEnabled()))); int yLimit = this.minerLogic.getYLimit(); @@ -314,13 +322,11 @@ protected void addDisplayText(List textList) { value = new TextComponentTranslation("gregtech.machine.miner.display.y_limit.no_value"); hoverText = new TextComponentTranslation("gregtech.machine.miner.display.y_limit.value_hover_tooltip.no_value"); } - if (!this.minerLogic.isWorking()) { - value = new TextComponentString("") - .appendSibling(incrButton(yLimit, Integer.MAX_VALUE, MinerUtil.DISPLAY_CLICK_Y_LIMIT_INCR)) - .appendText(" ").appendSibling(decrButton(yLimit, 0, MinerUtil.DISPLAY_CLICK_Y_LIMIT_DECR)) - .appendText(" ").appendSibling(value); - } - textList.add(new TextComponentTranslation("gregtech.machine.miner.display.y_limit", value) + textList.add(new TextComponentTranslation( + "gregtech.machine.miner.display.y_limit", new TextComponentString("") + .appendSibling(incrButton(yLimit, Integer.MAX_VALUE, MinerUtil.DISPLAY_CLICK_Y_LIMIT_INCR)) + .appendText(" ").appendSibling(decrButton(yLimit, 0, MinerUtil.DISPLAY_CLICK_Y_LIMIT_DECR)) + .appendText(" ").appendSibling(value)) .setStyle(new Style().setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverText)))); boolean currentValue = this.minerLogic.isRepeat(); @@ -334,7 +340,8 @@ protected void addDisplayText(List textList) { "gregtech.machine.miner.display.toggle.disabled") .setStyle(button(currentValue ? MinerUtil.DISPLAY_CLICK_REPEAT_DISABLE : MinerUtil.DISPLAY_CLICK_REPEAT_ENABLE)))); - ITextComponent replaceOreText = new TextComponentTranslation(this.minerLogic.getOreReplacement().getBlock().getTranslationKey() + ".name"); + ITextComponent replaceOreText = new TextComponentTranslation( + this.minerLogic.getOreReplacement().getBlock().getTranslationKey() + ".name"); if (!this.minerLogic.isWorking()) { replaceOreText = new TextComponentString("[") .appendSibling(replaceOreText.setStyle(new Style().setColor(TextFormatting.AQUA))) @@ -344,17 +351,7 @@ protected void addDisplayText(List textList) { textList.add(new TextComponentTranslation("gregtech.machine.miner.display.replace_ore", replaceOreText)); - MutableBlockPos mpos = new MutableBlockPos(); - if (this.minerLogic.getMiningArea() == null || !this.minerLogic.getCurrentBlock(this.minerLogic.getMiningArea(), mpos)) { - textList.add(new TextComponentTranslation("gregtech.machine.miner.display.done") - .setStyle(new Style().setColor(TextFormatting.GREEN))); - } else if (this.minerLogic.isWorking()) { - textList.add(new TextComponentTranslation("gregtech.machine.miner.display.working", - mpos.getX(), mpos.getY(), mpos.getZ()) - .setStyle(new Style().setColor(TextFormatting.GOLD))); - } else if (!isWorkingEnabled()) { - textList.add(new TextComponentTranslation("gregtech.multiblock.work_paused")); - } + appendWorkingStatus(textList); textList.add(new TextComponentTranslation("gregtech.machine.miner.display.stats.total_mined", this.minedOreCount)); if (this.hasLastMinedOre) { @@ -363,6 +360,26 @@ protected void addDisplayText(List textList) { } } + private void appendWorkingStatus(List textList) { + if (!this.minerLogic.isDone()) { + MiningArea miningArea = minerLogic.getMiningArea(); + if (miningArea != null) { + MutableBlockPos mpos = new MutableBlockPos(); + if (miningArea.getCurrentBlockPos(mpos)) { + if (this.minerLogic.isWorking()) { + textList.add(TextComponentUtil.translationWithColor(TextFormatting.GOLD, + "gregtech.machine.miner.display.working", mpos.getX(), mpos.getY(), mpos.getZ())); + } else if (!isWorkingEnabled()) { + textList.add(new TextComponentTranslation("gregtech.multiblock.work_paused")); + } + return; + } + } + } + textList.add(TextComponentUtil.translationWithColor(TextFormatting.GREEN, + "gregtech.machine.miner.display.done")); + } + @Nonnull protected static ITextComponent previewAreaButton(boolean previewEnabled) { return new TextComponentTranslation(previewEnabled ? @@ -427,21 +444,28 @@ protected void handleDisplayClick(String componentData, Widget.ClickData clickDa @Override protected void addWarningText(List textList) { - super.addWarningText(textList); - if (isStructureFormed()) { - if (this.minerLogic.isInventoryFull()) { - textList.add(new TextComponentTranslation("gregtech.machine.miner.display.inventory_full") - .setStyle(new Style().setColor(TextFormatting.RED))); - } - if (!drainFluid(true)) { - textList.add(new TextComponentTranslation("gregtech.machine.miner.multi.needsfluid") - .setStyle(new Style().setColor(TextFormatting.RED))); - } - if (!drainEnergy(true)) { - textList.add(new TextComponentTranslation("gregtech.multiblock.not_enough_energy") - .setStyle(new Style().setColor(TextFormatting.RED))); - } - } + MultiblockDisplayText.builder(textList, isStructureFormed(), false) + .addMaintenanceProblemLines(getMaintenanceProblems()) + .addLowPowerLine(isStructureFormed() && !drainEnergy(true)) + .addCustom(l -> { + if (isStructureFormed()) { + if (inventoryFull) { + l.add(new TextComponentTranslation("gregtech.machine.miner.display.inventory_full") + .setStyle(new Style().setColor(TextFormatting.RED))); + } + } + }); + } + + @Override + protected void addErrorText(List textList) { + MultiblockDisplayText.builder(textList, isStructureFormed()) + .addCustom(l -> { + if (!drainFluid(true)) { + l.add(new TextComponentTranslation("gregtech.machine.miner.multi.needsfluid") + .setStyle(new Style().setColor(TextFormatting.RED))); + } + }); } @Override @@ -550,11 +574,6 @@ public T getCapability(Capability capability, EnumFacing side) { return super.getCapability(capability, side); } - @Override - public IItemHandlerModifiable getExportItems() { - return this.outputInventory; - } - @Override public SoundEvent getSound() { return GTSoundEvents.MINER; @@ -576,4 +595,22 @@ public List getDataInfo() { protected boolean shouldShowVoidingModeButton() { return false; } + + @Override + public double getFillPercentage(int index) { + long drillingFluidAmount = 0, fluidCapacity = 0; + for (IMultipleTankHandler.MultiFluidTankEntry tank : this.inputFluidInventory.getFluidTanks()) { + FluidStack fluid = tank.getFluid(); + if (fluid != null && CommonFluidFilters.matchesFluid(fluid, Materials.DrillingFluid)) { + drillingFluidAmount += tank.getFluidAmount(); + } + fluidCapacity += tank.getCapacity(); + } + return (double) drillingFluidAmount / fluidCapacity; + } + + @Override + public TextureArea getProgressBarTexture(int index) { + return GuiTextures.PROGRESS_BAR_MINER_DRILLING_FLUID; + } } diff --git a/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityMiner.java b/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityMiner.java index ec60ed9b690..f52e6d23860 100644 --- a/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityMiner.java +++ b/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityMiner.java @@ -17,10 +17,12 @@ import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.metatileentity.TieredMetaTileEntity; import gregtech.api.metatileentity.interfaces.IGregTechTileEntity; +import gregtech.api.util.GTTransferUtils; import gregtech.api.util.Position; import gregtech.api.util.Size; import gregtech.client.renderer.texture.Textures; import gregtech.core.sound.GTSoundEvents; +import net.minecraft.block.state.IBlockState; import net.minecraft.client.resources.I18n; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; @@ -31,6 +33,7 @@ import net.minecraft.util.ResourceLocation; import net.minecraft.util.SoundEvent; import net.minecraft.util.math.AxisAlignedBB; +import net.minecraft.util.math.BlockPos; import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.TextComponentString; import net.minecraft.util.text.TextComponentTranslation; @@ -204,6 +207,19 @@ public boolean drainMiningResources(@Nonnull MinedBlockType minedBlockType, bool return true; } + @Override + public boolean collectBlockDrops(@Nonnull World world, @Nonnull BlockPos pos, @Nonnull IBlockState state) { + NonNullList drops = NonNullList.create(); + IItemHandlerModifiable inventory = getExportItems(); + state.getBlock().getDrops(drops, world, pos, state, 0); + if (GTTransferUtils.addItemsToItemHandler(inventory, true, drops)) { + GTTransferUtils.addItemsToItemHandler(inventory, false, drops); + return true; + } else { + return false; + } + } + @Nonnull @Override @SideOnly(Side.CLIENT) diff --git a/src/main/java/gregtech/common/metatileentities/miner/Miner.java b/src/main/java/gregtech/common/metatileentities/miner/Miner.java index ddcfc1c2a20..5077f46e2e1 100644 --- a/src/main/java/gregtech/common/metatileentities/miner/Miner.java +++ b/src/main/java/gregtech/common/metatileentities/miner/Miner.java @@ -1,8 +1,6 @@ package gregtech.common.metatileentities.miner; import net.minecraft.block.state.IBlockState; -import net.minecraft.item.ItemStack; -import net.minecraft.util.NonNullList; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraft.world.WorldServer; @@ -23,6 +21,18 @@ public interface Miner { */ boolean drainMiningResources(@Nonnull MinedBlockType minedBlockType, boolean pipeExtended, boolean simulate); + /** + * Try to collect drops from the block. {@code true} is returned if the block drop is successfully collected; + * {@code false} means the operation cannot be done (ex. not enough inventory space to store the drops). Returning + * {@code false} will momentarily halt the miner operation. + * + * @param world the {@link WorldServer} the miner is in + * @param pos the {@link BlockPos} of the block being mined + * @param state the {@link IBlockState} of the block being mined + * @return Whether the action was successful + */ + boolean collectBlockDrops(@Nonnull World world, @Nonnull BlockPos pos, @Nonnull IBlockState state); + @Nonnull @SideOnly(Side.CLIENT) MiningPipeModel getMiningPipeModel(); @@ -40,18 +50,6 @@ default boolean canOperate() { */ default void onMineOperation(@Nonnull BlockPos pos, boolean isOre, boolean isOrigin) {} - /** - * Called to handle mining regular ores and blocks - * - * @param drops the List of items to fill after the operation - * @param world the {@link WorldServer} the miner is in - * @param pos the {@link BlockPos} of the block being mined - * @param state the {@link IBlockState} of the block being mined - */ - default void getRegularBlockDrops(@Nonnull NonNullList drops, @Nonnull World world, @Nonnull BlockPos pos, @Nonnull IBlockState state) { - state.getBlock().getDrops(drops, world, pos, state, 0); // regular ores do not get fortune applied - } - /** * Type of the block mined. */ diff --git a/src/main/java/gregtech/common/metatileentities/miner/MinerLogic.java b/src/main/java/gregtech/common/metatileentities/miner/MinerLogic.java index 780500866e8..fee2a076a0e 100644 --- a/src/main/java/gregtech/common/metatileentities/miner/MinerLogic.java +++ b/src/main/java/gregtech/common/metatileentities/miner/MinerLogic.java @@ -3,22 +3,18 @@ import gregtech.api.capability.GregtechDataCodes; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.util.BlockUtility; -import gregtech.api.util.GTTransferUtils; import gregtech.common.entities.MiningPipeEntity; import gregtech.common.metatileentities.miner.Miner.MinedBlockType; import net.minecraft.block.material.Material; import net.minecraft.block.state.IBlockState; import net.minecraft.init.Blocks; -import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.PacketBuffer; -import net.minecraft.util.NonNullList; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos.MutableBlockPos; import net.minecraft.util.math.MathHelper; import net.minecraft.world.World; import net.minecraftforge.common.util.Constants; -import net.minecraftforge.items.IItemHandlerModifiable; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -52,8 +48,6 @@ public class MinerLogic { private boolean active; private int workDelay; - // flag indicating last insertion to inventory failed - private boolean inventoryFull; // flag indicating mining area should be rebuilt protected boolean rebuildMiningArea; // flag for area preview @@ -102,7 +96,6 @@ public int getCurrentDiameter() { * @param currentDiameter the radius to set the miner to use */ public void setCurrentDiameter(int currentDiameter) { - if (isWorking()) return; currentDiameter = Math.max(1, Math.min(currentDiameter, getMaximumDiameter())); if (this.currentDiameter != currentDiameter) { this.currentDiameter = currentDiameter; @@ -115,10 +108,6 @@ public boolean isActive() { return this.active; } - public boolean isInventoryFull() { - return this.inventoryFull; - } - public int getPipeLength() { return this.pipeLength; } @@ -130,8 +119,8 @@ public MiningArea getPreviewArea() { public double getWorkProgress() { if (!isWorking()) return 0; - if (getWorkFrequency() < 2) return 1; - return (double) workDelay / getWorkFrequency(); + if (getWorkFrequency() == 2) return 1; + return 1 - (double) workDelay / getWorkFrequency(); } /** @@ -176,6 +165,10 @@ public boolean hasNotEnoughEnergy() { return hasNotEnoughEnergy; } + public boolean isDone() { + return done; + } + /** * @return origin position of the miner. Block boundary will be centered around this position, and mining pipes will * be rendered under this position. @@ -211,8 +204,7 @@ protected MiningArea createMiningArea() { public void reset() { setPipeLength(0); rebuildMiningArea(); - - this.mte.markDirty(); + this.done = false; } private void rebuildMiningArea() { @@ -234,7 +226,7 @@ public void update() { if (!this.mte.getWorld().isRemote) { // rebuild scan area every tick regardless of miner status, for accurate preview if (this.rebuildMiningArea || this.miningArea == null) { - rebuildMiningArea(); + reset(); } updateLogic(); @@ -245,12 +237,14 @@ public void update() { int pipeIndex = 0; int y = this.getOrigin().getY(); int yEnd = y - this.pipeLength; + MiningPipeEntity entity = null; while (y > yEnd) { // divide segments every 16 blocks, aligned with Y position int length = y % 16; if (length == 0) length = 16; + length = Math.min(length, y - yEnd); - MiningPipeEntity entity = this.pipeEntities.size() > pipeIndex ? this.pipeEntities.get(pipeIndex) : null; + entity = this.pipeEntities.size() > pipeIndex ? this.pipeEntities.get(pipeIndex) : null; if (entity == null || !entity.isEntityAlive()) { entity = new MiningPipeEntity<>(this.mte, this.getOrigin()); @@ -259,10 +253,15 @@ public void update() { this.mte.getWorld().spawnEntity(entity); } - entity.setProperties(y, length, (y -= length) > yEnd); + entity.y = y; + entity.length = length; + entity.end = false; + y -= length; pipeIndex++; } + if (entity != null) entity.end = true; + for (int i = this.pipeEntities.size() - 1; i >= pipeIndex; i--) { this.pipeEntities.remove(i).setDead(); } @@ -295,11 +294,10 @@ protected void mine(@Nonnull MiningArea miningArea) { MutableBlockPos pos = this.mpos; for (int i = MinerUtil.MAX_BLOCK_SCAN; i > 0; i--) { - if (!getCurrentBlock(miningArea, pos)) { + if (!miningArea.getCurrentBlockPos(pos) || mte.getWorld().isOutsideBuildHeight(pos)) { this.done = true; return; } - IBlockState state = world.getBlockState(pos); boolean isOrigin = pos.getX() == origin.getX() && pos.getZ() == origin.getZ(); @@ -308,17 +306,18 @@ protected void mine(@Nonnull MiningArea miningArea) { state.getBlockHardness(world, pos) < 0 || state.getBlock().hasTileEntity(state) || state.getMaterial().isLiquid()) { - if (isOrigin) { - // center block (where mining pipes goes in) can be skipped by this, it'll probably look kind of janky - // but it's 100x better than voiding bedrock - if (!this.mte.drainMiningResources(MinedBlockType.NOTHING, true, false)) { - return; - } - setPipeLength(this.pipeLength + 1); - this.workDelay /= 2; - } miningArea.nextBlock(); - continue; + if (!isOrigin) { + continue; + } + // center block (where mining pipes goes in) can be skipped by this, it'll probably look kind of janky + // but it's 100x better than voiding bedrock + if (!this.mte.drainMiningResources(MinedBlockType.NOTHING, true, false)) { + return; + } + setPipeLength(this.pipeLength + 1); + this.workDelay /= 2; + return; } boolean isOre = BlockUtility.isOre(state); @@ -331,17 +330,8 @@ protected void mine(@Nonnull MiningArea miningArea) { return; } - NonNullList blockDrops = NonNullList.create(); - this.mte.getRegularBlockDrops(blockDrops, world, pos, state); - - if (isOre) { - IItemHandlerModifiable exportItems = mte.getExportItems(); - if (!GTTransferUtils.addItemsToItemHandler(exportItems, true, blockDrops)) { - this.inventoryFull = true; - return; - } - GTTransferUtils.addItemsToItemHandler(exportItems, false, blockDrops); - this.inventoryFull = false; + if (isOre && !this.mte.collectBlockDrops(world, pos, state)) { + return; } world.setBlockState(pos, isOrigin ? Blocks.AIR.getDefaultState() : getOreReplacement()); if (isOrigin) setPipeLength(this.pipeLength + 1); @@ -349,6 +339,7 @@ protected void mine(@Nonnull MiningArea miningArea) { this.mte.onMineOperation(pos, isOre, isOrigin); this.mte.markDirty(); return; + } this.workDelay = 1; // re-scan next tick } @@ -386,17 +377,6 @@ protected MiningArea readPreviewArea(@Nonnull PacketBuffer buffer) { return SimpleMiningArea.readPreview(buffer); } - /** - * Get the block currently being mined by this miner. This method only works on server environment. - * - * @param mpos Mutable block position - * @return {@code true} if the block exists (in which the {@code mpos} instance gets modified with the value, or - * {@code false} if it does not exist - */ - public boolean getCurrentBlock(@Nonnull MiningArea miningArea, @Nonnull MutableBlockPos mpos) { - return miningArea.getCurrentBlockPos(mpos) && !mte.getWorld().isOutsideBuildHeight(mpos); - } - /** * Write states to NBT. Call this method in {@link MetaTileEntity#writeToNBT(NBTTagCompound)}. */ @@ -419,7 +399,6 @@ public NBTTagCompound writeToNBT(@Nonnull NBTTagCompound data) { * Read states from NBT. Call this method in {@link MetaTileEntity#readFromNBT(NBTTagCompound)}. */ public void readFromNBT(@Nonnull NBTTagCompound data) { - this.inventoryFull = false; this.rebuildMiningArea = false; if (data.hasKey("xPos", Constants.NBT.TAG_INT)) { diff --git a/src/main/java/gregtech/common/metatileentities/miner/MinerRenderHelper.java b/src/main/java/gregtech/common/metatileentities/miner/MinerRenderHelper.java index 0fdf2980d85..6ebd6ec59e8 100644 --- a/src/main/java/gregtech/common/metatileentities/miner/MinerRenderHelper.java +++ b/src/main/java/gregtech/common/metatileentities/miner/MinerRenderHelper.java @@ -53,7 +53,7 @@ private static void updateFrustum() { public static void renderPipe(double x, double y, double z, float partialTicks, @Nonnull MiningPipeEntity entity) { - if (entity.getMTE() == null || entity.getLength() <= 0) return; + if (entity.getMTE() == null || entity.length <= 0) return; updateFrustum(); x -= entity.lastTickPosX + (entity.posX - entity.lastTickPosX) * partialTicks; @@ -72,8 +72,8 @@ public static void renderPipe(double x, dou GlStateManager.bindTexture(mc.getTextureMapBlocks().getGlTextureId()); buffer.setTranslation(x, y, z); buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK); - for (int i = 0, len = entity.getLength(); i < len; i++) { - mpos.setY(entity.getY() - len + i); + for (int i = 0, len = entity.length; i < len; i++) { + mpos.setY(entity.y - len + i); // me epicly dodging AABB allocations by plugging in primitive values directly (very epic) if (!clippingHelper.isBoxInFrustum( mpos.getX() + .25 + x, mpos.getY() + y, mpos.getZ() + .25 + z, @@ -82,7 +82,7 @@ public static void renderPipe(double x, dou } mc.blockRenderDispatcher.getBlockModelRenderer().renderModel(entity.world, - i == (len - 1) && entity.isEnd() ? model.getBottomModel() : model.getBaseModel(), + i == (len - 1) && entity.end ? model.getBottomModel() : model.getBaseModel(), entity.world.getBlockState(mpos), mpos, buffer, false); } buffer.setTranslation(0, 0, 0); diff --git a/src/main/java/gregtech/common/metatileentities/miner/MultiblockMinerLogic.java b/src/main/java/gregtech/common/metatileentities/miner/MultiblockMinerLogic.java index d185056be77..bb1d0317c11 100644 --- a/src/main/java/gregtech/common/metatileentities/miner/MultiblockMinerLogic.java +++ b/src/main/java/gregtech/common/metatileentities/miner/MultiblockMinerLogic.java @@ -42,6 +42,10 @@ protected void mine(@Nonnull MiningArea miningArea) { this.done = false; } super.mine(miningArea); + if (this.done && this.repeat) { + miningArea.reset(); + this.done = false; + } } @Nonnull @@ -91,7 +95,6 @@ public int getCurrentChunkDiameter() { } public void setCurrentChunkDiameter(int currentChunkDiameter) { - if (isWorking()) return; currentChunkDiameter = Math.max(1, Math.min(currentChunkDiameter, getMaximumChunkDiameter())); setChunkMode(true); if (this.currentChunkDiameter != currentChunkDiameter) { @@ -103,7 +106,6 @@ public void setCurrentChunkDiameter(int currentChunkDiameter) { @Override public void setCurrentDiameter(int currentDiameter) { - if (isWorking()) return; setChunkMode(false); super.setCurrentDiameter(currentDiameter); } @@ -113,7 +115,7 @@ public boolean isChunkMode() { } public void setChunkMode(boolean chunkMode) { - if (isWorking() || this.chunkMode == chunkMode) return; + if (this.chunkMode == chunkMode) return; this.chunkMode = chunkMode; this.rebuildMiningArea = true; this.mte.markDirty(); @@ -134,7 +136,7 @@ public int getYLimit() { } public void setYLimit(int yLimit) { - if (isWorking() || this.yLimit == yLimit) return; + if (this.yLimit == yLimit) return; this.yLimit = yLimit; this.rebuildMiningArea = true; this.mte.markDirty(); diff --git a/src/main/java/gregtech/common/metatileentities/miner/SteamMiner.java b/src/main/java/gregtech/common/metatileentities/miner/SteamMiner.java index f9a22e5512c..04c0cfc855f 100644 --- a/src/main/java/gregtech/common/metatileentities/miner/SteamMiner.java +++ b/src/main/java/gregtech/common/metatileentities/miner/SteamMiner.java @@ -21,10 +21,12 @@ import gregtech.api.metatileentity.IFastRenderMetaTileEntity; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.metatileentity.interfaces.IGregTechTileEntity; +import gregtech.api.util.GTTransferUtils; import gregtech.api.util.GTUtility; import gregtech.client.renderer.texture.Textures; import gregtech.client.renderer.texture.cube.SimpleSidedCubeRenderer; import gregtech.common.ConfigHolder; +import net.minecraft.block.state.IBlockState; import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.client.resources.I18n; import net.minecraft.entity.player.EntityPlayer; @@ -32,6 +34,7 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.PacketBuffer; import net.minecraft.util.EnumFacing; +import net.minecraft.util.NonNullList; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; @@ -176,6 +179,19 @@ public void addToolUsages(ItemStack stack, @Nullable World world, List t super.addToolUsages(stack, world, tooltip, advanced); } + @Override + public boolean collectBlockDrops(@Nonnull World world, @Nonnull BlockPos pos, @Nonnull IBlockState state) { + NonNullList drops = NonNullList.create(); + IItemHandlerModifiable inventory = getExportItems(); + state.getBlock().getDrops(drops, world, pos, state, 0); + if (GTTransferUtils.addItemsToItemHandler(inventory, true, drops)) { + GTTransferUtils.addItemsToItemHandler(inventory, false, drops); + return true; + } else { + return false; + } + } + @Override public boolean drainMiningResources(@Nonnull MinedBlockType minedBlockType, boolean pipeExtended, boolean simulate) { if (minedBlockType == MinedBlockType.NOTHING) return true; diff --git a/src/main/resources/assets/gregtech/textures/gui/progress_bar/progress_bar_miner_drilling_fluid.png b/src/main/resources/assets/gregtech/textures/gui/progress_bar/progress_bar_miner_drilling_fluid.png new file mode 100644 index 0000000000000000000000000000000000000000..d30ea84ede286c5fbc4bbe690c61920f44f0f0c4 GIT binary patch literal 2834 zcmV+t3+?oYP)uJ@VVD_UC<6{N zG_fI~0ue<-1QkJoA_k0xBC#Thg@9ne9*`iQ#9$OrQF$}6R&?d%y_c8YA7_1QpS|}z zXYYO1x&V;8{kgn!SPFnNo`4_X6{c}T z{8k*B#$jdxfFg<9uYy1K45IaYvHg`_dOZM)Sy63ve6hvv1)yUy0P^?0*fb9UASvow`@mQC zp^4`uNg&9uGcn1|&Nk+9SjOUl{-OWr@Hh0;_l(8q{wNRKos+;6rV8ldy0Owz(}jF` zW(JeRp&R{qi2rfmU!TJ;gp(Kmm5I1s5m_f-n#TRsj}B0%?E`vOzxB z2#P=n*a3EfYETOrKoe*ICqM@{4K9Go;5xVgZi5G41dM~{UdP6d+Yd z3o?MrAqM0Kc|iV92owdyL5UC#5<>aVCa44|hpM4Es0sQWIt5*Tu0n&*J!lk~f_{hI z!w5`*sjxDv4V%CW*ah~3!{C*0BD@;TgA3v9a1~q+AA{TB3-ERLHar49hi4Ih5D^-p zh8Q6X#0?2VqLBoIkE}zAkxHZUgRb+f=natP#6>iMMoK->`~sRLq)(kHo*Vn{;LcG6+edD1=7 zD>9j^O?D{Qg|tCDK{ym)H7&wDr6*;uGTJg8GHjVbnL{!c zWyUB7MT6o-VNo_w8Yq`2<5Ub)hw4L3rj}5@qxMs0WMyP6Wy582WNT#4$d1qunl{ac zmP#w5ouJ*Jy_Zv#bCKi7ZIf$}8dZdVy& z)LYdbX%I9R8VMQ|8r>Q*nyQ)sn)#Z|n)kKvS`4iutvy=3T65Yu+7a4Yv^%sXb>ww? zbn(=Yu(!=O6^iuTp>)p_Y^{w=i^lS773}6Fm1Fpe-gF!>Ip{*g$ zu-szvGhed;vo5pW z&GpS$<~8QGEXWp~7V9lKEnZq0SaK{6Sl+dwSOr*ZvFf(^Xl-N7w{EeXveC4Ov)N}e z%%C!Y7^RFWwrE>d+x51mZQt2h+X?JW*!^a2WS?Sx)P8cQ&Qi|OhNWW;>JChYI)@QQ zx?`Nj^# zuJBl~d&PK+RZLOLos~K(b5>qmrMN0})tOkySZ3_WICNY@+|jrX%s^&6b2i>5eqa0y z%Z;^%^_=a@u3%4b9605ii3Ep)@`TAmhs0fpQ%O!ql}XcFH*PieWwLj2ZSq`7V9Mc? zh17`D)-+sNT-qs~3@?S(ldh7UlRlVXkWrK|vf6I-?$tAVKYn8-l({mqQ$Q8{O!WzM zg`0(=S&msXS#Pt$vrpzo=kRj+a`kh!z=6$;cwT88(J6|n-WB%w`m$h~4pmp)< zy4P#0FI+#q!E3{jjf9OU8-FS=EhsN|y(wZ-SD|v@hQhJUUYnbXB#QV&!&~gP)NVy> zYIh_3ETV2tjiAU!0h1dxU-n=E9e!)6|Z;4?!H=SSy{V>ut&IOq{_dlbFb#!9eY1iCsp6Bajj|Hr?hX| zzPbJE{X++w546-O*Ot`2Kgd0Jx6Z4syTu9enWavU5N9)I?I-1m1*_?_rJ z$vD~agVqoG+9++s?NEDe`%Fht$4F;X=in*dQ{7$mU2Q)a|9JSc+Uc4zvS-T963!N$ zT{xF_ZuWe}`RNOZ7sk3{yB}PPym+f8xTpV;-=!;;JuhGEb?H5K#o@~7t9DmUU1MD9 zxNd#Dz0azz?I)|B+WM{g+Xrk0I&awC=o(x)cy`EX=)z6+o0o6-+`4{y+3mqQ%kSJB zju{@g%f35#FZJHb`&swrA8dGtepviS>QUumrN{L@>;2q1Vm)$Z)P1z?N$8UYW2~{~ zzhwUMVZ87u`Dx{Z>O|9|`Q+&->FRy-Sjp7DHsy69KwU-!MxeeuI@&cF4|M9z%A zjVG*0GCNbK~!jg?bxvmgg^{L(ea6fh>$GmxO!aA)qyM#Q4*w7 za1;2y3MTMayN;^51q`!DQdOB_%+%e=Om~cNs!AVsh^e~U9bq&E-zYOFfC+_z3C}{M{v~vfFVMX?)%5qH@MD2>$baNj1%zbs kIDVWn4c?oc0s#1%2S;Ek8mMU7L;wH)07*qoM6N<$g5Vc^C;$Ke literal 0 HcmV?d00001 From 4f8cd7d14f0e98050ec1838c8c10a0a33440e80a Mon Sep 17 00:00:00 2001 From: Tictim Date: Thu, 16 Nov 2023 12:41:06 +0900 Subject: [PATCH 10/27] Recipe tweak (first actually helpful commit message, this is shocking) --- .../java/gregtech/loaders/recipe/MetaTileEntityLoader.java | 2 +- .../loaders/recipe/MetaTileEntityMachineRecipeLoader.java | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/gregtech/loaders/recipe/MetaTileEntityLoader.java b/src/main/java/gregtech/loaders/recipe/MetaTileEntityLoader.java index cf52d5862a0..8414e05508b 100644 --- a/src/main/java/gregtech/loaders/recipe/MetaTileEntityLoader.java +++ b/src/main/java/gregtech/loaders/recipe/MetaTileEntityLoader.java @@ -323,7 +323,7 @@ public static void init() { registerMachineRecipe(MetaTileEntities.ITEM_COLLECTOR, "MRM", "RHR", "CWC", 'M', MOTOR, 'R', ROTOR, 'H', HULL, 'C', CIRCUIT, 'W', CABLE); registerMachineRecipe(MetaTileEntities.BLOCK_BREAKER, "MGM", "CHC", "WSW", 'M', MOTOR, 'H', HULL, 'C', CIRCUIT, 'W', CABLE, 'S', OreDictNames.chestWood, 'G', GRINDER); registerMachineRecipe(MetaTileEntities.WORLD_ACCELERATOR, "IGI", "FHF", "IGI", 'H', HULL, 'F', EMITTER, 'G', SENSOR, 'I', FIELD_GENERATOR); - registerMachineRecipe(MetaTileEntities.MINER, "MMM", "WHW", "CSC", 'M', MOTOR, 'W', CABLE, 'H', HULL, 'C', CIRCUIT, 'S', SENSOR); + registerMachineRecipe(MetaTileEntities.MINER, "MSM", "WHW", "CGC", 'M', MOTOR, 'W', CABLE, 'H', HULL, 'C', CIRCUIT, 'S', SENSOR, 'G', MetaItems.COMPONENT_GRINDER_DIAMOND); registerMachineRecipe(MetaTileEntities.MUFFLER_HATCH, "HM", "PR", 'H', HULL, 'M', MOTOR, 'P', PIPE_NORMAL, 'R', ROTOR); diff --git a/src/main/java/gregtech/loaders/recipe/MetaTileEntityMachineRecipeLoader.java b/src/main/java/gregtech/loaders/recipe/MetaTileEntityMachineRecipeLoader.java index aa727ac912d..fa1002df0d0 100644 --- a/src/main/java/gregtech/loaders/recipe/MetaTileEntityMachineRecipeLoader.java +++ b/src/main/java/gregtech/loaders/recipe/MetaTileEntityMachineRecipeLoader.java @@ -918,6 +918,7 @@ public static void init() { .input(ELECTRIC_PUMP_EV, 4) .input(CONVEYOR_MODULE_EV, 4) .input(gear, Tungsten, 4) + .input(COMPONENT_GRINDER_TUNGSTEN) .circuitMeta(2) .output(BASIC_LARGE_MINER) .duration(400).EUt(VA[EV]).buildAndRegister(); @@ -930,6 +931,7 @@ public static void init() { .input(ELECTRIC_PUMP_IV, 4) .input(CONVEYOR_MODULE_IV, 4) .input(gear, Iridium, 4) + .input(COMPONENT_GRINDER_TUNGSTEN) .circuitMeta(2) .output(LARGE_MINER) .duration(400).EUt(VA[IV]).buildAndRegister(); @@ -942,6 +944,7 @@ public static void init() { .input(ELECTRIC_PUMP_LuV, 4) .input(CONVEYOR_MODULE_LuV, 4) .input(gear, Ruridit, 4) + .input(COMPONENT_GRINDER_TUNGSTEN) .circuitMeta(2) .output(ADVANCED_LARGE_MINER) .duration(400).EUt(VA[LuV]).buildAndRegister(); From 302193dc10a979a83ae777973d2cb8490f3d3d2f Mon Sep 17 00:00:00 2001 From: Tictim Date: Thu, 16 Nov 2023 12:53:03 +0900 Subject: [PATCH 11/27] =?UTF-8?q?Rest=20in=20piss=20steam=20miner=20?= =?UTF-8?q?=F0=9F=98=AD=F0=9F=98=AD=F0=9F=98=AD=F0=9F=98=AD=F0=9F=98=AD?= =?UTF-8?q?=F0=9F=98=AD=F0=9F=98=AD=F0=9F=98=AD=F0=9F=98=AD=F0=9F=98=AD?= =?UTF-8?q?=F0=9F=98=AD=F0=9F=98=AD=F0=9F=98=AD=F0=9F=98=AD=F0=9F=98=AD?= =?UTF-8?q?=F0=9F=98=AD=F0=9F=98=AD=F0=9F=98=AD=F0=9F=98=AD=F0=9F=98=AD?= =?UTF-8?q?=F0=9F=98=AD=F0=9F=98=AD=F0=9F=98=AD=F0=9F=98=AD=F0=9F=98=AD?= =?UTF-8?q?=F0=9F=98=AD=F0=9F=98=AD=F0=9F=98=AD=F0=9F=98=AD=F0=9F=98=AD?= =?UTF-8?q?=F0=9F=98=AD=F0=9F=98=AD=F0=9F=98=AD=F0=9F=98=AD=F0=9F=98=AD?= =?UTF-8?q?=F0=9F=98=AD=F0=9F=98=AD=F0=9F=98=AD=F0=9F=98=AD=F0=9F=98=AD?= =?UTF-8?q?=F0=9F=98=AD=F0=9F=98=AD=F0=9F=98=AD=F0=9F=98=AD=F0=9F=98=AD?= =?UTF-8?q?=F0=9F=98=AD=F0=9F=98=AD=F0=9F=98=AD=F0=9F=98=AD=F0=9F=98=AD?= =?UTF-8?q?=F0=9F=98=AD=F0=9F=98=AD=F0=9F=98=AD=F0=9F=98=AD=F0=9F=98=AD?= =?UTF-8?q?=F0=9F=98=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../metatileentities/MetaTileEntities.java | 6 +- .../miner/MiningPipeModels.java | 1 - .../metatileentities/miner/SteamMiner.java | 347 ------------------ .../loaders/recipe/MetaTileEntityLoader.java | 1 - .../models/block/mining_pipe/bronze.json | 6 - .../block/mining_pipe/bronze_bottom.json | 6 - 6 files changed, 1 insertion(+), 366 deletions(-) delete mode 100644 src/main/java/gregtech/common/metatileentities/miner/SteamMiner.java delete mode 100644 src/main/resources/assets/gregtech/models/block/mining_pipe/bronze.json delete mode 100644 src/main/resources/assets/gregtech/models/block/mining_pipe/bronze_bottom.json diff --git a/src/main/java/gregtech/common/metatileentities/MetaTileEntities.java b/src/main/java/gregtech/common/metatileentities/MetaTileEntities.java index ed0213de17d..512a254c561 100644 --- a/src/main/java/gregtech/common/metatileentities/MetaTileEntities.java +++ b/src/main/java/gregtech/common/metatileentities/MetaTileEntities.java @@ -20,10 +20,9 @@ import gregtech.common.blocks.MetaBlocks; import gregtech.common.metatileentities.converter.MetaTileEntityConverter; import gregtech.common.metatileentities.electric.*; -import gregtech.common.metatileentities.miner.MetaTileEntityLargeMiner; import gregtech.common.metatileentities.miner.LargeMinerTypes; +import gregtech.common.metatileentities.miner.MetaTileEntityLargeMiner; import gregtech.common.metatileentities.miner.MetaTileEntityMiner; -import gregtech.common.metatileentities.miner.SteamMiner; import gregtech.common.metatileentities.multi.*; import gregtech.common.metatileentities.multi.electric.*; import gregtech.common.metatileentities.multi.electric.centralmonitor.MetaTileEntityCentralMonitor; @@ -195,7 +194,6 @@ public class MetaTileEntities { public static SteamAlloySmelter STEAM_ALLOY_SMELTER_STEEL; public static SteamRockBreaker STEAM_ROCK_BREAKER_BRONZE; public static SteamRockBreaker STEAM_ROCK_BREAKER_STEEL; - public static SteamMiner STEAM_MINER; public static MetaTileEntityPumpHatch PUMP_OUTPUT_HATCH; public static MetaTileEntityPrimitiveWaterPump PRIMITIVE_WATER_PUMP; public static MetaTileEntityMagicEnergyAbsorber MAGIC_ENERGY_ABSORBER; @@ -318,8 +316,6 @@ public static void init() { STEAM_ROCK_BREAKER_BRONZE = registerMetaTileEntity(19, new SteamRockBreaker(gregtechId("steam_rock_breaker_bronze"), false)); STEAM_ROCK_BREAKER_STEEL = registerMetaTileEntity(20, new SteamRockBreaker(gregtechId("steam_rock_breaker_steel"), true)); - STEAM_MINER = registerMetaTileEntity(21, new SteamMiner(gregtechId("steam_miner"), 320, 9)); - // Electric Furnace, IDs 50-64 registerSimpleMetaTileEntity(ELECTRIC_FURNACE, 50, "electric_furnace", RecipeMaps.FURNACE_RECIPES, Textures.ELECTRIC_FURNACE_OVERLAY, true); diff --git a/src/main/java/gregtech/common/metatileentities/miner/MiningPipeModels.java b/src/main/java/gregtech/common/metatileentities/miner/MiningPipeModels.java index c3fd36fd1ea..6036303cce8 100644 --- a/src/main/java/gregtech/common/metatileentities/miner/MiningPipeModels.java +++ b/src/main/java/gregtech/common/metatileentities/miner/MiningPipeModels.java @@ -6,7 +6,6 @@ private MiningPipeModels() {} public static void init() {} - public static final SimpleMiningPipeModel BRONZE = SimpleMiningPipeModel.register("bronze"); public static final SimpleMiningPipeModel STEEL = SimpleMiningPipeModel.register("steel"); public static final SimpleMiningPipeModel TITANIUM = SimpleMiningPipeModel.register("titanium"); public static final SimpleMiningPipeModel TUNGSTEN_STEEL = SimpleMiningPipeModel.register("tungsten_steel"); diff --git a/src/main/java/gregtech/common/metatileentities/miner/SteamMiner.java b/src/main/java/gregtech/common/metatileentities/miner/SteamMiner.java deleted file mode 100644 index 04c0cfc855f..00000000000 --- a/src/main/java/gregtech/common/metatileentities/miner/SteamMiner.java +++ /dev/null @@ -1,347 +0,0 @@ -package gregtech.common.metatileentities.miner; - -import codechicken.lib.render.CCRenderState; -import codechicken.lib.render.pipeline.ColourMultiplier; -import codechicken.lib.render.pipeline.IVertexOperation; -import codechicken.lib.vec.Matrix4; -import gregtech.api.capability.GregtechDataCodes; -import gregtech.api.capability.GregtechTileCapabilities; -import gregtech.api.capability.IControllable; -import gregtech.api.capability.IVentable; -import gregtech.api.capability.impl.CommonFluidFilters; -import gregtech.api.capability.impl.FilteredFluidHandler; -import gregtech.api.capability.impl.FluidTankList; -import gregtech.api.capability.impl.NotifiableItemStackHandler; -import gregtech.api.gui.GuiTextures; -import gregtech.api.gui.ModularUI; -import gregtech.api.gui.widgets.ImageWidget; -import gregtech.api.gui.widgets.ProgressWidget; -import gregtech.api.gui.widgets.ToggleButtonWidget; -import gregtech.api.metatileentity.IDataInfoProvider; -import gregtech.api.metatileentity.IFastRenderMetaTileEntity; -import gregtech.api.metatileentity.MetaTileEntity; -import gregtech.api.metatileentity.interfaces.IGregTechTileEntity; -import gregtech.api.util.GTTransferUtils; -import gregtech.api.util.GTUtility; -import gregtech.client.renderer.texture.Textures; -import gregtech.client.renderer.texture.cube.SimpleSidedCubeRenderer; -import gregtech.common.ConfigHolder; -import net.minecraft.block.state.IBlockState; -import net.minecraft.client.renderer.texture.TextureAtlasSprite; -import net.minecraft.client.resources.I18n; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.network.PacketBuffer; -import net.minecraft.util.EnumFacing; -import net.minecraft.util.NonNullList; -import net.minecraft.util.ResourceLocation; -import net.minecraft.util.math.AxisAlignedBB; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.text.ITextComponent; -import net.minecraft.util.text.TextComponentTranslation; -import net.minecraft.util.text.TextFormatting; -import net.minecraft.world.World; -import net.minecraftforge.common.capabilities.Capability; -import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.fml.relauncher.Side; -import net.minecraftforge.fml.relauncher.SideOnly; -import net.minecraftforge.items.IItemHandlerModifiable; -import org.apache.commons.lang3.ArrayUtils; -import org.apache.commons.lang3.tuple.Pair; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; -import java.util.Collections; -import java.util.List; - -public class SteamMiner extends MetaTileEntity implements Miner, IControllable, IVentable, IDataInfoProvider, IFastRenderMetaTileEntity { - - private boolean needsVenting = false; - private boolean ventingStuck = false; - - private final int inventorySize; - private final int energyPerTick; - - private final MinerLogic minerLogic; - - public SteamMiner(ResourceLocation metaTileEntityId, int workFrequency, int maximumDiameter) { - super(metaTileEntityId); - this.inventorySize = 4; - this.energyPerTick = 16; - this.minerLogic = new MinerLogic<>(this, workFrequency, maximumDiameter); - initializeInventory(); - } - - @Override - public MetaTileEntity createMetaTileEntity(IGregTechTileEntity tileEntity) { - return new SteamMiner(metaTileEntityId, this.minerLogic.getWorkFrequency(), this.minerLogic.getMaximumDiameter()); - } - - @Override - public FluidTankList createImportFluidHandler() { - return new FluidTankList(false, new FilteredFluidHandler(16000).setFilter(CommonFluidFilters.STEAM)); - } - - protected IItemHandlerModifiable createImportItemHandler() { - return new NotifiableItemStackHandler(0, this, false); - } - - @Override - protected IItemHandlerModifiable createExportItemHandler() { - return new NotifiableItemStackHandler(inventorySize, this, true); - } - - @Override - @SideOnly(Side.CLIENT) - public void renderMetaTileEntity(CCRenderState renderState, Matrix4 translation, IVertexOperation[] pipeline) { - IVertexOperation[] colouredPipeline = ArrayUtils.add(pipeline, new ColourMultiplier(GTUtility.convertRGBtoOpaqueRGBA_CL(getPaintingColorForRendering()))); - Textures.STEAM_CASING_BRONZE.render(renderState, translation, colouredPipeline); - // TODO replace top with vent, in standalone mod - Textures.MINER_OVERLAY.renderOrientedState(renderState, translation, pipeline, getFrontFacing(), minerLogic.isActive(), minerLogic.isWorkingEnabled()); - } - - @Override - public void renderMetaTileEntity(double x, double y, double z, float partialTicks) { - MiningArea previewArea = this.minerLogic.getPreviewArea(); - if (previewArea != null) previewArea.renderMetaTileEntity(this, x, y, z, partialTicks); - } - - @Override - public void renderMetaTileEntityFast(CCRenderState renderState, Matrix4 translation, float partialTicks) { - MiningArea previewArea = this.minerLogic.getPreviewArea(); - if (previewArea != null) previewArea.renderMetaTileEntityFast(this, renderState, translation, partialTicks); - } - - @Override - public AxisAlignedBB getRenderBoundingBox() { - MiningArea previewArea = this.minerLogic.getPreviewArea(); - return previewArea != null ? previewArea.getRenderBoundingBox() : MinerUtil.EMPTY_AABB; - } - - @Override - public boolean shouldRenderInPass(int pass) { - MiningArea previewArea = this.minerLogic.getPreviewArea(); - return previewArea != null && previewArea.shouldRenderInPass(pass); - } - - @Override - public boolean isGlobalRenderer() { - return true; - } - - @Override - protected ModularUI createUI(EntityPlayer entityPlayer) { - int columns = 2; - int xStart = (176 - (18 * columns)) / 2; - int yStart = 25; - int sideWidgetY = yStart + (columns * 18 - 18) / 2; - - ModularUI.Builder builder = ModularUI.builder(GuiTextures.BACKGROUND_STEAM.get(false), 176, 166) - .label(6, 6, getMetaFullName()) - .shouldColor(false) - .widget(new ToggleButtonWidget(152, 25, 18, 18, - GuiTextures.BUTTON_MINER_AREA_PREVIEW, - this.minerLogic::isPreviewEnabled, this.minerLogic::setPreviewEnabled)); - - IItemHandlerModifiable exportItems = this.getExportItems(); - for (int i = 0, slots = exportItems.getSlots(); i < slots; i++) { - builder.slot(exportItems, i, xStart + 18 * (i % columns), yStart + 18 * (i / columns), - true, false, GuiTextures.SLOT_STEAM.get(false)); - } - - builder.widget( - new ProgressWidget(this.minerLogic::getWorkProgress, xStart - 4 - 21, sideWidgetY, 21, 18, - GuiTextures.PROGRESS_BAR_MACERATE_STEAM.get(false), ProgressWidget.MoveType.HORIZONTAL) - ).widget( - new ImageWidget(xStart - 4 - 20, sideWidgetY + 18, 18, 18, - GuiTextures.INDICATOR_NO_STEAM.get(false)) - .setPredicate(minerLogic::hasNotEnoughEnergy) - ).bindPlayerInventory(entityPlayer.inventory, GuiTextures.SLOT_STEAM.get(false), 0); - - return builder.build(getHolder(), entityPlayer); - } - - @Override - public void addInformation(ItemStack stack, @Nullable World player, List tooltip, boolean advanced) { - tooltip.add(I18n.format("gregtech.universal.tooltip.uses_per_tick_steam", energyPerTick) - + TextFormatting.GRAY + ", " + - I18n.format("gregtech.machine.miner.per_block", this.minerLogic.getWorkFrequency() / 20)); - int maxDiameter = minerLogic.getMaximumDiameter(); - tooltip.add(I18n.format("gregtech.universal.tooltip.working_area", maxDiameter, maxDiameter)); - } - - @Override - public void addToolUsages(ItemStack stack, @Nullable World world, List tooltip, boolean advanced) { - tooltip.add(I18n.format("gregtech.tool_action.screwdriver.access_covers")); - tooltip.add(I18n.format("gregtech.tool_action.wrench.set_facing")); - tooltip.add(I18n.format("gregtech.tool_action.soft_mallet.reset")); - super.addToolUsages(stack, world, tooltip, advanced); - } - - @Override - public boolean collectBlockDrops(@Nonnull World world, @Nonnull BlockPos pos, @Nonnull IBlockState state) { - NonNullList drops = NonNullList.create(); - IItemHandlerModifiable inventory = getExportItems(); - state.getBlock().getDrops(drops, world, pos, state, 0); - if (GTTransferUtils.addItemsToItemHandler(inventory, true, drops)) { - GTTransferUtils.addItemsToItemHandler(inventory, false, drops); - return true; - } else { - return false; - } - } - - @Override - public boolean drainMiningResources(@Nonnull MinedBlockType minedBlockType, boolean pipeExtended, boolean simulate) { - if (minedBlockType == MinedBlockType.NOTHING) return true; - if (this.ventingStuck) return false; - FluidStack drained = this.importFluids.drain(energyPerTick, simulate); - return drained != null && drained.amount >= energyPerTick; - } - - @Nonnull - @Override - @SideOnly(Side.CLIENT) - public MiningPipeModel getMiningPipeModel() { - return MiningPipeModels.BRONZE; - } - - @Override - public boolean canOperate() { - if (!isNeedsVenting()) return true; - tryDoVenting(); - return !isVentingStuck(); - } - - @Override - public void onMineOperation(@Nonnull BlockPos pos, boolean isOre, boolean isOrigin) { - setNeedsVenting(true); - } - - @Override - public void update() { - super.update(); - this.minerLogic.update(); - if (!getWorld().isRemote) { - if (getOffsetTimer() % 5 == 0) - pushItemsIntoNearbyHandlers(getFrontFacing()); - } - } - - @Override - public NBTTagCompound writeToNBT(NBTTagCompound data) { - super.writeToNBT(data); - data.setBoolean("needsVenting", this.needsVenting); - data.setBoolean("ventingStuck", this.ventingStuck); - return this.minerLogic.writeToNBT(data); - } - - @Override - public void readFromNBT(NBTTagCompound data) { - super.readFromNBT(data); - this.needsVenting = data.getBoolean("needsVenting"); - this.ventingStuck = data.getBoolean("ventingStuck"); - this.minerLogic.readFromNBT(data); - } - - @Override - public void writeInitialSyncData(PacketBuffer buf) { - super.writeInitialSyncData(buf); - buf.writeBoolean(this.needsVenting); - buf.writeBoolean(this.ventingStuck); - this.minerLogic.writeInitialSyncData(buf); - } - - @Override - public void receiveInitialSyncData(PacketBuffer buf) { - super.receiveInitialSyncData(buf); - this.needsVenting = buf.readBoolean(); - this.ventingStuck = buf.readBoolean(); - this.minerLogic.receiveInitialSyncData(buf); - } - - @Override - public void receiveCustomData(int dataId, PacketBuffer buf) { - super.receiveCustomData(dataId, buf); - if (dataId == GregtechDataCodes.NEEDS_VENTING) { - this.needsVenting = buf.readBoolean(); - } else if (dataId == GregtechDataCodes.VENTING_STUCK) { - this.ventingStuck = buf.readBoolean(); - } - this.minerLogic.receiveCustomData(dataId, buf); - } - - @Override - @SideOnly(Side.CLIENT) - public Pair getParticleTexture() { - return Pair.of(Textures.STEAM_CASING_BRONZE.getSpriteOnSide(SimpleSidedCubeRenderer.RenderSide.TOP), getPaintingColorForRendering()); - } - - @Override - public T getCapability(Capability capability, EnumFacing side) { - if (capability == GregtechTileCapabilities.CAPABILITY_CONTROLLABLE) { - return GregtechTileCapabilities.CAPABILITY_CONTROLLABLE.cast(this); - } - return super.getCapability(capability, side); - } - - @Override - public boolean isWorkingEnabled() { - return this.minerLogic.isWorkingEnabled(); - } - - @Override - public void setWorkingEnabled(boolean isActivationAllowed) { - this.minerLogic.setWorkingEnabled(isActivationAllowed); - } - - @Override - public boolean isNeedsVenting() { - return this.needsVenting; - } - - public void setVentingStuck(boolean ventingStuck) { - if (this.ventingStuck == ventingStuck) return; - this.ventingStuck = ventingStuck; - if (!this.getWorld().isRemote) { - this.markDirty(); - this.writeCustomData(GregtechDataCodes.VENTING_STUCK, (buf) -> buf.writeBoolean(ventingStuck)); - } - } - - @Override - public void tryDoVenting() { - if (GTUtility.tryVenting(getWorld(), getPos(), EnumFacing.UP, - 6, true, - ConfigHolder.machines.machineSounds && !this.isMuffled())) { - setNeedsVenting(false); - } else { - setVentingStuck(true); - } - } - - @Override - public boolean isVentingStuck() { - return ventingStuck; - } - - @Override - public void setNeedsVenting(boolean needsVenting) { - this.needsVenting = needsVenting; - if (!needsVenting && this.ventingStuck) - this.setVentingStuck(false); - - if (!this.getWorld().isRemote) { - this.markDirty(); - this.writeCustomData(GregtechDataCodes.NEEDS_VENTING, (buf) -> buf.writeBoolean(needsVenting)); - } - } - - @Nonnull - @Override - public List getDataInfo() { - int diameter = this.minerLogic.getCurrentDiameter(); - return Collections.singletonList(new TextComponentTranslation("gregtech.machine.miner.working_area", diameter, diameter)); - } -} diff --git a/src/main/java/gregtech/loaders/recipe/MetaTileEntityLoader.java b/src/main/java/gregtech/loaders/recipe/MetaTileEntityLoader.java index 8414e05508b..f110d3780b1 100644 --- a/src/main/java/gregtech/loaders/recipe/MetaTileEntityLoader.java +++ b/src/main/java/gregtech/loaders/recipe/MetaTileEntityLoader.java @@ -199,7 +199,6 @@ public static void init() { ModHandler.addShapedRecipe(true, "steam_alloy_smelter_steel", MetaTileEntities.STEAM_ALLOY_SMELTER_STEEL.getStackForm(), "WSW", "WMW", "WPW", 'M', MetaTileEntities.STEAM_ALLOY_SMELTER_BRONZE.getStackForm(), 'S', new UnificationEntry(OrePrefix.plate, Materials.Steel), 'W', new UnificationEntry(OrePrefix.plate, Materials.WroughtIron), 'P', new UnificationEntry(OrePrefix.pipeSmallFluid, Materials.TinAlloy)); ModHandler.addShapedRecipe(true, "steam_rock_breaker_bronze", MetaTileEntities.STEAM_ROCK_BREAKER_BRONZE.getStackForm(), "PXP", "XMX", "DXD", 'M', MetaBlocks.STEAM_CASING.getItemVariant(BRONZE_HULL), 'X', new UnificationEntry(OrePrefix.pipeSmallFluid, Materials.Bronze), 'P', "craftingPiston", 'D', new UnificationEntry(OrePrefix.gem, Materials.Diamond)); ModHandler.addShapedRecipe(true, "steam_rock_breaker_steel", MetaTileEntities.STEAM_ROCK_BREAKER_STEEL.getStackForm(), "WSW", "PMP", "WWW", 'M', MetaTileEntities.STEAM_ROCK_BREAKER_BRONZE.getStackForm(), 'W', new UnificationEntry(OrePrefix.plate, Materials.WroughtIron), 'S', new UnificationEntry(OrePrefix.plate, Materials.Steel), 'P', new UnificationEntry(OrePrefix.pipeSmallFluid, Materials.TinAlloy)); - ModHandler.addShapedRecipe(true, "steam_miner", MetaTileEntities.STEAM_MINER.getStackForm(), "DSD", "SMS", "GSG", 'M', MetaBlocks.STEAM_CASING.getItemVariant(BRONZE_HULL), 'S', new UnificationEntry(OrePrefix.pipeNormalFluid, Materials.Bronze), 'D', new UnificationEntry(OrePrefix.gem, Materials.Diamond), 'G', new UnificationEntry(OrePrefix.gearSmall, Materials.Bronze)); // MULTI BLOCK CONTROLLERS ModHandler.addShapedRecipe(true, "bronze_primitive_blast_furnace", MetaTileEntities.PRIMITIVE_BLAST_FURNACE.getStackForm(), "hRS", "PBR", "dRS", 'R', new UnificationEntry(OrePrefix.stick, Materials.Iron), 'S', new UnificationEntry(OrePrefix.screw, Materials.Iron), 'P', new UnificationEntry(OrePrefix.plate, Materials.Iron), 'B', MetaBlocks.METAL_CASING.getItemVariant(PRIMITIVE_BRICKS)); diff --git a/src/main/resources/assets/gregtech/models/block/mining_pipe/bronze.json b/src/main/resources/assets/gregtech/models/block/mining_pipe/bronze.json deleted file mode 100644 index cd6e6c4826e..00000000000 --- a/src/main/resources/assets/gregtech/models/block/mining_pipe/bronze.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "parent": "gregtech:block/mining_pipe/base", - "textures": { - "texture": "gregtech:blocks/casings/solid/machine_bronze_plated_bricks" - } -} diff --git a/src/main/resources/assets/gregtech/models/block/mining_pipe/bronze_bottom.json b/src/main/resources/assets/gregtech/models/block/mining_pipe/bronze_bottom.json deleted file mode 100644 index 1042660f918..00000000000 --- a/src/main/resources/assets/gregtech/models/block/mining_pipe/bronze_bottom.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "parent": "gregtech:block/mining_pipe/base_bottom", - "textures": { - "texture": "gregtech:blocks/casings/solid/machine_bronze_plated_bricks" - } -} From f028a3e933c0a40dce154e3f7e359dde30697da4 Mon Sep 17 00:00:00 2001 From: Tictim Date: Thu, 16 Nov 2023 13:15:22 +0900 Subject: [PATCH 12/27] Relocate mining pipe model classes to client package --- src/main/java/gregtech/client/ClientProxy.java | 2 +- .../miner => client/model/miningpipe}/MiningPipeModel.java | 2 +- .../miner => client/model/miningpipe}/MiningPipeModels.java | 4 +++- .../common/metatileentities/miner/LargeMinerType.java | 1 + .../common/metatileentities/miner/LargeMinerTypes.java | 2 ++ .../metatileentities/miner/MetaTileEntityLargeMiner.java | 1 + .../common/metatileentities/miner/MetaTileEntityMiner.java | 2 ++ .../java/gregtech/common/metatileentities/miner/Miner.java | 1 + .../common/metatileentities/miner/MinerRenderHelper.java | 1 + .../common/metatileentities/miner/SimpleMiningPipeModel.java | 1 + 10 files changed, 14 insertions(+), 3 deletions(-) rename src/main/java/gregtech/{common/metatileentities/miner => client/model/miningpipe}/MiningPipeModel.java (82%) rename src/main/java/gregtech/{common/metatileentities/miner => client/model/miningpipe}/MiningPipeModels.java (78%) diff --git a/src/main/java/gregtech/client/ClientProxy.java b/src/main/java/gregtech/client/ClientProxy.java index 62bf4f09285..039ac6e16c3 100644 --- a/src/main/java/gregtech/client/ClientProxy.java +++ b/src/main/java/gregtech/client/ClientProxy.java @@ -25,7 +25,7 @@ import gregtech.common.blocks.MetaBlocks; import gregtech.common.items.MetaItems; import gregtech.common.items.ToolItems; -import gregtech.common.metatileentities.miner.MiningPipeModels; +import gregtech.client.model.miningpipe.MiningPipeModels; import net.minecraft.block.Block; import net.minecraft.client.Minecraft; import net.minecraft.client.resources.I18n; diff --git a/src/main/java/gregtech/common/metatileentities/miner/MiningPipeModel.java b/src/main/java/gregtech/client/model/miningpipe/MiningPipeModel.java similarity index 82% rename from src/main/java/gregtech/common/metatileentities/miner/MiningPipeModel.java rename to src/main/java/gregtech/client/model/miningpipe/MiningPipeModel.java index 2be985f07c1..910a9e48341 100644 --- a/src/main/java/gregtech/common/metatileentities/miner/MiningPipeModel.java +++ b/src/main/java/gregtech/client/model/miningpipe/MiningPipeModel.java @@ -1,4 +1,4 @@ -package gregtech.common.metatileentities.miner; +package gregtech.client.model.miningpipe; import net.minecraft.client.renderer.block.model.IBakedModel; diff --git a/src/main/java/gregtech/common/metatileentities/miner/MiningPipeModels.java b/src/main/java/gregtech/client/model/miningpipe/MiningPipeModels.java similarity index 78% rename from src/main/java/gregtech/common/metatileentities/miner/MiningPipeModels.java rename to src/main/java/gregtech/client/model/miningpipe/MiningPipeModels.java index 6036303cce8..a978a2529d5 100644 --- a/src/main/java/gregtech/common/metatileentities/miner/MiningPipeModels.java +++ b/src/main/java/gregtech/client/model/miningpipe/MiningPipeModels.java @@ -1,4 +1,6 @@ -package gregtech.common.metatileentities.miner; +package gregtech.client.model.miningpipe; + +import gregtech.common.metatileentities.miner.SimpleMiningPipeModel; public class MiningPipeModels { diff --git a/src/main/java/gregtech/common/metatileentities/miner/LargeMinerType.java b/src/main/java/gregtech/common/metatileentities/miner/LargeMinerType.java index 816b45e22d6..3323be47469 100644 --- a/src/main/java/gregtech/common/metatileentities/miner/LargeMinerType.java +++ b/src/main/java/gregtech/common/metatileentities/miner/LargeMinerType.java @@ -2,6 +2,7 @@ import gregtech.api.metatileentity.multiblock.IMultiblockPart; import gregtech.api.pattern.TraceabilityPredicate; +import gregtech.client.model.miningpipe.MiningPipeModel; import gregtech.client.renderer.ICubeRenderer; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; diff --git a/src/main/java/gregtech/common/metatileentities/miner/LargeMinerTypes.java b/src/main/java/gregtech/common/metatileentities/miner/LargeMinerTypes.java index 07da47a88ef..a2308388417 100644 --- a/src/main/java/gregtech/common/metatileentities/miner/LargeMinerTypes.java +++ b/src/main/java/gregtech/common/metatileentities/miner/LargeMinerTypes.java @@ -4,6 +4,8 @@ import gregtech.api.metatileentity.multiblock.MultiblockControllerBase; import gregtech.api.pattern.TraceabilityPredicate; import gregtech.api.unification.material.Materials; +import gregtech.client.model.miningpipe.MiningPipeModel; +import gregtech.client.model.miningpipe.MiningPipeModels; import gregtech.client.renderer.ICubeRenderer; import gregtech.client.renderer.texture.Textures; import gregtech.common.blocks.BlockMetalCasing; diff --git a/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityLargeMiner.java b/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityLargeMiner.java index 94d0dc4ce2d..ce607436b42 100644 --- a/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityLargeMiner.java +++ b/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityLargeMiner.java @@ -31,6 +31,7 @@ import gregtech.api.util.GTTransferUtils; import gregtech.api.util.GTUtility; import gregtech.api.util.TextComponentUtil; +import gregtech.client.model.miningpipe.MiningPipeModel; import gregtech.client.renderer.ICubeRenderer; import gregtech.client.renderer.texture.Textures; import gregtech.core.sound.GTSoundEvents; diff --git a/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityMiner.java b/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityMiner.java index f52e6d23860..c755fbe285a 100644 --- a/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityMiner.java +++ b/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityMiner.java @@ -20,6 +20,8 @@ import gregtech.api.util.GTTransferUtils; import gregtech.api.util.Position; import gregtech.api.util.Size; +import gregtech.client.model.miningpipe.MiningPipeModel; +import gregtech.client.model.miningpipe.MiningPipeModels; import gregtech.client.renderer.texture.Textures; import gregtech.core.sound.GTSoundEvents; import net.minecraft.block.state.IBlockState; diff --git a/src/main/java/gregtech/common/metatileentities/miner/Miner.java b/src/main/java/gregtech/common/metatileentities/miner/Miner.java index 5077f46e2e1..32108ae0d5f 100644 --- a/src/main/java/gregtech/common/metatileentities/miner/Miner.java +++ b/src/main/java/gregtech/common/metatileentities/miner/Miner.java @@ -1,5 +1,6 @@ package gregtech.common.metatileentities.miner; +import gregtech.client.model.miningpipe.MiningPipeModel; import net.minecraft.block.state.IBlockState; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; diff --git a/src/main/java/gregtech/common/metatileentities/miner/MinerRenderHelper.java b/src/main/java/gregtech/common/metatileentities/miner/MinerRenderHelper.java index 6ebd6ec59e8..8580fd6fcde 100644 --- a/src/main/java/gregtech/common/metatileentities/miner/MinerRenderHelper.java +++ b/src/main/java/gregtech/common/metatileentities/miner/MinerRenderHelper.java @@ -2,6 +2,7 @@ import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.util.GTUtility; +import gregtech.client.model.miningpipe.MiningPipeModel; import gregtech.common.entities.MiningPipeEntity; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.BufferBuilder; diff --git a/src/main/java/gregtech/common/metatileentities/miner/SimpleMiningPipeModel.java b/src/main/java/gregtech/common/metatileentities/miner/SimpleMiningPipeModel.java index e3f1769be09..d041c833f6b 100644 --- a/src/main/java/gregtech/common/metatileentities/miner/SimpleMiningPipeModel.java +++ b/src/main/java/gregtech/common/metatileentities/miner/SimpleMiningPipeModel.java @@ -4,6 +4,7 @@ import gregtech.api.GTValues; import gregtech.api.util.GTLog; import gregtech.api.util.GTUtility; +import gregtech.client.model.miningpipe.MiningPipeModel; import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import net.minecraft.client.renderer.block.model.IBakedModel; import net.minecraft.client.renderer.vertex.DefaultVertexFormats; From 6747b3be1232c81ef40fcf2be8cac4c747895ddb Mon Sep 17 00:00:00 2001 From: Tictim Date: Thu, 16 Nov 2023 13:16:20 +0900 Subject: [PATCH 13/27] Relocate miner render helper class to client package --- .../gregtech/client/renderer/handler/MiningPipeRenderer.java | 2 +- .../miner => client/utils}/MinerRenderHelper.java | 3 ++- .../common/metatileentities/miner/SimpleMiningArea.java | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) rename src/main/java/gregtech/{common/metatileentities/miner => client/utils}/MinerRenderHelper.java (99%) diff --git a/src/main/java/gregtech/client/renderer/handler/MiningPipeRenderer.java b/src/main/java/gregtech/client/renderer/handler/MiningPipeRenderer.java index ae93c9aada3..a9ee8b4727d 100644 --- a/src/main/java/gregtech/client/renderer/handler/MiningPipeRenderer.java +++ b/src/main/java/gregtech/client/renderer/handler/MiningPipeRenderer.java @@ -1,7 +1,7 @@ package gregtech.client.renderer.handler; import gregtech.common.entities.MiningPipeEntity; -import gregtech.common.metatileentities.miner.MinerRenderHelper; +import gregtech.client.utils.MinerRenderHelper; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.entity.Render; import net.minecraft.client.renderer.entity.RenderManager; diff --git a/src/main/java/gregtech/common/metatileentities/miner/MinerRenderHelper.java b/src/main/java/gregtech/client/utils/MinerRenderHelper.java similarity index 99% rename from src/main/java/gregtech/common/metatileentities/miner/MinerRenderHelper.java rename to src/main/java/gregtech/client/utils/MinerRenderHelper.java index 8580fd6fcde..ce64c8a52f7 100644 --- a/src/main/java/gregtech/common/metatileentities/miner/MinerRenderHelper.java +++ b/src/main/java/gregtech/client/utils/MinerRenderHelper.java @@ -1,9 +1,10 @@ -package gregtech.common.metatileentities.miner; +package gregtech.client.utils; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.util.GTUtility; import gregtech.client.model.miningpipe.MiningPipeModel; import gregtech.common.entities.MiningPipeEntity; +import gregtech.common.metatileentities.miner.Miner; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.BufferBuilder; import net.minecraft.client.renderer.GlStateManager; diff --git a/src/main/java/gregtech/common/metatileentities/miner/SimpleMiningArea.java b/src/main/java/gregtech/common/metatileentities/miner/SimpleMiningArea.java index 78d3fa63bd6..03e1d79a5ab 100644 --- a/src/main/java/gregtech/common/metatileentities/miner/SimpleMiningArea.java +++ b/src/main/java/gregtech/common/metatileentities/miner/SimpleMiningArea.java @@ -1,6 +1,7 @@ package gregtech.common.metatileentities.miner; import gregtech.api.metatileentity.MetaTileEntity; +import gregtech.client.utils.MinerRenderHelper; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.PacketBuffer; import net.minecraft.util.math.AxisAlignedBB; From 51db077b9c1ca5dfda707cf2f0499c780262c234 Mon Sep 17 00:00:00 2001 From: Tictim Date: Thu, 16 Nov 2023 13:17:05 +0900 Subject: [PATCH 14/27] Fuck --- .../gregtech/client/model/miningpipe/MiningPipeModels.java | 2 -- .../model/miningpipe}/SimpleMiningPipeModel.java | 3 +-- 2 files changed, 1 insertion(+), 4 deletions(-) rename src/main/java/gregtech/{common/metatileentities/miner => client/model/miningpipe}/SimpleMiningPipeModel.java (97%) diff --git a/src/main/java/gregtech/client/model/miningpipe/MiningPipeModels.java b/src/main/java/gregtech/client/model/miningpipe/MiningPipeModels.java index a978a2529d5..7574d677e49 100644 --- a/src/main/java/gregtech/client/model/miningpipe/MiningPipeModels.java +++ b/src/main/java/gregtech/client/model/miningpipe/MiningPipeModels.java @@ -1,7 +1,5 @@ package gregtech.client.model.miningpipe; -import gregtech.common.metatileentities.miner.SimpleMiningPipeModel; - public class MiningPipeModels { private MiningPipeModels() {} diff --git a/src/main/java/gregtech/common/metatileentities/miner/SimpleMiningPipeModel.java b/src/main/java/gregtech/client/model/miningpipe/SimpleMiningPipeModel.java similarity index 97% rename from src/main/java/gregtech/common/metatileentities/miner/SimpleMiningPipeModel.java rename to src/main/java/gregtech/client/model/miningpipe/SimpleMiningPipeModel.java index d041c833f6b..b1e681e4465 100644 --- a/src/main/java/gregtech/common/metatileentities/miner/SimpleMiningPipeModel.java +++ b/src/main/java/gregtech/client/model/miningpipe/SimpleMiningPipeModel.java @@ -1,10 +1,9 @@ -package gregtech.common.metatileentities.miner; +package gregtech.client.model.miningpipe; import com.google.common.base.Suppliers; import gregtech.api.GTValues; import gregtech.api.util.GTLog; import gregtech.api.util.GTUtility; -import gregtech.client.model.miningpipe.MiningPipeModel; import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import net.minecraft.client.renderer.block.model.IBakedModel; import net.minecraft.client.renderer.vertex.DefaultVertexFormats; From 02700731573a2968c3f6973e263b7ff7eb62360b Mon Sep 17 00:00:00 2001 From: Tictim Date: Thu, 16 Nov 2023 14:01:39 +0900 Subject: [PATCH 15/27] ? --- .../metatileentities/multi/electric/MetaTileEntityCleanroom.java | 1 - 1 file changed, 1 deletion(-) 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 f54cc171c08..2de93c60273 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/electric/MetaTileEntityCleanroom.java +++ b/src/main/java/gregtech/common/metatileentities/multi/electric/MetaTileEntityCleanroom.java @@ -49,7 +49,6 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.MathHelper; import net.minecraft.util.text.ITextComponent; -import net.minecraft.util.text.Style; import net.minecraft.util.text.TextComponentTranslation; import net.minecraft.util.text.TextFormatting; import net.minecraft.world.World; From 783bb40bbfaeec1f19ab107d1cac530da05b5366 Mon Sep 17 00:00:00 2001 From: Tictim Date: Thu, 16 Nov 2023 14:02:25 +0900 Subject: [PATCH 16/27] Don't lie --- src/main/java/gregtech/common/metatileentities/miner/Miner.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/gregtech/common/metatileentities/miner/Miner.java b/src/main/java/gregtech/common/metatileentities/miner/Miner.java index 32108ae0d5f..6c02240fdf0 100644 --- a/src/main/java/gregtech/common/metatileentities/miner/Miner.java +++ b/src/main/java/gregtech/common/metatileentities/miner/Miner.java @@ -27,7 +27,7 @@ public interface Miner { * {@code false} means the operation cannot be done (ex. not enough inventory space to store the drops). Returning * {@code false} will momentarily halt the miner operation. * - * @param world the {@link WorldServer} the miner is in + * @param world the {@link World} the miner is in * @param pos the {@link BlockPos} of the block being mined * @param state the {@link IBlockState} of the block being mined * @return Whether the action was successful From a73ff6aed4a55dcd767466d9ac557ee651f13c54 Mon Sep 17 00:00:00 2001 From: Tictim Date: Thu, 16 Nov 2023 14:02:58 +0900 Subject: [PATCH 17/27] Fuck --- src/main/java/gregtech/common/metatileentities/miner/Miner.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/gregtech/common/metatileentities/miner/Miner.java b/src/main/java/gregtech/common/metatileentities/miner/Miner.java index 6c02240fdf0..0004595d4df 100644 --- a/src/main/java/gregtech/common/metatileentities/miner/Miner.java +++ b/src/main/java/gregtech/common/metatileentities/miner/Miner.java @@ -4,7 +4,6 @@ import net.minecraft.block.state.IBlockState; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; -import net.minecraft.world.WorldServer; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; From 01c50580fc0d337b4e9e8605ee79365965733743 Mon Sep 17 00:00:00 2001 From: Tictim Date: Thu, 16 Nov 2023 14:12:58 +0900 Subject: [PATCH 18/27] Lang cleanup --- src/main/resources/assets/gregtech/lang/en_us.lang | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/main/resources/assets/gregtech/lang/en_us.lang b/src/main/resources/assets/gregtech/lang/en_us.lang index d6b9a5b5f88..cd0c3bd9111 100644 --- a/src/main/resources/assets/gregtech/lang/en_us.lang +++ b/src/main/resources/assets/gregtech/lang/en_us.lang @@ -2855,8 +2855,6 @@ gregtech.machine.steam_rock_breaker_bronze.name=Steam Rock Breaker gregtech.machine.steam_rock_breaker_bronze.tooltip=Requires §bWater§7 and §cLava§7 horizontally adjacent gregtech.machine.steam_rock_breaker_steel.name=High Pressure Steam Rock Breaker gregtech.machine.steam_rock_breaker_steel.tooltip=Requires §bWater§7 and §cLava§7 horizontally adjacent -gregtech.machine.steam_miner.name=Steam Miner -gregtech.machine.steam_miner.tooltip=Mines ores below the Miner! # Generators gregtech.machine.combustion_generator.tooltip=Requires flammable Liquids @@ -4676,10 +4674,6 @@ gregtech.machine.miner.multi.needsfluid=No Drilling Fluid! gregtech.machine.miner.working_area=Working Area: %dx%d blocks gregtech.machine.miner.working_area_chunks=Working Area: %dx%d chunks -gregtech.machine.steam_miner.vent=Venting Blocked! -gregtech.machine.steam_miner.steam=Needs Steam! -gregtech.machine.miner.errorradius=§cCannot change radius while working! - gregtech.machine.miner.display.working_area=Working Area: %sx%s blocks gregtech.machine.miner.display.working_area.chunks=Working Area: %sx%s chunks gregtech.machine.miner.display.working_area.preview=[§bPreview§r] From 2b0350ce3ed3e4e54fea3563ae63b29b1db15dc3 Mon Sep 17 00:00:00 2001 From: Tictim Date: Sun, 19 Nov 2023 12:25:27 +0900 Subject: [PATCH 19/27] More GUI shenanigans --- .../java/gregtech/api/gui/GuiTextures.java | 2 +- .../miner/MetaTileEntityLargeMiner.java | 188 +++++++++++------- .../metatileentities/miner/MinerUtil.java | 4 + .../resources/assets/gregtech/lang/en_us.lang | 12 +- .../gui/widget/button_miner_config_mode.png | Bin 0 -> 371 bytes .../gui/widget/button_miner_modes.png | Bin 621 -> 0 bytes 6 files changed, 126 insertions(+), 80 deletions(-) create mode 100644 src/main/resources/assets/gregtech/textures/gui/widget/button_miner_config_mode.png delete mode 100644 src/main/resources/assets/gregtech/textures/gui/widget/button_miner_modes.png diff --git a/src/main/java/gregtech/api/gui/GuiTextures.java b/src/main/java/gregtech/api/gui/GuiTextures.java index 73e50345e7c..1bba05047a9 100644 --- a/src/main/java/gregtech/api/gui/GuiTextures.java +++ b/src/main/java/gregtech/api/gui/GuiTextures.java @@ -71,7 +71,7 @@ public class GuiTextures { public static final TextureArea BUTTON_NO_FLEX = TextureArea.fullImage("textures/gui/widget/button_no_flex.png"); public static final TextureArea BUTTON_MULTI_MAP = TextureArea.fullImage("textures/gui/widget/button_multi_map.png"); public static final TextureArea BUTTON_MINER_AREA_PREVIEW = TextureArea.fullImage("textures/gui/widget/button_miner_area_preview.png"); - public static final TextureArea BUTTON_MINER_MODES = TextureArea.fullImage("textures/gui/widget/button_miner_modes.png"); + public static final TextureArea BUTTON_MINER_CONFIG_MODE = TextureArea.fullImage("textures/gui/widget/button_miner_config_mode.png"); public static final TextureArea BUTTON_THROTTLE_MINUS = TextureArea.fullImage("textures/gui/widget/button_throttle_minus.png"); public static final TextureArea BUTTON_THROTTLE_PLUS = TextureArea.fullImage("textures/gui/widget/button_throttle_plus.png"); diff --git a/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityLargeMiner.java b/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityLargeMiner.java index ce607436b42..94bf57a0f4e 100644 --- a/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityLargeMiner.java +++ b/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityLargeMiner.java @@ -14,8 +14,10 @@ import gregtech.api.capability.impl.FluidTankList; import gregtech.api.capability.impl.ItemHandlerList; import gregtech.api.gui.GuiTextures; +import gregtech.api.gui.ModularUI; import gregtech.api.gui.Widget; import gregtech.api.gui.resources.TextureArea; +import gregtech.api.gui.widgets.AdvancedTextWidget; import gregtech.api.gui.widgets.ImageCycleButtonWidget; import gregtech.api.items.toolitem.ToolHelper; import gregtech.api.metatileentity.IDataInfoProvider; @@ -37,6 +39,7 @@ import gregtech.core.sound.GTSoundEvents; import net.minecraft.block.state.IBlockState; import net.minecraft.client.resources.I18n; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.PacketBuffer; @@ -64,6 +67,7 @@ import java.util.Collections; import java.util.List; import java.util.Objects; +import java.util.concurrent.atomic.AtomicBoolean; import static gregtech.api.unification.material.Materials.DrillingFluid; @@ -285,17 +289,50 @@ public void addToolUsages(ItemStack stack, @Nullable World world, List t tooltip.add(I18n.format("gregtech.tool_action.crowbar")); } + @Nullable + private AtomicBoolean uiConfigModeStateHolder; + + @Override + protected ModularUI.Builder createUITemplate(EntityPlayer entityPlayer) { + AtomicBoolean stateHolder = new AtomicBoolean(); + this.uiConfigModeStateHolder = stateHolder; + ModularUI.Builder b = super.createUITemplate(entityPlayer); + b.widget(new AdvancedTextWidget(9, 20, l -> addRealDisplayText(l, stateHolder.get()), 0xFFFFFF) + .setMaxWidthLimit(181) + .setClickHandler(this::handleDisplayClick)); + this.uiConfigModeStateHolder = null; + return b; + } + + @Nonnull @Override - protected void addDisplayText(List textList) { - super.addDisplayText(textList); + protected Widget getFlexButton(int x, int y, int width, int height) { + AtomicBoolean stateHolder = this.uiConfigModeStateHolder; + if (stateHolder == null) return super.getFlexButton(x, y, width, height); + return new ImageCycleButtonWidget(x, y, width, height, GuiTextures.BUTTON_MINER_CONFIG_MODE, + stateHolder::get, stateHolder::set) + .setTooltipHoverString(i -> i == 0 ? + "gregtech.machine.miner.button.tooltip.info" : + "gregtech.machine.miner.button.tooltip.config"); + } + + @Override + protected void addDisplayText(List textList) {} // unused + + protected void addRealDisplayText(List textList, boolean configMode) { + if (!configMode) { + super.addDisplayText(textList); + } if (!this.isStructureFormed()) return; - if (energyContainer != null && energyContainer.getEnergyCapacity() > 0) { - int energyContainer = getEnergyTier(); - long maxVoltage = GTValues.V[energyContainer]; - String voltageName = GTValues.VNF[energyContainer]; - textList.add(new TextComponentTranslation("gregtech.multiblock.max_energy_per_tick", maxVoltage, voltageName)); + if (!configMode) { + if (energyContainer != null && energyContainer.getEnergyCapacity() > 0) { + int energyContainer = getEnergyTier(); + long maxVoltage = GTValues.V[energyContainer]; + String voltageName = GTValues.VNF[energyContainer]; + textList.add(new TextComponentTranslation("gregtech.multiblock.max_energy_per_tick", maxVoltage, voltageName)); + } } ITextComponent areaText; @@ -309,59 +346,69 @@ protected void addDisplayText(List textList) { maxArea = this.minerLogic.getMaximumDiameter(); areaText = new TextComponentTranslation("gregtech.machine.miner.display.working_area", area, area); } - areaText.appendText(" ").appendSibling(incrButton(area, maxArea, MinerUtil.DISPLAY_CLICK_AREA_INCR)) - .appendText(" ").appendSibling(decrButton(area, 1, MinerUtil.DISPLAY_CLICK_AREA_DECR)); - textList.add(areaText.appendText(" ").appendSibling(previewAreaButton(this.minerLogic.isPreviewEnabled()))); - - int yLimit = this.minerLogic.getYLimit(); - ITextComponent value; - ITextComponent hoverText; - if (yLimit > 0) { - value = new TextComponentString(String.format("%,d", yLimit)); - hoverText = new TextComponentTranslation("gregtech.machine.miner.display.y_limit.value_hover_tooltip", value.createCopy()); - } else { - value = new TextComponentTranslation("gregtech.machine.miner.display.y_limit.no_value"); - hoverText = new TextComponentTranslation("gregtech.machine.miner.display.y_limit.value_hover_tooltip.no_value"); - } - textList.add(new TextComponentTranslation( - "gregtech.machine.miner.display.y_limit", new TextComponentString("") - .appendSibling(incrButton(yLimit, Integer.MAX_VALUE, MinerUtil.DISPLAY_CLICK_Y_LIMIT_INCR)) - .appendText(" ").appendSibling(decrButton(yLimit, 0, MinerUtil.DISPLAY_CLICK_Y_LIMIT_DECR)) - .appendText(" ").appendSibling(value)) - .setStyle(new Style().setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverText)))); - - boolean currentValue = this.minerLogic.isRepeat(); - textList.add(new TextComponentTranslation("gregtech.machine.miner.display.repeat", - this.minerLogic.isWorking() ? - new TextComponentTranslation(this.minerLogic.isRepeat() ? - "gregtech.machine.miner.display.enabled" : - "gregtech.machine.miner.display.disabled") : - new TextComponentTranslation(currentValue ? - "gregtech.machine.miner.display.toggle.enabled" : - "gregtech.machine.miner.display.toggle.disabled") - .setStyle(button(currentValue ? MinerUtil.DISPLAY_CLICK_REPEAT_DISABLE : MinerUtil.DISPLAY_CLICK_REPEAT_ENABLE)))); - - ITextComponent replaceOreText = new TextComponentTranslation( - this.minerLogic.getOreReplacement().getBlock().getTranslationKey() + ".name"); - if (!this.minerLogic.isWorking()) { - replaceOreText = new TextComponentString("[") - .appendSibling(replaceOreText.setStyle(new Style().setColor(TextFormatting.AQUA))) - .appendText("]").setStyle(button(this.minerLogic.isReplaceOreWithAir() ? - MinerUtil.DISPLAY_CLICK_REPLACE_ORE_DISABLE : MinerUtil.DISPLAY_CLICK_REPLACE_ORE_ENABLE)); - } - textList.add(new TextComponentTranslation("gregtech.machine.miner.display.replace_ore", replaceOreText)); + if (configMode) { + areaText.appendText(" ").appendSibling(incrButton(area, maxArea, MinerUtil.DISPLAY_CLICK_AREA_INCR)) + .appendText(" ").appendSibling(decrButton(area, 1, MinerUtil.DISPLAY_CLICK_AREA_DECR)) + .appendText(" ").appendSibling(previewAreaButton(this.minerLogic.isPreviewEnabled())); + } - appendWorkingStatus(textList); + textList.add(areaText); + + if (configMode) { + int yLimit = this.minerLogic.getYLimit(); + ITextComponent value; + ITextComponent hoverText; + if (yLimit > 0) { + value = new TextComponentString(String.format("%,d", yLimit)); + hoverText = new TextComponentTranslation("gregtech.machine.miner.display.y_limit.value_hover_tooltip", value.createCopy()); + } else { + value = new TextComponentTranslation("gregtech.machine.miner.display.y_limit.no_value"); + hoverText = new TextComponentTranslation("gregtech.machine.miner.display.y_limit.value_hover_tooltip.no_value"); + } + textList.add(new TextComponentTranslation( + "gregtech.machine.miner.display.y_limit", new TextComponentString("") + .appendSibling(incrButton(yLimit, Integer.MAX_VALUE, MinerUtil.DISPLAY_CLICK_Y_LIMIT_INCR)) + .appendText(" ").appendSibling(decrButton(yLimit, 0, MinerUtil.DISPLAY_CLICK_Y_LIMIT_DECR)) + .appendText(" ").appendSibling(value)) + .setStyle(new Style().setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverText)))); + + textList.add(new TextComponentTranslation("gregtech.machine.miner.display.repeat", + toggleButton(this.minerLogic.isRepeat(), this.minerLogic.isWorking(), + MinerUtil.DISPLAY_CLICK_REPEAT_ENABLE, MinerUtil.DISPLAY_CLICK_REPEAT_DISABLE))); + + textList.add(new TextComponentTranslation("gregtech.machine.miner.display.chunk_mode", + toggleButton(this.minerLogic.isRepeat(), this.minerLogic.isWorking(), + MinerUtil.DISPLAY_CLICK_CHUNK_MODE_ENABLE, MinerUtil.DISPLAY_CLICK_CHUNK_MODE_DISABLE))); + + textList.add(new TextComponentTranslation("gregtech.machine.miner.display.silk_touch", + toggleButton(this.minerLogic.isRepeat(), this.minerLogic.isWorking(), + MinerUtil.DISPLAY_CLICK_SILK_TOUCH_ENABLE, MinerUtil.DISPLAY_CLICK_SILK_TOUCH_DISABLE))); + + ITextComponent replaceOreText = new TextComponentTranslation( + this.minerLogic.getOreReplacement().getBlock().getTranslationKey() + ".name"); + if (!this.minerLogic.isWorking()) { + replaceOreText = new TextComponentString("[") + .appendSibling(replaceOreText.setStyle(new Style().setColor(TextFormatting.AQUA))) + .appendText("]").setStyle(button(this.minerLogic.isReplaceOreWithAir() ? + MinerUtil.DISPLAY_CLICK_REPLACE_ORE_DISABLE : MinerUtil.DISPLAY_CLICK_REPLACE_ORE_ENABLE)); + } - textList.add(new TextComponentTranslation("gregtech.machine.miner.display.stats.total_mined", this.minedOreCount)); - if (this.hasLastMinedOre) { - textList.add(new TextComponentTranslation("gregtech.machine.miner.display.stats.last_mined", - this.lastMinedOre.getX(), this.lastMinedOre.getY(), this.lastMinedOre.getZ())); + textList.add(new TextComponentTranslation("gregtech.machine.miner.display.replace_ore", replaceOreText)); + } else { + appendWorkingStatus(textList); + + textList.add(new TextComponentTranslation( + "gregtech.machine.miner.display.stats.total_mined", this.minedOreCount)); + if (this.hasLastMinedOre) { + textList.add(new TextComponentTranslation( + "gregtech.machine.miner.display.stats.last_mined", + this.lastMinedOre.getX(), this.lastMinedOre.getY(), this.lastMinedOre.getZ())); + } } } - private void appendWorkingStatus(List textList) { + protected void appendWorkingStatus(List textList) { if (!this.minerLogic.isDone()) { MiningArea miningArea = minerLogic.getMiningArea(); if (miningArea != null) { @@ -403,6 +450,16 @@ protected static ITextComponent decrButton(int currentValue, int minValue, @Nonn new TextComponentTranslation("gregtech.machine.miner.display.decr").setStyle(button(event)); } + @Nonnull + protected static ITextComponent toggleButton(boolean currentValue, boolean canInteract, @Nonnull String onEvent, @Nonnull String offEvent) { + return canInteract ? + new TextComponentTranslation(currentValue ? + "gregtech.machine.miner.display.enabled" : "gregtech.machine.miner.display.disabled") : + new TextComponentTranslation(currentValue ? + "gregtech.machine.miner.display.toggle.enabled" : "gregtech.machine.miner.display.toggle.disabled") + .setStyle(button(currentValue ? offEvent : onEvent)); + } + @Nonnull protected static Style button(@Nonnull String event) { return new Style().setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "@!" + event)); @@ -440,6 +497,10 @@ protected void handleDisplayClick(String componentData, Widget.ClickData clickDa case MinerUtil.DISPLAY_CLICK_REPEAT_DISABLE -> this.minerLogic.setRepeat(false); case MinerUtil.DISPLAY_CLICK_REPLACE_ORE_ENABLE -> this.minerLogic.setReplaceOreWithAir(true); case MinerUtil.DISPLAY_CLICK_REPLACE_ORE_DISABLE -> this.minerLogic.setReplaceOreWithAir(false); + case MinerUtil.DISPLAY_CLICK_CHUNK_MODE_ENABLE -> this.minerLogic.setChunkMode(true); + case MinerUtil.DISPLAY_CLICK_CHUNK_MODE_DISABLE -> this.minerLogic.setChunkMode(false); + case MinerUtil.DISPLAY_CLICK_SILK_TOUCH_ENABLE -> this.minerLogic.setSilkTouchMode(true); + case MinerUtil.DISPLAY_CLICK_SILK_TOUCH_DISABLE -> this.minerLogic.setSilkTouchMode(false); } } @@ -533,25 +594,6 @@ protected ICubeRenderer getFrontOverlay() { return this.type.getFrontOverlay(); } - @Nonnull - @Override - protected Widget getFlexButton(int x, int y, int width, int height) { - return new ImageCycleButtonWidget(x, y, width, height, GuiTextures.BUTTON_MINER_MODES, 4, () -> { - int mode = 0; - if (minerLogic.isChunkMode()) mode |= 1; - if (minerLogic.isSilkTouchMode()) mode |= 2; - return mode; - }, m -> { - minerLogic.setChunkMode((m & 1) != 0); - minerLogic.setSilkTouchMode((m & 2) != 0); - }).setTooltipHoverString(m -> switch (m) { - case 0 -> "gregtech.multiblock.miner.neither_mode"; - case 1 -> "gregtech.multiblock.miner.chunk_mode"; - case 2 -> "gregtech.multiblock.miner.silk_touch_mode"; - default -> "gregtech.multiblock.miner.both_modes"; - }); - } - @Override public boolean hasMaintenanceMechanics() { return false; diff --git a/src/main/java/gregtech/common/metatileentities/miner/MinerUtil.java b/src/main/java/gregtech/common/metatileentities/miner/MinerUtil.java index 8746efa11a1..986ca402925 100644 --- a/src/main/java/gregtech/common/metatileentities/miner/MinerUtil.java +++ b/src/main/java/gregtech/common/metatileentities/miner/MinerUtil.java @@ -39,6 +39,10 @@ private MinerUtil() {} public static final String DISPLAY_CLICK_REPEAT_DISABLE = "disable_repeat"; public static final String DISPLAY_CLICK_REPLACE_ORE_ENABLE = "enable_replace_ore"; public static final String DISPLAY_CLICK_REPLACE_ORE_DISABLE = "disable_replace_ore"; + public static final String DISPLAY_CLICK_CHUNK_MODE_ENABLE = "enable_chunk_mode"; + public static final String DISPLAY_CLICK_CHUNK_MODE_DISABLE = "disable_chunk_mode"; + public static final String DISPLAY_CLICK_SILK_TOUCH_ENABLE = "enable_silk_touch"; + public static final String DISPLAY_CLICK_SILK_TOUCH_DISABLE = "disable_silk_touch"; public static final AxisAlignedBB EMPTY_AABB = new AxisAlignedBB(0, 0, 0, 0, 0, 0); diff --git a/src/main/resources/assets/gregtech/lang/en_us.lang b/src/main/resources/assets/gregtech/lang/en_us.lang index cd0c3bd9111..648af1012f9 100644 --- a/src/main/resources/assets/gregtech/lang/en_us.lang +++ b/src/main/resources/assets/gregtech/lang/en_us.lang @@ -4674,6 +4674,9 @@ gregtech.machine.miner.multi.needsfluid=No Drilling Fluid! gregtech.machine.miner.working_area=Working Area: %dx%d blocks gregtech.machine.miner.working_area_chunks=Working Area: %dx%d chunks +gregtech.machine.miner.button.tooltip.info=Information +gregtech.machine.miner.button.tooltip.config=Configuration + gregtech.machine.miner.display.working_area=Working Area: %sx%s blocks gregtech.machine.miner.display.working_area.chunks=Working Area: %sx%s chunks gregtech.machine.miner.display.working_area.preview=[§bPreview§r] @@ -4683,7 +4686,9 @@ gregtech.machine.miner.display.y_limit.no_value=No limit gregtech.machine.miner.display.y_limit.value_hover_tooltip=Miner will operate in §6%s§r Y layer(s) before halting. gregtech.machine.miner.display.y_limit.value_hover_tooltip.no_value=Miner will operate until hitting the bedrock layer. gregtech.machine.miner.display.repeat=Repeat after finished: %s -gregtech.machine.miner.display.replace_ore=Replace mined ore with: %s +gregtech.machine.miner.display.chunk_mode=Chunk Mode: %s +gregtech.machine.miner.display.silk_touch=Silk Touch: %s +gregtech.machine.miner.display.replace_ore=Replace ore with: %s gregtech.machine.miner.display.decr=[§b-§r] gregtech.machine.miner.display.decr.disabled=[§8-§r] gregtech.machine.miner.display.incr=[§b+§r] @@ -5529,11 +5534,6 @@ gregtech.multiblock.large_boiler.explosion_tooltip=Will explode if provided Fuel gregtech.multiblock.large_boiler.water_bar_hover=Water: %s gregtech.multiblock.large_boiler.no_water=No Water! -gregtech.multiblock.miner.neither_mode=Chunk Mode: §cDisabled§r/nSilk Touch Mode: §cDisabled§r/n§7Switching requires an idle machine. -gregtech.multiblock.miner.chunk_mode=Chunk Mode: §aEnabled§r/nSilk Touch Mode: §cDisabled§r/n§7Switching requires an idle machine. -gregtech.multiblock.miner.silk_touch_mode=Chunk Mode: §cDisabled§r/nSilk Touch Mode: §aEnabled§r/n§7Switching requires an idle machine. -gregtech.multiblock.miner.both_modes=Chunk Mode: §aEnabled§r/nSilk Touch Mode: §aEnabled§r/n§7Switching requires an idle machine. - gregtech.multiblock.fluid_rig.drilled_fluid=Fluid: %s gregtech.multiblock.fluid_rig.fluid_amount=Pumping Rate: %s gregtech.multiblock.fluid_rig.vein_depletion=Vein Size: %s diff --git a/src/main/resources/assets/gregtech/textures/gui/widget/button_miner_config_mode.png b/src/main/resources/assets/gregtech/textures/gui/widget/button_miner_config_mode.png new file mode 100644 index 0000000000000000000000000000000000000000..4e2fc39e0ec9226ef5e0be35bb62dee192b1c007 GIT binary patch literal 371 zcmV-(0gV2MP)Px$ElET{R5*>rlrgTuAPk0`s#nPNu8><~&dvdHf^Ky8@{oD}4#2|3$}O0mkUC^x z;skWCit>QAN?+UeFTs{Sj2zotN(nYf2(hQnCQNI++nS2>B(|?zAp~n}Hpg-7`~Du5 z0Yn^z0RWtHobwvq6$~O8W4!m|^xhj|5Ybv2LTF&b5b$$6o`wMcrfDLW$OcBDxFyEg zxz?Y50Aq}E?wkXF@AG+yk=_Z{!Z5~i@UKb|iHKw_G14ssQ(~E%=lSb!008g3l(JwN z7?D!SwOPkBuv?*PeYll{5L)Z4Soh!4t&~zq)#tTJOesZOlE(xQYw~qVfilog=Lsy- zrId=2Nn{1`_XhZcxc>kDzq`BJ+}vEFMMJAoORGamXM&FI6kWslh9)aaOxK!fwrlE5 z*VCD(qd!w$tyWEUlCFBax<<2xcCWThzmDk|Q`2>(mb)xfN>$Vw)Qy)Lo2)i5US_P` zsIE6nPj9N8!E6K73RSHxEsL!d+TGe}HEKpnj7(OU7|by+-)yeYq@mfWsokTkKSSSS zrHOW*w((M9i)|LVlXa~RSgTg58Z96 z4+40aE?6_MUfd`;cMhL>`hw3tl4@S|t$o0i(*2++VVC(t{#{$&zw$*Q{gzXWT{pD#WazaROcox38vKQx2*ioVE4?k@~f`h zzrdUn`ZwQo4OddA!0M(5(IcxA!dN$Ib%Z*uxfSr;PYbB}R?*ceXZ{mYs;staJ&&B1 zzA0i$Ua0-4=hR=Z9+{cf#TchK9WkgG|NRz~Wo6RRex<#Jt>4h`KVc2zny^qlAE wO{=v2A6&a=)xYgZFtd@Z%gwOfo+WW#lixx&)FgEZFk~4#UHx3vIVCg!07De=&Hw-a From 427c106f051ff18ccce8eea55407a638b274ea90 Mon Sep 17 00:00:00 2001 From: Tictim Date: Sun, 19 Nov 2023 12:27:50 +0900 Subject: [PATCH 20/27] oops --- .../common/metatileentities/miner/LargeMinerTypes.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/gregtech/common/metatileentities/miner/LargeMinerTypes.java b/src/main/java/gregtech/common/metatileentities/miner/LargeMinerTypes.java index a2308388417..726d85533fd 100644 --- a/src/main/java/gregtech/common/metatileentities/miner/LargeMinerTypes.java +++ b/src/main/java/gregtech/common/metatileentities/miner/LargeMinerTypes.java @@ -66,9 +66,9 @@ public MiningPipeModel getMiningPipeModel() { @SideOnly(Side.CLIENT) public ICubeRenderer getFrontOverlay() { return switch (this) { - case STEEL -> Textures.LARGE_MINER_OVERLAY_ADVANCED; - case TITANIUM -> Textures.LARGE_MINER_OVERLAY_ADVANCED_2; - case TUNGSTEN_STEEL -> Textures.LARGE_MINER_OVERLAY_BASIC; + case STEEL -> Textures.LARGE_MINER_OVERLAY_BASIC; + case TITANIUM -> Textures.LARGE_MINER_OVERLAY_ADVANCED; + case TUNGSTEN_STEEL -> Textures.LARGE_MINER_OVERLAY_ADVANCED_2; }; } } From e7cac6d37c284a3a18362ef84327e30d5a2c4384 Mon Sep 17 00:00:00 2001 From: Tictim Date: Thu, 23 Nov 2023 17:11:03 +0900 Subject: [PATCH 21/27] me and my boys merging --- .../java/gregtech/api/util/GTUtility.java | 3 +-- .../miner/MetaTileEntityLargeMiner.java | 4 +-- .../miner/MetaTileEntityMiner.java | 17 +++++-------- .../metatileentities/miner/MinerLogic.java | 25 ++++++++----------- 4 files changed, 19 insertions(+), 30 deletions(-) diff --git a/src/main/java/gregtech/api/util/GTUtility.java b/src/main/java/gregtech/api/util/GTUtility.java index 8606cd9d25d..0fd91fde230 100644 --- a/src/main/java/gregtech/api/util/GTUtility.java +++ b/src/main/java/gregtech/api/util/GTUtility.java @@ -6,9 +6,9 @@ import gregtech.api.block.machines.MachineItemBlock; import gregtech.api.capability.IMultipleTankHandler; import gregtech.api.cover.CoverDefinition; +import gregtech.api.damagesources.DamageSources; import gregtech.api.fluids.GTFluid; import gregtech.api.items.behavior.CoverItemBehavior; -import gregtech.api.damagesources.DamageSources; import gregtech.api.items.metaitem.MetaItem; import gregtech.api.items.metaitem.stats.IItemBehaviour; import gregtech.api.items.toolitem.ToolClasses; @@ -19,7 +19,6 @@ import gregtech.api.recipes.RecipeMap; import gregtech.api.unification.OreDictUnifier; import gregtech.api.unification.ore.OrePrefix; -import gregtech.common.items.behaviors.CoverPlaceBehavior; import gregtech.core.advancement.AdvancementTriggers; import it.unimi.dsi.fastutil.objects.ObjectOpenCustomHashSet; import net.minecraft.block.Block; diff --git a/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityLargeMiner.java b/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityLargeMiner.java index 94bf57a0f4e..c75deebdaf6 100644 --- a/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityLargeMiner.java +++ b/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityLargeMiner.java @@ -19,6 +19,7 @@ import gregtech.api.gui.resources.TextureArea; import gregtech.api.gui.widgets.AdvancedTextWidget; import gregtech.api.gui.widgets.ImageCycleButtonWidget; +import gregtech.api.items.itemhandlers.GTItemStackHandler; import gregtech.api.items.toolitem.ToolHelper; import gregtech.api.metatileentity.IDataInfoProvider; import gregtech.api.metatileentity.IFastRenderMetaTileEntity; @@ -60,7 +61,6 @@ import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; import net.minecraftforge.items.IItemHandlerModifiable; -import net.minecraftforge.items.ItemStackHandler; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -112,7 +112,7 @@ public MetaTileEntity createMetaTileEntity(IGregTechTileEntity tileEntity) { public void invalidateStructure() { super.invalidateStructure(); this.inputFluidInventory = new FluidTankList(true); - this.outputInventory = new ItemStackHandler(0); + this.outputInventory = new GTItemStackHandler(this, 0); this.energyContainer = new EnergyContainerList(Lists.newArrayList()); } diff --git a/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityMiner.java b/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityMiner.java index c755fbe285a..eb9bbdea58f 100644 --- a/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityMiner.java +++ b/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityMiner.java @@ -8,10 +8,10 @@ import gregtech.api.capability.GregtechTileCapabilities; import gregtech.api.capability.IControllable; import gregtech.api.capability.impl.EnergyContainerHandler; -import gregtech.api.capability.impl.NotifiableItemStackHandler; import gregtech.api.gui.GuiTextures; import gregtech.api.gui.ModularUI; import gregtech.api.gui.widgets.*; +import gregtech.api.items.itemhandlers.GTItemStackHandler; import gregtech.api.metatileentity.IDataInfoProvider; import gregtech.api.metatileentity.IFastRenderMetaTileEntity; import gregtech.api.metatileentity.MetaTileEntity; @@ -67,7 +67,7 @@ public MetaTileEntityMiner(@Nonnull ResourceLocation metaTileEntityId, int tier, this.inventorySize = (tier + 1) * (tier + 1); this.energyPerTick = GTValues.V[tier - 1]; this.minerLogic = new MinerLogic<>(this, workFrequency, maximumDiameter); - this.chargerInventory = new ItemStackHandler(1); + this.chargerInventory = new GTItemStackHandler(this, 1); initializeInventory(); } @@ -76,14 +76,9 @@ public MetaTileEntity createMetaTileEntity(IGregTechTileEntity tileEntity) { return new MetaTileEntityMiner(metaTileEntityId, getTier(), this.minerLogic.getWorkFrequency(), this.minerLogic.getMaximumDiameter()); } - @Override - protected IItemHandlerModifiable createImportItemHandler() { - return new NotifiableItemStackHandler(0, this, false); - } - @Override protected IItemHandlerModifiable createExportItemHandler() { - return new NotifiableItemStackHandler(inventorySize, this, true); + return new GTItemStackHandler(this, inventorySize); } @Override @@ -256,19 +251,19 @@ public void readFromNBT(NBTTagCompound data) { } @Override - public void writeInitialSyncData(PacketBuffer buf) { + public void writeInitialSyncData(@Nonnull PacketBuffer buf) { super.writeInitialSyncData(buf); this.minerLogic.writeInitialSyncData(buf); } @Override - public void receiveInitialSyncData(PacketBuffer buf) { + public void receiveInitialSyncData(@Nonnull PacketBuffer buf) { super.receiveInitialSyncData(buf); this.minerLogic.receiveInitialSyncData(buf); } @Override - public void receiveCustomData(int dataId, PacketBuffer buf) { + public void receiveCustomData(int dataId, @Nonnull PacketBuffer buf) { super.receiveCustomData(dataId, buf); this.minerLogic.receiveCustomData(dataId, buf); } diff --git a/src/main/java/gregtech/common/metatileentities/miner/MinerLogic.java b/src/main/java/gregtech/common/metatileentities/miner/MinerLogic.java index fee2a076a0e..ef55f1f06db 100644 --- a/src/main/java/gregtech/common/metatileentities/miner/MinerLogic.java +++ b/src/main/java/gregtech/common/metatileentities/miner/MinerLogic.java @@ -450,21 +450,16 @@ public void receiveInitialSyncData(@Nonnull PacketBuffer buf) { * Callback for handling custom data packet sent by miner logic. Call this method in {@link MetaTileEntity#receiveCustomData(int, PacketBuffer)}. */ public void receiveCustomData(int dataId, @Nonnull PacketBuffer buf) { - switch (dataId) { - case GregtechDataCodes.PUMP_HEAD_LEVEL -> { - this.pipeLength = buf.readVarInt(); - } - case GregtechDataCodes.WORKING_ENABLED -> { - this.workingEnabled = buf.readBoolean(); - this.mte.scheduleRenderUpdate(); - } - case GregtechDataCodes.MINER_UPDATE_PREVIEW -> { - readPreviewUpdatePacket(buf); - } - case GregtechDataCodes.MINER_UPDATE_ACTIVE -> { - this.active = buf.readBoolean(); - this.mte.scheduleRenderUpdate(); - } + if (dataId == GregtechDataCodes.PUMP_HEAD_LEVEL) { + this.pipeLength = buf.readVarInt(); + } else if (dataId == GregtechDataCodes.WORKING_ENABLED) { + this.workingEnabled = buf.readBoolean(); + this.mte.scheduleRenderUpdate(); + } else if (dataId == GregtechDataCodes.MINER_UPDATE_PREVIEW) { + readPreviewUpdatePacket(buf); + } else if (dataId == GregtechDataCodes.MINER_UPDATE_ACTIVE) { + this.active = buf.readBoolean(); + this.mte.scheduleRenderUpdate(); } } } From 7fe538ca518bff12237cf4e7601e19fc4ab24f5c Mon Sep 17 00:00:00 2001 From: Tictim Date: Thu, 23 Nov 2023 17:14:35 +0900 Subject: [PATCH 22/27] review --- .../java/gregtech/common/metatileentities/MetaTileEntities.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/gregtech/common/metatileentities/MetaTileEntities.java b/src/main/java/gregtech/common/metatileentities/MetaTileEntities.java index 3f7ec9213fd..0541f3979ce 100644 --- a/src/main/java/gregtech/common/metatileentities/MetaTileEntities.java +++ b/src/main/java/gregtech/common/metatileentities/MetaTileEntities.java @@ -318,6 +318,8 @@ public static void init() { STEAM_ROCK_BREAKER_BRONZE = registerMetaTileEntity(19, new SteamRockBreaker(gregtechId("steam_rock_breaker_bronze"), false)); STEAM_ROCK_BREAKER_STEEL = registerMetaTileEntity(20, new SteamRockBreaker(gregtechId("steam_rock_breaker_steel"), true)); + // Steam Miner ("gregtech:steam_miner"), ID 21; added by external addon for compatibility + // Electric Furnace, IDs 50-64 registerSimpleMetaTileEntity(ELECTRIC_FURNACE, 50, "electric_furnace", RecipeMaps.FURNACE_RECIPES, Textures.ELECTRIC_FURNACE_OVERLAY, true); From 336ecc94cfe6148215b20934e1f535635ce65863 Mon Sep 17 00:00:00 2001 From: Tictim Date: Fri, 1 Dec 2023 11:52:49 +0900 Subject: [PATCH 23/27] change annotations --- .editorconfig | 4 +- .../api/unification/OreDictUnifier.java | 10 +- .../java/gregtech/api/util/BlockUtility.java | 12 +- .../java/gregtech/api/util/GTUtility.java | 6 +- .../model/miningpipe/MiningPipeModel.java | 6 +- .../miningpipe/SimpleMiningPipeModel.java | 28 +++-- .../renderer/handler/MiningPipeRenderer.java | 15 +-- .../client/utils/MinerRenderHelper.java | 17 ++- .../common/entities/MiningPipeEntity.java | 23 ++-- .../miner/LargeMinerType.java | 15 +-- .../miner/LargeMinerTypes.java | 15 +-- .../miner/MetaTileEntityLargeMiner.java | 114 +++++++++++------- .../miner/MetaTileEntityMiner.java | 76 +++++++----- .../common/metatileentities/miner/Miner.java | 11 +- .../metatileentities/miner/MinerLogic.java | 39 +++--- .../metatileentities/miner/MinerUtil.java | 24 ++-- .../metatileentities/miner/MiningArea.java | 25 ++-- .../miner/MultiblockMinerLogic.java | 19 +-- .../miner/SimpleMiningArea.java | 31 ++--- 19 files changed, 284 insertions(+), 206 deletions(-) diff --git a/.editorconfig b/.editorconfig index 14c3798da03..61a63aa508c 100644 --- a/.editorconfig +++ b/.editorconfig @@ -58,9 +58,9 @@ ij_java_blank_lines_around_field_in_interface = 0 ij_java_blank_lines_around_initializer = 1 ij_java_blank_lines_around_method = 1 ij_java_blank_lines_around_method_in_interface = 1 -ij_java_blank_lines_before_class_end = 1 +ij_java_blank_lines_before_class_end = 0 ij_java_blank_lines_before_imports = 1 -ij_java_blank_lines_before_method_body = 1 +ij_java_blank_lines_before_method_body = 0 ij_java_blank_lines_before_package = 1 ij_java_block_brace_style = end_of_line ij_java_block_comment_add_space = false diff --git a/src/main/java/gregtech/api/unification/OreDictUnifier.java b/src/main/java/gregtech/api/unification/OreDictUnifier.java index b6dc49dc875..54d00cd5a81 100644 --- a/src/main/java/gregtech/api/unification/OreDictUnifier.java +++ b/src/main/java/gregtech/api/unification/OreDictUnifier.java @@ -175,8 +175,8 @@ public static Set getOreDictionaryNames(@NotNull ItemStack itemStack) { return getOreDictionaryNames(itemStack.getItem(), itemStack.getItemDamage()); } - @Nonnull - public static Set getOreDictionaryNames(@Nonnull Item item, int metadata) { + @NotNull + public static Set getOreDictionaryNames(@NotNull Item item, int metadata) { ItemVariantMap> nameEntry = stackOreDictName.get(item); if (nameEntry == null) return Collections.emptySet(); Set names = nameEntry.get((short) metadata); @@ -233,7 +233,7 @@ public static MaterialStack getMaterial(ItemStack itemStack) { } @Nullable - public static MaterialStack getMaterial(@Nonnull Item item, int metadata) { + public static MaterialStack getMaterial(@NotNull Item item, int metadata) { ItemAndMetadata key = new ItemAndMetadata(item, metadata); UnificationEntry entry = getOrWildcard(stackUnificationInfo, key); if (entry != null) { @@ -256,12 +256,12 @@ public static ItemMaterialInfo getMaterialInfo(ItemStack itemStack) { } @Nullable - public static OrePrefix getPrefix(@Nonnull ItemStack itemStack) { + public static OrePrefix getPrefix(@NotNull ItemStack itemStack) { return itemStack.isEmpty() ? null : getPrefix(itemStack.getItem(), itemStack.getItemDamage()); } @Nullable - public static OrePrefix getPrefix(@Nonnull Item item, int metadata) { + public static OrePrefix getPrefix(@NotNull Item item, int metadata) { UnificationEntry entry = getOrWildcard(stackUnificationInfo, new ItemAndMetadata(item, metadata)); return entry != null ? entry.orePrefix : null; } diff --git a/src/main/java/gregtech/api/util/BlockUtility.java b/src/main/java/gregtech/api/util/BlockUtility.java index c3ffeff9d3f..1402c2c2a63 100644 --- a/src/main/java/gregtech/api/util/BlockUtility.java +++ b/src/main/java/gregtech/api/util/BlockUtility.java @@ -2,8 +2,7 @@ import gregtech.api.unification.OreDictUnifier; import gregtech.api.unification.ore.OrePrefix; -import it.unimi.dsi.fastutil.objects.Object2BooleanMap; -import it.unimi.dsi.fastutil.objects.Object2BooleanOpenHashMap; + import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.block.state.IBlockState; @@ -11,7 +10,10 @@ import net.minecraft.item.ItemStack; import net.minecraft.util.NonNullList; +import it.unimi.dsi.fastutil.objects.Object2BooleanMap; +import it.unimi.dsi.fastutil.objects.Object2BooleanOpenHashMap; import org.jetbrains.annotations.NotNull; + import java.util.Objects; public class BlockUtility { @@ -23,12 +25,12 @@ public static void startCaptureDrops() { WRAPPER.captureDrops(true); } - @Nonnull + @NotNull public static NonNullList stopCaptureDrops() { return WRAPPER.captureDrops(false); } - public static boolean isOre(@Nonnull IBlockState state) { + public static boolean isOre(@NotNull IBlockState state) { return ORE_CACHE.computeIfAbsent(Objects.requireNonNull(state, "state == null"), s -> { Item item = Item.getItemFromBlock(s.getBlock()); int meta = s.getBlock().getMetaFromState(s); @@ -44,7 +46,7 @@ public static boolean isOre(@Nonnull IBlockState state) { * @param isOre Whether this block state is an ore or not * @throws NullPointerException if {@code state == null} */ - public static void markBlockstateAsOre(@Nonnull IBlockState state, boolean isOre) { + public static void markBlockstateAsOre(@NotNull IBlockState state, boolean isOre) { ORE_CACHE.put(Objects.requireNonNull(state, "state == null"), isOre); } diff --git a/src/main/java/gregtech/api/util/GTUtility.java b/src/main/java/gregtech/api/util/GTUtility.java index ea1233dc2b2..23512da30cc 100644 --- a/src/main/java/gregtech/api/util/GTUtility.java +++ b/src/main/java/gregtech/api/util/GTUtility.java @@ -630,7 +630,7 @@ public static ItemStack toItem(IBlockState state, int amount) { * @deprecated use {@link BlockUtility#isOre(IBlockState)} or check it yourself */ @Deprecated - public static boolean isOre(@Nonnull ItemStack item) { + public static boolean isOre(@NotNull ItemStack item) { OrePrefix orePrefix = OreDictUnifier.getPrefix(item); return orePrefix != null && orePrefix.name().startsWith("ore"); } @@ -775,8 +775,8 @@ public static boolean isBlockSnow(@NotNull IBlockState blockState) { * @param playSound Whether to play sounds or not * @return {@code true} if vented */ - public static boolean tryVenting(@Nonnull World world, @Nonnull BlockPos machinePos, - @Nonnull EnumFacing ventingSide, float ventingDamage, + public static boolean tryVenting(@NotNull World world, @NotNull BlockPos machinePos, + @NotNull EnumFacing ventingSide, float ventingDamage, boolean spawnParticle, boolean playSound) { BlockPos ventingPos = machinePos.offset(ventingSide); IBlockState ventingState = world.getBlockState(ventingPos); diff --git a/src/main/java/gregtech/client/model/miningpipe/MiningPipeModel.java b/src/main/java/gregtech/client/model/miningpipe/MiningPipeModel.java index 910a9e48341..934e6d60ffb 100644 --- a/src/main/java/gregtech/client/model/miningpipe/MiningPipeModel.java +++ b/src/main/java/gregtech/client/model/miningpipe/MiningPipeModel.java @@ -2,13 +2,13 @@ import net.minecraft.client.renderer.block.model.IBakedModel; -import javax.annotation.Nonnull; +import org.jetbrains.annotations.NotNull; public interface MiningPipeModel { - @Nonnull + @NotNull IBakedModel getBaseModel(); - @Nonnull + @NotNull IBakedModel getBottomModel(); } diff --git a/src/main/java/gregtech/client/model/miningpipe/SimpleMiningPipeModel.java b/src/main/java/gregtech/client/model/miningpipe/SimpleMiningPipeModel.java index b1e681e4465..46b7d061204 100644 --- a/src/main/java/gregtech/client/model/miningpipe/SimpleMiningPipeModel.java +++ b/src/main/java/gregtech/client/model/miningpipe/SimpleMiningPipeModel.java @@ -1,10 +1,9 @@ package gregtech.client.model.miningpipe; -import com.google.common.base.Suppliers; import gregtech.api.GTValues; import gregtech.api.util.GTLog; import gregtech.api.util.GTUtility; -import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; + import net.minecraft.client.renderer.block.model.IBakedModel; import net.minecraft.client.renderer.vertex.DefaultVertexFormats; import net.minecraft.util.ResourceLocation; @@ -17,8 +16,11 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.relauncher.Side; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; +import com.google.common.base.Suppliers; +import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + import java.util.Map; import java.util.function.Supplier; @@ -31,12 +33,12 @@ public final class SimpleMiningPipeModel implements MiningPipeModel { return model.bake(model.getDefaultState(), DefaultVertexFormats.ITEM, ModelLoader.defaultTextureGetter()); }); - @Nonnull - public static SimpleMiningPipeModel register(@Nonnull String type) { + @NotNull + public static SimpleMiningPipeModel register(@NotNull String type) { return MINING_PIPE_MODELS.computeIfAbsent(type, SimpleMiningPipeModel::new); } - @Nonnull + @NotNull public final String type; @Nullable @@ -48,17 +50,17 @@ public static SimpleMiningPipeModel register(@Nonnull String type) { @Nullable private IModel unbakedBottomModel; - private SimpleMiningPipeModel(@Nonnull String type) { + private SimpleMiningPipeModel(@NotNull String type) { this.type = type; } - @Nonnull + @NotNull @Override public IBakedModel getBaseModel() { return this.baseModel != null ? this.baseModel : MISSING_MODEL_MEMOIZE.get(); } - @Nonnull + @NotNull @Override public IBakedModel getBottomModel() { return this.bottomModel != null ? this.bottomModel : MISSING_MODEL_MEMOIZE.get(); @@ -72,8 +74,10 @@ public String toString() { @SubscribeEvent public static void onTextureStitch(TextureStitchEvent.Pre event) { for (SimpleMiningPipeModel miningPipe : MINING_PIPE_MODELS.values()) { - miningPipe.unbakedBaseModel = loadModel(event, GTUtility.gregtechId("block/mining_pipe/" + miningPipe.type)); - miningPipe.unbakedBottomModel = loadModel(event, GTUtility.gregtechId("block/mining_pipe/" + miningPipe.type + "_bottom")); + miningPipe.unbakedBaseModel = loadModel(event, + GTUtility.gregtechId("block/mining_pipe/" + miningPipe.type)); + miningPipe.unbakedBottomModel = loadModel(event, + GTUtility.gregtechId("block/mining_pipe/" + miningPipe.type + "_bottom")); } } diff --git a/src/main/java/gregtech/client/renderer/handler/MiningPipeRenderer.java b/src/main/java/gregtech/client/renderer/handler/MiningPipeRenderer.java index a9ee8b4727d..343760198a0 100644 --- a/src/main/java/gregtech/client/renderer/handler/MiningPipeRenderer.java +++ b/src/main/java/gregtech/client/renderer/handler/MiningPipeRenderer.java @@ -1,30 +1,31 @@ package gregtech.client.renderer.handler; -import gregtech.common.entities.MiningPipeEntity; import gregtech.client.utils.MinerRenderHelper; +import gregtech.common.entities.MiningPipeEntity; + import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.entity.Render; import net.minecraft.client.renderer.entity.RenderManager; import net.minecraft.util.ResourceLocation; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; public class MiningPipeRenderer extends Render> { - @SuppressWarnings({"unchecked", "rawtypes"}) + @SuppressWarnings({ "unchecked", "rawtypes" }) public static Render iHateJavaGenerics(RenderManager manager) { return (Render) (Render) new MiningPipeRenderer(manager); } public MiningPipeRenderer(RenderManager manager) { super(manager); - this.shadowSize = 0; } @Override - public void doRender(@Nonnull MiningPipeEntity entity, double x, double y, double z, float entityYaw, float partialTicks) { + public void doRender(@NotNull MiningPipeEntity entity, double x, double y, double z, float entityYaw, + float partialTicks) { boolean renderOutlines = this.renderOutlines; if (renderOutlines) { GlStateManager.enableColorMaterial(); @@ -41,7 +42,7 @@ public void doRender(@Nonnull MiningPipeEntity entity, double x, double y, do @Nullable @Override - protected ResourceLocation getEntityTexture(@Nonnull MiningPipeEntity entity) { + protected ResourceLocation getEntityTexture(@NotNull MiningPipeEntity entity) { return null; } } diff --git a/src/main/java/gregtech/client/utils/MinerRenderHelper.java b/src/main/java/gregtech/client/utils/MinerRenderHelper.java index ce64c8a52f7..25b7f2e98d9 100644 --- a/src/main/java/gregtech/client/utils/MinerRenderHelper.java +++ b/src/main/java/gregtech/client/utils/MinerRenderHelper.java @@ -5,6 +5,7 @@ import gregtech.client.model.miningpipe.MiningPipeModel; import gregtech.common.entities.MiningPipeEntity; import gregtech.common.metatileentities.miner.Miner; + import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.BufferBuilder; import net.minecraft.client.renderer.GlStateManager; @@ -18,16 +19,18 @@ import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos.MutableBlockPos; + +import org.jetbrains.annotations.NotNull; import org.lwjgl.opengl.GL11; -import javax.annotation.Nonnull; import javax.vecmath.Vector3f; public class MinerRenderHelper { private MinerRenderHelper() {} - public static final ResourceLocation MINER_AREA_PREVIEW_TEXTURE = GTUtility.gregtechId("textures/fx/miner_area_preview.png"); + public static final ResourceLocation MINER_AREA_PREVIEW_TEXTURE = GTUtility.gregtechId( + "textures/fx/miner_area_preview.png"); private static final long TEXTURE_WRAP_INTERVAL_NANOSECONDS = 3_000_000_000L; @@ -54,7 +57,7 @@ private static void updateFrustum() { } public static void renderPipe(double x, double y, double z, float partialTicks, - @Nonnull MiningPipeEntity entity) { + @NotNull MiningPipeEntity entity) { if (entity.getMTE() == null || entity.length <= 0) return; updateFrustum(); @@ -101,7 +104,7 @@ public static void renderPipe(double x, dou * @param y Y position; generally {@code cameraY + blockY} * @param z Z position; generally {@code cameraZ + blockZ} */ - public static void renderAreaPreview(@Nonnull AxisAlignedBB box, @Nonnull BlockPos pos, + public static void renderAreaPreview(@NotNull AxisAlignedBB box, @NotNull BlockPos pos, double x, double y, double z) { // skull emoji @@ -113,7 +116,8 @@ public static void renderAreaPreview(@Nonnull AxisAlignedBB box, @Nonnull BlockP boolean isBoxClippingThroughCamera = isBoxClippingThroughCamera(minX, maxX, minY, maxY, minZ, maxZ); // texture UVs - double texOffset = (System.nanoTime() % TEXTURE_WRAP_INTERVAL_NANOSECONDS) / (double) (TEXTURE_WRAP_INTERVAL_NANOSECONDS); + double texOffset = + (System.nanoTime() % TEXTURE_WRAP_INTERVAL_NANOSECONDS) / (double) (TEXTURE_WRAP_INTERVAL_NANOSECONDS); double dx = (box.maxX - box.minX); double dy = (box.maxY - Math.max(0, box.minY)); @@ -134,7 +138,8 @@ public static void renderAreaPreview(@Nonnull AxisAlignedBB box, @Nonnull BlockP Minecraft.getMinecraft().getTextureManager().bindTexture(MINER_AREA_PREVIEW_TEXTURE); GlStateManager.disableLighting(); GlStateManager.enableBlend(); - GlStateManager.tryBlendFuncSeparate(SourceFactor.SRC_ALPHA, DestFactor.ONE_MINUS_SRC_ALPHA, SourceFactor.ONE, DestFactor.ZERO); + GlStateManager.tryBlendFuncSeparate(SourceFactor.SRC_ALPHA, DestFactor.ONE_MINUS_SRC_ALPHA, SourceFactor.ONE, + DestFactor.ZERO); Tessellator tessellator = Tessellator.getInstance(); BufferBuilder buffer = tessellator.getBuffer(); diff --git a/src/main/java/gregtech/common/entities/MiningPipeEntity.java b/src/main/java/gregtech/common/entities/MiningPipeEntity.java index 09be325c889..125405311fc 100644 --- a/src/main/java/gregtech/common/entities/MiningPipeEntity.java +++ b/src/main/java/gregtech/common/entities/MiningPipeEntity.java @@ -2,6 +2,7 @@ import gregtech.api.metatileentity.MetaTileEntity; import gregtech.common.metatileentities.miner.Miner; + import net.minecraft.block.material.EnumPushReaction; import net.minecraft.entity.Entity; import net.minecraft.nbt.NBTTagCompound; @@ -10,8 +11,8 @@ import net.minecraft.world.World; import net.minecraftforge.common.util.ITeleporter; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; /** * Section of the mining pipe. The pipe should be divided into multiple segments due to a naive algorithm used in AABB @@ -29,7 +30,7 @@ public class MiningPipeEntity extends Entity private int prevLength = -1; - protected MiningPipeEntity(@Nonnull World world, @Nullable MTE mte, @Nonnull BlockPos origin) { + protected MiningPipeEntity(@NotNull World world, @Nullable MTE mte, @NotNull BlockPos origin) { super(world); this.setSize(.5f, 0); this.setNoGravity(true); @@ -42,11 +43,11 @@ protected MiningPipeEntity(@Nonnull World world, @Nullable MTE mte, @Nonnull Blo } @SuppressWarnings("unused") - public MiningPipeEntity(@Nonnull World world) { + public MiningPipeEntity(@NotNull World world) { this(world, null, BlockPos.ORIGIN); } - public MiningPipeEntity(@Nonnull MTE mte, @Nonnull BlockPos origin) { + public MiningPipeEntity(@NotNull MTE mte, @NotNull BlockPos origin) { this(mte.getWorld(), mte, origin.toImmutable()); this.setPosition(this.origin.getX() + .5, this.origin.getY(), this.origin.getZ() + .5); } @@ -56,7 +57,7 @@ public MTE getMTE() { return mte; } - @Nonnull + @NotNull public BlockPos getOrigin() { return origin; } @@ -96,7 +97,7 @@ public boolean canBeAttackedWithItem() { return false; } - @Nonnull + @NotNull @Override public EnumPushReaction getPushReaction() { return EnumPushReaction.IGNORE; @@ -104,7 +105,7 @@ public EnumPushReaction getPushReaction() { @Nullable @Override - public AxisAlignedBB getCollisionBox(@Nonnull Entity entity) { + public AxisAlignedBB getCollisionBox(@NotNull Entity entity) { return entity.canBePushed() ? entity.getEntityBoundingBox() : null; } @@ -115,13 +116,13 @@ public AxisAlignedBB getCollisionBoundingBox() { } @Override - public Entity changeDimension(int dim, @Nonnull ITeleporter teleporter) { + public Entity changeDimension(int dim, @NotNull ITeleporter teleporter) { return this; } @Override - protected void readEntityFromNBT(@Nonnull NBTTagCompound tag) {} + protected void readEntityFromNBT(@NotNull NBTTagCompound tag) {} @Override - protected void writeEntityToNBT(@Nonnull NBTTagCompound tag) {} + protected void writeEntityToNBT(@NotNull NBTTagCompound tag) {} } diff --git a/src/main/java/gregtech/common/metatileentities/miner/LargeMinerType.java b/src/main/java/gregtech/common/metatileentities/miner/LargeMinerType.java index 3323be47469..833a30b792d 100644 --- a/src/main/java/gregtech/common/metatileentities/miner/LargeMinerType.java +++ b/src/main/java/gregtech/common/metatileentities/miner/LargeMinerType.java @@ -4,29 +4,30 @@ import gregtech.api.pattern.TraceabilityPredicate; import gregtech.client.model.miningpipe.MiningPipeModel; import gregtech.client.renderer.ICubeRenderer; + import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; public interface LargeMinerType { - @Nonnull + @NotNull TraceabilityPredicate getCasing(); - @Nonnull + @NotNull TraceabilityPredicate getFrame(); @SideOnly(Side.CLIENT) - @Nonnull + @NotNull ICubeRenderer getFrontOverlay(); @SideOnly(Side.CLIENT) - @Nonnull + @NotNull ICubeRenderer getBaseTexture(@Nullable IMultiblockPart sourcePart); @SideOnly(Side.CLIENT) - @Nonnull + @NotNull MiningPipeModel getMiningPipeModel(); } diff --git a/src/main/java/gregtech/common/metatileentities/miner/LargeMinerTypes.java b/src/main/java/gregtech/common/metatileentities/miner/LargeMinerTypes.java index 726d85533fd..af92a7bccc8 100644 --- a/src/main/java/gregtech/common/metatileentities/miner/LargeMinerTypes.java +++ b/src/main/java/gregtech/common/metatileentities/miner/LargeMinerTypes.java @@ -10,18 +10,19 @@ import gregtech.client.renderer.texture.Textures; import gregtech.common.blocks.BlockMetalCasing; import gregtech.common.blocks.MetaBlocks; + import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; public enum LargeMinerTypes implements LargeMinerType { STEEL, TITANIUM, TUNGSTEN_STEEL; - @Nonnull + @NotNull public TraceabilityPredicate getCasing() { return MultiblockControllerBase.states(switch (this) { case STEEL -> MetaBlocks.METAL_CASING.getState(BlockMetalCasing.MetalCasingType.STEEL_SOLID); @@ -31,7 +32,7 @@ public TraceabilityPredicate getCasing() { }); } - @Nonnull + @NotNull public TraceabilityPredicate getFrame() { return MultiblockControllerBase.frames(switch (this) { case STEEL -> Materials.Steel; @@ -40,7 +41,7 @@ public TraceabilityPredicate getFrame() { }); } - @Nonnull + @NotNull @Override @SideOnly(Side.CLIENT) public ICubeRenderer getBaseTexture(@Nullable IMultiblockPart sourcePart) { @@ -51,7 +52,7 @@ public ICubeRenderer getBaseTexture(@Nullable IMultiblockPart sourcePart) { }; } - @Nonnull + @NotNull @Override public MiningPipeModel getMiningPipeModel() { return switch (this) { @@ -61,7 +62,7 @@ public MiningPipeModel getMiningPipeModel() { }; } - @Nonnull + @NotNull @Override @SideOnly(Side.CLIENT) public ICubeRenderer getFrontOverlay() { diff --git a/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityLargeMiner.java b/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityLargeMiner.java index c75deebdaf6..74df058a71e 100644 --- a/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityLargeMiner.java +++ b/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityLargeMiner.java @@ -1,9 +1,5 @@ package gregtech.common.metatileentities.miner; -import codechicken.lib.render.CCRenderState; -import codechicken.lib.render.pipeline.IVertexOperation; -import codechicken.lib.vec.Matrix4; -import com.google.common.collect.Lists; import gregtech.api.GTValues; import gregtech.api.capability.GregtechTileCapabilities; import gregtech.api.capability.IControllable; @@ -25,7 +21,11 @@ import gregtech.api.metatileentity.IFastRenderMetaTileEntity; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.metatileentity.interfaces.IGregTechTileEntity; -import gregtech.api.metatileentity.multiblock.*; +import gregtech.api.metatileentity.multiblock.IMultiblockPart; +import gregtech.api.metatileentity.multiblock.IProgressBarMultiblock; +import gregtech.api.metatileentity.multiblock.MultiblockAbility; +import gregtech.api.metatileentity.multiblock.MultiblockDisplayText; +import gregtech.api.metatileentity.multiblock.MultiblockWithDisplayBase; import gregtech.api.pattern.BlockPattern; import gregtech.api.pattern.FactoryBlockPattern; import gregtech.api.pattern.PatternMatchContext; @@ -38,6 +38,7 @@ import gregtech.client.renderer.ICubeRenderer; import gregtech.client.renderer.texture.Textures; import gregtech.core.sound.GTSoundEvents; + import net.minecraft.block.state.IBlockState; import net.minecraft.client.resources.I18n; import net.minecraft.entity.player.EntityPlayer; @@ -51,7 +52,11 @@ import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos.MutableBlockPos; -import net.minecraft.util.text.*; +import net.minecraft.util.text.ITextComponent; +import net.minecraft.util.text.Style; +import net.minecraft.util.text.TextComponentString; +import net.minecraft.util.text.TextComponentTranslation; +import net.minecraft.util.text.TextFormatting; import net.minecraft.util.text.event.ClickEvent; import net.minecraft.util.text.event.HoverEvent; import net.minecraft.world.World; @@ -62,8 +67,13 @@ import net.minecraftforge.fml.relauncher.SideOnly; import net.minecraftforge.items.IItemHandlerModifiable; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; +import codechicken.lib.render.CCRenderState; +import codechicken.lib.render.pipeline.IVertexOperation; +import codechicken.lib.vec.Matrix4; +import com.google.common.collect.Lists; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + import java.util.Collections; import java.util.List; import java.util.Objects; @@ -71,9 +81,10 @@ import static gregtech.api.unification.material.Materials.DrillingFluid; -public class MetaTileEntityLargeMiner extends MultiblockWithDisplayBase implements Miner, IControllable, IDataInfoProvider, IFastRenderMetaTileEntity, IProgressBarMultiblock { +public class MetaTileEntityLargeMiner extends MultiblockWithDisplayBase + implements Miner, IControllable, IDataInfoProvider, IFastRenderMetaTileEntity, IProgressBarMultiblock { - @Nonnull + @NotNull public final LargeMinerType type; public final int tier; public final int drillingFluidConsumePerTick; @@ -93,7 +104,7 @@ public class MetaTileEntityLargeMiner extends MultiblockWithDisplayBase implemen private boolean inventoryFull; public MetaTileEntityLargeMiner(ResourceLocation metaTileEntityId, int tier, int speed, int maxChunkDiameter, - int drillingFluidConsumePerTick, @Nonnull LargeMinerType type) { + int drillingFluidConsumePerTick, @NotNull LargeMinerType type) { super(metaTileEntityId); this.type = Objects.requireNonNull(type, "type == null"); this.tier = tier; @@ -126,11 +137,13 @@ protected void formStructure(PatternMatchContext context) { public int getEnergyTier() { if (energyContainer == null) return this.tier; - return Math.min(this.tier + 1, Math.max(this.tier, GTUtility.getFloorTierByVoltage(energyContainer.getInputVoltage()))); + return Math.min(this.tier + 1, + Math.max(this.tier, GTUtility.getFloorTierByVoltage(energyContainer.getInputVoltage()))); } @Override - public boolean drainMiningResources(@Nonnull MinedBlockType minedBlockType, boolean pipeExtended, boolean simulate) { + public boolean drainMiningResources(@NotNull MinedBlockType minedBlockType, boolean pipeExtended, + boolean simulate) { if (minedBlockType == MinedBlockType.NOTHING) return true; if (!drainEnergy(true) || !drainFluid(true)) return false; if (!simulate) { @@ -160,7 +173,7 @@ protected boolean drainFluid(boolean simulate) { } @Override - public boolean collectBlockDrops(@Nonnull World world, @Nonnull BlockPos pos, @Nonnull IBlockState state) { + public boolean collectBlockDrops(@NotNull World world, @NotNull BlockPos pos, @NotNull IBlockState state) { NonNullList drops = NonNullList.create(); IItemHandlerModifiable inventory = this.outputInventory; @@ -177,7 +190,7 @@ public boolean collectBlockDrops(@Nonnull World world, @Nonnull BlockPos pos, @N } @Override - public void onMineOperation(@Nonnull BlockPos pos, boolean isOre, boolean isOrigin) { + public void onMineOperation(@NotNull BlockPos pos, boolean isOre, boolean isOrigin) { if (isOre) { this.lastMinedOre.setPos(pos); this.hasLastMinedOre = true; @@ -185,7 +198,7 @@ public void onMineOperation(@Nonnull BlockPos pos, boolean isOre, boolean isOrig } } - @Nonnull + @NotNull @Override @SideOnly(Side.CLIENT) public MiningPipeModel getMiningPipeModel() { @@ -196,7 +209,8 @@ public MiningPipeModel getMiningPipeModel() { @SideOnly(Side.CLIENT) public void renderMetaTileEntity(CCRenderState renderState, Matrix4 translation, IVertexOperation[] pipeline) { super.renderMetaTileEntity(renderState, translation, pipeline); - this.getFrontOverlay().renderOrientedState(renderState, translation, pipeline, getFrontFacing(), isActive(), isWorkingEnabled()); + this.getFrontOverlay().renderOrientedState(renderState, translation, pipeline, getFrontFacing(), isActive(), + isWorkingEnabled()); if (isStructureFormed()) { EnumFacing f = getFrontFacing().getOpposite(); Textures.PIPE_IN_OVERLAY.renderSided(EnumFacing.DOWN, renderState, @@ -246,7 +260,7 @@ public void update() { } } - @Nonnull + @NotNull @Override protected BlockPattern createStructurePattern() { return FactoryBlockPattern.start() @@ -257,7 +271,8 @@ protected BlockPattern createStructurePattern() { .where('X', this.type.getCasing() .or(abilities(MultiblockAbility.EXPORT_ITEMS).setMaxGlobalLimited(1).setPreviewCount(1)) .or(abilities(MultiblockAbility.IMPORT_FLUIDS).setExactLimit(1).setPreviewCount(1)) - .or(abilities(MultiblockAbility.INPUT_ENERGY).setMinGlobalLimited(1).setMaxGlobalLimited(3).setPreviewCount(1))) + .or(abilities(MultiblockAbility.INPUT_ENERGY).setMinGlobalLimited(1).setMaxGlobalLimited(3) + .setPreviewCount(1))) .where('C', this.type.getCasing()) .where('F', this.type.getFrame()) .where('#', any()) @@ -266,17 +281,21 @@ protected BlockPattern createStructurePattern() { @Override public String[] getDescription() { - return new String[]{I18n.format("gregtech.machine.miner.multi.description")}; + return new String[] { I18n.format("gregtech.machine.miner.multi.description") }; } @Override - public void addInformation(ItemStack stack, @Nullable World player, @Nonnull List tooltip, boolean advanced) { + public void addInformation(ItemStack stack, @Nullable World player, @NotNull List tooltip, + boolean advanced) { int workingAreaChunks = this.minerLogic.getMaximumChunkDiameter(); tooltip.add(I18n.format("gregtech.machine.miner.multi.modes")); tooltip.add(I18n.format("gregtech.machine.miner.multi.production")); - tooltip.add(I18n.format("gregtech.machine.miner.fluid_usage", this.drillingFluidConsumePerTick, DrillingFluid.getLocalizedName())); - tooltip.add(I18n.format("gregtech.universal.tooltip.working_area_chunks_max", workingAreaChunks, workingAreaChunks)); - tooltip.add(I18n.format("gregtech.universal.tooltip.energy_tier_range", GTValues.VNF[this.tier], GTValues.VNF[this.tier + 1])); + tooltip.add(I18n.format("gregtech.machine.miner.fluid_usage", this.drillingFluidConsumePerTick, + DrillingFluid.getLocalizedName())); + tooltip.add(I18n.format("gregtech.universal.tooltip.working_area_chunks_max", workingAreaChunks, + workingAreaChunks)); + tooltip.add(I18n.format("gregtech.universal.tooltip.energy_tier_range", GTValues.VNF[this.tier], + GTValues.VNF[this.tier + 1])); } @Override @@ -304,7 +323,7 @@ protected ModularUI.Builder createUITemplate(EntityPlayer entityPlayer) { return b; } - @Nonnull + @NotNull @Override protected Widget getFlexButton(int x, int y, int width, int height) { AtomicBoolean stateHolder = this.uiConfigModeStateHolder; @@ -331,7 +350,8 @@ protected void addRealDisplayText(List textList, boolean configM int energyContainer = getEnergyTier(); long maxVoltage = GTValues.V[energyContainer]; String voltageName = GTValues.VNF[energyContainer]; - textList.add(new TextComponentTranslation("gregtech.multiblock.max_energy_per_tick", maxVoltage, voltageName)); + textList.add(new TextComponentTranslation("gregtech.multiblock.max_energy_per_tick", maxVoltage, + voltageName)); } } @@ -361,10 +381,12 @@ protected void addRealDisplayText(List textList, boolean configM ITextComponent hoverText; if (yLimit > 0) { value = new TextComponentString(String.format("%,d", yLimit)); - hoverText = new TextComponentTranslation("gregtech.machine.miner.display.y_limit.value_hover_tooltip", value.createCopy()); + hoverText = new TextComponentTranslation("gregtech.machine.miner.display.y_limit.value_hover_tooltip", + value.createCopy()); } else { value = new TextComponentTranslation("gregtech.machine.miner.display.y_limit.no_value"); - hoverText = new TextComponentTranslation("gregtech.machine.miner.display.y_limit.value_hover_tooltip.no_value"); + hoverText = new TextComponentTranslation( + "gregtech.machine.miner.display.y_limit.value_hover_tooltip.no_value"); } textList.add(new TextComponentTranslation( "gregtech.machine.miner.display.y_limit", new TextComponentString("") @@ -391,7 +413,8 @@ protected void addRealDisplayText(List textList, boolean configM replaceOreText = new TextComponentString("[") .appendSibling(replaceOreText.setStyle(new Style().setColor(TextFormatting.AQUA))) .appendText("]").setStyle(button(this.minerLogic.isReplaceOreWithAir() ? - MinerUtil.DISPLAY_CLICK_REPLACE_ORE_DISABLE : MinerUtil.DISPLAY_CLICK_REPLACE_ORE_ENABLE)); + MinerUtil.DISPLAY_CLICK_REPLACE_ORE_DISABLE : + MinerUtil.DISPLAY_CLICK_REPLACE_ORE_ENABLE)); } textList.add(new TextComponentTranslation("gregtech.machine.miner.display.replace_ore", replaceOreText)); @@ -428,40 +451,43 @@ protected void appendWorkingStatus(List textList) { "gregtech.machine.miner.display.done")); } - @Nonnull + @NotNull protected static ITextComponent previewAreaButton(boolean previewEnabled) { return new TextComponentTranslation(previewEnabled ? "gregtech.machine.miner.display.working_area.hide_preview" : "gregtech.machine.miner.display.working_area.preview") - .setStyle(button(previewEnabled ? MinerUtil.DISPLAY_CLICK_AREA_PREVIEW_HIDE : MinerUtil.DISPLAY_CLICK_AREA_PREVIEW)); + .setStyle(button(previewEnabled ? MinerUtil.DISPLAY_CLICK_AREA_PREVIEW_HIDE : + MinerUtil.DISPLAY_CLICK_AREA_PREVIEW)); } - @Nonnull - protected static ITextComponent incrButton(int currentValue, int maxValue, @Nonnull String event) { + @NotNull + protected static ITextComponent incrButton(int currentValue, int maxValue, @NotNull String event) { return currentValue >= maxValue ? new TextComponentTranslation("gregtech.machine.miner.display.incr.disabled") : new TextComponentTranslation("gregtech.machine.miner.display.incr").setStyle(button(event)); } - @Nonnull - protected static ITextComponent decrButton(int currentValue, int minValue, @Nonnull String event) { + @NotNull + protected static ITextComponent decrButton(int currentValue, int minValue, @NotNull String event) { return currentValue <= minValue ? new TextComponentTranslation("gregtech.machine.miner.display.decr.disabled") : new TextComponentTranslation("gregtech.machine.miner.display.decr").setStyle(button(event)); } - @Nonnull - protected static ITextComponent toggleButton(boolean currentValue, boolean canInteract, @Nonnull String onEvent, @Nonnull String offEvent) { + @NotNull + protected static ITextComponent toggleButton(boolean currentValue, boolean canInteract, @NotNull String onEvent, + @NotNull String offEvent) { return canInteract ? new TextComponentTranslation(currentValue ? "gregtech.machine.miner.display.enabled" : "gregtech.machine.miner.display.disabled") : new TextComponentTranslation(currentValue ? - "gregtech.machine.miner.display.toggle.enabled" : "gregtech.machine.miner.display.toggle.disabled") + "gregtech.machine.miner.display.toggle.enabled" : + "gregtech.machine.miner.display.toggle.disabled") .setStyle(button(currentValue ? offEvent : onEvent)); } - @Nonnull - protected static Style button(@Nonnull String event) { + @NotNull + protected static Style button(@NotNull String event) { return new Style().setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "@!" + event)); } @@ -580,14 +606,13 @@ public void receiveCustomData(int dataId, PacketBuffer buf) { this.minerLogic.receiveCustomData(dataId, buf); } - @Override @SideOnly(Side.CLIENT) public ICubeRenderer getBaseTexture(@Nullable IMultiblockPart sourcePart) { return this.type.getBaseTexture(sourcePart); } - @Nonnull + @NotNull @Override @SideOnly(Side.CLIENT) protected ICubeRenderer getFrontOverlay() { @@ -627,11 +652,12 @@ public boolean isActive() { return isStructureFormed() && minerLogic.isActive(); } - @Nonnull + @NotNull @Override public List getDataInfo() { int diameter = this.minerLogic.getCurrentDiameter(); - return Collections.singletonList(new TextComponentTranslation("gregtech.machine.miner.working_area", diameter, diameter)); + return Collections.singletonList( + new TextComponentTranslation("gregtech.machine.miner.working_area", diameter, diameter)); } @Override diff --git a/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityMiner.java b/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityMiner.java index eb9bbdea58f..4743f7761d7 100644 --- a/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityMiner.java +++ b/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityMiner.java @@ -1,16 +1,17 @@ package gregtech.common.metatileentities.miner; -import codechicken.lib.render.CCRenderState; -import codechicken.lib.render.pipeline.IVertexOperation; -import codechicken.lib.vec.Matrix4; -import com.google.common.math.IntMath; import gregtech.api.GTValues; import gregtech.api.capability.GregtechTileCapabilities; import gregtech.api.capability.IControllable; import gregtech.api.capability.impl.EnergyContainerHandler; import gregtech.api.gui.GuiTextures; import gregtech.api.gui.ModularUI; -import gregtech.api.gui.widgets.*; +import gregtech.api.gui.widgets.AdvancedTextWidget; +import gregtech.api.gui.widgets.ClickButtonWidget; +import gregtech.api.gui.widgets.ImageWidget; +import gregtech.api.gui.widgets.ProgressWidget; +import gregtech.api.gui.widgets.SlotWidget; +import gregtech.api.gui.widgets.ToggleButtonWidget; import gregtech.api.items.itemhandlers.GTItemStackHandler; import gregtech.api.metatileentity.IDataInfoProvider; import gregtech.api.metatileentity.IFastRenderMetaTileEntity; @@ -24,6 +25,7 @@ import gregtech.client.model.miningpipe.MiningPipeModels; import gregtech.client.renderer.texture.Textures; import gregtech.core.sound.GTSoundEvents; + import net.minecraft.block.state.IBlockState; import net.minecraft.client.resources.I18n; import net.minecraft.entity.player.EntityPlayer; @@ -47,13 +49,19 @@ import net.minecraftforge.items.IItemHandlerModifiable; import net.minecraftforge.items.ItemStackHandler; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; +import codechicken.lib.render.CCRenderState; +import codechicken.lib.render.pipeline.IVertexOperation; +import codechicken.lib.vec.Matrix4; +import com.google.common.math.IntMath; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + import java.math.RoundingMode; import java.util.Collections; import java.util.List; -public class MetaTileEntityMiner extends TieredMetaTileEntity implements Miner, IControllable, IDataInfoProvider, IFastRenderMetaTileEntity { +public class MetaTileEntityMiner extends TieredMetaTileEntity + implements Miner, IControllable, IDataInfoProvider, IFastRenderMetaTileEntity { private final ItemStackHandler chargerInventory; @@ -62,7 +70,8 @@ public class MetaTileEntityMiner extends TieredMetaTileEntity implements Miner, private final MinerLogic minerLogic; - public MetaTileEntityMiner(@Nonnull ResourceLocation metaTileEntityId, int tier, int workFrequency, int maximumDiameter) { + public MetaTileEntityMiner(@NotNull ResourceLocation metaTileEntityId, int tier, int workFrequency, + int maximumDiameter) { super(metaTileEntityId, tier); this.inventorySize = (tier + 1) * (tier + 1); this.energyPerTick = GTValues.V[tier - 1]; @@ -73,7 +82,8 @@ public MetaTileEntityMiner(@Nonnull ResourceLocation metaTileEntityId, int tier, @Override public MetaTileEntity createMetaTileEntity(IGregTechTileEntity tileEntity) { - return new MetaTileEntityMiner(metaTileEntityId, getTier(), this.minerLogic.getWorkFrequency(), this.minerLogic.getMaximumDiameter()); + return new MetaTileEntityMiner(metaTileEntityId, getTier(), this.minerLogic.getWorkFrequency(), + this.minerLogic.getMaximumDiameter()); } @Override @@ -85,7 +95,8 @@ protected IItemHandlerModifiable createExportItemHandler() { @SideOnly(Side.CLIENT) public void renderMetaTileEntity(CCRenderState renderState, Matrix4 translation, IVertexOperation[] pipeline) { super.renderMetaTileEntity(renderState, translation, pipeline); - Textures.MINER_OVERLAY.renderOrientedState(renderState, translation, pipeline, getFrontFacing(), minerLogic.isActive(), minerLogic.isWorkingEnabled()); + Textures.MINER_OVERLAY.renderOrientedState(renderState, translation, pipeline, getFrontFacing(), + minerLogic.isActive(), minerLogic.isWorkingEnabled()); } @Override @@ -118,7 +129,7 @@ public boolean isGlobalRenderer() { } @Override - protected ModularUI createUI(@Nonnull EntityPlayer entityPlayer) { + protected ModularUI createUI(@NotNull EntityPlayer entityPlayer) { IItemHandlerModifiable exportItems = this.getExportItems(); int slots = exportItems.getSlots(); int columns = IntMath.sqrt(slots, RoundingMode.UP); @@ -133,15 +144,18 @@ protected ModularUI createUI(@Nonnull EntityPlayer entityPlayer) { GuiTextures.BUTTON_MINER_AREA_PREVIEW, this.minerLogic::isPreviewEnabled, this.minerLogic::setPreviewEnabled)) .widget(new ClickButtonWidget(161, yStart + 18 + 2, 9, 9, - "", cd -> this.minerLogic.setCurrentDiameter(this.minerLogic.getCurrentDiameter() + (cd.isShiftClick ? 5 : 1))) + "", cd -> this.minerLogic.setCurrentDiameter( + this.minerLogic.getCurrentDiameter() + (cd.isShiftClick ? 5 : 1))) .setButtonTexture(GuiTextures.BUTTON_INT_CIRCUIT_PLUS)) .widget(new ClickButtonWidget(161, yStart + 18 + 2 + 9, 9, 9, - "", cd -> this.minerLogic.setCurrentDiameter(this.minerLogic.getCurrentDiameter() - (cd.isShiftClick ? 5 : 1))) + "", cd -> this.minerLogic.setCurrentDiameter( + this.minerLogic.getCurrentDiameter() - (cd.isShiftClick ? 5 : 1))) .setButtonTexture(GuiTextures.BUTTON_INT_CIRCUIT_MINUS)) .widget(new AdvancedTextWidget(159, yStart + 18 + 2 + (18 - 11) / 2, list -> { int currentDiameter = this.minerLogic.getCurrentDiameter(); list.add(new TextComponentString(currentDiameter + "x" + currentDiameter)); }, 0x404040) { + @Override protected void onSizeUpdate() { // >:( Size size = this.getSize(); @@ -150,7 +164,8 @@ protected void onSizeUpdate() { // >:( }) .widget(new SlotWidget(this.chargerInventory, 0, 79, 62 + yOffset, true, true, false) .setBackgroundTexture(GuiTextures.SLOT, GuiTextures.CHARGER_OVERLAY) - .setTooltipText("gregtech.gui.charger_slot.tooltip", GTValues.VNF[getTier()], GTValues.VNF[getTier()])); + .setTooltipText("gregtech.gui.charger_slot.tooltip", GTValues.VNF[getTier()], + GTValues.VNF[getTier()])); for (int i = 0; i < slots; i++) { builder.slot(exportItems, i, xStart + 18 * (i % columns), yStart + 18 * (i / columns), @@ -175,12 +190,16 @@ protected void onSizeUpdate() { // >:( } @Override - public void addInformation(ItemStack stack, @Nullable World player, @Nonnull List tooltip, boolean advanced) { + public void addInformation(ItemStack stack, @Nullable World player, @NotNull List tooltip, + boolean advanced) { tooltip.add(I18n.format("gregtech.machine.miner.tooltip")); tooltip.add(I18n.format("gregtech.universal.tooltip.uses_per_tick", energyPerTick) - + TextFormatting.GRAY + ", " + I18n.format("gregtech.machine.miner.per_block", this.minerLogic.getWorkFrequency() / 20)); - tooltip.add(I18n.format("gregtech.universal.tooltip.voltage_in", energyContainer.getInputVoltage(), GTValues.VNF[getTier()])); - tooltip.add(I18n.format("gregtech.universal.tooltip.energy_storage_capacity", energyContainer.getEnergyCapacity())); + + TextFormatting.GRAY + ", " + + I18n.format("gregtech.machine.miner.per_block", this.minerLogic.getWorkFrequency() / 20)); + tooltip.add(I18n.format("gregtech.universal.tooltip.voltage_in", energyContainer.getInputVoltage(), + GTValues.VNF[getTier()])); + tooltip.add( + I18n.format("gregtech.universal.tooltip.energy_storage_capacity", energyContainer.getEnergyCapacity())); int maxArea = minerLogic.getMaximumDiameter(); tooltip.add(I18n.format("gregtech.universal.tooltip.working_area_max", maxArea, maxArea)); } @@ -194,7 +213,8 @@ public void addToolUsages(ItemStack stack, @Nullable World world, List t } @Override - public boolean drainMiningResources(@Nonnull MinedBlockType minedBlockType, boolean pipeExtended, boolean simulate) { + public boolean drainMiningResources(@NotNull MinedBlockType minedBlockType, boolean pipeExtended, + boolean simulate) { if (minedBlockType == MinedBlockType.NOTHING) return true; long resultEnergy = energyContainer.getEnergyStored() - energyPerTick; if (resultEnergy < 0 || resultEnergy > energyContainer.getEnergyCapacity()) return false; @@ -205,7 +225,7 @@ public boolean drainMiningResources(@Nonnull MinedBlockType minedBlockType, bool } @Override - public boolean collectBlockDrops(@Nonnull World world, @Nonnull BlockPos pos, @Nonnull IBlockState state) { + public boolean collectBlockDrops(@NotNull World world, @NotNull BlockPos pos, @NotNull IBlockState state) { NonNullList drops = NonNullList.create(); IItemHandlerModifiable inventory = getExportItems(); state.getBlock().getDrops(drops, world, pos, state, 0); @@ -217,7 +237,7 @@ public boolean collectBlockDrops(@Nonnull World world, @Nonnull BlockPos pos, @N } } - @Nonnull + @NotNull @Override @SideOnly(Side.CLIENT) public MiningPipeModel getMiningPipeModel() { @@ -230,7 +250,6 @@ public void update() { this.minerLogic.update(); if (!getWorld().isRemote) { ((EnergyContainerHandler) this.energyContainer).dischargeOrRechargeEnergyContainers(chargerInventory, 0); - if (getOffsetTimer() % 5 == 0) pushItemsIntoNearbyHandlers(getFrontFacing()); } @@ -251,19 +270,19 @@ public void readFromNBT(NBTTagCompound data) { } @Override - public void writeInitialSyncData(@Nonnull PacketBuffer buf) { + public void writeInitialSyncData(@NotNull PacketBuffer buf) { super.writeInitialSyncData(buf); this.minerLogic.writeInitialSyncData(buf); } @Override - public void receiveInitialSyncData(@Nonnull PacketBuffer buf) { + public void receiveInitialSyncData(@NotNull PacketBuffer buf) { super.receiveInitialSyncData(buf); this.minerLogic.receiveInitialSyncData(buf); } @Override - public void receiveCustomData(int dataId, @Nonnull PacketBuffer buf) { + public void receiveCustomData(int dataId, @NotNull PacketBuffer buf) { super.receiveCustomData(dataId, buf); this.minerLogic.receiveCustomData(dataId, buf); } @@ -302,10 +321,11 @@ public boolean isActive() { return minerLogic.isActive(); } - @Nonnull + @NotNull @Override public List getDataInfo() { int diameter = minerLogic.getCurrentDiameter(); - return Collections.singletonList(new TextComponentTranslation("gregtech.machine.miner.working_area", diameter, diameter)); + return Collections.singletonList( + new TextComponentTranslation("gregtech.machine.miner.working_area", diameter, diameter)); } } diff --git a/src/main/java/gregtech/common/metatileentities/miner/Miner.java b/src/main/java/gregtech/common/metatileentities/miner/Miner.java index 0004595d4df..62f5c8e1ac4 100644 --- a/src/main/java/gregtech/common/metatileentities/miner/Miner.java +++ b/src/main/java/gregtech/common/metatileentities/miner/Miner.java @@ -1,13 +1,14 @@ package gregtech.common.metatileentities.miner; import gregtech.client.model.miningpipe.MiningPipeModel; + import net.minecraft.block.state.IBlockState; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; -import javax.annotation.Nonnull; +import org.jetbrains.annotations.NotNull; public interface Miner { @@ -19,7 +20,7 @@ public interface Miner { * @param simulate If {@code true}, this action will not affect the state of the game * @return Whether the action was successful */ - boolean drainMiningResources(@Nonnull MinedBlockType minedBlockType, boolean pipeExtended, boolean simulate); + boolean drainMiningResources(@NotNull MinedBlockType minedBlockType, boolean pipeExtended, boolean simulate); /** * Try to collect drops from the block. {@code true} is returned if the block drop is successfully collected; @@ -31,9 +32,9 @@ public interface Miner { * @param state the {@link IBlockState} of the block being mined * @return Whether the action was successful */ - boolean collectBlockDrops(@Nonnull World world, @Nonnull BlockPos pos, @Nonnull IBlockState state); + boolean collectBlockDrops(@NotNull World world, @NotNull BlockPos pos, @NotNull IBlockState state); - @Nonnull + @NotNull @SideOnly(Side.CLIENT) MiningPipeModel getMiningPipeModel(); @@ -48,7 +49,7 @@ default boolean canOperate() { * @param isOre whether it was ore block * @param isOrigin whether it was origin (the block mining pipe goes in) */ - default void onMineOperation(@Nonnull BlockPos pos, boolean isOre, boolean isOrigin) {} + default void onMineOperation(@NotNull BlockPos pos, boolean isOre, boolean isOrigin) {} /** * Type of the block mined. diff --git a/src/main/java/gregtech/common/metatileentities/miner/MinerLogic.java b/src/main/java/gregtech/common/metatileentities/miner/MinerLogic.java index ef55f1f06db..f9dc0c720bc 100644 --- a/src/main/java/gregtech/common/metatileentities/miner/MinerLogic.java +++ b/src/main/java/gregtech/common/metatileentities/miner/MinerLogic.java @@ -5,6 +5,7 @@ import gregtech.api.util.BlockUtility; import gregtech.common.entities.MiningPipeEntity; import gregtech.common.metatileentities.miner.Miner.MinedBlockType; + import net.minecraft.block.material.Material; import net.minecraft.block.state.IBlockState; import net.minecraft.init.Blocks; @@ -16,8 +17,9 @@ import net.minecraft.world.World; import net.minecraftforge.common.util.Constants; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + import java.util.ArrayList; import java.util.List; import java.util.Objects; @@ -73,7 +75,7 @@ public class MinerLogic { * @throws IllegalArgumentException if {@code workFrequency <= 0} * @throws NullPointerException if {@code mte == null} */ - public MinerLogic(@Nonnull MTE mte, int workFrequency, int maximumDiameter) { + public MinerLogic(@NotNull MTE mte, int workFrequency, int maximumDiameter) { if (workFrequency <= 0) throw new IllegalArgumentException("workFrequency <= 0"); this.mte = Objects.requireNonNull(mte, "mte == null"); this.workDelay = this.workFrequency = workFrequency; @@ -173,7 +175,7 @@ public boolean isDone() { * @return origin position of the miner. Block boundary will be centered around this position, and mining pipes will * be rendered under this position. */ - @Nonnull + @NotNull protected BlockPos getOrigin() { return mte.getPos(); } @@ -188,7 +190,7 @@ public final MiningArea getMiningArea() { * * @return new {@link MiningArea} instance */ - @Nonnull + @NotNull protected MiningArea createMiningArea() { BlockPos origin = getOrigin(); int radius = this.currentDiameter / 2; @@ -284,7 +286,7 @@ protected void updateLogic() { } } - protected void mine(@Nonnull MiningArea miningArea) { + protected void mine(@NotNull MiningArea miningArea) { if (this.done || --this.workDelay > 0) return; this.workDelay = this.workFrequency; if (!this.workingEnabled || !this.mte.canOperate()) return; @@ -344,7 +346,7 @@ protected void mine(@Nonnull MiningArea miningArea) { this.workDelay = 1; // re-scan next tick } - @Nonnull + @NotNull protected IBlockState getOreReplacement() { return MinerUtil.getOreReplacement(); } @@ -356,7 +358,7 @@ private void setPipeLength(int length) { this.mte.writeCustomData(GregtechDataCodes.PUMP_HEAD_LEVEL, b -> b.writeVarInt(length)); } - protected void writePreviewUpdatePacket(@Nonnull PacketBuffer buffer) { + protected void writePreviewUpdatePacket(@NotNull PacketBuffer buffer) { if (this.preview) { MiningArea miningArea = this.miningArea; if (miningArea != null) { @@ -368,20 +370,20 @@ protected void writePreviewUpdatePacket(@Nonnull PacketBuffer buffer) { buffer.writeBoolean(false); } - protected void readPreviewUpdatePacket(@Nonnull PacketBuffer buffer) { + protected void readPreviewUpdatePacket(@NotNull PacketBuffer buffer) { this.previewArea = buffer.readBoolean() ? readPreviewArea(buffer) : null; } - @Nonnull - protected MiningArea readPreviewArea(@Nonnull PacketBuffer buffer) { + @NotNull + protected MiningArea readPreviewArea(@NotNull PacketBuffer buffer) { return SimpleMiningArea.readPreview(buffer); } /** * Write states to NBT. Call this method in {@link MetaTileEntity#writeToNBT(NBTTagCompound)}. */ - @Nonnull - public NBTTagCompound writeToNBT(@Nonnull NBTTagCompound data) { + @NotNull + public NBTTagCompound writeToNBT(@NotNull NBTTagCompound data) { data.setInteger("currentDiameter", this.currentDiameter); if (!this.workingEnabled) data.setBoolean("disabled", true); if (this.done) data.setBoolean("done", true); @@ -398,7 +400,7 @@ public NBTTagCompound writeToNBT(@Nonnull NBTTagCompound data) { /** * Read states from NBT. Call this method in {@link MetaTileEntity#readFromNBT(NBTTagCompound)}. */ - public void readFromNBT(@Nonnull NBTTagCompound data) { + public void readFromNBT(@NotNull NBTTagCompound data) { this.rebuildMiningArea = false; if (data.hasKey("xPos", Constants.NBT.TAG_INT)) { @@ -427,7 +429,7 @@ public void readFromNBT(@Nonnull NBTTagCompound data) { /** * Write states to packet buffer. Call this method in {@link MetaTileEntity#writeInitialSyncData(PacketBuffer)}. */ - public void writeInitialSyncData(@Nonnull PacketBuffer buf) { + public void writeInitialSyncData(@NotNull PacketBuffer buf) { buf.writeVarInt(this.pipeLength); buf.writeBoolean(this.workingEnabled); buf.writeBoolean(this.done); @@ -438,7 +440,7 @@ public void writeInitialSyncData(@Nonnull PacketBuffer buf) { /** * Read states from packet buffer. Call this method in {@link MetaTileEntity#receiveInitialSyncData(PacketBuffer)}. */ - public void receiveInitialSyncData(@Nonnull PacketBuffer buf) { + public void receiveInitialSyncData(@NotNull PacketBuffer buf) { this.pipeLength = buf.readVarInt(); this.workingEnabled = buf.readBoolean(); this.done = buf.readBoolean(); @@ -447,9 +449,10 @@ public void receiveInitialSyncData(@Nonnull PacketBuffer buf) { } /** - * Callback for handling custom data packet sent by miner logic. Call this method in {@link MetaTileEntity#receiveCustomData(int, PacketBuffer)}. + * Callback for handling custom data packet sent by miner logic. Call this method in + * {@link MetaTileEntity#receiveCustomData(int, PacketBuffer)}. */ - public void receiveCustomData(int dataId, @Nonnull PacketBuffer buf) { + public void receiveCustomData(int dataId, @NotNull PacketBuffer buf) { if (dataId == GregtechDataCodes.PUMP_HEAD_LEVEL) { this.pipeLength = buf.readVarInt(); } else if (dataId == GregtechDataCodes.WORKING_ENABLED) { diff --git a/src/main/java/gregtech/common/metatileentities/miner/MinerUtil.java b/src/main/java/gregtech/common/metatileentities/miner/MinerUtil.java index 986ca402925..692ed542e6e 100644 --- a/src/main/java/gregtech/common/metatileentities/miner/MinerUtil.java +++ b/src/main/java/gregtech/common/metatileentities/miner/MinerUtil.java @@ -8,14 +8,16 @@ import gregtech.api.util.GTLog; import gregtech.api.util.GTUtility; import gregtech.common.ConfigHolder; + import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; import net.minecraft.util.math.AxisAlignedBB; + import org.apache.commons.lang3.StringUtils; +import org.jetbrains.annotations.NotNull; -import javax.annotation.Nonnull; import java.util.Collections; import java.util.List; import java.util.Objects; @@ -49,7 +51,7 @@ private MinerUtil() {} private static String oreReplacementConfigCache; private static IBlockState oreReplacement; - @Nonnull + @NotNull @SuppressWarnings("deprecation") public static IBlockState getOreReplacement() { String config = ConfigHolder.machines.replaceMinedBlocksWith; @@ -64,15 +66,20 @@ public static IBlockState getOreReplacement() { Block block = Block.getBlockFromName(blockName); if (block == null) { - GTLog.logger.error("Invalid configuration on entry 'machines/replaceMinedBlocksWith': Cannot find block with name '{}', using cobblestone as fallback.", blockName); + GTLog.logger.error( + "Invalid configuration on entry 'machines/replaceMinedBlocksWith': Cannot find block with name '{}', using cobblestone as fallback.", + blockName); return oreReplacement = Blocks.COBBLESTONE.getDefaultState(); } else if (blockDescription.length <= 2 || blockDescription[2].isEmpty()) { return oreReplacement = block.getDefaultState(); } else { try { - return oreReplacement = block.getDefaultState().getBlock().getStateFromMeta(Integer.parseInt(blockDescription[2])); + return oreReplacement = block.getDefaultState().getBlock() + .getStateFromMeta(Integer.parseInt(blockDescription[2])); } catch (NumberFormatException ex) { - GTLog.logger.error("Invalid configuration on entry 'machines/replaceMinedBlocksWith': Cannot parse metadata value '{}' as integer, using cobblestone as fallback.", blockDescription[2]); + GTLog.logger.error( + "Invalid configuration on entry 'machines/replaceMinedBlocksWith': Cannot parse metadata value '{}' as integer, using cobblestone as fallback.", + blockDescription[2]); return oreReplacement = Blocks.COBBLESTONE.getDefaultState(); } } @@ -85,8 +92,8 @@ public static IBlockState getOreReplacement() { * @param drops where the drops are stored to * @return amount of items inserted to {@code drops} */ - public static int applyTieredHammerDrops(@Nonnull ItemStack stack, @Nonnull List drops, - int energyTier, @Nonnull RecipeMap blockDropRecipeMap, + public static int applyTieredHammerDrops(@NotNull ItemStack stack, @NotNull List drops, + int energyTier, @NotNull RecipeMap blockDropRecipeMap, int oreMultiplier) { Recipe recipe = blockDropRecipeMap.findRecipe( GTValues.V[energyTier], @@ -94,7 +101,8 @@ public static int applyTieredHammerDrops(@Nonnull ItemStack stack, @Nonnull List Collections.emptyList()); if (recipe == null || recipe.getOutputs().isEmpty()) return 0; int c = 0; - for (ItemStack output : recipe.getResultItemOutputs(GTUtility.getTierByVoltage(recipe.getEUt()), energyTier, blockDropRecipeMap)) { + for (ItemStack output : recipe.getResultItemOutputs(GTUtility.getTierByVoltage(recipe.getEUt()), energyTier, + blockDropRecipeMap)) { output = output.copy(); if (oreMultiplier > 0 && OreDictUnifier.getPrefix(output) == OrePrefix.crushed) { output.grow(output.getCount() * oreMultiplier); diff --git a/src/main/java/gregtech/common/metatileentities/miner/MiningArea.java b/src/main/java/gregtech/common/metatileentities/miner/MiningArea.java index f99920d81b4..4e77878db03 100644 --- a/src/main/java/gregtech/common/metatileentities/miner/MiningArea.java +++ b/src/main/java/gregtech/common/metatileentities/miner/MiningArea.java @@ -1,9 +1,8 @@ package gregtech.common.metatileentities.miner; -import codechicken.lib.render.CCRenderState; -import codechicken.lib.vec.Matrix4; import gregtech.api.metatileentity.IFastRenderMetaTileEntity; import gregtech.api.metatileentity.MetaTileEntity; + import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.PacketBuffer; import net.minecraft.util.math.AxisAlignedBB; @@ -11,7 +10,9 @@ import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; -import javax.annotation.Nonnull; +import codechicken.lib.render.CCRenderState; +import codechicken.lib.vec.Matrix4; +import org.jetbrains.annotations.NotNull; /** * Object representing operation area of {@link MinerLogic}. @@ -21,13 +22,12 @@ public interface MiningArea { /** * Get current block position for processing. If this method returns {@code true}, {@code mpos} argument should be * modified to the block position. Return value of {@code false} indicates there aren't any block left to process. - *
- * Calling this method does not affect the state. Use {@link #nextBlock()} for advancing to next block. + *
Calling this method does not affect the state. Use {@link #nextBlock()} for advancing to next block. * * @param mpos Mutable block position * @return {@code true} if {@code mpos} is set to current block position for processing, {@code false} otherwise */ - boolean getCurrentBlockPos(@Nonnull MutableBlockPos mpos); + boolean getCurrentBlockPos(@NotNull MutableBlockPos mpos); /** * Move on to next block for processing, if it exists. Does nothing if there aren't any block left to process. @@ -42,12 +42,13 @@ public interface MiningArea { void reset(); @SideOnly(Side.CLIENT) - default void renderMetaTileEntityFast(@Nonnull MetaTileEntity mte, @Nonnull CCRenderState renderState, @Nonnull Matrix4 translation, float partialTicks) {} + default void renderMetaTileEntityFast(@NotNull MetaTileEntity mte, @NotNull CCRenderState renderState, + @NotNull Matrix4 translation, float partialTicks) {} @SideOnly(Side.CLIENT) - default void renderMetaTileEntity(@Nonnull MetaTileEntity mte, double x, double y, double z, float partialTicks) {} + default void renderMetaTileEntity(@NotNull MetaTileEntity mte, double x, double y, double z, float partialTicks) {} - @Nonnull + @NotNull AxisAlignedBB getRenderBoundingBox(); default boolean shouldRenderInPass(int pass) { @@ -59,19 +60,19 @@ default boolean shouldRenderInPass(int pass) { * * @param data NBT data */ - void write(@Nonnull NBTTagCompound data); + void write(@NotNull NBTTagCompound data); /** * Read any persistent data here. * * @param data NBT data */ - void read(@Nonnull NBTTagCompound data); + void read(@NotNull NBTTagCompound data); /** * Write data for area preview. * * @param buffer Packet buffer */ - void writePreviewPacket(@Nonnull PacketBuffer buffer); + void writePreviewPacket(@NotNull PacketBuffer buffer); } diff --git a/src/main/java/gregtech/common/metatileentities/miner/MultiblockMinerLogic.java b/src/main/java/gregtech/common/metatileentities/miner/MultiblockMinerLogic.java index bb1d0317c11..2f1da4444ab 100644 --- a/src/main/java/gregtech/common/metatileentities/miner/MultiblockMinerLogic.java +++ b/src/main/java/gregtech/common/metatileentities/miner/MultiblockMinerLogic.java @@ -8,7 +8,7 @@ import net.minecraft.util.math.MathHelper; import net.minecraftforge.common.util.Constants; -import javax.annotation.Nonnull; +import org.jetbrains.annotations.NotNull; public class MultiblockMinerLogic extends MinerLogic { @@ -30,13 +30,14 @@ public class MultiblockMinerLogic extends MinerLogic { // flag for disabling ore replacement (if true, ores will be replaced with air instead of whatever block that was specified in the config) private boolean replaceOreWithAir; - public MultiblockMinerLogic(@Nonnull MetaTileEntityLargeMiner largeMiner, int workFrequency, int maximumChunkDiameter) { + public MultiblockMinerLogic(@NotNull MetaTileEntityLargeMiner largeMiner, int workFrequency, + int maximumChunkDiameter) { super(largeMiner, workFrequency, maximumChunkDiameter * 16); this.currentChunkDiameter = this.maximumChunkDiameter = maximumChunkDiameter; } @Override - protected void mine(@Nonnull MiningArea miningArea) { + protected void mine(@NotNull MiningArea miningArea) { if (this.done && this.repeat) { miningArea.reset(); this.done = false; @@ -48,13 +49,13 @@ protected void mine(@Nonnull MiningArea miningArea) { } } - @Nonnull + @NotNull @Override protected IBlockState getOreReplacement() { return this.replaceOreWithAir ? Blocks.AIR.getDefaultState() : super.getOreReplacement(); } - @Nonnull + @NotNull @Override protected MiningArea createMiningArea() { BlockPos origin = getOrigin(); @@ -80,7 +81,7 @@ protected MiningArea createMiningArea() { } } - @Nonnull + @NotNull @Override protected BlockPos getOrigin() { return this.mpos.setPos(this.mte.getPos()).move(this.mte.getFrontFacing().getOpposite()); @@ -165,9 +166,9 @@ public void setReplaceOreWithAir(boolean replaceOreWithAir) { this.mte.markDirty(); } - @Nonnull + @NotNull @Override - public NBTTagCompound writeToNBT(@Nonnull NBTTagCompound data) { + public NBTTagCompound writeToNBT(@NotNull NBTTagCompound data) { if (this.chunkMode) data.setBoolean("chunkMode", true); if (this.silkTouchMode) data.setBoolean("silkTouch", true); data.setInteger("currentChunkDiameter", currentChunkDiameter); @@ -178,7 +179,7 @@ public NBTTagCompound writeToNBT(@Nonnull NBTTagCompound data) { } @Override - public void readFromNBT(@Nonnull NBTTagCompound data) { + public void readFromNBT(@NotNull NBTTagCompound data) { this.chunkMode = data.getBoolean("chunkMode") || data.getBoolean("isChunkMode"); this.silkTouchMode = data.getBoolean("silkTouch") || data.getBoolean("isSilkTouchMode"); this.currentChunkDiameter = data.hasKey("currentChunkDiameter", Constants.NBT.TAG_INT) ? diff --git a/src/main/java/gregtech/common/metatileentities/miner/SimpleMiningArea.java b/src/main/java/gregtech/common/metatileentities/miner/SimpleMiningArea.java index 03e1d79a5ab..06c5a330085 100644 --- a/src/main/java/gregtech/common/metatileentities/miner/SimpleMiningArea.java +++ b/src/main/java/gregtech/common/metatileentities/miner/SimpleMiningArea.java @@ -2,6 +2,7 @@ import gregtech.api.metatileentity.MetaTileEntity; import gregtech.client.utils.MinerRenderHelper; + import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.PacketBuffer; import net.minecraft.util.math.AxisAlignedBB; @@ -10,8 +11,8 @@ import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import static gregtech.api.metatileentity.IFastRenderMetaTileEntity.RENDER_PASS_TRANSLUCENT; @@ -32,8 +33,7 @@ public class SimpleMiningArea implements MiningArea { /** * Index for current block position. This implementation of {@link MiningArea} operates by first mapping each block * in given area to non-negative long indices, then processing it by incrementing internal counter starting from 0. - *
- * The area iterates through X plane first, then Z plane, before moving down one Y block. + *
The area iterates through X plane first, then Z plane, before moving down one Y block. */ private long currentBlock; @@ -57,13 +57,14 @@ public SimpleMiningArea(int startX, int startY, int startZ, int endX, int endY, this.endZ = endZ; } - @Nonnull - public static SimpleMiningArea readPreview(@Nonnull PacketBuffer buffer) { - return new SimpleMiningArea(buffer.readInt(), buffer.readInt(), buffer.readInt(), buffer.readInt(), buffer.readInt(), buffer.readInt()); + @NotNull + public static SimpleMiningArea readPreview(@NotNull PacketBuffer buffer) { + return new SimpleMiningArea(buffer.readInt(), buffer.readInt(), buffer.readInt(), buffer.readInt(), + buffer.readInt(), buffer.readInt()); } @Override - public boolean getCurrentBlockPos(@Nonnull MutableBlockPos mpos) { + public boolean getCurrentBlockPos(@NotNull MutableBlockPos mpos) { long index = this.currentBlock; if (index < 0) return false; int sizeX = this.endX - this.startX; @@ -93,35 +94,37 @@ public void reset() { @Override @SideOnly(Side.CLIENT) - public void renderMetaTileEntity(@Nonnull MetaTileEntity mte, double x, double y, double z, float partialTicks) { + public void renderMetaTileEntity(@NotNull MetaTileEntity mte, double x, double y, double z, float partialTicks) { if (MinecraftForgeClient.getRenderPass() == RENDER_PASS_TRANSLUCENT) { MinerRenderHelper.renderAreaPreview(this.getRenderBoundingBox(), mte.getPos(), x, y, z); } } - @Nonnull + @NotNull @Override public AxisAlignedBB getRenderBoundingBox() { if (this.boundingBoxCache == null) { return this.boundingBoxCache = new AxisAlignedBB( - startX + PREVIEW_OFFSET, endY == Integer.MIN_VALUE ? Double.NEGATIVE_INFINITY : endY + PREVIEW_OFFSET, startZ + PREVIEW_OFFSET, + startX + PREVIEW_OFFSET, + endY == Integer.MIN_VALUE ? Double.NEGATIVE_INFINITY : endY + PREVIEW_OFFSET, + startZ + PREVIEW_OFFSET, endX - PREVIEW_OFFSET, startY + 1 - PREVIEW_OFFSET, endZ - PREVIEW_OFFSET); } return this.boundingBoxCache; } @Override - public void write(@Nonnull NBTTagCompound data) { + public void write(@NotNull NBTTagCompound data) { data.setLong("i", this.currentBlock); } @Override - public void read(@Nonnull NBTTagCompound data) { + public void read(@NotNull NBTTagCompound data) { this.currentBlock = Math.max(0, data.getLong("i")); } @Override - public void writePreviewPacket(@Nonnull PacketBuffer buffer) { + public void writePreviewPacket(@NotNull PacketBuffer buffer) { buffer.writeInt(startX); buffer.writeInt(startY); buffer.writeInt(startZ); From d5293b56772955518a23b926e563c4466dfe3fe1 Mon Sep 17 00:00:00 2001 From: Tictim Date: Thu, 7 Dec 2023 12:39:42 +0900 Subject: [PATCH 24/27] amo --- src/main/java/gregtech/api/util/BlockUtility.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/main/java/gregtech/api/util/BlockUtility.java b/src/main/java/gregtech/api/util/BlockUtility.java index 792dac555ec..e82051ba286 100644 --- a/src/main/java/gregtech/api/util/BlockUtility.java +++ b/src/main/java/gregtech/api/util/BlockUtility.java @@ -3,13 +3,26 @@ import gregtech.api.unification.OreDictUnifier; import gregtech.api.unification.ore.OrePrefix; +import it.unimi.dsi.fastutil.objects.Object2BooleanMap; +import it.unimi.dsi.fastutil.objects.Object2BooleanOpenHashMap; + +import it.unimi.dsi.fastutil.objects.Object2DoubleMap; + +import it.unimi.dsi.fastutil.objects.Object2DoubleMaps; +import it.unimi.dsi.fastutil.objects.Object2DoubleOpenHashMap; + import net.minecraft.block.Block; import net.minecraft.block.material.Material; +import net.minecraft.block.state.IBlockState; +import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.NonNullList; import org.jetbrains.annotations.NotNull; +import java.util.Objects; +import java.util.UUID; + public class BlockUtility { private static final BlockWrapper WRAPPER = new BlockWrapper(); From 6de4916fb1dffb466767c882669fe237e73a3081 Mon Sep 17 00:00:00 2001 From: Tictim Date: Thu, 7 Dec 2023 13:44:15 +0900 Subject: [PATCH 25/27] fix button --- .../metatileentities/miner/MetaTileEntityLargeMiner.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityLargeMiner.java b/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityLargeMiner.java index 74df058a71e..3e2da94816c 100644 --- a/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityLargeMiner.java +++ b/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityLargeMiner.java @@ -400,11 +400,11 @@ protected void addRealDisplayText(List textList, boolean configM MinerUtil.DISPLAY_CLICK_REPEAT_ENABLE, MinerUtil.DISPLAY_CLICK_REPEAT_DISABLE))); textList.add(new TextComponentTranslation("gregtech.machine.miner.display.chunk_mode", - toggleButton(this.minerLogic.isRepeat(), this.minerLogic.isWorking(), + toggleButton(this.minerLogic.isChunkMode(), this.minerLogic.isWorking(), MinerUtil.DISPLAY_CLICK_CHUNK_MODE_ENABLE, MinerUtil.DISPLAY_CLICK_CHUNK_MODE_DISABLE))); textList.add(new TextComponentTranslation("gregtech.machine.miner.display.silk_touch", - toggleButton(this.minerLogic.isRepeat(), this.minerLogic.isWorking(), + toggleButton(this.minerLogic.isSilkTouchMode(), this.minerLogic.isWorking(), MinerUtil.DISPLAY_CLICK_SILK_TOUCH_ENABLE, MinerUtil.DISPLAY_CLICK_SILK_TOUCH_DISABLE))); ITextComponent replaceOreText = new TextComponentTranslation( From b5047f3c91ca7a7de2b3ae5ab5f743b32d7f51dd Mon Sep 17 00:00:00 2001 From: Tictim Date: Thu, 21 Dec 2023 15:52:31 +0900 Subject: [PATCH 26/27] holy shit so many spots --- .../api/capability/impl/RecipeLogicSteam.java | 3 +- .../java/gregtech/api/gui/GuiTextures.java | 6 +- .../unification/stack/ItemAndMetadata.java | 3 +- .../java/gregtech/api/util/BlockUtility.java | 13 +-- .../java/gregtech/api/util/GTUtility.java | 5 +- .../java/gregtech/client/ClientProxy.java | 3 +- .../client/renderer/texture/Textures.java | 92 ++++++++++++------- .../client/utils/MinerRenderHelper.java | 22 +---- .../java/gregtech/common/MetaEntities.java | 3 +- .../metatileentities/MetaTileEntities.java | 7 +- .../miner/LargeMinerTypes.java | 5 +- .../miner/MetaTileEntityLargeMiner.java | 28 +++--- .../miner/MetaTileEntityMiner.java | 38 ++++---- .../metatileentities/miner/MinerLogic.java | 4 +- .../metatileentities/miner/MiningArea.java | 5 +- .../miner/MultiblockMinerLogic.java | 3 +- .../miner/SimpleMiningArea.java | 3 +- .../widget/WidgetProspectingMap.java | 2 +- .../loaders/recipe/MetaTileEntityLoader.java | 82 ++++++++++++++--- 19 files changed, 201 insertions(+), 126 deletions(-) diff --git a/src/main/java/gregtech/api/capability/impl/RecipeLogicSteam.java b/src/main/java/gregtech/api/capability/impl/RecipeLogicSteam.java index e78ff493826..b0b981ee856 100644 --- a/src/main/java/gregtech/api/capability/impl/RecipeLogicSteam.java +++ b/src/main/java/gregtech/api/capability/impl/RecipeLogicSteam.java @@ -8,6 +8,7 @@ import gregtech.api.recipes.RecipeMap; import gregtech.api.util.GTUtility; import gregtech.common.ConfigHolder; + import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.PacketBuffer; import net.minecraft.util.EnumFacing; @@ -114,7 +115,7 @@ public void receiveInitialSyncData(@NotNull PacketBuffer buf) { public void tryDoVenting() { if (GTUtility.tryVenting(metaTileEntity.getWorld(), metaTileEntity.getPos(), getVentingSide(), this.isHighPressure ? 12 : 6, true, - ConfigHolder.machines.machineSounds && !this.metaTileEntity.isMuffled()) ) { + ConfigHolder.machines.machineSounds && !this.metaTileEntity.isMuffled())) { setNeedsVenting(false); } else { setVentingStuck(true); diff --git a/src/main/java/gregtech/api/gui/GuiTextures.java b/src/main/java/gregtech/api/gui/GuiTextures.java index decdeeb7c05..a24a26cb099 100644 --- a/src/main/java/gregtech/api/gui/GuiTextures.java +++ b/src/main/java/gregtech/api/gui/GuiTextures.java @@ -116,7 +116,8 @@ public class GuiTextures { public static final TextureArea BUTTON_NO_FLEX = TextureArea.fullImage("textures/gui/widget/button_no_flex.png"); public static final TextureArea BUTTON_MULTI_MAP = TextureArea .fullImage("textures/gui/widget/button_multi_map.png"); - public static final TextureArea BUTTON_MINER_AREA_PREVIEW = TextureArea.fullImage("textures/gui/widget/button_miner_area_preview.png"); + public static final TextureArea BUTTON_MINER_AREA_PREVIEW = TextureArea + .fullImage("textures/gui/widget/button_miner_area_preview.png"); public static final TextureArea BUTTON_MINER_CONFIG_MODE = TextureArea .fullImage("textures/gui/widget/button_miner_config_mode.png"); public static final TextureArea BUTTON_THROTTLE_MINUS = TextureArea @@ -409,7 +410,8 @@ public class GuiTextures { .fullImage("textures/gui/progress_bar/progress_bar_turbine_rotor_durability.png"); public static final TextureArea PROGRESS_BAR_FLUID_RIG_DEPLETION = TextureArea .fullImage("textures/gui/progress_bar/progress_bar_fluid_rig_depletion.png"); - public static final TextureArea PROGRESS_BAR_MINER_DRILLING_FLUID = TextureArea.fullImage("textures/gui/progress_bar/progress_bar_miner_drilling_fluid.png"); + public static final TextureArea PROGRESS_BAR_MINER_DRILLING_FLUID = TextureArea + .fullImage("textures/gui/progress_bar/progress_bar_miner_drilling_fluid.png"); // Fusion reactor diagram progress bar parts public static final TextureArea PROGRESS_BAR_FUSION_REACTOR_DIAGRAM_BL = TextureArea diff --git a/src/main/java/gregtech/api/unification/stack/ItemAndMetadata.java b/src/main/java/gregtech/api/unification/stack/ItemAndMetadata.java index 1c9ebfcf887..f826854d41b 100644 --- a/src/main/java/gregtech/api/unification/stack/ItemAndMetadata.java +++ b/src/main/java/gregtech/api/unification/stack/ItemAndMetadata.java @@ -44,7 +44,8 @@ public ItemAndMetadata toWildcard() { @Override public boolean equals(Object o) { - return this == o || o instanceof ItemAndMetadata that && itemDamage == that.itemDamage && item.equals(that.item); + return this == o || + o instanceof ItemAndMetadata that && itemDamage == that.itemDamage && item.equals(that.item); } @Override diff --git a/src/main/java/gregtech/api/util/BlockUtility.java b/src/main/java/gregtech/api/util/BlockUtility.java index e82051ba286..1dcc43cc531 100644 --- a/src/main/java/gregtech/api/util/BlockUtility.java +++ b/src/main/java/gregtech/api/util/BlockUtility.java @@ -3,14 +3,6 @@ import gregtech.api.unification.OreDictUnifier; import gregtech.api.unification.ore.OrePrefix; -import it.unimi.dsi.fastutil.objects.Object2BooleanMap; -import it.unimi.dsi.fastutil.objects.Object2BooleanOpenHashMap; - -import it.unimi.dsi.fastutil.objects.Object2DoubleMap; - -import it.unimi.dsi.fastutil.objects.Object2DoubleMaps; -import it.unimi.dsi.fastutil.objects.Object2DoubleOpenHashMap; - import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.block.state.IBlockState; @@ -18,6 +10,11 @@ import net.minecraft.item.ItemStack; import net.minecraft.util.NonNullList; +import it.unimi.dsi.fastutil.objects.Object2BooleanMap; +import it.unimi.dsi.fastutil.objects.Object2BooleanOpenHashMap; +import it.unimi.dsi.fastutil.objects.Object2DoubleMap; +import it.unimi.dsi.fastutil.objects.Object2DoubleMaps; +import it.unimi.dsi.fastutil.objects.Object2DoubleOpenHashMap; import org.jetbrains.annotations.NotNull; import java.util.Objects; diff --git a/src/main/java/gregtech/api/util/GTUtility.java b/src/main/java/gregtech/api/util/GTUtility.java index b7da571251d..917604be7f7 100644 --- a/src/main/java/gregtech/api/util/GTUtility.java +++ b/src/main/java/gregtech/api/util/GTUtility.java @@ -20,7 +20,7 @@ import gregtech.api.unification.OreDictUnifier; import gregtech.api.unification.ore.OrePrefix; import gregtech.core.advancement.AdvancementTriggers; -import it.unimi.dsi.fastutil.objects.ObjectOpenCustomHashSet; + import net.minecraft.block.Block; import net.minecraft.block.BlockRedstoneWire; import net.minecraft.block.BlockSnow; @@ -811,7 +811,8 @@ public static boolean tryVenting(@NotNull World world, @NotNull BlockPos machine ventingSide.getZOffset() / 2.0, 0.1); } if (playSound) { - world.playSound(null, posX, posY, posZ, SoundEvents.BLOCK_LAVA_EXTINGUISH, SoundCategory.BLOCKS, 1.0f, 1.0f); + world.playSound(null, posX, posY, posZ, SoundEvents.BLOCK_LAVA_EXTINGUISH, SoundCategory.BLOCKS, 1.0f, + 1.0f); } return true; } diff --git a/src/main/java/gregtech/client/ClientProxy.java b/src/main/java/gregtech/client/ClientProxy.java index a62dd43d399..0e08caf1a3b 100644 --- a/src/main/java/gregtech/client/ClientProxy.java +++ b/src/main/java/gregtech/client/ClientProxy.java @@ -13,6 +13,7 @@ import gregtech.api.util.ModCompatibility; import gregtech.client.model.customtexture.CustomTextureModelHandler; import gregtech.client.model.customtexture.MetadataSectionCTM; +import gregtech.client.model.miningpipe.MiningPipeModels; import gregtech.client.renderer.handler.FacadeRenderer; import gregtech.client.renderer.handler.MetaTileEntityRenderer; import gregtech.client.renderer.pipe.*; @@ -25,7 +26,7 @@ import gregtech.common.blocks.MetaBlocks; import gregtech.common.items.MetaItems; import gregtech.common.items.ToolItems; -import gregtech.client.model.miningpipe.MiningPipeModels; + import net.minecraft.block.Block; import net.minecraft.client.Minecraft; import net.minecraft.client.resources.I18n; diff --git a/src/main/java/gregtech/client/renderer/texture/Textures.java b/src/main/java/gregtech/client/renderer/texture/Textures.java index a44606ddf6f..d8fb67f238d 100644 --- a/src/main/java/gregtech/client/renderer/texture/Textures.java +++ b/src/main/java/gregtech/client/renderer/texture/Textures.java @@ -252,11 +252,16 @@ public class Textures { "machines/mass_fabricator"); public static final OrientedOverlayRenderer REPLICATOR_OVERLAY = new OrientedOverlayRenderer("machines/replicator"); public static final OrientedOverlayRenderer SCANNER_OVERLAY = new OrientedOverlayRenderer("machines/scanner"); - public static final OrientedOverlayRenderer COMBUSTION_GENERATOR_OVERLAY = new OrientedOverlayRenderer("generators/combustion"); - public static final OrientedOverlayRenderer GAS_TURBINE_OVERLAY = new OrientedOverlayRenderer("generators/gas_turbine"); - public static final OrientedOverlayRenderer STEAM_TURBINE_OVERLAY = new OrientedOverlayRenderer("generators/steam_turbine"); - public static final OrientedOverlayRenderer WORLD_ACCELERATOR_OVERLAY = new OrientedOverlayRenderer("machines/world_accelerator"); - public static final OrientedOverlayRenderer WORLD_ACCELERATOR_TE_OVERLAY = new OrientedOverlayRenderer("machines/world_accelerator_te"); + public static final OrientedOverlayRenderer COMBUSTION_GENERATOR_OVERLAY = new OrientedOverlayRenderer( + "generators/combustion"); + public static final OrientedOverlayRenderer GAS_TURBINE_OVERLAY = new OrientedOverlayRenderer( + "generators/gas_turbine"); + public static final OrientedOverlayRenderer STEAM_TURBINE_OVERLAY = new OrientedOverlayRenderer( + "generators/steam_turbine"); + public static final OrientedOverlayRenderer WORLD_ACCELERATOR_OVERLAY = new OrientedOverlayRenderer( + "machines/world_accelerator"); + public static final OrientedOverlayRenderer WORLD_ACCELERATOR_TE_OVERLAY = new OrientedOverlayRenderer( + "machines/world_accelerator_te"); public static final OrientedOverlayRenderer MINER_OVERLAY = new OrientedOverlayRenderer("machines/miner"); // Simple Overlay Renderers @@ -414,31 +419,56 @@ public class Textures { "overlay/machine/overlay_maintenance_cleaning"); public static final SimpleOverlayRenderer MUFFLER_OVERLAY = new SimpleOverlayRenderer( "overlay/machine/overlay_muffler"); - public static final SimpleOverlayRenderer BLANK_SCREEN = new SimpleOverlayRenderer("overlay/machine/overlay_blank_screen"); - public static final SimpleOverlayRenderer DATA_ACCESS_HATCH = new SimpleOverlayRenderer("overlay/machine/overlay_data_hatch"); - public static final SimpleOverlayRenderer CREATIVE_DATA_ACCESS_HATCH = new SimpleOverlayRenderer("overlay/machine/overlay_data_hatch_creative"); - public static final SimpleOverlayRenderer OPTICAL_DATA_ACCESS_HATCH = new SimpleOverlayRenderer("overlay/machine/overlay_data_hatch_optical"); - public static final SimpleOverlayRenderer LASER_SOURCE = new SimpleOverlayRenderer("overlay/machine/overlay_laser_source"); - public static final SimpleOverlayRenderer LASER_TARGET = new SimpleOverlayRenderer("overlay/machine/overlay_laser_target"); - public static final SimpleOverlayRenderer OBJECT_HOLDER_OVERLAY = new SimpleOverlayRenderer("overlay/machine/overlay_object_holder"); - public static final SimpleOverlayRenderer OBJECT_HOLDER_ACTIVE_OVERLAY = new SimpleOverlayRenderer("overlay/machine/overlay_object_holder_active"); - public static final SimpleOverlayRenderer HPCA_ACTIVE_COOLER_OVERLAY = new SimpleOverlayRenderer("overlay/machine/hpca/active_cooler"); - public static final SimpleOverlayRenderer HPCA_ACTIVE_COOLER_ACTIVE_OVERLAY = new SimpleOverlayRenderer("overlay/machine/hpca/active_cooler_active"); - public static final SimpleOverlayRenderer HPCA_BRIDGE_OVERLAY = new SimpleOverlayRenderer("overlay/machine/hpca/bridge"); - public static final SimpleOverlayRenderer HPCA_BRIDGE_ACTIVE_OVERLAY = new SimpleOverlayRenderer("overlay/machine/hpca/bridge_active"); - public static final SimpleOverlayRenderer HPCA_COMPUTATION_OVERLAY = new SimpleOverlayRenderer("overlay/machine/hpca/computation"); - public static final SimpleOverlayRenderer HPCA_COMPUTATION_ACTIVE_OVERLAY = new SimpleOverlayRenderer("overlay/machine/hpca/computation_active"); - public static final SimpleOverlayRenderer HPCA_ADVANCED_COMPUTATION_OVERLAY = new SimpleOverlayRenderer("overlay/machine/hpca/computation_advanced"); - public static final SimpleOverlayRenderer HPCA_ADVANCED_COMPUTATION_ACTIVE_OVERLAY = new SimpleOverlayRenderer("overlay/machine/hpca/computation_advanced_active"); - public static final SimpleOverlayRenderer HPCA_DAMAGED_OVERLAY = new SimpleOverlayRenderer("overlay/machine/hpca/damaged"); - public static final SimpleOverlayRenderer HPCA_DAMAGED_ACTIVE_OVERLAY = new SimpleOverlayRenderer("overlay/machine/hpca/damaged_active"); - public static final SimpleOverlayRenderer HPCA_ADVANCED_DAMAGED_OVERLAY = new SimpleOverlayRenderer("overlay/machine/hpca/damaged_advanced"); - public static final SimpleOverlayRenderer HPCA_ADVANCED_DAMAGED_ACTIVE_OVERLAY = new SimpleOverlayRenderer("overlay/machine/hpca/damaged_advanced_active"); - public static final SimpleOverlayRenderer HPCA_EMPTY_OVERLAY = new SimpleOverlayRenderer("overlay/machine/hpca/empty"); - public static final SimpleOverlayRenderer HPCA_HEAT_SINK_OVERLAY = new SimpleOverlayRenderer("overlay/machine/hpca/heat_sink"); - public static final SimpleOverlayRenderer ALARM_OVERLAY = new SimpleOverlayRenderer("overlay/machine/overlay_alarm"); - public static final SimpleOverlayRenderer ALARM_OVERLAY_ACTIVE = new SimpleOverlayRenderer("overlay/machine/overlay_alarm_active"); - public static final SimpleOverlayRenderer TAPED_OVERLAY = new SimpleOverlayRenderer("overlay/machine/overlay_ducttape"); + public static final SimpleOverlayRenderer BLANK_SCREEN = new SimpleOverlayRenderer( + "overlay/machine/overlay_blank_screen"); + public static final SimpleOverlayRenderer DATA_ACCESS_HATCH = new SimpleOverlayRenderer( + "overlay/machine/overlay_data_hatch"); + public static final SimpleOverlayRenderer CREATIVE_DATA_ACCESS_HATCH = new SimpleOverlayRenderer( + "overlay/machine/overlay_data_hatch_creative"); + public static final SimpleOverlayRenderer OPTICAL_DATA_ACCESS_HATCH = new SimpleOverlayRenderer( + "overlay/machine/overlay_data_hatch_optical"); + public static final SimpleOverlayRenderer LASER_SOURCE = new SimpleOverlayRenderer( + "overlay/machine/overlay_laser_source"); + public static final SimpleOverlayRenderer LASER_TARGET = new SimpleOverlayRenderer( + "overlay/machine/overlay_laser_target"); + public static final SimpleOverlayRenderer OBJECT_HOLDER_OVERLAY = new SimpleOverlayRenderer( + "overlay/machine/overlay_object_holder"); + public static final SimpleOverlayRenderer OBJECT_HOLDER_ACTIVE_OVERLAY = new SimpleOverlayRenderer( + "overlay/machine/overlay_object_holder_active"); + public static final SimpleOverlayRenderer HPCA_ACTIVE_COOLER_OVERLAY = new SimpleOverlayRenderer( + "overlay/machine/hpca/active_cooler"); + public static final SimpleOverlayRenderer HPCA_ACTIVE_COOLER_ACTIVE_OVERLAY = new SimpleOverlayRenderer( + "overlay/machine/hpca/active_cooler_active"); + public static final SimpleOverlayRenderer HPCA_BRIDGE_OVERLAY = new SimpleOverlayRenderer( + "overlay/machine/hpca/bridge"); + public static final SimpleOverlayRenderer HPCA_BRIDGE_ACTIVE_OVERLAY = new SimpleOverlayRenderer( + "overlay/machine/hpca/bridge_active"); + public static final SimpleOverlayRenderer HPCA_COMPUTATION_OVERLAY = new SimpleOverlayRenderer( + "overlay/machine/hpca/computation"); + public static final SimpleOverlayRenderer HPCA_COMPUTATION_ACTIVE_OVERLAY = new SimpleOverlayRenderer( + "overlay/machine/hpca/computation_active"); + public static final SimpleOverlayRenderer HPCA_ADVANCED_COMPUTATION_OVERLAY = new SimpleOverlayRenderer( + "overlay/machine/hpca/computation_advanced"); + public static final SimpleOverlayRenderer HPCA_ADVANCED_COMPUTATION_ACTIVE_OVERLAY = new SimpleOverlayRenderer( + "overlay/machine/hpca/computation_advanced_active"); + public static final SimpleOverlayRenderer HPCA_DAMAGED_OVERLAY = new SimpleOverlayRenderer( + "overlay/machine/hpca/damaged"); + public static final SimpleOverlayRenderer HPCA_DAMAGED_ACTIVE_OVERLAY = new SimpleOverlayRenderer( + "overlay/machine/hpca/damaged_active"); + public static final SimpleOverlayRenderer HPCA_ADVANCED_DAMAGED_OVERLAY = new SimpleOverlayRenderer( + "overlay/machine/hpca/damaged_advanced"); + public static final SimpleOverlayRenderer HPCA_ADVANCED_DAMAGED_ACTIVE_OVERLAY = new SimpleOverlayRenderer( + "overlay/machine/hpca/damaged_advanced_active"); + public static final SimpleOverlayRenderer HPCA_EMPTY_OVERLAY = new SimpleOverlayRenderer( + "overlay/machine/hpca/empty"); + public static final SimpleOverlayRenderer HPCA_HEAT_SINK_OVERLAY = new SimpleOverlayRenderer( + "overlay/machine/hpca/heat_sink"); + public static final SimpleOverlayRenderer ALARM_OVERLAY = new SimpleOverlayRenderer( + "overlay/machine/overlay_alarm"); + public static final SimpleOverlayRenderer ALARM_OVERLAY_ACTIVE = new SimpleOverlayRenderer( + "overlay/machine/overlay_alarm_active"); + public static final SimpleOverlayRenderer TAPED_OVERLAY = new SimpleOverlayRenderer( + "overlay/machine/overlay_ducttape"); public static final SimpleOverlayRenderer COVER_INTERFACE_FLUID = new SimpleOverlayRenderer( "cover/cover_interface_fluid"); @@ -468,7 +498,7 @@ public class Textures { "overlay/appeng/me_input_hatch"); public static final SimpleOverlayRenderer ME_OUTPUT_BUS = new SimpleOverlayRenderer("overlay/appeng/me_output_bus"); public static final SimpleOverlayRenderer ME_INPUT_BUS = new SimpleOverlayRenderer("overlay/appeng/me_input_bus"); -public static final ResourceLocation ACE_CAPE_TEXTURE = gregtechId("textures/capes/acecape.png"); + public static final ResourceLocation ACE_CAPE_TEXTURE = gregtechId("textures/capes/acecape.png"); public static final ResourceLocation AGENDER_CAPE_TEXTURE = gregtechId("textures/capes/agendercape.png"); public static final ResourceLocation AROMANTIC_CAPE_TEXTURE = gregtechId("textures/capes/aromanticcape.png"); public static final ResourceLocation BI_CAPE_TEXTURE = gregtechId("textures/capes/bicape.png"); diff --git a/src/main/java/gregtech/client/utils/MinerRenderHelper.java b/src/main/java/gregtech/client/utils/MinerRenderHelper.java index 25b7f2e98d9..fb2db16ad75 100644 --- a/src/main/java/gregtech/client/utils/MinerRenderHelper.java +++ b/src/main/java/gregtech/client/utils/MinerRenderHelper.java @@ -116,8 +116,8 @@ public static void renderAreaPreview(@NotNull AxisAlignedBB box, @NotNull BlockP boolean isBoxClippingThroughCamera = isBoxClippingThroughCamera(minX, maxX, minY, maxY, minZ, maxZ); // texture UVs - double texOffset = - (System.nanoTime() % TEXTURE_WRAP_INTERVAL_NANOSECONDS) / (double) (TEXTURE_WRAP_INTERVAL_NANOSECONDS); + double texOffset = (System.nanoTime() % TEXTURE_WRAP_INTERVAL_NANOSECONDS) / + (double) (TEXTURE_WRAP_INTERVAL_NANOSECONDS); double dx = (box.maxX - box.minX); double dy = (box.maxY - Math.max(0, box.minY)); @@ -144,7 +144,7 @@ public static void renderAreaPreview(@NotNull AxisAlignedBB box, @NotNull BlockP Tessellator tessellator = Tessellator.getInstance(); BufferBuilder buffer = tessellator.getBuffer(); - for (boolean looped = false; ; looped = true) { + for (boolean looped = false;; looped = true) { int alpha = looped ? 70 : 200; if (looped) { @@ -359,22 +359,6 @@ private static void swapRow(int r1, int r2) { System.arraycopy(mat, 12, mat, r2 * 4, 4); } - /* for debug - private static String matrixToString() { - StringBuilder stb = new StringBuilder(); - for (int r = 0; r < 3; r++) { - if (r != 0) stb.append('\n'); - for (int c = 0; c < 4; c++) { - if (c != 0) stb.append('\t'); - float v = getMatrixValue(c, r); - if (v >= 0) stb.append(" "); - stb.append(String.format("%.4f", v)); - } - } - return stb.toString(); - } - */ - private static final class SATTestResult { private float min, max; diff --git a/src/main/java/gregtech/common/MetaEntities.java b/src/main/java/gregtech/common/MetaEntities.java index 58707d7c6b3..126fedf6fd9 100644 --- a/src/main/java/gregtech/common/MetaEntities.java +++ b/src/main/java/gregtech/common/MetaEntities.java @@ -26,7 +26,8 @@ public static void init() { GregTechAPI.instance, 64, 5, true); EntityRegistry.registerModEntity(GTUtility.gregtechId("gtboat"), GTBoatEntity.class, "GTBoat", 3, GregTechAPI.instance, 64, 2, true); - EntityRegistry.registerModEntity(GTUtility.gregtechId("mining_pipe"), MiningPipeEntity.class, "MiningPipe", 4, GregTechAPI.instance, 0, 2, false); + EntityRegistry.registerModEntity(GTUtility.gregtechId("mining_pipe"), MiningPipeEntity.class, "MiningPipe", 4, + GregTechAPI.instance, 0, 2, false); } @SideOnly(Side.CLIENT) diff --git a/src/main/java/gregtech/common/metatileentities/MetaTileEntities.java b/src/main/java/gregtech/common/metatileentities/MetaTileEntities.java index 4a9c1e17492..1f29d36c874 100644 --- a/src/main/java/gregtech/common/metatileentities/MetaTileEntities.java +++ b/src/main/java/gregtech/common/metatileentities/MetaTileEntities.java @@ -30,7 +30,6 @@ import gregtech.common.metatileentities.electric.MetaTileEntityHull; import gregtech.common.metatileentities.electric.MetaTileEntityItemCollector; import gregtech.common.metatileentities.electric.MetaTileEntityMagicEnergyAbsorber; -import gregtech.common.metatileentities.electric.MetaTileEntityMiner; import gregtech.common.metatileentities.electric.MetaTileEntityPump; import gregtech.common.metatileentities.electric.MetaTileEntityRockBreaker; import gregtech.common.metatileentities.electric.MetaTileEntitySingleCombustion; @@ -62,7 +61,6 @@ import gregtech.common.metatileentities.multi.electric.MetaTileEntityHPCA; import gregtech.common.metatileentities.multi.electric.MetaTileEntityImplosionCompressor; import gregtech.common.metatileentities.multi.electric.MetaTileEntityLargeChemicalReactor; -import gregtech.common.metatileentities.multi.electric.MetaTileEntityLargeMiner; import gregtech.common.metatileentities.multi.electric.MetaTileEntityMultiSmelter; import gregtech.common.metatileentities.multi.electric.MetaTileEntityNetworkSwitch; import gregtech.common.metatileentities.multi.electric.MetaTileEntityPowerSubstation; @@ -110,7 +108,6 @@ import gregtech.common.metatileentities.steam.SteamFurnace; import gregtech.common.metatileentities.steam.SteamHammer; import gregtech.common.metatileentities.steam.SteamMacerator; -import gregtech.common.metatileentities.steam.SteamMiner; import gregtech.common.metatileentities.steam.SteamRockBreaker; import gregtech.common.metatileentities.steam.boiler.SteamCoalBoiler; import gregtech.common.metatileentities.steam.boiler.SteamLavaBoiler; @@ -778,8 +775,8 @@ public static void init() { STEAM_OVEN = registerMetaTileEntity(1024, new MetaTileEntitySteamOven(gregtechId("steam_oven"))); STEAM_GRINDER = registerMetaTileEntity(1025, new MetaTileEntitySteamGrinder(gregtechId("steam_grinder"))); - BASIC_LARGE_MINER = registerMetaTileEntity(1026, - new MetaTileEntityLargeMiner(gregtechId("large_miner.ev"), GTValues.EV, 16, 3, 8, LargeMinerTypes.STEEL)); + BASIC_LARGE_MINER = registerMetaTileEntity(1026, new MetaTileEntityLargeMiner(gregtechId("large_miner.ev"), + GTValues.EV, 16, 3, 8, LargeMinerTypes.STEEL)); LARGE_MINER = registerMetaTileEntity(1027, new MetaTileEntityLargeMiner(gregtechId("large_miner.iv"), GTValues.IV, 4, 5, 16, LargeMinerTypes.TITANIUM)); ADVANCED_LARGE_MINER = registerMetaTileEntity(1028, new MetaTileEntityLargeMiner(gregtechId("large_miner.luv"), diff --git a/src/main/java/gregtech/common/metatileentities/miner/LargeMinerTypes.java b/src/main/java/gregtech/common/metatileentities/miner/LargeMinerTypes.java index af92a7bccc8..acb8b4bf253 100644 --- a/src/main/java/gregtech/common/metatileentities/miner/LargeMinerTypes.java +++ b/src/main/java/gregtech/common/metatileentities/miner/LargeMinerTypes.java @@ -18,6 +18,7 @@ import org.jetbrains.annotations.Nullable; public enum LargeMinerTypes implements LargeMinerType { + STEEL, TITANIUM, TUNGSTEN_STEEL; @@ -27,8 +28,8 @@ public TraceabilityPredicate getCasing() { return MultiblockControllerBase.states(switch (this) { case STEEL -> MetaBlocks.METAL_CASING.getState(BlockMetalCasing.MetalCasingType.STEEL_SOLID); case TITANIUM -> MetaBlocks.METAL_CASING.getState(BlockMetalCasing.MetalCasingType.TITANIUM_STABLE); - case TUNGSTEN_STEEL -> - MetaBlocks.METAL_CASING.getState(BlockMetalCasing.MetalCasingType.TUNGSTENSTEEL_ROBUST); + case TUNGSTEN_STEEL -> MetaBlocks.METAL_CASING + .getState(BlockMetalCasing.MetalCasingType.TUNGSTENSTEEL_ROBUST); }); } diff --git a/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityLargeMiner.java b/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityLargeMiner.java index 3e2da94816c..f9417309651 100644 --- a/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityLargeMiner.java +++ b/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityLargeMiner.java @@ -82,7 +82,8 @@ import static gregtech.api.unification.material.Materials.DrillingFluid; public class MetaTileEntityLargeMiner extends MultiblockWithDisplayBase - implements Miner, IControllable, IDataInfoProvider, IFastRenderMetaTileEntity, IProgressBarMultiblock { + implements Miner, IControllable, IDataInfoProvider, IFastRenderMetaTileEntity, + IProgressBarMultiblock { @NotNull public final LargeMinerType type; @@ -181,8 +182,8 @@ public boolean collectBlockDrops(@NotNull World world, @NotNull BlockPos pos, @N drops.add(ToolHelper.getSilkTouchDrop(state)); } else if (MinerUtil.applyTieredHammerDrops(GTUtility.toItem(state), drops, this.getEnergyTier(), RecipeMaps.MACERATOR_RECIPES, 3) == 0) { - state.getBlock().getDrops(drops, world, pos, state, 0); // fallback - } + state.getBlock().getDrops(drops, world, pos, state, 0); // fallback + } boolean result = GTTransferUtils.addItemsToItemHandler(inventory, true, drops); this.inventoryFull = result; if (result) GTTransferUtils.addItemsToItemHandler(inventory, false, drops); @@ -330,9 +331,9 @@ protected Widget getFlexButton(int x, int y, int width, int height) { if (stateHolder == null) return super.getFlexButton(x, y, width, height); return new ImageCycleButtonWidget(x, y, width, height, GuiTextures.BUTTON_MINER_CONFIG_MODE, stateHolder::get, stateHolder::set) - .setTooltipHoverString(i -> i == 0 ? - "gregtech.machine.miner.button.tooltip.info" : - "gregtech.machine.miner.button.tooltip.config"); + .setTooltipHoverString(i -> i == 0 ? + "gregtech.machine.miner.button.tooltip.info" : + "gregtech.machine.miner.button.tooltip.config"); } @Override @@ -390,10 +391,11 @@ protected void addRealDisplayText(List textList, boolean configM } textList.add(new TextComponentTranslation( "gregtech.machine.miner.display.y_limit", new TextComponentString("") - .appendSibling(incrButton(yLimit, Integer.MAX_VALUE, MinerUtil.DISPLAY_CLICK_Y_LIMIT_INCR)) - .appendText(" ").appendSibling(decrButton(yLimit, 0, MinerUtil.DISPLAY_CLICK_Y_LIMIT_DECR)) - .appendText(" ").appendSibling(value)) - .setStyle(new Style().setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverText)))); + .appendSibling(incrButton(yLimit, Integer.MAX_VALUE, MinerUtil.DISPLAY_CLICK_Y_LIMIT_INCR)) + .appendText(" ").appendSibling(decrButton(yLimit, 0, MinerUtil.DISPLAY_CLICK_Y_LIMIT_DECR)) + .appendText(" ").appendSibling(value)) + .setStyle(new Style() + .setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverText)))); textList.add(new TextComponentTranslation("gregtech.machine.miner.display.repeat", toggleButton(this.minerLogic.isRepeat(), this.minerLogic.isWorking(), @@ -456,8 +458,8 @@ protected static ITextComponent previewAreaButton(boolean previewEnabled) { return new TextComponentTranslation(previewEnabled ? "gregtech.machine.miner.display.working_area.hide_preview" : "gregtech.machine.miner.display.working_area.preview") - .setStyle(button(previewEnabled ? MinerUtil.DISPLAY_CLICK_AREA_PREVIEW_HIDE : - MinerUtil.DISPLAY_CLICK_AREA_PREVIEW)); + .setStyle(button(previewEnabled ? MinerUtil.DISPLAY_CLICK_AREA_PREVIEW_HIDE : + MinerUtil.DISPLAY_CLICK_AREA_PREVIEW)); } @NotNull @@ -483,7 +485,7 @@ protected static ITextComponent toggleButton(boolean currentValue, boolean canIn new TextComponentTranslation(currentValue ? "gregtech.machine.miner.display.toggle.enabled" : "gregtech.machine.miner.display.toggle.disabled") - .setStyle(button(currentValue ? offEvent : onEvent)); + .setStyle(button(currentValue ? offEvent : onEvent)); } @NotNull diff --git a/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityMiner.java b/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityMiner.java index 4743f7761d7..e1bcf9f7c82 100644 --- a/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityMiner.java +++ b/src/main/java/gregtech/common/metatileentities/miner/MetaTileEntityMiner.java @@ -61,7 +61,7 @@ import java.util.List; public class MetaTileEntityMiner extends TieredMetaTileEntity - implements Miner, IControllable, IDataInfoProvider, IFastRenderMetaTileEntity { + implements Miner, IControllable, IDataInfoProvider, IFastRenderMetaTileEntity { private final ItemStackHandler chargerInventory; @@ -145,12 +145,12 @@ protected ModularUI createUI(@NotNull EntityPlayer entityPlayer) { this.minerLogic::isPreviewEnabled, this.minerLogic::setPreviewEnabled)) .widget(new ClickButtonWidget(161, yStart + 18 + 2, 9, 9, "", cd -> this.minerLogic.setCurrentDiameter( - this.minerLogic.getCurrentDiameter() + (cd.isShiftClick ? 5 : 1))) - .setButtonTexture(GuiTextures.BUTTON_INT_CIRCUIT_PLUS)) + this.minerLogic.getCurrentDiameter() + (cd.isShiftClick ? 5 : 1))) + .setButtonTexture(GuiTextures.BUTTON_INT_CIRCUIT_PLUS)) .widget(new ClickButtonWidget(161, yStart + 18 + 2 + 9, 9, 9, "", cd -> this.minerLogic.setCurrentDiameter( - this.minerLogic.getCurrentDiameter() - (cd.isShiftClick ? 5 : 1))) - .setButtonTexture(GuiTextures.BUTTON_INT_CIRCUIT_MINUS)) + this.minerLogic.getCurrentDiameter() - (cd.isShiftClick ? 5 : 1))) + .setButtonTexture(GuiTextures.BUTTON_INT_CIRCUIT_MINUS)) .widget(new AdvancedTextWidget(159, yStart + 18 + 2 + (18 - 11) / 2, list -> { int currentDiameter = this.minerLogic.getCurrentDiameter(); list.add(new TextComponentString(currentDiameter + "x" + currentDiameter)); @@ -174,17 +174,17 @@ protected void onSizeUpdate() { // >:( builder.widget( new ProgressWidget(this.minerLogic::getWorkProgress, xStart - 4 - 20, sideWidgetY, 20, 20, - GuiTextures.PROGRESS_BAR_MACERATE, ProgressWidget.MoveType.HORIZONTAL) - ).widget( - new ImageWidget(xStart - 4 - 20, sideWidgetY + 20, 18, 18, - GuiTextures.INDICATOR_NO_ENERGY) - .setIgnoreColor(true) - .setPredicate(minerLogic::hasNotEnoughEnergy) - ).widget( - new ImageWidget(152, 63 + yOffset, 17, 17, - GTValues.XMAS.get() ? GuiTextures.GREGTECH_LOGO_XMAS : GuiTextures.GREGTECH_LOGO) - .setIgnoreColor(true) - ).bindPlayerInventory(entityPlayer.inventory, GuiTextures.SLOT, yOffset); + GuiTextures.PROGRESS_BAR_MACERATE, ProgressWidget.MoveType.HORIZONTAL)) + .widget( + new ImageWidget(xStart - 4 - 20, sideWidgetY + 20, 18, 18, + GuiTextures.INDICATOR_NO_ENERGY) + .setIgnoreColor(true) + .setPredicate(minerLogic::hasNotEnoughEnergy)) + .widget( + new ImageWidget(152, 63 + yOffset, 17, 17, + GTValues.XMAS.get() ? GuiTextures.GREGTECH_LOGO_XMAS : GuiTextures.GREGTECH_LOGO) + .setIgnoreColor(true)) + .bindPlayerInventory(entityPlayer.inventory, GuiTextures.SLOT, yOffset); return builder.build(getHolder(), entityPlayer); } @@ -193,9 +193,9 @@ protected void onSizeUpdate() { // >:( public void addInformation(ItemStack stack, @Nullable World player, @NotNull List tooltip, boolean advanced) { tooltip.add(I18n.format("gregtech.machine.miner.tooltip")); - tooltip.add(I18n.format("gregtech.universal.tooltip.uses_per_tick", energyPerTick) - + TextFormatting.GRAY + ", " + - I18n.format("gregtech.machine.miner.per_block", this.minerLogic.getWorkFrequency() / 20)); + tooltip.add( + I18n.format("gregtech.universal.tooltip.uses_per_tick", energyPerTick) + TextFormatting.GRAY + ", " + + I18n.format("gregtech.machine.miner.per_block", this.minerLogic.getWorkFrequency() / 20)); tooltip.add(I18n.format("gregtech.universal.tooltip.voltage_in", energyContainer.getInputVoltage(), GTValues.VNF[getTier()])); tooltip.add( diff --git a/src/main/java/gregtech/common/metatileentities/miner/MinerLogic.java b/src/main/java/gregtech/common/metatileentities/miner/MinerLogic.java index f9dc0c720bc..1536ada98c8 100644 --- a/src/main/java/gregtech/common/metatileentities/miner/MinerLogic.java +++ b/src/main/java/gregtech/common/metatileentities/miner/MinerLogic.java @@ -173,7 +173,7 @@ public boolean isDone() { /** * @return origin position of the miner. Block boundary will be centered around this position, and mining pipes will - * be rendered under this position. + * be rendered under this position. */ @NotNull protected BlockPos getOrigin() { @@ -420,7 +420,7 @@ public void readFromNBT(@NotNull NBTTagCompound data) { this.miningArea = createMiningArea(); // Shouldn't be a problem but whatever - //noinspection ConstantValue + // noinspection ConstantValue if (this.miningArea != null) { this.miningArea.read(data); } diff --git a/src/main/java/gregtech/common/metatileentities/miner/MiningArea.java b/src/main/java/gregtech/common/metatileentities/miner/MiningArea.java index 4e77878db03..224d11f94cb 100644 --- a/src/main/java/gregtech/common/metatileentities/miner/MiningArea.java +++ b/src/main/java/gregtech/common/metatileentities/miner/MiningArea.java @@ -22,7 +22,8 @@ public interface MiningArea { /** * Get current block position for processing. If this method returns {@code true}, {@code mpos} argument should be * modified to the block position. Return value of {@code false} indicates there aren't any block left to process. - *
Calling this method does not affect the state. Use {@link #nextBlock()} for advancing to next block. + *
+ * Calling this method does not affect the state. Use {@link #nextBlock()} for advancing to next block. * * @param mpos Mutable block position * @return {@code true} if {@code mpos} is set to current block position for processing, {@code false} otherwise @@ -37,7 +38,7 @@ public interface MiningArea { void nextBlock(); /** - * Reset the cursor to starting point (i.e. re-start iteration from start) + * Reset the cursor to starting point (i.e. re-start iteration from start) */ void reset(); diff --git a/src/main/java/gregtech/common/metatileentities/miner/MultiblockMinerLogic.java b/src/main/java/gregtech/common/metatileentities/miner/MultiblockMinerLogic.java index 2f1da4444ab..6c30406d8a0 100644 --- a/src/main/java/gregtech/common/metatileentities/miner/MultiblockMinerLogic.java +++ b/src/main/java/gregtech/common/metatileentities/miner/MultiblockMinerLogic.java @@ -27,7 +27,8 @@ public class MultiblockMinerLogic extends MinerLogic { // bool config for repeating the operation after finished private boolean repeat; - // flag for disabling ore replacement (if true, ores will be replaced with air instead of whatever block that was specified in the config) + // flag for disabling ore replacement (if true, ores will be replaced with air instead of whatever block that was + // specified in the config) private boolean replaceOreWithAir; public MultiblockMinerLogic(@NotNull MetaTileEntityLargeMiner largeMiner, int workFrequency, diff --git a/src/main/java/gregtech/common/metatileentities/miner/SimpleMiningArea.java b/src/main/java/gregtech/common/metatileentities/miner/SimpleMiningArea.java index 06c5a330085..a424019ace7 100644 --- a/src/main/java/gregtech/common/metatileentities/miner/SimpleMiningArea.java +++ b/src/main/java/gregtech/common/metatileentities/miner/SimpleMiningArea.java @@ -33,7 +33,8 @@ public class SimpleMiningArea implements MiningArea { /** * Index for current block position. This implementation of {@link MiningArea} operates by first mapping each block * in given area to non-negative long indices, then processing it by incrementing internal counter starting from 0. - *
The area iterates through X plane first, then Z plane, before moving down one Y block. + *
+ * The area iterates through X plane first, then Z plane, before moving down one Y block. */ private long currentBlock; diff --git a/src/main/java/gregtech/common/terminal/app/prospector/widget/WidgetProspectingMap.java b/src/main/java/gregtech/common/terminal/app/prospector/widget/WidgetProspectingMap.java index 66764e494c6..698be63082d 100644 --- a/src/main/java/gregtech/common/terminal/app/prospector/widget/WidgetProspectingMap.java +++ b/src/main/java/gregtech/common/terminal/app/prospector/widget/WidgetProspectingMap.java @@ -153,7 +153,7 @@ public void detectAndSendChanges() { MaterialStack materialStack = OreDictUnifier.getMaterial(item, meta); if (materialStack != null) { String oreDict = "ore" + - oreDictString.replaceFirst(prefix.name(), ""); + oreDictString.replaceFirst(prefix.name(), ""); packet.addBlock(x, y, z, oreDict); added = true; break; diff --git a/src/main/java/gregtech/loaders/recipe/MetaTileEntityLoader.java b/src/main/java/gregtech/loaders/recipe/MetaTileEntityLoader.java index 5d20cdbe1c2..4ab3a49c389 100644 --- a/src/main/java/gregtech/loaders/recipe/MetaTileEntityLoader.java +++ b/src/main/java/gregtech/loaders/recipe/MetaTileEntityLoader.java @@ -452,20 +452,74 @@ public static void init() { new UnificationEntry(OrePrefix.pipeSmallFluid, Materials.Steel), 'S', new UnificationEntry(OrePrefix.plateDouble, Materials.Silver), 'G', new ItemStack(Blocks.GLASS)); - ModHandler.addShapedRecipe(true, "steam_furnace_bronze", MetaTileEntities.STEAM_FURNACE_BRONZE.getStackForm(), "XXX", "XMX", "XFX", 'M', MetaBlocks.STEAM_CASING.getItemVariant(BRONZE_BRICKS_HULL), 'X', new UnificationEntry(OrePrefix.pipeSmallFluid, Materials.Bronze), 'F', OreDictNames.craftingFurnace); - ModHandler.addShapedRecipe(true, "steam_furnace_steel", MetaTileEntities.STEAM_FURNACE_STEEL.getStackForm(), "XSX", "PMP", "XXX", 'M', MetaTileEntities.STEAM_FURNACE_BRONZE.getStackForm(), 'X', new UnificationEntry(OrePrefix.pipeSmallFluid, Materials.TinAlloy), 'S', new UnificationEntry(OrePrefix.plate, Materials.Steel), 'P', new UnificationEntry(OrePrefix.plate, Materials.WroughtIron)); - ModHandler.addShapedRecipe(true, "steam_macerator_bronze", MetaTileEntities.STEAM_MACERATOR_BRONZE.getStackForm(), "DXD", "XMX", "PXP", 'M', MetaBlocks.STEAM_CASING.getItemVariant(BRONZE_HULL), 'X', new UnificationEntry(OrePrefix.pipeSmallFluid, Materials.Bronze), 'P', OreDictNames.craftingPiston, 'D', new UnificationEntry(OrePrefix.gem, Materials.Diamond)); - ModHandler.addShapedRecipe(true, "steam_macerator_steel", MetaTileEntities.STEAM_MACERATOR_STEEL.getStackForm(), "WSW", "PMP", "WWW", 'M', MetaTileEntities.STEAM_MACERATOR_BRONZE.getStackForm(), 'W', new UnificationEntry(OrePrefix.plate, Materials.WroughtIron), 'S', new UnificationEntry(OrePrefix.plate, Materials.Steel), 'P', new UnificationEntry(OrePrefix.pipeSmallFluid, Materials.TinAlloy)); - ModHandler.addShapedRecipe(true, "steam_extractor_bronze", MetaTileEntities.STEAM_EXTRACTOR_BRONZE.getStackForm(), "XXX", "PMG", "XXX", 'M', MetaBlocks.STEAM_CASING.getItemVariant(BRONZE_HULL), 'X', new UnificationEntry(OrePrefix.pipeSmallFluid, Materials.Bronze), 'P', OreDictNames.craftingPiston, 'G', new ItemStack(Blocks.GLASS)); - ModHandler.addShapedRecipe(true, "steam_extractor_steel", MetaTileEntities.STEAM_EXTRACTOR_STEEL.getStackForm(), "PSP", "WMW", "PPP", 'M', MetaTileEntities.STEAM_EXTRACTOR_BRONZE.getStackForm(), 'P', new UnificationEntry(OrePrefix.pipeSmallFluid, Materials.TinAlloy), 'S', new UnificationEntry(OrePrefix.plate, Materials.Steel), 'W', new UnificationEntry(OrePrefix.plate, Materials.WroughtIron)); - ModHandler.addShapedRecipe(true, "steam_hammer_bronze", MetaTileEntities.STEAM_HAMMER_BRONZE.getStackForm(), "XPX", "XMX", "XAX", 'M', MetaBlocks.STEAM_CASING.getItemVariant(BRONZE_HULL), 'X', new UnificationEntry(OrePrefix.pipeSmallFluid, Materials.Bronze), 'P', OreDictNames.craftingPiston, 'A', OreDictNames.craftingAnvil); - ModHandler.addShapedRecipe(true, "steam_hammer_steel", MetaTileEntities.STEAM_HAMMER_STEEL.getStackForm(), "WSW", "PMP", "WWW", 'M', MetaTileEntities.STEAM_HAMMER_BRONZE.getStackForm(), 'S', new UnificationEntry(OrePrefix.plate, Materials.Steel), 'W', new UnificationEntry(OrePrefix.plate, Materials.WroughtIron), 'P', new UnificationEntry(OrePrefix.pipeSmallFluid, Materials.TinAlloy)); - ModHandler.addShapedRecipe(true, "steam_compressor_bronze", MetaTileEntities.STEAM_COMPRESSOR_BRONZE.getStackForm(), "XXX", "PMP", "XXX", 'M', MetaBlocks.STEAM_CASING.getItemVariant(BRONZE_HULL), 'X', new UnificationEntry(OrePrefix.pipeSmallFluid, Materials.Bronze), 'P', OreDictNames.craftingPiston); - ModHandler.addShapedRecipe(true, "steam_compressor_steel", MetaTileEntities.STEAM_COMPRESSOR_STEEL.getStackForm(), "PSP", "WMW", "PPP", 'M', MetaTileEntities.STEAM_COMPRESSOR_BRONZE.getStackForm(), 'S', new UnificationEntry(OrePrefix.plate, Materials.Steel), 'W', new UnificationEntry(OrePrefix.plate, Materials.WroughtIron), 'P', new UnificationEntry(OrePrefix.pipeSmallFluid, Materials.TinAlloy)); - ModHandler.addShapedRecipe(true, "steam_alloy_smelter_bronze", MetaTileEntities.STEAM_ALLOY_SMELTER_BRONZE.getStackForm(), "XXX", "FMF", "XXX", 'M', MetaBlocks.STEAM_CASING.getItemVariant(BRONZE_BRICKS_HULL), 'X', new UnificationEntry(OrePrefix.pipeSmallFluid, Materials.Bronze), 'F', OreDictNames.craftingFurnace); - ModHandler.addShapedRecipe(true, "steam_alloy_smelter_steel", MetaTileEntities.STEAM_ALLOY_SMELTER_STEEL.getStackForm(), "WSW", "WMW", "WPW", 'M', MetaTileEntities.STEAM_ALLOY_SMELTER_BRONZE.getStackForm(), 'S', new UnificationEntry(OrePrefix.plate, Materials.Steel), 'W', new UnificationEntry(OrePrefix.plate, Materials.WroughtIron), 'P', new UnificationEntry(OrePrefix.pipeSmallFluid, Materials.TinAlloy)); - ModHandler.addShapedRecipe(true, "steam_rock_breaker_bronze", MetaTileEntities.STEAM_ROCK_BREAKER_BRONZE.getStackForm(), "PXP", "XMX", "DXD", 'M', MetaBlocks.STEAM_CASING.getItemVariant(BRONZE_HULL), 'X', new UnificationEntry(OrePrefix.pipeSmallFluid, Materials.Bronze), 'P', "craftingPiston", 'D', new UnificationEntry(OrePrefix.gem, Materials.Diamond)); - ModHandler.addShapedRecipe(true, "steam_rock_breaker_steel", MetaTileEntities.STEAM_ROCK_BREAKER_STEEL.getStackForm(), "WSW", "PMP", "WWW", 'M', MetaTileEntities.STEAM_ROCK_BREAKER_BRONZE.getStackForm(), 'W', new UnificationEntry(OrePrefix.plate, Materials.WroughtIron), 'S', new UnificationEntry(OrePrefix.plate, Materials.Steel), 'P', new UnificationEntry(OrePrefix.pipeSmallFluid, Materials.TinAlloy)); + ModHandler.addShapedRecipe(true, "steam_furnace_bronze", MetaTileEntities.STEAM_FURNACE_BRONZE.getStackForm(), + "XXX", "XMX", "XFX", 'M', MetaBlocks.STEAM_CASING.getItemVariant(BRONZE_BRICKS_HULL), 'X', + new UnificationEntry(OrePrefix.pipeSmallFluid, Materials.Bronze), 'F', OreDictNames.craftingFurnace); + ModHandler.addShapedRecipe(true, "steam_furnace_steel", MetaTileEntities.STEAM_FURNACE_STEEL.getStackForm(), + "XSX", "PMP", "XXX", 'M', MetaTileEntities.STEAM_FURNACE_BRONZE.getStackForm(), 'X', + new UnificationEntry(OrePrefix.pipeSmallFluid, Materials.TinAlloy), 'S', + new UnificationEntry(OrePrefix.plate, Materials.Steel), 'P', + new UnificationEntry(OrePrefix.plate, Materials.WroughtIron)); + ModHandler.addShapedRecipe(true, "steam_macerator_bronze", + MetaTileEntities.STEAM_MACERATOR_BRONZE.getStackForm(), "DXD", "XMX", "PXP", 'M', + MetaBlocks.STEAM_CASING.getItemVariant(BRONZE_HULL), 'X', + new UnificationEntry(OrePrefix.pipeSmallFluid, Materials.Bronze), 'P', OreDictNames.craftingPiston, 'D', + new UnificationEntry(OrePrefix.gem, Materials.Diamond)); + ModHandler.addShapedRecipe(true, "steam_macerator_steel", MetaTileEntities.STEAM_MACERATOR_STEEL.getStackForm(), + "WSW", "PMP", "WWW", 'M', MetaTileEntities.STEAM_MACERATOR_BRONZE.getStackForm(), 'W', + new UnificationEntry(OrePrefix.plate, Materials.WroughtIron), 'S', + new UnificationEntry(OrePrefix.plate, Materials.Steel), 'P', + new UnificationEntry(OrePrefix.pipeSmallFluid, Materials.TinAlloy)); + ModHandler.addShapedRecipe(true, "steam_extractor_bronze", + MetaTileEntities.STEAM_EXTRACTOR_BRONZE.getStackForm(), "XXX", "PMG", "XXX", 'M', + MetaBlocks.STEAM_CASING.getItemVariant(BRONZE_HULL), 'X', + new UnificationEntry(OrePrefix.pipeSmallFluid, Materials.Bronze), 'P', OreDictNames.craftingPiston, 'G', + new ItemStack(Blocks.GLASS)); + ModHandler.addShapedRecipe(true, "steam_extractor_steel", MetaTileEntities.STEAM_EXTRACTOR_STEEL.getStackForm(), + "PSP", "WMW", "PPP", 'M', MetaTileEntities.STEAM_EXTRACTOR_BRONZE.getStackForm(), 'P', + new UnificationEntry(OrePrefix.pipeSmallFluid, Materials.TinAlloy), 'S', + new UnificationEntry(OrePrefix.plate, Materials.Steel), 'W', + new UnificationEntry(OrePrefix.plate, Materials.WroughtIron)); + ModHandler.addShapedRecipe(true, "steam_hammer_bronze", MetaTileEntities.STEAM_HAMMER_BRONZE.getStackForm(), + "XPX", "XMX", "XAX", 'M', MetaBlocks.STEAM_CASING.getItemVariant(BRONZE_HULL), 'X', + new UnificationEntry(OrePrefix.pipeSmallFluid, Materials.Bronze), 'P', OreDictNames.craftingPiston, 'A', + OreDictNames.craftingAnvil); + ModHandler.addShapedRecipe(true, "steam_hammer_steel", MetaTileEntities.STEAM_HAMMER_STEEL.getStackForm(), + "WSW", "PMP", "WWW", 'M', MetaTileEntities.STEAM_HAMMER_BRONZE.getStackForm(), 'S', + new UnificationEntry(OrePrefix.plate, Materials.Steel), 'W', + new UnificationEntry(OrePrefix.plate, Materials.WroughtIron), 'P', + new UnificationEntry(OrePrefix.pipeSmallFluid, Materials.TinAlloy)); + ModHandler.addShapedRecipe(true, "steam_compressor_bronze", + MetaTileEntities.STEAM_COMPRESSOR_BRONZE.getStackForm(), "XXX", "PMP", "XXX", 'M', + MetaBlocks.STEAM_CASING.getItemVariant(BRONZE_HULL), 'X', + new UnificationEntry(OrePrefix.pipeSmallFluid, Materials.Bronze), 'P', OreDictNames.craftingPiston); + ModHandler.addShapedRecipe(true, "steam_compressor_steel", + MetaTileEntities.STEAM_COMPRESSOR_STEEL.getStackForm(), "PSP", "WMW", "PPP", 'M', + MetaTileEntities.STEAM_COMPRESSOR_BRONZE.getStackForm(), 'S', + new UnificationEntry(OrePrefix.plate, Materials.Steel), 'W', + new UnificationEntry(OrePrefix.plate, Materials.WroughtIron), 'P', + new UnificationEntry(OrePrefix.pipeSmallFluid, Materials.TinAlloy)); + ModHandler.addShapedRecipe(true, "steam_alloy_smelter_bronze", + MetaTileEntities.STEAM_ALLOY_SMELTER_BRONZE.getStackForm(), "XXX", "FMF", "XXX", 'M', + MetaBlocks.STEAM_CASING.getItemVariant(BRONZE_BRICKS_HULL), 'X', + new UnificationEntry(OrePrefix.pipeSmallFluid, Materials.Bronze), 'F', OreDictNames.craftingFurnace); + ModHandler.addShapedRecipe(true, "steam_alloy_smelter_steel", + MetaTileEntities.STEAM_ALLOY_SMELTER_STEEL.getStackForm(), "WSW", "WMW", "WPW", 'M', + MetaTileEntities.STEAM_ALLOY_SMELTER_BRONZE.getStackForm(), 'S', + new UnificationEntry(OrePrefix.plate, Materials.Steel), 'W', + new UnificationEntry(OrePrefix.plate, Materials.WroughtIron), 'P', + new UnificationEntry(OrePrefix.pipeSmallFluid, Materials.TinAlloy)); + ModHandler.addShapedRecipe(true, "steam_rock_breaker_bronze", + MetaTileEntities.STEAM_ROCK_BREAKER_BRONZE.getStackForm(), "PXP", "XMX", "DXD", 'M', + MetaBlocks.STEAM_CASING.getItemVariant(BRONZE_HULL), 'X', + new UnificationEntry(OrePrefix.pipeSmallFluid, Materials.Bronze), 'P', "craftingPiston", 'D', + new UnificationEntry(OrePrefix.gem, Materials.Diamond)); + ModHandler.addShapedRecipe(true, "steam_rock_breaker_steel", + MetaTileEntities.STEAM_ROCK_BREAKER_STEEL.getStackForm(), "WSW", "PMP", "WWW", 'M', + MetaTileEntities.STEAM_ROCK_BREAKER_BRONZE.getStackForm(), 'W', + new UnificationEntry(OrePrefix.plate, Materials.WroughtIron), 'S', + new UnificationEntry(OrePrefix.plate, Materials.Steel), 'P', + new UnificationEntry(OrePrefix.pipeSmallFluid, Materials.TinAlloy)); // MULTI BLOCK CONTROLLERS ModHandler.addShapedRecipe(true, "bronze_primitive_blast_furnace", From f31f2d1ef47384f980be7b3d5e3b6eac286952be Mon Sep 17 00:00:00 2001 From: Tictim Date: Thu, 21 Dec 2023 16:00:21 +0900 Subject: [PATCH 27/27] Fuck you spotless --- .../java/gregtech/common/metatileentities/MetaTileEntities.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/gregtech/common/metatileentities/MetaTileEntities.java b/src/main/java/gregtech/common/metatileentities/MetaTileEntities.java index 1f29d36c874..84c32da7b48 100644 --- a/src/main/java/gregtech/common/metatileentities/MetaTileEntities.java +++ b/src/main/java/gregtech/common/metatileentities/MetaTileEntities.java @@ -1286,7 +1286,7 @@ public static void registerMetaTileEntities( } public static T registerMetaTileEntity(int id, T sampleMetaTileEntity) { - if (sampleMetaTileEntity instanceof IMultiblockAbilityPart abilityPart) { + if (sampleMetaTileEntity instanceof IMultiblockAbilityPartabilityPart) { MultiblockAbility.registerMultiblockAbility(abilityPart.getAbility(), sampleMetaTileEntity); } if (sampleMetaTileEntity instanceof MultiblockControllerBase && Loader.isModLoaded(GTValues.MODID_JEI)) {