Start work on fluid pipes

This commit is contained in:
modmuss50 2016-05-09 11:13:52 +01:00
parent b97e884432
commit dd6e69bea5
26 changed files with 516 additions and 47 deletions

View file

@ -6,6 +6,7 @@ import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.event.FMLServerStartingEvent;
import net.minecraftforge.fml.common.registry.GameRegistry;
import techreborn.compat.ICompatModule;
import techreborn.parts.powerCables.ItemStandaloneCables;
/**
* Created by modmuss50 on 06/03/2016.

View file

@ -12,6 +12,11 @@ import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.event.FMLServerStartingEvent;
import net.minecraftforge.fml.common.registry.GameRegistry;
import techreborn.compat.ICompatModule;
import techreborn.parts.fluidPipes.ItemFluidPipe;
import techreborn.parts.fluidPipes.MultipartFluidPipe;
import techreborn.parts.powerCables.CableMultipart;
import techreborn.parts.powerCables.EnumCableType;
import techreborn.parts.powerCables.ItemCables;
/**
* Created by modmuss50 on 02/03/2016.
@ -22,6 +27,9 @@ public class TechRebornParts implements ICompatModule
@Nullable
public static Item cables;
@Nullable
public static Item fluidPipe;
public static HashMap<EnumCableType, Class<? extends CableMultipart>> multipartHashMap = new HashMap<>();
@Override
@ -39,7 +47,13 @@ public class TechRebornParts implements ICompatModule
MultipartRegistry.registerPart(cableType.cableClass, "techreborn:cable." + cableType.name());
}
cables = new ItemCables();
GameRegistry.registerItem(cables, "cables");
cables.setRegistryName("cables");
GameRegistry.register(cables);
MultipartRegistry.registerPart(MultipartFluidPipe.class, "techreborn:fluidpipe");
fluidPipe = new ItemFluidPipe();
fluidPipe.setRegistryName("fluidPipe");
GameRegistry.register(fluidPipe);
}
@Override

View file

@ -0,0 +1,29 @@
package techreborn.parts.fluidPipes;
import mcmultipart.item.ItemMultiPart;
import mcmultipart.multipart.IMultipart;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import reborncore.RebornCore;
import techreborn.client.TechRebornCreativeTab;
/**
* Created by modmuss50 on 09/05/2016.
*/
public class ItemFluidPipe extends ItemMultiPart {
public ItemFluidPipe() {
setCreativeTab(TechRebornCreativeTab.instance);
setUnlocalizedName("techreborn.fluidpipe");
RebornCore.jsonDestroyer.registerObject(this);
}
@Override
public IMultipart createPart(World world, BlockPos pos, EnumFacing side, Vec3d hit, ItemStack stack, EntityPlayer player) {
return new MultipartFluidPipe();
}
}

View file

@ -0,0 +1,282 @@
package techreborn.parts.fluidPipes;
import mcmultipart.MCMultiPartMod;
import mcmultipart.microblock.IMicroblock;
import mcmultipart.multipart.*;
import mcmultipart.raytrace.PartMOP;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyBool;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ITickable;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.common.property.ExtendedBlockState;
import net.minecraftforge.common.property.IExtendedBlockState;
import net.minecraftforge.common.property.IUnlistedProperty;
import net.minecraftforge.common.property.Properties;
import reborncore.api.power.IEnergyInterfaceTile;
import reborncore.common.misc.Functions;
import reborncore.common.misc.vecmath.Vecs3dCube;
import reborncore.common.util.WorldUtils;
import techreborn.parts.TechRebornParts;
import java.util.*;
/**
* Created by modmuss50 on 09/05/2016.
*/
public class MultipartFluidPipe extends Multipart implements INormallyOccludingPart, ISlottedPart, ITickable {
public static final IUnlistedProperty<Boolean> UP = Properties.toUnlisted(PropertyBool.create("up"));
public static final IUnlistedProperty<Boolean> DOWN = Properties.toUnlisted(PropertyBool.create("down"));
public static final IUnlistedProperty<Boolean> NORTH = Properties.toUnlisted(PropertyBool.create("north"));
public static final IUnlistedProperty<Boolean> EAST = Properties.toUnlisted(PropertyBool.create("east"));
public static final IUnlistedProperty<Boolean> SOUTH = Properties.toUnlisted(PropertyBool.create("south"));
public static final IUnlistedProperty<Boolean> WEST = Properties.toUnlisted(PropertyBool.create("west"));
public Vecs3dCube[] boundingBoxes = new Vecs3dCube[14];
public float center = 0.6F;
public float offset = 0.10F;
public Map<EnumFacing, BlockPos> connectedSides;
public static final int thickness = 12;
public MultipartFluidPipe() {
connectedSides = new HashMap<>();
refreshBounding();
}
public static MultipartFluidPipe getPartFromWorld(World world, BlockPos pos, EnumFacing side) {
if (world == null || pos == null) {
return null;
}
IMultipartContainer container = MultipartHelper.getPartContainer(world, pos);
if (side != null && container != null) {
ISlottedPart slottedPart = container.getPartInSlot(PartSlot.getFaceSlot(side));
if (slottedPart instanceof IMicroblock.IFaceMicroblock
&& !((IMicroblock.IFaceMicroblock) slottedPart).isFaceHollow()) {
return null;
}
}
if (container == null) {
return null;
}
ISlottedPart part = container.getPartInSlot(PartSlot.CENTER);
if (part instanceof MultipartFluidPipe) {
return (MultipartFluidPipe) part;
}
return null;
}
public void refreshBounding() {
float centerFirst = center - offset;
double w = (thickness / 16) - 0.5;
boundingBoxes[6] = new Vecs3dCube(centerFirst - w, centerFirst - w, centerFirst - w, centerFirst + w,
centerFirst + w, centerFirst + w);
int i = 0;
for (EnumFacing dir : EnumFacing.VALUES) {
double xMin1 = (dir.getFrontOffsetX() < 0 ? 0.0
: (dir.getFrontOffsetX() == 0 ? centerFirst - w : centerFirst + w));
double xMax1 = (dir.getFrontOffsetX() > 0 ? 1.0
: (dir.getFrontOffsetX() == 0 ? centerFirst + w : centerFirst - w));
double yMin1 = (dir.getFrontOffsetY() < 0 ? 0.0
: (dir.getFrontOffsetY() == 0 ? centerFirst - w : centerFirst + w));
double yMax1 = (dir.getFrontOffsetY() > 0 ? 1.0
: (dir.getFrontOffsetY() == 0 ? centerFirst + w : centerFirst - w));
double zMin1 = (dir.getFrontOffsetZ() < 0 ? 0.0
: (dir.getFrontOffsetZ() == 0 ? centerFirst - w : centerFirst + w));
double zMax1 = (dir.getFrontOffsetZ() > 0 ? 1.0
: (dir.getFrontOffsetZ() == 0 ? centerFirst + w : centerFirst - w));
boundingBoxes[i] = new Vecs3dCube(xMin1, yMin1, zMin1, xMax1, yMax1, zMax1);
i++;
}
}
@Override
public void addCollisionBoxes(AxisAlignedBB mask, List<AxisAlignedBB> list, Entity collidingEntity) {
for (EnumFacing dir : EnumFacing.VALUES) {
if (connectedSides.containsKey(dir)
&& mask.intersectsWith(boundingBoxes[Functions.getIntDirFromDirection(dir)].toAABB()))
list.add(boundingBoxes[Functions.getIntDirFromDirection(dir)].toAABB());
}
if (mask.intersectsWith(boundingBoxes[6].toAABB())) {
list.add(boundingBoxes[6].toAABB());
}
super.addCollisionBoxes(mask, list, collidingEntity);
}
@Override
public void addSelectionBoxes(List<AxisAlignedBB> list) {
for (EnumFacing dir : EnumFacing.VALUES) {
if (connectedSides.containsKey(dir))
list.add(boundingBoxes[Functions.getIntDirFromDirection(dir)].toAABB());
}
list.add(boundingBoxes[6].toAABB());
super.addSelectionBoxes(list);
}
@Override
public void onRemoved() {
super.onRemoved();
for (EnumFacing dir : EnumFacing.VALUES) {
MultipartFluidPipe multipart = getPartFromWorld(getWorld(), getPos().offset(dir), dir);
if (multipart != null) {
multipart.nearByChange();
}
}
}
@Override
public void addOcclusionBoxes(List<AxisAlignedBB> list) {
for (EnumFacing dir : EnumFacing.VALUES) {
if (connectedSides.containsKey(dir))
list.add(boundingBoxes[Functions.getIntDirFromDirection(dir)].toAABB());
}
list.add(boundingBoxes[6].toAABB());
}
@Override
public void onNeighborBlockChange(Block block) {
super.onNeighborBlockChange(block);
nearByChange();
}
public void nearByChange() {
checkConnectedSides();
for (EnumFacing direction : EnumFacing.VALUES) {
BlockPos blockPos = getPos().offset(direction);
WorldUtils.updateBlock(getWorld(), blockPos);
MultipartFluidPipe part = getPartFromWorld(getWorld(), blockPos, direction);
if (part != null) {
part.checkConnectedSides();
}
}
}
@Override
public void onAdded() {
nearByChange();
}
public boolean shouldConnectTo(EnumFacing dir) {
if (dir != null) {
if (internalShouldConnectTo(dir)) {
MultipartFluidPipe multipartFluidPipe = getPartFromWorld(getWorld(), getPos().offset(dir), dir);
if (multipartFluidPipe != null && multipartFluidPipe.internalShouldConnectTo(dir.getOpposite())) {
return true;
}
} else {
TileEntity tile = getNeighbourTile(dir);
if (tile instanceof IEnergyInterfaceTile) {
return true;
}
}
}
return false;
}
public boolean internalShouldConnectTo(EnumFacing dir) {
ISlottedPart part = getContainer().getPartInSlot(PartSlot.getFaceSlot(dir));
if (part instanceof IMicroblock.IFaceMicroblock) {
if (!((IMicroblock.IFaceMicroblock) part).isFaceHollow()) {
return false;
}
}
if (!OcclusionHelper.occlusionTest(getContainer().getParts(), p -> p == this, boundingBoxes[Functions.getIntDirFromDirection(dir)].toAABB())) {
return false;
}
MultipartFluidPipe multipartFluidPipe = getPartFromWorld(getWorld(), getPos().offset(dir), dir.getOpposite());
return multipartFluidPipe != null;
}
public TileEntity getNeighbourTile(EnumFacing side) {
return side != null ? getWorld().getTileEntity(getPos().offset(side)) : null;
}
public void checkConnectedSides() {
refreshBounding();
connectedSides = new HashMap<>();
for (EnumFacing dir : EnumFacing.values()) {
int d = Functions.getIntDirFromDirection(dir);
if (getWorld() == null) {
return;
}
TileEntity te = getNeighbourTile(dir);
if (shouldConnectTo(dir)) {
connectedSides.put(dir, te.getPos());
}
}
}
@Override
public EnumSet<PartSlot> getSlotMask() {
return EnumSet.of(PartSlot.CENTER);
}
@Override
public IBlockState getExtendedState(IBlockState state) {
IExtendedBlockState extendedBlockState = (IExtendedBlockState) state;
return extendedBlockState.withProperty(DOWN, shouldConnectTo(EnumFacing.DOWN))
.withProperty(UP, shouldConnectTo(EnumFacing.UP)).withProperty(NORTH, shouldConnectTo(EnumFacing.NORTH))
.withProperty(SOUTH, shouldConnectTo(EnumFacing.SOUTH))
.withProperty(WEST, shouldConnectTo(EnumFacing.WEST))
.withProperty(EAST, shouldConnectTo(EnumFacing.EAST));
}
@Override
public BlockStateContainer createBlockState() {
return new ExtendedBlockState(MCMultiPartMod.multipart, new IProperty[]{},
new IUnlistedProperty[]{DOWN, UP, NORTH, SOUTH, WEST, EAST});
}
@Override
public float getHardness(PartMOP hit) {
return 0.5F;
}
public Material getMaterial() {
return Material.CLOTH;
}
@Override
public List<ItemStack> getDrops() {
List<ItemStack> list = new ArrayList<>();
list.add(new ItemStack(TechRebornParts.fluidPipe, 1, 0));
return list;
}
@Override
public ResourceLocation getModelPath() {
return new ResourceLocation("techreborn:fluidpipe");
}
@Override
public boolean canRenderInLayer(BlockRenderLayer layer) {
return layer == BlockRenderLayer.CUTOUT;
}
@Override
public void update() {
}
}

View file

@ -1,4 +1,4 @@
package techreborn.parts;
package techreborn.parts.powerCables;
import mcmultipart.MCMultiPartMod;
import mcmultipart.microblock.IMicroblock;
@ -31,6 +31,7 @@ import reborncore.common.misc.vecmath.Vecs3dCube;
import reborncore.common.util.WorldUtils;
import techreborn.config.ConfigTechReborn;
import techreborn.init.ModSounds;
import techreborn.parts.TechRebornParts;
import techreborn.parts.walia.IPartWaliaProvider;
import techreborn.power.TRPowerNet;
import techreborn.utils.damageSources.ElectrialShockSource;

View file

@ -1,15 +1,15 @@
package techreborn.parts;
package techreborn.parts.powerCables;
import net.minecraft.util.IStringSerializable;
import reborncore.api.power.EnumPowerTier;
import techreborn.parts.types.CopperCable;
import techreborn.parts.types.GlassFiberCable;
import techreborn.parts.types.GoldCable;
import techreborn.parts.types.HVCable;
import techreborn.parts.types.InsulatedCopperCable;
import techreborn.parts.types.InsulatedGoldCable;
import techreborn.parts.types.InsulatedHVCable;
import techreborn.parts.types.TinCable;
import techreborn.parts.powerCables.types.CopperCable;
import techreborn.parts.powerCables.types.GlassFiberCable;
import techreborn.parts.powerCables.types.GoldCable;
import techreborn.parts.powerCables.types.HVCable;
import techreborn.parts.powerCables.types.InsulatedCopperCable;
import techreborn.parts.powerCables.types.InsulatedGoldCable;
import techreborn.parts.powerCables.types.InsulatedHVCable;
import techreborn.parts.powerCables.types.TinCable;
public enum EnumCableType implements IStringSerializable
{

View file

@ -1,4 +1,4 @@
package techreborn.parts;
package techreborn.parts.powerCables;
import net.minecraft.util.IStringSerializable;
import reborncore.api.power.EnumPowerTier;

View file

@ -1,4 +1,4 @@
package techreborn.parts;
package techreborn.parts.powerCables;
/**
* Created by modmuss50 on 05/03/2016.

View file

@ -1,4 +1,4 @@
package techreborn.parts;
package techreborn.parts.powerCables;
import java.util.List;
@ -21,6 +21,7 @@ import net.minecraftforge.fml.relauncher.SideOnly;
import reborncore.RebornCore;
import techreborn.client.TechRebornCreativeTab;
import techreborn.lib.ModInfo;
import techreborn.parts.TechRebornParts;
/**
* Created by modmuss50 on 27/02/2016.

View file

@ -1,4 +1,4 @@
package techreborn.parts;
package techreborn.parts.powerCables;
import java.security.InvalidParameterException;
import java.util.List;
@ -12,6 +12,7 @@ import reborncore.RebornCore;
import techreborn.client.TechRebornCreativeTab;
import techreborn.items.ItemTextureBase;
import techreborn.lib.ModInfo;
import techreborn.parts.StandalonePartCompact;
/**
* Created by modmuss50 on 06/03/2016.

View file

@ -1,7 +1,7 @@
package techreborn.parts.types;
package techreborn.parts.powerCables.types;
import techreborn.parts.CableMultipart;
import techreborn.parts.EnumCableType;
import techreborn.parts.powerCables.CableMultipart;
import techreborn.parts.powerCables.EnumCableType;
/**
* Created by modmuss50 on 05/03/2016.

View file

@ -1,7 +1,7 @@
package techreborn.parts.types;
package techreborn.parts.powerCables.types;
import techreborn.parts.CableMultipart;
import techreborn.parts.EnumCableType;
import techreborn.parts.powerCables.CableMultipart;
import techreborn.parts.powerCables.EnumCableType;
/**
* Created by modmuss50 on 05/03/2016.

View file

@ -1,7 +1,7 @@
package techreborn.parts.types;
package techreborn.parts.powerCables.types;
import techreborn.parts.CableMultipart;
import techreborn.parts.EnumCableType;
import techreborn.parts.powerCables.CableMultipart;
import techreborn.parts.powerCables.EnumCableType;
/**
* Created by modmuss50 on 05/03/2016.

View file

@ -1,7 +1,7 @@
package techreborn.parts.types;
package techreborn.parts.powerCables.types;
import techreborn.parts.CableMultipart;
import techreborn.parts.EnumCableType;
import techreborn.parts.powerCables.CableMultipart;
import techreborn.parts.powerCables.EnumCableType;
/**
* Created by modmuss50 on 05/03/2016.

View file

@ -1,7 +1,7 @@
package techreborn.parts.types;
package techreborn.parts.powerCables.types;
import techreborn.parts.CableMultipart;
import techreborn.parts.EnumCableType;
import techreborn.parts.powerCables.CableMultipart;
import techreborn.parts.powerCables.EnumCableType;
/**
* Created by modmuss50 on 05/03/2016.

View file

@ -1,7 +1,7 @@
package techreborn.parts.types;
package techreborn.parts.powerCables.types;
import techreborn.parts.CableMultipart;
import techreborn.parts.EnumCableType;
import techreborn.parts.powerCables.CableMultipart;
import techreborn.parts.powerCables.EnumCableType;
/**
* Created by modmuss50 on 05/03/2016.

View file

@ -1,7 +1,7 @@
package techreborn.parts.types;
package techreborn.parts.powerCables.types;
import techreborn.parts.CableMultipart;
import techreborn.parts.EnumCableType;
import techreborn.parts.powerCables.CableMultipart;
import techreborn.parts.powerCables.EnumCableType;
/**
* Created by modmuss50 on 05/03/2016.

View file

@ -1,7 +1,7 @@
package techreborn.parts.types;
package techreborn.parts.powerCables.types;
import techreborn.parts.CableMultipart;
import techreborn.parts.EnumCableType;
import techreborn.parts.powerCables.CableMultipart;
import techreborn.parts.powerCables.EnumCableType;
/**
* Created by modmuss50 on 05/03/2016.

View file

@ -18,7 +18,7 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import techreborn.parts.CableMultipart;
import techreborn.parts.powerCables.CableMultipart;
/**
* Created by modmuss50 on 07/03/2016.