feat: add the source code

This commit is contained in:
LordMZTE 2022-10-28 16:20:12 +02:00
parent 43b72681fa
commit 994c6746e9
Signed by: LordMZTE
GPG Key ID: B64802DC33A64FF6
284 changed files with 15413 additions and 3 deletions

4
.gitignore vendored
View File

@ -1,3 +1,7 @@
.project
.classpath
bin
.settings
.gradle
.idea
build

View File

@ -17,9 +17,22 @@ buildscript {
apply plugin: 'forge'
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
sourceSets {
api {}
}
version = "1.0"
group= "modgroup"
archivesBaseName = "modid"
group = "universalelectricity"
archivesBaseName = "mffs"
jar {
manifest {
attributes "FMLAT": "mffs_at.cfg"
}
}
minecraft {
version = "1.7.10-10.13.4.1614-1.7.10"
@ -31,7 +44,7 @@ repositories {
}
dependencies {
compile "universalelectricity:basiccomponents:1.0.0-dirty:deobf"
compile "universalelectricity:basiccomponents:1.0.2-dirty:deobf"
}
processResources

0
gradlew vendored Normal file → Executable file
View File

View File

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

View File

@ -0,0 +1,111 @@
package calclavia.lib;
import java.util.Iterator;
import java.util.List;
import net.minecraft.entity.Entity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.Vec3;
import net.minecraft.world.World;
import universalelectricity.core.vector.Vector3;
public class CalculationHelper {
public static void rotateByAngle(Vector3 vector, double yaw) {
double yawRadians = Math.toRadians(yaw);
double x = vector.x;
double z = vector.z;
if(yaw != 0.0D) {
vector.x = x * Math.cos(yawRadians) - z * Math.sin(yawRadians);
vector.z = x * Math.sin(yawRadians) + z * Math.cos(yawRadians);
}
}
public static void rotateByAngle(Vector3 vector, double yaw, double pitch) {
rotateByAngle(vector, yaw, pitch, 0.0D);
}
public static void rotateByAngle(Vector3 vector, double yaw, double pitch, double roll) {
double yawRadians = Math.toRadians(yaw);
double pitchRadians = Math.toRadians(pitch);
double rollRadians = Math.toRadians(roll);
double x = vector.x;
double y = vector.y;
double z = vector.z;
vector.x = x * Math.cos(yawRadians) * Math.cos(pitchRadians) + z * (Math.cos(yawRadians) * Math.sin(pitchRadians) * Math.sin(rollRadians) - Math.sin(yawRadians) * Math.cos(rollRadians)) + y * (Math.cos(yawRadians) * Math.sin(pitchRadians) * Math.cos(rollRadians) + Math.sin(yawRadians) * Math.sin(rollRadians));
vector.z = x * Math.sin(yawRadians) * Math.cos(pitchRadians) + z * (Math.sin(yawRadians) * Math.sin(pitchRadians) * Math.sin(rollRadians) + Math.cos(yawRadians) * Math.cos(rollRadians)) + y * (Math.sin(yawRadians) * Math.sin(pitchRadians) * Math.cos(rollRadians) - Math.cos(yawRadians) * Math.sin(rollRadians));
vector.y = -x * Math.sin(pitchRadians) + z * Math.cos(pitchRadians) * Math.sin(rollRadians) + y * Math.cos(pitchRadians) * Math.cos(rollRadians);
}
public static Vector3 getDeltaPositionFromRotation(float rotationYaw, float rotationPitch) {
rotationYaw += 90.0F;
rotationPitch = -rotationPitch;
return new Vector3(Math.cos(Math.toRadians((double)rotationYaw)), Math.sin(Math.toRadians((double)rotationPitch)), Math.sin(Math.toRadians((double)rotationYaw)));
}
public static MovingObjectPosition raytraceEntities(World world, Vector3 startPosition, float rotationYaw, float rotationPitch, boolean collisionFlag, double reachDistance) {
MovingObjectPosition pickedEntity = null;
Vec3 startingPosition = startPosition.toVec3();
Vec3 look = getDeltaPositionFromRotation(rotationYaw, rotationPitch).toVec3();
Vec3 reachPoint = Vec3.createVectorHelper(startingPosition.xCoord + look.xCoord * reachDistance, startingPosition.yCoord + look.yCoord * reachDistance, startingPosition.zCoord + look.zCoord * reachDistance);
double playerBorder = 1.1D * reachDistance;
AxisAlignedBB boxToScan = AxisAlignedBB.getBoundingBox(-playerBorder, -playerBorder, -playerBorder, playerBorder, playerBorder, playerBorder);
List entitiesHit = world.getEntitiesWithinAABBExcludingEntity((Entity)null, boxToScan);
double closestEntity = reachDistance;
if(entitiesHit != null && !entitiesHit.isEmpty()) {
Iterator i$ = entitiesHit.iterator();
while(i$.hasNext()) {
Entity entityHit = (Entity)i$.next();
if(entityHit != null && entityHit.canBeCollidedWith() && entityHit.boundingBox != null) {
float border = entityHit.getCollisionBorderSize();
AxisAlignedBB aabb = entityHit.boundingBox.expand((double)border, (double)border, (double)border);
MovingObjectPosition hitMOP = aabb.calculateIntercept(startingPosition, reachPoint);
if(hitMOP != null) {
if(aabb.isVecInside(startingPosition)) {
if(0.0D < closestEntity || closestEntity == 0.0D) {
pickedEntity = new MovingObjectPosition(entityHit);
if(pickedEntity != null) {
pickedEntity.hitVec = hitMOP.hitVec;
closestEntity = 0.0D;
}
}
} else {
double distance = startingPosition.distanceTo(hitMOP.hitVec);
if(distance < closestEntity || closestEntity == 0.0D) {
pickedEntity = new MovingObjectPosition(entityHit);
pickedEntity.hitVec = hitMOP.hitVec;
closestEntity = distance;
}
}
}
}
}
return pickedEntity;
} else {
return null;
}
}
public static MovingObjectPosition raytraceBlocks(World world, Vector3 startPosition, float rotationYaw, float rotationPitch, boolean collisionFlag, double reachDistance) {
Vector3 lookVector = getDeltaPositionFromRotation(rotationYaw, rotationPitch);
Vector3 reachPoint = Vector3.add(startPosition, Vector3.multiply(lookVector, reachDistance));
return world.rayTraceBlocks(startPosition.toVec3(), reachPoint.toVec3(), collisionFlag);
}
public static MovingObjectPosition doCustomRayTrace(World world, Vector3 startPosition, float rotationYaw, float rotationPitch, boolean collisionFlag, double reachDistance) {
MovingObjectPosition pickedBlock = raytraceBlocks(world, startPosition, rotationYaw, rotationPitch, collisionFlag, reachDistance);
MovingObjectPosition pickedEntity = raytraceEntities(world, startPosition, rotationYaw, rotationPitch, collisionFlag, reachDistance);
if(pickedBlock == null) {
return pickedEntity;
} else if(pickedEntity == null) {
return pickedBlock;
} else {
double dBlock = startPosition.distanceTo(new Vector3(pickedBlock.hitVec));
double dEntity = startPosition.distanceTo(new Vector3(pickedEntity.hitVec));
return dEntity < dBlock?pickedEntity:pickedBlock;
}
}
}

View File

@ -0,0 +1,8 @@
package calclavia.lib;
import java.util.HashSet;
public interface IPlayerUsing {
HashSet getPlayersUsing();
}

View File

@ -0,0 +1,7 @@
package calclavia.lib;
import universalelectricity.core.block.IConnector;
import universalelectricity.core.block.IVoltage;
public interface IUniversalEnergyTile extends IConnector, IVoltage {
}

View File

@ -0,0 +1,25 @@
package calclavia.lib;
import net.minecraftforge.common.util.ForgeDirection;
import universalelectricity.core.electricity.ElectricityNetworkHelper;
import universalelectricity.core.electricity.ElectricityPack;
import universalelectricity.prefab.implement.IRotatable;
import universalelectricity.prefab.tile.TileEntityElectrical;
public class TileEntityUniversalProducer extends TileEntityElectrical {
public ElectricityPack produce(double watts) {
ElectricityPack pack =
new ElectricityPack(watts / this.getVoltage(), this.getVoltage());
ElectricityPack remaining =
ElectricityNetworkHelper.produceFromMultipleSides(this, pack);
return remaining;
}
@Override
public boolean canConnect(ForgeDirection direction) {
return this instanceof IRotatable
? direction.ordinal() == this.getBlockMetadata()
: true;
}
}

View File

@ -0,0 +1,28 @@
package calclavia.lib;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import universalelectricity.prefab.implement.IRotatable;
import universalelectricity.prefab.tile.TileEntityElectricityRunnable;
public abstract class TileEntityUniversalRunnable
extends TileEntityElectricityRunnable implements IUniversalEnergyTile {
@Override
public boolean canConnect(ForgeDirection direction) {
return this instanceof IRotatable
? direction == ForgeDirection.getOrientation(this.getBlockMetadata())
.getOpposite()
: true;
}
public ForgeDirection getDirection(IBlockAccess world, int x, int y, int z) {
return ForgeDirection.getOrientation(this.getBlockMetadata());
}
public void setDirection(World world, int x, int y, int z,
ForgeDirection facingDirection) {
this.worldObj.setBlockMetadataWithNotify(
this.xCoord, this.yCoord, this.zCoord, facingDirection.ordinal(), 2);
}
}

View File

@ -0,0 +1,28 @@
package calclavia.lib;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import universalelectricity.prefab.implement.IRotatable;
import universalelectricity.prefab.tile.TileEntityElectricityStorage;
public abstract class TileEntityUniversalStorable
extends TileEntityElectricityStorage implements IUniversalEnergyTile {
@Override
public boolean canConnect(ForgeDirection direction) {
return this instanceof IRotatable
? direction == ForgeDirection.getOrientation(this.getBlockMetadata())
.getOpposite()
: true;
}
public ForgeDirection getDirection(IBlockAccess world, int x, int y, int z) {
return ForgeDirection.getOrientation(this.getBlockMetadata());
}
public void setDirection(World world, int x, int y, int z,
ForgeDirection facingDirection) {
this.worldObj.setBlockMetadataWithNotify(
this.xCoord, this.yCoord, this.zCoord, facingDirection.ordinal(), 2);
}
}

View File

@ -0,0 +1,102 @@
package calclavia.lib;
import cpw.mods.fml.common.FMLLog;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
public class UniversalRecipes {
public static final String PRIMARY_METAL = "ingotSteel";
public static final String PRIMARY_PLATE = "plateSteel";
public static final String SECONDARY_METAL = "ingotBronze";
public static final String SECONDARY_PLATE = "plateBronze";
public static final String CIRCUIT_T1 = "calclavia:CIRCUIT_T1";
public static final String CIRCUIT_T2 = "calclavia:CIRCUIT_T2";
public static final String CIRCUIT_T3 = "calclavia:CIRCUIT_T3";
public static String ADVANCED_BATTERY = "calclavia:ADVANCED_BATTERY";
public static String BATTERY = "calclavia:BATTERY";
public static String BATTERY_BOX = "calclavia:BATTERY_BOX";
public static final String WRENCH = "calclavia:WRENCH";
public static final String WIRE = "calclavia:WIRE";
public static final String MOTOR = "calclavia:MOTOR";
public static boolean isInit = false;
public static void init() {
if (!isInit) {
// TODO: WTF
// register("calclavia:CIRCUIT_T1", new Object[]{"circuitBasic",
// Items.getItem("electronicCircuit"), new
// ItemStack(Blocks.redstone_torch)}); register("calclavia:CIRCUIT_T2",
// new Object[]{"circuitAdvanced", Items.getItem("advancedCircuit"), new
// ItemStack(Items.repeater)}); register("calclavia:CIRCUIT_T3", new
// Object[]{"circuitElite", Items.getItem("iridiumPlate"), new
// ItemStack(Block.field_94346_cn)}); register(ADVANCED_BATTERY, new
// Object[]{"advancedBattery", Items.getItem("energyCrystal"), "battery",
// new ItemStack(Items.repeater)}); register(BATTERY, new
// Object[]{"battery", Items.getItem("reBattery"), new
// ItemStack(Items.repeater)});
// register(BATTERY_BOX, new Object[]{"batteryBox",
// Items.getItem("batBox"), new ItemStack(Block.field_72105_ah)});
// register("calclavia:WRENCH", new Object[]{"wrench",
// Items.getItem("wrench"), new ItemStack(Item.field_77708_h)});
// register("calclavia:WIRE", new Object[]{"copperWire",
// "copperCableBlock", new ItemStack(Item.field_77767_aC)});
// register("calclavia:MOTOR", new Object[]{"motor",
// Items.getItem("generator"), new ItemStack(Block.field_71963_Z)});
isInit = true;
}
}
public static void register(String name, Object... possiblities) {
Object[] arr$ = possiblities;
int len$ = possiblities.length;
for (int i$ = 0; i$ < len$; ++i$) {
Object possiblity = arr$[i$];
if (possiblity instanceof ItemStack) {
if (registerItemStacksToDictionary(
name, new ItemStack[] {(ItemStack)possiblity})) {
break;
}
} else if (possiblity instanceof String) {
if (registerItemStacksToDictionary(name, (String)possiblity)) {
break;
}
} else {
FMLLog.severe("Universal Recipes: Error Registering " + name,
new Object[0]);
}
}
}
public static boolean registerItemStacksToDictionary(String name,
List itemStacks) {
boolean returnValue = false;
if (itemStacks != null && itemStacks.size() > 0) {
Iterator i$ = itemStacks.iterator();
while (i$.hasNext()) {
ItemStack stack = (ItemStack)i$.next();
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, (List)OreDictionary.getOres(stackName));
}
}

View File

@ -0,0 +1,96 @@
package calclavia.lib.gui;
import calclavia.lib.IPlayerUsing;
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;
public class ContainerBase extends Container {
protected int slotCount = 0;
private IInventory inventory;
public ContainerBase(IInventory inventory) {
this.inventory = inventory;
this.slotCount = inventory.getSizeInventory();
}
public void onContainerClosed(EntityPlayer player) {
if(this.inventory instanceof IPlayerUsing) {
((IPlayerUsing)this.inventory).getPlayersUsing().remove(player);
}
}
public void addPlayerInventory(EntityPlayer player) {
if(this.inventory instanceof IPlayerUsing) {
((IPlayerUsing)this.inventory).getPlayersUsing().add(player);
}
int var3;
for(var3 = 0; var3 < 3; ++var3) {
for(int var4 = 0; var4 < 9; ++var4) {
this.addSlotToContainer(new Slot(player.inventory, var4 + var3 * 9 + 9, 8 + var4 * 18, 135 + var3 * 18));
}
}
for(var3 = 0; var3 < 9; ++var3) {
this.addSlotToContainer(new Slot(player.inventory, var3, 8 + var3 * 18, 193));
}
}
public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int slotID) {
ItemStack var2 = null;
Slot var3 = (Slot)super.inventorySlots.get(slotID);
if(var3 != null && var3.getHasStack()) {
ItemStack itemStack = var3.getStack();
var2 = itemStack.copy();
if(slotID >= this.slotCount) {
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, this.slotCount, 27 + this.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;
}
public boolean canInteractWith(EntityPlayer entityplayer) {
return this.inventory.isUseableByPlayer(entityplayer);
}
}

View File

@ -0,0 +1,296 @@
package calclavia.lib.gui;
import calclavia.lib.Calclavia;
import java.util.HashMap;
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.IIcon;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fluids.FluidStack;
import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.GL11;
import universalelectricity.core.vector.Vector2;
import universalelectricity.prefab.TranslationHelper;
import universalelectricity.prefab.vector.Region2;
public class GuiContainerBase extends GuiContainer {
//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 = 68;
public String tooltip = "";
protected HashMap<Region2, String> tooltips = new HashMap<>();
protected int containerWidth;
protected int containerHeight;
public GuiContainerBase(Container container) {
super(container);
this.ySize = 217;
}
@Override
public void initGui() {
super.initGui();
}
@Override
public void onGuiClosed() {
Keyboard.enableRepeatEvents(false);
super.onGuiClosed();
}
@Override
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
for (Entry<Region2, String> entry : this.tooltips.entrySet()) {
if (((Region2)entry.getKey())
.isIn(new Vector2((double)(mouseX - this.guiLeft),
(double)(mouseY - this.guiTop)))) {
this.tooltip = (String)entry.getValue();
break;
}
}
if (this.tooltip != null && this.tooltip != "") {
this.drawTooltip(mouseX - this.guiLeft, mouseY - this.guiTop,
(String[])Calclavia.splitStringPerWord(this.tooltip, 5)
.toArray(new String[0]));
}
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(
new ResourceLocation("calclavia", "textures/gui/gui_base.png"));
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(
new ResourceLocation("calclavia", "textures/gui/gui_base.png"));
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(
new ResourceLocation("calclavia", "textures/gui/gui_base.png"));
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;
++y;
GL11.glTranslatef(0.0F, 0.0F, 32.0F);
itemRender.renderItemAndEffectIntoGUI(
this.fontRendererObj, this.mc.renderEngine, itemStack, x, y);
}
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.fontRendererObj.drawString(text, x, y, color);
String tooltip = TranslationHelper.getLocal("gui." + textName + ".tooltip");
if (tooltip != null && tooltip != "" &&
this.func_146978_c(x, y, (int)((double)text.length() * 4.8D), 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(
new ResourceLocation("calclavia", "textures/gui/gui_components.png"));
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.0F, 1.0F, 1.0F);
}
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(
new ResourceLocation("calclavia", "textures/gui/gui_components.png"));
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
this.drawTexturedModalRect(this.containerWidth + x,
this.containerHeight + y, 18, 0, 22, 15);
if (scale > 0.0F) {
this.drawTexturedModalRect(this.containerWidth + x,
this.containerHeight + y, 18, 15,
22 - (int)(scale * 22.0F), 15);
}
}
protected void drawForce(int x, int y, float scale) {
this.mc.renderEngine.bindTexture(
new ResourceLocation("calclavia", "textures/gui/gui_components.png"));
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
this.drawTexturedModalRect(this.containerWidth + x,
this.containerHeight + y, 54, 0, 107, 11);
if (scale > 0.0F) {
this.drawTexturedModalRect(this.containerWidth + x,
this.containerHeight + y, 54, 11,
(int)(scale * 107.0F), 11);
}
}
protected void drawElectricity(int x, int y, float scale) {
this.mc.renderEngine.bindTexture(
new ResourceLocation("calclavia", "textures/gui/gui_components.png"));
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
this.drawTexturedModalRect(this.containerWidth + x,
this.containerHeight + y, 54, 0, 107, 11);
if (scale > 0.0F) {
this.drawTexturedModalRect(this.containerWidth + x,
this.containerHeight + y, 54, 22,
(int)(scale * 107.0F), 11);
}
}
protected void drawMeter(int x, int y, float scale, FluidStack liquidStack) {
this.mc.renderEngine.bindTexture(
new ResourceLocation("calclavia", "textures/gui/gui_base.png"));
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
this.drawTexturedModalRect(this.containerWidth + x,
this.containerHeight + y, 40, 0, 14, 49);
this.displayGauge(this.containerWidth + x, this.containerHeight + y, 0, 0,
(int)(48.0F * scale), liquidStack);
this.mc.renderEngine.bindTexture(
new ResourceLocation("calclavia", "textures/gui/gui_base.png"));
this.drawTexturedModalRect(this.containerWidth + x,
this.containerHeight + y, 40, 98, 14, 49);
}
public void drawTooltip(int x, int y, String... toolTips) {
if (!GuiScreen.isShiftKeyDown()) {
GL11.glDisable('\u803a');
RenderHelper.disableStandardItemLighting();
GL11.glDisable(2896);
GL11.glDisable(2929);
if (toolTips != null) {
int var5 = 0;
int var6;
int var7;
for (var6 = 0; var6 < toolTips.length; ++var6) {
var7 = this.fontRendererObj.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;
}
super.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.fontRendererObj.drawStringWithShadow(var14, var6, var7, -1);
var7 += 10;
}
super.zLevel = 0.0F;
GL11.glEnable(2929);
GL11.glEnable(2896);
RenderHelper.enableGUIStandardItemLighting();
GL11.glEnable('\u803a');
}
}
}
protected void displayGauge(int j, int k, int line, int col, int squaled,
FluidStack liquid) {
if (liquid != null) {
int start = 0;
IIcon liquidIcon = liquid.getFluid().getIcon();
int x1;
do {
if (squaled > 16) {
x1 = 16;
squaled -= 16;
} else {
x1 = squaled;
squaled = 0;
}
this.drawTexturedModelRectFromIcon(j + col, k + line + 58 - x1 - start,
liquidIcon, 16, 16 - (16 - x1));
start += 16;
} while (x1 != 0 && squaled != 0);
}
}
}

View File

@ -0,0 +1,271 @@
package calclavia.lib.gui;
import calclavia.lib.Calclavia;
import java.util.HashMap;
import java.util.Map.Entry;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.util.IIcon;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fluids.FluidStack;
import org.lwjgl.opengl.GL11;
import universalelectricity.core.vector.Vector2;
import universalelectricity.prefab.GuiBase;
import universalelectricity.prefab.TranslationHelper;
import universalelectricity.prefab.vector.Region2;
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 = 68;
public String tooltip = "";
protected HashMap<Region2, String> tooltips = new HashMap<>();
protected int containerWidth;
protected int containerHeight;
public GuiScreenBase() { super.ySize = 217; }
@Override
protected void drawForegroundLayer(int mouseX, int mouseY, float var1) {
for (Entry<Region2, String> entry : this.tooltips.entrySet()) {
if (((Region2)entry.getKey())
.isIn(new Vector2((double)(mouseX - this.guiLeft),
(double)(mouseY - this.guiTop)))) {
this.tooltip = (String)entry.getValue();
break;
}
}
if (this.tooltip != null && this.tooltip != "") {
this.drawTooltip(mouseX - this.guiLeft, mouseY - this.guiTop,
(String[])Calclavia.splitStringPerWord(this.tooltip, 5)
.toArray(new String[0]));
}
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(
new ResourceLocation("calclavia", "textures/gui/gui_base.png"));
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(
new ResourceLocation("calclavia", "textures/gui/gui_base.png"));
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.fontRendererObj.drawString(text, x, y, color);
String tooltip = TranslationHelper.getLocal("gui." + textName + ".tooltip");
if (tooltip != null && tooltip != "" &&
this.isPointInRegion(x, y, (int)((double)text.length() * 4.8D), 12,
mouseX, mouseY)) {
this.tooltip = tooltip;
}
}
protected boolean isPointInRegion(int par1, int par2, int par3, int par4,
int par5, int par6) {
int k1 = super.guiLeft;
int l1 = super.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(
new ResourceLocation("calclavia", "textures/gui/gui_empty.png"));
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.0F, 1.0F, 1.0F);
}
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(
new ResourceLocation("calclavia", "textures/gui/gui_empty.png"));
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
this.drawTexturedModalRect(this.containerWidth + x,
this.containerHeight + y, 18, 0, 22, 15);
if (scale > 0.0F) {
this.drawTexturedModalRect(this.containerWidth + x,
this.containerHeight + y, 18, 15,
22 - (int)(scale * 22.0F), 15);
}
}
protected void drawForce(int x, int y, float scale) {
this.mc.renderEngine.bindTexture(
new ResourceLocation("calclavia", "textures/gui/gui_empty.png"));
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
this.drawTexturedModalRect(this.containerWidth + x,
this.containerHeight + y, 54, 0, 107, 11);
if (scale > 0.0F) {
this.drawTexturedModalRect(this.containerWidth + x,
this.containerHeight + y, 54, 11,
(int)(scale * 107.0F), 11);
}
}
protected void drawElectricity(int x, int y, float scale) {
this.mc.renderEngine.bindTexture(
new ResourceLocation("calclavia", "textures/gui/gui_empty.png"));
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
this.drawTexturedModalRect(this.containerWidth + x,
this.containerHeight + y, 54, 0, 107, 11);
if (scale > 0.0F) {
this.drawTexturedModalRect(this.containerWidth + x,
this.containerHeight + y, 54, 22,
(int)(scale * 107.0F), 11);
}
}
protected void drawMeter(int x, int y, float scale, FluidStack liquidStack) {
this.mc.renderEngine.bindTexture(
new ResourceLocation("calclavia", "textures/gui/gui_empty.png"));
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
this.drawTexturedModalRect(this.containerWidth + x,
this.containerHeight + y, 40, 0, 14, 49);
this.displayGauge(this.containerWidth + x, this.containerHeight + y, 0, 0,
(int)(48.0F * scale), liquidStack);
this.mc.renderEngine.bindTexture(
new ResourceLocation("calclavia", "textures/gui/gui_empty.png"));
this.drawTexturedModalRect(this.containerWidth + x,
this.containerHeight + y, 40, 98, 14, 49);
}
public void drawTooltip(int x, int y, String... toolTips) {
if (!GuiScreen.isShiftKeyDown()) {
GL11.glDisable('\u803a');
RenderHelper.disableStandardItemLighting();
GL11.glDisable(2896);
GL11.glDisable(2929);
if (toolTips != null) {
int var5 = 0;
int var6;
int var7;
for (var6 = 0; var6 < toolTips.length; ++var6) {
var7 = this.fontRendererObj.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 (super.guiTop + var7 + var9 + 6 > this.height) {
var7 = this.height - var9 - super.guiTop - 6;
}
super.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.fontRendererObj.drawStringWithShadow(var14, var6, var7, -1);
var7 += 10;
}
super.zLevel = 0.0F;
GL11.glEnable(2929);
GL11.glEnable(2896);
RenderHelper.enableGUIStandardItemLighting();
GL11.glEnable('\u803a');
}
}
}
protected void displayGauge(int j, int k, int line, int col, int squaled,
FluidStack liquid) {
if (liquid != null) {
int start = 0;
IIcon liquidIcon = liquid.getFluid().getIcon();
int x1;
do {
if (squaled > 16) {
x1 = 16;
squaled -= 16;
} else {
x1 = squaled;
squaled = 0;
}
this.drawTexturedModelRectFromIcon(j + col, k + line + 58 - x1 - start,
liquidIcon, 16, 16 - (16 - x1));
start += 16;
} while (x1 != 0 && squaled != 0);
}
}
}

View File

@ -0,0 +1,23 @@
package calclavia.lib.gui;
public enum GuiSlotType {
NONE("NONE", 0),
BATTERY("BATTERY", 1),
LIQUID("LIQUID", 2),
ARR_UP("ARR_UP", 3),
ARR_DOWN("ARR_DOWN", 4),
ARR_LEFT("ARR_LEFT", 5),
ARR_RIGHT("ARR_RIGHT", 6),
ARR_UP_RIGHT("ARR_UP_RIGHT", 7),
ARR_UP_LEFT("ARR_UP_LEFT", 8),
ARR_DOWN_LEFT("ARR_DOWN_LEFT", 9),
ARR_DOWN_RIGHT("ARR_DOWN_RIGHT", 10);
// $FF: synthetic field
private static final GuiSlotType[] $VALUES = new GuiSlotType[]{NONE, BATTERY, LIQUID, ARR_UP, ARR_DOWN, ARR_LEFT, ARR_RIGHT, ARR_UP_RIGHT, ARR_UP_LEFT, ARR_DOWN_LEFT, ARR_DOWN_RIGHT};
private GuiSlotType(String var1, int var2) {}
}

View File

@ -0,0 +1,111 @@
package calclavia.lib.render;
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 org.lwjgl.opengl.GL11;
public class CalclaviaRenderHelper {
public static void enableBlending() {
GL11.glShadeModel(7425);
GL11.glEnable(3042);
GL11.glBlendFunc(770, 771);
}
public static void disableBlending() {
GL11.glShadeModel(7424);
GL11.glDisable(2848);
GL11.glDisable(2881);
GL11.glDisable(3042);
}
public static void enableLighting() {
RenderHelper.enableStandardItemLighting();
}
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);
GL11.glRotatef(90.0F, 0.0F, 1.0F, 0.0F);
GL11.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();
GL11.glTranslatef(0.5F, 0.5F, 0.5F);
}
public static void renderFloatingText(String text, float x, float y, float z) {
renderFloatingText(text, x, y, z, 16777215);
}
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(1.0F, 1.0F, 1.0F, 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(2896);
GL11.glDepthMask(false);
GL11.glDisable(2929);
GL11.glEnable(3042);
GL11.glBlendFunc(770, 771);
Tessellator tessellator = Tessellator.instance;
byte yOffset = 0;
GL11.glDisable(3553);
tessellator.startDrawingQuads();
int stringMiddle = fontRenderer.getStringWidth(text) / 2;
tessellator.setColorRGBA_F(0.0F, 0.0F, 0.0F, 0.5F);
tessellator.addVertex((double)(-stringMiddle - 1), (double)(-1 + yOffset), 0.0D);
tessellator.addVertex((double)(-stringMiddle - 1), (double)(8 + yOffset), 0.0D);
tessellator.addVertex((double)(stringMiddle + 1), (double)(8 + yOffset), 0.0D);
tessellator.addVertex((double)(stringMiddle + 1), (double)(-1 + yOffset), 0.0D);
tessellator.draw();
GL11.glEnable(3553);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 0.5F);
fontRenderer.drawString(text, -fontRenderer.getStringWidth(text) / 2, yOffset, color);
GL11.glEnable(2929);
GL11.glDepthMask(true);
fontRenderer.drawString(text, -fontRenderer.getStringWidth(text) / 2, yOffset, color);
GL11.glEnable(2896);
GL11.glDisable(3042);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
GL11.glPopMatrix();
}
}

View File

@ -0,0 +1,9 @@
package calclavia.lib.render;
import java.util.HashMap;
import net.minecraft.entity.player.EntityPlayer;
public interface ITagRender {
float addInformation(HashMap var1, EntityPlayer var2);
}

View File

@ -0,0 +1,64 @@
package calclavia.lib.render;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map.Entry;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityClientPlayerMP;
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;
@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 && t instanceof ITagRender &&
this.getPlayer().getDistance((double)t.xCoord, (double)t.yCoord,
(double)t.zCoord) <=
(double)RendererLivingEntity.NAME_TAG_RANGE) {
HashMap tags = new HashMap();
float height = ((ITagRender)t).addInformation(tags, this.getPlayer());
EntityClientPlayerMP player = Minecraft.getMinecraft().thePlayer;
if (player.ridingEntity == null) {
MovingObjectPosition objectPosition = player.rayTrace(8.0D, 1.0F);
if (objectPosition != null) {
boolean isLooking = false;
for (int it = 0; (float)it < height; ++it) {
if (objectPosition.blockX == t.xCoord &&
objectPosition.blockY == t.yCoord + it &&
objectPosition.blockZ == t.zCoord) {
isLooking = true;
}
}
if (isLooking) {
Iterator var17 = tags.entrySet().iterator();
for (int i = 0; var17.hasNext(); ++i) {
Entry entry = (Entry)var17.next();
if (entry.getKey() != null) {
CalclaviaRenderHelper.renderFloatingText(
(String)entry.getKey(), (float)x + 0.5F,
(float)y + (float)i * 0.25F - 2.0F + height,
(float)z + 0.5F, ((Integer)entry.getValue()).intValue());
}
}
}
}
}
}
}
public EntityPlayer getPlayer() {
EntityLivingBase entity = this.field_147501_a.field_147551_g;
return entity instanceof EntityPlayer ? (EntityPlayer)entity : null;
}
}

View File

@ -0,0 +1,315 @@
/**
* This file is part of the public ComputerCraft API - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2015. This API may be redistributed unmodified and in full only.
* For help using the API, and posting your mods, visit the forums at computercraft.info.
*/
package dan200.computercraft.api;
import dan200.computercraft.api.filesystem.IMount;
import dan200.computercraft.api.filesystem.IWritableMount;
import dan200.computercraft.api.media.IMediaProvider;
import dan200.computercraft.api.peripheral.IPeripheralProvider;
import dan200.computercraft.api.permissions.ITurtlePermissionProvider;
import dan200.computercraft.api.redstone.IBundledRedstoneProvider;
import dan200.computercraft.api.turtle.ITurtleUpgrade;
import net.minecraft.world.World;
import java.lang.reflect.Method;
/**
* The static entry point to the ComputerCraft API.
* Members in this class must be called after mod_ComputerCraft has been initialised,
* but may be called before it is fully loaded.
*/
public final class ComputerCraftAPI
{
public static boolean isInstalled()
{
findCC();
return computerCraft != null;
}
public static String getInstalledVersion()
{
findCC();
if( computerCraft_getVersion != null )
{
try {
return (String)computerCraft_getVersion.invoke( null );
} catch (Exception e) {
// It failed
}
}
return "";
}
public static String getAPIVersion()
{
return "1.75";
}
/**
* Creates a numbered directory in a subfolder of the save directory for a given world, and returns that number.<br>
* Use in conjuction with createSaveDirMount() to create a unique place for your peripherals or media items to store files.<br>
* @param world The world for which the save dir should be created. This should be the serverside world object.
* @param parentSubPath The folder path within the save directory where the new directory should be created. eg: "computercraft/disk"
* @return The numerical value of the name of the new folder, or -1 if the folder could not be created for some reason.<br>
* eg: if createUniqueNumberedSaveDir( world, "computer/disk" ) was called returns 42, then "computer/disk/42" is now available for writing.
* @see #createSaveDirMount(World, String, long)
*/
public static int createUniqueNumberedSaveDir( World world, String parentSubPath )
{
findCC();
if( computerCraft_createUniqueNumberedSaveDir != null )
{
try {
return (Integer)computerCraft_createUniqueNumberedSaveDir.invoke( null, world, parentSubPath );
} catch (Exception e) {
// It failed
}
}
return -1;
}
/**
* Creates a file system mount that maps to a subfolder of the save directory for a given world, and returns it.<br>
* Use in conjuction with IComputerAccess.mount() or IComputerAccess.mountWritable() to mount a folder from the
* users save directory onto a computers file system.<br>
* @param world The world for which the save dir can be found. This should be the serverside world object.
* @param subPath The folder path within the save directory that the mount should map to. eg: "computer/disk/42".<br>
* Use createUniqueNumberedSaveDir() to create a new numbered folder to use.
* @param capacity The ammount of data that can be stored in the directory before it fills up, in bytes.
* @return The mount, or null if it could be created for some reason. Use IComputerAccess.mount() or IComputerAccess.mountWritable()
* to mount this on a Computers' file system.
* @see #createUniqueNumberedSaveDir(World, String)
* @see dan200.computercraft.api.peripheral.IComputerAccess#mount(String, dan200.computercraft.api.filesystem.IMount)
* @see dan200.computercraft.api.peripheral.IComputerAccess#mountWritable(String, dan200.computercraft.api.filesystem.IWritableMount)
* @see dan200.computercraft.api.filesystem.IMount
* @see IWritableMount
*/
public static IWritableMount createSaveDirMount( World world, String subPath, long capacity )
{
findCC();
if( computerCraft_createSaveDirMount != null )
{
try {
return (IWritableMount)computerCraft_createSaveDirMount.invoke( null, world, subPath, capacity );
} catch (Exception e){
// It failed
}
}
return null;
}
/**
* Creates a file system mount to a resource folder, and returns it.<br>
* Use in conjuction with IComputerAccess.mount() or IComputerAccess.mountWritable() to mount a resource folder onto a computers file system.<br>
* The files in this mount will be a combination of files in the specified mod jar, and resource packs that contain resources with the same domain and path.<br>
* @param modClass A class in whose jar to look first for the resources to mount. Using your main mod class is recommended. eg: MyMod.class
* @param domain The domain under which to look for resources. eg: "mymod"
* @param subPath The domain under which to look for resources. eg: "mymod/lua/myfiles"
* @return The mount, or null if it could be created for some reason. Use IComputerAccess.mount() or IComputerAccess.mountWritable()
* to mount this on a Computers' file system.
* @see dan200.computercraft.api.peripheral.IComputerAccess#mount(String, dan200.computercraft.api.filesystem.IMount)
* @see dan200.computercraft.api.peripheral.IComputerAccess#mountWritable(String, IWritableMount)
* @see dan200.computercraft.api.filesystem.IMount
*/
public static IMount createResourceMount( Class modClass, String domain, String subPath )
{
findCC();
if( computerCraft_createResourceMount != null )
{
try {
return (IMount)computerCraft_createResourceMount.invoke( null, modClass, domain, subPath );
} catch (Exception e){
// It failed
}
}
return null;
}
/**
* Registers a peripheral handler to convert blocks into IPeripheral implementations.
* @see dan200.computercraft.api.peripheral.IPeripheral
* @see dan200.computercraft.api.peripheral.IPeripheralProvider
*/
public static void registerPeripheralProvider( IPeripheralProvider handler )
{
findCC();
if ( computerCraft_registerPeripheralProvider != null)
{
try {
computerCraft_registerPeripheralProvider.invoke( null, handler );
} catch (Exception e){
// It failed
}
}
}
/**
* Registers a new turtle turtle for use in ComputerCraft. After calling this,
* users should be able to craft Turtles with your new turtle. It is recommended to call
* this during the load() method of your mod.
* @see dan200.computercraft.api.turtle.ITurtleUpgrade
*/
public static void registerTurtleUpgrade( ITurtleUpgrade upgrade )
{
if( upgrade != null )
{
findCC();
if( computerCraft_registerTurtleUpgrade != null )
{
try {
computerCraft_registerTurtleUpgrade.invoke( null, upgrade );
} catch( Exception e ) {
// It failed
}
}
}
}
/**
* Registers a bundled redstone handler to provide bundled redstone output for blocks
* @see dan200.computercraft.api.redstone.IBundledRedstoneProvider
*/
public static void registerBundledRedstoneProvider( IBundledRedstoneProvider handler )
{
findCC();
if( computerCraft_registerBundledRedstoneProvider != null )
{
try {
computerCraft_registerBundledRedstoneProvider.invoke( null, handler );
} catch (Exception e) {
// It failed
}
}
}
/**
* If there is a Computer or Turtle at a certain position in the world, get it's bundled redstone output.
* @see dan200.computercraft.api.redstone.IBundledRedstoneProvider
* @return If there is a block capable of emitting bundled redstone at the location, it's signal (0-65535) will be returned.
* If there is no block capable of emitting bundled redstone at the location, -1 will be returned.
*/
public static int getBundledRedstoneOutput( World world, int x, int y, int z, int side )
{
findCC();
if( computerCraft_getDefaultBundledRedstoneOutput != null )
{
try {
return (Integer)computerCraft_getDefaultBundledRedstoneOutput.invoke( null, world, x, y, z, side );
} catch (Exception e){
// It failed
}
}
return -1;
}
/**
* Registers a media handler to provide IMedia implementations for Items
* @see dan200.computercraft.api.media.IMediaProvider
*/
public static void registerMediaProvider( IMediaProvider handler )
{
findCC();
if( computerCraft_registerMediaProvider != null )
{
try {
computerCraft_registerMediaProvider.invoke( null, handler );
} catch (Exception e){
// It failed
}
}
}
/**
* Registers a permission handler to restrict where turtles can move or build
* @see dan200.computercraft.api.permissions.ITurtlePermissionProvider
*/
public static void registerPermissionProvider( ITurtlePermissionProvider handler )
{
findCC();
if( computerCraft_registerPermissionProvider != null )
{
try {
computerCraft_registerPermissionProvider.invoke( null, handler );
} catch (Exception e) {
// It failed
}
}
}
// The functions below here are private, and are used to interface with the non-API ComputerCraft classes.
// Reflection is used here so you can develop your mod without decompiling ComputerCraft and including
// it in your solution, and so your mod won't crash if ComputerCraft is installed.
private static void findCC()
{
if( !ccSearched ) {
try {
computerCraft = Class.forName( "dan200.computercraft.ComputerCraft" );
computerCraft_getVersion = findCCMethod( "getVersion", new Class[]{
} );
computerCraft_createUniqueNumberedSaveDir = findCCMethod( "createUniqueNumberedSaveDir", new Class[]{
World.class, String.class
} );
computerCraft_createSaveDirMount = findCCMethod( "createSaveDirMount", new Class[] {
World.class, String.class, Long.TYPE
} );
computerCraft_createResourceMount = findCCMethod( "createResourceMount", new Class[] {
Class.class, String.class, String.class
} );
computerCraft_registerPeripheralProvider = findCCMethod( "registerPeripheralProvider", new Class[] {
IPeripheralProvider.class
} );
computerCraft_registerTurtleUpgrade = findCCMethod( "registerTurtleUpgrade", new Class[] {
ITurtleUpgrade.class
} );
computerCraft_registerBundledRedstoneProvider = findCCMethod( "registerBundledRedstoneProvider", new Class[] {
IBundledRedstoneProvider.class
} );
computerCraft_getDefaultBundledRedstoneOutput = findCCMethod( "getDefaultBundledRedstoneOutput", new Class[] {
World.class, Integer.TYPE, Integer.TYPE, Integer.TYPE, Integer.TYPE
} );
computerCraft_registerMediaProvider = findCCMethod( "registerMediaProvider", new Class[] {
IMediaProvider.class
} );
computerCraft_registerPermissionProvider = findCCMethod( "registerPermissionProvider", new Class[] {
ITurtlePermissionProvider.class
} );
} catch( Exception e ) {
System.out.println( "ComputerCraftAPI: ComputerCraft not found." );
} finally {
ccSearched = true;
}
}
}
private static Method findCCMethod( String name, Class[] args )
{
try {
if( computerCraft != null )
{
return computerCraft.getMethod( name, args );
}
return null;
} catch( NoSuchMethodException e ) {
System.out.println( "ComputerCraftAPI: ComputerCraft method " + name + " not found." );
return null;
}
}
private static boolean ccSearched = false;
private static Class computerCraft = null;
private static Method computerCraft_getVersion = null;
private static Method computerCraft_createUniqueNumberedSaveDir = null;
private static Method computerCraft_createSaveDirMount = null;
private static Method computerCraft_createResourceMount = null;
private static Method computerCraft_registerPeripheralProvider = null;
private static Method computerCraft_registerTurtleUpgrade = null;
private static Method computerCraft_registerBundledRedstoneProvider = null;
private static Method computerCraft_getDefaultBundledRedstoneOutput = null;
private static Method computerCraft_registerMediaProvider = null;
private static Method computerCraft_registerPermissionProvider = null;
}

View File

@ -0,0 +1,57 @@
/**
* This file is part of the public ComputerCraft API - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2015. This API may be redistributed unmodified and in full only.
* For help using the API, and posting your mods, visit the forums at computercraft.info.
*/
package dan200.computercraft.api.filesystem;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
/**
* Represents a read only part of a virtual filesystem that can be mounted onto a computercraft using IComputerAccess.mount().
* Ready made implementations of this interface can be created using ComputerCraftAPI.createSaveDirMount() or ComputerCraftAPI.createResourceMount(), or you're free to implement it yourselves!
* @see dan200.computercraft.api.ComputerCraftAPI#createSaveDirMount(World, String)
* @see dan200.computercraft.api.ComputerCraftAPI#createResourceMount(Class, String, String)
* @see dan200.computercraft.api.peripheral.IComputerAccess#mount(String, IMount)
* @see IWritableMount
*/
public interface IMount
{
/**
* Returns whether a file with a given path exists or not.
* @param path A file path in normalised format, relative to the mount location. ie: "programs/myprogram"
* @return true if the file exists, false otherwise
*/
public boolean exists( String path ) throws IOException;
/**
* Returns whether a file with a given path is a directory or not.
* @param path A file path in normalised format, relative to the mount location. ie: "programs/myprograms"
* @return true if the file exists and is a directory, false otherwise
*/
public boolean isDirectory( String path ) throws IOException;
/**
* Returns the file names of all the files in a directory.
* @param path A file path in normalised format, relative to the mount location. ie: "programs/myprograms"
* @param contents A list of strings. Add all the file names to this list
*/
public void list( String path, List<String> contents ) throws IOException;
/**
* Returns the size of a file with a given path, in bytes
* @param path A file path in normalised format, relative to the mount location. ie: "programs/myprogram"
* @return the size of the file, in bytes
*/
public long getSize( String path ) throws IOException;
/**
* Opens a file with a given path, and returns an inputstream representing it's contents.
* @param path A file path in normalised format, relative to the mount location. ie: "programs/myprogram"
* @return a stream representing the contents of the file
*/
public InputStream openForRead( String path ) throws IOException;
}

View File

@ -0,0 +1,52 @@
/**
* This file is part of the public ComputerCraft API - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2015. This API may be redistributed unmodified and in full only.
* For help using the API, and posting your mods, visit the forums at computercraft.info.
*/
package dan200.computercraft.api.filesystem;
import java.io.IOException;
import java.io.OutputStream;
/**
* Represents a part of a virtual filesystem that can be mounted onto a computercraft using IComputerAccess.mount() or IComputerAccess.mountWritable(), that can also be written to.
* Ready made implementations of this interface can be created using ComputerCraftAPI.createSaveDirMount(), or you're free to implement it yourselves!
* @see dan200.computercraft.api.ComputerCraftAPI#createSaveDirMount(World, String)
* @see dan200.computercraft.api.peripheral.IComputerAccess#mountWritable(String, dan200.computercraft.api.filesystem.IMount)
* @see dan200.computercraft.api.filesystem.IMount
*/
public interface IWritableMount extends IMount
{
/**
* Creates a directory at a given path inside the virtual file system.
* @param path A file path in normalised format, relative to the mount location. ie: "programs/mynewprograms"
*/
public void makeDirectory( String path ) throws IOException;
/**
* Deletes a directory at a given path inside the virtual file system.
* @param path A file path in normalised format, relative to the mount location. ie: "programs/myoldprograms"
*/
public void delete( String path ) throws IOException;
/**
* Opens a file with a given path, and returns an outputstream for writing to it.
* @param path A file path in normalised format, relative to the mount location. ie: "programs/myprogram"
* @return a stream for writing to
*/
public OutputStream openForWrite( String path ) throws IOException;
/**
* Opens a file with a given path, and returns an outputstream for appending to it.
* @param path A file path in normalised format, relative to the mount location. ie: "programs/myprogram"
* @return a stream for writing to
*/
public OutputStream openForAppend( String path ) throws IOException;
/**
* Get the ammount of free space on the mount, in bytes. You should decrease this value as the user writes to the mount, and write operations should fail once it reaches zero.
* @return The ammount of free space, in bytes.
*/
public long getRemainingSpace() throws IOException;
}

View File

@ -0,0 +1,10 @@
/**
* This file is part of the public ComputerCraft API - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2015. This API may be redistributed unmodified and in full only.
* For help using the API, and posting your mods, visit the forums at computercraft.info.
*/
@API( owner="ComputerCraft", provides="ComputerCraft|API|FileSystem", apiVersion="1.75" )
package dan200.computercraft.api.filesystem;
import cpw.mods.fml.common.API;

View File

@ -0,0 +1,58 @@
/**
* This file is part of the public ComputerCraft API - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2015. This API may be redistributed unmodified and in full only.
* For help using the API, and posting your mods, visit the forums at computercraft.info.
*/
package dan200.computercraft.api.lua;
/**
* An interface passed to peripherals and ILuaObjects' by computers or turtles, providing methods
* that allow the peripheral call to wait for events before returning, just like in lua.
* This is very useful if you need to signal work to be performed on the main thread, and don't want to return
* until the work has been completed.
*/
public interface ILuaContext
{
/**
* Wait for an event to occur on the computercraft, suspending the thread until it arises. This method is exactly equivalent to os.pullEvent() in lua.
* @param filter A specific event to wait for, or null to wait for any event
* @return An object array containing the name of the event that occurred, and any event parameters
* @throws Exception If the user presses CTRL+T to terminate the current program while pullEvent() is waiting for an event, a "Terminated" exception will be thrown here.
* Do not attempt to common this exception, unless you wish to prevent termination, which is not recommended.
* @throws InterruptedException If the user shuts down or reboots the computercraft while pullEvent() is waiting for an event, InterruptedException will be thrown. This exception must not be caught or intercepted, or the computercraft will leak memory and end up in a broken state.
*/
public Object[] pullEvent( String filter ) throws LuaException, InterruptedException;
/**
* The same as pullEvent(), except "terminated" events are ignored. Only use this if you want to prevent program termination, which is not recommended. This method is exactly equivalent to os.pullEventRaw() in lua.
* @param filter A specific event to wait for, or null to wait for any event
* @return An object array containing the name of the event that occurred, and any event parameters
* @throws InterruptedException If the user shuts down or reboots the computercraft while pullEventRaw() is waiting for an event, InterruptedException will be thrown. This exception must not be caught or intercepted, or the computercraft will leak memory and end up in a broken state.
* @see #pullEvent(String)
*/
public Object[] pullEventRaw( String filter ) throws InterruptedException;
/**
* Yield the current coroutine with some arguments until it is resumed. This method is exactly equivalent to coroutine.yield() in lua. Use pullEvent() if you wish to wait for events.
* @param arguments An object array containing the arguments to pass to coroutine.yield()
* @return An object array containing the return values from coroutine.yield()
* @throws InterruptedException If the user shuts down or reboots the computercraft the coroutine is suspended, InterruptedException will be thrown. This exception must not be caught or intercepted, or the computercraft will leak memory and end up in a broken state.
* @see #pullEvent(String)
*/
public Object[] yield( Object[] arguments ) throws InterruptedException;
/**
* TODO: Document me
* @param task
* @return
*/
public Object[] executeMainThreadTask( ILuaTask task ) throws LuaException, InterruptedException;
/**
* TODO: Document me
* @param task
* @return
*/
public long issueMainThreadTask( ILuaTask task ) throws LuaException;
}

View File

@ -0,0 +1,26 @@
/**
* This file is part of the public ComputerCraft API - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2015. This API may be redistributed unmodified and in full only.
* For help using the API, and posting your mods, visit the forums at computercraft.info.
*/
package dan200.computercraft.api.lua;
/**
* An interface for representing custom objects returned by IPeripheral.callMethod() calls.
* Return objects implementing this interface to expose objects with methods to lua.
*/
public interface ILuaObject
{
/**
* Get the names of the methods that this object implements. This works the same as IPeripheral.getMethodNames(). See that method for detailed documentation.
* @see dan200.computercraft.api.peripheral.IPeripheral#getMethodNames()
*/
public String[] getMethodNames();
/**
* Called when a user calls one of the methods that this object implements. This works the same as IPeripheral.callMethod(). See that method for detailed documentation.
* @see dan200.computercraft.api.peripheral.IPeripheral#callMethod(dan200.computercraft.api.peripheral.IComputerAccess, ILuaContext, int, Object[])
*/
public Object[] callMethod( ILuaContext context, int method, Object[] arguments ) throws LuaException, InterruptedException;
}

View File

@ -0,0 +1,12 @@
/**
* This file is part of the public ComputerCraft API - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2015. This API may be redistributed unmodified and in full only.
* For help using the API, and posting your mods, visit the forums at computercraft.info.
*/
package dan200.computercraft.api.lua;
public interface ILuaTask
{
public Object[] execute() throws LuaException;
}

View File

@ -0,0 +1,36 @@
/**
* This file is part of the public ComputerCraft API - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2015. This API may be redistributed unmodified and in full only.
* For help using the API, and posting your mods, visit the forums at computercraft.info.
*/
package dan200.computercraft.api.lua;
/**
* An exception representing an error in Lua, like that raised by the error() function
*/
public class LuaException extends Exception
{
private final int m_level;
public LuaException()
{
this( "error", 1 );
}
public LuaException( String message )
{
this( message, 1 );
}
public LuaException( String message, int level )
{
super( message );
m_level = level;
}
public int getLevel()
{
return m_level;
}
}

View File

@ -0,0 +1,10 @@
/**
* This file is part of the public ComputerCraft API - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2015. This API may be redistributed unmodified and in full only.
* For help using the API, and posting your mods, visit the forums at computercraft.info.
*/
@API( owner="ComputerCraft", provides="ComputerCraft|API|Lua", apiVersion="1.75" )
package dan200.computercraft.api.lua;
import cpw.mods.fml.common.API;

View File

@ -0,0 +1,59 @@
/**
* This file is part of the public ComputerCraft API - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2015. This API may be redistributed unmodified and in full only.
* For help using the API, and posting your mods, visit the forums at computercraft.info.
*/
package dan200.computercraft.api.media;
import dan200.computercraft.api.filesystem.IMount;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
/**
* Represents an item that can be placed in a disk drive and used by a Computer.
* Implement this interface on your Item class to allow it to be used in the drive.
*/
public interface IMedia
{
/**
* Get a string representing the label of this item. Will be called vi disk.getLabel() in lua.
* @param stack The itemstack to inspect
* @return The label. ie: "Dan's Programs"
*/
public String getLabel( ItemStack stack );
/**
* Set a string representing the label of this item. Will be called vi disk.setLabel() in lua.
* @param stack The itemstack to modify.
* @param label The string to set the label to.
* @return true if the label was updated, false if the label may not be modified.
*/
public boolean setLabel( ItemStack stack, String label );
/**
* If this disk represents an item with audio (like a record), get the readable name of the audio track. ie: "Jonathon Coulton - Still Alive"
* @param stack The itemstack to inspect.
* @return The name, or null if this item does not represent an item with audio.
*/
public String getAudioTitle( ItemStack stack );
/**
* If this disk represents an item with audio (like a record), get the resource name of the audio track to play.
* @param stack The itemstack to inspect.
* @return The name, or null if this item does not represent an item with audio.
*/
public String getAudioRecordName( ItemStack stack );
/**
* If this disk represents an item with data (like a floppy disk), get a mount representing it's contents. This will be mounted onto the filesystem of the computercraft while the media is in the disk drive.
* @param stack The itemstack to inspect.
* @param world The world in which the item and disk drive reside.
* @return The mount, or null if this item does not represent an item with data. If the IMount returned also implements IWritableMount, it will mounted using mountWritable()
* @see dan200.computercraft.api.filesystem.IMount
* @see dan200.computercraft.api.filesystem.IWritableMount
* @see dan200.computercraft.api.ComputerCraftAPI#createSaveDirMount(World, String, long)
* @see dan200.computercraft.api.ComputerCraftAPI#createResourceMount(Class, String, String)
*/
public IMount createDataMount( ItemStack stack, World world );
}

View File

@ -0,0 +1,23 @@
/**
* This file is part of the public ComputerCraft API - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2015. This API may be redistributed unmodified and in full only.
* For help using the API, and posting your mods, visit the forums at computercraft.info.
*/
package dan200.computercraft.api.media;
import net.minecraft.item.ItemStack;
/**
* This interface is used to provide IMedia implementations for ItemStack
* @see dan200.computercraft.api.ComputerCraftAPI#registerMediaProvider(IMediaProvider)
*/
public interface IMediaProvider
{
/**
* Produce an IMedia implementation from an ItemStack.
* @see dan200.computercraft.api.ComputerCraftAPI#registerMediaProvider(IMediaProvider)
* @return an IMedia implementation, or null if the item is not something you wish to handle
*/
public IMedia getMedia( ItemStack stack );
}

View File

@ -0,0 +1,10 @@
/**
* This file is part of the public ComputerCraft API - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2015. This API may be redistributed unmodified and in full only.
* For help using the API, and posting your mods, visit the forums at computercraft.info.
*/
@API( owner="ComputerCraft", provides="ComputerCraft|API|Media", apiVersion="1.75" )
package dan200.computercraft.api.media;
import cpw.mods.fml.common.API;

View File

@ -0,0 +1,10 @@
/**
* This file is part of the public ComputerCraft API - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2015. This API may be redistributed unmodified and in full only.
* For help using the API, and posting your mods, visit the forums at computercraft.info.
*/
@API( owner="ComputerCraft", provides="ComputerCraft|API", apiVersion="1.75" )
package dan200.computercraft.api;
import cpw.mods.fml.common.API;

View File

@ -0,0 +1,102 @@
/**
* This file is part of the public ComputerCraft API - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2015. This API may be redistributed unmodified and in full only.
* For help using the API, and posting your mods, visit the forums at computercraft.info.
*/
package dan200.computercraft.api.peripheral;
import dan200.computercraft.api.filesystem.IMount;
import dan200.computercraft.api.filesystem.IWritableMount;
/**
* The interface passed to peripherals by computers or turtles, providing methods
* that they can call. This should not be implemented by your classes. Do not interact
* with computers except via this interface.
*/
public interface IComputerAccess
{
/**
* Mount a mount onto the computers' file system in a read only mode.<br>
* @param desiredLocation The location on the computercraft's file system where you would like the mount to be mounted.
* @param mount The mount object to mount on the computercraft. These can be obtained by calling ComputerCraftAPI.createSaveDirMount(), ComputerCraftAPI.createResourceMount() or by creating your own objects that implement the IMount interface.
* @return The location on the computercraft's file system where you the mount mounted, or null if there was already a file in the desired location. Store this value if you wish to unmount the mount later.
* @see dan200.computercraft.api.ComputerCraftAPI#createSaveDirMount(World, String)
* @see dan200.computercraft.api.ComputerCraftAPI#createResourceMount(Class, String, String)
* @see #mountWritable(String, dan200.computercraft.api.filesystem.IWritableMount)
* @see #unmount(String)
* @see dan200.computercraft.api.filesystem.IMount
*/
public String mount( String desiredLocation, IMount mount );
/**
* TODO: Document me
*/
public String mount( String desiredLocation, IMount mount, String driveName );
/**
* Mount a mount onto the computers' file system in a writable mode.<br>
* @param desiredLocation The location on the computercraft's file system where you would like the mount to be mounted.
* @param mount The mount object to mount on the computercraft. These can be obtained by calling ComputerCraftAPI.createSaveDirMount() or by creating your own objects that implement the IWritableMount interface.
* @return The location on the computercraft's file system where you the mount mounted, or null if there was already a file in the desired location. Store this value if you wish to unmount the mount later.
* @see dan200.computercraft.api.ComputerCraftAPI#createSaveDirMount(World, String)
* @see dan200.computercraft.api.ComputerCraftAPI#createResourceMount(Class, String, String)
* @see #mount(String, IMount)
* @see #unmount(String)
* @see IMount
*/
public String mountWritable( String desiredLocation, IWritableMount mount );
/**
* TODO: Document me
*/
public String mountWritable( String desiredLocation, IWritableMount mount, String driveName );
/**
* Unmounts a directory previously mounted onto the computers file system by mount() or mountWritable().<br>
* When a directory is unmounted, it will disappear from the computers file system, and the user will no longer be able to
* access it. All directories mounted by a mount or mountWritable are automatically unmounted when the peripheral
* is attached if they have not been explicitly unmounted.
* @param location The desired location in the computers file system of the directory to unmount.
* This must be the location of a directory previously mounted by mount() or mountWritable(), as
* indicated by their return value.
* @see #mount(String, IMount)
* @see #mountWritable(String, IWritableMount)
*/
public void unmount( String location );
/**
* Returns the numerical ID of this computercraft.<br>
* This is the same number obtained by calling os.getComputerID() or running the "id" program from lua,
* and is guarunteed unique. This number will be positive.
* @return The identifier.
*/
public int getID();
/**
* Causes an event to be raised on this computercraft, which the computercraft can respond to by calling
* os.pullEvent(). This can be used to notify the computercraft when things happen in the world or to
* this peripheral.
* @param event A string identifying the type of event that has occurred, this will be
* returned as the first value from os.pullEvent(). It is recommended that you
* you choose a name that is unique, and recognisable as originating from your
* peripheral. eg: If your peripheral type is "button", a suitable event would be
* "button_pressed".
* @param arguments In addition to a name, you may pass an array of extra arguments to the event, that will
* be supplied as extra return values to os.pullEvent(). Objects in the array will be converted
* to lua data types in the same fashion as the return values of IPeripheral.callMethod().<br>
* You may supply null to indicate that no arguments are to be supplied.
* @see dan200.computercraft.api.peripheral.IPeripheral#callMethod
*/
public void queueEvent( String event, Object[] arguments );
/**
* Get a string, unique to the computercraft, by which the computercraft refers to this peripheral.
* For directly attached peripherals this will be "left","right","front","back",etc, but
* for peripherals attached remotely it will be different. It is good practice to supply
* this string when raising events to the computercraft, so that the computercraft knows from
* which peripheral the event came.
* @return A string unique to the computercraft, but not globally.
*/
public String getAttachmentName();
}

View File

@ -0,0 +1,100 @@
/**
* This file is part of the public ComputerCraft API - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2015. This API may be redistributed unmodified and in full only.
* For help using the API, and posting your mods, visit the forums at computercraft.info.
*/
package dan200.computercraft.api.peripheral;
import dan200.computercraft.api.lua.ILuaContext;
import dan200.computercraft.api.lua.LuaException;
/**
* The interface that defines a peripheral. This should be implemented by the
* TileEntity of any common that you wish to be interacted with by
* computercraft or turtle.
*/
public interface IPeripheral
{
/**
* Should return a string that uniquely identifies this type of peripheral.
* This can be queried from lua by calling peripheral.getType()
* @return A string identifying the type of peripheral.
*/
public String getType();
/**
* Should return an array of strings that identify the methods that this
* peripheral exposes to Lua. This will be called once before each attachment,
* and should not change when called multiple times.
* @return An array of strings representing method names.
* @see #callMethod
*/
public String[] getMethodNames();
/**
* This is called when a lua program on an attached computercraft calls peripheral.call() with
* one of the methods exposed by getMethodNames().<br>
* <br>
* Be aware that this will be called from the ComputerCraft Lua thread, and must be thread-safe
* when interacting with minecraft objects.
* @param computer The interface to the computercraft that is making the call. Remember that multiple
* computers can be attached to a peripheral at once.
* @param context The context of the currently running lua thread. This can be used to wait for events
* or otherwise yield.
* @param method An integer identifying which of the methods from getMethodNames() the computercraft
* wishes to call. The integer indicates the index into the getMethodNames() table
* that corresponds to the string passed into peripheral.call()
* @param arguments An array of objects, representing the arguments passed into peripheral.call().<br>
* Lua values of type "string" will be represented by Object type String.<br>
* Lua values of type "number" will be represented by Object type Double.<br>
* Lua values of type "boolean" will be represented by Object type Boolean.<br>
* Lua values of any other type will be represented by a null object.<br>
* This array will be empty if no arguments are passed.
* @return An array of objects, representing values you wish to return to the lua program.<br>
* Integers, Doubles, Floats, Strings, Booleans and null be converted to their corresponding lua type.<br>
* All other types will be converted to nil.<br>
* You may return null to indicate no values should be returned.
* @throws Exception If you throw any exception from this function, a lua error will be raised with the
* same message as your exception. Use this to throw appropriate errors if the wrong
* arguments are supplied to your method.
* @see #getMethodNames
*/
public Object[] callMethod( IComputerAccess computer, ILuaContext context, int method, Object[] arguments ) throws LuaException, InterruptedException;
/**
* Is called when canAttachToSide has returned true, and a computercraft is attaching to the peripheral.
* This will occur when a peripheral is placed next to an active computercraft, when a computercraft is turned on next to a peripheral,
* or when a turtle travels into a square next to a peripheral.
* Between calls to attach() and detach(), the attached computercraft can make method calls on the peripheral using peripheral.call().
* This method can be used to keep track of which computers are attached to the peripheral, or to take action when attachment
* occurs.<br>
* <br>
* Be aware that this will be called from the ComputerCraft Lua thread, and must be thread-safe
* when interacting with minecraft objects.
* @param computer The interface to the computercraft that is being attached. Remember that multiple
* computers can be attached to a peripheral at once.
* @see #detach
*/
public void attach( IComputerAccess computer );
/**
* Is called when a computercraft is detaching from the peripheral.
* This will occur when a computercraft shuts down, when the peripheral is removed while attached to computers,
* or when a turtle moves away from a square attached to a peripheral.
* This method can be used to keep track of which computers are attached to the peripheral, or to take action when detachment
* occurs.<br>
* <br>
* Be aware that this will be called from the ComputerCraft Lua thread, and must be thread-safe
* when interacting with minecraft objects.
* @param computer The interface to the computercraft that is being detached. Remember that multiple
* computers can be attached to a peripheral at once.
* @see #detach
*/
public void detach( IComputerAccess computer );
/**
* TODO: Document me
*/
public boolean equals( IPeripheral other );
}

View File

@ -0,0 +1,23 @@
/**
* This file is part of the public ComputerCraft API - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2015. This API may be redistributed unmodified and in full only.
* For help using the API, and posting your mods, visit the forums at computercraft.info.
*/
package dan200.computercraft.api.peripheral;
import net.minecraft.world.World;
/**
* This interface is used to create peripheral implementations for blocks
* @see dan200.computercraft.api.ComputerCraftAPI#registerPeripheralProvider(IPeripheralProvider)
*/
public interface IPeripheralProvider
{
/**
* Produce an peripheral implementation from a block location.
* @see dan200.computercraft.api.ComputerCraftAPI#registerPeripheralProvider(IPeripheralProvider)
* @return a peripheral, or null if there is not a peripheral here you'd like to handle.
*/
public IPeripheral getPeripheral( World world, int x, int y, int z, int side );
}

View File

@ -0,0 +1,10 @@
/**
* This file is part of the public ComputerCraft API - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2015. This API may be redistributed unmodified and in full only.
* For help using the API, and posting your mods, visit the forums at computercraft.info.
*/
@API( owner="ComputerCraft", provides="ComputerCraft|API|Peripheral", apiVersion="1.75" )
package dan200.computercraft.api.peripheral;
import cpw.mods.fml.common.API;

View File

@ -0,0 +1,19 @@
/**
* This file is part of the public ComputerCraft API - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2015. This API may be redistributed unmodified and in full only.
* For help using the API, and posting your mods, visit the forums at computercraft.info.
*/
package dan200.computercraft.api.permissions;
import net.minecraft.world.World;
/**
* This interface is used to restrict where turtles can move or build
* @see dan200.computercraft.api.ComputerCraftAPI#registerPermissionProvider(ITurtlePermissionProvider)
*/
public interface ITurtlePermissionProvider
{
public boolean isBlockEnterable( World world, int x, int y, int z );
public boolean isBlockEditable( World world, int x, int y, int z );
}

View File

@ -0,0 +1,10 @@
/**
* This file is part of the public ComputerCraft API - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2015. This API may be redistributed unmodified and in full only.
* For help using the API, and posting your mods, visit the forums at computercraft.info.
*/
@API( owner="ComputerCraft", provides="ComputerCraft|API|Permissions", apiVersion="1.75" )
package dan200.computercraft.api.permissions;
import cpw.mods.fml.common.API;

View File

@ -0,0 +1,23 @@
/**
* This file is part of the public ComputerCraft API - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2015. This API may be redistributed unmodified and in full only.
* For help using the API, and posting your mods, visit the forums at computercraft.info.
*/
package dan200.computercraft.api.redstone;
import net.minecraft.world.World;
/**
* This interface is used to provide bundled redstone output for blocks
* @see dan200.computercraft.api.ComputerCraftAPI#registerBundledRedstoneProvider(IBundledRedstoneProvider)
*/
public interface IBundledRedstoneProvider
{
/**
* Produce an bundled redstone output from a block location.
* @see dan200.computercraft.api.ComputerCraftAPI#registerBundledRedstoneProvider(IBundledRedstoneProvider)
* @return a number in the range 0-65535 to indicate this block is providing output, or -1 if you do not wish to handle this block
*/
public int getBundledRedstoneOutput( World world, int x, int y, int z, int side );
}

View File

@ -0,0 +1,10 @@
/**
* This file is part of the public ComputerCraft API - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2015. This API may be redistributed unmodified and in full only.
* For help using the API, and posting your mods, visit the forums at computercraft.info.
*/
@API( owner="ComputerCraft", provides="ComputerCraft|API|Redstone", apiVersion="1.75" )
package dan200.computercraft.api.redstone;
import cpw.mods.fml.common.API;

View File

@ -0,0 +1,168 @@
/**
* This file is part of the public ComputerCraft API - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2015. This API may be redistributed unmodified and in full only.
* For help using the API, and posting your mods, visit the forums at computercraft.info.
*/
package dan200.computercraft.api.turtle;
import dan200.computercraft.api.lua.ILuaContext;
import dan200.computercraft.api.lua.LuaException;
import dan200.computercraft.api.peripheral.IPeripheral;
import net.minecraft.inventory.IInventory;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ChunkCoordinates;
import net.minecraft.util.Vec3;
import net.minecraft.world.World;
/**
* The interface passed to turtle by turtles, providing methods that they can call.
* This should not be implemented by your classes. Do not interact with turtles except via this interface and ITurtleUpgrade.
*/
public interface ITurtleAccess
{
/**
* Returns the world in which the turtle resides.
* @return the world in which the turtle resides.
*/
public World getWorld();
/**
* Returns a vector containing the integer co-ordinates at which the turtle resides.
* @return a vector containing the integer co-ordinates at which the turtle resides.
*/
public ChunkCoordinates getPosition();
/**
* TODO: Document me
*/
public boolean teleportTo( World world, int x, int y, int z );
/**
* Returns a vector containing the floating point co-ordinates at which the turtle is rendered.
* This will shift when the turtle is moving.
* @param f The subframe fraction
* @return a vector containing the floating point co-ordinates at which the turtle resides.
*/
public Vec3 getVisualPosition( float f );
/**
* TODO: Document me
*/
public float getVisualYaw( float f );
/**
* Returns the world direction the turtle is currently facing.
* @return the world direction the turtle is currently facing.
*/
public int getDirection();
/**
* TODO: Document me
*/
public void setDirection( int dir );
/**
* TODO: Document me
*/
public int getSelectedSlot();
/**
* TODO: Document me
*/
public void setSelectedSlot( int slot );
/**
* Sets the colour of the turtle, as if the player had dyed it with a dye item.
* @param dyeColour 0-15 to dye the turtle one of the 16 standard minecraft colours, or -1 to remove the dye from the turtle.
*/
public void setDyeColour( int dyeColour );
/**
* Gets the colour the turtle has been dyed.
* @return 0-15 if the turtle has been dyed one of the 16 standard minecraft colours, -1 if the turtle is clean.
*/
public int getDyeColour();
/**
* TODO: Document me
*/
public IInventory getInventory();
/**
* TODO: Document me
*/
public boolean isFuelNeeded();
/**
* TODO: Document me
*/
public int getFuelLevel();
/**
* TODO: Document me
*/
public void setFuelLevel( int fuel );
/**
* TODO: Document me
*/
public int getFuelLimit();
/**
* Removes some fuel from the turtles fuel supply. Negative numbers can be passed in to INCREASE the fuel level of the turtle.
* @return Whether the turtle was able to consume the ammount of fuel specified. Will return false if you supply a number
* greater than the current fuel level of the turtle.
*/
public boolean consumeFuel( int fuel );
/**
* TODO: Document me
*/
public void addFuel( int fuel );
/**
* Adds a custom command to the turtles command queue. Unlike peripheral methods, these custom commands will be executed
* on the main thread, so are guaranteed to be able to access Minecraft objects safely, and will be queued up
* with the turtles standard movement and tool commands. An issued command will return an unique integer, which will
* be supplied as a parameter to a "turtle_response" event issued to the turtle after the command has completed. Look at the
* lua source code for "rom/apis/turtle" for how to build a lua wrapper around this functionality.
* @param command an object which will execute the custom command when its point in the queue is reached
* @return the objects the command returned when executed. you should probably return these to the player
* unchanged if called from a peripheral method.
* @see ITurtleCommand
*/
public Object[] executeCommand( ILuaContext context, ITurtleCommand command ) throws LuaException, InterruptedException;
/**
* TODO: Document me
*/
public void playAnimation( TurtleAnimation animation );
/**
* Returns the turtle on the specified side of the turtle, if there is one.
* @return the turtle on the specified side of the turtle, if there is one.
*/
public ITurtleUpgrade getUpgrade( TurtleSide side );
/**
* TODO: Document me
*/
public void setUpgrade( TurtleSide side, ITurtleUpgrade upgrade );
/**
* Returns the peripheral created by the upgrade on the specified side of the turtle, if there is one.
* @return the peripheral created by the upgrade on the specified side of the turtle, if there is one.
*/
public IPeripheral getPeripheral( TurtleSide side );
/**
* TODO: Document me
*/
public NBTTagCompound getUpgradeNBTData( TurtleSide side );
/**
* TODO: Document me
*/
public void updateUpgradeNBTData( TurtleSide side );
}

View File

@ -0,0 +1,25 @@
/**
* This file is part of the public ComputerCraft API - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2015. This API may be redistributed unmodified and in full only.
* For help using the API, and posting your mods, visit the forums at computercraft.info.
*/
package dan200.computercraft.api.turtle;
/**
* An interface for objects executing custom turtle commands, used with ITurtleAccess.issueCommand
* @see ITurtleAccess#executeCommand(dan200.computercraft.api.lua.ILuaContext,ITurtleCommand)
*/
public interface ITurtleCommand
{
/**
* Will be called by the turtle on the main thread when it is time to execute the custom command.
* The handler should either perform the work of the command, and return success, or return
* failure with an error message to indicate the command cannot be executed at this time.
* @param turtle access to the turtle for whom the command was issued
* @return TurtleCommandResult.success() or TurtleCommandResult.failure( errorMessage )
* @see ITurtleAccess#executeCommand(dan200.computercraft.api.lua.ILuaContext,ITurtleCommand)
* @see dan200.computercraft.api.turtle.TurtleCommandResult
*/
public TurtleCommandResult execute( ITurtleAccess turtle );
}

View File

@ -0,0 +1,94 @@
/**
* This file is part of the public ComputerCraft API - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2015. This API may be redistributed unmodified and in full only.
* For help using the API, and posting your mods, visit the forums at computercraft.info.
*/
package dan200.computercraft.api.turtle;
import dan200.computercraft.api.peripheral.IPeripheral;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
/**
* The primary interface for defining an turtle for Turtles. A turtle turtle
* can either be a new tool, or a new peripheral.
* @see dan200.computercraft.api.ComputerCraftAPI#registerTurtleUpgrade( dan200.computercraft.api.turtle.ITurtleUpgrade )
*/
public interface ITurtleUpgrade
{
/**
* Gets a unique numerical identifier representing this type of turtle turtle.
* Like Minecraft common and item IDs, you should strive to make this number unique
* among all turtle turtle that have been released for ComputerCraft.
* The ID must be in the range 64 to 255, as the ID is stored as an 8-bit value,
* and 0-64 is reserved for future use by ComputerCraft. The turtle will
* fail registration if an already used ID is specified.
* @see dan200.computercraft.api.ComputerCraftAPI#registerTurtleUpgrade( dan200.computercraft.api.turtle.ITurtleUpgrade )
*/
public int getUpgradeID();
/**
* Return a String to describe this type of turtle in turtle item names.
* Examples of built-in adjectives are "Wireless", "Mining" and "Crafty".
*/
public String getUnlocalisedAdjective();
/**
* Return whether this turtle adds a tool or a peripheral to the turtle.
* Currently, turtle crafting is restricted to one tool & one peripheral per turtle.
* @see TurtleUpgradeType for the differences between the two.
*/
public TurtleUpgradeType getType();
/**
* Return an item stack representing the type of item that a turtle must be crafted
* with to create a turtle which holds this turtle.
* Currently, turtle crafting is restricted to one tool & one peripheral per turtle.
*/
public ItemStack getCraftingItem();
/**
* Will only be called for Peripheral turtle. Creates a peripheral for a turtle
* being placed using this turtle. The peripheral created will be stored
* for the lifetime of the turtle, will have update() called once-per-tick, and will be
* attach'd detach'd and have methods called in the same manner as a Computer peripheral.
*
* @param turtle Access to the turtle that the peripheral is being created for.
* @param side Which side of the turtle (left or right) that the turtle resides on.
* @return The newly created peripheral. You may return null if this turtle is a Tool
* and this method is not expected to be called.
*/
public IPeripheral createPeripheral( ITurtleAccess turtle, TurtleSide side );
/**
* Will only be called for Tool turtle. Called when turtle.dig() or turtle.attack() is called
* by the turtle, and the tool is required to do some work.
* @param turtle Access to the turtle that the tool resides on.
* @param side Which side of the turtle (left or right) the tool resides on.
* @param verb Which action (dig or attack) the turtle is being called on to perform.
* @param direction Which world direction the action should be performed in, relative to the turtles
* position. This will either be up, down, or the direction the turtle is facing, depending on
* whether dig, digUp or digDown was called.
* @return Whether the turtle was able to perform the action, and hence whether the turtle.dig()
* or turtle.attack() lua method should return true. If true is returned, the tool will perform
* a swinging animation. You may return null if this turtle is a Peripheral
* and this method is not expected to be called.
*/
public TurtleCommandResult useTool( ITurtleAccess turtle, TurtleSide side, TurtleVerb verb, int direction );
/**
* Called to obtain the IIcon to be used when rendering a turtle peripheral. Needs to be a "common"
* type IIcon for now, as there is no way to determine which texture sheet an IIcon is from by the
* IIcon itself.
* @param turtle Access to the turtle that the peripheral resides on.
* @param side Which side of the turtle (left or right) the peripheral resides on.
* @return The IIcon that you wish to be used to render your turtle peripheral.
*/
public IIcon getIcon( ITurtleAccess turtle, TurtleSide side );
/**
* TODO: Document me
*/
public void update( ITurtleAccess turtle, TurtleSide side );
}

View File

@ -0,0 +1,22 @@
/**
* This file is part of the public ComputerCraft API - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2015. This API may be redistributed unmodified and in full only.
* For help using the API, and posting your mods, visit the forums at computercraft.info.
*/
package dan200.computercraft.api.turtle;
public enum TurtleAnimation
{
None,
MoveForward,
MoveBack,
MoveUp,
MoveDown,
TurnLeft,
TurnRight,
SwingLeftTool,
SwingRightTool,
Wait,
ShortWait,
}

View File

@ -0,0 +1,73 @@
/**
* This file is part of the public ComputerCraft API - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2015. This API may be redistributed unmodified and in full only.
* For help using the API, and posting your mods, visit the forums at computercraft.info.
*/
package dan200.computercraft.api.turtle;
public final class TurtleCommandResult
{
private static final TurtleCommandResult s_success = new TurtleCommandResult( true, null, null );
private static final TurtleCommandResult s_emptyFailure = new TurtleCommandResult( false, null, null );
public static TurtleCommandResult success()
{
return success( null );
}
public static TurtleCommandResult success( Object[] results )
{
if( results == null || results.length == 0 )
{
return s_success;
}
else
{
return new TurtleCommandResult( true, null, results );
}
}
public static TurtleCommandResult failure()
{
return failure( null );
}
public static TurtleCommandResult failure( String errorMessage )
{
if( errorMessage == null )
{
return s_emptyFailure;
}
else
{
return new TurtleCommandResult( false, errorMessage, null );
}
}
private final boolean m_success;
private final String m_errorMessage;
private final Object[] m_results;
private TurtleCommandResult( boolean success, String errorMessage, Object[] results )
{
m_success = success;
m_errorMessage = errorMessage;
m_results = results;
}
public boolean isSuccess()
{
return m_success;
}
public String getErrorMessage()
{
return m_errorMessage;
}
public Object[] getResults()
{
return m_results;
}
}

View File

@ -0,0 +1,23 @@
/**
* This file is part of the public ComputerCraft API - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2015. This API may be redistributed unmodified and in full only.
* For help using the API, and posting your mods, visit the forums at computercraft.info.
*/
package dan200.computercraft.api.turtle;
/**
* An enum representing the two sides of the turtle that a turtle turtle might reside.
*/
public enum TurtleSide
{
/**
* The turtles left side (where the pickaxe usually is on a Wireless Mining Turtle)
*/
Left,
/**
* The turtles right side (where the modem usually is on a Wireless Mining Turtle)
*/
Right,
}

View File

@ -0,0 +1,27 @@
/**
* This file is part of the public ComputerCraft API - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2015. This API may be redistributed unmodified and in full only.
* For help using the API, and posting your mods, visit the forums at computercraft.info.
*/
package dan200.computercraft.api.turtle;
/**
* An enum representing the two different types of turtle that an ITurtleUpgrade
* implementation can add to a turtle.
* @see ITurtleUpgrade
*/
public enum TurtleUpgradeType
{
/**
* A tool is rendered as an item on the side of the turtle, and responds to the turtle.dig()
* and turtle.attack() methods (Such as pickaxe or sword on Mining and Melee turtles).
*/
Tool,
/**
* A peripheral adds a special peripheral which is attached to the side of the turtle,
* and can be interacted with the peripheral API (Such as the modem on Wireless Turtles).
*/
Peripheral,
}

View File

@ -0,0 +1,26 @@
/**
* This file is part of the public ComputerCraft API - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2015. This API may be redistributed unmodified and in full only.
* For help using the API, and posting your mods, visit the forums at computercraft.info.
*/
package dan200.computercraft.api.turtle;
/**
* An enum representing the two different actions that an ITurtleUpgrade of type
* Tool may be called on to perform by a turtle.
* @see ITurtleUpgrade
* @see ITurtleUpgrade#useTool
*/
public enum TurtleVerb
{
/**
* The turtle called turtle.dig(), turtle.digUp() or turtle.digDown()
*/
Dig,
/**
* The turtle called turtle.attack(), turtle.attackUp() or turtle.attackDown()
*/
Attack,
}

View File

@ -0,0 +1,10 @@
/**
* This file is part of the public ComputerCraft API - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2015. This API may be redistributed unmodified and in full only.
* For help using the API, and posting your mods, visit the forums at computercraft.info.
*/
@API( owner="ComputerCraft", provides="ComputerCraft|API|Turtle", apiVersion="1.75" )
package dan200.computercraft.api.turtle;
import cpw.mods.fml.common.API;

View File

@ -0,0 +1,10 @@
package icbm.api;
import net.minecraft.item.ItemStack;
public interface IAmmunition {
boolean hasAmmunition(ItemStack var1);
boolean useAmmunition(ItemStack var1);
}

View File

@ -0,0 +1,9 @@
package icbm.api;
public interface IBlockFrequency {
int getFrequency();
void setFrequency(int var1);
}

View File

@ -0,0 +1,41 @@
package icbm.api;
import icbm.api.explosion.IExplosive;
import java.lang.reflect.Method;
import net.minecraft.entity.Entity;
import net.minecraft.world.World;
public class ICBM {
public static final String NAME = "ICBM";
public static final String VERSION = "1.1.1";
public static final int BLOCK_ID_PREFIX = 3880;
public static final int ITEM_ID_PREFIX = 3900;
public static Class explosionManager;
public static void createExplosion(World worldObj, double x, double y, double z, Entity entity, int explosiveID) {
try {
Method e = explosionManager.getMethod("createExplosion", new Class[]{World.class, Double.class, Double.class, Double.class, Entity.class, Integer.class});
e.invoke((Object)null, new Object[]{worldObj, Double.valueOf(x), Double.valueOf(y), Double.valueOf(z), entity, Integer.valueOf(explosiveID)});
} catch (Exception var10) {
System.out.println("ICBM: Failed to create an ICBM explosion with the ID: " + explosiveID);
var10.printStackTrace();
}
}
public static IExplosive getExplosive(String name) {
if(name != null) {
try {
Method e = explosionManager.getMethod("getExplosiveByName", new Class[]{String.class});
return (IExplosive)e.invoke((Object)null, new Object[]{name});
} catch (Exception var2) {
System.out.println("ICBM: Failed to get explosive with the name: " + name);
var2.printStackTrace();
}
}
return null;
}
}

View File

@ -0,0 +1,15 @@
package icbm.api;
public class ICBMFlags {
// TODO: WTF
// public static final String FLAG_BAN_GLOBAL =
// FlagRegistry.registerFlag("ban_icbm");
// public static final String FLAG_BAN_EXPLOSIVE =
// FlagRegistry.registerFlag("ban_explosive");
// public static final String FLAG_BAN_GRENADE =
// FlagRegistry.registerFlag("ban_grenade");
// public static final String FLAG_BAN_MISSILE =
// FlagRegistry.registerFlag("ban_missile");
// public static final String FLAG_BAN_MINECART =
// FlagRegistry.registerFlag("ban_minecart");
}

View File

@ -0,0 +1,5 @@
package icbm.api;
public interface ICamouflageMaterial {
}

View File

@ -0,0 +1,10 @@
package icbm.api;
import net.minecraft.entity.player.EntityPlayer;
public interface IHackable {
void generateNewKey();
boolean tryForAccess(EntityPlayer var1, String var2);
}

View File

@ -0,0 +1,10 @@
package icbm.api;
import net.minecraft.item.ItemStack;
public interface IItemFrequency {
int getFrequency(ItemStack var1);
void setFrequency(int var1, ItemStack var2);
}

View File

@ -0,0 +1,13 @@
package icbm.api;
import icbm.api.ILauncherController;
import icbm.api.IMissile;
public interface ILauncherContainer {
IMissile getContainingMissile();
void setContainingMissile(IMissile var1);
ILauncherController getController();
}

View File

@ -0,0 +1,28 @@
package icbm.api;
import icbm.api.IBlockFrequency;
import icbm.api.IMissile;
import icbm.api.LauncherType;
import net.minecraft.item.ItemStack;
import universalelectricity.core.block.IElectricityStorage;
import universalelectricity.core.vector.Vector3;
import universalelectricity.prefab.implement.IRedstoneReceptor;
public interface ILauncherController extends IElectricityStorage, IRedstoneReceptor, IBlockFrequency {
LauncherType getLauncherType();
void launch();
boolean canLaunch();
String getStatus();
Vector3 getTarget();
void setTarget(Vector3 var1);
void placeMissile(ItemStack var1);
IMissile getMissile();
}

View File

@ -0,0 +1,26 @@
package icbm.api;
import icbm.api.ILauncherContainer;
import icbm.api.explosion.IExplosiveContainer;
import universalelectricity.core.vector.Vector3;
public interface IMissile extends IExplosiveContainer {
void explode();
void setExplode();
void normalExplode();
void setNormalExplode();
void dropMissileAsItem();
int getTicksInAir();
ILauncherContainer getLauncher();
void launch(Vector3 var1);
void launch(Vector3 var1, int var2);
}

View File

@ -0,0 +1,11 @@
package icbm.api;
import icbm.api.IMissile;
import universalelectricity.core.vector.Vector3;
public interface IMissileLockable {
boolean canLock(IMissile var1);
Vector3 getPredictedPosition(int var1);
}

View File

@ -0,0 +1,14 @@
package icbm.api;
public enum LauncherType {
TRADITIONAL("TRADITIONAL", 0),
CRUISE("CRUISE", 1);
// $FF: synthetic field
private static final LauncherType[] $VALUES = new LauncherType[]{TRADITIONAL, CRUISE};
private LauncherType(String var1, int var2) {}
}

View File

@ -0,0 +1,110 @@
package icbm.api;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import net.minecraft.entity.Entity;
import net.minecraft.tileentity.TileEntity;
import universalelectricity.core.vector.Vector2;
import universalelectricity.core.vector.Vector3;
import universalelectricity.prefab.vector.Region2;
public class RadarRegistry {
private static Set<TileEntity> detectableTileEntities = new HashSet<>();
private static Set<Entity> detectableEntities = new HashSet<>();
public static void register(TileEntity tileEntity) {
if (!detectableTileEntities.contains(tileEntity)) {
detectableTileEntities.add(tileEntity);
}
}
public static void unregister(TileEntity tileEntity) {
if (detectableTileEntities.contains(tileEntity)) {
detectableTileEntities.remove(tileEntity);
}
}
public static void register(Entity entity) {
if (!detectableEntities.contains(entity)) {
detectableEntities.add(entity);
}
}
public static void unregister(Entity entity) {
if (detectableEntities.contains(entity)) {
detectableEntities.remove(entity);
}
}
public static List<TileEntity> getTileEntitiesInArea(Vector2 minVector,
Vector2 maxVector) {
ArrayList<TileEntity> returnArray = new ArrayList<>();
cleanUpArray();
for (TileEntity tileEntity : detectableTileEntities) {
if ((new Region2(minVector, maxVector))
.isIn((new Vector3(tileEntity)).toVector2())) {
returnArray.add(tileEntity);
}
}
return returnArray;
}
public static List<Entity> getEntitiesWithinRadius(Vector2 vector,
int radius) {
cleanUpArray();
ArrayList<Entity> returnArray = new ArrayList<>();
for (Entity entity : detectableEntities) {
if (Vector2.distance(vector, (new Vector3(entity)).toVector2()) <=
(double)radius) {
returnArray.add(entity);
}
}
return returnArray;
}
public static Set<TileEntity> getTileEntities() {
cleanUpArray();
return detectableTileEntities;
}
public static Set<Entity> getEntities() {
cleanUpArray();
return detectableEntities;
}
public static void cleanUpArray() {
try {
Iterator<TileEntity> e = detectableTileEntities.iterator();
while (e.hasNext()) {
TileEntity it2 = e.next();
if (it2 == null) {
e.remove();
} else if (it2.isInvalid()) {
e.remove();
} else if (it2.getWorldObj().getTileEntity(it2.xCoord, it2.yCoord,
it2.zCoord) != it2) {
e.remove();
}
}
Iterator<Entity> it21 = detectableEntities.iterator();
while (it21.hasNext()) {
Entity entity = (Entity)it21.next();
if (entity == null) {
it21.remove();
} else if (entity.isDead) {
it21.remove();
}
}
} catch (Exception var3) {
System.out.println("Failed to clean up radar list properly.");
var3.printStackTrace();
}
}
}

View File

@ -0,0 +1,36 @@
package icbm.api.explosion;
import cpw.mods.fml.common.eventhandler.Event;
import net.minecraft.world.World;
public class ExplosionEvent extends Event {
public final World world;
public final double x;
public final double y;
public final double z;
public IExplosive explosive;
public ExplosionEvent(World world, double x, double y, double z, IExplosive explosive) {
this.world = world;
this.x = x;
this.y = y;
this.z = z;
this.explosive = explosive;
}
public static class PostExplosionEvent extends ExplosionEvent {
public PostExplosionEvent(World world, double x, double y, double z, IExplosive explosive) {
super(world, x, y, z, explosive);
}
}
public static class PreExplosionEvent extends ExplosionEvent {
public PreExplosionEvent(World world, double x, double y, double z, IExplosive explosive) {
super(world, x, y, z, explosive);
}
}
}

View File

@ -0,0 +1,10 @@
package icbm.api.explosion;
import icbm.api.explosion.IExplosive;
import net.minecraft.world.World;
import universalelectricity.core.vector.Vector3;
public interface IEMPBlock {
void onEMP(World var1, Vector3 var2, IExplosive var3);
}

View File

@ -0,0 +1,11 @@
package icbm.api.explosion;
import icbm.api.explosion.IExplosive;
import net.minecraft.entity.Entity;
import net.minecraft.item.ItemStack;
import universalelectricity.core.item.IItemElectric;
public interface IEMPItem extends IItemElectric {
void onEMP(ItemStack var1, Entity var2, IExplosive var3);
}

View File

@ -0,0 +1,23 @@
package icbm.api.explosion;
public interface IExplosive {
int getID();
String getUnlocalizedName();
String getExplosiveName();
String getGrenadeName();
String getMissileName();
String getMinecartName();
float getRadius();
int getTier();
double getEnergy();
}

View File

@ -0,0 +1,8 @@
package icbm.api.explosion;
import icbm.api.explosion.IExplosive;
public interface IExplosiveContainer {
IExplosive getExplosiveType();
}

View File

@ -0,0 +1,8 @@
package icbm.api.explosion;
import icbm.api.explosion.ExplosionEvent;
public interface IExplosiveIgnore {
boolean canIgnore(ExplosionEvent var1);
}

View File

@ -0,0 +1,131 @@
package mffs;
import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.client.registry.ClientRegistry;
import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
import cpw.mods.fml.client.registry.RenderingRegistry;
import mffs.gui.GuiBiometricIdentifier;
import mffs.gui.GuiCoercionDeriver;
import mffs.gui.GuiForceFieldProjector;
import mffs.gui.GuiForceManipulator;
import mffs.gui.GuiFortronCapacitor;
import mffs.gui.GuiInterdictionMatrix;
import mffs.render.FXBeam;
import mffs.render.FXHologram;
import mffs.render.FXHologramMoving;
import mffs.render.RenderBlockHandler;
import mffs.render.RenderCoercionDeriver;
import mffs.render.RenderForceField;
import mffs.render.RenderForceFieldProjector;
import mffs.render.RenderForceManipulator;
import mffs.render.RenderFortronCapacitor;
import mffs.render.RenderIDCard;
import mffs.tileentity.TileEntityBiometricIdentifier;
import mffs.tileentity.TileEntityCoercionDeriver;
import mffs.tileentity.TileEntityForceFieldProjector;
import mffs.tileentity.TileEntityForceManipulator;
import mffs.tileentity.TileEntityFortronCapacitor;
import mffs.tileentity.TileEntityInterdictionMatrix;
import net.minecraft.client.particle.EntityFX;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.client.IItemRenderer;
import net.minecraftforge.client.MinecraftForgeClient;
import universalelectricity.core.vector.Vector3;
public class ClientProxy extends CommonProxy {
@Override
public void init() {
super.init();
RenderingRegistry.registerBlockHandler(
(ISimpleBlockRenderingHandler) new RenderBlockHandler());
RenderingRegistry.registerBlockHandler(
(ISimpleBlockRenderingHandler) new RenderForceField());
MinecraftForgeClient.registerItemRenderer(
ModularForceFieldSystem.itemCardID, (IItemRenderer) new RenderIDCard());
ClientRegistry.bindTileEntitySpecialRenderer(
TileEntityFortronCapacitor.class,
(TileEntitySpecialRenderer) new RenderFortronCapacitor());
ClientRegistry.bindTileEntitySpecialRenderer(
TileEntityCoercionDeriver.class,
(TileEntitySpecialRenderer) new RenderCoercionDeriver());
ClientRegistry.bindTileEntitySpecialRenderer(
TileEntityForceManipulator.class,
(TileEntitySpecialRenderer) new RenderForceManipulator());
ClientRegistry.bindTileEntitySpecialRenderer(
TileEntityForceFieldProjector.class,
(TileEntitySpecialRenderer) new RenderForceFieldProjector());
}
@Override
public World getClientWorld() {
return (World)FMLClientHandler.instance().getClient().theWorld;
}
@Override
public Object getClientGuiElement(final int ID, final EntityPlayer player,
final World world, final int x, final int y,
final int z) {
final TileEntity tileEntity = world.getTileEntity(x, y, z);
if (tileEntity != null) {
if (tileEntity.getClass() == TileEntityFortronCapacitor.class) {
return new GuiFortronCapacitor(player,
(TileEntityFortronCapacitor)tileEntity);
}
if (tileEntity.getClass() == TileEntityForceFieldProjector.class) {
return new GuiForceFieldProjector(
player, (TileEntityForceFieldProjector)tileEntity);
}
if (tileEntity.getClass() == TileEntityCoercionDeriver.class) {
return new GuiCoercionDeriver(player,
(TileEntityCoercionDeriver)tileEntity);
}
if (tileEntity.getClass() == TileEntityBiometricIdentifier.class) {
return new GuiBiometricIdentifier(
player, (TileEntityBiometricIdentifier)tileEntity);
}
if (tileEntity.getClass() == TileEntityInterdictionMatrix.class) {
return new GuiInterdictionMatrix(
player, (TileEntityInterdictionMatrix)tileEntity);
}
if (tileEntity.getClass() == TileEntityForceManipulator.class) {
return new GuiForceManipulator(player,
(TileEntityForceManipulator)tileEntity);
}
}
return null;
}
@Override
public boolean isOp(final String username) {
return false;
}
@Override
public void renderBeam(final World world, final Vector3 position,
final Vector3 target, final float red,
final float green, final float blue, final int age) {
FMLClientHandler.instance().getClient().effectRenderer.addEffect(
(EntityFX) new FXBeam(world, position, target, red, green, blue, age));
}
@Override
public void renderHologram(final World world, final Vector3 position,
final float red, final float green,
final float blue, final int age,
final Vector3 targetPosition) {
FMLClientHandler.instance().getClient().effectRenderer.addEffect(
(EntityFX) new FXHologram(world, position, red, green, blue, age)
.setTarget(targetPosition));
}
@Override
public void renderHologramMoving(final World world, final Vector3 position,
final float red, final float green,
final float blue, final int age) {
FMLClientHandler.instance().getClient().effectRenderer.addEffect((
EntityFX) new FXHologramMoving(world, position, red, green, blue, age));
}
}

View File

@ -0,0 +1,94 @@
package mffs;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.network.IGuiHandler;
import mffs.container.ContainerBiometricIdentifier;
import mffs.container.ContainerCoercionDeriver;
import mffs.container.ContainerForceFieldProjector;
import mffs.container.ContainerForceManipulator;
import mffs.container.ContainerFortronCapacitor;
import mffs.container.ContainerInterdictionMatrix;
import mffs.tileentity.TileEntityBiometricIdentifier;
import mffs.tileentity.TileEntityCoercionDeriver;
import mffs.tileentity.TileEntityForceFieldProjector;
import mffs.tileentity.TileEntityForceManipulator;
import mffs.tileentity.TileEntityFortronCapacitor;
import mffs.tileentity.TileEntityInterdictionMatrix;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.server.MinecraftServer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import universalelectricity.core.vector.Vector3;
public class CommonProxy implements IGuiHandler {
public void preInit() {}
public void init() {}
public Object getClientGuiElement(final int ID, final EntityPlayer player,
final World world, final int x, final int y,
final int z) {
return null;
}
public Object getServerGuiElement(final int ID, final EntityPlayer player,
final World world, final int x, final int y,
final int z) {
final TileEntity tileEntity = world.getTileEntity(x, y, z);
if (tileEntity != null) {
if (tileEntity.getClass() == TileEntityFortronCapacitor.class) {
return new ContainerFortronCapacitor(
player, (TileEntityFortronCapacitor)tileEntity);
}
if (tileEntity.getClass() == TileEntityForceFieldProjector.class) {
return new ContainerForceFieldProjector(
player, (TileEntityForceFieldProjector)tileEntity);
}
if (tileEntity.getClass() == TileEntityCoercionDeriver.class) {
return new ContainerCoercionDeriver(
player, (TileEntityCoercionDeriver)tileEntity);
}
if (tileEntity.getClass() == TileEntityBiometricIdentifier.class) {
return new ContainerBiometricIdentifier(
player, (TileEntityBiometricIdentifier)tileEntity);
}
if (tileEntity.getClass() == TileEntityInterdictionMatrix.class) {
return new ContainerInterdictionMatrix(
player, (TileEntityInterdictionMatrix)tileEntity);
}
if (tileEntity.getClass() == TileEntityForceManipulator.class) {
return new ContainerForceManipulator(
player, (TileEntityForceManipulator)tileEntity);
}
}
return null;
}
public World getClientWorld() { return null; }
public boolean isOp(final String username) {
final MinecraftServer theServer =
FMLCommonHandler.instance().getMinecraftServerInstance();
if (theServer == null)
return false;
for (String op : theServer.getConfigurationManager().func_152606_n())
if (username.trim().equalsIgnoreCase(op))
return true;
return false;
}
public void renderBeam(final World world, final Vector3 position,
final Vector3 target, final float red,
final float green, final float blue, final int age) {}
public void renderHologram(final World world, final Vector3 position,
final float red, final float green,
final float blue, final int age,
final Vector3 targetPosition) {}
public void renderHologramMoving(final World world, final Vector3 position,
final float red, final float green,
final float blue, final int age) {}
}

View File

@ -0,0 +1,23 @@
package mffs;
public abstract class DelayedEvent {
public int ticks;
protected IDelayedEventHandler handler;
public DelayedEvent(final IDelayedEventHandler handler, final int ticks) {
this.ticks = 0;
this.handler = handler;
this.ticks = ticks;
}
protected abstract void onEvent();
public void update() {
--this.ticks;
if (this.ticks <= 0) {
this.onEvent();
}
}
public int getPriority() { return 0; }
}

View File

@ -0,0 +1,10 @@
package mffs;
import java.util.List;
public interface IDelayedEventHandler
{
List<DelayedEvent> getDelayedEvents();
List<DelayedEvent> getQuedDelayedEvents();
}

View File

@ -0,0 +1,23 @@
package mffs;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
public class MFFSCreativeTab extends CreativeTabs {
public static CreativeTabs INSTANCE;
public MFFSCreativeTab(final int par1, final String par2Str) {
super(par1, par2Str);
}
@Override
public Item getTabIconItem() {
return Item.getItemFromBlock(
ModularForceFieldSystem.blockForceFieldProjector);
}
static {
MFFSCreativeTab.INSTANCE =
new MFFSCreativeTab(CreativeTabs.getNextID(), "MFFS");
}
}

View File

@ -0,0 +1,370 @@
package mffs;
import calclavia.lib.CalculationHelper;
import icbm.api.IBlockFrequency;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Set;
import mffs.api.IProjector;
import mffs.api.fortron.IFortronFrequency;
import mffs.api.modules.IModuleAcceptor;
import mffs.api.security.IInterdictionMatrix;
import mffs.api.security.Permission;
import mffs.fortron.FrequencyGrid;
import mffs.item.module.projector.ItemModeCustom;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import universalelectricity.core.vector.Vector3;
public class MFFSHelper {
public static void
transferFortron(final IFortronFrequency transferer,
final Set<IFortronFrequency> frequencyTiles,
final TransferMode transferMode, final int limit) {
if (transferer != null && frequencyTiles.size() > 1) {
int totalFortron = 0;
int totalCapacity = 0;
for (final IFortronFrequency machine : frequencyTiles) {
if (machine != null) {
totalFortron += machine.getFortronEnergy();
totalCapacity += machine.getFortronCapacity();
}
}
if (totalFortron > 0 && totalCapacity > 0) {
switch (transferMode) {
case EQUALIZE: {
for (final IFortronFrequency machine : frequencyTiles) {
if (machine != null) {
final double capacityPercentage =
machine.getFortronCapacity() / (double)totalCapacity;
final int amountToSet = (int)(totalFortron * capacityPercentage);
doTransferFortron(transferer, machine,
amountToSet - machine.getFortronEnergy(),
limit);
}
}
break;
}
case DISTRIBUTE: {
final int amountToSet2 = totalFortron / frequencyTiles.size();
for (final IFortronFrequency machine2 : frequencyTiles) {
if (machine2 != null) {
doTransferFortron(transferer, machine2,
amountToSet2 - machine2.getFortronEnergy(),
limit);
}
}
break;
}
case DRAIN: {
frequencyTiles.remove(transferer);
for (final IFortronFrequency machine : frequencyTiles) {
if (machine != null) {
final double capacityPercentage =
machine.getFortronCapacity() / (double)totalCapacity;
final int amountToSet = (int)(totalFortron * capacityPercentage);
if (amountToSet - machine.getFortronEnergy() <= 0) {
continue;
}
doTransferFortron(transferer, machine,
amountToSet - machine.getFortronEnergy(),
limit);
}
}
break;
}
case FILL: {
if (transferer.getFortronEnergy() < transferer.getFortronCapacity()) {
frequencyTiles.remove(transferer);
final int requiredFortron =
transferer.getFortronCapacity() - transferer.getFortronEnergy();
for (final IFortronFrequency machine2 : frequencyTiles) {
if (machine2 != null) {
final int amountToConsume =
Math.min(requiredFortron, machine2.getFortronEnergy());
final int amountToSet =
-machine2.getFortronEnergy() - amountToConsume;
if (amountToConsume <= 0) {
continue;
}
doTransferFortron(transferer, machine2,
amountToSet - machine2.getFortronEnergy(),
limit);
}
}
break;
}
break;
}
}
}
}
}
public static void doTransferFortron(final IFortronFrequency transferer,
final IFortronFrequency receiver,
int joules, final int limit) {
if (transferer != null && receiver != null) {
final TileEntity tileEntity = (TileEntity)transferer;
final World world = tileEntity.getWorldObj();
boolean isCamo = false;
if (transferer instanceof IModuleAcceptor) {
isCamo =
(((IModuleAcceptor)transferer)
.getModuleCount(ModularForceFieldSystem.itemModuleCamouflage,
new int[0]) > 0);
}
if (joules > 0) {
joules = Math.min(joules, limit);
int toBeInjected = receiver.provideFortron(
transferer.requestFortron(joules, false), false);
toBeInjected = transferer.requestFortron(
receiver.provideFortron(toBeInjected, true), true);
if (world.isRemote && toBeInjected > 0 && !isCamo) {
ModularForceFieldSystem.proxy.renderBeam(
world, Vector3.add(new Vector3(tileEntity), 0.5),
Vector3.add(new Vector3((TileEntity)receiver), 0.5), 0.6f, 0.6f,
1.0f, 20);
}
} else {
joules = Math.min(Math.abs(joules), limit);
int toBeEjected = transferer.provideFortron(
receiver.requestFortron(joules, false), false);
toBeEjected = receiver.requestFortron(
transferer.provideFortron(toBeEjected, true), true);
if (world.isRemote && toBeEjected > 0 && !isCamo) {
ModularForceFieldSystem.proxy.renderBeam(
world, Vector3.add(new Vector3((TileEntity)receiver), 0.5),
Vector3.add(new Vector3(tileEntity), 0.5), 0.6f, 0.6f, 1.0f, 20);
}
}
}
}
public static IInterdictionMatrix
getNearestInterdictionMatrix(final World world, final Vector3 position) {
for (final IBlockFrequency frequencyTile : FrequencyGrid.instance().get()) {
if (((TileEntity)frequencyTile).getWorldObj() == world &&
frequencyTile instanceof IInterdictionMatrix) {
final IInterdictionMatrix interdictionMatrix =
(IInterdictionMatrix)frequencyTile;
if (interdictionMatrix.isActive() &&
position.distanceTo(new Vector3((TileEntity)interdictionMatrix)) <=
interdictionMatrix.getActionRange()) {
return interdictionMatrix;
}
continue;
}
}
return null;
}
public static boolean
isPermittedByInterdictionMatrix(final IInterdictionMatrix interdictionMatrix,
final String username,
final Permission... permissions) {
if (interdictionMatrix != null && interdictionMatrix.isActive() &&
interdictionMatrix.getBiometricIdentifier() != null) {
for (final Permission permission : permissions) {
if (!interdictionMatrix.getBiometricIdentifier().isAccessGranted(
username, permission)) {
return interdictionMatrix.getModuleCount(
ModularForceFieldSystem.itemModuleInvert, new int[0]) > 0;
}
}
}
return interdictionMatrix.getModuleCount(
ModularForceFieldSystem.itemModuleInvert, new int[0]) <= 0;
}
public static List<String> splitStringPerWord(final String string,
final int wordsPerLine) {
final String[] words = string.split(" ");
final List<String> lines = new ArrayList<>();
for (int lineCount = 0;
lineCount < Math.ceil(words.length / (float)wordsPerLine);
++lineCount) {
String stringInLine = "";
for (int i = lineCount * wordsPerLine;
i < Math.min(wordsPerLine + lineCount * wordsPerLine, words.length);
++i) {
stringInLine = stringInLine + words[i] + " ";
}
lines.add(stringInLine.trim());
}
return lines;
}
public static ItemStack getFirstItemBlock(final TileEntity tileEntity,
final ItemStack itemStack) {
return getFirstItemBlock(tileEntity, itemStack, true);
}
public static ItemStack getFirstItemBlock(final TileEntity tileEntity,
final ItemStack itemStack,
final boolean recur) {
if (tileEntity instanceof IProjector) {
for (final int i : ((IProjector)tileEntity).getModuleSlots()) {
final ItemStack checkStack =
getFirstItemBlock(i, (IInventory)tileEntity, itemStack);
if (checkStack != null) {
return checkStack;
}
}
} else if (tileEntity instanceof IInventory) {
final IInventory inventory = (IInventory)tileEntity;
for (int j = 0; j < inventory.getSizeInventory(); ++j) {
final ItemStack checkStack2 =
getFirstItemBlock(j, inventory, itemStack);
if (checkStack2 != null) {
return checkStack2;
}
}
}
if (recur) {
for (int k = 0; k < 6; ++k) {
final ForgeDirection direction = ForgeDirection.getOrientation(k);
final Vector3 vector = new Vector3(tileEntity);
vector.modifyPositionFromSide(direction);
final TileEntity checkTile =
vector.getTileEntity((IBlockAccess)tileEntity.getWorldObj());
if (checkTile != null) {
final ItemStack checkStack =
getFirstItemBlock(checkTile, itemStack, false);
if (checkStack != null) {
return checkStack;
}
}
}
}
return null;
}
public static ItemStack getFirstItemBlock(final int i,
final IInventory inventory,
final ItemStack itemStack) {
final ItemStack checkStack = inventory.getStackInSlot(i);
if (checkStack != null && checkStack.getItem() instanceof ItemBlock &&
(itemStack == null || checkStack.isItemEqual(itemStack))) {
return checkStack;
}
return null;
}
public static Block getFilterBlock(final ItemStack itemStack) {
if (itemStack != null && itemStack.getItem() instanceof ItemBlock) {
final Block block = Block.getBlockFromItem(itemStack.getItem());
if (block.renderAsNormalBlock()) {
return block;
}
}
return null;
}
public static ItemStack getCamoBlock(final IProjector projector,
final Vector3 position) {
if (projector != null && !((TileEntity)projector).getWorldObj().isRemote &&
projector != null &&
projector.getModuleCount(ModularForceFieldSystem.itemModuleCamouflage,
new int[0]) > 0) {
if (projector.getMode() instanceof ItemModeCustom) {
final HashMap<Vector3, int[]> fieldMap =
((ItemModeCustom)projector.getMode())
.getFieldBlockMap(projector, projector.getModeStack());
if (fieldMap != null) {
final Vector3 fieldCenter = new Vector3((TileEntity)projector)
.add(projector.getTranslation());
final Vector3 relativePosition =
position.clone().subtract(fieldCenter);
CalculationHelper.rotateByAngle(relativePosition,
-projector.getRotationYaw(),
-projector.getRotationPitch());
final int[] blockInfo = fieldMap.get(relativePosition.round());
if (blockInfo != null && blockInfo[0] > 0) {
return new ItemStack(Block.getBlockById(blockInfo[0]), 1,
blockInfo[1]);
}
}
}
for (final int i : projector.getModuleSlots()) {
final ItemStack checkStack = projector.getStackInSlot(i);
final Block block = getFilterBlock(checkStack);
if (block != null) {
return checkStack;
}
}
}
return null;
}
public static NBTTagCompound getNBTTagCompound(final ItemStack itemStack) {
if (itemStack != null) {
if (itemStack.getTagCompound() == null) {
itemStack.setTagCompound(new NBTTagCompound());
}
return itemStack.getTagCompound();
}
return null;
}
public static boolean hasPermission(final World world, final Vector3 position,
final Permission permission,
final EntityPlayer player) {
final IInterdictionMatrix interdictionMatrix =
getNearestInterdictionMatrix(world, position);
return interdictionMatrix == null ||
isPermittedByInterdictionMatrix(interdictionMatrix,
player.getDisplayName(), permission);
}
public static boolean hasPermission(final World world, final Vector3 position,
final PlayerInteractEvent.Action action,
final EntityPlayer player) {
final IInterdictionMatrix interdictionMatrix =
getNearestInterdictionMatrix(world, position);
return interdictionMatrix == null ||
hasPermission(world, position, interdictionMatrix, action, player);
}
public static boolean
hasPermission(final World world, final Vector3 position,
final IInterdictionMatrix interdictionMatrix,
final PlayerInteractEvent.Action action,
final EntityPlayer player) {
boolean hasPermission = true;
if (action == PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK &&
position.getTileEntity((IBlockAccess)world) != null &&
interdictionMatrix.getModuleCount(
ModularForceFieldSystem.itemModuleBlockAccess, new int[0]) > 0) {
hasPermission = false;
if (isPermittedByInterdictionMatrix(interdictionMatrix,
player.getDisplayName(),
Permission.BLOCK_ACCESS)) {
hasPermission = true;
}
}
if (hasPermission &&
interdictionMatrix.getModuleCount(
ModularForceFieldSystem.itemModuleBlockAlter, new int[0]) > 0 &&
(player.getCurrentEquippedItem() != null ||
action == PlayerInteractEvent.Action.LEFT_CLICK_BLOCK)) {
hasPermission = false;
if (isPermittedByInterdictionMatrix(interdictionMatrix,
player.getDisplayName(),
Permission.BLOCK_ALTER)) {
hasPermission = true;
}
}
return hasPermission;
}
}

View File

@ -0,0 +1,67 @@
package mffs;
import net.minecraft.block.Block;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.storage.ExtendedBlockStorage;
import universalelectricity.core.vector.Vector3;
public class ManipulatorHelper {
public static void setBlockSneaky(final World world, final Vector3 position,
final Block id, final int metadata,
final TileEntity tileEntity) {
final Chunk chunk = world.getChunkFromChunkCoords(position.intX() >> 4,
position.intZ() >> 4);
final Vector3 chunkPosition = new Vector3(
position.intX() & 0xF, position.intY() & 0xF, position.intZ() & 0xF);
final int heightMapIndex = chunkPosition.intZ() << 4 | chunkPosition.intX();
if (position.intY() >= chunk.precipitationHeightMap[heightMapIndex] - 1) {
chunk.precipitationHeightMap[heightMapIndex] = -999;
}
final int heightMapValue = chunk.heightMap[heightMapIndex];
world.removeTileEntity(position.intX(), position.intY(), position.intZ());
ExtendedBlockStorage extendedBlockStorage =
chunk.getBlockStorageArray()[position.intY() >> 4];
if (extendedBlockStorage == null) {
extendedBlockStorage = new ExtendedBlockStorage(position.intY() >> 4 << 4,
!world.provider.hasNoSky);
chunk.getBlockStorageArray()[position.intY() >> 4] = extendedBlockStorage;
}
extendedBlockStorage.func_150818_a(
chunkPosition.intX(), chunkPosition.intY(), chunkPosition.intZ(), id);
extendedBlockStorage.setExtBlockMetadata(chunkPosition.intX(),
chunkPosition.intY(),
chunkPosition.intZ(), metadata);
if (position.intY() >= heightMapValue) {
chunk.generateSkylightMap();
} else {
if (chunk.func_150808_b(chunkPosition.intX(), position.intY(),
chunkPosition.intZ()) > 0) {
if (position.intY() >= heightMapValue) {
relightBlock(chunk,
Vector3.add(chunkPosition, new Vector3(0.0, 1.0, 0.0)));
}
} else if (position.intY() == heightMapValue - 1) {
relightBlock(chunk, chunkPosition);
}
propagateSkylightOcclusion(chunk, chunkPosition);
}
chunk.isModified = true;
world.func_147451_t(position.intX(), position.intY(), position.intZ());
if (tileEntity != null) {
world.setTileEntity(position.intX(), position.intY(), position.intZ(),
tileEntity);
}
world.markBlockForUpdate(position.intX(), position.intY(), position.intZ());
}
public static void relightBlock(final Chunk chunk, final Vector3 position) {
chunk.relightBlock(position.intX(), position.intY(), position.intZ());
}
public static void propagateSkylightOcclusion(final Chunk chunk,
final Vector3 position) {
chunk.propagateSkylightOcclusion(position.intX(), position.intZ());
}
}

View File

@ -0,0 +1,355 @@
package mffs;
import calclavia.lib.UniversalRecipes;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.ModMetadata;
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.event.FMLServerStartingEvent;
import cpw.mods.fml.common.network.IGuiHandler;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.relauncher.Side;
import java.util.Arrays;
import java.util.logging.Logger;
import mffs.base.BlockBase;
import mffs.base.BlockMachine;
import mffs.base.ItemBase;
import mffs.base.PacketFxs;
import mffs.base.PacketFxsHandler;
import mffs.base.PacketTile;
import mffs.base.PacketTileHandler;
import mffs.block.BlockBiometricIdentifier;
import mffs.block.BlockCoercionDeriver;
import mffs.block.BlockForceField;
import mffs.block.BlockForceFieldProjector;
import mffs.block.BlockForceManipulator;
import mffs.block.BlockFortronCapacitor;
import mffs.block.BlockInterdictionMatrix;
import mffs.card.ItemCard;
import mffs.fortron.FortronHelper;
import mffs.fortron.FrequencyGrid;
import mffs.item.ItemRemoteController;
import mffs.item.card.ItemCardFrequency;
import mffs.item.card.ItemCardID;
import mffs.item.card.ItemCardInfinite;
import mffs.item.card.ItemCardLink;
import mffs.item.mode.ItemMode;
import mffs.item.mode.ItemModeCube;
import mffs.item.mode.ItemModeSphere;
import mffs.item.mode.ItemModeTube;
import mffs.item.module.ItemModule;
import mffs.item.module.interdiction.ItemModuleAntiFriendly;
import mffs.item.module.interdiction.ItemModuleAntiHostile;
import mffs.item.module.interdiction.ItemModuleAntiPersonnel;
import mffs.item.module.interdiction.ItemModuleConfiscate;
import mffs.item.module.interdiction.ItemModuleInterdictionMatrix;
import mffs.item.module.interdiction.ItemModuleWarn;
import mffs.item.module.projector.ItemModeCustom;
import mffs.item.module.projector.ItemModeCylinder;
import mffs.item.module.projector.ItemModePyramid;
import mffs.item.module.projector.ItemModuleDisintegration;
import mffs.item.module.projector.ItemModuleFusion;
import mffs.item.module.projector.ItemModuleManipulator;
import mffs.item.module.projector.ItemModuleShock;
import mffs.item.module.projector.ItemModuleSponge;
import mffs.item.module.projector.ItemModuleStablize;
import mffs.tileentity.TileEntityBiometricIdentifier;
import mffs.tileentity.TileEntityCoercionDeriver;
import mffs.tileentity.TileEntityForceField;
import mffs.tileentity.TileEntityForceFieldProjector;
import mffs.tileentity.TileEntityForceManipulator;
import mffs.tileentity.TileEntityFortronCapacitor;
import mffs.tileentity.TileEntityInterdictionMatrix;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.util.DamageSource;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidRegistry;
import universalelectricity.prefab.CustomDamageSource;
import universalelectricity.prefab.TranslationHelper;
@Mod(modid = "MFFS", name = "Modular Force Field System", version = "3.1.0",
useMetadata = true)
public class ModularForceFieldSystem {
public static final String CHANNEL = "MFFS";
public static final String ID = "MFFS";
public static final String NAME = "Modular Force Field System";
public static final String PREFIX = "mffs:";
public static final String MAJOR_VERSION = "3";
public static final String MINOR_VERSION = "1";
public static final String REVISION_VERSION = "0";
public static final String VERSION = "3.1.0";
public static final String BUILD_VERSION = "175";
@Mod.Instance("MFFS") public static ModularForceFieldSystem instance;
@Mod.Metadata("MFFS") public static ModMetadata metadata;
@SidedProxy(clientSide = "mffs.ClientProxy", serverSide = "mffs.CommonProxy")
public static CommonProxy proxy;
public static final Logger LOGGER;
public static final String RESOURCE_DIRECTORY = "/mods/mffs/";
public static final String LANGUAGE_DIRECTORY = "/mods/mffs/languages/";
public static final String TEXTURE_DIRECTORY = "/mods/mffs/textures/";
public static final String BLOCK_DIRECTORY = "/mods/mffs/textures/blocks/";
public static final String ITEM_DIRECTORY = "/mods/mffs/textures/items/";
public static final String MODEL_DIRECTORY = "/mods/mffs/textures/models/";
public static final String GUI_DIRECTORY = "/mods/mffs/textures/gui/";
public static final String GUI_BASE_DIRECTORY =
"/mods/mffs/textures/gui/gui_base.png";
public static final String GUI_COMPONENTS =
"/mods/mffs/textures/gui/gui_components.png";
public static final String GUI_BUTTON =
"/mods/mffs/textures/gui/gui_button.png";
public static BlockMachine blockCoercionDeriver;
public static BlockMachine blockFortronCapacitor;
public static BlockMachine blockForceFieldProjector;
public static BlockMachine blockBiometricIdentifier;
public static BlockMachine blockInterdictionMatrix;
public static BlockMachine blockForceManipulator;
public static BlockBase blockForceField;
public static Item itemRemoteController;
public static Item itemFocusMatrix;
public static ItemCard itemCardBlank;
public static ItemCard itemCardInfinite;
public static ItemCard itemCardFrequency;
public static ItemCard itemCardID;
public static ItemCard itemCardLink;
public static ItemMode itemModeCube;
public static ItemMode itemModeSphere;
public static ItemMode itemModeTube;
public static ItemMode itemModeCylinder;
public static ItemMode itemModePyramid;
public static ItemMode itemModeCustom;
public static ItemModule itemModuleSpeed;
public static ItemModule itemModuleCapacity;
public static ItemModule itemModuleTranslate;
public static ItemModule itemModuleScale;
public static ItemModule itemModuleRotate;
public static ItemModule itemModuleCollection;
public static ItemModule itemModuleInvert;
public static ItemModule itemModuleSilence;
public static ItemModule itemModuleFusion;
public static ItemModule itemModuleManipulator;
public static ItemModule itemModuleCamouflage;
public static ItemModule itemModuleDisintegration;
public static ItemModule itemModuleShock;
public static ItemModule itemModuleGlow;
public static ItemModule itemModuleSponge;
public static ItemModule itemModuleStablize;
public static ItemModule itemModuleAntiHostile;
public static ItemModule itemModuleAntiFriendly;
public static ItemModule itemModuleAntiPersonnel;
public static ItemModule itemModuleConfiscate;
public static ItemModule itemModuleWarn;
public static ItemModule itemModuleBlockAccess;
public static ItemModule itemModuleBlockAlter;
public static ItemModule itemModuleAntiSpawn;
public static DamageSource damagefieldShock;
public static SimpleNetworkWrapper channel;
@EventHandler
public void preInit(final FMLPreInitializationEvent event) {
NetworkRegistry.INSTANCE.registerGuiHandler(
(Object)this, (IGuiHandler)ModularForceFieldSystem.proxy);
MinecraftForge.EVENT_BUS.register((Object) new SubscribeEventHandler());
Settings.load();
Settings.CONFIGURATION.load();
ModularForceFieldSystem.blockForceField = new BlockForceField();
ModularForceFieldSystem.blockCoercionDeriver = new BlockCoercionDeriver();
ModularForceFieldSystem.blockFortronCapacitor = new BlockFortronCapacitor();
ModularForceFieldSystem.blockForceFieldProjector =
new BlockForceFieldProjector();
ModularForceFieldSystem.blockBiometricIdentifier =
new BlockBiometricIdentifier();
ModularForceFieldSystem.blockInterdictionMatrix =
new BlockInterdictionMatrix();
ModularForceFieldSystem.blockForceManipulator = new BlockForceManipulator();
ModularForceFieldSystem.itemRemoteController = new ItemRemoteController();
ModularForceFieldSystem.itemFocusMatrix = new ItemBase("focusMatrix");
ModularForceFieldSystem.itemModeCube =
new ItemModeCube(Settings.getNextItemID());
ModularForceFieldSystem.itemModeSphere =
new ItemModeSphere(Settings.getNextItemID());
ModularForceFieldSystem.itemModeTube = new ItemModeTube();
ModularForceFieldSystem.itemModePyramid = new ItemModePyramid();
ModularForceFieldSystem.itemModeCylinder = new ItemModeCylinder();
ModularForceFieldSystem.itemModeCustom = new ItemModeCustom();
ModularForceFieldSystem.itemModuleTranslate =
new ItemModule("moduleTranslate").setCost(1.6f);
ModularForceFieldSystem.itemModuleScale =
new ItemModule("moduleScale").setCost(1.2f);
ModularForceFieldSystem.itemModuleRotate =
new ItemModule("moduleRotate").setCost(0.1f);
ModularForceFieldSystem.itemModuleSpeed =
new ItemModule("moduleSpeed").setCost(1.0f);
ModularForceFieldSystem.itemModuleCapacity =
new ItemModule("moduleCapacity").setCost(0.5f);
ModularForceFieldSystem.itemModuleFusion = new ItemModuleFusion();
ModularForceFieldSystem.itemModuleManipulator = new ItemModuleManipulator();
ModularForceFieldSystem.itemModuleCamouflage =
new ItemModule("moduleCamouflage").setCost(1.5f).setMaxStackSize(1);
ModularForceFieldSystem.itemModuleDisintegration =
new ItemModuleDisintegration();
ModularForceFieldSystem.itemModuleShock = new ItemModuleShock();
ModularForceFieldSystem.itemModuleGlow = new ItemModule("moduleGlow");
ModularForceFieldSystem.itemModuleSponge = new ItemModuleSponge();
ModularForceFieldSystem.itemModuleStablize = new ItemModuleStablize();
ModularForceFieldSystem.itemModuleAntiFriendly =
new ItemModuleAntiFriendly();
ModularForceFieldSystem.itemModuleAntiHostile = new ItemModuleAntiHostile();
ModularForceFieldSystem.itemModuleAntiPersonnel =
new ItemModuleAntiPersonnel();
ModularForceFieldSystem.itemModuleConfiscate = new ItemModuleConfiscate();
ModularForceFieldSystem.itemModuleWarn = new ItemModuleWarn();
ModularForceFieldSystem.itemModuleBlockAccess =
new ItemModuleInterdictionMatrix("moduleBlockAccess").setCost(10.0f);
ModularForceFieldSystem.itemModuleBlockAlter =
new ItemModuleInterdictionMatrix("moduleBlockAlter").setCost(15.0f);
ModularForceFieldSystem.itemModuleAntiSpawn =
new ItemModuleInterdictionMatrix("moduleAntiSpawn").setCost(10.0f);
ModularForceFieldSystem.itemCardBlank = new ItemCard("cardBlank");
ModularForceFieldSystem.itemCardFrequency = new ItemCardFrequency();
ModularForceFieldSystem.itemCardLink = new ItemCardLink();
ModularForceFieldSystem.itemCardID = new ItemCardID();
ModularForceFieldSystem.itemCardInfinite = new ItemCardInfinite();
FortronHelper.FLUID_FORTRON = new Fluid("fortron");
ModularForceFieldSystem.itemModuleCollection =
new ItemModule("moduleCollection").setMaxStackSize(1).setCost(15.0f);
ModularForceFieldSystem.itemModuleInvert =
new ItemModule("moduleInvert").setMaxStackSize(1).setCost(15.0f);
ModularForceFieldSystem.itemModuleSilence =
new ItemModule("moduleSilence").setMaxStackSize(1).setCost(1.0f);
Settings.CONFIGURATION.save();
GameRegistry.registerBlock((Block)ModularForceFieldSystem.blockForceField,
"blockForceField");
GameRegistry.registerBlock(
(Block)ModularForceFieldSystem.blockCoercionDeriver,
"blockCoercionDeriver");
GameRegistry.registerBlock(
(Block)ModularForceFieldSystem.blockFortronCapacitor,
"blockFortronCapacitor");
GameRegistry.registerBlock(
(Block)ModularForceFieldSystem.blockForceFieldProjector,
"blockForceFieldProjector");
GameRegistry.registerBlock(
(Block)ModularForceFieldSystem.blockBiometricIdentifier,
"blockBiometricIdentifier");
GameRegistry.registerBlock(
(Block)ModularForceFieldSystem.blockInterdictionMatrix,
"blockInterdictionMatrix");
GameRegistry.registerBlock(
(Block)ModularForceFieldSystem.blockForceManipulator,
"blockForceManipulator"
);
GameRegistry.registerTileEntity(TileEntityForceField.class,
"tileForceField");
GameRegistry.registerTileEntity(TileEntityCoercionDeriver.class,
"tileCoercionDeriver");
GameRegistry.registerTileEntity(TileEntityFortronCapacitor.class,
"tileFortronCapacitor");
GameRegistry.registerTileEntity(TileEntityForceFieldProjector.class,
"tileForceFieldProjector");
GameRegistry.registerTileEntity(TileEntityBiometricIdentifier.class,
"tileBiometricIdentifier");
GameRegistry.registerTileEntity(TileEntityInterdictionMatrix.class,
"tileInterdictionMatrix");
GameRegistry.registerTileEntity(TileEntityForceManipulator.class,
"tileForceManipulator");
ModularForceFieldSystem.proxy.preInit();
FluidRegistry.registerFluid(FortronHelper.FLUID_FORTRON);
GameRegistry.registerItem(itemRemoteController, "itemRemoteController");
GameRegistry.registerItem(itemFocusMatrix, "itemFocusMatix");
GameRegistry.registerItem(itemCardBlank, "itemCardBlank");
GameRegistry.registerItem(itemCardInfinite, "itemCardInfinite");
GameRegistry.registerItem(itemCardFrequency, "itemCardFrequency");
GameRegistry.registerItem(itemCardID, "itemCardID");
GameRegistry.registerItem(itemCardLink, "itemCardLink");
GameRegistry.registerItem(itemModeCube, "itemModeCube");
GameRegistry.registerItem(itemModeSphere, "itemModeSphere");
GameRegistry.registerItem(itemModeTube, "itemModeTube");
GameRegistry.registerItem(itemModeCylinder, "itemModeCylinder");
GameRegistry.registerItem(itemModePyramid, "itemModePyramid");
GameRegistry.registerItem(itemModeCustom, "itemModeCustom");
GameRegistry.registerItem(itemModuleSpeed, "itemModuleSpeed");
GameRegistry.registerItem(itemModuleCapacity, "itemModuleCapacity");
GameRegistry.registerItem(itemModuleTranslate, "itemModuleTranslate");
GameRegistry.registerItem(itemModuleScale, "itemModuleScale");
GameRegistry.registerItem(itemModuleRotate, "itemModuleRotate");
GameRegistry.registerItem(itemModuleCollection, "itemModuleCollection");
GameRegistry.registerItem(itemModuleInvert, "itemModuleInvert");
GameRegistry.registerItem(itemModuleSilence, "itemModuleSilence");
GameRegistry.registerItem(itemModuleFusion, "itemModuleFusion");
GameRegistry.registerItem(itemModuleManipulator, "itemModuleManipulator");
GameRegistry.registerItem(itemModuleCamouflage, "itemModuleCamouflage");
GameRegistry.registerItem(itemModuleDisintegration,
"itemModuleDisintegration");
GameRegistry.registerItem(itemModuleShock, "itemModuleShock");
GameRegistry.registerItem(itemModuleGlow, "itemModuleGlow");
GameRegistry.registerItem(itemModuleSponge, "itemModuleSponge");
GameRegistry.registerItem(itemModuleStablize, "itemModuleStablize");
GameRegistry.registerItem(itemModuleAntiHostile, "itemModuleAntiHostile");
GameRegistry.registerItem(itemModuleAntiFriendly, "itemModuleAntiFriendly");
GameRegistry.registerItem(itemModuleAntiPersonnel,
"itemModuleAntiPersonnel");
GameRegistry.registerItem(itemModuleConfiscate, "itemModuleConfiscate");
GameRegistry.registerItem(itemModuleWarn, "itemModuleWarn");
GameRegistry.registerItem(itemModuleBlockAccess, "itemModuleBlockAccess");
GameRegistry.registerItem(itemModuleBlockAlter, "itemModuleBlockAlter");
GameRegistry.registerItem(itemModuleAntiSpawn, "itemModuleAntiSpawn");
channel =
NetworkRegistry.INSTANCE.newSimpleChannel("ModularForceFieldSystem");
int pkgDiscriminator = 0;
channel.registerMessage(PacketTileHandler.class, PacketTile.class,
pkgDiscriminator++, Side.SERVER);
channel.registerMessage(PacketFxsHandler.class, PacketFxs.class,
pkgDiscriminator++, Side.CLIENT);
}
@EventHandler
public void load(final FMLInitializationEvent evt) {
ModularForceFieldSystem.LOGGER.fine(
"Language(s) Loaded: " +
TranslationHelper.loadLanguages(
"/assets/mffs/lang/", new String[] {"en_US", "zh_CN", "de_DE"}));
ModularForceFieldSystem.metadata.modId = "MFFS";
ModularForceFieldSystem.metadata.name = "Modular Force Field System";
ModularForceFieldSystem.metadata.description =
"Modular Force Field System is a mod that adds force fields, high tech machinery and defensive measures to Minecraft.";
ModularForceFieldSystem.metadata.url =
"http://www.universalelectricity.com/mffs/";
ModularForceFieldSystem.metadata.logoFile = "/mffs_logo.png";
ModularForceFieldSystem.metadata.version = "3.1.0.175";
ModularForceFieldSystem.metadata.authorList = Arrays.asList("Calclavia");
ModularForceFieldSystem.metadata.credits = "Please visit the website.";
ModularForceFieldSystem.metadata.autogenerated = false;
}
@EventHandler
public void postInit(final FMLPostInitializationEvent evt) {
UniversalRecipes.init();
Recipes.registerRecipes();
ModularForceFieldSystem.proxy.init();
}
@EventHandler
public void serverStarting(final FMLServerStartingEvent evt) {
FrequencyGrid.reinitiate();
}
static {
LOGGER = Logger.getLogger("Modular Force Field System");
ModularForceFieldSystem.damagefieldShock =
new CustomDamageSource("fieldShock").setDamageBypassesArmor();
}
}

View File

@ -0,0 +1,331 @@
package mffs;
import basiccomponents.common.BasicComponents;
import mffs.recipe.RecipeBuilder;
import mffs.recipe.ShapedOreRecipeAdapter;
import mffs.recipe.ShapelessOreRecipeAdapter;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
public class Recipes {
public static void registerRecipes() {
new RecipeBuilder(new ShapedOreRecipeAdapter())
.output(ModularForceFieldSystem.itemFocusMatrix, 9)
.pattern("RMR", "MDM", "RMR")
.ingredient('M', "ingotSteel")
.ingredient('D', Items.diamond)
.ingredient('R', Items.redstone)
.register();
new RecipeBuilder(new ShapedOreRecipeAdapter())
.output(ModularForceFieldSystem.itemRemoteController)
.pattern("WWW", "MCM", "MCM")
.ingredient('W', BasicComponents.blockCopperWire)
.ingredient('M', "ingotSteel")
.ingredient('C', BasicComponents.itemBattery)
.register();
new RecipeBuilder(new ShapedOreRecipeAdapter())
.output(ModularForceFieldSystem.blockCoercionDeriver)
.pattern("M M", "MFM", "MCM")
.ingredient('C', BasicComponents.itemBattery)
.ingredient('M', "ingotSteel")
.ingredient('F', ModularForceFieldSystem.itemFocusMatrix)
.register();
new RecipeBuilder(new ShapedOreRecipeAdapter())
.output(ModularForceFieldSystem.blockFortronCapacitor)
.pattern("MFM", "FCF", "MFM")
.ingredient('C', BasicComponents.itemBattery)
.ingredient('F', ModularForceFieldSystem.itemFocusMatrix)
.ingredient('M', "ingotSteel")
.register();
new RecipeBuilder(new ShapedOreRecipeAdapter())
.output(ModularForceFieldSystem.blockForceFieldProjector)
.pattern(" D ", "FFF", "MCM")
.ingredient('D', Items.diamond)
.ingredient('C', BasicComponents.itemBattery)
.ingredient('F', ModularForceFieldSystem.itemFocusMatrix)
.ingredient('M', "ingotSteel")
.register();
new RecipeBuilder(new ShapedOreRecipeAdapter())
.output(ModularForceFieldSystem.blockBiometricIdentifier)
.pattern("FMF", "MCM", "FMF")
.ingredient('C', ModularForceFieldSystem.itemCardBlank)
.ingredient('M', "ingotSteel")
.ingredient('F', ModularForceFieldSystem.itemFocusMatrix)
.register();
new RecipeBuilder(new ShapedOreRecipeAdapter())
.output(ModularForceFieldSystem.blockInterdictionMatrix)
.pattern("SSS", "FFF", "FEF")
.ingredient('S', ModularForceFieldSystem.itemModuleShock)
.ingredient('E', Blocks.ender_chest)
.ingredient('F', ModularForceFieldSystem.itemFocusMatrix)
.register();
new RecipeBuilder(new ShapedOreRecipeAdapter())
.output(ModularForceFieldSystem.blockForceManipulator)
.pattern("F F", "FMF", "F F")
.ingredient('F', ModularForceFieldSystem.itemFocusMatrix)
.ingredient('M', BasicComponents.itemMotor)
.register();
new RecipeBuilder(new ShapedOreRecipeAdapter())
.output(ModularForceFieldSystem.itemCardBlank)
.pattern("PPP", "PMP", "PPP")
.ingredient('M', "ingotSteel")
.ingredient('P', Items.paper)
.register();
new RecipeBuilder(new ShapedOreRecipeAdapter())
.output(ModularForceFieldSystem.itemCardLink)
.pattern("BWB")
.ingredient('B', ModularForceFieldSystem.itemCardBlank)
.ingredient('W', BasicComponents.blockCopperWire)
.register();
new RecipeBuilder(new ShapedOreRecipeAdapter())
.output(ModularForceFieldSystem.itemCardLink)
.pattern("WBW")
.ingredient('B', ModularForceFieldSystem.itemCardFrequency)
.ingredient('W', BasicComponents.blockCopperWire)
.register();
new RecipeBuilder(new ShapedOreRecipeAdapter())
.output(ModularForceFieldSystem.itemCardID)
.pattern("RBR")
.ingredient('B', ModularForceFieldSystem.itemCardBlank)
.ingredient('R', Items.redstone)
.register();
new RecipeBuilder(new ShapedOreRecipeAdapter())
.output(ModularForceFieldSystem.itemModeSphere)
.pattern(" F ", "FFF", " F ")
.ingredient('F', ModularForceFieldSystem.itemFocusMatrix)
.register();
new RecipeBuilder(new ShapedOreRecipeAdapter())
.output(ModularForceFieldSystem.itemModeCube)
.pattern("FFF", "FFF", "FFF")
.ingredient('F', ModularForceFieldSystem.itemFocusMatrix)
.register();
new RecipeBuilder(new ShapedOreRecipeAdapter())
.output(ModularForceFieldSystem.itemModeTube)
.pattern("FFF", " ", "FFF")
.ingredient('F', ModularForceFieldSystem.itemFocusMatrix)
.register();
new RecipeBuilder(new ShapedOreRecipeAdapter())
.output(ModularForceFieldSystem.itemModePyramid)
.pattern("F ", "FF ", "FFF")
.ingredient('F', ModularForceFieldSystem.itemFocusMatrix)
.register();
new RecipeBuilder(new ShapedOreRecipeAdapter())
.output(ModularForceFieldSystem.itemModeCylinder)
.pattern("S", "S", "S")
.ingredient('S', ModularForceFieldSystem.itemModeSphere)
.register();
new RecipeBuilder(new ShapedOreRecipeAdapter())
.output(ModularForceFieldSystem.itemModeCustom)
.pattern(" C ", "TFP", " S ")
.ingredient('S', ModularForceFieldSystem.itemModeSphere)
.ingredient('C', ModularForceFieldSystem.itemModeCube)
.ingredient('T', ModularForceFieldSystem.itemModeTube)
.ingredient('P', ModularForceFieldSystem.itemModePyramid)
.ingredient('F', ModularForceFieldSystem.itemFocusMatrix)
.register();
new RecipeBuilder(new ShapelessOreRecipeAdapter())
.output(ModularForceFieldSystem.itemModeCustom)
.ingredient(ModularForceFieldSystem.itemModeCustom)
.register();
new RecipeBuilder(new ShapedOreRecipeAdapter())
.output(ModularForceFieldSystem.itemModuleSpeed)
.pattern("FFF", "RRR", "FFF")
.ingredient('F', ModularForceFieldSystem.itemFocusMatrix)
.ingredient('R', Items.redstone)
.register();
new RecipeBuilder(new ShapedOreRecipeAdapter())
.output(ModularForceFieldSystem.itemModuleCapacity)
.pattern("FCF")
.ingredient('F', ModularForceFieldSystem.itemFocusMatrix)
.ingredient('C', BasicComponents.itemBattery)
.register();
new RecipeBuilder(new ShapedOreRecipeAdapter())
.output(ModularForceFieldSystem.itemModuleShock)
.pattern("FWF")
.ingredient('F', ModularForceFieldSystem.itemFocusMatrix)
.ingredient('W', BasicComponents.blockCopperWire)
.register();
new RecipeBuilder(new ShapedOreRecipeAdapter())
.output(ModularForceFieldSystem.itemModuleSponge)
.pattern("BBB", "BFB", "BBB")
.ingredient('F', ModularForceFieldSystem.itemFocusMatrix)
.ingredient('B', Items.water_bucket)
.register();
new RecipeBuilder(new ShapedOreRecipeAdapter())
.output(ModularForceFieldSystem.itemModuleDisintegration)
.pattern(" W ", "FBF", " W ")
.ingredient('F', ModularForceFieldSystem.itemFocusMatrix)
.ingredient('W', BasicComponents.blockCopperWire)
.ingredient('B', BasicComponents.itemBattery)
.register();
new RecipeBuilder(new ShapedOreRecipeAdapter())
.output(ModularForceFieldSystem.itemModuleManipulator)
.pattern("F", " ", "F")
.ingredient('F', ModularForceFieldSystem.itemFocusMatrix)
.register();
new RecipeBuilder(new ShapedOreRecipeAdapter())
.output(ModularForceFieldSystem.itemModuleCamouflage)
.pattern("WFW", "FWF", "WFW")
.ingredient('F', ModularForceFieldSystem.itemFocusMatrix)
.ingredient('W', new ItemStack(Blocks.wool, 1, 32767))
.register();
new RecipeBuilder(new ShapedOreRecipeAdapter())
.output(ModularForceFieldSystem.itemModuleFusion)
.pattern("FJF")
.ingredient('F', ModularForceFieldSystem.itemFocusMatrix)
.ingredient('J', ModularForceFieldSystem.itemModuleShock)
.register();
new RecipeBuilder(new ShapedOreRecipeAdapter())
.output(ModularForceFieldSystem.itemModuleScale, 2)
.pattern("FRF")
.ingredient('F', ModularForceFieldSystem.itemFocusMatrix)
.ingredient(
'R',
Items.redstone) // this is a guess, R isnt defined in the original
.register();
new RecipeBuilder(new ShapedOreRecipeAdapter())
.output(ModularForceFieldSystem.itemModuleTranslate, 2)
.pattern("FSF")
.ingredient('F', ModularForceFieldSystem.itemFocusMatrix)
.ingredient('S', ModularForceFieldSystem.itemModuleScale)
.register();
new RecipeBuilder(new ShapedOreRecipeAdapter())
.output(ModularForceFieldSystem.itemModuleRotate)
.pattern("F ", " F", " F")
.ingredient('F', ModularForceFieldSystem.itemFocusMatrix)
.register();
new RecipeBuilder(new ShapedOreRecipeAdapter())
.output(ModularForceFieldSystem.itemModuleGlow)
.pattern("GGG", "GFG", "GGG")
.ingredient('F', ModularForceFieldSystem.itemFocusMatrix)
.ingredient('G', Blocks.glowstone)
.register();
new RecipeBuilder(new ShapedOreRecipeAdapter())
.output(ModularForceFieldSystem.itemModuleStablize)
.pattern("FDF", "PSA", "FDF")
.ingredient('F', ModularForceFieldSystem.itemFocusMatrix)
.ingredient('P', Items.diamond_pickaxe)
.ingredient('S', Items.diamond_shovel)
.ingredient('A', Items.diamond_axe)
.register();
new RecipeBuilder(new ShapedOreRecipeAdapter())
.output(ModularForceFieldSystem.itemModuleCollection)
.pattern("F F", " H ", "F F")
.ingredient('F', ModularForceFieldSystem.itemFocusMatrix)
.ingredient('H', Blocks.hopper)
.register();
new RecipeBuilder(new ShapedOreRecipeAdapter())
.output(ModularForceFieldSystem.itemModuleInvert)
.pattern("L", "F", "L")
.ingredient('F', ModularForceFieldSystem.itemFocusMatrix)
.ingredient('L', Blocks.lapis_block)
.register();
new RecipeBuilder(new ShapedOreRecipeAdapter())
.output(ModularForceFieldSystem.itemModuleSilence)
.pattern(" N ", "NFN", " N ")
.ingredient('F', ModularForceFieldSystem.itemFocusMatrix)
.ingredient('N', Blocks.noteblock)
.register();
new RecipeBuilder(new ShapedOreRecipeAdapter())
.output(ModularForceFieldSystem.itemModuleAntiHostile)
.pattern(" R ", "GFB", " S ")
.ingredient('F', ModularForceFieldSystem.itemFocusMatrix)
.ingredient('G', Items.gunpowder)
.ingredient('R', Items.rotten_flesh)
.ingredient('B', Items.bone)
.ingredient('S', Items.ghast_tear)
.register();
new RecipeBuilder(new ShapedOreRecipeAdapter())
.output(ModularForceFieldSystem.itemModuleAntiFriendly)
.pattern(" R ", "GFB", " S ")
.ingredient('F', ModularForceFieldSystem.itemFocusMatrix)
.ingredient('G', Items.cooked_porkchop)
.ingredient('R', new ItemStack(Blocks.wool, 1, 32767))
.ingredient('B', Items.leather)
.ingredient('S', Items.slime_ball)
.register();
new RecipeBuilder(new ShapedOreRecipeAdapter())
.output(ModularForceFieldSystem.itemModuleAntiPersonnel)
.pattern("BFG")
.ingredient('F', ModularForceFieldSystem.itemFocusMatrix)
.ingredient('B', ModularForceFieldSystem.itemModuleAntiHostile)
.ingredient('G', ModularForceFieldSystem.itemModuleAntiFriendly)
.register();
// TODO: config option for confiscate module
new RecipeBuilder(new ShapedOreRecipeAdapter())
.output(ModularForceFieldSystem.itemModuleConfiscate)
.pattern("PEP", "EFE", "PEP")
.ingredient('F', ModularForceFieldSystem.itemFocusMatrix)
.ingredient('E', Items.ender_eye)
.ingredient('P', Items.ender_pearl)
.register();
new RecipeBuilder(new ShapedOreRecipeAdapter())
.output(ModularForceFieldSystem.itemModuleWarn)
.pattern("NFN")
.ingredient('F', ModularForceFieldSystem.itemFocusMatrix)
.ingredient('N', Blocks.noteblock)
.register();
new RecipeBuilder(new ShapedOreRecipeAdapter())
.output(ModularForceFieldSystem.itemModuleBlockAccess)
.pattern(" C ", "BFB", " C ")
.ingredient('F', ModularForceFieldSystem.itemFocusMatrix)
.ingredient('B', Blocks.iron_block)
.ingredient('C', Blocks.chest)
.register();
new RecipeBuilder(new ShapedOreRecipeAdapter())
.output(ModularForceFieldSystem.itemModuleBlockAlter)
.pattern(" G ", "GFG", " G ")
.ingredient('F', ModularForceFieldSystem.itemFocusMatrix)
.ingredient('G', Blocks.gold_block)
.register();
new RecipeBuilder(new ShapedOreRecipeAdapter())
.output(ModularForceFieldSystem.itemModuleAntiSpawn)
.pattern(" H ", "G G", " H ")
.ingredient('H', ModularForceFieldSystem.itemModuleAntiHostile)
.ingredient('G', ModularForceFieldSystem.itemModuleAntiFriendly)
.register();
}
}

View File

@ -0,0 +1,176 @@
package mffs;
import cpw.mods.fml.common.Loader;
import java.io.File;
import mffs.api.Blacklist;
import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.common.config.Property;
public class Settings {
public static final Configuration CONFIGURATION;
public static final int BLOCK_ID_PREFIX = 1680;
public static final int ITEM_ID_PREFIX = 11130;
private static int NEXT_BLOCK_ID;
private static int NEXT_ITEM_ID;
public static int MAX_FORCE_FIELDS_PER_TICK;
public static int MAX_FORCE_FIELD_SCALE;
public static boolean INTERACT_CREATIVE;
public static boolean LOAD_CHUNKS;
public static boolean OP_OVERRIDE;
public static boolean USE_CACHE;
public static boolean ENABLE_ELECTRICITY;
public static boolean CONSERVE_PACKETS;
public static boolean HIGH_GRAPHICS;
public static int INTERDICTION_MURDER_ENERGY;
public static final int MAX_FREQUENCY_DIGITS = 6;
public static boolean ENABLE_MANIPULATOR;
public static int getNextBlockID() { return ++Settings.NEXT_BLOCK_ID; }
public static int getNextItemID() { return ++Settings.NEXT_ITEM_ID; }
public static void load() {
Settings.CONFIGURATION.load();
Settings.ENABLE_MANIPULATOR =
Settings.CONFIGURATION
.get("general", "Enable Force Manipulator",
Settings.ENABLE_MANIPULATOR)
.getBoolean(Settings.ENABLE_MANIPULATOR);
final Property propFieldScale = Settings.CONFIGURATION.get(
"general", "Max Force Field Scale", Settings.MAX_FORCE_FIELD_SCALE);
Settings.MAX_FORCE_FIELD_SCALE =
propFieldScale.getInt(Settings.MAX_FORCE_FIELD_SCALE);
final Property propInterdiction = Settings.CONFIGURATION.get(
"general", "Interdiction Murder Fortron Consumption",
Settings.INTERDICTION_MURDER_ENERGY);
Settings.INTERDICTION_MURDER_ENERGY =
propInterdiction.getInt(Settings.INTERDICTION_MURDER_ENERGY);
final Property propCreative = Settings.CONFIGURATION.get(
"general", "Effect Creative Players", Settings.INTERACT_CREATIVE);
propCreative.comment =
"Should the interdiction matrix interact with creative players?.";
Settings.INTERACT_CREATIVE =
propCreative.getBoolean(Settings.INTERACT_CREATIVE);
final Property propChunkLoading = Settings.CONFIGURATION.get(
"general", "Load Chunks", Settings.LOAD_CHUNKS);
propChunkLoading.comment =
"Set this to false to turn off the MFFS Chunkloading capabilities.";
Settings.LOAD_CHUNKS = propChunkLoading.getBoolean(Settings.LOAD_CHUNKS);
final Property propOpOverride = Settings.CONFIGURATION.get(
"general", "Op Override", Settings.OP_OVERRIDE);
propOpOverride.comment =
"Allow the operator(s) to override security measures created by MFFS?";
Settings.OP_OVERRIDE = propOpOverride.getBoolean(Settings.OP_OVERRIDE);
final Property propUseCache =
Settings.CONFIGURATION.get("general", "Use Cache", Settings.USE_CACHE);
propUseCache.comment =
"Cache allows temporary data saving to decrease calculations required.";
Settings.USE_CACHE = propUseCache.getBoolean(Settings.USE_CACHE);
final Property maxFFGenPerTick =
Settings.CONFIGURATION.get("general", "Field Calculation Per Tick",
Settings.MAX_FORCE_FIELDS_PER_TICK);
maxFFGenPerTick.comment =
"How many force field blocks can be generated per tick? Less reduces lag.";
Settings.MAX_FORCE_FIELDS_PER_TICK =
maxFFGenPerTick.getInt(Settings.MAX_FORCE_FIELDS_PER_TICK);
final Property useElectricity = Settings.CONFIGURATION.get(
"general", "Require Electricity?", Settings.ENABLE_ELECTRICITY);
useElectricity.comment =
"Turning this to false will make MFFS run without electricity or energy systems required. Great for vanilla!";
Settings.ENABLE_ELECTRICITY =
useElectricity.getBoolean(Settings.ENABLE_ELECTRICITY);
final Property conservePackets = Settings.CONFIGURATION.get(
"general", "Conserve Packets?", Settings.CONSERVE_PACKETS);
conservePackets.comment =
"Turning this to false will enable better client side packet and updates but in the cost of more packets sent.";
Settings.CONSERVE_PACKETS =
conservePackets.getBoolean(Settings.CONSERVE_PACKETS);
final Property highGraphics = Settings.CONFIGURATION.get(
"general", "High Graphics", Settings.HIGH_GRAPHICS);
highGraphics.comment =
"Turning this to false will reduce rendering and client side packet graphical packets.";
Settings.CONSERVE_PACKETS = highGraphics.getBoolean(Settings.HIGH_GRAPHICS);
final Property forceManipulatorBlacklist = Settings.CONFIGURATION.get(
"general", "Force Manipulator Blacklist", "");
highGraphics.comment =
"Put a list of block IDs to be not-moved by the force manipulator. Separate by commas, no space.";
final String blackListString = forceManipulatorBlacklist.getString();
if (blackListString != null) {
for (final String blockIDString : blackListString.split(",")) {
Block b = Block.getBlockFromName(blockIDString);
if (b == null) {
ModularForceFieldSystem.LOGGER.severe(
"Invalid block blacklist ID \'" + blockIDString + "\'!");
continue;
}
Blacklist.forceManipulationBlacklist.add(b);
}
}
final Property blacklist1 =
Settings.CONFIGURATION.get("general", "Stabilization Blacklist", "");
final String blackListString2 = blacklist1.getString();
if (blackListString2 != null) {
for (final String blockIDString2 : blackListString2.split(",")) {
Block b = Block.getBlockFromName(blockIDString2);
if (b == null) {
ModularForceFieldSystem.LOGGER.severe(
"Invalid block blacklist ID \'" + blockIDString2 + "\'!");
continue;
}
Blacklist.stabilizationBlacklist.add(b);
}
}
final Property blacklist2 =
Settings.CONFIGURATION.get("general", "Disintegration Blacklist", "");
final String blackListString3 = blacklist2.getString();
if (blackListString3 != null) {
for (final String blockIDString3 : blackListString3.split(",")) {
if (blockIDString3 != null && !blockIDString3.isEmpty()) {
Block b = Block.getBlockFromName(blockIDString3);
if (b == null) {
ModularForceFieldSystem.LOGGER.severe(
"Invalid block blacklist ID \'" + blockIDString3 + "\'!");
continue;
}
Blacklist.disintegrationBlacklist.add(b);
}
}
}
Blacklist.stabilizationBlacklist.add(Blocks.water);
Blacklist.stabilizationBlacklist.add(Blocks.flowing_water);
Blacklist.stabilizationBlacklist.add(Blocks.lava);
Blacklist.stabilizationBlacklist.add(Blocks.flowing_lava);
Blacklist.disintegrationBlacklist.add(Blocks.water);
Blacklist.disintegrationBlacklist.add(Blocks.flowing_water);
Blacklist.disintegrationBlacklist.add(Blocks.lava);
Blacklist.stabilizationBlacklist.add(Blocks.flowing_lava);
Blacklist.forceManipulationBlacklist.add(Blocks.bedrock);
Blacklist.forceManipulationBlacklist.add(
ModularForceFieldSystem.blockForceField);
Settings.CONFIGURATION.save();
}
static {
CONFIGURATION = new Configuration(new File(
Loader.instance().getConfigDir(), "Modular Force Field System.cfg"));
Settings.NEXT_BLOCK_ID = 1680;
Settings.NEXT_ITEM_ID = 11130;
Settings.MAX_FORCE_FIELDS_PER_TICK = 1000;
Settings.MAX_FORCE_FIELD_SCALE = 200;
Settings.INTERACT_CREATIVE = true;
Settings.LOAD_CHUNKS = true;
Settings.OP_OVERRIDE = true;
Settings.USE_CACHE = true;
Settings.ENABLE_ELECTRICITY = true;
Settings.CONSERVE_PACKETS = true;
Settings.HIGH_GRAPHICS = true;
Settings.INTERDICTION_MURDER_ENERGY = 0;
Settings.ENABLE_MANIPULATOR = true;
}
}

View File

@ -0,0 +1,86 @@
package mffs;
import cpw.mods.fml.common.eventhandler.Event.Result;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import mffs.api.security.IInterdictionMatrix;
import mffs.api.security.Permission;
import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
import net.minecraft.util.ChatComponentText;
import net.minecraft.world.IBlockAccess;
import net.minecraftforge.client.event.TextureStitchEvent;
import net.minecraftforge.event.entity.living.LivingSpawnEvent;
import net.minecraftforge.event.entity.player.PlayerEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.fluids.FluidRegistry;
import universalelectricity.core.vector.Vector3;
public class SubscribeEventHandler {
@SubscribeEvent
@SideOnly(Side.CLIENT)
public void textureHook(final TextureStitchEvent.Pre event) {
if (event.map.getTextureType() == 1) {
FluidRegistry.getFluid("fortron").setIcons(
event.map.registerIcon("mffs:fortron"));
}
}
@SubscribeEvent
public void playerInteractEvent(final PlayerInteractEvent evt) {
if (evt.action == PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK ||
evt.action == PlayerInteractEvent.Action.LEFT_CLICK_BLOCK) {
if (evt.action == PlayerInteractEvent.Action.LEFT_CLICK_BLOCK &&
((Entity)((PlayerEvent)evt).entityPlayer)
.worldObj.getBlock(evt.x, evt.y, evt.z) ==
ModularForceFieldSystem.blockForceField) {
evt.setCanceled(true);
return;
}
if (((PlayerEvent)evt).entityPlayer.capabilities.isCreativeMode) {
return;
}
final Vector3 position = new Vector3(evt.x, evt.y, evt.z);
final IInterdictionMatrix interdictionMatrix =
MFFSHelper.getNearestInterdictionMatrix(
((Entity)((PlayerEvent)evt).entityPlayer).worldObj, position);
if (interdictionMatrix != null) {
final Block block = position.getBlock(
(IBlockAccess)((Entity)((PlayerEvent)evt).entityPlayer).worldObj);
if (ModularForceFieldSystem.blockBiometricIdentifier == block &&
MFFSHelper.isPermittedByInterdictionMatrix(
interdictionMatrix,
((PlayerEvent)evt).entityPlayer.getDisplayName(),
Permission.SECURITY_CENTER_CONFIGURE)) {
return;
}
final boolean hasPermission = MFFSHelper.hasPermission(
((Entity)((PlayerEvent)evt).entityPlayer).worldObj,
new Vector3(evt.x, evt.y, evt.z), interdictionMatrix, evt.action,
((PlayerEvent)evt).entityPlayer);
if (!hasPermission) {
((PlayerEvent)evt)
.entityPlayer.addChatMessage(new ChatComponentText(
"[" +
ModularForceFieldSystem.blockInterdictionMatrix
.getLocalizedName() +
"] You have no permission to do that!"));
evt.setCanceled(true);
}
}
}
}
@SubscribeEvent
public void livingSpawnEvent(final LivingSpawnEvent evt) {
final IInterdictionMatrix interdictionMatrix =
MFFSHelper.getNearestInterdictionMatrix(
evt.world, new Vector3((Entity)evt.entityLiving));
if (interdictionMatrix != null &&
interdictionMatrix.getModuleCount(
ModularForceFieldSystem.itemModuleAntiSpawn, new int[0]) > 0) {
evt.setResult(Result.DENY);
}
}
}

View File

@ -0,0 +1,16 @@
package mffs;
public enum TransferMode {
EQUALIZE,
DISTRIBUTE,
DRAIN,
FILL;
public TransferMode toggle() {
int newOrdinal = this.ordinal() + 1;
if (newOrdinal >= values().length) {
newOrdinal = 0;
}
return values()[newOrdinal];
}
}

View File

@ -0,0 +1,19 @@
package mffs.api;
import java.util.HashSet;
import java.util.Set;
import net.minecraft.block.Block;
public class Blacklist
{
public static final Set<Block> stabilizationBlacklist;
public static final Set<Block> disintegrationBlacklist;
public static final Set<Block> forceManipulationBlacklist;
static {
stabilizationBlacklist = new HashSet<>();
disintegrationBlacklist = new HashSet<>();
forceManipulationBlacklist = new HashSet<>();
}
}

View File

@ -0,0 +1,8 @@
package mffs.api;
public interface IActivatable
{
boolean isActive();
void setActive(final boolean p0);
}

View File

@ -0,0 +1,11 @@
package mffs.api;
import java.util.Set;
import mffs.api.security.IBiometricIdentifier;
public interface IBiometricIdentifierLink
{
IBiometricIdentifier getBiometricIdentifier();
Set<IBiometricIdentifier> getBiometricIdentifiers();
}

View File

@ -0,0 +1,10 @@
package mffs.api;
public interface ICache
{
Object getCache(final String p0);
void clearCache(final String p0);
void clearCache();
}

View File

@ -0,0 +1,41 @@
package mffs.api;
import java.util.Set;
import universalelectricity.core.vector.Vector3;
import mffs.api.modules.IModule;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.util.ForgeDirection;
import mffs.api.modules.IProjectorMode;
import universalelectricity.prefab.implement.IRotatable;
import mffs.api.modules.IModuleAcceptor;
public interface IFieldInteraction extends IModuleAcceptor, IRotatable, IActivatable
{
IProjectorMode getMode();
ItemStack getModeStack();
int[] getSlotsBasedOnDirection(final ForgeDirection p0);
int[] getModuleSlots();
int getSidedModuleCount(final IModule p0, final ForgeDirection... p1);
Vector3 getTranslation();
Vector3 getPositiveScale();
Vector3 getNegativeScale();
int getRotationYaw();
int getRotationPitch();
Set<Vector3> getCalculatedField();
Set<Vector3> getInteriorPoints();
void setCalculating(final boolean p0);
void setCalculated(final boolean p0);
}

View File

@ -0,0 +1,11 @@
package mffs.api;
import net.minecraft.world.World;
import net.minecraft.world.IBlockAccess;
public interface IForceFieldBlock
{
IProjector getProjector(final IBlockAccess p0, final int p1, final int p2, final int p3);
void weakenForceField(final World p0, final int p1, final int p2, final int p3, final int p4);
}

View File

@ -0,0 +1,14 @@
package mffs.api;
import net.minecraft.inventory.IInventory;
public interface IProjector extends IInventory, IBiometricIdentifierLink, IFieldInteraction
{
void projectField();
void destroyField();
int getProjectionSpeed();
long getTicks();
}

View File

@ -0,0 +1,10 @@
package mffs.api;
public interface ISpecialForceManipulation
{
boolean preMove(final int p0, final int p1, final int p2);
void move(final int p0, final int p1, final int p2);
void postMove();
}

View File

@ -0,0 +1,5 @@
package mffs.api.card;
public interface ICard
{
}

View File

@ -0,0 +1,17 @@
package mffs.api.card;
import mffs.api.security.Permission;
import net.minecraft.item.ItemStack;
public interface ICardIdentification extends ICard
{
boolean hasPermission(final ItemStack p0, final Permission p1);
boolean addPermission(final ItemStack p0, final Permission p1);
boolean removePermission(final ItemStack p0, final Permission p1);
String getUsername(final ItemStack p0);
void setUsername(final ItemStack p0, final String p1);
}

View File

@ -0,0 +1,5 @@
package mffs.api.card;
public interface ICardInfinite
{
}

View File

@ -0,0 +1,11 @@
package mffs.api.card;
import universalelectricity.core.vector.Vector3;
import net.minecraft.item.ItemStack;
public interface ICardLink
{
void setLink(final ItemStack p0, final Vector3 p1);
Vector3 getLink(final ItemStack p0);
}

View File

@ -0,0 +1,12 @@
package mffs.api.fortron;
import java.util.Set;
public interface IFortronCapacitor
{
Set<IFortronFrequency> getLinkedDevices();
int getTransmissionRange();
int getTransmissionRate();
}

View File

@ -0,0 +1,7 @@
package mffs.api.fortron;
import icbm.api.IBlockFrequency;
public interface IFortronFrequency extends IFortronStorage, IBlockFrequency
{
}

View File

@ -0,0 +1,14 @@
package mffs.api.fortron;
public interface IFortronStorage
{
void setFortronEnergy(final int p0);
int getFortronEnergy();
int getFortronCapacity();
int requestFortron(final int p0, final boolean p1);
int provideFortron(final int p0, final boolean p1);
}

View File

@ -0,0 +1,9 @@
package mffs.api.modules;
import mffs.api.security.IInterdictionMatrix;
import net.minecraft.entity.EntityLivingBase;
public interface IInterdictionMatrixModule extends IModule
{
boolean onDefend(final IInterdictionMatrix p0, final EntityLivingBase p1);
}

View File

@ -0,0 +1,22 @@
package mffs.api.modules;
import mffs.api.IFieldInteraction;
import net.minecraft.item.ItemStack;
import net.minecraft.entity.Entity;
import net.minecraft.world.World;
import universalelectricity.core.vector.Vector3;
import java.util.Set;
import mffs.api.IProjector;
public interface IModule
{
float getFortronCost(final float p0);
boolean onProject(final IProjector p0, final Set<Vector3> fieldBlocks);
int onProject(final IProjector p0, final Vector3 p1);
boolean onCollideWithForceField(final World p0, final int p1, final int p2, final int p3, final Entity p4, final ItemStack p5);
void onCalculate(final IFieldInteraction p0, final Set<Vector3> fieldBlocks);
}

View File

@ -0,0 +1,17 @@
package mffs.api.modules;
import java.util.Set;
import net.minecraft.item.ItemStack;
public interface IModuleAcceptor
{
ItemStack getModule(final IModule p0);
int getModuleCount(final IModule p0, final int... p1);
Set<ItemStack> getModuleStacks(final int... p0);
Set<IModule> getModules(final int... p0);
int getFortronCost();
}

View File

@ -0,0 +1,17 @@
package mffs.api.modules;
import java.util.Set;
import mffs.api.IFieldInteraction;
import mffs.api.IProjector;
import universalelectricity.core.vector.Vector3;
public interface IProjectorMode {
Set<Vector3> getExteriorPoints(final IFieldInteraction p0);
Set<Vector3> getInteriorPoints(final IFieldInteraction p0);
boolean isInField(final IFieldInteraction p0, final Vector3 p1);
void render(final IProjector p0, final double p1, final double p2,
final double p3, final float p4, final long p5);
}

View File

@ -0,0 +1,12 @@
package mffs.api.security;
import net.minecraft.item.ItemStack;
public interface IBiometricIdentifier
{
boolean isAccessGranted(final String p0, final Permission p1);
String getOwner();
ItemStack getManipulatingCard();
}

View File

@ -0,0 +1,24 @@
package mffs.api.security;
import java.util.Set;
import net.minecraft.item.ItemStack;
import mffs.api.IActivatable;
import mffs.api.IBiometricIdentifierLink;
import mffs.api.modules.IModuleAcceptor;
import mffs.api.fortron.IFortronFrequency;
import net.minecraft.inventory.IInventory;
public interface IInterdictionMatrix extends IInventory, IFortronFrequency, IModuleAcceptor, IBiometricIdentifierLink, IActivatable
{
int getWarningRange();
int getActionRange();
boolean mergeIntoInventory(final ItemStack p0);
Set<ItemStack> getFilteredItems();
boolean getFilterMode();
int getFortronCost();
}

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