Added some Armbot API

This commit is contained in:
Henry Mao 2013-02-03 12:30:40 +08:00
parent d5e61527d0
commit 934f7cca17
26 changed files with 211 additions and 642 deletions

View file

@ -11,5 +11,23 @@ import net.minecraft.entity.Entity;
*/
public interface IArmbot
{
/**
* Adds an entity to the Armbot's grab list.
*/
public void grabEntity(Entity entity);
/**
* Drops a specific entity from the Armbot's hand.
*/
public void dropEntity(Entity entity);
/**
* Drops all entities in the Armbot's hand.
*/
public void dropAll();
/**
* @return Returns all entities being grabbed by the Armbot.
*/
public List<Entity> getGrabbedEntities();
}

View file

@ -16,6 +16,6 @@ public interface IArmbotUseable
*
* @param armbot - The Armbot instance.
*/
public boolean onUse(IArmbot armbot);
public boolean onUse(IArmbot armbot, String[] args);
}

View file

@ -62,17 +62,17 @@ public class RenderArmbot extends TileEntitySpecialRenderer
GL11.glPushMatrix();
GL11.glRotatef(180, 0, 0, 1);
for (Entity entity : ((TileEntityArmbot) tileEntity).grabbedEntities)
for (Entity entity : ((TileEntityArmbot) tileEntity).getGrabbedEntities())
{
if (entity != null && entity instanceof EntityItem) // items don't move right, so we
// render them manually
// Items don't move right, so we render them manually
if (entity != null && entity instanceof EntityItem)
{
EntityItem item = (EntityItem) entity;
item.age = 0;
EntityItem entityItem = (EntityItem) entity;
RenderItem render = (RenderItem) RenderManager.instance.getEntityRenderObject(entity);
if (render != null)
{
render.doRender(item, -handPos.x + 0.5f, handPos.y - 1.5f, -handPos.z + 0.5f, 0, 0);
render.doRender(entityItem, -handPos.x + 0.5f, handPos.y - 1.5f, -handPos.z + 0.5f, 0, 0);
}
}
}

View file

@ -13,8 +13,8 @@ import assemblyline.common.AssemblyLine;
public class RenderCraneController extends RenderImprintable
{
public static final String TEXTURE = "QuarryControllerMap.png";
public static final ModelCraneController MODEL = new ModelCraneController();
public static final String TEXTURE = "quarry_controller_map.png";
public static final ModelCraneController MODEL = new ModelCraneController();
@Override
public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float f)

View file

@ -0,0 +1,75 @@
package assemblyline.common.machine;
import ic2.api.Direction;
import ic2.api.energy.event.EnergyTileLoadEvent;
import ic2.api.energy.event.EnergyTileUnloadEvent;
import ic2.api.energy.tile.IEnergySink;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.MinecraftForge;
import universalelectricity.core.UniversalElectricity;
import universalelectricity.core.electricity.ElectricityPack;
import universalelectricity.prefab.tile.TileEntityElectricityRunnable;
public class TIC2Receiver extends TileEntityElectricityRunnable implements IEnergySink
{
@Override
public void initiate()
{
super.initiate();
MinecraftForge.EVENT_BUS.post(new EnergyTileLoadEvent(this));
}
@Override
public void invalidate()
{
MinecraftForge.EVENT_BUS.post(new EnergyTileUnloadEvent(this));
super.invalidate();
}
@Override
public boolean acceptsEnergyFrom(TileEntity emitter, Direction direction)
{
if (this.getConsumingSides() != null)
{
return this.getConsumingSides().contains(direction.toForgeDirection());
}
else
{
return true;
}
}
@Override
public boolean isAddedToEnergyNet()
{
return this.ticks > 0;
}
@Override
public int demandsEnergy()
{
return (int) (this.getRequest().getWatts() * UniversalElectricity.TO_IC2_RATIO);
}
@Override
public int injectEnergy(Direction direction, int i)
{
double givenElectricity = i * UniversalElectricity.IC2_RATIO;
double rejects = 0;
if (givenElectricity > this.getWattBuffer())
{
rejects = givenElectricity - this.getRequest().getWatts();
}
this.onReceive(new ElectricityPack(givenElectricity / this.getVoltage(), this.getVoltage()));
return (int) (rejects * UniversalElectricity.TO_IC2_RATIO);
}
@Override
public int getMaxSafeInput()
{
return 2048;
}
}

View file

@ -6,7 +6,6 @@ import net.minecraftforge.common.ForgeDirection;
import universalelectricity.core.electricity.ElectricityNetwork;
import universalelectricity.core.electricity.ElectricityPack;
import universalelectricity.prefab.network.PacketManager;
import universalelectricity.prefab.tile.TileEntityElectricityReceiver;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.relauncher.Side;
@ -17,13 +16,8 @@ import cpw.mods.fml.relauncher.Side;
* @author Calclavia
*
*/
public abstract class TileEntityAssemblyNetwork extends TileEntityElectricityReceiver
public abstract class TileEntityAssemblyNetwork extends TIC2Receiver
{
/**
* The amount of watts received.
*/
public double wattsReceived = 0;
public boolean debugMode = false;
/**
* The range in which power can be transfered.
@ -32,7 +26,7 @@ public abstract class TileEntityAssemblyNetwork extends TileEntityElectricityRec
public boolean isRunning()
{
return debugMode || this.powerTransferRange > 0 || this.wattsReceived > this.getRequest().getWatts();
return this.debugMode || this.powerTransferRange > 0 || this.wattsReceived > this.getRequest().getWatts();
}
public void updatePowerTransferRange()
@ -66,18 +60,6 @@ public abstract class TileEntityAssemblyNetwork extends TileEntityElectricityRec
{
super.updateEntity();
if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER)
{
if (this.wattsReceived < this.getRequest().getWatts())
{
this.wattsReceived += ElectricityNetwork.consumeFromMultipleSides(this, this.getRequest()).getWatts() * 2;
}
else
{
ElectricityNetwork.consumeFromMultipleSides(this, new ElectricityPack());
}
}
this.onUpdate();
if (this.ticks % 10 == 0)
@ -85,7 +67,6 @@ public abstract class TileEntityAssemblyNetwork extends TileEntityElectricityRec
if (this.wattsReceived >= this.getRequest().getWatts())
{
this.wattsReceived -= getRequest().getWatts();
// this.wattsReceived = 0;
this.powerTransferRange = this.getMaxTransferRange();
}
else
@ -109,9 +90,10 @@ public abstract class TileEntityAssemblyNetwork extends TileEntityElectricityRec
}
protected ElectricityPack getRequest()
@Override
public ElectricityPack getRequest()
{
return new ElectricityPack(10, this.getVoltage());
return new ElectricityPack(1, this.getVoltage());
}
protected int getMaxTransferRange()

View file

@ -80,7 +80,7 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult
/**
* An entity that the armbot is grabbed onto.
*/
public final List<Entity> grabbedEntities = new ArrayList<Entity>();
private final List<Entity> grabbedEntities = new ArrayList<Entity>();
@Override
public void initiate()
@ -489,7 +489,8 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult
}
}
/*
* NBTTagCompound cmdManager = nbt.getCompoundTag("cmdManager"); this.commandManager.readFromNBT(this, cmdManager);
* NBTTagCompound cmdManager = nbt.getCompoundTag("cmdManager");
* this.commandManager.readFromNBT(this, cmdManager);
*/
this.commandManager.setCurrentTask(nbt.getInteger("curTask"));
@ -526,7 +527,8 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult
nbt.setFloat("pitch", this.rotationPitch);
/*
* NBTTagCompound cmdManager = new NBTTagCompound("cmdManager"); this.commandManager.writeToNBT(cmdManager); nbt.setCompoundTag("cmdManager", cmdManager);
* NBTTagCompound cmdManager = new NBTTagCompound("cmdManager");
* this.commandManager.writeToNBT(cmdManager); nbt.setCompoundTag("cmdManager", cmdManager);
*/
nbt.setString("cmdText", this.displayText);
@ -872,4 +874,34 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult
return this.grabbedEntities;
}
@Override
public void grabEntity(Entity entity)
{
this.grabbedEntities.add(entity);
if (entity instanceof EntityItem)
{
// Items don't move right, so we render them manually
this.worldObj.removeEntity(entity);
}
entity.isDead = false;
}
@Override
public void dropEntity(Entity entity)
{
this.grabbedEntities.remove(entity);
}
@Override
public void dropAll()
{
for (Entity entity : this.grabbedEntities)
{
this.dropEntity(entity);
}
this.grabbedEntities.clear();
}
}

View file

@ -33,14 +33,16 @@ public class CommandBreak extends Command
if (block != null && BREAK_TIME <= this.ticks)
{
ArrayList<ItemStack> items = block.getBlockDropped(this.world, serachPosition.intX(), serachPosition.intY(), serachPosition.intZ(), serachPosition.getBlockMetadata(world), 0);
if (!keep || items.size() > 1)
if (!this.keep || items.size() > 1)
{
this.dropBlockAsItem(this.world, serachPosition.intX(), serachPosition.intY(), serachPosition.intZ());
}
else
{
this.tileEntity.grabbedEntities.add(new EntityItem(world, (double) serachPosition.intX() + 0.5D, (double) serachPosition.intY() + 0.5D, (double) serachPosition.intZ() + 0.5D, items.get(0)));
this.tileEntity.grabEntity(new EntityItem(this.world, (double) serachPosition.intX() + 0.5D, (double) serachPosition.intY() + 0.5D, (double) serachPosition.intZ() + 0.5D, items.get(0)));
}
serachPosition.setBlockWithNotify(this.world, 0);
return true;
}

View file

@ -10,10 +10,10 @@ public class CommandDrop extends Command
{
super.doTask();
if (this.tileEntity.grabbedEntities.size() == 0)
if (this.tileEntity.getGrabbedEntities().size() == 0)
return false;
for (Entity entity : this.tileEntity.grabbedEntities)
for (Entity entity : this.tileEntity.getGrabbedEntities())
{
if (entity != null)
{
@ -33,7 +33,7 @@ public class CommandDrop extends Command
this.world.playSound(this.tileEntity.xCoord, this.tileEntity.yCoord, this.tileEntity.zCoord, "random.pop", 0.2F, ((this.tileEntity.worldObj.rand.nextFloat() - this.tileEntity.worldObj.rand.nextFloat()) * 0.7F + 1.0F) * 1.0F, true);
this.tileEntity.grabbedEntities.clear();
this.tileEntity.getGrabbedEntities().clear();
return false;
}

View file

@ -61,9 +61,9 @@ public class CommandFire extends Command
{
this.finalVelocity = new Vector3(0, 0, 0);
}
if (this.tileEntity.grabbedEntities.size() > 0)
if (this.tileEntity.getGrabbedEntities().size() > 0)
{
Entity held = this.tileEntity.grabbedEntities.get(0);
Entity held = this.tileEntity.getGrabbedEntities().get(0);
if (held != null)
{
this.world.playSound(this.tileEntity.xCoord, this.tileEntity.yCoord, this.tileEntity.zCoord, "random.bow", velocity, 2f - (velocity / 4f), true);

View file

@ -35,7 +35,7 @@ public class CommandGrab extends Command
{
super.doTask();
if (this.tileEntity.grabbedEntities.size() > 0)
if (this.tileEntity.getGrabbedEntities().size() > 0)
return false;
Vector3 serachPosition = this.tileEntity.getHandPosition();
@ -47,16 +47,7 @@ public class CommandGrab extends Command
{
if (found.get(i) != null && !(found.get(i) instanceof EntityPlayer) && !(found.get(i) instanceof EntityArrow) && found.get(i).ridingEntity == null)
{
this.tileEntity.grabbedEntities.add(found.get(i));
if (found.get(i) instanceof EntityItem)
{
// items don't move right, so we render them manually
this.tileEntity.worldObj.removeEntity(found.get(i));
}
found.get(i).isDead = false;
this.tileEntity.grabEntity(found.get(i));
this.world.playSound(this.tileEntity.xCoord, this.tileEntity.yCoord, this.tileEntity.zCoord, "random.pop", 0.2F, ((this.tileEntity.worldObj.rand.nextFloat() - this.tileEntity.worldObj.rand.nextFloat()) * 0.7F + 1.0F) * 1.0F, true);
return false;
}

View file

@ -35,7 +35,7 @@ public class CommandPlace extends Command
if (block == null && ticks >= this.PLACE_TIME)
{
for (Entity entity : this.tileEntity.grabbedEntities)
for (Entity entity : this.tileEntity.getGrabbedEntities())
{
if (entity instanceof EntityItem)
{
@ -47,7 +47,7 @@ public class CommandPlace extends Command
{
((ItemBlock) itemStack.getItem()).placeBlockAt(itemStack, null, this.world, serachPosition.intX(), serachPosition.intY(), serachPosition.intZ(), 0, 0.5f, 0.5f, 0.5f, itemStack.getItemDamage());
this.tileEntity.grabbedEntities.remove(entity);
this.tileEntity.dropEntity(entity);
return false;
}
else if (itemStack.getItem() instanceof IPlantable)
@ -68,7 +68,7 @@ public class CommandPlace extends Command
{
Block.blocksList[blockID].onBlockPlacedBy(world, serachPosition.intX(), serachPosition.intY(), serachPosition.intZ(), null);
Block.blocksList[blockID].onPostBlockPlaced(world, serachPosition.intX(), serachPosition.intY(), serachPosition.intZ(), blockMetadata);
this.tileEntity.grabbedEntities.remove(entity);
this.tileEntity.dropEntity(entity);
return false;
}
}

View file

@ -34,7 +34,7 @@ public class CommandUse extends Command
{
if (targetTile instanceof IArmbotUseable)
{
((IArmbotUseable) targetTile).onUse(this.tileEntity);
((IArmbotUseable) targetTile).onUse(this.tileEntity, this.getArgs());
}
}

View file

@ -9,7 +9,6 @@ import assemblyline.common.AssemblyLine;
public class ContainerImprinter extends Container implements ISlotWatcher
{
private InventoryPlayer inventoryPlayer;
public TileEntityImprinter tileEntity;

View file

@ -59,15 +59,12 @@ public class TileEntityImprinter extends TileEntityAdvanced implements ISidedInv
@Override
public int getStartInventorySide(ForgeDirection side)
{
if (side == ForgeDirection.UP || side == ForgeDirection.DOWN)
return 3;
return imprinterMatrix.length;
return INVENTORY_START;
}
@Override
public int getSizeInventorySide(ForgeDirection side)
{
if (side == ForgeDirection.UP || side == ForgeDirection.DOWN) { return 1; }
return containingItems.length;
}
@ -624,108 +621,53 @@ public class TileEntityImprinter extends TileEntityAdvanced implements ISidedInv
* @return
*/
@Override
public boolean onUse(IArmbot armbot)
public boolean onUse(IArmbot armbot, String[] args)
{
this.onInventoryChanged();
TileEntityArmbot armbotTile = (TileEntityArmbot) armbot;
if (armbotTile.getGrabbedEntities().size() > 0)
if (this.imprinterMatrix[3] != null)
{
Entity heldEntity = armbot.getGrabbedEntities().get(0);
if (heldEntity != null)
{
if (heldEntity instanceof EntityItem)
{
ItemStack stack = ((EntityItem) heldEntity).getEntityItem();
if (this.getStackInSlot(3) == null && stack != null && stack.itemID == AssemblyLine.itemImprint.itemID)
{
this.setInventorySlotContents(3, stack);
this.onInventoryChanged();
armbotTile.grabbedEntities.remove(0);
return true;
}
else if (this.getStackInSlot(3) != null && stack != null)
{
ItemStack result = this.getStackInSlot(4); // crafting result
if (result != null)
{
result = this.getStackInSlot(4);
if (stack.isItemEqual(result))
{
if (result != null)
{
ItemStack[] requiredItems = this.getIdealRecipe(result).getValue().clone();
if (requiredItems != null)
{
for (ItemStack searchStack : requiredItems)
{
for (int i = 0; i < this.getSizeInventory(); i++)
{
ItemStack checkStack = this.getStackInSlot(i);
if (checkStack != null)
{
if (searchStack.isItemEqual(checkStack))
{
this.decrStackSize(i + INVENTORY_START, 1);
break;
}
}
}
}
}
}
if (stack.isStackable())
{
stack.stackSize += result.stackSize;
this.onInventoryChanged();
armbotTile.grabbedEntities.remove(0);
armbotTile.grabbedEntities.add(new EntityItem(this.worldObj, this.xCoord, this.yCoord, this.zCoord, stack));
return true;
}
}
}
}
}
}
else
{
ItemStack result = this.getStackInSlot(4); // crafting result
if (result != null)
{
result = this.getStackInSlot(4);
if (result != null)
{
ItemStack[] requiredItems = this.getIdealRecipe(result).getValue().clone();
if (requiredItems != null)
{
for (ItemStack searchStack : requiredItems)
{
for (int i = 0; i < this.getSizeInventory(); i++)
{
ItemStack checkStack = this.getStackInSlot(i);
if (checkStack != null)
{
if (searchStack.isItemEqual(checkStack) || (searchStack.itemID == checkStack.itemID && searchStack.getItemDamage() < 0))
{
this.decrStackSize(i + INVENTORY_START, 1);
break;
}
}
}
}
}
}
this.onInventoryChanged();
armbotTile.grabbedEntities.add(new EntityItem(this.worldObj, this.xCoord, this.yCoord, this.zCoord, result));
return true;
}
}
armbot.grabEntity(new EntityItem(this.worldObj, this.xCoord + 0.5, this.yCoord + 0.5, this.zCoord + 0.5, this.imprinterMatrix[3]));
this.imprinterMatrix[3] = null;
}
/*
* if (armbotTile.getGrabbedEntities().size() > 0) { Entity heldEntity =
* armbot.getGrabbedEntities().get(0);
*
* if (heldEntity != null) { if (heldEntity instanceof EntityItem) { ItemStack stack =
* ((EntityItem) heldEntity).getEntityItem(); if (this.getStackInSlot(3) == null && stack !=
* null && stack.itemID == AssemblyLine.itemImprint.itemID) {
* this.setInventorySlotContents(3, stack); this.onInventoryChanged();
* armbotTile.grabbedEntities.remove(0); return true; } else if (this.getStackInSlot(3) !=
* null && stack != null) { // Crafting Result ItemStack result = this.getStackInSlot(4); if
* (result != null) { result = this.getStackInSlot(4); if (stack.isItemEqual(result)) { if
* (result != null) { ItemStack[] requiredItems =
* this.getIdealRecipe(result).getValue().clone();
*
* if (requiredItems != null) { for (ItemStack searchStack : requiredItems) { for (int i =
* 0; i < this.getSizeInventory(); i++) { ItemStack checkStack = this.getStackInSlot(i);
*
* if (checkStack != null) { if (searchStack.isItemEqual(checkStack)) { this.decrStackSize(i
* + INVENTORY_START, 1); break; } } } } } } if (stack.isStackable()) { stack.stackSize +=
* result.stackSize; this.onInventoryChanged(); armbotTile.grabbedEntities.remove(0);
* armbotTile.grabbedEntities.add(new EntityItem(this.worldObj, this.xCoord, this.yCoord,
* this.zCoord, stack)); return true; } } } } } } else { ItemStack result =
* this.getStackInSlot(4); // crafting result if (result != null) { result =
* this.getStackInSlot(4); if (result != null) { ItemStack[] requiredItems =
* this.getIdealRecipe(result).getValue().clone();
*
* if (requiredItems != null) { for (ItemStack searchStack : requiredItems) { for (int i =
* 0; i < this.getSizeInventory(); i++) { ItemStack checkStack = this.getStackInSlot(i);
*
* if (checkStack != null) { if (searchStack.isItemEqual(checkStack) || (searchStack.itemID
* == checkStack.itemID && searchStack.getItemDamage() < 0)) { this.decrStackSize(i +
* INVENTORY_START, 1); break; } } } } } } this.onInventoryChanged();
* armbotTile.grabbedEntities.add(new EntityItem(this.worldObj, this.xCoord, this.yCoord,
* this.zCoord, result)); return true; } } }
*/
return false;
}

View file

@ -2,9 +2,9 @@ package universalelectricity.core;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.ForgeSubscribe;
import net.minecraftforge.event.world.WorldEvent.Unload;
import net.minecraftforge.event.world.ChunkEvent;
import net.minecraftforge.event.world.WorldEvent;
import universalelectricity.core.electricity.Electricity;
import universalelectricity.core.electricity.ElectricityConnections;
import cpw.mods.fml.common.FMLLog;
import cpw.mods.fml.common.Loader;
@ -34,24 +34,6 @@ public class UELoader
UniversalElectricity.TO_IC2_RATIO = 1 / UniversalElectricity.IC2_RATIO;
UniversalElectricity.TO_BC_RATIO = 1 / UniversalElectricity.BC3_RATIO;
if (UniversalElectricity.BC3_RATIO <= 0 || !Loader.isModLoaded("BuildCraft|Core"))
{
System.out.println("Disabled Buildcraft electricity conversion!");
}
else
{
System.out.println("Buildcraft conversion ratio: " + UniversalElectricity.BC3_RATIO);
}
if (UniversalElectricity.IC2_RATIO <= 0 || !Loader.isModLoaded("IC2"))
{
System.out.println("Disabled Industrialcraft electricity conversion!");
}
else
{
System.out.println("IC2 conversion ratio: " + UniversalElectricity.IC2_RATIO);
}
FMLLog.finest("Universal Electricity v" + UniversalElectricity.VERSION + " successfully loaded!");
isInitialized = true;
@ -59,9 +41,16 @@ public class UELoader
}
@ForgeSubscribe
public void onWorldUnload(Unload event)
public void onWorldUnLoad(WorldEvent.Unload event)
{
Electricity.instance = new Electricity();
ElectricityConnections.clearAll();
Electricity.instance.cleanUpNetworks();
}
@ForgeSubscribe
public void onWorldLoad(WorldEvent.Load event)
{
Electricity.instance = new Electricity();
Electricity.instance.cleanUpNetworks();
}
}

View file

@ -31,7 +31,7 @@ public class UniversalElectricity
*/
public static final int MAJOR_VERSION = 1;
public static final int MINOR_VERSION = 2;
public static final int REVISION_VERSION = 4;
public static final int REVISION_VERSION = 5;
public static final String VERSION = MAJOR_VERSION + "." + MINOR_VERSION + "." + REVISION_VERSION;
/**

View file

@ -11,8 +11,6 @@ import universalelectricity.core.vector.Vector3;
import cpw.mods.fml.common.FMLLog;
/**
* THIS IS THE NEW ELECTRICITY MANAGER. THIS IS ONLY A DRAFT!
*
* The Electricity Network Manager.
*
* @author Calclavia

View file

@ -1,22 +0,0 @@
package universalelectricity.prefab.modifier;
import net.minecraft.item.ItemStack;
/**
* This must be applied to an item that acts as a modifier or an upgrade.
*
* @author Calclavia
*
*/
public interface IModifier
{
/**
* @return - The name of the modifier.
*/
public String getName(ItemStack itemstack);
/**
* @return - How much effect does this modifier have?
*/
public int getEffectiveness(ItemStack itemstack);
}

View file

@ -1,29 +0,0 @@
package universalelectricity.prefab.modifier;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
/**
* This slot should be used by any container that contains an item that is a modifier. An example of
* this would be upgrade slots.
*
* @author Calclavia
*
*/
public class SlotModifier extends Slot
{
public SlotModifier(IInventory par2IInventory, int par3, int par4, int par5)
{
super(par2IInventory, par3, par4, par5);
}
/**
* Check if the stack is a valid item for this slot. Always true beside for the armor slots.
*/
@Override
public boolean isItemValid(ItemStack par1ItemStack)
{
return par1ItemStack.getItem() instanceof IModifier;
}
}

View file

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

View file

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

View file

@ -1,17 +0,0 @@
package universalelectricity.prefab.ore;
import net.minecraft.item.ItemStack;
public class OreGenReplaceStone extends OreGenReplace
{
public OreGenReplaceStone(String name, String oreDiectionaryName, ItemStack stack, int minGenerateLevel, int maxGenerateLevel, int amountPerChunk, int amountPerBranch, String harvestTool, int harvestLevel)
{
super(name, oreDiectionaryName, stack, 1, minGenerateLevel, maxGenerateLevel, amountPerChunk, amountPerBranch, harvestTool, harvestLevel);
}
// A simplified version of the constructor
public OreGenReplaceStone(String name, String oreDiectionaryName, ItemStack stack, int maxGenerateLevel, int amountPerChunk, int amountPerBranch)
{
this(name, oreDiectionaryName, stack, 0, maxGenerateLevel, amountPerChunk, amountPerBranch, "pickaxe", 1);
}
}

View file

@ -1,75 +0,0 @@
package universalelectricity.prefab.ore;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import net.minecraft.world.World;
import net.minecraft.world.chunk.IChunkProvider;
import cpw.mods.fml.common.IWorldGenerator;
import cpw.mods.fml.common.registry.GameRegistry;
public class OreGenerator implements IWorldGenerator
{
public static boolean isInitiated = false;
/**
* Add your ore data to this list of ores for it to automatically generate! No hassle indeed!
*/
private static final List<OreGenBase> ORES_TO_GENERATE = new ArrayList<OreGenBase>();
/**
* Adds an ore to the ore generate list. Do this in pre-init.
*/
public static void addOre(OreGenBase data)
{
if (!isInitiated)
{
GameRegistry.registerWorldGenerator(new OreGenerator());
}
ORES_TO_GENERATE.add(data);
}
/**
* Checks to see if this ore
*
* @param oreName
* @return
*/
public static boolean oreExists(String oreName)
{
for (OreGenBase ore : ORES_TO_GENERATE)
{
if (ore.oreDictionaryName == oreName) { return true; }
}
return false;
}
/**
* Removes an ore to the ore generate list. Do this in init.
*/
public static void removeOre(OreGenBase data)
{
ORES_TO_GENERATE.remove(data);
}
@Override
public void generate(Random rand, int chunkX, int chunkZ, World world, IChunkProvider chunkGenerator, IChunkProvider chunkProvider)
{
chunkX = chunkX << 4;
chunkZ = chunkZ << 4;
// Checks to make sure this is the normal
// world
for (OreGenBase oreData : ORES_TO_GENERATE)
{
if (oreData.shouldGenerate && oreData.isOreGeneratedInWorld(world, chunkGenerator))
{
oreData.generate(world, rand, chunkX, chunkZ);
}
}
}
}

View file

@ -1,37 +0,0 @@
package universalelectricity.prefab.potion;
import net.minecraft.potion.Potion;
import cpw.mods.fml.common.registry.LanguageRegistry;
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);
LanguageRegistry.instance().addStringLocalization(this.getName(), name);
}
@Override
public Potion setIconIndex(int par1, int par2)
{
super.setIconIndex(par1, par2);
return this;
}
/**
* You must register all your potion effects during mod initialization!
*/
public void register()
{
Potion.potionTypes[this.getId()] = this;
}
}

View file

@ -1,40 +0,0 @@
package universalelectricity.prefab.potion;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
public class CustomPotionEffect extends PotionEffect
{
public CustomPotionEffect(int potionID, int duration, int amplifier)
{
super(potionID, duration, amplifier);
}
public CustomPotionEffect(Potion potion, int duration, int amplifier)
{
this(potion.getId(), duration, amplifier);
}
/**
* Creates a potion effect with custom curable items.
*
* @param curativeItems - ItemStacks that can cure this potion effect
*/
public CustomPotionEffect(int potionID, int duration, int amplifier, List<ItemStack> curativeItems)
{
super(potionID, duration, amplifier);
if (curativeItems == null)
{
this.setCurativeItems(new ArrayList<ItemStack>());
}
else
{
this.setCurativeItems(curativeItems);
}
}
}