Its all broke, mcmultipart support
This commit is contained in:
parent
f255137753
commit
471a945de6
18 changed files with 83 additions and 73 deletions
|
@ -1,5 +1,6 @@
|
|||
package techreborn.client.render.parts;
|
||||
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
|
||||
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
|
||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||
|
@ -13,7 +14,7 @@ public class ClientPartLoader implements ICompatModule {
|
|||
|
||||
@Override
|
||||
public void preInit(FMLPreInitializationEvent event) {
|
||||
// MinecraftForge.EVENT_BUS.register(new ClientPartModelBakery());
|
||||
MinecraftForge.EVENT_BUS.register(new ClientPartModelBakery());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
package techreborn.client.render.parts;
|
||||
|
||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.client.event.ModelBakeEvent;
|
||||
import net.minecraftforge.client.event.TextureStitchEvent;
|
||||
import net.minecraftforge.fml.common.eventhandler.EventPriority;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import techreborn.parts.EnumCableType;
|
||||
|
||||
/**
|
||||
* Created by modmuss50 on 04/03/2016.
|
||||
*/
|
||||
public class ClientPartModelBakery {
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@SubscribeEvent(priority = EventPriority.LOWEST)
|
||||
public void onModelBake(ModelBakeEvent event){
|
||||
for(EnumCableType type : EnumCableType.values()){
|
||||
event.getModelRegistry().putObject(new ModelResourceLocation("techreborn:cable#type=" + type.getName().toLowerCase()), new RenderCablePart(type));
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void textureStichEvent(TextureStitchEvent event){
|
||||
for(EnumCableType type : EnumCableType.values()){
|
||||
event.map.registerSprite(new ResourceLocation(type.textureName));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,107 @@
|
|||
package techreborn.client.render.parts;
|
||||
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.block.model.BakedQuad;
|
||||
import net.minecraft.client.renderer.block.model.BlockFaceUV;
|
||||
import net.minecraft.client.renderer.block.model.BlockPartFace;
|
||||
import net.minecraft.client.renderer.block.model.FaceBakery;
|
||||
import net.minecraft.client.renderer.block.model.IBakedModel;
|
||||
import net.minecraft.client.renderer.block.model.ItemCameraTransforms;
|
||||
import net.minecraft.client.renderer.block.model.ItemOverrideList;
|
||||
import net.minecraft.client.renderer.block.model.ModelRotation;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraftforge.common.property.IExtendedBlockState;
|
||||
import org.lwjgl.util.vector.Vector3f;
|
||||
import reborncore.common.misc.vecmath.Vecs3dCube;
|
||||
import techreborn.parts.CableMultipart;
|
||||
import techreborn.parts.EnumCableType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class RenderCablePart implements IBakedModel {
|
||||
|
||||
private FaceBakery faceBakery = new FaceBakery();
|
||||
|
||||
private TextureAtlasSprite texture;
|
||||
|
||||
EnumCableType type;
|
||||
|
||||
public RenderCablePart(EnumCableType type) {
|
||||
texture = Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(type.textureName);
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public void addCubeToList(Vecs3dCube cube, ArrayList<BakedQuad> list, BlockPartFace face, ModelRotation modelRotation, TextureAtlasSprite cubeTexture) {
|
||||
list.add(faceBakery.makeBakedQuad(new Vector3f((float) cube.getMinX(), (float) cube.getMinY(), (float) cube.getMinZ()), new Vector3f((float) cube.getMaxX(), (float) cube.getMinY(), (float) cube.getMaxZ()), face, cubeTexture, EnumFacing.DOWN, modelRotation, null, true, true));//down
|
||||
list.add(faceBakery.makeBakedQuad(new Vector3f((float) cube.getMinX(), (float) cube.getMaxY(), (float) cube.getMinZ()), new Vector3f((float) cube.getMaxX(), (float) cube.getMaxY(), (float) cube.getMaxZ()), face, cubeTexture, EnumFacing.UP, modelRotation, null, true, true));//up
|
||||
list.add(faceBakery.makeBakedQuad(new Vector3f((float) cube.getMinX(), (float) cube.getMinY(), (float) cube.getMinZ()), new Vector3f((float) cube.getMaxX(), (float) cube.getMaxY(), (float) cube.getMaxZ()), face, cubeTexture, EnumFacing.NORTH, modelRotation, null, true, true));//north
|
||||
list.add(faceBakery.makeBakedQuad(new Vector3f((float) cube.getMinX(), (float) cube.getMinY(), (float) cube.getMaxZ()), new Vector3f((float) cube.getMaxX(), (float) cube.getMaxY(), (float) cube.getMaxZ()), face, cubeTexture, EnumFacing.SOUTH, modelRotation, null, true, true));//south
|
||||
list.add(faceBakery.makeBakedQuad(new Vector3f((float) cube.getMaxX(), (float) cube.getMinY(), (float) cube.getMinZ()), new Vector3f((float) cube.getMaxX(), (float) cube.getMaxY(), (float) cube.getMaxZ()), face, cubeTexture, EnumFacing.EAST, modelRotation, null, true, true));//east
|
||||
list.add(faceBakery.makeBakedQuad(new Vector3f((float) cube.getMinX(), (float) cube.getMinY(), (float) cube.getMinZ()), new Vector3f((float) cube.getMinX(), (float) cube.getMaxY(), (float) cube.getMaxZ()), face, cubeTexture, EnumFacing.WEST, modelRotation, null, true, true));//west
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BakedQuad> getQuads(IBlockState blockState, EnumFacing side, long rand) {
|
||||
ArrayList<BakedQuad> list = new ArrayList<BakedQuad>();
|
||||
BlockFaceUV uv = new BlockFaceUV(new float[]{0.0F, 0.0F, 16.0F, 16.0F}, 0);
|
||||
BlockPartFace face = new BlockPartFace(null, 0, "", uv);
|
||||
double thickness = type.cableThickness;
|
||||
double lastThickness = 16 - thickness;
|
||||
IExtendedBlockState state = (IExtendedBlockState) blockState;
|
||||
addCubeToList(new Vecs3dCube(thickness, thickness, thickness, lastThickness, lastThickness, lastThickness), list, face, ModelRotation.X0_Y0, texture);
|
||||
if (state != null) {
|
||||
if (state.getValue(CableMultipart.UP)) {
|
||||
addCubeToList(new Vecs3dCube(thickness, lastThickness, thickness, lastThickness, 16.0, lastThickness), list, face, ModelRotation.X0_Y0, texture);
|
||||
}
|
||||
if (state.getValue(CableMultipart.DOWN)) {
|
||||
addCubeToList(new Vecs3dCube(thickness, 0.0, thickness, lastThickness, thickness, lastThickness), list, face, ModelRotation.X0_Y0, texture);
|
||||
}
|
||||
if (state.getValue(CableMultipart.NORTH)) {
|
||||
addCubeToList(new Vecs3dCube(thickness, thickness, 0.0, lastThickness, lastThickness, lastThickness), list, face, ModelRotation.X0_Y0, texture);
|
||||
}
|
||||
if (state.getValue(CableMultipart.SOUTH)) {
|
||||
addCubeToList(new Vecs3dCube(thickness, thickness, thickness, lastThickness, lastThickness, 16.0), list, face, ModelRotation.X0_Y0, texture);
|
||||
}
|
||||
if (state.getValue(CableMultipart.EAST)) {
|
||||
addCubeToList(new Vecs3dCube(thickness, thickness, thickness, 16.0, lastThickness, lastThickness), list, face, ModelRotation.X0_Y0, texture);
|
||||
}
|
||||
if (state.getValue(CableMultipart.WEST)) {
|
||||
addCubeToList(new Vecs3dCube(0.0, thickness, thickness, lastThickness, lastThickness, lastThickness), list, face, ModelRotation.X0_Y0, texture);
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAmbientOcclusion() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGui3d() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBuiltInRenderer() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextureAtlasSprite getParticleTexture() {
|
||||
return texture;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemCameraTransforms getItemCameraTransforms() {
|
||||
return ItemCameraTransforms.DEFAULT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemOverrideList getOverrides() {
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -6,6 +6,7 @@ import net.minecraftforge.fml.relauncher.Side;
|
|||
import techreborn.client.render.parts.ClientPartLoader;
|
||||
import techreborn.config.ConfigTechReborn;
|
||||
import techreborn.parts.StandalonePartCompact;
|
||||
import techreborn.parts.TechRebornParts;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
|
@ -37,7 +38,7 @@ public class CompatManager {
|
|||
// registerCompact(RecipesBiomesOPlenty.class, "BiomesOPlenty");
|
||||
// registerCompact(RecipesBuildcraft.class, "BuildCraft|Builders");
|
||||
// registerCompact(RecipesThaumcraft.class, "Thaumcraft");
|
||||
// registerCompact(TechRebornParts.class, "mcmultipart");
|
||||
registerCompact(TechRebornParts.class, "mcmultipart");
|
||||
registerCompact(ClientPartLoader.class, "mcmultipart", "@client");
|
||||
registerCompact(StandalonePartCompact.class, "!mcmultipart");
|
||||
//registerCompact(WailaMcMultiPartCompact.class, "mcmultipart", "Waila");
|
||||
|
|
436
src/main/java/techreborn/parts/CableMultipart.java
Normal file
436
src/main/java/techreborn/parts/CableMultipart.java
Normal file
|
@ -0,0 +1,436 @@
|
|||
package techreborn.parts;
|
||||
|
||||
import mcmultipart.MCMultiPartMod;
|
||||
import mcmultipart.microblock.IMicroblock;
|
||||
import mcmultipart.multipart.ICollidableMultipart;
|
||||
import mcmultipart.multipart.IMultipartContainer;
|
||||
import mcmultipart.multipart.INormallyOccludingPart;
|
||||
import mcmultipart.multipart.ISlottedPart;
|
||||
import mcmultipart.multipart.Multipart;
|
||||
import mcmultipart.multipart.MultipartHelper;
|
||||
import mcmultipart.multipart.OcclusionHelper;
|
||||
import mcmultipart.multipart.PartSlot;
|
||||
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.properties.PropertyEnum;
|
||||
import net.minecraft.block.state.BlockStateContainer;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.BlockRenderLayer;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumParticleTypes;
|
||||
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.config.ConfigTechReborn;
|
||||
import techreborn.power.TRPowerNet;
|
||||
import techreborn.utils.damageSources.ElectrialShockSource;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by modmuss50 on 02/03/2016.
|
||||
*/
|
||||
public abstract class CableMultipart extends Multipart implements INormallyOccludingPart, ISlottedPart, ITickable, ICableType, ICollidableMultipart {
|
||||
|
||||
public Vecs3dCube[] boundingBoxes = new Vecs3dCube[14];
|
||||
public float center = 0.6F;
|
||||
public float offset = 0.10F;
|
||||
public Map<EnumFacing, BlockPos> connectedSides;
|
||||
public int ticks = 0;
|
||||
public ItemStack stack;
|
||||
|
||||
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 static final IProperty<EnumCableType> TYPE = PropertyEnum.create("type", EnumCableType.class);
|
||||
|
||||
public CableMultipart() {
|
||||
connectedSides = new HashMap<>();
|
||||
refreshBounding();
|
||||
}
|
||||
|
||||
public void refreshBounding() {
|
||||
float centerFirst = center - offset;
|
||||
double w = (getCableType().cableThickness / 16) - 0.5;
|
||||
boundingBoxes[6] = new Vecs3dCube(centerFirst - w - 0.03, centerFirst
|
||||
- w - 0.08, centerFirst - w - 0.03, centerFirst + w + 0.08,
|
||||
centerFirst + w + 0.04, centerFirst + w + 0.08);
|
||||
|
||||
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) {
|
||||
super.addSelectionBoxes(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 onRemoved() {
|
||||
super.onRemoved();
|
||||
removeFromNetwork();
|
||||
for(EnumFacing dir : EnumFacing.VALUES){
|
||||
CableMultipart multipart = getPartFromWorld(getWorld(), getPos().offset(dir), dir);
|
||||
if(multipart != null){
|
||||
multipart.nearByChange();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUnloaded() {
|
||||
super.onUnloaded();
|
||||
removeFromNetwork();
|
||||
}
|
||||
|
||||
@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();
|
||||
findAndJoinNetwork(getWorld(), getPos());
|
||||
}
|
||||
|
||||
public void nearByChange() {
|
||||
checkConnectedSides();
|
||||
for (EnumFacing direction : EnumFacing.VALUES) {
|
||||
BlockPos blockPos = getPos().offset(direction);
|
||||
WorldUtils.updateBlock(getWorld(), blockPos);
|
||||
CableMultipart part = getPartFromWorld(getWorld(), blockPos, direction);
|
||||
if (part != null) {
|
||||
part.checkConnectedSides();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public CableMultipart 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 CableMultipart) {
|
||||
return (CableMultipart) part;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAdded() {
|
||||
nearByChange();
|
||||
}
|
||||
|
||||
public boolean shouldConnectTo(EnumFacing dir) {
|
||||
if (dir != null) {
|
||||
if (internalShouldConnectTo(dir)) {
|
||||
CableMultipart cableMultipart = getPartFromWorld(getWorld(), getPos().offset(dir), dir);
|
||||
if (cableMultipart != null && cableMultipart.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;
|
||||
}
|
||||
}
|
||||
|
||||
//TODO 1.9 boken
|
||||
// if (!OcclusionHelper.occlusionTest(this, boundingBoxes[Functions.getIntDirFromDirection(dir)].toAABB())) {
|
||||
// return false;
|
||||
// }
|
||||
|
||||
CableMultipart cableMultipart = getPartFromWorld(getWorld(), getPos().offset(dir), dir.getOpposite());
|
||||
|
||||
if (cableMultipart != null && cableMultipart.getCableType() == getCableType()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
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 void update() {
|
||||
if (getWorld() != null) {
|
||||
if (getWorld().getTotalWorldTime() % 80 == 0) {
|
||||
checkConnectedSides();
|
||||
}
|
||||
}
|
||||
if (network == null) {
|
||||
this.findAndJoinNetwork(getWorld(), getPos());
|
||||
}
|
||||
}
|
||||
|
||||
@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))
|
||||
.withProperty(TYPE, getCableType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockStateContainer createBlockState() {
|
||||
return new ExtendedBlockState(MCMultiPartMod.multipart,
|
||||
new IProperty[]{
|
||||
TYPE
|
||||
},
|
||||
new IUnlistedProperty[]{
|
||||
DOWN,
|
||||
UP,
|
||||
NORTH,
|
||||
SOUTH,
|
||||
WEST,
|
||||
EAST});
|
||||
}
|
||||
|
||||
|
||||
// @Override
|
||||
// public String getModelPath() {
|
||||
// return "techreborn:cable";
|
||||
// }
|
||||
|
||||
@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.cables, 1, getCableType().ordinal()));
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onEntityCollided(Entity entity) {
|
||||
if (getCableType().canKill && entity instanceof EntityLivingBase) {
|
||||
if(ConfigTechReborn.UninsulatedElectocutionDamage){
|
||||
entity.attackEntityFrom(new ElectrialShockSource(), 1F);
|
||||
}
|
||||
if(ConfigTechReborn.UninsulatedElectocutionSound){
|
||||
//TODO 1.9 nope
|
||||
// getWorld().playSoundAtEntity(entity, "techreborn:cable_shock", 0.6F, 1F);
|
||||
}
|
||||
if(ConfigTechReborn.UninsulatedElectocutionParticle){
|
||||
getWorld().spawnParticle(EnumParticleTypes.CRIT, entity.posX, entity.posY, entity.posZ, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEntityStanding(Entity entity) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getPickBlock(EntityPlayer player, PartMOP hit) {
|
||||
return new ItemStack(TechRebornParts.cables, 1, getCableType().ordinal());
|
||||
}
|
||||
|
||||
private TRPowerNet network;
|
||||
|
||||
public final void findAndJoinNetwork(World world, BlockPos pos) {
|
||||
for (EnumFacing dir : EnumFacing.VALUES) {
|
||||
CableMultipart cableMultipart = getPartFromWorld(getWorld(), getPos().offset(dir), dir);
|
||||
if (cableMultipart != null && cableMultipart.getCableType() == getCableType()) {
|
||||
TRPowerNet net = cableMultipart.getNetwork();
|
||||
if (net != null) {
|
||||
network = net;
|
||||
network.addElement(this);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(network == null){
|
||||
network = new TRPowerNet(getCableType());
|
||||
network.addElement(this);
|
||||
}
|
||||
network.endpoints.clear();
|
||||
for (EnumFacing dir : EnumFacing.VALUES) {
|
||||
TileEntity te = getNeighbourTile(dir);
|
||||
if (te != null && te instanceof IEnergyInterfaceTile) {
|
||||
network.addConnection((IEnergyInterfaceTile) te, dir.getOpposite());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public final TRPowerNet getNetwork() {
|
||||
return network;
|
||||
}
|
||||
|
||||
public final void setNetwork(TRPowerNet n) {
|
||||
if (n == null) {
|
||||
} else {
|
||||
network = n;
|
||||
network.addElement(this);
|
||||
}
|
||||
}
|
||||
|
||||
public final void removeFromNetwork() {
|
||||
if (network == null) {
|
||||
} else
|
||||
network.removeElement(this);
|
||||
}
|
||||
|
||||
public final void rebuildNetwork() {
|
||||
this.removeFromNetwork();
|
||||
this.resetNetwork();
|
||||
this.findAndJoinNetwork(getWorld(), getPos());
|
||||
}
|
||||
|
||||
public final void resetNetwork() {
|
||||
if(network != null){
|
||||
network.removeElement(this);
|
||||
}
|
||||
|
||||
network = null;
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public void addInfo(List<String> info) {
|
||||
// info.add(EnumChatFormatting.GREEN + "EU Transfer: " + EnumChatFormatting.LIGHT_PURPLE + getCableType().transferRate);
|
||||
// if (getCableType().canKill) {
|
||||
// info.add(EnumChatFormatting.RED + "Damages entity's!");
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
@Override
|
||||
public ResourceLocation getModelPath() {
|
||||
return new ResourceLocation("techreborn:cable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canRenderInLayer(BlockRenderLayer layer) {
|
||||
return layer == BlockRenderLayer.CUTOUT;
|
||||
}
|
||||
}
|
|
@ -2,32 +2,40 @@ package techreborn.parts;
|
|||
|
||||
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;
|
||||
|
||||
public enum EnumCableType implements IStringSerializable {
|
||||
COPPER("copper", "techreborn:blocks/cables/copper_cable", 128, 12.0, true, EnumPowerTier.LOW),
|
||||
TIN("tin", "techreborn:blocks/cables/tin_cable", 32, 12.0, true, EnumPowerTier.MEDIUM),
|
||||
GOLD("gold", "techreborn:blocks/cables/gold_cable", 512, 12.0, true, EnumPowerTier.MEDIUM),
|
||||
HV("hv", "techreborn:blocks/cables/hv_cable", 2048, 12.0, true, EnumPowerTier.HIGH),
|
||||
GLASSFIBER("glassfiber", "techreborn:blocks/cables/glass_fiber_cable", 8192, 12.0, false, EnumPowerTier.HIGH),
|
||||
ICOPPER("insulatedcopper", "techreborn:blocks/cables/copper_insulated_cable", 128, 10.0, false, EnumPowerTier.LOW),
|
||||
IGOLD("insulatedgold", "techreborn:blocks/cables/gold_insulated_cable", 512, 10.0, false, EnumPowerTier.HIGH),
|
||||
IHV("insulatedhv", "techreborn:blocks/cables/hv_insulated_cable", 2048, 10.0, false, EnumPowerTier.HIGH);
|
||||
COPPER("copper", "techreborn:blocks/cables/copper_cable", 128, 12.0, true, EnumPowerTier.LOW, CopperCable.class),
|
||||
TIN("tin", "techreborn:blocks/cables/tin_cable", 32, 12.0, true, EnumPowerTier.MEDIUM, TinCable.class),
|
||||
GOLD("gold", "techreborn:blocks/cables/gold_cable", 512, 12.0, true, EnumPowerTier.MEDIUM, GoldCable.class),
|
||||
HV("hv", "techreborn:blocks/cables/hv_cable", 2048, 12.0, true, EnumPowerTier.HIGH, HVCable.class),
|
||||
GLASSFIBER("glassfiber", "techreborn:blocks/cables/glass_fiber_cable", 8192, 12.0, false, EnumPowerTier.HIGH, GlassFiberCable.class),
|
||||
ICOPPER("insulatedcopper", "techreborn:blocks/cables/copper_insulated_cable", 128, 10.0, false, EnumPowerTier.LOW, InsulatedCopperCable.class),
|
||||
IGOLD("insulatedgold", "techreborn:blocks/cables/gold_insulated_cable", 512, 10.0, false, EnumPowerTier.HIGH, InsulatedGoldCable.class),
|
||||
IHV("insulatedhv", "techreborn:blocks/cables/hv_insulated_cable", 2048, 10.0, false, EnumPowerTier.HIGH, InsulatedHVCable.class);
|
||||
|
||||
private String friendlyName;
|
||||
public String textureName = "minecraft:blocks/iron_block";
|
||||
public int transferRate = 128;
|
||||
public double cableThickness = 3.0;
|
||||
public boolean canKill = false;
|
||||
//public Class<? extends CableMultipart> cableClass;
|
||||
public Class<? extends CableMultipart> cableClass;
|
||||
public EnumPowerTier tier;
|
||||
|
||||
EnumCableType(String friendlyName, String textureName, int transferRate, double cableThickness, boolean canKill, EnumPowerTier tier) {
|
||||
EnumCableType(String friendlyName, String textureName, int transferRate, double cableThickness, boolean canKill, EnumPowerTier tier, Class<? extends CableMultipart> cableClass) {
|
||||
this.friendlyName = friendlyName;
|
||||
this.textureName = textureName;
|
||||
this.transferRate = transferRate;
|
||||
this.cableThickness = cableThickness / 2;
|
||||
this.canKill = canKill;
|
||||
// this.cableClass = cableClass;
|
||||
this.cableClass = cableClass;
|
||||
this.tier = tier;
|
||||
}
|
||||
|
||||
|
|
92
src/main/java/techreborn/parts/ItemCables.java
Normal file
92
src/main/java/techreborn/parts/ItemCables.java
Normal file
|
@ -0,0 +1,92 @@
|
|||
package techreborn.parts;
|
||||
|
||||
import mcmultipart.item.ItemMultiPart;
|
||||
import mcmultipart.multipart.IMultipart;
|
||||
import me.modmuss50.jsonDestroyer.api.ITexturedItem;
|
||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
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.util.text.TextFormatting;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import reborncore.RebornCore;
|
||||
import techreborn.client.TechRebornCreativeTab;
|
||||
import techreborn.lib.ModInfo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by modmuss50 on 27/02/2016.
|
||||
*/
|
||||
public class ItemCables extends ItemMultiPart implements ITexturedItem {
|
||||
|
||||
public ItemCables() {
|
||||
setCreativeTab(TechRebornCreativeTab.instance);
|
||||
setHasSubtypes(true);
|
||||
setUnlocalizedName("techreborn.cable");
|
||||
setNoRepair();
|
||||
RebornCore.jsonDestroyer.registerObject(this);
|
||||
ItemStandaloneCables.mcPartCable = this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMultipart createPart(World world, BlockPos pos, EnumFacing side, Vec3d hit, ItemStack stack, EntityPlayer player) {
|
||||
try {
|
||||
return TechRebornParts.multipartHashMap.get(EnumCableType.values()[stack.getItemDamage()]).newInstance();
|
||||
} catch (InstantiationException | IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
// gets Unlocalized Name depending on meta data
|
||||
public String getUnlocalizedName(ItemStack itemStack) {
|
||||
int meta = itemStack.getItemDamage();
|
||||
if (meta < 0 || meta >= EnumCableType.values().length) {
|
||||
meta = 0;
|
||||
}
|
||||
|
||||
return super.getUnlocalizedName() + "." + EnumCableType.values()[meta];
|
||||
}
|
||||
|
||||
// Adds Dusts SubItems To Creative Tab
|
||||
public void getSubItems(Item item, CreativeTabs creativeTabs, List list) {
|
||||
for (int meta = 0; meta < EnumCableType.values().length; ++meta) {
|
||||
list.add(new ItemStack(item, 1, meta));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTextureName(int damage) {
|
||||
return ModInfo.MOD_ID + ":items/cables/" + EnumCableType.values()[damage];
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxMeta() {
|
||||
return EnumCableType.values().length;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public ModelResourceLocation getModel(ItemStack stack, EntityPlayer player, int useRemaining) {
|
||||
return new ModelResourceLocation(ModInfo.MOD_ID + ":" + getUnlocalizedName(stack).substring(5), "inventory");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInformation(ItemStack stack, EntityPlayer playerIn, List<String> tooltip, boolean advanced) {
|
||||
EnumCableType type = EnumCableType.values()[stack.getItemDamage()];
|
||||
tooltip.add(TextFormatting.GREEN + "EU Transfer: " + TextFormatting.LIGHT_PURPLE + type.transferRate);
|
||||
if (type.canKill) {
|
||||
tooltip.add(TextFormatting.RED + "Damages entity's!");
|
||||
}
|
||||
tooltip.add(TextFormatting.GREEN + "Tier: " + TextFormatting.LIGHT_PURPLE + type.tier);
|
||||
}
|
||||
}
|
50
src/main/java/techreborn/parts/TechRebornParts.java
Normal file
50
src/main/java/techreborn/parts/TechRebornParts.java
Normal file
|
@ -0,0 +1,50 @@
|
|||
package techreborn.parts;
|
||||
|
||||
import mcmultipart.multipart.MultipartRegistry;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
|
||||
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
|
||||
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 javax.annotation.Nullable;
|
||||
import java.util.HashMap;
|
||||
|
||||
|
||||
/**
|
||||
* Created by modmuss50 on 02/03/2016.
|
||||
*/
|
||||
public class TechRebornParts implements ICompatModule {
|
||||
|
||||
@Nullable
|
||||
public static Item cables;
|
||||
|
||||
public static HashMap<EnumCableType, Class<? extends CableMultipart>> multipartHashMap = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public void preInit(FMLPreInitializationEvent event) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(FMLInitializationEvent event) {
|
||||
for (EnumCableType cableType : EnumCableType.values()) {
|
||||
multipartHashMap.put(cableType, cableType.cableClass);
|
||||
MultipartRegistry.registerPart(cableType.cableClass, "techreborn:cable." + cableType.name());
|
||||
}
|
||||
cables = new ItemCables();
|
||||
GameRegistry.registerItem(cables, "cables");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postInit(FMLPostInitializationEvent event) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serverStarting(FMLServerStartingEvent event) {
|
||||
|
||||
}
|
||||
}
|
14
src/main/java/techreborn/parts/types/CopperCable.java
Normal file
14
src/main/java/techreborn/parts/types/CopperCable.java
Normal file
|
@ -0,0 +1,14 @@
|
|||
package techreborn.parts.types;
|
||||
|
||||
import techreborn.parts.CableMultipart;
|
||||
import techreborn.parts.EnumCableType;
|
||||
|
||||
/**
|
||||
* Created by modmuss50 on 05/03/2016.
|
||||
*/
|
||||
public class CopperCable extends CableMultipart {
|
||||
@Override
|
||||
public EnumCableType getCableType() {
|
||||
return EnumCableType.COPPER;
|
||||
}
|
||||
}
|
14
src/main/java/techreborn/parts/types/GlassFiberCable.java
Normal file
14
src/main/java/techreborn/parts/types/GlassFiberCable.java
Normal file
|
@ -0,0 +1,14 @@
|
|||
package techreborn.parts.types;
|
||||
|
||||
import techreborn.parts.CableMultipart;
|
||||
import techreborn.parts.EnumCableType;
|
||||
|
||||
/**
|
||||
* Created by modmuss50 on 05/03/2016.
|
||||
*/
|
||||
public class GlassFiberCable extends CableMultipart {
|
||||
@Override
|
||||
public EnumCableType getCableType() {
|
||||
return EnumCableType.GLASSFIBER;
|
||||
}
|
||||
}
|
14
src/main/java/techreborn/parts/types/GoldCable.java
Normal file
14
src/main/java/techreborn/parts/types/GoldCable.java
Normal file
|
@ -0,0 +1,14 @@
|
|||
package techreborn.parts.types;
|
||||
|
||||
import techreborn.parts.CableMultipart;
|
||||
import techreborn.parts.EnumCableType;
|
||||
|
||||
/**
|
||||
* Created by modmuss50 on 05/03/2016.
|
||||
*/
|
||||
public class GoldCable extends CableMultipart {
|
||||
@Override
|
||||
public EnumCableType getCableType() {
|
||||
return EnumCableType.GOLD;
|
||||
}
|
||||
}
|
14
src/main/java/techreborn/parts/types/HVCable.java
Normal file
14
src/main/java/techreborn/parts/types/HVCable.java
Normal file
|
@ -0,0 +1,14 @@
|
|||
package techreborn.parts.types;
|
||||
|
||||
import techreborn.parts.CableMultipart;
|
||||
import techreborn.parts.EnumCableType;
|
||||
|
||||
/**
|
||||
* Created by modmuss50 on 05/03/2016.
|
||||
*/
|
||||
public class HVCable extends CableMultipart {
|
||||
@Override
|
||||
public EnumCableType getCableType() {
|
||||
return EnumCableType.HV;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package techreborn.parts.types;
|
||||
|
||||
import techreborn.parts.CableMultipart;
|
||||
import techreborn.parts.EnumCableType;
|
||||
|
||||
/**
|
||||
* Created by modmuss50 on 05/03/2016.
|
||||
*/
|
||||
public class InsulatedCopperCable extends CableMultipart {
|
||||
@Override
|
||||
public EnumCableType getCableType() {
|
||||
return EnumCableType.ICOPPER;
|
||||
}
|
||||
}
|
14
src/main/java/techreborn/parts/types/InsulatedGoldCable.java
Normal file
14
src/main/java/techreborn/parts/types/InsulatedGoldCable.java
Normal file
|
@ -0,0 +1,14 @@
|
|||
package techreborn.parts.types;
|
||||
|
||||
import techreborn.parts.CableMultipart;
|
||||
import techreborn.parts.EnumCableType;
|
||||
|
||||
/**
|
||||
* Created by modmuss50 on 05/03/2016.
|
||||
*/
|
||||
public class InsulatedGoldCable extends CableMultipart {
|
||||
@Override
|
||||
public EnumCableType getCableType() {
|
||||
return EnumCableType.IGOLD;
|
||||
}
|
||||
}
|
14
src/main/java/techreborn/parts/types/InsulatedHVCable.java
Normal file
14
src/main/java/techreborn/parts/types/InsulatedHVCable.java
Normal file
|
@ -0,0 +1,14 @@
|
|||
package techreborn.parts.types;
|
||||
|
||||
import techreborn.parts.CableMultipart;
|
||||
import techreborn.parts.EnumCableType;
|
||||
|
||||
/**
|
||||
* Created by modmuss50 on 05/03/2016.
|
||||
*/
|
||||
public class InsulatedHVCable extends CableMultipart {
|
||||
@Override
|
||||
public EnumCableType getCableType() {
|
||||
return EnumCableType.IHV;
|
||||
}
|
||||
}
|
14
src/main/java/techreborn/parts/types/TinCable.java
Normal file
14
src/main/java/techreborn/parts/types/TinCable.java
Normal file
|
@ -0,0 +1,14 @@
|
|||
package techreborn.parts.types;
|
||||
|
||||
import techreborn.parts.CableMultipart;
|
||||
import techreborn.parts.EnumCableType;
|
||||
|
||||
/**
|
||||
* Created by modmuss50 on 05/03/2016.
|
||||
*/
|
||||
public class TinCable extends CableMultipart {
|
||||
@Override
|
||||
public EnumCableType getCableType() {
|
||||
return EnumCableType.COPPER;
|
||||
}
|
||||
}
|
236
src/main/java/techreborn/power/TRPowerNet.java
Normal file
236
src/main/java/techreborn/power/TRPowerNet.java
Normal file
|
@ -0,0 +1,236 @@
|
|||
package techreborn.power;
|
||||
|
||||
import net.minecraft.entity.item.EntityTNTPrimed;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import reborncore.api.power.IEnergyInterfaceTile;
|
||||
import techreborn.parts.CableMultipart;
|
||||
import techreborn.parts.EnumCableType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class TRPowerNet {
|
||||
int tick = 0;
|
||||
private ArrayList<CableMultipart> cables = new ArrayList();
|
||||
public ArrayList<EnergyHandler> endpoints = new ArrayList();
|
||||
private int energy = 0;
|
||||
EnumCableType cableType;
|
||||
|
||||
public TRPowerNet(EnumCableType cableType) {
|
||||
this.cableType = cableType;
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
}
|
||||
|
||||
public int getIOLimit() {
|
||||
return cableType.transferRate;
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void tick(PowerTickEvent evt) {
|
||||
if (tick < 20) {
|
||||
tick++;
|
||||
return;
|
||||
}
|
||||
if (tick % 80 == 0) {
|
||||
List<CableMultipart> oldCables = new ArrayList<>();
|
||||
for (CableMultipart cableMultipart : cables) {
|
||||
if (cableMultipart.getWorld() == null || cableMultipart.getPos() == null) {
|
||||
oldCables.add(cableMultipart);
|
||||
}
|
||||
CableMultipart mp = cableMultipart.getPartFromWorld(cableMultipart.getWorld(), cableMultipart.getPos(), null);
|
||||
if (mp == null) {
|
||||
oldCables.add(cableMultipart);
|
||||
}
|
||||
}
|
||||
cables.removeAll(oldCables);
|
||||
}
|
||||
if (!cables.isEmpty()) {
|
||||
ArrayList<EnergyHandler> collectibles = new ArrayList();
|
||||
ArrayList<EnergyHandler> insertibles = new ArrayList();
|
||||
for (int i = 0; i < endpoints.size(); i++) {
|
||||
EnergyHandler ei = endpoints.get(i);
|
||||
if (ei.isCollectible()) {
|
||||
collectibles.add(ei);
|
||||
}
|
||||
if (ei.isInsertible()) {
|
||||
insertibles.add(ei);
|
||||
}
|
||||
}
|
||||
|
||||
for (EnergyHandler handler : collectibles) {
|
||||
energy += handler.collectEnergy(cableType.transferRate);
|
||||
}
|
||||
|
||||
for (EnergyHandler handler : insertibles) {
|
||||
energy -= handler.addEnergy(Math.min(energy, cableType.transferRate));
|
||||
}
|
||||
} else {
|
||||
MinecraftForge.EVENT_BUS.unregister(this);
|
||||
}
|
||||
tick++;
|
||||
}
|
||||
|
||||
public void addElement(CableMultipart te) {
|
||||
if (!cables.contains(te)) {
|
||||
cables.add(te);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeElement(CableMultipart te) {
|
||||
cables.remove(te);
|
||||
this.rebuild();
|
||||
}
|
||||
|
||||
private void rebuild() {
|
||||
for (int i = 0; i < cables.size(); i++) {
|
||||
CableMultipart te = cables.get(i);
|
||||
te.setNetwork(null);
|
||||
te.findAndJoinNetwork(te.getWorld(), te.getPos());
|
||||
}
|
||||
this.clear(true);
|
||||
MinecraftForge.EVENT_BUS.unregister(this);
|
||||
}
|
||||
|
||||
public void addConnection(IEnergyInterfaceTile ih, EnumFacing dir) {
|
||||
if (ih instanceof CableMultipart)
|
||||
return;
|
||||
EnergyHandler has = this.getHandleFrom(ih);
|
||||
if (has == null) {
|
||||
endpoints.add(new EnergyHandler(ih, cableType, dir));
|
||||
} else {
|
||||
has.side = dir;
|
||||
}
|
||||
}
|
||||
|
||||
public void merge(TRPowerNet n) {
|
||||
if (n != this) {
|
||||
ArrayList<CableMultipart> li = new ArrayList();
|
||||
for (int i = 0; i < n.cables.size(); i++) {
|
||||
CableMultipart wire = n.cables.get(i);
|
||||
li.add(wire);
|
||||
}
|
||||
for (int i = 0; i < n.endpoints.size(); i++) {
|
||||
EnergyHandler ei = n.endpoints.get(i);
|
||||
EnergyHandler has = this.getHandleFrom(ei.tile);
|
||||
if (has == null) {
|
||||
endpoints.add(ei);
|
||||
}
|
||||
}
|
||||
n.clear(false);
|
||||
for (int i = 0; i < li.size(); i++) {
|
||||
CableMultipart wire = li.get(i);
|
||||
wire.setNetwork(this);
|
||||
}
|
||||
MinecraftForge.EVENT_BUS.unregister(n);
|
||||
}
|
||||
}
|
||||
|
||||
private EnergyHandler getHandleFrom(IEnergyInterfaceTile tile) {
|
||||
for (int i = 0; i < endpoints.size(); i++) {
|
||||
EnergyHandler ei = endpoints.get(i);
|
||||
if (ei.contains(tile))
|
||||
return ei;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void clear(boolean clearTiles) {
|
||||
if (clearTiles) {
|
||||
for (int i = 0; i < cables.size(); i++) {
|
||||
cables.get(i).resetNetwork();
|
||||
}
|
||||
}
|
||||
|
||||
cables.clear();
|
||||
endpoints.clear();
|
||||
energy = 0;
|
||||
|
||||
MinecraftForge.EVENT_BUS.unregister(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return cables.size() + ": " + endpoints.toString();
|
||||
}
|
||||
|
||||
public int addEnergy(int maxAdd, boolean simulate) {
|
||||
if (energy >= this.getIOLimit())
|
||||
return 0;
|
||||
maxAdd = Math.min(this.getIOLimit(), maxAdd);
|
||||
if (!simulate)
|
||||
energy += maxAdd;
|
||||
return maxAdd;
|
||||
}
|
||||
|
||||
private static class EnergyHandler {
|
||||
private final IEnergyInterfaceTile tile;
|
||||
private EnumFacing side;
|
||||
private final EnumCableType type;
|
||||
|
||||
private EnergyHandler(IEnergyInterfaceTile ih, EnumCableType type, EnumFacing dir) {
|
||||
tile = ih;
|
||||
this.type = type;
|
||||
this.side = dir;
|
||||
}
|
||||
|
||||
public boolean isInsertible() {
|
||||
return this.getTotalInsertible() > 0;
|
||||
}
|
||||
|
||||
public boolean isCollectible() {
|
||||
return this.getTotalCollectible() > 0;
|
||||
}
|
||||
|
||||
public boolean contains(IEnergyInterfaceTile tile) {
|
||||
return tile == this.tile;
|
||||
}
|
||||
|
||||
public int collectEnergy(int max) {
|
||||
int total = 0;
|
||||
if (tile.canProvideEnergy(EnumFacing.NORTH)) {
|
||||
int collect = (int) Math.min(max, tile.getMaxOutput());
|
||||
total = (int) tile.useEnergy(collect, false);
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
public int addEnergy(int max) {
|
||||
int total = 0;
|
||||
if (tile.canAcceptEnergy(EnumFacing.NORTH) && max > 0) {
|
||||
if (type.tier.ordinal() > tile.getTier().ordinal()) {
|
||||
if (tile instanceof TileEntity) {
|
||||
((TileEntity) tile).getWorld().createExplosion(new EntityTNTPrimed(((TileEntity) tile).getWorld()), ((TileEntity) tile).getPos().getX(), ((TileEntity) tile).getPos().getY(), ((TileEntity) tile).getPos().getZ(), 2.5F, true);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
int add = max - total;
|
||||
total += tile.addEnergy(add, false);
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
public int getTotalCollectible() {
|
||||
if (tile.canProvideEnergy(EnumFacing.NORTH)) {
|
||||
return (int) Math.min(tile.getMaxOutput(), tile.getEnergy());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int getTotalInsertible() {
|
||||
int total = 0;
|
||||
if (tile.canAcceptEnergy(EnumFacing.NORTH)) {
|
||||
total += tile.addEnergy(type.transferRate, true);
|
||||
}
|
||||
|
||||
return total;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return tile + " @ " + side;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue