small fixes, proper fluid duct collisions

This commit is contained in:
Bob 2022-11-22 22:37:22 +01:00
parent 30038b7f06
commit 3e89c021b8
9 changed files with 134 additions and 23 deletions

View File

@ -7,5 +7,6 @@ import net.minecraftforge.common.util.ForgeDirection;
public interface IFluidConnectorBlock {
/** dir is the face that is connected to, the direction going outwards from the block */
public boolean canConnect(FluidType type, IBlockAccess world, int x, int y, int z, ForgeDirection dir);
}

View File

@ -126,7 +126,7 @@ public class FluidDuctBox extends FluidDuctBase implements IBlockMulti, ILookOve
@SideOnly(Side.CLIENT)
public void getSubBlocks(Item item, CreativeTabs tab, List list) {
for(int i = 0; i < 12; ++i) {
for(int i = 0; i < 15; ++i) {
list.add(new ItemStack(item, 1, i));
}
}

View File

@ -6,6 +6,8 @@ import java.util.List;
import com.hbm.blocks.IBlockMulti;
import com.hbm.blocks.ILookOverlay;
import com.hbm.blocks.test.TestPipe;
import com.hbm.inventory.fluid.FluidType;
import com.hbm.lib.Library;
import com.hbm.lib.RefStrings;
import com.hbm.tileentity.network.TileEntityPipeBaseNT;
import com.hbm.util.I18nUtil;
@ -15,12 +17,16 @@ import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.IIcon;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.client.event.RenderGameOverlayEvent.Pre;
import net.minecraftforge.common.util.ForgeDirection;
public class FluidDuctStandard extends FluidDuctBase implements IBlockMulti, ILookOverlay {
@ -85,6 +91,109 @@ public class FluidDuctStandard extends FluidDuctBase implements IBlockMulti, ILo
return 3;
}
@Override
public void addCollisionBoxesToList(World world, int x, int y, int z, AxisAlignedBB entityBounding, List list, Entity entity) {
List<AxisAlignedBB> bbs = new ArrayList();
bbs.add(AxisAlignedBB.getBoundingBox(x + 0.3125D, y + 0.3125D, z + 0.3125D, x + 0.6875D, y + 0.6875D, z + 0.6875D));
TileEntity te = world.getTileEntity(x, y, z);
if(te instanceof TileEntityPipeBaseNT) {
TileEntityPipeBaseNT pipe = (TileEntityPipeBaseNT) te;
FluidType type = pipe.getType();
boolean nX = canConnectTo(world, x, y, z, Library.NEG_X, type);
boolean pX = canConnectTo(world, x, y, z, Library.POS_X, type);
boolean nY = canConnectTo(world, x, y, z, Library.NEG_Y, type);
boolean pY = canConnectTo(world, x, y, z, Library.POS_Y, type);
boolean nZ = canConnectTo(world, x, y, z, Library.NEG_Z, type);
boolean pZ = canConnectTo(world, x, y, z, Library.POS_Z, type);
int mask = 0 + (pX ? 32 : 0) + (nX ? 16 : 0) + (pY ? 8 : 0) + (nY ? 4 : 0) + (pZ ? 2 : 0) + (nZ ? 1 : 0);
if(mask == 0) {
bbs.add(AxisAlignedBB.getBoundingBox(x + 0.6875D, y + 0.3125D, z + 0.3125D, x + 1.0D, y + 0.6875D, z + 0.6875D));
bbs.add(AxisAlignedBB.getBoundingBox(x + 0.0D, y + 0.3125D, z + 0.3125D, x + 0.3125D, y + 0.6875D, z + 0.6875D));
bbs.add(AxisAlignedBB.getBoundingBox(x + 0.3125D, y + 0.6875D, z + 0.3125D, x + 0.6875D, y + 1.0D, z + 0.6875D));
bbs.add(AxisAlignedBB.getBoundingBox(x + 0.3125D, y + 0.0D, z + 0.3125D, x + 0.6875D, y + 0.3125D, z + 0.6875D));
bbs.add(AxisAlignedBB.getBoundingBox(x + 0.3125D, y + 0.3125D, z + 0.6875D, x + 0.6875D, y + 0.6875D, z + 1.0D));
bbs.add(AxisAlignedBB.getBoundingBox(x + 0.3125D, y + 0.3125D, z + 0.0D, x + 0.6875D, y + 0.6875D, z + 0.3125D));
} else if(mask == 0b100000 || mask == 0b010000) {
bbs.add(AxisAlignedBB.getBoundingBox(x + 0.0D, y + 0.3125D, z + 0.3125D, x + 0.3125D, y + 0.6875D, z + 0.6875D));
bbs.add(AxisAlignedBB.getBoundingBox(x + 0.3125D, y + 0.3125D, z + 0.0D, x + 0.6875D, y + 0.6875D, z + 0.3125D));
} else if(mask == 0b001000 || mask == 0b000100) {
bbs.add(AxisAlignedBB.getBoundingBox(x + 0.3125D, y + 0.6875D, z + 0.3125D, x + 0.6875D, y + 1.0D, z + 0.6875D));
bbs.add(AxisAlignedBB.getBoundingBox(x + 0.3125D, y + 0.0D, z + 0.3125D, x + 0.6875D, y + 0.3125D, z + 0.6875D));
} else if(mask == 0b000010 || mask == 0b000001) {
bbs.add(AxisAlignedBB.getBoundingBox(x + 0.3125D, y + 0.3125D, z + 0.6875D, x + 0.6875D, y + 0.6875D, z + 1.0D));
bbs.add(AxisAlignedBB.getBoundingBox(x + 0.3125D, y + 0.3125D, z + 0.0D, x + 0.6875D, y + 0.6875D, z + 0.3125D));
} else {
if(pX) bbs.add(AxisAlignedBB.getBoundingBox(x + 0.6875D, y + 0.3125D, z + 0.3125D, x + 1.0D, y + 0.6875D, z + 0.6875D));
if(nX) bbs.add(AxisAlignedBB.getBoundingBox(x + 0.0D, y + 0.3125D, z + 0.3125D, x + 0.3125D, y + 0.6875D, z + 0.6875D));
if(pY) bbs.add(AxisAlignedBB.getBoundingBox(x + 0.3125D, y + 0.6875D, z + 0.3125D, x + 0.6875D, y + 1.0D, z + 0.6875D));
if(nY) bbs.add(AxisAlignedBB.getBoundingBox(x + 0.3125D, y + 0.0D, z + 0.3125D, x + 0.6875D, y + 0.3125D, z + 0.6875D));
if(pZ) bbs.add(AxisAlignedBB.getBoundingBox(x + 0.3125D, y + 0.3125D, z + 0.6875D, x + 0.6875D, y + 0.6875D, z + 1.0D));
if(nZ) bbs.add(AxisAlignedBB.getBoundingBox(x + 0.3125D, y + 0.3125D, z + 0.0D, x + 0.6875D, y + 0.6875D, z + 0.3125D));
}
}
for(AxisAlignedBB bb : bbs) {
if(entityBounding.intersectsWith(bb)) {
list.add(bb);
}
}
}
@Override
@SideOnly(Side.CLIENT)
public AxisAlignedBB getSelectedBoundingBoxFromPool(World world, int x, int y, int z) {
setBlockBoundsBasedOnState(world, x, y, z);
return AxisAlignedBB.getBoundingBox(x + this.minX, y + this.minY, z + this.minZ, x + this.maxX, y + this.maxY, z + this.maxZ);
}
@Override
public void setBlockBoundsBasedOnState(IBlockAccess world, int x, int y, int z) {
TileEntity te = world.getTileEntity(x, y, z);
if(te instanceof TileEntityPipeBaseNT) {
TileEntityPipeBaseNT pipe = (TileEntityPipeBaseNT) te;
FluidType type = pipe.getType();
boolean nX = canConnectTo(world, x, y, z, Library.NEG_X, type);
boolean pX = canConnectTo(world, x, y, z, Library.POS_X, type);
boolean nY = canConnectTo(world, x, y, z, Library.NEG_Y, type);
boolean pY = canConnectTo(world, x, y, z, Library.POS_Y, type);
boolean nZ = canConnectTo(world, x, y, z, Library.NEG_Z, type);
boolean pZ = canConnectTo(world, x, y, z, Library.POS_Z, type);
int mask = 0 + (pX ? 32 : 0) + (nX ? 16 : 0) + (pY ? 8 : 0) + (nY ? 4 : 0) + (pZ ? 2 : 0) + (nZ ? 1 : 0);
if(mask == 0) {
this.setBlockBounds(0F, 0F, 0F, 1F, 1F, 1F);
} else if(mask == 0b100000 || mask == 0b010000) {
this.setBlockBounds(0F, 0.3125F, 0.3125F, 1F, 0.6875F, 0.6875F);
} else if(mask == 0b001000 || mask == 0b000100) {
this.setBlockBounds(0.3125F, 0F, 0.3125F, 0.6875F, 1F, 0.6875F);
} else if(mask == 0b000010 || mask == 0b000001) {
this.setBlockBounds(0.3125F, 0.3125F, 0F, 0.6875F, 0.6875F, 1F);
} else {
this.setBlockBounds(
nX ? 0F : 0.3125F,
nY ? 0F : 0.3125F,
nZ ? 0F : 0.3125F,
pX ? 1F : 0.6875F,
pY ? 1F : 0.6875F,
pZ ? 1F : 0.6875F);
}
}
}
public boolean canConnectTo(IBlockAccess world, int x, int y, int z, ForgeDirection dir, FluidType type) {
return Library.canConnectFluid(world, x + dir.offsetX, y + dir.offsetY, z + dir.offsetZ, dir, type);
}
@Override
public void printHook(Pre event, World world, int x, int y, int z) {

View File

@ -223,7 +223,7 @@ public class ExplosionLarge {
if(world.getBlock((int)x0, (int)y0, (int)z0) != Blocks.air) {
if(world.getBlock((int)x0, (int)y0, (int)z0).getExplosionResistance(null) > 70)
if(world.getBlock((int)x0, (int)y0, (int)z0).getExplosionResistance(null, world, (int)x0, (int)y0, (int)z0, posX, posY, posZ) > 70)
continue;
EntityRubble rubble = new EntityRubble(world);

View File

@ -188,23 +188,25 @@ public class ItemEnergy extends Item {
HbmLivingProps.incrementRadiation(player, 500F);
player.triggerAchievement(MainRegistry.achRadium);
}
}
if(!player.capabilities.isCreativeMode) {
if(!player.capabilities.isCreativeMode) {
if(this.cap != null) {
if(this == ModItems.bottle2_sunset && world.rand.nextInt(20) == 0)
player.inventory.addItemStackToInventory(new ItemStack(ModItems.cap_star));
else
player.inventory.addItemStackToInventory(new ItemStack(this.cap));
}
if(this.container != null) {
if(stack.stackSize <= 0) {
return new ItemStack(this.container);
if(this.cap != null) {
if(this == ModItems.bottle2_sunset && world.rand.nextInt(20) == 0)
player.inventory.addItemStackToInventory(new ItemStack(ModItems.cap_star));
else
player.inventory.addItemStackToInventory(new ItemStack(this.cap));
}
if(this.container != null) {
if(stack.stackSize <= 0) {
return new ItemStack(this.container);
}
player.inventory.addItemStackToInventory(new ItemStack(this.container));
}
player.inventory.addItemStackToInventory(new ItemStack(this.container));
}
player.inventoryContainer.detectAndSendChanges();
}
return stack;

View File

@ -1,16 +1,12 @@
package com.hbm.items.special;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import com.hbm.items.ItemCustomLore;
import com.hbm.items.ModItems;
import com.hbm.potion.HbmPotion;
import com.hbm.util.Tuple.Pair;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;

View File

@ -132,6 +132,7 @@ public class Library {
return false;
}
/** dir is the direction along the fluid duct entering the block */
public static boolean canConnectFluid(IBlockAccess world, int x, int y, int z, ForgeDirection dir, FluidType type) {
if(y > 255 || y < 0)
@ -143,14 +144,14 @@ public class Library {
if(b instanceof IFluidConnectorBlock) {
IFluidConnectorBlock con = (IFluidConnectorBlock) b;
if(con.canConnect(type, world, x, y, z, dir))
if(con.canConnect(type, world, x, y, z, dir.getOpposite()))
return true;
}
if(te instanceof IFluidConnector) {
IFluidConnector con = (IFluidConnector) te;
if(con.canConnect(type, dir))
if(con.canConnect(type, dir.getOpposite()))
return true;
}

View File

@ -51,7 +51,7 @@ public class RenderBoxDuct implements ISimpleBlockRenderingHandler {
double jLower = 0.0625D;
double jUpper = 0.9375D;
for(int i = 2; i < 10; i += 3) {
for(int i = 2; i < 13; i += 3) {
if(meta > i) {
lower += 0.0625D;

View File

@ -175,8 +175,10 @@ public class TileEntityMachineChemfac extends TileEntityMachineChemplantBase {
protected List<DirPos> getConPos() {
if(conPos != null)
if(conPos != null && !conPos.isEmpty())
return conPos;
conPos = new ArrayList();
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - BlockDummyable.offset).getOpposite();
ForgeDirection rot = dir.getRotation(ForgeDirection.DOWN);