fix merge
This commit is contained in:
commit
10aa2f2ffb
33 changed files with 507 additions and 859 deletions
|
@ -39,7 +39,7 @@ public class GuiThermalGenerator extends GuiContainer
|
|||
String name = I18n.translateToLocal("tile.techreborn.thermalGenerator.name");
|
||||
this.fontRendererObj.drawString(name, this.xSize / 2 - this.fontRendererObj.getStringWidth(name) / 2, 6,
|
||||
4210752);
|
||||
this.fontRendererObj.drawString(I18n.translateToLocalFormatted("container.inventory", new Object[0]), 8,
|
||||
this.fontRendererObj.drawString(I18n.translateToLocalFormatted("container.inventory"), 8,
|
||||
this.ySize - 96 + 2, 4210752);
|
||||
this.fontRendererObj.drawString("Liquid Amount", 10, 20, 16448255);
|
||||
this.fontRendererObj.drawString(tile.tank.getFluidAmount() + "", 10, 30, 16448255);
|
||||
|
|
|
@ -4,12 +4,10 @@ import net.minecraft.entity.player.EntityPlayer;
|
|||
import net.minecraft.init.MobEffects;
|
||||
import net.minecraft.inventory.EntityEquipmentSlot;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.fml.common.eventhandler.EventPriority;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.gameevent.TickEvent;
|
||||
import techreborn.init.ModItems;
|
||||
import techreborn.power.PowerTickEvent;
|
||||
|
||||
public class TRTickHandler
|
||||
{
|
||||
|
@ -32,14 +30,4 @@ public class TRTickHandler
|
|||
previouslyWearing = chestslot;
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void worldTick(TickEvent.WorldTickEvent e)
|
||||
{
|
||||
if (e.world.isRemote)
|
||||
{
|
||||
return;
|
||||
}
|
||||
MinecraftForge.EVENT_BUS.post(new PowerTickEvent());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -889,10 +889,10 @@ public class ModRecipes
|
|||
}
|
||||
}
|
||||
|
||||
CraftingHelper.addShapedOreRecipe(ItemParts.getPartByName("nichromeHeatingCoil"), " N ", "NCN", " N ", 'N',
|
||||
TechRebornAPI.addRollingOreMachinceRecipe(ItemParts.getPartByName("nichromeHeatingCoil"), " N ", "NCN", " N ", 'N',
|
||||
"ingotNickel", 'C', "ingotChrome");
|
||||
|
||||
CraftingHelper.addShapedOreRecipe(ItemParts.getPartByName("kanthalHeatingCoil"), "III", "CAA", "AAA", 'I',
|
||||
TechRebornAPI.addRollingOreMachinceRecipe(ItemParts.getPartByName("kanthalHeatingCoil"), "III", "CAA", "AAA", 'I',
|
||||
"ingotSteel", 'C', "ingotChrome", 'A', "ingotAluminum");
|
||||
|
||||
CraftingHelper.addShapedOreRecipe(ItemParts.getPartByName("heliumCoolantSimple"), " T ", "TCT", " T ", 'T',
|
||||
|
@ -1072,8 +1072,7 @@ public class ModRecipes
|
|||
.addShapedOreRecipe(new ItemStack(ModBlocks.LesuStorage), "LLL", "LCL", "LLL", 'L', "blockLapis", 'C',
|
||||
"circuitBasic");
|
||||
|
||||
TechRebornAPI
|
||||
.addRollingOreMachinceRecipe(ItemParts.getPartByName("cupronickelHeatingCoil"), "NCN", "C C", "NCN",
|
||||
TechRebornAPI.addRollingOreMachinceRecipe(ItemParts.getPartByName("cupronickelHeatingCoil"), "NCN", "C C", "NCN",
|
||||
'N', "ingotCupronickel", 'C', "ingotCopper");
|
||||
|
||||
RecipeHandler.addRecipe(new VacuumFreezerRecipe(ItemIngots.getIngotByName("hotTungstensteel"),
|
||||
|
@ -2313,7 +2312,7 @@ public class ModRecipes
|
|||
getOre("ic2Extractor"));
|
||||
|
||||
CraftingHelper.addShapedOreRecipe(new ItemStack(ModBlocks.BlastFurnace), "CHC", "HBH", "FHF", 'H',
|
||||
new ItemStack(ModItems.parts, 1, 17), 'C', "circuitAdvanced", 'B',
|
||||
ItemParts.getPartByName("cupronickelHeatingCoil"), 'C', "circuitAdvanced", 'B',
|
||||
BlockMachineFrame.getFrameByName("advancedMachine", 1), 'F', ModBlocks.ElectricFurnace);
|
||||
|
||||
CraftingHelper.addShapedOreRecipe(new ItemStack(ModBlocks.IndustrialGrinder), "ECP", "GGG", "CBC", 'E',
|
||||
|
@ -2346,7 +2345,7 @@ public class ModRecipes
|
|||
CraftingHelper
|
||||
.addShapedOreRecipe(new ItemStack(ModBlocks.RollingMachine), "PCP", "MBM", "PCP", 'P', Blocks.PISTON,
|
||||
'C', "circuitAdvanced", 'M', ModBlocks.Compressor, 'B',
|
||||
BlockMachineFrame.getFrameByName("machine", 1));
|
||||
"machineBlockAdvanced");
|
||||
|
||||
// CraftingHelper.addShapedOreRecipe(new
|
||||
// ItemStack(ModBlocks.ElectricCraftingTable),
|
||||
|
|
|
@ -30,8 +30,6 @@ public class TechRebornParts implements ICompatModule
|
|||
@Nullable
|
||||
public static Item fluidPipe;
|
||||
|
||||
public static HashMap<EnumCableType, Class<? extends CableMultipart>> multipartHashMap = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public void preInit(FMLPreInitializationEvent event)
|
||||
{
|
||||
|
@ -39,17 +37,13 @@ public class TechRebornParts implements ICompatModule
|
|||
}
|
||||
|
||||
@Override
|
||||
public void init(FMLInitializationEvent event)
|
||||
{
|
||||
for (EnumCableType cableType : EnumCableType.values())
|
||||
{
|
||||
multipartHashMap.put(cableType, cableType.cableClass);
|
||||
MultipartRegistry.registerPart(cableType.cableClass, "techreborn:cable." + cableType.name());
|
||||
}
|
||||
public void init(FMLInitializationEvent event) {
|
||||
|
||||
cables = new ItemCables();
|
||||
cables.setRegistryName("cables");
|
||||
GameRegistry.register(cables);
|
||||
|
||||
MultipartRegistry.registerPart(CableMultipart.class, "techreborn:cable");
|
||||
MultipartRegistry.registerPart(EmptyFluidPipe.class, "techreborn:fluidpipe.empty");
|
||||
MultipartRegistry.registerPart(InsertingFluidPipe.class, "techreborn:fluidpipe.inserting");
|
||||
MultipartRegistry.registerPart(ExtractingFluidPipe.class, "techreborn:fluidpipe.extracting");
|
||||
|
|
|
@ -1,9 +1,5 @@
|
|||
package techreborn.parts.powerCables;
|
||||
|
||||
import reborncore.mcmultipart.MCMultiPartMod;
|
||||
import reborncore.mcmultipart.microblock.IMicroblock;
|
||||
import reborncore.mcmultipart.multipart.*;
|
||||
import reborncore.mcmultipart.raytrace.PartMOP;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.properties.IProperty;
|
||||
|
@ -15,8 +11,13 @@ import net.minecraft.entity.Entity;
|
|||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.*;
|
||||
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.util.text.TextFormatting;
|
||||
|
@ -29,11 +30,12 @@ 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.init.ModSounds;
|
||||
import reborncore.mcmultipart.MCMultiPartMod;
|
||||
import reborncore.mcmultipart.microblock.IMicroblock;
|
||||
import reborncore.mcmultipart.multipart.*;
|
||||
import reborncore.mcmultipart.raytrace.PartMOP;
|
||||
import techreborn.parts.TechRebornParts;
|
||||
import techreborn.parts.walia.IPartWaliaProvider;
|
||||
import techreborn.power.TRPowerNet;
|
||||
import techreborn.utils.damageSources.ElectrialShockSource;
|
||||
|
||||
import java.util.*;
|
||||
|
@ -41,7 +43,7 @@ import java.util.*;
|
|||
/**
|
||||
* Created by modmuss50 on 02/03/2016.
|
||||
*/
|
||||
public abstract class CableMultipart extends Multipart
|
||||
public class CableMultipart extends Multipart
|
||||
implements INormallyOccludingPart, ISlottedPart, ITickable, ICableType, IPartWaliaProvider {
|
||||
|
||||
public static final IUnlistedProperty<Boolean> UP = Properties.toUnlisted(PropertyBool.create("up"));
|
||||
|
@ -55,10 +57,14 @@ public abstract class CableMultipart extends Multipart
|
|||
public float center = 0.6F;
|
||||
public float offset = 0.10F;
|
||||
public Map<EnumFacing, BlockPos> connectedSides;
|
||||
public int ticks = 0;
|
||||
public ItemStack stack;
|
||||
public TRPowerNet mergeWith = null;
|
||||
private TRPowerNet network;
|
||||
public double lastEnergyPacket;
|
||||
public EnumCableType cableType = EnumCableType.ICOPPER;
|
||||
|
||||
public CableMultipart(EnumCableType cableType) {
|
||||
this.cableType = cableType;
|
||||
connectedSides = new HashMap<>();
|
||||
refreshBounding();
|
||||
}
|
||||
|
||||
public CableMultipart() {
|
||||
connectedSides = new HashMap<>();
|
||||
|
@ -144,7 +150,6 @@ public abstract class CableMultipart extends Multipart
|
|||
@Override
|
||||
public void onRemoved() {
|
||||
super.onRemoved();
|
||||
removeFromNetwork();
|
||||
for (EnumFacing dir : EnumFacing.VALUES) {
|
||||
CableMultipart multipart = getPartFromWorld(getWorld(), getPos().offset(dir), dir);
|
||||
if (multipart != null) {
|
||||
|
@ -153,12 +158,6 @@ public abstract class CableMultipart extends Multipart
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUnloaded() {
|
||||
super.onUnloaded();
|
||||
removeFromNetwork();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addOcclusionBoxes(List<AxisAlignedBB> list) {
|
||||
for (EnumFacing dir : EnumFacing.VALUES) {
|
||||
|
@ -172,13 +171,9 @@ public abstract class CableMultipart extends Multipart
|
|||
public void onNeighborBlockChange(Block block) {
|
||||
super.onNeighborBlockChange(block);
|
||||
nearByChange();
|
||||
|
||||
}
|
||||
|
||||
public void nearByChange() {
|
||||
if (network == null) {
|
||||
findAndJoinNetwork(getWorld(), getPos());
|
||||
}
|
||||
checkConnectedSides();
|
||||
for (EnumFacing direction : EnumFacing.VALUES) {
|
||||
BlockPos blockPos = getPos().offset(direction);
|
||||
|
@ -188,7 +183,6 @@ public abstract class CableMultipart extends Multipart
|
|||
part.checkConnectedSides();
|
||||
}
|
||||
}
|
||||
TRPowerNet.buildEndpoint(network);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -258,18 +252,14 @@ public abstract class CableMultipart extends Multipart
|
|||
@Override
|
||||
public void update() {
|
||||
if (getWorld() != null) {
|
||||
if(lastEnergyPacket > 0)
|
||||
--lastEnergyPacket;
|
||||
|
||||
if (getWorld().getTotalWorldTime() % 80 == 0) {
|
||||
checkConnectedSides();
|
||||
}
|
||||
}
|
||||
if (network == null) {
|
||||
this.findAndJoinNetwork(getWorld(), getPos());
|
||||
} else {
|
||||
if (mergeWith != null) {
|
||||
getNetwork().merge(mergeWith);
|
||||
mergeWith = null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -294,7 +284,7 @@ public abstract class CableMultipart extends Multipart
|
|||
}
|
||||
|
||||
public Material getMaterial() {
|
||||
return Material.CLOTH;
|
||||
return getCableType().material;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -307,97 +297,16 @@ public abstract class CableMultipart extends Multipart
|
|||
@Override
|
||||
public void onEntityCollided(Entity entity) {
|
||||
if (getCableType().canKill && entity instanceof EntityLivingBase) {
|
||||
if (network != null) {
|
||||
if (network.getEnergy() != 0) {
|
||||
if (ConfigTechReborn.UninsulatedElectocutionDamage) {
|
||||
if (getCableType() == EnumCableType.HV) {
|
||||
entity.setFire(1);
|
||||
}
|
||||
network.setEnergy(-1);
|
||||
entity.attackEntityFrom(new ElectrialShockSource(), 1F);
|
||||
}
|
||||
if (ConfigTechReborn.UninsulatedElectocutionSound) {
|
||||
getWorld().playSound(null, entity.posX, entity.posY,
|
||||
entity.posZ, ModSounds.shock,
|
||||
SoundCategory.BLOCKS, 0.6F, 1F);
|
||||
}
|
||||
if (ConfigTechReborn.UninsulatedElectocutionParticle) {
|
||||
getWorld().spawnParticle(EnumParticleTypes.CRIT, entity.posX, entity.posY, entity.posZ, 0,
|
||||
0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
entity.attackEntityFrom(new ElectrialShockSource(), (float) (lastEnergyPacket / 16F));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEntityStanding(Entity entity) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getPickBlock(EntityPlayer player, PartMOP hit) {
|
||||
return new ItemStack(TechRebornParts.cables, 1, getCableType().ordinal());
|
||||
}
|
||||
|
||||
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(TextFormatting.GREEN + "EU Transfer: " +
|
||||
|
@ -416,4 +325,35 @@ public abstract class CableMultipart extends Multipart
|
|||
public boolean canRenderInLayer(BlockRenderLayer layer) {
|
||||
return layer == BlockRenderLayer.CUTOUT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound tag) {
|
||||
tag.setString("CableType", cableType.name());
|
||||
return tag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound tag) {
|
||||
if(tag.hasKey("CableType")) {
|
||||
cableType = EnumCableType.valueOf(tag.getString("CableType"));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeUpdatePacket(PacketBuffer buf) {
|
||||
super.writeUpdatePacket(buf);
|
||||
buf.writeInt(cableType.ordinal());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readUpdatePacket(PacketBuffer buf) {
|
||||
super.readUpdatePacket(buf);
|
||||
cableType = EnumCableType.values()[buf.readInt()];
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumCableType getCableType() {
|
||||
return cableType;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,44 +1,37 @@
|
|||
package techreborn.parts.powerCables;
|
||||
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.util.IStringSerializable;
|
||||
import reborncore.api.power.EnumPowerTier;
|
||||
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
|
||||
{
|
||||
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.MEDIUM, InsulatedGoldCable.class),
|
||||
IHV("insulatedhv", "techreborn:blocks/cables/hv_insulated_cable", 2048, 10.0, false, EnumPowerTier.HIGH, InsulatedHVCable.class);
|
||||
COPPER("copper", "techreborn:blocks/cables/copper_cable", Material.IRON, 128, 12.0, true, EnumPowerTier.LOW),
|
||||
TIN("tin", "techreborn:blocks/cables/tin_cable", Material.IRON, 32, 12.0, true, EnumPowerTier.MEDIUM),
|
||||
GOLD("gold", "techreborn:blocks/cables/gold_cable", Material.IRON, 512, 12.0, true, EnumPowerTier.MEDIUM),
|
||||
HV("hv", "techreborn:blocks/cables/hv_cable", Material.IRON, 2048, 12.0, true, EnumPowerTier.HIGH),
|
||||
GLASSFIBER("glassfiber", "techreborn:blocks/cables/glass_fiber_cable", Material.GLASS, 8192, 12.0, false, EnumPowerTier.HIGH),
|
||||
ICOPPER("insulatedcopper", "techreborn:blocks/cables/copper_insulated_cable", Material.CLOTH, 128, 10.0, false, EnumPowerTier.LOW),
|
||||
IGOLD("insulatedgold", "techreborn:blocks/cables/gold_insulated_cable", Material.CLOTH, 512, 10.0, false, EnumPowerTier.MEDIUM),
|
||||
IHV("insulatedhv", "techreborn:blocks/cables/hv_insulated_cable", Material.CLOTH, 2048, 10.0, false, EnumPowerTier.HIGH);
|
||||
|
||||
public Material material;
|
||||
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 EnumPowerTier tier;
|
||||
private String friendlyName;
|
||||
|
||||
EnumCableType(String friendlyName, String textureName, int transferRate, double cableThickness, boolean canKill,
|
||||
EnumPowerTier tier, Class<? extends CableMultipart> cableClass)
|
||||
EnumCableType(String friendlyName, String textureName, Material material, int transferRate, double cableThickness, boolean canKill,
|
||||
EnumPowerTier tier)
|
||||
{
|
||||
this.friendlyName = friendlyName;
|
||||
this.textureName = textureName;
|
||||
this.material = material;
|
||||
this.transferRate = transferRate;
|
||||
this.cableThickness = cableThickness / 2;
|
||||
this.canKill = canKill;
|
||||
this.cableClass = cableClass;
|
||||
this.tier = tier;
|
||||
}
|
||||
|
||||
|
|
|
@ -40,17 +40,8 @@ public class ItemCables extends ItemMultiPart implements ITexturedItem
|
|||
}
|
||||
|
||||
@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;
|
||||
public IMultipart createPart(World world, BlockPos pos, EnumFacing side, Vec3d hit, ItemStack stack, EntityPlayer player) {
|
||||
return new CableMultipart(EnumCableType.values()[stack.getItemDamage()]);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,16 +0,0 @@
|
|||
package techreborn.parts.powerCables.types;
|
||||
|
||||
import techreborn.parts.powerCables.CableMultipart;
|
||||
import techreborn.parts.powerCables.EnumCableType;
|
||||
|
||||
/**
|
||||
* Created by modmuss50 on 05/03/2016.
|
||||
*/
|
||||
public class CopperCable extends CableMultipart
|
||||
{
|
||||
@Override
|
||||
public EnumCableType getCableType()
|
||||
{
|
||||
return EnumCableType.COPPER;
|
||||
}
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
package techreborn.parts.powerCables.types;
|
||||
|
||||
import techreborn.parts.powerCables.CableMultipart;
|
||||
import techreborn.parts.powerCables.EnumCableType;
|
||||
|
||||
/**
|
||||
* Created by modmuss50 on 05/03/2016.
|
||||
*/
|
||||
public class GlassFiberCable extends CableMultipart
|
||||
{
|
||||
@Override
|
||||
public EnumCableType getCableType()
|
||||
{
|
||||
return EnumCableType.GLASSFIBER;
|
||||
}
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
package techreborn.parts.powerCables.types;
|
||||
|
||||
import techreborn.parts.powerCables.CableMultipart;
|
||||
import techreborn.parts.powerCables.EnumCableType;
|
||||
|
||||
/**
|
||||
* Created by modmuss50 on 05/03/2016.
|
||||
*/
|
||||
public class GoldCable extends CableMultipart
|
||||
{
|
||||
@Override
|
||||
public EnumCableType getCableType()
|
||||
{
|
||||
return EnumCableType.GOLD;
|
||||
}
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
package techreborn.parts.powerCables.types;
|
||||
|
||||
import techreborn.parts.powerCables.CableMultipart;
|
||||
import techreborn.parts.powerCables.EnumCableType;
|
||||
|
||||
/**
|
||||
* Created by modmuss50 on 05/03/2016.
|
||||
*/
|
||||
public class HVCable extends CableMultipart
|
||||
{
|
||||
@Override
|
||||
public EnumCableType getCableType()
|
||||
{
|
||||
return EnumCableType.HV;
|
||||
}
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
package techreborn.parts.powerCables.types;
|
||||
|
||||
import techreborn.parts.powerCables.CableMultipart;
|
||||
import techreborn.parts.powerCables.EnumCableType;
|
||||
|
||||
/**
|
||||
* Created by modmuss50 on 05/03/2016.
|
||||
*/
|
||||
public class InsulatedCopperCable extends CableMultipart
|
||||
{
|
||||
@Override
|
||||
public EnumCableType getCableType()
|
||||
{
|
||||
return EnumCableType.ICOPPER;
|
||||
}
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
package techreborn.parts.powerCables.types;
|
||||
|
||||
import techreborn.parts.powerCables.CableMultipart;
|
||||
import techreborn.parts.powerCables.EnumCableType;
|
||||
|
||||
/**
|
||||
* Created by modmuss50 on 05/03/2016.
|
||||
*/
|
||||
public class InsulatedGoldCable extends CableMultipart
|
||||
{
|
||||
@Override
|
||||
public EnumCableType getCableType()
|
||||
{
|
||||
return EnumCableType.IGOLD;
|
||||
}
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
package techreborn.parts.powerCables.types;
|
||||
|
||||
import techreborn.parts.powerCables.CableMultipart;
|
||||
import techreborn.parts.powerCables.EnumCableType;
|
||||
|
||||
/**
|
||||
* Created by modmuss50 on 05/03/2016.
|
||||
*/
|
||||
public class InsulatedHVCable extends CableMultipart
|
||||
{
|
||||
@Override
|
||||
public EnumCableType getCableType()
|
||||
{
|
||||
return EnumCableType.IHV;
|
||||
}
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
package techreborn.parts.powerCables.types;
|
||||
|
||||
import techreborn.parts.powerCables.CableMultipart;
|
||||
import techreborn.parts.powerCables.EnumCableType;
|
||||
|
||||
/**
|
||||
* Created by modmuss50 on 05/03/2016.
|
||||
*/
|
||||
public class TinCable extends CableMultipart
|
||||
{
|
||||
@Override
|
||||
public EnumCableType getCableType()
|
||||
{
|
||||
return EnumCableType.TIN;
|
||||
}
|
||||
}
|
241
src/main/java/techreborn/power/PowerNet.java
Normal file
241
src/main/java/techreborn/power/PowerNet.java
Normal file
|
@ -0,0 +1,241 @@
|
|||
package techreborn.power;
|
||||
|
||||
import cofh.api.energy.IEnergyReceiver;
|
||||
import com.google.common.collect.Lists;
|
||||
import ic2.api.energy.tile.IEnergySink;
|
||||
import net.darkhax.tesla.api.ITeslaConsumer;
|
||||
import net.darkhax.tesla.capability.TeslaCapabilities;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.common.Loader;
|
||||
import reborncore.api.power.IEnergyInterfaceTile;
|
||||
import reborncore.common.RebornCoreConfig;
|
||||
import reborncore.common.powerSystem.TilePowerAcceptor;
|
||||
import reborncore.mcmultipart.block.TileMultipartContainer;
|
||||
import reborncore.mcmultipart.multipart.ISlottedPart;
|
||||
import reborncore.mcmultipart.multipart.PartSlot;
|
||||
import techreborn.parts.powerCables.CableMultipart;
|
||||
import techreborn.parts.powerCables.EnumCableType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
public class PowerNet {
|
||||
|
||||
|
||||
/**
|
||||
* Same as {@link #dispatchEnergyPacketRecursively(World, ArrayList, BlockPos, boolean, double)}
|
||||
* But not simulated and excluding source block
|
||||
* @param world the world to dispatch in
|
||||
* @param energyAmount energy units to dispatch
|
||||
* @return dispatched energy units
|
||||
*/
|
||||
public static double dispatchEnergyPacket(World world, BlockPos source, double energyAmount) {
|
||||
return dispatchEnergyPacketRecursively(world, Lists.newArrayList(source), source, false, energyAmount);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatches energy packet recursively through wires to all connected decives
|
||||
* @param world the world to dispatch in
|
||||
* @param excludes blocks to exclude from checking. as example, start block
|
||||
* @param blockPos block pos to start checking
|
||||
* @param maxEnergy energy units to dispatch
|
||||
* @param simulate true if dispatch is only simulated
|
||||
* @return dispatched energy units
|
||||
*/
|
||||
public static double dispatchEnergyPacketRecursively(World world, ArrayList<BlockPos> excludes, BlockPos blockPos, boolean simulate, final double maxEnergy) {
|
||||
double energyLeft = maxEnergy;
|
||||
Collection<EnumFacing> connections = Lists.newArrayList(EnumFacing.VALUES);
|
||||
|
||||
//Workaround for multipart cables
|
||||
CableMultipart selfCable = getWire(world, blockPos);
|
||||
|
||||
if(selfCable != null) {
|
||||
connections = selfCable.connectedSides.keySet();
|
||||
}
|
||||
|
||||
TileEntity tileEntity = world.getTileEntity(blockPos);
|
||||
if(tileEntity instanceof TilePowerAcceptor) {
|
||||
for(EnumFacing facing : EnumFacing.VALUES) {
|
||||
if(!((TilePowerAcceptor) tileEntity).canProvideEnergy(facing))
|
||||
connections.remove(facing);
|
||||
}
|
||||
}
|
||||
|
||||
for(EnumFacing facing : connections) {
|
||||
BlockPos offsetPos = blockPos.offset(facing);
|
||||
if(!excludes.contains(offsetPos)) {
|
||||
excludes.add(offsetPos);
|
||||
if(isWire(world, offsetPos)) {
|
||||
CableMultipart cable = getWire(world, offsetPos);
|
||||
EnumCableType cableType = cable.getCableType();
|
||||
double transferRate = cableType.transferRate;
|
||||
double maxPacket = transferRate > maxEnergy ? maxEnergy : transferRate;
|
||||
energyLeft -= dispatchEnergyPacketRecursively(world, excludes, offsetPos, simulate, maxPacket);
|
||||
if(energyLeft == 0) {
|
||||
if(selfCable != null)
|
||||
selfCable.lastEnergyPacket = maxEnergy * 1.3F;
|
||||
return maxEnergy;
|
||||
}
|
||||
} else {
|
||||
PowerNetReceiver receiver = getReceiver(world, facing.getOpposite(), offsetPos);
|
||||
if(receiver != null) {
|
||||
energyLeft -= receiver.receiveEnergy(energyLeft, simulate);
|
||||
if(energyLeft == 0) {
|
||||
if(selfCable != null)
|
||||
selfCable.lastEnergyPacket = maxEnergy * 1.3F;
|
||||
return maxEnergy;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
double energyDispatched = maxEnergy - energyLeft;
|
||||
if(selfCable != null)
|
||||
selfCable.lastEnergyPacket = energyDispatched * 1.3F;
|
||||
return energyDispatched;
|
||||
}
|
||||
|
||||
|
||||
//////////////////// Wire utilities ////////////////////
|
||||
|
||||
public static boolean isWire(World world, BlockPos blockPos) {
|
||||
return getWire(world, blockPos) != null;
|
||||
}
|
||||
|
||||
public static CableMultipart getWire(World world, BlockPos pos) {
|
||||
TileEntity tileEntity = world.getTileEntity(pos);
|
||||
if(tileEntity instanceof TileMultipartContainer) {
|
||||
TileMultipartContainer multipart = (TileMultipartContainer) tileEntity;
|
||||
ISlottedPart centerPart = multipart.getPartInSlot(PartSlot.CENTER);
|
||||
if(centerPart instanceof CableMultipart)
|
||||
return (CableMultipart) centerPart;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
//////////////////// Power Net Sources functionality ////////////////////
|
||||
//TODO
|
||||
|
||||
|
||||
|
||||
|
||||
//////////////////// Power Net Receivers functionality ////////////////////
|
||||
|
||||
public static PowerNetReceiver getReceiver(World world, EnumFacing side, BlockPos pos) {
|
||||
TileEntity tileEntity = world.getTileEntity(pos);
|
||||
if(Loader.isModLoaded("IC2") && RebornCoreConfig.getRebornPower().eu()) {
|
||||
PowerNetReceiver ic2receiver = getIC2Receiver(tileEntity, side);
|
||||
if(ic2receiver != null) return ic2receiver;
|
||||
}
|
||||
if(Loader.isModLoaded("Tesla") && RebornCoreConfig.getRebornPower().tesla()) {
|
||||
PowerNetReceiver teslaReceiver = getTeslaReceiver(tileEntity, side);
|
||||
if(teslaReceiver != null) return teslaReceiver;
|
||||
}
|
||||
if(RebornCoreConfig.getRebornPower().rf()) {
|
||||
PowerNetReceiver rfReceiver = getRFReceiver(tileEntity, side);
|
||||
if(rfReceiver != null) return rfReceiver;
|
||||
}
|
||||
if(RebornCoreConfig.getRebornPower().internal()) {
|
||||
PowerNetReceiver internalReceiver = getInternalReceiver(tileEntity, side);
|
||||
if(internalReceiver != null) return internalReceiver;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static PowerNetReceiver getInternalReceiver(TileEntity tileEntity, EnumFacing side) {
|
||||
if(tileEntity instanceof IEnergyInterfaceTile) {
|
||||
IEnergyInterfaceTile energyInterface = (IEnergyInterfaceTile) tileEntity;
|
||||
return new PowerNetReceiver(
|
||||
(energy, simulated) -> {
|
||||
if(energyInterface.canAcceptEnergy(side))
|
||||
return energyInterface.addEnergy(energy, simulated);
|
||||
return 0.0;
|
||||
});
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static PowerNetReceiver getIC2Receiver(TileEntity tileEntity, EnumFacing side) {
|
||||
if(tileEntity instanceof IEnergySink) {
|
||||
IEnergySink acceptor = (IEnergySink) tileEntity;
|
||||
return new PowerNetReceiver(
|
||||
(energy, simulated) -> {
|
||||
if(simulated) {
|
||||
double max = acceptor.getDemandedEnergy();
|
||||
return max > energy ? energy : max;
|
||||
}
|
||||
return energy - acceptor.injectEnergy(side, energy, acceptor.getSinkTier());
|
||||
});
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static PowerNetReceiver getTeslaReceiver(TileEntity tileEntity, EnumFacing side) {
|
||||
if(tileEntity.hasCapability(TeslaCapabilities.CAPABILITY_CONSUMER, side)) {
|
||||
ITeslaConsumer consumer = tileEntity.getCapability(TeslaCapabilities.CAPABILITY_CONSUMER, side);
|
||||
return new PowerNetReceiver(
|
||||
(energy, simulated) -> {
|
||||
long teslaEnergy = eu2tesla(energy);
|
||||
return tesla2eu(consumer.givePower(teslaEnergy, simulated));
|
||||
});
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static PowerNetReceiver getRFReceiver(TileEntity tileEntity, EnumFacing side) {
|
||||
if(tileEntity instanceof IEnergyReceiver) {
|
||||
IEnergyReceiver receiver = (IEnergyReceiver) tileEntity;
|
||||
return new PowerNetReceiver(
|
||||
(energy, simulated) -> {
|
||||
int rfEnergy = eu2rf(energy);
|
||||
return rf2eu(receiver.receiveEnergy(side, rfEnergy, simulated));
|
||||
});
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
//////////////////// Energy Conversion utils ////////////////////
|
||||
|
||||
public static double rf2eu(int rf) {
|
||||
return rf / 4F;
|
||||
}
|
||||
|
||||
public static int eu2rf(double eu) {
|
||||
return (int) Math.floor(eu * 4F);
|
||||
}
|
||||
|
||||
public static long eu2tesla(double eu) {
|
||||
return (long) Math.floor(eu / 3.75F);
|
||||
}
|
||||
|
||||
public static double tesla2eu(long tesla) {
|
||||
return tesla * 3.75F;
|
||||
}
|
||||
|
||||
|
||||
public static class PowerNetReceiver {
|
||||
|
||||
private final BiFunction<Double, Boolean, Double> receiveEnergy;
|
||||
|
||||
public PowerNetReceiver(BiFunction<Double, Boolean, Double> receiveEnergy) {
|
||||
this.receiveEnergy = receiveEnergy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends given amount fo EU to receiver
|
||||
* @param max max eu to receive
|
||||
* @return eu received
|
||||
*/
|
||||
public double receiveEnergy(double max, boolean simulated) {
|
||||
return receiveEnergy.apply(max, simulated);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
package techreborn.power;
|
||||
|
||||
import net.minecraftforge.fml.common.eventhandler.Event;
|
||||
|
||||
public class PowerTickEvent extends Event
|
||||
{
|
||||
public PowerTickEvent()
|
||||
{
|
||||
}
|
||||
}
|
|
@ -1,358 +0,0 @@
|
|||
package techreborn.power;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.entity.item.EntityTNTPrimed;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import reborncore.api.power.IEnergyInterfaceTile;
|
||||
import techreborn.parts.powerCables.CableMultipart;
|
||||
import techreborn.parts.powerCables.EnumCableType;
|
||||
|
||||
public class TRPowerNet
|
||||
{
|
||||
public ArrayList<EnergyHandler> endpoints = new ArrayList();
|
||||
int tick = 0;
|
||||
EnumCableType cableType;
|
||||
private ArrayList<CableMultipart> cables = new ArrayList();
|
||||
private int energy = 0;
|
||||
|
||||
public TRPowerNet(EnumCableType cableType)
|
||||
{
|
||||
this.cableType = cableType;
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
}
|
||||
|
||||
public static void buildEndpoint(TRPowerNet net)
|
||||
{
|
||||
ArrayList<CableMultipart> parts = new ArrayList<>();
|
||||
ArrayList<CableMultipart> partsToMerge = new ArrayList<>();
|
||||
parts.addAll(net.cables);
|
||||
for (CableMultipart cable : parts)
|
||||
{
|
||||
for (EnumFacing facing : EnumFacing.VALUES)
|
||||
{
|
||||
BlockPos pos = cable.getPos().offset(facing);
|
||||
TileEntity tile = cable.getWorld().getTileEntity(pos);
|
||||
if (tile != null && tile instanceof IEnergyInterfaceTile)
|
||||
{
|
||||
IEnergyInterfaceTile eit = (IEnergyInterfaceTile) tile;
|
||||
net.addConnection(eit, facing);
|
||||
}
|
||||
CableMultipart cableMultipart = CableMultipart.getPartFromWorld(cable.getWorld(), pos, null);
|
||||
if (cableMultipart != null)
|
||||
{
|
||||
if (cableMultipart.getNetwork() != net)
|
||||
{
|
||||
partsToMerge.add(cableMultipart);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (CableMultipart cableMultipart : partsToMerge)
|
||||
{
|
||||
cableMultipart.mergeWith = net;
|
||||
}
|
||||
net.checkAndRemoveOldEndpoints();
|
||||
}
|
||||
|
||||
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 (EnergyHandler ei : endpoints)
|
||||
{
|
||||
if (ei.isCollectible())
|
||||
{
|
||||
collectibles.add(ei);
|
||||
}
|
||||
if (ei.isInsertible())
|
||||
{
|
||||
insertibles.add(ei);
|
||||
}
|
||||
}
|
||||
|
||||
if (energy < cableType.transferRate * cables.size())
|
||||
{
|
||||
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();
|
||||
this.checkAndRemoveOldEndpoints();
|
||||
}
|
||||
|
||||
public void checkAndRemoveOldEndpoints()
|
||||
{
|
||||
List<EnergyHandler> deadHandlers = new ArrayList<>();
|
||||
for (EnergyHandler energyHandler : endpoints)
|
||||
{
|
||||
TileEntity tile = (TileEntity) energyHandler.tile;
|
||||
if (tile.getWorld().getTileEntity(tile.getPos()) == null)
|
||||
{
|
||||
deadHandlers.add(energyHandler);
|
||||
} else
|
||||
{
|
||||
boolean hasNet = false;
|
||||
for (EnumFacing facing : EnumFacing.VALUES)
|
||||
{
|
||||
BlockPos pos = tile.getPos().offset(facing);
|
||||
CableMultipart multipart = CableMultipart.getPartFromWorld(tile.getWorld(), pos, facing);
|
||||
if (multipart != null && multipart.getNetwork() == this)
|
||||
{
|
||||
hasNet = true;
|
||||
}
|
||||
}
|
||||
if (!hasNet)
|
||||
{
|
||||
deadHandlers.add(energyHandler);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
endpoints.removeAll(deadHandlers);
|
||||
}
|
||||
|
||||
public 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(false);
|
||||
MinecraftForge.EVENT_BUS.unregister(this);
|
||||
}
|
||||
|
||||
public int getEnergy()
|
||||
{
|
||||
return energy;
|
||||
}
|
||||
|
||||
public void setEnergy(int energy)
|
||||
{
|
||||
energy += energy;
|
||||
if (energy < 0)
|
||||
{
|
||||
energy = 0;
|
||||
}
|
||||
}
|
||||
|
||||
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 (EnergyHandler ei : n.endpoints)
|
||||
{
|
||||
endpoints.add(ei);
|
||||
}
|
||||
n.clear(false);
|
||||
for (int i = 0; i < li.size(); i++)
|
||||
{
|
||||
CableMultipart wire = li.get(i);
|
||||
wire.setNetwork(this);
|
||||
}
|
||||
checkAndRemoveOldEndpoints();
|
||||
MinecraftForge.EVENT_BUS.unregister(n);
|
||||
}
|
||||
}
|
||||
|
||||
private EnergyHandler getHandleFrom(IEnergyInterfaceTile tile)
|
||||
{
|
||||
for (EnergyHandler ei : endpoints)
|
||||
{
|
||||
if (ei.tile == 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);
|
||||
}
|
||||
|
||||
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 final EnumCableType type;
|
||||
private EnumFacing side;
|
||||
|
||||
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(side.getOpposite()))
|
||||
{
|
||||
int collect = (int) Math.min(max, Math.min(tile.getMaxOutput(), tile.getEnergy()));
|
||||
total = (int) tile.useEnergy(collect, false);
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
public int addEnergy(int max)
|
||||
{
|
||||
int total = 0;
|
||||
if (tile.canAcceptEnergy(side.getOpposite()) && max > 0)
|
||||
{
|
||||
if (type.tier.ordinal() > tile.getTier().ordinal() && max > tile.getMaxInput())
|
||||
{
|
||||
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(side.getOpposite()) && tile.getEnergy() != 0)
|
||||
{
|
||||
return (int) Math.min(tile.getMaxOutput(), tile.getEnergy());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int getTotalInsertible()
|
||||
{
|
||||
int total = 0;
|
||||
if (tile.canAcceptEnergy(side.getOpposite()) && tile.getMaxPower() - tile.getEnergy() != 0)
|
||||
{
|
||||
total += tile.addEnergy(type.transferRate, true);
|
||||
}
|
||||
|
||||
return total;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -13,6 +13,7 @@ import reborncore.common.util.ItemUtils;
|
|||
import techreborn.api.reactor.FusionReactorRecipe;
|
||||
import techreborn.api.reactor.FusionReactorRecipeHelper;
|
||||
import techreborn.init.ModBlocks;
|
||||
import techreborn.power.PowerNet;
|
||||
|
||||
public class TileEntityFusionController extends TilePowerAcceptor implements IInventoryProvider
|
||||
{
|
||||
|
@ -36,8 +37,7 @@ public class TileEntityFusionController extends TilePowerAcceptor implements IIn
|
|||
}
|
||||
|
||||
@Override
|
||||
public double getMaxPower()
|
||||
{
|
||||
public double getMaxPower() {
|
||||
return 100000000;
|
||||
}
|
||||
|
||||
|
@ -64,10 +64,8 @@ public class TileEntityFusionController extends TilePowerAcceptor implements IIn
|
|||
}
|
||||
|
||||
@Override
|
||||
public double getMaxInput()
|
||||
{
|
||||
if (hasStartedCrafting)
|
||||
{
|
||||
public double getMaxInput() {
|
||||
if (hasStartedCrafting) {
|
||||
return 0;
|
||||
}
|
||||
return 8192;
|
||||
|
@ -275,6 +273,12 @@ public class TileEntityFusionController extends TilePowerAcceptor implements IIn
|
|||
{
|
||||
inventory.hasChanged = false;
|
||||
}
|
||||
|
||||
if (!worldObj.isRemote && getEnergy() > 0 && hasStartedCrafting) {
|
||||
double maxOutput = getEnergy() > getMaxOutput() ? getMaxOutput() : getEnergy();
|
||||
useEnergy(PowerNet.dispatchEnergyPacket(worldObj, getPos(), maxOutput));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private boolean validateRecipe()
|
||||
|
|
|
@ -18,6 +18,7 @@ import reborncore.common.util.Inventory;
|
|||
import reborncore.common.util.Tank;
|
||||
import techreborn.config.ConfigTechReborn;
|
||||
import techreborn.init.ModBlocks;
|
||||
import techreborn.power.PowerNet;
|
||||
|
||||
public class TileDieselGenerator extends TilePowerAcceptor implements IWrenchable, IFluidHandler, IInventoryProvider
|
||||
{
|
||||
|
@ -131,35 +132,33 @@ public class TileDieselGenerator extends TilePowerAcceptor implements IWrenchabl
|
|||
}
|
||||
|
||||
@Override
|
||||
public void updateEntity()
|
||||
{
|
||||
public void updateEntity() {
|
||||
super.updateEntity();
|
||||
if (!worldObj.isRemote)
|
||||
{
|
||||
if (!worldObj.isRemote) {
|
||||
FluidUtils.drainContainers(this, inventory, 0, 1);
|
||||
FluidUtils.fillContainers(this, inventory, 0, 1, tank.getFluidType());
|
||||
if (tank.getFluidType() != null && getStackInSlot(2) == null)
|
||||
{
|
||||
if (tank.getFluidType() != null && getStackInSlot(2) == null) {
|
||||
inventory.setInventorySlotContents(2, new ItemStack(tank.getFluidType().getBlock()));
|
||||
syncWithAll();
|
||||
} else if (tank.getFluidType() == null && getStackInSlot(2) != null)
|
||||
{
|
||||
} else if (tank.getFluidType() == null && getStackInSlot(2) != null) {
|
||||
setInventorySlotContents(2, null);
|
||||
syncWithAll();
|
||||
}
|
||||
|
||||
if (!tank.isEmpty() && tank.getFluidType() != null
|
||||
&& FluidPowerManager.fluidPowerValues.containsKey(tank.getFluidType()))
|
||||
{
|
||||
&& FluidPowerManager.fluidPowerValues.containsKey(tank.getFluidType())) {
|
||||
double powerIn = FluidPowerManager.fluidPowerValues.get(tank.getFluidType());
|
||||
if (getFreeSpace() >= powerIn)
|
||||
{
|
||||
if (getFreeSpace() >= powerIn) {
|
||||
addEnergy(powerIn, false);
|
||||
tank.drain(1, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!worldObj.isRemote && getEnergy() > 0) {
|
||||
double maxOutput = getEnergy() > getMaxOutput() ? getMaxOutput() : getEnergy();
|
||||
useEnergy(PowerNet.dispatchEnergyPacket(worldObj, getPos(), maxOutput));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -12,6 +12,7 @@ import reborncore.common.powerSystem.TilePowerAcceptor;
|
|||
import reborncore.common.util.Inventory;
|
||||
import techreborn.config.ConfigTechReborn;
|
||||
import techreborn.init.ModBlocks;
|
||||
import techreborn.power.PowerNet;
|
||||
|
||||
public class TileDragonEggSiphoner extends TilePowerAcceptor implements IWrenchable,IInventoryProvider
|
||||
{
|
||||
|
@ -25,18 +26,20 @@ public class TileDragonEggSiphoner extends TilePowerAcceptor implements IWrencha
|
|||
}
|
||||
|
||||
@Override
|
||||
public void updateEntity()
|
||||
{
|
||||
public void updateEntity() {
|
||||
super.updateEntity();
|
||||
|
||||
if (!worldObj.isRemote)
|
||||
{
|
||||
if (!worldObj.isRemote) {
|
||||
if (worldObj.getBlockState(new BlockPos(getPos().getX(), getPos().getY() + 1, getPos().getZ()))
|
||||
.getBlock() == Blocks.DRAGON_EGG)
|
||||
{
|
||||
.getBlock() == Blocks.DRAGON_EGG) {
|
||||
addEnergy(euTick);
|
||||
}
|
||||
}
|
||||
|
||||
if (!worldObj.isRemote && getEnergy() > 0) {
|
||||
double maxOutput = getEnergy() > getMaxOutput() ? getMaxOutput() : getEnergy();
|
||||
useEnergy(PowerNet.dispatchEnergyPacket(worldObj, getPos(), maxOutput));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -17,6 +17,7 @@ import reborncore.common.util.Inventory;
|
|||
import reborncore.common.util.Tank;
|
||||
import techreborn.config.ConfigTechReborn;
|
||||
import techreborn.init.ModBlocks;
|
||||
import techreborn.power.PowerNet;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
@ -144,17 +145,14 @@ public class TileGasTurbine extends TilePowerAcceptor implements IWrenchable, IF
|
|||
}
|
||||
|
||||
@Override
|
||||
public void updateEntity()
|
||||
{
|
||||
public void updateEntity() {
|
||||
super.updateEntity();
|
||||
if (!worldObj.isRemote)
|
||||
{
|
||||
if (!worldObj.isRemote) {
|
||||
FluidUtils.drainContainers(this, inventory, 0, 1);
|
||||
tank.compareAndUpdate();
|
||||
}
|
||||
|
||||
if (tank.getFluidAmount() > 0 && getMaxPower() - getEnergy() >= euTick)
|
||||
{
|
||||
if (tank.getFluidAmount() > 0 && getMaxPower() - getEnergy() >= euTick) {
|
||||
Integer euPerBucket = fluids.get(tank.getFluidType().getName());
|
||||
// float totalTicks = (float)euPerBucket / 8f; //x eu per bucket / 8
|
||||
// eu per tick
|
||||
|
@ -163,20 +161,23 @@ public class TileGasTurbine extends TilePowerAcceptor implements IWrenchable, IF
|
|||
pendingWithdraw += millibucketsPerTick;
|
||||
|
||||
int currentWithdraw = (int) pendingWithdraw; // float --> int
|
||||
// conversion floors
|
||||
// the float
|
||||
// conversion floors
|
||||
// the float
|
||||
pendingWithdraw -= currentWithdraw;
|
||||
|
||||
tank.drain(currentWithdraw, true);
|
||||
addEnergy(euTick);
|
||||
}
|
||||
if (tank.getFluidType() != null && getStackInSlot(2) == null)
|
||||
{
|
||||
if (tank.getFluidType() != null && getStackInSlot(2) == null) {
|
||||
inventory.setInventorySlotContents(2, new ItemStack(tank.getFluidType().getBlock()));
|
||||
} else if (tank.getFluidType() == null && getStackInSlot(2) != null)
|
||||
{
|
||||
} else if (tank.getFluidType() == null && getStackInSlot(2) != null) {
|
||||
setInventorySlotContents(2, null);
|
||||
}
|
||||
|
||||
if (!worldObj.isRemote && getEnergy() > 0) {
|
||||
double maxOutput = getEnergy() > getMaxOutput() ? getMaxOutput() : getEnergy();
|
||||
useEnergy(PowerNet.dispatchEnergyPacket(worldObj, getPos(), maxOutput));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -12,6 +12,7 @@ import reborncore.common.blocks.BlockMachineBase;
|
|||
import reborncore.common.powerSystem.TilePowerAcceptor;
|
||||
import reborncore.common.util.Inventory;
|
||||
import techreborn.init.ModBlocks;
|
||||
import techreborn.power.PowerNet;
|
||||
|
||||
public class TileGenerator extends TilePowerAcceptor implements IWrenchable,IInventoryProvider
|
||||
{
|
||||
|
@ -37,45 +38,41 @@ public class TileGenerator extends TilePowerAcceptor implements IWrenchable,IInv
|
|||
}
|
||||
|
||||
@Override
|
||||
public void updateEntity()
|
||||
{
|
||||
public void updateEntity() {
|
||||
super.updateEntity();
|
||||
if (worldObj.isRemote)
|
||||
{
|
||||
if (worldObj.isRemote) {
|
||||
return;
|
||||
}
|
||||
if (getEnergy() < getMaxPower())
|
||||
{
|
||||
if (burnTime > 0)
|
||||
{
|
||||
if (getEnergy() < getMaxPower()) {
|
||||
if (burnTime > 0) {
|
||||
burnTime--;
|
||||
addEnergy(outputAmount);
|
||||
isBurning = true;
|
||||
}
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
isBurning = false;
|
||||
}
|
||||
|
||||
if (burnTime == 0)
|
||||
{
|
||||
if (burnTime == 0) {
|
||||
updateState();
|
||||
burnTime = totalBurnTime = getItemBurnTime(getStackInSlot(fuelSlot));
|
||||
if (burnTime > 0)
|
||||
{
|
||||
if (burnTime > 0) {
|
||||
updateState();
|
||||
burnItem = getStackInSlot(fuelSlot);
|
||||
if (getStackInSlot(fuelSlot).stackSize == 1)
|
||||
{
|
||||
if (getStackInSlot(fuelSlot).stackSize == 1) {
|
||||
setInventorySlotContents(fuelSlot, null);
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
decrStackSize(fuelSlot, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
lastTickBurning = isBurning;
|
||||
|
||||
if (!worldObj.isRemote && getEnergy() > 0) {
|
||||
double maxOutput = getEnergy() > getMaxOutput() ? getMaxOutput() : getEnergy();
|
||||
useEnergy(PowerNet.dispatchEnergyPacket(worldObj, getPos(), maxOutput));
|
||||
}
|
||||
}
|
||||
|
||||
public void updateState()
|
||||
|
|
|
@ -10,6 +10,7 @@ import reborncore.api.power.EnumPowerTier;
|
|||
import reborncore.common.powerSystem.TilePowerAcceptor;
|
||||
import techreborn.config.ConfigTechReborn;
|
||||
import techreborn.init.ModBlocks;
|
||||
import techreborn.power.PowerNet;
|
||||
|
||||
public class TileHeatGenerator extends TilePowerAcceptor implements IWrenchable
|
||||
{
|
||||
|
@ -22,35 +23,33 @@ public class TileHeatGenerator extends TilePowerAcceptor implements IWrenchable
|
|||
}
|
||||
|
||||
@Override
|
||||
public void updateEntity()
|
||||
{
|
||||
public void updateEntity() {
|
||||
super.updateEntity();
|
||||
|
||||
if (!worldObj.isRemote)
|
||||
{
|
||||
if (!worldObj.isRemote) {
|
||||
if (worldObj.getBlockState(new BlockPos(getPos().getX() + 1, getPos().getY(), getPos().getZ()))
|
||||
.getBlock() == Blocks.LAVA)
|
||||
{
|
||||
.getBlock() == Blocks.LAVA) {
|
||||
addEnergy(euTick);
|
||||
} else if (worldObj.getBlockState(new BlockPos(getPos().getX(), getPos().getY(), getPos().getZ() + 1))
|
||||
.getBlock() == Blocks.LAVA)
|
||||
{
|
||||
.getBlock() == Blocks.LAVA) {
|
||||
addEnergy(euTick);
|
||||
} else if (worldObj.getBlockState(new BlockPos(getPos().getX(), getPos().getY(), getPos().getZ() - 1))
|
||||
.getBlock() == Blocks.LAVA)
|
||||
{
|
||||
.getBlock() == Blocks.LAVA) {
|
||||
addEnergy(euTick);
|
||||
} else if (worldObj.getBlockState(new BlockPos(getPos().getX() - 1, getPos().getY(), getPos().getZ()))
|
||||
.getBlock() == Blocks.LAVA)
|
||||
{
|
||||
.getBlock() == Blocks.LAVA) {
|
||||
addEnergy(euTick);
|
||||
} else if (worldObj.getBlockState(new BlockPos(getPos().getX(), getPos().getY() - 1, getPos().getZ()))
|
||||
.getBlock() == Blocks.LAVA)
|
||||
{
|
||||
.getBlock() == Blocks.LAVA) {
|
||||
addEnergy(euTick);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (!worldObj.isRemote && getEnergy() > 0) {
|
||||
double maxOutput = getEnergy() > getMaxOutput() ? getMaxOutput() : getEnergy();
|
||||
useEnergy(PowerNet.dispatchEnergyPacket(worldObj, getPos(), maxOutput));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -10,6 +10,7 @@ import reborncore.api.power.EnumPowerTier;
|
|||
import reborncore.common.blocks.BlockMachineBase;
|
||||
import reborncore.common.powerSystem.TilePowerAcceptor;
|
||||
import techreborn.config.ConfigTechReborn;
|
||||
import techreborn.power.PowerNet;
|
||||
|
||||
public class TileLightningRod extends TilePowerAcceptor {
|
||||
|
||||
|
@ -23,17 +24,17 @@ public class TileLightningRod extends TilePowerAcceptor {
|
|||
public void update() {
|
||||
super.update();
|
||||
|
||||
if(onStatusHoldTicks > 0)
|
||||
if (onStatusHoldTicks > 0)
|
||||
--onStatusHoldTicks;
|
||||
|
||||
if(onStatusHoldTicks == 0 || getEnergy() <= 0) {
|
||||
if(getBlockType() instanceof BlockMachineBase)
|
||||
if (onStatusHoldTicks == 0 || getEnergy() <= 0) {
|
||||
if (getBlockType() instanceof BlockMachineBase)
|
||||
((BlockMachineBase) getBlockType()).setActive(false, worldObj, pos);
|
||||
onStatusHoldTicks = -1;
|
||||
}
|
||||
|
||||
float weatherStrength = worldObj.getThunderStrength(1.0F);
|
||||
if(weatherStrength > 0.2F) {
|
||||
if (weatherStrength > 0.2F) {
|
||||
//lightStrikeChance = (MAX - (CHANCE * WEATHER_STRENGTH)
|
||||
float lightStrikeChance = ((100F - ConfigTechReborn.LightningRodChance) * 20F);
|
||||
float totalChance = lightStrikeChance * getLightningStrikeMultiplier() * ((1.1F - weatherStrength));
|
||||
|
@ -50,6 +51,10 @@ public class TileLightningRod extends TilePowerAcceptor {
|
|||
}
|
||||
}
|
||||
|
||||
if (!worldObj.isRemote && getEnergy() > 0) {
|
||||
double maxOutput = getEnergy() > getMaxOutput() ? getMaxOutput() : getEnergy();
|
||||
useEnergy(PowerNet.dispatchEnergyPacket(worldObj, getPos(), maxOutput));
|
||||
}
|
||||
}
|
||||
|
||||
public float getLightningStrikeMultiplier() {
|
||||
|
|
|
@ -17,6 +17,7 @@ import reborncore.common.util.Inventory;
|
|||
import reborncore.common.util.Tank;
|
||||
import techreborn.config.ConfigTechReborn;
|
||||
import techreborn.init.ModBlocks;
|
||||
import techreborn.power.PowerNet;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
@ -150,14 +151,12 @@ public class TileSemifluidGenerator extends TilePowerAcceptor implements IWrench
|
|||
}
|
||||
|
||||
@Override
|
||||
public void updateEntity()
|
||||
{
|
||||
public void updateEntity() {
|
||||
super.updateEntity();
|
||||
if (!worldObj.isRemote)
|
||||
FluidUtils.drainContainers(this, inventory, 0, 1);
|
||||
|
||||
if (tank.getFluidAmount() > 0 && getMaxPower() - getEnergy() >= euTick)
|
||||
{
|
||||
if (tank.getFluidAmount() > 0 && getMaxPower() - getEnergy() >= euTick) {
|
||||
Integer euPerBucket = fluids.get(tank.getFluidType().getName());
|
||||
// float totalTicks = (float)euPerBucket / 8f; //x eu per bucket / 8
|
||||
// eu per tick
|
||||
|
@ -166,20 +165,23 @@ public class TileSemifluidGenerator extends TilePowerAcceptor implements IWrench
|
|||
pendingWithdraw += millibucketsPerTick;
|
||||
|
||||
int currentWithdraw = (int) pendingWithdraw; // float --> int
|
||||
// conversion floors
|
||||
// the float
|
||||
// conversion floors
|
||||
// the float
|
||||
pendingWithdraw -= currentWithdraw;
|
||||
|
||||
tank.drain(currentWithdraw, true);
|
||||
addEnergy(euTick);
|
||||
}
|
||||
if (tank.getFluidType() != null && getStackInSlot(2) == null)
|
||||
{
|
||||
if (tank.getFluidType() != null && getStackInSlot(2) == null) {
|
||||
inventory.setInventorySlotContents(2, new ItemStack(tank.getFluidType().getBlock()));
|
||||
} else if (tank.getFluidType() == null && getStackInSlot(2) != null)
|
||||
{
|
||||
} else if (tank.getFluidType() == null && getStackInSlot(2) != null) {
|
||||
setInventorySlotContents(2, null);
|
||||
}
|
||||
|
||||
if (!worldObj.isRemote && getEnergy() > 0) {
|
||||
double maxOutput = getEnergy() > getMaxOutput() ? getMaxOutput() : getEnergy();
|
||||
useEnergy(PowerNet.dispatchEnergyPacket(worldObj, getPos(), maxOutput));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -5,6 +5,7 @@ import net.minecraft.util.ITickable;
|
|||
import reborncore.api.power.EnumPowerTier;
|
||||
import reborncore.common.powerSystem.TilePowerAcceptor;
|
||||
import techreborn.blocks.generator.BlockSolarPanel;
|
||||
import techreborn.power.PowerNet;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -25,27 +26,26 @@ public class TileSolarPanel extends TilePowerAcceptor implements ITickable
|
|||
}
|
||||
|
||||
@Override
|
||||
public void updateEntity()
|
||||
{
|
||||
public void updateEntity() {
|
||||
super.updateEntity();
|
||||
if(!worldObj.isRemote){
|
||||
if (worldObj.getTotalWorldTime() % 60 == 0)
|
||||
{
|
||||
shouldMakePower = isSunOut();
|
||||
if (!worldObj.isRemote) {
|
||||
if (worldObj.getTotalWorldTime() % 60 == 0) {
|
||||
shouldMakePower = isSunOut();
|
||||
|
||||
}
|
||||
if (shouldMakePower)
|
||||
{
|
||||
powerToAdd = 10;
|
||||
addEnergy(powerToAdd);
|
||||
} else
|
||||
{
|
||||
powerToAdd = 0;
|
||||
}
|
||||
if (shouldMakePower) {
|
||||
powerToAdd = 10;
|
||||
addEnergy(powerToAdd);
|
||||
} else {
|
||||
powerToAdd = 0;
|
||||
}
|
||||
worldObj.setBlockState(getPos(), worldObj.getBlockState(this.getPos()).withProperty(BlockSolarPanel.ACTIVE, isSunOut()));
|
||||
}
|
||||
|
||||
worldObj.setBlockState(getPos(),
|
||||
worldObj.getBlockState(this.getPos()).withProperty(BlockSolarPanel.ACTIVE, isSunOut()));
|
||||
}
|
||||
if (!worldObj.isRemote && getEnergy() > 0) {
|
||||
double maxOutput = getEnergy() > getMaxOutput() ? getMaxOutput() : getEnergy();
|
||||
useEnergy(PowerNet.dispatchEnergyPacket(worldObj, getPos(), maxOutput));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -20,6 +20,7 @@ import reborncore.common.util.Inventory;
|
|||
import reborncore.common.util.Tank;
|
||||
import techreborn.config.ConfigTechReborn;
|
||||
import techreborn.init.ModBlocks;
|
||||
import techreborn.power.PowerNet;
|
||||
|
||||
public class TileThermalGenerator extends TilePowerAcceptor implements IWrenchable, IFluidHandler,IInventoryProvider
|
||||
{
|
||||
|
@ -137,51 +138,46 @@ public class TileThermalGenerator extends TilePowerAcceptor implements IWrenchab
|
|||
|
||||
@Override
|
||||
// TODO optimise this code
|
||||
public void updateEntity()
|
||||
{
|
||||
public void updateEntity() {
|
||||
super.updateEntity();
|
||||
if (!worldObj.isRemote)
|
||||
{
|
||||
if (!worldObj.isRemote) {
|
||||
FluidUtils.drainContainers(this, inventory, 0, 1);
|
||||
for (EnumFacing direction : EnumFacing.values())
|
||||
{
|
||||
for (EnumFacing direction : EnumFacing.values()) {
|
||||
if (worldObj.getBlockState(new BlockPos(getPos().getX() + direction.getFrontOffsetX(),
|
||||
getPos().getY() + direction.getFrontOffsetY(), getPos().getZ() + direction.getFrontOffsetZ()))
|
||||
.getBlock() == Blocks.LAVA)
|
||||
{
|
||||
.getBlock() == Blocks.LAVA) {
|
||||
addEnergy(1);
|
||||
}
|
||||
}
|
||||
|
||||
if (worldObj.getTotalWorldTime() % 40 == 0)
|
||||
{
|
||||
if (worldObj.getTotalWorldTime() % 40 == 0) {
|
||||
BlockMachineBase bmb = (BlockMachineBase) worldObj.getBlockState(pos).getBlock();
|
||||
boolean didFindLava = false;
|
||||
for (EnumFacing direction : EnumFacing.values())
|
||||
{
|
||||
for (EnumFacing direction : EnumFacing.values()) {
|
||||
if (worldObj.getBlockState(new BlockPos(getPos().getX() + direction.getFrontOffsetX(),
|
||||
getPos().getY() + direction.getFrontOffsetY(),
|
||||
getPos().getZ() + direction.getFrontOffsetZ())).getBlock() == Blocks.LAVA)
|
||||
{
|
||||
getPos().getZ() + direction.getFrontOffsetZ())).getBlock() == Blocks.LAVA) {
|
||||
didFindLava = true;
|
||||
}
|
||||
}
|
||||
bmb.setActive(didFindLava, worldObj, pos);
|
||||
}
|
||||
}
|
||||
if (tank.getFluidAmount() > 0 && getMaxPower() - getEnergy() >= euTick)
|
||||
{
|
||||
if (tank.getFluidAmount() > 0 && getMaxPower() - getEnergy() >= euTick) {
|
||||
tank.drain(1, true);
|
||||
addEnergy(euTick);
|
||||
}
|
||||
if (tank.getFluidType() != null && getStackInSlot(2) == null)
|
||||
{
|
||||
if (tank.getFluidType() != null && getStackInSlot(2) == null) {
|
||||
// inventory.setInventorySlotContents(2, new ItemStack(tank
|
||||
// .getFluidType().getBlock()));
|
||||
} else if (tank.getFluidType() == null && getStackInSlot(2) != null)
|
||||
{
|
||||
} else if (tank.getFluidType() == null && getStackInSlot(2) != null) {
|
||||
setInventorySlotContents(2, null);
|
||||
}
|
||||
|
||||
if (!worldObj.isRemote && getEnergy() > 0) {
|
||||
double maxOutput = getEnergy() > getMaxOutput() ? getMaxOutput() : getEnergy();
|
||||
useEnergy(PowerNet.dispatchEnergyPacket(worldObj, getPos(), maxOutput));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -4,6 +4,7 @@ import net.minecraft.init.Blocks;
|
|||
import net.minecraft.util.EnumFacing;
|
||||
import reborncore.api.power.EnumPowerTier;
|
||||
import reborncore.common.powerSystem.TilePowerAcceptor;
|
||||
import techreborn.power.PowerNet;
|
||||
|
||||
/**
|
||||
* Created by modmuss50 on 25/02/2016.
|
||||
|
@ -19,17 +20,19 @@ public class TileWaterMill extends TilePowerAcceptor
|
|||
}
|
||||
|
||||
@Override
|
||||
public void updateEntity()
|
||||
{
|
||||
public void updateEntity() {
|
||||
super.updateEntity();
|
||||
if (worldObj.getTotalWorldTime() % 20 == 0)
|
||||
{
|
||||
if (worldObj.getTotalWorldTime() % 20 == 0) {
|
||||
checkForWater();
|
||||
}
|
||||
if (waterblocks > 0)
|
||||
{
|
||||
if (waterblocks > 0) {
|
||||
addEnergy(waterblocks);
|
||||
}
|
||||
|
||||
if (!worldObj.isRemote && getEnergy() > 0) {
|
||||
double maxOutput = getEnergy() > getMaxOutput() ? getMaxOutput() : getEnergy();
|
||||
useEnergy(PowerNet.dispatchEnergyPacket(worldObj, getPos(), maxOutput));
|
||||
}
|
||||
}
|
||||
|
||||
public void checkForWater()
|
||||
|
|
|
@ -3,6 +3,7 @@ package techreborn.tiles.generator;
|
|||
import net.minecraft.util.EnumFacing;
|
||||
import reborncore.api.power.EnumPowerTier;
|
||||
import reborncore.common.powerSystem.TilePowerAcceptor;
|
||||
import techreborn.power.PowerNet;
|
||||
|
||||
/**
|
||||
* Created by modmuss50 on 25/02/2016.
|
||||
|
@ -18,19 +19,16 @@ public class TileWindMill extends TilePowerAcceptor
|
|||
}
|
||||
|
||||
@Override
|
||||
public void updateEntity()
|
||||
{
|
||||
public void updateEntity() {
|
||||
super.updateEntity();
|
||||
if (pos.getY() > 64)
|
||||
{
|
||||
int actualPower = basePower;
|
||||
if (worldObj.isThundering())
|
||||
{
|
||||
actualPower *= 1.25;
|
||||
}
|
||||
addEnergy(actualPower); // Value taken from
|
||||
// http://wiki.industrial-craft.net/?title=Wind_Mill
|
||||
// Not worth making more complicated
|
||||
if (pos.getY() > 64) {
|
||||
double actualPower = basePower + basePower * worldObj.getThunderStrength(1.0F);
|
||||
addEnergy(actualPower);
|
||||
}
|
||||
|
||||
if (!worldObj.isRemote && getEnergy() > 0) {
|
||||
double maxOutput = getEnergy() > getMaxOutput() ? getMaxOutput() : getEnergy();
|
||||
useEnergy(PowerNet.dispatchEnergyPacket(worldObj, getPos(), maxOutput));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ import reborncore.api.power.EnumPowerTier;
|
|||
import reborncore.common.powerSystem.TilePowerAcceptor;
|
||||
import techreborn.config.ConfigTechReborn;
|
||||
import techreborn.init.ModBlocks;
|
||||
import techreborn.power.PowerNet;
|
||||
|
||||
public class TileIDSU extends TilePowerAcceptor implements IWrenchable
|
||||
{
|
||||
|
@ -125,32 +126,26 @@ public class TileIDSU extends TilePowerAcceptor implements IWrenchable
|
|||
return nbttagcompound;
|
||||
}
|
||||
|
||||
public void updateEntity()
|
||||
{
|
||||
public void updateEntity() {
|
||||
super.updateEntity();
|
||||
|
||||
if (ticks == ConfigTechReborn.AverageEuOutTickTime)
|
||||
{
|
||||
if (ticks == ConfigTechReborn.AverageEuOutTickTime) {
|
||||
euChange = -1;
|
||||
ticks = 0;
|
||||
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
ticks++;
|
||||
euChange += getEnergy() - euLastTick;
|
||||
if (euLastTick == getEnergy())
|
||||
{
|
||||
if (euLastTick == getEnergy()) {
|
||||
euChange = 0;
|
||||
}
|
||||
}
|
||||
|
||||
euLastTick = getEnergy();
|
||||
|
||||
boolean needsInvUpdate = false;
|
||||
|
||||
if (needsInvUpdate)
|
||||
{
|
||||
this.markDirty();
|
||||
if (!worldObj.isRemote && getEnergy() > 0) {
|
||||
double maxOutput = getEnergy() > getMaxOutput() ? getMaxOutput() : getEnergy();
|
||||
useEnergy(PowerNet.dispatchEnergyPacket(worldObj, getPos(), maxOutput));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import reborncore.api.power.EnumPowerTier;
|
|||
import reborncore.common.powerSystem.TilePowerAcceptor;
|
||||
import reborncore.common.util.Inventory;
|
||||
import techreborn.config.ConfigTechReborn;
|
||||
import techreborn.power.PowerNet;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
|
@ -27,32 +28,25 @@ public class TileLesu extends TilePowerAcceptor
|
|||
}
|
||||
|
||||
@Override
|
||||
public void updateEntity()
|
||||
{
|
||||
public void updateEntity() {
|
||||
super.updateEntity();
|
||||
if (worldObj.isRemote)
|
||||
{
|
||||
if (worldObj.isRemote) {
|
||||
return;
|
||||
}
|
||||
countedNetworks.clear();
|
||||
connectedBlocks = 0;
|
||||
for (EnumFacing dir : EnumFacing.values())
|
||||
{
|
||||
for (EnumFacing dir : EnumFacing.values()) {
|
||||
if (worldObj.getTileEntity(
|
||||
new BlockPos(getPos().getX() + dir.getFrontOffsetX(), getPos().getY() + dir.getFrontOffsetY(),
|
||||
getPos().getZ() + dir.getFrontOffsetZ())) instanceof TileLesuStorage)
|
||||
{
|
||||
getPos().getZ() + dir.getFrontOffsetZ())) instanceof TileLesuStorage) {
|
||||
if (((TileLesuStorage) worldObj.getTileEntity(
|
||||
new BlockPos(getPos().getX() + dir.getFrontOffsetX(), getPos().getY() + dir.getFrontOffsetY(),
|
||||
getPos().getZ() + dir.getFrontOffsetZ()))).network != null)
|
||||
{
|
||||
getPos().getZ() + dir.getFrontOffsetZ()))).network != null) {
|
||||
LesuNetwork network = ((TileLesuStorage) worldObj.getTileEntity(new BlockPos(
|
||||
getPos().getX() + dir.getFrontOffsetX(), getPos().getY() + dir.getFrontOffsetY(),
|
||||
getPos().getZ() + dir.getFrontOffsetZ()))).network;
|
||||
if (!countedNetworks.contains(network))
|
||||
{
|
||||
if (network.master == null || network.master == this)
|
||||
{
|
||||
if (!countedNetworks.contains(network)) {
|
||||
if (network.master == null || network.master == this) {
|
||||
connectedBlocks += network.storages.size();
|
||||
countedNetworks.add(network);
|
||||
network.master = this;
|
||||
|
@ -65,25 +59,27 @@ public class TileLesu extends TilePowerAcceptor
|
|||
maxStorage = ((connectedBlocks + 1) * ConfigTechReborn.LesuStoragePerBlock);
|
||||
output = (connectedBlocks * ConfigTechReborn.ExtraOutputPerLesuBlock) + ConfigTechReborn.BaseLesuOutput;
|
||||
|
||||
if (ticks == ConfigTechReborn.AverageEuOutTickTime)
|
||||
{
|
||||
if (ticks == ConfigTechReborn.AverageEuOutTickTime) {
|
||||
euChange = -1;
|
||||
ticks = 0;
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
ticks++;
|
||||
if (euChange == -1)
|
||||
{
|
||||
if (euChange == -1) {
|
||||
euChange = 0;
|
||||
}
|
||||
euChange += getEnergy() - euLastTick;
|
||||
if (euLastTick == getEnergy())
|
||||
{
|
||||
if (euLastTick == getEnergy()) {
|
||||
euChange = 0;
|
||||
}
|
||||
}
|
||||
|
||||
euLastTick = getEnergy();
|
||||
|
||||
if (!worldObj.isRemote && getEnergy() > 0) {
|
||||
double maxOutput = getEnergy() > getMaxOutput() ? getMaxOutput() : getEnergy();
|
||||
useEnergy(PowerNet.dispatchEnergyPacket(worldObj, getPos(), maxOutput));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public double getEuChange()
|
||||
|
|
|
@ -13,6 +13,7 @@ import reborncore.common.powerSystem.PoweredItem;
|
|||
import reborncore.common.powerSystem.TilePowerAcceptor;
|
||||
import reborncore.common.util.Inventory;
|
||||
import techreborn.blocks.storage.BlockEnergyStorage;
|
||||
import techreborn.power.PowerNet;
|
||||
|
||||
/**
|
||||
* Created by Rushmead
|
||||
|
@ -54,40 +55,39 @@ public class TileEnergyStorage extends TilePowerAcceptor implements IWrenchable,
|
|||
return entityPlayer.isSneaking();
|
||||
}
|
||||
|
||||
@Override public void updateEntity()
|
||||
{
|
||||
if (inventory.getStackInSlot(0) != null)
|
||||
{
|
||||
@Override public void updateEntity() {
|
||||
if (inventory.getStackInSlot(0) != null) {
|
||||
ItemStack stack = inventory.getStackInSlot(0);
|
||||
if(!(stack.getItem() instanceof IEnergyItemInfo)){
|
||||
if (!(stack.getItem() instanceof IEnergyItemInfo)) {
|
||||
return;
|
||||
}
|
||||
IEnergyItemInfo item = (IEnergyItemInfo) inventory.getStackInSlot(0).getItem();
|
||||
if (PoweredItem.getEnergy(stack) != PoweredItem.getMaxPower(stack))
|
||||
{
|
||||
if (canUseEnergy(item.getMaxTransfer(stack)))
|
||||
{
|
||||
if (PoweredItem.getEnergy(stack) != PoweredItem.getMaxPower(stack)) {
|
||||
if (canUseEnergy(item.getMaxTransfer(stack))) {
|
||||
useEnergy(item.getMaxTransfer(stack));
|
||||
PoweredItem.setEnergy(PoweredItem.getEnergy(stack) + item.getMaxTransfer(stack), stack);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (inventory.getStackInSlot(1) != null)
|
||||
{
|
||||
if (inventory.getStackInSlot(1) != null) {
|
||||
ItemStack stack = inventory.getStackInSlot(1);
|
||||
if(!(stack.getItem() instanceof IEnergyItemInfo)){
|
||||
if (!(stack.getItem() instanceof IEnergyItemInfo)) {
|
||||
return;
|
||||
}
|
||||
IEnergyItemInfo item = (IEnergyItemInfo) stack.getItem();
|
||||
if (item.canProvideEnergy(stack))
|
||||
{
|
||||
if (getEnergy() != getMaxPower())
|
||||
{
|
||||
if (item.canProvideEnergy(stack)) {
|
||||
if (getEnergy() != getMaxPower()) {
|
||||
addEnergy(item.getMaxTransfer(stack));
|
||||
PoweredItem.setEnergy(PoweredItem.getEnergy(stack) - item.getMaxTransfer(stack), stack);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!worldObj.isRemote && getEnergy() > 0) {
|
||||
double maxOutput = getEnergy() > getMaxOutput() ? getMaxOutput() : getEnergy();
|
||||
useEnergy(PowerNet.dispatchEnergyPacket(worldObj, getPos(), maxOutput));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue