More work on the cables, and add items

This commit is contained in:
modmuss50 2016-02-27 19:36:01 +00:00
parent 1cd886e770
commit e4b8918224
7 changed files with 98 additions and 26 deletions

View file

@ -42,6 +42,7 @@ import techreborn.init.RecipeCompact;
import techreborn.lib.ModInfo;
import techreborn.packets.PacketAesu;
import techreborn.packets.PacketIdsu;
import techreborn.powernet.PowerEvent;
import techreborn.proxies.CommonProxy;
import techreborn.tiles.idsu.IDSUManager;
import techreborn.world.TROreGen;
@ -128,9 +129,10 @@ public class Core {
// IDSU manager
IDSUManager.INSTANCE = new IDSUManager();
MinecraftForge.EVENT_BUS.register(IDSUManager.INSTANCE);
FMLCommonHandler.instance().bus().register(new MultiblockServerTickHandler());
FMLCommonHandler.instance().bus().register(new TRTickHandler());
FMLCommonHandler.instance().bus().register(new OreUnifier());
MinecraftForge.EVENT_BUS.register(new MultiblockServerTickHandler());
MinecraftForge.EVENT_BUS.register(new TRTickHandler());
MinecraftForge.EVENT_BUS.register(new OreUnifier());
MinecraftForge.EVENT_BUS.register(new PowerEvent());
logHelper.info("Initialization Complete");
}

View file

@ -12,21 +12,7 @@ import reborncore.common.powerSystem.PoweredItem;
import reborncore.common.util.BucketHandler;
import techreborn.Core;
import techreborn.events.OreUnifier;
import techreborn.items.ItemCells;
import techreborn.items.ItemCrushedOre;
import techreborn.items.ItemDusts;
import techreborn.items.ItemDustsSmall;
import techreborn.items.ItemGems;
import techreborn.items.ItemIngots;
import techreborn.items.ItemLapotronicOrb;
import techreborn.items.ItemLithiumBattery;
import techreborn.items.ItemMissingRecipe;
import techreborn.items.ItemNuggets;
import techreborn.items.ItemParts;
import techreborn.items.ItemPlates;
import techreborn.items.ItemPurifiedCrushedOre;
import techreborn.items.ItemReBattery;
import techreborn.items.ItemUUmatter;
import techreborn.items.*;
import techreborn.items.armor.ItemLapotronPack;
import techreborn.items.armor.ItemLithiumBatpack;
import techreborn.items.tools.*;
@ -95,6 +81,7 @@ public class ModItems {
public static Item advancedChainsaw;
public static Item hammer;
public static Item wrench;
public static Item cables;
public static Item upgrades;
@ -317,6 +304,9 @@ public class ModItems {
missingRecipe = new ItemMissingRecipe().setUnlocalizedName("missingRecipe");
GameRegistry.registerItem(missingRecipe, "mssingRecipe");
cables = new ItemCables();
GameRegistry.registerItem(cables, "cables");
MinecraftForge.EVENT_BUS.register(BucketHandler.INSTANCE);

View file

@ -0,0 +1,69 @@
package techreborn.items;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import techreborn.client.TechRebornCreativeTab;
import techreborn.init.ModItems;
import techreborn.lib.ModInfo;
import java.security.InvalidParameterException;
import java.util.List;
/**
* Created by Mark on 27/02/2016.
*/
public class ItemCables extends ItemTextureBase {
public static ItemStack getCableByName(String name, int count) {
for (int i = 0; i < types.length; i++) {
if (types[i].equalsIgnoreCase(name)) {
return new ItemStack(ModItems.cables, count, i);
}
}
throw new InvalidParameterException("The cabel " + name + " could not be found.");
}
public static ItemStack getCableByName(String name) {
return getCableByName(name, 1);
}
public static final String[] types = new String[]
{"copper", "gold"};
public ItemCables() {
setCreativeTab(TechRebornCreativeTab.instance);
setHasSubtypes(true);
setUnlocalizedName("techreborn.cable");
}
@Override
// gets Unlocalized Name depending on meta data
public String getUnlocalizedName(ItemStack itemStack) {
int meta = itemStack.getItemDamage();
if (meta < 0 || meta >= types.length) {
meta = 0;
}
return super.getUnlocalizedName() + "." + types[meta];
}
// Adds Dusts SubItems To Creative Tab
public void getSubItems(Item item, CreativeTabs creativeTabs, List list) {
for (int meta = 0; meta < types.length; ++meta) {
list.add(new ItemStack(item, 1, meta));
}
}
@Override
public String getTextureName(int damage) {
return ModInfo.MOD_ID + ":items/cables/" + types[damage];
}
@Override
public int getMaxMeta() {
return types.length;
}
}

View file

@ -36,7 +36,7 @@ public class PowerCable {
if(network != null){
if(tileEntity instanceof IPowerCableContainer){
IPowerCableContainer powerCableContainer = (IPowerCableContainer) tileEntity;
if(powerCableContainer.getPowerCable().network != network){
if(powerCableContainer.getPowerCable() != null && powerCableContainer.getPowerCable().network != network){
network.merge(powerCableContainer.getPowerCable().network);
}
}

View file

@ -2,6 +2,9 @@ package techreborn.powernet;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;
import reborncore.api.power.IEnergyInterfaceTile;
import java.util.ArrayList;
@ -13,7 +16,11 @@ public class PowerNetwork {
int networkPower;
double maxTransfur;
double maxTransfer = 128;
public PowerNetwork() {
MinecraftForge.EVENT_BUS.register(this);
}
public PowerNetwork merge(PowerNetwork network){
cables.addAll(network.cables);
@ -34,7 +41,9 @@ public class PowerNetwork {
cable.setNetwork(null);
}
public void tick(World world){
@SubscribeEvent
public void tick(PowerEvent event){
World world = event.world;
for(PowerCable cable : cables){
if(cable.container.getWorld() == world){
for(PowerNode node : cable.nodes){
@ -46,13 +55,13 @@ public class PowerNetwork {
switch (node.type){
case COLLECTOR:
if(iEnergyInterfaceTile.canProvideEnergy(node.facingFromCable)){
double transfur = Math.min(maxTransfur, Math.min(iEnergyInterfaceTile.getMaxOutput(), iEnergyInterfaceTile.getEnergy()));
double transfur = Math.min(maxTransfer, Math.min(iEnergyInterfaceTile.getMaxOutput(), iEnergyInterfaceTile.getEnergy()));
networkPower += iEnergyInterfaceTile.useEnergy(transfur);
}
break;
case RECEIVER:
if(iEnergyInterfaceTile.canAcceptEnergy(node.facingFromCable)){
double transfur = Math.min(maxTransfur, Math.min(iEnergyInterfaceTile.getMaxOutput(), iEnergyInterfaceTile.getEnergy()));
double transfur = Math.min(maxTransfer, Math.min(iEnergyInterfaceTile.getMaxOutput(), iEnergyInterfaceTile.getEnergy()));
networkPower -= iEnergyInterfaceTile.addEnergy(transfur);
}
break;
@ -60,6 +69,7 @@ public class PowerNetwork {
}
}
}
System.out.println(networkPower);
}
}

View file

@ -27,7 +27,7 @@ public class TileCable extends TileEntity implements IPowerCableContainer, ITick
@Override
public void update() {
if(cable == null){
cable = new PowerCable(this);
createCable();
} else {
cable.checkNodes();
}
@ -43,5 +43,6 @@ public class TileCable extends TileEntity implements IPowerCableContainer, ITick
cable = new PowerCable(this);
cable.setNetwork(network);
network.addCable(cable);
cable.checkNodes();
}
}

View file

@ -12,7 +12,7 @@ public class TileWindMill extends TilePowerAcceptor {
super(2);
}
int basePower = 10;
int basePower = 4;
@Override
public void updateEntity() {
@ -22,7 +22,7 @@ public class TileWindMill extends TilePowerAcceptor {
if(worldObj.isThundering()){
actualPower *= 1.25;
}
addEnergy(actualPower * (pos.getY() - 64)); //Value taken from http://wiki.industrial-craft.net/?title=Wind_Mill Not worth making more complicated
addEnergy(actualPower); //Value taken from http://wiki.industrial-craft.net/?title=Wind_Mill Not worth making more complicated
}
}