v4.2.3 Release

*Updated to 1.4.2.
*Add 'getMaxEnergy' command to machines and power units.
*Add 'getEnergyNeeded' command to machines and power units.
*Add crafting recipes and creative tab assignment for machine upgrades.
*Add power transfer system for power units, so energy can be
transferred without needing UE, IC2, or BC.
*Bugfixes.
This commit is contained in:
Aidan Brady 2012-10-25 17:55:32 -04:00
parent d8634f5615
commit 7e4f1e7a1b
135 changed files with 3562 additions and 3579 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 15 KiB

View file

@ -23,5 +23,5 @@ public interface IEnergyStorage {
*
* @return Energy output in EU/t
*/
public int getOutput();
public int getRate();
}

View file

@ -165,7 +165,7 @@ public class ContainerAdvancedElectricMachine extends Container
return null;
}
currentSlot.onPickupFromSlot(slotStack);
currentSlot.putStack(slotStack);
}
return stack;

View file

@ -122,7 +122,7 @@ public class ContainerElectricMachine extends Container
return null;
}
currentSlot.onPickupFromSlot(slotStack);
currentSlot.putStack(slotStack);
}
return stack;

View file

@ -91,7 +91,7 @@ public class ContainerPowerUnit extends Container
return null;
}
currentSlot.onPickupFromSlot(slotStack);
currentSlot.putStack(slotStack);
}
return stack;

View file

@ -97,7 +97,7 @@ public class EntityObsidianTNT extends Entity
private void explode()
{
worldObj.createExplosion((Entity)null, posX, posY, posZ, ObsidianIngots.ObsidianTNTBlastRadius);
worldObj.createExplosion((Entity)null, posX, posY, posZ, ObsidianIngots.ObsidianTNTBlastRadius, true);
hasExploded = true;
}

View file

@ -4,7 +4,7 @@ import java.util.List;
import obsidian.api.IEnergizedItem;
import universalelectricity.UniversalElectricity;
import universalelectricity.core.UniversalElectricity;
import universalelectricity.electricity.ElectricInfo;
import universalelectricity.implement.IItemElectric;
@ -28,7 +28,7 @@ public class ItemEnergized extends ItemObsidian implements IEnergizedItem, IItem
setCreativeTab(CreativeTabs.tabRedstone);
}
public void addInformation(ItemStack itemstack, List list)
public void addInformation(ItemStack itemstack, EntityPlayer entityplayer, List list, boolean flag)
{
int energy = getEnergy(itemstack);

View file

@ -2,6 +2,7 @@ package net.uberkat.obsidian.common;
import java.util.List;
import net.minecraft.src.CreativeTabs;
import net.minecraft.src.ItemStack;
import obsidian.api.IMachineUpgrade;
@ -11,5 +12,6 @@ public class ItemMachineUpgrade extends ItemObsidian implements IMachineUpgrade
{
super(i);
setMaxStackSize(1);
setCreativeTab(CreativeTabs.tabRedstone);
}
}

View file

@ -65,7 +65,7 @@ public class ItemObsidianBow extends ItemObsidian
if (f == 1.0F)
{
entityarrow.func_70243_d(true);
entityarrow.setIsCritical(true);
}
int j = EnchantmentHelper.getEnchantmentLevel(Enchantment.power.effectId, itemstack);

View file

@ -16,9 +16,9 @@ public class ItemObsidianHoe extends ItemObsidian
* Callback for item usage. If the item does something special on right clicking, he will have one of those. Return
* True if something happen and false if it don't. This is for ITEMS, not BLOCKS !
*/
public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7)
public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10)
{
if (!par2EntityPlayer.canPlayerEdit(par4, par5, par6))
if (!par2EntityPlayer.func_82247_a(par4, par5, par6, par7, par1ItemStack))
{
return false;
}

View file

@ -503,6 +503,15 @@ public class ObsidianIngots
GameRegistry.addRecipe(new ItemStack(MachineBlock, 1, 3), new Object[] {
"***", "*L*", "***", Character.valueOf('*'), PlatinumIngot, Character.valueOf('L'), Item.bucketLava
});
GameRegistry.addRecipe(new ItemStack(SpeedUpgrade), new Object[] {
"PAP", "ARA", "PAP", Character.valueOf('P'), PlatinumDust, Character.valueOf('A'), EnrichedAlloy, Character.valueOf('E'), Item.emerald
});
GameRegistry.addRecipe(new ItemStack(EnergyUpgrade), new Object[] {
"RAR", "AEA", "RAR", Character.valueOf('R'), Item.redstone, Character.valueOf('A'), EnrichedAlloy, Character.valueOf('E'), Item.emerald
});
GameRegistry.addRecipe(new ItemStack(UltimateUpgrade), new Object[] {
"ERA", "RDR", "ARS", Character.valueOf('E'), EnergyUpgrade, Character.valueOf('R'), Item.redstone, Character.valueOf('A'), EnrichedAlloy, Character.valueOf('D'), Item.diamond, Character.valueOf('S'), SpeedUpgrade
});
if(extrasEnabled)
{

View file

@ -13,7 +13,7 @@ import com.google.common.io.ByteStreams;
import net.minecraft.src.EntityPlayer;
import net.minecraft.src.ModLoader;
import net.minecraft.src.NetworkManager;
import net.minecraft.src.INetworkManager;
import net.minecraft.src.Packet;
import net.minecraft.src.Packet250CustomPayload;
import net.minecraft.src.TileEntity;
@ -32,7 +32,7 @@ import cpw.mods.fml.server.FMLServerHandler;
*/
public class PacketHandler implements IPacketHandler
{
public void onPacketData(NetworkManager manager, Packet250CustomPayload packet, Player player)
public void onPacketData(INetworkManager manager, Packet250CustomPayload packet, Player player)
{
ByteArrayDataInput dataStream = ByteStreams.newDataInput(packet.data);
EntityPlayer entityplayer = (EntityPlayer)player;

View file

@ -7,7 +7,7 @@ import java.util.List;
import obsidian.api.IEnergizedItem;
import universalelectricity.UniversalElectricity;
import universalelectricity.core.UniversalElectricity;
import universalelectricity.electricity.ElectricInfo;
import universalelectricity.implement.IItemElectric;
@ -327,7 +327,7 @@ public abstract class TileEntityAdvancedElectricMachine extends TileEntityBasicM
PacketHandler.sendAdvancedElectricMachinePacketWithRange(this, 50);
}
public void handlePacketData(NetworkManager network, Packet250CustomPayload packet, EntityPlayer player, ByteArrayDataInput dataStream)
public void handlePacketData(INetworkManager network, Packet250CustomPayload packet, EntityPlayer player, ByteArrayDataInput dataStream)
{
try {
facing = dataStream.readInt();
@ -421,7 +421,7 @@ public abstract class TileEntityAdvancedElectricMachine extends TileEntityBasicM
public String[] getMethodNames()
{
return new String[] {"getStored", "getSecondaryStored", "getProgress", "isActive", "facing", "canOperate"};
return new String[] {"getStored", "getSecondaryStored", "getProgress", "isActive", "facing", "canOperate", "getMaxEnergy", "getEnergyNeeded"};
}
public Object[] callMethod(IComputerAccess computer, int method, Object[] arguments) throws Exception
@ -440,9 +440,13 @@ public abstract class TileEntityAdvancedElectricMachine extends TileEntityBasicM
return new Object[] {facing};
case 5:
return new Object[] {canOperate()};
case 6:
return new Object[] {currentMaxEnergy};
case 7:
return new Object[] {(currentMaxEnergy-energyStored)};
default:
System.err.println("[ObsidianIngots] Attempted to call unknown method with computer ID " + computer.getID());
return null;
return new Object[] {"Unknown command."};
}
}
}

View file

@ -1,7 +1,7 @@
package net.uberkat.obsidian.common;
import obsidian.api.IElectricMachine;
import universalelectricity.UniversalElectricity;
import universalelectricity.core.UniversalElectricity;
import universalelectricity.electricity.ElectricInfo;
import universalelectricity.electricity.ElectricityManager;
import universalelectricity.prefab.TileEntityDisableable;
@ -92,10 +92,6 @@ public abstract class TileEntityBasicMachine extends TileEntityDisableable imple
*/
public TileEntityBasicMachine(String soundPath, String name, String path, int perTick, int ticksRequired, int maxEnergy)
{
if(ObsidianIngots.hooks.UELoaded)
{
ElectricityManager.instance.registerElectricUnit(this);
}
ENERGY_PER_TICK = perTick;
TICKS_REQUIRED = currentTicksRequired = ticksRequired;
MAX_ENERGY = currentMaxEnergy = maxEnergy;
@ -446,4 +442,25 @@ public abstract class TileEntityBasicMachine extends TileEntityDisableable imple
}
}
public int transferToAcceptor(int amount)
{
int rejects = 0;
int neededEnergy = currentMaxEnergy-energyStored;
if(amount <= neededEnergy)
{
energyStored += amount;
}
else if(amount > neededEnergy)
{
energyStored += neededEnergy;
rejects = amount-neededEnergy;
}
return rejects;
}
public boolean canReceive(ForgeDirection side)
{
return true;
}
}

View file

@ -7,7 +7,7 @@ import java.util.List;
import obsidian.api.IEnergizedItem;
import universalelectricity.UniversalElectricity;
import universalelectricity.core.UniversalElectricity;
import universalelectricity.electricity.ElectricInfo;
import universalelectricity.implement.IItemElectric;
@ -266,7 +266,7 @@ public abstract class TileEntityElectricMachine extends TileEntityBasicMachine
PacketHandler.sendElectricMachinePacketWithRange(this, 50);
}
public void handlePacketData(NetworkManager network, Packet250CustomPayload packet, EntityPlayer player, ByteArrayDataInput dataStream)
public void handlePacketData(INetworkManager network, Packet250CustomPayload packet, EntityPlayer player, ByteArrayDataInput dataStream)
{
try {
facing = dataStream.readInt();
@ -343,7 +343,7 @@ public abstract class TileEntityElectricMachine extends TileEntityBasicMachine
public String[] getMethodNames()
{
return new String[] {"getStored", "getProgress", "isActive", "facing", "canOperate"};
return new String[] {"getStored", "getProgress", "isActive", "facing", "canOperate", "getMaxEnergy", "getEnergyNeeded"};
}
public Object[] callMethod(IComputerAccess computer, int method, Object[] arguments) throws Exception
@ -360,9 +360,13 @@ public abstract class TileEntityElectricMachine extends TileEntityBasicMachine
return new Object[] {facing};
case 4:
return new Object[] {canOperate()};
case 5:
return new Object[] {currentMaxEnergy};
case 6:
return new Object[] {(currentMaxEnergy-energyStored)};
default:
System.err.println("[ObsidianIngots] Attempted to call unknown method with computer ID " + computer.getID());
return null;
return new Object[] {"Unknown command."};
}
}
}

View file

@ -6,20 +6,18 @@ import java.io.IOException;
import obsidian.api.IEnergizedItem;
import obsidian.api.ITileNetwork;
import obsidian.api.IEnergyAcceptor;
import universalelectricity.UniversalElectricity;
import universalelectricity.core.UniversalElectricity;
import universalelectricity.core.Vector3;
import universalelectricity.electricity.ElectricInfo;
import universalelectricity.electricity.ElectricityManager;
import universalelectricity.implement.IConductor;
import universalelectricity.implement.IElectricityReceiver;
import universalelectricity.implement.IItemElectric;
import universalelectricity.implement.IJouleStorage;
import universalelectricity.network.ConnectionHandler;
import universalelectricity.network.ConnectionHandler.ConnectionType;
import universalelectricity.network.ISimpleConnectionHandler;
import universalelectricity.prefab.TileEntityConductor;
import universalelectricity.prefab.TileEntityDisableable;
import universalelectricity.prefab.Vector3;
import buildcraft.api.power.IPowerProvider;
import buildcraft.api.power.IPowerReceptor;
@ -44,7 +42,7 @@ import net.minecraft.src.*;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.common.ISidedInventory;
public class TileEntityPowerUnit extends TileEntityDisableable implements IInventory, ISidedInventory, ITileNetwork, IWrenchable, IEnergySink, IEnergySource, IEnergyStorage, IPowerReceptor, IJouleStorage, IElectricityReceiver, IPeripheral
public class TileEntityPowerUnit extends TileEntityDisableable implements IInventory, ISidedInventory, ITileNetwork, IWrenchable, IEnergySink, IEnergySource, IEnergyStorage, IPowerReceptor, IJouleStorage, IElectricityReceiver, IEnergyAcceptor, IPeripheral
{
/** The inventory slot itemstacks used by this power unit. */
public ItemStack[] inventory = new ItemStack[2];
@ -85,10 +83,6 @@ public class TileEntityPowerUnit extends TileEntityDisableable implements IInven
*/
public TileEntityPowerUnit(int energy, int i)
{
if(ObsidianIngots.hooks.UELoaded)
{
ElectricityManager.instance.registerElectricUnit(this);
}
maxEnergy = energy;
output = i;
if(PowerFramework.currentFramework != null)
@ -199,6 +193,8 @@ public class TileEntityPowerUnit extends TileEntityDisableable implements IInven
}
}
if(tileEntity != null)
{
if(isPowerReceptor(tileEntity))
{
IPowerReceptor receptor = (IPowerReceptor)tileEntity;
@ -207,19 +203,36 @@ public class TileEntityPowerUnit extends TileEntityDisableable implements IInven
receptor.getPowerProvider().receiveEnergy((float)(transferEnergy/10), Orientations.dirs()[ForgeDirection.getOrientation(facing).getOpposite().ordinal()]);
setEnergy(energyStored - (int)transferEnergy);
}
TileEntity connector = Vector3.getConnectorFromSide(worldObj, Vector3.get(this), ForgeDirection.getOrientation(facing));
if(connector != null && connector instanceof TileEntityConductor)
else if(tileEntity instanceof TileEntityConductor)
{
double joulesNeeded = ElectricityManager.instance.getElectricityRequired(((IConductor) connector).getConnectionID());
double joulesNeeded = ElectricityManager.instance.getElectricityRequired(((IConductor) tileEntity).getNetwork());
double transferAmps = Math.max(Math.min(Math.min(ElectricInfo.getAmps(joulesNeeded, getVoltage()), ElectricInfo.getAmps(energyStored*UniversalElectricity.IC2_RATIO, getVoltage())), 80), 0);
if (!worldObj.isRemote)
{
ElectricityManager.instance.produceElectricity(this, (IConductor) connector, transferAmps, getVoltage());
ElectricityManager.instance.produceElectricity(this, (IConductor)tileEntity, transferAmps, getVoltage());
}
setEnergy(energyStored - (int)(ElectricInfo.getJoules(transferAmps, getVoltage())*UniversalElectricity.TO_IC2_RATIO));
}
else if(tileEntity instanceof IEnergyAcceptor)
{
if(((IEnergyAcceptor)tileEntity).canReceive(ForgeDirection.getOrientation(facing).getOpposite()))
{
int sendingEnergy = 0;
if(energyStored >= output)
{
sendingEnergy = output;
}
else if(energyStored < output)
{
sendingEnergy = energyStored;
}
int rejects = ((IEnergyAcceptor)tileEntity).transferToAcceptor(output);
setEnergy(energyStored - (sendingEnergy - rejects));
}
}
}
}
if(!worldObj.isRemote)
@ -375,7 +388,7 @@ public class TileEntityPowerUnit extends TileEntityDisableable implements IInven
nbtTags.setTag("Items", tagList);
}
public void handlePacketData(NetworkManager network, Packet250CustomPayload packet, EntityPlayer player, ByteArrayDataInput dataStream)
public void handlePacketData(INetworkManager network, Packet250CustomPayload packet, EntityPlayer player, ByteArrayDataInput dataStream)
{
try {
facing = dataStream.readInt();
@ -448,7 +461,7 @@ public class TileEntityPowerUnit extends TileEntityDisableable implements IInven
return maxEnergy;
}
public int getOutput()
public int getRate()
{
return output;
}
@ -570,7 +583,7 @@ public class TileEntityPowerUnit extends TileEntityDisableable implements IInven
public String[] getMethodNames()
{
return new String[] {"getStored", "getOutput"};
return new String[] {"getStored", "getOutput", "getMaxEnergy", "getEnergyNeeded"};
}
public Object[] callMethod(IComputerAccess computer, int method, Object[] arguments) throws Exception
@ -581,6 +594,10 @@ public class TileEntityPowerUnit extends TileEntityDisableable implements IInven
return new Object[] {energyStored};
case 1:
return new Object[] {output};
case 2:
return new Object[] {maxEnergy};
case 3:
return new Object[] {(maxEnergy-energyStored)};
default:
System.err.println("[ObsidianIngots] Attempted to call unknown method with computer ID " + computer.getID());
return null;
@ -595,4 +612,26 @@ public class TileEntityPowerUnit extends TileEntityDisableable implements IInven
public void attach(IComputerAccess computer, String computerSide) {}
public void detach(IComputerAccess computer) {}
public int transferToAcceptor(int amount)
{
int rejects = 0;
int neededEnergy = maxEnergy-energyStored;
if(amount <= neededEnergy)
{
energyStored += amount;
}
else if(amount > neededEnergy)
{
energyStored += neededEnergy;
rejects = amount-neededEnergy;
}
return rejects;
}
public boolean canReceive(ForgeDirection side)
{
return side != ForgeDirection.getOrientation(facing);
}
}

View file

@ -19,7 +19,7 @@ import net.minecraftforge.common.ISidedInventory;
* @author AidanBrady
*
*/
public interface IElectricMachine extends IInventory, ISidedInventory, IWrenchable, ITileNetwork, IPowerReceptor, IEnergySink, IJouleStorage, IElectricityReceiver, IPeripheral
public interface IElectricMachine extends IInventory, ISidedInventory, IWrenchable, ITileNetwork, IPowerReceptor, IEnergySink, IJouleStorage, IElectricityReceiver, IEnergyAcceptor, IPeripheral
{
/**
* Update call for machines. Use instead of updateEntity() - it's called every tick.

View file

@ -0,0 +1,10 @@
package obsidian.api;
import net.minecraftforge.common.ForgeDirection;
public interface IEnergyAcceptor
{
public int transferToAcceptor(int amount);
public boolean canReceive(ForgeDirection side);
}

View file

@ -1,7 +1,7 @@
package obsidian.api;
import net.minecraft.src.EntityPlayer;
import net.minecraft.src.NetworkManager;
import net.minecraft.src.INetworkManager;
import net.minecraft.src.Packet250CustomPayload;
import com.google.common.io.ByteArrayDataInput;
@ -20,5 +20,5 @@ public interface ITileNetwork
* @param player
* @param dataStream
*/
public void handlePacketData(NetworkManager network, Packet250CustomPayload packet, EntityPlayer player, ByteArrayDataInput dataStream);
public void handlePacketData(INetworkManager network, Packet250CustomPayload packet, EntityPlayer player, ByteArrayDataInput dataStream);
}

0
src/common/railcraft/common/api/carts/CartBase.java Normal file → Executable file
View file

108
src/common/railcraft/common/api/carts/CartTools.java Normal file → Executable file
View file

@ -17,6 +17,7 @@ public abstract class CartTools
{
public static ILinkageManager serverLinkageManager;
/**
* Registers a subclass of EntityMinecart with the game engine.
*
@ -29,8 +30,7 @@ public abstract class CartTools
* @param tag The String identifier
* @param internalId The mods internal entity id
*/
public static void registerMinecart(Object mod, Class<? extends EntityMinecart> type, String tag, int internalId)
{
public static void registerMinecart(Object mod, Class<? extends EntityMinecart> type, String tag, int internalId) {
EntityRegistry.registerModEntity(type, tag, internalId, mod, 80, 3, true);
}
@ -42,8 +42,7 @@ public abstract class CartTools
* @param world The World, may be required in the future
* @return an instance of ILinkageManager
*/
public static ILinkageManager getLinkageManager(World world)
{
public static ILinkageManager getLinkageManager(World world) {
return serverLinkageManager;
}
@ -54,8 +53,7 @@ public abstract class CartTools
*
* @param owner
*/
public static void setCartOwner(EntityMinecart cart, EntityPlayer owner)
{
public static void setCartOwner(EntityMinecart cart, EntityPlayer owner) {
cart.getEntityData().setString("owner", owner.username);
}
@ -66,8 +64,7 @@ public abstract class CartTools
*
* @param owner
*/
public static void setCartOwner(EntityMinecart cart, String owner)
{
public static void setCartOwner(EntityMinecart cart, String owner) {
cart.getEntityData().setString("owner", owner);
}
@ -78,8 +75,7 @@ public abstract class CartTools
*
* @param owner
*/
public static String getCartOwner(EntityMinecart cart)
{
public static String getCartOwner(EntityMinecart cart) {
return cart.getEntityData().getString("owner");
}
@ -91,8 +87,7 @@ public abstract class CartTools
* @return true if the item matches the cart
* @see IMinecart
*/
public static boolean doesCartMatchFilter(ItemStack stack, EntityMinecart cart)
{
public static boolean doesCartMatchFilter(ItemStack stack, EntityMinecart cart) {
if(stack == null) {
return false;
}
@ -100,7 +95,26 @@ public abstract class CartTools
return ((IMinecart)cart).doesCartMatchFilter(stack, cart);
}
ItemStack cartItem = cart.getCartItem();
return cartItem != null && stack.isItemEqual(cartItem);
return cartItem != null && isItemEqual(stack, cartItem);
}
private static boolean isItemEqual(ItemStack a, ItemStack b) {
if(a == null || b == null) {
return false;
}
if(a.itemID != b.itemID) {
return false;
}
if(a.stackTagCompound != null && !a.stackTagCompound.equals(b.stackTagCompound)) {
return false;
}
if(a.getHasSubtypes() && (a.getItemDamage() == -1 || b.getItemDamage() == -1)) {
return true;
}
if(a.getHasSubtypes() && a.getItemDamage() != b.getItemDamage()) {
return false;
}
return true;
}
/**
@ -120,8 +134,7 @@ public abstract class CartTools
* @return the cart placed or null if failed
* @see IMinecartItem, ItemMinecart
*/
public static EntityMinecart placeCart(String owner, ItemStack cart, World world, int i, int j, int k)
{
public static EntityMinecart placeCart(String owner, ItemStack cart, World world, int i, int j, int k) {
if(cart == null) {
return null;
}
@ -131,7 +144,7 @@ public abstract class CartTools
return mi.placeCart(owner, cart, world, i, j, k);
} else if(cart.getItem() instanceof ItemMinecart) {
try {
boolean placed = cart.getItem().onItemUseFirst(cart, null, world, i, j, k, 0, 0, 0, 0);
boolean placed = cart.getItem().onItemUse(cart, null, world, i, j, k, 0, 0, 0, 0);
if(placed) {
List<EntityMinecart> carts = getMinecartsAt(world, i, j, k, 0.3f);
if(carts.size() > 0) {
@ -152,8 +165,7 @@ public abstract class CartTools
* @param cart
* @param stack
*/
public static void offerOrDropItem(EntityMinecart cart, ItemStack stack)
{
public static void offerOrDropItem(EntityMinecart cart, ItemStack stack) {
EntityMinecart link_A = getLinkageManager(cart.worldObj).getLinkedCartA(cart);
EntityMinecart link_B = getLinkageManager(cart.worldObj).getLinkedCartB(cart);
@ -169,26 +181,22 @@ public abstract class CartTools
}
}
public static boolean isMinecartOnRailAt(World world, int i, int j, int k, float sensitivity)
{
public static boolean isMinecartOnRailAt(World world, int i, int j, int k, float sensitivity) {
return isMinecartOnRailAt(world, i, j, k, sensitivity, null, true);
}
public static boolean isMinecartOnRailAt(World world, int i, int j, int k, float sensitivity, Class<? extends EntityMinecart> type, boolean subclass)
{
public static boolean isMinecartOnRailAt(World world, int i, int j, int k, float sensitivity, Class<? extends EntityMinecart> type, boolean subclass) {
if(BlockRail.isRailBlockAt(world, i, j, k)) {
return isMinecartAt(world, i, j, k, sensitivity, type, subclass);
}
return false;
}
public static boolean isMinecartOnAnySide(World world, int i, int j, int k, float sensitivity)
{
public static boolean isMinecartOnAnySide(World world, int i, int j, int k, float sensitivity) {
return isMinecartOnAnySide(world, i, j, k, sensitivity, null, true);
}
public static boolean isMinecartOnAnySide(World world, int i, int j, int k, float sensitivity, Class<? extends EntityMinecart> type, boolean subclass)
{
public static boolean isMinecartOnAnySide(World world, int i, int j, int k, float sensitivity, Class<? extends EntityMinecart> type, boolean subclass) {
List<EntityMinecart> list = new ArrayList<EntityMinecart>();
for(int side = 0; side < 6; side++) {
list.addAll(getMinecartsOnSide(world, i, j, k, sensitivity, ForgeDirection.getOrientation(side)));
@ -206,13 +214,11 @@ public abstract class CartTools
return false;
}
public static boolean isMinecartAt(World world, int i, int j, int k, float sensitivity)
{
public static boolean isMinecartAt(World world, int i, int j, int k, float sensitivity) {
return isMinecartAt(world, i, j, k, sensitivity, null, true);
}
public static boolean isMinecartAt(World world, int i, int j, int k, float sensitivity, Class<? extends EntityMinecart> type, boolean subclass)
{
public static boolean isMinecartAt(World world, int i, int j, int k, float sensitivity, Class<? extends EntityMinecart> type, boolean subclass) {
List<EntityMinecart> list = getMinecartsAt(world, i, j, k, sensitivity);
if(type == null) {
@ -227,8 +233,7 @@ public abstract class CartTools
return false;
}
public static List<EntityMinecart> getMinecartsOnAllSides(World world, int i, int j, int k, float sensitivity)
{
public static List<EntityMinecart> getMinecartsOnAllSides(World world, int i, int j, int k, float sensitivity) {
List<EntityMinecart> carts = new ArrayList<EntityMinecart>();
for(int side = 0; side < 6; side++) {
carts.addAll(getMinecartsOnSide(world, i, j, k, sensitivity, ForgeDirection.getOrientation(side)));
@ -237,8 +242,7 @@ public abstract class CartTools
return carts;
}
public static List<EntityMinecart> getMinecartsOnAllSides(World world, int i, int j, int k, float sensitivity, Class<? extends EntityMinecart> type, boolean subclass)
{
public static List<EntityMinecart> getMinecartsOnAllSides(World world, int i, int j, int k, float sensitivity, Class<? extends EntityMinecart> type, boolean subclass) {
List<EntityMinecart> list = new ArrayList<EntityMinecart>();
List<EntityMinecart> carts = new ArrayList<EntityMinecart>();
for(int side = 0; side < 6; side++) {
@ -253,8 +257,7 @@ public abstract class CartTools
return carts;
}
private static int getYOnSide(int y, ForgeDirection side)
{
private static int getYOnSide(int y, ForgeDirection side) {
switch (side) {
case UP:
return y + 1;
@ -265,8 +268,7 @@ public abstract class CartTools
}
}
private static int getXOnSide(int x, ForgeDirection side)
{
private static int getXOnSide(int x, ForgeDirection side) {
switch (side) {
case EAST:
return x + 1;
@ -277,8 +279,7 @@ public abstract class CartTools
}
}
private static int getZOnSide(int z, ForgeDirection side)
{
private static int getZOnSide(int z, ForgeDirection side) {
switch (side) {
case NORTH:
return z - 1;
@ -289,31 +290,26 @@ public abstract class CartTools
}
}
public static List<EntityMinecart> getMinecartsOnSide(World world, int i, int j, int k, float sensitivity, ForgeDirection side)
{
public static List<EntityMinecart> getMinecartsOnSide(World world, int i, int j, int k, float sensitivity, ForgeDirection side) {
return getMinecartsAt(world, getXOnSide(i, side), getYOnSide(j, side), getZOnSide(k, side), sensitivity);
}
public static boolean isMinecartOnSide(World world, int i, int j, int k, float sensitivity, ForgeDirection side)
{
public static boolean isMinecartOnSide(World world, int i, int j, int k, float sensitivity, ForgeDirection side) {
return getMinecartOnSide(world, i, j, k, sensitivity, side) != null;
}
public static EntityMinecart getMinecartOnSide(World world, int i, int j, int k, float sensitivity, ForgeDirection side)
{
public static EntityMinecart getMinecartOnSide(World world, int i, int j, int k, float sensitivity, ForgeDirection side) {
for(EntityMinecart cart : getMinecartsOnSide(world, i, j, k, sensitivity, side)) {
return cart;
}
return null;
}
public static boolean isMinecartOnSide(World world, int i, int j, int k, float sensitivity, ForgeDirection side, Class<? extends EntityMinecart> type, boolean subclass)
{
public static boolean isMinecartOnSide(World world, int i, int j, int k, float sensitivity, ForgeDirection side, Class<? extends EntityMinecart> type, boolean subclass) {
return getMinecartOnSide(world, i, j, k, sensitivity, side, type, subclass) != null;
}
public static EntityMinecart getMinecartOnSide(World world, int i, int j, int k, float sensitivity, ForgeDirection side, Class<? extends EntityMinecart> type, boolean subclass)
{
public static EntityMinecart getMinecartOnSide(World world, int i, int j, int k, float sensitivity, ForgeDirection side, Class<? extends EntityMinecart> type, boolean subclass) {
for(EntityMinecart cart : getMinecartsOnSide(world, i, j, k, sensitivity, side)) {
if(type == null || (subclass && type.isInstance(cart)) || cart.getClass() == type) {
return cart;
@ -331,8 +327,7 @@ public abstract class CartTools
* @param sensitivity Controls the size of the search box, ranges from (-inf, 0.49].
* @return
*/
public static List<EntityMinecart> getMinecartsAt(World world, int i, int j, int k, float sensitivity)
{
public static List<EntityMinecart> getMinecartsAt(World world, int i, int j, int k, float sensitivity) {
sensitivity = Math.min(sensitivity, 0.49f);
List entities = world.getEntitiesWithinAABB(net.minecraft.src.EntityMinecart.class, AxisAlignedBB.getAABBPool().addOrModifyAABBInPool(i + sensitivity, j + sensitivity, k + sensitivity, i + 1 - sensitivity, j + 1 - sensitivity, k + 1 - sensitivity));
List<EntityMinecart> carts = new ArrayList<EntityMinecart>();
@ -342,8 +337,7 @@ public abstract class CartTools
return carts;
}
public static List<EntityMinecart> getMinecartsIn(World world, int i1, int j1, int k1, int i2, int j2, int k2)
{
public static List<EntityMinecart> getMinecartsIn(World world, int i1, int j1, int k1, int i2, int j2, int k2) {
List entities = world.getEntitiesWithinAABB(net.minecraft.src.EntityMinecart.class, AxisAlignedBB.getAABBPool().addOrModifyAABBInPool(i1, j1, k1, i2, j2, k2));
List<EntityMinecart> carts = new ArrayList<EntityMinecart>();
for(Object o : entities) {
@ -360,13 +354,11 @@ public abstract class CartTools
* @param cart
* @return speed
*/
public static double getCartSpeedUncapped(EntityMinecart cart)
{
public static double getCartSpeedUncapped(EntityMinecart cart) {
return Math.sqrt(cart.motionX * cart.motionX + cart.motionZ * cart.motionZ);
}
public static boolean cartVelocityIsLessThan(EntityMinecart cart, float vel)
{
public static boolean cartVelocityIsLessThan(EntityMinecart cart, float vel) {
return Math.abs(cart.motionX) < vel && Math.abs(cart.motionZ) < vel;
}
}

View file

View file

View file

@ -0,0 +1,56 @@
package railcraft.common.api.carts;
public interface IExplosiveCart
{
/**
* If set to true the cart should explode after
* whatever fuse duration is set.
*
* @param primed
*/
public void setPrimed(boolean primed);
/**
* Returns whether the cart is primed to explode.
*
* @return primed
*/
public boolean isPrimed();
/**
* Returns the length of the current fuse.
*
* @return fuse length in ticks
*/
public int getFuse();
/**
* Optional function to allow setting the fuse duration.
*
* Used by the Priming Track.
*
* @param fuse in ticks
*/
public void setFuse(int fuse);
/**
* Returns the blast radius, but I don't think anything currently uses this.
*
* @return blast radius
*/
public float getBlastRadius();
/**
* Optional function to allow setting the blast radius.
*
* @param radius
*/
public void setBlastRadius(float radius);
/**
* Causes the cart to explode immediately.
*
*/
public void explode();
}

View file

View file

View file

View file

0
src/common/railcraft/common/api/carts/IMinecart.java Normal file → Executable file
View file

View file

View file

View file

View file

View file

View file

View file

View file

@ -31,7 +31,7 @@ public enum EnumItemType
}
switch (this) {
case FUEL:
return TileEntityFurnace.getItemBurnTime(stack) > 0;
return TileEntityFurnace.isItemFuel(stack);
case RAIL:
return stack.getItem() instanceof ITrackItem || (stack.getItem() instanceof ItemBlock && BlockRail.isRailBlock(stack.itemID));
case MINECART:

View file

View file

View file

View file

@ -62,6 +62,7 @@ public final class ItemRegistry
*/
public static void registerItem(String tag, ItemStack item)
{
tag = tag.replace("rc.", "");
registry.put(tag, item);
}

View file

View file

View file

View file

View file

@ -4,6 +4,7 @@ import java.util.List;
import net.minecraft.src.IRecipe;
import net.minecraft.src.InventoryCrafting;
import net.minecraft.src.ItemStack;
import net.minecraft.src.World;
/**
*
@ -16,7 +17,7 @@ public interface IRollingMachineCraftingManager
void addShapelessRecipe(ItemStack output, Object[] compenents);
ItemStack findMatchingRecipe(InventoryCrafting inventorycrafting);
ItemStack findMatchingRecipe(InventoryCrafting inventorycrafting, World world);
List<IRecipe> getRecipeList();

View file

View file

View file

View file

View file

View file

View file

View file

View file

View file

View file

View file

View file

View file

0
src/common/railcraft/common/api/tracks/ITrackTile.java Normal file → Executable file
View file

0
src/common/railcraft/common/api/tracks/RailTools.java Normal file → Executable file
View file

View file

View file

0
src/common/railcraft/common/api/tracks/TrackSpec.java Normal file → Executable file
View file

View file

@ -1,61 +0,0 @@
package universalelectricity;
import net.minecraft.src.Block;
import net.minecraft.src.Item;
import net.minecraft.src.ItemStack;
import universalelectricity.ore.OreGenBase;
import universalelectricity.prefab.ItemElectric;
/**
* The main class for managing Basic Component items and blocks. Reference objects from this class to add them to your
* recipes and such.
* @author Calclavia
*/
public class BasicComponents
{
public static final String FILE_PATH = "/basiccomponents/textures/";
public static final String BLOCK_TEXTURE_FILE = FILE_PATH + "blocks.png";
public static final String ITEM_TEXTURE_FILE = FILE_PATH + "items.png";
/**
* Try not reference to these variable in pre-initialization as they might be null!
*/
public static int BLOCK_ID_PREFIX = 3970;
//Metadata ore block that contains copper
public static Block blockBasicOre;
public static Block blockCopperWire;
public static Block oilMoving;
public static Block oilStill;
public static Block blockMachine;
public static Block blockMulti;
public static final int ITEM_ID_PREFIX = 13970;
public static ItemElectric itemBattery;
public static Item itemWrench;
public static Item itemCopperIngot;
public static Item itemTinIngot;
public static Item itemSteelIngot;
public static Item itemSteelDust;
public static Item itemCircuit;
public static Item itemBronzeIngot;
public static Item itemBronzeDust;
public static Item itemSteelPlate;
public static Item itemBronzePlate;
public static Item itemMotor;
public static Item itemOilBucket;
public static Item itemCopperPlate;
public static Item itemTinPlate;
/**
* Some neat references to help you out.
*/
public static ItemStack coalGenerator;
public static ItemStack batteryBox;
public static ItemStack electricFurnace;
public static OreGenBase copperOreGeneration;
public static OreGenBase tinOreGeneration;
}

View file

@ -1,56 +0,0 @@
package universalelectricity;
import net.minecraftforge.common.Configuration;
public class UEConfig
{
public static int getConfigData(Configuration configuration, String name, int defaultInt)
{
configuration.load();
int returnInt = defaultInt;
returnInt = Integer.parseInt(configuration.get(name, Configuration.CATEGORY_GENERAL, defaultInt).value);
configuration.save();
return returnInt;
}
public static boolean getConfigData(Configuration configuration, String name, boolean defaultBoolean)
{
configuration.load();
boolean returnBoolean = defaultBoolean;
returnBoolean = Boolean.parseBoolean(configuration.get(name, Configuration.CATEGORY_GENERAL, defaultBoolean).value);
configuration.save();
return returnBoolean;
}
public static int getBlockConfigID(Configuration configuration, String name, int defaultID)
{
configuration.load();
int id = defaultID;
id = Integer.parseInt(configuration.getBlock(name, defaultID).value);
if (id <= 136)
{
return defaultID;
}
configuration.save();
return id;
}
public static int getItemConfigID(Configuration configuration, String name, int defaultID)
{
configuration.load();
int id = defaultID;
id = Integer.parseInt(configuration.getItem(name, Configuration.CATEGORY_ITEM, defaultID).value);
if (id < 256)
{
return defaultID;
}
configuration.save();
return id;
}
}

View file

@ -1,90 +0,0 @@
package universalelectricity;
import java.io.File;
import net.minecraft.src.MapColor;
import net.minecraft.src.Material;
import net.minecraftforge.common.Configuration;
import net.minecraftforge.common.ForgeVersion;
import cpw.mods.fml.common.Loader;
public class UniversalElectricity
{
public static final int MAJOR_VERSION = 0;
public static final int MINOR_VERSION = 9;
public static final int REVISION_VERSION = 3;
public static final String VERSION = MAJOR_VERSION+"."+MINOR_VERSION+"."+REVISION_VERSION;
public static final Configuration CONFIGURATION = new Configuration(new File(Loader.instance().getConfigDir(), "UniversalElectricity/UniversalElectricity.cfg"));
//EU to Watts ratio
public static final float IC2_RATIO = (float)UEConfig.getConfigData(CONFIGURATION, "IndustrialCraft Conversion Ratio", 7);
//MJ to Watts ratio.
public static final float BC3_RATIO = (float)UEConfig.getConfigData(CONFIGURATION, "BuildCraft Conversion Ratio", 85);;
public static final float TO_IC2_RATIO = 1/IC2_RATIO;
public static final float TO_BC_RATIO = 1/BC3_RATIO;
/**
* Use this material for all your machine blocks. It can be breakable by hand.
*/
public static final Material machine = new Material(MapColor.ironColor);
public static void versionLock(int major, int minor, int revision, boolean strict)
{
if(MAJOR_VERSION != major)
{
throw new RuntimeException("Universal Electricity wrong version! Require v"+major+"."+minor+"."+revision);
}
if(MINOR_VERSION < minor)
{
throw new RuntimeException("Universal Electricity minor version is too old! Require v"+major+"."+minor+"."+revision);
}
if(REVISION_VERSION < revision)
{
if(strict)
{
throw new RuntimeException("Universal Electricity is too old! Require v"+major+"."+minor+"."+revision);
}
else
{
System.out.println("Universal Electricity is not the specified version. Odd things might happen. Require "+major+"."+minor+"."+revision);
}
}
}
public static void forgeLock(int major, int minor, int revision, boolean strict)
{
if(ForgeVersion.getMajorVersion() != major)
{
throw new RuntimeException("Universal Electricity: Wrong Minecraft Forge version! Require "+major+"."+minor+"."+revision);
}
if(ForgeVersion.getMinorVersion() < minor)
{
throw new RuntimeException("Universal Electricity: Minecraft Forge minor version is too old! Require "+major+"."+minor+"."+revision);
}
if(ForgeVersion.getRevisionVersion() < revision)
{
if(strict)
{
throw new RuntimeException("Universal Electricity: Minecraft Forge revision version is too old! Require "+major+"."+minor+"."+revision);
}
else
{
System.out.println("Universal Electricity Warning: Minecraft Forge is not the specified version. Odd things might happen. Require "+major+"."+minor+"."+revision);
}
}
}
public static void forgeLock(int major, int minor, int revision)
{
forgeLock(major, minor, revision, false);
}
}

View file

@ -0,0 +1,50 @@
package universalelectricity.core;
import net.minecraftforge.common.Configuration;
public class UEConfig
{
public static int getConfigData(Configuration configuration, String name, int defaultInt)
{
configuration.load();
int returnInt = defaultInt;
returnInt = Integer.parseInt(configuration.get(name, Configuration.CATEGORY_GENERAL, defaultInt).value);
configuration.save();
return returnInt;
}
public static boolean getConfigData(Configuration configuration, String name, boolean defaultBoolean)
{
configuration.load();
boolean returnBoolean = defaultBoolean;
returnBoolean = Boolean.parseBoolean(configuration.get(name, Configuration.CATEGORY_GENERAL, defaultBoolean).value);
configuration.save();
return returnBoolean;
}
public static int getBlockConfigID(Configuration configuration, String name, int defaultID)
{
configuration.load();
int id = defaultID;
id = Integer.parseInt(configuration.getBlock(name, defaultID).value);
if (id <= 136) { return defaultID; }
configuration.save();
return id;
}
public static int getItemConfigID(Configuration configuration, String name, int defaultID)
{
configuration.load();
int id = defaultID;
id = Integer.parseInt(configuration.getItem(name, Configuration.CATEGORY_ITEM, defaultID).value);
if (id < 256) { return defaultID; }
configuration.save();
return id;
}
}

View file

@ -0,0 +1,68 @@
package universalelectricity.core;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.ForgeSubscribe;
import net.minecraftforge.event.world.WorldEvent.Load;
import net.minecraftforge.event.world.WorldEvent.Unload;
import universalelectricity.electricity.ElectricityManager;
import universalelectricity.electricity.ElectricityManagerTicker;
import cpw.mods.fml.common.FMLLog;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.Side;
import cpw.mods.fml.common.registry.TickRegistry;
/**
* A class used to load Universal Electricity and make it work.
* @author Calclavia
*
*/
public class UELoader
{
public static final UELoader INSTANCE = new UELoader();
public static boolean isInitialized = false;
public void initiate()
{
if (!isInitialized)
{
TickRegistry.registerTickHandler(new ElectricityManagerTicker(), Side.SERVER);
ElectricityManager.instance = new ElectricityManager();
MinecraftForge.EVENT_BUS.register(this);
if (UniversalElectricity.BC3_RATIO <= 0 || !Loader.isModLoaded("BuildCraft|Core"))
{
FMLLog.fine("Disabled Buildcraft electricity conversion!");
}
else
{
FMLLog.fine("Buildcraft conversion ratio: " + UniversalElectricity.BC3_RATIO);
}
if (UniversalElectricity.IC2_RATIO <= 0 || !Loader.isModLoaded("IC2"))
{
FMLLog.fine("Disabled Industrialcraft electricity conversion!");
}
else
{
FMLLog.fine("IC2 conversion ratio: " + UniversalElectricity.IC2_RATIO);
}
FMLLog.finest("Universal Electricity v" + UniversalElectricity.VERSION + " successfully loaded!");
isInitialized = true;
}
}
@ForgeSubscribe
public void onWorldLoad(Load event)
{
ElectricityManagerTicker.inGameTicks = 0;
}
@ForgeSubscribe
public void onWorldUnload(Unload event)
{
ElectricityManager.instance = new ElectricityManager();
}
}

View file

@ -0,0 +1,119 @@
package universalelectricity.core;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.src.MapColor;
import net.minecraft.src.Material;
import net.minecraftforge.common.Configuration;
import net.minecraftforge.common.ForgeVersion;
import cpw.mods.fml.common.FMLLog;
import cpw.mods.fml.common.Loader;
/**
* Instructions for using the Universal Electricity API.
*
* The less you include of the API, the more compatible your
* mod will be for future releases of Universal Electricity.
*
* REQUIRED PACKAGES:
* "universalelectricity"
* "universalelectricity.electricity"
* "universalelectricity.implements" - Some interfaces can be removed if not needed.
*
* The rest of the classes should be removed if you are not going to use them.
*
* @author Calclavia
*
*/
public class UniversalElectricity
{
/**
* The version of the Universal Electricity API.
*/
public static final int MAJOR_VERSION = 1;
public static final int MINOR_VERSION = 0;
public static final int REVISION_VERSION = 0;
public static final String VERSION = MAJOR_VERSION + "." + MINOR_VERSION + "." + REVISION_VERSION;
/**
* The Universal Electricity configuration file.
*/
public static final Configuration CONFIGURATION = new Configuration(new File(Loader.instance().getConfigDir(), "UniversalElectricity/UniversalElectricity.cfg"));
/**
* Conversion ratios between Buildcraft and Industrialcraft energy.
*/
// EU to Watts ratio
public static final float IC2_RATIO = (float) UEConfig.getConfigData(CONFIGURATION, "IndustrialCraft Conversion Ratio", 7);
// MJ to Watts ratio.
public static final float BC3_RATIO = (float) UEConfig.getConfigData(CONFIGURATION, "BuildCraft Conversion Ratio", 85);;
public static final float TO_IC2_RATIO = 1 / IC2_RATIO;
public static final float TO_BC_RATIO = 1 / BC3_RATIO;
/**
* Use this material for all your machine blocks. It can be breakable by
* hand.
*/
public static final Material machine = new Material(MapColor.ironColor);
public static final List<Object> mods = new ArrayList<Object>();
/**
* You must register your mod with Universal Electricity. Call this in your
* mod's pre-initialization stage.
*/
public static void register(Object mod, int major, int minor, int revision, boolean strict)
{
if (MAJOR_VERSION != major) { throw new RuntimeException("Universal Electricity wrong version! Require v" + major + "." + minor + "." + revision); }
if (MINOR_VERSION < minor) { throw new RuntimeException("Universal Electricity minor version is too old! Require v" + major + "." + minor + "." + revision); }
if (REVISION_VERSION < revision)
{
if (strict)
{
throw new RuntimeException("Universal Electricity is too old! Require v" + major + "." + minor + "." + revision);
}
else
{
FMLLog.warning("Universal Electricity is not the specified version. Odd things might happen. Recommend to have v" + major + "." + minor + "." + revision);
}
}
mods.add(mod);
FMLLog.fine(mod.getClass().getSimpleName()+" has been registered to Universal Electricity.");
UELoader.INSTANCE.initiate();
}
/**
* A function that allows you to lock your mod to a specific version of
* Forge.
*/
public static void forgeLock(int major, int minor, int revision, boolean strict)
{
if (ForgeVersion.getMajorVersion() != major) { throw new RuntimeException("Universal Electricity: Wrong Minecraft Forge version! Require " + major + "." + minor + "." + revision); }
if (ForgeVersion.getMinorVersion() < minor) { throw new RuntimeException("Universal Electricity: Minecraft Forge minor version is too old! Require " + major + "." + minor + "." + revision); }
if (ForgeVersion.getRevisionVersion() < revision)
{
if (strict)
{
throw new RuntimeException("Universal Electricity: Minecraft Forge revision version is too old! Require " + major + "." + minor + "." + revision);
}
else
{
System.out.println("Universal Electricity Warning: Minecraft Forge is not the specified version. Odd things might happen. Require " + major + "." + minor + "." + revision);
}
}
}
public static void forgeLock(int major, int minor, int revision)
{
forgeLock(major, minor, revision, false);
}
}

View file

@ -0,0 +1,106 @@
package universalelectricity.core;
import net.minecraft.src.MathHelper;
/**
* Vector2 Class is used for defining objects in a 2D space. Vector2 makes it
* easier to handle the coordinates of objects. Instead of fumbling with x and y
* variables, all x and y variables are stored in one class. Vector3.x,
* Vector3.y.
*
* @author Calclavia
*/
public class Vector2 implements Cloneable
{
public double x;
public double y;
public Vector2()
{
this(0, 0);
}
public Vector2(int x, int y)
{
this.x = x;
this.y = y;
}
public Vector2(double x, double y)
{
this.x = x;
this.y = y;
}
// Returns the values as an int
public int intX()
{
return (int) Math.floor(this.x);
}
public int intY()
{
return (int) Math.floor(this.y);
}
/**
* Makes a new copy of this Vector. Prevents variable referencing problems.
*/
@Override
public Vector2 clone()
{
return new Vector2(this.x, this.y);
}
public static boolean isPointInRegion(Vector2 point, Vector2 minPoint, Vector2 maxPoint)
{
return (point.x > minPoint.x && point.x < maxPoint.x) && (point.y > minPoint.y && point.y < maxPoint.y);
}
public static double distance(Vector2 par1, Vector2 par2)
{
double var2 = par1.x - par2.x;
double var4 = par1.y - par2.y;
return MathHelper.sqrt_double(var2 * var2 + var4 * var4);
}
public static double slope(Vector2 par1, Vector2 par2)
{
double var2 = par1.x - par2.x;
double var4 = par1.y - par2.y;
return var4 / var2;
}
public void add(Vector2 par1)
{
this.x += par1.x;
this.y += par1.y;
}
public void add(double par1)
{
this.x += par1;
this.y += par1;
}
public Vector2 round()
{
return new Vector2(Math.round(this.x), Math.round(this.y));
}
public Vector2 floor()
{
return new Vector2(Math.floor(this.x), Math.floor(this.y));
}
public String output()
{
return "Vector2: " + this.x + "," + this.y;
}
public void printVector()
{
System.out.println(output());
}
}

View file

@ -0,0 +1,448 @@
package universalelectricity.core;
import net.minecraft.src.ChunkCoordinates;
import net.minecraft.src.Entity;
import net.minecraft.src.MathHelper;
import net.minecraft.src.MovingObjectPosition;
import net.minecraft.src.NBTTagCompound;
import net.minecraft.src.TileEntity;
import net.minecraft.src.Vec3;
import net.minecraft.src.World;
import net.minecraftforge.common.ForgeDirection;
import universalelectricity.implement.IConnector;
/**
* Vector3 Class is used for defining objects in a 3D space. Vector3 makes it
* easier to handle the coordinates of objects. Instead of fumbling with x, y
* and z variables, all x, y and z variables are stored in one class. Vector3.x,
* Vector3.y, Vector3.z.
*
* @author Calclavia
*/
public class Vector3 extends Vector2 implements Cloneable
{
public double z;
public Vector3()
{
this(0, 0, 0);
}
public Vector3(int x, int y, int z)
{
this.x = x;
this.y = y;
this.z = z;
}
public Vector3(double x, double y, double z)
{
this.x = x;
this.y = y;
this.z = z;
}
/**
* Returns the coordinates as integers
*/
public int intX()
{
return (int) Math.floor(this.x);
}
public int intY()
{
return (int) Math.floor(this.y);
}
public int intZ()
{
return (int) Math.floor(this.z);
}
/**
* Makes a new copy of this Vector. Prevents variable referencing problems.
*/
@Override
public Vector3 clone()
{
return new Vector3(this.x, this.y, this.z);
}
/**
* Converts a TileEntity's position into Vector3
*/
public static Vector3 get(Entity par1)
{
return new Vector3(par1.posX, par1.posY, par1.posZ);
}
/**
* Converts an entity's position into Vector3
*/
public static Vector3 get(TileEntity par1)
{
return new Vector3(par1.xCoord, par1.yCoord, par1.zCoord);
}
/**
* Converts from Vec3 into a Vector3
*/
public static Vector3 get(Vec3 par1)
{
return new Vector3(par1.xCoord, par1.yCoord, par1.zCoord);
}
/**
* Converts a MovingObjectPosition to Vector3
*/
public static Vector3 get(MovingObjectPosition par1)
{
return new Vector3(par1.blockX, par1.blockY, par1.blockZ);
}
/**
* Converts a MovingObjectPosition to Vector3
*/
public static Vector3 get(ChunkCoordinates par1)
{
return new Vector3(par1.posX, par1.posY, par1.posZ);
}
public int getBlockID(World world)
{
return world.getBlockId(this.intX(), this.intY(), this.intZ());
}
public int getBlockMetadata(World world)
{
return world.getBlockMetadata(this.intX(), this.intY(), this.intZ());
}
public TileEntity getTileEntity(World world)
{
return world.getBlockTileEntity(this.intX(), this.intY(), this.intZ());
}
public void setBlock(World world, int id, int metadata)
{
world.setBlockAndMetadata(this.intX(), this.intY(), this.intZ(), id, metadata);
}
public void setBlock(World world, int id)
{
world.setBlock(this.intX(), this.intY(), this.intZ(), id);
}
public void setBlockWithNotify(World world, int id, int metadata)
{
world.setBlockAndMetadataWithNotify(this.intX(), this.intY(), this.intZ(), id, metadata);
}
public void setBlockWithNotify(World world, int id)
{
world.setBlockWithNotify(this.intX(), this.intY(), this.intZ(), id);
}
/**
* Converts this Vector3 into a Vector2 by dropping the Y axis.
*/
public Vector2 toVector2()
{
return new Vector2(this.x, this.z);
}
/**
* Converts this vector three into a Minecraft Vec3 object
*/
public Vec3 toVec3()
{
return Vec3.createVectorHelper(this.x, this.y, this.z);
}
/**
* Checks if a Vector3 point is located inside a region
*/
public static boolean isPointInRegion(Vector3 point, Vector3 minPoint, Vector3 maxPoint)
{
return (point.x > minPoint.x && point.x < maxPoint.x) && (point.y > minPoint.y && point.y < maxPoint.y) && (point.z > minPoint.z && point.z < maxPoint.z);
}
/**
* Compares two vectors and see if they are equal. True if so.
*/
public boolean isEqual(Vector3 vector3)
{
return (this.x == vector3.x && this.y == vector3.y && this.z == vector3.z);
}
/**
* Gets the distance between two vectors
*
* @return The distance
*/
public static double distance(Vector3 par1, Vector3 par2)
{
double var2 = par1.x - par2.x;
double var4 = par1.y - par2.y;
double var6 = par1.z - par2.z;
return MathHelper.sqrt_double(var2 * var2 + var4 * var4 + var6 * var6);
}
public double distanceTo(Vector3 vector3)
{
double var2 = vector3.x - this.x;
double var4 = vector3.y - this.y;
double var6 = vector3.z - this.z;
return MathHelper.sqrt_double(var2 * var2 + var4 * var4 + var6 * var6);
}
public static Vector3 subtract(Vector3 par1, Vector3 par2)
{
return new Vector3(par1.x - par2.x, par1.y - par2.y, par1.z - par2.z);
}
public static Vector3 add(Vector3 par1, Vector3 par2)
{
return new Vector3(par1.x + par2.x, par1.y + par2.y, par1.z + par2.z);
}
public static Vector3 add(Vector3 par1, double par2)
{
return new Vector3(par1.x + par2, par1.y + par2, par1.z + par2);
}
public void add(Vector3 par1)
{
this.x += par1.x;
this.y += par1.y;
this.z += par1.z;
}
@Override
public void add(double par1)
{
this.x += par1;
this.y += par1;
this.z += par1;
}
public static Vector3 multiply(Vector3 par1, Vector3 par2)
{
return new Vector3(par1.x * par2.x, par1.y * par2.y, par1.z * par2.z);
}
public static Vector3 multiply(Vector3 par1, double par2)
{
return new Vector3(par1.x * par2, par1.y * par2, par1.z * par2);
}
public static Vector3 readFromNBT(String prefix, NBTTagCompound par1NBTTagCompound)
{
Vector3 tempVector = new Vector3();
tempVector.x = par1NBTTagCompound.getDouble(prefix + "X");
tempVector.y = par1NBTTagCompound.getDouble(prefix + "Y");
tempVector.z = par1NBTTagCompound.getDouble(prefix + "Z");
return tempVector;
}
/**
* Saves this Vector3 to disk
*
* @param prefix
* - The prefix of this save. Use some unique string.
* @param par1NBTTagCompound
* - The NBT compound object to save the data in
*/
public void writeToNBT(String prefix, NBTTagCompound par1NBTTagCompound)
{
par1NBTTagCompound.setDouble(prefix + "X", this.x);
par1NBTTagCompound.setDouble(prefix + "Y", this.y);
par1NBTTagCompound.setDouble(prefix + "Z", this.z);
}
@Override
public Vector3 round()
{
return new Vector3(Math.round(this.x), Math.round(this.y), Math.round(this.z));
}
@Override
public Vector3 floor()
{
return new Vector3(Math.floor(this.x), Math.floor(this.y), Math.floor(this.z));
}
@Override
public String output()
{
return "Vector3: " + this.x + "," + this.y + "," + this.z;
}
/**
* Gets a position relative to another position's side
*
* @param position
* - The position
* @param side
* - The side. 0-5
* @return The position relative to the original position's side
*/
public void modifyPositionFromSide(ForgeDirection side)
{
switch (side.ordinal())
{
case 0:
this.y -= 1;
break;
case 1:
this.y += 1;
break;
case 2:
this.z -= 1;
break;
case 3:
this.z += 1;
break;
case 4:
this.x -= 1;
break;
case 5:
this.x += 1;
break;
}
}
public static TileEntity getTileEntityFromSide(World world, Vector3 position, ForgeDirection side)
{
position.modifyPositionFromSide(side);
return world.getBlockTileEntity(position.intX(), position.intY(), position.intZ());
}
/**
* Gets a connector unit based on the given side.
*/
public static TileEntity getConnectorFromSide(World world, Vector3 position, ForgeDirection side)
{
TileEntity tileEntity = getTileEntityFromSide(world, position, side);
if (tileEntity instanceof IConnector)
{
if (((IConnector) tileEntity).canConnect(getOrientationFromSide(side, ForgeDirection.NORTH))) { return tileEntity; }
}
return null;
}
/**
* Finds the side of a block depending on it's facing direction from the
* given side. The side numbers are compatible with the
* function"getBlockTextureFromSideAndMetadata".
*
* Bottom: 0; Top: 1; Back: 2; Front: 3; Left: 4; Right: 5;
*
* @param front
* - The direction in which this block is facing/front. Use a
* number between 0 and 5. Default is 3.
* @param side
* - The side you are trying to find. A number between 0 and 5.
* @return The side relative to the facing direction.
*/
public static ForgeDirection getOrientationFromSide(ForgeDirection front, ForgeDirection side)
{
switch (front.ordinal())
{
case 0:
switch (side.ordinal())
{
case 0:
return ForgeDirection.getOrientation(3);
case 1:
return ForgeDirection.getOrientation(2);
case 2:
return ForgeDirection.getOrientation(1);
case 3:
return ForgeDirection.getOrientation(0);
case 4:
return ForgeDirection.getOrientation(5);
case 5:
return ForgeDirection.getOrientation(4);
}
case 1:
switch (side.ordinal())
{
case 0:
return ForgeDirection.getOrientation(4);
case 1:
return ForgeDirection.getOrientation(5);
case 2:
return ForgeDirection.getOrientation(0);
case 3:
return ForgeDirection.getOrientation(1);
case 4:
return ForgeDirection.getOrientation(2);
case 5:
return ForgeDirection.getOrientation(3);
}
case 2:
switch (side.ordinal())
{
case 0:
return ForgeDirection.getOrientation(0);
case 1:
return ForgeDirection.getOrientation(1);
case 2:
return ForgeDirection.getOrientation(3);
case 3:
return ForgeDirection.getOrientation(2);
case 4:
return ForgeDirection.getOrientation(5);
case 5:
return ForgeDirection.getOrientation(4);
}
case 3:
return side;
case 4:
switch (side.ordinal())
{
case 0:
return ForgeDirection.getOrientation(0);
case 1:
return ForgeDirection.getOrientation(1);
case 2:
return ForgeDirection.getOrientation(5);
case 3:
return ForgeDirection.getOrientation(4);
case 4:
return ForgeDirection.getOrientation(3);
case 5:
return ForgeDirection.getOrientation(2);
}
case 5:
switch (side.ordinal())
{
case 0:
return ForgeDirection.getOrientation(0);
case 1:
return ForgeDirection.getOrientation(1);
case 2:
return ForgeDirection.getOrientation(4);
case 3:
return ForgeDirection.getOrientation(5);
case 4:
return ForgeDirection.getOrientation(2);
case 5:
return ForgeDirection.getOrientation(3);
}
}
return ForgeDirection.UNKNOWN;
}
}

View file

@ -1,8 +1,8 @@
package universalelectricity.electricity;
/**
* A better way to storage information on electricity
* An easy way to display information on electricity.
*
* @author Calclavia
*/
@ -10,14 +10,7 @@ public class ElectricInfo
{
public static enum ElectricUnit
{
AMPERE("Amp", "I"),
AMP_HOUR("Amp Hour", "Ah"),
VOLTAGE("Volt", "V"),
WATT("Watt", "W"),
WATT_HOUR("Watt Hour", "Wh"),
RESISTANCE("Ohm", "R"),
CONDUCTANCE("Siemen", "S"),
JOULES("Joule", "J");
AMPERE("Amp", "I"), AMP_HOUR("Amp Hour", "Ah"), VOLTAGE("Volt", "V"), WATT("Watt", "W"), WATT_HOUR("Watt Hour", "Wh"), RESISTANCE("Ohm", "R"), CONDUCTANCE("Siemen", "S"), JOULES("Joule", "J");
public String name;
public String symbol;
@ -36,10 +29,7 @@ public class ElectricInfo
public static enum MeasurementUnit
{
MICRO("Micro", "mi", 0.000001),
MILLI("Milli", "m", 0.001),
KILO("Kilo", "k", 1000),
MEGA("Mega", "M", 1000000);
MICRO("Micro", "mi", 0.000001), MILLI("Milli", "m", 0.001), KILO("Kilo", "k", 1000), MEGA("Mega", "M", 1000000);
public String name;
public String symbol;
@ -156,30 +146,15 @@ public class ElectricInfo
unitName = unit.getPlural();
}
if(value == 0)
{
return value + " " + unitName;
}
if (value == 0) { return value + " " + unitName; }
if(value <= MeasurementUnit.MILLI.process)
{
return roundDecimals(MeasurementUnit.MICRO.process(value), significantFigures) + " " + MeasurementUnit.MICRO.getName(isShort)+unitName;
}
if (value <= MeasurementUnit.MILLI.process) { return roundDecimals(MeasurementUnit.MICRO.process(value), significantFigures) + " " + MeasurementUnit.MICRO.getName(isShort) + unitName; }
if(value < 1)
{
return roundDecimals(MeasurementUnit.MILLI.process(value), significantFigures) + " " + MeasurementUnit.MILLI.getName(isShort)+unitName;
}
if (value < 1) { return roundDecimals(MeasurementUnit.MILLI.process(value), significantFigures) + " " + MeasurementUnit.MILLI.getName(isShort) + unitName; }
if(value > MeasurementUnit.KILO.process)
{
return roundDecimals(MeasurementUnit.KILO.process(value), significantFigures) + " " + MeasurementUnit.KILO.getName(isShort)+unitName;
}
if (value > MeasurementUnit.KILO.process) { return roundDecimals(MeasurementUnit.KILO.process(value), significantFigures) + " " + MeasurementUnit.KILO.getName(isShort) + unitName; }
if(value > MeasurementUnit.MEGA.process)
{
return roundDecimals(MeasurementUnit.MEGA.process(value), significantFigures) + " " + MeasurementUnit.MEGA.getName(isShort)+unitName;
}
if (value > MeasurementUnit.MEGA.process) { return roundDecimals(MeasurementUnit.MEGA.process(value), significantFigures) + " " + MeasurementUnit.MEGA.getName(isShort) + unitName; }
return roundDecimals(value, significantFigures) + " " + unitName;
}
@ -198,26 +173,21 @@ public class ElectricInfo
{
if (value > 1)
{
if(significantFigures < 1)
{
return (int)value + " " + unit.getPlural();
}
if (significantFigures < 1) { return (int) value + " " + unit.getPlural(); }
return roundDecimals(value, significantFigures) + " " + unit.getPlural();
}
if(significantFigures < 1)
{
return (int)value + " " + unit.name;
}
if (significantFigures < 1) { return (int) value + " " + unit.name; }
return roundDecimals(value, significantFigures) + " " + unit.name;
}
/**
* Rounds a number to a specific number place places
* @param The number
*
* @param The
* number
* @return The rounded number
*/
public static double roundDecimals(double d, int significantFigures)

View file

@ -9,32 +9,32 @@ import java.util.Map;
import net.minecraft.src.TileEntity;
import net.minecraftforge.common.ForgeDirection;
import universalelectricity.Ticker;
import universalelectricity.core.Vector3;
import universalelectricity.implement.IConductor;
import universalelectricity.implement.IElectricityReceiver;
import universalelectricity.prefab.Vector3;
import cpw.mods.fml.common.FMLLog;
import cpw.mods.fml.common.TickType;
/**
* This class is used to manage electricity transferring and flow. It is also used to call updates on UE tile entities.
* This class is used to manage electricity
* transferring and flow. It is also used to call
* updates on UE tile entities.
*
* @author Calclavia
*
*/
public class ElectricityManager
{
/**
* ElectricityManager exists on both client and server side.
* Rely on the server side one as it is more accurate! Client side only simulates.
* ElectricityManager exists on both client
* and server side. Rely on the server side
* one as it is more accurate! Client side
* only simulates.
*/
public static ElectricityManager instance;
private List<IElectricityReceiver> electricityReceivers = new ArrayList<IElectricityReceiver>();
private List<IConductor> electricConductors = new ArrayList<IConductor>();
private List<ElectricityTransferData> electricityTransferQueue = new ArrayList<ElectricityTransferData>();
private List<ElectricityNetwork> electricityNetworks = new ArrayList<ElectricityNetwork>();
private int maxConnectionID = 0;
public ElectricityManager()
{
@ -42,52 +42,39 @@ public class ElectricityManager
}
/**
* Registers an electricity consumer for it to receive electricity.
* Call it in your consumer's tile entity constructor like this:
* ElectricityManager.registerConsumer(this);
* @param newUnit - The consumer to be registered.
*/
public void registerElectricUnit(IElectricityReceiver newUnit)
{
if (!this.electricityReceivers.contains(newUnit))
{
this.electricityReceivers.add(newUnit);
}
}
/**
* Registers a UE conductor
* @param conductor - The conductor tile entity
* @return - The ID of the connection line that is assigned to this conductor
* Registers a the conductor into the UE
* electricity net.
*
* @param conductor
* - The IConductor tile entity.
*/
public void registerConductor(IConductor newConductor)
{
cleanUpConnections();
this.electricityNetworks.add(new ElectricityNetwork(getMaxConnectionID(), newConductor));
if (!this.electricConductors.contains(newConductor))
{
this.electricConductors.add(newConductor);
}
this.electricityNetworks.add(new ElectricityNetwork(newConductor));
}
/**
* Merges two connection lines together into one.
* @param ID1 - ID of connection line
* @param ID2 - ID of connection line
* Merges two connection lines together into
* one.
*
* @param networkA
* - The network to be merged into.
* This network will be kept.
* @param networkB
* - The network to be merged. This
* network will be deleted.
*/
public void mergeConnection(int ID1, int ID2)
public void mergeConnection(ElectricityNetwork networkA, ElectricityNetwork networkB)
{
if(ID1 != ID2)
if (networkA != networkB)
{
ElectricityNetwork connection1 = getConnectionByID(ID1);
ElectricityNetwork connection2 = getConnectionByID(ID2);
if(connection1 != null && connection2 != null)
if (networkA != null && networkB != null)
{
connection1.conductors.addAll(connection2.conductors);
connection1.setID(ID1);
this.electricityNetworks.remove(connection2);
networkA.conductors.addAll(networkB.conductors);
networkA.setNetwork();
this.electricityNetworks.remove(networkB);
networkB = null;
}
else
{
@ -97,15 +84,23 @@ public class ElectricityManager
}
/**
* Separate one connection line into two different ones between two conductors.
* This function does this by resetting all wires in the connection line and
* making them each reconnect.
* @param conductorA - existing conductor
* @param conductorB - broken/invalid conductor
* Separate one connection line into two
* different ones between two conductors. This
* function does this by resetting all wires
* in the connection line and making them each
* reconnect.
*
* @param conductorA
* - existing conductor
* @param conductorB
* - broken/invalid conductor
*/
public void splitConnection(IConductor conductorA, IConductor conductorB)
{
ElectricityNetwork connection = getConnectionByID(conductorA.getConnectionID());
ElectricityNetwork connection = conductorA.getNetwork();
if (connection != null)
{
connection.cleanUpArray();
for (IConductor conductor : connection.conductors)
@ -121,29 +116,15 @@ public class ElectricityManager
}
}
}
/**
* Gets a electricity wire connection line by it's connection ID
* @param ID
* @return
*/
public ElectricityNetwork getConnectionByID(int ID)
else
{
cleanUpConnections();
for (int i = 0; i < this.electricityNetworks.size(); i++)
{
if (this.electricityNetworks.get(i).getID() == ID)
{
return this.electricityNetworks.get(i);
FMLLog.severe("Conductor invalid network while splitting connection!");
}
}
return null;
}
/**
* Clean up and remove useless connections
* Clean up and remove all useless and invalid
* connections.
*/
public void cleanUpConnections()
{
@ -166,34 +147,33 @@ public class ElectricityManager
}
/**
* Get the highest connection ID. Use this to assign new wire connection lines
* @return
*/
public int getMaxConnectionID()
{
this.maxConnectionID ++;
if(this.maxConnectionID >= Integer.MAX_VALUE)
{
this.maxConnectionID = 0;
}
return this.maxConnectionID;
}
/**
* Produces electricity into a specific wire which will be distributed across the electricity network.
* @param sender - The machine sending the electricity.
* @param targetConductor - The conductor receiving the electricity (or connected to the machine).
* @param amps - The amount of amps this machine is sending.
* @param voltage 0 The amount of volts this machine is sending.
* Produces electricity into a specific wire
* which will be distributed across the
* electricity network.
*
* @param sender
* The machine sending the
* electricity.
* @param targetConductor
* The conductor receiving the
* electricity (or connected to the
* machine).
* @param amps
* The amount of amps this machine
* is sending.
* @param voltage
* The amount of volts this machine
* is sending.
*/
public void produceElectricity(TileEntity sender, IConductor targetConductor, double amps, double voltage)
{
if (targetConductor != null && amps > 0 && voltage > 0)
{
//Find a path between this conductor and all connected units and try to send the electricity to them directly
ElectricityNetwork electricityNetwork = this.getConnectionByID(targetConductor.getConnectionID());
// Find a path between this conductor
// and all connected units and
// try to send the electricity to them
// directly
ElectricityNetwork electricityNetwork = targetConductor.getNetwork();
if (electricityNetwork != null)
{
@ -217,7 +197,9 @@ public class ElectricityManager
double transferAmps = Math.max(0, Math.min(leftOverAmps, Math.min(amps / allElectricUnitsInLine.size(), ElectricInfo.getAmps(this.getActualWattRequest(receiver), receiver.getVoltage()))));
leftOverAmps -= transferAmps;
//Calculate electricity loss
// Calculate
// electricity
// loss
double distance = Vector3.distance(Vector3.get(sender), Vector3.get((TileEntity) receiver));
double ampsReceived = transferAmps - (transferAmps * transferAmps * targetConductor.getResistance() * distance) / voltage;
double voltsReceived = voltage - (transferAmps * targetConductor.getResistance() * distance);
@ -229,11 +211,18 @@ public class ElectricityManager
}
}
}
else
{
FMLLog.severe("Conductor not registered to a network!");
}
}
}
/**
* Gets the actual watt request of an electric receiver accounting all current electricity packets qued up for it.
* Gets the actual watt request of an electric
* receiver accounting all current electricity
* packets qued up for it.
*
* @return - The amount of watts requested.
*/
public double getActualWattRequest(IElectricityReceiver receiver)
@ -265,17 +254,19 @@ public class ElectricityManager
}
/**
* Checks if the current connection line needs electricity
* @return - The amount of joules this connection line needs
* Checks if the current connection line needs
* electricity
*
* @return - The amount of joules this
* connection line needs
*/
public double getElectricityRequired(int ID)
public double getElectricityRequired(ElectricityNetwork network)
{
ElectricityNetwork connection = this.getConnectionByID(ID);
double need = 0;
if (connection != null)
if (network != null)
{
for (IConductor conductor : connection.conductors)
for (IConductor conductor : network.conductors)
{
for (byte i = 0; i < conductor.getConnectedBlocks().length; i++)
{
@ -300,14 +291,13 @@ public class ElectricityManager
return need;
}
public double getActualElectricityRequired(int ID)
public double getActualElectricityRequired(ElectricityNetwork network)
{
ElectricityNetwork connection = this.getConnectionByID(ID);
double need = 0;
if (connection != null)
if (network != null)
{
for (IConductor conductor : connection.conductors)
for (IConductor conductor : network.conductors)
{
for (byte i = 0; i < conductor.getConnectedBlocks().length; i++)
{
@ -333,50 +323,35 @@ public class ElectricityManager
}
/**
* This function is called to refresh all conductors in UE
* This function is called to refresh all
* conductors in the world.
*/
public void refreshConductors()
{
for(int j = 0; j < this.electricConductors.size(); j ++)
{
IConductor conductor = this.electricConductors.get(j);
conductor.refreshConnectedBlocks();
}
}
/**
* Clean up and remove useless connections
*/
public void cleanUpElectricityReceivers()
{
try
{
for (int i = 0; i < this.electricityReceivers.size(); i++)
{
IElectricityReceiver electricUnit = electricityReceivers.get(i);
Iterator it = electricityNetworks.iterator();
//Cleanup useless units
if (electricUnit == null)
while (it.hasNext())
{
electricityReceivers.remove(electricUnit);
}
else if (((TileEntity)electricUnit).isInvalid())
{
electricityReceivers.remove(electricUnit);
}
((ElectricityNetwork) it.next()).refreshConductors();
}
}
catch (Exception e)
{
System.err.println("Failed to clean up electricity receivers.");
e.printStackTrace();
FMLLog.fine("Failed to refresh conductors.");
}
}
public void onTick(EnumSet<TickType> type, Object... tickData)
{
if((type.contains(TickType.CLIENT) || type.contains(TickType.WORLD)) && !type.contains(TickType.WORLDLOAD))
if (type.contains(TickType.WORLD) && !type.contains(TickType.WORLDLOAD))
{
if (ElectricityManagerTicker.inGameTicks % 40 == 0)
{
this.refreshConductors();
}
try
{
HashMap conductorAmpData = new HashMap<ElectricityNetwork, Double>();
@ -414,7 +389,7 @@ public class ElectricityManager
{
if (((Double) pairs.getValue()) > ((ElectricityNetwork) pairs.getKey()).getLowestAmpConductor())
{
((ElectricityNetwork)pairs.getKey()).meltDown();
((ElectricityNetwork) pairs.getKey()).onOverCharge();
}
}
}
@ -429,7 +404,7 @@ public class ElectricityManager
}
}
if(Ticker.inGameTicks == 0)
if (ElectricityManagerTicker.inGameTicks == 0)
{
this.refreshConductors();
}

View file

@ -1,23 +1,16 @@
package universalelectricity;
package universalelectricity.electricity;
import java.util.EnumSet;
import universalelectricity.electricity.ElectricityManager;
import cpw.mods.fml.common.ITickHandler;
import cpw.mods.fml.common.TickType;
public class Ticker implements ITickHandler
public class ElectricityManagerTicker implements ITickHandler
{
public static long inGameTicks = 0;
@Override
public void tickStart(EnumSet<TickType> type, Object... tickData)
{
}
@Override
public void tickEnd(EnumSet<TickType> type, Object... tickData)
{
if (ElectricityManager.instance != null)
{
@ -32,10 +25,16 @@ public class Ticker implements ITickHandler
}
}
@Override
public void tickEnd(EnumSet<TickType> type, Object... tickData)
{
}
@Override
public EnumSet<TickType> ticks()
{
return EnumSet.of(TickType.WORLD, TickType.WORLDLOAD, TickType.CLIENT, TickType.SERVER);
return EnumSet.of(TickType.WORLD, TickType.WORLDLOAD, TickType.SERVER);
}
@Override

View file

@ -10,12 +10,10 @@ import universalelectricity.implement.IElectricityReceiver;
public class ElectricityNetwork
{
private int ID;
public List<IConductor> conductors = new ArrayList<IConductor>();
public ElectricityNetwork(int ID, IConductor conductor)
public ElectricityNetwork(IConductor conductor)
{
this.ID = ID;
this.addConductor(conductor);
}
@ -26,12 +24,13 @@ public class ElectricityNetwork
if (!conductors.contains(newConductor))
{
conductors.add(newConductor);
newConductor.setConnectionID(this.ID);
newConductor.setNetwork(this);
}
}
/**
* Get only the electric units that can receive electricity from the given side.
* Get only the electric units that can receive electricity from the given
* side.
*/
public List<IElectricityReceiver> getConnectedReceivers()
{
@ -75,29 +74,23 @@ public class ElectricityNetwork
}
}
public void setID(int ID)
public void setNetwork()
{
this.ID = ID;
this.cleanUpArray();
for (IConductor conductor : this.conductors)
{
conductor.setConnectionID(this.ID);
conductor.setNetwork(this);
}
}
public int getID()
{
return this.ID;
}
public void meltDown()
public void onOverCharge()
{
this.cleanUpArray();
for (int i = 0; i < conductors.size(); i++)
{
conductors.get(i).onConductorMelt();
conductors.get(i).onOverCharge();
}
}
@ -115,4 +108,16 @@ public class ElectricityNetwork
return lowestAmp;
}
/**
* This function is called to refresh all conductors in this network
*/
public void refreshConductors()
{
for (int j = 0; j < this.conductors.size(); j++)
{
IConductor conductor = this.conductors.get(j);
conductor.refreshConnectedBlocks();
}
}
}

View file

@ -14,10 +14,14 @@ public class ElectricityTransferData
public ForgeDirection side;
/**
* @param sender - Tile that's sending electricity.
* @param receiver - Receiver that's receiving electricity
* @param conductor - Conductor that is conducting the electricity
* @param side -
* @param sender
* - Tile that's sending electricity.
* @param receiver
* - Receiver that's receiving electricity
* @param conductor
* - Conductor that is conducting the electricity
* @param side
* -
* @param amps
* @param voltage
*/
@ -33,10 +37,6 @@ public class ElectricityTransferData
public boolean isValid()
{
return this.sender != null &&
this.receiver != null &&
this.network != null &&
this.amps > 0 &&
this.voltage > 0;
return this.sender != null && this.receiver != null && this.network != null && this.amps > 0 && this.voltage > 0;
}
}

View file

@ -3,37 +3,42 @@ package universalelectricity.implement;
import net.minecraft.src.TileEntity;
import net.minecraft.src.World;
import net.minecraftforge.common.ForgeDirection;
import universalelectricity.electricity.ElectricityNetwork;
/**
* Must be applied to all tile entities that are conductors.
*
* @author Calclavia
*
*/
public interface IConductor extends IConnector
{
/**
* The ID of the connection this conductor is in.
* The electrical network this conductor is on.
*/
public int getConnectionID();
public ElectricityNetwork getNetwork();
public void setConnectionID(int ID);
public void setNetwork(ElectricityNetwork network);
/**
* The UE tile entities that this conductor is connected to.
*
* @return
*/
public TileEntity[] getConnectedBlocks();
/**
* Gets the resistance of the conductor. Used to calculate energy loss.
* A higher resistance means a higher energy loss.
* Gets the resistance of the conductor. Used to calculate energy loss. A
* higher resistance means a higher energy loss.
*
* @return The amount of Ohm's of resistance.
*/
public double getResistance();
/**
* The maximum amount of amps this conductor can handle before melting down. This is calculating
* PER TICK!
* The maximum amount of amps this conductor can handle before melting down.
* This is calculating PER TICK!
*
* @return The amount of amps in volts
*/
public double getMaxAmps();
@ -41,7 +46,7 @@ public interface IConductor extends IConnector
/**
* Called when the electricity passing through exceeds the maximum voltage.
*/
public void onConductorMelt();
public void onOverCharge();
/**
* Resets the conductor and recalculate connection IDs again
@ -50,6 +55,14 @@ public interface IConductor extends IConnector
public World getWorld();
/**
* Adds a connection between this conductor and a UE unit
*
* @param tileEntity
* - Must be either a producer, consumer or a conductor
* @param side
* - side in which the connection is coming from
*/
public void updateConnection(TileEntity tileEntity, ForgeDirection side);
public void updateConnectionWithoutSplit(TileEntity connectorFromSide, ForgeDirection orientation);

View file

@ -3,7 +3,8 @@ package universalelectricity.implement;
import net.minecraftforge.common.ForgeDirection;
/**
* Applied to tile entities that can connect to UE wires.
* Applied to TileEntities that can connect to UE wires.
*
* @author Calclavia
*
*/
@ -11,7 +12,9 @@ public interface IConnector
{
/**
* Can this tile entity visually connect to a wire on this specific side?
* @param side. 0-5 byte
*
* @param side
* - The side in which the connection is coming from.
* @return - True if so.
*/
public boolean canConnect(ForgeDirection side);

View file

@ -1,7 +1,9 @@
package universalelectricity.implement;
/**
* This class should be applied to all tile entities (mainly machines) that can be disabled (by things like EMP, short circuit etc.).
* This class should be applied to all tile entities (mainly machines) that can
* be disabled (by things like EMP, short circuit etc.).
*
* @author Calclavia
*
*/
@ -9,12 +11,15 @@ public interface IDisableable
{
/**
* This is called when the tile entity is to be disabled.
* @param duration - The duration of the disable in ticks.
*
* @param duration
* - The duration of the disable in ticks.
*/
public void onDisable(int duration);
/**
* Called to see if this tile entity is disabled.
*
* @return True if the tile entity is disabled.
*/
public boolean isDisabled();

View file

@ -4,13 +4,16 @@ import net.minecraftforge.common.ForgeDirection;
/**
* Applied to tile entities that can produce electricity
*
* @author Calclavia
*/
public interface IElectricityProducer extends IConnector, IDisableable, IVoltage
{
/**
* Can this machine visually connect to a wire on this specific side?
* @param side. 0-5 byte
*
* @param side
* . 0-5 byte
* @return - True if so.
*/
public boolean canConnect(ForgeDirection side);

View file

@ -3,9 +3,10 @@ package universalelectricity.implement;
import net.minecraft.src.TileEntity;
import net.minecraftforge.common.ForgeDirection;
/**
* The IElectricityReceiver interface is an interface that must be applied to all tile entities that can input or output electricity.
* The IElectricityReceiver interface is an interface that must be applied to
* all tile entities that can input or output electricity.
*
* @author Calclavia
*
*/
@ -14,17 +15,22 @@ public interface IElectricityReceiver extends IDisableable, IConnector, IVoltage
/**
* Called every tick on this machine.
*
* @param amps - Amount of amps this electric unit is receiving.
* @param voltage - The voltage of the electricity sent. If more than one
* packet is being sent to you in this update, the highest voltage will
* @param amps
* - Amount of amps this electric unit is receiving.
* @param voltage
* - The voltage of the electricity sent. If more than one packet
* is being sent to you in this update, the highest voltage will
* override.
* @param side - The side of the block in which the electricity is coming from.
* @param side
* - The side of the block in which the electricity is coming
* from.
*/
public void onReceive(TileEntity sender, double amps, double voltage, ForgeDirection side);
/**
* How many watts does this electrical unit need this tick?
* Recommended for you to return the max electricity storage of this machine (if there is one).
* How many watts does this electrical unit need this tick? Recommended for
* you to return the max electricity storage of this machine (if there is
* one).
*/
public double wattRequest();

View file

@ -11,18 +11,22 @@ public interface IItemElectric extends IJouleStorage, IVoltage
/**
* Called when something requests electricity from this item.
*
* @return - The amount of given joules
*/
public double onUse(double joulesNeeded, ItemStack itemStack);
/**
* @return Returns true or false if this consumer can receive electricity at this given tick or moment.
* @return Returns true or false if this consumer can receive electricity at
* this given tick or moment.
*/
public boolean canReceiveElectricity();
/**
* Can this item give out electricity when placed in an tile entity? Electric items like batteries
* should be able to produce electricity (if they are rechargeable).
* Can this item give out electricity when placed in an tile entity?
* Electric items like batteries should be able to produce electricity (if
* they are rechargeable).
*
* @return - True or False.
*/
public boolean canProduceElectricity();

View file

@ -1,7 +1,9 @@
package universalelectricity.implement;
/**
* This interface is to be applied to all tile entities which stores energy within them.
* This interface is to be applied to all tile entities which stores energy
* within them.
*
* @author Calclavia
*/
public interface IJouleStorage

View file

@ -2,6 +2,7 @@ package universalelectricity.implement;
/**
* This should be applied on tile entities that can provide redstone power
*
* @author Henry
*
*/

View file

@ -1,9 +1,9 @@
package universalelectricity.implement;
/**
* OPTIONAL
* This interface should be applied onto all tile entities that needs to receive redstone power.
* Look at TileEntityBatteryBox for reference.
* OPTIONAL This interface should be applied onto all tile entities that needs
* to receive redstone power. Look at TileEntityBatteryBox for reference.
*
* @author Calclavia
*
*/

View file

@ -3,9 +3,10 @@ package universalelectricity.implement;
import net.minecraftforge.common.ForgeDirection;
/**
* OPTIONAL
* This interface should be applied onto all tile entities that are rotatable. This interface however is optional
* and you do not need it for your add-on to function. It just makes things easier for you to code.
* This interface should be applied onto all tile entities that are
* rotatable. This interface however is optional and you do not need it for your
* add-on to function. It just makes things easier for you to code.
*
* @author Calclavia
*
*/
@ -13,16 +14,20 @@ import net.minecraftforge.common.ForgeDirection;
public interface IRotatable
{
/**
* Gets the facing direction of the tile entity. Always returns the front side of the tile entity.
* @return The facing side from 0-5 The full list of which side the number represents
* is in the UniversalElectricity class.
* Gets the facing direction of the tile entity. Always returns the front
* side of the tile entity.
*
* @return The facing side from 0-5 The full list of which side the number
* represents is in the UniversalElectricity class.
*/
public ForgeDirection getDirection();
/**
* Sets the facing direction of the tile entity.
* @param facingDirection - A direction from 0-5. The full list of which side the number represents
* is in the UniversalElectricity class.
*
* @param facingDirection
* - A direction from 0-5. The full list of which side the number
* represents is in the UniversalElectricity class.
*/
public void setDirection(ForgeDirection facingDirection);
}

8
src/common/universalelectricity/implement/ITier.java Normal file → Executable file
View file

@ -1,7 +1,8 @@
package universalelectricity.implement;
/**
* This interface should be applied to all things that has a tier/level
* This interface should be applied to all things that has a tier/level.
*
* @author Calclavia
*
*/
@ -9,13 +10,16 @@ public interface ITier
{
/**
* Gets the tier of this object
*
* @return - The tier
*/
public int getTier();
/**
* Sets the tier of the object
* @param tier - The tier to be set
*
* @param tier
* - The tier to be set
*/
public void setTier(int tier);
}

View file

@ -1,5 +1,10 @@
package universalelectricity.implement;
/**
* Applies to all objects that has a voltage.
* @author Calclavia
*
*/
public interface IVoltage
{
/**

View file

@ -35,14 +35,6 @@ public class UEDamageSource extends DamageSource
return this;
}
public static void registerDeathMesages()
{
for(UEDamageSource damageSource : damageSources)
{
damageSource.registerDeathMessage();
}
}
public DamageSource setDamageBypassesArmor()
{
return super.setDamageBypassesArmor();

View file

@ -1,15 +0,0 @@
package universalelectricity.network;
import net.minecraft.src.EntityPlayer;
import net.minecraft.src.NetworkManager;
import net.minecraft.src.Packet250CustomPayload;
import com.google.common.io.ByteArrayDataInput;
public interface IPacketReceiver
{
/**
* Sends some data to the tile entity.
*/
public void handlePacketData(NetworkManager network, int packetType, Packet250CustomPayload packet, EntityPlayer player, ByteArrayDataInput dataStream);
}

View file

@ -1,12 +0,0 @@
package universalelectricity.network;
import universalelectricity.network.ConnectionHandler.ConnectionType;
public interface ISimpleConnectionHandler
{
/**
* Called when a player logs in. Use this to reset some tile entities variables if you need to.
* @param player
*/
public void handelConnection(ConnectionType type, Object... data);
}

View file

@ -1,264 +0,0 @@
package universalelectricity.network;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import net.minecraft.src.EntityPlayer;
import net.minecraft.src.NetworkManager;
import net.minecraft.src.Packet;
import net.minecraft.src.Packet250CustomPayload;
import net.minecraft.src.TileEntity;
import net.minecraft.src.World;
import universalelectricity.prefab.Vector3;
import com.google.common.io.ByteArrayDataInput;
import com.google.common.io.ByteStreams;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.network.IPacketHandler;
import cpw.mods.fml.common.network.PacketDispatcher;
import cpw.mods.fml.common.network.Player;
/**
* This class is used for sending and receiving packets between the server
* and the client. You can directly use this by registering this packet manager
* with NetworkMod. Example:
* @NetworkMod(channels = { "BasicComponents" }, clientSideRequired = true, serverSideRequired = false, packetHandler = PacketManager.class)
*
* Check out {@link #BasicComponents} for better reference.
*
* @author Calclavia
*/
public class PacketManager implements IPacketHandler, IPacketReceiver
{
public enum PacketType
{
UNSPECIFIED, TILEENTITY;
public static PacketType get(int id)
{
if (id >= 0 && id < PacketType.values().length)
{
return PacketType.values()[id];
}
return UNSPECIFIED;
}
}
public static Packet getPacketWithID(String channelName, int id, Object... sendData)
{
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
DataOutputStream data = new DataOutputStream(bytes);
try
{
data.writeInt(id);
data = encodeDataStream(data, sendData);
Packet250CustomPayload packet = new Packet250CustomPayload();
packet.channel = channelName;
packet.data = bytes.toByteArray();
packet.length = packet.data.length;
return packet;
}
catch (IOException e)
{
System.out.println("Failed to create packet.");
e.printStackTrace();
}
return null;
}
public static Packet getPacket(String channelName, Object... sendData)
{
return getPacketWithID(channelName, PacketType.UNSPECIFIED.ordinal(), sendData);
}
/**
* Gets a packet for the tile entity.
* @return
*/
public static Packet getPacket(String channelName, TileEntity sender, Object... sendData)
{
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
DataOutputStream data = new DataOutputStream(bytes);
try
{
data.writeInt(PacketType.TILEENTITY.ordinal());
data.writeInt(sender.xCoord);
data.writeInt(sender.yCoord);
data.writeInt(sender.zCoord);
data = encodeDataStream(data, sendData);
Packet250CustomPayload packet = new Packet250CustomPayload();
packet.channel = channelName;
packet.data = bytes.toByteArray();
packet.length = packet.data.length;
return packet;
}
catch (IOException e)
{
System.out.println("Failed to create packet.");
e.printStackTrace();
}
return null;
}
/**
* Sends packets to clients around a specific coordinate. A wrapper using Vector3.
* See {@PacketDispatcher} for detailed information.
*/
public static void sendPacketToClients(Packet packet, World worldObj, Vector3 position, double range)
{
try
{
PacketDispatcher.sendPacketToAllAround(position.x, position.y, position.z, range, worldObj.provider.dimensionId, packet);
}
catch (Exception e)
{
System.out.println("Sending packet to client failed.");
e.printStackTrace();
}
}
/**
* Sends a packet to all the clients on this server.
*/
public static void sendPacketToClients(Packet packet, World worldObj)
{
try
{
PacketDispatcher.sendPacketToAllInDimension(packet, worldObj.provider.dimensionId);
}
catch (Exception e)
{
System.out.println("Sending packet to client failed.");
e.printStackTrace();
}
}
public static void sendPacketToClients(Packet packet)
{
try
{
if(FMLCommonHandler.instance().getMinecraftServerInstance() != null)
{
FMLCommonHandler.instance().getMinecraftServerInstance().getConfigurationManager().sendPacketToAllPlayers(packet);
}
}
catch (Exception e)
{
System.out.println("Sending packet to client failed.");
e.printStackTrace();
}
}
public static DataOutputStream encodeDataStream(DataOutputStream data, Object... sendData)
{
try
{
for(Object dataValue : sendData)
{
if(dataValue instanceof Integer)
{
data.writeInt((Integer)dataValue);
}
else if(dataValue instanceof Float)
{
data.writeFloat((Float)dataValue);
}
else if(dataValue instanceof Double)
{
data.writeDouble((Double)dataValue);
}
else if(dataValue instanceof Byte)
{
data.writeByte((Byte)dataValue);
}
else if(dataValue instanceof Boolean)
{
data.writeBoolean((Boolean)dataValue);
}
else if(dataValue instanceof String)
{
data.writeUTF((String)dataValue);
}
else if(dataValue instanceof Short)
{
data.writeShort((Short)dataValue);
}
else if(dataValue instanceof Long)
{
data.writeLong((Long)dataValue);
}
}
return data;
}
catch (IOException e)
{
System.out.println("Packet data encoding failed.");
e.printStackTrace();
}
return data;
}
@Override
public void onPacketData(NetworkManager network, Packet250CustomPayload packet, Player player)
{
try
{
ByteArrayDataInput data = ByteStreams.newDataInput(packet.data);
int packetTypeID = data.readInt();
PacketType packetType = PacketType.get(packetTypeID);
if(packetType == PacketType.TILEENTITY)
{
int x = data.readInt();
int y = data.readInt();
int z = data.readInt();
World world = ((EntityPlayer)player).worldObj;
if(world != null)
{
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
if(tileEntity != null)
{
if(tileEntity instanceof IPacketReceiver)
{
((IPacketReceiver)tileEntity).handlePacketData(network, packetTypeID, packet, ((EntityPlayer)player), data);
}
}
}
}
else
{
this.handlePacketData(network, packetTypeID, packet, ((EntityPlayer)player), data);
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
@Override
public void handlePacketData(NetworkManager network, int packetType, Packet250CustomPayload packet, EntityPlayer player, ByteArrayDataInput dataStream)
{
}
}

View file

@ -1,49 +0,0 @@
package universalelectricity.network;
import java.util.Arrays;
import java.util.List;
import net.minecraft.src.CommandBase;
import net.minecraft.src.ICommand;
import net.minecraft.src.ICommandSender;
import net.minecraft.src.WrongUsageException;
import universalelectricity.UniversalElectricity;
public class UECommand extends CommandBase
{
@Override
public int compareTo(Object arg0)
{
return this.getCommandName().compareTo(((ICommand)arg0).getCommandName());
}
@Override
public String getCommandName()
{
return "universalelectricity";
}
@Override
public String getCommandUsage(ICommandSender sender)
{
return "/" + this.getCommandName();
}
@Override
public List getCommandAliases()
{
return Arrays.asList(new String[]{"ue"});
}
@Override
public void processCommand(ICommandSender sender, String[] arguments)
{
if(arguments.length <= 0)
{
sender.sendChatToPlayer(String.format("You are using Universal Electricity v" + UniversalElectricity.VERSION));
return;
}
throw new WrongUsageException(this.getCommandUsage(sender));
}
}

View file

@ -1,91 +0,0 @@
package universalelectricity.ore;
import java.util.Random;
import net.minecraft.src.Block;
import net.minecraft.src.IChunkProvider;
import net.minecraft.src.ItemStack;
import net.minecraft.src.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.oredict.OreDictionary;
import universalelectricity.UEConfig;
import universalelectricity.UniversalElectricity;
/**
* This class is used for storing ore generation data. If you are too
* lazy to generate your own ores, you can do {@link #OreGenerator.ORES_TO_GENERATE.add()}
* to add your ore to the list of ores to generate.
* @author Calclavia
*
*/
public abstract class OreGenBase
{
public String name;
public String oreDictionaryName;
public boolean shouldGenerate;
public int blockIndexTexture;
public ItemStack oreStack;
public int oreID;
public int oreMeta;
/**
* What harvest level does this machine need to be acquired?
*/
public int harvestLevel;
/**
* The predefined tool classes are "pickaxe", "shovel", "axe". You can add others for custom tools.
*/
public String harvestTool;
/**
* @param name - The name of the ore for display
* @param textureFile - The 16x16 png texture of your ore to override
* @param minGenerateLevel - The highest generation level of your ore
* @param maxGenerateLevel - The lowest generation level of your ore
* @param amountPerChunk - The amount of ores to generate per chunk
* @param amountPerBranch - The amount of ores to generate in a clutter. E.g coal generates with a lot of other coal next to it. How much do you want?
*/
public OreGenBase(String name, String oreDiectionaryName, ItemStack stack, String harvestTool, int harvestLevel)
{
this.name = name;
this.shouldGenerate = false;
this.harvestTool = harvestTool;
this.harvestLevel = harvestLevel;
this.oreDictionaryName = oreDiectionaryName;
this.oreStack = stack;
this.oreID = stack.itemID;
this.oreMeta = stack.getItemDamage();
OreDictionary.registerOre(oreDictionaryName, stack);
MinecraftForge.setBlockHarvestLevel(Block.blocksList[stack.itemID], stack.getItemDamage(), harvestTool, harvestLevel);
}
public OreGenBase enable()
{
this.shouldGenerate = shouldGenerateOre(name);
return this;
}
//You may inherit from this class and change this function if you want a custom texture render for your ore.
public int getBlockTextureFromSide(int side)
{
return this.blockIndexTexture;
}
//Checks the config file and see if Universal Electricity should generate this ore
private static boolean shouldGenerateOre(String oreName)
{
return UEConfig.getConfigData(UniversalElectricity.CONFIGURATION, "Generate " + oreName, true);
}
public abstract void generate(World world, Random random, int varX, int varZ);
public abstract boolean isOreGeneratedInWorld(World world, IChunkProvider chunkGenerator);
}

View file

@ -1,128 +0,0 @@
package universalelectricity.ore;
import java.util.Random;
import net.minecraft.src.ChunkProviderEnd;
import net.minecraft.src.ChunkProviderGenerate;
import net.minecraft.src.ChunkProviderHell;
import net.minecraft.src.IChunkProvider;
import net.minecraft.src.ItemStack;
import net.minecraft.src.MathHelper;
import net.minecraft.src.World;
/**
* This class is used for storing ore generation data. If you are too
* lazy to generate your own ores, you can do {@link #OreGenerator.ORES_TO_GENERATE.add()}
* to add your ore to the list of ores to generate.
* @author Calclavia
*
*/
public class OreGenReplace extends OreGenBase
{
public int minGenerateLevel;
public int maxGenerateLevel;
public int amountPerChunk;
public int amountPerBranch;
public int replaceID;
public boolean generateSurface;
public boolean generateNether;
public boolean generateEnd;
/**
* @param name - The name of the ore for display
* @param textureFile - The 16x16 png texture of your ore to override
* @param minGenerateLevel - The highest generation level of your ore
* @param maxGenerateLevel - The lowest generation level of your ore
* @param amountPerChunk - The amount of ores to generate per chunk
* @param amountPerBranch - The amount of ores to generate in a clutter. E.g coal generates with a lot of other coal next to it. How much do you want?
*/
public OreGenReplace(String name, String oreDiectionaryName, ItemStack stack, int replaceID, int minGenerateLevel, int maxGenerateLevel, int amountPerChunk, int amountPerBranch, String harvestTool, int harvestLevel)
{
super(name, oreDiectionaryName, stack, harvestTool, harvestLevel);
this.minGenerateLevel = minGenerateLevel;
this.maxGenerateLevel = maxGenerateLevel;
this.amountPerChunk = amountPerChunk;
this.amountPerBranch = amountPerBranch;
this.replaceID = replaceID;
}
public void generate(World world, Random random, int varX, int varZ)
{
for (int i = 0; i < this.amountPerChunk; i++)
{
int x = varX + random.nextInt(16);
int z = varZ + random.nextInt(16);
int y = random.nextInt(this.maxGenerateLevel-this.minGenerateLevel) + this.minGenerateLevel;
generateReplace(world, random, x, y, z);
}
}
public boolean generateReplace(World par1World, Random par2Random, int par3, int par4, int par5)
{
float var6 = par2Random.nextFloat() * (float)Math.PI;
double var7 = (double)((float)(par3 + 8) + MathHelper.sin(var6) * (float)this.amountPerBranch / 8.0F);
double var9 = (double)((float)(par3 + 8) - MathHelper.sin(var6) * (float)this.amountPerBranch / 8.0F);
double var11 = (double)((float)(par5 + 8) + MathHelper.cos(var6) * (float)this.amountPerBranch / 8.0F);
double var13 = (double)((float)(par5 + 8) - MathHelper.cos(var6) * (float)this.amountPerBranch / 8.0F);
double var15 = (double)(par4 + par2Random.nextInt(3) - 2);
double var17 = (double)(par4 + par2Random.nextInt(3) - 2);
for (int var19 = 0; var19 <= this.amountPerBranch; ++var19)
{
double var20 = var7 + (var9 - var7) * (double)var19 / (double)this.amountPerBranch;
double var22 = var15 + (var17 - var15) * (double)var19 / (double)this.amountPerBranch;
double var24 = var11 + (var13 - var11) * (double)var19 / (double)this.amountPerBranch;
double var26 = par2Random.nextDouble() * (double)this.amountPerBranch / 16.0D;
double var28 = (double)(MathHelper.sin((float)var19 * (float)Math.PI / (float)this.amountPerBranch) + 1.0F) * var26 + 1.0D;
double var30 = (double)(MathHelper.sin((float)var19 * (float)Math.PI / (float)this.amountPerBranch) + 1.0F) * var26 + 1.0D;
int var32 = MathHelper.floor_double(var20 - var28 / 2.0D);
int var33 = MathHelper.floor_double(var22 - var30 / 2.0D);
int var34 = MathHelper.floor_double(var24 - var28 / 2.0D);
int var35 = MathHelper.floor_double(var20 + var28 / 2.0D);
int var36 = MathHelper.floor_double(var22 + var30 / 2.0D);
int var37 = MathHelper.floor_double(var24 + var28 / 2.0D);
for (int var38 = var32; var38 <= var35; ++var38)
{
double var39 = ((double)var38 + 0.5D - var20) / (var28 / 2.0D);
if (var39 * var39 < 1.0D)
{
for (int var41 = var33; var41 <= var36; ++var41)
{
double var42 = ((double)var41 + 0.5D - var22) / (var30 / 2.0D);
if (var39 * var39 + var42 * var42 < 1.0D)
{
for (int var44 = var34; var44 <= var37; ++var44)
{
double var45 = ((double)var44 + 0.5D - var24) / (var28 / 2.0D);
int block = par1World.getBlockId(var38, var41, var44);
if (var39 * var39 + var42 * var42 + var45 * var45 < 1.0D && (this.replaceID == 0 || block==this.replaceID))
{
par1World.setBlockAndMetadata(var38, var41, var44, this.oreID, this.oreMeta);
}
}
}
}
}
}
}
return true;
}
@Override
public boolean isOreGeneratedInWorld(World world, IChunkProvider chunkGenerator)
{
return ((this.generateSurface && chunkGenerator instanceof ChunkProviderGenerate) ||
(this.generateNether && chunkGenerator instanceof ChunkProviderHell) ||
(this.generateEnd && chunkGenerator instanceof ChunkProviderEnd)
);
}
}

Some files were not shown because too many files have changed in this diff Show more