Merge pull request #322 from MartinTheDragon/fluid-duct-qof

Make marking pipelines easier and quicker
This commit is contained in:
HbmMods 2021-10-30 17:59:20 +02:00 committed by GitHub
commit 29687f339a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 53 additions and 4 deletions

View File

@ -1,7 +1,11 @@
package com.hbm.items.machine;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import com.hbm.handler.FluidTypeHandler.FluidType;
import com.hbm.interfaces.IFluidDuct;
import com.hbm.items.ModItems;
import com.hbm.tileentity.conductor.TileEntityFluidDuct;
import com.hbm.util.I18nUtil;
@ -18,6 +22,7 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.IIcon;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
public class ItemFluidIdentifier extends Item {
@ -65,8 +70,12 @@ public class ItemFluidIdentifier extends Item {
list.add(EnumChatFormatting.YELLOW + I18nUtil.resolveKey("info.templatefolder", I18nUtil.resolveKey(ModItems.template_folder.getUnlocalizedName() + ".name")));
list.add("");
list.add("Universal fluid identifier for:");
list.add(I18nUtil.resolveKey(getUnlocalizedName() + ".info"));
list.add(" " + I18n.format(FluidType.getEnum(stack.getItemDamage()).getUnlocalizedName()));
list.add("");
list.add(I18nUtil.resolveKey(getUnlocalizedName() + ".usage0"));
list.add(I18nUtil.resolveKey(getUnlocalizedName() + ".usage1"));
list.add(I18nUtil.resolveKey(getUnlocalizedName() + ".usage2"));
}
public static FluidType getType(ItemStack stack) {
@ -79,11 +88,12 @@ public class ItemFluidIdentifier extends Item {
@Override
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int i, float f1, float f2, float f3) {
TileEntity te = world.getTileEntity(x, y, z);
if(te != null && te instanceof TileEntityFluidDuct) {
if(te instanceof TileEntityFluidDuct) {
if(!world.isRemote) {
TileEntityFluidDuct duct = (TileEntityFluidDuct) te;
duct.type = FluidType.getEnum(stack.getItemDamage());
FluidType type = FluidType.getEnum(stack.getItemDamage());
if (player.isSneaking()) markDuctsRecursively(world, x, y, z, type);
else duct.type = type;
}
player.swingItem();
@ -91,6 +101,37 @@ public class ItemFluidIdentifier extends Item {
return false;
}
private void markDuctsRecursively(World world, int x, int y, int z, FluidType type) {
markDuctsRecursively(world, x, y, z, type, 64);
}
private void markDuctsRecursively(World world, int x, int y, int z, FluidType type, int maxRecursion) {
TileEntity start = world.getTileEntity(x, y, z);
if (!(start instanceof TileEntityFluidDuct)) return;
TileEntityFluidDuct startDuct = (TileEntityFluidDuct) start;
FluidType oldType = startDuct.type;
if (oldType == type) return; // prevent infinite loops
startDuct.type = type;
directionLoop: for (ForgeDirection direction : ForgeDirection.values()) {
for (int currentRecursion = 1; currentRecursion <= maxRecursion; currentRecursion++) {
int nextX = x + direction.offsetX * currentRecursion;
int nextY = y + direction.offsetY * currentRecursion;
int nextZ = z + direction.offsetZ * currentRecursion;
TileEntity te = world.getTileEntity(nextX, nextY, nextZ);
if (te instanceof IFluidDuct && ((IFluidDuct) te).getType() == oldType) {
TileEntityFluidDuct nextDuct = (TileEntityFluidDuct) te;
long connectionsCount = Arrays.stream(nextDuct.connections).filter(Objects::nonNull).count();
if (connectionsCount > 1) {
markDuctsRecursively(world, nextX, nextY, nextZ, type, maxRecursion - currentRecursion);
continue directionLoop;
} else nextDuct.type = type;
} else break;
}
}
}
@Override
@SideOnly(Side.CLIENT)
public boolean requiresMultipleRenderPasses() {

View File

@ -1213,6 +1213,10 @@ item.fluid_barrel_full.name=Flüssigkeitsfass:
item.fluid_barrel_infinite.name=Unendliches Fass
item.fluid_duct.name=Flüssigkeitsrohr:
item.fluid_identifier.name=Flüssigkeits-Kennzeichnung
item.fluid_identifier.info=Universelle Flüssigkeits-Kennzeichnung für:
item.fluid_identifier.usage0=Rechtsklicke Rohre, um ihnen die jeweilige Flüssigkeit zuzuweisen.
item.fluid_identifier.usage1=Shift-rechtsklicke Rohre, um angeschlossene Rohre mit
item.fluid_identifier.usage2=einer maximalen Reichweite von 64 Rohren zuzuweisen.
item.fluid_tank_empty.name=Leere universelle Flüssigkeitszelle
item.fluid_tank_full.name=Universelle Flüssigkeitszelle:
item.fluorite.name=Fluorit

View File

@ -1281,6 +1281,10 @@ item.fluid_barrel_full.name=Fluid Barrel:
item.fluid_barrel_infinite.name=Infinite Fluid Barrel
item.fluid_duct.name=Fluid Duct:
item.fluid_identifier.name=Fluid Identifier
item.fluid_identifier.info=Universal fluid identifier for:
item.fluid_identifier.usage0=Right click fluid ducts to designate them for that fluid.
item.fluid_identifier.usage1=Shift right click fluid ducts to designate adjacent ducts
item.fluid_identifier.usage2=up to a maximum range of 64 ducts.
item.fluid_tank_empty.name=Empty Universal Fluid Tank
item.fluid_tank_full.name=Universal Fluid Tank:
item.fluorite.name=Fluorite