the great energy massacre part 1

This commit is contained in:
Boblet 2021-11-15 16:57:57 +01:00
parent cb1661f5d3
commit 8539a9b830
18 changed files with 218 additions and 514 deletions

View File

@ -1,5 +1,7 @@
package api.hbm.energy;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
/**
@ -34,4 +36,23 @@ public interface IEnergyConnector {
* @return
*/
public long getMaxPower();
/**
* Basic implementation of subscribing to a nearby power grid
* @param world
* @param x
* @param y
* @param z
*/
public default void trySubscribe(World world, int x, int y, int z) {
TileEntity te = world.getTileEntity(x, y, z);
if(te instanceof IEnergyConductor) {
IEnergyConductor con = (IEnergyConductor) te;
if(con.getPowerNet() != null && !con.getPowerNet().isSubscribed(this))
con.getPowerNet().subscribe(this);
}
}
}

View File

@ -7,7 +7,7 @@ package api.hbm.energy;
public interface IEnergyUser extends IEnergyConnector {
/**
* Not to be used for actual energy transfer, rather special external things like EMPs
* Not to be used for actual energy transfer, rather special external things like EMPs and sync packets
*/
public void setPower();
public void setPower(long power);
}

View File

@ -1,17 +0,0 @@
package com.hbm.calc;
import com.hbm.interfaces.ISource;
import com.hbm.interfaces.Spaghetti;
@Spaghetti("i deserve to be shot for this one")
public class UnionOfTileEntitiesAndBooleans {
public UnionOfTileEntitiesAndBooleans(ISource tileentity, boolean bool)
{
source = tileentity;
ticked = bool;
}
public ISource source;
public boolean ticked = false;
}

View File

@ -3,11 +3,10 @@ package com.hbm.entity.logic;
import java.util.ArrayList;
import java.util.List;
import com.hbm.interfaces.IConsumer;
import com.hbm.interfaces.ISource;
import com.hbm.packet.PacketDispatcher;
import com.hbm.packet.ParticleBurstPacket;
import api.hbm.energy.IEnergyUser;
import cofh.api.energy.IEnergyProvider;
import cpw.mods.fml.common.network.NetworkRegistry.TargetPoint;
import net.minecraft.block.Block;
@ -82,9 +81,7 @@ public class EntityEMP extends Entity {
private void add(int x, int y, int z) {
TileEntity te = worldObj.getTileEntity(x, y, z);
if (te != null && te instanceof ISource) {
machines.add(new int[] { x, y, z });
} else if (te != null && te instanceof IConsumer) {
if (te != null && te instanceof IEnergyUser) {
machines.add(new int[] { x, y, z });
} else if (te != null && te instanceof IEnergyProvider) {
machines.add(new int[] { x, y, z });
@ -97,14 +94,9 @@ public class EntityEMP extends Entity {
boolean flag = false;
if (te != null && te instanceof ISource) {
if (te != null && te instanceof IEnergyUser) {
((ISource)te).setSPower(0);
flag = true;
}
if (te != null && te instanceof IConsumer) {
((IConsumer)te).setPower(0);
((IEnergyUser)te).setPower(0);
flag = true;
}
if (te != null && te instanceof IEnergyProvider) {

View File

@ -31,8 +31,6 @@ import com.hbm.entity.grenade.EntityGrenadeNuclear;
import com.hbm.entity.missile.EntityMIRV;
import com.hbm.entity.projectile.EntityBulletBase;
import com.hbm.entity.projectile.EntityExplosiveBeam;
import com.hbm.interfaces.IConsumer;
import com.hbm.interfaces.ISource;
import com.hbm.interfaces.Spaghetti;
import com.hbm.items.ModItems;
import com.hbm.lib.Library;
@ -41,6 +39,7 @@ import com.hbm.main.MainRegistry;
import com.hbm.tileentity.turret.TileEntityTurretBase;
import com.hbm.util.ArmorUtil;
import api.hbm.energy.IEnergyUser;
import cofh.api.energy.IEnergyProvider;
public class ExplosionNukeGeneric {
@ -594,16 +593,9 @@ public class ExplosionNukeGeneric {
Block b = world.getBlock(x,y,z);
TileEntity te = world.getTileEntity(x, y, z);
if (te != null && te instanceof ISource) {
if (te != null && te instanceof IEnergyUser) {
((ISource)te).setSPower(0);
if(random.nextInt(5) < 1)
world.setBlock(x, y, z, ModBlocks.block_electrical_scrap);
}
if (te != null && te instanceof IConsumer) {
((IConsumer)te).setPower(0);
((IEnergyUser)te).setPower(0);
if(random.nextInt(5) < 1)
world.setBlock(x, y, z, ModBlocks.block_electrical_scrap);

View File

@ -1,5 +0,0 @@
package com.hbm.interfaces;
public interface IConductor {
}

View File

@ -1,10 +0,0 @@
package com.hbm.interfaces;
public interface IConsumer {
void setPower(long i);
long getPower();
long getMaxPower();
}

View File

@ -1,16 +0,0 @@
package com.hbm.interfaces;
import java.util.List;
public interface ISource {
void ffgeuaInit();
void ffgeua(int x, int y, int z, boolean newTact);
boolean getTact();
long getSPower();
void setSPower(long i);
List<IConsumer> getList();
void clearList();
}

View File

@ -2,15 +2,14 @@ package com.hbm.items.tool;
import java.util.List;
import com.hbm.interfaces.IConsumer;
import com.hbm.interfaces.IFluidContainer;
import com.hbm.interfaces.IFluidDuct;
import com.hbm.interfaces.ISource;
import com.hbm.inventory.FluidTank;
import com.hbm.tileentity.conductor.TileEntityPylonRedWire;
import com.hbm.tileentity.machine.TileEntityDummy;
import com.hbm.tileentity.machine.TileEntityLockableBase;
import api.hbm.energy.IEnergyConnector;
import net.minecraft.block.Block;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.EntityPlayer;
@ -71,14 +70,10 @@ public class ItemAnalyzer extends Item {
"Slots: " + ((IInventory)te).getSizeInventory()));
}
if(te instanceof IConsumer) {
if(te instanceof IEnergyConnector) {
player.addChatMessage(new ChatComponentText(
"Electricity: " + ((IConsumer)te).getPower() + " HE"));
} else if(te instanceof ISource) {
player.addChatMessage(new ChatComponentText(
"Electricity: " + ((ISource)te).getSPower() + " HE"));
"Electricity: " + ((IEnergyConnector)te).getPower() + " HE"));
}
if(te instanceof IFluidContainer) {

View File

@ -7,17 +7,13 @@ import java.util.Set;
import com.google.common.collect.Sets;
import com.hbm.blocks.ModBlocks;
import com.hbm.calc.UnionOfTileEntitiesAndBooleans;
import com.hbm.calc.UnionOfTileEntitiesAndBooleansForFluids;
import com.hbm.entity.mob.EntityHunterChopper;
import com.hbm.entity.projectile.EntityChopperMine;
import com.hbm.handler.FluidTypeHandler.FluidType;
import com.hbm.interfaces.IConductor;
import com.hbm.interfaces.IConsumer;
import com.hbm.interfaces.IFluidAcceptor;
import com.hbm.interfaces.IFluidDuct;
import com.hbm.interfaces.IFluidSource;
import com.hbm.interfaces.ISource;
import com.hbm.interfaces.Spaghetti;
import com.hbm.items.ModItems;
import com.hbm.tileentity.TileEntityProxyInventory;
@ -35,6 +31,8 @@ import com.hbm.tileentity.machine.TileEntityMachineBattery;
import com.hbm.tileentity.machine.TileEntityMachineTransformer;
import api.hbm.energy.IBatteryItem;
import api.hbm.energy.IEnergyConnector;
import api.hbm.energy.IEnergyConnectorBlock;
import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
@ -44,7 +42,9 @@ import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.Vec3;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
@Spaghetti("this whole class")
public class Library {
@ -96,37 +96,39 @@ public class Library {
return player.getHeldItem().getItem() == item;
}
public static final ForgeDirection POS_X = ForgeDirection.EAST;
public static final ForgeDirection NEG_X = ForgeDirection.WEST;
public static final ForgeDirection POS_Y = ForgeDirection.UP;
public static final ForgeDirection NEG_Y = ForgeDirection.DOWN;
public static final ForgeDirection POS_Z = ForgeDirection.SOUTH;
public static final ForgeDirection NEG_Z = ForgeDirection.NORTH;
public static boolean checkCableConnectables(World world, int x, int y, int z)
{
TileEntity tileentity = world.getTileEntity(x, y, z);
if((tileentity != null && (tileentity instanceof IConductor ||
tileentity instanceof IConsumer ||
tileentity instanceof ISource)) ||
world.getBlock(x, y, z) == ModBlocks.fusion_center ||
world.getBlock(x, y, z) == ModBlocks.factory_titanium_conductor ||
world.getBlock(x, y, z) == ModBlocks.factory_advanced_conductor ||
world.getBlock(x, y, z) == ModBlocks.watz_conductor ||
world.getBlock(x, y, z) == ModBlocks.fwatz_hatch ||
world.getBlock(x, y, z) == ModBlocks.dummy_port_igenerator ||
world.getBlock(x, y, z) == ModBlocks.dummy_port_cyclotron ||
world.getBlock(x, y, z) == ModBlocks.dummy_port_well ||
world.getBlock(x, y, z) == ModBlocks.dummy_port_flare ||
world.getBlock(x, y, z) == ModBlocks.dummy_port_drill ||
world.getBlock(x, y, z) == ModBlocks.dummy_port_assembler ||
world.getBlock(x, y, z) == ModBlocks.dummy_port_chemplant ||
world.getBlock(x, y, z) == ModBlocks.dummy_port_refinery ||
world.getBlock(x, y, z) == ModBlocks.dummy_port_pumpjack ||
world.getBlock(x, y, z) == ModBlocks.dummy_port_turbofan ||
world.getBlock(x, y, z) == ModBlocks.dummy_port_ams_limiter ||
world.getBlock(x, y, z) == ModBlocks.dummy_port_ams_emitter ||
world.getBlock(x, y, z) == ModBlocks.dummy_port_ams_base ||
world.getBlock(x, y, z) == ModBlocks.dummy_port_radgen ||
world.getBlock(x, y, z) == ModBlocks.dummy_port_compact_launcher ||
world.getBlock(x, y, z) == ModBlocks.dummy_port_launch_table)
{
return true;
/*
* Is putting this into this trash can a good idea? No. Do I have a better idea? Not currently.
*/
public static boolean canConnect(IBlockAccess world, int x, int y, int z, ForgeDirection dir) {
if(y > 255 || y < 0)
return false;
Block b = world.getBlock(x, y, z);
TileEntity te = world.getTileEntity(x, y, z);
if(b instanceof IEnergyConnectorBlock) {
IEnergyConnectorBlock con = (IEnergyConnectorBlock) b;
if(con.canConnect(world, x, y, z, dir))
return true;
}
if(te instanceof IEnergyConnectorBlock) {
IEnergyConnector con = (IEnergyConnector) te;
if(con.canConnect(dir))
return true;
}
return false;
}
@ -165,19 +167,6 @@ public class Library {
return false;
}
public static boolean checkUnionList(List<UnionOfTileEntitiesAndBooleans> list, ISource that) {
for(UnionOfTileEntitiesAndBooleans union : list)
{
if(union.source == that)
{
return true;
}
}
return false;
}
public static boolean checkUnionListForFluids(List<UnionOfTileEntitiesAndBooleansForFluids> list, IFluidSource that) {
for(UnionOfTileEntitiesAndBooleansForFluids union : list)
@ -421,244 +410,13 @@ public class Library {
//Flut-Füll gesteuerter Energieübertragungsalgorithmus
//Flood fill controlled energy transmission algorithm
//TODO: bring back the @Cursed annotation just for garbage like this
public static void ffgeua(int x, int y, int z, boolean newTact, ISource that, World worldObj) {
Block block = worldObj.getBlock(x, y, z);
TileEntity tileentity = worldObj.getTileEntity(x, y, z);
//Factories
if(block == ModBlocks.factory_titanium_conductor && worldObj.getBlock(x, y + 1, z) == ModBlocks.factory_titanium_core)
{
tileentity = worldObj.getTileEntity(x, y + 1, z);
}
if(block == ModBlocks.factory_titanium_conductor && worldObj.getBlock(x, y - 1, z) == ModBlocks.factory_titanium_core)
{
tileentity = worldObj.getTileEntity(x, y - 1, z);
}
if(block == ModBlocks.factory_advanced_conductor && worldObj.getBlock(x, y + 1, z) == ModBlocks.factory_advanced_core)
{
tileentity = worldObj.getTileEntity(x, y + 1, z);
}
if(block == ModBlocks.factory_advanced_conductor && worldObj.getBlock(x, y - 1, z) == ModBlocks.factory_advanced_core)
{
tileentity = worldObj.getTileEntity(x, y - 1, z);
}
//Derrick
if(block == ModBlocks.dummy_port_well && worldObj.getBlock(x + 1, y, z) == ModBlocks.machine_well)
{
tileentity = worldObj.getTileEntity(x + 1, y, z);
}
if(block == ModBlocks.dummy_port_well && worldObj.getBlock(x - 1, y, z) == ModBlocks.machine_well)
{
tileentity = worldObj.getTileEntity(x - 1, y, z);
}
if(block == ModBlocks.dummy_port_well && worldObj.getBlock(x, y, z + 1) == ModBlocks.machine_well)
{
tileentity = worldObj.getTileEntity(x, y, z + 1);
}
if(block == ModBlocks.dummy_port_well && worldObj.getBlock(x, y, z - 1) == ModBlocks.machine_well)
{
tileentity = worldObj.getTileEntity(x, y, z - 1);
}
//Mining Drill
if(block == ModBlocks.dummy_port_drill && worldObj.getBlock(x + 1, y, z) == ModBlocks.machine_drill)
{
tileentity = worldObj.getTileEntity(x + 1, y, z);
}
if(block == ModBlocks.dummy_port_drill && worldObj.getBlock(x - 1, y, z) == ModBlocks.machine_drill)
{
tileentity = worldObj.getTileEntity(x - 1, y, z);
}
if(block == ModBlocks.dummy_port_drill && worldObj.getBlock(x, y, z + 1) == ModBlocks.machine_drill)
{
tileentity = worldObj.getTileEntity(x, y, z + 1);
}
if(block == ModBlocks.dummy_port_drill && worldObj.getBlock(x, y, z - 1) == ModBlocks.machine_drill)
{
tileentity = worldObj.getTileEntity(x, y, z - 1);
}
//Assembler
if(block == ModBlocks.dummy_port_assembler)
{
tileentity = worldObj.getTileEntity(((TileEntityDummy)worldObj.getTileEntity(x, y, z)).targetX, ((TileEntityDummy)worldObj.getTileEntity(x, y, z)).targetY, ((TileEntityDummy)worldObj.getTileEntity(x, y, z)).targetZ);
}
//Chemplant
if(block == ModBlocks.dummy_port_chemplant)
{
tileentity = worldObj.getTileEntity(((TileEntityDummy)worldObj.getTileEntity(x, y, z)).targetX, ((TileEntityDummy)worldObj.getTileEntity(x, y, z)).targetY, ((TileEntityDummy)worldObj.getTileEntity(x, y, z)).targetZ);
}
//Refinery
if(block == ModBlocks.dummy_port_refinery)
{
tileentity = worldObj.getTileEntity(((TileEntityDummy)worldObj.getTileEntity(x, y, z)).targetX, ((TileEntityDummy)worldObj.getTileEntity(x, y, z)).targetY, ((TileEntityDummy)worldObj.getTileEntity(x, y, z)).targetZ);
}
//Pumpjack
if(block == ModBlocks.dummy_port_pumpjack)
{
tileentity = worldObj.getTileEntity(((TileEntityDummy)worldObj.getTileEntity(x, y, z)).targetX, ((TileEntityDummy)worldObj.getTileEntity(x, y, z)).targetY, ((TileEntityDummy)worldObj.getTileEntity(x, y, z)).targetZ);
}
//AMS Limiter
if(block == ModBlocks.dummy_port_ams_limiter)
{
tileentity = worldObj.getTileEntity(((TileEntityDummy)worldObj.getTileEntity(x, y, z)).targetX, ((TileEntityDummy)worldObj.getTileEntity(x, y, z)).targetY, ((TileEntityDummy)worldObj.getTileEntity(x, y, z)).targetZ);
}
//AMS Emitter
if(block == ModBlocks.dummy_port_ams_emitter)
{
tileentity = worldObj.getTileEntity(((TileEntityDummy)worldObj.getTileEntity(x, y, z)).targetX, ((TileEntityDummy)worldObj.getTileEntity(x, y, z)).targetY, ((TileEntityDummy)worldObj.getTileEntity(x, y, z)).targetZ);
}
//Launchers
if(block == ModBlocks.dummy_port_compact_launcher || block == ModBlocks.dummy_port_launch_table)
{
tileentity = worldObj.getTileEntity(((TileEntityDummy)worldObj.getTileEntity(x, y, z)).targetX, ((TileEntityDummy)worldObj.getTileEntity(x, y, z)).targetY, ((TileEntityDummy)worldObj.getTileEntity(x, y, z)).targetZ);
}
public static void ffgeua(int x, int y, int z, boolean newTact, Object that, World worldObj) {
if(tileentity instanceof IConductor)
{
if(tileentity instanceof TileEntityCable)
{
if(Library.checkUnionList(((TileEntityCable)tileentity).uoteab, that))
{
for(int i = 0; i < ((TileEntityCable)tileentity).uoteab.size(); i++)
{
if(((TileEntityCable)tileentity).uoteab.get(i).source == that)
{
if(((TileEntityCable)tileentity).uoteab.get(i).ticked != newTact)
{
((TileEntityCable)tileentity).uoteab.get(i).ticked = newTact;
ffgeua(x, y + 1, z, that.getTact(), that, worldObj);
ffgeua(x, y - 1, z, that.getTact(), that, worldObj);
ffgeua(x - 1, y, z, that.getTact(), that, worldObj);
ffgeua(x + 1, y, z, that.getTact(), that, worldObj);
ffgeua(x, y, z - 1, that.getTact(), that, worldObj);
ffgeua(x, y, z + 1, that.getTact(), that, worldObj);
}
}
}
} else {
((TileEntityCable)tileentity).uoteab.add(new UnionOfTileEntitiesAndBooleans(that, newTact));
}
}
if(tileentity instanceof TileEntityWireCoated)
{
if(Library.checkUnionList(((TileEntityWireCoated)tileentity).uoteab, that))
{
for(int i = 0; i < ((TileEntityWireCoated)tileentity).uoteab.size(); i++)
{
if(((TileEntityWireCoated)tileentity).uoteab.get(i).source == that)
{
if(((TileEntityWireCoated)tileentity).uoteab.get(i).ticked != newTact)
{
((TileEntityWireCoated)tileentity).uoteab.get(i).ticked = newTact;
ffgeua(x, y + 1, z, that.getTact(), that, worldObj);
ffgeua(x, y - 1, z, that.getTact(), that, worldObj);
ffgeua(x - 1, y, z, that.getTact(), that, worldObj);
ffgeua(x + 1, y, z, that.getTact(), that, worldObj);
ffgeua(x, y, z - 1, that.getTact(), that, worldObj);
ffgeua(x, y, z + 1, that.getTact(), that, worldObj);
}
}
}
} else {
((TileEntityWireCoated)tileentity).uoteab.add(new UnionOfTileEntitiesAndBooleans(that, newTact));
}
}
if(tileentity instanceof TileEntityCableSwitch)
{
if(tileentity.getBlockMetadata() == 1) {
if(Library.checkUnionList(((TileEntityCableSwitch)tileentity).uoteab, that))
{
for(int i = 0; i < ((TileEntityCableSwitch)tileentity).uoteab.size(); i++)
{
if(((TileEntityCableSwitch)tileentity).uoteab.get(i).source == that)
{
if(((TileEntityCableSwitch)tileentity).uoteab.get(i).ticked != newTact)
{
((TileEntityCableSwitch)tileentity).uoteab.get(i).ticked = newTact;
ffgeua(x, y + 1, z, that.getTact(), that, worldObj);
ffgeua(x, y - 1, z, that.getTact(), that, worldObj);
ffgeua(x - 1, y, z, that.getTact(), that, worldObj);
ffgeua(x + 1, y, z, that.getTact(), that, worldObj);
ffgeua(x, y, z - 1, that.getTact(), that, worldObj);
ffgeua(x, y, z + 1, that.getTact(), that, worldObj);
}
}
}
} else {
((TileEntityCableSwitch)tileentity).uoteab.add(new UnionOfTileEntitiesAndBooleans(that, newTact));
}
} else {
((TileEntityCableSwitch)tileentity).uoteab.clear();
}
}
if(tileentity instanceof TileEntityPylonRedWire)
{
if(Library.checkUnionList(((TileEntityPylonRedWire)tileentity).uoteab, that))
{
for(int i = 0; i < ((TileEntityPylonRedWire)tileentity).uoteab.size(); i++)
{
if(((TileEntityPylonRedWire)tileentity).uoteab.get(i).source == that)
{
if(((TileEntityPylonRedWire)tileentity).uoteab.get(i).ticked != newTact)
{
((TileEntityPylonRedWire)tileentity).uoteab.get(i).ticked = newTact;
for(int j = 0; j < ((TileEntityPylonRedWire)tileentity).connected.size(); j++) {
int[] pylon = ((TileEntityPylonRedWire)tileentity).connected.get(j);
if(pylon != null) {
ffgeua(pylon[0] + 1, pylon[1], pylon[2], that.getTact(), that, worldObj);
ffgeua(pylon[0] - 1, pylon[1], pylon[2], that.getTact(), that, worldObj);
ffgeua(pylon[0], pylon[1] + 1, pylon[2], that.getTact(), that, worldObj);
ffgeua(pylon[0], pylon[1] - 1, pylon[2], that.getTact(), that, worldObj);
ffgeua(pylon[0], pylon[1], pylon[2] + 1, that.getTact(), that, worldObj);
ffgeua(pylon[0], pylon[1], pylon[2] - 1, that.getTact(), that, worldObj);
ffgeua(pylon[0], pylon[1], pylon[2], that.getTact(), that, worldObj);
}
}
}
}
}
} else {
((TileEntityPylonRedWire)tileentity).uoteab.add(new UnionOfTileEntitiesAndBooleans(that, newTact));
}
}
}
//TE will not be added as consumer if:
// -TE is the source (will not send to itself)
// -TE is already full
// -TE is a battery set to output only
// -TE as well as source are transformers of the same frequency
if(tileentity instanceof IConsumer && newTact && !(tileentity instanceof TileEntityMachineBattery && ((TileEntityMachineBattery)tileentity).conducts) &&
tileentity != that && ((IConsumer)tileentity).getPower() < ((IConsumer)tileentity).getMaxPower() &&
!(tileentity instanceof TileEntityMachineTransformer && that instanceof TileEntityMachineTransformer &&
((TileEntityMachineTransformer)tileentity).delay == ((TileEntityMachineTransformer)that).delay))
{
that.getList().add((IConsumer)tileentity);
}
if(!newTact)
{
int size = that.getList().size();
if(size > 0)
{
long part = that.getSPower() / size;
for(IConsumer consume : that.getList())
{
if(consume.getPower() < consume.getMaxPower())
{
if(consume.getMaxPower() - consume.getPower() >= part)
{
that.setSPower(that.getSPower()-part);
consume.setPower(consume.getPower() + part);
} else {
that.setSPower(that.getSPower() - (consume.getMaxPower() - consume.getPower()));
consume.setPower(consume.getMaxPower());
}
}
}
}
that.clearList();
}
/*
* This here smoldering crater is all that remains from the old energy system.
* In loving memory, 2016-2021.
* You won't be missed.
*/
}
public static void transmitFluid(int x, int y, int z, boolean newTact, IFluidSource that, World worldObj, FluidType type) {

View File

@ -1,8 +1,6 @@
package com.hbm.packet;
import com.hbm.interfaces.IConsumer;
import com.hbm.interfaces.ISource;
import api.hbm.energy.IEnergyUser;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
@ -54,17 +52,13 @@ public class AuxElectricityPacket implements IMessage {
@SideOnly(Side.CLIENT)
public IMessage onMessage(AuxElectricityPacket m, MessageContext ctx) {
try {
TileEntity te = Minecraft.getMinecraft().theWorld.getTileEntity(m.x, m.y, m.z);
if (te != null && te instanceof IConsumer) {
IConsumer gen = (IConsumer) te;
gen.setPower(m.charge);
} else if (te != null && te instanceof ISource) {
ISource gen = (ISource) te;
gen.setSPower(m.charge);
}
TileEntity te = Minecraft.getMinecraft().theWorld.getTileEntity(m.x, m.y, m.z);
if (te instanceof IEnergyUser) {
IEnergyUser gen = (IEnergyUser) te;
gen.setPower(m.charge);
}
} catch (Exception x) { }
return null;
}

View File

@ -3,6 +3,7 @@ package com.hbm.render.block;
import org.lwjgl.opengl.GL11;
import com.hbm.blocks.test.TestConductor;
import com.hbm.lib.Library;
import com.hbm.main.ResourceManager;
import com.hbm.render.util.ObjUtil;
@ -59,12 +60,12 @@ public class RenderTestCable implements ISimpleBlockRenderingHandler {
tessellator.setBrightness(block.getMixedBrightnessForBlock(world, x, y, z));
tessellator.setColorOpaque_F(1, 1, 1);
boolean pX = canConnect(world, x + 1, y, z, ForgeDirection.EAST);
boolean nX = canConnect(world, x - 1, y, z, ForgeDirection.WEST);
boolean pY = canConnect(world, x, y + 1, z, ForgeDirection.UP);
boolean nY = canConnect(world, x, y - 1, z, ForgeDirection.DOWN);
boolean pZ = canConnect(world, x, y, z + 1, ForgeDirection.SOUTH);
boolean nZ = canConnect(world, x, y, z - 1, ForgeDirection.NORTH);
boolean pX = Library.canConnect(world, x + 1, y, z, Library.POS_X);
boolean nX = Library.canConnect(world, x - 1, y, z, Library.NEG_X);
boolean pY = Library.canConnect(world, x, y + 1, z, Library.POS_Y);
boolean nY = Library.canConnect(world, x, y - 1, z, Library.NEG_Y);
boolean pZ = Library.canConnect(world, x, y, z + 1, Library.POS_Z);
boolean nZ = Library.canConnect(world, x, y, z - 1, Library.NEG_Z);
tessellator.addTranslation(x + 0.5F, y + 0.5F, z + 0.5F);
@ -89,31 +90,6 @@ public class RenderTestCable implements ISimpleBlockRenderingHandler {
return true;
}
private boolean canConnect(IBlockAccess world, int x, int y, int z, ForgeDirection dir) {
if(y > 255 || y < 0)
return false;
Block b = world.getBlock(x, y, z);
TileEntity te = world.getTileEntity(x, y, z);
if(b instanceof IEnergyConnectorBlock) {
IEnergyConnectorBlock con = (IEnergyConnectorBlock) b;
if(con.canConnect(world, x, y, z, dir))
return true;
}
if(te instanceof IEnergyConnectorBlock) {
IEnergyConnector con = (IEnergyConnector) te;
if(con.canConnect(dir))
return true;
}
return false;
}
@Override
public boolean shouldRender3DInInventory(int modelId) {

View File

@ -33,22 +33,22 @@ public class RenderRTG extends TileEntitySpecialRenderer {
int iy = te.yCoord;
int iz = te.zCoord;
if(Library.checkCableConnectables(te.getWorldObj(), ix + 1, iy, iz))
if(Library.canConnect(te.getWorldObj(), ix + 1, iy, iz, Library.POS_X))
ResourceManager.rtg.renderPart("Connector");
if(Library.checkCableConnectables(te.getWorldObj(), ix - 1, iy, iz)) {
if(Library.canConnect(te.getWorldObj(), ix - 1, iy, iz, Library.NEG_X)) {
GL11.glRotatef(180, 0F, 1F, 0F);
ResourceManager.rtg.renderPart("Connector");
GL11.glRotatef(-180, 0F, 1F, 0F);
}
if(Library.checkCableConnectables(te.getWorldObj(), ix, iy, iz - 1)) {
if(Library.canConnect(te.getWorldObj(), ix, iy, iz - 1, Library.NEG_Z)) {
GL11.glRotatef(90, 0F, 1F, 0F);
ResourceManager.rtg.renderPart("Connector");
GL11.glRotatef(-90, 0F, 1F, 0F);
}
if(Library.checkCableConnectables(te.getWorldObj(), ix, iy, iz + 1)) {
if(Library.canConnect(te.getWorldObj(), ix, iy, iz + 1, Library.POS_Z)) {
GL11.glRotatef(-90, 0F, 1F, 0F);
ResourceManager.rtg.renderPart("Connector");
GL11.glRotatef(90, 0F, 1F, 0F);

View File

@ -10,6 +10,7 @@ import com.hbm.tileentity.turret.TileEntityTurretBaseNT;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.util.Vec3;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
public abstract class RenderTurretBase extends TileEntitySpecialRenderer {
@ -21,23 +22,22 @@ public abstract class RenderTurretBase extends TileEntitySpecialRenderer {
int y = turret.yCoord;
int z = (int)(turret.zCoord + pos.zCoord);
checkPlug(turret.getWorldObj(), x - 2, y, z, power, fluid, type, 0, 0, 0);
checkPlug(turret.getWorldObj(), x - 2, y, z - 1, power, fluid, type, 0, -1, 0);
checkPlug(turret.getWorldObj(), x - 2, y, z, power, fluid, type, 0, 0, 0, Library.NEG_X);
checkPlug(turret.getWorldObj(), x - 2, y, z - 1, power, fluid, type, 0, -1, 0, Library.NEG_X);
checkPlug(turret.getWorldObj(), x - 1, y, z + 1, power, fluid, type, 0, -1, 90);
checkPlug(turret.getWorldObj(), x, y, z + 1, power, fluid, type, 0, 0, 90);
checkPlug(turret.getWorldObj(), x - 1, y, z + 1, power, fluid, type, 0, -1, 90, Library.POS_Z);
checkPlug(turret.getWorldObj(), x, y, z + 1, power, fluid, type, 0, 0, 90, Library.POS_Z);
checkPlug(turret.getWorldObj(), x + 1, y, z, power, fluid, type, 0, -1, 180);
checkPlug(turret.getWorldObj(), x + 1, y, z - 1, power, fluid, type, 0, 0, 180);
checkPlug(turret.getWorldObj(), x + 1, y, z, power, fluid, type, 0, -1, 180, Library.POS_X);
checkPlug(turret.getWorldObj(), x + 1, y, z - 1, power, fluid, type, 0, 0, 180, Library.POS_X);
checkPlug(turret.getWorldObj(), x, y, z - 2, power, fluid, type, 0, -1, 270);
checkPlug(turret.getWorldObj(), x - 1, y, z - 2, power, fluid, type, 0, 0, 270);
checkPlug(turret.getWorldObj(), x, y, z - 2, power, fluid, type, 0, -1, 270, Library.NEG_Z);
checkPlug(turret.getWorldObj(), x - 1, y, z - 2, power, fluid, type, 0, 0, 270, Library.NEG_Z);
}
private void checkPlug(World world, int x, int y, int z, boolean power, boolean fluid, FluidType type, int ox, int oz, int rot) {
private void checkPlug(World world, int x, int y, int z, boolean power, boolean fluid, FluidType type, int ox, int oz, int rot, ForgeDirection dir) {
if( (power && Library.checkCableConnectables(world, x, y, z)) ||
(fluid && Library.checkFluidConnectables(world, x, y, z, type)) ) {
if((power && Library.canConnect(world, x, y, z, dir)) || (fluid && Library.checkFluidConnectables(world, x, y, z, type))) {
GL11.glPushMatrix();
GL11.glRotated(rot, 0, 1, 0);

View File

@ -3,17 +3,18 @@ package com.hbm.tileentity;
import java.util.List;
import com.hbm.handler.FluidTypeHandler.FluidType;
import com.hbm.interfaces.IConsumer;
import com.hbm.interfaces.IFluidAcceptor;
import com.hbm.inventory.FluidTank;
import api.hbm.energy.IEnergyUser;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
public class TileEntityProxyCombo extends TileEntityProxyBase implements IConsumer, IFluidAcceptor, ISidedInventory {
public class TileEntityProxyCombo extends TileEntityProxyBase implements IEnergyUser, IFluidAcceptor, ISidedInventory {
TileEntity tile;
boolean inventory;
@ -116,8 +117,8 @@ public class TileEntityProxyCombo extends TileEntityProxyBase implements IConsum
if(!power)
return;
if(getTile() instanceof IConsumer) {
((IConsumer)getTile()).setPower(i);
if(getTile() instanceof IEnergyUser) {
((IEnergyUser)getTile()).setPower(i);
}
}
@ -127,8 +128,8 @@ public class TileEntityProxyCombo extends TileEntityProxyBase implements IConsum
if(!power)
return 0;
if(getTile() instanceof IConsumer) {
return ((IConsumer)getTile()).getPower();
if(getTile() instanceof IEnergyUser) {
return ((IEnergyUser)getTile()).getPower();
}
return 0;
@ -140,13 +141,39 @@ public class TileEntityProxyCombo extends TileEntityProxyBase implements IConsum
if(!power)
return 0;
if(getTile() instanceof IConsumer) {
return ((IConsumer)getTile()).getMaxPower();
if(getTile() instanceof IEnergyUser) {
return ((IEnergyUser)getTile()).getMaxPower();
}
return 0;
}
@Override
public long transferPower(long power) {
if(!this.power)
return 0;
if(getTile() instanceof IEnergyUser) {
return ((IEnergyUser)getTile()).transferPower(power);
}
return 0;
}
@Override
public boolean canConnect(ForgeDirection dir) {
if(!power)
return false;
if(getTile() instanceof IEnergyUser) {
return ((IEnergyUser)getTile()).canConnect(dir);
}
return false;
}
@Override
public int getSizeInventory() {
@ -350,5 +377,4 @@ public class TileEntityProxyCombo extends TileEntityProxyBase implements IConsum
nbt.setBoolean("power", power);
nbt.setBoolean("fluid", fluid);
}
}

View File

@ -1,11 +1,11 @@
package com.hbm.tileentity;
import com.hbm.interfaces.IConsumer;
import api.hbm.energy.IEnergyUser;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
//can be used as a soruce too since the core TE handles that anyway
public class TileEntityProxyEnergy extends TileEntityProxyBase implements IConsumer {
public class TileEntityProxyEnergy extends TileEntityProxyBase implements IEnergyUser {
public boolean canUpdate()
{
@ -17,8 +17,8 @@ public class TileEntityProxyEnergy extends TileEntityProxyBase implements IConsu
TileEntity te = getTE();
if(te instanceof IConsumer) {
((IConsumer)te).setPower(i);
if(te instanceof IEnergyUser) {
((IEnergyUser)te).setPower(i);
}
}
@ -27,8 +27,8 @@ public class TileEntityProxyEnergy extends TileEntityProxyBase implements IConsu
TileEntity te = getTE();
if(te instanceof IConsumer) {
return ((IConsumer)te).getPower();
if(te instanceof IEnergyUser) {
return ((IEnergyUser)te).getPower();
}
return 0;
@ -39,10 +39,30 @@ public class TileEntityProxyEnergy extends TileEntityProxyBase implements IConsu
TileEntity te = getTE();
if(te instanceof IConsumer) {
return ((IConsumer)te).getMaxPower();
if(te instanceof IEnergyUser) {
return ((IEnergyUser)te).getMaxPower();
}
return 0;
}
@Override
public long transferPower(long power) {
if(getTE() instanceof IEnergyUser) {
return ((IEnergyUser)getTE()).transferPower(power);
}
return 0;
}
@Override
public boolean canConnect(ForgeDirection dir) {
if(getTE() instanceof IEnergyUser) {
return ((IEnergyUser)getTE()).canConnect(dir);
}
return false;
}
}

View File

@ -6,7 +6,6 @@ import java.util.List;
import com.hbm.entity.missile.EntityMissileCustom;
import com.hbm.handler.FluidTypeHandler.FluidType;
import com.hbm.handler.MissileStruct;
import com.hbm.interfaces.IConsumer;
import com.hbm.interfaces.IFluidAcceptor;
import com.hbm.interfaces.IFluidContainer;
import com.hbm.inventory.FluidTank;
@ -22,6 +21,7 @@ import com.hbm.packet.AuxGaugePacket;
import com.hbm.packet.PacketDispatcher;
import com.hbm.packet.TEMissileMultipartPacket;
import api.hbm.energy.IEnergyUser;
import api.hbm.item.IDesignatorItem;
import cpw.mods.fml.common.network.NetworkRegistry.TargetPoint;
import cpw.mods.fml.relauncher.Side;
@ -36,8 +36,9 @@ import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.Vec3;
import net.minecraftforge.common.util.ForgeDirection;
public class TileEntityCompactLauncher extends TileEntity implements ISidedInventory, IConsumer, IFluidContainer, IFluidAcceptor {
public class TileEntityCompactLauncher extends TileEntity implements ISidedInventory, IFluidContainer, IFluidAcceptor, IEnergyUser {
private ItemStack slots[];
@ -178,6 +179,8 @@ public class TileEntityCompactLauncher extends TileEntity implements ISidedInven
this.decrStackSize(4, 1);
solid += 250;
}
this.updateConnections();
PacketDispatcher.wrapper.sendToAllAround(new AuxElectricityPacket(xCoord, yCoord, zCoord, power), new TargetPoint(worldObj.provider.dimensionId, xCoord, yCoord, zCoord, 50));
PacketDispatcher.wrapper.sendToAllAround(new AuxGaugePacket(xCoord, yCoord, zCoord, solid, 0), new TargetPoint(worldObj.provider.dimensionId, xCoord, yCoord, zCoord, 50));
@ -222,6 +225,21 @@ public class TileEntityCompactLauncher extends TileEntity implements ISidedInven
}
}
private void updateConnections() {
this.trySubscribe(worldObj, xCoord + 2, yCoord, zCoord + 1);
this.trySubscribe(worldObj, xCoord + 2, yCoord, zCoord - 1);
this.trySubscribe(worldObj, xCoord - 2, yCoord, zCoord + 1);
this.trySubscribe(worldObj, xCoord - 2, yCoord, zCoord - 1);
this.trySubscribe(worldObj, xCoord + 1, yCoord, zCoord + 2);
this.trySubscribe(worldObj, xCoord - 1, yCoord, zCoord + 2);
this.trySubscribe(worldObj, xCoord + 1, yCoord, zCoord - 2);
this.trySubscribe(worldObj, xCoord - 1, yCoord, zCoord - 2);
this.trySubscribe(worldObj, xCoord + 1, yCoord - 1, zCoord + 1);
this.trySubscribe(worldObj, xCoord + 1, yCoord - 1, zCoord - 1);
this.trySubscribe(worldObj, xCoord - 1, yCoord - 1, zCoord + 1);
this.trySubscribe(worldObj, xCoord - 1, yCoord - 1, zCoord - 1);
}
public boolean canLaunch() {
if(power >= maxPower * 0.75 && isMissileValid() && hasDesignator() && hasFuel())
@ -558,4 +576,24 @@ public class TileEntityCompactLauncher extends TileEntity implements ISidedInven
public long getMaxPower() {
return this.maxPower;
}
@Override
public long transferPower(long power) {
this.power += power;
if(this.power > this.getMaxPower()) {
long overshoot = this.power - this.getMaxPower();
this.power = this.getMaxPower();
return overshoot;
}
return 0;
}
@Override
public boolean canConnect(ForgeDirection dir) {
return dir != ForgeDirection.UP && dir != ForgeDirection.UNKNOWN;
}
}

View File

@ -4,21 +4,20 @@ import java.util.ArrayList;
import java.util.List;
import com.hbm.blocks.machine.MachineBattery;
import com.hbm.interfaces.IConsumer;
import com.hbm.interfaces.ISource;
import com.hbm.lib.Library;
import com.hbm.tileentity.TileEntityMachineBase;
import api.hbm.energy.IBatteryItem;
import api.hbm.energy.IEnergyConductor;
import api.hbm.energy.IEnergyConnector;
import api.hbm.energy.IEnergyUser;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
public class TileEntityMachineBattery extends TileEntityMachineBase implements IConsumer, ISource, IEnergyConnector {
public class TileEntityMachineBattery extends TileEntityMachineBase implements IEnergyUser {
public long[] log = new long[20];
public long power = 0;
@ -36,8 +35,6 @@ public class TileEntityMachineBattery extends TileEntityMachineBase implements I
private static final int[] slots_top = new int[] {0};
private static final int[] slots_bottom = new int[] {0, 1};
private static final int[] slots_side = new int[] {1};
public int age = 0;
public List<IConsumer> list = new ArrayList();
private String customName;
@ -162,11 +159,13 @@ public class TileEntityMachineBattery extends TileEntityMachineBase implements I
public void updateEntity() {
if(worldObj.getBlock(xCoord, yCoord, zCoord) instanceof MachineBattery && !worldObj.isRemote) {
this.maxPower = ((MachineBattery)worldObj.getBlock(xCoord, yCoord, zCoord)).maxPower;
short mode = (short) this.getRelevantMode();
//////////////////////////////////////////////////////////////////////
/*for(ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
for(ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
TileEntity te = worldObj.getTileEntity(xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ);
@ -195,20 +194,8 @@ public class TileEntityMachineBattery extends TileEntityMachineBase implements I
if(con.getPowerNet() != null && !con.getPowerNet().isSubscribed(this))
con.getPowerNet().subscribe(this);
}
}*/
//////////////////////////////////////////////////////////////////////
this.maxPower = ((MachineBattery)worldObj.getBlock(xCoord, yCoord, zCoord)).maxPower;
if(mode == 1 || mode == 2) {
age++;
if(age >= 20) {
age = 0;
}
if(age == 9 || age == 19)
ffgeuaInit();
}
//////////////////////////////////////////////////////////////////////
power = Library.chargeTEFromItems(slots, 0, power, maxPower);
power = Library.chargeItemsFromTE(slots, 1, power, maxPower);
@ -240,41 +227,10 @@ public class TileEntityMachineBattery extends TileEntityMachineBase implements I
this.redHigh = nbt.getShort("redHigh");
}
@Override
public void setPower(long i) {
power = i;
}
@Override
public long getPower() {
return power;
}
@Override
public void ffgeua(int x, int y, int z, boolean newTact) {
Library.ffgeua(x, y, z, newTact, this, worldObj);
}
@Override
public void ffgeuaInit() {
ffgeua(this.xCoord, this.yCoord + 1, this.zCoord, getTact());
ffgeua(this.xCoord, this.yCoord - 1, this.zCoord, getTact());
ffgeua(this.xCoord - 1, this.yCoord, this.zCoord, getTact());
ffgeua(this.xCoord + 1, this.yCoord, this.zCoord, getTact());
ffgeua(this.xCoord, this.yCoord, this.zCoord - 1, getTact());
ffgeua(this.xCoord, this.yCoord, this.zCoord + 1, getTact());
}
@Override
public boolean getTact() {
if(age >= 0 && age < 10)
{
return true;
}
return false;
}
public short getRelevantMode() {
@ -293,26 +249,6 @@ public class TileEntityMachineBattery extends TileEntityMachineBase implements I
return maxPower;
}
@Override
public long getSPower() {
return power;
}
@Override
public void setSPower(long i) {
this.power = i;
}
@Override
public List<IConsumer> getList() {
return list;
}
@Override
public void clearList() {
this.list.clear();
}
/*
* SATAN - TECH
@ -337,4 +273,8 @@ public class TileEntityMachineBattery extends TileEntityMachineBase implements I
return true;
}
@Override
public void setPower(long power) {
this.power = power;
}
}