MekanismInduction module - done!

Still need to configure the build
This commit is contained in:
Aidan C. Brady 2013-11-16 10:21:37 -05:00
parent 3d4625ddb9
commit 53323279c7
166 changed files with 15794 additions and 369 deletions

View file

@ -0,0 +1,44 @@
package calclavia.lib;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.util.ResourceLocation;
public class Calclavia
{
public static final String NAME = "Calclavia";
public static final String DOMAIN = "calclavia";
public static final String TEXTURE_NAME_PREFIX = DOMAIN + ":";
public static final String RESOURCE_DIRECTORY = "/assets/calclavia/";
public static final String TEXTURE_DIRECTORY = "textures/";
public static final String GUI_DIRECTORY = TEXTURE_DIRECTORY + "gui/";
public static final ResourceLocation GUI_EMPTY_FILE = new ResourceLocation(DOMAIN, GUI_DIRECTORY + "gui_empty.png");
public static final ResourceLocation GUI_COMPONENTS = new ResourceLocation(DOMAIN, GUI_DIRECTORY + "gui_components.png");
public static final ResourceLocation GUI_BASE = new ResourceLocation(DOMAIN, GUI_DIRECTORY + "gui_base.png");
public static List<String> splitStringPerWord(String string, int wordsPerLine)
{
String[] words = string.split(" ");
List<String> lines = new ArrayList<String>();
for (int lineCount = 0; lineCount < Math.ceil((float) words.length / (float) wordsPerLine); lineCount++)
{
String stringInLine = "";
for (int i = lineCount * wordsPerLine; i < Math.min(wordsPerLine + lineCount * wordsPerLine, words.length); i++)
{
stringInLine += words[i] + " ";
}
lines.add(stringInLine.trim());
}
return lines;
}
}

View file

@ -0,0 +1,35 @@
package calclavia.lib;
import net.minecraft.potion.Potion;
public abstract class CustomPotion extends Potion
{
/**
* Creates a new type of potion
*
* @param id - The ID of this potion. Make it greater than 20.
* @param isBadEffect - Is this potion a good potion or a bad one?
* @param color - The color of this potion.
* @param name - The name of this potion.
*/
public CustomPotion(int id, boolean isBadEffect, int color, String name)
{
super(id, isBadEffect, color);
this.setPotionName("potion." + name);
Potion.potionTypes[this.getId()] = this;
}
@Override
public Potion setIconIndex(int par1, int par2)
{
super.setIconIndex(par1, par2);
return this;
}
@Override
protected Potion setEffectiveness(double par1)
{
super.setEffectiveness(par1);
return this;
}
}

View file

@ -0,0 +1,10 @@
package calclavia.lib;
import java.util.HashSet;
import net.minecraft.entity.player.EntityPlayer;
public interface IPlayerUsing
{
public HashSet<EntityPlayer> getPlayersUsing();
}

View file

@ -0,0 +1,112 @@
package calclavia.lib;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.server.MinecraftServer;
import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.FMLLog;
public class NBTFileLoader
{
/**
* Saves NBT data in the world folder.
*
* @return True on success.
*/
public static boolean saveData(File saveDirectory, String filename, NBTTagCompound data)
{
try
{
File tempFile = new File(saveDirectory, filename + "_tmp.dat");
File file = new File(saveDirectory, filename + ".dat");
CompressedStreamTools.writeCompressed(data, new FileOutputStream(tempFile));
if (file.exists())
{
file.delete();
}
tempFile.renameTo(file);
FMLLog.fine("Saved " + filename + " NBT data file successfully.");
return true;
}
catch (Exception e)
{
System.out.println("Failed to save " + filename + ".dat!");
e.printStackTrace();
return false;
}
}
public static boolean saveData(String filename, NBTTagCompound data)
{
return saveData(getSaveDirectory(MinecraftServer.getServer().getFolderName()), filename, data);
}
/**
* Reads NBT data from the world folder.
*
* @return The NBT data
*/
public static NBTTagCompound loadData(File saveDirectory, String filename)
{
try
{
File file = new File(saveDirectory, filename + ".dat");
if (file.exists())
{
FMLLog.fine("Loaded " + filename + " data.");
return CompressedStreamTools.readCompressed(new FileInputStream(file));
}
else
{
FMLLog.fine("Created new " + filename + " data.");
return new NBTTagCompound();
}
}
catch (Exception e)
{
System.out.println("Failed to load " + filename + ".dat!");
e.printStackTrace();
return null;
}
}
public static NBTTagCompound loadData(String filename)
{
return loadData(getSaveDirectory(MinecraftServer.getServer().getFolderName()), filename);
}
public static File getSaveDirectory(String worldName)
{
File parent = getBaseDirectory();
if (FMLCommonHandler.instance().getSide().isClient())
{
parent = new File(getBaseDirectory(), "saves" + File.separator);
}
return new File(parent, worldName + File.separator);
}
public static File getBaseDirectory()
{
if (FMLCommonHandler.instance().getSide().isClient())
{
FMLClientHandler.instance().getClient();
return FMLClientHandler.instance().getClient().mcDataDir;
}
else
{
return new File(".");
}
}
}

View file

@ -0,0 +1,153 @@
package calclavia.lib;
import ic2.api.item.Items;
import java.util.Arrays;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
import com.google.common.collect.Lists;
import cpw.mods.fml.common.FMLLog;
/**
* Allows recipes that are compatible with UE -> IC2 -> Buildcraft.
*
* @author Calclavia
*
*/
public class UniversalRecipes
{
private static final String PREFIX = "calclavia:";
/**
* Primary Metal: Steel
*/
public static final String PRIMARY_METAL = "ingotSteel";
public static final String PRIMARY_PLATE = "plateSteel";
/**
* Secondary Metal: Bronze
*/
public static final String SECONDARY_METAL = "ingotBronze";
public static final String SECONDARY_PLATE = "plateBronze";
/**
* Circuits
*/
public static final String CIRCUIT_T1 = PREFIX + "CIRCUIT_T1";
public static final String CIRCUIT_T2 = PREFIX + "CIRCUIT_T2";
public static final String CIRCUIT_T3 = PREFIX + "CIRCUIT_T3";
/**
* Battery
*/
public static String ADVANCED_BATTERY = PREFIX + "ADVANCED_BATTERY";
public static String BATTERY = PREFIX + "BATTERY";
public static String BATTERY_BOX = PREFIX + "BATTERY_BOX";
/**
* Misc
*/
public static final String WRENCH = PREFIX + "WRENCH";
public static final String WIRE = PREFIX + "WIRE";
public static final String MOTOR = PREFIX + "MOTOR";
public static boolean isInit = false;
public static void init()
{
if (!isInit)
{
// Metals
/*
* register(PRIMARY_METAL, "ingotSteel", "ingotRefinedIron", new
* ItemStack(Item.ingotIron)); register(SECONDARY_METAL, "ingotBronze", new
* ItemStack(Item.brick));
*/
// Plates
register(PRIMARY_PLATE, "plateSteel", Items.getItem("advancedAlloy"), new ItemStack(Block.blockIron));
register(SECONDARY_PLATE, "plateBronze", Items.getItem("carbonPlate"), new ItemStack(Block.brick));
// Miscs
register(CIRCUIT_T1, "circuitBasic", Items.getItem("electronicCircuit"), new ItemStack(Block.torchRedstoneActive));
register(CIRCUIT_T2, "circuitAdvanced", Items.getItem("advancedCircuit"), new ItemStack(Item.redstoneRepeater));
register(CIRCUIT_T3, "circuitElite", Items.getItem("iridiumPlate"), new ItemStack(Item.comparator));
register(ADVANCED_BATTERY, "advancedBattery", Items.getItem("energyCrystal"), "battery", new ItemStack(Item.redstoneRepeater));
register(BATTERY, "battery", Items.getItem("reBattery"), new ItemStack(Item.redstoneRepeater));
register(BATTERY_BOX, "batteryBox", Items.getItem("batBox"), new ItemStack(Block.blockGold));
register(WRENCH, "wrench", Items.getItem("wrench"), new ItemStack(Item.axeIron));
register(WIRE, "copperWire", "copperCableBlock", new ItemStack(Item.redstone));
register(MOTOR, "motor", Items.getItem("generator"), new ItemStack(Block.pistonBase));
isInit = true;
}
}
public static void register(String name, Object... possiblities)
{
for (Object possiblity : possiblities)
{
if (possiblity instanceof ItemStack)
{
if (registerItemStacksToDictionary(name, (ItemStack) possiblity))
{
break;
}
continue;
}
else if (possiblity instanceof String)
{
if (registerItemStacksToDictionary(name, (String) possiblity))
{
break;
}
continue;
}
FMLLog.severe("Universal Recipes: Error Registering " + name);
}
}
public static boolean registerItemStacksToDictionary(String name, List<ItemStack> itemStacks)
{
boolean returnValue = false;
if (itemStacks != null)
{
if (itemStacks.size() > 0)
{
for (ItemStack stack : itemStacks.toArray(new ItemStack[0]))
{
if (stack != null)
{
OreDictionary.registerOre(name, stack);
returnValue = true;
}
}
}
}
return returnValue;
}
public static boolean registerItemStacksToDictionary(String name, ItemStack... itemStacks)
{
return registerItemStacksToDictionary(name, Arrays.asList(itemStacks));
}
public static boolean registerItemStacksToDictionary(String name, String stackName)
{
return registerItemStacksToDictionary(name, OreDictionary.getOres(stackName));
}
}

View file

@ -0,0 +1,16 @@
package calclavia.lib.base;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraftforge.common.Configuration;
public class ItemBase extends Item
{
public ItemBase(int id, String name, Configuration config, String prefix, CreativeTabs tab)
{
super(config.getItem(name, id).getInt());
this.setUnlocalizedName(prefix + name);
this.setCreativeTab(tab);
this.setTextureName(prefix + name);
}
}

View file

@ -0,0 +1,16 @@
package calclavia.lib.base;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraftforge.common.Configuration;
import universalelectricity.compatibility.ItemUniversalElectric;
public abstract class ItemElectricBase extends ItemUniversalElectric
{
public ItemElectricBase(int id, String name, Configuration config, String prefix, CreativeTabs tab)
{
super(config.getItem(name, id).getInt());
this.setUnlocalizedName(prefix + name);
this.setCreativeTab(tab);
this.setTextureName(prefix + name);
}
}

View file

@ -0,0 +1,320 @@
package calclavia.lib.flag;
import java.util.Iterator;
import java.util.List;
import net.minecraft.command.CommandBase;
import net.minecraft.command.ICommandSender;
import net.minecraft.command.WrongUsageException;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.ChatMessageComponent;
import universalelectricity.core.vector.Vector3;
/**
* Commands used for flags and regions. This can be used for protection for specific mod components
* that might be dangerous.
*
* @author Calclavia
*
*/
public class CommandFlag extends CommandBase
{
public static final String[] COMMANDS = new String[] { "list", "setregion", "removeregion", "set" };
public String commandName = "modflag";
public ModFlag modFlagData;
public CommandFlag(ModFlag modFlag)
{
this.modFlagData = modFlag;
}
public CommandFlag(ModFlag modFlag, String commandName)
{
this(modFlag);
this.commandName = commandName;
}
@Override
public String getCommandName()
{
return commandName;
}
@Override
public String getCommandUsage(ICommandSender par1ICommandSender)
{
String returnString = "";
for (String command : COMMANDS)
{
returnString = returnString + "\n/" + this.getCommandName() + " " + command;
}
return returnString;
}
@Override
public void processCommand(ICommandSender sender, String[] args)
{
if (args.length > 0)
{
EntityPlayer entityPlayer = (EntityPlayer) sender;
// The world data the player is on.
FlagWorld flagWorld = this.modFlagData.getFlagWorld(entityPlayer.worldObj);
String commandName = args[0].toLowerCase();
if (commandName.equalsIgnoreCase("list"))
{
/**
* The list command lists out all regions in this world/region.
*/
if (args.length > 1)
{
String regionName = args[1];
if (regionName.equalsIgnoreCase("all"))
{
String msg = "";
Iterator<FlagWorld> itWorlds = this.modFlagData.getFlagWorlds().iterator();
while (itWorlds.hasNext())
{
Iterator<FlagRegion> itRegion = itWorlds.next().getRegions().iterator();
while (itRegion.hasNext())
{
FlagRegion flagRegion = itRegion.next();
msg = msg + " " + flagRegion.name + " (" + flagRegion.region.min.x + "," + flagRegion.region.min.z + ")" + ",";
}
}
if (msg != "")
{
msg = "List of regions in world:\n" + msg;
}
else
{
msg = "No regions in this world.";
}
sender.sendChatToPlayer(ChatMessageComponent.createFromText(msg));
}
else if (flagWorld.getRegion(regionName) != null)
{
String msg = "";
Iterator<Flag> i = flagWorld.getRegion(regionName).getFlags().iterator();
while (i.hasNext())
{
Flag flag = i.next();
msg = msg + " " + flag.name + " => " + flag.value + ",";
}
if (msg != "")
{
msg = "List of flags in region " + regionName + ":\n" + msg;
}
else
{
msg = "No flags in this region.";
}
sender.sendChatToPlayer(ChatMessageComponent.createFromText(msg));
}
else
{
String msg = "Region does not exist, but here are existing flags in the position you are standing on:\n";
Iterator<Flag> i = flagWorld.getFlagsInPosition(new Vector3(entityPlayer)).iterator();
while (i.hasNext())
{
Flag flag = i.next();
msg = msg + " " + flag.name + "=>" + flag.value + ",";
}
sender.sendChatToPlayer(ChatMessageComponent.createFromText(msg));
}
}
else
{
String msg = "";
Iterator<FlagRegion> i = flagWorld.getRegions().iterator();
while (i.hasNext())
{
FlagRegion flagRegion = i.next();
msg = msg + " " + flagRegion.name + " (" + flagRegion.region.min.x + "," + flagRegion.region.min.z + ")" + ",";
}
if (msg != "")
{
msg = "List of regions in this dimension:\n" + msg;
}
else
{
msg = "No regions in this dimension.";
}
sender.sendChatToPlayer(ChatMessageComponent.createFromText(msg));
}
return;
}
else if (commandName.equalsIgnoreCase("setregion"))
{
if (args.length > 1)
{
String regionName = args[1];
if (regionName.equalsIgnoreCase(FlagWorld.GLOBAL_REGION))
{
if (flagWorld.addRegion(regionName, new Vector3(entityPlayer), 1))
{
sender.sendChatToPlayer(ChatMessageComponent.createFromText("Created global dimension region setting."));
return;
}
}
else if (args.length > 2)
{
int radius = 0;
try
{
radius = Integer.parseInt(args[2]);
}
catch (Exception e)
{
throw new WrongUsageException("Radius not a number!");
}
if (radius > 0)
{
FlagRegion region = flagWorld.getRegion(regionName);
if (region == null)
{
if (flagWorld.addRegion(regionName, new Vector3(entityPlayer), radius))
{
sender.sendChatToPlayer(ChatMessageComponent.createFromText("Region " + regionName + " added."));
}
}
else
{
region.edit(new Vector3(entityPlayer), radius);
sender.sendChatToPlayer(ChatMessageComponent.createFromText("Region " + regionName + " already exists. Modified region to have a radius of: " + radius));
}
}
else
{
throw new WrongUsageException("Radius has to be greater than zero!");
}
}
else
{
throw new WrongUsageException("/" + this.getCommandName() + " addregion <name> <radius>");
}
}
else
{
throw new WrongUsageException("Please specify the region name.");
}
return;
}
else if (commandName.equalsIgnoreCase("removeregion"))
{
if (args.length > 1)
{
String regionName = args[1];
if (flagWorld.removeRegion(regionName))
{
sender.sendChatToPlayer(ChatMessageComponent.createFromText("Region with name " + regionName + " is removed."));
}
else
{
throw new WrongUsageException("The specified region does not exist in this world.");
}
}
else
{
throw new WrongUsageException("Please specify the region name.");
}
return;
}
else if (commandName.equalsIgnoreCase("set"))
{
if (args.length > 2)
{
String regionName = args[1];
String flagName = args[2];
FlagRegion flagRegion = flagWorld.getRegion(regionName);
if (flagRegion != null)
{
if (FlagRegistry.flags.contains(flagName))
{
if (args.length > 3)
{
String flagValue = args[3];
flagRegion.setFlag(flagName, flagValue);
sender.sendChatToPlayer(ChatMessageComponent.createFromText("Flag '" + flagName + "' has been set to '" + flagValue + "' in " + regionName + "."));
}
else
{
flagRegion.removeFlag(flagName);
sender.sendChatToPlayer(ChatMessageComponent.createFromText("Removed flag '" + flagName + "'."));
}
}
else
{
String flags = "Flag does not exist. Existing flags:\n";
for (String registeredFlag : FlagRegistry.flags)
{
flags = flags + registeredFlag + ", ";
}
throw new WrongUsageException(flags);
}
}
else
{
throw new WrongUsageException("The specified region '" + regionName + "' does not exist.");
}
}
else
{
throw new WrongUsageException("/" + this.getCommandName() + " set <regionName> <flagName> <value>");
}
return;
}
}
throw new WrongUsageException(this.getCommandUsage(sender));
}
@Override
public int getRequiredPermissionLevel()
{
return 2;
}
@Override
public List addTabCompletionOptions(ICommandSender sender, String[] args)
{
return args.length == 1 ? getListOfStringsMatchingLastWord(args, COMMANDS) : null;
}
}

View file

@ -0,0 +1,43 @@
package calclavia.lib.flag;
import net.minecraft.nbt.NBTTagCompound;
public class Flag extends FlagBase
{
/**
* The region in which this flag has affect in.
*/
public FlagRegion flagRegion;
public String name;
public String value;
public Flag(FlagRegion flagRegion)
{
this.flagRegion = flagRegion;
}
public Flag(FlagRegion flagRegion, String name, String value)
{
this(flagRegion);
this.name = name;
this.value = value;
}
@Override
public void readFromNBT(NBTTagCompound nbt)
{
this.name = nbt.getString("name");
this.value = nbt.getString("value");
}
@Override
public void writeToNBT(NBTTagCompound nbt)
{
nbt.setString("name", this.name);
nbt.setString("value", this.value);
}
}

View file

@ -0,0 +1,26 @@
package calclavia.lib.flag;
import net.minecraft.nbt.NBTTagCompound;
public abstract class FlagBase
{
public abstract void readFromNBT(NBTTagCompound nbt);
public abstract void writeToNBT(NBTTagCompound nbt);
public NBTTagCompound getNBT()
{
NBTTagCompound nbt = new NBTTagCompound();
try
{
this.writeToNBT(nbt);
}
catch (Exception e)
{
System.out.println("Failed to read flag");
e.printStackTrace();
}
return nbt;
}
}

View file

@ -0,0 +1,184 @@
package calclavia.lib.flag;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import universalelectricity.core.vector.Vector3;
import universalelectricity.prefab.vector.Region3;
/**
* A defined region.
*
* @author Calclavia
*
*/
public class FlagRegion extends FlagBase
{
/**
* The region in which this flag has affect in.
*/
public FlagWorld flagWorld;
public String name;
public Region3 region;
private final List<Flag> flags = new ArrayList<Flag>();
public FlagRegion(FlagWorld worldFlagData)
{
this.flagWorld = worldFlagData;
}
public FlagRegion(FlagWorld flagWorld, String name, Region3 region)
{
this.flagWorld = flagWorld;
this.name = name;
this.region = region;
}
@Override
public void readFromNBT(NBTTagCompound nbt)
{
this.name = nbt.getName();
Vector3 startVector = Vector3.readFromNBT(nbt.getCompoundTag("min"));
Vector3 endVector = Vector3.readFromNBT(nbt.getCompoundTag("max"));
this.region = new Region3(startVector, endVector);
/**
* Child Data
*/
NBTTagList flagList = nbt.getTagList("flags");
for (int i = 0; i < flagList.tagCount(); i++)
{
NBTTagCompound childNode = (NBTTagCompound) flagList.tagAt(i);
try
{
Flag flag = new Flag(this);
flag.readFromNBT(childNode);
this.flags.add(flag);
}
catch (Exception e)
{
System.out.println("Mod Flag: Failed to read flag data: " + childNode.getName());
e.printStackTrace();
}
}
}
@Override
public void writeToNBT(NBTTagCompound nbt)
{
nbt.setName(this.name);
nbt.setTag("min", this.region.min.writeToNBT(new NBTTagCompound()));
nbt.setTag("max", this.region.max.writeToNBT(new NBTTagCompound()));
NBTTagList flagList = new NBTTagList();
for (Flag flag : this.getFlags())
{
try
{
flagList.appendTag(flag.getNBT());
}
catch (Exception e)
{
System.out.println("Failed to save world flag data: " + flag.name);
e.printStackTrace();
}
}
nbt.setTag("flags", flagList);
}
public boolean containsValue(String flagName, String checkValue, Vector3 position)
{
for (Flag flag : this.flags)
{
if (flag.name.equalsIgnoreCase(flagName) && flag.value.equalsIgnoreCase(checkValue))
{
return true;
}
}
return false;
}
public boolean setFlag(String flagName, String value)
{
this.removeFlag(flagName);
if (value != null && value != "")
{
if (!containsFlag(flagName))
{
return this.flags.add(new Flag(this, flagName, value));
}
}
return false;
}
public boolean containsFlag(String flagName)
{
for (Flag region : this.flags)
{
if (region.name.equalsIgnoreCase(flagName))
{
return true;
}
}
return false;
}
public boolean removeFlag(String flagName)
{
for (Flag region : this.flags)
{
if (region.name.equalsIgnoreCase(flagName))
{
this.flags.remove(region);
return true;
}
}
return false;
}
public List<Flag> getFlags()
{
Iterator<Flag> it = this.flags.iterator();
while (it.hasNext())
{
Flag flag = it.next();
if (flag == null)
{
it.remove();
continue;
}
if (flag.name == null || flag.name == "")
{
it.remove();
continue;
}
}
return this.flags;
}
public void edit(Vector3 position, int radius)
{
Vector3 minVec = new Vector3(position.intX() - radius, 0, position.intZ() - radius);
Vector3 maxVec = new Vector3(position.intX() + radius, this.flagWorld.world.getHeight(), position.intZ() + radius);
this.region = new Region3(minVec, maxVec);
}
}

View file

@ -0,0 +1,52 @@
package calclavia.lib.flag;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
/**
* All the different types of flags that can be registered.
*
* @author Calclavia
*
*/
public class FlagRegistry
{
public static final String DEFAULT_NAME = "ModFlags";
private static final HashMap<String, ModFlag> MOD_FLAGS = new HashMap<String, ModFlag>();
public static final List<String> flags = new ArrayList<String>();
public static boolean isInitiated = false;
public static void registerModFlag(String name, ModFlag flagData)
{
MOD_FLAGS.put(name, flagData);
}
public static ModFlag getModFlag(String name)
{
return MOD_FLAGS.get(name);
}
/**
* Registers a flag name, allowing it to be used and called by the player. Call this in your
* mod's init function.
*/
public static String registerFlag(String name)
{
if (!isInitiated)
{
isInitiated = true;
}
name = name.toLowerCase();
if (!flags.contains(name))
{
flags.add(name);
}
return name;
}
}

View file

@ -0,0 +1,200 @@
package calclavia.lib.flag;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import universalelectricity.core.vector.Vector3;
import universalelectricity.prefab.vector.Region3;
/**
* Data structure for world protection.
*
* @author Calclavia
*
*/
public class FlagWorld extends FlagBase
{
public static final String GLOBAL_REGION = "dimension";
public World world;
private final List<FlagRegion> regions = new ArrayList<FlagRegion>();
public FlagWorld(World world)
{
this.world = world;
}
@Override
public void readFromNBT(NBTTagCompound nbt)
{
// A list containing all flags within it for this world.
Iterator<NBTTagCompound> childCompounds = nbt.getTags().iterator();
while (childCompounds.hasNext())
{
NBTTagCompound childCompound = childCompounds.next();
try
{
FlagRegion flagRegion = new FlagRegion(this);
flagRegion.readFromNBT(childCompound);
this.regions.add(flagRegion);
}
catch (Exception e)
{
System.out.println("Mod Flag: Failed to read flag data: " + childCompound.getName());
e.printStackTrace();
}
}
}
@Override
public void writeToNBT(NBTTagCompound nbt)
{
for (FlagRegion region : this.regions)
{
try
{
NBTTagCompound flagCompound = new NBTTagCompound();
region.writeToNBT(flagCompound);
nbt.setTag(region.name, flagCompound);
}
catch (Exception e)
{
System.out.println("Failed to save world flag data: " + region.name);
e.printStackTrace();
}
}
}
/**
* Gets all the flags that have an effect in this position.
*
* @param position
* @return
*/
public List<Flag> getFlagsInPosition(Vector3 position)
{
List<Flag> returnFlags = new ArrayList<Flag>();
for (FlagRegion flagRegion : this.regions)
{
if (flagRegion.region.isIn(position) || flagRegion.name.equalsIgnoreCase(GLOBAL_REGION))
{
for (Flag flag : flagRegion.getFlags())
{
returnFlags.add(flag);
}
}
}
return returnFlags;
}
/**
* Gets all the values of the flags in this position.
*/
public List<String> getValues(String flagName, Vector3 position)
{
List<String> values = new ArrayList<String>();
for (Flag flag : this.getFlagsInPosition(position))
{
values.add(flag.value);
}
return values;
}
/**
* Checks if there is a flag in this position that has a specific value.
*/
public boolean containsValue(String flagName, String checkValue, Vector3 position)
{
for (Flag flag : this.getFlagsInPosition(position))
{
if (flag.name.equalsIgnoreCase(flagName) && flag.value.equalsIgnoreCase(checkValue))
{
return true;
}
}
return false;
}
public boolean addRegion(String name, Vector3 position, int radius)
{
Vector3 minVec = new Vector3(position.intX() - radius, 0, position.intZ() - radius);
Vector3 maxVec = new Vector3(position.intX() + radius, this.world.getHeight(), position.intZ() + radius);
return this.regions.add(new FlagRegion(this, name, new Region3(minVec, maxVec)));
}
public FlagRegion getRegion(String name)
{
for (FlagRegion region : this.regions)
{
if (region.name.equals(name))
{
return region;
}
}
return null;
}
/**
* Gets all regions that intersect this point.
*/
public List<FlagRegion> getRegions(Vector3 position)
{
List<FlagRegion> returnRegions = new ArrayList<FlagRegion>();
for (FlagRegion region : this.regions)
{
if (region.region.isIn(position))
{
returnRegions.add(region);
}
}
return returnRegions;
}
public boolean removeRegion(String name)
{
for (FlagRegion region : this.regions)
{
if (region.name.equals(name))
{
this.regions.remove(region);
return true;
}
}
return false;
}
public List<FlagRegion> getRegions()
{
Iterator<FlagRegion> it = this.regions.iterator();
while (it.hasNext())
{
FlagRegion region = it.next();
if (region == null)
{
it.remove();
continue;
}
if (region.name == null || region.name == "")
{
it.remove();
continue;
}
}
return this.regions;
}
}

View file

@ -0,0 +1,117 @@
package calclavia.lib.flag;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import net.minecraftforge.common.DimensionManager;
import universalelectricity.core.vector.Vector3;
public class ModFlag extends FlagBase
{
/**
* An array of world flag data. Each representing a world.
*/
private final List<FlagWorld> flagWorlds = new ArrayList<FlagWorld>();
/**
* Initiates a new mod flag data and loads everything from NBT into memory. Only exists server
* side.
*
* @param nbt
*/
public ModFlag(NBTTagCompound nbt)
{
this.readFromNBT(nbt);
}
@Override
public void readFromNBT(NBTTagCompound nbt)
{
if (nbt != null)
{
// A list containing all dimension ID and data within it.
Iterator dimensions = nbt.getTags().iterator();
while (dimensions.hasNext())
{
NBTTagCompound dimensionCompound = (NBTTagCompound) dimensions.next();
try
{
int dimensionID = Integer.parseInt(dimensionCompound.getName().replace("dim_", ""));
World world = DimensionManager.getWorld(dimensionID);
FlagWorld flagWorld = new FlagWorld(world);
flagWorld.readFromNBT(dimensionCompound);
this.flagWorlds.add(flagWorld);
}
catch (Exception e)
{
System.out.println("Mod Flag: Failed to read dimension data: " + dimensionCompound.getName());
e.printStackTrace();
}
}
}
}
@Override
public void writeToNBT(NBTTagCompound nbt)
{
if (nbt != null)
{
for (FlagWorld worldData : this.flagWorlds)
{
try
{
nbt.setTag("dim_" + worldData.world.provider.dimensionId, worldData.getNBT());
}
catch (Exception e)
{
System.out.println("Mod Flag: Failed to save world flag data: " + worldData.world);
e.printStackTrace();
}
}
}
}
public FlagWorld getFlagWorld(World world)
{
FlagWorld worldData = null;
if (world != null)
{
for (FlagWorld data : this.flagWorlds)
{
if (data.world != null && data.world.provider != null)
{
if (data.world.provider.dimensionId == world.provider.dimensionId)
{
worldData = data;
break;
}
}
}
// If data is null, create it.
if (worldData == null)
{
worldData = new FlagWorld(world);
this.flagWorlds.add(worldData);
}
}
return worldData;
}
public boolean containsValue(World world, String flagName, String checkValue, Vector3 position)
{
return this.getFlagWorld(world).containsValue(flagName, checkValue, position);
}
public List<FlagWorld> getFlagWorlds()
{
return this.flagWorlds;
}
}

View file

@ -0,0 +1,136 @@
package calclavia.lib.gui;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import calclavia.lib.IPlayerUsing;
public class ContainerBase extends Container
{
protected int slotCount = 0;
protected int xInventoryDisplacement = 8;
protected int yInventoryDisplacement = 135;
protected int yHotBarDisplacement = 193;
private IInventory inventory;
public ContainerBase(IInventory inventory)
{
this.inventory = inventory;
this.slotCount = inventory.getSizeInventory();
}
@Override
public void onContainerClosed(EntityPlayer entityplayer)
{
super.onContainerClosed(entityplayer);
if (this.inventory instanceof IPlayerUsing)
{
((IPlayerUsing) this.inventory).getPlayersUsing().remove(entityplayer);
}
}
public void addPlayerInventory(EntityPlayer player)
{
if (this.inventory instanceof IPlayerUsing)
{
((IPlayerUsing) this.inventory).getPlayersUsing().add(player);
}
for (int y = 0; y < 3; y++)
{
for (int x = 0; x < 9; x++)
{
this.addSlotToContainer(new Slot(player.inventory, x + y * 9 + 9, this.xInventoryDisplacement + x * 18, this.yInventoryDisplacement + y * 18));
}
}
for (int x = 0; x < 9; x++)
{
this.addSlotToContainer(new Slot(player.inventory, x, this.xInventoryDisplacement + x * 18, this.yHotBarDisplacement));
}
}
/**
* Called to transfer a stack from one inventory to the other eg. when shift clicking.
*/
@Override
public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int slotID)
{
ItemStack var2 = null;
Slot var3 = (Slot) this.inventorySlots.get(slotID);
if (var3 != null && var3.getHasStack())
{
ItemStack itemStack = var3.getStack();
var2 = itemStack.copy();
// A slot ID greater than the slot count means it is inside the TileEntity GUI.
if (slotID >= this.slotCount)
{
// Player Inventory, Try to place into slot.
boolean didTry = false;
for (int i = 0; i < this.slotCount; i++)
{
if (this.getSlot(i).isItemValid(itemStack))
{
didTry = true;
if (this.mergeItemStack(itemStack, i, i + 1, false))
{
break;
}
}
}
if (!didTry)
{
if (slotID < 27 + this.slotCount)
{
if (!this.mergeItemStack(itemStack, 27 + this.slotCount, 36 + this.slotCount, false))
{
return null;
}
}
else if (slotID >= 27 + this.slotCount && slotID < 36 + this.slotCount && !this.mergeItemStack(itemStack, slotCount, 27 + slotCount, false))
{
return null;
}
}
}
else if (!this.mergeItemStack(itemStack, this.slotCount, 36 + this.slotCount, false))
{
return null;
}
if (itemStack.stackSize == 0)
{
var3.putStack((ItemStack) null);
}
else
{
var3.onSlotChanged();
}
if (itemStack.stackSize == var2.stackSize)
{
return null;
}
var3.onPickupFromSlot(par1EntityPlayer, itemStack);
}
return var2;
}
@Override
public boolean canInteractWith(EntityPlayer entityplayer)
{
return this.inventory.isUseableByPlayer(entityplayer);
}
}

View file

@ -0,0 +1,197 @@
package calclavia.lib.gui;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.RenderHelper;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public abstract class GuiBase extends GuiScreen
{
/**
* The X size of the inventory window in pixels.
*/
protected int xSize = 176;
/**
* The Y size of the inventory window in pixels.
*/
protected int ySize = 166;
/**
* Starting X position for the Gui. Inconsistent use for Gui backgrounds.
*/
protected int guiLeft;
/**
* Starting Y position for the Gui. Inconsistent use for Gui backgrounds.
*/
protected int guiTop;
/**
* Adds the buttons (and other controls) to the screen in question.
*/
@Override
public void initGui()
{
super.initGui();
this.guiLeft = (this.width - this.xSize) / 2;
this.guiTop = (this.height - this.ySize) / 2;
}
/**
* Draws the screen and all the components in it.
*/
@Override
public void drawScreen(int par1, int par2, float par3)
{
this.drawDefaultBackground();
int var4 = this.guiLeft;
int var5 = this.guiTop;
this.drawBackgroundLayer(par1, par2, par3);
GL11.glPushMatrix();
GL11.glTranslatef(var4, var5, 0.0F);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
short var7 = 240;
short var8 = 240;
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, var7 / 1.0F, var8 / 1.0F);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
this.drawForegroundLayer(par1, par2, par3);
GL11.glDisable(GL12.GL_RESCALE_NORMAL);
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glDisable(GL11.GL_DEPTH_TEST);
GL11.glPopMatrix();
super.drawScreen(par1, par2, par3);
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glEnable(GL11.GL_DEPTH_TEST);
}
/**
* Draws the foreground layer for the GUI
*/
protected abstract void drawForegroundLayer(int var2, int var3, float var1);
/**
* Draws the background layer for the GUI
*/
protected abstract void drawBackgroundLayer(int var2, int var3, float var1);
/**
* Fired when a key is typed. This is the equivalent of KeyListener.keyTyped(KeyEvent e).
*/
@Override
protected void keyTyped(char x, int y)
{
if (y == 1 || y == this.mc.gameSettings.keyBindInventory.keyCode)
{
this.mc.thePlayer.closeScreen();
}
}
/**
* Returns true if this GUI should pause the game when it is displayed in single-player
*/
@Override
public boolean doesGuiPauseGame()
{
return false;
}
/**
* Called from the main game loop to update the screen.
*/
@Override
public void updateScreen()
{
super.updateScreen();
if (!this.mc.thePlayer.isEntityAlive() || this.mc.thePlayer.isDead)
{
this.mc.thePlayer.closeScreen();
}
}
public void drawTooltip(int x, int y, String... toolTips)
{
GL11.glDisable(GL12.GL_RESCALE_NORMAL);
RenderHelper.disableStandardItemLighting();
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glDisable(GL11.GL_DEPTH_TEST);
if (toolTips != null)
{
int var5 = 0;
int var6;
int var7;
for (var6 = 0; var6 < toolTips.length; ++var6)
{
var7 = this.fontRenderer.getStringWidth(toolTips[var6]);
if (var7 > var5)
{
var5 = var7;
}
}
var6 = x + 12;
var7 = y - 12;
int var9 = 8;
if (toolTips.length > 1)
{
var9 += 2 + (toolTips.length - 1) * 10;
}
if (this.guiTop + var7 + var9 + 6 > this.height)
{
var7 = this.height - var9 - this.guiTop - 6;
}
this.zLevel = 300.0F;
int var10 = -267386864;
this.drawGradientRect(var6 - 3, var7 - 4, var6 + var5 + 3, var7 - 3, var10, var10);
this.drawGradientRect(var6 - 3, var7 + var9 + 3, var6 + var5 + 3, var7 + var9 + 4, var10, var10);
this.drawGradientRect(var6 - 3, var7 - 3, var6 + var5 + 3, var7 + var9 + 3, var10, var10);
this.drawGradientRect(var6 - 4, var7 - 3, var6 - 3, var7 + var9 + 3, var10, var10);
this.drawGradientRect(var6 + var5 + 3, var7 - 3, var6 + var5 + 4, var7 + var9 + 3, var10, var10);
int var11 = 1347420415;
int var12 = (var11 & 16711422) >> 1 | var11 & -16777216;
this.drawGradientRect(var6 - 3, var7 - 3 + 1, var6 - 3 + 1, var7 + var9 + 3 - 1, var11, var12);
this.drawGradientRect(var6 + var5 + 2, var7 - 3 + 1, var6 + var5 + 3, var7 + var9 + 3 - 1, var11, var12);
this.drawGradientRect(var6 - 3, var7 - 3, var6 + var5 + 3, var7 - 3 + 1, var11, var11);
this.drawGradientRect(var6 - 3, var7 + var9 + 2, var6 + var5 + 3, var7 + var9 + 3, var12, var12);
for (int var13 = 0; var13 < toolTips.length; ++var13)
{
String var14 = toolTips[var13];
this.fontRenderer.drawStringWithShadow(var14, var6, var7, -1);
if (var13 == 0)
{
var7 += 2;
}
var7 += 10;
}
this.zLevel = 0.0F;
}
GL11.glEnable(GL11.GL_DEPTH_TEST);
GL11.glEnable(GL11.GL_LIGHTING);
RenderHelper.enableGUIStandardItemLighting();
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
}
}

View file

@ -0,0 +1,470 @@
package calclavia.lib.gui;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map.Entry;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.inventory.Container;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Icon;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;
import universalelectricity.compatibility.Compatibility;
import universalelectricity.core.electricity.ElectricityDisplay;
import universalelectricity.core.electricity.ElectricityDisplay.ElectricUnit;
import universalelectricity.core.vector.Vector2;
import universalelectricity.prefab.TranslationHelper;
import universalelectricity.prefab.vector.Region2;
import calclavia.lib.Calclavia;
import calclavia.lib.render.CalclaviaRenderHelper;
public class GuiContainerBase extends GuiContainer
{
public ResourceLocation baseTexture;
public enum SlotType
{
NONE, BATTERY, LIQUID, GAS, ARR_UP, ARR_DOWN, ARR_LEFT, ARR_RIGHT, ARR_UP_RIGHT,
ARR_UP_LEFT, ARR_DOWN_LEFT, ARR_DOWN_RIGHT
}
protected int meterX = 54;
protected int meterHeight = 49;
protected int meterWidth = 14;
protected int meterEnd = meterX + meterWidth;
protected int energyMode = 0;
public String tooltip = "";
protected HashMap<Region2, String> tooltips = new HashMap<Region2, String>();
protected int containerWidth;
protected int containerHeight;
public GuiContainerBase(Container container)
{
super(container);
this.ySize = 217;
this.baseTexture = Calclavia.GUI_BASE;
}
@Override
public void initGui()
{
super.initGui();
}
@Override
public void onGuiClosed()
{
Keyboard.enableRepeatEvents(false);
super.onGuiClosed();
}
@Override
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY)
{
Iterator<Entry<Region2, String>> it = this.tooltips.entrySet().iterator();
while (it.hasNext())
{
Entry<Region2, String> entry = it.next();
if (entry.getKey().isIn(new Vector2(mouseX - this.guiLeft, mouseY - this.guiTop)))
{
this.tooltip = entry.getValue();
break;
}
}
if (this.tooltip != null && this.tooltip != "")
{
this.drawTooltip(mouseX - this.guiLeft, mouseY - this.guiTop, Calclavia.splitStringPerWord(this.tooltip, 5).toArray(new String[] {}));
}
this.tooltip = "";
}
@Override
protected void drawGuiContainerBackgroundLayer(float var1, int x, int y)
{
this.containerWidth = (this.width - this.xSize) / 2;
this.containerHeight = (this.height - this.ySize) / 2;
this.mc.renderEngine.bindTexture(this.baseTexture);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
this.drawTexturedModalRect(this.containerWidth, this.containerHeight, 0, 0, this.xSize, this.ySize);
}
protected void drawBulb(int x, int y, boolean isOn)
{
this.mc.renderEngine.bindTexture(this.baseTexture);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
if (isOn)
{
this.drawTexturedModalRect(this.containerWidth + x, this.containerHeight + y, 161, 0, 6, 6);
}
else
{
this.drawTexturedModalRect(this.containerWidth + x, this.containerHeight + y, 161, 4, 6, 6);
}
}
protected void drawSlot(int x, int y, ItemStack itemStack)
{
this.mc.renderEngine.bindTexture(this.baseTexture);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
this.drawTexturedModalRect(this.containerWidth + x, this.containerHeight + y, 0, 0, 18, 18);
this.drawItemStack(itemStack, this.containerWidth + x, this.containerHeight + y);
}
protected void drawItemStack(ItemStack itemStack, int x, int y)
{
x += 1;
y += 1;
GL11.glTranslatef(0.0F, 0.0F, 32.0F);
// drawTexturedModelRectFromIcon
// GL11.glEnable(GL11.GL_BLEND);
// GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
itemRenderer.renderItemAndEffectIntoGUI(this.fontRenderer, this.mc.renderEngine, itemStack, x, y);
// GL11.glDisable(GL11.GL_BLEND);
}
protected void drawTextWithTooltip(String textName, String format, int x, int y, int mouseX, int mouseY)
{
this.drawTextWithTooltip(textName, format, x, y, mouseX, mouseY, 4210752);
}
protected void drawTextWithTooltip(String textName, String format, int x, int y, int mouseX, int mouseY, int color)
{
String name = TranslationHelper.getLocal("gui." + textName + ".name");
String text = format.replaceAll("%1", name);
this.fontRenderer.drawString(text, x, y, color);
String tooltip = TranslationHelper.getLocal("gui." + textName + ".tooltip");
if (tooltip != null && tooltip != "")
{
if (this.isPointInRegion(x, y, (int) (text.length() * 4.8), 12, mouseX, mouseY))
{
this.tooltip = tooltip;
}
}
}
protected void drawTextWithTooltip(String textName, int x, int y, int mouseX, int mouseY)
{
this.drawTextWithTooltip(textName, "%1", x, y, mouseX, mouseY);
}
protected void drawSlot(int x, int y, GuiSlotType type, float r, float g, float b)
{
this.mc.renderEngine.bindTexture(Calclavia.GUI_COMPONENTS);
GL11.glColor4f(r, g, b, 1.0F);
this.drawTexturedModalRect(this.containerWidth + x, this.containerHeight + y, 0, 0, 18, 18);
if (type != GuiSlotType.NONE)
{
this.drawTexturedModalRect(this.containerWidth + x, this.containerHeight + y, 0, 18 * type.ordinal(), 18, 18);
}
}
protected void drawSlot(int x, int y, GuiSlotType type)
{
this.drawSlot(x, y, type, 1, 1, 1);
}
protected void drawSlot(int x, int y)
{
this.drawSlot(x, y, GuiSlotType.NONE);
}
protected void drawBar(int x, int y, float scale)
{
this.mc.renderEngine.bindTexture(Calclavia.GUI_COMPONENTS);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
/**
* Draw background progress bar/
*/
this.drawTexturedModalRect(this.containerWidth + x, this.containerHeight + y, 18, 0, 22, 15);
if (scale > 0)
{
/**
* Draw white color actual progress.
*/
this.drawTexturedModalRect(this.containerWidth + x, this.containerHeight + y, 18, 15, 22 - (int) (scale * 22), 15);
}
}
protected void drawForce(int x, int y, float scale)
{
this.mc.renderEngine.bindTexture(Calclavia.GUI_COMPONENTS);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
/**
* Draw background progress bar/
*/
this.drawTexturedModalRect(this.containerWidth + x, this.containerHeight + y, 54, 0, 107, 11);
if (scale > 0)
{
/**
* Draw white color actual progress.
*/
this.drawTexturedModalRect(this.containerWidth + x, this.containerHeight + y, meterX, 11, (int) (scale * 107), 11);
}
}
protected void drawElectricity(int x, int y, float scale)
{
this.mc.renderEngine.bindTexture(Calclavia.GUI_COMPONENTS);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
/**
* Draw background progress bar/
*/
this.drawTexturedModalRect(this.containerWidth + x, this.containerHeight + y, 54, 0, 107, 11);
if (scale > 0)
{
/**
* Draw white color actual progress.
*/
this.drawTexturedModalRect(this.containerWidth + x, this.containerHeight + y, 54, 22, (int) (scale * 107), 11);
}
}
protected void drawMeter(int x, int y, float scale, float r, float g, float b)
{
this.mc.renderEngine.bindTexture(Calclavia.GUI_COMPONENTS);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
/**
* Draw the background meter.
*/
this.drawTexturedModalRect(this.containerWidth + x, this.containerHeight + y, 40, 0, this.meterWidth, this.meterHeight);
/**
* Draw liquid/gas inside
*/
GL11.glColor4f(r, g, b, 1.0F);
int actualScale = (int) ((this.meterHeight - 1) * scale);
this.drawTexturedModalRect(this.containerWidth + x, this.containerHeight + y + (this.meterHeight - 1 - actualScale), 40, 49, this.meterHeight - 1, actualScale);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
/**
* Draw measurement lines
*/
this.drawTexturedModalRect(this.containerWidth + x, this.containerHeight + y, 40, 49 * 2, this.meterWidth, this.meterHeight);
}
protected void drawMeter(int x, int y, float scale, FluidStack liquidStack)
{
this.mc.renderEngine.bindTexture(Calclavia.GUI_COMPONENTS);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
/**
* Draw the background meter.
*/
this.drawTexturedModalRect(this.containerWidth + x, this.containerHeight + y, 40, 0, meterWidth, meterHeight);
/**
* Draw liquid/gas inside
*/
this.displayGauge(this.containerWidth + x, this.containerHeight + y, -10, 1, 12, (int) ((meterHeight - 1) * scale), liquidStack);
/**
* Draw measurement lines
*/
this.mc.renderEngine.bindTexture(Calclavia.GUI_COMPONENTS);
this.drawTexturedModalRect(this.containerWidth + x, this.containerHeight + y, 40, 49 * 2, meterWidth, meterHeight);
}
protected void drawSlot(int x, int y, SlotType type, float r, float g, float b)
{
this.mc.renderEngine.bindTexture(Calclavia.GUI_COMPONENTS);
GL11.glColor4f(r, g, b, 1.0F);
this.drawTexturedModalRect(this.containerWidth + x, this.containerHeight + y, 0, 0, 18, 18);
if (type != SlotType.NONE)
{
this.drawTexturedModalRect(this.containerWidth + x, this.containerHeight + y, 0, 18 * type.ordinal(), 18, 18);
}
}
protected void drawSlot(int x, int y, SlotType type)
{
this.drawSlot(x, y, type, 1, 1, 1);
}
public void renderUniversalDisplay(int x, int y, float energy, int mouseX, int mouseY)
{
String display;
switch (this.energyMode)
{
default:
display = ElectricityDisplay.getDisplay(energy, ElectricUnit.WATT);
break;
case 1:
display = ElectricityDisplay.roundDecimals(energy * Compatibility.TO_BC_RATIO) + " MJ";
break;
case 2:
display = ElectricityDisplay.roundDecimals(energy * Compatibility.TO_IC2_RATIO) + " EU";
break;
}
if (Mouse.isButtonDown(0) && this.isPointInRegion(x, y, display.length() * 5, 9, mouseX, mouseY))
{
this.energyMode = (this.energyMode + 1) % 3;
}
this.fontRenderer.drawString(display, x, y, 4210752);
}
public void drawTooltip(int x, int y, String... toolTips)
{
if (!GuiScreen.isShiftKeyDown())
{
GL11.glDisable(GL12.GL_RESCALE_NORMAL);
RenderHelper.disableStandardItemLighting();
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glDisable(GL11.GL_DEPTH_TEST);
if (toolTips != null)
{
int var5 = 0;
int var6;
int var7;
for (var6 = 0; var6 < toolTips.length; ++var6)
{
var7 = this.fontRenderer.getStringWidth(toolTips[var6]);
if (var7 > var5)
{
var5 = var7;
}
}
var6 = x + 12;
var7 = y - 12;
int var9 = 8;
if (toolTips.length > 1)
{
var9 += 2 + (toolTips.length - 1) * 10;
}
if (this.guiTop + var7 + var9 + 6 > this.height)
{
var7 = this.height - var9 - this.guiTop - 6;
}
this.zLevel = 300.0F;
int var10 = -267386864;
this.drawGradientRect(var6 - 3, var7 - 4, var6 + var5 + 3, var7 - 3, var10, var10);
this.drawGradientRect(var6 - 3, var7 + var9 + 3, var6 + var5 + 3, var7 + var9 + 4, var10, var10);
this.drawGradientRect(var6 - 3, var7 - 3, var6 + var5 + 3, var7 + var9 + 3, var10, var10);
this.drawGradientRect(var6 - 4, var7 - 3, var6 - 3, var7 + var9 + 3, var10, var10);
this.drawGradientRect(var6 + var5 + 3, var7 - 3, var6 + var5 + 4, var7 + var9 + 3, var10, var10);
int var11 = 1347420415;
int var12 = (var11 & 16711422) >> 1 | var11 & -16777216;
this.drawGradientRect(var6 - 3, var7 - 3 + 1, var6 - 3 + 1, var7 + var9 + 3 - 1, var11, var12);
this.drawGradientRect(var6 + var5 + 2, var7 - 3 + 1, var6 + var5 + 3, var7 + var9 + 3 - 1, var11, var12);
this.drawGradientRect(var6 - 3, var7 - 3, var6 + var5 + 3, var7 - 3 + 1, var11, var11);
this.drawGradientRect(var6 - 3, var7 + var9 + 2, var6 + var5 + 3, var7 + var9 + 3, var12, var12);
for (int var13 = 0; var13 < toolTips.length; ++var13)
{
String var14 = toolTips[var13];
this.fontRenderer.drawStringWithShadow(var14, var6, var7, -1);
var7 += 10;
}
this.zLevel = 0.0F;
GL11.glEnable(GL11.GL_DEPTH_TEST);
GL11.glEnable(GL11.GL_LIGHTING);
RenderHelper.enableGUIStandardItemLighting();
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
}
}
}
/**
* Based on BuildCraft
*/
protected void displayGauge(int j, int k, int line, int col, int width, int squaled, FluidStack liquid)
{
squaled -= 1;
if (liquid == null)
{
return;
}
int start = 0;
Icon liquidIcon = null;
Fluid fluid = liquid.getFluid();
if (fluid != null && fluid.getStillIcon() != null)
{
liquidIcon = fluid.getStillIcon();
}
CalclaviaRenderHelper.setSpriteTexture(fluid.getSpriteNumber());
if (liquidIcon != null)
{
while (true)
{
int x;
if (squaled > 16)
{
x = 16;
squaled -= 16;
}
else
{
x = squaled;
squaled = 0;
}
this.drawTexturedModelRectFromIcon(j + col, k + line + 58 - x - start, liquidIcon, width, 16 - (16 - x));
start = start + 16;
if (x == 0 || squaled == 0)
{
break;
}
}
}
}
}

View file

@ -0,0 +1,370 @@
package calclavia.lib.gui;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map.Entry;
import net.minecraft.block.Block;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.item.Item;
import net.minecraft.util.Icon;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fluids.FluidStack;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;
import universalelectricity.core.vector.Vector2;
import universalelectricity.prefab.TranslationHelper;
import universalelectricity.prefab.vector.Region2;
import calclavia.lib.Calclavia;
public class GuiScreenBase extends GuiBase
{
private static final int METER_X = 54;
public static final int METER_HEIGHT = 49;
public static final int METER_WIDTH = 14;
public static final int METER_END = METER_X + METER_WIDTH;
public String tooltip = "";
protected HashMap<Region2, String> tooltips = new HashMap<Region2, String>();
protected int containerWidth;
protected int containerHeight;
public GuiScreenBase()
{
this.ySize = 217;
}
@Override
protected void drawForegroundLayer(int mouseX, int mouseY, float var1)
{
Iterator<Entry<Region2, String>> it = this.tooltips.entrySet().iterator();
while (it.hasNext())
{
Entry<Region2, String> entry = it.next();
if (entry.getKey().isIn(new Vector2(mouseX - this.guiLeft, mouseY - this.guiTop)))
{
this.tooltip = entry.getValue();
break;
}
}
if (this.tooltip != null && this.tooltip != "")
{
this.drawTooltip(mouseX - this.guiLeft, mouseY - this.guiTop, Calclavia.splitStringPerWord(this.tooltip, 5).toArray(new String[] {}));
}
this.tooltip = "";
}
@Override
protected void drawBackgroundLayer(int x, int y, float var1)
{
this.containerWidth = (this.width - this.xSize) / 2;
this.containerHeight = (this.height - this.ySize) / 2;
this.mc.renderEngine.bindTexture(Calclavia.GUI_EMPTY_FILE);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
this.drawTexturedModalRect(this.containerWidth, this.containerHeight, 0, 0, this.xSize, this.ySize);
}
protected void drawBulb(int x, int y, boolean isOn)
{
this.mc.renderEngine.bindTexture(Calclavia.GUI_EMPTY_FILE);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
if (isOn)
{
this.drawTexturedModalRect(this.containerWidth + x, this.containerHeight + y, 161, 0, 6, 6);
}
else
{
this.drawTexturedModalRect(this.containerWidth + x, this.containerHeight + y, 161, 4, 6, 6);
}
}
protected void drawTextWithTooltip(String textName, String format, int x, int y, int mouseX, int mouseY)
{
this.drawTextWithTooltip(textName, format, x, y, mouseX, mouseY, 4210752);
}
protected void drawTextWithTooltip(String textName, String format, int x, int y, int mouseX, int mouseY, int color)
{
String name = TranslationHelper.getLocal("gui." + textName + ".name");
String text = format.replaceAll("%1", name);
this.fontRenderer.drawString(text, x, y, color);
String tooltip = TranslationHelper.getLocal("gui." + textName + ".tooltip");
if (tooltip != null && tooltip != "")
{
if (this.isPointInRegion(x, y, (int) (text.length() * 4.8), 12, mouseX, mouseY))
{
this.tooltip = tooltip;
}
}
}
protected boolean isPointInRegion(int par1, int par2, int par3, int par4, int par5, int par6)
{
int k1 = this.guiLeft;
int l1 = this.guiTop;
par5 -= k1;
par6 -= l1;
return par5 >= par1 - 1 && par5 < par1 + par3 + 1 && par6 >= par2 - 1 && par6 < par2 + par4 + 1;
}
protected void drawTextWithTooltip(String textName, int x, int y, int mouseX, int mouseY)
{
this.drawTextWithTooltip(textName, "%1", x, y, mouseX, mouseY);
}
protected void drawSlot(int x, int y, GuiSlotType type, float r, float g, float b)
{
this.mc.renderEngine.bindTexture(Calclavia.GUI_EMPTY_FILE);
GL11.glColor4f(r, g, b, 1.0F);
this.drawTexturedModalRect(this.containerWidth + x, this.containerHeight + y, 0, 0, 18, 18);
if (type != GuiSlotType.NONE)
{
this.drawTexturedModalRect(this.containerWidth + x, this.containerHeight + y, 0, 18 * type.ordinal(), 18, 18);
}
}
protected void drawSlot(int x, int y, GuiSlotType type)
{
this.drawSlot(x, y, type, 1, 1, 1);
}
protected void drawSlot(int x, int y)
{
this.drawSlot(x, y, GuiSlotType.NONE);
}
protected void drawBar(int x, int y, float scale)
{
this.mc.renderEngine.bindTexture(Calclavia.GUI_EMPTY_FILE);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
/**
* Draw background progress bar/
*/
this.drawTexturedModalRect(this.containerWidth + x, this.containerHeight + y, 18, 0, 22, 15);
if (scale > 0)
{
/**
* Draw white color actual progress.
*/
this.drawTexturedModalRect(this.containerWidth + x, this.containerHeight + y, 18, 15, 22 - (int) (scale * 22), 15);
}
}
protected void drawForce(int x, int y, float scale)
{
this.mc.renderEngine.bindTexture(Calclavia.GUI_EMPTY_FILE);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
/**
* Draw background progress bar/
*/
this.drawTexturedModalRect(this.containerWidth + x, this.containerHeight + y, 54, 0, 107, 11);
if (scale > 0)
{
/**
* Draw white color actual progress.
*/
this.drawTexturedModalRect(this.containerWidth + x, this.containerHeight + y, METER_X, 11, (int) (scale * 107), 11);
}
}
protected void drawElectricity(int x, int y, float scale)
{
this.mc.renderEngine.bindTexture(Calclavia.GUI_EMPTY_FILE);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
/**
* Draw background progress bar/
*/
this.drawTexturedModalRect(this.containerWidth + x, this.containerHeight + y, 54, 0, 107, 11);
if (scale > 0)
{
/**
* Draw white color actual progress.
*/
this.drawTexturedModalRect(this.containerWidth + x, this.containerHeight + y, 54, 22, (int) (scale * 107), 11);
}
}
protected void drawMeter(int x, int y, float scale, FluidStack fluidStack)
{
this.mc.renderEngine.bindTexture(Calclavia.GUI_EMPTY_FILE);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
/**
* Draw the background meter.
*/
this.drawTexturedModalRect(this.containerWidth + x, this.containerHeight + y, 40, 0, METER_WIDTH, METER_HEIGHT);
/**
* Draw liquid/gas inside
*/
this.displayGauge(this.containerWidth + x, this.containerHeight + y, 0, 0, (int) ((METER_HEIGHT - 1) * scale), fluidStack);
/**
* Draw measurement lines
*/
this.mc.renderEngine.bindTexture(Calclavia.GUI_EMPTY_FILE);
this.drawTexturedModalRect(this.containerWidth + x, this.containerHeight + y, 40, 49 * 2, METER_WIDTH, METER_HEIGHT);
}
@Override
public void drawTooltip(int x, int y, String... toolTips)
{
if (!GuiScreen.isShiftKeyDown())
{
GL11.glDisable(GL12.GL_RESCALE_NORMAL);
RenderHelper.disableStandardItemLighting();
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glDisable(GL11.GL_DEPTH_TEST);
if (toolTips != null)
{
int var5 = 0;
int var6;
int var7;
for (var6 = 0; var6 < toolTips.length; ++var6)
{
var7 = this.fontRenderer.getStringWidth(toolTips[var6]);
if (var7 > var5)
{
var5 = var7;
}
}
var6 = x + 12;
var7 = y - 12;
int var9 = 8;
if (toolTips.length > 1)
{
var9 += 2 + (toolTips.length - 1) * 10;
}
if (this.guiTop + var7 + var9 + 6 > this.height)
{
var7 = this.height - var9 - this.guiTop - 6;
}
this.zLevel = 300.0F;
int var10 = -267386864;
this.drawGradientRect(var6 - 3, var7 - 4, var6 + var5 + 3, var7 - 3, var10, var10);
this.drawGradientRect(var6 - 3, var7 + var9 + 3, var6 + var5 + 3, var7 + var9 + 4, var10, var10);
this.drawGradientRect(var6 - 3, var7 - 3, var6 + var5 + 3, var7 + var9 + 3, var10, var10);
this.drawGradientRect(var6 - 4, var7 - 3, var6 - 3, var7 + var9 + 3, var10, var10);
this.drawGradientRect(var6 + var5 + 3, var7 - 3, var6 + var5 + 4, var7 + var9 + 3, var10, var10);
int var11 = 1347420415;
int var12 = (var11 & 16711422) >> 1 | var11 & -16777216;
this.drawGradientRect(var6 - 3, var7 - 3 + 1, var6 - 3 + 1, var7 + var9 + 3 - 1, var11, var12);
this.drawGradientRect(var6 + var5 + 2, var7 - 3 + 1, var6 + var5 + 3, var7 + var9 + 3 - 1, var11, var12);
this.drawGradientRect(var6 - 3, var7 - 3, var6 + var5 + 3, var7 - 3 + 1, var11, var11);
this.drawGradientRect(var6 - 3, var7 + var9 + 2, var6 + var5 + 3, var7 + var9 + 3, var12, var12);
for (int var13 = 0; var13 < toolTips.length; ++var13)
{
String var14 = toolTips[var13];
this.fontRenderer.drawStringWithShadow(var14, var6, var7, -1);
var7 += 10;
}
this.zLevel = 0.0F;
GL11.glEnable(GL11.GL_DEPTH_TEST);
GL11.glEnable(GL11.GL_LIGHTING);
RenderHelper.enableGUIStandardItemLighting();
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
}
}
}
/**
* Based on BuildCraft
*/
protected void displayGauge(int j, int k, int line, int col, int squaled, FluidStack fluid)
{
if (fluid == null)
{
return;
}
int start = 0;
Icon liquidIcon;
ResourceLocation textureSheet;
if (fluid.getFluid().getIcon() != null)
{
if (fluid.getFluid().canBePlacedInWorld())
{
textureSheet = new ResourceLocation("/terrain.png");
}
else
{
textureSheet = new ResourceLocation("/terrain.png");
}
liquidIcon = fluid.getFluid().getIcon();
}
else
{
if (fluid.fluidID < Block.blocksList.length && Block.blocksList[fluid.fluidID].blockID > 0)
{
liquidIcon = Block.blocksList[fluid.fluidID].getIcon(0, 0);
textureSheet = new ResourceLocation("/terrain.png");
}
else
{
liquidIcon = Item.itemsList[fluid.fluidID].getIconFromDamage(0);
textureSheet = new ResourceLocation("/gui/items.png");
}
}
this.mc.renderEngine.bindTexture(textureSheet);
while (true)
{
int x = 0;
if (squaled > 16)
{
x = 16;
squaled -= 16;
}
else
{
x = squaled;
squaled = 0;
}
drawTexturedModelRectFromIcon(j + col, k + line + 58 - x - start, liquidIcon, 16, 16 - (16 - x));
start = start + 16;
if (x == 0 || squaled == 0)
{
break;
}
}
}
}

View file

@ -0,0 +1,7 @@
package calclavia.lib.gui;
public enum GuiSlotType
{
NONE, BATTERY, LIQUID, ARR_UP, ARR_DOWN, ARR_LEFT, ARR_RIGHT, ARR_UP_RIGHT, ARR_UP_LEFT,
ARR_DOWN_LEFT, ARR_DOWN_RIGHT
}

View file

@ -0,0 +1,164 @@
package calclavia.lib.multiblock;
import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;
import universalelectricity.core.UniversalElectricity;
import universalelectricity.core.vector.Vector3;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class BlockMulti extends BlockContainer
{
public String textureName = null;
public String channel = "";
public BlockMulti(int id)
{
super(id, UniversalElectricity.machine);
this.setHardness(0.8F);
this.setUnlocalizedName("multiBlock");
}
public BlockMulti setChannel(String channel)
{
this.channel = channel;
return this;
}
@Override
public BlockMulti setTextureName(String name)
{
this.textureName = name;
return this;
}
public void createMultiBlockStructure(IMultiBlock tile)
{
TileEntity tileEntity = (TileEntity) tile;
Vector3[] positions = tile.getMultiBlockVectors();
for (Vector3 position : positions)
{
makeFakeBlock(tileEntity.worldObj, new Vector3(tileEntity).translate(position), new Vector3(tileEntity));
}
}
public void destroyMultiBlockStructure(IMultiBlock tile)
{
TileEntity tileEntity = (TileEntity) tile;
Vector3[] positions = tile.getMultiBlockVectors();
for (Vector3 position : positions)
{
new Vector3(tileEntity).translate(position).setBlock(tileEntity.worldObj, 0);
}
new Vector3(tileEntity).setBlock(tileEntity.worldObj, 0);
}
public void makeFakeBlock(World worldObj, Vector3 position, Vector3 mainBlock)
{
// Creates a fake block, then sets the relative main block position.
worldObj.setBlock(position.intX(), position.intY(), position.intZ(), this.blockID);
((TileEntityMultiBlockPart) worldObj.getBlockTileEntity(position.intX(), position.intY(), position.intZ())).setMainBlock(mainBlock);
}
@SideOnly(Side.CLIENT)
@Override
public void registerIcons(IconRegister iconRegister)
{
if (this.textureName != null)
{
this.blockIcon = iconRegister.registerIcon(this.textureName);
}
else
{
super.registerIcons(iconRegister);
}
}
@Override
public void breakBlock(World world, int x, int y, int z, int par5, int par6)
{
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
if (tileEntity instanceof TileEntityMultiBlockPart)
{
((TileEntityMultiBlockPart) tileEntity).onBlockRemoval(this);
}
super.breakBlock(world, x, y, z, par5, par6);
}
/**
* Called when the block is right clicked by the player. This modified version detects electric
* items and wrench actions on your machine block. Do not override this function. Use
* machineActivated instead! (It does the same thing)
*/
@Override
public boolean onBlockActivated(World par1World, int x, int y, int z, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9)
{
TileEntityMultiBlockPart tileEntity = (TileEntityMultiBlockPart) par1World.getBlockTileEntity(x, y, z);
return tileEntity.onBlockActivated(par1World, x, y, z, par5EntityPlayer);
}
/**
* Returns the quantity of items to drop on block destruction.
*/
@Override
public int quantityDropped(Random par1Random)
{
return 0;
}
@Override
public int getRenderType()
{
return -1;
}
@Override
public boolean isOpaqueCube()
{
return false;
}
@Override
public boolean renderAsNormalBlock()
{
return false;
}
@Override
public TileEntity createNewTileEntity(World var1)
{
return new TileEntityMultiBlockPart(this.channel);
}
@Override
public ItemStack getPickBlock(MovingObjectPosition target, World par1World, int x, int y, int z)
{
TileEntity tileEntity = par1World.getBlockTileEntity(x, y, z);
Vector3 mainBlockPosition = ((TileEntityMultiBlockPart) tileEntity).getMainBlock();
if (mainBlockPosition != null)
{
int mainBlockID = par1World.getBlockId(mainBlockPosition.intX(), mainBlockPosition.intY(), mainBlockPosition.intZ());
if (mainBlockID > 0)
{
return Block.blocksList[mainBlockID].getPickBlock(target, par1World, mainBlockPosition.intX(), mainBlockPosition.intY(), mainBlockPosition.intZ());
}
}
return null;
}
}

View file

@ -0,0 +1,17 @@
package calclavia.lib.multiblock;
import net.minecraft.entity.player.EntityPlayer;
/**
* A general interface to be implemented by anything that needs it.
*
* @author Calclavia
*
*/
public interface IBlockActivate
{
/**
* Called when activated
*/
public boolean onActivated(EntityPlayer entityPlayer);
}

View file

@ -0,0 +1,18 @@
package calclavia.lib.multiblock;
import universalelectricity.core.vector.Vector3;
/**
* Interface to be applied to tile entity blocks that occupies more than one block space. Useful for
* large machines.
*
* @author Calclavia
*
*/
public interface IMultiBlock
{
/**
* @return An array of Vector3 containing the multiblock relative coordinates to be constructed.
*/
public Vector3[] getMultiBlockVectors();
}

View file

@ -0,0 +1,6 @@
package calclavia.lib.multiblock;
public class MultiBlock
{
}

View file

@ -0,0 +1,158 @@
package calclavia.lib.multiblock;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.INetworkManager;
import net.minecraft.network.packet.Packet;
import net.minecraft.network.packet.Packet250CustomPayload;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import universalelectricity.core.vector.Vector3;
import universalelectricity.prefab.network.IPacketReceiver;
import universalelectricity.prefab.network.PacketManager;
import com.google.common.io.ByteArrayDataInput;
/**
* This is a multiblock to be used for blocks that are bigger than one block.
*
* @author Calclavia
*
*/
public class TileEntityMultiBlockPart extends TileEntity implements IPacketReceiver
{
// The the position of the main block. Relative to this block's position.
private Vector3 mainBlockPosition;
public String channel;
public TileEntityMultiBlockPart()
{
}
public TileEntityMultiBlockPart(String channel)
{
this.channel = channel;
}
public Vector3 getMainBlock()
{
if (this.mainBlockPosition != null)
{
return new Vector3(this).translate(this.mainBlockPosition);
}
return null;
}
public void setMainBlock(Vector3 mainBlock)
{
this.mainBlockPosition = mainBlock.clone().translate(new Vector3(this).invert());
if (!this.worldObj.isRemote)
{
this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord);
}
}
@Override
public Packet getDescriptionPacket()
{
if (this.mainBlockPosition != null)
{
if (this.channel == null || this.channel == "" && this.getBlockType() instanceof BlockMulti)
{
this.channel = ((BlockMulti) this.getBlockType()).channel;
}
return PacketManager.getPacket(this.channel, this, this.mainBlockPosition.intX(), this.mainBlockPosition.intY(), this.mainBlockPosition.intZ());
}
return null;
}
@Override
public void handlePacketData(INetworkManager network, int packetType, Packet250CustomPayload packet, EntityPlayer player, ByteArrayDataInput dataStream)
{
try
{
this.mainBlockPosition = new Vector3(dataStream.readInt(), dataStream.readInt(), dataStream.readInt());
}
catch (Exception e)
{
e.printStackTrace();
}
}
public void onBlockRemoval(BlockMulti block)
{
if (this.getMainBlock() != null)
{
TileEntity tileEntity = this.getMainBlock().getTileEntity(this.worldObj);
if (tileEntity instanceof IMultiBlock)
{
block.destroyMultiBlockStructure((IMultiBlock) tileEntity);
}
}
}
public boolean onBlockActivated(World par1World, int x, int y, int z, EntityPlayer entityPlayer)
{
if (this.getMainBlock() != null)
{
TileEntity tileEntity = this.getMainBlock().getTileEntity(this.worldObj);
if (tileEntity instanceof IBlockActivate)
{
return ((IBlockActivate) tileEntity).onActivated(entityPlayer);
}
}
return false;
}
/**
* Reads a tile entity from NBT.
*/
@Override
public void readFromNBT(NBTTagCompound nbt)
{
super.readFromNBT(nbt);
if (nbt.hasKey("mainBlockPosition"))
{
this.mainBlockPosition = new Vector3(nbt.getCompoundTag("mainBlockPosition"));
}
this.channel = nbt.getString("channel");
}
/**
* Writes a tile entity to NBT.
*/
@Override
public void writeToNBT(NBTTagCompound nbt)
{
super.writeToNBT(nbt);
if (this.mainBlockPosition != null)
{
nbt.setCompoundTag("mainBlockPosition", this.mainBlockPosition.writeToNBT(new NBTTagCompound()));
}
nbt.setString("channel", this.channel);
}
/**
* Determines if this TileEntity requires update calls.
*
* @return True if you want updateEntity() to be called, false if not
*/
@Override
public boolean canUpdate()
{
return false;
}
}

View file

@ -0,0 +1,173 @@
package calclavia.lib.render;
import static org.lwjgl.opengl.GL11.GL_BLEND;
import static org.lwjgl.opengl.GL11.GL_FLAT;
import static org.lwjgl.opengl.GL11.GL_LINE_SMOOTH;
import static org.lwjgl.opengl.GL11.GL_ONE_MINUS_SRC_ALPHA;
import static org.lwjgl.opengl.GL11.GL_POLYGON_SMOOTH;
import static org.lwjgl.opengl.GL11.GL_SMOOTH;
import static org.lwjgl.opengl.GL11.GL_SRC_ALPHA;
import static org.lwjgl.opengl.GL11.glBlendFunc;
import static org.lwjgl.opengl.GL11.glDisable;
import static org.lwjgl.opengl.GL11.glEnable;
import static org.lwjgl.opengl.GL11.glRotatef;
import static org.lwjgl.opengl.GL11.glShadeModel;
import static org.lwjgl.opengl.GL11.glTranslatef;
import net.minecraft.block.Block;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.GL11;
import cpw.mods.fml.client.FMLClientHandler;
public class CalclaviaRenderHelper
{
public static final ResourceLocation PARTICLE_RESOURCE = new ResourceLocation("textures/particle/particles.png");
public static void setTerrainTexture()
{
setSpriteTexture(0);
}
public static void setSpriteTexture(ItemStack itemStack)
{
setSpriteTexture(itemStack.getItemSpriteNumber());
}
public static void setSpriteTexture(int sprite)
{
FMLClientHandler.instance().getClient().renderEngine.bindTexture(FMLClientHandler.instance().getClient().renderEngine.getResourceLocation(sprite));
}
/**
* Enables blending.
*/
public static void enableBlending()
{
glShadeModel(GL_SMOOTH);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
/**
* Disables blending.
*/
public static void disableBlending()
{
glShadeModel(GL_FLAT);
glDisable(GL_LINE_SMOOTH);
glDisable(GL_POLYGON_SMOOTH);
glDisable(GL_BLEND);
}
public static void enableLighting()
{
RenderHelper.enableStandardItemLighting();
}
/**
* Disables lighting and turns glow on.
*/
public static void disableLighting()
{
RenderHelper.disableStandardItemLighting();
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240.0F, 240.0F);
}
public static void renderNormalBlockAsItem(Block block, int metadata, RenderBlocks renderer)
{
Tessellator tessellator = Tessellator.instance;
block.setBlockBoundsForItemRender();
renderer.setRenderBoundsFromBlock(block);
glRotatef(90.0F, 0.0F, 1.0F, 0.0F);
glTranslatef(-0.5F, -0.5F, -0.5F);
tessellator.startDrawingQuads();
tessellator.setNormal(0.0F, -1.0F, 0.0F);
renderer.renderFaceYNeg(block, 0.0D, 0.0D, 0.0D, renderer.getBlockIconFromSideAndMetadata(block, 0, metadata));
tessellator.draw();
tessellator.startDrawingQuads();
tessellator.setNormal(0.0F, 1.0F, 0.0F);
renderer.renderFaceYPos(block, 0.0D, 0.0D, 0.0D, renderer.getBlockIconFromSideAndMetadata(block, 1, metadata));
tessellator.draw();
tessellator.startDrawingQuads();
tessellator.setNormal(0.0F, 0.0F, -1.0F);
renderer.renderFaceZNeg(block, 0.0D, 0.0D, 0.0D, renderer.getBlockIconFromSideAndMetadata(block, 2, metadata));
tessellator.draw();
tessellator.startDrawingQuads();
tessellator.setNormal(0.0F, 0.0F, 1.0F);
renderer.renderFaceZPos(block, 0.0D, 0.0D, 0.0D, renderer.getBlockIconFromSideAndMetadata(block, 3, metadata));
tessellator.draw();
tessellator.startDrawingQuads();
tessellator.setNormal(-1.0F, 0.0F, 0.0F);
renderer.renderFaceXNeg(block, 0.0D, 0.0D, 0.0D, renderer.getBlockIconFromSideAndMetadata(block, 4, metadata));
tessellator.draw();
tessellator.startDrawingQuads();
tessellator.setNormal(1.0F, 0.0F, 0.0F);
renderer.renderFaceXPos(block, 0.0D, 0.0D, 0.0D, renderer.getBlockIconFromSideAndMetadata(block, 5, metadata));
tessellator.draw();
glTranslatef(0.5F, 0.5F, 0.5F);
}
public static void renderFloatingText(String text, float x, float y, float z)
{
renderFloatingText(text, x, y, z, 0xFFFFFF);
}
/**
* Renders a floating text in a specific position.
*
* @author Briman0094
*
*/
public static void renderFloatingText(String text, float x, float y, float z, int color)
{
RenderManager renderManager = RenderManager.instance;
FontRenderer fontRenderer = renderManager.getFontRenderer();
float scale = 0.027f;
GL11.glColor4f(1f, 1f, 1f, 0.5f);
GL11.glPushMatrix();
GL11.glTranslatef(x + 0.0F, y + 2.3F, z);
GL11.glNormal3f(0.0F, 1.0F, 0.0F);
GL11.glRotatef(-renderManager.playerViewY, 0.0F, 1.0F, 0.0F);
GL11.glRotatef(renderManager.playerViewX, 1.0F, 0.0F, 0.0F);
GL11.glScalef(-scale, -scale, scale);
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glDepthMask(false);
GL11.glDisable(GL11.GL_DEPTH_TEST);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
Tessellator tessellator = Tessellator.instance;
int yOffset = 0;
GL11.glDisable(GL11.GL_TEXTURE_2D);
tessellator.startDrawingQuads();
int stringMiddle = fontRenderer.getStringWidth(text) / 2;
tessellator.setColorRGBA_F(0.0F, 0.0F, 0.0F, 0.5F);
tessellator.addVertex(-stringMiddle - 1, -1 + yOffset, 0.0D);
tessellator.addVertex(-stringMiddle - 1, 8 + yOffset, 0.0D);
tessellator.addVertex(stringMiddle + 1, 8 + yOffset, 0.0D);
tessellator.addVertex(stringMiddle + 1, -1 + yOffset, 0.0D);
tessellator.draw();
GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glColor4f(1f, 1f, 1f, 0.5f);
fontRenderer.drawString(text, -fontRenderer.getStringWidth(text) / 2, yOffset, color);
GL11.glEnable(GL11.GL_DEPTH_TEST);
GL11.glDepthMask(true);
fontRenderer.drawString(text, -fontRenderer.getStringWidth(text) / 2, yOffset, color);
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glDisable(GL11.GL_BLEND);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
GL11.glPopMatrix();
}
}

View file

@ -0,0 +1,23 @@
package calclavia.lib.render;
import java.util.HashMap;
import net.minecraft.entity.player.EntityPlayer;
/**
* Applied to TileEntities to render a tag above them.
*
* @author Calclavia
*
*/
public interface ITagRender
{
/**
* Gets the list of strings to render above the object.
*
* @param player The player this list will display for
* @param map HashMap of strings followed by there color Example {"Hello World",0x88FF88}
* @return The height in which the render should happen.
*/
public float addInformation(HashMap<String, Integer> map, EntityPlayer player);
}

View file

@ -0,0 +1,89 @@
package calclavia.lib.render;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map.Entry;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.entity.RendererLivingEntity;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.MovingObjectPosition;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
/**
* @author Rseifert & Calclavia
*/
@SideOnly(Side.CLIENT)
public abstract class RenderTaggedTile extends TileEntitySpecialRenderer
{
@Override
public void renderTileEntityAt(TileEntity t, double x, double y, double z, float f)
{
if (t != null)
{
if (t instanceof ITagRender && this.getPlayer().getDistance(t.xCoord, t.yCoord, t.zCoord) <= RendererLivingEntity.NAME_TAG_RANGE)
{
HashMap<String, Integer> tags = new HashMap<String, Integer>();
float height = ((ITagRender) t).addInformation(tags, this.getPlayer());
EntityPlayer player = Minecraft.getMinecraft().thePlayer;
if (player.ridingEntity == null)
{
MovingObjectPosition objectPosition = player.rayTrace(8, 1);
if (objectPosition != null)
{
boolean isLooking = false;
for (int h = 0; h < height; h++)
{
if (objectPosition.blockX == t.xCoord && objectPosition.blockY == t.yCoord + h && objectPosition.blockZ == t.zCoord)
{
isLooking = true;
}
}
if (isLooking)
{
Iterator<Entry<String, Integer>> it = tags.entrySet().iterator();
int i = 0;
while (it.hasNext())
{
Entry<String, Integer> entry = it.next();
if (entry.getKey() != null)
{
CalclaviaRenderHelper.renderFloatingText(entry.getKey(), (float) x + 0.5f, ((float) y + (i * 0.25f)) - 2f + height, (float) z + 0.5f, entry.getValue());
}
i++;
}
}
}
}
}
}
}
/**
* gets the player linked with the renderer
*/
public EntityPlayer getPlayer()
{
EntityLivingBase entity = this.tileEntityRenderer.entityLivingPlayer;
if (entity instanceof EntityPlayer)
{
return (EntityPlayer) entity;
}
return null;
}
}

View file

@ -0,0 +1,12 @@
package mekanism.api.induction;
import universalelectricity.core.item.IItemElectric;
/**
* @author Calclavia
*
*/
public interface ICapacitor extends IItemElectric
{
}

View file

@ -0,0 +1,23 @@
/**
*
*/
package mekanism.api.induction;
import net.minecraft.tileentity.TileEntity;
/**
* @author Calclavia
*
*/
public interface ITesla
{
/**
* @param transferEnergy - The energy amount in kilojoules.
* @param doTransfer - Actually transfer
* @return Energy actually transfered.
*/
public float transfer(float transferEnergy, boolean doTransfer);
public boolean canReceive(TileEntity transferTile);
}

View file

@ -22,7 +22,7 @@ public abstract class MachineRecipeHandler extends TemplateRecipeHandler
public abstract String getRecipeId();
public abstract Set<Entry<ItemStack, ItemStack>> getRecipes();
@Override
public void drawBackground(int i)
{

View file

@ -10,6 +10,7 @@ import mekanism.api.Object3D;
import mekanism.api.SideData;
import mekanism.common.tileentity.TileEntityContainerBlock;
import mekanism.common.tileentity.TileEntityLogisticalTransporter;
import mekanism.common.util.InventoryUtils;
import mekanism.common.util.MekanismUtils;
import mekanism.common.util.TransporterUtils;
import net.minecraft.inventory.IInventory;
@ -116,7 +117,7 @@ public class TileComponentEjector implements ITileComponent, IEjector
if(tile instanceof IInventory && !(tile instanceof TileEntityLogisticalTransporter))
{
stack = TransporterUtils.putStackInInventory((IInventory)tile, stack, side.ordinal(), false);
stack = InventoryUtils.putStackInInventory((IInventory)tile, stack, side.ordinal(), false);
}
else if(tile instanceof TileEntityLogisticalTransporter)
{

View file

@ -257,13 +257,13 @@ public class ItemBlockEnergyCube extends ItemBlock implements IEnergizedItem, II
@Override
public int receiveEnergy(ItemStack theItem, int energy, boolean doReceive)
{
return (int)(recharge(theItem, (int)((energy*Mekanism.FROM_TE)*Mekanism.TO_UE), doReceive)*Mekanism.TO_TE);
return (int)(recharge(theItem, (int)((energy*Mekanism.FROM_TE)*Mekanism.TO_UE), !doReceive)*Mekanism.TO_TE);
}
@Override
public int extractEnergy(ItemStack theItem, int energy, boolean doTransfer)
{
return (int)(discharge(theItem, (int)((energy*Mekanism.FROM_TE)*Mekanism.TO_UE), doTransfer)*Mekanism.TO_TE);
return (int)(discharge(theItem, (int)((energy*Mekanism.FROM_TE)*Mekanism.TO_UE), !doTransfer)*Mekanism.TO_TE);
}
@Override

View file

@ -691,13 +691,13 @@ public class ItemBlockMachine extends ItemBlock implements IEnergizedItem, IItem
@Override
public int receiveEnergy(ItemStack theItem, int energy, boolean doReceive)
{
return (int)(recharge(theItem, (int)((energy*Mekanism.FROM_TE)*Mekanism.TO_UE), doReceive)*Mekanism.TO_TE);
return (int)(recharge(theItem, (int)((energy*Mekanism.FROM_TE)*Mekanism.TO_UE), !doReceive)*Mekanism.TO_TE);
}
@Override
public int extractEnergy(ItemStack theItem, int energy, boolean doTransfer)
{
return (int)(discharge(theItem, (int)((energy*Mekanism.FROM_TE)*Mekanism.TO_UE), doTransfer)*Mekanism.TO_TE);
return (int)(discharge(theItem, (int)((energy*Mekanism.FROM_TE)*Mekanism.TO_UE), !doTransfer)*Mekanism.TO_TE);
}
@Override

View file

@ -165,13 +165,13 @@ public class ItemEnergized extends ItemMekanism implements IEnergizedItem, IItem
@Override
public int receiveEnergy(ItemStack theItem, int energy, boolean doReceive)
{
return (int)(recharge(theItem, (int)((energy*Mekanism.FROM_TE)*Mekanism.TO_UE), doReceive)*Mekanism.TO_TE);
return (int)(recharge(theItem, (int)((energy*Mekanism.FROM_TE)*Mekanism.TO_UE), !doReceive)*Mekanism.TO_TE);
}
@Override
public int extractEnergy(ItemStack theItem, int energy, boolean doTransfer)
{
return (int)(discharge(theItem, (int)((energy*Mekanism.FROM_TE)*Mekanism.TO_UE), doTransfer)*Mekanism.TO_TE);
return (int)(discharge(theItem, (int)((energy*Mekanism.FROM_TE)*Mekanism.TO_UE), !doTransfer)*Mekanism.TO_TE);
}
@Override

View file

@ -58,9 +58,9 @@ public abstract class TileEntityBasicBlock extends TileEntity implements IWrench
PacketHandler.sendPacket(Transmission.SINGLE_CLIENT, new PacketTileEntity().setParams(Object3D.get(this), getNetworkedData(new ArrayList())), player);
}
}
ticker++;
}
ticker++;
}
@Override

View file

@ -14,7 +14,7 @@ import mekanism.common.block.BlockMachine.MachineType;
import mekanism.common.network.PacketTileEntity;
import mekanism.common.transporter.InvStack;
import mekanism.common.transporter.TransporterFilter;
import mekanism.common.transporter.TransporterStack;
import mekanism.common.util.InventoryUtils;
import mekanism.common.util.MekanismUtils;
import mekanism.common.util.TransporterUtils;
import net.minecraft.entity.player.EntityPlayer;
@ -104,7 +104,7 @@ public class TileEntityLogisticalSorter extends TileEntityElectricBlock implemen
if(!hasFilter && autoEject)
{
inInventory = TransporterUtils.takeTopItem(inventory, ForgeDirection.getOrientation(facing).getOpposite().ordinal());
inInventory = InventoryUtils.takeTopItem(inventory, ForgeDirection.getOrientation(facing).getOpposite().ordinal());
}
if(inInventory != null && inInventory.getStack() != null)
@ -391,7 +391,7 @@ public class TileEntityLogisticalSorter extends TileEntityElectricBlock implemen
if(back instanceof IInventory)
{
return TransporterUtils.putStackInInventory((IInventory)back, stack, ForgeDirection.getOrientation(facing).getOpposite().ordinal(), true);
return InventoryUtils.putStackInInventory((IInventory)back, stack, ForgeDirection.getOrientation(facing).getOpposite().ordinal(), true);
}
return stack;

View file

@ -14,6 +14,7 @@ import mekanism.common.network.PacketDataRequest;
import mekanism.common.network.PacketTileEntity;
import mekanism.common.transporter.TransporterStack;
import mekanism.common.transporter.TransporterStack.Path;
import mekanism.common.util.InventoryUtils;
import mekanism.common.util.MekanismUtils;
import mekanism.common.util.TransporterUtils;
import net.minecraft.inventory.IInventory;
@ -104,7 +105,7 @@ public class TileEntityLogisticalTransporter extends TileEntity implements ITile
if(inventory != null)
{
ItemStack rejected = TransporterUtils.putStackInInventory(inventory, stack.itemStack, stack.getSide(this), stack.pathType == Path.HOME);
ItemStack rejected = InventoryUtils.putStackInInventory(inventory, stack.itemStack, stack.getSide(this), stack.pathType == Path.HOME);
if(rejected == null)
{

View file

@ -2,14 +2,14 @@ package mekanism.common.transporter;
import java.util.ArrayList;
import com.google.common.io.ByteArrayDataInput;
import mekanism.common.util.TransporterUtils;
import mekanism.common.util.InventoryUtils;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.ForgeDirection;
import com.google.common.io.ByteArrayDataInput;
public class ItemStackFilter extends TransporterFilter
{
public boolean sizeMode;
@ -40,10 +40,10 @@ public class ItemStackFilter extends TransporterFilter
{
if(sizeMode)
{
return TransporterUtils.takeDefinedItem(inv, side.ordinal(), itemType, min, max);
return InventoryUtils.takeDefinedItem(inv, side.ordinal(), itemType, min, max);
}
else {
return TransporterUtils.takeTopItem(inv, side.ordinal());
return InventoryUtils.takeTopItem(inv, side.ordinal());
}
}

View file

@ -2,15 +2,15 @@ package mekanism.common.transporter;
import java.util.ArrayList;
import com.google.common.io.ByteArrayDataInput;
import mekanism.common.util.InventoryUtils;
import mekanism.common.util.MekanismUtils;
import mekanism.common.util.TransporterUtils;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.ForgeDirection;
import com.google.common.io.ByteArrayDataInput;
public class OreDictFilter extends TransporterFilter
{
public String oreDictName;
@ -57,7 +57,7 @@ public class OreDictFilter extends TransporterFilter
@Override
public InvStack getStackFromInventory(IInventory inv, ForgeDirection side)
{
return TransporterUtils.takeTopItem(inv, side.ordinal());
return InventoryUtils.takeTopItem(inv, side.ordinal());
}
@Override

View file

@ -0,0 +1,335 @@
package mekanism.common.util;
import mekanism.common.tileentity.TileEntityBin;
import mekanism.common.tileentity.TileEntityLogisticalSorter;
import mekanism.common.transporter.InvStack;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.inventory.InventoryLargeChest;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntityChest;
import net.minecraftforge.common.ForgeDirection;
public final class InventoryUtils
{
public static IInventory checkChestInv(IInventory inv)
{
if(inv instanceof TileEntityChest)
{
TileEntityChest main = (TileEntityChest)inv;
TileEntityChest adj = null;
if(main.adjacentChestXNeg != null)
{
adj = main.adjacentChestXNeg;
}
else if(main.adjacentChestXPos != null)
{
adj = main.adjacentChestXPos;
}
else if(main.adjacentChestZNeg != null)
{
adj = main.adjacentChestZNeg;
}
else if(main.adjacentChestZPosition != null)
{
adj = main.adjacentChestZPosition;
}
if(adj != null)
{
return new InventoryLargeChest("", main, adj);
}
}
return inv;
}
public static ItemStack putStackInInventory(IInventory inventory, ItemStack itemStack, int side, boolean force)
{
if(force && inventory instanceof TileEntityLogisticalSorter)
{
return ((TileEntityLogisticalSorter)inventory).sendHome(itemStack.copy());
}
ItemStack toInsert = itemStack.copy();
if(!(inventory instanceof ISidedInventory))
{
inventory = checkChestInv(inventory);
for(int i = 0; i <= inventory.getSizeInventory() - 1; i++)
{
if(!force)
{
if(!inventory.isItemValidForSlot(i, toInsert))
{
continue;
}
}
ItemStack inSlot = inventory.getStackInSlot(i);
if(inSlot == null)
{
inventory.setInventorySlotContents(i, toInsert);
return null;
}
else if(inSlot.isItemEqual(toInsert) && inSlot.stackSize < inSlot.getMaxStackSize())
{
if(inSlot.stackSize + toInsert.stackSize <= inSlot.getMaxStackSize())
{
ItemStack toSet = toInsert.copy();
toSet.stackSize += inSlot.stackSize;
inventory.setInventorySlotContents(i, toSet);
return null;
}
else {
int rejects = (inSlot.stackSize + toInsert.stackSize) - inSlot.getMaxStackSize();
ItemStack toSet = toInsert.copy();
toSet.stackSize = inSlot.getMaxStackSize();
ItemStack remains = toInsert.copy();
remains.stackSize = rejects;
inventory.setInventorySlotContents(i, toSet);
toInsert = remains;
}
}
}
}
else {
ISidedInventory sidedInventory = (ISidedInventory)inventory;
int[] slots = sidedInventory.getAccessibleSlotsFromSide(ForgeDirection.getOrientation(side).getOpposite().ordinal());
if(slots != null && slots.length != 0)
{
if(force && sidedInventory instanceof TileEntityBin && ForgeDirection.getOrientation(side).getOpposite().ordinal() == 0)
{
slots = sidedInventory.getAccessibleSlotsFromSide(1);
}
for(int get = 0; get <= slots.length - 1; get++)
{
int slotID = slots[get];
if(!force)
{
if(!sidedInventory.isItemValidForSlot(slotID, toInsert) && !sidedInventory.canInsertItem(slotID, toInsert, ForgeDirection.getOrientation(side).getOpposite().ordinal()))
{
continue;
}
}
ItemStack inSlot = inventory.getStackInSlot(slotID);
if(inSlot == null)
{
inventory.setInventorySlotContents(slotID, toInsert);
return null;
}
else if(inSlot.isItemEqual(toInsert) && inSlot.stackSize < inSlot.getMaxStackSize())
{
if(inSlot.stackSize + toInsert.stackSize <= inSlot.getMaxStackSize())
{
ItemStack toSet = toInsert.copy();
toSet.stackSize += inSlot.stackSize;
inventory.setInventorySlotContents(slotID, toSet);
return null;
}
else {
int rejects = (inSlot.stackSize + toInsert.stackSize) - inSlot.getMaxStackSize();
ItemStack toSet = toInsert.copy();
toSet.stackSize = inSlot.getMaxStackSize();
ItemStack remains = toInsert.copy();
remains.stackSize = rejects;
inventory.setInventorySlotContents(slotID, toSet);
toInsert = remains;
}
}
}
}
}
return toInsert;
}
public static ItemStack takeTopItemFromInventory(IInventory inventory, int side)
{
if(!(inventory instanceof ISidedInventory))
{
for(int i = inventory.getSizeInventory() - 1; i >= 0; i--)
{
if(inventory.getStackInSlot(i) != null)
{
ItemStack toSend = inventory.getStackInSlot(i).copy();
toSend.stackSize = 1;
inventory.decrStackSize(i, 1);
return toSend;
}
}
}
else {
ISidedInventory sidedInventory = (ISidedInventory) inventory;
int[] slots = sidedInventory.getAccessibleSlotsFromSide(side);
if(slots != null)
{
for(int get = slots.length - 1; get >= 0; get--)
{
int slotID = slots[get];
if(sidedInventory.getStackInSlot(slotID) != null)
{
ItemStack toSend = sidedInventory.getStackInSlot(slotID);
toSend.stackSize = 1;
if(sidedInventory.canExtractItem(slotID, toSend, side))
{
sidedInventory.decrStackSize(slotID, 1);
return toSend;
}
}
}
}
}
return null;
}
public static InvStack takeDefinedItem(IInventory inventory, int side, ItemStack type, int min, int max)
{
InvStack ret = new InvStack(inventory);
if(!(inventory instanceof ISidedInventory))
{
inventory = checkChestInv(inventory);
for(int i = inventory.getSizeInventory() - 1; i >= 0; i--)
{
if(inventory.getStackInSlot(i) != null && inventory.getStackInSlot(i).isItemEqual(type))
{
ItemStack stack = inventory.getStackInSlot(i);
int current = ret.getStack() != null ? ret.getStack().stackSize : 0;
if(current+stack.stackSize <= max)
{
ret.appendStack(i, stack.copy());
}
else {
ItemStack copy = stack.copy();
copy.stackSize = max-current;
ret.appendStack(i, copy);
}
if(ret.getStack() != null && ret.getStack().stackSize == max)
{
return ret;
}
}
}
}
else {
ISidedInventory sidedInventory = (ISidedInventory)inventory;
int[] slots = sidedInventory.getAccessibleSlotsFromSide(ForgeDirection.getOrientation(side).getOpposite().ordinal());
if(slots != null && slots.length != 0)
{
for(int get = slots.length - 1; get >= 0; get--)
{
int slotID = slots[get];
if(sidedInventory.getStackInSlot(slotID) != null && inventory.getStackInSlot(slotID).isItemEqual(type))
{
ItemStack stack = sidedInventory.getStackInSlot(slotID);
int current = ret.getStack() != null ? ret.getStack().stackSize : 0;
if(current+stack.stackSize <= max)
{
ItemStack copy = stack.copy();
if(sidedInventory.canExtractItem(slotID, copy, ForgeDirection.getOrientation(side).getOpposite().ordinal()))
{
ret.appendStack(slotID, copy);
}
}
else {
ItemStack copy = stack.copy();
if(sidedInventory.canExtractItem(slotID, copy, ForgeDirection.getOrientation(side).getOpposite().ordinal()))
{
copy.stackSize = max-current;
ret.appendStack(slotID, copy);
}
}
if(ret.getStack() != null && ret.getStack().stackSize == max)
{
return ret;
}
}
}
}
}
if(ret != null && ret.getStack() != null && ret.getStack().stackSize >= min)
{
return ret;
}
return null;
}
public static InvStack takeTopItem(IInventory inventory, int side)
{
if(!(inventory instanceof ISidedInventory))
{
inventory = checkChestInv(inventory);
for(int i = inventory.getSizeInventory() - 1; i >= 0; i--)
{
if(inventory.getStackInSlot(i) != null)
{
ItemStack toSend = inventory.getStackInSlot(i).copy();
return new InvStack(inventory, i, toSend);
}
}
}
else {
ISidedInventory sidedInventory = (ISidedInventory)inventory;
int[] slots = sidedInventory.getAccessibleSlotsFromSide(ForgeDirection.getOrientation(side).getOpposite().ordinal());
if(slots != null && slots.length != 0)
{
for(int get = slots.length - 1; get >= 0; get--)
{
int slotID = slots[get];
if(sidedInventory.getStackInSlot(slotID) != null)
{
ItemStack toSend = sidedInventory.getStackInSlot(slotID);
if(sidedInventory.canExtractItem(slotID, toSend, ForgeDirection.getOrientation(side).getOpposite().ordinal()))
{
return new InvStack(inventory, slotID, toSend);
}
}
}
}
}
return null;
}
}

View file

@ -41,6 +41,7 @@ import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemDye;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.item.crafting.IRecipe;

View file

@ -10,15 +10,12 @@ import mekanism.api.transmitters.ITransmitter;
import mekanism.common.tileentity.TileEntityBin;
import mekanism.common.tileentity.TileEntityLogisticalSorter;
import mekanism.common.tileentity.TileEntityLogisticalTransporter;
import mekanism.common.transporter.InvStack;
import mekanism.common.transporter.TransporterStack;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.inventory.InventoryLargeChest;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityChest;
import net.minecraftforge.common.ForgeDirection;
import buildcraft.api.power.IPowerReceptor;
import buildcraft.api.power.PowerHandler.Type;
@ -196,7 +193,7 @@ public final class TransporterUtils
if(!(inventory instanceof ISidedInventory))
{
inventory = checkChestInv(inventory);
inventory = InventoryUtils.checkChestInv(inventory);
for(int i = 0; i <= inventory.getSizeInventory() - 1; i++)
{
@ -282,281 +279,7 @@ public final class TransporterUtils
return false;
}
public static IInventory checkChestInv(IInventory inv)
{
if(inv instanceof TileEntityChest)
{
TileEntityChest main = (TileEntityChest)inv;
TileEntityChest adj = null;
if(main.adjacentChestXNeg != null)
{
adj = main.adjacentChestXNeg;
}
else if(main.adjacentChestXPos != null)
{
adj = main.adjacentChestXPos;
}
else if(main.adjacentChestZNeg != null)
{
adj = main.adjacentChestZNeg;
}
else if(main.adjacentChestZPosition != null)
{
adj = main.adjacentChestZPosition;
}
if(adj != null)
{
return new InventoryLargeChest("", main, adj);
}
}
return inv;
}
public static ItemStack putStackInInventory(IInventory inventory, ItemStack itemStack, int side, boolean force)
{
if(force && inventory instanceof TileEntityLogisticalSorter)
{
return ((TileEntityLogisticalSorter)inventory).sendHome(itemStack.copy());
}
ItemStack toInsert = itemStack.copy();
if(!(inventory instanceof ISidedInventory))
{
inventory = checkChestInv(inventory);
for(int i = 0; i <= inventory.getSizeInventory() - 1; i++)
{
if(!force)
{
if(!inventory.isItemValidForSlot(i, toInsert))
{
continue;
}
}
ItemStack inSlot = inventory.getStackInSlot(i);
if(inSlot == null)
{
inventory.setInventorySlotContents(i, toInsert);
return null;
}
else if(inSlot.isItemEqual(toInsert) && inSlot.stackSize < inSlot.getMaxStackSize())
{
if(inSlot.stackSize + toInsert.stackSize <= inSlot.getMaxStackSize())
{
ItemStack toSet = toInsert.copy();
toSet.stackSize += inSlot.stackSize;
inventory.setInventorySlotContents(i, toSet);
return null;
}
else {
int rejects = (inSlot.stackSize + toInsert.stackSize) - inSlot.getMaxStackSize();
ItemStack toSet = toInsert.copy();
toSet.stackSize = inSlot.getMaxStackSize();
ItemStack remains = toInsert.copy();
remains.stackSize = rejects;
inventory.setInventorySlotContents(i, toSet);
toInsert = remains;
}
}
}
}
else {
ISidedInventory sidedInventory = (ISidedInventory)inventory;
int[] slots = sidedInventory.getAccessibleSlotsFromSide(ForgeDirection.getOrientation(side).getOpposite().ordinal());
if(slots != null && slots.length != 0)
{
if(force && sidedInventory instanceof TileEntityBin && ForgeDirection.getOrientation(side).getOpposite().ordinal() == 0)
{
slots = sidedInventory.getAccessibleSlotsFromSide(1);
}
for(int get = 0; get <= slots.length - 1; get++)
{
int slotID = slots[get];
if(!force)
{
if(!sidedInventory.isItemValidForSlot(slotID, toInsert) && !sidedInventory.canInsertItem(slotID, toInsert, ForgeDirection.getOrientation(side).getOpposite().ordinal()))
{
continue;
}
}
ItemStack inSlot = inventory.getStackInSlot(slotID);
if(inSlot == null)
{
inventory.setInventorySlotContents(slotID, toInsert);
return null;
}
else if(inSlot.isItemEqual(toInsert) && inSlot.stackSize < inSlot.getMaxStackSize())
{
if(inSlot.stackSize + toInsert.stackSize <= inSlot.getMaxStackSize())
{
ItemStack toSet = toInsert.copy();
toSet.stackSize += inSlot.stackSize;
inventory.setInventorySlotContents(slotID, toSet);
return null;
}
else {
int rejects = (inSlot.stackSize + toInsert.stackSize) - inSlot.getMaxStackSize();
ItemStack toSet = toInsert.copy();
toSet.stackSize = inSlot.getMaxStackSize();
ItemStack remains = toInsert.copy();
remains.stackSize = rejects;
inventory.setInventorySlotContents(slotID, toSet);
toInsert = remains;
}
}
}
}
}
return toInsert;
}
public static InvStack takeDefinedItem(IInventory inventory, int side, ItemStack type, int min, int max)
{
InvStack ret = new InvStack(inventory);
if(!(inventory instanceof ISidedInventory))
{
inventory = checkChestInv(inventory);
for(int i = inventory.getSizeInventory() - 1; i >= 0; i--)
{
if(inventory.getStackInSlot(i) != null && inventory.getStackInSlot(i).isItemEqual(type))
{
ItemStack stack = inventory.getStackInSlot(i);
int current = ret.getStack() != null ? ret.getStack().stackSize : 0;
if(current+stack.stackSize <= max)
{
ret.appendStack(i, stack.copy());
}
else {
ItemStack copy = stack.copy();
copy.stackSize = max-current;
ret.appendStack(i, copy);
}
if(ret.getStack() != null && ret.getStack().stackSize == max)
{
return ret;
}
}
}
}
else {
ISidedInventory sidedInventory = (ISidedInventory)inventory;
int[] slots = sidedInventory.getAccessibleSlotsFromSide(ForgeDirection.getOrientation(side).getOpposite().ordinal());
if(slots != null && slots.length != 0)
{
for(int get = slots.length - 1; get >= 0; get--)
{
int slotID = slots[get];
if(sidedInventory.getStackInSlot(slotID) != null && inventory.getStackInSlot(slotID).isItemEqual(type))
{
ItemStack stack = sidedInventory.getStackInSlot(slotID);
int current = ret.getStack() != null ? ret.getStack().stackSize : 0;
if(current+stack.stackSize <= max)
{
ItemStack copy = stack.copy();
if(sidedInventory.canExtractItem(slotID, copy, ForgeDirection.getOrientation(side).getOpposite().ordinal()))
{
ret.appendStack(slotID, copy);
}
}
else {
ItemStack copy = stack.copy();
if(sidedInventory.canExtractItem(slotID, copy, ForgeDirection.getOrientation(side).getOpposite().ordinal()))
{
copy.stackSize = max-current;
ret.appendStack(slotID, copy);
}
}
if(ret.getStack() != null && ret.getStack().stackSize == max)
{
return ret;
}
}
}
}
}
if(ret != null && ret.getStack() != null && ret.getStack().stackSize >= min)
{
return ret;
}
return null;
}
public static InvStack takeTopItem(IInventory inventory, int side)
{
if(!(inventory instanceof ISidedInventory))
{
inventory = checkChestInv(inventory);
for(int i = inventory.getSizeInventory() - 1; i >= 0; i--)
{
if(inventory.getStackInSlot(i) != null)
{
ItemStack toSend = inventory.getStackInSlot(i).copy();
return new InvStack(inventory, i, toSend);
}
}
}
else {
ISidedInventory sidedInventory = (ISidedInventory)inventory;
int[] slots = sidedInventory.getAccessibleSlotsFromSide(ForgeDirection.getOrientation(side).getOpposite().ordinal());
if(slots != null && slots.length != 0)
{
for(int get = slots.length - 1; get >= 0; get--)
{
int slotID = slots[get];
if(sidedInventory.getStackInSlot(slotID) != null)
{
ItemStack toSend = sidedInventory.getStackInSlot(slotID);
if(sidedInventory.canExtractItem(slotID, toSend, ForgeDirection.getOrientation(side).getOpposite().ordinal()))
{
return new InvStack(inventory, slotID, toSend);
}
}
}
}
}
return null;
}
public static EnumColor increment(EnumColor color)
public static EnumColor increment(EnumColor color)
{
if(color == null)
{

View file

@ -337,13 +337,13 @@ public class ItemBlockGenerator extends ItemBlock implements IEnergizedItem, IIt
@Override
public int receiveEnergy(ItemStack theItem, int energy, boolean doReceive)
{
return (int)(recharge(theItem, (int)((energy*Mekanism.FROM_TE)*Mekanism.TO_UE), doReceive)*Mekanism.TO_TE);
return (int)(recharge(theItem, (int)((energy*Mekanism.FROM_TE)*Mekanism.TO_UE), !doReceive)*Mekanism.TO_TE);
}
@Override
public int extractEnergy(ItemStack theItem, int energy, boolean doTransfer)
{
return (int)(discharge(theItem, (int)((energy*Mekanism.FROM_TE)*Mekanism.TO_UE), doTransfer)*Mekanism.TO_TE);
return (int)(discharge(theItem, (int)((energy*Mekanism.FROM_TE)*Mekanism.TO_UE), !doTransfer)*Mekanism.TO_TE);
}
@Override

View file

@ -0,0 +1,101 @@
package mekanism.induction.client;
import mekanism.induction.client.fx.FXElectricBolt;
import mekanism.induction.client.gui.GuiBattery;
import mekanism.induction.client.gui.GuiMultimeter;
import mekanism.induction.client.render.BlockRenderingHandler;
import mekanism.induction.client.render.RenderBattery;
import mekanism.induction.client.render.RenderEMContractor;
import mekanism.induction.client.render.RenderMultimeter;
import mekanism.induction.client.render.RenderTesla;
import mekanism.induction.client.render.RenderWire;
import mekanism.induction.common.InductionCommonProxy;
import mekanism.induction.common.battery.TileEntityBattery;
import mekanism.induction.common.contractor.TileEntityEMContractor;
import mekanism.induction.common.multimeter.TileEntityMultimeter;
import mekanism.induction.common.tesla.TileEntityTesla;
import mekanism.induction.common.wire.TileEntityWire;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import universalelectricity.core.vector.Vector3;
import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.client.registry.ClientRegistry;
import cpw.mods.fml.client.registry.RenderingRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
/**
* @author Calclavia
*
*/
@SideOnly(Side.CLIENT)
public class InductionClientProxy extends InductionCommonProxy
{
@Override
public void registerRenderers()
{
MinecraftForge.EVENT_BUS.register(SoundHandler.INSTANCE);
RenderingRegistry.registerBlockHandler(BlockRenderingHandler.INSTANCE);
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityTesla.class, new RenderTesla());
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityMultimeter.class, new RenderMultimeter());
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityEMContractor.class, new RenderEMContractor());
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityBattery.class, new RenderBattery());
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityWire.class, new RenderWire());
}
@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z)
{
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
if (tileEntity instanceof TileEntityMultimeter)
{
return new GuiMultimeter(player.inventory, ((TileEntityMultimeter) tileEntity));
}
else if (tileEntity instanceof TileEntityBattery)
{
return new GuiBattery(player.inventory, ((TileEntityBattery) tileEntity));
}
return null;
}
@Override
public boolean isPaused()
{
if (FMLClientHandler.instance().getClient().isSingleplayer() && !FMLClientHandler.instance().getClient().getIntegratedServer().getPublic())
{
GuiScreen screen = FMLClientHandler.instance().getClient().currentScreen;
if (screen != null)
{
if (screen.doesGuiPauseGame())
{
return true;
}
}
}
return false;
}
@Override
public boolean isFancy()
{
return FMLClientHandler.instance().getClient().gameSettings.fancyGraphics;
}
@Override
public void renderElectricShock(World world, Vector3 start, Vector3 target, float r, float g, float b, boolean split)
{
if (world.isRemote)
{
FMLClientHandler.instance().getClient().effectRenderer.addEffect(new FXElectricBolt(world, start, target, split).setColor(r, g, b));
}
}
}

View file

@ -0,0 +1,33 @@
/**
*
*/
package mekanism.induction.client;
import mekanism.induction.common.MekanismInduction;
import net.minecraftforge.client.event.sound.SoundLoadEvent;
import net.minecraftforge.event.ForgeSubscribe;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
/**
* @author Calclavia
*
*/
@SideOnly(Side.CLIENT)
public class SoundHandler
{
public static final SoundHandler INSTANCE = new SoundHandler();
public static final String[] SOUND_FILES = { "Shock1.ogg", "Shock2.ogg", "Shock3.ogg", "Shock4.ogg", "Shock5.ogg", "Shock6.ogg", "Shock7.ogg" };
@ForgeSubscribe
public void loadSoundEvents(SoundLoadEvent event)
{
for (int i = 0; i < SOUND_FILES.length; i++)
{
event.manager.addSound(MekanismInduction.PREFIX + SOUND_FILES[i]);
}
MekanismInduction.LOGGER.fine("Loaded sound fxs");
}
}

View file

@ -0,0 +1,458 @@
package mekanism.induction.client.fx;
import static org.lwjgl.opengl.GL11.GL_BLEND;
import static org.lwjgl.opengl.GL11.GL_ONE_MINUS_SRC_ALPHA;
import static org.lwjgl.opengl.GL11.GL_SMOOTH;
import static org.lwjgl.opengl.GL11.GL_SRC_ALPHA;
import static org.lwjgl.opengl.GL11.glBlendFunc;
import static org.lwjgl.opengl.GL11.glEnable;
import static org.lwjgl.opengl.GL11.glShadeModel;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Random;
import mekanism.induction.common.MekanismInduction;
import net.minecraft.client.Minecraft;
import net.minecraft.client.particle.EntityFX;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import org.lwjgl.opengl.GL11;
import universalelectricity.core.vector.Vector3;
import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
/**
* Electric shock Fxs.
*
* @author Calclavia
*
*/
@SideOnly(Side.CLIENT)
public class FXElectricBolt extends EntityFX
{
public static final ResourceLocation TEXTURE = new ResourceLocation(MekanismInduction.DOMAIN, MekanismInduction.MODEL_TEXTURE_DIRECTORY + "fadedSphere.png");
public static final ResourceLocation PARTICLE_RESOURCE = new ResourceLocation("textures/particle/particles.png");
/** The width of the electrical bolt. */
private float boltWidth;
/** The maximum length of the bolt */
public double boltLength;
/** Electric Bolt's start and end positions; */
private BoltPoint start;
private BoltPoint end;
/** An array of the segments of the bolt. */
private List<BoltSegment> segments = new ArrayList<BoltSegment>();
private final Map<Integer, Integer> parentIDMap = new HashMap<Integer, Integer>();
/** Determines how complex the bolt is. */
public float complexity;
public int segmentCount;
private int maxSplitID;
private Random rand;
public FXElectricBolt(World world, Vector3 startVec, Vector3 targetVec, boolean doSplits)
{
super(world, startVec.x, startVec.y, startVec.z);
this.rand = new Random();
this.start = new BoltPoint(startVec);
this.end = new BoltPoint(targetVec);
if (this.end.y == Double.POSITIVE_INFINITY)
{
this.end.y = Minecraft.getMinecraft().thePlayer.posY + 30;
}
/** By default, we do an electrical color */
this.segmentCount = 1;
this.particleMaxAge = (3 + this.rand.nextInt(3) - 1);
this.complexity = 2f;
this.boltWidth = 0.05f;
this.boltLength = this.start.distance(this.end);
this.setUp(doSplits);
}
public FXElectricBolt(World world, Vector3 startVec, Vector3 targetVec)
{
this(world, startVec, targetVec, true);
}
/**
* Calculate all required segments of the entire bolt.
*/
private void setUp(boolean doSplits)
{
this.segments.add(new BoltSegment(this.start, this.end));
this.recalculate();
if (doSplits)
{
double offsetRatio = this.boltLength * this.complexity;
this.split(2, offsetRatio / 10, 0.7f, 0.1f, 20 / 2);
this.split(2, offsetRatio / 15, 0.5f, 0.1f, 25 / 2);
this.split(2, offsetRatio / 25, 0.5f, 0.1f, 28 / 2);
this.split(2, offsetRatio / 38, 0.5f, 0.1f, 30 / 2);
this.split(2, offsetRatio / 55, 0, 0, 0);
this.split(2, offsetRatio / 70, 0, 0, 0);
this.recalculate();
Collections.sort(this.segments, new Comparator()
{
public int compare(BoltSegment bolt1, BoltSegment bolt2)
{
return Float.compare(bolt2.alpha, bolt1.alpha);
}
@Override
public int compare(Object obj1, Object obj2)
{
return compare((BoltSegment) obj1, (BoltSegment) obj2);
}
});
}
}
public FXElectricBolt setColor(float r, float g, float b)
{
this.particleRed = r + (this.rand.nextFloat() * 0.1f) - 0.1f;
this.particleGreen = g + (this.rand.nextFloat() * 0.1f) - 0.1f;
this.particleBlue = b + (this.rand.nextFloat() * 0.1f) - 0.1f;
return this;
}
/**
* Slits a large segment into multiple smaller ones.
*
* @param splitAmount - The amount of splits
* @param offset - The multiplier scale for the offset.
* @param splitChance - The chance of creating a split.
* @param splitLength - The length of each split.
* @param splitAngle - The angle of the split.
*/
public void split(int splitAmount, double offset, float splitChance, float splitLength, float splitAngle)
{
/** Temporarily store old segments in a new array */
List<BoltSegment> oldSegments = this.segments;
this.segments = new ArrayList();
/** Previous segment */
BoltSegment prev = null;
for (BoltSegment segment : oldSegments)
{
prev = segment.prev;
/** Length of each subsegment */
Vector3 subSegment = segment.difference.clone().scale(1.0F / splitAmount);
/**
* Creates an array of new bolt points. The first and last points of the bolts are the
* respected start and end points of the current segment.
*/
BoltPoint[] newPoints = new BoltPoint[splitAmount + 1];
Vector3 startPoint = segment.start;
newPoints[0] = segment.start;
newPoints[splitAmount] = segment.end;
/**
* Create bolt points.
*/
for (int i = 1; i < splitAmount; i++)
{
Vector3 newOffset = segment.difference.getPerpendicular().rotate(this.rand.nextFloat() * 360, segment.difference).scale((this.rand.nextFloat() - 0.5F) * offset);
Vector3 basePoint = startPoint.clone().translate(subSegment.clone().scale(i));
newPoints[i] = new BoltPoint(basePoint, newOffset);
}
for (int i = 0; i < splitAmount; i++)
{
BoltSegment next = new BoltSegment(newPoints[i], newPoints[(i + 1)], segment.alpha, segment.id * splitAmount + i, segment.splitID);
next.prev = prev;
if (prev != null)
{
prev.next = next;
}
if ((i != 0) && (this.rand.nextFloat() < splitChance))
{
Vector3 splitrot = next.difference.xCrossProduct().rotate(this.rand.nextFloat() * 360, next.difference);
Vector3 diff = next.difference.clone().rotate((this.rand.nextFloat() * 0.66F + 0.33F) * splitAngle, splitrot).scale(splitLength);
this.maxSplitID += 1;
this.parentIDMap.put(this.maxSplitID, next.splitID);
BoltSegment split = new BoltSegment(newPoints[i], new BoltPoint(newPoints[(i + 1)].base, newPoints[(i + 1)].offset.clone().translate(diff)), segment.alpha / 2f, next.id, this.maxSplitID);
split.prev = prev;
this.segments.add(split);
}
prev = next;
this.segments.add(next);
}
if (segment.next != null)
{
segment.next.prev = prev;
}
}
this.segmentCount *= splitAmount;
}
private void recalculate()
{
HashMap<Integer, Integer> lastActiveSegment = new HashMap<Integer, Integer>();
Collections.sort(this.segments, new Comparator()
{
public int compare(BoltSegment o1, BoltSegment o2)
{
int comp = Integer.valueOf(o1.splitID).compareTo(Integer.valueOf(o2.splitID));
if (comp == 0)
{
return Integer.valueOf(o1.id).compareTo(Integer.valueOf(o2.id));
}
return comp;
}
@Override
public int compare(Object obj, Object obj1)
{
return compare((BoltSegment) obj, (BoltSegment) obj1);
}
});
int lastSplitCalc = 0;
int lastActiveSeg = 0;
for (BoltSegment segment : this.segments)
{
if (segment.splitID > lastSplitCalc)
{
lastActiveSegment.put(lastSplitCalc, lastActiveSeg);
lastSplitCalc = segment.splitID;
lastActiveSeg = lastActiveSegment.get(this.parentIDMap.get(segment.splitID)).intValue();
}
lastActiveSeg = segment.id;
}
lastActiveSegment.put(lastSplitCalc, lastActiveSeg);
lastSplitCalc = 0;
lastActiveSeg = lastActiveSegment.get(0).intValue();
BoltSegment segment;
for (Iterator<BoltSegment> iterator = this.segments.iterator(); iterator.hasNext(); segment.recalculate())
{
segment = iterator.next();
if (lastSplitCalc != segment.splitID)
{
lastSplitCalc = segment.splitID;
lastActiveSeg = lastActiveSegment.get(segment.splitID);
}
if (segment.id > lastActiveSeg)
{
iterator.remove();
}
}
}
@Override
public void onUpdate()
{
this.prevPosX = this.posX;
this.prevPosY = this.posY;
this.prevPosZ = this.posZ;
if (this.particleAge++ >= this.particleMaxAge)
{
this.setDead();
}
}
@Override
public void renderParticle(Tessellator tessellator, float partialframe, float cosYaw, float cosPitch, float sinYaw, float sinSinPitch, float cosSinPitch)
{
EntityPlayer player = Minecraft.getMinecraft().thePlayer;
tessellator.draw();
GL11.glPushMatrix();
GL11.glDepthMask(false);
GL11.glEnable(3042);
glShadeModel(GL_SMOOTH);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
FMLClientHandler.instance().getClient().renderEngine.bindTexture(TEXTURE);
/**
* Render the actual bolts.
*/
tessellator.startDrawingQuads();
tessellator.setBrightness(15728880);
Vector3 playerVector = new Vector3(sinYaw * -cosPitch, -cosSinPitch / cosYaw, cosYaw * cosPitch);
int renderlength = (int) ((this.particleAge + partialframe + (int) (this.boltLength * 3.0F)) / (int) (this.boltLength * 3.0F) * this.segmentCount);
for (BoltSegment segment : this.segments)
{
if (segment != null && segment.id <= renderlength)
{
double renderWidth = this.boltWidth * ((new Vector3(player).distance(segment.start) / 5f + 1f) * (1 + segment.alpha) * 0.5f);
renderWidth = Math.min(this.boltWidth, Math.max(renderWidth, 0));
if (segment.difference.getMagnitude() > 0 && segment.difference.getMagnitude() != Double.NaN && segment.difference.getMagnitude() != Double.POSITIVE_INFINITY && renderWidth > 0 && renderWidth != Double.NaN && renderWidth != Double.POSITIVE_INFINITY)
{
Vector3 diffPrev = playerVector.crossProduct(segment.prevDiff).scale(renderWidth / segment.sinPrev);
Vector3 diffNext = playerVector.crossProduct(segment.nextDiff).scale(renderWidth / segment.sinNext);
Vector3 startVec = segment.start;
Vector3 endVec = segment.end;
float rx1 = (float) (startVec.x - interpPosX);
float ry1 = (float) (startVec.y - interpPosY);
float rz1 = (float) (startVec.z - interpPosZ);
float rx2 = (float) (endVec.x - interpPosX);
float ry2 = (float) (endVec.y - interpPosY);
float rz2 = (float) (endVec.z - interpPosZ);
tessellator.setColorRGBA_F(this.particleRed, this.particleGreen, this.particleBlue, (1.0F - (this.particleAge >= 0 ? ((float) this.particleAge / (float) this.particleMaxAge) : 0.0F) * 0.6f) * segment.alpha);
tessellator.addVertexWithUV(rx2 - diffNext.x, ry2 - diffNext.y, rz2 - diffNext.z, 0.5D, 0.0D);
tessellator.addVertexWithUV(rx1 - diffPrev.x, ry1 - diffPrev.y, rz1 - diffPrev.z, 0.5D, 0.0D);
tessellator.addVertexWithUV(rx1 + diffPrev.x, ry1 + diffPrev.y, rz1 + diffPrev.z, 0.5D, 1.0D);
tessellator.addVertexWithUV(rx2 + diffNext.x, ry2 + diffNext.y, rz2 + diffNext.z, 0.5D, 1.0D);
/**
* Render the bolts balls.
*/
if (segment.next == null)
{
Vector3 roundEnd = segment.end.clone().translate(segment.difference.clone().normalize().scale(renderWidth));
float rx3 = (float) (roundEnd.x - interpPosX);
float ry3 = (float) (roundEnd.y - interpPosY);
float rz3 = (float) (roundEnd.z - interpPosZ);
tessellator.addVertexWithUV(rx3 - diffNext.x, ry3 - diffNext.y, rz3 - diffNext.z, 0.0D, 0.0D);
tessellator.addVertexWithUV(rx2 - diffNext.x, ry2 - diffNext.y, rz2 - diffNext.z, 0.5D, 0.0D);
tessellator.addVertexWithUV(rx2 + diffNext.x, ry2 + diffNext.y, rz2 + diffNext.z, 0.5D, 1.0D);
tessellator.addVertexWithUV(rx3 + diffNext.x, ry3 + diffNext.y, rz3 + diffNext.z, 0.0D, 1.0D);
}
if (segment.prev == null)
{
Vector3 roundEnd = segment.start.clone().difference(segment.difference.clone().normalize().scale(renderWidth));
float rx3 = (float) (roundEnd.x - interpPosX);
float ry3 = (float) (roundEnd.y - interpPosY);
float rz3 = (float) (roundEnd.z - interpPosZ);
tessellator.addVertexWithUV(rx1 - diffPrev.x, ry1 - diffPrev.y, rz1 - diffPrev.z, 0.5D, 0.0D);
tessellator.addVertexWithUV(rx3 - diffPrev.x, ry3 - diffPrev.y, rz3 - diffPrev.z, 0.0D, 0.0D);
tessellator.addVertexWithUV(rx3 + diffPrev.x, ry3 + diffPrev.y, rz3 + diffPrev.z, 0.0D, 1.0D);
tessellator.addVertexWithUV(rx1 + diffPrev.x, ry1 + diffPrev.y, rz1 + diffPrev.z, 0.5D, 1.0D);
}
}
}
}
tessellator.draw();
GL11.glDisable(3042);
GL11.glDepthMask(true);
GL11.glPopMatrix();
FMLClientHandler.instance().getClient().renderEngine.bindTexture(PARTICLE_RESOURCE);
tessellator.startDrawingQuads();
}
private class BoltPoint extends Vector3
{
public Vector3 base;
public Vector3 offset;
public BoltPoint(Vector3 base, Vector3 offset)
{
super(base.clone().translate(offset));
this.base = base;
this.offset = offset;
}
public BoltPoint(Vector3 base)
{
this(base, new Vector3());
}
}
private class BoltSegment
{
public BoltPoint start;
public BoltPoint end;
public BoltSegment prev;
public BoltSegment next;
public float alpha;
public int id;
public int splitID;
/**
* All differences are cached.
*/
public Vector3 difference;
public Vector3 prevDiff;
public Vector3 nextDiff;
public double sinPrev;
public double sinNext;
public BoltSegment(BoltPoint start, BoltPoint end)
{
this(start, end, 1, 0, 0);
}
public BoltSegment(BoltPoint start, BoltPoint end, float alpha, int id, int splitID)
{
this.start = start;
this.end = end;
this.alpha = alpha;
this.id = id;
this.splitID = splitID;
this.difference = this.end.clone().difference(this.start);
}
public void recalculate()
{
if (this.prev != null)
{
Vector3 prevDiffNorm = this.prev.difference.clone().normalize();
Vector3 diffNorm = this.difference.clone().normalize();
this.prevDiff = diffNorm.clone().translate(prevDiffNorm).normalize();
this.sinPrev = Math.sin(diffNorm.anglePreNorm(prevDiffNorm.clone().scale(-1)) / 2);
}
else
{
this.prevDiff = this.difference.clone().normalize();
this.sinPrev = 1;
}
if (this.next != null)
{
Vector3 nextDiffNorm = this.next.difference.clone().normalize();
Vector3 diffNorm = this.difference.clone().normalize();
this.nextDiff = diffNorm.clone().translate(nextDiffNorm).normalize();
this.sinNext = Math.sin(diffNorm.anglePreNorm(nextDiffNorm.clone().scale(-1)) / 2);
}
else
{
this.nextDiff = this.difference.clone().normalize();
this.sinNext = 1;
}
}
}
}

View file

@ -0,0 +1,59 @@
package mekanism.induction.client.gui;
import mekanism.induction.common.MekanismInduction;
import mekanism.induction.common.battery.ContainerBattery;
import mekanism.induction.common.battery.TileEntityBattery;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector;
import org.lwjgl.opengl.GL11;
import universalelectricity.core.electricity.ElectricityDisplay;
import universalelectricity.core.electricity.ElectricityDisplay.ElectricUnit;
public class GuiBattery extends GuiContainer
{
private static final ResourceLocation TEXTURE = new ResourceLocation(MekanismInduction.DOMAIN, MekanismInduction.GUI_DIRECTORY + "batterybox_gui.png");
public TileEntityBattery tileEntity;
public GuiBattery(InventoryPlayer inventory, TileEntityBattery tentity)
{
super(new ContainerBattery(inventory, tentity));
tileEntity = tentity;
ySize += 41;
}
@Override
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY)
{
int xAxis = (mouseX - (width - xSize) / 2);
int yAxis = (mouseY - (height - ySize) / 2);
fontRenderer.drawString("Battery", 43, 6, 0x404040);
fontRenderer.drawString(StatCollector.translateToLocal("container.inventory"), 8, ySize - 96 + 2, 0x404040);
fontRenderer.drawString("Cells: " + tileEntity.clientCells + " / " + tileEntity.structure.getMaxCells(), 62, 23, 0x404040);
fontRenderer.drawString("Energy: ", 62, 33, 0x404040);
fontRenderer.drawString(ElectricityDisplay.getDisplay(this.tileEntity.getEnergyStored(), ElectricUnit.JOULES, 4, true), 62, 43, 0x404040);
fontRenderer.drawString("Max: " + ElectricityDisplay.getDisplayShort(this.tileEntity.getMaxEnergyStored(), ElectricUnit.JOULES), 62, 53, 0x404040);
fontRenderer.drawString("Percentage: " + (int) (this.tileEntity.getEnergyStored() / this.tileEntity.getMaxEnergyStored() * 100) + "%", 62, 63, 0x404040);
fontRenderer.drawString("Volume: " + tileEntity.structure.getVolume(), 62, 73, 0x404040);
}
@Override
protected void drawGuiContainerBackgroundLayer(float par1, int mouseX, int mouseY)
{
mc.renderEngine.bindTexture(TEXTURE);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
int guiWidth = (width - xSize) / 2;
int guiHeight = (height - ySize) / 2;
drawTexturedModalRect(guiWidth, guiHeight, 0, 0, xSize, ySize);
int xAxis = (mouseX - (width - xSize) / 2);
int yAxis = (mouseY - (height - ySize) / 2);
int scale = (int) ((tileEntity.getEnergyStored() / tileEntity.getMaxEnergyStored()) * 105);
drawTexturedModalRect(guiWidth + 61, guiHeight + 102, 0, 207, scale, 12);
}
}

View file

@ -0,0 +1,122 @@
/**
*
*/
package mekanism.induction.client.gui;
import java.util.ArrayList;
import mekanism.api.Object3D;
import mekanism.common.PacketHandler;
import mekanism.common.PacketHandler.Transmission;
import mekanism.common.network.PacketTileEntity;
import mekanism.induction.common.MekanismInduction;
import mekanism.induction.common.multimeter.ContainerMultimeter;
import mekanism.induction.common.multimeter.TileEntityMultimeter;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiTextField;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.GL11;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
/**
* Multimeter GUI
*
* @author Calclavia
*
*/
@SideOnly(Side.CLIENT)
public class GuiMultimeter extends GuiContainer
{
private static final ResourceLocation TEXTURE = new ResourceLocation(MekanismInduction.DOMAIN, MekanismInduction.GUI_DIRECTORY + "gui_multimeter.png");
TileEntityMultimeter tileEntity;
private int containerWidth;
private int containerHeight;
private GuiTextField textFieldLimit;
public GuiMultimeter(InventoryPlayer inventoryPlayer, TileEntityMultimeter tileEntity)
{
super(new ContainerMultimeter(inventoryPlayer, tileEntity));
this.tileEntity = tileEntity;
this.ySize = 217;
}
@Override
public void initGui()
{
super.initGui();
this.buttonList.add(new GuiButton(0, this.width / 2 + 20, this.height / 2 - 30, 50, 20, "Toggle"));
this.textFieldLimit = new GuiTextField(fontRenderer, 35, 82, 65, 12);
this.textFieldLimit.setMaxStringLength(8);
this.textFieldLimit.setText("" + this.tileEntity.getLimit());
}
@Override
protected void keyTyped(char par1, int par2)
{
super.keyTyped(par1, par2);
this.textFieldLimit.textboxKeyTyped(par1, par2);
try
{
ArrayList data = new ArrayList();
data.add((byte)3);
data.add(Float.parseFloat(textFieldLimit.getText()));
PacketHandler.sendPacket(Transmission.SERVER, new PacketTileEntity().setParams(Object3D.get(tileEntity)), data);
}
catch (Exception e)
{
}
}
@Override
protected void mouseClicked(int par1, int par2, int par3)
{
super.mouseClicked(par1, par2, par3);
this.textFieldLimit.mouseClicked(par1 - this.containerWidth, par2 - this.containerHeight, par3);
}
@Override
protected void drawGuiContainerForegroundLayer(int par1, int par2)
{
String s = this.tileEntity.getBlockType().getLocalizedName();
this.fontRenderer.drawString(s, this.xSize / 2 - this.fontRenderer.getStringWidth(s) / 2, 15, 4210752);
this.fontRenderer.drawString("Average Energy: " + Math.round(this.tileEntity.getAverageDetectedEnergy()) + " J", 35, 25, 4210752);
this.fontRenderer.drawString("Energy: " + Math.round(this.tileEntity.getDetectedEnergy()) + " J", 35, 35, 4210752);
this.fontRenderer.drawString("Output Redstone If... ", 35, 54, 4210752);
this.fontRenderer.drawString(this.tileEntity.getMode().display, 35, 65, 4210752);
this.fontRenderer.drawString("KiloJoules", 35, 100, 4210752);
this.textFieldLimit.drawTextBox();
}
@Override
protected void drawGuiContainerBackgroundLayer(float f, int x, int y)
{
this.containerWidth = (this.width - this.xSize) / 2;
this.containerHeight = (this.height - this.ySize) / 2;
this.mc.renderEngine.bindTexture(TEXTURE);
GL11.glColor4f(1, 1, 1, 1);
this.drawTexturedModalRect(this.containerWidth, this.containerHeight, 0, 0, this.xSize, this.ySize);
int length = Math.min((int) (this.tileEntity.getDetectedEnergy() / this.tileEntity.getPeak()) * 115, 115);
this.drawTexturedModalRect(this.containerWidth + 14, this.containerHeight + 126 - length, 176, 115 - length, 6, length);
}
@Override
protected void actionPerformed(GuiButton button)
{
ArrayList data = new ArrayList();
data.add((byte)2);
PacketHandler.sendPacket(Transmission.SERVER, new PacketTileEntity().setParams(Object3D.get(tileEntity), data));
}
}

View file

@ -0,0 +1,348 @@
package mekanism.induction.client.model;
import net.minecraft.client.model.ModelBase;
import net.minecraft.client.model.ModelRenderer;
public class ModelBattery extends ModelBase
{
// fields
ModelRenderer BackInnerPanel;
ModelRenderer Slide1;
ModelRenderer Slide2;
ModelRenderer Slide3;
ModelRenderer Slide4;
ModelRenderer Slide5;
ModelRenderer Slide6;
ModelRenderer Slide7;
ModelRenderer Slide8;
ModelRenderer Slide9;
ModelRenderer Slide10;
ModelRenderer Slide11;
ModelRenderer Slide12;
ModelRenderer Slide13;
ModelRenderer Slide14;
ModelRenderer Slide15;
ModelRenderer Slide16;
ModelRenderer Slide17;
ModelRenderer Slide18;
ModelRenderer Slide19;
ModelRenderer Slide20;
ModelRenderer Slide21;
ModelRenderer Slide22;
ModelRenderer Slide23;
ModelRenderer Slide24;
ModelRenderer Slide25;
ModelRenderer Slide26;
ModelRenderer Slide27;
ModelRenderer Slide28;
ModelRenderer FrontInnerPanel;
ModelRenderer RightInnerPanel;
ModelRenderer LeftInnerPanel;
ModelRenderer Podium;
ModelRenderer BottomBase;
ModelRenderer PodiumBase;
ModelRenderer TapNode1;
ModelRenderer TapNode2;
ModelRenderer TapNode3;
ModelRenderer TapNode4;
ModelRenderer ElectricalConduit;
public ModelBattery()
{
textureWidth = 128;
textureHeight = 128;
BackInnerPanel = new ModelRenderer(this, 0, 46);
BackInnerPanel.addBox(0F, 0F, 0F, 14, 15, 3);
BackInnerPanel.setRotationPoint(-7F, 9F, 4F);
BackInnerPanel.setTextureSize(64, 32);
BackInnerPanel.mirror = true;
setRotation(BackInnerPanel, 0F, 0F, 0F);
Slide1 = new ModelRenderer(this, 39, 0);
Slide1.addBox(0F, 0F, 0F, 14, 1, 1);
Slide1.setRotationPoint(-7F, 15F, 7F);
Slide1.setTextureSize(64, 32);
Slide1.mirror = true;
setRotation(Slide1, 0F, 0F, 0F);
Slide2 = new ModelRenderer(this, 39, 0);
Slide2.addBox(0F, 0F, 0F, 14, 1, 1);
Slide2.setRotationPoint(-7F, 15F, -8F);
Slide2.setTextureSize(64, 32);
Slide2.mirror = true;
setRotation(Slide2, 0F, 0F, 0F);
Slide3 = new ModelRenderer(this, 35, 0);
Slide3.addBox(0F, 0F, 0F, 16, 1, 1);
Slide3.setRotationPoint(-8F, 23F, -8F);
Slide3.setTextureSize(64, 32);
Slide3.mirror = true;
setRotation(Slide3, 0F, 0F, 0F);
Slide4 = new ModelRenderer(this, 35, 0);
Slide4.addBox(0F, 0F, 0F, 16, 1, 1);
Slide4.setRotationPoint(-8F, 23F, 7F);
Slide4.setTextureSize(64, 32);
Slide4.mirror = true;
setRotation(Slide4, 0F, 0F, 0F);
Slide5 = new ModelRenderer(this, 0, 19);
Slide5.addBox(0F, 0F, 0F, 1, 1, 14);
Slide5.setRotationPoint(-8F, 16F, -7F);
Slide5.setTextureSize(64, 32);
Slide5.mirror = true;
setRotation(Slide5, 0F, 0F, 0F);
Slide6 = new ModelRenderer(this, 0, 19);
Slide6.addBox(0F, 0F, 0F, 1, 1, 14);
Slide6.setRotationPoint(7F, 16F, -7F);
Slide6.setTextureSize(64, 32);
Slide6.mirror = true;
setRotation(Slide6, 0F, 0F, 0F);
Slide7 = new ModelRenderer(this, 0, 19);
Slide7.addBox(0F, 0F, 0F, 1, 1, 14);
Slide7.setRotationPoint(7F, 23F, -7F);
Slide7.setTextureSize(64, 32);
Slide7.mirror = true;
setRotation(Slide7, 0F, 0F, 0F);
Slide8 = new ModelRenderer(this, 0, 19);
Slide8.addBox(0F, 0F, 0F, 1, 1, 14);
Slide8.setRotationPoint(-8F, 23F, -7F);
Slide8.setTextureSize(64, 32);
Slide8.mirror = true;
setRotation(Slide8, 0F, 0F, 0F);
Slide9 = new ModelRenderer(this, 0, 0);
Slide9.addBox(0F, 0F, 0F, 1, 14, 1);
Slide9.setRotationPoint(7F, 9F, 0F);
Slide9.setTextureSize(64, 32);
Slide9.mirror = true;
setRotation(Slide9, 0F, 0F, 0F);
Slide10 = new ModelRenderer(this, 0, 0);
Slide10.addBox(0F, 0F, 0F, 1, 14, 1);
Slide10.setRotationPoint(7F, 9F, -8F);
Slide10.setTextureSize(64, 32);
Slide10.mirror = true;
setRotation(Slide10, 0F, 0F, 0F);
Slide11 = new ModelRenderer(this, 0, 0);
Slide11.addBox(0F, 0F, 0F, 1, 14, 1);
Slide11.setRotationPoint(0F, 9F, -8F);
Slide11.setTextureSize(64, 32);
Slide11.mirror = true;
setRotation(Slide11, 0F, 0F, 0F);
Slide12 = new ModelRenderer(this, 0, 0);
Slide12.addBox(0F, 0F, 0F, 1, 14, 1);
Slide12.setRotationPoint(0F, 9F, 7F);
Slide12.setTextureSize(64, 32);
Slide12.mirror = true;
setRotation(Slide12, 0F, 0F, 0F);
Slide13 = new ModelRenderer(this, 0, 0);
Slide13.addBox(0F, 0F, 0F, 1, 14, 1);
Slide13.setRotationPoint(-8F, 9F, -8F);
Slide13.setTextureSize(64, 32);
Slide13.mirror = true;
setRotation(Slide13, 0F, 0F, 0F);
Slide14 = new ModelRenderer(this, 0, 0);
Slide14.addBox(0F, 0F, 0F, 1, 14, 1);
Slide14.setRotationPoint(-8F, 9F, 0F);
Slide14.setTextureSize(64, 32);
Slide14.mirror = true;
setRotation(Slide14, 0F, 0F, 0F);
Slide15 = new ModelRenderer(this, 0, 0);
Slide15.addBox(0F, 0F, 0F, 1, 14, 1);
Slide15.setRotationPoint(-1F, 9F, -8F);
Slide15.setTextureSize(64, 32);
Slide15.mirror = true;
setRotation(Slide15, 0F, 0F, 0F);
Slide16 = new ModelRenderer(this, 0, 0);
Slide16.addBox(0F, 0F, 0F, 1, 14, 1);
Slide16.setRotationPoint(-1F, 9F, 7F);
Slide16.setTextureSize(64, 32);
Slide16.mirror = true;
setRotation(Slide16, 0F, 0F, 0F);
Slide17 = new ModelRenderer(this, 0, 0);
Slide17.addBox(0F, 0F, 0F, 1, 14, 1);
Slide17.setRotationPoint(7F, 9F, 7F);
Slide17.setTextureSize(64, 32);
Slide17.mirror = true;
setRotation(Slide17, 0F, 0F, 0F);
Slide18 = new ModelRenderer(this, 0, 0);
Slide18.addBox(0F, 0F, 0F, 1, 14, 1);
Slide18.setRotationPoint(-8F, 9F, 7F);
Slide18.setTextureSize(64, 32);
Slide18.mirror = true;
setRotation(Slide18, 0F, 0F, 0F);
Slide19 = new ModelRenderer(this, 0, 0);
Slide19.addBox(0F, 0F, 0F, 1, 14, 1);
Slide19.setRotationPoint(7F, 9F, -1F);
Slide19.setTextureSize(64, 32);
Slide19.mirror = true;
setRotation(Slide19, 0F, 0F, 0F);
Slide20 = new ModelRenderer(this, 0, 0);
Slide20.addBox(0F, 0F, 0F, 1, 14, 1);
Slide20.setRotationPoint(-8F, 9F, -1F);
Slide20.setTextureSize(64, 32);
Slide20.mirror = true;
setRotation(Slide20, 0F, 0F, 0F);
Slide21 = new ModelRenderer(this, 0, 19);
Slide21.addBox(0F, 0F, 0F, 1, 1, 14);
Slide21.setRotationPoint(-8F, 15F, -7F);
Slide21.setTextureSize(64, 32);
Slide21.mirror = true;
setRotation(Slide21, 0F, 0F, 0F);
Slide22 = new ModelRenderer(this, 0, 19);
Slide22.addBox(0F, 0F, 0F, 1, 1, 14);
Slide22.setRotationPoint(7F, 8F, -7F);
Slide22.setTextureSize(64, 32);
Slide22.mirror = true;
setRotation(Slide22, 0F, 0F, 0F);
Slide23 = new ModelRenderer(this, 0, 19);
Slide23.addBox(0F, 0F, 0F, 1, 1, 14);
Slide23.setRotationPoint(-8F, 8F, -7F);
Slide23.setTextureSize(64, 32);
Slide23.mirror = true;
setRotation(Slide23, 0F, 0F, 0F);
Slide24 = new ModelRenderer(this, 0, 19);
Slide24.addBox(0F, 0F, 0F, 1, 1, 14);
Slide24.setRotationPoint(7F, 15F, -7F);
Slide24.setTextureSize(64, 32);
Slide24.mirror = true;
setRotation(Slide24, 0F, 0F, 0F);
Slide25 = new ModelRenderer(this, 35, 0);
Slide25.addBox(0F, 0F, 0F, 16, 1, 1);
Slide25.setRotationPoint(-8F, 8F, 7F);
Slide25.setTextureSize(64, 32);
Slide25.mirror = true;
setRotation(Slide25, 0F, 0F, 0F);
Slide26 = new ModelRenderer(this, 35, 0);
Slide26.addBox(0F, 0F, 0F, 16, 1, 1);
Slide26.setRotationPoint(-8F, 8F, -8F);
Slide26.setTextureSize(64, 32);
Slide26.mirror = true;
setRotation(Slide26, 0F, 0F, 0F);
Slide27 = new ModelRenderer(this, 39, 0);
Slide27.addBox(0F, 0F, 0F, 14, 1, 1);
Slide27.setRotationPoint(-7F, 16F, 7F);
Slide27.setTextureSize(64, 32);
Slide27.mirror = true;
setRotation(Slide27, 0F, 0F, 0F);
Slide28 = new ModelRenderer(this, 39, 0);
Slide28.addBox(0F, 0F, 0F, 14, 1, 1);
Slide28.setRotationPoint(-7F, 16F, -8F);
Slide28.setTextureSize(64, 32);
Slide28.mirror = true;
setRotation(Slide28, 0F, 0F, 0F);
FrontInnerPanel = new ModelRenderer(this, 0, 46);
FrontInnerPanel.addBox(0F, 0F, 0F, 14, 15, 3);
FrontInnerPanel.setRotationPoint(-7F, 9F, -7F);
FrontInnerPanel.setTextureSize(64, 32);
FrontInnerPanel.mirror = true;
setRotation(FrontInnerPanel, 0F, 0F, 0F);
RightInnerPanel = new ModelRenderer(this, 0, 65);
RightInnerPanel.addBox(0F, 0F, 0F, 3, 15, 8);
RightInnerPanel.setRotationPoint(-7F, 9F, -4F);
RightInnerPanel.setTextureSize(64, 32);
RightInnerPanel.mirror = true;
setRotation(RightInnerPanel, 0F, 0F, 0F);
LeftInnerPanel = new ModelRenderer(this, 0, 65);
LeftInnerPanel.addBox(0F, 0F, 0F, 3, 15, 8);
LeftInnerPanel.setRotationPoint(4F, 9F, -4F);
LeftInnerPanel.setTextureSize(64, 32);
LeftInnerPanel.mirror = true;
setRotation(LeftInnerPanel, 0F, 0F, 0F);
Podium = new ModelRenderer(this, 23, 65);
Podium.addBox(0F, 0F, 0F, 1, 9, 1);
Podium.setRotationPoint(-0.5F, 12F, -0.5F);
Podium.setTextureSize(64, 32);
Podium.mirror = true;
setRotation(Podium, 0F, 0F, 0F);
BottomBase = new ModelRenderer(this, 0, 36);
BottomBase.addBox(0F, 0F, 0F, 8, 1, 8);
BottomBase.setRotationPoint(-4F, 23F, -4F);
BottomBase.setTextureSize(64, 32);
BottomBase.mirror = true;
setRotation(BottomBase, 0F, 0F, 0F);
PodiumBase = new ModelRenderer(this, 0, 89);
PodiumBase.addBox(0F, 0F, 0F, 4, 2, 4);
PodiumBase.setRotationPoint(-2F, 21F, -2F);
PodiumBase.setTextureSize(64, 32);
PodiumBase.mirror = true;
setRotation(PodiumBase, 0F, 0F, 0F);
TapNode1 = new ModelRenderer(this, 23, 76);
TapNode1.addBox(0F, 0F, 0F, 1, 2, 1);
TapNode1.setRotationPoint(-0.5F, 15F, 3F);
TapNode1.setTextureSize(64, 32);
TapNode1.mirror = true;
setRotation(TapNode1, 0F, 0F, 0F);
TapNode2 = new ModelRenderer(this, 23, 76);
TapNode2.addBox(0F, 0F, 0F, 1, 2, 1);
TapNode2.setRotationPoint(3F, 15F, -0.5F);
TapNode2.setTextureSize(64, 32);
TapNode2.mirror = true;
setRotation(TapNode2, 0F, 0F, 0F);
TapNode3 = new ModelRenderer(this, 23, 76);
TapNode3.addBox(0F, 0F, 0F, 1, 2, 1);
TapNode3.setRotationPoint(-0.5F, 15F, -4F);
TapNode3.setTextureSize(64, 32);
TapNode3.mirror = true;
setRotation(TapNode3, 0F, 0F, 0F);
TapNode4 = new ModelRenderer(this, 23, 76);
TapNode4.addBox(0F, 0F, 0F, 1, 2, 1);
TapNode4.setRotationPoint(-4F, 15F, -0.5F);
TapNode4.setTextureSize(64, 32);
TapNode4.mirror = true;
setRotation(TapNode4, 0F, 0F, 0F);
ElectricalConduit = new ModelRenderer(this, 17, 89);
ElectricalConduit.addBox(0F, 0F, 0F, 3, 3, 3);
ElectricalConduit.setRotationPoint(-1.5F, 11F, -1.5F);
ElectricalConduit.setTextureSize(64, 32);
ElectricalConduit.mirror = true;
setRotation(ElectricalConduit, 0F, 0F, 0F);
}
public void render(float f5)
{
BackInnerPanel.render(f5);
Slide1.render(f5);
Slide2.render(f5);
Slide3.render(f5);
Slide4.render(f5);
Slide5.render(f5);
Slide6.render(f5);
Slide7.render(f5);
Slide8.render(f5);
Slide9.render(f5);
Slide10.render(f5);
Slide11.render(f5);
Slide12.render(f5);
Slide13.render(f5);
Slide14.render(f5);
Slide15.render(f5);
Slide16.render(f5);
Slide17.render(f5);
Slide18.render(f5);
Slide19.render(f5);
Slide20.render(f5);
Slide21.render(f5);
Slide22.render(f5);
Slide23.render(f5);
Slide24.render(f5);
Slide25.render(f5);
Slide26.render(f5);
Slide27.render(f5);
Slide28.render(f5);
FrontInnerPanel.render(f5);
RightInnerPanel.render(f5);
LeftInnerPanel.render(f5);
Podium.render(f5);
BottomBase.render(f5);
PodiumBase.render(f5);
TapNode1.render(f5);
TapNode2.render(f5);
TapNode3.render(f5);
TapNode4.render(f5);
ElectricalConduit.render(f5);
}
private void setRotation(ModelRenderer model, float x, float y, float z)
{
model.rotateAngleX = x;
model.rotateAngleY = y;
model.rotateAngleZ = z;
}
}

View file

@ -0,0 +1,246 @@
package mekanism.induction.client.model;
import net.minecraft.client.model.ModelBase;
import net.minecraft.client.model.ModelRenderer;
public class ModelEMContractor extends ModelBase
{
public boolean doSpin;
// fields
ModelRenderer frame1;
ModelRenderer frame2;
ModelRenderer frame3;
ModelRenderer frame4;
ModelRenderer frame5;
ModelRenderer frame6;
ModelRenderer frame7;
ModelRenderer frame8;
ModelRenderer left_frame_connector;
ModelRenderer right_frame_connector;
ModelRenderer teslapole;
ModelRenderer Coil1;
ModelRenderer coil2;
ModelRenderer coil3;
ModelRenderer coil4;
ModelRenderer pole1;
ModelRenderer pole2;
ModelRenderer pole3;
ModelRenderer pole4;
ModelRenderer poletop1;
ModelRenderer poletop2;
ModelRenderer poletop3;
ModelRenderer poletop4;
ModelRenderer base1;
ModelRenderer base2;
ModelRenderer base3;
public ModelEMContractor(boolean spin)
{
doSpin = spin;
textureWidth = 128;
textureHeight = 128;
frame1 = new ModelRenderer(this, 0, 24);
frame1.addBox(0F, 0F, 0F, 1, 8, 1);
frame1.setRotationPoint(-3F, 15F, -2F);
frame1.setTextureSize(128, 128);
frame1.mirror = true;
setRotation(frame1, 0F, 0F, 0F);
frame2 = new ModelRenderer(this, 0, 24);
frame2.addBox(0F, 0F, 0F, 1, 8, 1);
frame2.setRotationPoint(1F, 15F, 2F);
frame2.setTextureSize(128, 128);
frame2.mirror = true;
setRotation(frame2, 0F, 0F, 0F);
frame3 = new ModelRenderer(this, 0, 24);
frame3.addBox(0F, 0F, 0F, 1, 8, 1);
frame3.setRotationPoint(2F, 15F, -2F);
frame3.setTextureSize(128, 128);
frame3.mirror = true;
setRotation(frame3, 0F, 0F, 0F);
frame4 = new ModelRenderer(this, 0, 24);
frame4.addBox(0F, 0F, 0F, 1, 8, 1);
frame4.setRotationPoint(-3F, 15F, 1F);
frame4.setTextureSize(128, 128);
frame4.mirror = true;
setRotation(frame4, 0F, 0F, 0F);
frame5 = new ModelRenderer(this, 0, 24);
frame5.addBox(0F, 0F, 0F, 1, 8, 1);
frame5.setRotationPoint(2F, 15F, 1F);
frame5.setTextureSize(128, 128);
frame5.mirror = true;
setRotation(frame5, 0F, 0F, 0F);
frame6 = new ModelRenderer(this, 0, 24);
frame6.addBox(0F, 0F, 0F, 1, 8, 1);
frame6.setRotationPoint(1F, 15F, -3F);
frame6.setTextureSize(128, 128);
frame6.mirror = true;
setRotation(frame6, 0F, 0F, 0F);
frame7 = new ModelRenderer(this, 0, 24);
frame7.addBox(0F, 0F, 0F, 1, 8, 1);
frame7.setRotationPoint(-2F, 15F, 2F);
frame7.setTextureSize(128, 128);
frame7.mirror = true;
setRotation(frame7, 0F, 0F, 0F);
frame8 = new ModelRenderer(this, 0, 24);
frame8.addBox(0F, 0F, 0F, 1, 8, 1);
frame8.setRotationPoint(-2F, 15F, -3F);
frame8.setTextureSize(128, 128);
frame8.mirror = true;
setRotation(frame8, 0F, 0F, 0F);
left_frame_connector = new ModelRenderer(this, 0, 20);
left_frame_connector.addBox(0F, 0F, 0F, 1, 1, 2);
left_frame_connector.setRotationPoint(-3F, 15F, -1F);
left_frame_connector.setTextureSize(128, 128);
left_frame_connector.mirror = true;
setRotation(left_frame_connector, 0F, 0F, 0F);
right_frame_connector = new ModelRenderer(this, 0, 20);
right_frame_connector.addBox(0F, 0F, 0F, 1, 1, 2);
right_frame_connector.setRotationPoint(2F, 15F, -1F);
right_frame_connector.setTextureSize(128, 128);
right_frame_connector.mirror = true;
setRotation(right_frame_connector, 0F, 0F, 0F);
teslapole = new ModelRenderer(this, 0, 0);
teslapole.addBox(-1F, -1F, -1F, 2, 15, 2);
teslapole.setRotationPoint(0F, 9F, 0F);
teslapole.setTextureSize(128, 128);
teslapole.mirror = true;
setRotation(teslapole, 0F, 0F, 0F);
Coil1 = new ModelRenderer(this, 17, 0);
Coil1.addBox(-1.5F, -0.5F, -1.5F, 3, 1, 3);
Coil1.setRotationPoint(0F, 12.5F, 0F);
Coil1.setTextureSize(128, 128);
Coil1.mirror = true;
setRotation(Coil1, 0F, 0F, 0F);
coil2 = new ModelRenderer(this, 17, 0);
coil2.addBox(-1.5F, -0.5F, -1.5F, 3, 1, 3);
coil2.setRotationPoint(0F, 14F, 0F);
coil2.setTextureSize(128, 128);
coil2.mirror = true;
setRotation(coil2, 0F, 0F, 0F);
coil3 = new ModelRenderer(this, 17, 0);
coil3.addBox(-1.5F, -0.5F, -1.5F, 3, 1, 3);
coil3.setRotationPoint(0F, 9.5F, 0F);
coil3.setTextureSize(128, 128);
coil3.mirror = true;
setRotation(coil3, 0F, 0F, 0F);
coil4 = new ModelRenderer(this, 17, 0);
coil4.addBox(-1.5F, -0.5F, -1.5F, 3, 1, 3);
coil4.setRotationPoint(0F, 11F, 0F);
coil4.setTextureSize(128, 128);
coil4.mirror = true;
setRotation(coil4, 0F, 0F, 0F);
pole1 = new ModelRenderer(this, 5, 26);
pole1.addBox(-0.5F, -1F, -0.5F, 1, 6, 1);
pole1.setRotationPoint(0F, 18F, 6.5F);
pole1.setTextureSize(128, 128);
pole1.mirror = true;
setRotation(pole1, 0F, 0F, 0F);
pole2 = new ModelRenderer(this, 5, 26);
pole2.addBox(-0.5F, -1F, -0.5F, 1, 6, 1);
pole2.setRotationPoint(0F, 18F, -6.5F);
pole2.setTextureSize(128, 128);
pole2.mirror = true;
setRotation(pole2, 0F, 0F, 0F);
pole3 = new ModelRenderer(this, 5, 26);
pole3.addBox(-0.5F, -1F, -0.5F, 1, 6, 1);
pole3.setRotationPoint(-6.5F, 18F, 0F);
pole3.setTextureSize(128, 128);
pole3.mirror = true;
setRotation(pole3, 0F, 0F, 0F);
pole4 = new ModelRenderer(this, 5, 26);
pole4.addBox(-0.5F, -1F, -0.5F, 1, 6, 1);
pole4.setRotationPoint(6.5F, 18F, 0F);
pole4.setTextureSize(128, 128);
pole4.mirror = true;
setRotation(pole4, 0F, 0F, 0F);
poletop1 = new ModelRenderer(this, 31, 0);
poletop1.addBox(-1F, -1F, -1F, 2, 2, 2);
poletop1.setRotationPoint(0F, 16.5F, -6.5F);
poletop1.setTextureSize(128, 128);
poletop1.mirror = true;
setRotation(poletop1, 0F, 0F, 0F);
poletop2 = new ModelRenderer(this, 31, 0);
poletop2.addBox(-1F, -1F, -1F, 2, 2, 2);
poletop2.setRotationPoint(0F, 16.5F, 6.5F);
poletop2.setTextureSize(128, 128);
poletop2.mirror = true;
setRotation(poletop2, 0F, 0F, 0F);
poletop3 = new ModelRenderer(this, 31, 0);
poletop3.addBox(-1F, -1F, -1F, 2, 2, 2);
poletop3.setRotationPoint(6.5F, 16.5F, 0F);
poletop3.setTextureSize(128, 128);
poletop3.mirror = true;
setRotation(poletop3, 0F, 0F, 0F);
poletop4 = new ModelRenderer(this, 31, 0);
poletop4.addBox(-1F, -1F, -1F, 2, 2, 2);
poletop4.setRotationPoint(-6.5F, 16.5F, 0F);
poletop4.setTextureSize(128, 128);
poletop4.mirror = true;
setRotation(poletop4, 0F, 0F, 0F);
base1 = new ModelRenderer(this, 0, 55);
base1.addBox(0F, 0F, 0F, 16, 1, 8);
base1.setRotationPoint(-8F, 23F, -4F);
base1.setTextureSize(128, 128);
base1.mirror = true;
setRotation(base1, 0F, 0F, 0F);
base2 = new ModelRenderer(this, 0, 68);
base2.addBox(0F, 0F, 0F, 8, 1, 5);
base2.setRotationPoint(-4F, 23F, 3F);
base2.setTextureSize(128, 128);
base2.mirror = true;
setRotation(base2, 0F, 0F, 0F);
base3 = new ModelRenderer(this, 0, 79);
base3.addBox(0F, 0F, 0F, 8, 1, 5);
base3.setRotationPoint(-4F, 23F, -8F);
base3.setTextureSize(128, 128);
base3.mirror = true;
setRotation(base3, 0F, 0F, 0F);
}
public void render(float f5)
{
if (doSpin)
{
Coil1.rotateAngleY = (float) Math.toRadians(Math.toDegrees(Coil1.rotateAngleY) + 3 < 360 ? Math.toDegrees(Coil1.rotateAngleY) + 3 : 0);
coil2.rotateAngleY = (float) Math.toRadians(Math.toDegrees(coil2.rotateAngleY) + 3 < 360 ? Math.toDegrees(coil2.rotateAngleY) + 3 : 0);
coil3.rotateAngleY = (float) Math.toRadians(Math.toDegrees(coil3.rotateAngleY) + 3 < 360 ? Math.toDegrees(coil3.rotateAngleY) + 3 : 0);
coil4.rotateAngleY = (float) Math.toRadians(Math.toDegrees(coil4.rotateAngleY) + 3 < 360 ? Math.toDegrees(coil4.rotateAngleY) + 3 : 0);
}
frame1.render(f5);
frame2.render(f5);
frame3.render(f5);
frame4.render(f5);
frame5.render(f5);
frame6.render(f5);
frame7.render(f5);
frame8.render(f5);
left_frame_connector.render(f5);
right_frame_connector.render(f5);
teslapole.render(f5);
Coil1.render(f5);
coil2.render(f5);
coil3.render(f5);
coil4.render(f5);
pole1.render(f5);
pole2.render(f5);
pole3.render(f5);
pole4.render(f5);
poletop1.render(f5);
poletop2.render(f5);
poletop3.render(f5);
poletop4.render(f5);
base1.render(f5);
base2.render(f5);
base3.render(f5);
}
private void setRotation(ModelRenderer model, float x, float y, float z)
{
model.rotateAngleX = x;
model.rotateAngleY = y;
model.rotateAngleZ = z;
}
}

View file

@ -0,0 +1,454 @@
package mekanism.induction.client.model;
import net.minecraft.client.model.ModelBase;
import net.minecraft.client.model.ModelRenderer;
import net.minecraft.entity.Entity;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class ModelInsulation extends ModelBase
{
// fields
ModelRenderer Middle;
ModelRenderer ToBLeft;
ModelRenderer BoBLeft;
ModelRenderer ToBRight;
ModelRenderer BoBRight;
ModelRenderer BoBFront;
ModelRenderer BoBBack;
ModelRenderer ToBFront;
ModelRenderer ToBBack;
ModelRenderer BoTLeft;
ModelRenderer ToTRight;
ModelRenderer BoTRight;
ModelRenderer BoTFront;
ModelRenderer ToTLeft;
ModelRenderer BoTBack;
ModelRenderer ToTBack;
ModelRenderer ToTFront;
ModelRenderer LoFFront;
ModelRenderer BoFBack;
ModelRenderer RoFFront;
ModelRenderer BoFFront;
ModelRenderer ToFBack;
ModelRenderer ToFFront;
ModelRenderer RoFBack;
ModelRenderer LoFBack;
ModelRenderer BoBackBack;
ModelRenderer ToBackBack;
ModelRenderer RoBackBack;
ModelRenderer RoBackFront;
ModelRenderer LoBackFront;
ModelRenderer BoBackFront;
ModelRenderer ToBackFront;
ModelRenderer LoBackFront2;
ModelRenderer BToRLeft;
ModelRenderer FoRRight;
ModelRenderer ToRLeft;
ModelRenderer BToRRight;
ModelRenderer BoRLeft;
ModelRenderer ToRRight;
ModelRenderer FoRLeft;
ModelRenderer BoRRight;
ModelRenderer BoLRight;
ModelRenderer BToLRight;
ModelRenderer FoLLeft;
ModelRenderer ToLRight;
ModelRenderer FoLRight;
ModelRenderer BoLLeft;
ModelRenderer ToLLeft;
ModelRenderer BToLLeft;
public ModelInsulation()
{
textureWidth = 128;
textureHeight = 128;
Middle = new ModelRenderer(this, 0, 0);
Middle.addBox(0F, 0F, 0F, 6, 6, 6);
Middle.setRotationPoint(-3F, 13F, -3F);
Middle.setTextureSize(128, 128);
Middle.mirror = true;
setRotation(Middle, 0F, 0F, 0F);
ToBLeft = new ModelRenderer(this, 25, 0);
ToBLeft.addBox(0F, 0F, 0F, 1, 2, 4);
ToBLeft.setRotationPoint(-3F, 19F, -2F);
ToBLeft.setTextureSize(128, 128);
ToBLeft.mirror = true;
setRotation(ToBLeft, 0F, 0F, 0F);
BoBLeft = new ModelRenderer(this, 25, 0);
BoBLeft.addBox(0F, 0F, 0F, 1, 2, 4);
BoBLeft.setRotationPoint(-3F, 22F, -2F);
BoBLeft.setTextureSize(128, 128);
BoBLeft.mirror = true;
setRotation(BoBLeft, 0F, 0F, 0F);
ToBRight = new ModelRenderer(this, 36, 0);
ToBRight.addBox(0F, 0F, 0F, 1, 2, 4);
ToBRight.setRotationPoint(2F, 19F, -2F);
ToBRight.setTextureSize(128, 128);
ToBRight.mirror = true;
setRotation(ToBRight, 0F, 0F, 0F);
BoBRight = new ModelRenderer(this, 36, 0);
BoBRight.addBox(0F, 0F, 0F, 1, 2, 4);
BoBRight.setRotationPoint(2F, 22F, -2F);
BoBRight.setTextureSize(128, 128);
BoBRight.mirror = true;
setRotation(BoBRight, 0F, 0F, 0F);
BoBFront = new ModelRenderer(this, 25, 7);
BoBFront.addBox(0F, 0F, 0F, 6, 2, 1);
BoBFront.setRotationPoint(-3F, 22F, -3F);
BoBFront.setTextureSize(128, 128);
BoBFront.mirror = true;
setRotation(BoBFront, 0F, 0F, 0F);
BoBBack = new ModelRenderer(this, 40, 7);
BoBBack.addBox(0F, 0F, 0F, 6, 2, 1);
BoBBack.setRotationPoint(-3F, 22F, 2F);
BoBBack.setTextureSize(128, 128);
BoBBack.mirror = true;
setRotation(BoBBack, 0F, 0F, 0F);
ToBFront = new ModelRenderer(this, 25, 7);
ToBFront.addBox(0F, 0F, 0F, 6, 2, 1);
ToBFront.setRotationPoint(-3F, 19F, -3F);
ToBFront.setTextureSize(128, 128);
ToBFront.mirror = true;
setRotation(ToBFront, 0F, 0F, 0F);
ToBBack = new ModelRenderer(this, 40, 7);
ToBBack.addBox(0F, 0F, 0F, 6, 2, 1);
ToBBack.setRotationPoint(-3F, 19F, 2F);
ToBBack.setTextureSize(128, 128);
ToBBack.mirror = true;
setRotation(ToBBack, 0F, 0F, 0F);
BoTLeft = new ModelRenderer(this, 57, 0);
BoTLeft.addBox(0F, 0F, 0F, 1, 2, 4);
BoTLeft.setRotationPoint(-3F, 11F, -2F);
BoTLeft.setTextureSize(128, 128);
BoTLeft.mirror = true;
setRotation(BoTLeft, 0F, 0F, 0F);
ToTRight = new ModelRenderer(this, 68, 0);
ToTRight.addBox(0F, 0F, 0F, 1, 2, 4);
ToTRight.setRotationPoint(2F, 8F, -2F);
ToTRight.setTextureSize(128, 128);
ToTRight.mirror = true;
setRotation(ToTRight, 0F, 0F, 0F);
BoTRight = new ModelRenderer(this, 68, 0);
BoTRight.addBox(0F, 0F, 0F, 1, 2, 4);
BoTRight.setRotationPoint(2F, 11F, -2F);
BoTRight.setTextureSize(128, 128);
BoTRight.mirror = true;
setRotation(BoTRight, 0F, 0F, 0F);
BoTFront = new ModelRenderer(this, 57, 7);
BoTFront.addBox(0F, 0F, 0F, 6, 2, 1);
BoTFront.setRotationPoint(-3F, 11F, -3F);
BoTFront.setTextureSize(128, 128);
BoTFront.mirror = true;
setRotation(BoTFront, 0F, 0F, 0F);
ToTLeft = new ModelRenderer(this, 57, 0);
ToTLeft.addBox(0F, 0F, 0F, 1, 2, 4);
ToTLeft.setRotationPoint(-3F, 8F, -2F);
ToTLeft.setTextureSize(128, 128);
ToTLeft.mirror = true;
setRotation(ToTLeft, 0F, 0F, 0F);
BoTBack = new ModelRenderer(this, 72, 7);
BoTBack.addBox(0F, 0F, 0F, 6, 2, 1);
BoTBack.setRotationPoint(-3F, 11F, 2F);
BoTBack.setTextureSize(128, 128);
BoTBack.mirror = true;
setRotation(BoTBack, 0F, 0F, 0F);
ToTBack = new ModelRenderer(this, 72, 7);
ToTBack.addBox(0F, 0F, 0F, 6, 2, 1);
ToTBack.setRotationPoint(-3F, 8F, 2F);
ToTBack.setTextureSize(128, 128);
ToTBack.mirror = true;
setRotation(ToTBack, 0F, 0F, 0F);
ToTFront = new ModelRenderer(this, 57, 7);
ToTFront.addBox(0F, 0F, 0F, 6, 2, 1);
ToTFront.setRotationPoint(-3F, 8F, -3F);
ToTFront.setTextureSize(128, 128);
ToTFront.mirror = true;
setRotation(ToTFront, 0F, 0F, 0F);
LoFFront = new ModelRenderer(this, 25, 14);
LoFFront.addBox(0F, 0F, 0F, 1, 4, 2);
LoFFront.setRotationPoint(-3F, 14F, -8F);
LoFFront.setTextureSize(128, 128);
LoFFront.mirror = true;
setRotation(LoFFront, 0F, 0F, 0F);
BoFBack = new ModelRenderer(this, 32, 14);
BoFBack.addBox(0F, 0F, 0F, 6, 1, 2);
BoFBack.setRotationPoint(-3F, 18F, -5F);
BoFBack.setTextureSize(128, 128);
BoFBack.mirror = true;
setRotation(BoFBack, 0F, 0F, 0F);
RoFFront = new ModelRenderer(this, 25, 21);
RoFFront.addBox(0F, 0F, 0F, 1, 4, 2);
RoFFront.setRotationPoint(2F, 14F, -8F);
RoFFront.setTextureSize(128, 128);
RoFFront.mirror = true;
setRotation(RoFFront, 0F, 0F, 0F);
BoFFront = new ModelRenderer(this, 32, 14);
BoFFront.addBox(0F, 0F, 0F, 6, 1, 2);
BoFFront.setRotationPoint(-3F, 18F, -8F);
BoFFront.setTextureSize(128, 128);
BoFFront.mirror = true;
setRotation(BoFFront, 0F, 0F, 0F);
ToFBack = new ModelRenderer(this, 32, 18);
ToFBack.addBox(0F, 0F, 0F, 6, 1, 2);
ToFBack.setRotationPoint(-3F, 13F, -5F);
ToFBack.setTextureSize(128, 128);
ToFBack.mirror = true;
setRotation(ToFBack, 0F, 0F, 0F);
ToFFront = new ModelRenderer(this, 32, 18);
ToFFront.addBox(0F, 0F, 0F, 6, 1, 2);
ToFFront.setRotationPoint(-3F, 13F, -8F);
ToFFront.setTextureSize(128, 128);
ToFFront.mirror = true;
setRotation(ToFFront, 0F, 0F, 0F);
RoFBack = new ModelRenderer(this, 25, 21);
RoFBack.addBox(0F, 0F, 0F, 1, 4, 2);
RoFBack.setRotationPoint(2F, 14F, -5F);
RoFBack.setTextureSize(128, 128);
RoFBack.mirror = true;
setRotation(RoFBack, 0F, 0F, 0F);
LoFBack = new ModelRenderer(this, 25, 14);
LoFBack.addBox(0F, 0F, 0F, 1, 4, 2);
LoFBack.setRotationPoint(-3F, 14F, -5F);
LoFBack.setTextureSize(128, 128);
LoFBack.mirror = true;
setRotation(LoFBack, 0F, 0F, 0F);
BoBackBack = new ModelRenderer(this, 57, 14);
BoBackBack.addBox(0F, 0F, 0F, 6, 1, 2);
BoBackBack.setRotationPoint(-3F, 18F, 6F);
BoBackBack.setTextureSize(128, 128);
BoBackBack.mirror = true;
setRotation(BoBackBack, 0F, 0F, 0F);
ToBackBack = new ModelRenderer(this, 57, 18);
ToBackBack.addBox(0F, 0F, 0F, 6, 1, 2);
ToBackBack.setRotationPoint(-3F, 13F, 6F);
ToBackBack.setTextureSize(128, 128);
ToBackBack.mirror = true;
setRotation(ToBackBack, 0F, 0F, 0F);
RoBackBack = new ModelRenderer(this, 74, 14);
RoBackBack.addBox(0F, 0F, 0F, 1, 4, 2);
RoBackBack.setRotationPoint(-3F, 14F, 6F);
RoBackBack.setTextureSize(128, 128);
RoBackBack.mirror = true;
setRotation(RoBackBack, 0F, 0F, 0F);
RoBackFront = new ModelRenderer(this, 74, 14);
RoBackFront.addBox(0F, 0F, 0F, 1, 4, 2);
RoBackFront.setRotationPoint(-3F, 14F, 3F);
RoBackFront.setTextureSize(128, 128);
RoBackFront.mirror = true;
setRotation(RoBackFront, 0F, 0F, 0F);
LoBackFront = new ModelRenderer(this, 74, 21);
LoBackFront.addBox(0F, 0F, 0F, 1, 4, 2);
LoBackFront.setRotationPoint(2F, 14F, 3F);
LoBackFront.setTextureSize(128, 128);
LoBackFront.mirror = true;
setRotation(LoBackFront, 0F, 0F, 0F);
BoBackFront = new ModelRenderer(this, 57, 14);
BoBackFront.addBox(0F, 0F, 0F, 6, 1, 2);
BoBackFront.setRotationPoint(-3F, 18F, 3F);
BoBackFront.setTextureSize(128, 128);
BoBackFront.mirror = true;
setRotation(BoBackFront, 0F, 0F, 0F);
ToBackFront = new ModelRenderer(this, 57, 18);
ToBackFront.addBox(0F, 0F, 0F, 6, 1, 2);
ToBackFront.setRotationPoint(-3F, 13F, 3F);
ToBackFront.setTextureSize(128, 128);
ToBackFront.mirror = true;
setRotation(ToBackFront, 0F, 0F, 0F);
LoBackFront2 = new ModelRenderer(this, 74, 21);
LoBackFront2.addBox(0F, 0F, 0F, 1, 4, 2);
LoBackFront2.setRotationPoint(2F, 14F, 6F);
LoBackFront2.setTextureSize(128, 128);
LoBackFront2.mirror = true;
setRotation(LoBackFront2, 0F, 0F, 0F);
BToRLeft = new ModelRenderer(this, 0, 30);
BToRLeft.addBox(0F, 0F, 0F, 2, 1, 4);
BToRLeft.setRotationPoint(3F, 18F, -2F);
BToRLeft.setTextureSize(128, 128);
BToRLeft.mirror = true;
setRotation(BToRLeft, 0F, 0F, 0F);
FoRRight = new ModelRenderer(this, 0, 22);
FoRRight.addBox(0F, 0F, 0F, 2, 6, 1);
FoRRight.setRotationPoint(6F, 13F, -3F);
FoRRight.setTextureSize(128, 128);
FoRRight.mirror = true;
setRotation(FoRRight, 0F, 0F, 0F);
ToRLeft = new ModelRenderer(this, 0, 36);
ToRLeft.addBox(0F, 0F, 0F, 2, 1, 4);
ToRLeft.setRotationPoint(3F, 13F, -2F);
ToRLeft.setTextureSize(128, 128);
ToRLeft.mirror = true;
setRotation(ToRLeft, 0F, 0F, 0F);
BToRRight = new ModelRenderer(this, 0, 30);
BToRRight.addBox(0F, 0F, 0F, 2, 1, 4);
BToRRight.setRotationPoint(6F, 18F, -2F);
BToRRight.setTextureSize(128, 128);
BToRRight.mirror = true;
setRotation(BToRRight, 0F, 0F, 0F);
BoRLeft = new ModelRenderer(this, 7, 22);
BoRLeft.addBox(0F, 0F, 0F, 2, 6, 1);
BoRLeft.setRotationPoint(3F, 13F, 2F);
BoRLeft.setTextureSize(128, 128);
BoRLeft.mirror = true;
setRotation(BoRLeft, 0F, 0F, 0F);
ToRRight = new ModelRenderer(this, 0, 36);
ToRRight.addBox(0F, 0F, 0F, 2, 1, 4);
ToRRight.setRotationPoint(6F, 13F, -2F);
ToRRight.setTextureSize(128, 128);
ToRRight.mirror = true;
setRotation(ToRRight, 0F, 0F, 0F);
FoRLeft = new ModelRenderer(this, 0, 22);
FoRLeft.addBox(0F, 0F, 0F, 2, 6, 1);
FoRLeft.setRotationPoint(3F, 13F, -3F);
FoRLeft.setTextureSize(128, 128);
FoRLeft.mirror = true;
setRotation(FoRLeft, 0F, 0F, 0F);
BoRRight = new ModelRenderer(this, 7, 22);
BoRRight.addBox(0F, 0F, 0F, 2, 6, 1);
BoRRight.setRotationPoint(6F, 13F, 2F);
BoRRight.setTextureSize(128, 128);
BoRRight.mirror = true;
setRotation(BoRRight, 0F, 0F, 0F);
BoLRight = new ModelRenderer(this, 0, 45);
BoLRight.addBox(0F, 0F, 0F, 2, 6, 1);
BoLRight.setRotationPoint(-5F, 13F, 2F);
BoLRight.setTextureSize(128, 128);
BoLRight.mirror = true;
setRotation(BoLRight, 0F, 0F, 0F);
BToLRight = new ModelRenderer(this, 0, 53);
BToLRight.addBox(0F, 0F, 0F, 2, 1, 4);
BToLRight.setRotationPoint(-5F, 18F, -2F);
BToLRight.setTextureSize(128, 128);
BToLRight.mirror = true;
setRotation(BToLRight, 0F, 0F, 0F);
FoLLeft = new ModelRenderer(this, 7, 45);
FoLLeft.addBox(0F, 0F, 0F, 2, 6, 1);
FoLLeft.setRotationPoint(-8F, 13F, -3F);
FoLLeft.setTextureSize(128, 128);
FoLLeft.mirror = true;
setRotation(FoLLeft, 0F, 0F, 0F);
ToLRight = new ModelRenderer(this, 0, 59);
ToLRight.addBox(0F, 0F, 0F, 2, 1, 4);
ToLRight.setRotationPoint(-5F, 13F, -2F);
ToLRight.setTextureSize(128, 128);
ToLRight.mirror = true;
setRotation(ToLRight, 0F, 0F, 0F);
FoLRight = new ModelRenderer(this, 7, 45);
FoLRight.addBox(0F, 0F, 0F, 2, 6, 1);
FoLRight.setRotationPoint(-5F, 13F, -3F);
FoLRight.setTextureSize(128, 128);
FoLRight.mirror = true;
setRotation(FoLRight, 0F, 0F, 0F);
BoLLeft = new ModelRenderer(this, 0, 45);
BoLLeft.addBox(0F, 0F, 0F, 2, 6, 1);
BoLLeft.setRotationPoint(-8F, 13F, 2F);
BoLLeft.setTextureSize(128, 128);
BoLLeft.mirror = true;
setRotation(BoLLeft, 0F, 0F, 0F);
ToLLeft = new ModelRenderer(this, 0, 59);
ToLLeft.addBox(0F, 0F, 0F, 2, 1, 4);
ToLLeft.setRotationPoint(-8F, 13F, -2F);
ToLLeft.setTextureSize(128, 128);
ToLLeft.mirror = true;
setRotation(ToLLeft, 0F, 0F, 0F);
BToLLeft = new ModelRenderer(this, 0, 53);
BToLLeft.addBox(0F, 0F, 0F, 2, 1, 4);
BToLLeft.setRotationPoint(-8F, 18F, -2F);
BToLLeft.setTextureSize(128, 128);
BToLLeft.mirror = true;
setRotation(BToLLeft, 0F, 0F, 0F);
}
public void renderMiddle(float f5)
{
Middle.render(f5);
}
public void renderBottom(float f5)
{
ToBLeft.render(f5);
BoBLeft.render(f5);
ToBRight.render(f5);
BoBRight.render(f5);
BoBFront.render(f5);
BoBBack.render(f5);
ToBFront.render(f5);
ToBBack.render(f5);
}
public void renderTop(float f5)
{
BoTLeft.render(f5);
ToTRight.render(f5);
BoTRight.render(f5);
BoTFront.render(f5);
ToTLeft.render(f5);
BoTBack.render(f5);
ToTBack.render(f5);
ToTFront.render(f5);
}
public void renderLeft(float f5)
{
BoLRight.render(f5);
BToLRight.render(f5);
FoLLeft.render(f5);
ToLRight.render(f5);
FoLRight.render(f5);
BoLLeft.render(f5);
ToLLeft.render(f5);
BToLLeft.render(f5);
}
public void renderRight(float f5)
{
BToRLeft.render(f5);
FoRRight.render(f5);
ToRLeft.render(f5);
BToRRight.render(f5);
BoRLeft.render(f5);
ToRRight.render(f5);
FoRLeft.render(f5);
BoRRight.render(f5);
}
public void renderBack(float f5)
{
BoBackBack.render(f5);
ToBackBack.render(f5);
RoBackBack.render(f5);
RoBackFront.render(f5);
LoBackFront.render(f5);
BoBackFront.render(f5);
ToBackFront.render(f5);
LoBackFront2.render(f5);
}
public void renderFront(float f5)
{
LoFFront.render(f5);
BoFBack.render(f5);
RoFFront.render(f5);
BoFFront.render(f5);
ToFBack.render(f5);
ToFFront.render(f5);
RoFBack.render(f5);
LoFBack.render(f5);
}
private void setRotation(ModelRenderer model, float x, float y, float z)
{
model.rotateAngleX = x;
model.rotateAngleY = y;
model.rotateAngleZ = z;
}
@Override
public void setRotationAngles(float x, float y, float z, float f3, float f4, float f5, Entity entity)
{
super.setRotationAngles(x, y, z, f3, f4, f5, entity);
}
}

View file

@ -0,0 +1,75 @@
package mekanism.induction.client.model;
import net.minecraft.client.model.ModelBase;
import net.minecraft.client.model.ModelRenderer;
public class ModelMultimeter extends ModelBase
{
// fields
ModelRenderer Base;
ModelRenderer secPanel;
ModelRenderer arm;
ModelRenderer button;
ModelRenderer arm2;
ModelRenderer infopanel;
public ModelMultimeter()
{
textureWidth = 128;
textureHeight = 128;
Base = new ModelRenderer(this, 0, 0);
Base.addBox(0F, 0F, 0F, 14, 14, 1);
Base.setRotationPoint(-7F, 9F, 7F);
Base.setTextureSize(128, 128);
Base.mirror = true;
setRotation(Base, 0F, 0F, 0F);
secPanel = new ModelRenderer(this, 0, 18);
secPanel.addBox(0F, 0F, 0F, 4, 8, 1);
secPanel.setRotationPoint(-6F, 10F, 6F);
secPanel.setTextureSize(128, 128);
secPanel.mirror = true;
setRotation(secPanel, 0F, 0F, 0F);
arm = new ModelRenderer(this, 0, 29);
arm.addBox(0F, 0F, 0F, 1, 9, 2);
arm.setRotationPoint(-3.5F, 13F, 5.5F);
arm.setTextureSize(128, 128);
arm.mirror = true;
setRotation(arm, 0F, 0F, 0F);
button = new ModelRenderer(this, 0, 43);
button.addBox(0F, 0F, 0F, 2, 1, 1);
button.setRotationPoint(-5F, 11F, 5.5F);
button.setTextureSize(128, 128);
button.mirror = true;
setRotation(button, 0F, 0F, 0F);
arm2 = new ModelRenderer(this, 10, 29);
arm2.addBox(0F, 0F, 0F, 1, 9, 2);
arm2.setRotationPoint(-5.5F, 13F, 5.5F);
arm2.setTextureSize(128, 128);
arm2.mirror = true;
setRotation(arm2, 0F, 0F, 0F);
infopanel = new ModelRenderer(this, 33, 0);
infopanel.addBox(0F, 0F, 0F, 7, 12, 1);
infopanel.setRotationPoint(-1F, 10F, 6.5F);
infopanel.setTextureSize(128, 128);
infopanel.mirror = true;
setRotation(infopanel, 0F, 0F, 0F);
}
public void render(float f5)
{
Base.render(f5);
secPanel.render(f5);
arm.render(f5);
button.render(f5);
arm2.render(f5);
infopanel.render(f5);
}
private void setRotation(ModelRenderer model, float x, float y, float z)
{
model.rotateAngleX = x;
model.rotateAngleY = y;
model.rotateAngleZ = z;
}
}

View file

@ -0,0 +1,206 @@
package mekanism.induction.client.model;
import net.minecraft.client.model.ModelBase;
import net.minecraft.client.model.ModelRenderer;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class ModelTeslaBottom extends ModelBase
{
// fields
ModelRenderer Base;
ModelRenderer BackBottomSide;
ModelRenderer FrontBottomSide;
ModelRenderer SlantedFrontPanel;
ModelRenderer SlantedPanelBase;
ModelRenderer TopBase;
ModelRenderer FrontTopPole;
ModelRenderer SideTopPole;
ModelRenderer LeftAntennae;
ModelRenderer RightAntennae;
ModelRenderer BackAntennae;
ModelRenderer FrontAntennae;
ModelRenderer TopBasePanel;
ModelRenderer ChargePack;
ModelRenderer WireLeftBottomPole;
ModelRenderer WireLeftTopPole;
ModelRenderer WireRightBottomPole;
ModelRenderer WireRightTopPole;
ModelRenderer BackRightConnector;
ModelRenderer BackLeftConnector;
ModelRenderer FrontLeftConnector;
ModelRenderer FrontRightConnector;
public ModelTeslaBottom()
{
textureWidth = 128;
textureHeight = 128;
Base = new ModelRenderer(this, 0, 0);
Base.addBox(0F, 0F, 0F, 9, 10, 9);
Base.setRotationPoint(-4.5F, 14F, -4.5F);
Base.setTextureSize(128, 128);
Base.mirror = true;
setRotation(Base, 0F, 0F, 0F);
BackBottomSide = new ModelRenderer(this, 38, 0);
BackBottomSide.addBox(0F, 0F, 0F, 11, 7, 2);
BackBottomSide.setRotationPoint(-5.5F, 17F, 1F);
BackBottomSide.setTextureSize(128, 128);
BackBottomSide.mirror = true;
setRotation(BackBottomSide, 0F, 0F, 0F);
FrontBottomSide = new ModelRenderer(this, 38, 0);
FrontBottomSide.addBox(0F, 0F, 0F, 11, 7, 2);
FrontBottomSide.setRotationPoint(-5.5F, 17F, -3F);
FrontBottomSide.setTextureSize(128, 128);
FrontBottomSide.mirror = true;
setRotation(FrontBottomSide, 0F, 0F, 0F);
SlantedFrontPanel = new ModelRenderer(this, 38, 10);
SlantedFrontPanel.addBox(0F, 0F, 0F, 4, 6, 2);
SlantedFrontPanel.setRotationPoint(-2F, 17F, -4F);
SlantedFrontPanel.setTextureSize(128, 128);
SlantedFrontPanel.mirror = true;
setRotation(SlantedFrontPanel, -0.4234231F, 0F, 0F);
SlantedPanelBase = new ModelRenderer(this, 51, 10);
SlantedPanelBase.addBox(0F, 0F, 0F, 6, 3, 2);
SlantedPanelBase.setRotationPoint(-3F, 21F, -6.5F);
SlantedPanelBase.setTextureSize(128, 128);
SlantedPanelBase.mirror = true;
setRotation(SlantedPanelBase, 0F, 0F, 0F);
TopBase = new ModelRenderer(this, 0, 20);
TopBase.addBox(0F, 0F, 0F, 6, 5, 6);
TopBase.setRotationPoint(-3F, 9F, -3F);
TopBase.setTextureSize(128, 128);
TopBase.mirror = true;
setRotation(TopBase, 0F, 0F, 0F);
FrontTopPole = new ModelRenderer(this, 0, 32);
FrontTopPole.addBox(0F, 0F, 0F, 2, 2, 8);
FrontTopPole.setRotationPoint(-1F, 10F, -4F);
FrontTopPole.setTextureSize(128, 128);
FrontTopPole.mirror = true;
setRotation(FrontTopPole, 0F, 0F, 0F);
SideTopPole = new ModelRenderer(this, 0, 43);
SideTopPole.addBox(0F, 0F, 0F, 8, 2, 2);
SideTopPole.setRotationPoint(-4F, 10F, -1F);
SideTopPole.setTextureSize(128, 128);
SideTopPole.mirror = true;
setRotation(SideTopPole, 0F, 0F, 0F);
LeftAntennae = new ModelRenderer(this, 25, 20);
LeftAntennae.addBox(0F, 0F, 0F, 1, 3, 1);
LeftAntennae.setRotationPoint(-4.5F, 8.8F, -0.5F);
LeftAntennae.setTextureSize(128, 128);
LeftAntennae.mirror = true;
setRotation(LeftAntennae, 0F, 0F, 0F);
RightAntennae = new ModelRenderer(this, 30, 20);
RightAntennae.addBox(0F, 0F, 0F, 1, 3, 1);
RightAntennae.setRotationPoint(3.5F, 8.8F, -0.5F);
RightAntennae.setTextureSize(128, 128);
RightAntennae.mirror = true;
setRotation(RightAntennae, 0F, 0F, 0F);
BackAntennae = new ModelRenderer(this, 25, 25);
BackAntennae.addBox(0F, 0F, 0F, 1, 3, 1);
BackAntennae.setRotationPoint(-0.5F, 8.8F, 3.5F);
BackAntennae.setTextureSize(128, 128);
BackAntennae.mirror = true;
setRotation(BackAntennae, 0F, 0F, 0F);
FrontAntennae = new ModelRenderer(this, 30, 25);
FrontAntennae.addBox(0F, 0F, 0F, 1, 3, 1);
FrontAntennae.setRotationPoint(-0.5F, 8.8F, -4.5F);
FrontAntennae.setTextureSize(128, 128);
FrontAntennae.mirror = true;
setRotation(FrontAntennae, 0F, 0F, 0F);
TopBasePanel = new ModelRenderer(this, 36, 20);
TopBasePanel.addBox(0F, 0F, 0F, 7, 1, 7);
TopBasePanel.setRotationPoint(-3.5F, 13F, -3.5F);
TopBasePanel.setTextureSize(128, 128);
TopBasePanel.mirror = true;
setRotation(TopBasePanel, 0F, 0F, 0F);
ChargePack = new ModelRenderer(this, 37, 29);
ChargePack.addBox(0F, 0F, 0F, 6, 7, 3);
ChargePack.setRotationPoint(-3F, 17F, 3.5F);
ChargePack.setTextureSize(128, 128);
ChargePack.mirror = true;
setRotation(ChargePack, 0F, 0F, 0F);
WireLeftBottomPole = new ModelRenderer(this, 21, 32);
WireLeftBottomPole.addBox(0F, 0F, 0F, 1, 10, 1);
WireLeftBottomPole.setRotationPoint(-2F, 11.86667F, 6F);
WireLeftBottomPole.setTextureSize(128, 128);
WireLeftBottomPole.mirror = true;
setRotation(WireLeftBottomPole, 0F, 0F, 0F);
WireLeftTopPole = new ModelRenderer(this, 26, 32);
WireLeftTopPole.addBox(0F, 0F, 0F, 1, 1, 4);
WireLeftTopPole.setRotationPoint(-2F, 10.86667F, 3F);
WireLeftTopPole.setTextureSize(128, 128);
WireLeftTopPole.mirror = true;
setRotation(WireLeftTopPole, 0F, 0F, 0F);
WireRightBottomPole = new ModelRenderer(this, 21, 32);
WireRightBottomPole.addBox(0F, 0F, 0F, 1, 10, 1);
WireRightBottomPole.setRotationPoint(1F, 11.86667F, 6F);
WireRightBottomPole.setTextureSize(128, 128);
WireRightBottomPole.mirror = true;
setRotation(WireRightBottomPole, 0F, 0F, 0F);
WireRightTopPole = new ModelRenderer(this, 26, 38);
WireRightTopPole.addBox(0F, 0F, 0F, 1, 1, 4);
WireRightTopPole.setRotationPoint(1F, 10.86667F, 3F);
WireRightTopPole.setTextureSize(128, 128);
WireRightTopPole.mirror = true;
setRotation(WireRightTopPole, 0F, 0F, 0F);
BackRightConnector = new ModelRenderer(this, 65, 0);
BackRightConnector.addBox(0F, 0F, 0F, 1, 1, 1);
BackRightConnector.setRotationPoint(1F, 8F, 1.066667F);
BackRightConnector.setTextureSize(128, 128);
BackRightConnector.mirror = true;
setRotation(BackRightConnector, 0F, 0F, 0F);
BackLeftConnector = new ModelRenderer(this, 65, 0);
BackLeftConnector.addBox(0F, 0F, 0F, 1, 1, 1);
BackLeftConnector.setRotationPoint(-2F, 8F, 1F);
BackLeftConnector.setTextureSize(128, 128);
BackLeftConnector.mirror = true;
setRotation(BackLeftConnector, 0F, 0F, 0F);
FrontLeftConnector = new ModelRenderer(this, 65, 0);
FrontLeftConnector.addBox(0F, 0F, 0F, 1, 1, 1);
FrontLeftConnector.setRotationPoint(-2F, 8F, -2F);
FrontLeftConnector.setTextureSize(128, 128);
FrontLeftConnector.mirror = true;
setRotation(FrontLeftConnector, 0F, 0F, 0F);
FrontRightConnector = new ModelRenderer(this, 65, 0);
FrontRightConnector.addBox(0F, 0F, 0F, 1, 1, 1);
FrontRightConnector.setRotationPoint(1F, 8F, -2F);
FrontRightConnector.setTextureSize(128, 128);
FrontRightConnector.mirror = true;
setRotation(FrontRightConnector, 0F, 0F, 0F);
}
public void render(float f5)
{
Base.render(f5);
BackBottomSide.render(f5);
FrontBottomSide.render(f5);
SlantedFrontPanel.render(f5);
SlantedPanelBase.render(f5);
TopBase.render(f5);
FrontTopPole.render(f5);
SideTopPole.render(f5);
LeftAntennae.render(f5);
RightAntennae.render(f5);
BackAntennae.render(f5);
FrontAntennae.render(f5);
TopBasePanel.render(f5);
ChargePack.render(f5);
WireLeftBottomPole.render(f5);
WireLeftTopPole.render(f5);
WireRightBottomPole.render(f5);
WireRightTopPole.render(f5);
BackRightConnector.render(f5);
BackLeftConnector.render(f5);
FrontLeftConnector.render(f5);
FrontRightConnector.render(f5);
}
private void setRotation(ModelRenderer model, float x, float y, float z)
{
model.rotateAngleX = x;
model.rotateAngleY = y;
model.rotateAngleZ = z;
}
}

View file

@ -0,0 +1,215 @@
package mekanism.induction.client.model;
import net.minecraft.client.model.ModelBase;
import net.minecraft.client.model.ModelRenderer;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class ModelTeslaMiddle extends ModelBase
{
// fields
ModelRenderer Base;
ModelRenderer Collumn1;
ModelRenderer Collumn2;
ModelRenderer CrossCollumn1;
ModelRenderer Collumn3;
ModelRenderer Ball;
ModelRenderer Plate;
ModelRenderer TopBase;
ModelRenderer FrontPole;
ModelRenderer SidePole;
ModelRenderer FrontAntennae;
ModelRenderer BackAntennae;
ModelRenderer LeftAntennae;
ModelRenderer RightAntennae;
ModelRenderer CrossCollumn2;
ModelRenderer CrossCollumn3;
ModelRenderer Collumn4;
ModelRenderer CrossCollumn4;
ModelRenderer BallStand;
ModelRenderer FrontTopLeftPole;
ModelRenderer FrontTopRightPole;
ModelRenderer SideTopFirstPole;
ModelRenderer SodeTopLastPole;
public ModelTeslaMiddle()
{
textureWidth = 128;
textureHeight = 128;
Base = new ModelRenderer(this, 0, 0);
Base.addBox(0F, 0F, 0F, 6, 6, 6);
Base.setRotationPoint(-3F, 18F, -3F);
Base.setTextureSize(128, 128);
Base.mirror = true;
setRotation(Base, 0F, 0F, 0F);
Collumn1 = new ModelRenderer(this, 0, 20);
Collumn1.addBox(0F, 0F, 0F, 1, 4, 1);
Collumn1.setRotationPoint(-3F, 14F, -3F);
Collumn1.setTextureSize(128, 128);
Collumn1.mirror = true;
setRotation(Collumn1, 0F, 0F, 0F);
Collumn2 = new ModelRenderer(this, 0, 20);
Collumn2.addBox(0F, 0F, 0F, 1, 4, 1);
Collumn2.setRotationPoint(2F, 14F, -3F);
Collumn2.setTextureSize(128, 128);
Collumn2.mirror = true;
setRotation(Collumn2, 0F, 0F, 0F);
CrossCollumn1 = new ModelRenderer(this, 5, 20);
CrossCollumn1.addBox(0F, 0F, 0F, 4, 1, 1);
CrossCollumn1.setRotationPoint(-2F, 15.5F, -3F);
CrossCollumn1.setTextureSize(128, 128);
CrossCollumn1.mirror = true;
setRotation(CrossCollumn1, 0F, 0F, 0F);
Collumn3 = new ModelRenderer(this, 0, 20);
Collumn3.addBox(0F, 0F, 0F, 1, 4, 1);
Collumn3.setRotationPoint(2F, 14F, 2F);
Collumn3.setTextureSize(128, 128);
Collumn3.mirror = true;
setRotation(Collumn3, 0F, 0F, 0F);
Ball = new ModelRenderer(this, 0, 15);
Ball.addBox(-1F, -1F, -1F, 2, 2, 2);
Ball.setRotationPoint(0F, 16F, 0F);
Ball.setTextureSize(128, 128);
Ball.mirror = true;
setRotation(Ball, 0F, 0F, 0F);
Plate = new ModelRenderer(this, 25, 0);
Plate.addBox(0F, 0F, 0F, 7, 1, 7);
Plate.setRotationPoint(-3.5F, 13F, -3.5F);
Plate.setTextureSize(128, 128);
Plate.mirror = true;
setRotation(Plate, 0F, 0F, 0F);
TopBase = new ModelRenderer(this, 25, 9);
TopBase.addBox(0F, 0F, 0F, 4, 5, 4);
TopBase.setRotationPoint(-2F, 8F, -2F);
TopBase.setTextureSize(128, 128);
TopBase.mirror = true;
setRotation(TopBase, 0F, 0F, 0F);
FrontPole = new ModelRenderer(this, 0, 26);
FrontPole.addBox(0F, 0F, 0F, 2, 2, 8);
FrontPole.setRotationPoint(-1F, 20F, -4F);
FrontPole.setTextureSize(128, 128);
FrontPole.mirror = true;
setRotation(FrontPole, 0F, 0F, 0F);
SidePole = new ModelRenderer(this, 0, 37);
SidePole.addBox(0F, 0F, 0F, 8, 2, 2);
SidePole.setRotationPoint(-4F, 20F, -1F);
SidePole.setTextureSize(128, 128);
SidePole.mirror = true;
setRotation(SidePole, 0F, 0F, 0F);
FrontAntennae = new ModelRenderer(this, 25, 19);
FrontAntennae.addBox(0F, 0F, 0F, 1, 3, 1);
FrontAntennae.setRotationPoint(-0.5F, 18.8F, -4.466667F);
FrontAntennae.setTextureSize(128, 128);
FrontAntennae.mirror = true;
setRotation(FrontAntennae, 0F, 0F, 0F);
BackAntennae = new ModelRenderer(this, 25, 19);
BackAntennae.addBox(0F, 0F, 0F, 1, 3, 1);
BackAntennae.setRotationPoint(-0.5F, 18.8F, 3.533333F);
BackAntennae.setTextureSize(128, 128);
BackAntennae.mirror = true;
setRotation(BackAntennae, 0F, 0F, 0F);
LeftAntennae = new ModelRenderer(this, 25, 19);
LeftAntennae.addBox(0F, 0F, 0F, 1, 3, 1);
LeftAntennae.setRotationPoint(-4.5F, 18.8F, -0.5F);
LeftAntennae.setTextureSize(128, 128);
LeftAntennae.mirror = true;
setRotation(LeftAntennae, 0F, 0F, 0F);
RightAntennae = new ModelRenderer(this, 25, 19);
RightAntennae.addBox(0F, 0F, 0F, 1, 3, 1);
RightAntennae.setRotationPoint(3.5F, 18.8F, -0.5F);
RightAntennae.setTextureSize(128, 128);
RightAntennae.mirror = true;
setRotation(RightAntennae, 0F, 0F, 0F);
CrossCollumn2 = new ModelRenderer(this, 30, 19);
CrossCollumn2.addBox(0F, 0F, 0F, 1, 1, 4);
CrossCollumn2.setRotationPoint(2F, 15.5F, -2F);
CrossCollumn2.setTextureSize(128, 128);
CrossCollumn2.mirror = true;
setRotation(CrossCollumn2, 0F, 0F, 0F);
CrossCollumn3 = new ModelRenderer(this, 5, 20);
CrossCollumn3.addBox(0F, 0F, 0F, 4, 1, 1);
CrossCollumn3.setRotationPoint(-2F, 15.5F, 2F);
CrossCollumn3.setTextureSize(128, 128);
CrossCollumn3.mirror = true;
setRotation(CrossCollumn3, 0F, 0F, 0F);
Collumn4 = new ModelRenderer(this, 0, 20);
Collumn4.addBox(0F, 0F, 0F, 1, 4, 1);
Collumn4.setRotationPoint(-3F, 14F, 2F);
Collumn4.setTextureSize(128, 128);
Collumn4.mirror = true;
setRotation(Collumn4, 0F, 0F, 0F);
CrossCollumn4 = new ModelRenderer(this, 30, 19);
CrossCollumn4.addBox(0F, 0F, 0F, 1, 1, 4);
CrossCollumn4.setRotationPoint(-3F, 15.5F, -2F);
CrossCollumn4.setTextureSize(128, 128);
CrossCollumn4.mirror = true;
setRotation(CrossCollumn4, 0F, 0F, 0F);
BallStand = new ModelRenderer(this, 9, 16);
BallStand.addBox(0F, 0F, 0F, 1, 1, 1);
BallStand.setRotationPoint(-0.5F, 17F, -0.5F);
BallStand.setTextureSize(128, 128);
BallStand.mirror = true;
setRotation(BallStand, 0F, 0F, 0F);
FrontTopLeftPole = new ModelRenderer(this, 42, 9);
FrontTopLeftPole.addBox(0F, 0F, 0F, 1, 4, 5);
FrontTopLeftPole.setRotationPoint(-1.5F, 9F, -2.5F);
FrontTopLeftPole.setTextureSize(128, 128);
FrontTopLeftPole.mirror = true;
setRotation(FrontTopLeftPole, 0F, 0F, 0F);
FrontTopRightPole = new ModelRenderer(this, 42, 9);
FrontTopRightPole.addBox(0F, 0F, 0F, 1, 4, 5);
FrontTopRightPole.setRotationPoint(0.5F, 9F, -2.5F);
FrontTopRightPole.setTextureSize(128, 128);
FrontTopRightPole.mirror = true;
setRotation(FrontTopRightPole, 0F, 0F, 0F);
SideTopFirstPole = new ModelRenderer(this, 42, 19);
SideTopFirstPole.addBox(0F, 0F, 0F, 5, 4, 1);
SideTopFirstPole.setRotationPoint(-2.5F, 9F, -1.5F);
SideTopFirstPole.setTextureSize(128, 128);
SideTopFirstPole.mirror = true;
setRotation(SideTopFirstPole, 0F, 0F, 0F);
SodeTopLastPole = new ModelRenderer(this, 42, 19);
SodeTopLastPole.addBox(0F, 0F, 0F, 5, 4, 1);
SodeTopLastPole.setRotationPoint(-2.5F, 9F, 0.5F);
SodeTopLastPole.setTextureSize(128, 128);
SodeTopLastPole.mirror = true;
setRotation(SodeTopLastPole, 0F, 0F, 0F);
}
public void render(float f5)
{
Base.render(f5);
Collumn1.render(f5);
Collumn2.render(f5);
CrossCollumn1.render(f5);
Collumn3.render(f5);
Ball.render(f5);
Plate.render(f5);
TopBase.render(f5);
FrontPole.render(f5);
SidePole.render(f5);
FrontAntennae.render(f5);
BackAntennae.render(f5);
LeftAntennae.render(f5);
RightAntennae.render(f5);
CrossCollumn2.render(f5);
CrossCollumn3.render(f5);
Collumn4.render(f5);
CrossCollumn4.render(f5);
BallStand.render(f5);
FrontTopLeftPole.render(f5);
FrontTopRightPole.render(f5);
SideTopFirstPole.render(f5);
SodeTopLastPole.render(f5);
}
private void setRotation(ModelRenderer model, float x, float y, float z)
{
model.rotateAngleX = x;
model.rotateAngleY = y;
model.rotateAngleZ = z;
}
}

View file

@ -0,0 +1,204 @@
package mekanism.induction.client.model;
import net.minecraft.client.model.ModelBase;
import net.minecraft.client.model.ModelRenderer;
public class ModelTeslaTop extends ModelBase
{
// fields
ModelRenderer Base;
ModelRenderer Collumn1;
ModelRenderer Collumn2;
ModelRenderer Collumn3;
ModelRenderer Collumn4;
ModelRenderer CrossCollumn1;
ModelRenderer CrossCollumn2;
ModelRenderer CrossCollumn3;
ModelRenderer CrossCollumn4;
ModelRenderer CrossCollumn5;
ModelRenderer CrossCollumn6;
ModelRenderer CrossCollumn7;
ModelRenderer CrossCollumn8;
ModelRenderer HolderLeft;
ModelRenderer FrontCoil;
ModelRenderer RightCoil;
ModelRenderer BackCoil;
ModelRenderer LeftCoil;
ModelRenderer LFSCoil;
ModelRenderer RFSCoil;
ModelRenderer RBSCoil;
ModelRenderer LBSCoil;
public ModelTeslaTop()
{
textureWidth = 128;
textureHeight = 128;
Base = new ModelRenderer(this, 0, 0);
Base.addBox(0F, 0F, 0F, 4, 4, 4);
Base.setRotationPoint(-2F, 20F, -2F);
Base.setTextureSize(128, 128);
Base.mirror = true;
setRotation(Base, 0F, 0F, 0F);
Collumn1 = new ModelRenderer(this, 0, 9);
Collumn1.addBox(0F, 0F, 0F, 1, 6, 1);
Collumn1.setRotationPoint(1F, 14F, 1F);
Collumn1.setTextureSize(128, 128);
Collumn1.mirror = true;
setRotation(Collumn1, 0F, 0F, 0F);
Collumn2 = new ModelRenderer(this, 0, 9);
Collumn2.addBox(0F, 0F, 0F, 1, 6, 1);
Collumn2.setRotationPoint(1F, 14F, -2F);
Collumn2.setTextureSize(128, 128);
Collumn2.mirror = true;
setRotation(Collumn2, 0F, 0F, 0F);
Collumn3 = new ModelRenderer(this, 0, 9);
Collumn3.addBox(0F, 0F, 0F, 1, 6, 1);
Collumn3.setRotationPoint(-2F, 14F, -2F);
Collumn3.setTextureSize(128, 128);
Collumn3.mirror = true;
setRotation(Collumn3, 0F, 0F, 0F);
Collumn4 = new ModelRenderer(this, 0, 9);
Collumn4.addBox(0F, 0F, 0F, 1, 6, 1);
Collumn4.setRotationPoint(-2F, 14F, 1F);
Collumn4.setTextureSize(128, 128);
Collumn4.mirror = true;
setRotation(Collumn4, 0F, 0F, 0F);
CrossCollumn1 = new ModelRenderer(this, 17, 0);
CrossCollumn1.addBox(0F, 0F, 0F, 1, 1, 2);
CrossCollumn1.setRotationPoint(-2F, 16.5F, -1F);
CrossCollumn1.setTextureSize(128, 128);
CrossCollumn1.mirror = true;
setRotation(CrossCollumn1, 0F, 0F, 0F);
CrossCollumn2 = new ModelRenderer(this, 17, 0);
CrossCollumn2.addBox(0F, 0F, 0F, 2, 1, 1);
CrossCollumn2.setRotationPoint(-1F, 15.5F, -2F);
CrossCollumn2.setTextureSize(128, 128);
CrossCollumn2.mirror = true;
setRotation(CrossCollumn2, 0F, 0F, 0F);
CrossCollumn3 = new ModelRenderer(this, 17, 0);
CrossCollumn3.addBox(0F, 0F, 0F, 1, 1, 2);
CrossCollumn3.setRotationPoint(-2F, 14.5F, -1F);
CrossCollumn3.setTextureSize(128, 128);
CrossCollumn3.mirror = true;
setRotation(CrossCollumn3, 0F, 0F, 0F);
CrossCollumn4 = new ModelRenderer(this, 17, 0);
CrossCollumn4.addBox(0F, 0F, 0F, 1, 1, 2);
CrossCollumn4.setRotationPoint(1F, 14.5F, -1F);
CrossCollumn4.setTextureSize(128, 128);
CrossCollumn4.mirror = true;
setRotation(CrossCollumn4, 0F, 0F, 0F);
CrossCollumn5 = new ModelRenderer(this, 17, 0);
CrossCollumn5.addBox(0F, 0F, 0F, 1, 1, 2);
CrossCollumn5.setRotationPoint(1F, 16.5F, -1F);
CrossCollumn5.setTextureSize(128, 128);
CrossCollumn5.mirror = true;
setRotation(CrossCollumn5, 0F, 0F, 0F);
CrossCollumn6 = new ModelRenderer(this, 17, 0);
CrossCollumn6.addBox(0F, 0F, 0F, 2, 1, 1);
CrossCollumn6.setRotationPoint(-1F, 15.5F, 1F);
CrossCollumn6.setTextureSize(128, 128);
CrossCollumn6.mirror = true;
setRotation(CrossCollumn6, 0F, 0F, 0F);
CrossCollumn7 = new ModelRenderer(this, 17, 0);
CrossCollumn7.addBox(0F, 0F, 0F, 2, 1, 1);
CrossCollumn7.setRotationPoint(-1F, 17.5F, -2F);
CrossCollumn7.setTextureSize(128, 128);
CrossCollumn7.mirror = true;
setRotation(CrossCollumn7, 0F, 0F, 0F);
CrossCollumn8 = new ModelRenderer(this, 17, 0);
CrossCollumn8.addBox(0F, 0F, 0F, 2, 1, 1);
CrossCollumn8.setRotationPoint(-1F, 17.5F, 1F);
CrossCollumn8.setTextureSize(128, 128);
CrossCollumn8.mirror = true;
setRotation(CrossCollumn8, 0F, 0F, 0F);
HolderLeft = new ModelRenderer(this, 5, 9);
HolderLeft.addBox(0F, 0F, 0F, 2, 5, 2);
HolderLeft.setRotationPoint(-1F, 10.5F, -1F);
HolderLeft.setTextureSize(128, 128);
HolderLeft.mirror = true;
setRotation(HolderLeft, 0F, 0F, 0F);
FrontCoil = new ModelRenderer(this, 26, 0);
FrontCoil.addBox(0F, 0F, 0F, 6, 2, 1);
FrontCoil.setRotationPoint(-3F, 11F, -4F);
FrontCoil.setTextureSize(128, 128);
FrontCoil.mirror = true;
setRotation(FrontCoil, 0F, 0F, 0F);
RightCoil = new ModelRenderer(this, 26, 4);
RightCoil.addBox(0F, 0F, 0F, 1, 2, 6);
RightCoil.setRotationPoint(3F, 11.02222F, -3F);
RightCoil.setTextureSize(128, 128);
RightCoil.mirror = true;
setRotation(RightCoil, 0F, 0F, 0F);
BackCoil = new ModelRenderer(this, 26, 0);
BackCoil.addBox(0F, 0F, 0F, 6, 2, 1);
BackCoil.setRotationPoint(-3F, 11F, 3F);
BackCoil.setTextureSize(128, 128);
BackCoil.mirror = true;
setRotation(BackCoil, 0F, 0F, 0F);
LeftCoil = new ModelRenderer(this, 26, 4);
LeftCoil.addBox(0F, 0F, 0F, 1, 2, 6);
LeftCoil.setRotationPoint(-4F, 11.02222F, -3F);
LeftCoil.setTextureSize(128, 128);
LeftCoil.mirror = true;
setRotation(LeftCoil, 0F, 0F, 0F);
LFSCoil = new ModelRenderer(this, 0, 20);
LFSCoil.addBox(0F, 0F, 0F, 1, 2, 1);
LFSCoil.setRotationPoint(-3F, 11F, -3F);
LFSCoil.setTextureSize(128, 128);
LFSCoil.mirror = true;
setRotation(LFSCoil, 0F, 0F, 0F);
RFSCoil = new ModelRenderer(this, 0, 20);
RFSCoil.addBox(0F, 0F, 0F, 1, 2, 1);
RFSCoil.setRotationPoint(2F, 11F, -3F);
RFSCoil.setTextureSize(128, 128);
RFSCoil.mirror = true;
setRotation(RFSCoil, 0F, 0F, 0F);
RBSCoil = new ModelRenderer(this, 0, 20);
RBSCoil.addBox(0F, 0F, 0F, 1, 2, 1);
RBSCoil.setRotationPoint(2F, 11F, 2F);
RBSCoil.setTextureSize(128, 128);
RBSCoil.mirror = true;
setRotation(RBSCoil, 0F, 0F, 0F);
LBSCoil = new ModelRenderer(this, 0, 20);
LBSCoil.addBox(0F, 0F, 0F, 1, 2, 1);
LBSCoil.setRotationPoint(-3F, 11F, 2F);
LBSCoil.setTextureSize(128, 128);
LBSCoil.mirror = true;
setRotation(LBSCoil, 0F, 0F, 0F);
}
public void render(float f5)
{
Base.render(f5);
Collumn1.render(f5);
Collumn2.render(f5);
Collumn3.render(f5);
Collumn4.render(f5);
CrossCollumn1.render(f5);
CrossCollumn2.render(f5);
CrossCollumn3.render(f5);
CrossCollumn4.render(f5);
CrossCollumn5.render(f5);
CrossCollumn6.render(f5);
CrossCollumn7.render(f5);
CrossCollumn8.render(f5);
HolderLeft.render(f5);
FrontCoil.render(f5);
RightCoil.render(f5);
BackCoil.render(f5);
LeftCoil.render(f5);
LFSCoil.render(f5);
RFSCoil.render(f5);
RBSCoil.render(f5);
LBSCoil.render(f5);
}
private void setRotation(ModelRenderer model, float x, float y, float z)
{
model.rotateAngleX = x;
model.rotateAngleY = y;
model.rotateAngleZ = z;
}
}

View file

@ -0,0 +1,130 @@
package mekanism.induction.client.model;
import net.minecraft.client.model.ModelBase;
import net.minecraft.client.model.ModelRenderer;
import net.minecraft.entity.Entity;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class ModelWire extends ModelBase
{
// fields
ModelRenderer Middle;
ModelRenderer Right;
ModelRenderer Left;
ModelRenderer Back;
ModelRenderer Front;
ModelRenderer Top;
ModelRenderer Bottom;
public ModelWire()
{
textureWidth = 64;
textureHeight = 32;
Middle = new ModelRenderer(this, 0, 0);
Middle.addBox(-1F, -1F, -1F, 4, 4, 4);
Middle.setRotationPoint(-1F, 15F, -1F);
Middle.setTextureSize(64, 32);
Middle.mirror = true;
setRotation(Middle, 0F, 0F, 0F);
Right = new ModelRenderer(this, 21, 0);
Right.addBox(0F, 0F, 0F, 6, 4, 4);
Right.setRotationPoint(2F, 14F, -2F);
Right.setTextureSize(64, 32);
Right.mirror = true;
setRotation(Right, 0F, 0F, 0F);
Left = new ModelRenderer(this, 21, 0);
Left.addBox(0F, 0F, 0F, 6, 4, 4);
Left.setRotationPoint(-8F, 14F, -2F);
Left.setTextureSize(64, 32);
Left.mirror = true;
setRotation(Left, 0F, 0F, 0F);
Back = new ModelRenderer(this, 0, 11);
Back.addBox(0F, 0F, 0F, 4, 4, 6);
Back.setRotationPoint(-2F, 14F, 2F);
Back.setTextureSize(64, 32);
Back.mirror = true;
setRotation(Back, 0F, 0F, 0F);
Front = new ModelRenderer(this, 0, 11);
Front.addBox(0F, 0F, 0F, 4, 4, 6);
Front.setRotationPoint(-2F, 14F, -8F);
Front.setTextureSize(64, 32);
Front.mirror = true;
setRotation(Front, 0F, 0F, 0F);
Top = new ModelRenderer(this, 21, 11);
Top.addBox(0F, 0F, 0F, 4, 6, 4);
Top.setRotationPoint(-2F, 8F, -2F);
Top.setTextureSize(64, 32);
Top.mirror = true;
setRotation(Top, 0F, 0F, 0F);
Bottom = new ModelRenderer(this, 21, 11);
Bottom.addBox(0F, 0F, 0F, 4, 6, 4);
Bottom.setRotationPoint(-2F, 18F, -2F);
Bottom.setTextureSize(64, 32);
Bottom.mirror = true;
setRotation(Bottom, 0F, 0F, 0F);
}
@Override
public void render(Entity entity, float f, float f1, float f2, float f3, float f4, float f5)
{
super.render(entity, f, f1, f2, f3, f4, f5);
this.setRotationAngles(f, f1, f2, f3, f4, f5, entity);
this.renderMiddle();
this.renderBottom();
this.renderTop();
this.renderLeft();
this.renderRight();
this.renderBack();
this.renderFront();
}
public void renderMiddle()
{
Middle.render(0.0625F);
}
public void renderBottom()
{
Bottom.render(0.0625F);
}
public void renderTop()
{
Top.render(0.0625F);
}
public void renderLeft()
{
Left.render(0.0625F);
}
public void renderRight()
{
Right.render(0.0625F);
}
public void renderBack()
{
Back.render(0.0625F);
}
public void renderFront()
{
Front.render(0.0625F);
}
private void setRotation(ModelRenderer model, float x, float y, float z)
{
model.rotateAngleX = x;
model.rotateAngleY = y;
model.rotateAngleZ = z;
}
@Override
public void setRotationAngles(float x, float y, float z, float f3, float f4, float f5, Entity entity)
{
super.setRotationAngles(x, y, z, f3, f4, f5, entity);
}
}

View file

@ -0,0 +1,97 @@
/**
*
*/
package mekanism.induction.client.render;
import mekanism.induction.common.battery.BlockBattery;
import mekanism.induction.common.contractor.BlockEMContractor;
import mekanism.induction.common.multimeter.BlockMultimeter;
import mekanism.induction.common.tesla.BlockTesla;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.world.IBlockAccess;
import org.lwjgl.opengl.GL11;
import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
import cpw.mods.fml.client.registry.RenderingRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
/**
* @author Calclavia
*
*/
@SideOnly(Side.CLIENT)
public class BlockRenderingHandler implements ISimpleBlockRenderingHandler
{
public static final BlockRenderingHandler INSTANCE = new BlockRenderingHandler();
private static final int ID = RenderingRegistry.getNextAvailableRenderId();
@Override
public void renderInventoryBlock(Block block, int metadata, int modelID, RenderBlocks renderer)
{
if (block instanceof BlockTesla)
{
GL11.glPushMatrix();
GL11.glTranslated(0.5, 1.5, 0.5);
GL11.glRotatef(180F, 0.0F, 0.0F, 1.0F);
FMLClientHandler.instance().getClient().renderEngine.bindTexture(RenderTesla.TEXTURE_BOTTOM);
RenderTesla.MODEL_BOTTOM.render(0.0625f);
GL11.glPopMatrix();
}
else if (block instanceof BlockEMContractor)
{
GL11.glPushMatrix();
GL11.glTranslated(0.5, 1.5, 0.5);
GL11.glRotatef(180F, 0.0F, 0.0F, 1.0F);
FMLClientHandler.instance().getClient().renderEngine.bindTexture(RenderEMContractor.TEXTURE);
RenderEMContractor.MODEL.render(0.0625f);
GL11.glPopMatrix();
}
else if (block instanceof BlockBattery)
{
GL11.glPushMatrix();
GL11.glTranslated(0.5, 1.42, 0.5);
GL11.glRotatef(180F, 0.0F, 0.0F, 1.0F);
FMLClientHandler.instance().getClient().renderEngine.bindTexture(RenderBattery.TEXTURE);
RenderBattery.MODEL.render(0.0625f);
GL11.glPopMatrix();
}
else if (block instanceof BlockMultimeter)
{
GL11.glPushMatrix();
GL11.glRotatef(180, 0, 1, 0);
GL11.glTranslated(0, -1, -0.7);
FMLClientHandler.instance().getClient().renderEngine.bindTexture(RenderMultimeter.TEXTURE);
RenderMultimeter.MODEL.render(0.0625f);
GL11.glPopMatrix();
}
}
@Override
public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer)
{
if (block instanceof BlockBattery)
{
// FMLClientHandler.instance().getClient().renderEngine.bindTexture(RenderBattery.TEXTURE);
return true;
}
return false;
}
@Override
public boolean shouldRender3DInInventory()
{
return true;
}
@Override
public int getRenderId()
{
return ID;
}
}

View file

@ -0,0 +1,26 @@
package mekanism.induction.client.render;
import codechicken.lib.vec.Matrix4;
import codechicken.lib.vec.Transformation;
import codechicken.lib.vec.VariableTransformation;
import codechicken.lib.vec.Vector3;
public class InvertX extends VariableTransformation
{
public InvertX()
{
super(new Matrix4(-1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1));
}
@Override
public void apply(Vector3 vec)
{
this.mat.apply(vec);
}
@Override
public Transformation inverse()
{
return this;
}
}

View file

@ -0,0 +1,265 @@
/**
*
*/
package mekanism.induction.client.render;
import java.util.Random;
import mekanism.induction.client.model.ModelBattery;
import mekanism.induction.common.MekanismInduction;
import mekanism.induction.common.battery.TileEntityBattery;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.ItemRenderer;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Icon;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.ForgeDirection;
import org.lwjgl.opengl.GL11;
import universalelectricity.core.vector.Vector3;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
/**
* @author Calclavia
*
*/
@SideOnly(Side.CLIENT)
public class RenderBattery extends TileEntitySpecialRenderer
{
public static final ResourceLocation TEXTURE = new ResourceLocation(MekanismInduction.DOMAIN, MekanismInduction.MODEL_TEXTURE_DIRECTORY + "battery.png");
public static final ResourceLocation TEXTURE_MULTI = new ResourceLocation(MekanismInduction.DOMAIN, MekanismInduction.MODEL_TEXTURE_DIRECTORY + "battery_multi.png");
public static final ModelBattery MODEL = new ModelBattery();
private EntityItem fakeBattery;
private Random random = new Random();
protected RenderManager renderManager;
@Override
public void renderTileEntityAt(TileEntity t, double x, double y, double z, float f)
{
GL11.glPushMatrix();
GL11.glTranslated(x + 0.5, y + 1.5, z + 0.5);
GL11.glRotatef(180F, 0.0F, 0.0F, 1.0F);
if (((TileEntityBattery) t).structure.isMultiblock)
{
this.bindTexture(TEXTURE_MULTI);
}
else
{
this.bindTexture(TEXTURE);
}
MODEL.render(0.0625f);
/*
* GL11.glScalef(0.0625f, 0.0625f, 0.0625f); batteryModel.renderAll();
*/
GL11.glPopMatrix();
if (Minecraft.getMinecraft().gameSettings.fancyGraphics)
{
if (this.fakeBattery == null)
{
this.fakeBattery = new EntityItem(t.worldObj, 0, 0, 0, new ItemStack(MekanismInduction.itemCapacitor));
this.fakeBattery.age = 10;
}
if (this.renderManager == null)
{
this.renderManager = RenderManager.instance;
}
int renderAmount = Math.min(((TileEntityBattery) t).clientCells, 16);
if (renderAmount == 0)
{
return;
}
for (int i = 2; i < 6; i++)
{
ForgeDirection direction = ForgeDirection.getOrientation(i);
for (int slot = 0; slot < 4; slot++)
{
Vector3 sideVec = new Vector3(t).modifyPositionFromSide(correctSide(direction));
Block block = Block.blocksList[sideVec.getBlockID(t.worldObj)];
if (block != null && block.isOpaqueCube())
{
continue;
}
GL11.glPushMatrix();
GL11.glTranslatef((float) x + 0.5f, (float) y + 0.7f, (float) z + 0.5f);
float translateX = 0;
float translateY = 0;
switch (slot)
{
case 0:
translateX = 0.25f;
break;
case 1:
translateX = 0.25f;
translateY = -0.5f;
break;
case 2:
translateX = -0.25f;
translateY = -0.5f;
break;
case 3:
translateX = -0.25f;
break;
}
switch (direction)
{
case NORTH:
GL11.glTranslatef(-0.5f, 0, 0);
GL11.glTranslatef(0, translateY, translateX);
GL11.glRotatef(90, 0, 1, 0);
break;
case SOUTH:
GL11.glTranslatef(0, 0, -0.5f);
GL11.glTranslatef(translateX, translateY, 0);
break;
case WEST:
GL11.glTranslatef(0.5f, 0, 0);
GL11.glTranslatef(0, translateY, translateX);
GL11.glRotatef(90, 0, 1, 0);
break;
case EAST:
GL11.glTranslatef(0, 0, 0.5f);
GL11.glTranslatef(translateX, translateY, 0);
break;
}
GL11.glScalef(0.5f, 0.5f, 0.5f);
this.renderItemSimple(this.fakeBattery);
GL11.glPopMatrix();
if (--renderAmount <= 0)
{
return;
}
}
}
}
}
private ForgeDirection correctSide(ForgeDirection side)
{
switch (side)
{
case NORTH:
return ForgeDirection.WEST;
case SOUTH:
return ForgeDirection.NORTH;
case EAST:
return ForgeDirection.SOUTH;
case WEST:
return ForgeDirection.EAST;
default:
return null;
}
}
public void renderItemSimple(EntityItem entityItem)
{
if (entityItem != null)
{
Tessellator tessellator = Tessellator.instance;
ItemStack itemStack = entityItem.getEntityItem();
for (int k = 0; k < itemStack.getItem().getRenderPasses(itemStack.getItemDamage()); ++k)
{
Icon icon = itemStack.getItem().getIcon(itemStack, k);
if (icon == null)
{
TextureManager texturemanager = Minecraft.getMinecraft().getTextureManager();
ResourceLocation resourcelocation = texturemanager.getResourceLocation(entityItem.getEntityItem().getItemSpriteNumber());
icon = ((TextureMap) texturemanager.getTexture(resourcelocation)).getAtlasSprite("missingno");
}
float f4 = icon.getMinU();
float f5 = icon.getMaxU();
float f6 = icon.getMinV();
float f7 = icon.getMaxV();
float f8 = 1.0F;
float f9 = 0.5F;
float f10 = 0.25F;
float f11;
GL11.glPushMatrix();
float f12 = 0.0625F;
f11 = 0.021875F;
ItemStack itemstack = entityItem.getEntityItem();
int j = itemstack.stackSize;
byte b0 = getMiniItemCount(itemstack);
GL11.glTranslatef(-f9, -f10, -((f12 + f11) * b0 / 2.0F));
for (int kj = 0; kj < b0; ++kj)
{
// Makes items offset when in 3D, like when in 2D, looks much better. Considered
// a
// vanilla bug...
if (kj > 0)
{
float x = (random.nextFloat() * 2.0F - 1.0F) * 0.3F / 0.5F;
float y = (random.nextFloat() * 2.0F - 1.0F) * 0.3F / 0.5F;
float z = (random.nextFloat() * 2.0F - 1.0F) * 0.3F / 0.5F;
GL11.glTranslatef(x, y, f12 + f11);
}
else
{
GL11.glTranslatef(0f, 0f, f12 + f11);
}
if (itemstack.getItemSpriteNumber() == 0)
{
this.bindTexture(TextureMap.locationBlocksTexture);
}
else
{
this.bindTexture(TextureMap.locationItemsTexture);
}
GL11.glColor4f(1, 1, 1, 1.0F);
ItemRenderer.renderItemIn2D(tessellator, f5, f6, f4, f7, icon.getIconWidth(), icon.getIconHeight(), f12);
}
GL11.glPopMatrix();
}
}
}
public byte getMiniItemCount(ItemStack stack)
{
byte ret = 1;
if (stack.stackSize > 1)
ret = 2;
if (stack.stackSize > 15)
ret = 3;
if (stack.stackSize > 31)
ret = 4;
return ret;
}
}

View file

@ -0,0 +1,73 @@
package mekanism.induction.client.render;
import mekanism.induction.client.model.ModelEMContractor;
import mekanism.induction.common.MekanismInduction;
import mekanism.induction.common.contractor.TileEntityEMContractor;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.GL11;
public class RenderEMContractor extends TileEntitySpecialRenderer
{
public static final ModelEMContractor MODEL = new ModelEMContractor(false);
public static final ModelEMContractor MODEL_SPIN = new ModelEMContractor(true);
public static final ResourceLocation TEXTURE = new ResourceLocation(MekanismInduction.DOMAIN, MekanismInduction.MODEL_TEXTURE_DIRECTORY + "em_contractor.png");
public static final ResourceLocation TEXTURE_PUSH = new ResourceLocation(MekanismInduction.DOMAIN, MekanismInduction.MODEL_TEXTURE_DIRECTORY + "em_contractor_push.png");
@Override
public void renderTileEntityAt(TileEntity t, double x, double y, double z, float f)
{
GL11.glPushMatrix();
GL11.glTranslated(x + 0.5, y + 1.5, z + 0.5);
GL11.glRotatef(180F, 0.0F, 0.0F, 1.0F);
GL11.glRotatef(90F, 0.0F, 1.0F, 0.0F);
switch (((TileEntityEMContractor) t).getDirection())
{
case DOWN:
GL11.glRotatef(180, 0, 0, 1);
GL11.glTranslatef(0, -2, 0);
break;
case UP:
break;
case NORTH:
GL11.glTranslatef(1, 1, 0);
GL11.glRotatef(90, 0, 0, 1);
break;
case SOUTH:
GL11.glTranslatef(-1, 1, 0);
GL11.glRotatef(-90, 0, 0, 1);
break;
case WEST:
GL11.glTranslatef(0, 1, 1);
GL11.glRotatef(-90, 1, 0, 0);
break;
case EAST:
GL11.glTranslatef(0, 1, -1);
GL11.glRotatef(90, 1, 0, 0);
break;
}
if (((TileEntityEMContractor) t).suck)
{
this.bindTexture(TEXTURE);
}
else
{
this.bindTexture(TEXTURE_PUSH);
}
if (((TileEntityEMContractor) t).canFunction() && !MekanismInduction.proxy.isPaused())
{
MODEL_SPIN.render(0.0625f);
}
else
{
MODEL.render(0.0625f);
}
GL11.glPopMatrix();
}
}

View file

@ -0,0 +1,158 @@
package mekanism.induction.client.render;
import mekanism.induction.client.model.ModelMultimeter;
import mekanism.induction.common.MekanismInduction;
import mekanism.induction.common.multimeter.TileEntityMultimeter;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.ForgeDirection;
import org.lwjgl.opengl.GL11;
import universalelectricity.core.electricity.ElectricityDisplay;
import universalelectricity.core.electricity.ElectricityDisplay.ElectricUnit;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
/**
* Class used to render text onto the multimeter block.
*
* @author Calclavia
*
*/
@SideOnly(Side.CLIENT)
public class RenderMultimeter extends TileEntitySpecialRenderer
{
public static final ModelMultimeter MODEL = new ModelMultimeter();
public static final ResourceLocation TEXTURE = new ResourceLocation(MekanismInduction.DOMAIN, MekanismInduction.MODEL_TEXTURE_DIRECTORY + "multimeter.png");
@Override
public void renderTileEntityAt(TileEntity t, double x, double y, double z, float var8)
{
TileEntityMultimeter tileEntity = (TileEntityMultimeter) t;
ForgeDirection direction = ForgeDirection.getOrientation(tileEntity.worldObj.getBlockMetadata(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord));
GL11.glPushMatrix();
GL11.glTranslated(x + 0.5, y + 0.5, z + 0.5);
GL11.glRotatef(90, 0, 0, 1);
GL11.glTranslated(0, -1, 0);
switch (direction)
{
case UP:
GL11.glRotatef(90, 0, 1, 0);
break;
case DOWN:
GL11.glRotatef(-90, 0, 1, 0);
break;
case NORTH:
GL11.glRotatef(180, 0, 1, 0);
GL11.glRotatef(180, 0, 0, 1);
GL11.glTranslatef(0, -2, 0);
break;
case SOUTH:
break;
case WEST:
GL11.glTranslatef(0, 1, 1);
GL11.glRotatef(-90, 1, 0, 0);
break;
case EAST:
GL11.glTranslatef(0, 1, -1);
GL11.glRotatef(90, 1, 0, 0);
break;
}
this.bindTexture(TEXTURE);
MODEL.render(0.0625f);
GL11.glPopMatrix();
GL11.glPushMatrix();
GL11.glPolygonOffset(-10, -10);
GL11.glEnable(GL11.GL_POLYGON_OFFSET_FILL);
float dx = 1F / 16;
float dz = 1F / 16;
float displayWidth = 1 - 2F / 16;
float displayHeight = 1 - 2F / 16;
GL11.glTranslatef((float) x, (float) y, (float) z);
switch (direction)
{
case UP:
GL11.glTranslatef(1, 1, 0);
GL11.glRotatef(180, 1, 0, 0);
GL11.glRotatef(180, 0, 1, 0);
GL11.glTranslatef(0, -0.9f, -0.1f);
break;
case DOWN:
GL11.glRotatef(180, 0, 1, 0);
GL11.glTranslatef(-1, -0.9f, -1.1f);
break;
case SOUTH:
GL11.glTranslatef(1, 1, 1);
GL11.glRotatef(180, 0, 1, 0);
GL11.glRotatef(90, 1, 0, 0);
GL11.glTranslatef(0, -0.9f, -0.1f);
break;
case NORTH:
GL11.glTranslatef(0, 1, 0);
GL11.glRotatef(0, 0, 1, 0);
GL11.glRotatef(90, 1, 0, 0);
GL11.glTranslatef(0, -0.9f, -0.1f);
break;
case EAST:
GL11.glTranslatef(1, 1, 0);
GL11.glRotatef(-90, 0, 1, 0);
GL11.glRotatef(90, 1, 0, 0);
GL11.glTranslatef(0, -0.9f, -0.1f);
break;
case WEST:
GL11.glTranslatef(0, 1, 1);
GL11.glRotatef(90, 0, 1, 0);
GL11.glRotatef(90, 1, 0, 0);
GL11.glTranslatef(0, -0.9f, -0.1f);
break;
}
GL11.glTranslatef(dx + displayWidth / 2, 1F, dz + displayHeight / 2);
GL11.glRotatef(-90, 1, 0, 0);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
FontRenderer fontRenderer = this.getFontRenderer();
String joules = ElectricityDisplay.getDisplayShort(tileEntity.getDetectedEnergy(), ElectricUnit.JOULES);
int stringWidth = Math.max(fontRenderer.getStringWidth(joules), 0);
// maxWidth += 8;
int lineHeight = fontRenderer.FONT_HEIGHT + 2;
int requiredHeight = lineHeight * 1;
/**
* Create an average scale.
*/
float scaleX = displayWidth / stringWidth;
float scaleY = displayHeight / requiredHeight;
float scale = (float) (Math.min(scaleX, scaleY) * 0.8);
GL11.glScalef(scale, -scale, scale);
GL11.glDepthMask(false);
int realHeight = (int) Math.floor(displayHeight / scale);
int realWidth = (int) Math.floor(displayWidth / scale);
int offsetY = (realHeight - requiredHeight) / 2;
int offsetX = (realWidth - stringWidth) / 2;
GL11.glDisable(GL11.GL_LIGHTING);
fontRenderer.drawString(joules, offsetX - realWidth / 2, 1 + offsetY - realHeight / 2 + 0 * lineHeight, 1);
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
GL11.glDepthMask(true);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
GL11.glDisable(GL11.GL_POLYGON_OFFSET_FILL);
GL11.glPopMatrix();
}
}

View file

@ -0,0 +1,188 @@
package mekanism.induction.client.render;
import java.nio.FloatBuffer;
import java.util.Map;
import mekanism.induction.common.MekanismInduction;
import mekanism.induction.common.wire.multipart.PartConductor;
import mekanism.induction.common.wire.multipart.PartWire;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.util.Icon;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.ForgeDirection;
import org.lwjgl.BufferUtils;
import org.lwjgl.opengl.GL11;
import universalelectricity.core.vector.Vector3;
import codechicken.lib.colour.Colour;
import codechicken.lib.colour.ColourRGBA;
import codechicken.lib.lighting.LightModel;
import codechicken.lib.render.CCModel;
import codechicken.lib.render.CCRenderState;
import codechicken.lib.render.ColourMultiplier;
import codechicken.lib.render.IconTransformation;
import codechicken.lib.render.TextureUtils;
import codechicken.lib.vec.Rotation;
import codechicken.lib.vec.Translation;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
/**
*
* @author unpairedbracket
*
*/
@SideOnly(Side.CLIENT)
public class RenderPartWire
{
private static final ResourceLocation WIRE_SHINE = new ResourceLocation(MekanismInduction.DOMAIN, MekanismInduction.MODEL_TEXTURE_DIRECTORY + "white.png");
public static final Map<String, CCModel> models;
public static final Map<String, CCModel> shinyModels;
public static Icon wireIcon;
public static Icon insulationIcon;
public static Icon breakIcon;
public static FloatBuffer location = BufferUtils.createFloatBuffer(4);
public static FloatBuffer specular = BufferUtils.createFloatBuffer(4);
public static FloatBuffer zero = BufferUtils.createFloatBuffer(4);
public static FloatBuffer defaultAmbient = BufferUtils.createFloatBuffer(4);
public static final RenderPartWire INSTANCE = new RenderPartWire();
static
{
models = CCModel.parseObjModels(new ResourceLocation("resonantinduction", "models/wire.obj"), 7, new InvertX());
for (CCModel c : models.values())
{
c.apply(new Translation(.5, 0, .5));
c.computeLighting(LightModel.standardLightModel);
c.shrinkUVs(0.0005);
}
shinyModels = CCModel.parseObjModels(new ResourceLocation("resonantinduction", "models/wireShine.obj"), 7, new InvertX());
for (CCModel c : shinyModels.values())
{
c.apply(new Translation(.5, 0, .5));
c.computeLighting(LightModel.standardLightModel);
c.shrinkUVs(0.0005);
}
loadBuffer(location, 0, 0, 0, 1);
loadBuffer(specular, 1, 1, 1, 1);
loadBuffer(zero, 0, 0, 0, 0);
loadBuffer(defaultAmbient, 0.4F, 0.4F, 0.4F, 1);
GL11.glLightModel(GL11.GL_LIGHT_MODEL_AMBIENT, zero);
GL11.glLight(GL11.GL_LIGHT3, GL11.GL_SPECULAR, specular);
GL11.glMaterial(GL11.GL_FRONT, GL11.GL_SPECULAR, specular);
GL11.glMaterial(GL11.GL_FRONT, GL11.GL_AMBIENT, zero);
GL11.glMaterial(GL11.GL_FRONT, GL11.GL_DIFFUSE, zero);
GL11.glMaterialf(GL11.GL_FRONT, GL11.GL_SHININESS, 128f);
}
public static void loadBuffer(FloatBuffer buffer, float... src)
{
buffer.clear();
buffer.put(src);
buffer.flip();
}
public void renderShine(PartWire wire, double x, double y, double z, float f)
{
if (wire != null)
{
GL11.glPushMatrix();
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_COLOR, GL11.GL_ONE_MINUS_SRC_COLOR);
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glDisable(GL11.GL_LIGHT0);
GL11.glDisable(GL11.GL_LIGHT1);
GL11.glEnable(GL11.GL_LIGHT3);
GL11.glLight(GL11.GL_LIGHT3, GL11.GL_POSITION, location);
GL11.glTranslatef((float) x, (float) y, (float) z);
GL11.glLightModel(GL11.GL_LIGHT_MODEL_AMBIENT, zero);
CCRenderState.reset();
CCRenderState.useNormals(true);
CCRenderState.changeTexture(WIRE_SHINE);
CCRenderState.startDrawing(7);
renderSideShine(ForgeDirection.UNKNOWN, wire);
byte renderSides = wire.getAllCurrentConnections();
for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS)
{
if (PartConductor.connectionMapContainsSide(renderSides, side))
renderSideShine(side, wire);
}
CCRenderState.draw();
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glEnable(GL11.GL_LIGHT0);
GL11.glEnable(GL11.GL_LIGHT1);
GL11.glDisable(GL11.GL_LIGHT3);
GL11.glLightModel(GL11.GL_LIGHT_MODEL_AMBIENT, defaultAmbient);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glPopMatrix();
}
}
public static void registerIcons(IconRegister iconReg)
{
wireIcon = iconReg.registerIcon("resonantinduction:models/wire");
insulationIcon = iconReg.registerIcon("resonantinduction:models/insulation" + (MekanismInduction.LO_FI_INSULATION ? "tiny" : ""));
breakIcon = iconReg.registerIcon("resonantinduction:wire");
}
public void renderStatic(PartWire wire)
{
TextureUtils.bindAtlas(0);
CCRenderState.reset();
CCRenderState.useModelColours(true);
CCRenderState.setBrightness(wire.world(), wire.x(), wire.y(), wire.z());
renderSide(ForgeDirection.UNKNOWN, wire);
byte renderSides = wire.getAllCurrentConnections();
for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS)
{
if (PartConductor.connectionMapContainsSide(renderSides, side))
renderSide(side, wire);
}
}
public void renderSide(ForgeDirection side, PartWire wire)
{
String name = side.name().toLowerCase();
name = name.equals("unknown") ? "center" : name;
Vector3 materialColour = wire.getMaterial().color;
Colour colour = new ColourRGBA(materialColour.x, materialColour.y, materialColour.z, 1);
renderPart(wireIcon, models.get(name), wire.x(), wire.y(), wire.z(), colour);
if (wire.isInsulated())
{
Vector3 vecColour = MekanismInduction.DYE_COLORS[wire.dyeID];
Colour insulationColour = new ColourRGBA(vecColour.x, vecColour.y, vecColour.z, 1);
renderPart(insulationIcon, models.get(name + "Insulation"), wire.x(), wire.y(), wire.z(), insulationColour);
}
}
public void renderSideShine(ForgeDirection side, PartWire wire)
{
String name = side.name().toLowerCase();
name = name.equals("unknown") ? "center" : name;
Vector3 materialColour = wire.getMaterial().color;
renderPartShine(shinyModels.get(name));
}
public void renderPart(Icon icon, CCModel cc, double x, double y, double z, Colour colour)
{
cc.render(0, cc.verts.length, Rotation.sideOrientation(0, Rotation.rotationTo(0, 2)).at(codechicken.lib.vec.Vector3.center).with(new Translation(x, y, z)), new IconTransformation(icon), new ColourMultiplier(colour));
}
public void renderPartShine(CCModel cc)
{
cc.render(null, 0, 0);
}
}

View file

@ -0,0 +1,59 @@
/**
*
*/
package mekanism.induction.client.render;
import mekanism.induction.client.model.ModelTeslaBottom;
import mekanism.induction.client.model.ModelTeslaMiddle;
import mekanism.induction.client.model.ModelTeslaTop;
import mekanism.induction.common.MekanismInduction;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.GL11;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
/**
* @author Calclavia
*
*/
@SideOnly(Side.CLIENT)
public class RenderTesla extends TileEntitySpecialRenderer
{
public static final ResourceLocation TEXTURE_BOTTOM = new ResourceLocation(MekanismInduction.DOMAIN, MekanismInduction.MODEL_TEXTURE_DIRECTORY + "tesla_bottom.png");
public static final ResourceLocation TEXTURE_MIDDLE = new ResourceLocation(MekanismInduction.DOMAIN, MekanismInduction.MODEL_TEXTURE_DIRECTORY + "tesla_middle.png");
public static final ResourceLocation TEXTURE_TOP = new ResourceLocation(MekanismInduction.DOMAIN, MekanismInduction.MODEL_TEXTURE_DIRECTORY + "tesla_top.png");
public static final ModelTeslaBottom MODEL_BOTTOM = new ModelTeslaBottom();
public static final ModelTeslaMiddle MODEL_MIDDLE = new ModelTeslaMiddle();
public static final ModelTeslaTop MODEL_TOP = new ModelTeslaTop();
@Override
public void renderTileEntityAt(TileEntity t, double x, double y, double z, float f)
{
GL11.glPushMatrix();
GL11.glTranslated(x + 0.5, y + 1.5, z + 0.5);
GL11.glRotatef(180F, 0.0F, 0.0F, 1.0F);
switch (t.getBlockMetadata())
{
default:
this.bindTexture(TEXTURE_BOTTOM);
MODEL_BOTTOM.render(0.0625f);
break;
case 1:
this.bindTexture(TEXTURE_MIDDLE);
MODEL_MIDDLE.render(0.0625f);
break;
case 2:
this.bindTexture(TEXTURE_TOP);
MODEL_TOP.render(0.0625f);
break;
}
GL11.glPopMatrix();
}
}

View file

@ -0,0 +1,136 @@
package mekanism.induction.client.render;
import mekanism.induction.client.model.ModelInsulation;
import mekanism.induction.client.model.ModelWire;
import mekanism.induction.common.MekanismInduction;
import mekanism.induction.common.wire.EnumWireMaterial;
import mekanism.induction.common.wire.TileEntityWire;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.GL11;
import universalelectricity.core.vector.Vector3;
import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
/**
* TODO: Use ISBRH.
*
* @author Calclavia
*
*/
@SideOnly(Side.CLIENT)
public class RenderWire extends TileEntitySpecialRenderer
{
private static final ResourceLocation WIRE_TEXTURE = new ResourceLocation(MekanismInduction.DOMAIN, MekanismInduction.MODEL_TEXTURE_DIRECTORY + "wire.png");
private static final ResourceLocation INSULATION_TEXTURE = new ResourceLocation(MekanismInduction.DOMAIN, MekanismInduction.MODEL_TEXTURE_DIRECTORY + "insulation.png");
public static final ModelWire WIRE_MODEL = new ModelWire();
public static final ModelInsulation INSULATION_MODEL = new ModelInsulation();
public void renderModelAt(TileEntityWire tileEntity, double x, double y, double z, float f)
{
if (tileEntity != null)
{
GL11.glPushMatrix();
GL11.glTranslatef((float) x + 0.5F, (float) y + 1.5F, (float) z + 0.5F);
GL11.glScalef(1, -1, -1);
EnumWireMaterial material = tileEntity.getMaterial();
// Texture file
FMLClientHandler.instance().getClient().renderEngine.bindTexture(WIRE_TEXTURE);
GL11.glColor4d(material.color.x, material.color.y, material.color.z, 1);
tileEntity.adjacentConnections = null;
TileEntity[] adjacentConnections = tileEntity.getAdjacentConnections();
if (adjacentConnections != null)
{
if (adjacentConnections[0] != null)
{
WIRE_MODEL.renderBottom();
}
if (adjacentConnections[1] != null)
{
WIRE_MODEL.renderTop();
}
if (adjacentConnections[2] != null)
{
WIRE_MODEL.renderBack();
}
if (adjacentConnections[3] != null)
{
WIRE_MODEL.renderFront();
}
if (adjacentConnections[4] != null)
{
WIRE_MODEL.renderLeft();
}
if (adjacentConnections[5] != null)
{
WIRE_MODEL.renderRight();
}
}
WIRE_MODEL.renderMiddle();
if (tileEntity.isInsulated)
{
// Texture file
FMLClientHandler.instance().getClient().renderEngine.bindTexture(INSULATION_TEXTURE);
Vector3 insulationColor = MekanismInduction.DYE_COLORS[tileEntity.dyeID];
GL11.glColor4d(insulationColor.x, insulationColor.y, insulationColor.z, 1);
if (adjacentConnections != null)
{
if (adjacentConnections[0] != null)
{
INSULATION_MODEL.renderBottom(0.0625f);
}
if (adjacentConnections[1] != null)
{
INSULATION_MODEL.renderTop(0.0625f);
}
if (adjacentConnections[2] != null)
{
INSULATION_MODEL.renderBack(0.0625f);
}
if (adjacentConnections[3] != null)
{
INSULATION_MODEL.renderFront(0.0625f);
}
if (adjacentConnections[4] != null)
{
INSULATION_MODEL.renderLeft(0.0625f);
}
if (adjacentConnections[5] != null)
{
INSULATION_MODEL.renderRight(0.0625f);
}
}
INSULATION_MODEL.renderMiddle(0.0625f);
}
GL11.glPopMatrix();
}
}
@Override
public void renderTileEntityAt(TileEntity tileEntity, double var2, double var4, double var6, float var8)
{
this.renderModelAt((TileEntityWire) tileEntity, var2, var4, var6, var8);
}
}

View file

@ -0,0 +1,59 @@
package mekanism.induction.common;
import net.minecraft.block.Block;
import net.minecraft.block.BlockFurnace;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
/**
* @author Calclavia
*
*/
public class BlockAdvancedFurnace extends BlockFurnace
{
protected BlockAdvancedFurnace(int id, boolean isBurning)
{
super(id, isBurning);
this.setHardness(3.5F);
this.setStepSound(soundStoneFootstep);
this.setUnlocalizedName("furnace");
if (isBurning)
{
this.setLightValue(0.875F);
}
else
{
this.setCreativeTab(CreativeTabs.tabDecorations);
}
}
public static BlockAdvancedFurnace createNew(boolean isBurning)
{
int id = Block.furnaceIdle.blockID;
if (isBurning)
{
id = Block.furnaceBurning.blockID;
}
Block.blocksList[id] = null;
Item.itemsList[id] = null;
return new BlockAdvancedFurnace(id, isBurning);
}
@Override
public void onNeighborBlockChange(World world, int x, int y, int z, int newID)
{
super.onNeighborBlockChange(world, x, y, z, newID);
((TileEntityAdvancedFurnace)world.getBlockTileEntity(x, y, z)).checkProduce();
}
@Override
public TileEntity createNewTileEntity(World par1World)
{
return new TileEntityAdvancedFurnace();
}
}

View file

@ -0,0 +1,91 @@
/**
*
*/
package mekanism.induction.common;
import mekanism.induction.common.battery.ContainerBattery;
import mekanism.induction.common.battery.TileEntityBattery;
import mekanism.induction.common.multimeter.ContainerMultimeter;
import mekanism.induction.common.multimeter.TileEntityMultimeter;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import universalelectricity.core.vector.Vector3;
import cpw.mods.fml.common.network.IGuiHandler;
/**
* @author Calclavia
*
*/
public class InductionCommonProxy implements IGuiHandler
{
public void registerRenderers()
{
}
@Override
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z)
{
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
if (tileEntity instanceof TileEntityMultimeter)
{
return new ContainerMultimeter(player.inventory, ((TileEntityMultimeter) tileEntity));
}
else if (tileEntity instanceof TileEntityBattery)
{
return new ContainerBattery(player.inventory, ((TileEntityBattery) tileEntity));
}
return null;
}
@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z)
{
return null;
}
public boolean isPaused()
{
return false;
}
public void renderElectricShock(World world, Vector3 start, Vector3 target, float r, float g, float b, boolean split)
{
}
public void renderElectricShock(World world, Vector3 start, Vector3 target, float r, float g, float b)
{
this.renderElectricShock(world, start, target, r, g, b, true);
}
public void renderElectricShock(World world, Vector3 start, Vector3 target, Vector3 color)
{
this.renderElectricShock(world, start, target, (float) color.x, (float) color.y, (float) color.z);
}
public void renderElectricShock(World world, Vector3 start, Vector3 target, Vector3 color, boolean split)
{
this.renderElectricShock(world, start, target, (float) color.x, (float) color.y, (float) color.z, split);
}
public void renderElectricShock(World world, Vector3 start, Vector3 target)
{
this.renderElectricShock(world, start, target, true);
}
public void renderElectricShock(World world, Vector3 start, Vector3 target, boolean b)
{
this.renderElectricShock(world, start, target, 0.55f, 0.7f, 1f, b);
}
public boolean isFancy()
{
return false;
}
}

View file

@ -0,0 +1,359 @@
package mekanism.induction.common;
import ic2.api.item.Items;
import java.io.File;
import java.util.Map;
import java.util.logging.Logger;
import mekanism.common.IModule;
import mekanism.common.Version;
import mekanism.induction.common.battery.BlockBattery;
import mekanism.induction.common.battery.ItemCapacitor;
import mekanism.induction.common.battery.ItemInfiniteCapacitor;
import mekanism.induction.common.battery.TileEntityBattery;
import mekanism.induction.common.contractor.BlockEMContractor;
import mekanism.induction.common.contractor.ItemBlockContractor;
import mekanism.induction.common.contractor.TileEntityEMContractor;
import mekanism.induction.common.entangler.ItemLinker;
import mekanism.induction.common.multimeter.BlockMultimeter;
import mekanism.induction.common.multimeter.ItemBlockMultimeter;
import mekanism.induction.common.multimeter.MultimeterEventHandler;
import mekanism.induction.common.multimeter.TileEntityMultimeter;
import mekanism.induction.common.tesla.BlockTesla;
import mekanism.induction.common.tesla.TileEntityTesla;
import mekanism.induction.common.wire.BlockWire;
import mekanism.induction.common.wire.EnumWireMaterial;
import mekanism.induction.common.wire.ItemBlockWire;
import mekanism.induction.common.wire.TileEntityWire;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityFurnace;
import net.minecraftforge.common.Configuration;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.oredict.ShapedOreRecipe;
import net.minecraftforge.oredict.ShapelessOreRecipe;
import universalelectricity.compatibility.Compatibility;
import universalelectricity.core.item.IItemElectric;
import universalelectricity.core.vector.Vector3;
import calclavia.lib.UniversalRecipes;
import cpw.mods.fml.common.FMLLog;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.ObfuscationReflectionHelper;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.network.NetworkMod;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.registry.GameRegistry;
@Mod(modid = "MekanismInduction", name = "MekanismInduction", version = "5.6.0")
@NetworkMod(clientSideRequired = true, serverSideRequired = false)
public class MekanismInduction implements IModule
{
/**
* Mod Information
*/
public static final String ID = "mekanism";
public static final String NAME = "MekanismInduction";
public static final String MAJOR_VERSION = "@MAJOR@";
public static final String MINOR_VERSION = "@MINOR@";
public static final String REVISION_VERSION = "@REVIS@";
public static final String BUILD_VERSION = "@BUILD@";
public static final String VERSION = MAJOR_VERSION + "." + MINOR_VERSION + "." + REVISION_VERSION;
@Instance("MekanismInduction")
public static MekanismInduction instance;
@SidedProxy(clientSide = "mekanism.induction.client.InductionClientProxy", serverSide = "mekanism.induction.common.InductionCommonProxy")
public static InductionCommonProxy proxy;
/** MekanismInduction version number */
public static Version versionNumber = new Version(5, 6, 0);
public static final Logger LOGGER = Logger.getLogger(NAME);
/**
* Directory Information
*/
public static final String DOMAIN = "mekanism";
public static final String PREFIX = DOMAIN + ":";
public static final String DIRECTORY = "/assets/" + DOMAIN + "/";
public static final String TEXTURE_DIRECTORY = "textures/";
public static final String GUI_DIRECTORY = "gui/";
public static final String BLOCK_TEXTURE_DIRECTORY = TEXTURE_DIRECTORY + "blocks/";
public static final String ITEM_TEXTURE_DIRECTORY = TEXTURE_DIRECTORY + "items/";
public static final String MODEL_TEXTURE_DIRECTORY = "render/";
/**
* Settings
*/
public static final Configuration CONFIGURATION = new Configuration(new File(Loader.instance().getConfigDir(), NAME + ".cfg"));
public static float FURNACE_WATTAGE = 10;
public static boolean SOUND_FXS = true;
public static boolean LO_FI_INSULATION = false;
public static boolean SHINY_SILVER = true;
public static boolean REPLACE_FURNACE = true;
/** Block ID by Jyzarc */
private static final int BLOCK_ID_PREFIX = 3200;
/** Item ID by Horfius */
private static final int ITEM_ID_PREFIX = 20150;
public static int MAX_CONTRACTOR_DISTANCE = 200;
private static int NEXT_BLOCK_ID = BLOCK_ID_PREFIX;
private static int NEXT_ITEM_ID = ITEM_ID_PREFIX;
public static int getNextBlockID()
{
return NEXT_BLOCK_ID++;
}
public static int getNextItemID()
{
return NEXT_ITEM_ID++;
}
// Items
public static Item itemCapacitor;
public static Item itemInfiniteCapacitor;
public static Item itemLinker;
/** With Forge Multipart; Use EnumWireMaterial reference. **/
private static Item itemPartWire;
// Blocks
public static Block blockTesla;
public static Block blockMultimeter;
public static Block blockEMContractor;
public static Block blockBattery;
/** Without Forge Multipart **/
private static Block blockWire;
public static Block blockAdvancedFurnaceIdle, blockAdvancedFurnaceBurning;
public static final Vector3[] DYE_COLORS = new Vector3[] { new Vector3(), new Vector3(1, 0, 0), new Vector3(0, 0.608, 0.232), new Vector3(0.588, 0.294, 0), new Vector3(0, 0, 1), new Vector3(0.5, 0, 05), new Vector3(0, 1, 1), new Vector3(0.8, 0.8, 0.8), new Vector3(0.3, 0.3, 0.3), new Vector3(1, 0.412, 0.706), new Vector3(0.616, 1, 0), new Vector3(1, 1, 0), new Vector3(0.46f, 0.932, 1), new Vector3(0.5, 0.2, 0.5), new Vector3(0.7, 0.5, 0.1), new Vector3(1, 1, 1) };
@EventHandler
public void preInit(FMLPreInitializationEvent evt)
{
LOGGER.setParent(FMLLog.getLogger());
NetworkRegistry.instance().registerGuiHandler(this, MekanismInduction.proxy);
MinecraftForge.EVENT_BUS.register(new MultimeterEventHandler());
CONFIGURATION.load();
// Config
FURNACE_WATTAGE = (float) CONFIGURATION.get(Configuration.CATEGORY_GENERAL, "Furnace Wattage Per Tick", FURNACE_WATTAGE).getDouble(FURNACE_WATTAGE);
SOUND_FXS = CONFIGURATION.get(Configuration.CATEGORY_GENERAL, "Tesla Sound FXs", SOUND_FXS).getBoolean(SOUND_FXS);
LO_FI_INSULATION = CONFIGURATION.get(Configuration.CATEGORY_GENERAL, "Use lo-fi insulation texture", LO_FI_INSULATION).getBoolean(LO_FI_INSULATION);
SHINY_SILVER = CONFIGURATION.get(Configuration.CATEGORY_GENERAL, "Shiny silver wires", SHINY_SILVER).getBoolean(SHINY_SILVER);
MAX_CONTRACTOR_DISTANCE = CONFIGURATION.get(Configuration.CATEGORY_GENERAL, "Max EM Contractor Path", MAX_CONTRACTOR_DISTANCE).getInt(MAX_CONTRACTOR_DISTANCE);
REPLACE_FURNACE = CONFIGURATION.get(Configuration.CATEGORY_GENERAL, "Replace vanilla furnace", REPLACE_FURNACE).getBoolean(REPLACE_FURNACE);
TileEntityEMContractor.ACCELERATION = CONFIGURATION.get(Configuration.CATEGORY_GENERAL, "Contractor Item Acceleration", TileEntityEMContractor.ACCELERATION).getDouble(TileEntityEMContractor.ACCELERATION);
TileEntityEMContractor.MAX_REACH = CONFIGURATION.get(Configuration.CATEGORY_GENERAL, "Contractor Max Item Reach", TileEntityEMContractor.MAX_REACH).getInt(TileEntityEMContractor.MAX_REACH);
TileEntityEMContractor.MAX_SPEED = CONFIGURATION.get(Configuration.CATEGORY_GENERAL, "Contractor Max Item Speed", TileEntityEMContractor.MAX_SPEED).getDouble(TileEntityEMContractor.MAX_SPEED);
TileEntityEMContractor.PUSH_DELAY = CONFIGURATION.get(Configuration.CATEGORY_GENERAL, "Contractor Item Push Delay", TileEntityEMContractor.PUSH_DELAY).getInt(TileEntityEMContractor.PUSH_DELAY);
// Items
itemCapacitor = new ItemCapacitor(getNextItemID());
itemLinker = new ItemLinker(getNextItemID());
itemInfiniteCapacitor = new ItemInfiniteCapacitor(getNextItemID());
if (Loader.isModLoaded("ForgeMultipart"))
{
try
{
itemPartWire = (Item) Class.forName("resonantinduction.wire.multipart.ItemPartWire").getConstructor(Integer.TYPE).newInstance(getNextItemID());
}
catch (Exception e)
{
LOGGER.severe("Failed to load multipart wire.");
}
}
// Blocks
blockTesla = new BlockTesla(getNextBlockID());
blockMultimeter = new BlockMultimeter(getNextBlockID());
blockEMContractor = new BlockEMContractor(getNextBlockID());
blockBattery = new BlockBattery(getNextBlockID());
if (itemPartWire == null)
{
blockWire = new BlockWire(getNextBlockID());
}
if (REPLACE_FURNACE)
{
blockAdvancedFurnaceIdle = BlockAdvancedFurnace.createNew(false);
blockAdvancedFurnaceBurning = BlockAdvancedFurnace.createNew(true);
GameRegistry.registerBlock(blockAdvancedFurnaceIdle, "ri_" + blockAdvancedFurnaceIdle.getUnlocalizedName());
GameRegistry.registerBlock(blockAdvancedFurnaceBurning, "ri_" + blockAdvancedFurnaceBurning.getUnlocalizedName() + "2");
GameRegistry.registerTileEntity(TileEntityAdvancedFurnace.class, blockAdvancedFurnaceIdle.getUnlocalizedName());
}
CONFIGURATION.save();
GameRegistry.registerItem(itemCapacitor, itemCapacitor.getUnlocalizedName());
GameRegistry.registerItem(itemInfiniteCapacitor, itemInfiniteCapacitor.getUnlocalizedName());
GameRegistry.registerItem(itemLinker, itemLinker.getUnlocalizedName());
GameRegistry.registerBlock(blockTesla, blockTesla.getUnlocalizedName());
GameRegistry.registerBlock(blockMultimeter, ItemBlockMultimeter.class, blockMultimeter.getUnlocalizedName());
GameRegistry.registerBlock(blockEMContractor, ItemBlockContractor.class, blockEMContractor.getUnlocalizedName());
GameRegistry.registerBlock(blockBattery, blockBattery.getUnlocalizedName());
if (blockWire != null)
{
GameRegistry.registerBlock(blockWire, ItemBlockWire.class, blockWire.getUnlocalizedName());
}
// Tiles
GameRegistry.registerTileEntity(TileEntityTesla.class, blockTesla.getUnlocalizedName());
GameRegistry.registerTileEntity(TileEntityMultimeter.class, blockMultimeter.getUnlocalizedName());
GameRegistry.registerTileEntity(TileEntityEMContractor.class, blockEMContractor.getUnlocalizedName());
GameRegistry.registerTileEntity(TileEntityBattery.class, blockBattery.getUnlocalizedName());
if (blockWire != null)
{
GameRegistry.registerTileEntity(TileEntityWire.class, blockWire.getUnlocalizedName());
}
MekanismInduction.proxy.registerRenderers();
if (itemPartWire != null)
{
for (EnumWireMaterial material : EnumWireMaterial.values())
{
material.setWire(itemPartWire);
}
}
else
{
for (EnumWireMaterial material : EnumWireMaterial.values())
{
material.setWire(blockWire);
}
}
}
@EventHandler
public void init(FMLInitializationEvent evt)
{
if (itemPartWire != null)
{
try
{
Class.forName("resonantinduction.MultipartRI").newInstance();
}
catch (Exception e)
{
e.printStackTrace();
LOGGER.severe("Failed to initiate Resonant Induction multipart module.");
}
}
Compatibility.initiate();
}
@EventHandler
public void postInit(FMLPostInitializationEvent evt)
{
/**
* Recipes
*/
ItemStack emptyCapacitor = new ItemStack(itemCapacitor);
((IItemElectric) itemCapacitor).setElectricity(emptyCapacitor, 0);
final ItemStack defaultWire = EnumWireMaterial.IRON.getWire();
/** Capacitor **/
GameRegistry.addRecipe(new ShapedOreRecipe(emptyCapacitor, "RRR", "RIR", "RRR", 'R', Item.redstone, 'I', UniversalRecipes.PRIMARY_METAL));
/** Linker **/
GameRegistry.addRecipe(new ShapedOreRecipe(itemLinker, " E ", "GCG", " E ", 'E', Item.eyeOfEnder, 'C', emptyCapacitor, 'G', UniversalRecipes.SECONDARY_METAL));
/** Tesla - by Jyzarc */
GameRegistry.addRecipe(new ShapedOreRecipe(blockTesla, "WEW", " C ", " I ", 'W', defaultWire, 'E', Item.eyeOfEnder, 'C', emptyCapacitor, 'I', UniversalRecipes.PRIMARY_PLATE));
/** Multimeter */
GameRegistry.addRecipe(new ShapedOreRecipe(blockMultimeter, "WWW", "ICI", 'W', defaultWire, 'C', emptyCapacitor, 'I', UniversalRecipes.PRIMARY_METAL));
/** Multimeter */
GameRegistry.addRecipe(new ShapedOreRecipe(blockBattery, "III", "IRI", "III", 'R', Block.blockRedstone, 'I', UniversalRecipes.PRIMARY_METAL));
/** EM Contractor */
GameRegistry.addRecipe(new ShapedOreRecipe(blockEMContractor, " I ", "GCG", "WWW", 'W', UniversalRecipes.PRIMARY_METAL, 'C', emptyCapacitor, 'G', UniversalRecipes.SECONDARY_METAL, 'I', UniversalRecipes.PRIMARY_METAL));
/** Wires **/
GameRegistry.addRecipe(new ShapedOreRecipe(EnumWireMaterial.COPPER.getWire(3), "MMM", 'M', "ingotCopper"));
GameRegistry.addRecipe(new ShapedOreRecipe(EnumWireMaterial.TIN.getWire(3), "MMM", 'M', "ingotTin"));
GameRegistry.addRecipe(new ShapedOreRecipe(EnumWireMaterial.IRON.getWire(3), "MMM", 'M', Item.ingotIron));
GameRegistry.addRecipe(new ShapedOreRecipe(EnumWireMaterial.ALUMINUM.getWire(3), "MMM", 'M', "ingotAluminum"));
GameRegistry.addRecipe(new ShapedOreRecipe(EnumWireMaterial.SILVER.getWire(), "MMM", 'M', "ingotSilver"));
GameRegistry.addRecipe(new ShapedOreRecipe(EnumWireMaterial.SUPERCONDUCTOR.getWire(3), "MMM", 'M', "ingotSuperconductor"));
GameRegistry.addRecipe(new ShapedOreRecipe(EnumWireMaterial.SUPERCONDUCTOR.getWire(3), "MMM", "MEM", "MMM", 'M', Item.ingotGold, 'E', Item.eyeOfEnder));
/** Wire Compatiblity **/
if (Loader.isModLoaded("IC2"))
{
GameRegistry.addRecipe(new ShapelessOreRecipe(EnumWireMaterial.COPPER.getWire(), Items.getItem("copperCableItem")));
GameRegistry.addRecipe(new ShapelessOreRecipe(EnumWireMaterial.TIN.getWire(), Items.getItem("tinCableItem")));
GameRegistry.addRecipe(new ShapelessOreRecipe(EnumWireMaterial.IRON.getWire(), Items.getItem("ironCableItem")));
GameRegistry.addRecipe(new ShapelessOreRecipe(EnumWireMaterial.SUPERCONDUCTOR.getWire(), Items.getItem("glassFiberCableItem")));
}
if (Loader.isModLoaded("Mekanism"))
{
GameRegistry.addRecipe(new ShapelessOreRecipe(EnumWireMaterial.COPPER.getWire(), "universalCable"));
}
/** Inject new furnace tile class */
replaceTileEntity(TileEntityFurnace.class, TileEntityAdvancedFurnace.class);
}
public static void replaceTileEntity(Class<? extends TileEntity> findTile, Class<? extends TileEntity> replaceTile)
{
try
{
Map<String, Class> nameToClassMap = ObfuscationReflectionHelper.getPrivateValue(TileEntity.class, null, "field_" + "70326_a", "nameToClassMap", "a");
Map<Class, String> classToNameMap = ObfuscationReflectionHelper.getPrivateValue(TileEntity.class, null, "field_" + "70326_b", "classToNameMap", "b");
String findTileID = classToNameMap.get(findTile);
if (findTileID != null)
{
nameToClassMap.put(findTileID, replaceTile);
classToNameMap.put(replaceTile, findTileID);
classToNameMap.remove(findTile);
LOGGER.fine("Replaced TileEntity: " + findTile);
}
else
{
LOGGER.severe("Failed to replace TileEntity: " + findTile);
}
}
catch (Exception e)
{
LOGGER.severe("Failed to replace TileEntity: " + findTile);
e.printStackTrace();
}
}
@Override
public Version getVersion()
{
return versionNumber;
}
@Override
public String getName()
{
return "Induction";
}
}

View file

@ -0,0 +1,36 @@
package mekanism.induction.common;
import mekanism.induction.common.wire.EnumWireMaterial;
import mekanism.induction.common.wire.multipart.PartWire;
import codechicken.multipart.MultiPartRegistry;
import codechicken.multipart.MultiPartRegistry.IPartFactory;
import codechicken.multipart.MultipartGenerator;
import codechicken.multipart.TMultiPart;
public class MultipartMI implements IPartFactory
{
public MultipartMI()
{
this.init();
}
@Override
public TMultiPart createPart(String name, boolean client)
{
if (name == "resonant_induction_wire")
return new PartWire(EnumWireMaterial.COPPER.ordinal());
return null;
}
public void init()
{
MultiPartRegistry.registerParts(this, new String[] { "resonant_induction_wire" });
MultipartGenerator.registerPassThroughInterface("universalelectricity.core.block.IConductor");
MultipartGenerator.registerPassThroughInterface("buildcraft.api.power.IPowerReceptor");
MultipartGenerator.registerPassThroughInterface("resonantinduction.wire.IInsulatedMaterial");
MultipartGenerator.registerPassThroughInterface("resonantinduction.wire.multipart.IBlockableConnection");
MultipartGenerator.registerTrait("ic2.api.energy.tile.IEnergySink", "resonantinduction.wire.multipart.javatraits.TEnergySink");
}
}

View file

@ -0,0 +1,245 @@
package mekanism.induction.common;
import net.minecraft.block.BlockFurnace;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.FurnaceRecipes;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityFurnace;
import net.minecraftforge.common.ForgeDirection;
import universalelectricity.core.block.IConductor;
import universalelectricity.core.block.IElectrical;
import universalelectricity.core.electricity.ElectricityHelper;
import universalelectricity.core.electricity.ElectricityPack;
import universalelectricity.core.grid.IElectricityNetwork;
import universalelectricity.core.vector.Vector3;
import universalelectricity.core.vector.VectorHelper;
/**
* Meant to replace the furnace class.
*
* @author Calclavia
*
*/
public class TileEntityAdvancedFurnace extends TileEntityFurnace implements IElectrical
{
private static final float WATTAGE = 5;
private boolean doProduce = false;
private boolean init = true;
private float energyBuffer = 0;
@Override
public void updateEntity()
{
if (this.init)
{
this.checkProduce();
this.init = false;
}
if (this.energyBuffer >= MekanismInduction.FURNACE_WATTAGE / 20)
{
this.furnaceCookTime++;
if (this.furnaceCookTime == 200)
{
this.furnaceCookTime = 0;
this.smeltItem();
this.onInventoryChanged();
}
this.energyBuffer = 0;
}
else
{
super.updateEntity();
if (this.doProduce)
{
if (this.getStackInSlot(0) == null)
{
boolean hasRequest = false;
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS)
{
TileEntity tileEntity = new Vector3(this).modifyPositionFromSide(direction).getTileEntity(this.worldObj);
if (tileEntity instanceof IConductor)
{
if (((IConductor) tileEntity).getNetwork().getRequest(this).getWatts() > 0)
{
if (this.furnaceBurnTime > 0)
{
this.produceUE(direction);
}
hasRequest = true;
break;
}
}
}
if (hasRequest)
{
/**
* Steal power from furnace.
*/
boolean doBlockStateUpdate = this.furnaceBurnTime > 0;
if (this.furnaceBurnTime == 0)
{
int burnTime = TileEntityFurnace.getItemBurnTime(this.getStackInSlot(1));
this.decrStackSize(1, 1);
this.furnaceBurnTime = burnTime;
}
if (doBlockStateUpdate != this.furnaceBurnTime > 0)
{
//BlockFurnace.updateFurnaceBlockState(this.furnaceBurnTime > 0, this.worldObj, this.xCoord, this.yCoord, this.zCoord);
this.refreshConductors();
}
}
}
}
}
}
/**
* Checks if the furnace should produce power.
*/
public void checkProduce()
{
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS)
{
TileEntity tileEntity = new Vector3(this).modifyPositionFromSide(direction).getTileEntity(this.worldObj);
if (tileEntity instanceof IConductor)
{
this.doProduce = true;
return;
}
}
this.doProduce = false;
}
public void refreshConductors()
{
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS)
{
TileEntity tileEntity = new Vector3(this).modifyPositionFromSide(direction).getTileEntity(this.worldObj);
if (tileEntity instanceof IConductor)
{
((IConductor) tileEntity).refresh();
}
}
}
/**
* Produces UE power towards a specific direction.
*
* @param outputDirection - The output direction.
*/
public boolean produceUE(ForgeDirection outputDirection)
{
if (!this.worldObj.isRemote && outputDirection != null && outputDirection != ForgeDirection.UNKNOWN)
{
float provide = this.getProvide(outputDirection);
if (provide > 0)
{
TileEntity outputTile = VectorHelper.getConnectorFromSide(this.worldObj, new Vector3(this), outputDirection);
IElectricityNetwork outputNetwork = ElectricityHelper.getNetworkFromTileEntity(outputTile, outputDirection);
if (outputNetwork != null)
{
ElectricityPack powerRequest = outputNetwork.getRequest(this);
if (powerRequest.getWatts() > 0)
{
ElectricityPack sendPack = ElectricityPack.getFromWatts(provide, this.getVoltage());
float rejectedPower = outputNetwork.produce(sendPack, this);
this.provideElectricity(outputDirection.getOpposite(), ElectricityPack.getFromWatts(sendPack.getWatts() - rejectedPower, this.getVoltage()), true);
}
return true;
}
}
}
return false;
}
@Override
public boolean canConnect(ForgeDirection direction)
{
return true;
}
private boolean canSmelt()
{
if (this.getStackInSlot(0) == null)
{
return false;
}
else
{
ItemStack itemstack = FurnaceRecipes.smelting().getSmeltingResult(this.getStackInSlot(0));
if (itemstack == null)
return false;
if (this.getStackInSlot(2) == null)
return true;
if (!this.getStackInSlot(2).isItemEqual(itemstack))
return false;
int result = getStackInSlot(2).stackSize + itemstack.stackSize;
return (result <= getInventoryStackLimit() && result <= itemstack.getMaxStackSize());
}
}
@Override
public float receiveElectricity(ForgeDirection from, ElectricityPack receive, boolean doReceive)
{
if (doReceive)
{
this.energyBuffer += receive.getWatts();
return 0;
}
return receive.getWatts();
}
@Override
public ElectricityPack provideElectricity(ForgeDirection from, ElectricityPack request, boolean doProvide)
{
return ElectricityPack.getFromWatts(MekanismInduction.FURNACE_WATTAGE / 20, this.getVoltage());
}
@Override
public float getRequest(ForgeDirection direction)
{
if (this.canSmelt() && this.getStackInSlot(1) == null && this.furnaceBurnTime == 0)
{
return MekanismInduction.FURNACE_WATTAGE / 20;
}
return 0;
}
@Override
public float getProvide(ForgeDirection direction)
{
if (this.furnaceBurnTime > 0)
{
return MekanismInduction.FURNACE_WATTAGE / 20;
}
return 0;
}
@Override
public float getVoltage()
{
return 0.12f;
}
}

View file

@ -0,0 +1,26 @@
/**
*
*/
package mekanism.induction.common.base;
import mekanism.common.Mekanism;
import mekanism.induction.common.MekanismInduction;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraftforge.common.Configuration;
/**
* @author Calclavia
*
*/
public class BlockBase extends Block
{
public BlockBase(String name, int id)
{
super(MekanismInduction.CONFIGURATION.get(Configuration.CATEGORY_BLOCK, name, id).getInt(id), Material.piston);
this.setCreativeTab(Mekanism.tabMekanism);
this.setUnlocalizedName(MekanismInduction.PREFIX + name);
this.setTextureName(MekanismInduction.PREFIX + name);
this.setHardness(1f);
}
}

View file

@ -0,0 +1,146 @@
package mekanism.induction.common.base;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.ItemStack;
public final class InventoryUtil
{
public static ItemStack putStackInInventory(IInventory inventory, ItemStack itemStack, int side)
{
if (!(inventory instanceof ISidedInventory))
{
for (int i = 0; i <= inventory.getSizeInventory() - 1; i++)
{
if (inventory.isItemValidForSlot(i, itemStack))
{
ItemStack inSlot = inventory.getStackInSlot(i);
if (inSlot == null)
{
inventory.setInventorySlotContents(i, itemStack);
return null;
}
else if (inSlot.isItemEqual(itemStack) && inSlot.stackSize < inSlot.getMaxStackSize())
{
if (inSlot.stackSize + itemStack.stackSize <= inSlot.getMaxStackSize())
{
ItemStack toSet = itemStack.copy();
toSet.stackSize += inSlot.stackSize;
inventory.setInventorySlotContents(i, toSet);
return null;
}
else
{
int rejects = (inSlot.stackSize + itemStack.stackSize) - inSlot.getMaxStackSize();
ItemStack toSet = itemStack.copy();
toSet.stackSize = inSlot.getMaxStackSize();
ItemStack remains = itemStack.copy();
remains.stackSize = rejects;
inventory.setInventorySlotContents(i, toSet);
return remains;
}
}
}
}
}
else
{
ISidedInventory sidedInventory = (ISidedInventory) inventory;
int[] slots = sidedInventory.getAccessibleSlotsFromSide(side);
for (int get = 0; get <= slots.length - 1; get++)
{
int slotID = slots[get];
if (sidedInventory.isItemValidForSlot(slotID, itemStack) && sidedInventory.canInsertItem(slotID, itemStack, side))
{
ItemStack inSlot = inventory.getStackInSlot(slotID);
if (inSlot == null)
{
inventory.setInventorySlotContents(slotID, itemStack);
return null;
}
else if (inSlot.isItemEqual(itemStack) && inSlot.stackSize < inSlot.getMaxStackSize())
{
if (inSlot.stackSize + itemStack.stackSize <= inSlot.getMaxStackSize())
{
ItemStack toSet = itemStack.copy();
toSet.stackSize += inSlot.stackSize;
inventory.setInventorySlotContents(slotID, toSet);
return null;
}
else
{
int rejects = (inSlot.stackSize + itemStack.stackSize) - inSlot.getMaxStackSize();
ItemStack toSet = itemStack.copy();
toSet.stackSize = inSlot.getMaxStackSize();
ItemStack remains = itemStack.copy();
remains.stackSize = rejects;
inventory.setInventorySlotContents(slotID, toSet);
return remains;
}
}
}
}
}
return itemStack;
}
public static ItemStack takeTopItemFromInventory(IInventory inventory, int side)
{
if (!(inventory instanceof ISidedInventory))
{
for (int i = inventory.getSizeInventory() - 1; i >= 0; i--)
{
if (inventory.getStackInSlot(i) != null)
{
ItemStack toSend = inventory.getStackInSlot(i).copy();
toSend.stackSize = 1;
inventory.decrStackSize(i, 1);
return toSend;
}
}
}
else
{
ISidedInventory sidedInventory = (ISidedInventory) inventory;
int[] slots = sidedInventory.getAccessibleSlotsFromSide(side);
if (slots != null)
{
for (int get = slots.length - 1; get >= 0; get--)
{
int slotID = slots[get];
if (sidedInventory.getStackInSlot(slotID) != null)
{
ItemStack toSend = sidedInventory.getStackInSlot(slotID);
toSend.stackSize = 1;
if (sidedInventory.canExtractItem(slotID, toSend, side))
{
sidedInventory.decrStackSize(slotID, 1);
return toSend;
}
}
}
}
}
return null;
}
}

View file

@ -0,0 +1,22 @@
package mekanism.induction.common.base;
import mekanism.common.Mekanism;
import mekanism.induction.common.MekanismInduction;
import net.minecraft.item.Item;
import net.minecraftforge.common.Configuration;
/**
*
* @author AidanBrady
*
*/
public class ItemBase extends Item
{
public ItemBase(String name, int id)
{
super(MekanismInduction.CONFIGURATION.get(Configuration.CATEGORY_ITEM, name, id).getInt(id));
this.setCreativeTab(Mekanism.tabMekanism);
this.setUnlocalizedName(MekanismInduction.PREFIX + name);
this.setTextureName(MekanismInduction.PREFIX + name);
}
}

View file

@ -0,0 +1,169 @@
package mekanism.induction.common.base;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
public class ListUtil
{
public static <V> List<V> inverse(List<V> list)
{
List<V> toReturn = new ArrayList<V>();
for (int i = list.size() - 1; i >= 0; i--)
{
toReturn.add(list.get(i));
}
return toReturn;
}
public static <V> List<V> cap(List<V> list, int cap)
{
List<V> toReturn = new ArrayList<V>();
if (list.size() <= cap)
{
toReturn = copy(list);
}
else
{
int count = 0;
for (V obj : list)
{
count++;
toReturn.add(obj);
if (count == cap)
{
break;
}
}
}
return toReturn;
}
public static <V> List<V> copy(List<V> list)
{
List<V> toReturn = new ArrayList<V>();
for (V obj : list)
{
toReturn.add(obj);
}
return toReturn;
}
public static <V> List<V> merge(List<V> listOne, List<V> listTwo)
{
List<V> newList = new ArrayList<V>();
for (V obj : listOne)
{
newList.add(obj);
}
for (V obj : listTwo)
{
newList.add(obj);
}
return newList;
}
public static <V> List<V> capRemains(List<V> list, int cap)
{
List<V> toReturn = new ArrayList<V>();
if (list.size() <= cap)
{
return toReturn;
}
else
{
List<V> inverse = inverse(list);
int iterNeeded = list.size() - cap;
int count = 0;
for (V obj : list)
{
count++;
toReturn.add(obj);
if (count == iterNeeded)
{
break;
}
}
return toReturn;
}
}
public static <V> ArrayList<List<V>> split(List<V> list, int divide)
{
int remain = list.size() % divide;
int size = (list.size() - remain) / divide;
ArrayList<List<V>> toReturn = new ArrayList<List<V>>();
for (int i = 0; i < divide; i++)
{
toReturn.add(i, new ArrayList<V>());
}
for (List<V> iterSet : toReturn)
{
List<V> removed = new ArrayList<V>();
int toAdd = size;
if (remain > 0)
{
remain--;
toAdd++;
}
for (V obj : list)
{
if (toAdd == 0)
{
break;
}
iterSet.add(obj);
removed.add(obj);
toAdd--;
}
for (V obj : removed)
{
list.remove(obj);
}
}
return toReturn;
}
public static <V> V getTop(List<V> list)
{
for (V obj : list)
{
return obj;
}
return null;
}
public static <V> List<V> asList(Set<V> set)
{
return (List<V>) Arrays.asList(set.toArray());
}
}

View file

@ -0,0 +1,39 @@
package mekanism.induction.common.battery;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import universalelectricity.core.item.IItemElectric;
public class BatteryManager
{
public static final int CELLS_PER_BATTERY = 16;
public static class SlotOut extends Slot
{
public SlotOut(IInventory inventory, int index, int x, int y)
{
super(inventory, index, x, y);
}
@Override
public boolean isItemValid(ItemStack itemstack)
{
return false;
}
}
public static class SlotBattery extends Slot
{
public SlotBattery(IInventory inventory, int index, int x, int y)
{
super(inventory, index, x, y);
}
@Override
public boolean isItemValid(ItemStack itemstack)
{
return itemstack.getItem() instanceof IItemElectric;
}
}
}

View file

@ -0,0 +1,298 @@
package mekanism.induction.common.battery;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import mekanism.induction.common.base.ListUtil;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
import universalelectricity.core.vector.Vector3;
public class BatteryUpdateProtocol
{
/** The battery nodes that have already been iterated over. */
public Set<TileEntityBattery> iteratedNodes = new HashSet<TileEntityBattery>();
/** The structures found, all connected by some nodes to the pointer. */
public SynchronizedBatteryData structureFound = null;
/** The original block the calculation is getting run from. */
public TileEntity pointer;
public BatteryUpdateProtocol(TileEntity tileEntity)
{
pointer = tileEntity;
}
private void loopThrough(TileEntity tile)
{
if (structureFound == null)
{
World worldObj = tile.worldObj;
int origX = tile.xCoord, origY = tile.yCoord, origZ = tile.zCoord;
boolean isCorner = true;
boolean rightBlocks = true;
Set<Vector3> locations = new HashSet<Vector3>();
int xmin = 0, xmax = 0, ymin = 0, ymax = 0, zmin = 0, zmax = 0;
int x = 0, y = 0, z = 0;
if ((isBattery(origX + 1, origY, origZ) && isBattery(origX - 1, origY, origZ)) || (isBattery(origX, origY + 1, origZ) && isBattery(origX, origY - 1, origZ)) || (isBattery(origX, origY, origZ + 1) && isBattery(origX, origY, origZ - 1)))
{
isCorner = false;
}
if (isCorner)
{
if (isBattery(origX + 1, origY, origZ))
{
xmin = 0;
while (isBattery(origX + x + 1, origY, origZ))
{
x++;
}
xmax = x;
}
else
{
xmax = 0;
while (isBattery(origX + x - 1, origY, origZ))
{
x--;
}
xmin = x;
}
if (isBattery(origX, origY + 1, origZ))
{
ymin = 0;
while (isBattery(origX, origY + y + 1, origZ))
{
y++;
}
ymax = y;
}
else
{
ymax = 0;
while (isBattery(origX, origY + y - 1, origZ))
{
y--;
}
ymin = y;
}
if (isBattery(origX, origY, origZ + 1))
{
zmin = 0;
while (isBattery(origX, origY, origZ + z + 1))
{
z++;
}
zmax = z;
}
else
{
zmax = 0;
while (isBattery(origX, origY, origZ + z - 1))
{
z--;
}
zmin = z;
}
for (x = xmin; x <= xmax; x++)
{
for (y = ymin; y <= ymax; y++)
{
for (z = zmin; z <= zmax; z++)
{
if (!isBattery(origX + x, origY + y, origZ + z))
{
rightBlocks = false;
break;
}
else
{
locations.add(new Vector3(tile).translate(new Vector3(x, y, z)));
}
}
if (!rightBlocks)
{
break;
}
}
if (!rightBlocks)
{
break;
}
}
}
if (locations.size() >= 1 && locations.size() < 512)
{
if (rightBlocks && isCorner)
{
SynchronizedBatteryData structure = new SynchronizedBatteryData();
structure.locations = locations;
structure.length = Math.abs(xmax - xmin) + 1;
structure.height = Math.abs(ymax - ymin) + 1;
structure.width = Math.abs(zmax - zmin) + 1;
if (structure.getVolume() > 1)
{
structure.isMultiblock = true;
}
if (structure.locations.contains(new Vector3(pointer)))
{
structureFound = structure;
}
}
}
}
iteratedNodes.add((TileEntityBattery) tile);
for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS)
{
TileEntity tileEntity = new Vector3(tile).modifyPositionFromSide(side).getTileEntity(tile.worldObj);
if (tileEntity instanceof TileEntityBattery)
{
if (!iteratedNodes.contains(tileEntity))
{
loopThrough(tileEntity);
}
}
}
}
private boolean isBattery(int x, int y, int z)
{
if (pointer.worldObj.getBlockTileEntity(x, y, z) instanceof TileEntityBattery)
{
return true;
}
return false;
}
private void disperseCells()
{
SynchronizedBatteryData oldStructure = null;
for (TileEntityBattery tile : iteratedNodes)
{
if (tile.structure.isMultiblock)
{
oldStructure = tile.structure;
break;
}
}
if (oldStructure != null)
{
int maxCells = iteratedNodes.size() * BatteryManager.CELLS_PER_BATTERY;
List<ItemStack> rejected = ListUtil.capRemains(oldStructure.inventory, maxCells);
ejectItems(rejected, new Vector3(pointer));
ArrayList<List<ItemStack>> inventories = ListUtil.split(ListUtil.cap(oldStructure.inventory, maxCells), iteratedNodes.size());
List<TileEntityBattery> iterList = ListUtil.asList(iteratedNodes);
boolean didVisibleInventory = false;
for (int i = 0; i < iterList.size(); i++)
{
TileEntityBattery tile = iterList.get(i);
tile.structure = SynchronizedBatteryData.getBase(tile, inventories.get(i));
if (!didVisibleInventory)
{
tile.structure.visibleInventory = oldStructure.visibleInventory;
didVisibleInventory = true;
}
}
}
}
private void ejectItems(List<ItemStack> items, Vector3 vec)
{
for (ItemStack itemStack : items)
{
float motion = 0.7F;
double motionX = (pointer.worldObj.rand.nextFloat() * motion) + (1.0F - motion) * 0.5D;
double motionY = (pointer.worldObj.rand.nextFloat() * motion) + (1.0F - motion) * 0.5D;
double motionZ = (pointer.worldObj.rand.nextFloat() * motion) + (1.0F - motion) * 0.5D;
EntityItem entityItem = new EntityItem(pointer.worldObj, vec.x + motionX, vec.y + motionY, vec.z + motionZ, itemStack);
pointer.worldObj.spawnEntityInWorld(entityItem);
}
}
public void updateBatteries()
{
loopThrough(pointer);
if (structureFound != null)
{
for (TileEntityBattery tileEntity : iteratedNodes)
{
if (!structureFound.locations.contains(new Vector3(tileEntity)))
{
disperseCells();
return;
}
}
for (Vector3 obj : structureFound.locations)
{
TileEntityBattery tileEntity = (TileEntityBattery) obj.getTileEntity(pointer.worldObj);
structureFound.inventory = ListUtil.merge(structureFound.inventory, tileEntity.structure.inventory);
if (tileEntity.structure.hasVisibleInventory())
{
structureFound.visibleInventory = tileEntity.structure.visibleInventory;
}
tileEntity.structure = structureFound;
}
List<ItemStack> rejected = ListUtil.capRemains(structureFound.inventory, structureFound.getMaxCells());
ejectItems(rejected, new Vector3(pointer));
structureFound.inventory = ListUtil.cap(structureFound.inventory, structureFound.getMaxCells());
}
else
{
disperseCells();
}
}
}

View file

@ -0,0 +1,183 @@
/**
*
*/
package mekanism.induction.common.battery;
import mekanism.api.induction.ICapacitor;
import mekanism.induction.client.render.BlockRenderingHandler;
import mekanism.induction.common.MekanismInduction;
import mekanism.induction.common.base.BlockBase;
import mekanism.induction.common.base.ListUtil;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
/**
* A block that detects power.
*
* @author Calclavia
*
*/
public class BlockBattery extends BlockBase implements ITileEntityProvider
{
public BlockBattery(int id)
{
super("battery", id);
this.setTextureName(MekanismInduction.PREFIX + "machine");
}
@Override
public void onBlockClicked(World world, int x, int y, int z, EntityPlayer entityPlayer)
{
if (!world.isRemote)
{
if (!entityPlayer.capabilities.isCreativeMode)
{
TileEntityBattery tileEntity = (TileEntityBattery) world.getBlockTileEntity(x, y, z);
ItemStack itemStack = ListUtil.getTop(tileEntity.structure.inventory);
if (tileEntity.structure.inventory.remove(itemStack))
{
entityPlayer.dropPlayerItem(itemStack);
tileEntity.updateAllClients();
}
}
}
}
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float xClick, float yClick, float zClick)
{
TileEntityBattery tileEntity = (TileEntityBattery) world.getBlockTileEntity(x, y, z);
if (entityPlayer.isSneaking())
{
boolean result = tileEntity.toggleSide(ForgeDirection.getOrientation(side));
if (!world.isRemote)
{
entityPlayer.addChatMessage("Toggled side to: " + (result ? "input" : "output"));
}
return true;
}
else
{
if (entityPlayer.getCurrentEquippedItem() != null)
{
if (entityPlayer.getCurrentEquippedItem().getItem() instanceof ICapacitor)
{
if (side != 0 && side != 1)
{
if (!world.isRemote)
{
if (tileEntity.structure.addCell(entityPlayer.getCurrentEquippedItem()))
{
entityPlayer.inventory.setInventorySlotContents(entityPlayer.inventory.currentItem, null);
tileEntity.updateAllClients();
}
}
}
}
}
}
if (!world.isRemote)
{
if(entityPlayer.getCurrentEquippedItem() != null && entityPlayer.getCurrentEquippedItem().itemID == MekanismInduction.blockBattery.blockID)
{
if(!tileEntity.structure.isMultiblock)
{
return false;
}
}
entityPlayer.openGui(MekanismInduction.instance, 0, world, x, y, z);
}
return true;
}
@Override
public void onNeighborBlockChange(World world, int x, int y, int z, int id)
{
if (!world.isRemote)
{
if (id == blockID)
{
TileEntityBattery battery = (TileEntityBattery) world.getBlockTileEntity(x, y, z);
battery.update();
}
}
}
@Override
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entityliving, ItemStack itemstack)
{
if (!world.isRemote)
{
TileEntityBattery battery = (TileEntityBattery) world.getBlockTileEntity(x, y, z);
battery.update();
}
}
@Override
public boolean renderAsNormalBlock()
{
return false;
}
@Override
public boolean isOpaqueCube()
{
return false;
}
@Override
public boolean removeBlockByPlayer(World world, EntityPlayer player, int x, int y, int z)
{
if (!world.isRemote && canHarvestBlock(player, world.getBlockMetadata(x, y, z)))
{
TileEntityBattery tileEntity = (TileEntityBattery) world.getBlockTileEntity(x, y, z);
if (!tileEntity.structure.isMultiblock)
{
for (ItemStack itemStack : tileEntity.structure.inventory)
{
float motion = 0.7F;
double motionX = (world.rand.nextFloat() * motion) + (1.0F - motion) * 0.5D;
double motionY = (world.rand.nextFloat() * motion) + (1.0F - motion) * 0.5D;
double motionZ = (world.rand.nextFloat() * motion) + (1.0F - motion) * 0.5D;
EntityItem entityItem = new EntityItem(world, x + motionX, y + motionY, z + motionZ, itemStack);
world.spawnEntityInWorld(entityItem);
}
}
}
return super.removeBlockByPlayer(world, player, x, y, z);
}
@Override
@SideOnly(Side.CLIENT)
public int getRenderType()
{
return BlockRenderingHandler.INSTANCE.getRenderId();
}
@Override
public TileEntity createNewTileEntity(World world)
{
return new TileEntityBattery();
}
}

View file

@ -0,0 +1,87 @@
package mekanism.induction.common.battery;
import mekanism.induction.common.battery.BatteryManager.SlotBattery;
import mekanism.induction.common.battery.BatteryManager.SlotOut;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.ICrafting;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import calclavia.lib.gui.ContainerBase;
public class ContainerBattery extends ContainerBase
{
private TileEntityBattery tileEntity;
public ContainerBattery(InventoryPlayer inventory, TileEntityBattery unit)
{
super(unit);
tileEntity = unit;
addSlotToContainer(new SlotBattery(unit, 0, 8, 22));
addSlotToContainer(new SlotOut(unit, 1, 8, 58));
addSlotToContainer(new SlotBattery(unit, 2, 31, 22));
addSlotToContainer(new SlotBattery(unit, 3, 31, 58));
int slotX;
for (slotX = 0; slotX < 3; ++slotX)
{
for (int slotY = 0; slotY < 9; ++slotY)
{
addSlotToContainer(new Slot(inventory, slotY + slotX * 9 + 9, 8 + slotY * 18, 125 + slotX * 18));
}
}
for (slotX = 0; slotX < 9; ++slotX)
{
addSlotToContainer(new Slot(inventory, slotX, 8 + slotX * 18, 183));
}
tileEntity.openChest();
tileEntity.playersUsing.add(inventory.player);
}
@Override
public ItemStack slotClick(int slotID, int par2, int par3, EntityPlayer par4EntityPlayer)
{
ItemStack stack = super.slotClick(slotID, par2, par3, par4EntityPlayer);
if (slotID == 1)
{
ItemStack itemstack = ((Slot) inventorySlots.get(slotID)).getStack();
ItemStack itemstack1 = itemstack == null ? null : itemstack.copy();
inventoryItemStacks.set(slotID, itemstack1);
for (int j = 0; j < crafters.size(); ++j)
{
((ICrafting) crafters.get(j)).sendSlotContents(this, slotID, itemstack1);
}
}
return stack;
}
@Override
public void onContainerClosed(EntityPlayer entityplayer)
{
super.onContainerClosed(entityplayer);
tileEntity.closeChest();
tileEntity.playersUsing.remove(entityplayer);
}
@Override
public boolean canInteractWith(EntityPlayer entityplayer)
{
return tileEntity.isUseableByPlayer(entityplayer);
}
@Override
public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int slotID)
{
if (slotID != 1)
{
return super.transferStackInSlot(par1EntityPlayer, slotID);
}
return null;
}
}

View file

@ -0,0 +1,43 @@
/**
*
*/
package mekanism.induction.common.battery;
import mekanism.api.induction.ICapacitor;
import mekanism.common.Mekanism;
import mekanism.induction.common.MekanismInduction;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.Configuration;
import universalelectricity.compatibility.ItemUniversalElectric;
/**
* Stores power.
*
* @author Calclavia
*
*/
public class ItemCapacitor extends ItemUniversalElectric implements ICapacitor
{
public ItemCapacitor(int id)
{
super(MekanismInduction.CONFIGURATION.get(Configuration.CATEGORY_ITEM, "capacitor", id).getInt(id));
this.setCreativeTab(Mekanism.tabMekanism);
this.setUnlocalizedName(MekanismInduction.PREFIX + "capacitor");
this.setTextureName(MekanismInduction.PREFIX + "capacitor");
this.setMaxStackSize(1);
this.setMaxDamage(100);
}
@Override
public float getTransfer(ItemStack itemStack)
{
return this.getMaxEnergyStored(itemStack) * 0.05F;
}
@Override
public float getMaxElectricityStored(ItemStack theItem)
{
return 500;
}
}

View file

@ -0,0 +1,81 @@
/**
*
*/
package mekanism.induction.common.battery;
import java.util.List;
import mekanism.common.Mekanism;
import mekanism.induction.common.MekanismInduction;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.Configuration;
import universalelectricity.compatibility.ItemUniversalElectric;
/**
* Stores power.
*
* @author Calclavia
*
*/
public class ItemInfiniteCapacitor extends ItemUniversalElectric
{
public ItemInfiniteCapacitor(int id)
{
super(MekanismInduction.CONFIGURATION.get(Configuration.CATEGORY_ITEM, "infiniteCapacitor", id).getInt(id));
this.setCreativeTab(Mekanism.tabMekanism);
this.setUnlocalizedName(MekanismInduction.PREFIX + "infiniteCapacitor");
this.setTextureName(MekanismInduction.PREFIX + "capacitor");
this.setMaxStackSize(1);
this.setMaxDamage(100);
}
@Override
public void addInformation(ItemStack itemStack, EntityPlayer entityPlayer, List list, boolean par4)
{
list.add("Infinite");
}
@Override
public float recharge(ItemStack itemStack, float energy, boolean doReceive)
{
return energy;
}
@Override
public float discharge(ItemStack itemStack, float energy, boolean doTransfer)
{
return energy;
}
@Override
public void setElectricity(ItemStack itemStack, float joules)
{
}
@Override
public float getTransfer(ItemStack itemStack)
{
return Float.POSITIVE_INFINITY;
}
@Override
public float getElectricityStored(ItemStack itemStack)
{
return Float.POSITIVE_INFINITY;
}
@Override
public float getMaxElectricityStored(ItemStack theItem)
{
return Float.POSITIVE_INFINITY;
}
@Override
public void getSubItems(int par1, CreativeTabs par2CreativeTabs, List par3List)
{
par3List.add(new ItemStack(this));
}
}

View file

@ -0,0 +1,163 @@
package mekanism.induction.common.battery;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import mekanism.induction.common.base.ListUtil;
import net.minecraft.item.ItemStack;
import universalelectricity.core.item.IItemElectric;
import universalelectricity.core.vector.Vector3;
public class SynchronizedBatteryData
{
public Set<Vector3> locations = new HashSet<Vector3>();
public List<ItemStack> inventory = new ArrayList<ItemStack>();
/**
* Slot 0: Cell input slot Slot 1: Battery charge slot Slot 2: Battery discharge slot
*/
public ItemStack[] visibleInventory = new ItemStack[3];
public int length;
public int width;
public int height;
public ItemStack tempStack;
public boolean isMultiblock;
public boolean didTick;
public boolean wroteInventory;
public int getVolume()
{
return length * width * height;
}
public int getMaxCells()
{
return getVolume() * BatteryManager.CELLS_PER_BATTERY;
}
public boolean addCell(ItemStack cell)
{
if (this.inventory.size() < this.getMaxCells())
{
this.inventory.add(cell);
this.sortInventory();
return true;
}
return false;
}
public void sortInventory()
{
Object[] array = ListUtil.copy(inventory).toArray();
ItemStack[] toSort = new ItemStack[array.length];
for (int i = 0; i < array.length; i++)
{
toSort[i] = (ItemStack) array[i];
}
boolean cont = true;
ItemStack temp;
while (cont)
{
cont = false;
for (int i = 0; i < toSort.length - 1; i++)
{
if (((IItemElectric) toSort[i].getItem()).getElectricityStored(toSort[i]) < ((IItemElectric) toSort[i + 1].getItem()).getElectricityStored(toSort[i + 1]))
{
temp = toSort[i];
toSort[i] = toSort[i + 1];
toSort[i + 1] = temp;
cont = true;
}
}
}
inventory = new ArrayList<ItemStack>();
for (ItemStack itemStack : toSort)
{
inventory.add(itemStack);
}
}
public boolean hasVisibleInventory()
{
for (ItemStack itemStack : visibleInventory)
{
if (itemStack != null)
{
return true;
}
}
return false;
}
public static SynchronizedBatteryData getBase(TileEntityBattery tileEntity, List<ItemStack> inventory)
{
SynchronizedBatteryData structure = getBase(tileEntity);
structure.inventory = inventory;
return structure;
}
public static SynchronizedBatteryData getBase(TileEntityBattery tileEntity)
{
SynchronizedBatteryData structure = new SynchronizedBatteryData();
structure.length = 1;
structure.width = 1;
structure.height = 1;
structure.locations.add(new Vector3(tileEntity));
return structure;
}
@Override
public int hashCode()
{
int code = 1;
code = 31 * locations.hashCode();
code = 31 * length;
code = 31 * width;
code = 31 * height;
return code;
}
@Override
public boolean equals(Object obj)
{
if (!(obj instanceof SynchronizedBatteryData))
{
return false;
}
SynchronizedBatteryData data = (SynchronizedBatteryData) obj;
if (!data.locations.equals(locations))
{
return false;
}
if (data.length != length || data.width != width || data.height != height)
{
return false;
}
return true;
}
}

View file

@ -0,0 +1,711 @@
/**
*
*/
package mekanism.induction.common.battery;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import mekanism.api.Object3D;
import mekanism.api.induction.ICapacitor;
import mekanism.common.ITileNetwork;
import mekanism.common.PacketHandler;
import mekanism.common.PacketHandler.Transmission;
import mekanism.common.network.PacketDataRequest;
import mekanism.common.network.PacketTileEntity;
import mekanism.induction.common.base.ListUtil;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.util.AxisAlignedBB;
import net.minecraftforge.common.ForgeDirection;
import universalelectricity.compatibility.TileEntityUniversalElectrical;
import universalelectricity.core.electricity.ElectricityPack;
import universalelectricity.core.item.IItemElectric;
import universalelectricity.core.vector.Vector3;
import com.google.common.io.ByteArrayDataInput;
import cpw.mods.fml.common.network.PacketDispatcher;
import cpw.mods.fml.common.network.Player;
/**
* A modular battery with no GUI.
*
* @author AidanBrady
*/
public class TileEntityBattery extends TileEntityUniversalElectrical implements ITileNetwork, IInventory
{
public Set<EntityPlayer> playersUsing = new HashSet<EntityPlayer>();
public SynchronizedBatteryData structure = SynchronizedBatteryData.getBase(this);
public SynchronizedBatteryData prevStructure;
public float clientEnergy;
public int clientCells;
public float clientMaxEnergy;
private EnumSet inputSides = EnumSet.allOf(ForgeDirection.class);
@Override
public void updateEntity()
{
super.updateEntity();
if (!this.worldObj.isRemote)
{
if (this.ticks == 5 && !this.structure.isMultiblock)
{
this.update();
}
if (this.structure.visibleInventory[0] != null)
{
if (structure.inventory.size() < structure.getMaxCells())
{
if (structure.visibleInventory[0].getItem() instanceof ICapacitor)
{
structure.inventory.add(structure.visibleInventory[0]);
structure.visibleInventory[0] = null;
structure.sortInventory();
updateAllClients();
}
}
}
/**
* Attempt to charge entities above it.
*/
ItemStack chargeItem = null;
if (this.worldObj.isBlockIndirectlyGettingPowered(this.xCoord, this.yCoord, this.zCoord))
{
List<Entity> entities = this.worldObj.getEntitiesWithinAABB(Entity.class, AxisAlignedBB.getBoundingBox(this.xCoord, this.yCoord + 1, this.zCoord, this.xCoord + 1, this.yCoord + 2, this.zCoord + 1));
electricItemLoop:
for (Entity entity : entities)
{
if (entity instanceof EntityPlayer)
{
IInventory inventory = ((EntityPlayer) entity).inventory;
for (int i = 0; i < inventory.getSizeInventory(); i++)
{
ItemStack checkStack = inventory.getStackInSlot(i);
if (checkStack != null)
{
if (checkStack.getItem() instanceof IItemElectric)
{
if (((IItemElectric) checkStack.getItem()).recharge(checkStack, provideElectricity(this.getTransferThreshhold(), false).getWatts(), false) > 0)
{
chargeItem = checkStack;
break electricItemLoop;
}
}
}
}
}
else if (entity instanceof EntityItem)
{
ItemStack checkStack = ((EntityItem) entity).getEntityItem();
if (checkStack != null)
{
if (checkStack.getItem() instanceof IItemElectric)
{
if (((IItemElectric) checkStack.getItem()).recharge(checkStack, provideElectricity(this.getTransferThreshhold(), false).getWatts(), false) > 0)
{
chargeItem = checkStack;
break electricItemLoop;
}
}
}
}
}
}
if (chargeItem == null)
{
chargeItem = this.structure.visibleInventory[1];
}
if (chargeItem != null)
{
ItemStack itemStack = chargeItem;
IItemElectric battery = (IItemElectric) itemStack.getItem();
float energyStored = getMaxEnergyStored();
float batteryNeeded = battery.recharge(itemStack, provideElectricity(this.getTransferThreshhold(), false).getWatts(), false);
float toGive = Math.min(energyStored, Math.min(battery.getTransfer(itemStack), batteryNeeded));
battery.recharge(itemStack, provideElectricity(toGive, true).getWatts(), true);
}
if (structure.visibleInventory[2] != null)
{
ItemStack itemStack = structure.visibleInventory[2];
IItemElectric battery = (IItemElectric) itemStack.getItem();
float energyNeeded = getMaxEnergyStored() - getEnergyStored();
float batteryStored = battery.getElectricityStored(itemStack);
float toReceive = Math.min(energyNeeded, Math.min(this.getTransferThreshhold(), Math.min(battery.getTransfer(itemStack), batteryStored)));
battery.discharge(itemStack, receiveElectricity(toReceive, true), true);
}
if (prevStructure != structure)
{
for (EntityPlayer player : playersUsing)
{
player.closeScreen();
}
updateClient();
}
this.prevStructure = structure;
this.structure.wroteInventory = false;
this.structure.didTick = false;
if (this.playersUsing.size() > 0)
{
updateClient();
}
for (EntityPlayer player : this.playersUsing)
{
PacketHandler.sendPacket(Transmission.SINGLE_CLIENT, new PacketTileEntity().setParams(Object3D.get(this), getNetworkedData(new ArrayList())), player);
}
this.produce();
}
}
public float getTransferThreshhold()
{
return this.structure.getVolume() * 50;
}
public void updateClient()
{
PacketHandler.sendPacket(Transmission.ALL_CLIENTS, new PacketTileEntity().setParams(Object3D.get(this), getNetworkedData(new ArrayList())));
}
public void updateAllClients()
{
for (Vector3 vec : structure.locations)
{
TileEntityBattery battery = (TileEntityBattery) vec.getTileEntity(worldObj);
PacketHandler.sendPacket(Transmission.ALL_CLIENTS, new PacketTileEntity().setParams(Object3D.get(battery), battery.getNetworkedData(new ArrayList())));
}
}
@Override
public void validate()
{
super.validate();
if(worldObj.isRemote)
{
PacketHandler.sendPacket(Transmission.SERVER, new PacketDataRequest().setParams(Object3D.get(this)));
}
}
@Override
public void readFromNBT(NBTTagCompound nbtTags)
{
super.readFromNBT(nbtTags);
// Main inventory
if (nbtTags.hasKey("Items"))
{
NBTTagList tagList = nbtTags.getTagList("Items");
structure.inventory = new ArrayList<ItemStack>();
for (int tagCount = 0; tagCount < tagList.tagCount(); tagCount++)
{
NBTTagCompound tagCompound = (NBTTagCompound) tagList.tagAt(tagCount);
int slotID = tagCompound.getInteger("Slot");
structure.inventory.add(slotID, ItemStack.loadItemStackFromNBT(tagCompound));
}
}
// Visible inventory
if (nbtTags.hasKey("VisibleItems"))
{
NBTTagList tagList = nbtTags.getTagList("VisibleItems");
structure.visibleInventory = new ItemStack[3];
for (int tagCount = 0; tagCount < tagList.tagCount(); tagCount++)
{
NBTTagCompound tagCompound = (NBTTagCompound) tagList.tagAt(tagCount);
byte slotID = tagCompound.getByte("Slot");
if (slotID >= 0 && slotID < structure.visibleInventory.length)
{
if (slotID == 0)
{
setInventorySlotContents(slotID, ItemStack.loadItemStackFromNBT(tagCompound));
}
else
{
setInventorySlotContents(slotID + 1, ItemStack.loadItemStackFromNBT(tagCompound));
}
}
}
}
this.inputSides = EnumSet.noneOf(ForgeDirection.class);
NBTTagList tagList = nbtTags.getTagList("inputSides");
for (int tagCount = 0; tagCount < tagList.tagCount(); tagCount++)
{
NBTTagCompound tagCompound = (NBTTagCompound) tagList.tagAt(tagCount);
byte side = tagCompound.getByte("side");
this.inputSides.add(ForgeDirection.getOrientation(side));
}
this.inputSides.remove(ForgeDirection.UNKNOWN);
}
@Override
public void writeToNBT(NBTTagCompound nbt)
{
super.writeToNBT(nbt);
if (!structure.wroteInventory)
{
// Inventory
if (structure.inventory != null)
{
NBTTagList tagList = new NBTTagList();
for (int slotCount = 0; slotCount < structure.inventory.size(); slotCount++)
{
if (structure.inventory.get(slotCount) != null)
{
NBTTagCompound tagCompound = new NBTTagCompound();
tagCompound.setInteger("Slot", slotCount);
structure.inventory.get(slotCount).writeToNBT(tagCompound);
tagList.appendTag(tagCompound);
}
}
nbt.setTag("Items", tagList);
}
// Visible inventory
if (structure.visibleInventory != null)
{
NBTTagList tagList = new NBTTagList();
for (int slotCount = 0; slotCount < structure.visibleInventory.length; slotCount++)
{
if (slotCount > 0)
{
slotCount++;
}
if (getStackInSlot(slotCount) != null)
{
NBTTagCompound tagCompound = new NBTTagCompound();
tagCompound.setByte("Slot", (byte) slotCount);
getStackInSlot(slotCount).writeToNBT(tagCompound);
tagList.appendTag(tagCompound);
}
}
nbt.setTag("VisibleItems", tagList);
}
structure.wroteInventory = true;
/**
* Save the input sides.
*/
NBTTagList tagList = new NBTTagList();
Iterator<ForgeDirection> it = this.inputSides.iterator();
while (it.hasNext())
{
ForgeDirection dir = it.next();
if (dir != ForgeDirection.UNKNOWN)
{
NBTTagCompound tagCompound = new NBTTagCompound();
tagCompound.setByte("side", (byte) dir.ordinal());
tagList.appendTag(tagCompound);
}
}
nbt.setTag("inputSides", tagList);
}
}
public void update()
{
if (!worldObj.isRemote && (structure == null || !structure.didTick))
{
new BatteryUpdateProtocol(this).updateBatteries();
if (structure != null)
{
structure.didTick = true;
}
}
}
@Override
public float receiveElectricity(ElectricityPack receive, boolean doAdd)
{
float amount = receive.getWatts();
float added = 0;
for (ItemStack itemStack : structure.inventory)
{
if (itemStack.getItem() instanceof IItemElectric)
{
IItemElectric battery = (IItemElectric) itemStack.getItem();
float needed = amount - added;
float itemAdd = Math.min(battery.getMaxElectricityStored(itemStack) - battery.getElectricityStored(itemStack), needed);
if (doAdd)
{
battery.setElectricity(itemStack, battery.getElectricityStored(itemStack) + itemAdd);
}
added += itemAdd;
if (amount == added)
{
break;
}
}
}
return added;
}
@Override
public ElectricityPack provideElectricity(ElectricityPack pack, boolean doRemove)
{
float amount = pack.getWatts();
List<ItemStack> inverse = ListUtil.inverse(structure.inventory);
float removed = 0;
for (ItemStack itemStack : inverse)
{
if (itemStack.getItem() instanceof IItemElectric)
{
IItemElectric battery = (IItemElectric) itemStack.getItem();
float needed = amount - removed;
float itemRemove = Math.min(battery.getElectricityStored(itemStack), needed);
if (doRemove)
{
battery.setElectricity(itemStack, battery.getElectricityStored(itemStack) - itemRemove);
}
removed += itemRemove;
if (amount == removed)
{
break;
}
}
}
return ElectricityPack.getFromWatts(removed, this.getVoltage());
}
@Override
public float getMaxEnergyStored()
{
if (!this.worldObj.isRemote)
{
float max = 0;
for (ItemStack itemStack : this.structure.inventory)
{
if (itemStack != null)
{
if (itemStack.getItem() instanceof IItemElectric)
{
max += ((IItemElectric) itemStack.getItem()).getMaxElectricityStored(itemStack);
}
}
}
return max;
}
else
{
return this.clientMaxEnergy;
}
}
@Override
public float getEnergyStored()
{
if (!this.worldObj.isRemote)
{
float energy = 0;
for (ItemStack itemStack : this.structure.inventory)
{
if (itemStack != null)
{
if (itemStack.getItem() instanceof IItemElectric)
{
energy += ((IItemElectric) itemStack.getItem()).getElectricityStored(itemStack);
}
}
}
return energy;
}
else
{
return clientEnergy;
}
}
@Override
public void handlePacketData(ByteArrayDataInput input)
{
try
{
structure.isMultiblock = input.readBoolean();
clientEnergy = input.readFloat();
clientCells = input.readInt();
clientMaxEnergy = input.readFloat();
structure.height = input.readInt();
structure.length = input.readInt();
structure.width = input.readInt();
}
catch (Exception e)
{
}
}
@Override
public ArrayList getNetworkedData(ArrayList data)
{
data.add(structure.isMultiblock);
data.add(getEnergyStored());
data.add(structure.inventory.size());
data.add(getMaxEnergyStored());
data.add(structure.height);
data.add(structure.length);
data.add(structure.width);
return data;
}
@Override
public int getSizeInventory()
{
return 4;
}
@Override
public ItemStack getStackInSlot(int i)
{
if (i == 0)
{
return structure.visibleInventory[0];
}
else if (i == 1)
{
if (!worldObj.isRemote)
{
return ListUtil.getTop(structure.inventory);
}
else
{
return structure.tempStack;
}
}
else
{
return structure.visibleInventory[i - 1];
}
}
@Override
public ItemStack decrStackSize(int slotID, int amount)
{
if (getStackInSlot(slotID) != null)
{
ItemStack tempStack;
if (getStackInSlot(slotID).stackSize <= amount)
{
tempStack = getStackInSlot(slotID);
setInventorySlotContents(slotID, null);
return tempStack;
}
else
{
tempStack = getStackInSlot(slotID).splitStack(amount);
if (getStackInSlot(slotID).stackSize == 0)
{
setInventorySlotContents(slotID, null);
}
return tempStack;
}
}
else
{
return null;
}
}
@Override
public ItemStack getStackInSlotOnClosing(int i)
{
return getStackInSlot(i);
}
@Override
public void setInventorySlotContents(int i, ItemStack itemstack)
{
if (i == 0)
{
structure.visibleInventory[0] = itemstack;
}
else if (i == 1)
{
if (itemstack == null)
{
if (!worldObj.isRemote)
{
structure.inventory.remove(ListUtil.getTop(structure.inventory));
}
else
{
structure.tempStack = null;
}
}
else
{
if (worldObj.isRemote)
{
structure.tempStack = itemstack;
}
}
}
else
{
structure.visibleInventory[i - 1] = itemstack;
}
}
@Override
public String getInvName()
{
return "Battery";
}
@Override
public boolean isInvNameLocalized()
{
return false;
}
@Override
public int getInventoryStackLimit()
{
return 64;
}
@Override
public boolean isUseableByPlayer(EntityPlayer entityplayer)
{
return true;
}
@Override
public void openChest()
{
}
@Override
public void closeChest()
{
}
@Override
public boolean isItemValidForSlot(int i, ItemStack itemsSack)
{
return itemsSack.getItem() instanceof IItemElectric;
}
@Override
public float getRequest(ForgeDirection direction)
{
if (this.getInputDirections().contains(direction))
{
return Math.min(this.getMaxEnergyStored() - this.getEnergyStored(), this.getTransferThreshhold());
}
return 0;
}
@Override
public float getProvide(ForgeDirection direction)
{
if (this.getOutputDirections().contains(direction))
{
return Math.min(this.getEnergyStored(), this.getTransferThreshhold());
}
return 0;
}
@Override
public EnumSet<ForgeDirection> getInputDirections()
{
return this.inputSides;
}
@Override
public EnumSet<ForgeDirection> getOutputDirections()
{
return EnumSet.complementOf(this.inputSides);
}
/**
* Toggles the input/output sides of the battery.
*/
public boolean toggleSide(ForgeDirection orientation)
{
if (this.inputSides.contains(orientation))
{
this.inputSides.remove(orientation);
return false;
}
else
{
this.inputSides.add(orientation);
return true;
}
}
}

View file

@ -0,0 +1,126 @@
package mekanism.induction.common.contractor;
import mekanism.induction.client.render.BlockRenderingHandler;
import mekanism.induction.common.MekanismInduction;
import mekanism.induction.common.base.BlockBase;
import mekanism.induction.common.entangler.ItemCoordLink;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.Item;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
import universalelectricity.core.vector.Vector3;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class BlockEMContractor extends BlockBase implements ITileEntityProvider
{
public BlockEMContractor(int id)
{
super("contractor", id);
this.setTextureName(MekanismInduction.PREFIX + "machine");
}
@SideOnly(Side.CLIENT)
@Override
public int getRenderType()
{
return BlockRenderingHandler.INSTANCE.getRenderId();
}
@Override
public boolean onBlockActivated(World world, int par2, int par3, int par4, EntityPlayer entityPlayer, int par6, float par7, float par8, float par9)
{
TileEntityEMContractor contractor = (TileEntityEMContractor) world.getBlockTileEntity(par2, par3, par4);
if (entityPlayer.getCurrentEquippedItem() != null)
{
if (entityPlayer.getCurrentEquippedItem().itemID == Item.dyePowder.itemID)
{
contractor.setDye(entityPlayer.getCurrentEquippedItem().getItemDamage());
if (!entityPlayer.capabilities.isCreativeMode)
{
entityPlayer.inventory.decrStackSize(entityPlayer.inventory.currentItem, 1);
}
return true;
}
else if (entityPlayer.getCurrentEquippedItem().getItem() instanceof ItemCoordLink)
{
ItemCoordLink link = ((ItemCoordLink) entityPlayer.getCurrentEquippedItem().getItem());
Vector3 linkVec = link.getLink(entityPlayer.getCurrentEquippedItem());
if (linkVec != null)
{
if (linkVec.getTileEntity(world) instanceof TileEntityEMContractor)
{
contractor.setLink((TileEntityEMContractor) linkVec.getTileEntity(world), true);
if (world.isRemote)
{
entityPlayer.addChatMessage("Linked " + this.getLocalizedName() + " with " + " [" + (int) linkVec.x + ", " + (int) linkVec.y + ", " + (int) linkVec.z + "]");
}
link.clearLink(entityPlayer.getCurrentEquippedItem());
return true;
}
}
return false;
}
}
if (!entityPlayer.isSneaking())
{
contractor.incrementFacing();
}
else
{
contractor.suck = !contractor.suck;
contractor.updatePath();
}
return true;
}
@Override
public void onNeighborBlockChange(World world, int x, int y, int z, int blockID)
{
TileEntityEMContractor tileContractor = (TileEntityEMContractor) world.getBlockTileEntity(x, y, z);
if (!world.isRemote && !tileContractor.isLatched())
{
for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS)
{
TileEntity tileEntity = world.getBlockTileEntity(x + side.offsetX, y + side.offsetY, z + side.offsetZ);
if (tileEntity instanceof IInventory)
{
tileContractor.setFacing(side.getOpposite());
return;
}
}
}
}
@Override
public TileEntity createNewTileEntity(World world)
{
return new TileEntityEMContractor();
}
@Override
public boolean renderAsNormalBlock()
{
return false;
}
@Override
public boolean isOpaqueCube()
{
return false;
}
}

View file

@ -0,0 +1,45 @@
package mekanism.induction.common.contractor;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
public class ItemBlockContractor extends ItemBlock
{
public ItemBlockContractor(int id)
{
super(id);
}
@Override
public boolean placeBlockAt(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ, int metadata)
{
boolean place = super.placeBlockAt(stack, player, world, x, y, z, side, hitX, hitY, hitZ, metadata);
if (place)
{
TileEntityEMContractor tileContractor = (TileEntityEMContractor) world.getBlockTileEntity(x, y, z);
tileContractor.setFacing(ForgeDirection.getOrientation(side));
if (!tileContractor.isLatched())
{
for (ForgeDirection side1 : ForgeDirection.VALID_DIRECTIONS)
{
TileEntity tileEntity = world.getBlockTileEntity(x + side1.offsetX, y + side1.offsetY, z + side1.offsetZ);
if (tileEntity instanceof IInventory)
{
tileContractor.setFacing(side1.getOpposite());
break;
}
}
}
}
return place;
}
}

View file

@ -0,0 +1,154 @@
/**
*
*/
package mekanism.induction.common.contractor;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
import universalelectricity.core.vector.Vector3;
/**
* Uses the well known A* Pathfinding algorithm.
*
* @author Calclavia
*
*/
public class PathfinderEMContractor
{
public final Set<Vector3> openSet, closedSet;
public final HashMap<Vector3, Vector3> navMap;
public final HashMap<Vector3, Double> gScore, fScore;
public final Vector3 target;
public List<Vector3> results;
private World world;
public PathfinderEMContractor(World world, Vector3 target)
{
this.world = world;
this.target = target;
/**
* Instantiate Variables
*/
this.openSet = new HashSet<Vector3>();
this.closedSet = new HashSet<Vector3>();
this.navMap = new HashMap<Vector3, Vector3>();
this.gScore = new HashMap<Vector3, Double>();
this.fScore = new HashMap<Vector3, Double>();
this.results = new ArrayList<Vector3>();
}
public boolean find(final Vector3 start)
{
this.openSet.add(start);
this.gScore.put(start, 0d);
this.fScore.put(start, this.gScore.get(start) + getEstimate(start, this.target));
int blockCount = 0;
for (int i = 0; i < 6; i++)
{
ForgeDirection direction = ForgeDirection.getOrientation(i);
Vector3 neighbor = this.target.clone().translate(new Vector3(direction.offsetX, direction.offsetY, direction.offsetZ));
if (!TileEntityEMContractor.canBePath(this.world, neighbor))
{
blockCount++;
}
}
if (blockCount >= 6)
{
return false;
}
double maxSearchDistance = start.distance(this.target) * 2;
while (!this.openSet.isEmpty())
{
Vector3 currentNode = null;
double lowestFScore = 0;
for (Vector3 node : this.openSet)
{
if (currentNode == null || this.fScore.get(node) < lowestFScore)
{
currentNode = node;
lowestFScore = this.fScore.get(node);
}
}
if (currentNode == null && start.distance(currentNode) > maxSearchDistance)
{
break;
}
if (currentNode.equals(this.target))
{
this.results = this.reconstructPath(this.navMap, this.target);
return true;
}
this.openSet.remove(currentNode);
this.closedSet.add(currentNode);
for (int i = 0; i < 6; i++)
{
ForgeDirection direction = ForgeDirection.getOrientation(i);
Vector3 neighbor = currentNode.clone().modifyPositionFromSide(direction);
if (TileEntityEMContractor.canBePath(this.world, neighbor))
{
double tentativeG = this.gScore.get(currentNode) + currentNode.distance(neighbor);
if (this.closedSet.contains(neighbor))
{
if (tentativeG >= this.gScore.get(neighbor))
{
continue;
}
}
if (!this.openSet.contains(neighbor) || tentativeG < this.gScore.get(neighbor))
{
this.navMap.put(neighbor, currentNode);
this.gScore.put(neighbor, tentativeG);
this.fScore.put(neighbor, this.gScore.get(neighbor) + this.getEstimate(neighbor, this.target));
this.openSet.add(neighbor);
}
}
}
}
return false;
}
private List<Vector3> reconstructPath(HashMap<Vector3, Vector3> naviMap, Vector3 currentNode)
{
List<Vector3> path = new ArrayList<Vector3>();
path.add(currentNode);
if (naviMap.containsKey(currentNode))
{
path.addAll(this.reconstructPath(naviMap, naviMap.get(currentNode)));
}
return path;
}
private double getEstimate(Vector3 start, Vector3 target2)
{
return start.distance(target2);
}
}

View file

@ -0,0 +1,41 @@
/**
*
*/
package mekanism.induction.common.contractor;
import universalelectricity.core.vector.Vector3;
/**
* @author Calclavia
*
*/
public class ThreadEMPathfinding extends Thread
{
private boolean isCompleted = false;
private PathfinderEMContractor pathfinder;
private Vector3 start;
public ThreadEMPathfinding(PathfinderEMContractor pathfinder, Vector3 start)
{
this.pathfinder = pathfinder;
this.start = start;
this.setPriority(Thread.MIN_PRIORITY);
}
@Override
public void run()
{
this.pathfinder.find(this.start);
this.isCompleted = true;
}
public PathfinderEMContractor getPath()
{
if (this.isCompleted)
{
return this.pathfinder;
}
return null;
}
}

View file

@ -0,0 +1,597 @@
package mekanism.induction.common.contractor;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import mekanism.api.Object3D;
import mekanism.common.ITileNetwork;
import mekanism.common.PacketHandler;
import mekanism.common.PacketHandler.Transmission;
import mekanism.common.network.PacketDataRequest;
import mekanism.induction.common.MekanismInduction;
import mekanism.induction.common.base.InventoryUtil;
import mekanism.induction.common.tesla.TileEntityTesla;
import net.minecraft.block.Block;
import net.minecraft.block.BlockFluid;
import net.minecraft.block.BlockLadder;
import net.minecraft.block.BlockSnow;
import net.minecraft.block.BlockVine;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.packet.Packet;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.fluids.IFluidBlock;
import universalelectricity.core.vector.Vector3;
import universalelectricity.prefab.tile.TileEntityAdvanced;
import com.google.common.io.ByteArrayDataInput;
/**
*
* @author AidanBrady
*
*/
public class TileEntityEMContractor extends TileEntityAdvanced implements ITileNetwork
{
public static int MAX_REACH = 40;
public static int PUSH_DELAY = 5;
public static double MAX_SPEED = .2;
public static double ACCELERATION = .02;
private int pushDelay;
private AxisAlignedBB operationBounds;
private AxisAlignedBB suckBounds;
/**
* true = suck, false = push
*/
public boolean suck = true;
/**
* Pathfinding
*/
private ThreadEMPathfinding thread;
private PathfinderEMContractor pathfinder;
private Set<EntityItem> pathfindingTrackers = new HashSet<EntityItem>();
private TileEntityEMContractor linked;
private int lastCalcTime = 0;
/** Color of beam */
private int dyeID = TileEntityTesla.DEFAULT_COLOR;
private Vector3 tempLinkVector;
@Override
public void initiate()
{
super.initiate();
this.updateBounds();
}
@Override
public void updateEntity()
{
super.updateEntity();
this.pushDelay = Math.max(0, this.pushDelay - 1);
if (this.tempLinkVector != null)
{
if (this.tempLinkVector.getTileEntity(this.worldObj) instanceof TileEntityEMContractor)
{
this.setLink((TileEntityEMContractor) this.tempLinkVector.getTileEntity(this.worldObj), true);
}
this.tempLinkVector = null;
}
if (canFunction())
{
TileEntity inventoryTile = getLatched();
IInventory inventory = (IInventory) inventoryTile;
if (!suck && pushDelay == 0)
{
ItemStack retrieved = InventoryUtil.takeTopItemFromInventory(inventory, this.getDirection().ordinal());
if (retrieved != null)
{
EntityItem item = getItemWithPosition(retrieved);
if (!worldObj.isRemote)
{
this.worldObj.spawnEntityInWorld(item);
}
pushDelay = PUSH_DELAY;
}
}
else if (suck)
{
if (suckBounds != null)
{
for (EntityItem item : (List<EntityItem>) worldObj.getEntitiesWithinAABB(EntityItem.class, suckBounds))
{
ItemStack remains = InventoryUtil.putStackInInventory(inventory, item.getEntityItem(), this.getDirection().ordinal());
if (remains == null)
{
item.setDead();
}
else
{
item.setEntityItemStack(remains);
}
}
}
}
if (this.thread != null)
{
PathfinderEMContractor newPath = this.thread.getPath();
if (newPath != null)
{
this.pathfinder = newPath;
this.thread = null;
}
}
final int renderFrequency = MekanismInduction.proxy.isFancy() ? 1 + this.worldObj.rand.nextInt(2) : 10 + this.worldObj.rand.nextInt(2);
final boolean renderBeam = this.ticks % renderFrequency == 0 && this.linked != null && !this.linked.isInvalid() && this.linked.suck != this.suck;
if (!this.suck)
{
if (this.linked != null && !this.linked.isInvalid())
{
if (renderBeam)
{
MekanismInduction.proxy.renderElectricShock(this.worldObj, new Vector3(this).translate(0.5), new Vector3(this).translate(new Vector3(this.getDirection())).translate(0.5), MekanismInduction.DYE_COLORS[dyeID], false);
}
/**
* Push entity along path.
*/
if (this.pathfinder != null)
{
for (int i = 0; i < this.pathfinder.results.size(); i++)
{
Vector3 result = this.pathfinder.results.get(i).clone();
if (TileEntityEMContractor.canBePath(this.worldObj, result))
{
if (i - 1 >= 0)
{
Vector3 prevResult = this.pathfinder.results.get(i - 1).clone();
Vector3 difference = prevResult.clone().difference(result);
final ForgeDirection direction = difference.toForgeDirection();
if (renderBeam)
{
MekanismInduction.proxy.renderElectricShock(this.worldObj, prevResult.clone().translate(0.5), result.clone().translate(0.5), MekanismInduction.DYE_COLORS[dyeID], false);
}
AxisAlignedBB bounds = AxisAlignedBB.getAABBPool().getAABB(result.x, result.y, result.z, result.x + 1, result.y + 1, result.z + 1);
List<EntityItem> entities = this.worldObj.getEntitiesWithinAABB(EntityItem.class, bounds);
for (EntityItem entityItem : entities)
{
this.moveEntity(entityItem, direction, result);
}
}
}
else
{
this.updatePath();
break;
}
}
}
else
{
this.updatePath();
}
}
}
else
{
if (renderBeam && this.linked != null && this.linked.pathfinder != null)
{
MekanismInduction.proxy.renderElectricShock(this.worldObj, new Vector3(this).translate(0.5), new Vector3(this).translate(new Vector3(this.getDirection())).translate(0.5), MekanismInduction.DYE_COLORS[dyeID], false);
}
this.pathfinder = null;
AxisAlignedBB searchBounds = this.operationBounds;
if (this.linked != null)
{
Vector3 searchVec = new Vector3(this).modifyPositionFromSide(this.getDirection());
searchBounds = AxisAlignedBB.getAABBPool().getAABB(searchVec.x, searchVec.y, searchVec.z, searchVec.x + 1, searchVec.y + 1, searchVec.z + 1);
}
if (searchBounds != null)
{
for (EntityItem entityItem : (List<EntityItem>) worldObj.getEntitiesWithinAABB(EntityItem.class, searchBounds))
{
if (renderBeam)
{
MekanismInduction.proxy.renderElectricShock(this.worldObj, new Vector3(this).translate(0.5), new Vector3(entityItem), MekanismInduction.DYE_COLORS[dyeID], false);
}
this.moveEntity(entityItem, this.getDirection(), new Vector3(this));
}
}
}
}
this.lastCalcTime--;
}
public static boolean canBePath(World world, Vector3 position)
{
Block block = Block.blocksList[position.getBlockID(world)];
return block == null || (block instanceof BlockSnow || block instanceof BlockVine || block instanceof BlockLadder || ((block instanceof BlockFluid || block instanceof IFluidBlock) && block.blockID != Block.lavaMoving.blockID && block.blockID != Block.lavaStill.blockID));
}
private void moveEntity(EntityItem entityItem, ForgeDirection direction, Vector3 lockVector)
{
switch (direction)
{
case DOWN:
entityItem.setPosition(lockVector.x + 0.5, entityItem.posY, lockVector.z + 0.5);
entityItem.motionX = 0;
entityItem.motionZ = 0;
if (!suck)
{
entityItem.motionY = Math.max(-MAX_SPEED, entityItem.motionY - ACCELERATION);
}
else
{
entityItem.motionY = Math.min(MAX_SPEED, entityItem.motionY + .04 + ACCELERATION);
}
break;
case UP:
entityItem.setPosition(lockVector.x + 0.5, entityItem.posY, lockVector.z + 0.5);
entityItem.motionX = 0;
entityItem.motionZ = 0;
if (!suck)
{
entityItem.motionY = Math.min(MAX_SPEED, entityItem.motionY + .04 + ACCELERATION);
}
else
{
entityItem.motionY = Math.max(-MAX_SPEED, entityItem.motionY - ACCELERATION);
}
break;
case NORTH:
entityItem.setPosition(lockVector.x + 0.5, lockVector.y + 0.5, entityItem.posZ);
entityItem.motionX = 0;
entityItem.motionY = 0;
if (!suck)
{
entityItem.motionZ = Math.max(-MAX_SPEED, entityItem.motionZ - ACCELERATION);
}
else
{
entityItem.motionZ = Math.min(MAX_SPEED, entityItem.motionZ + ACCELERATION);
}
break;
case SOUTH:
entityItem.setPosition(lockVector.x + 0.5, lockVector.y + 0.5, entityItem.posZ);
entityItem.motionX = 0;
entityItem.motionY = 0;
if (!suck)
{
entityItem.motionZ = Math.min(MAX_SPEED, entityItem.motionZ + ACCELERATION);
}
else
{
entityItem.motionZ = Math.max(-MAX_SPEED, entityItem.motionZ - ACCELERATION);
}
break;
case WEST:
entityItem.setPosition(entityItem.posX, lockVector.y + 0.5, lockVector.z + 0.5);
entityItem.motionY = 0;
entityItem.motionZ = 0;
if (!suck)
{
entityItem.motionX = Math.max(-MAX_SPEED, entityItem.motionX - ACCELERATION);
}
else
{
entityItem.motionX = Math.min(MAX_SPEED, entityItem.motionX + ACCELERATION);
}
break;
case EAST:
entityItem.setPosition(entityItem.posX, lockVector.y + 0.5, lockVector.z + 0.5);
entityItem.motionY = 0;
entityItem.motionZ = 0;
if (!suck)
{
entityItem.motionX = Math.min(MAX_SPEED, entityItem.motionX + ACCELERATION);
}
else
{
entityItem.motionX = Math.max(-MAX_SPEED, entityItem.motionX - ACCELERATION);
}
break;
default:
break;
}
entityItem.isAirBorne = true;
entityItem.delayBeforeCanPickup = 1;
entityItem.age = Math.max(entityItem.age - 1, 0);
}
private EntityItem getItemWithPosition(ItemStack toSend)
{
EntityItem item = null;
switch (this.getDirection())
{
case DOWN:
item = new EntityItem(worldObj, xCoord + 0.5, yCoord - 0.2, zCoord + 0.5, toSend);
break;
case UP:
item = new EntityItem(worldObj, xCoord + 0.5, yCoord + 1.2, zCoord + 0.5, toSend);
break;
case NORTH:
item = new EntityItem(worldObj, xCoord + 0.5, yCoord + 0.5, zCoord - 0.2, toSend);
break;
case SOUTH:
item = new EntityItem(worldObj, xCoord + 0.5, yCoord + 0.5, zCoord + 1.2, toSend);
break;
case WEST:
item = new EntityItem(worldObj, xCoord - 0.2, yCoord + 0.5, zCoord + 0.5, toSend);
break;
case EAST:
item = new EntityItem(worldObj, xCoord + 1.2, yCoord + 0.5, zCoord + 0.5, toSend);
break;
default:
break;
}
item.motionX = 0;
item.motionY = 0;
item.motionZ = 0;
return item;
}
@Override
public void validate()
{
super.validate();
if(worldObj.isRemote)
{
PacketHandler.sendPacket(Transmission.SERVER, new PacketDataRequest().setParams(Object3D.get(this)));
}
}
public void updateBounds()
{
switch (this.getDirection())
{
case DOWN:
operationBounds = AxisAlignedBB.getBoundingBox(xCoord, Math.max(yCoord - MAX_REACH, 1), zCoord, xCoord + 1, yCoord, zCoord + 1);
suckBounds = AxisAlignedBB.getBoundingBox(xCoord, yCoord - 0.1, zCoord, xCoord + 1, yCoord, zCoord + 1);
break;
case UP:
operationBounds = AxisAlignedBB.getBoundingBox(xCoord, yCoord + 1, zCoord, xCoord + 1, Math.min(yCoord + 1 + MAX_REACH, 255), zCoord + 1);
suckBounds = AxisAlignedBB.getBoundingBox(xCoord, yCoord + 1, zCoord, xCoord + 1, yCoord + 1.1, zCoord + 1);
break;
case NORTH:
operationBounds = AxisAlignedBB.getBoundingBox(xCoord, yCoord, zCoord - MAX_REACH, xCoord + 1, yCoord + 1, zCoord);
suckBounds = AxisAlignedBB.getBoundingBox(xCoord, yCoord, zCoord - 0.1, xCoord + 1, yCoord + 1, zCoord);
break;
case SOUTH:
operationBounds = AxisAlignedBB.getBoundingBox(xCoord, yCoord, zCoord + 1, xCoord + 1, yCoord + 1, zCoord + 1 + MAX_REACH);
suckBounds = AxisAlignedBB.getBoundingBox(xCoord, yCoord, zCoord + 1, xCoord + 1, yCoord + 1, zCoord + 1.1);
break;
case WEST:
operationBounds = AxisAlignedBB.getBoundingBox(xCoord - MAX_REACH, yCoord, zCoord, xCoord, yCoord + 1, zCoord + 1);
suckBounds = AxisAlignedBB.getBoundingBox(xCoord - 0.1, yCoord, zCoord, xCoord, yCoord + 1, zCoord + 1);
break;
case EAST:
operationBounds = AxisAlignedBB.getBoundingBox(xCoord + 1, yCoord, zCoord, xCoord + 1 + MAX_REACH, yCoord + 1, zCoord + 1);
suckBounds = AxisAlignedBB.getBoundingBox(xCoord + 1, yCoord, zCoord, xCoord + 1.1, yCoord + 1, zCoord + 1);
break;
default:
break;
}
}
public boolean isLatched()
{
return getLatched() != null;
}
public TileEntity getLatched()
{
ForgeDirection side = this.getDirection().getOpposite();
TileEntity tile = worldObj.getBlockTileEntity(xCoord + side.offsetX, yCoord + side.offsetY, zCoord + side.offsetZ);
if (tile instanceof IInventory)
{
return tile;
}
return null;
}
public void incrementFacing()
{
int newOrdinal = this.getDirection().ordinal() < 5 ? this.getDirection().ordinal() + 1 : 0;
this.setFacing(ForgeDirection.getOrientation(newOrdinal));
}
public ForgeDirection getDirection()
{
return ForgeDirection.getOrientation(this.worldObj.getBlockMetadata(this.xCoord, this.yCoord, this.zCoord));
}
public void setFacing(ForgeDirection side)
{
this.worldObj.setBlockMetadataWithNotify(this.xCoord, this.yCoord, this.zCoord, side.ordinal(), 3);
if (!worldObj.isRemote)
{
this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord);
}
updateBounds();
}
public boolean canFunction()
{
return isLatched() && !this.worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord);
}
@Override
public void readFromNBT(NBTTagCompound nbt)
{
super.readFromNBT(nbt);
this.suck = nbt.getBoolean("suck");
this.dyeID = nbt.getInteger("dyeID");
this.tempLinkVector = new Vector3(nbt.getCompoundTag("link"));
}
@Override
public void writeToNBT(NBTTagCompound nbt)
{
super.writeToNBT(nbt);
nbt.setBoolean("suck", suck);
nbt.setInteger("dyeID", this.dyeID);
if (this.linked != null)
{
nbt.setCompoundTag("link", new Vector3(this.linked).writeToNBT(new NBTTagCompound()));
}
}
@Override
public void handlePacketData(ByteArrayDataInput input)
{
try
{
suck = input.readBoolean();
this.dyeID = input.readInt();
if (input.readBoolean())
{
this.tempLinkVector = new Vector3(input.readInt(), input.readInt(), input.readInt());
}
this.worldObj.markBlockForRenderUpdate(xCoord, yCoord, zCoord);
updateBounds();
}
catch (Exception e)
{
}
}
@Override
public ArrayList getNetworkedData(ArrayList data)
{
data.add(suck);
data.add(dyeID);
if(linked != null)
{
data.add(true);
data.add(linked.xCoord);
data.add(linked.yCoord);
data.add(linked.zCoord);
}
else {
data.add(false);
}
return data;
}
/**
* Link between two TileEntities, do pathfinding operation.
*/
public void setLink(TileEntityEMContractor tileEntity, boolean setOpponent)
{
if (this.linked != null && setOpponent)
{
this.linked.setLink(null, false);
}
this.linked = tileEntity;
if (setOpponent)
{
this.linked.setLink(this, false);
}
this.updatePath();
}
public void updatePath()
{
if (this.thread == null && this.linked != null && this.lastCalcTime <= 0)
{
this.pathfinder = null;
Vector3 start = new Vector3(this).modifyPositionFromSide(this.getDirection());
Vector3 target = new Vector3(this.linked).modifyPositionFromSide(this.linked.getDirection());
if (start.distance(target) < MekanismInduction.MAX_CONTRACTOR_DISTANCE)
{
if (TileEntityEMContractor.canBePath(this.worldObj, start) && TileEntityEMContractor.canBePath(this.worldObj, target))
{
this.thread = new ThreadEMPathfinding(new PathfinderEMContractor(this.worldObj, target), start);
this.thread.start();
this.lastCalcTime = 40;
}
}
}
}
/**
* @param itemDamage
*/
public void setDye(int dyeID)
{
this.dyeID = dyeID;
this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord);
}
}

View file

@ -0,0 +1,88 @@
/**
*
*/
package mekanism.induction.common.entangler;
import java.util.List;
import mekanism.induction.common.base.ItemBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import universalelectricity.core.vector.Vector3;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
/**
* @author Calclavia
*
*/
public abstract class ItemCoordLink extends ItemBase
{
public ItemCoordLink(String name, int id)
{
super(name, id);
this.setMaxStackSize(1);
}
@Override
@SideOnly(Side.CLIENT)
public void addInformation(ItemStack itemstack, EntityPlayer entityplayer, List list, boolean flag)
{
super.addInformation(itemstack, entityplayer, list, flag);
if (hasLink(itemstack))
{
Vector3 vec = getLink(itemstack);
int dimID = getLinkDim(itemstack);
list.add("Bound to [" + (int) vec.x + ", " + (int) vec.y + ", " + (int) vec.z + "], dimension '" + dimID + "'");
}
else
{
list.add("No block bound");
}
}
public boolean hasLink(ItemStack itemStack)
{
return getLink(itemStack) != null;
}
public Vector3 getLink(ItemStack itemStack)
{
if (itemStack.stackTagCompound == null || !itemStack.getTagCompound().hasKey("position"))
{
return null;
}
return new Vector3(itemStack.getTagCompound().getCompoundTag("position"));
}
public void setLink(ItemStack itemStack, Vector3 vec, int dimID)
{
if (itemStack.getTagCompound() == null)
{
itemStack.setTagCompound(new NBTTagCompound());
}
itemStack.getTagCompound().setCompoundTag("position", vec.writeToNBT(new NBTTagCompound()));
itemStack.stackTagCompound.setInteger("dimID", dimID);
}
public int getLinkDim(ItemStack itemStack)
{
if (itemStack.stackTagCompound == null)
{
return 0;
}
return itemStack.stackTagCompound.getInteger("dimID");
}
public void clearLink(ItemStack itemStack)
{
itemStack.getTagCompound().removeTag("position");
itemStack.getTagCompound().removeTag("dimID");
}
}

View file

@ -0,0 +1,34 @@
/**
*
*/
package mekanism.induction.common.entangler;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import universalelectricity.core.vector.Vector3;
/**
* @author Calclavia
*
*/
public class ItemLinker extends ItemCoordLink
{
public ItemLinker(int id)
{
super("linker", id);
}
@Override
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int par7, float par8, float par9, float par10)
{
if (!world.isRemote)
{
int dimID = world.provider.dimensionId;
player.addChatMessage("Set link to block [" + x + ", " + y + ", " + z + "], dimension '" + dimID + "'");
this.setLink(stack, new Vector3(x, y, z), dimID);
}
return true;
}
}

View file

@ -0,0 +1,148 @@
/**
*
*/
package mekanism.induction.common.multimeter;
import mekanism.induction.client.render.BlockRenderingHandler;
import mekanism.induction.common.MekanismInduction;
import mekanism.induction.common.base.BlockBase;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.Vec3;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
/**
* A block that detects power.
*
* @author Calclavia
*
*/
public class BlockMultimeter extends BlockBase implements ITileEntityProvider
{
public BlockMultimeter(int id)
{
super("multimeter", id);
this.setTextureName(MekanismInduction.PREFIX + "machine");
}
@Override
public AxisAlignedBB getCollisionBoundingBoxFromPool(World par1World, int par2, int par3, int par4)
{
return null;
}
@Override
public MovingObjectPosition collisionRayTrace(World par1World, int par2, int par3, int par4, Vec3 par5Vec3, Vec3 par6Vec3)
{
int metadata = par1World.getBlockMetadata(par2, par3, par4) & 7;
float thickness = 0.15f;
if (metadata == 0)
{
this.setBlockBounds(0, 0, 0, 1, thickness, 1);
}
else if (metadata == 1)
{
this.setBlockBounds(0, 1 - thickness, 0, 1, 1, 1);
}
else if (metadata == 2)
{
this.setBlockBounds(0, 0, 0, 1, 1, thickness);
}
else if (metadata == 3)
{
this.setBlockBounds(0, 0, 1 - thickness, 1, 1, 1);
}
else if (metadata == 4)
{
this.setBlockBounds(0, 0, 0, thickness, 1, 1);
}
else if (metadata == 5)
{
this.setBlockBounds(1 - thickness, 0, 0, 1, 1, 1);
}
return super.collisionRayTrace(par1World, par2, par3, par4, par5Vec3, par6Vec3);
}
/**
* Called when a block is placed using its ItemBlock. Args: World, X, Y, Z, side, hitX, hitY,
* hi@OverridetZ, block metadata
*/
@Override
public int onBlockPlaced(World par1World, int par2, int par3, int par4, int side, float hitX, float hitY, float hitZ, int metadata)
{
return ForgeDirection.getOrientation(side).getOpposite().ordinal();
}
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float par7, float par8, float par9)
{
if (entityPlayer.isSneaking())
{
world.setBlockMetadataWithNotify(x, y, z, ForgeDirection.ROTATION_MATRIX[world.getBlockMetadata(x, y, z)][side], 3);
}
else
{
entityPlayer.openGui(MekanismInduction.instance, 0, world, x, y, z);
}
return true;
}
@Override
public int isProvidingStrongPower(IBlockAccess blockAccess, int x, int y, int z, int par5)
{
return this.isProvidingWeakPower(blockAccess, x, y, z, par5);
}
@Override
public int isProvidingWeakPower(IBlockAccess blockAccess, int x, int y, int z, int par5)
{
TileEntity tile = blockAccess.getBlockTileEntity(x, y, z);
if (tile instanceof TileEntityMultimeter)
{
return ((TileEntityMultimeter) tile).redstoneOn ? 14 : 0;
}
return 0;
}
@Override
public boolean canProvidePower()
{
return true;
}
@SideOnly(Side.CLIENT)
@Override
public int getRenderType()
{
return BlockRenderingHandler.INSTANCE.getRenderId();
}
@Override
public boolean renderAsNormalBlock()
{
return false;
}
@Override
public boolean isOpaqueCube()
{
return false;
}
@Override
public TileEntity createNewTileEntity(World world)
{
return new TileEntityMultimeter();
}
}

View file

@ -0,0 +1,54 @@
/**
*
*/
package mekanism.induction.common.multimeter;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
/**
* @author Calclavia
*
*/
public class ContainerMultimeter extends Container
{
private final int yDisplacement = 51;
private TileEntityMultimeter tileEntity;
public ContainerMultimeter(InventoryPlayer inventoryPlayer, TileEntityMultimeter tileEntity)
{
this.tileEntity = tileEntity;
int i;
for (i = 0; i < 3; ++i)
{
for (int j = 0; j < 9; ++j)
{
this.addSlotToContainer(new Slot(inventoryPlayer, j + i * 9 + 9, 8 + j * 18, 84 + i * 18 + yDisplacement));
}
}
for (i = 0; i < 9; ++i)
{
this.addSlotToContainer(new Slot(inventoryPlayer, i, 8 + i * 18, 142 + yDisplacement));
}
this.tileEntity.playersUsing.add(inventoryPlayer.player);
}
@Override
public void onContainerClosed(EntityPlayer entityPlayer)
{
this.tileEntity.playersUsing.remove(entityPlayer);
super.onContainerClosed(entityPlayer);
}
@Override
public boolean canInteractWith(EntityPlayer entityplayer)
{
return true;
}
}

View file

@ -0,0 +1,81 @@
/**
*
*/
package mekanism.induction.common.multimeter;
import java.util.List;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
/**
* ItemBlock for the Multimeter
*
* @author Calclavia
*
*/
public class ItemBlockMultimeter extends ItemBlock
{
public ItemBlockMultimeter(int par1)
{
super(par1);
}
@Override
public void addInformation(ItemStack itemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4)
{
par3List.add("Shift-right click to place,");
par3List.add("Right click to scan data.");
float detection = this.getDetection(itemStack);
if (detection != -1)
{
par3List.add("Last Detection: " + detection + " KJ");
}
else
{
par3List.add("No detection saved.");
}
}
@Override
public boolean onItemUseFirst(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World world, int x, int y, int z, int par7, float par8, float par9, float par10)
{
if (!par2EntityPlayer.isSneaking())
{
// if (!world.isRemote)
{
par2EntityPlayer.addChatMessage("Energy: " + TileEntityMultimeter.getDetectedEnergy(ForgeDirection.getOrientation(par7), world.getBlockTileEntity(x, y, z)) + " J");
}
return true;
}
return super.onItemUseFirst(par1ItemStack, par2EntityPlayer, world, x, y, z, par7, par8, par9, par10);
}
public float getDetection(ItemStack itemStack)
{
if (itemStack.stackTagCompound == null || !itemStack.getTagCompound().hasKey("detection"))
{
return -1;
}
return itemStack.stackTagCompound.getFloat("detection");
}
public void setDetection(ItemStack itemStack, float detection)
{
if (itemStack.stackTagCompound == null)
{
itemStack.setTagCompound(new NBTTagCompound());
}
itemStack.stackTagCompound.setFloat("detection", detection);
}
}

View file

@ -0,0 +1,42 @@
package mekanism.induction.common.multimeter;
import java.util.HashMap;
import net.minecraft.world.World;
import net.minecraftforge.event.ForgeSubscribe;
import universalelectricity.core.electricity.ElectricalEvent.ElectricityProductionEvent;
import universalelectricity.core.grid.IElectricityNetwork;
/**
* @author Calclavia
*
*/
public class MultimeterEventHandler
{
private static final HashMap<IElectricityNetwork, Float> networkEnergyCache = new HashMap<IElectricityNetwork, Float>();
private static long lastCheckTime = 0;
public static HashMap<IElectricityNetwork, Float> getCache(World worldObj)
{
HashMap<IElectricityNetwork, Float> returnCache = (HashMap<IElectricityNetwork, Float>) networkEnergyCache.clone();
if (Math.abs(worldObj.getWorldTime() - lastCheckTime) >= 40)
{
lastCheckTime = worldObj.getWorldTime();
networkEnergyCache.clear();
}
return returnCache;
}
@ForgeSubscribe
public void event(ElectricityProductionEvent evt)
{
IElectricityNetwork network = evt.network;
if (evt.electricityPack.getWatts() != 0)
{
networkEnergyCache.put(network, evt.electricityPack.getWatts());
}
}
}

View file

@ -0,0 +1,290 @@
/**
*
*/
package mekanism.induction.common.multimeter;
import ic2.api.tile.IEnergyStorage;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
import mekanism.api.Object3D;
import mekanism.common.ITileNetwork;
import mekanism.common.PacketHandler;
import mekanism.common.PacketHandler.Transmission;
import mekanism.common.network.PacketDataRequest;
import mekanism.common.network.PacketTileEntity;
import mekanism.induction.common.MekanismInduction;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;
import universalelectricity.core.block.IConductor;
import universalelectricity.core.block.IConnector;
import universalelectricity.core.block.IElectricalStorage;
import universalelectricity.core.grid.IElectricityNetwork;
import universalelectricity.prefab.tile.IRotatable;
import universalelectricity.prefab.tile.TileEntityAdvanced;
import universalelectricity.prefab.tile.TileEntityElectrical;
import buildcraft.api.power.IPowerReceptor;
import com.google.common.io.ByteArrayDataInput;
import cpw.mods.fml.common.network.PacketDispatcher;
import cpw.mods.fml.common.network.Player;
/**
* Block that detects power.
*
* @author Calclavia
*
*/
public class TileEntityMultimeter extends TileEntityAdvanced implements ITileNetwork, IConnector, IRotatable
{
public Set<EntityPlayer> playersUsing = new HashSet<EntityPlayer>();
public enum DetectMode
{
NONE("None"), LESS_THAN("Less Than"), LESS_THAN_EQUAL("Less Than or Equal"),
EQUAL("Equal"), GREATER_THAN("Greater Than or Equal"), GREATER_THAN_EQUAL("Greater Than");
public String display;
private DetectMode(String display)
{
this.display = display;
}
}
private DetectMode detectMode = DetectMode.NONE;
private float peakDetection;
private float energyLimit;
private float detectedEnergy;
private float detectedAverageEnergy;
public boolean redstoneOn;
@Override
public void updateEntity()
{
super.updateEntity();
if (!this.worldObj.isRemote)
{
if (this.ticks % 20 == 0)
{
float prevDetectedEnergy = this.detectedEnergy;
this.updateDetection(this.doGetDetectedEnergy());
boolean outputRedstone = false;
switch (detectMode)
{
default:
break;
case EQUAL:
outputRedstone = this.detectedEnergy == this.energyLimit;
break;
case GREATER_THAN:
outputRedstone = this.detectedEnergy > this.energyLimit;
break;
case GREATER_THAN_EQUAL:
outputRedstone = this.detectedEnergy >= this.energyLimit;
break;
case LESS_THAN:
outputRedstone = this.detectedEnergy < this.energyLimit;
break;
case LESS_THAN_EQUAL:
outputRedstone = this.detectedEnergy <= this.energyLimit;
break;
}
if (outputRedstone != this.redstoneOn)
{
this.redstoneOn = outputRedstone;
this.worldObj.notifyBlocksOfNeighborChange(this.xCoord, this.yCoord, this.zCoord, MekanismInduction.blockMultimeter.blockID);
}
if (prevDetectedEnergy != this.detectedEnergy)
{
this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord);
}
}
}
if (!this.worldObj.isRemote)
{
for (EntityPlayer player : this.playersUsing)
{
PacketHandler.sendPacket(Transmission.SINGLE_CLIENT, new PacketTileEntity().setParams(Object3D.get(this), getNetworkedData(new ArrayList())), player);
}
}
}
@Override
public void handlePacketData(ByteArrayDataInput input)
{
switch (input.readByte())
{
default:
this.detectMode = DetectMode.values()[input.readByte()];
this.detectedEnergy = input.readFloat();
this.energyLimit = input.readFloat();
break;
case 2:
this.toggleMode();
break;
case 3:
this.energyLimit = input.readFloat();
break;
}
}
@Override
public ArrayList getNetworkedData(ArrayList data)
{
data.add((byte)1);
data.add((byte)detectMode.ordinal());
data.add(detectedEnergy);
data.add(energyLimit);
return data;
}
@Override
public void validate()
{
super.validate();
if(worldObj.isRemote)
{
PacketHandler.sendPacket(Transmission.SERVER, new PacketDataRequest().setParams(Object3D.get(this)));
}
}
public float doGetDetectedEnergy()
{
ForgeDirection direction = this.getDirection();
TileEntity tileEntity = this.worldObj.getBlockTileEntity(this.xCoord + direction.offsetX, this.yCoord + direction.offsetY, this.zCoord + direction.offsetZ);
return getDetectedEnergy(direction.getOpposite(), tileEntity);
}
public static float getDetectedEnergy(ForgeDirection side, TileEntity tileEntity)
{
if (tileEntity instanceof TileEntityElectrical)
{
return ((TileEntityElectrical) tileEntity).getEnergyStored();
}
else if (tileEntity instanceof IElectricalStorage)
{
return ((IElectricalStorage) tileEntity).getEnergyStored();
}
else if (tileEntity instanceof IConductor)
{
IElectricityNetwork network = ((IConductor) tileEntity).getNetwork();
if (MultimeterEventHandler.getCache(tileEntity.worldObj).containsKey(network) && MultimeterEventHandler.getCache(tileEntity.worldObj).get(network) instanceof Float)
{
return MultimeterEventHandler.getCache(tileEntity.worldObj).get(network);
}
}
else if (tileEntity instanceof IEnergyStorage)
{
return ((IEnergyStorage) tileEntity).getStored();
}
else if (tileEntity instanceof IEnergyStorage)
{
return ((IEnergyStorage) tileEntity).getStored();
}
else if (tileEntity instanceof IPowerReceptor)
{
if (((IPowerReceptor) tileEntity).getPowerReceiver(side) != null)
{
return ((IPowerReceptor) tileEntity).getPowerReceiver(side).getEnergyStored();
}
}
return 0;
}
public void updateDetection(float detected)
{
this.detectedEnergy = detected;
this.detectedAverageEnergy = (detectedAverageEnergy + this.detectedEnergy) / 2;
this.peakDetection = Math.max(peakDetection, this.detectedEnergy);
}
public float getDetectedEnergy()
{
return this.detectedEnergy;
}
public float getAverageDetectedEnergy()
{
return this.detectedAverageEnergy;
}
public void toggleMode()
{
this.detectMode = DetectMode.values()[(this.detectMode.ordinal() + 1) % DetectMode.values().length];
}
/**
* Reads a tile entity from NBT.
*/
@Override
public void readFromNBT(NBTTagCompound nbt)
{
super.readFromNBT(nbt);
this.detectMode = DetectMode.values()[nbt.getInteger("detectMode")];
this.energyLimit = nbt.getFloat("energyLimit");
}
/**
* Writes a tile entity to NBT.
*/
@Override
public void writeToNBT(NBTTagCompound nbt)
{
super.writeToNBT(nbt);
nbt.setInteger("detectMode", this.detectMode.ordinal());
nbt.setFloat("energyLimit", this.energyLimit);
}
public DetectMode getMode()
{
return this.detectMode;
}
public float getLimit()
{
return this.energyLimit;
}
/**
* @return
*/
public float getPeak()
{
return this.peakDetection;
}
@Override
public boolean canConnect(ForgeDirection direction)
{
return direction == this.getDirection();
}
@Override
public ForgeDirection getDirection()
{
return ForgeDirection.getOrientation(this.worldObj.getBlockMetadata(this.xCoord, this.yCoord, this.zCoord));
}
@Override
public void setDirection(ForgeDirection direction)
{
this.worldObj.setBlockMetadataWithNotify(this.xCoord, this.yCoord, this.zCoord, direction.ordinal(), 3);
}
}

View file

@ -0,0 +1,163 @@
/**
*
*/
package mekanism.induction.common.tesla;
import mekanism.induction.client.render.BlockRenderingHandler;
import mekanism.induction.common.MekanismInduction;
import mekanism.induction.common.base.BlockBase;
import mekanism.induction.common.entangler.ItemCoordLink;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.server.MinecraftServer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import universalelectricity.core.vector.Vector3;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
/**
* @author Calclavia
*
*/
public class BlockTesla extends BlockBase implements ITileEntityProvider
{
public BlockTesla(int id)
{
super("tesla", id);
this.setTextureName(MekanismInduction.PREFIX + "machine");
}
@Override
public void onBlockAdded(World world, int x, int y, int z)
{
super.onBlockAdded(world, x, y, z);
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
((TileEntityTesla) tileEntity).updatePositionStatus();
}
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int par6, float par7, float par8, float par9)
{
TileEntity t = world.getBlockTileEntity(x, y, z);
TileEntityTesla tileEntity = ((TileEntityTesla) t).getControllingTelsa();
if (entityPlayer.getCurrentEquippedItem() != null)
{
if (entityPlayer.getCurrentEquippedItem().itemID == Item.dyePowder.itemID)
{
tileEntity.setDye(entityPlayer.getCurrentEquippedItem().getItemDamage());
if (!entityPlayer.capabilities.isCreativeMode)
{
entityPlayer.inventory.decrStackSize(entityPlayer.inventory.currentItem, 1);
}
return true;
}
else if (entityPlayer.getCurrentEquippedItem().itemID == Item.redstone.itemID)
{
boolean status = tileEntity.toggleEntityAttack();
if (!entityPlayer.capabilities.isCreativeMode)
{
entityPlayer.inventory.decrStackSize(entityPlayer.inventory.currentItem, 1);
}
if (!world.isRemote)
{
entityPlayer.addChatMessage("Toggled entity attack to: " + status);
}
return true;
}
else if (entityPlayer.getCurrentEquippedItem().getItem() instanceof ItemCoordLink)
{
if (tileEntity.linked == null)
{
ItemCoordLink link = ((ItemCoordLink) entityPlayer.getCurrentEquippedItem().getItem());
Vector3 linkVec = link.getLink(entityPlayer.getCurrentEquippedItem());
if (linkVec != null)
{
if (!world.isRemote)
{
int dimID = link.getLinkDim(entityPlayer.getCurrentEquippedItem());
World otherWorld = MinecraftServer.getServer().worldServerForDimension(dimID);
if (linkVec.getTileEntity(otherWorld) instanceof TileEntityTesla)
{
tileEntity.setLink(new Vector3(((TileEntityTesla) linkVec.getTileEntity(otherWorld)).getTopTelsa()), dimID, true);
entityPlayer.addChatMessage("Linked " + this.getLocalizedName() + " with " + " [" + (int) linkVec.x + ", " + (int) linkVec.y + ", " + (int) linkVec.z + "]");
link.clearLink(entityPlayer.getCurrentEquippedItem());
world.playSoundEffect(x + 0.5, y + 0.5, z + 0.5, "ambient.weather.thunder", 5, 1);
return true;
}
}
}
}
else
{
tileEntity.setLink(null, world.provider.dimensionId, true);
if (!world.isRemote)
{
entityPlayer.addChatMessage("Unlinked Tesla.");
}
return true;
}
}
}
else
{
boolean receiveMode = tileEntity.toggleReceive();
if (world.isRemote)
{
entityPlayer.addChatMessage("Tesla receive mode is now " + receiveMode);
}
return true;
}
return false;
}
@Override
public void onNeighborBlockChange(World world, int x, int y, int z, int id)
{
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
((TileEntityTesla) tileEntity).updatePositionStatus();
}
@Override
public TileEntity createNewTileEntity(World world)
{
return new TileEntityTesla();
}
@SideOnly(Side.CLIENT)
@Override
public int getRenderType()
{
return BlockRenderingHandler.INSTANCE.getRenderId();
}
@Override
public boolean renderAsNormalBlock()
{
return false;
}
@Override
public boolean isOpaqueCube()
{
return false;
}
}

View file

@ -0,0 +1,68 @@
/**
*
*/
package mekanism.induction.common.tesla;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import mekanism.api.induction.ITesla;
import net.minecraft.tileentity.TileEntity;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.relauncher.Side;
/**
* @author Calclavia
*
*/
public class TeslaGrid
{
private static final TeslaGrid INSTANCE_CLIENT = new TeslaGrid();
private static final TeslaGrid INSTANCE_SERVER = new TeslaGrid();
private final Set<ITesla> tileEntities = new HashSet<ITesla>();
public void register(ITesla iTesla)
{
Iterator<ITesla> it = this.tileEntities.iterator();
while (it.hasNext())
{
ITesla tesla = it.next();
if (tesla instanceof TileEntity)
{
if (!((TileEntity) tesla).isInvalid())
{
continue;
}
}
it.remove();
}
this.tileEntities.add(iTesla);
}
public void unregister(ITesla iTesla)
{
this.tileEntities.remove(iTesla);
}
public Set<ITesla> get()
{
return this.tileEntities;
}
public static TeslaGrid instance()
{
if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER)
{
return INSTANCE_SERVER;
}
return INSTANCE_CLIENT;
}
}

View file

@ -0,0 +1,666 @@
/**
*
*/
package mekanism.induction.common.tesla;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.EnumSet;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import mekanism.api.Object3D;
import mekanism.api.induction.ITesla;
import mekanism.common.ITileNetwork;
import mekanism.common.PacketHandler;
import mekanism.common.PacketHandler.Transmission;
import mekanism.common.network.PacketDataRequest;
import mekanism.common.network.PacketTileEntity;
import mekanism.induction.common.MekanismInduction;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.server.MinecraftServer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.DamageSource;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
import universalelectricity.compatibility.TileEntityUniversalElectrical;
import universalelectricity.core.electricity.ElectricityPack;
import universalelectricity.core.vector.Vector3;
import com.google.common.io.ByteArrayDataInput;
import cpw.mods.fml.common.network.PacketDispatcher;
/**
* The Tesla TileEntity.
*
* - Redstone (Prevent Output Toggle) - Right click (Prevent Input Toggle)
*
* @author Calclavia
*
*/
public class TileEntityTesla extends TileEntityUniversalElectrical implements ITesla, ITileNetwork
{
public final static int DEFAULT_COLOR = 12;
public final float TRANSFER_CAP = 10;
private int dyeID = DEFAULT_COLOR;
private boolean canReceive = true;
private boolean attackEntities = true;
/** Client side to do sparks */
private boolean doTransfer = true;
/** Prevents transfer loops */
private final Set<TileEntityTesla> outputBlacklist = new HashSet<TileEntityTesla>();
private final Set<TileEntityTesla> connectedTeslas = new HashSet<TileEntityTesla>();
/**
* Caching
*/
private TileEntityTesla topCache = null;
private TileEntityTesla controlCache = null;
/**
* Quantum Tesla
*/
public Vector3 linked;
public int linkDim;
/**
* Client
*/
private int zapCounter = 0;
private boolean isLinkedClient;
@Override
public void initiate()
{
super.initiate();
TeslaGrid.instance().register(this);
}
@Override
public void updateEntity()
{
super.updateEntity();
boolean doPacketUpdate = this.getEnergyStored() > 0;
/**
* Only transfer if it is the bottom controlling Tesla tower.
*/
if (this.isController())
{
this.produce();
if (this.ticks % (5 + this.worldObj.rand.nextInt(2)) == 0 && ((this.worldObj.isRemote && this.doTransfer) || (this.getEnergyStored() > 0 && !this.worldObj.isBlockIndirectlyGettingPowered(this.xCoord, this.yCoord, this.zCoord))))
{
final TileEntityTesla topTesla = this.getTopTelsa();
final Vector3 topTeslaVector = new Vector3(topTesla);
/**
* Quantum transportation.
*/
if (this.linked != null || this.isLinkedClient)
{
if (!this.worldObj.isRemote)
{
World dimWorld = MinecraftServer.getServer().worldServerForDimension(this.linkDim);
if (dimWorld != null)
{
TileEntity transferTile = this.linked.getTileEntity(dimWorld);
if (transferTile instanceof TileEntityTesla && !transferTile.isInvalid())
{
this.transfer(((TileEntityTesla) transferTile), Math.min(this.getProvide(ForgeDirection.UNKNOWN), TRANSFER_CAP));
if (this.zapCounter % 5 == 0 && MekanismInduction.SOUND_FXS)
{
this.worldObj.playSoundEffect(this.xCoord + 0.5, this.yCoord + 0.5, this.zCoord + 0.5, MekanismInduction.PREFIX + "electricshock", this.getEnergyStored() / 25, 1.3f - 0.5f * (this.dyeID / 16f));
}
}
}
}
else
{
MekanismInduction.proxy.renderElectricShock(this.worldObj, topTeslaVector.clone().translate(0.5), topTeslaVector.clone().translate(new Vector3(0.5, Double.POSITIVE_INFINITY, 0.5)), false);
}
}
else
{
List<ITesla> transferTeslaCoils = new ArrayList<ITesla>();
for (ITesla tesla : TeslaGrid.instance().get())
{
if (new Vector3((TileEntity) tesla).distance(new Vector3(this)) < this.getRange())
{
/**
* Make sure Tesla is not part of this tower.
*/
if (!this.connectedTeslas.contains(tesla) && tesla.canReceive(this))
{
if (tesla instanceof TileEntityTesla)
{
if (((TileEntityTesla) tesla).getHeight() <= 1)
{
continue;
}
tesla = ((TileEntityTesla) tesla).getControllingTelsa();
}
transferTeslaCoils.add(tesla);
}
}
}
/**
* Sort by distance.
*/
Collections.sort(transferTeslaCoils, new Comparator()
{
public int compare(ITesla o1, ITesla o2)
{
double distance1 = new Vector3(topTesla).distance(new Vector3((TileEntity) o1));
double distance2 = new Vector3(topTesla).distance(new Vector3((TileEntity) o2));
if (distance1 < distance2)
{
return 1;
}
else if (distance1 > distance2)
{
return -1;
}
return 0;
}
@Override
public int compare(Object obj, Object obj1)
{
return compare((ITesla) obj, (ITesla) obj1);
}
});
if (transferTeslaCoils.size() > 0)
{
float transferEnergy = this.getEnergyStored() / transferTeslaCoils.size();
int count = 0;
boolean sentPacket = false;
for (ITesla tesla : transferTeslaCoils)
{
if (this.zapCounter % 5 == 0 && MekanismInduction.SOUND_FXS)
{
this.worldObj.playSoundEffect(this.xCoord + 0.5, this.yCoord + 0.5, this.zCoord + 0.5, MekanismInduction.PREFIX + "electricshock", this.getEnergyStored() / 25, 1.3f - 0.5f * (this.dyeID / 16f));
}
Vector3 targetVector = new Vector3((TileEntity) tesla);
if (tesla instanceof TileEntityTesla)
{
((TileEntityTesla) tesla).getControllingTelsa().outputBlacklist.add(this);
targetVector = new Vector3(((TileEntityTesla) tesla).getTopTelsa());
}
double distance = topTeslaVector.distance(targetVector);
MekanismInduction.proxy.renderElectricShock(this.worldObj, new Vector3(topTesla).translate(new Vector3(0.5)), targetVector.translate(new Vector3(0.5)), (float) MekanismInduction.DYE_COLORS[this.dyeID].x, (float) MekanismInduction.DYE_COLORS[this.dyeID].y, (float) MekanismInduction.DYE_COLORS[this.dyeID].z);
this.transfer(tesla, Math.min(transferEnergy, TRANSFER_CAP));
if (!sentPacket && transferEnergy > 0)
{
this.sendPacket(3);
}
if (this.attackEntities && this.zapCounter % 5 == 0)
{
MovingObjectPosition mop = topTeslaVector.clone().translate(0.5).rayTraceEntities(this.worldObj, targetVector.clone().translate(0.5));
if (mop != null && mop.entityHit != null)
{
if (mop.entityHit instanceof EntityLivingBase)
{
mop.entityHit.attackEntityFrom(DamageSource.magic, 4);
MekanismInduction.proxy.renderElectricShock(this.worldObj, new Vector3(topTesla).clone().translate(0.5), new Vector3(mop.entityHit));
}
}
}
if (count++ > 1)
{
break;
}
}
}
}
this.zapCounter++;
this.outputBlacklist.clear();
this.doTransfer = false;
}
if (!this.worldObj.isRemote && this.getEnergyStored() > 0 != doPacketUpdate)
{
this.sendPacket(2);
}
}
this.clearCache();
}
private void transfer(ITesla tesla, float transferEnergy)
{
if (transferEnergy > 0)
{
tesla.transfer(transferEnergy * (1 - (this.worldObj.rand.nextFloat() * 0.1f)), true);
this.transfer(-transferEnergy, true);
}
}
@Override
public float receiveElectricity(ElectricityPack receive, boolean doReceive)
{
return super.receiveElectricity(receive, doReceive);
}
@Override
public boolean canReceive(TileEntity tileEntity)
{
return this.canReceive && !this.outputBlacklist.contains(tileEntity) && this.getRequest(ForgeDirection.UNKNOWN) > 0;
}
@Override
public boolean canConnect(ForgeDirection direction)
{
return this.isController();
}
@Override
public ArrayList getNetworkedData(ArrayList data)
{
data.add((byte)1);
data.add(getEnergyStored());
data.add(dyeID);
data.add(canReceive);
data.add(attackEntities);
data.add(linked != null);
return data;
}
public ArrayList getEnergyPacket()
{
ArrayList data = new ArrayList();
data.add((byte)2);
data.add(getEnergyStored());
return data;
}
/**
* Do Tesla Beam.
*/
public ArrayList getTeslaPacket()
{
ArrayList data = new ArrayList();
data.add((byte)3);
return data;
}
public void sendPacket(int id)
{
switch (id)
{
case 1:
PacketHandler.sendPacket(Transmission.ALL_CLIENTS, new PacketTileEntity().setParams(Object3D.get(this), getNetworkedData(new ArrayList())));
break;
case 2:
PacketHandler.sendPacket(Transmission.ALL_CLIENTS, new PacketTileEntity().setParams(Object3D.get(this), getEnergyPacket()));
break;
case 3:
PacketHandler.sendPacket(Transmission.ALL_CLIENTS, new PacketTileEntity().setParams(Object3D.get(this), getTeslaPacket()));
break;
}
}
@Override
public void handlePacketData(ByteArrayDataInput input)
{
switch (input.readByte())
{
case 1:
this.setEnergyStored(input.readFloat());
this.dyeID = input.readInt();
this.canReceive = input.readBoolean();
this.attackEntities = input.readBoolean();
this.isLinkedClient = input.readBoolean();
break;
case 2:
this.setEnergyStored(input.readFloat());
break;
case 3:
this.doTransfer = true;
}
}
private boolean isController()
{
return this.worldObj.getBlockMetadata(this.xCoord, this.yCoord, this.zCoord) == 0;
}
private void clearCache()
{
this.topCache = null;
this.controlCache = null;
}
@Override
public float transfer(float transferEnergy, boolean doTransfer)
{
if (isController() || this.getControllingTelsa() == this)
{
if (doTransfer)
{
this.receiveElectricity(transferEnergy, true);
}
this.sendPacket(2);
return transferEnergy;
}
else
{
if (this.getEnergyStored() > 0)
{
transferEnergy += this.getEnergyStored();
this.setEnergyStored(0);
}
return this.getControllingTelsa().transfer(transferEnergy, doTransfer);
}
}
public int getRange()
{
return Math.min(4 * (this.getHeight() - 1), 50);
}
public void updatePositionStatus()
{
boolean isTop = new Vector3(this).translate(new Vector3(0, 1, 0)).getTileEntity(this.worldObj) instanceof TileEntityTesla;
boolean isBottom = new Vector3(this).translate(new Vector3(0, -1, 0)).getTileEntity(this.worldObj) instanceof TileEntityTesla;
if (isTop && isBottom)
{
this.worldObj.setBlockMetadataWithNotify(this.xCoord, this.yCoord, this.zCoord, 1, 3);
}
else if (isBottom)
{
this.worldObj.setBlockMetadataWithNotify(this.xCoord, this.yCoord, this.zCoord, 2, 3);
}
else
{
this.worldObj.setBlockMetadataWithNotify(this.xCoord, this.yCoord, this.zCoord, 0, 3);
}
}
/**
* Called only on bottom.
*
* @return The highest Tesla coil in this tower.
*/
public TileEntityTesla getTopTelsa()
{
if (this.topCache != null)
{
return this.topCache;
}
this.connectedTeslas.clear();
Vector3 checkPosition = new Vector3(this);
TileEntityTesla returnTile = this;
while (true)
{
TileEntity t = checkPosition.getTileEntity(this.worldObj);
if (t instanceof TileEntityTesla)
{
this.connectedTeslas.add((TileEntityTesla) t);
returnTile = (TileEntityTesla) t;
}
else
{
break;
}
checkPosition.y++;
}
this.topCache = returnTile;
return returnTile;
}
/**
* For non-controlling Tesla to use.
*
* @return
*/
public TileEntityTesla getControllingTelsa()
{
if (this.controlCache != null)
{
return this.controlCache;
}
Vector3 checkPosition = new Vector3(this);
TileEntityTesla returnTile = this;
while (true)
{
TileEntity t = checkPosition.getTileEntity(this.worldObj);
if (t instanceof TileEntityTesla)
{
returnTile = (TileEntityTesla) t;
}
else
{
break;
}
checkPosition.y--;
}
this.controlCache = returnTile;
return returnTile;
}
/**
* Called only on bottom.
*
* @return The highest Tesla coil in this tower.
*/
public int getHeight()
{
this.connectedTeslas.clear();
int y = 0;
while (true)
{
TileEntity t = new Vector3(this).translate(new Vector3(0, y, 0)).getTileEntity(this.worldObj);
if (t instanceof TileEntityTesla)
{
this.connectedTeslas.add((TileEntityTesla) t);
y++;
}
else
{
break;
}
}
return y;
}
@Override
public void invalidate()
{
TeslaGrid.instance().unregister(this);
super.invalidate();
}
@Override
public void validate()
{
super.validate();
if(worldObj.isRemote)
{
PacketHandler.sendPacket(Transmission.SERVER, new PacketDataRequest().setParams(Object3D.get(this)));
}
}
public void setDye(int id)
{
this.dyeID = id;
this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord);
}
public boolean toggleReceive()
{
return this.canReceive = !this.canReceive;
}
public boolean toggleEntityAttack()
{
boolean returnBool = this.attackEntities = !this.attackEntities;
this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord);
return returnBool;
}
/**
* Reads a tile entity from NBT.
*/
@Override
public void readFromNBT(NBTTagCompound nbt)
{
super.readFromNBT(nbt);
this.dyeID = nbt.getInteger("dyeID");
this.canReceive = nbt.getBoolean("canReceive");
this.attackEntities = nbt.getBoolean("attackEntities");
if (nbt.hasKey("link_x") && nbt.hasKey("link_y") && nbt.hasKey("link_z"))
{
this.linked = new Vector3(nbt.getInteger("link_x"), nbt.getInteger("link_y"), nbt.getInteger("link_z"));
this.linkDim = nbt.getInteger("linkDim");
}
}
/**
* Writes a tile entity to NBT.
*/
@Override
public void writeToNBT(NBTTagCompound nbt)
{
super.writeToNBT(nbt);
nbt.setInteger("dyeID", this.dyeID);
nbt.setBoolean("canReceive", this.canReceive);
nbt.setBoolean("attackEntities", this.attackEntities);
if (this.linked != null)
{
nbt.setInteger("link_x", (int) this.linked.x);
nbt.setInteger("link_y", (int) this.linked.y);
nbt.setInteger("link_z", (int) this.linked.z);
nbt.setInteger("linkDim", this.linkDim);
}
}
public void setLink(Vector3 vector3, int dimID, boolean setOpponent)
{
if (!this.worldObj.isRemote)
{
World otherWorld = MinecraftServer.getServer().worldServerForDimension(this.linkDim);
if (setOpponent && this.linked != null && otherWorld != null)
{
TileEntity tileEntity = this.linked.getTileEntity(otherWorld);
if (tileEntity instanceof TileEntityTesla)
{
((TileEntityTesla) tileEntity).setLink(null, this.linkDim, false);
}
}
this.linked = vector3;
this.linkDim = dimID;
this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord);
World newOtherWorld = MinecraftServer.getServer().worldServerForDimension(this.linkDim);
if (setOpponent && newOtherWorld != null && this.linked != null)
{
TileEntity tileEntity = this.linked.getTileEntity(newOtherWorld);
if (tileEntity instanceof TileEntityTesla)
{
((TileEntityTesla) tileEntity).setLink(new Vector3(this), this.worldObj.provider.dimensionId, false);
}
}
}
}
@Override
public float getRequest(ForgeDirection direction)
{
if (direction != ForgeDirection.DOWN)
{
return this.getMaxEnergyStored() - this.getEnergyStored();
}
return 0;
}
@Override
public float getProvide(ForgeDirection direction)
{
if (this.isController() && direction == ForgeDirection.DOWN)
{
return this.getEnergyStored();
}
return 0;
}
@Override
public float getMaxEnergyStored()
{
return TRANSFER_CAP;
}
@Override
public EnumSet<ForgeDirection> getInputDirections()
{
EnumSet input = EnumSet.allOf(ForgeDirection.class);
input.remove(ForgeDirection.DOWN);
return input;
}
@Override
public EnumSet<ForgeDirection> getOutputDirections()
{
return EnumSet.of(ForgeDirection.DOWN);
}
}

View file

@ -0,0 +1,135 @@
package mekanism.induction.common.wire;
import java.util.List;
import mekanism.common.Mekanism;
import mekanism.induction.common.MekanismInduction;
import net.minecraft.block.Block;
import net.minecraft.block.BlockColored;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import universalelectricity.prefab.block.BlockConductor;
/**
* A copper wire block that can change its collision bounds based on the connection.
*
* @author Calclavia, Aidancbrady
*/
public class BlockWire extends BlockConductor
{
public BlockWire(int id)
{
super(MekanismInduction.CONFIGURATION.getBlock("wire", id).getInt(id), Material.cloth);
this.setUnlocalizedName(MekanismInduction.PREFIX + "wire");
this.setStepSound(soundClothFootstep);
this.setResistance(0.2F);
this.setHardness(0.1f);
this.setBlockBounds(0.3f, 0.3f, 0.3f, 0.7f, 0.7f, 0.7f);
this.setCreativeTab(CreativeTabs.tabRedstone);
Block.setBurnProperties(this.blockID, 30, 60);
this.setTextureName(MekanismInduction.PREFIX + "wire");
this.setCreativeTab(Mekanism.tabMekanism);
}
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int par6, float par7, float par8, float par9)
{
TileEntity t = world.getBlockTileEntity(x, y, z);
TileEntityWire tileEntity = (TileEntityWire) t;
if (entityPlayer.getCurrentEquippedItem() != null)
{
if (entityPlayer.getCurrentEquippedItem().itemID == Item.dyePowder.itemID)
{
tileEntity.setDye(entityPlayer.getCurrentEquippedItem().getItemDamage());
return true;
}
else if (entityPlayer.getCurrentEquippedItem().itemID == Block.cloth.blockID && !tileEntity.isInsulated)
{
tileEntity.setInsulated();
tileEntity.setDye(BlockColored.getDyeFromBlock(entityPlayer.getCurrentEquippedItem().getItemDamage()));
entityPlayer.inventory.decrStackSize(entityPlayer.inventory.currentItem, 1);
return true;
}
}
return false;
}
/**
* Is this block (a) opaque and (b) a full 1m cube? This determines whether or not to render the
* shared face of two adjacent blocks and also whether the player can attach torches, redstone
* wire, etc to this block.
*/
@Override
public boolean isOpaqueCube()
{
return false;
}
/**
* If this block doesn't render as an ordinary block it will return False (examples: signs,
* buttons, stairs, etc)
*/
@Override
public boolean renderAsNormalBlock()
{
return false;
}
/**
* The type of render function that is called for this block
*/
@Override
public int getRenderType()
{
return -1;
}
@Override
public TileEntity createNewTileEntity(World var1)
{
return new TileEntityWire();
}
@Override
public int damageDropped(int par1)
{
return par1;
}
@Override
public void getSubBlocks(int par1, CreativeTabs par2CreativeTabs, List par3List)
{
for (int i = 0; i < EnumWireMaterial.values().length; i++)
{
par3List.add(new ItemStack(par1, 1, i));
}
}
@Override
public void breakBlock(World world, int x, int y, int z, int par5, int par6)
{
TileEntity t = world.getBlockTileEntity(x, y, z);
/**
* Drop wool insulation if the wire is insulated.
*/
if (t instanceof TileEntityWire)
{
TileEntityWire tileEntity = (TileEntityWire) t;
if (tileEntity.isInsulated)
{
this.dropBlockAsItem_do(world, x, y, z, new ItemStack(Block.cloth, 1, BlockColored.getBlockFromDye(tileEntity.dyeID)));
}
}
super.breakBlock(world, x, y, z, par5, par6);
}
}

View file

@ -0,0 +1,69 @@
package mekanism.induction.common.wire;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
import universalelectricity.core.vector.Vector3;
/**
* An enumerator for different wire materials. The metadata of the wire determines the type of the
* wire.
*
* @author Calclavia
*
*/
public enum EnumWireMaterial
{
COPPER(12.5f, 3, 2, new Vector3(184, 115, 51)), TIN(13, 2, 0.5f, new Vector3(132, 132, 130)),
IRON(0.1f, 2, 4, new Vector3(97, 102, 105)),
ALUMINUM(0.025f, 6, 0.15f, new Vector3(215, 205, 181)),
SILVER(0.005f, 1, 2, new Vector3(192, 192, 192)),
SUPERCONDUCTOR(0, 8, Float.MAX_VALUE, new Vector3(212, 175, 55));
public final float resistance;
public final float damage;
public final float maxAmps;
public final Vector3 color;
private ItemStack wire;
EnumWireMaterial(float resistance, float electrocutionDamage, float maxAmps, Vector3 color)
{
this.resistance = resistance;
this.damage = electrocutionDamage;
this.maxAmps = maxAmps;
this.color = color.scale(1D / 255D);
}
public ItemStack getWire()
{
return this.getWire(1);
}
public ItemStack getWire(int amount)
{
ItemStack returnStack = this.wire.copy();
returnStack.stackSize = amount;
return returnStack;
}
public void setWire(ItemStack item)
{
if (this.wire == null)
{
this.wire = item;
OreDictionary.registerOre(this.name().toLowerCase() + "Wire", this.wire);
}
}
public void setWire(Item item)
{
this.setWire(new ItemStack(item, 1, this.ordinal()));
}
public void setWire(Block block)
{
this.setWire(new ItemStack(block, 1, this.ordinal()));
}
}

View file

@ -0,0 +1,6 @@
package mekanism.induction.common.wire;
public interface IInsulatedMaterial extends IInsulation, IWireMaterial
{
}

View file

@ -0,0 +1,12 @@
package mekanism.induction.common.wire;
public interface IInsulation
{
public boolean isInsulated();
public void setInsulated(boolean insulated);
public int getInsulationColor();
public void setInsulationColor(int dyeID);
}

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