diff --git a/.gitignore b/.gitignore index 8d16946..bbc8ac8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,7 @@ +.project +.classpath +bin +.settings .gradle .idea build diff --git a/build.gradle b/build.gradle index ee53ffc..54d8090 100644 --- a/build.gradle +++ b/build.gradle @@ -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 diff --git a/gradlew b/gradlew old mode 100644 new mode 100755 diff --git a/src/main/java/calclavia/lib/Calclavia.java b/src/main/java/calclavia/lib/Calclavia.java new file mode 100644 index 0000000..ff6b180 --- /dev/null +++ b/src/main/java/calclavia/lib/Calclavia.java @@ -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 splitStringPerWord(String string, int wordsPerLine) { + String[] words = string.split(" "); + ArrayList 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; + } +} diff --git a/src/main/java/calclavia/lib/CalculationHelper.java b/src/main/java/calclavia/lib/CalculationHelper.java new file mode 100644 index 0000000..1748b8b --- /dev/null +++ b/src/main/java/calclavia/lib/CalculationHelper.java @@ -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; + } + } +} diff --git a/src/main/java/calclavia/lib/IPlayerUsing.java b/src/main/java/calclavia/lib/IPlayerUsing.java new file mode 100644 index 0000000..c7681eb --- /dev/null +++ b/src/main/java/calclavia/lib/IPlayerUsing.java @@ -0,0 +1,8 @@ +package calclavia.lib; + +import java.util.HashSet; + +public interface IPlayerUsing { + + HashSet getPlayersUsing(); +} diff --git a/src/main/java/calclavia/lib/IUniversalEnergyTile.java b/src/main/java/calclavia/lib/IUniversalEnergyTile.java new file mode 100644 index 0000000..ed5452c --- /dev/null +++ b/src/main/java/calclavia/lib/IUniversalEnergyTile.java @@ -0,0 +1,7 @@ +package calclavia.lib; + +import universalelectricity.core.block.IConnector; +import universalelectricity.core.block.IVoltage; + +public interface IUniversalEnergyTile extends IConnector, IVoltage { +} diff --git a/src/main/java/calclavia/lib/TileEntityUniversalProducer.java b/src/main/java/calclavia/lib/TileEntityUniversalProducer.java new file mode 100644 index 0000000..e90c0c9 --- /dev/null +++ b/src/main/java/calclavia/lib/TileEntityUniversalProducer.java @@ -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; + } +} diff --git a/src/main/java/calclavia/lib/TileEntityUniversalRunnable.java b/src/main/java/calclavia/lib/TileEntityUniversalRunnable.java new file mode 100644 index 0000000..19387fb --- /dev/null +++ b/src/main/java/calclavia/lib/TileEntityUniversalRunnable.java @@ -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); + } +} diff --git a/src/main/java/calclavia/lib/TileEntityUniversalStorable.java b/src/main/java/calclavia/lib/TileEntityUniversalStorable.java new file mode 100644 index 0000000..a5a1978 --- /dev/null +++ b/src/main/java/calclavia/lib/TileEntityUniversalStorable.java @@ -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); + } +} diff --git a/src/main/java/calclavia/lib/UniversalRecipes.java b/src/main/java/calclavia/lib/UniversalRecipes.java new file mode 100644 index 0000000..198b506 --- /dev/null +++ b/src/main/java/calclavia/lib/UniversalRecipes.java @@ -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)); + } +} diff --git a/src/main/java/calclavia/lib/gui/ContainerBase.java b/src/main/java/calclavia/lib/gui/ContainerBase.java new file mode 100644 index 0000000..d2c20d4 --- /dev/null +++ b/src/main/java/calclavia/lib/gui/ContainerBase.java @@ -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); + } +} diff --git a/src/main/java/calclavia/lib/gui/GuiContainerBase.java b/src/main/java/calclavia/lib/gui/GuiContainerBase.java new file mode 100644 index 0000000..8d2cad3 --- /dev/null +++ b/src/main/java/calclavia/lib/gui/GuiContainerBase.java @@ -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 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 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); + } + } +} diff --git a/src/main/java/calclavia/lib/gui/GuiScreenBase.java b/src/main/java/calclavia/lib/gui/GuiScreenBase.java new file mode 100644 index 0000000..10e570a --- /dev/null +++ b/src/main/java/calclavia/lib/gui/GuiScreenBase.java @@ -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 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 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); + } + } +} diff --git a/src/main/java/calclavia/lib/gui/GuiSlotType.java b/src/main/java/calclavia/lib/gui/GuiSlotType.java new file mode 100644 index 0000000..02757f0 --- /dev/null +++ b/src/main/java/calclavia/lib/gui/GuiSlotType.java @@ -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) {} + +} diff --git a/src/main/java/calclavia/lib/render/CalclaviaRenderHelper.java b/src/main/java/calclavia/lib/render/CalclaviaRenderHelper.java new file mode 100644 index 0000000..120743d --- /dev/null +++ b/src/main/java/calclavia/lib/render/CalclaviaRenderHelper.java @@ -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(); + } +} diff --git a/src/main/java/calclavia/lib/render/ITagRender.java b/src/main/java/calclavia/lib/render/ITagRender.java new file mode 100644 index 0000000..dad2bb7 --- /dev/null +++ b/src/main/java/calclavia/lib/render/ITagRender.java @@ -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); +} diff --git a/src/main/java/calclavia/lib/render/RenderTaggedTile.java b/src/main/java/calclavia/lib/render/RenderTaggedTile.java new file mode 100644 index 0000000..bd1c55c --- /dev/null +++ b/src/main/java/calclavia/lib/render/RenderTaggedTile.java @@ -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; + } +} diff --git a/src/main/java/dan200/computercraft/api/ComputerCraftAPI.java b/src/main/java/dan200/computercraft/api/ComputerCraftAPI.java new file mode 100755 index 0000000..4f84caa --- /dev/null +++ b/src/main/java/dan200/computercraft/api/ComputerCraftAPI.java @@ -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.
+ * Use in conjuction with createSaveDirMount() to create a unique place for your peripherals or media items to store files.
+ * @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.
+ * 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.
+ * Use in conjuction with IComputerAccess.mount() or IComputerAccess.mountWritable() to mount a folder from the + * users save directory onto a computers file system.
+ * @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".
+ * 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.
+ * Use in conjuction with IComputerAccess.mount() or IComputerAccess.mountWritable() to mount a resource folder onto a computers file system.
+ * 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.
+ * @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; +} diff --git a/src/main/java/dan200/computercraft/api/filesystem/IMount.java b/src/main/java/dan200/computercraft/api/filesystem/IMount.java new file mode 100755 index 0000000..cf884d9 --- /dev/null +++ b/src/main/java/dan200/computercraft/api/filesystem/IMount.java @@ -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 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; +} diff --git a/src/main/java/dan200/computercraft/api/filesystem/IWritableMount.java b/src/main/java/dan200/computercraft/api/filesystem/IWritableMount.java new file mode 100755 index 0000000..ffe3290 --- /dev/null +++ b/src/main/java/dan200/computercraft/api/filesystem/IWritableMount.java @@ -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; +} diff --git a/src/main/java/dan200/computercraft/api/filesystem/package-info.java b/src/main/java/dan200/computercraft/api/filesystem/package-info.java new file mode 100755 index 0000000..d7a2d59 --- /dev/null +++ b/src/main/java/dan200/computercraft/api/filesystem/package-info.java @@ -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; \ No newline at end of file diff --git a/src/main/java/dan200/computercraft/api/lua/ILuaContext.java b/src/main/java/dan200/computercraft/api/lua/ILuaContext.java new file mode 100755 index 0000000..1ffbeea --- /dev/null +++ b/src/main/java/dan200/computercraft/api/lua/ILuaContext.java @@ -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; +} diff --git a/src/main/java/dan200/computercraft/api/lua/ILuaObject.java b/src/main/java/dan200/computercraft/api/lua/ILuaObject.java new file mode 100755 index 0000000..abd8b40 --- /dev/null +++ b/src/main/java/dan200/computercraft/api/lua/ILuaObject.java @@ -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; +} diff --git a/src/main/java/dan200/computercraft/api/lua/ILuaTask.java b/src/main/java/dan200/computercraft/api/lua/ILuaTask.java new file mode 100755 index 0000000..45feead --- /dev/null +++ b/src/main/java/dan200/computercraft/api/lua/ILuaTask.java @@ -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; +} diff --git a/src/main/java/dan200/computercraft/api/lua/LuaException.java b/src/main/java/dan200/computercraft/api/lua/LuaException.java new file mode 100755 index 0000000..6683c4b --- /dev/null +++ b/src/main/java/dan200/computercraft/api/lua/LuaException.java @@ -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; + } +} diff --git a/src/main/java/dan200/computercraft/api/lua/package-info.java b/src/main/java/dan200/computercraft/api/lua/package-info.java new file mode 100755 index 0000000..3ea3d91 --- /dev/null +++ b/src/main/java/dan200/computercraft/api/lua/package-info.java @@ -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; diff --git a/src/main/java/dan200/computercraft/api/media/IMedia.java b/src/main/java/dan200/computercraft/api/media/IMedia.java new file mode 100755 index 0000000..57ebc08 --- /dev/null +++ b/src/main/java/dan200/computercraft/api/media/IMedia.java @@ -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 ); +} diff --git a/src/main/java/dan200/computercraft/api/media/IMediaProvider.java b/src/main/java/dan200/computercraft/api/media/IMediaProvider.java new file mode 100755 index 0000000..c0aabd5 --- /dev/null +++ b/src/main/java/dan200/computercraft/api/media/IMediaProvider.java @@ -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 ); +} diff --git a/src/main/java/dan200/computercraft/api/media/package-info.java b/src/main/java/dan200/computercraft/api/media/package-info.java new file mode 100755 index 0000000..9e2f507 --- /dev/null +++ b/src/main/java/dan200/computercraft/api/media/package-info.java @@ -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; diff --git a/src/main/java/dan200/computercraft/api/package-info.java b/src/main/java/dan200/computercraft/api/package-info.java new file mode 100755 index 0000000..f3a706a --- /dev/null +++ b/src/main/java/dan200/computercraft/api/package-info.java @@ -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; \ No newline at end of file diff --git a/src/main/java/dan200/computercraft/api/peripheral/IComputerAccess.java b/src/main/java/dan200/computercraft/api/peripheral/IComputerAccess.java new file mode 100755 index 0000000..2458c06 --- /dev/null +++ b/src/main/java/dan200/computercraft/api/peripheral/IComputerAccess.java @@ -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.
+ * @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.
+ * @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().
+ * 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.
+ * 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().
+ * 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(); +} diff --git a/src/main/java/dan200/computercraft/api/peripheral/IPeripheral.java b/src/main/java/dan200/computercraft/api/peripheral/IPeripheral.java new file mode 100755 index 0000000..a28d656 --- /dev/null +++ b/src/main/java/dan200/computercraft/api/peripheral/IPeripheral.java @@ -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().
+ *
+ * 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().
+ * Lua values of type "string" will be represented by Object type String.
+ * Lua values of type "number" will be represented by Object type Double.
+ * Lua values of type "boolean" will be represented by Object type Boolean.
+ * Lua values of any other type will be represented by a null object.
+ * 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.
+ * Integers, Doubles, Floats, Strings, Booleans and null be converted to their corresponding lua type.
+ * All other types will be converted to nil.
+ * 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.
+ *
+ * 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.
+ *
+ * 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 ); +} diff --git a/src/main/java/dan200/computercraft/api/peripheral/IPeripheralProvider.java b/src/main/java/dan200/computercraft/api/peripheral/IPeripheralProvider.java new file mode 100755 index 0000000..a2775f9 --- /dev/null +++ b/src/main/java/dan200/computercraft/api/peripheral/IPeripheralProvider.java @@ -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 ); +} diff --git a/src/main/java/dan200/computercraft/api/peripheral/package-info.java b/src/main/java/dan200/computercraft/api/peripheral/package-info.java new file mode 100755 index 0000000..10ea4da --- /dev/null +++ b/src/main/java/dan200/computercraft/api/peripheral/package-info.java @@ -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; diff --git a/src/main/java/dan200/computercraft/api/permissions/ITurtlePermissionProvider.java b/src/main/java/dan200/computercraft/api/permissions/ITurtlePermissionProvider.java new file mode 100644 index 0000000..476b4fc --- /dev/null +++ b/src/main/java/dan200/computercraft/api/permissions/ITurtlePermissionProvider.java @@ -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 ); +} diff --git a/src/main/java/dan200/computercraft/api/permissions/package-info.java b/src/main/java/dan200/computercraft/api/permissions/package-info.java new file mode 100644 index 0000000..a51e7ec --- /dev/null +++ b/src/main/java/dan200/computercraft/api/permissions/package-info.java @@ -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; \ No newline at end of file diff --git a/src/main/java/dan200/computercraft/api/redstone/IBundledRedstoneProvider.java b/src/main/java/dan200/computercraft/api/redstone/IBundledRedstoneProvider.java new file mode 100755 index 0000000..b85f2ef --- /dev/null +++ b/src/main/java/dan200/computercraft/api/redstone/IBundledRedstoneProvider.java @@ -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 ); +} diff --git a/src/main/java/dan200/computercraft/api/redstone/package-info.java b/src/main/java/dan200/computercraft/api/redstone/package-info.java new file mode 100755 index 0000000..e01c623 --- /dev/null +++ b/src/main/java/dan200/computercraft/api/redstone/package-info.java @@ -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; diff --git a/src/main/java/dan200/computercraft/api/turtle/ITurtleAccess.java b/src/main/java/dan200/computercraft/api/turtle/ITurtleAccess.java new file mode 100755 index 0000000..96c6159 --- /dev/null +++ b/src/main/java/dan200/computercraft/api/turtle/ITurtleAccess.java @@ -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 ); +} diff --git a/src/main/java/dan200/computercraft/api/turtle/ITurtleCommand.java b/src/main/java/dan200/computercraft/api/turtle/ITurtleCommand.java new file mode 100755 index 0000000..17d113e --- /dev/null +++ b/src/main/java/dan200/computercraft/api/turtle/ITurtleCommand.java @@ -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 ); +} diff --git a/src/main/java/dan200/computercraft/api/turtle/ITurtleUpgrade.java b/src/main/java/dan200/computercraft/api/turtle/ITurtleUpgrade.java new file mode 100755 index 0000000..0dcc6e6 --- /dev/null +++ b/src/main/java/dan200/computercraft/api/turtle/ITurtleUpgrade.java @@ -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 ); +} diff --git a/src/main/java/dan200/computercraft/api/turtle/TurtleAnimation.java b/src/main/java/dan200/computercraft/api/turtle/TurtleAnimation.java new file mode 100755 index 0000000..abb4134 --- /dev/null +++ b/src/main/java/dan200/computercraft/api/turtle/TurtleAnimation.java @@ -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, +} diff --git a/src/main/java/dan200/computercraft/api/turtle/TurtleCommandResult.java b/src/main/java/dan200/computercraft/api/turtle/TurtleCommandResult.java new file mode 100755 index 0000000..67046bd --- /dev/null +++ b/src/main/java/dan200/computercraft/api/turtle/TurtleCommandResult.java @@ -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; + } +} diff --git a/src/main/java/dan200/computercraft/api/turtle/TurtleSide.java b/src/main/java/dan200/computercraft/api/turtle/TurtleSide.java new file mode 100755 index 0000000..5fc7c61 --- /dev/null +++ b/src/main/java/dan200/computercraft/api/turtle/TurtleSide.java @@ -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, +} diff --git a/src/main/java/dan200/computercraft/api/turtle/TurtleUpgradeType.java b/src/main/java/dan200/computercraft/api/turtle/TurtleUpgradeType.java new file mode 100755 index 0000000..e5fd1af --- /dev/null +++ b/src/main/java/dan200/computercraft/api/turtle/TurtleUpgradeType.java @@ -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, +} diff --git a/src/main/java/dan200/computercraft/api/turtle/TurtleVerb.java b/src/main/java/dan200/computercraft/api/turtle/TurtleVerb.java new file mode 100755 index 0000000..566fa48 --- /dev/null +++ b/src/main/java/dan200/computercraft/api/turtle/TurtleVerb.java @@ -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, +} diff --git a/src/main/java/dan200/computercraft/api/turtle/package-info.java b/src/main/java/dan200/computercraft/api/turtle/package-info.java new file mode 100755 index 0000000..7825971 --- /dev/null +++ b/src/main/java/dan200/computercraft/api/turtle/package-info.java @@ -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; diff --git a/src/main/java/icbm/api/IAmmunition.java b/src/main/java/icbm/api/IAmmunition.java new file mode 100644 index 0000000..34b3071 --- /dev/null +++ b/src/main/java/icbm/api/IAmmunition.java @@ -0,0 +1,10 @@ +package icbm.api; + +import net.minecraft.item.ItemStack; + +public interface IAmmunition { + + boolean hasAmmunition(ItemStack var1); + + boolean useAmmunition(ItemStack var1); +} diff --git a/src/main/java/icbm/api/IBlockFrequency.java b/src/main/java/icbm/api/IBlockFrequency.java new file mode 100644 index 0000000..d831270 --- /dev/null +++ b/src/main/java/icbm/api/IBlockFrequency.java @@ -0,0 +1,9 @@ +package icbm.api; + + +public interface IBlockFrequency { + + int getFrequency(); + + void setFrequency(int var1); +} diff --git a/src/main/java/icbm/api/ICBM.java b/src/main/java/icbm/api/ICBM.java new file mode 100644 index 0000000..5e8e014 --- /dev/null +++ b/src/main/java/icbm/api/ICBM.java @@ -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; + } +} diff --git a/src/main/java/icbm/api/ICBMFlags.java b/src/main/java/icbm/api/ICBMFlags.java new file mode 100644 index 0000000..03ab58c --- /dev/null +++ b/src/main/java/icbm/api/ICBMFlags.java @@ -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"); +} diff --git a/src/main/java/icbm/api/ICamouflageMaterial.java b/src/main/java/icbm/api/ICamouflageMaterial.java new file mode 100644 index 0000000..d47aebb --- /dev/null +++ b/src/main/java/icbm/api/ICamouflageMaterial.java @@ -0,0 +1,5 @@ +package icbm.api; + + +public interface ICamouflageMaterial { +} diff --git a/src/main/java/icbm/api/IHackable.java b/src/main/java/icbm/api/IHackable.java new file mode 100644 index 0000000..63d4909 --- /dev/null +++ b/src/main/java/icbm/api/IHackable.java @@ -0,0 +1,10 @@ +package icbm.api; + +import net.minecraft.entity.player.EntityPlayer; + +public interface IHackable { + + void generateNewKey(); + + boolean tryForAccess(EntityPlayer var1, String var2); +} diff --git a/src/main/java/icbm/api/IItemFrequency.java b/src/main/java/icbm/api/IItemFrequency.java new file mode 100644 index 0000000..3ac4618 --- /dev/null +++ b/src/main/java/icbm/api/IItemFrequency.java @@ -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); +} diff --git a/src/main/java/icbm/api/ILauncherContainer.java b/src/main/java/icbm/api/ILauncherContainer.java new file mode 100644 index 0000000..a462a3b --- /dev/null +++ b/src/main/java/icbm/api/ILauncherContainer.java @@ -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(); +} diff --git a/src/main/java/icbm/api/ILauncherController.java b/src/main/java/icbm/api/ILauncherController.java new file mode 100644 index 0000000..cdb9bb0 --- /dev/null +++ b/src/main/java/icbm/api/ILauncherController.java @@ -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(); +} diff --git a/src/main/java/icbm/api/IMissile.java b/src/main/java/icbm/api/IMissile.java new file mode 100644 index 0000000..6ea09cd --- /dev/null +++ b/src/main/java/icbm/api/IMissile.java @@ -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); +} diff --git a/src/main/java/icbm/api/IMissileLockable.java b/src/main/java/icbm/api/IMissileLockable.java new file mode 100644 index 0000000..4474c02 --- /dev/null +++ b/src/main/java/icbm/api/IMissileLockable.java @@ -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); +} diff --git a/src/main/java/icbm/api/LauncherType.java b/src/main/java/icbm/api/LauncherType.java new file mode 100644 index 0000000..1c8d1c3 --- /dev/null +++ b/src/main/java/icbm/api/LauncherType.java @@ -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) {} + +} diff --git a/src/main/java/icbm/api/RadarRegistry.java b/src/main/java/icbm/api/RadarRegistry.java new file mode 100644 index 0000000..83b2bb9 --- /dev/null +++ b/src/main/java/icbm/api/RadarRegistry.java @@ -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 detectableTileEntities = new HashSet<>(); + private static Set 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 getTileEntitiesInArea(Vector2 minVector, + Vector2 maxVector) { + ArrayList 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 getEntitiesWithinRadius(Vector2 vector, + int radius) { + cleanUpArray(); + ArrayList 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 getTileEntities() { + cleanUpArray(); + return detectableTileEntities; + } + + public static Set getEntities() { + cleanUpArray(); + return detectableEntities; + } + + public static void cleanUpArray() { + try { + Iterator 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 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(); + } + } +} diff --git a/src/main/java/icbm/api/explosion/ExplosionEvent.java b/src/main/java/icbm/api/explosion/ExplosionEvent.java new file mode 100644 index 0000000..b3fd936 --- /dev/null +++ b/src/main/java/icbm/api/explosion/ExplosionEvent.java @@ -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); + } + } +} diff --git a/src/main/java/icbm/api/explosion/IEMPBlock.java b/src/main/java/icbm/api/explosion/IEMPBlock.java new file mode 100644 index 0000000..c74d838 --- /dev/null +++ b/src/main/java/icbm/api/explosion/IEMPBlock.java @@ -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); +} diff --git a/src/main/java/icbm/api/explosion/IEMPItem.java b/src/main/java/icbm/api/explosion/IEMPItem.java new file mode 100644 index 0000000..32b4e4a --- /dev/null +++ b/src/main/java/icbm/api/explosion/IEMPItem.java @@ -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); +} diff --git a/src/main/java/icbm/api/explosion/IExplosive.java b/src/main/java/icbm/api/explosion/IExplosive.java new file mode 100644 index 0000000..d923615 --- /dev/null +++ b/src/main/java/icbm/api/explosion/IExplosive.java @@ -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(); +} diff --git a/src/main/java/icbm/api/explosion/IExplosiveContainer.java b/src/main/java/icbm/api/explosion/IExplosiveContainer.java new file mode 100644 index 0000000..72f54b6 --- /dev/null +++ b/src/main/java/icbm/api/explosion/IExplosiveContainer.java @@ -0,0 +1,8 @@ +package icbm.api.explosion; + +import icbm.api.explosion.IExplosive; + +public interface IExplosiveContainer { + + IExplosive getExplosiveType(); +} diff --git a/src/main/java/icbm/api/explosion/IExplosiveIgnore.java b/src/main/java/icbm/api/explosion/IExplosiveIgnore.java new file mode 100644 index 0000000..093a592 --- /dev/null +++ b/src/main/java/icbm/api/explosion/IExplosiveIgnore.java @@ -0,0 +1,8 @@ +package icbm.api.explosion; + +import icbm.api.explosion.ExplosionEvent; + +public interface IExplosiveIgnore { + + boolean canIgnore(ExplosionEvent var1); +} diff --git a/src/main/java/mffs/ClientProxy.java b/src/main/java/mffs/ClientProxy.java new file mode 100644 index 0000000..ac81aa7 --- /dev/null +++ b/src/main/java/mffs/ClientProxy.java @@ -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)); + } +} diff --git a/src/main/java/mffs/CommonProxy.java b/src/main/java/mffs/CommonProxy.java new file mode 100644 index 0000000..14dda3a --- /dev/null +++ b/src/main/java/mffs/CommonProxy.java @@ -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) {} +} diff --git a/src/main/java/mffs/DelayedEvent.java b/src/main/java/mffs/DelayedEvent.java new file mode 100644 index 0000000..811bf6b --- /dev/null +++ b/src/main/java/mffs/DelayedEvent.java @@ -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; } +} diff --git a/src/main/java/mffs/IDelayedEventHandler.java b/src/main/java/mffs/IDelayedEventHandler.java new file mode 100644 index 0000000..eafa6c0 --- /dev/null +++ b/src/main/java/mffs/IDelayedEventHandler.java @@ -0,0 +1,10 @@ +package mffs; + +import java.util.List; + +public interface IDelayedEventHandler +{ + List getDelayedEvents(); + + List getQuedDelayedEvents(); +} diff --git a/src/main/java/mffs/MFFSCreativeTab.java b/src/main/java/mffs/MFFSCreativeTab.java new file mode 100644 index 0000000..e5ea716 --- /dev/null +++ b/src/main/java/mffs/MFFSCreativeTab.java @@ -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"); + } +} diff --git a/src/main/java/mffs/MFFSHelper.java b/src/main/java/mffs/MFFSHelper.java new file mode 100644 index 0000000..f351785 --- /dev/null +++ b/src/main/java/mffs/MFFSHelper.java @@ -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 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 splitStringPerWord(final String string, + final int wordsPerLine) { + final String[] words = string.split(" "); + final List 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 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; + } +} diff --git a/src/main/java/mffs/ManipulatorHelper.java b/src/main/java/mffs/ManipulatorHelper.java new file mode 100644 index 0000000..2ddd463 --- /dev/null +++ b/src/main/java/mffs/ManipulatorHelper.java @@ -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()); + } +} diff --git a/src/main/java/mffs/ModularForceFieldSystem.java b/src/main/java/mffs/ModularForceFieldSystem.java new file mode 100644 index 0000000..8937802 --- /dev/null +++ b/src/main/java/mffs/ModularForceFieldSystem.java @@ -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(); + } +} diff --git a/src/main/java/mffs/Recipes.java b/src/main/java/mffs/Recipes.java new file mode 100644 index 0000000..fde741e --- /dev/null +++ b/src/main/java/mffs/Recipes.java @@ -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(); + } +} diff --git a/src/main/java/mffs/Settings.java b/src/main/java/mffs/Settings.java new file mode 100644 index 0000000..4b19b6c --- /dev/null +++ b/src/main/java/mffs/Settings.java @@ -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; + } +} diff --git a/src/main/java/mffs/SubscribeEventHandler.java b/src/main/java/mffs/SubscribeEventHandler.java new file mode 100644 index 0000000..4f2994b --- /dev/null +++ b/src/main/java/mffs/SubscribeEventHandler.java @@ -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); + } + } +} diff --git a/src/main/java/mffs/TransferMode.java b/src/main/java/mffs/TransferMode.java new file mode 100644 index 0000000..59995ce --- /dev/null +++ b/src/main/java/mffs/TransferMode.java @@ -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]; + } +} diff --git a/src/main/java/mffs/api/Blacklist.java b/src/main/java/mffs/api/Blacklist.java new file mode 100644 index 0000000..01e2033 --- /dev/null +++ b/src/main/java/mffs/api/Blacklist.java @@ -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 stabilizationBlacklist; + public static final Set disintegrationBlacklist; + public static final Set forceManipulationBlacklist; + + static { + stabilizationBlacklist = new HashSet<>(); + disintegrationBlacklist = new HashSet<>(); + forceManipulationBlacklist = new HashSet<>(); + } +} diff --git a/src/main/java/mffs/api/IActivatable.java b/src/main/java/mffs/api/IActivatable.java new file mode 100644 index 0000000..c5e4068 --- /dev/null +++ b/src/main/java/mffs/api/IActivatable.java @@ -0,0 +1,8 @@ +package mffs.api; + +public interface IActivatable +{ + boolean isActive(); + + void setActive(final boolean p0); +} diff --git a/src/main/java/mffs/api/IBiometricIdentifierLink.java b/src/main/java/mffs/api/IBiometricIdentifierLink.java new file mode 100644 index 0000000..884e934 --- /dev/null +++ b/src/main/java/mffs/api/IBiometricIdentifierLink.java @@ -0,0 +1,11 @@ +package mffs.api; + +import java.util.Set; +import mffs.api.security.IBiometricIdentifier; + +public interface IBiometricIdentifierLink +{ + IBiometricIdentifier getBiometricIdentifier(); + + Set getBiometricIdentifiers(); +} diff --git a/src/main/java/mffs/api/ICache.java b/src/main/java/mffs/api/ICache.java new file mode 100644 index 0000000..06a06d5 --- /dev/null +++ b/src/main/java/mffs/api/ICache.java @@ -0,0 +1,10 @@ +package mffs.api; + +public interface ICache +{ + Object getCache(final String p0); + + void clearCache(final String p0); + + void clearCache(); +} diff --git a/src/main/java/mffs/api/IFieldInteraction.java b/src/main/java/mffs/api/IFieldInteraction.java new file mode 100644 index 0000000..e6c92a4 --- /dev/null +++ b/src/main/java/mffs/api/IFieldInteraction.java @@ -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 getCalculatedField(); + + Set getInteriorPoints(); + + void setCalculating(final boolean p0); + + void setCalculated(final boolean p0); +} diff --git a/src/main/java/mffs/api/IForceFieldBlock.java b/src/main/java/mffs/api/IForceFieldBlock.java new file mode 100644 index 0000000..d6965fa --- /dev/null +++ b/src/main/java/mffs/api/IForceFieldBlock.java @@ -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); +} diff --git a/src/main/java/mffs/api/IProjector.java b/src/main/java/mffs/api/IProjector.java new file mode 100644 index 0000000..0199e80 --- /dev/null +++ b/src/main/java/mffs/api/IProjector.java @@ -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(); +} diff --git a/src/main/java/mffs/api/ISpecialForceManipulation.java b/src/main/java/mffs/api/ISpecialForceManipulation.java new file mode 100644 index 0000000..3210b48 --- /dev/null +++ b/src/main/java/mffs/api/ISpecialForceManipulation.java @@ -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(); +} diff --git a/src/main/java/mffs/api/card/ICard.java b/src/main/java/mffs/api/card/ICard.java new file mode 100644 index 0000000..4c47839 --- /dev/null +++ b/src/main/java/mffs/api/card/ICard.java @@ -0,0 +1,5 @@ +package mffs.api.card; + +public interface ICard +{ +} diff --git a/src/main/java/mffs/api/card/ICardIdentification.java b/src/main/java/mffs/api/card/ICardIdentification.java new file mode 100644 index 0000000..06c8d87 --- /dev/null +++ b/src/main/java/mffs/api/card/ICardIdentification.java @@ -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); +} diff --git a/src/main/java/mffs/api/card/ICardInfinite.java b/src/main/java/mffs/api/card/ICardInfinite.java new file mode 100644 index 0000000..4f35a5a --- /dev/null +++ b/src/main/java/mffs/api/card/ICardInfinite.java @@ -0,0 +1,5 @@ +package mffs.api.card; + +public interface ICardInfinite +{ +} diff --git a/src/main/java/mffs/api/card/ICardLink.java b/src/main/java/mffs/api/card/ICardLink.java new file mode 100644 index 0000000..460c031 --- /dev/null +++ b/src/main/java/mffs/api/card/ICardLink.java @@ -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); +} diff --git a/src/main/java/mffs/api/fortron/IFortronCapacitor.java b/src/main/java/mffs/api/fortron/IFortronCapacitor.java new file mode 100644 index 0000000..65d7874 --- /dev/null +++ b/src/main/java/mffs/api/fortron/IFortronCapacitor.java @@ -0,0 +1,12 @@ +package mffs.api.fortron; + +import java.util.Set; + +public interface IFortronCapacitor +{ + Set getLinkedDevices(); + + int getTransmissionRange(); + + int getTransmissionRate(); +} diff --git a/src/main/java/mffs/api/fortron/IFortronFrequency.java b/src/main/java/mffs/api/fortron/IFortronFrequency.java new file mode 100644 index 0000000..1e4f9b4 --- /dev/null +++ b/src/main/java/mffs/api/fortron/IFortronFrequency.java @@ -0,0 +1,7 @@ +package mffs.api.fortron; + +import icbm.api.IBlockFrequency; + +public interface IFortronFrequency extends IFortronStorage, IBlockFrequency +{ +} diff --git a/src/main/java/mffs/api/fortron/IFortronStorage.java b/src/main/java/mffs/api/fortron/IFortronStorage.java new file mode 100644 index 0000000..fd7424f --- /dev/null +++ b/src/main/java/mffs/api/fortron/IFortronStorage.java @@ -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); +} diff --git a/src/main/java/mffs/api/modules/IInterdictionMatrixModule.java b/src/main/java/mffs/api/modules/IInterdictionMatrixModule.java new file mode 100644 index 0000000..9916f8c --- /dev/null +++ b/src/main/java/mffs/api/modules/IInterdictionMatrixModule.java @@ -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); +} diff --git a/src/main/java/mffs/api/modules/IModule.java b/src/main/java/mffs/api/modules/IModule.java new file mode 100644 index 0000000..f01ab79 --- /dev/null +++ b/src/main/java/mffs/api/modules/IModule.java @@ -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 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 fieldBlocks); +} diff --git a/src/main/java/mffs/api/modules/IModuleAcceptor.java b/src/main/java/mffs/api/modules/IModuleAcceptor.java new file mode 100644 index 0000000..352b8e3 --- /dev/null +++ b/src/main/java/mffs/api/modules/IModuleAcceptor.java @@ -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 getModuleStacks(final int... p0); + + Set getModules(final int... p0); + + int getFortronCost(); +} diff --git a/src/main/java/mffs/api/modules/IProjectorMode.java b/src/main/java/mffs/api/modules/IProjectorMode.java new file mode 100644 index 0000000..3ed4ec1 --- /dev/null +++ b/src/main/java/mffs/api/modules/IProjectorMode.java @@ -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 getExteriorPoints(final IFieldInteraction p0); + + Set 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); +} diff --git a/src/main/java/mffs/api/security/IBiometricIdentifier.java b/src/main/java/mffs/api/security/IBiometricIdentifier.java new file mode 100644 index 0000000..eaa760b --- /dev/null +++ b/src/main/java/mffs/api/security/IBiometricIdentifier.java @@ -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(); +} diff --git a/src/main/java/mffs/api/security/IInterdictionMatrix.java b/src/main/java/mffs/api/security/IInterdictionMatrix.java new file mode 100644 index 0000000..4c1aebb --- /dev/null +++ b/src/main/java/mffs/api/security/IInterdictionMatrix.java @@ -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 getFilteredItems(); + + boolean getFilterMode(); + + int getFortronCost(); +} diff --git a/src/main/java/mffs/api/security/Permission.java b/src/main/java/mffs/api/security/Permission.java new file mode 100644 index 0000000..03ea1f1 --- /dev/null +++ b/src/main/java/mffs/api/security/Permission.java @@ -0,0 +1,45 @@ +package mffs.api.security; + +public class Permission +{ + public static final Permission FORCE_FIELD_WARP; + public static final Permission BLOCK_ALTER; + public static final Permission BLOCK_ACCESS; + public static final Permission SECURITY_CENTER_CONFIGURE; + public static final Permission BYPASS_INTERDICTION_MATRIX; + public static final Permission DEFENSE_STATION_CONFISCATION; + public static final Permission REMOTE_CONTROL; + private static Permission[] LIST; + public final int id; + public final String name; + + public Permission(final int id, final String name) { + this.id = id; + this.name = name; + if (Permission.LIST == null) { + Permission.LIST = new Permission[7]; + } + Permission.LIST[this.id] = this; + } + + public static Permission getPermission(final int id) { + if (id < Permission.LIST.length && id >= 0) { + return Permission.LIST[id]; + } + return null; + } + + public static Permission[] getPermissions() { + return Permission.LIST; + } + + static { + FORCE_FIELD_WARP = new Permission(0, "warp"); + BLOCK_ALTER = new Permission(1, "blockPlaceAccess"); + BLOCK_ACCESS = new Permission(2, "blockAccess"); + SECURITY_CENTER_CONFIGURE = new Permission(3, "configure"); + BYPASS_INTERDICTION_MATRIX = new Permission(4, "bypassDefense"); + DEFENSE_STATION_CONFISCATION = new Permission(5, "bypassConfiscation"); + REMOTE_CONTROL = new Permission(6, "remoteControl"); + } +} diff --git a/src/main/java/mffs/base/BlockBase.java b/src/main/java/mffs/base/BlockBase.java new file mode 100644 index 0000000..6b2a79d --- /dev/null +++ b/src/main/java/mffs/base/BlockBase.java @@ -0,0 +1,21 @@ +package mffs.base; + +import mffs.MFFSCreativeTab; +import net.minecraft.block.material.Material; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; +import universalelectricity.prefab.block.BlockAdvanced; + +public abstract class BlockBase extends BlockAdvanced { + public BlockBase(final String name, final Material material) { + super(material); + this.setBlockName("mffs:" + name); + this.setCreativeTab(MFFSCreativeTab.INSTANCE); + } + + // anti-bullshit + @Override + public TileEntity createTileEntity(World world, int meta) { + return this.createNewTileEntity(world, meta); + } +} diff --git a/src/main/java/mffs/base/BlockMachine.java b/src/main/java/mffs/base/BlockMachine.java new file mode 100644 index 0000000..de6e840 --- /dev/null +++ b/src/main/java/mffs/base/BlockMachine.java @@ -0,0 +1,137 @@ +package mffs.base; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import icbm.api.ICamouflageMaterial; +import mffs.MFFSCreativeTab; +import mffs.ModularForceFieldSystem; +import mffs.api.IBiometricIdentifierLink; +import mffs.api.security.Permission; +import mffs.item.card.ItemCardLink; +import mffs.render.RenderBlockHandler; +import net.minecraft.block.Block; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.ChatComponentText; +import net.minecraft.world.World; +import universalelectricity.core.UniversalElectricity; +import universalelectricity.prefab.block.BlockRotatable; +import universalelectricity.prefab.implement.IRedstoneReceptor; + +public abstract class BlockMachine + extends BlockRotatable implements ICamouflageMaterial { + public BlockMachine(final String name) { + super(UniversalElectricity.machine); + this.setBlockName("mffs:" + name); + this.setHardness(Float.MAX_VALUE); + this.setResistance(100.0f); + this.setStepSound(BlockMachine.soundTypeMetal); + this.setCreativeTab(MFFSCreativeTab.INSTANCE); + } + + @Override + public boolean onMachineActivated(final World world, final int x, final int y, final int z, + final EntityPlayer entityPlayer, final int side, + final float hitX, final float hitY, final float hitZ) { + if (!world.isRemote) { + if (entityPlayer.getCurrentEquippedItem() != null && + entityPlayer.getCurrentEquippedItem().getItem() instanceof ItemCardLink) { + return false; + } + entityPlayer.openGui((Object) ModularForceFieldSystem.instance, 0, world, + x, y, z); + } + return true; + } + + @Override + public boolean onSneakMachineActivated(final World world, final int x, + final int y, final int z, + final EntityPlayer entityPlayer, + final int side, final float hitX, + final float hitY, final float hitZ) { + return this.onUseWrench(world, x, y, z, entityPlayer, side, hitX, hitY, + hitZ); + } + + @Override + public boolean onSneakUseWrench(final World world, final int x, final int y, + final int z, final EntityPlayer entityPlayer, + final int side, final float hitX, + final float hitY, final float hitZ) { + if (!world.isRemote) { + final TileEntity tileEntity = world.getTileEntity(x, y, z); + if (tileEntity instanceof IBiometricIdentifierLink) { + if (((IBiometricIdentifierLink) tileEntity).getBiometricIdentifier() == null) { + this.dropBlockAsItem(world, x, y, z, world.getBlockMetadata(x, y, z), + 0); + world.setBlockToAir(x, y, z); + return true; + } + if (((IBiometricIdentifierLink) tileEntity) + .getBiometricIdentifier() + .isAccessGranted(entityPlayer.getDisplayName(), + Permission.SECURITY_CENTER_CONFIGURE)) { + this.dropBlockAsItem(world, x, y, z, world.getBlockMetadata(x, y, z), + 0); + world.setBlockToAir(x, y, z); + return true; + } + entityPlayer.addChatMessage(new ChatComponentText( + "[" + + ModularForceFieldSystem.blockBiometricIdentifier + .getLocalizedName() + + + "]" + + " Cannot remove machine! Access denied!")); + } + } + return false; + } + + @Override + public void onNeighborBlockChange(final World world, final int x, final int y, + final int z, final Block block) { + if (!world.isRemote) { + final TileEntity tileEntity = world.getTileEntity(x, y, z); + if (tileEntity instanceof IRedstoneReceptor) { + if (world.isBlockIndirectlyGettingPowered(x, y, z)) { + ((IRedstoneReceptor) tileEntity).onPowerOn(); + } else { + ((IRedstoneReceptor) tileEntity).onPowerOff(); + } + } + } + } + + @Override + public float getExplosionResistance(final Entity entity, final World world, + final int i, final int j, final int k, + final double d, final double d1, + final double d2) { + return 100.0f; + } + + @Override + public void registerBlockIcons(final IIconRegister par1IconRegister) { + this.blockIcon = par1IconRegister.registerIcon("mffs:machine"); + } + + @Override + public boolean isOpaqueCube() { + return false; + } + + @Override + public boolean renderAsNormalBlock() { + return false; + } + + @SideOnly(Side.CLIENT) + @Override + public int getRenderType() { + return RenderBlockHandler.ID; + } +} diff --git a/src/main/java/mffs/base/ContainerBase.java b/src/main/java/mffs/base/ContainerBase.java new file mode 100644 index 0000000..d8d4c16 --- /dev/null +++ b/src/main/java/mffs/base/ContainerBase.java @@ -0,0 +1,95 @@ +package mffs.base; + +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; + private IInventory inventory; + + public ContainerBase(final IInventory inventory) { + this.slotCount = 0; + this.inventory = inventory; + this.slotCount = inventory.getSizeInventory(); + } + + @Override + public void onContainerClosed(final EntityPlayer player) { + if (this.inventory instanceof TileEntityBase) { + ((TileEntityBase)this.inventory).playersUsing.remove(player); + } + } + + public void addPlayerInventory(final EntityPlayer player) { + if (this.inventory instanceof TileEntityBase) { + ((TileEntityBase)this.inventory).playersUsing.add(player); + } + for (int var3 = 0; var3 < 3; ++var3) { + for (int var4 = 0; var4 < 9; ++var4) { + this.addSlotToContainer(new Slot((IInventory)player.inventory, + var4 + var3 * 9 + 9, 8 + var4 * 18, + 135 + var3 * 18)); + } + } + for (int var3 = 0; var3 < 9; ++var3) { + this.addSlotToContainer( + new Slot((IInventory)player.inventory, var3, 8 + var3 * 18, 193)); + } + } + + @Override + public ItemStack transferStackInSlot(final EntityPlayer par1EntityPlayer, + final int slotID) { + ItemStack var2 = null; + final Slot var3 = (Slot)super.inventorySlots.get(slotID); + if (var3 != null && var3.getHasStack()) { + final 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; + } + + @Override + public boolean canInteractWith(final EntityPlayer entityplayer) { + return this.inventory.isUseableByPlayer(entityplayer); + } +} diff --git a/src/main/java/mffs/base/GuiBase.java b/src/main/java/mffs/base/GuiBase.java new file mode 100644 index 0000000..5f1ec2a --- /dev/null +++ b/src/main/java/mffs/base/GuiBase.java @@ -0,0 +1,362 @@ +package mffs.base; + +import icbm.api.IBlockFrequency; +import java.util.HashMap; +import java.util.Map; +import mffs.MFFSHelper; +import mffs.ModularForceFieldSystem; +import mffs.api.IBiometricIdentifierLink; +import mffs.gui.button.GuiIcon; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.gui.GuiTextField; +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.client.renderer.RenderHelper; +import net.minecraft.init.Blocks; +import net.minecraft.inventory.Container; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.ResourceLocation; +import org.lwjgl.input.Keyboard; +import org.lwjgl.opengl.GL11; +import universalelectricity.core.vector.Vector2; +import universalelectricity.core.vector.Vector3; +import universalelectricity.prefab.TranslationHelper; +import universalelectricity.prefab.vector.Region2; + +public class GuiBase extends GuiContainer { + public static final int METER_HEIGHT = 49; + public static final int METER_WIDTH = 14; + public static final int METER_END = 68; + protected GuiTextField textFieldFrequency; + protected Vector2 textFieldPos; + public String tooltip; + protected int containerWidth; + protected int containerHeight; + protected IBlockFrequency frequencyTile; + protected HashMap tooltips; + + public GuiBase(final Container container) { + super(container); + this.textFieldPos = new Vector2(); + this.tooltip = ""; + this.tooltips = new HashMap<>(); + this.ySize = 217; + } + + public GuiBase(final Container container, + final IBlockFrequency frequencyTile) { + this(container); + this.frequencyTile = frequencyTile; + } + + @Override + public void initGui() { + super.initGui(); + this.buttonList.clear(); + this.buttonList.add(new GuiIcon( + 0, this.width / 2 - 82, this.height / 2 - 104, + new ItemStack(Blocks.torch), new ItemStack(Blocks.redstone_torch))); + Keyboard.enableRepeatEvents(true); + if (this.frequencyTile != null) { + (this.textFieldFrequency = + new GuiTextField(this.fontRendererObj, this.textFieldPos.intX(), + this.textFieldPos.intY(), 50, 12)) + .setMaxStringLength(6); + this.textFieldFrequency.setText(this.frequencyTile.getFrequency() + ""); + } + } + + @Override + public void onGuiClosed() { + Keyboard.enableRepeatEvents(false); + super.onGuiClosed(); + } + + @Override + protected void keyTyped(final char par1, final int par2) { + super.keyTyped(par1, par2); + if (this.textFieldFrequency != null) { + this.textFieldFrequency.textboxKeyTyped(par1, par2); + try { + final int newFrequency = + Math.max(0, Integer.parseInt(this.textFieldFrequency.getText())); + this.frequencyTile.setFrequency(newFrequency); + this.textFieldFrequency.setText(this.frequencyTile.getFrequency() + ""); + NBTTagCompound nbt = new NBTTagCompound(); + nbt.setInteger("frequency", this.frequencyTile.getFrequency()); + ModularForceFieldSystem.channel.sendToServer( + new PacketTile(PacketTile.Type.FREQUENCY, + new Vector3((TileEntity)this.frequencyTile), nbt)); + } catch (final NumberFormatException ex) { + } + } + } + + @Override + protected void actionPerformed(final GuiButton guiButton) { + super.actionPerformed(guiButton); + if (this.frequencyTile != null && guiButton.id == 0) { + ModularForceFieldSystem.channel.sendToServer(new PacketTile( + PacketTile.Type.TOGGLE_ACTIVATION, + new Vector3((TileEntity)this.frequencyTile), new NBTTagCompound())); + } + } + + @Override + public void updateScreen() { + super.updateScreen(); + if (this.textFieldFrequency != null && + !this.textFieldFrequency.isFocused()) { + this.textFieldFrequency.setText(this.frequencyTile.getFrequency() + ""); + } + if (this.frequencyTile instanceof TileEntityBase && + this.buttonList.size() > 0 && this.buttonList.get(0) != null) { + ((GuiIcon)this.buttonList.get(0)) + .setIndex(((TileEntityBase)this.frequencyTile).isActive() ? 1 : 0); + } + } + + @Override + protected void mouseClicked(final int x, final int y, final int par3) { + super.mouseClicked(x, y, par3); + if (this.textFieldFrequency != null) { + this.textFieldFrequency.mouseClicked(x - this.containerWidth, + y - this.containerHeight, par3); + } + } + + @Override + protected void drawGuiContainerForegroundLayer(final int mouseX, + final int mouseY) { + if (this.textFieldFrequency != null && + this.func_146978_c(this.textFieldPos.intX(), this.textFieldPos.intY(), + this.textFieldFrequency.getWidth(), 12, mouseX, + mouseY)) { + this.tooltip = TranslationHelper.getLocal("gui.frequency.tooltip"); + } + for (final Map.Entry entry : this.tooltips.entrySet()) { + if (entry.getKey().isIn( + new Vector2(mouseX - this.guiLeft, mouseY - this.guiTop))) { + this.tooltip = entry.getValue(); + break; + } + } + if (this.tooltip != null && this.tooltip != "") { + this.drawTooltip(mouseX - this.guiLeft, mouseY - this.guiTop, + MFFSHelper.splitStringPerWord(this.tooltip, 5) + .toArray(new String[] {})); + } + this.tooltip = ""; + } + + @Override + protected void drawGuiContainerBackgroundLayer(final float var1, final int x, + final int y) { + this.containerWidth = (this.width - this.xSize) / 2; + this.containerHeight = (this.height - this.ySize) / 2; + this.mc.renderEngine.bindTexture( + new ResourceLocation("mffs", "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); + if (this.frequencyTile instanceof IBiometricIdentifierLink) { + this.drawBulb(167, 4, + ((IBiometricIdentifierLink)this.frequencyTile) + .getBiometricIdentifier() != null); + } + } + + protected void drawBulb(final int x, final int y, final boolean isOn) { + this.mc.renderEngine.bindTexture( + new ResourceLocation("mffs", "textures/gui/gui_components.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(final int x, final int y, final ItemStack itemStack) { + this.mc.renderEngine.bindTexture( + new ResourceLocation("mffs", "textures/gui/gui_components.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(final ItemStack itemStack, int x, int y) { + ++x; + ++y; + GL11.glTranslatef(0.0f, 0.0f, 32.0f); + GuiBase.itemRender.renderItemAndEffectIntoGUI( + this.fontRendererObj, this.mc.renderEngine, itemStack, x, y); + } + + protected void drawTextWithTooltip(final String textName, final String format, + final int x, final int y, final int mouseX, + final int mouseY) { + this.drawTextWithTooltip(textName, format, x, y, mouseX, mouseY, 4210752); + } + + protected void drawTextWithTooltip(final String textName, final String format, + final int x, final int y, final int mouseX, + final int mouseY, final int color) { + final String name = TranslationHelper.getLocal("gui." + textName + ".name"); + final String text = format.replaceAll("%1", name); + this.fontRendererObj.drawString(text, x, y, color); + final String tooltip = + TranslationHelper.getLocal("gui." + textName + ".tooltip"); + if (tooltip != null && tooltip != "" && + this.func_146978_c(x, y, (int)(text.length() * 4.8), 12, mouseX, + mouseY)) { + this.tooltip = tooltip; + } + } + + protected void drawTextWithTooltip(final String textName, final int x, + final int y, final int mouseX, + final int mouseY) { + this.drawTextWithTooltip(textName, "%1", x, y, mouseX, mouseY); + } + + protected void drawSlot(final int x, final int y, final SlotType type, + final float r, final float g, final float b) { + this.mc.renderEngine.bindTexture( + new ResourceLocation("mffs", "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 != SlotType.NONE) { + this.drawTexturedModalRect(this.containerWidth + x, + this.containerHeight + y, 0, + 18 * type.ordinal(), 18, 18); + } + } + + protected void drawSlot(final int x, final int y, final SlotType type) { + this.drawSlot(x, y, type, 1.0f, 1.0f, 1.0f); + } + + protected void drawSlot(final int x, final int y) { + this.drawSlot(x, y, SlotType.NONE); + } + + protected void drawBar(final int x, final int y, final float scale) { + this.mc.renderEngine.bindTexture( + new ResourceLocation("mffs", "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(final int x, final int y, final float scale) { + this.mc.renderEngine.bindTexture( + new ResourceLocation("mffs", "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(final int x, final int y, final float scale) { + this.mc.renderEngine.bindTexture( + new ResourceLocation("mffs", "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); + } + } + + public void drawTooltip(final int x, final int y, final String... toolTips) { + if (!GuiScreen.isShiftKeyDown()) { + GL11.glDisable(32826); + RenderHelper.disableStandardItemLighting(); + GL11.glDisable(2896); + GL11.glDisable(2929); + if (toolTips != null) { + int var5 = 0; + for (int var6 = 0; var6 < toolTips.length; ++var6) { + final int var7 = this.fontRendererObj.getStringWidth(toolTips[var6]); + if (var7 > var5) { + var5 = var7; + } + } + int var6 = x + 12; + int var7 = y - 12; + int var8 = 8; + if (toolTips.length > 1) { + var8 += 2 + (toolTips.length - 1) * 10; + } + if (this.guiTop + var7 + var8 + 6 > this.height) { + var7 = this.height - var8 - this.guiTop - 6; + } + zLevel = 300.0f; + final int var9 = -267386864; + this.drawGradientRect(var6 - 3, var7 - 4, var6 + var5 + 3, var7 - 3, + var9, var9); + this.drawGradientRect(var6 - 3, var7 + var8 + 3, var6 + var5 + 3, + var7 + var8 + 4, var9, var9); + this.drawGradientRect(var6 - 3, var7 - 3, var6 + var5 + 3, + var7 + var8 + 3, var9, var9); + this.drawGradientRect(var6 - 4, var7 - 3, var6 - 3, var7 + var8 + 3, + var9, var9); + this.drawGradientRect(var6 + var5 + 3, var7 - 3, var6 + var5 + 4, + var7 + var8 + 3, var9, var9); + final int var10 = 1347420415; + final int var11 = (var10 & 0xFEFEFE) >> 1 | (var10 & 0xFF000000); + this.drawGradientRect(var6 - 3, var7 - 3 + 1, var6 - 3 + 1, + var7 + var8 + 3 - 1, var10, var11); + this.drawGradientRect(var6 + var5 + 2, var7 - 3 + 1, var6 + var5 + 3, + var7 + var8 + 3 - 1, var10, var11); + this.drawGradientRect(var6 - 3, var7 - 3, var6 + var5 + 3, var7 - 3 + 1, + var10, var10); + this.drawGradientRect(var6 - 3, var7 + var8 + 2, var6 + var5 + 3, + var7 + var8 + 3, var11, var11); + for (int var12 = 0; var12 < toolTips.length; ++var12) { + final String var13 = toolTips[var12]; + this.fontRendererObj.drawStringWithShadow(var13, var6, var7, -1); + var7 += 10; + } + this.zLevel = 0.0f; + GL11.glEnable(2929); + GL11.glEnable(2896); + RenderHelper.enableGUIStandardItemLighting(); + GL11.glEnable(32826); + } + } + } + + public enum SlotType { + NONE, + BATTERY, + LIQUID, + ARR_UP, + ARR_DOWN, + ARR_LEFT, + ARR_RIGHT, + ARR_UP_RIGHT, + ARR_UP_LEFT, + ARR_DOWN_LEFT, + ARR_DOWN_RIGHT; + } +} diff --git a/src/main/java/mffs/base/ItemBase.java b/src/main/java/mffs/base/ItemBase.java new file mode 100644 index 0000000..0bae7e7 --- /dev/null +++ b/src/main/java/mffs/base/ItemBase.java @@ -0,0 +1,30 @@ +package mffs.base; + +import java.util.List; +import mffs.MFFSCreativeTab; +import mffs.MFFSHelper; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import universalelectricity.prefab.TranslationHelper; + +public class ItemBase extends Item { + public ItemBase(final String name) { + super(); + this.setUnlocalizedName("mffs:" + name); + this.setCreativeTab(MFFSCreativeTab.INSTANCE); + this.setNoRepair(); + this.iconString = "mffs:" + name; + } + + @Override + public void addInformation(final ItemStack itemStack, + final EntityPlayer player, final List info, + final boolean b) { + final String tooltip = + TranslationHelper.getLocal(this.getUnlocalizedName() + ".tooltip"); + if (tooltip != null && tooltip.length() > 0) { + info.addAll(MFFSHelper.splitStringPerWord(tooltip, 5)); + } + } +} diff --git a/src/main/java/mffs/base/PacketFxs.java b/src/main/java/mffs/base/PacketFxs.java new file mode 100644 index 0000000..1395c93 --- /dev/null +++ b/src/main/java/mffs/base/PacketFxs.java @@ -0,0 +1,55 @@ +package mffs.base; + +import cpw.mods.fml.common.network.simpleimpl.IMessage; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.ByteBufInputStream; +import io.netty.buffer.ByteBufOutputStream; +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import net.minecraft.nbt.CompressedStreamTools; +import net.minecraft.nbt.NBTTagCompound; +import universalelectricity.core.vector.Vector3; + +public class PacketFxs implements IMessage { + Vector3 pos; + NBTTagCompound data; + + public PacketFxs() { + this(null, null); + } + + public PacketFxs(Vector3 pos, NBTTagCompound data) { + this.pos = pos; + this.data = data; + } + + @Override + public void fromBytes(ByteBuf buf) { + NBTTagCompound nbt = null; + try { + nbt = CompressedStreamTools.read( + new DataInputStream(new ByteBufInputStream(buf))); + } catch (IOException e) { + e.printStackTrace(); + } + + this.pos = Vector3.readFromNBT(nbt); + this.data = nbt.getCompoundTag("data"); + } + + @Override + public void toBytes(ByteBuf buf) { + NBTTagCompound nbt = new NBTTagCompound(); + + this.pos.writeToNBT(nbt); + nbt.setTag("data", this.data); + + try { + CompressedStreamTools.write( + nbt, new DataOutputStream(new ByteBufOutputStream(buf))); + } catch (IOException e) { + e.printStackTrace(); + } + } +} diff --git a/src/main/java/mffs/base/PacketFxsHandler.java b/src/main/java/mffs/base/PacketFxsHandler.java new file mode 100644 index 0000000..5d1ecd7 --- /dev/null +++ b/src/main/java/mffs/base/PacketFxsHandler.java @@ -0,0 +1,24 @@ +package mffs.base; + +import cpw.mods.fml.client.FMLClientHandler; +import cpw.mods.fml.common.network.simpleimpl.IMessage; +import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; +import cpw.mods.fml.common.network.simpleimpl.MessageContext; +import mffs.base.TileEntityBase; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; + +public class PacketFxsHandler implements IMessageHandler { + + @Override + public IMessage onMessage(PacketFxs message, MessageContext ctx) { + World world = FMLClientHandler.instance().getWorldClient(); + + TileEntity te = message.pos.getTileEntity(world); + if (te instanceof TileEntityBase) { + ((TileEntityBase) te).onFxsPacket(message.data); + } + + return null; + } +} diff --git a/src/main/java/mffs/base/PacketTile.java b/src/main/java/mffs/base/PacketTile.java new file mode 100644 index 0000000..60bac39 --- /dev/null +++ b/src/main/java/mffs/base/PacketTile.java @@ -0,0 +1,65 @@ +package mffs.base; + +import cpw.mods.fml.common.network.simpleimpl.IMessage; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.ByteBufInputStream; +import io.netty.buffer.ByteBufOutputStream; +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import net.minecraft.nbt.CompressedStreamTools; +import net.minecraft.nbt.NBTTagCompound; +import universalelectricity.core.vector.Vector3; + +public class PacketTile implements IMessage { + Type type; + Vector3 pos; + NBTTagCompound data; + + public PacketTile(Type type, Vector3 pos, NBTTagCompound data) { + this.type = type; + this.pos = pos; + this.data = data; + } + + public PacketTile() {} + + @Override + public void fromBytes(ByteBuf buf) { + try { + NBTTagCompound nbt = CompressedStreamTools.read( + new DataInputStream(new ByteBufInputStream(buf))); + + this.type = Type.values()[nbt.getInteger("type")]; + this.pos = Vector3.readFromNBT(nbt); + this.data = nbt.getCompoundTag("data"); + } catch (IOException e) { + e.printStackTrace(); + } + } + + @Override + public void toBytes(ByteBuf buf) { + try { + NBTTagCompound nbt = new NBTTagCompound(); + + nbt.setInteger("type", this.type.ordinal()); + this.pos.writeToNBT(nbt); + nbt.setTag("data", this.data); + + CompressedStreamTools.write( + nbt, new DataOutputStream(new ByteBufOutputStream(buf))); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public enum Type { + NONE, + FREQUENCY, + TOGGLE_ACTIVATION, + TOGGLE_MODE, + INVENTORY, + STRING, + } +} diff --git a/src/main/java/mffs/base/PacketTileHandler.java b/src/main/java/mffs/base/PacketTileHandler.java new file mode 100644 index 0000000..2e077d4 --- /dev/null +++ b/src/main/java/mffs/base/PacketTileHandler.java @@ -0,0 +1,24 @@ +package mffs.base; + +import cpw.mods.fml.common.network.simpleimpl.IMessage; +import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; +import cpw.mods.fml.common.network.simpleimpl.MessageContext; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; + +public class PacketTileHandler + implements IMessageHandler { + @Override + public IMessage onMessage(PacketTile arg0, MessageContext arg1) { + World w = arg1.getServerHandler().playerEntity.worldObj; + + TileEntity te = arg0.pos.getTileEntity(w); + + if (!(te instanceof TileEntityBase)) + return null; + + ((TileEntityBase)te).onReceivePacket(arg0.type, arg0.data); + + return null; + } +} diff --git a/src/main/java/mffs/base/TileEntityBase.java b/src/main/java/mffs/base/TileEntityBase.java new file mode 100644 index 0000000..586d066 --- /dev/null +++ b/src/main/java/mffs/base/TileEntityBase.java @@ -0,0 +1,133 @@ +package mffs.base; + +import dan200.computercraft.api.peripheral.IPeripheral; +import java.util.ArrayList; +import java.util.List; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import mffs.api.IActivatable; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.network.NetworkManager; +import net.minecraft.network.Packet; +import net.minecraft.network.play.server.S35PacketUpdateTileEntity; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; +import universalelectricity.core.vector.Vector3; +import universalelectricity.prefab.implement.IRedstoneReceptor; +import universalelectricity.prefab.implement.IRotatable; +import universalelectricity.prefab.tile.TileEntityDisableable; + +public abstract class TileEntityBase extends TileEntityDisableable + implements IRotatable, IRedstoneReceptor, IActivatable, IPeripheral { + public boolean isActive; + public boolean isRedstoneActive; + public final List playersUsing; + public float animation; + + public TileEntityBase() { + this.isActive = false; + this.isRedstoneActive = false; + this.playersUsing = new ArrayList<>(); + this.animation = 0.0f; + } + + @Override + public void updateEntity() { + super.updateEntity(); + if (super.ticks % 4L == 0L && this.playersUsing.size() > 0) { + this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord); + } + } + + @Override + public Packet getDescriptionPacket() { + NBTTagCompound nbt = new NBTTagCompound(); + + nbt.setBoolean("isActive", this.isActive); + + return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, + this.getBlockMetadata(), nbt); + } + + @Override + public void onDataPacket(NetworkManager arg0, + S35PacketUpdateTileEntity arg1) { + NBTTagCompound nbt = arg1.func_148857_g(); + + this.isActive = nbt.getBoolean("isActive"); + } + + @SideOnly(Side.CLIENT) + public void onFxsPacket(NBTTagCompound data) {} + + public void onReceivePacket(final PacketTile.Type type, + final NBTTagCompound data) { + if (type == PacketTile.Type.TOGGLE_ACTIVATION) { + this.isRedstoneActive = !this.isRedstoneActive; + this.setActive(this.isRedstoneActive); + } + } + + public boolean isPoweredByRedstone() { + return this.worldObj.isBlockIndirectlyGettingPowered( + this.xCoord, this.yCoord, this.zCoord); + } + + @Override + public void readFromNBT(final NBTTagCompound nbt) { + super.readFromNBT(nbt); + this.isActive = nbt.getBoolean("isActive"); + this.isRedstoneActive = nbt.getBoolean("isRedstoneActive"); + } + + @Override + public void writeToNBT(final NBTTagCompound nbttagcompound) { + super.writeToNBT(nbttagcompound); + nbttagcompound.setBoolean("isActive", this.isActive); + nbttagcompound.setBoolean("isRedstoneActive", this.isRedstoneActive); + } + + @Override + public boolean isActive() { + return this.isActive; + } + + @Override + public void setActive(final boolean flag) { + this.isActive = flag; + this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord); + } + + @Override + public ForgeDirection getDirection(final IBlockAccess world, final int x, + final int y, final int z) { + return ForgeDirection.getOrientation(this.getBlockMetadata()); + } + + @Override + public void setDirection(final World world, final int x, final int y, + final int z, final ForgeDirection facingDirection) { + this.worldObj.setBlockMetadataWithNotify( + this.xCoord, this.yCoord, this.zCoord, facingDirection.ordinal(), 3); + } + + @Override + public void onPowerOn() { + this.setActive(true); + } + + @Override + public void onPowerOff() { + if (!this.isRedstoneActive && !this.worldObj.isRemote) { + this.setActive(false); + } + } + + @Override + public boolean equals(IPeripheral other) { + return this == other; + } +} diff --git a/src/main/java/mffs/base/TileEntityFortron.java b/src/main/java/mffs/base/TileEntityFortron.java new file mode 100644 index 0000000..3c72f1e --- /dev/null +++ b/src/main/java/mffs/base/TileEntityFortron.java @@ -0,0 +1,171 @@ +package mffs.base; + +import mffs.MFFSHelper; +import mffs.Settings; +import mffs.TransferMode; +import mffs.api.ISpecialForceManipulation; +import mffs.api.card.ICard; +import mffs.api.fortron.IFortronFrequency; +import mffs.fortron.FortronHelper; +import mffs.fortron.FrequencyGrid; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTBase; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.network.NetworkManager; +import net.minecraft.network.Packet; +import net.minecraft.network.play.server.S35PacketUpdateTileEntity; +import net.minecraftforge.common.util.ForgeDirection; +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.FluidTank; +import net.minecraftforge.fluids.FluidTankInfo; +import net.minecraftforge.fluids.IFluidHandler; +import universalelectricity.core.vector.Vector3; + +public abstract class TileEntityFortron extends TileEntityFrequency + implements IFluidHandler, IFortronFrequency, ISpecialForceManipulation { + protected FluidTank fortronTank; + private boolean markSendFortron; + + public TileEntityFortron() { + this.fortronTank = new FluidTank(FortronHelper.FLUID_FORTRON, 0, 1000); + this.markSendFortron = true; + } + + @Override + public void updateEntity() { + super.updateEntity(); + if (!Settings.CONSERVE_PACKETS && super.ticks % 60L == 0L) { + this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord); + } + } + + @Override + public void invalidate() { + if (this.markSendFortron) { + MFFSHelper.transferFortron( + this, + FrequencyGrid.instance().getFortronTiles( + this.worldObj, new Vector3(this), 100, this.getFrequency()), + TransferMode.DRAIN, Integer.MAX_VALUE); + } + super.invalidate(); + } + + @Override + public Packet getDescriptionPacket() { + NBTTagCompound nbt = new NBTTagCompound(); + + nbt.setInteger("fortron", this.fortronTank.getFluidAmount()); + nbt.setBoolean("isActive", this.isActive()); + + return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, + this.getBlockMetadata(), nbt); + } + + @Override + public void onDataPacket(NetworkManager arg0, + S35PacketUpdateTileEntity arg1) { + NBTTagCompound nbt = arg1.func_148857_g(); + + this.fortronTank.setFluid( + new FluidStack(FortronHelper.FLUID_FORTRON, nbt.getInteger("fortron"))); + this.isActive = nbt.getBoolean("isActive"); + } + + @Override + public boolean preMove(final int x, final int y, final int z) { + return true; + } + + @Override + public void move(final int x, final int y, final int z) { + this.markSendFortron = false; + } + + @Override + public void postMove() {} + + @Override + public void readFromNBT(final NBTTagCompound nbt) { + super.readFromNBT(nbt); + this.fortronTank.setFluid( + FluidStack.loadFluidStackFromNBT(nbt.getCompoundTag("fortron"))); + } + + @Override + public void writeToNBT(final NBTTagCompound nbt) { + super.writeToNBT(nbt); + if (this.fortronTank.getFluid() != null) { + final NBTTagCompound fortronCompound = new NBTTagCompound(); + this.fortronTank.getFluid().writeToNBT(fortronCompound); + nbt.setTag("fortron", (NBTBase)fortronCompound); + } + } + + @Override + public int fill(final ForgeDirection from, final FluidStack resource, + final boolean doFill) { + if (resource.getFluid() == FortronHelper.FLUID_FORTRON) { + return this.fortronTank.fill(resource, doFill); + } + return 0; + } + + @Override + public boolean canFill(ForgeDirection arg0, Fluid arg1) { + return arg1 == FortronHelper.FLUID_FORTRON && + this.fortronTank.getFluidAmount() < this.fortronTank.getCapacity(); + } + + @Override + public FluidStack drain(final ForgeDirection from, final int maxDrain, + final boolean doDrain) { + return this.fortronTank.drain(maxDrain, doDrain); + } + + @Override + public FluidStack drain(ForgeDirection arg0, FluidStack arg1, boolean arg2) { + if (arg1.getFluid() != FortronHelper.FLUID_FORTRON) + return null; + + return this.fortronTank.drain(arg1.amount, arg2); + } + + @Override + public boolean canDrain(ForgeDirection arg0, Fluid arg1) { + return arg1 == FortronHelper.FLUID_FORTRON && + this.fortronTank.getFluidAmount() > 0; + } + + @Override + public FluidTankInfo[] getTankInfo(ForgeDirection arg0) { + return new FluidTankInfo[] {new FluidTankInfo(this.fortronTank)}; + } + + public void setFortronEnergy(final int joules) { + this.fortronTank.setFluid(FortronHelper.getFortron(joules)); + } + + public int getFortronEnergy() { + return FortronHelper.getAmount(this.fortronTank); + } + + public int getFortronCapacity() { return this.fortronTank.getCapacity(); } + + public int requestFortron(final int joules, final boolean doUse) { + return FortronHelper.getAmount(this.fortronTank.drain(joules, doUse)); + } + + public int provideFortron(final int joules, final boolean doUse) { + return this.fortronTank.fill(FortronHelper.getFortron(joules), doUse); + } + + public ItemStack getCard() { + final ItemStack itemStack = this.getStackInSlot(0); + if (itemStack != null && itemStack.getItem() instanceof ICard) { + return itemStack; + } + return null; + } +} diff --git a/src/main/java/mffs/base/TileEntityFrequency.java b/src/main/java/mffs/base/TileEntityFrequency.java new file mode 100644 index 0000000..91c915a --- /dev/null +++ b/src/main/java/mffs/base/TileEntityFrequency.java @@ -0,0 +1,95 @@ +package mffs.base; + +import icbm.api.IBlockFrequency; +import java.util.HashSet; +import java.util.Set; +import mffs.api.IBiometricIdentifierLink; +import mffs.api.card.ICardLink; +import mffs.api.security.IBiometricIdentifier; +import mffs.fortron.FrequencyGrid; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.IBlockAccess; +import universalelectricity.core.vector.Vector3; + +public abstract class TileEntityFrequency extends TileEntityInventory + implements IBlockFrequency, IBiometricIdentifierLink { + private int frequency; + + @Override + public void initiate() { + FrequencyGrid.instance().register(this); + super.initiate(); + } + + @Override + public void invalidate() { + FrequencyGrid.instance().unregister(this); + super.invalidate(); + } + + @Override + public void onReceivePacket(final PacketTile.Type type, + final NBTTagCompound data) { + super.onReceivePacket(type, data); + if (type == PacketTile.Type.FREQUENCY) { + this.setFrequency(data.getInteger("frequency")); + } + } + + @Override + public void readFromNBT(final NBTTagCompound nbt) { + super.readFromNBT(nbt); + this.setFrequency(nbt.getInteger("frequency")); + } + + @Override + public void writeToNBT(final NBTTagCompound nbt) { + super.writeToNBT(nbt); + nbt.setInteger("frequency", this.getFrequency()); + } + + @Override + public int getFrequency() { + return this.frequency; + } + + @Override + public void setFrequency(final int frequency) { + this.frequency = frequency; + } + + @Override + public IBiometricIdentifier getBiometricIdentifier() { + if (this.getBiometricIdentifiers().size() > 0) { + return (IBiometricIdentifier)this.getBiometricIdentifiers().toArray()[0]; + } + return null; + } + + @Override + public Set getBiometricIdentifiers() { + final Set list = new HashSet<>(); + for (final ItemStack itemStack : this.getCards()) { + if (itemStack != null && itemStack.getItem() instanceof ICardLink) { + final Vector3 linkedPosition = + ((ICardLink)itemStack.getItem()).getLink(itemStack); + final TileEntity tileEntity = + linkedPosition.getTileEntity((IBlockAccess)this.worldObj); + if (linkedPosition == null || + !(tileEntity instanceof IBiometricIdentifier)) { + continue; + } + list.add((IBiometricIdentifier)tileEntity); + } + } + for (final IBlockFrequency tileEntity2 : + FrequencyGrid.instance().get(this.getFrequency())) { + if (tileEntity2 instanceof IBiometricIdentifier) { + list.add((IBiometricIdentifier)tileEntity2); + } + } + return list; + } +} diff --git a/src/main/java/mffs/base/TileEntityInventory.java b/src/main/java/mffs/base/TileEntityInventory.java new file mode 100644 index 0000000..b8915f8 --- /dev/null +++ b/src/main/java/mffs/base/TileEntityInventory.java @@ -0,0 +1,345 @@ +package mffs.base; + +import dan200.computercraft.api.lua.ILuaContext; +import dan200.computercraft.api.lua.LuaException; +import dan200.computercraft.api.peripheral.IComputerAccess; +import java.util.HashSet; +import java.util.Set; +import net.minecraft.entity.Entity; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.ISidedInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTBase; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.network.NetworkManager; +import net.minecraft.network.play.server.S35PacketUpdateTileEntity; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.tileentity.TileEntityChest; +import net.minecraft.world.IBlockAccess; +import net.minecraftforge.common.util.ForgeDirection; +import universalelectricity.core.vector.Vector3; +import universalelectricity.prefab.multiblock.TileEntityMulti; + +public abstract class TileEntityInventory + extends TileEntityBase implements IInventory { + protected ItemStack[] inventory; + + public TileEntityInventory() { + this.inventory = new ItemStack[this.getSizeInventory()]; + } + + // TODO: WTF + // @Override + // public List getPacketUpdate() { + // final List objects = new ArrayList(); + // objects.addAll(super.getPacketUpdate()); + // final NBTTagCompound nbt = new NBTTagCompound(); + // this.writeToNBT(nbt); + // objects.add(nbt); + // return objects; + // } + + @Override + public void onDataPacket(NetworkManager arg0, + S35PacketUpdateTileEntity arg1) { + NBTTagCompound nbt = arg1.func_148857_g(); + + this.readFromNBT(nbt); + } + + // TODO: WTF + // @Override + // public void sendInventoryToClients() { + // final NBTTagCompound nbt = new NBTTagCompound(); + // this.writeToNBT(nbt); + // PacketManager.sendPacketToClients(PacketManager.getPacket("MFFS", this, + // TilePacketType.INVENTORY.ordinal(), nbt)); + // } + + @Override + public ItemStack getStackInSlot(final int i) { + return this.inventory[i]; + } + + @Override + public String getInventoryName() { + return this.getBlockType().getLocalizedName(); + } + + @Override + public boolean hasCustomInventoryName() { + return true; + } + + @Override + public void setInventorySlotContents(final int i, final ItemStack itemstack) { + this.inventory[i] = itemstack; + if (itemstack != null && + itemstack.stackSize > this.getInventoryStackLimit()) { + itemstack.stackSize = this.getInventoryStackLimit(); + } + } + + @Override + public ItemStack decrStackSize(final int i, final int j) { + if (this.inventory[i] == null) { + return null; + } + if (this.inventory[i].stackSize <= j) { + final ItemStack itemstack = this.inventory[i]; + this.inventory[i] = null; + return itemstack; + } + final ItemStack itemstack2 = this.inventory[i].splitStack(j); + if (this.inventory[i].stackSize == 0) { + this.inventory[i] = null; + } + return itemstack2; + } + + @Override + public void openInventory() { + } + + @Override + public void closeInventory() { + } + + @Override + public boolean isUseableByPlayer(final EntityPlayer entityplayer) { + return this.worldObj.getTileEntity(this.xCoord, this.yCoord, this.zCoord) == this; + } + + @Override + public ItemStack getStackInSlotOnClosing(final int slotID) { + if (this.inventory[slotID] != null) { + final ItemStack itemstack = this.inventory[slotID]; + this.inventory[slotID] = null; + return itemstack; + } + return null; + } + + @Override + public int getInventoryStackLimit() { + return 64; + } + + // TODO: what's the equivalent to isInvNameLocalized? + // @Override + // public boolean func_94042_c() { + // return true; + // } + + @Override + public boolean isItemValidForSlot(final int slotID, + final ItemStack itemStack) { + return true; + } + + public boolean canIncreaseStack(final int slotID, final ItemStack itemStack) { + return this.getStackInSlot(slotID) == null || + (this.getStackInSlot(slotID).stackSize + 1 <= 64 && + this.getStackInSlot(slotID).isItemEqual(itemStack)); + } + + public void incrStackSize(final int slot, final ItemStack itemStack) { + if (this.getStackInSlot(slot) == null) { + this.setInventorySlotContents(slot, itemStack.copy()); + } else if (this.getStackInSlot(slot).isItemEqual(itemStack)) { + final ItemStack stackInSlot = this.getStackInSlot(slot); + ++stackInSlot.stackSize; + } + } + + public Set getCards() { + final Set cards = new HashSet<>(); + cards.add(this.getStackInSlot(0)); + return cards; + } + + public ItemStack tryPlaceInPosition(ItemStack itemStack, + final Vector3 position, + final ForgeDirection dir) { + final TileEntity tileEntity = position.getTileEntity((IBlockAccess) this.worldObj); + final ForgeDirection direction = dir.getOpposite(); + if (tileEntity != null && itemStack != null) { + if (tileEntity instanceof TileEntityMulti) { + final Vector3 mainBlockPosition = ((TileEntityMulti) tileEntity).mainBlockPosition; + if (mainBlockPosition != null && + !(mainBlockPosition.getTileEntity((IBlockAccess) this.worldObj) instanceof TileEntityMulti)) { + return this.tryPlaceInPosition(itemStack, mainBlockPosition, + direction); + } + } else if (tileEntity instanceof TileEntityChest) { + final TileEntityChest[] chests = { (TileEntityChest) tileEntity, null }; + for (int i = 2; i < 6; ++i) { + final ForgeDirection searchDirection = ForgeDirection.getOrientation(i); + final Vector3 searchPosition = position.clone(); + searchPosition.modifyPositionFromSide(searchDirection); + if (searchPosition.getTileEntity((IBlockAccess) this.worldObj) != null && + searchPosition.getTileEntity((IBlockAccess) this.worldObj) + .getClass() == chests[0].getClass()) { + chests[1] = (TileEntityChest) searchPosition.getTileEntity( + (IBlockAccess) this.worldObj); + break; + } + } + for (final TileEntityChest chest : chests) { + if (chest != null) { + for (int j = 0; j < chest.getSizeInventory(); ++j) { + itemStack = this.addStackToInventory(j, (IInventory) chest, itemStack); + if (itemStack == null) { + return null; + } + } + } + } + } else if (tileEntity instanceof ISidedInventory) { + final ISidedInventory inventory = (ISidedInventory) tileEntity; + final int[] slots = inventory.getAccessibleSlotsFromSide(direction.ordinal()); + for (int k = 0; k < slots.length; ++k) { + if (inventory.canInsertItem(slots[k], itemStack, + direction.ordinal())) { + itemStack = this.addStackToInventory( + slots[k], (IInventory) inventory, itemStack); + } + if (itemStack == null) { + return null; + } + } + } else if (tileEntity instanceof IInventory) { + final IInventory inventory2 = (IInventory) tileEntity; + for (int i = 0; i < inventory2.getSizeInventory(); ++i) { + itemStack = this.addStackToInventory(i, inventory2, itemStack); + if (itemStack == null) { + return null; + } + } + } + } + if (itemStack.stackSize <= 0) { + return null; + } + return itemStack; + } + + public ItemStack addStackToInventory(final int slotIndex, + final IInventory inventory, + final ItemStack itemStack) { + if (inventory.getSizeInventory() > slotIndex) { + ItemStack stackInInventory = inventory.getStackInSlot(slotIndex); + if (stackInInventory == null) { + inventory.setInventorySlotContents(slotIndex, itemStack); + if (inventory.getStackInSlot(slotIndex) == null) { + return itemStack; + } + return null; + } else if (stackInInventory.isItemEqual(itemStack) && + stackInInventory.isStackable()) { + stackInInventory = stackInInventory.copy(); + final int stackLim = Math.min(inventory.getInventoryStackLimit(), + itemStack.getMaxStackSize()); + final int rejectedAmount = Math.max( + stackInInventory.stackSize + itemStack.stackSize - stackLim, 0); + stackInInventory.stackSize = Math.min(Math.max(stackInInventory.stackSize + itemStack.stackSize - + rejectedAmount, + 0), + inventory.getInventoryStackLimit()); + itemStack.stackSize = rejectedAmount; + inventory.setInventorySlotContents(slotIndex, stackInInventory); + } + } + if (itemStack.stackSize <= 0) { + return null; + } + return itemStack; + } + + public boolean mergeIntoInventory(ItemStack itemStack) { + if (!this.worldObj.isRemote) { + for (final ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) { + if (itemStack != null) { + itemStack = this.tryPlaceInPosition( + itemStack, new Vector3(this).modifyPositionFromSide(direction), + direction); + } + } + if (itemStack != null) { + this.worldObj.spawnEntityInWorld((Entity) new EntityItem( + this.worldObj, this.xCoord + 0.5, (double) (this.yCoord + 1), + this.zCoord + 0.5, itemStack)); + } + } + return false; + } + + @Override + public void readFromNBT(final NBTTagCompound nbttagcompound) { + super.readFromNBT(nbttagcompound); + final NBTTagList nbtTagList = nbttagcompound.getTagList("Items", 10); + this.inventory = new ItemStack[this.getSizeInventory()]; + for (int i = 0; i < nbtTagList.tagCount(); ++i) { + final NBTTagCompound nbttagcompound2 = (NBTTagCompound) nbtTagList.getCompoundTagAt(i); + final byte byte0 = nbttagcompound2.getByte("Slot"); + if (byte0 >= 0 && byte0 < this.inventory.length) { + this.inventory[byte0] = ItemStack.loadItemStackFromNBT(nbttagcompound2); + } + } + } + + @Override + public void writeToNBT(final NBTTagCompound nbttagcompound) { + super.writeToNBT(nbttagcompound); + final NBTTagList nbtTagList = new NBTTagList(); + for (int i = 0; i < this.inventory.length; ++i) { + if (this.inventory[i] != null) { + final NBTTagCompound nbttagcompound2 = new NBTTagCompound(); + nbttagcompound2.setByte("Slot", (byte) i); + this.inventory[i].writeToNBT(nbttagcompound2); + nbtTagList.appendTag((NBTBase) nbttagcompound2); + } + } + nbttagcompound.setTag("Items", (NBTBase) nbtTagList); + } + + @Override + public String getType() { + return this.getInventoryName(); + } + + @Override + public String[] getMethodNames() { + return new String[] { "isActivate", "setActivate" }; + } + + @Override + public Object[] callMethod(IComputerAccess computer, ILuaContext context, + int method, Object[] arguments) + throws LuaException, InterruptedException { + switch (method) { + case 0: { + return new Object[] { this.isActive() }; + } + case 1: { + this.setActive((boolean) arguments[0]); + return null; + } + default: { + throw new LuaException("Invalid method."); + } + } + } + + + @Override + public void attach(final IComputerAccess computer) { + } + + @Override + public void detach(final IComputerAccess computer) { + } +} diff --git a/src/main/java/mffs/base/TileEntityModuleAcceptor.java b/src/main/java/mffs/base/TileEntityModuleAcceptor.java new file mode 100644 index 0000000..137dff3 --- /dev/null +++ b/src/main/java/mffs/base/TileEntityModuleAcceptor.java @@ -0,0 +1,217 @@ +package mffs.base; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Set; + +import mffs.ModularForceFieldSystem; +import mffs.Settings; +import mffs.api.ICache; +import mffs.api.modules.IModule; +import mffs.api.modules.IModuleAcceptor; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; + +public abstract class TileEntityModuleAcceptor + extends TileEntityFortron implements IModuleAcceptor, ICache { + public final HashMap cache; + public int startModuleIndex; + public int endModuleIndex; + protected int capacityBase; + protected int capacityBoost; + + public TileEntityModuleAcceptor() { + this.cache = new HashMap<>(); + this.startModuleIndex = 0; + this.endModuleIndex = this.getSizeInventory() - 1; + this.capacityBase = 500; + this.capacityBoost = 5; + } + + @Override + public void initiate() { + super.initiate(); + super.fortronTank.setCapacity( + (this.getModuleCount(ModularForceFieldSystem.itemModuleCapacity, + new int[0]) * + this.capacityBoost + + this.capacityBase) * + 1000); + } + + public void consumeCost() { + if (this.getFortronCost() > 0) { + this.requestFortron(this.getFortronCost(), true); + } + } + + @Override + public ItemStack getModule(final IModule module) { + final String cacheID = "getModule_" + module.hashCode(); + if (Settings.USE_CACHE && this.cache.containsKey(cacheID) && + this.cache.get(cacheID) instanceof ItemStack) { + return (ItemStack) this.cache.get(cacheID); + } + final ItemStack returnStack = new ItemStack((Item) module, 0); + for (final ItemStack comparedModule : this.getModuleStacks(new int[0])) { + if (comparedModule.getItem() == module) { + final ItemStack itemStack = returnStack; + itemStack.stackSize += comparedModule.stackSize; + } + } + if (Settings.USE_CACHE) { + this.cache.put(cacheID, returnStack.copy()); + } + return returnStack; + } + + @Override + public int getModuleCount(final IModule module, final int... slots) { + int count = 0; + if (module != null) { + String cacheID = "getModuleCount_" + module.hashCode(); + if (slots != null) { + cacheID = cacheID + "_" + Arrays.hashCode(slots); + } + if (Settings.USE_CACHE && this.cache.containsKey(cacheID) && + this.cache.get(cacheID) instanceof Integer) { + return (int) this.cache.get(cacheID); + } + if (slots != null && slots.length > 0) { + for (final int slotID : slots) { + if (this.getStackInSlot(slotID) != null && + this.getStackInSlot(slotID).getItem() == module) { + count += this.getStackInSlot(slotID).stackSize; + } + } + } else { + for (final ItemStack itemStack : this.getModuleStacks(new int[0])) { + if (itemStack.getItem() == module) { + count += itemStack.stackSize; + } + } + } + if (Settings.USE_CACHE) { + this.cache.put(cacheID, count); + } + } + return count; + } + + @Override + public Set getModuleStacks(final int... slots) { + String cacheID = "getModuleStacks_"; + if (slots != null) { + cacheID += Arrays.hashCode(slots); + } + if (Settings.USE_CACHE && this.cache.containsKey(cacheID) && + this.cache.get(cacheID) instanceof Set) { + return (Set) this.cache.get(cacheID); + } + final Set modules = new HashSet<>(); + if (slots == null || slots.length <= 0) { + for (int slotID = this.startModuleIndex; slotID <= this.endModuleIndex; ++slotID) { + final ItemStack itemStack = this.getStackInSlot(slotID); + if (itemStack != null && itemStack.getItem() instanceof IModule) { + modules.add(itemStack); + } + } + } else { + for (final int slotID2 : slots) { + final ItemStack itemStack2 = this.getStackInSlot(slotID2); + if (itemStack2 != null && itemStack2.getItem() instanceof IModule) { + modules.add(itemStack2); + } + } + } + if (Settings.USE_CACHE) { + this.cache.put(cacheID, modules); + } + return modules; + } + + @Override + public Set getModules(final int... slots) { + String cacheID = "getModules_"; + if (slots != null) { + cacheID += Arrays.hashCode(slots); + } + if (Settings.USE_CACHE && this.cache.containsKey(cacheID) && + this.cache.get(cacheID) instanceof Set) { + return (Set) this.cache.get(cacheID); + } + final Set modules = new HashSet<>(); + if (slots == null || slots.length <= 0) { + for (int slotID = this.startModuleIndex; slotID <= this.endModuleIndex; ++slotID) { + final ItemStack itemStack = this.getStackInSlot(slotID); + if (itemStack != null && itemStack.getItem() instanceof IModule) { + modules.add((IModule) itemStack.getItem()); + } + } + } else { + for (final int slotID2 : slots) { + final ItemStack itemStack2 = this.getStackInSlot(slotID2); + if (itemStack2 != null && itemStack2.getItem() instanceof IModule) { + modules.add((IModule) itemStack2.getItem()); + } + } + } + if (Settings.USE_CACHE) { + this.cache.put(cacheID, modules); + } + return modules; + } + + @Override + public int getFortronCost() { + final String cacheID = "getFortronCost"; + if (Settings.USE_CACHE && this.cache.containsKey(cacheID) && + this.cache.get(cacheID) instanceof Integer) { + return (int) this.cache.get(cacheID); + } + float cost = 0.0f; + for (final ItemStack itemStack : this.getModuleStacks(new int[0])) { + if (itemStack != null) { + cost += itemStack.stackSize * + ((IModule) itemStack.getItem()).getFortronCost(this.getAmplifier()); + } + } + final int result = Math.round(cost); + if (Settings.USE_CACHE) { + this.cache.put(cacheID, result); + } + return result; + } + + protected float getAmplifier() { + return 1.0f; + } + + @Override + public void markDirty() { + super.markDirty(); + super.fortronTank.setCapacity( + (this.getModuleCount(ModularForceFieldSystem.itemModuleCapacity, + new int[0]) * + this.capacityBoost + + this.capacityBase) * + 1000); + this.clearCache(); + } + + @Override + public Object getCache(final String cacheID) { + return this.cache.get(cacheID); + } + + @Override + public void clearCache(final String cacheID) { + this.cache.remove(cacheID); + } + + @Override + public void clearCache() { + this.cache.clear(); + } +} diff --git a/src/main/java/mffs/base/TileEntityUniversalEnergy.java b/src/main/java/mffs/base/TileEntityUniversalEnergy.java new file mode 100644 index 0000000..d9da3e4 --- /dev/null +++ b/src/main/java/mffs/base/TileEntityUniversalEnergy.java @@ -0,0 +1,64 @@ +package mffs.base; + +import calclavia.lib.IUniversalEnergyTile; +import java.util.EnumSet; +import net.minecraftforge.common.util.ForgeDirection; +import universalelectricity.core.UniversalElectricity; +import universalelectricity.core.electricity.ElectricityNetworkHelper; +import universalelectricity.core.electricity.ElectricityPack; + +public abstract class TileEntityUniversalEnergy + extends TileEntityModuleAcceptor implements IUniversalEnergyTile { + public double prevWatts; + public double wattsReceived; + + public TileEntityUniversalEnergy() { this.wattsReceived = 0.0; } + + @Override + public void updateEntity() { + super.updateEntity(); + this.prevWatts = this.wattsReceived; + if (!this.worldObj.isRemote) { + if (!this.isDisabled()) { + final ElectricityPack electricityPack = + ElectricityNetworkHelper.consumeFromMultipleSides( + this, this.getConsumingSides(), this.getRequest()); + this.onReceive(electricityPack); + } else { + ElectricityNetworkHelper.consumeFromMultipleSides( + this, new ElectricityPack()); + } + } + } + + protected EnumSet getConsumingSides() { + return ElectricityNetworkHelper.getDirections(this); + } + + public ElectricityPack getRequest() { return new ElectricityPack(); } + + public void onReceive(final ElectricityPack electricityPack) { + if (UniversalElectricity.isVoltageSensitive && + electricityPack.voltage > this.getVoltage()) { + return; + } + this.wattsReceived = Math.min( + this.wattsReceived + electricityPack.getWatts(), this.getWattBuffer()); + } + + public double getWattBuffer() { return this.getRequest().getWatts() * 2.0; } + + @Override + public double getVoltage() { + return 120.0; + } + + public ElectricityPack produce(double watts) { + ElectricityPack pack = + new ElectricityPack(watts / this.getVoltage(), this.getVoltage()); + ElectricityPack remaining = + ElectricityNetworkHelper.produceFromMultipleSides(this, pack); + + return remaining; + } +} diff --git a/src/main/java/mffs/block/BlockBiometricIdentifier.java b/src/main/java/mffs/block/BlockBiometricIdentifier.java new file mode 100644 index 0000000..7de5e46 --- /dev/null +++ b/src/main/java/mffs/block/BlockBiometricIdentifier.java @@ -0,0 +1,16 @@ +package mffs.block; + +import mffs.tileentity.TileEntityBiometricIdentifier; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; + +public class BlockBiometricIdentifier extends BlockMachineBlock { + public BlockBiometricIdentifier() { + super("biometricIdentifier"); + } + + @Override + public TileEntity createNewTileEntity(final World world, int meta) { + return new TileEntityBiometricIdentifier(); + } +} diff --git a/src/main/java/mffs/block/BlockCoercionDeriver.java b/src/main/java/mffs/block/BlockCoercionDeriver.java new file mode 100644 index 0000000..0699d5d --- /dev/null +++ b/src/main/java/mffs/block/BlockCoercionDeriver.java @@ -0,0 +1,18 @@ +package mffs.block; + +import mffs.base.BlockMachine; +import mffs.tileentity.TileEntityCoercionDeriver; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; + +public class BlockCoercionDeriver extends BlockMachine { + public BlockCoercionDeriver() { + super("coercionDeriver"); + this.setBlockBounds(0.0f, 0.0f, 0.0f, 1.0f, 0.8f, 1.0f); + } + + @Override + public TileEntity createNewTileEntity(final World world, int meta) { + return new TileEntityCoercionDeriver(); + } +} diff --git a/src/main/java/mffs/block/BlockForceField.java b/src/main/java/mffs/block/BlockForceField.java new file mode 100644 index 0000000..38ea235 --- /dev/null +++ b/src/main/java/mffs/block/BlockForceField.java @@ -0,0 +1,323 @@ +package mffs.block; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import java.util.Arrays; +import java.util.List; +import java.util.Random; +import mffs.ModularForceFieldSystem; +import mffs.api.IForceFieldBlock; +import mffs.api.IProjector; +import mffs.api.fortron.IFortronStorage; +import mffs.api.modules.IModule; +import mffs.api.security.IBiometricIdentifier; +import mffs.api.security.Permission; +import mffs.base.BlockBase; +import mffs.render.RenderForceField; +import mffs.tileentity.TileEntityForceField; +import micdoodle8.mods.galacticraft.api.block.IPartialSealableBlock; +import net.minecraft.block.Block; +import net.minecraft.block.material.Material; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLiving; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraft.potion.Potion; +import net.minecraft.potion.PotionEffect; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.util.DamageSource; +import net.minecraft.util.IIcon; +import net.minecraft.util.MovingObjectPosition; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; +import universalelectricity.core.vector.Vector3; +import universalelectricity.prefab.CustomDamageSource; + +public class BlockForceField + extends BlockBase implements IForceFieldBlock, IPartialSealableBlock { + public BlockForceField() { + super("forceField", Material.glass); + this.setBlockUnbreakable(); + this.setResistance(999.0f); + this.setCreativeTab((CreativeTabs)null); + } + + @Override + public boolean isOpaqueCube() { + return false; + } + + @Override + public boolean renderAsNormalBlock() { + return false; + } + + @Override + protected boolean canSilkHarvest() { + return false; + } + + @Override + public int quantityDropped(final Random random) { + return 0; + } + + @Override + @SideOnly(Side.CLIENT) + public int getRenderBlockPass() { + return 1; + } + + @Override + @SideOnly(Side.CLIENT) + public int getRenderType() { + return RenderForceField.ID; + } + + @Override + @SideOnly(Side.CLIENT) + public boolean shouldSideBeRendered(final IBlockAccess par1IBlockAccess, + final int par2, final int par3, + final int par4, final int par5) { + final Block i1 = par1IBlockAccess.getBlock(par2, par3, par4); + return i1 != this && + super.shouldSideBeRendered(par1IBlockAccess, par2, par3, par4, par5); + } + + @Override + public void onBlockClicked(final World world, final int x, final int y, + final int z, final EntityPlayer entityPlayer) { + final TileEntity tileEntity = world.getTileEntity(x, y, z); + if (tileEntity instanceof TileEntityForceField && + ((TileEntityForceField)tileEntity).getProjector() != null) { + for (final ItemStack moduleStack : + ((TileEntityForceField)tileEntity) + .getProjector() + .getModuleStacks(((TileEntityForceField)tileEntity) + .getProjector() + .getModuleSlots())) { + if (((IModule)moduleStack.getItem()) + .onCollideWithForceField(world, x, y, z, (Entity)entityPlayer, + moduleStack)) { + return; + } + } + } + } + + @Override + public AxisAlignedBB getCollisionBoundingBoxFromPool(final World world, + final int x, final int y, + final int z) { + if (this.getProjector((IBlockAccess)world, x, y, z) != null) { + final IBiometricIdentifier BiometricIdentifier = + this.getProjector((IBlockAccess)world, x, y, z) + .getBiometricIdentifier(); + final List entities = world.getEntitiesWithinAABB( + EntityPlayer.class, AxisAlignedBB.getBoundingBox( + (double)x, (double)y, (double)z, + (double)(x + 1), y + 0.9, (double)(z + 1))); + for (final EntityPlayer entityPlayer : (List)entities) { + if (entityPlayer != null && entityPlayer.isSneaking()) { + if (entityPlayer.capabilities.isCreativeMode) { + return null; + } + if (BiometricIdentifier != null && + BiometricIdentifier.isAccessGranted( + entityPlayer.getDisplayName(), Permission.FORCE_FIELD_WARP)) { + return null; + } + continue; + } + } + } + final float f = 0.0625f; + return AxisAlignedBB.getBoundingBox( + (double)(x + f), (double)(y + f), (double)(z + f), (double)(x + 1 - f), + (double)(y + 1 - f), (double)(z + 1 - f)); + } + + @Override + public void onEntityCollidedWithBlock(final World world, final int x, + final int y, final int z, + final Entity entity) { + final TileEntity tileEntity = world.getTileEntity(x, y, z); + if (tileEntity instanceof TileEntityForceField && + this.getProjector((IBlockAccess)world, x, y, z) != null) { + for (final ItemStack moduleStack : + ((TileEntityForceField)tileEntity) + .getProjector() + .getModuleStacks(((TileEntityForceField)tileEntity) + .getProjector() + .getModuleSlots())) { + if (((IModule)moduleStack.getItem()) + .onCollideWithForceField(world, x, y, z, entity, moduleStack)) { + return; + } + } + final IBiometricIdentifier biometricIdentifier = + this.getProjector((IBlockAccess)world, x, y, z) + .getBiometricIdentifier(); + if (new Vector3(entity).distanceTo(new Vector3(x, y, z).add(0.4)) < 0.5 && + entity instanceof EntityLiving && !world.isRemote) { + ((EntityLiving)entity) + .addPotionEffect(new PotionEffect(Potion.confusion.id, 80, 3)); + ((EntityLiving)entity) + .addPotionEffect(new PotionEffect(Potion.moveSlowdown.id, 20, 1)); + boolean hasPermission = false; + final List entities = world.getEntitiesWithinAABB( + EntityPlayer.class, AxisAlignedBB.getBoundingBox( + (double)x, (double)y, (double)z, + (double)(x + 1), y + 0.9, (double)(z + 1))); + for (final EntityPlayer entityPlayer : (List)entities) { + if (entityPlayer != null && entityPlayer.isSneaking()) { + if (entityPlayer.capabilities.isCreativeMode) { + hasPermission = true; + break; + } + if (biometricIdentifier == null || + !biometricIdentifier.isAccessGranted( + entityPlayer.getDisplayName(), + Permission.FORCE_FIELD_WARP)) { + continue; + } + hasPermission = true; + } + } + if (!hasPermission) { + entity.attackEntityFrom( + (DamageSource)CustomDamageSource.electrocution, + Integer.MAX_VALUE); + } + } + } + } + + @Override + public IIcon getIcon(final IBlockAccess iBlockAccess, final int x, + final int y, final int z, final int side) { + final TileEntity tileEntity = iBlockAccess.getTileEntity(x, y, z); + if (tileEntity instanceof TileEntityForceField) { + final ItemStack checkStack = ((TileEntityForceField)tileEntity).camoStack; + if (checkStack != null) { + try { + final Block block = Block.getBlockFromItem(checkStack.getItem()); + final Integer[] allowedRenderTypes = { + 0, 1, 4, 31, 20, 39, 5, 13, 23, 6, 8, 7, 12, 29, 30, 14, 16, 17}; + if (Arrays.asList(allowedRenderTypes) + .contains(block.getRenderType())) { + final IIcon icon = block.getIcon(side, checkStack.getItemDamage()); + if (icon != null) { + return icon; + } + } + } catch (final Exception e) { + e.printStackTrace(); + } + } + } + return this.getIcon(side, iBlockAccess.getBlockMetadata(x, y, z)); + } + + @Override + public int colorMultiplier(final IBlockAccess iBlockAccess, final int x, + final int y, final int z) { + try { + final TileEntity tileEntity = iBlockAccess.getTileEntity(x, y, z); + if (tileEntity instanceof TileEntityForceField) { + final ItemStack checkStack = + ((TileEntityForceField)tileEntity).camoStack; + if (checkStack != null) { + try { + return Block.getBlockFromItem(checkStack.getItem()) + .colorMultiplier(iBlockAccess, x, y, x); + } catch (final Exception e) { + e.printStackTrace(); + } + } + } + } catch (final Exception e2) { + e2.printStackTrace(); + } + return super.colorMultiplier(iBlockAccess, x, y, z); + } + + @Override + public int getLightValue(final IBlockAccess iBlockAccess, final int x, + final int y, final int z) { + try { + final TileEntity tileEntity = iBlockAccess.getTileEntity(x, y, z); + if (tileEntity instanceof TileEntityForceField) { + final IProjector zhuYao = + ((TileEntityForceField)tileEntity).getProjectorSafe(); + if (zhuYao instanceof IProjector) { + return (int)(Math.min(zhuYao.getModuleCount( + ModularForceFieldSystem.itemModuleGlow, + new int[0]), + 64) / + 64.0f * 15.0f); + } + } + } catch (final Exception e) { + e.printStackTrace(); + } + return 0; + } + + @Override + public float getExplosionResistance(final Entity entity, final World world, + final int x, final int y, final int z, + final double d, final double d1, + final double d2) { + return 2.1474836E9f; + } + + @Override + public TileEntity createNewTileEntity(final World world, int meta) { + return new TileEntityForceField(); + } + + @Override + public void weakenForceField(final World world, final int x, final int y, + final int z, final int joules) { + final IProjector projector = + this.getProjector((IBlockAccess)world, x, y, z); + if (projector != null) { + ((IFortronStorage)projector).provideFortron(joules, true); + } + world.setBlock(x, y, z, Blocks.air, 0, 3); + } + + @Override + public ItemStack getPickBlock(final MovingObjectPosition target, + final World world, final int x, final int y, + final int z) { + return null; + } + + @Override + public IProjector getProjector(final IBlockAccess iBlockAccess, final int x, + final int y, final int z) { + final TileEntity tileEntity = iBlockAccess.getTileEntity(x, y, z); + if (tileEntity instanceof TileEntityForceField) { + return ((TileEntityForceField)tileEntity).getProjector(); + } + return null; + } + + @Override + public boolean isSealed(World world, int x, int y, int z, + ForgeDirection direction) { + return true; + } + + @Override + public void registerBlockIcons(IIconRegister p_149651_1_) { + this.blockIcon = p_149651_1_.registerIcon("mffs:forceField"); + } +} diff --git a/src/main/java/mffs/block/BlockForceFieldProjector.java b/src/main/java/mffs/block/BlockForceFieldProjector.java new file mode 100644 index 0000000..f5482f3 --- /dev/null +++ b/src/main/java/mffs/block/BlockForceFieldProjector.java @@ -0,0 +1,40 @@ +package mffs.block; + +import mffs.base.BlockMachine; +import mffs.tileentity.TileEntityForceFieldProjector; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; + +public class BlockForceFieldProjector extends BlockMachine { + public BlockForceFieldProjector() { + super("projector"); + this.setBlockBounds(0.0f, 0.0f, 0.0f, 1.0f, 0.8f, 1.0f); + } + + @Override + public TileEntity createNewTileEntity(final World world, int meta) { + return new TileEntityForceFieldProjector(); + } + + @Override + public boolean onMachineActivated(final World world, final int i, final int j, final int k, + final EntityPlayer entityplayer, final int par6, + final float par7, final float par8, final float par9) { + final TileEntityForceFieldProjector tileentity = (TileEntityForceFieldProjector) world.getTileEntity(i, j, k); + return !tileentity.isDisabled() && + super.onMachineActivated(world, i, j, k, entityplayer, par6, par7, par8, + par9); + } + + public int getLightValue(final IBlockAccess iBlockAccess, final int x, + final int y, final int z) { + final TileEntity tileEntity = iBlockAccess.getTileEntity(x, y, z); + if (tileEntity instanceof TileEntityForceFieldProjector && + ((TileEntityForceFieldProjector) tileEntity).getMode() != null) { + return 10; + } + return super.getLightValue(iBlockAccess, x, y, z); + } +} diff --git a/src/main/java/mffs/block/BlockForceManipulator.java b/src/main/java/mffs/block/BlockForceManipulator.java new file mode 100644 index 0000000..5fb9d05 --- /dev/null +++ b/src/main/java/mffs/block/BlockForceManipulator.java @@ -0,0 +1,70 @@ +package mffs.block; + +import mffs.base.BlockMachine; +import mffs.tileentity.TileEntityForceManipulator; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.MathHelper; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; + +public class BlockForceManipulator extends BlockMachine { + public BlockForceManipulator() { + super("manipulator"); + } + + public static int determineOrientation(final World world, final int x, + final int y, final int z, + final EntityPlayer entityPlayer) { + if (MathHelper.abs((float) ((Entity) entityPlayer).posX - x) < 2.0f && + MathHelper.abs((float) ((Entity) entityPlayer).posZ - z) < 2.0f) { + final double var5 = ((Entity) entityPlayer).posY + 1.82 - ((Entity) entityPlayer).yOffset; + if (var5 - y > 2.0) { + return 1; + } + if (y - var5 > 0.0) { + return 0; + } + } + final int var6 = MathHelper.floor_double( + ((Entity) entityPlayer).rotationYaw * 4.0f / 360.0f + 0.5) & + 0x3; + return (var6 == 0) + ? 2 + : ((var6 == 1) ? 5 : ((var6 == 2) ? 3 : ((var6 == 3) ? 4 : 0))); + } + + @Override + public void onBlockPlacedBy(final World world, final int x, final int y, + final int z, + final EntityLivingBase par5EntityLiving, + final ItemStack stack) { + final int metadata = determineOrientation( + world, x, y, z, + (EntityPlayer) par5EntityLiving); // TODO: ClassCastException? + world.setBlockMetadataWithNotify(x, y, z, metadata, 2); + } + + @Override + public boolean onUseWrench(final World world, final int x, final int y, + final int z, final EntityPlayer par5EntityPlayer, + final int side, final float hitX, final float hitY, + final float hitZ) { + final int mask = 7; + final int rotMeta = world.getBlockMetadata(x, y, z); + final int masked = rotMeta & ~mask; + final ForgeDirection orientation = ForgeDirection.getOrientation(rotMeta & mask); + final ForgeDirection rotated = orientation.getRotation(ForgeDirection.getOrientation(side)); + world.setBlockMetadataWithNotify(x, y, z, + (rotated.ordinal() & mask) | masked, 3); + return true; + } + + @Override + public TileEntity createNewTileEntity(final World world, int meta) { + return new TileEntityForceManipulator(); + } +} diff --git a/src/main/java/mffs/block/BlockFortronCapacitor.java b/src/main/java/mffs/block/BlockFortronCapacitor.java new file mode 100644 index 0000000..be56daa --- /dev/null +++ b/src/main/java/mffs/block/BlockFortronCapacitor.java @@ -0,0 +1,17 @@ +package mffs.block; + +import mffs.base.BlockMachine; +import mffs.tileentity.TileEntityFortronCapacitor; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; + +public class BlockFortronCapacitor extends BlockMachine { + public BlockFortronCapacitor() { + super("fortronCapacitor"); + } + + @Override + public TileEntity createNewTileEntity(final World world, int meta) { + return new TileEntityFortronCapacitor(); + } +} diff --git a/src/main/java/mffs/block/BlockInterdictionMatrix.java b/src/main/java/mffs/block/BlockInterdictionMatrix.java new file mode 100644 index 0000000..767ebe4 --- /dev/null +++ b/src/main/java/mffs/block/BlockInterdictionMatrix.java @@ -0,0 +1,16 @@ +package mffs.block; + +import mffs.tileentity.TileEntityInterdictionMatrix; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; + +public class BlockInterdictionMatrix extends BlockMachineBlock { + public BlockInterdictionMatrix() { + super("interdictionMatrix"); + } + + @Override + public TileEntity createNewTileEntity(final World world, int meta) { + return new TileEntityInterdictionMatrix(); + } +} diff --git a/src/main/java/mffs/block/BlockMachineBlock.java b/src/main/java/mffs/block/BlockMachineBlock.java new file mode 100644 index 0000000..719e471 --- /dev/null +++ b/src/main/java/mffs/block/BlockMachineBlock.java @@ -0,0 +1,63 @@ +package mffs.block; + +import mffs.base.BlockMachine; +import mffs.base.TileEntityBase; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.IIcon; +import net.minecraft.world.IBlockAccess; + +public abstract class BlockMachineBlock extends BlockMachine { + protected IIcon blockIconTop; + protected IIcon blockIconOn; + protected IIcon blockIconTopOn; + + public BlockMachineBlock(final String name) { + super(name); + } + + @Override + public IIcon getIcon(final IBlockAccess par1IBlockAccess, final int x, + final int y, final int z, final int side) { + final TileEntity tileEntity = par1IBlockAccess.getTileEntity(x, y, z); + if (tileEntity instanceof TileEntityBase && + ((TileEntityBase) tileEntity).isActive()) { + if (side == 0 || side == 1) { + return this.blockIconTopOn; + } + return this.blockIconOn; + } else { + if (side == 0 || side == 1) { + return this.blockIconTop; + } + return this.blockIcon; + } + } + + @Override + public void registerBlockIcons(final IIconRegister reg) { + this.blockIcon = reg.registerIcon( + this.getUnlocalizedName().replace("tile.", "")); + this.blockIconTop = reg.registerIcon( + this.getUnlocalizedName().replace("tile.", "") + "_top"); + this.blockIconOn = reg.registerIcon( + this.getUnlocalizedName().replace("tile.", "") + "_on"); + this.blockIconTopOn = reg.registerIcon( + this.getUnlocalizedName().replace("tile.", "") + "_top_on"); + } + + @Override + public boolean isOpaqueCube() { + return true; + } + + @Override + public boolean renderAsNormalBlock() { + return true; + } + + @Override + public int getRenderType() { + return 0; + } +} diff --git a/src/main/java/mffs/card/ItemCard.java b/src/main/java/mffs/card/ItemCard.java new file mode 100644 index 0000000..5a35d37 --- /dev/null +++ b/src/main/java/mffs/card/ItemCard.java @@ -0,0 +1,11 @@ +package mffs.card; + +import mffs.api.card.ICard; +import mffs.base.ItemBase; + +public class ItemCard extends ItemBase implements ICard { + public ItemCard(final String name) { + super(name); + this.setMaxStackSize(1); + } +} diff --git a/src/main/java/mffs/container/ContainerBiometricIdentifier.java b/src/main/java/mffs/container/ContainerBiometricIdentifier.java new file mode 100644 index 0000000..aa6adde --- /dev/null +++ b/src/main/java/mffs/container/ContainerBiometricIdentifier.java @@ -0,0 +1,25 @@ +package mffs.container; + +import mffs.base.ContainerBase; +import mffs.slot.SlotActive; +import mffs.slot.SlotBase; +import mffs.tileentity.TileEntityBiometricIdentifier; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.Slot; + +public class ContainerBiometricIdentifier extends ContainerBase { + public ContainerBiometricIdentifier(final EntityPlayer player, + final TileEntityBiometricIdentifier tileentity) { + super((IInventory) tileentity); + this.addSlotToContainer((Slot) new SlotActive(tileentity, 0, 88, 91)); + this.addSlotToContainer((Slot) new SlotBase(tileentity, 1, 8, 46)); + this.addSlotToContainer((Slot) new SlotActive(tileentity, 2, 8, 91)); + for (int var4 = 0; var4 < 9; ++var4) { + this.addSlotToContainer( + (Slot) new SlotActive(tileentity, 3 + var4, 8 + var4 * 18, 111)); + } + this.addSlotToContainer((Slot) new SlotBase(tileentity, 12, 8, 66)); + this.addPlayerInventory(player); + } +} diff --git a/src/main/java/mffs/container/ContainerCoercionDeriver.java b/src/main/java/mffs/container/ContainerCoercionDeriver.java new file mode 100644 index 0000000..ecc5797 --- /dev/null +++ b/src/main/java/mffs/container/ContainerCoercionDeriver.java @@ -0,0 +1,23 @@ +package mffs.container; + +import mffs.base.ContainerBase; +import mffs.slot.SlotBase; +import mffs.slot.SlotCard; +import mffs.tileentity.TileEntityCoercionDeriver; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.Slot; + +public class ContainerCoercionDeriver extends ContainerBase { + public ContainerCoercionDeriver(final EntityPlayer player, + final TileEntityCoercionDeriver tileEntity) { + super((IInventory) tileEntity); + this.addSlotToContainer((Slot) new SlotCard(tileEntity, 0, 9, 41)); + this.addSlotToContainer((Slot) new SlotBase(tileEntity, 1, 9, 83)); + this.addSlotToContainer((Slot) new SlotBase(tileEntity, 2, 29, 83)); + this.addSlotToContainer((Slot) new SlotBase(tileEntity, 3, 154, 67)); + this.addSlotToContainer((Slot) new SlotBase(tileEntity, 4, 154, 87)); + this.addSlotToContainer((Slot) new SlotBase(tileEntity, 5, 154, 47)); + this.addPlayerInventory(player); + } +} diff --git a/src/main/java/mffs/container/ContainerForceFieldProjector.java b/src/main/java/mffs/container/ContainerForceFieldProjector.java new file mode 100644 index 0000000..7edb2c3 --- /dev/null +++ b/src/main/java/mffs/container/ContainerForceFieldProjector.java @@ -0,0 +1,38 @@ +package mffs.container; + +import mffs.base.ContainerBase; +import mffs.slot.SlotBase; +import mffs.slot.SlotCard; +import mffs.tileentity.TileEntityForceFieldProjector; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.Slot; + +public class ContainerForceFieldProjector extends ContainerBase { + public ContainerForceFieldProjector(final EntityPlayer player, + final TileEntityForceFieldProjector tileEntity) { + super((IInventory) tileEntity); + this.addSlotToContainer((Slot) new SlotCard(tileEntity, 0, 10, 89)); + this.addSlotToContainer((Slot) new SlotCard(tileEntity, 1, 28, 89)); + this.addSlotToContainer((Slot) new SlotBase(tileEntity, 2, 118, 45)); + int i = 3; + for (int xSlot = 0; xSlot < 4; ++xSlot) { + for (int ySlot = 0; ySlot < 4; ++ySlot) { + if ((xSlot != 1 || ySlot != 1) && (xSlot != 2 || ySlot != 2) && + (xSlot != 1 || ySlot != 2) && (xSlot != 2 || ySlot != 1)) { + this.addSlotToContainer((Slot) new SlotBase( + tileEntity, i, 91 + 18 * xSlot, 18 + 18 * ySlot)); + ++i; + } + } + } + for (int xSlot = 0; xSlot < 3; ++xSlot) { + for (int ySlot = 0; ySlot < 2; ++ySlot) { + this.addSlotToContainer((Slot) new SlotBase( + tileEntity, i, 19 + 18 * xSlot, 36 + 18 * ySlot)); + ++i; + } + } + this.addPlayerInventory(player); + } +} diff --git a/src/main/java/mffs/container/ContainerForceManipulator.java b/src/main/java/mffs/container/ContainerForceManipulator.java new file mode 100644 index 0000000..2dfcd1a --- /dev/null +++ b/src/main/java/mffs/container/ContainerForceManipulator.java @@ -0,0 +1,38 @@ +package mffs.container; + +import mffs.base.ContainerBase; +import mffs.slot.SlotBase; +import mffs.slot.SlotCard; +import mffs.tileentity.TileEntityForceManipulator; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.Slot; + +public class ContainerForceManipulator extends ContainerBase { + public ContainerForceManipulator( + final EntityPlayer player, final TileEntityForceManipulator tileEntity) { + super((IInventory) tileEntity); + this.addSlotToContainer((Slot) new SlotCard(tileEntity, 0, 73, 91)); + this.addSlotToContainer((Slot) new SlotCard(tileEntity, 1, 91, 91)); + this.addSlotToContainer((Slot) new SlotBase(tileEntity, 2, 118, 45)); + int i = 3; + for (int xSlot = 0; xSlot < 4; ++xSlot) { + for (int ySlot = 0; ySlot < 4; ++ySlot) { + if ((xSlot != 1 || ySlot != 1) && (xSlot != 2 || ySlot != 2) && + (xSlot != 1 || ySlot != 2) && (xSlot != 2 || ySlot != 1)) { + this.addSlotToContainer((Slot) new SlotBase( + tileEntity, i, 91 + 18 * xSlot, 18 + 18 * ySlot)); + ++i; + } + } + } + for (int xSlot = 0; xSlot < 3; ++xSlot) { + for (int ySlot = 0; ySlot < 2; ++ySlot) { + this.addSlotToContainer((Slot) new SlotBase( + tileEntity, i, 31 + 18 * xSlot, 19 + 18 * ySlot)); + ++i; + } + } + this.addPlayerInventory(player); + } +} diff --git a/src/main/java/mffs/container/ContainerFortronCapacitor.java b/src/main/java/mffs/container/ContainerFortronCapacitor.java new file mode 100644 index 0000000..c566db5 --- /dev/null +++ b/src/main/java/mffs/container/ContainerFortronCapacitor.java @@ -0,0 +1,25 @@ +package mffs.container; + +import mffs.base.ContainerBase; +import mffs.slot.SlotBase; +import mffs.slot.SlotCard; +import mffs.tileentity.TileEntityFortronCapacitor; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.Slot; + +public class ContainerFortronCapacitor extends ContainerBase { + private TileEntityFortronCapacitor tileEntity; + + public ContainerFortronCapacitor( + final EntityPlayer player, final TileEntityFortronCapacitor tileEntity) { + super((IInventory) tileEntity); + this.tileEntity = tileEntity; + this.addSlotToContainer((Slot) new SlotCard(this.tileEntity, 0, 9, 74)); + this.addSlotToContainer((Slot) new SlotCard(this.tileEntity, 1, 27, 74)); + this.addSlotToContainer((Slot) new SlotBase(this.tileEntity, 2, 154, 47)); + this.addSlotToContainer((Slot) new SlotBase(this.tileEntity, 3, 154, 67)); + this.addSlotToContainer((Slot) new SlotBase(this.tileEntity, 4, 154, 87)); + this.addPlayerInventory(player); + } +} diff --git a/src/main/java/mffs/container/ContainerInterdictionMatrix.java b/src/main/java/mffs/container/ContainerInterdictionMatrix.java new file mode 100644 index 0000000..aba940f --- /dev/null +++ b/src/main/java/mffs/container/ContainerInterdictionMatrix.java @@ -0,0 +1,29 @@ +package mffs.container; + +import mffs.base.ContainerBase; +import mffs.slot.SlotBase; +import mffs.slot.SlotCard; +import mffs.tileentity.TileEntityInterdictionMatrix; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.Slot; + +public class ContainerInterdictionMatrix extends ContainerBase { + public ContainerInterdictionMatrix(final EntityPlayer player, + final TileEntityInterdictionMatrix tileEntity) { + super((IInventory) tileEntity); + this.addSlotToContainer((Slot) new SlotCard(tileEntity, 0, 87, 89)); + this.addSlotToContainer((Slot) new SlotBase(tileEntity, 1, 69, 89)); + for (int var3 = 0; var3 < 2; ++var3) { + for (int var4 = 0; var4 < 4; ++var4) { + this.addSlotToContainer((Slot) new SlotBase( + tileEntity, var4 + var3 * 4 + 2, 99 + var4 * 18, 31 + var3 * 18)); + } + } + for (int var5 = 0; var5 < 9; ++var5) { + this.addSlotToContainer( + (Slot) new SlotBase(tileEntity, var5 + 8 + 2, 9 + var5 * 18, 69)); + } + this.addPlayerInventory(player); + } +} diff --git a/src/main/java/mffs/event/BlockDropDelayedEvent.java b/src/main/java/mffs/event/BlockDropDelayedEvent.java new file mode 100644 index 0000000..4f44f64 --- /dev/null +++ b/src/main/java/mffs/event/BlockDropDelayedEvent.java @@ -0,0 +1,35 @@ +package mffs.event; + +import mffs.DelayedEvent; +import mffs.IDelayedEventHandler; +import net.minecraft.block.Block; +import net.minecraft.init.Blocks; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; +import universalelectricity.core.vector.Vector3; + +public class BlockDropDelayedEvent extends DelayedEvent { + protected Block block; + protected World world; + protected Vector3 position; + + public BlockDropDelayedEvent(final IDelayedEventHandler handler, + final int ticks, final Block block, + final World world, final Vector3 position) { + super(handler, ticks); + this.block = block; + this.world = world; + this.position = position; + } + + @Override + protected void onEvent() { + if (this.position.getBlock((IBlockAccess) this.world) == this.block) { + this.block.dropBlockAsItem( + this.world, this.position.intX(), this.position.intY(), + this.position.intZ(), + this.position.getBlockMetadata((IBlockAccess) this.world), 0); + this.position.setBlock(this.world, Blocks.air); + } + } +} diff --git a/src/main/java/mffs/event/BlockInventoryDropDelayedEvent.java b/src/main/java/mffs/event/BlockInventoryDropDelayedEvent.java new file mode 100644 index 0000000..2f3e08e --- /dev/null +++ b/src/main/java/mffs/event/BlockInventoryDropDelayedEvent.java @@ -0,0 +1,38 @@ +package mffs.event; + +import java.util.ArrayList; +import mffs.IDelayedEventHandler; +import mffs.base.TileEntityInventory; +import net.minecraft.block.Block; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; +import universalelectricity.core.vector.Vector3; + +public class BlockInventoryDropDelayedEvent extends BlockDropDelayedEvent { + private TileEntityInventory projector; + + public BlockInventoryDropDelayedEvent(final IDelayedEventHandler handler, + final int ticks, final Block block, + final World world, + final Vector3 position, + final TileEntityInventory projector) { + super(handler, ticks, block, world, position); + this.projector = projector; + } + + @Override + protected void onEvent() { + if (super.position.getBlock((IBlockAccess) super.world) == super.block) { + final ArrayList itemStacks = super.block.getDrops( + super.world, super.position.intX(), super.position.intY(), + super.position.intZ(), + super.position.getBlockMetadata((IBlockAccess) super.world), 0); + for (final ItemStack itemStack : itemStacks) { + this.projector.mergeIntoInventory(itemStack); + } + super.position.setBlock(super.world, Blocks.air); + } + } +} diff --git a/src/main/java/mffs/event/BlockNotifyDelayedEvent.java b/src/main/java/mffs/event/BlockNotifyDelayedEvent.java new file mode 100644 index 0000000..43aba54 --- /dev/null +++ b/src/main/java/mffs/event/BlockNotifyDelayedEvent.java @@ -0,0 +1,52 @@ +package mffs.event; + +import cpw.mods.fml.common.Loader; +import cpw.mods.fml.relauncher.ReflectionHelper; +import mffs.DelayedEvent; +import mffs.IDelayedEventHandler; +import mffs.api.ISpecialForceManipulation; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; +import universalelectricity.core.vector.Vector3; + +public class BlockNotifyDelayedEvent extends DelayedEvent { + private World world; + private Vector3 position; + + public BlockNotifyDelayedEvent(final IDelayedEventHandler handler, + final int ticks, final World world, + final Vector3 position) { + super(handler, ticks); + this.world = world; + this.position = position; + } + + @Override + protected void onEvent() { + if (!this.world.isRemote) { + this.world.notifyBlocksOfNeighborChange( + this.position.intX(), this.position.intY(), this.position.intZ(), + this.position.getBlock((IBlockAccess) this.world)); + final TileEntity newTile = this.position.getTileEntity((IBlockAccess) this.world); + if (newTile != null) { + if (newTile instanceof ISpecialForceManipulation) { + ((ISpecialForceManipulation) newTile).postMove(); + } + if (Loader.isModLoaded("BuildCraft|Factory")) { + try { + final Class clazz = Class.forName("buildcraft.factory.TileQuarry"); + if (clazz == newTile.getClass()) { + // TODO: W T F AAAAAAAAAAAAA + ReflectionHelper.setPrivateValue(clazz, (Object) newTile, + (Object) true, + new String[] { "isAlive" }); + } + } catch (final Exception e) { + e.printStackTrace(); + } + } + } + } + } +} diff --git a/src/main/java/mffs/event/BlockPostMoveDelayedEvent.java b/src/main/java/mffs/event/BlockPostMoveDelayedEvent.java new file mode 100644 index 0000000..0dc82b6 --- /dev/null +++ b/src/main/java/mffs/event/BlockPostMoveDelayedEvent.java @@ -0,0 +1,63 @@ +package mffs.event; + +import mffs.DelayedEvent; +import mffs.IDelayedEventHandler; +import mffs.ManipulatorHelper; +import net.minecraft.block.Block; +import net.minecraft.init.Blocks; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; +import universalelectricity.core.vector.Vector3; + +public class BlockPostMoveDelayedEvent extends DelayedEvent { + private World world; + private Vector3 originalPosition; + private Vector3 newPosition; + private Block blockID; + private int blockMetadata; + private TileEntity tileEntity; + private NBTTagCompound tileData; + + public BlockPostMoveDelayedEvent(final IDelayedEventHandler handler, + final int ticks, final World world, + final Vector3 originalPosition, + final Vector3 newPosition, final Block blockID, + final int blockMetadata, + final TileEntity tileEntity, + final NBTTagCompound tileData) { + super(handler, ticks); + this.blockID = Blocks.air; + this.blockMetadata = 0; + this.world = world; + this.originalPosition = originalPosition; + this.newPosition = newPosition; + this.blockID = blockID; + this.blockMetadata = blockMetadata; + this.tileEntity = tileEntity; + this.tileData = tileData; + } + + @Override + protected void onEvent() { + if (!this.world.isRemote && this.blockID != Blocks.air) { + try { + if (this.tileEntity != null && this.tileData != null) { + ManipulatorHelper.setBlockSneaky( + this.world, this.newPosition, this.blockID, this.blockMetadata, + TileEntity.createAndLoadEntity(this.tileData)); + } else { + ManipulatorHelper.setBlockSneaky(this.world, this.newPosition, + this.blockID, this.blockMetadata, + null); + } + super.handler.getQuedDelayedEvents().add(new BlockNotifyDelayedEvent( + super.handler, 0, this.world, this.originalPosition)); + super.handler.getQuedDelayedEvents().add(new BlockNotifyDelayedEvent( + super.handler, 0, this.world, this.newPosition)); + } catch (final Exception e) { + e.printStackTrace(); + } + } + } +} diff --git a/src/main/java/mffs/event/BlockPreMoveDelayedEvent.java b/src/main/java/mffs/event/BlockPreMoveDelayedEvent.java new file mode 100644 index 0000000..8324ac1 --- /dev/null +++ b/src/main/java/mffs/event/BlockPreMoveDelayedEvent.java @@ -0,0 +1,52 @@ +package mffs.event; + +import mffs.DelayedEvent; +import mffs.IDelayedEventHandler; +import mffs.ManipulatorHelper; +import mffs.api.ISpecialForceManipulation; +import net.minecraft.block.Block; +import net.minecraft.init.Blocks; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; +import universalelectricity.core.vector.Vector3; + +public class BlockPreMoveDelayedEvent extends DelayedEvent { + private World world; + private Vector3 position; + private Vector3 newPosition; + + public BlockPreMoveDelayedEvent(final IDelayedEventHandler handler, + final int ticks, final World world, + final Vector3 position, + final Vector3 newPosition) { + super(handler, ticks); + this.world = world; + this.position = position; + this.newPosition = newPosition; + } + + @Override + protected void onEvent() { + if (!this.world.isRemote) { + final TileEntity tileEntity = this.position.getTileEntity((IBlockAccess) this.world); + if (tileEntity instanceof ISpecialForceManipulation) { + ((ISpecialForceManipulation) tileEntity) + .move(this.newPosition.intX(), this.newPosition.intY(), + this.newPosition.intZ()); + } + final Block blockID = this.position.getBlock((IBlockAccess) this.world); + final int blockMetadata = this.position.getBlockMetadata((IBlockAccess) this.world); + final NBTTagCompound tileData = new NBTTagCompound(); + if (tileEntity != null) { + tileEntity.writeToNBT(tileData); + } + ManipulatorHelper.setBlockSneaky(this.world, this.position, Blocks.air, 0, + null); + super.handler.getQuedDelayedEvents().add(new BlockPostMoveDelayedEvent( + super.handler, 0, this.world, this.position, this.newPosition, + blockID, blockMetadata, tileEntity, tileData)); + } + } +} diff --git a/src/main/java/mffs/fortron/FortronHelper.java b/src/main/java/mffs/fortron/FortronHelper.java new file mode 100644 index 0000000..e3a8c43 --- /dev/null +++ b/src/main/java/mffs/fortron/FortronHelper.java @@ -0,0 +1,28 @@ +package mffs.fortron; + +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.FluidTank; + +public class FortronHelper +{ + public static Fluid FLUID_FORTRON; + + public static FluidStack getFortron(final int amount) { + return new FluidStack(FLUID_FORTRON, amount); + } + + public static int getAmount(final FluidStack fluidStack) { + if (fluidStack != null) { + return fluidStack.amount; + } + return 0; + } + + public static int getAmount(final FluidTank fortronTank) { + if (fortronTank != null) { + return fortronTank.getFluidAmount(); + } + return 0; + } +} diff --git a/src/main/java/mffs/fortron/FrequencyGrid.java b/src/main/java/mffs/fortron/FrequencyGrid.java new file mode 100644 index 0000000..fdafea5 --- /dev/null +++ b/src/main/java/mffs/fortron/FrequencyGrid.java @@ -0,0 +1,131 @@ +package mffs.fortron; + +import cpw.mods.fml.common.FMLCommonHandler; +import cpw.mods.fml.relauncher.Side; +import icbm.api.IBlockFrequency; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; +import mffs.api.fortron.IFortronFrequency; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; +import universalelectricity.core.vector.Vector3; + +public class FrequencyGrid { + private static FrequencyGrid CLIENT_INSTANCE; + private static FrequencyGrid SERVER_INSTANCE; + private final Set frequencyGrid; + + public FrequencyGrid() { + this.frequencyGrid = new HashSet<>(); + } + + public void register(final IBlockFrequency tileEntity) { + try { + final Iterator it = this.frequencyGrid.iterator(); + while (it.hasNext()) { + final IBlockFrequency frequency = it.next(); + if (frequency == null) { + it.remove(); + } else if (((TileEntity) frequency).isInvalid()) { + it.remove(); + } else { + if (!new Vector3((TileEntity) frequency) + .equals(new Vector3((TileEntity) tileEntity))) { + continue; + } + it.remove(); + } + } + } catch (final Exception e) { + e.printStackTrace(); + } + this.frequencyGrid.add(tileEntity); + } + + public void unregister(final IBlockFrequency tileEntity) { + this.frequencyGrid.remove(tileEntity); + this.cleanUp(); + } + + public Set get() { + return this.frequencyGrid; + } + + public Set get(final int frequency) { + final Set set = new HashSet<>(); + for (final IBlockFrequency tile : this.get()) { + if (tile != null && !((TileEntity) tile).isInvalid() && + tile.getFrequency() == frequency) { + set.add(tile); + } + } + return set; + } + + public void cleanUp() { + try { + final Iterator it = this.frequencyGrid.iterator(); + while (it.hasNext()) { + final IBlockFrequency frequency = it.next(); + if (frequency == null) { + it.remove(); + } else if (((TileEntity) frequency).isInvalid()) { + it.remove(); + } else { + if (((TileEntity) frequency).getWorldObj().getTileEntity( + ((TileEntity) frequency).xCoord, + ((TileEntity) frequency).yCoord, + ((TileEntity) frequency).zCoord) == (TileEntity) frequency) { + continue; + } + it.remove(); + } + } + } catch (final Exception e) { + e.printStackTrace(); + } + } + + public Set get(final World world, final Vector3 position, final int radius, + final int frequency) { + final Set set = new HashSet(); + for (final IBlockFrequency tileEntity : this.get(frequency)) { + if (((TileEntity) tileEntity).getWorldObj() == world && + Vector3.distance(new Vector3((TileEntity) tileEntity), position) <= radius) { + set.add(tileEntity); + } + } + return set; + } + + public Set getFortronTiles(final World world, final Vector3 position, + final int radius, final int frequency) { + final Set set = new HashSet(); + for (final IBlockFrequency tileEntity : this.get(frequency)) { + if (((TileEntity) tileEntity).getWorldObj() == world && + tileEntity instanceof IFortronFrequency && + Vector3.distance(new Vector3((TileEntity) tileEntity), position) <= radius) { + set.add(tileEntity); + } + } + return set; + } + + public static void reinitiate() { + FrequencyGrid.CLIENT_INSTANCE = new FrequencyGrid(); + FrequencyGrid.SERVER_INSTANCE = new FrequencyGrid(); + } + + public static FrequencyGrid instance() { + if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER) { + return FrequencyGrid.SERVER_INSTANCE; + } + return FrequencyGrid.CLIENT_INSTANCE; + } + + static { + FrequencyGrid.CLIENT_INSTANCE = new FrequencyGrid(); + FrequencyGrid.SERVER_INSTANCE = new FrequencyGrid(); + } +} diff --git a/src/main/java/mffs/gui/GuiBiometricIdentifier.java b/src/main/java/mffs/gui/GuiBiometricIdentifier.java new file mode 100644 index 0000000..5f49b6e --- /dev/null +++ b/src/main/java/mffs/gui/GuiBiometricIdentifier.java @@ -0,0 +1,147 @@ +package mffs.gui; + +import mffs.ModularForceFieldSystem; +import mffs.api.card.ICardIdentification; +import mffs.api.security.Permission; +import mffs.base.GuiBase; +import mffs.base.PacketTile; +import mffs.container.ContainerBiometricIdentifier; +import mffs.gui.button.GuiButtonPress; +import mffs.tileentity.TileEntityBiometricIdentifier; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.gui.GuiTextField; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.nbt.NBTTagCompound; +import universalelectricity.core.vector.Vector2; +import universalelectricity.core.vector.Vector3; + +public class GuiBiometricIdentifier extends GuiBase { + private TileEntityBiometricIdentifier tileEntity; + private GuiTextField textFieldUsername; + + public GuiBiometricIdentifier(final EntityPlayer player, + final TileEntityBiometricIdentifier tileEntity) { + super(new ContainerBiometricIdentifier(player, tileEntity), tileEntity); + this.tileEntity = tileEntity; + } + + @Override + public void initGui() { + super.textFieldPos = new Vector2(109.0, 92.0); + super.initGui(); + (this.textFieldUsername = new GuiTextField(this.fontRendererObj, 52, 18, 90, 12)) + .setMaxStringLength(30); + int x = 0; + int y = 0; + for (int i = 0; i < Permission.getPermissions().length; ++i) { + ++x; + this.buttonList.add(new GuiButtonPress( + i + 1, this.width / 2 - 50 + 20 * x, this.height / 2 - 75 + 20 * y, + new Vector2(18.0, 18 * i), this, + Permission.getPermissions()[i].name)); + if (i % 3 == 0 && i != 0) { + x = 0; + ++y; + } + } + } + + @Override + protected void drawGuiContainerForegroundLayer(final int x, final int y) { + this.fontRendererObj.drawString( + this.tileEntity.getInventoryName(), + this.xSize / 2 - this.fontRendererObj.getStringWidth( + this.tileEntity.getInventoryName()) / + 2, + 6, 4210752); + this.drawTextWithTooltip("rights", "%1", 8, 32, x, y, 0); + try { + if (this.tileEntity.getManipulatingCard() != null) { + final ICardIdentification idCard = (ICardIdentification) this.tileEntity.getManipulatingCard() + .getItem(); + this.textFieldUsername.drawTextBox(); + if (idCard.getUsername(this.tileEntity.getManipulatingCard()) != null) { + for (int i = 0; i < this.buttonList.size(); ++i) { + if (this.buttonList.get(i) instanceof GuiButtonPress) { + final GuiButtonPress button = (GuiButtonPress) this.buttonList.get(i); + button.visible = true; + final int permissionID = i - 1; + if (Permission.getPermission(permissionID) != null) { + if (idCard.hasPermission( + this.tileEntity.getManipulatingCard(), + Permission.getPermission(permissionID))) { + button.stuck = true; + } else { + button.stuck = false; + } + } + } + } + } + } else { + for (final Object button2 : this.buttonList) { + if (button2 instanceof GuiButtonPress) { + ((GuiButtonPress) button2).visible = false; + } + } + } + } catch (final Exception e) { + e.printStackTrace(); + } + super.textFieldFrequency.drawTextBox(); + this.drawTextWithTooltip("master", 28, + 90 + this.fontRendererObj.FONT_HEIGHT / 2, x, y); + super.drawGuiContainerForegroundLayer(x, y); + } + + @Override + public void updateScreen() { + super.updateScreen(); + if (!this.textFieldUsername.isFocused() && + this.tileEntity.getManipulatingCard() != null) { + final ICardIdentification idCard = (ICardIdentification) this.tileEntity.getManipulatingCard().getItem(); + if (idCard.getUsername(this.tileEntity.getManipulatingCard()) != null) { + this.textFieldUsername.setText( + idCard.getUsername(this.tileEntity.getManipulatingCard())); + } + } + } + + @Override + protected void drawGuiContainerBackgroundLayer(final float f, final int x, + final int y) { + super.drawGuiContainerBackgroundLayer(f, x, y); + this.drawSlot(87, 90); + this.drawSlot(7, 45); + this.drawSlot(7, 65); + this.drawSlot(7, 90); + for (int var4 = 0; var4 < 9; ++var4) { + this.drawSlot(8 + var4 * 18 - 1, 110); + } + } + + @Override + protected void keyTyped(final char par1, final int par2) { + if (par1 != 'e' && par1 != 'E') { + super.keyTyped(par1, par2); + } + this.textFieldUsername.textboxKeyTyped(par1, par2); + NBTTagCompound nbt = new NBTTagCompound(); + nbt.setString("username", this.textFieldUsername.getText()); + ModularForceFieldSystem.channel.sendToServer(new PacketTile( + PacketTile.Type.STRING, new Vector3(this.tileEntity), nbt)); + } + + @Override + protected void mouseClicked(final int x, final int y, final int par3) { + super.mouseClicked(x, y, par3); + this.textFieldUsername.mouseClicked(x - super.containerWidth, + y - super.containerHeight, par3); + } + + @Override + protected void actionPerformed(final GuiButton guiButton) { + ModularForceFieldSystem.channel.sendToServer(new PacketTile( + PacketTile.Type.TOGGLE_MODE, new Vector3(this.tileEntity), new NBTTagCompound())); + } +} diff --git a/src/main/java/mffs/gui/GuiCoercionDeriver.java b/src/main/java/mffs/gui/GuiCoercionDeriver.java new file mode 100644 index 0000000..f711794 --- /dev/null +++ b/src/main/java/mffs/gui/GuiCoercionDeriver.java @@ -0,0 +1,110 @@ +package mffs.gui; + +import mffs.ModularForceFieldSystem; +import mffs.base.GuiBase; +import mffs.base.PacketTile; +import mffs.container.ContainerCoercionDeriver; +import mffs.tileentity.TileEntityCoercionDeriver; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.nbt.NBTTagCompound; +import org.lwjgl.opengl.GL11; +import universalelectricity.core.UniversalElectricity; +import universalelectricity.core.electricity.ElectricityDisplay; +import universalelectricity.core.vector.Vector2; +import universalelectricity.core.vector.Vector3; + +public class GuiCoercionDeriver extends GuiBase { + private TileEntityCoercionDeriver tileEntity; + + public GuiCoercionDeriver(final EntityPlayer player, + final TileEntityCoercionDeriver tileentity) { + super(new ContainerCoercionDeriver(player, tileentity), tileentity); + this.tileEntity = tileentity; + } + + @Override + public void initGui() { + super.textFieldPos = new Vector2(30.0, 43.0); + super.initGui(); + this.buttonList.add(new GuiButton(1, this.width / 2 - 10, + this.height / 2 - 28, 58, 20, "Derive")); + } + + @Override + protected void drawGuiContainerForegroundLayer(final int x, final int y) { + this.fontRendererObj.drawString( + this.tileEntity.getInventoryName(), + this.xSize / 2 - this.fontRendererObj.getStringWidth( + this.tileEntity.getInventoryName()) / + 2, + 6, 4210752); + this.drawTextWithTooltip("frequency", "%1:", 8, 30, x, y); + super.textFieldFrequency.drawTextBox(); + GL11.glPushMatrix(); + GL11.glRotatef(-90.0f, 0.0f, 0.0f, 1.0f); + this.drawTextWithTooltip("upgrade", -95, 140, x, y); + GL11.glPopMatrix(); + if (this.buttonList.get(1) instanceof GuiButton) { + if (!this.tileEntity.isInversed) { + ((GuiButton) this.buttonList.get(1)).displayString = "Derive"; + } else { + ((GuiButton) this.buttonList.get(1)).displayString = "Integrate"; + } + } + this.fontRendererObj.drawString( + 1000.0 * UniversalElectricity.TO_BC_RATIO + " MJ/s", 85, 30, 4210752); + this.fontRendererObj.drawString( + 1000.0 * UniversalElectricity.TO_IC2_RATIO + " EU/s", 85, 40, 4210752); + this.fontRendererObj.drawString( + ElectricityDisplay.getDisplayShort( + 1000.0, ElectricityDisplay.ElectricUnit.WATT), + 85, 50, 4210752); + this.fontRendererObj.drawString( + ElectricityDisplay.getDisplayShort( + this.tileEntity.getVoltage(), + ElectricityDisplay.ElectricUnit.VOLTAGE), + 85, 60, 4210752); + this.drawTextWithTooltip( + "progress", "%1: " + (this.tileEntity.isActive() ? "Running" : "Idle"), + 8, 70, x, y); + this.drawTextWithTooltip("fortron", + "%1: " + + ElectricityDisplay.getDisplayShort( + this.tileEntity.getFortronEnergy(), + ElectricityDisplay.ElectricUnit.JOULES), + 8, 105, x, y); + this.fontRendererObj.drawString( + "§2+" + ElectricityDisplay.getDisplayShort( + this.tileEntity.getProductionRate() * 20, + ElectricityDisplay.ElectricUnit.JOULES), + 120, 117, 4210752); + super.drawGuiContainerForegroundLayer(x, y); + } + + @Override + protected void drawGuiContainerBackgroundLayer(final float f, final int x, + final int y) { + super.drawGuiContainerBackgroundLayer(f, x, y); + this.drawSlot(153, 46); + this.drawSlot(153, 66); + this.drawSlot(153, 86); + this.drawSlot(8, 40); + this.drawSlot(8, 82, SlotType.BATTERY); + this.drawSlot(28, 82); + this.drawBar(50, 84, 1.0f); + this.drawForce(8, 115, + this.tileEntity.getFortronEnergy() / + (float) this.tileEntity.getFortronCapacity()); + } + + @Override + protected void actionPerformed(final GuiButton guibutton) { + super.actionPerformed(guibutton); + if (guibutton.id == 1) { + ModularForceFieldSystem.channel.sendToServer( + new PacketTile(PacketTile.Type.TOGGLE_MODE, + new Vector3(this.tileEntity), new NBTTagCompound())); + } + } +} diff --git a/src/main/java/mffs/gui/GuiForceFieldProjector.java b/src/main/java/mffs/gui/GuiForceFieldProjector.java new file mode 100644 index 0000000..7669dd3 --- /dev/null +++ b/src/main/java/mffs/gui/GuiForceFieldProjector.java @@ -0,0 +1,150 @@ +package mffs.gui; + +import mffs.base.GuiBase; +import mffs.container.ContainerForceFieldProjector; +import mffs.tileentity.TileEntityForceFieldProjector; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.world.IBlockAccess; +import org.lwjgl.opengl.GL11; +import universalelectricity.core.electricity.ElectricityDisplay; +import universalelectricity.core.vector.Vector2; +import universalelectricity.prefab.vector.Region2; + +public class GuiForceFieldProjector extends GuiBase { + private TileEntityForceFieldProjector tileEntity; + + public GuiForceFieldProjector(final EntityPlayer player, + final TileEntityForceFieldProjector + tileEntity) { + super(new ContainerForceFieldProjector(player, tileEntity), tileEntity); + this.tileEntity = tileEntity; + } + + @Override + public void initGui() { + super.textFieldPos = new Vector2(48.0, 91.0); + super.initGui(); + super.tooltips.put(new Region2(new Vector2(117.0, 44.0), + new Vector2(117.0, 44.0).add(18.0)), + "Mode"); + super.tooltips.put( + new Region2(new Vector2(90.0, 17.0), new Vector2(90.0, 17.0).add(18.0)), + "Up"); + super.tooltips.put(new Region2(new Vector2(144.0, 17.0), + new Vector2(144.0, 17.0).add(18.0)), + "Up"); + super.tooltips.put( + new Region2(new Vector2(90.0, 71.0), new Vector2(90.0, 71.0).add(18.0)), + "Down"); + super.tooltips.put(new Region2(new Vector2(144.0, 71.0), + new Vector2(144.0, 71.0).add(18.0)), + "Down"); + super.tooltips.put(new Region2(new Vector2(108.0, 17.0), + new Vector2(108.0, 17.0).add(18.0)), + "Front"); + super.tooltips.put(new Region2(new Vector2(126.0, 17.0), + new Vector2(126.0, 17.0).add(18.0)), + "Front"); + super.tooltips.put(new Region2(new Vector2(108.0, 71.0), + new Vector2(108.0, 71.0).add(18.0)), + "Back"); + super.tooltips.put(new Region2(new Vector2(126.0, 71.0), + new Vector2(126.0, 71.0).add(18.0)), + "Back"); + super.tooltips.put(new Region2(new Vector2(90.0, 35.0), + new Vector2(108.0, 35.0).add(18.0)), + "Left"); + super.tooltips.put(new Region2(new Vector2(90.0, 53.0), + new Vector2(108.0, 53.0).add(18.0)), + "Left"); + super.tooltips.put(new Region2(new Vector2(144.0, 35.0), + new Vector2(144.0, 35.0).add(18.0)), + "Right"); + super.tooltips.put(new Region2(new Vector2(144.0, 53.0), + new Vector2(144.0, 53.0).add(18.0)), + "Right"); + } + + @Override + protected void drawGuiContainerForegroundLayer(final int x, final int y) { + this.fontRendererObj.drawString( + this.tileEntity.getInventoryName(), + this.xSize / 2 - this.fontRendererObj.getStringWidth( + this.tileEntity.getInventoryName()) / + 2, + 6, 4210752); + GL11.glPushMatrix(); + GL11.glRotatef(-90.0f, 0.0f, 0.0f, 1.0f); + this.fontRendererObj.drawString( + this.tileEntity + .getDirection((IBlockAccess)this.tileEntity.getWorldObj(), + this.tileEntity.xCoord, this.tileEntity.yCoord, + this.tileEntity.zCoord) + .name(), + -63, 8, 4210752); + GL11.glPopMatrix(); + this.drawTextWithTooltip("matrix", 32, 20, x, y); + this.drawTextWithTooltip("frequency", "%1:", 8, 76, x, y); + super.textFieldFrequency.drawTextBox(); + this.drawTextWithTooltip("fortron", + "%1: " + + ElectricityDisplay.getDisplayShort( + this.tileEntity.getFortronEnergy(), + ElectricityDisplay.ElectricUnit.JOULES) + + "/" + + ElectricityDisplay.getDisplayShort( + this.tileEntity.getFortronCapacity(), + ElectricityDisplay.ElectricUnit.JOULES), + 8, 110, x, y); + this.fontRendererObj.drawString( + "§4-" + ElectricityDisplay.getDisplayShort( + this.tileEntity.getFortronCost() * 20, + ElectricityDisplay.ElectricUnit.JOULES), + 120, 121, 4210752); + super.drawGuiContainerForegroundLayer(x, y); + } + + @Override + protected void drawGuiContainerBackgroundLayer(final float f, final int x, + final int y) { + super.drawGuiContainerBackgroundLayer(f, x, y); + this.drawSlot(9, 88); + this.drawSlot(27, 88); + this.drawSlot(117, 44, SlotType.NONE, 1.0f, 0.4f, 0.4f); + for (int xSlot = 0; xSlot < 4; ++xSlot) { + for (int ySlot = 0; ySlot < 4; ++ySlot) { + if ((xSlot != 1 || ySlot != 1) && (xSlot != 2 || ySlot != 2) && + (xSlot != 1 || ySlot != 2) && (xSlot != 2 || ySlot != 1)) { + SlotType type = SlotType.NONE; + if (xSlot == 0 && ySlot == 0) { + type = SlotType.ARR_UP_LEFT; + } else if (xSlot == 0 && ySlot == 3) { + type = SlotType.ARR_DOWN_LEFT; + } else if (xSlot == 3 && ySlot == 0) { + type = SlotType.ARR_UP_RIGHT; + } else if (xSlot == 3 && ySlot == 3) { + type = SlotType.ARR_DOWN_RIGHT; + } else if (ySlot == 0) { + type = SlotType.ARR_UP; + } else if (ySlot == 3) { + type = SlotType.ARR_DOWN; + } else if (xSlot == 0) { + type = SlotType.ARR_LEFT; + } else if (xSlot == 3) { + type = SlotType.ARR_RIGHT; + } + this.drawSlot(90 + 18 * xSlot, 17 + 18 * ySlot, type); + } + } + } + for (int xSlot = 0; xSlot < 3; ++xSlot) { + for (int ySlot = 0; ySlot < 2; ++ySlot) { + this.drawSlot(18 + 18 * xSlot, 35 + 18 * ySlot); + } + } + this.drawForce(8, 120, + Math.min(this.tileEntity.getFortronEnergy() / + (float)this.tileEntity.getFortronCapacity(), + 1.0f)); + } +} diff --git a/src/main/java/mffs/gui/GuiForceManipulator.java b/src/main/java/mffs/gui/GuiForceManipulator.java new file mode 100644 index 0000000..519cf92 --- /dev/null +++ b/src/main/java/mffs/gui/GuiForceManipulator.java @@ -0,0 +1,194 @@ +package mffs.gui; + +import mffs.ModularForceFieldSystem; +import mffs.base.GuiBase; +import mffs.base.PacketTile; +import mffs.container.ContainerForceManipulator; +import mffs.gui.button.GuiIcon; +import mffs.tileentity.TileEntityForceManipulator; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.init.Items; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.world.IBlockAccess; +import org.lwjgl.opengl.GL11; +import universalelectricity.core.electricity.ElectricityDisplay; +import universalelectricity.core.vector.Vector2; +import universalelectricity.core.vector.Vector3; +import universalelectricity.prefab.vector.Region2; + +public class GuiForceManipulator extends GuiBase { + private TileEntityForceManipulator tileEntity; + + public GuiForceManipulator(final EntityPlayer player, + final TileEntityForceManipulator tileEntity) { + super(new ContainerForceManipulator(player, tileEntity), tileEntity); + this.tileEntity = tileEntity; + } + + @Override + public void initGui() { + super.textFieldPos = new Vector2(111.0, 93.0); + super.initGui(); + this.buttonList.add(new GuiButton(1, this.width / 2 - 60, + this.height / 2 - 22, 40, 20, "Reset")); + this.buttonList.add( + new GuiIcon(2, this.width / 2 - 82, this.height / 2 - 82, + new ItemStack[] { null, new ItemStack(Items.redstone), + new ItemStack(Blocks.redstone_block) })); + this.buttonList.add( + new GuiIcon(3, this.width / 2 - 82, this.height / 2 - 60, + new ItemStack[] { null, new ItemStack(Blocks.anvil) })); + super.tooltips.put(new Region2(new Vector2(117.0, 44.0), + new Vector2(117.0, 44.0).add(18.0)), + "Mode"); + super.tooltips.put( + new Region2(new Vector2(90.0, 17.0), new Vector2(90.0, 17.0).add(18.0)), + "Up"); + super.tooltips.put(new Region2(new Vector2(144.0, 17.0), + new Vector2(144.0, 17.0).add(18.0)), + "Up"); + super.tooltips.put( + new Region2(new Vector2(90.0, 71.0), new Vector2(90.0, 71.0).add(18.0)), + "Down"); + super.tooltips.put(new Region2(new Vector2(144.0, 71.0), + new Vector2(144.0, 71.0).add(18.0)), + "Down"); + super.tooltips.put(new Region2(new Vector2(108.0, 17.0), + new Vector2(108.0, 17.0).add(18.0)), + "Front"); + super.tooltips.put(new Region2(new Vector2(126.0, 17.0), + new Vector2(126.0, 17.0).add(18.0)), + "Front"); + super.tooltips.put(new Region2(new Vector2(108.0, 71.0), + new Vector2(108.0, 71.0).add(18.0)), + "Back"); + super.tooltips.put(new Region2(new Vector2(126.0, 71.0), + new Vector2(126.0, 71.0).add(18.0)), + "Back"); + super.tooltips.put(new Region2(new Vector2(90.0, 35.0), + new Vector2(108.0, 35.0).add(18.0)), + "Left"); + super.tooltips.put(new Region2(new Vector2(90.0, 53.0), + new Vector2(108.0, 53.0).add(18.0)), + "Left"); + super.tooltips.put(new Region2(new Vector2(144.0, 35.0), + new Vector2(144.0, 35.0).add(18.0)), + "Right"); + super.tooltips.put(new Region2(new Vector2(144.0, 53.0), + new Vector2(144.0, 53.0).add(18.0)), + "Right"); + } + + @Override + protected void drawGuiContainerForegroundLayer(final int x, final int y) { + this.fontRendererObj.drawString( + this.tileEntity.getInventoryName(), + this.xSize / 2 - this.fontRendererObj.getStringWidth( + this.tileEntity.getInventoryName()) / + 2, + 6, 4210752); + GL11.glPushMatrix(); + GL11.glRotatef(-90.0f, 0.0f, 0.0f, 1.0f); + this.fontRendererObj.drawString( + this.tileEntity + .getDirection((IBlockAccess) this.tileEntity.getWorldObj(), + this.tileEntity.xCoord, this.tileEntity.yCoord, + this.tileEntity.zCoord) + .name(), + -100, 10, 4210752); + GL11.glPopMatrix(); + this.fontRendererObj.drawString("Anchor:", 30, 60, 4210752); + if (this.tileEntity.anchor != null) { + this.fontRendererObj.drawString(this.tileEntity.anchor.intX() + ", " + + this.tileEntity.anchor.intY() + ", " + + this.tileEntity.anchor.intZ(), + 30, 72, 4210752); + } + super.textFieldFrequency.drawTextBox(); + this.drawTextWithTooltip("fortron", + "%1: " + + ElectricityDisplay.getDisplayShort( + this.tileEntity.getFortronEnergy(), + ElectricityDisplay.ElectricUnit.JOULES) + + + "/" + + ElectricityDisplay.getDisplayShort( + this.tileEntity.getFortronCapacity(), + ElectricityDisplay.ElectricUnit.JOULES), + 8, 110, x, y); + this.fontRendererObj.drawString( + "§4-" + ElectricityDisplay.getDisplayShort( + this.tileEntity.getFortronCost(), + ElectricityDisplay.ElectricUnit.JOULES), + 120, 121, 4210752); + super.drawGuiContainerForegroundLayer(x, y); + } + + @Override + public void updateScreen() { + super.updateScreen(); + ((GuiIcon) this.buttonList.get(2)).setIndex(this.tileEntity.displayMode); + ((GuiIcon) this.buttonList.get(3)) + .setIndex(this.tileEntity.doAnchor ? 1 : 0); + } + + @Override + protected void drawGuiContainerBackgroundLayer(final float f, final int x, + final int y) { + super.drawGuiContainerBackgroundLayer(f, x, y); + this.drawSlot(72, 90); + this.drawSlot(90, 90); + this.drawSlot(117, 44, SlotType.NONE, 1.0f, 0.4f, 0.4f); + for (int xSlot = 0; xSlot < 4; ++xSlot) { + for (int ySlot = 0; ySlot < 4; ++ySlot) { + if ((xSlot != 1 || ySlot != 1) && (xSlot != 2 || ySlot != 2) && + (xSlot != 1 || ySlot != 2) && (xSlot != 2 || ySlot != 1)) { + SlotType type = SlotType.NONE; + if (xSlot == 0 && ySlot == 0) { + type = SlotType.ARR_UP_LEFT; + } else if (xSlot == 0 && ySlot == 3) { + type = SlotType.ARR_DOWN_LEFT; + } else if (xSlot == 3 && ySlot == 0) { + type = SlotType.ARR_UP_RIGHT; + } else if (xSlot == 3 && ySlot == 3) { + type = SlotType.ARR_DOWN_RIGHT; + } else if (ySlot == 0) { + type = SlotType.ARR_UP; + } else if (ySlot == 3) { + type = SlotType.ARR_DOWN; + } else if (xSlot == 0) { + type = SlotType.ARR_LEFT; + } else if (xSlot == 3) { + type = SlotType.ARR_RIGHT; + } + this.drawSlot(90 + 18 * xSlot, 17 + 18 * ySlot, type); + } + } + } + for (int xSlot = 0; xSlot < 3; ++xSlot) { + for (int ySlot = 0; ySlot < 2; ++ySlot) { + this.drawSlot(30 + 18 * xSlot, 18 + 18 * ySlot); + } + } + this.drawForce(8, 120, + Math.min(this.tileEntity.getFortronEnergy() / + (float) this.tileEntity.getFortronCapacity(), + 1.0f)); + } + + @Override + protected void actionPerformed(final GuiButton guiButton) { + super.actionPerformed(guiButton); + + NBTTagCompound nbt = new NBTTagCompound(); + nbt.setInteger("buttonId", guiButton.id); + + if (guiButton.id == 1 || guiButton.id == 2 || guiButton.id == 3) { + ModularForceFieldSystem.channel.sendToServer(new PacketTile( + PacketTile.Type.TOGGLE_MODE, new Vector3(this.tileEntity), nbt)); + } + } +} diff --git a/src/main/java/mffs/gui/GuiFortronCapacitor.java b/src/main/java/mffs/gui/GuiFortronCapacitor.java new file mode 100644 index 0000000..c7a8723 --- /dev/null +++ b/src/main/java/mffs/gui/GuiFortronCapacitor.java @@ -0,0 +1,96 @@ +package mffs.gui; + +import mffs.ModularForceFieldSystem; +import mffs.base.GuiBase; +import mffs.base.PacketTile; +import mffs.container.ContainerFortronCapacitor; +import mffs.gui.button.GuiButtonPressTransferMode; +import mffs.tileentity.TileEntityFortronCapacitor; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.nbt.NBTTagCompound; +import org.lwjgl.opengl.GL11; +import universalelectricity.core.electricity.ElectricityDisplay; +import universalelectricity.core.vector.Vector2; +import universalelectricity.core.vector.Vector3; + +public class GuiFortronCapacitor extends GuiBase { + private TileEntityFortronCapacitor tileEntity; + + public GuiFortronCapacitor(final EntityPlayer player, + final TileEntityFortronCapacitor tileentity) { + super(new ContainerFortronCapacitor(player, tileentity), tileentity); + this.tileEntity = tileentity; + } + + @Override + public void initGui() { + super.textFieldPos = new Vector2(50.0, 76.0); + super.initGui(); + this.buttonList.add(new GuiButtonPressTransferMode( + 1, this.width / 2 + 15, this.height / 2 - 37, this, this.tileEntity)); + } + + @Override + protected void drawGuiContainerForegroundLayer(final int x, final int y) { + this.fontRendererObj.drawString( + this.tileEntity.getInventoryName(), + this.xSize / 2 - this.fontRendererObj.getStringWidth( + this.tileEntity.getInventoryName()) / + 2, + 6, 4210752); + GL11.glPushMatrix(); + GL11.glRotatef(-90.0f, 0.0f, 0.0f, 1.0f); + this.drawTextWithTooltip("upgrade", -95, 140, x, y); + GL11.glPopMatrix(); + this.drawTextWithTooltip("linkedDevice", + "%1: " + this.tileEntity.getLinkedDevices().size(), + 8, 28, x, y); + this.drawTextWithTooltip("transmissionRate", + "%1: " + + ElectricityDisplay.getDisplayShort( + this.tileEntity.getTransmissionRate(), + ElectricityDisplay.ElectricUnit.JOULES), + 8, 40, x, y); + this.drawTextWithTooltip( + "range", "%1: " + this.tileEntity.getTransmissionRange(), 8, 52, x, y); + this.drawTextWithTooltip("frequency", "%1:", 8, 63, x, y); + super.textFieldFrequency.drawTextBox(); + this.drawTextWithTooltip("fortron", "%1:", 8, 95, x, y); + this.fontRendererObj.drawString( + ElectricityDisplay.getDisplayShort( + this.tileEntity.getFortronEnergy(), + ElectricityDisplay.ElectricUnit.JOULES) + + "/" + + ElectricityDisplay.getDisplayShort( + this.tileEntity.getFortronCapacity(), + ElectricityDisplay.ElectricUnit.JOULES), + 8, 105, 4210752); + super.drawGuiContainerForegroundLayer(x, y); + } + + @Override + protected void drawGuiContainerBackgroundLayer(final float f, final int x, + final int y) { + super.drawGuiContainerBackgroundLayer(f, x, y); + this.drawSlot(153, 46); + this.drawSlot(153, 66); + this.drawSlot(153, 86); + this.drawSlot(8, 73); + this.drawSlot(26, 73); + this.drawForce(8, 115, + Math.min(this.tileEntity.getFortronEnergy() / + (float)this.tileEntity.getFortronCapacity(), + 1.0f)); + } + + @Override + protected void actionPerformed(final GuiButton guibutton) { + super.actionPerformed(guibutton); + if (guibutton.id == 1) { + ModularForceFieldSystem.channel.sendToServer( + new PacketTile(PacketTile.Type.TOGGLE_MODE, + new Vector3(this.tileEntity), new NBTTagCompound())); + } + } +} diff --git a/src/main/java/mffs/gui/GuiInterdictionMatrix.java b/src/main/java/mffs/gui/GuiInterdictionMatrix.java new file mode 100644 index 0000000..f6b86b4 --- /dev/null +++ b/src/main/java/mffs/gui/GuiInterdictionMatrix.java @@ -0,0 +1,105 @@ +package mffs.gui; + +import mffs.ModularForceFieldSystem; +import mffs.base.GuiBase; +import mffs.base.PacketTile; +import mffs.container.ContainerInterdictionMatrix; +import mffs.tileentity.TileEntityInterdictionMatrix; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.nbt.NBTTagCompound; +import universalelectricity.core.electricity.ElectricityDisplay; +import universalelectricity.core.vector.Vector2; +import universalelectricity.core.vector.Vector3; + +public class GuiInterdictionMatrix extends GuiBase { + private TileEntityInterdictionMatrix tileEntity; + + public GuiInterdictionMatrix(final EntityPlayer player, + final TileEntityInterdictionMatrix tileEntity) { + super(new ContainerInterdictionMatrix(player, tileEntity), tileEntity); + this.tileEntity = tileEntity; + } + + @Override + public void initGui() { + super.textFieldPos = new Vector2(110.0, 91.0); + super.initGui(); + this.buttonList.add(new GuiButton(1, this.width / 2 - 80, + this.height / 2 - 65, 50, 20, "Banned")); + } + + @Override + protected void actionPerformed(final GuiButton guiButton) { + super.actionPerformed(guiButton); + if (guiButton.id == 1) { + ModularForceFieldSystem.channel.sendToServer( + new PacketTile(PacketTile.Type.TOGGLE_MODE, + new Vector3(this.tileEntity), new NBTTagCompound())); + } + } + + @Override + protected void drawGuiContainerForegroundLayer(final int x, final int y) { + this.fontRendererObj.drawString( + this.tileEntity.getInventoryName(), + this.xSize / 2 - this.fontRendererObj.getStringWidth( + this.tileEntity.getInventoryName()) / + 2, + 6, 4210752); + this.drawTextWithTooltip("warn", "%1: " + this.tileEntity.getWarningRange(), + 35, 19, x, y); + this.drawTextWithTooltip( + "action", "%1: " + this.tileEntity.getActionRange(), 100, 19, x, y); + this.drawTextWithTooltip("filterMode", "%1:", 9, 32, x, y); + if (!this.tileEntity.isBanMode()) { + if (this.buttonList.get(1) instanceof GuiButton) { + ((GuiButton)this.buttonList.get(1)).displayString = "Allowed"; + } + } else if (this.buttonList.get(1) instanceof GuiButton) { + ((GuiButton)this.buttonList.get(1)).displayString = "Banned"; + } + this.drawTextWithTooltip("frequency", "%1:", 8, 93, x, y); + super.textFieldFrequency.drawTextBox(); + this.drawTextWithTooltip("fortron", + "%1: " + + ElectricityDisplay.getDisplayShort( + this.tileEntity.getFortronEnergy(), + ElectricityDisplay.ElectricUnit.JOULES) + + "/" + + ElectricityDisplay.getDisplayShort( + this.tileEntity.getFortronCapacity(), + ElectricityDisplay.ElectricUnit.JOULES), + 8, 110, x, y); + this.fontRendererObj.drawString( + "§4-" + ElectricityDisplay.getDisplayShort( + this.tileEntity.getFortronCost() * 20, + ElectricityDisplay.ElectricUnit.JOULES), + 120, 121, 4210752); + super.drawGuiContainerForegroundLayer(x, y); + } + + @Override + protected void drawGuiContainerBackgroundLayer(final float var1, final int x, + final int y) { + super.drawGuiContainerBackgroundLayer(var1, x, y); + for (int var2 = 0; var2 < 2; ++var2) { + for (int var3 = 0; var3 < 4; ++var3) { + this.drawSlot(98 + var3 * 18, 30 + var2 * 18); + } + } + for (int var4 = 0; var4 < 9; ++var4) { + if (this.tileEntity.isBanMode()) { + this.drawSlot(8 + var4 * 18, 68, SlotType.NONE, 1.0f, 0.8f, 0.8f); + } else { + this.drawSlot(8 + var4 * 18, 68, SlotType.NONE, 0.8f, 1.0f, 0.8f); + } + } + this.drawSlot(68, 88); + this.drawSlot(86, 88); + this.drawForce(8, 120, + Math.min(this.tileEntity.getFortronEnergy() / + (float)this.tileEntity.getFortronCapacity(), + 1.0f)); + } +} diff --git a/src/main/java/mffs/gui/button/GuiButtonPress.java b/src/main/java/mffs/gui/button/GuiButtonPress.java new file mode 100644 index 0000000..3bfa4e8 --- /dev/null +++ b/src/main/java/mffs/gui/button/GuiButtonPress.java @@ -0,0 +1,89 @@ +// +// Decompiled by Procyon v0.6.0 +// + +package mffs.gui.button; + +import mffs.base.GuiBase; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.util.ResourceLocation; +import org.lwjgl.opengl.GL11; +import universalelectricity.core.vector.Vector2; +import universalelectricity.prefab.TranslationHelper; + +public class GuiButtonPress extends GuiButton { + protected Vector2 offset; + public boolean stuck; + private GuiBase mainGui; + + public GuiButtonPress(final int id, final int x, final int y, + final Vector2 offset, final GuiBase mainGui, + final String name) { + super(id, x, y, 18, 18, name); + this.offset = new Vector2(); + this.stuck = false; + this.offset = offset; + this.mainGui = mainGui; + } + + public GuiButtonPress(final int id, final int x, final int y, + final Vector2 offset, final GuiBase mainGui) { + this(id, x, y, offset, mainGui, ""); + } + + public GuiButtonPress(final int id, final int x, final int y, + final Vector2 offset) { + this(id, x, y, offset, null, ""); + } + + public GuiButtonPress(final int id, final int x, final int y) { + this(id, x, y, new Vector2()); + } + + @Override + public void drawButton(final Minecraft minecraft, final int x, + final int y) { + if (this.visible) { + Minecraft.getMinecraft().renderEngine.bindTexture( + new ResourceLocation("mffs", "textures/gui/gui_button.png")); + if (this.stuck) { + GL11.glColor4f(0.6f, 0.6f, 0.6f, 1.0f); + } else if (this.isPointInRegion(this.xPosition, this.yPosition, + this.width, this.height, x, y)) { + GL11.glColor4f(0.85f, 0.85f, 0.85f, 1.0f); + } else { + GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f); + } + this.drawTexturedModalRect(this.xPosition, this.yPosition, + this.offset.intX(), this.offset.intY(), + this.width, this.height); + this.mouseDragged(minecraft, x, y); + } + } + + @Override + protected void mouseDragged(final Minecraft minecraft, final int x, + final int y) { + if (this.mainGui != null && this.displayString != null && + this.displayString.length() > 0 && + this.isPointInRegion(this.xPosition, this.yPosition, this.width, + this.height, x, y)) { + final String title = TranslationHelper.getLocal("gui." + this.displayString + ".name"); + this.mainGui.tooltip = TranslationHelper.getLocal("gui." + this.displayString + ".tooltip"); + if (title != null && title.length() > 0) { + this.mainGui.tooltip = title + ": " + this.mainGui.tooltip; + } + } + } + + protected boolean isPointInRegion(final int x, final int y, final int width, + final int height, int checkX, int checkY) { + final int var7 = 0; + final int var8 = 0; + checkX -= var7; + checkY -= var8; + return checkX >= x - 1 && checkX < x + width + 1 && checkY >= y - 1 && + checkY < y + height + 1; + } +} diff --git a/src/main/java/mffs/gui/button/GuiButtonPressTransferMode.java b/src/main/java/mffs/gui/button/GuiButtonPressTransferMode.java new file mode 100644 index 0000000..cdd5159 --- /dev/null +++ b/src/main/java/mffs/gui/button/GuiButtonPressTransferMode.java @@ -0,0 +1,30 @@ +// +// Decompiled by Procyon v0.6.0 +// + +package mffs.gui.button; + +import net.minecraft.client.Minecraft; +import universalelectricity.core.vector.Vector2; +import mffs.base.GuiBase; +import mffs.tileentity.TileEntityFortronCapacitor; + +public class GuiButtonPressTransferMode extends GuiButtonPress +{ + private TileEntityFortronCapacitor tileEntity; + + public GuiButtonPressTransferMode(final int id, final int x, final int y, final GuiBase mainGui, final TileEntityFortronCapacitor tileEntity) { + super(id, x, y, new Vector2(), mainGui); + this.tileEntity = tileEntity; + } + + @Override + public void drawButton(final Minecraft minecraft, final int x, final int y) { + String transferName = this.tileEntity.getTransferMode().name().toLowerCase(); + final char first = Character.toUpperCase(transferName.charAt(0)); + transferName = first + transferName.substring(1); + this.displayString = "transferMode" + transferName; + super.offset.y = 18 * this.tileEntity.getTransferMode().ordinal(); + super.drawButton(minecraft, x, y); + } +} diff --git a/src/main/java/mffs/gui/button/GuiIcon.java b/src/main/java/mffs/gui/button/GuiIcon.java new file mode 100644 index 0000000..9be5951 --- /dev/null +++ b/src/main/java/mffs/gui/button/GuiIcon.java @@ -0,0 +1,70 @@ +package mffs.gui.button; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.renderer.RenderHelper; +import net.minecraft.client.renderer.entity.RenderItem; +import net.minecraft.init.Blocks; +import net.minecraft.item.Item; +import net.minecraft.item.ItemBlock; +import net.minecraft.item.ItemStack; +import org.lwjgl.opengl.GL11; + +public class GuiIcon extends GuiButton { + public static RenderItem itemRenderer; + public ItemStack[] itemStacks; + private int index; + + public GuiIcon(final int par1, final int par2, final int par3, + final ItemStack... itemStacks) { + super(par1, par2, par3, 20, 20, ""); + this.index = 0; + this.itemStacks = itemStacks; + } + + public void setIndex(final int i) { + if (i >= 0 && i < this.itemStacks.length) { + this.index = i; + } + } + + @Override + public void drawButton(final Minecraft par1Minecraft, final int par2, + final int par3) { + super.drawButton(par1Minecraft, par2, par3); + if (this.visible && this.itemStacks[this.index] != null) { + int yDisplacement = 2; + if (this.itemStacks[this.index].getItem() == Item.getItemFromBlock(Blocks.torch) || + this.itemStacks[this.index].getItem() == Item.getItemFromBlock(Blocks.redstone_torch)) { + yDisplacement = 0; + } else if (this.itemStacks[this.index].getItem() instanceof ItemBlock) { + yDisplacement = 3; + } + this.drawItemStack(this.itemStacks[this.index], this.xPosition, + this.yPosition + yDisplacement); + } + } + + protected void drawItemStack(final ItemStack itemStack, int x, int y) { + x += 2; + --y; + final Minecraft mc = Minecraft.getMinecraft(); + final FontRenderer fontRenderer = mc.fontRenderer; + RenderHelper.enableGUIStandardItemLighting(); + GL11.glTranslatef(0.0f, 0.0f, 32.0f); + this.zLevel = 500.0f; + GuiIcon.itemRenderer.zLevel = 500.0f; + GuiIcon.itemRenderer.renderItemAndEffectIntoGUI( + fontRenderer, mc.renderEngine, itemStack, x, y); + GuiIcon.itemRenderer.renderItemOverlayIntoGUI(fontRenderer, mc.renderEngine, + itemStack, x, y); + this.zLevel = 0.0f; + GuiIcon.itemRenderer.zLevel = 0.0f; + RenderHelper.disableStandardItemLighting(); + } + + static { + GuiIcon.itemRenderer = new RenderItem(); + } +} diff --git a/src/main/java/mffs/item/ItemRemoteController.java b/src/main/java/mffs/item/ItemRemoteController.java new file mode 100644 index 0000000..caca7c0 --- /dev/null +++ b/src/main/java/mffs/item/ItemRemoteController.java @@ -0,0 +1,145 @@ +package mffs.item; + +import java.util.List; +import java.util.Set; +import mffs.MFFSHelper; +import mffs.ModularForceFieldSystem; +import mffs.api.card.ICardLink; +import mffs.api.fortron.IFortronFrequency; +import mffs.api.security.Permission; +import mffs.fortron.FrequencyGrid; +import mffs.item.card.ItemCardFrequency; +import net.minecraft.block.Block; +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.ChatComponentText; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; +import net.minecraft.world.chunk.Chunk; +import net.minecraftforge.event.entity.player.PlayerInteractEvent; +import universalelectricity.core.electricity.ElectricityDisplay; +import universalelectricity.core.vector.Vector3; + +public class ItemRemoteController + extends ItemCardFrequency implements ICardLink { + public ItemRemoteController() { super("remoteController"); } + + @Override + public void addInformation(final ItemStack itemStack, + final EntityPlayer player, final List list, + final boolean b) { + super.addInformation(itemStack, player, list, b); + final Vector3 position = this.getLink(itemStack); + if (position != null) { + final Block blockId = position.getBlock(player.worldObj); + if (blockId != null) { + list.add("Linked with: " + blockId.getLocalizedName()); + list.add(position.intX() + ", " + position.intY() + ", " + + position.intZ()); + return; + } + } + list.add("Not linked."); + } + + @Override + public boolean onItemUse(final ItemStack itemStack, final EntityPlayer player, + final World world, final int x, final int y, + final int z, final int side, final float hitX, + final float hitY, final float hitZ) { + if (player.isSneaking()) { + if (!world.isRemote) { + final Vector3 vector = new Vector3(x, y, z); + this.setLink(itemStack, vector); + if (vector.getBlock((IBlockAccess)world) != null) { + player.addChatMessage(new ChatComponentText( + "Linked remote to position: " + x + ", " + y + ", " + z + + " with block: " + vector.getBlock(world).getLocalizedName())); + } + } + return true; + } + return false; + } + + @Override + public ItemStack onItemRightClick(final ItemStack itemStack, + final World world, + final EntityPlayer entityPlayer) { + if (!entityPlayer.isSneaking()) { + final Vector3 position = this.getLink(itemStack); + if (position != null) { + final Block blockId = position.getBlock(world); + if (blockId != null) { + final Chunk chunk = + world.getChunkFromBlockCoords(position.intX(), position.intZ()); + if (chunk != null && chunk.isChunkLoaded && + (MFFSHelper.hasPermission( + world, position, + PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK, + entityPlayer) || + MFFSHelper.hasPermission( + world, position, Permission.REMOTE_CONTROL, entityPlayer))) { + final double requiredEnergy = + Vector3.distance(new Vector3((Entity)entityPlayer), position) * + 10.0; + int receivedEnergy = 0; + final Set fortronTiles = + FrequencyGrid.instance().getFortronTiles( + world, new Vector3((Entity)entityPlayer), 50, + this.getFrequency(itemStack)); + for (final IFortronFrequency fortronTile : fortronTiles) { + final int consumedEnergy = fortronTile.requestFortron( + (int)Math.ceil(requiredEnergy / fortronTiles.size()), true); + if (consumedEnergy > 0) { + if (world.isRemote) { + ModularForceFieldSystem.proxy.renderBeam( + world, + new Vector3((Entity)entityPlayer) + .add(new Vector3( + 0.0, entityPlayer.getEyeHeight() - 0.2, 0.0)), + new Vector3((TileEntity)fortronTile).add(0.5), 0.6f, 0.6f, + 1.0f, 20); + } + receivedEnergy += consumedEnergy; + } + if (receivedEnergy >= requiredEnergy) { + try { + blockId.onBlockActivated(world, position.intX(), + position.intY(), position.intZ(), + entityPlayer, 0, 0.0f, 0.0f, 0.0f); + } catch (final Exception e) { + e.printStackTrace(); + } + return itemStack; + } + } + if (!world.isRemote) { + entityPlayer.addChatMessage(new ChatComponentText( + "Unable to harness " + + ElectricityDisplay.getDisplay( + requiredEnergy, ElectricityDisplay.ElectricUnit.JOULES) + + " from the Fortron field.")); + } + } + } + } + } + return itemStack; + } + + @Override + public void setLink(final ItemStack itemStack, final Vector3 position) { + final NBTTagCompound nbt = MFFSHelper.getNBTTagCompound(itemStack); + nbt.setTag("position", position.writeToNBT(new NBTTagCompound())); + } + + @Override + public Vector3 getLink(final ItemStack itemStack) { + final NBTTagCompound nbt = MFFSHelper.getNBTTagCompound(itemStack); + return Vector3.readFromNBT(nbt.getCompoundTag("position")); + } +} diff --git a/src/main/java/mffs/item/card/ItemCardFrequency.java b/src/main/java/mffs/item/card/ItemCardFrequency.java new file mode 100644 index 0000000..598c5fb --- /dev/null +++ b/src/main/java/mffs/item/card/ItemCardFrequency.java @@ -0,0 +1,77 @@ +package mffs.item.card; + +import icbm.api.IItemFrequency; +import java.util.List; +import mffs.base.TileEntityFrequency; +import mffs.card.ItemCard; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.ChatComponentText; +import net.minecraft.world.World; + +public class ItemCardFrequency extends ItemCard implements IItemFrequency { + public ItemCardFrequency(final String name) { super(name); } + + public ItemCardFrequency() { this("cardFrequency"); } + + @Override + public void addInformation(final ItemStack itemStack, + final EntityPlayer par2EntityPlayer, + final List list, final boolean par4) { + list.add("Frequency: " + this.getFrequency(itemStack)); + } + + @Override + public int getFrequency(final ItemStack itemStack) { + if (itemStack != null) { + if (itemStack.getTagCompound() == null) { + itemStack.setTagCompound(new NBTTagCompound()); + } + return itemStack.getTagCompound().getInteger("frequency"); + } + return 0; + } + + @Override + public void setFrequency(final int frequency, final ItemStack itemStack) { + if (itemStack != null) { + if (itemStack.getTagCompound() == null) { + itemStack.setTagCompound(new NBTTagCompound()); + } + itemStack.getTagCompound().setInteger("frequency", frequency); + } + } + + @Override + public ItemStack onItemRightClick(final ItemStack itemStack, + final World world, + final EntityPlayer player) { + if (!world.isRemote && player.isSneaking()) { + this.setFrequency(world.rand.nextInt(15), itemStack); + player.addChatMessage(new ChatComponentText( + "Generated random frequency: " + this.getFrequency(itemStack))); + } + return itemStack; + } + + @Override + public boolean onItemUse(final ItemStack itemStack, final EntityPlayer player, + final World world, final int x, final int y, + final int z, final int side, final float hitX, + final float hitY, final float hitZ) { + final TileEntity tileEntity = world.getTileEntity(x, y, z); + if (tileEntity instanceof TileEntityFrequency) { + if (!world.isRemote) { + ((TileEntityFrequency)tileEntity) + .setFrequency(this.getFrequency(itemStack)); + world.markBlockForUpdate(x, y, z); + player.addChatMessage(new ChatComponentText( + "Frequency set to: " + this.getFrequency(itemStack))); + } + return true; + } + return false; + } +} diff --git a/src/main/java/mffs/item/card/ItemCardID.java b/src/main/java/mffs/item/card/ItemCardID.java new file mode 100644 index 0000000..32dbd03 --- /dev/null +++ b/src/main/java/mffs/item/card/ItemCardID.java @@ -0,0 +1,106 @@ +package mffs.item.card; + +import java.util.List; +import mffs.MFFSHelper; +import mffs.api.card.ICardIdentification; +import mffs.api.security.Permission; +import mffs.card.ItemCard; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.world.World; +import universalelectricity.prefab.TranslationHelper; + +public class ItemCardID extends ItemCard implements ICardIdentification { + + public ItemCardID() { super("cardIdentification"); } + + public ItemCardID(final String name) { super(name); } + + @Override + public boolean hitEntity(final ItemStack itemStack, + final EntityLivingBase entityLiving, + final EntityLivingBase par3EntityLiving) { + if (entityLiving instanceof EntityPlayer) { + this.setUsername(itemStack, + ((EntityPlayer)entityLiving).getDisplayName()); + } + return false; + } + + @Override + public void addInformation(final ItemStack itemStack, + final EntityPlayer player, final List info, + final boolean b) { + if (this.getUsername(itemStack) != null && + !this.getUsername(itemStack).isEmpty()) { + info.add("Username: " + this.getUsername(itemStack)); + } else { + info.add("Unidentified"); + } + String tooltip = ""; + boolean isFirst = true; + for (final Permission permission : Permission.getPermissions()) { + if (this.hasPermission(itemStack, permission)) { + if (!isFirst) { + tooltip += ", "; + } + isFirst = false; + tooltip += + TranslationHelper.getLocal("gui." + permission.name + ".name"); + } + } + if (tooltip != null && tooltip.length() > 0) { + info.addAll(MFFSHelper.splitStringPerWord(tooltip, 5)); + } + } + + @Override + public ItemStack onItemRightClick(final ItemStack itemStack, + final World par2World, + final EntityPlayer entityPlayer) { + this.setUsername(itemStack, entityPlayer.getDisplayName()); + return itemStack; + } + + @Override + public void setUsername(final ItemStack itemStack, final String username) { + final NBTTagCompound nbtTagCompound = + MFFSHelper.getNBTTagCompound(itemStack); + nbtTagCompound.setString("name", username); + } + + @Override + public String getUsername(final ItemStack itemStack) { + final NBTTagCompound nbtTagCompound = + MFFSHelper.getNBTTagCompound(itemStack); + if (nbtTagCompound != null && nbtTagCompound.getString("name") != "") { + return nbtTagCompound.getString("name"); + } + return null; + } + + @Override + public boolean hasPermission(final ItemStack itemStack, + final Permission permission) { + final NBTTagCompound nbt = MFFSHelper.getNBTTagCompound(itemStack); + return nbt.getBoolean("mffs_permission_" + permission.id); + } + + @Override + public boolean addPermission(final ItemStack itemStack, + final Permission permission) { + final NBTTagCompound nbt = MFFSHelper.getNBTTagCompound(itemStack); + nbt.setBoolean("mffs_permission_" + permission.id, true); + return false; + } + + @Override + public boolean removePermission(final ItemStack itemStack, + final Permission permission) { + final NBTTagCompound nbt = MFFSHelper.getNBTTagCompound(itemStack); + nbt.setBoolean("mffs_permission_" + permission.id, false); + return false; + } +} diff --git a/src/main/java/mffs/item/card/ItemCardInfinite.java b/src/main/java/mffs/item/card/ItemCardInfinite.java new file mode 100644 index 0000000..14f3fed --- /dev/null +++ b/src/main/java/mffs/item/card/ItemCardInfinite.java @@ -0,0 +1,8 @@ +package mffs.item.card; + +import mffs.api.card.ICardInfinite; +import mffs.card.ItemCard; + +public class ItemCardInfinite extends ItemCard implements ICardInfinite { + public ItemCardInfinite() { super("cardInfinite"); } +} diff --git a/src/main/java/mffs/item/card/ItemCardLink.java b/src/main/java/mffs/item/card/ItemCardLink.java new file mode 100644 index 0000000..a9b8b5c --- /dev/null +++ b/src/main/java/mffs/item/card/ItemCardLink.java @@ -0,0 +1,66 @@ +package mffs.item.card; + +import java.util.List; +import mffs.MFFSHelper; +import mffs.api.card.ICardLink; +import mffs.card.ItemCard; +import net.minecraft.block.Block; +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.ChatComponentText; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; +import universalelectricity.core.vector.Vector3; + +public class ItemCardLink extends ItemCard implements ICardLink { + public ItemCardLink() { super("cardLink"); } + + @Override + public void addInformation(final ItemStack itemStack, + final EntityPlayer player, final List list, + final boolean b) { + final Vector3 position = this.getLink(itemStack); + if (position != null) { + final Block blockId = + position.getBlock((IBlockAccess)((Entity)player).worldObj); + if (blockId != null) { + list.add("Linked with: " + blockId.getLocalizedName()); + list.add(position.intX() + ", " + position.intY() + ", " + + position.intZ()); + return; + } + } + list.add("Not linked."); + } + + public boolean onItemUse(final ItemStack itemStack, final EntityPlayer player, + final World world, final int x, final int y, + final int z, final int par7, final float par8, + final float par9, final float par10) { + if (!world.isRemote) { + final Vector3 vector = new Vector3(x, y, z); + this.setLink(itemStack, vector); + Block block = vector.getBlock(world); + if (block != null) { + player.addChatMessage(new ChatComponentText( + "Linked card to position: " + x + ", " + y + ", " + z + + " with block: " + block.getLocalizedName())); + } + } + return true; + } + + @Override + public void setLink(final ItemStack itemStack, final Vector3 position) { + final NBTTagCompound nbt = MFFSHelper.getNBTTagCompound(itemStack); + nbt.setTag("position", position.writeToNBT(new NBTTagCompound())); + } + + @Override + public Vector3 getLink(final ItemStack itemStack) { + final NBTTagCompound nbt = MFFSHelper.getNBTTagCompound(itemStack); + return Vector3.readFromNBT(nbt.getCompoundTag("position")); + } +} diff --git a/src/main/java/mffs/item/mode/ItemMode.java b/src/main/java/mffs/item/mode/ItemMode.java new file mode 100644 index 0000000..a10db9b --- /dev/null +++ b/src/main/java/mffs/item/mode/ItemMode.java @@ -0,0 +1,27 @@ +package mffs.item.mode; + +import universalelectricity.core.vector.Vector3; +import mffs.api.IFieldInteraction; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import mffs.api.IProjector; +import mffs.api.modules.IProjectorMode; +import mffs.base.ItemBase; + +public abstract class ItemMode extends ItemBase implements IProjectorMode +{ + public ItemMode(final String name) { + super(name); + this.setMaxStackSize(1); + } + + @SideOnly(Side.CLIENT) + @Override + public void render(final IProjector projector, final double x, final double y, final double z, final float f, final long ticks) { + } + + @Override + public boolean isInField(final IFieldInteraction projector, final Vector3 position) { + return false; + } +} diff --git a/src/main/java/mffs/item/mode/ItemModeCube.java b/src/main/java/mffs/item/mode/ItemModeCube.java new file mode 100644 index 0000000..1ac8b52 --- /dev/null +++ b/src/main/java/mffs/item/mode/ItemModeCube.java @@ -0,0 +1,79 @@ +package mffs.item.mode; + +import calclavia.lib.CalculationHelper; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import java.util.HashSet; +import java.util.Set; +import mffs.api.IFieldInteraction; +import mffs.api.IProjector; +import mffs.render.model.ModelCube; +import net.minecraft.tileentity.TileEntity; +import org.lwjgl.opengl.GL11; +import universalelectricity.core.vector.Vector3; +import universalelectricity.prefab.vector.Region3; + +public class ItemModeCube extends ItemMode { + public ItemModeCube(final String name) { super(name); } + + public ItemModeCube(final int i) { this("modeCube"); } + + @Override + public Set getExteriorPoints(final IFieldInteraction projector) { + final Set fieldBlocks = new HashSet<>(); + final Vector3 posScale = projector.getPositiveScale(); + final Vector3 negScale = projector.getNegativeScale(); + for (float x = (float)(-negScale.intX()); x <= posScale.intX(); x += 0.5f) { + for (float z = (float)(-negScale.intZ()); z <= posScale.intZ(); + z += 0.5f) { + for (float y = (float)(-negScale.intY()); y <= posScale.intY(); + y += 0.5f) { + if (y == -negScale.intY() || y == posScale.intY() || + x == -negScale.intX() || x == posScale.intX() || + z == -negScale.intZ() || z == posScale.intZ()) { + fieldBlocks.add(new Vector3(x, y, z)); + } + } + } + } + return fieldBlocks; + } + + @Override + public Set getInteriorPoints(final IFieldInteraction projector) { + final Set fieldBlocks = new HashSet<>(); + final Vector3 posScale = projector.getPositiveScale(); + final Vector3 negScale = projector.getNegativeScale(); + for (int x = -negScale.intX(); x <= posScale.intX(); ++x) { + for (int z = -negScale.intZ(); z <= posScale.intZ(); ++z) { + for (int y = -negScale.intY(); y <= posScale.intY(); ++y) { + fieldBlocks.add(new Vector3(x, y, z)); + } + } + } + return fieldBlocks; + } + + @Override + public boolean isInField(final IFieldInteraction projector, + final Vector3 position) { + final Vector3 projectorPos = new Vector3((TileEntity)projector); + projectorPos.add(projector.getTranslation()); + final Vector3 relativePosition = position.clone().subtract(projectorPos); + CalculationHelper.rotateByAngle(relativePosition, + -projector.getRotationYaw(), + -projector.getRotationPitch()); + final Region3 region = + new Region3(projector.getNegativeScale().clone().multiply(-1.0), + projector.getPositiveScale()); + return region.isIn(relativePosition); + } + + @SideOnly(Side.CLIENT) + @Override + public void render(final IProjector projector, final double x, final double y, + final double z, final float f, final long ticks) { + GL11.glScalef(0.5f, 0.5f, 0.5f); + ModelCube.INSTNACE.render(); + } +} diff --git a/src/main/java/mffs/item/mode/ItemModeSphere.java b/src/main/java/mffs/item/mode/ItemModeSphere.java new file mode 100644 index 0000000..5ceeb4f --- /dev/null +++ b/src/main/java/mffs/item/mode/ItemModeSphere.java @@ -0,0 +1,98 @@ +package mffs.item.mode; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import java.util.HashSet; +import java.util.Set; +import mffs.ModularForceFieldSystem; +import mffs.api.IFieldInteraction; +import mffs.api.IProjector; +import mffs.render.model.ModelCube; +import net.minecraft.tileentity.TileEntity; +import org.lwjgl.opengl.GL11; +import universalelectricity.core.vector.Vector3; + +public class ItemModeSphere extends ItemMode { + public ItemModeSphere(final int i) { super("modeSphere"); } + + @Override + public Set getExteriorPoints(final IFieldInteraction projector) { + final Set fieldBlocks = new HashSet<>(); + final int radius = projector.getModuleCount( + ModularForceFieldSystem.itemModuleScale, new int[0]); + for (int steps = (int)Math.ceil(3.141592653589793 / + Math.atan(1.0 / radius / 2.0)), + phi_n = 0; + phi_n < 2 * steps; ++phi_n) { + for (int theta_n = 0; theta_n < steps; ++theta_n) { + final double phi = 6.283185307179586 / steps * phi_n; + final double theta = 3.141592653589793 / steps * theta_n; + final Vector3 point = + new Vector3(Math.sin(theta) * Math.cos(phi), Math.cos(theta), + Math.sin(theta) * Math.sin(phi)) + .multiply(radius); + fieldBlocks.add(point); + } + } + return fieldBlocks; + } + + @Override + public Set getInteriorPoints(final IFieldInteraction projector) { + final Set fieldBlocks = new HashSet<>(); + final Vector3 translation = projector.getTranslation(); + for (int radius = projector.getModuleCount( + ModularForceFieldSystem.itemModuleScale, new int[0]), + x = -radius; + x <= radius; ++x) { + for (int z = -radius; z <= radius; ++z) { + for (int y = -radius; y <= radius; ++y) { + final Vector3 position = new Vector3(x, y, z); + if (this.isInField( + projector, + Vector3.add(position, new Vector3((TileEntity)projector)) + .add(translation))) { + fieldBlocks.add(position); + } + } + } + } + return fieldBlocks; + } + + @Override + public boolean isInField(final IFieldInteraction projector, + final Vector3 position) { + return new Vector3((TileEntity)projector) + .add(projector.getTranslation()) + .distanceTo(position) < + projector.getModuleCount(ModularForceFieldSystem.itemModuleScale, + new int[0]); + } + + @SideOnly(Side.CLIENT) + @Override + public void render(final IProjector projector, final double x1, + final double y1, final double z1, final float f, + final long ticks) { + final float scale = 0.15f; + GL11.glScalef(scale, scale, scale); + final float radius = 1.5f; + for (int steps = (int)Math.ceil(3.141592653589793 / + Math.atan(1.0 / radius / 2.0)), + phi_n = 0; + phi_n < 2 * steps; ++phi_n) { + for (int theta_n = 0; theta_n < steps; ++theta_n) { + final double phi = 6.283185307179586 / steps * phi_n; + final double theta = 3.141592653589793 / steps * theta_n; + final Vector3 vector = + new Vector3(Math.sin(theta) * Math.cos(phi), Math.cos(theta), + Math.sin(theta) * Math.sin(phi)); + vector.multiply(radius); + GL11.glTranslated(vector.x, vector.y, vector.z); + ModelCube.INSTNACE.render(); + GL11.glTranslated(-vector.x, -vector.y, -vector.z); + } + } + } +} diff --git a/src/main/java/mffs/item/mode/ItemModeTube.java b/src/main/java/mffs/item/mode/ItemModeTube.java new file mode 100644 index 0000000..686e696 --- /dev/null +++ b/src/main/java/mffs/item/mode/ItemModeTube.java @@ -0,0 +1,61 @@ +package mffs.item.mode; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import mffs.render.model.ModelPlane; +import org.lwjgl.opengl.GL11; +import mffs.api.IProjector; +import universalelectricity.core.vector.Vector3; +import net.minecraft.world.IBlockAccess; +import net.minecraftforge.common.util.ForgeDirection; +import net.minecraft.tileentity.TileEntity; +import java.util.HashSet; +import java.util.Set; +import mffs.api.IFieldInteraction; + +public class ItemModeTube extends ItemModeCube +{ + public ItemModeTube() { + super("modeTube"); + } + + @Override + public Set getExteriorPoints(final IFieldInteraction projector) { + final Set fieldBlocks = new HashSet<>(); + final ForgeDirection direction = projector.getDirection((IBlockAccess)((TileEntity)projector).getWorldObj(), ((TileEntity)projector).xCoord, ((TileEntity)projector).yCoord, ((TileEntity)projector).zCoord); + final Vector3 posScale = projector.getPositiveScale(); + final Vector3 negScale = projector.getNegativeScale(); + for (float x = (float)(-negScale.intX()); x <= posScale.intX(); x += 0.5f) { + for (float z = (float)(-negScale.intZ()); z <= posScale.intZ(); z += 0.5f) { + for (float y = (float)(-negScale.intY()); y <= posScale.intY(); y += 0.5f) { + if (direction != ForgeDirection.UP && direction != ForgeDirection.DOWN && (y == -negScale.intY() || y == posScale.intY())) { + fieldBlocks.add(new Vector3(x, y, z)); + } + else if (direction != ForgeDirection.NORTH && direction != ForgeDirection.SOUTH && (z == -negScale.intZ() || z == posScale.intZ())) { + fieldBlocks.add(new Vector3(x, y, z)); + } + else if (direction != ForgeDirection.WEST && direction != ForgeDirection.EAST && (x == -negScale.intX() || x == posScale.intX())) { + fieldBlocks.add(new Vector3(x, y, z)); + } + } + } + } + return fieldBlocks; + } + + @SideOnly(Side.CLIENT) + @Override + public void render(final IProjector projector, final double x, final double y, final double z, final float f, final long ticks) { + GL11.glScalef(0.5f, 0.5f, 0.5f); + GL11.glTranslatef(-0.5f, 0.0f, 0.0f); + ModelPlane.INSTNACE.render(); + GL11.glTranslatef(1.0f, 0.0f, 0.0f); + ModelPlane.INSTNACE.render(); + GL11.glTranslatef(-0.5f, 0.0f, 0.0f); + GL11.glRotatef(90.0f, 0.0f, 1.0f, 0.0f); + GL11.glTranslatef(0.5f, 0.0f, 0.0f); + ModelPlane.INSTNACE.render(); + GL11.glTranslatef(-1.0f, 0.0f, 0.0f); + ModelPlane.INSTNACE.render(); + } +} diff --git a/src/main/java/mffs/item/module/ItemModule.java b/src/main/java/mffs/item/module/ItemModule.java new file mode 100644 index 0000000..002cdb2 --- /dev/null +++ b/src/main/java/mffs/item/module/ItemModule.java @@ -0,0 +1,68 @@ +package mffs.item.module; + +import java.util.List; +import java.util.Set; +import mffs.api.IFieldInteraction; +import mffs.api.IProjector; +import mffs.api.modules.IModule; +import mffs.base.ItemBase; +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; +import universalelectricity.core.vector.Vector3; + +public class ItemModule extends ItemBase implements IModule { + private float fortronCost; + + public ItemModule(final String name) { + super(name); + this.fortronCost = 0.5f; + } + + @Override + public void addInformation(final ItemStack itemStack, + final EntityPlayer player, final List info, + final boolean b) { + info.add("Fortron: " + this.getFortronCost(1.0f)); + super.addInformation(itemStack, player, info, b); + } + + @Override + public void onCalculate(final IFieldInteraction projector, + final Set position) {} + + @Override + public boolean onProject(final IProjector projector, + final Set fields) { + return false; + } + + @Override + public int onProject(final IProjector projector, final Vector3 position) { + return 0; + } + + @Override + public boolean onCollideWithForceField(final World world, final int x, + final int y, final int z, + final Entity entity, + final ItemStack moduleStack) { + return false; + } + + public ItemModule setCost(final float cost) { + this.fortronCost = cost; + return this; + } + + public ItemModule setMaxStackSize(final int par1) { + super.setMaxStackSize(par1); + return this; + } + + @Override + public float getFortronCost(final float amplifier) { + return this.fortronCost * amplifier; + } +} diff --git a/src/main/java/mffs/item/module/interdiction/ItemModuleAntiFriendly.java b/src/main/java/mffs/item/module/interdiction/ItemModuleAntiFriendly.java new file mode 100644 index 0000000..454b5ed --- /dev/null +++ b/src/main/java/mffs/item/module/interdiction/ItemModuleAntiFriendly.java @@ -0,0 +1,22 @@ +package mffs.item.module.interdiction; + +import mffs.ModularForceFieldSystem; +import net.minecraft.entity.INpc; +import net.minecraft.entity.monster.IMob; +import net.minecraft.entity.EntityLivingBase; +import mffs.api.security.IInterdictionMatrix; + +public class ItemModuleAntiFriendly extends ItemModuleInterdictionMatrix +{ + public ItemModuleAntiFriendly() { + super("moduleAntiFriendly"); + } + + @Override + public boolean onDefend(final IInterdictionMatrix interdictionMatrix, final EntityLivingBase entityLiving) { + if (!(entityLiving instanceof IMob) || entityLiving instanceof INpc) { + entityLiving.attackEntityFrom(ModularForceFieldSystem.damagefieldShock, Integer.MAX_VALUE); + } + return false; + } +} diff --git a/src/main/java/mffs/item/module/interdiction/ItemModuleAntiHostile.java b/src/main/java/mffs/item/module/interdiction/ItemModuleAntiHostile.java new file mode 100644 index 0000000..756c40b --- /dev/null +++ b/src/main/java/mffs/item/module/interdiction/ItemModuleAntiHostile.java @@ -0,0 +1,22 @@ +package mffs.item.module.interdiction; + +import mffs.ModularForceFieldSystem; +import net.minecraft.entity.INpc; +import net.minecraft.entity.monster.IMob; +import net.minecraft.entity.EntityLivingBase; +import mffs.api.security.IInterdictionMatrix; + +public class ItemModuleAntiHostile extends ItemModuleInterdictionMatrix +{ + public ItemModuleAntiHostile() { + super("moduleAntiHostile"); + } + + @Override + public boolean onDefend(final IInterdictionMatrix interdictionMatrix, final EntityLivingBase entityLiving) { + if (entityLiving instanceof IMob && !(entityLiving instanceof INpc)) { + entityLiving.attackEntityFrom(ModularForceFieldSystem.damagefieldShock, 20); + } + return false; + } +} diff --git a/src/main/java/mffs/item/module/interdiction/ItemModuleAntiPersonnel.java b/src/main/java/mffs/item/module/interdiction/ItemModuleAntiPersonnel.java new file mode 100644 index 0000000..506051f --- /dev/null +++ b/src/main/java/mffs/item/module/interdiction/ItemModuleAntiPersonnel.java @@ -0,0 +1,39 @@ +package mffs.item.module.interdiction; + +import mffs.ModularForceFieldSystem; +import mffs.Settings; +import mffs.api.security.IInterdictionMatrix; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ChatComponentText; + +public class ItemModuleAntiPersonnel extends ItemModuleInterdictionMatrix { + public ItemModuleAntiPersonnel() { super("moduleAntiPersonnel"); } + + @Override + public boolean onDefend(final IInterdictionMatrix interdictionMatrix, + final EntityLivingBase entityLiving) { + final boolean hasPermission = false; + if (!hasPermission && entityLiving instanceof EntityPlayer) { + final EntityPlayer player = (EntityPlayer)entityLiving; + if (!player.capabilities.isCreativeMode && + !player.isEntityInvulnerable()) { + for (int i = 0; i < player.inventory.getSizeInventory(); ++i) { + if (player.inventory.getStackInSlot(i) != null) { + interdictionMatrix.mergeIntoInventory( + player.inventory.getStackInSlot(i)); + player.inventory.setInventorySlotContents(i, (ItemStack)null); + } + } + player.attackEntityFrom(ModularForceFieldSystem.damagefieldShock, + Integer.MAX_VALUE); + interdictionMatrix.requestFortron(Settings.INTERDICTION_MURDER_ENERGY, + false); + player.addChatMessage(new ChatComponentText( + "[" + interdictionMatrix.getInventoryName() + "] Fairwell.")); + } + } + return false; + } +} diff --git a/src/main/java/mffs/item/module/interdiction/ItemModuleConfiscate.java b/src/main/java/mffs/item/module/interdiction/ItemModuleConfiscate.java new file mode 100644 index 0000000..541b19a --- /dev/null +++ b/src/main/java/mffs/item/module/interdiction/ItemModuleConfiscate.java @@ -0,0 +1,77 @@ +package mffs.item.module.interdiction; + +import java.util.Set; +import mffs.api.security.IBiometricIdentifier; +import mffs.api.security.IInterdictionMatrix; +import mffs.api.security.Permission; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ChatComponentText; + +public class ItemModuleConfiscate extends ItemModuleInterdictionMatrix { + public ItemModuleConfiscate() { super("moduleConfiscate"); } + + @Override + public boolean onDefend(final IInterdictionMatrix interdictionMatrix, + final EntityLivingBase entityLiving) { + if (entityLiving instanceof EntityPlayer) { + final EntityPlayer player = (EntityPlayer)entityLiving; + final IBiometricIdentifier biometricIdentifier = + interdictionMatrix.getBiometricIdentifier(); + if (biometricIdentifier != null && + biometricIdentifier.isAccessGranted( + player.getDisplayName(), + Permission.DEFENSE_STATION_CONFISCATION)) { + return false; + } + } + final Set controlledStacks = + interdictionMatrix.getFilteredItems(); + int confiscationCount = 0; + IInventory inventory = null; + if (entityLiving instanceof EntityPlayer) { + final IBiometricIdentifier biometricIdentifier2 = + interdictionMatrix.getBiometricIdentifier(); + if (biometricIdentifier2 != null && + biometricIdentifier2.isAccessGranted( + ((EntityPlayer)entityLiving).getDisplayName(), + Permission.BYPASS_INTERDICTION_MATRIX)) { + return false; + } + final EntityPlayer player2 = (EntityPlayer)entityLiving; + inventory = (IInventory)player2.inventory; + } else if (entityLiving instanceof IInventory) { + inventory = (IInventory)entityLiving; + } + if (inventory != null) { + for (int i = 0; i < inventory.getSizeInventory(); ++i) { + final ItemStack checkStack = inventory.getStackInSlot(i); + if (checkStack != null) { + boolean stacksMatch = false; + for (final ItemStack itemStack : controlledStacks) { + if (itemStack != null && itemStack.isItemEqual(checkStack)) { + stacksMatch = true; + break; + } + } + if ((interdictionMatrix.getFilterMode() && stacksMatch) || + (!interdictionMatrix.getFilterMode() && !stacksMatch)) { + interdictionMatrix.mergeIntoInventory(inventory.getStackInSlot(i)); + inventory.setInventorySlotContents(i, (ItemStack)null); + ++confiscationCount; + } + } + } + if (confiscationCount > 0 && entityLiving instanceof EntityPlayer) { + ((EntityPlayer)entityLiving) + .addChatMessage(new ChatComponentText( + "[" + interdictionMatrix.getInventoryName() + "] " + + confiscationCount + " of your item(s) has been confiscated.")); + } + interdictionMatrix.requestFortron(confiscationCount, true); + } + return false; + } +} diff --git a/src/main/java/mffs/item/module/interdiction/ItemModuleInterdictionMatrix.java b/src/main/java/mffs/item/module/interdiction/ItemModuleInterdictionMatrix.java new file mode 100644 index 0000000..1589217 --- /dev/null +++ b/src/main/java/mffs/item/module/interdiction/ItemModuleInterdictionMatrix.java @@ -0,0 +1,28 @@ +package mffs.item.module.interdiction; + +import java.util.List; +import mffs.api.modules.IInterdictionMatrixModule; +import mffs.api.security.IInterdictionMatrix; +import mffs.item.module.ItemModule; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; + +public class ItemModuleInterdictionMatrix + extends ItemModule implements IInterdictionMatrixModule { + public ItemModuleInterdictionMatrix(final String name) { super(name); } + + @Override + public void addInformation(final ItemStack itemStack, + final EntityPlayer player, final List info, + final boolean b) { + info.add("§4Interdiction Matrix"); + super.addInformation(itemStack, player, info, b); + } + + @Override + public boolean onDefend(final IInterdictionMatrix interdictionMatrix, + final EntityLivingBase entityLiving) { + return false; + } +} diff --git a/src/main/java/mffs/item/module/interdiction/ItemModuleWarn.java b/src/main/java/mffs/item/module/interdiction/ItemModuleWarn.java new file mode 100644 index 0000000..e316f59 --- /dev/null +++ b/src/main/java/mffs/item/module/interdiction/ItemModuleWarn.java @@ -0,0 +1,22 @@ +package mffs.item.module.interdiction; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.ChatComponentText; +import net.minecraft.entity.EntityLivingBase; +import mffs.api.security.IInterdictionMatrix; + +public class ItemModuleWarn extends ItemModuleInterdictionMatrix +{ + public ItemModuleWarn() { + super("moduleWarn"); + } + + @Override + public boolean onDefend(final IInterdictionMatrix interdictionMatrix, final EntityLivingBase entityLiving) { + final boolean hasPermission = false; + if (!hasPermission && entityLiving instanceof EntityPlayer) { + ((EntityPlayer)entityLiving).addChatMessage(new ChatComponentText("[" + interdictionMatrix.getInventoryName() + "] Leave this zone immediately. You have no right to enter.")); + } + return false; + } +} diff --git a/src/main/java/mffs/item/module/projector/ItemModeCustom.java b/src/main/java/mffs/item/module/projector/ItemModeCustom.java new file mode 100644 index 0000000..8ee7d95 --- /dev/null +++ b/src/main/java/mffs/item/module/projector/ItemModeCustom.java @@ -0,0 +1,339 @@ +package mffs.item.module.projector; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import java.io.File; +import java.io.IOException; +import java.io.UncheckedIOException; +import java.nio.file.Paths; +import java.util.HashMap; +import java.util.List; +import java.util.Set; +import mffs.MFFSHelper; +import mffs.ModularForceFieldSystem; +import mffs.Settings; +import mffs.api.ICache; +import mffs.api.IFieldInteraction; +import mffs.api.IProjector; +import mffs.api.modules.IProjectorMode; +import mffs.item.mode.ItemMode; +import net.minecraft.block.Block; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.CompressedStreamTools; +import net.minecraft.nbt.NBTBase; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.server.MinecraftServer; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.ChatComponentText; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; +import universalelectricity.core.vector.Vector3; + +public class ItemModeCustom extends ItemMode implements ICache { + private final HashMap cache; + + public ItemModeCustom() { + super("modeCustom"); + this.cache = new HashMap<>(); + } + + @Override + public void addInformation(final ItemStack itemStack, + final EntityPlayer par2EntityPlayer, + final List list, final boolean par4) { + final NBTTagCompound nbt = MFFSHelper.getNBTTagCompound(itemStack); + list.add("Mode: " + (nbt.getBoolean("mode") ? "Additive" : "Substraction")); + final Vector3 point1 = Vector3.readFromNBT(nbt.getCompoundTag("point1")); + list.add("Point 1: " + point1.intX() + ", " + point1.intY() + ", " + + point1.intZ()); + final Vector3 point2 = Vector3.readFromNBT(nbt.getCompoundTag("point2")); + list.add("Point 2: " + point2.intX() + ", " + point2.intY() + ", " + + point2.intZ()); + final int modeID = nbt.getInteger("id"); + if (modeID > 0) { + list.add("Mode ID: " + modeID); + final int fieldSize = nbt.getInteger("fieldSize"); + if (fieldSize > 0) { + list.add("Field size: " + fieldSize); + } else { + list.add("Field not saved."); + } + } + if (GuiScreen.isShiftKeyDown()) { + super.addInformation(itemStack, par2EntityPlayer, list, par4); + } else { + list.add("Hold shift for more..."); + } + } + + public ItemStack onItemRightClick(final ItemStack itemStack, + final World world, + final EntityPlayer entityPlayer) { + if (!world.isRemote) { + if (entityPlayer.isSneaking()) { + final NBTTagCompound nbt = MFFSHelper.getNBTTagCompound(itemStack); + if (nbt != null) { + final Vector3 point1 = + Vector3.readFromNBT(nbt.getCompoundTag("point1")); + final Vector3 point2 = + Vector3.readFromNBT(nbt.getCompoundTag("point2")); + if (nbt.hasKey("point1") && nbt.hasKey("point2") && + !point1.equals(point2) && + point1.distanceTo(point2) < Settings.MAX_FORCE_FIELD_SCALE) { + nbt.removeTag("point1"); + nbt.removeTag("point2"); + Vector3 midPoint = new Vector3(); + midPoint.x = (point1.x + point2.x) / 2.0; + midPoint.y = (point1.y + point2.y) / 2.0; + midPoint.z = (point1.z + point2.z) / 2.0; + midPoint = midPoint.floor(); + point1.subtract(midPoint); + point2.subtract(midPoint); + final Vector3 minPoint = new Vector3(Math.min(point1.x, point2.x), + Math.min(point1.y, point2.y), + Math.min(point1.z, point2.z)); + final Vector3 maxPoint = new Vector3(Math.max(point1.x, point2.x), + Math.max(point1.y, point2.y), + Math.max(point1.z, point2.z)); + File saveFile = Paths + .get(this.getSaveDirectory().getPath(), + "custom_mode_" + this.getModeID(itemStack)) + .toFile(); + // TODO: WTF happened to NBTFileLoader?! + NBTTagCompound saveNBT = null; + try { + saveNBT = CompressedStreamTools.read(saveFile); + } catch (IOException e1) { + throw new UncheckedIOException(e1); + } + + // NBTTagCompound saveNBT = NBTFileLoader.loadData( + // this.getSaveDirectory(), + // "custom_mode_" + this.getModeID(itemStack)); + + if (saveNBT == null) { + saveNBT = new NBTTagCompound(); + } + NBTTagList list; + if (saveNBT.hasKey("fieldPoints")) { + list = (NBTTagList)saveNBT.getTag("fieldPoints"); + } else { + list = new NBTTagList(); + } + for (int x = minPoint.intX(); x <= maxPoint.intX(); ++x) { + for (int y = minPoint.intY(); y <= maxPoint.intY(); ++y) { + for (int z = minPoint.intZ(); z <= maxPoint.intZ(); ++z) { + final Vector3 position = new Vector3(x, y, z); + final Vector3 targetCheck = Vector3.add(midPoint, position); + final Block blockID = targetCheck.getBlock(world); + if (blockID != Blocks.air) { + if (nbt.getBoolean("mode")) { + final NBTTagCompound vectorTag = new NBTTagCompound(); + position.writeToNBT(vectorTag); + vectorTag.setInteger("blockID", + Block.getIdFromBlock(blockID)); + vectorTag.setInteger( + "blockMetadata", + targetCheck.getBlockMetadata((IBlockAccess)world)); + list.appendTag((NBTBase)vectorTag); + } else { + for (int i = 0; i < list.tagCount(); ++i) { + final Vector3 vector = Vector3.readFromNBT( + (NBTTagCompound)list.getCompoundTagAt(i)); + if (vector.equals(position)) { + list.removeTag(i); + } + } + } + } + } + } + } + saveNBT.setTag("fieldPoints", (NBTBase)list); + nbt.setInteger("fieldSize", list.tagCount()); + + try { + CompressedStreamTools.write(saveNBT, saveFile); + } catch (IOException e) { + throw new UncheckedIOException(e); + } + + // NBTFileLoader.saveData(this.getSaveDirectory(), + // "custom_mode_" + this.getModeID(itemStack), + // saveNBT); + this.clearCache(); + entityPlayer.addChatMessage( + new ChatComponentText("Field structure saved.")); + } + } + } else { + final NBTTagCompound nbt = MFFSHelper.getNBTTagCompound(itemStack); + if (nbt != null) { + nbt.setBoolean("mode", !nbt.getBoolean("mode")); + entityPlayer.addChatMessage(new ChatComponentText( + "Changed selection mode to " + + (nbt.getBoolean("mode") ? "additive" : "substraction"))); + } + } + } + return itemStack; + } + + public boolean onItemUse(final ItemStack itemStack, + final EntityPlayer entityPlayer, final World world, + final int x, final int y, final int z, + final int par7, final float par8, final float par9, + final float par10) { + if (!world.isRemote) { + final NBTTagCompound nbt = MFFSHelper.getNBTTagCompound(itemStack); + if (nbt != null) { + final Vector3 point1 = + Vector3.readFromNBT(nbt.getCompoundTag("point1")); + if (!nbt.hasKey("point1") || + point1.equals(new Vector3(0.0, 0.0, 0.0))) { + nbt.setTag("point1", + new Vector3(x, y, z).writeToNBT(new NBTTagCompound())); + entityPlayer.addChatMessage(new ChatComponentText( + "Set point 1: " + x + ", " + y + ", " + z + ".")); + } else { + nbt.setTag("point2", + new Vector3(x, y, z).writeToNBT(new NBTTagCompound())); + entityPlayer.addChatMessage(new ChatComponentText( + "Set point 2: " + x + ", " + y + ", " + z + ".")); + } + } + } + return true; + } + + public int getModeID(final ItemStack itemStack) { + final NBTTagCompound nbt = MFFSHelper.getNBTTagCompound(itemStack); + int id = nbt.getInteger("id"); + if (id <= 0) { + nbt.setInteger("id", this.getNextAvaliableID()); + id = nbt.getInteger("id"); + } + return id; + } + + public int getNextAvaliableID() { + int i = 1; + i += this.getSaveDirectory().list().length; + return i; + } + + public File getSaveDirectory() { + final File saveDirectory = + // TODO: might be wrong path? + Paths.get(MinecraftServer.getServer().getFolderName(), "saves") + .toFile(); + if (!saveDirectory.exists()) { + saveDirectory.mkdir(); + } + final File file = new File(saveDirectory, "mffs"); + if (!file.exists()) { + file.mkdir(); + } + return file; + } + + public Set getFieldBlocks(final IFieldInteraction projector, + final ItemStack itemStack) { + return this.getFieldBlockMap(projector, itemStack).keySet(); + } + + public HashMap + getFieldBlockMap(final IFieldInteraction projector, + final ItemStack itemStack) { + final String cacheID = "itemStack_" + itemStack.hashCode(); + if (Settings.USE_CACHE && this.cache.containsKey(cacheID) && + this.cache.get(cacheID) instanceof HashMap) { + return (HashMap)this.cache.get(cacheID); + } + final float scale = + projector.getModuleCount(ModularForceFieldSystem.itemModuleScale, + new int[0]) / + 3.0f; + final HashMap fieldBlocks = new HashMap<>(); + if (this.getSaveDirectory() != null) { + NBTTagCompound nbt = null; + try { + nbt = CompressedStreamTools.read( + Paths + .get(this.getSaveDirectory().getPath(), + "custom_mode_" + this.getModeID(itemStack)) + .toFile()); + } catch (IOException e) { + e.printStackTrace(); + } + // final NBTTagCompound nbt = NBTFileLoader.loadData( + // this.getSaveDirectory(), "custom_mode_" + this.getModeID(itemStack)); + if (nbt != null) { + final NBTTagList nbtTagList = nbt.getTagList("fieldPoints", 10); + for (int i = 0; i < nbtTagList.tagCount(); ++i) { + final NBTTagCompound vectorTag = + (NBTTagCompound)nbtTagList.getCompoundTagAt(i); + final Vector3 position = Vector3.readFromNBT(vectorTag); + if (scale > 0.0f) { + position.multiply(scale); + } + final int[] blockInfo = {vectorTag.getInteger("blockID"), + vectorTag.getInteger("blockMetadata")}; + if (position != null) { + fieldBlocks.put(position, blockInfo); + } + } + } + if (Settings.USE_CACHE) { + this.cache.put(cacheID, fieldBlocks); + } + } + return fieldBlocks; + } + + @Override + public Object getCache(final String cacheID) { + return this.cache.get(cacheID); + } + + @Override + public void clearCache(final String cacheID) { + this.cache.remove(cacheID); + } + + @Override + public void clearCache() { + this.cache.clear(); + } + + public Set getExteriorPoints(final IFieldInteraction projector) { + return this.getFieldBlocks(projector, projector.getModeStack()); + } + + @Override + public Set getInteriorPoints(final IFieldInteraction projector) { + return this.getExteriorPoints(projector); + } + + @Override + public boolean isInField(final IFieldInteraction projector, + final Vector3 position) { + return false; + } + + @SideOnly(Side.CLIENT) + @Override + public void render(final IProjector projector, final double x, final double y, + final double z, final float f, final long ticks) { + final IProjectorMode[] modes = {ModularForceFieldSystem.itemModeCube, + ModularForceFieldSystem.itemModeSphere, + ModularForceFieldSystem.itemModeTube, + ModularForceFieldSystem.itemModePyramid}; + modes[((TileEntity)projector).getWorldObj().rand.nextInt(modes.length - 1)] + .render(projector, x, y, z, f, ticks); + } +} diff --git a/src/main/java/mffs/item/module/projector/ItemModeCylinder.java b/src/main/java/mffs/item/module/projector/ItemModeCylinder.java new file mode 100644 index 0000000..c659678 --- /dev/null +++ b/src/main/java/mffs/item/module/projector/ItemModeCylinder.java @@ -0,0 +1,122 @@ +package mffs.item.module.projector; + +import calclavia.lib.CalculationHelper; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import java.util.HashSet; +import java.util.Set; +import mffs.api.IFieldInteraction; +import mffs.api.IProjector; +import mffs.item.mode.ItemMode; +import mffs.render.model.ModelCube; +import net.minecraft.tileentity.TileEntity; +import org.lwjgl.opengl.GL11; +import universalelectricity.core.vector.Vector3; + +public class ItemModeCylinder extends ItemMode { + + public ItemModeCylinder() { super("modeCylinder"); } + + @Override + public Set getExteriorPoints(final IFieldInteraction projector) { + final Set fieldBlocks = new HashSet<>(); + final Vector3 posScale = projector.getPositiveScale(); + final Vector3 negScale = projector.getNegativeScale(); + final int radius = (posScale.intX() + negScale.intX() + posScale.intZ() + + negScale.intZ()) / + 2; + final int height = posScale.intY() + negScale.intY(); + for (float x = (float)(-radius); x <= radius; ++x) { + for (float z = (float)(-radius); z <= radius; ++z) { + for (float y = 0.0f; y < height; ++y) { + if ((y == 0.0f || y == height - 1) && + x * x + z * z + 0.0f <= radius * radius) { + fieldBlocks.add(new Vector3(x, y, z)); + } + if (x * x + z * z + 0.0f <= radius * radius && + x * x + z * z + 0.0f >= (radius - 1) * (radius - 1)) { + fieldBlocks.add(new Vector3(x, y, z)); + } + } + } + } + return fieldBlocks; + } + + @Override + public Set getInteriorPoints(final IFieldInteraction projector) { + final Set fieldBlocks = new HashSet<>(); + final Vector3 translation = projector.getTranslation(); + final Vector3 posScale = projector.getPositiveScale(); + final Vector3 negScale = projector.getNegativeScale(); + final int radius = (posScale.intX() + negScale.intX() + posScale.intZ() + + negScale.intZ()) / + 2; + final int height = posScale.intY() + negScale.intY(); + for (int x = -radius; x <= radius; ++x) { + for (int z = -radius; z <= radius; ++z) { + for (int y = 0; y < height; ++y) { + final Vector3 position = new Vector3(x, y, z); + if (this.isInField( + projector, + Vector3.add(position, new Vector3((TileEntity)projector)) + .add(translation))) { + fieldBlocks.add(position); + } + } + } + } + return fieldBlocks; + } + + @Override + public boolean isInField(final IFieldInteraction projector, + final Vector3 position) { + final Vector3 posScale = projector.getPositiveScale(); + final Vector3 negScale = projector.getNegativeScale(); + final int radius = (posScale.intX() + negScale.intX() + posScale.intZ() + + negScale.intZ()) / + 2; + final Vector3 projectorPos = new Vector3((TileEntity)projector); + projectorPos.add(projector.getTranslation()); + final Vector3 relativePosition = position.clone().subtract(projectorPos); + CalculationHelper.rotateByAngle(relativePosition, + -projector.getRotationYaw(), + -projector.getRotationPitch()); + return relativePosition.x * relativePosition.x + + relativePosition.z * relativePosition.z + 0.0 <= + radius * radius; + } + + @SideOnly(Side.CLIENT) + @Override + public void render(final IProjector projector, final double x, final double y, + final double z, final float f, final long ticks) { + final float scale = 0.15f; + final float detail = 0.5f; + GL11.glScalef(scale, scale, scale); + final float radius = 1.5f; + int i = 0; + for (float renderX = -radius; renderX <= radius; renderX += detail) { + for (float renderZ = -radius; renderZ <= radius; renderZ += detail) { + for (float renderY = -radius; renderY <= radius; renderY += detail) { + if ((renderX * renderX + renderZ * renderZ + 0.0f <= + radius * radius && + renderX * renderX + renderZ * renderZ + 0.0f >= + (radius - 1.0f) * (radius - 1.0f)) || + ((renderY == 0.0f || renderY == radius - 1.0f) && + renderX * renderX + renderZ * renderZ + 0.0f <= + radius * radius)) { + if (i % 2 == 0) { + final Vector3 vector = new Vector3(renderX, renderY, renderZ); + GL11.glTranslated(vector.x, vector.y, vector.z); + ModelCube.INSTNACE.render(); + GL11.glTranslated(-vector.x, -vector.y, -vector.z); + } + ++i; + } + } + } + } + } +} diff --git a/src/main/java/mffs/item/module/projector/ItemModePyramid.java b/src/main/java/mffs/item/module/projector/ItemModePyramid.java new file mode 100644 index 0000000..e890030 --- /dev/null +++ b/src/main/java/mffs/item/module/projector/ItemModePyramid.java @@ -0,0 +1,137 @@ +package mffs.item.module.projector; + +import calclavia.lib.CalculationHelper; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import java.util.HashSet; +import java.util.Set; +import mffs.api.IFieldInteraction; +import mffs.api.IProjector; +import mffs.item.mode.ItemMode; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.tileentity.TileEntity; +import org.lwjgl.opengl.GL11; +import universalelectricity.core.vector.Vector3; +import universalelectricity.prefab.vector.Region3; + +public class ItemModePyramid extends ItemMode { + public ItemModePyramid() { super("modePyramid"); } + + @Override + public Set getExteriorPoints(final IFieldInteraction projector) { + final Set fieldBlocks = new HashSet<>(); + final Vector3 posScale = projector.getPositiveScale(); + final Vector3 negScale = projector.getNegativeScale(); + final int xStretch = posScale.intX() + negScale.intX(); + final int yStretch = posScale.intY() + negScale.intY(); + final int zStretch = posScale.intZ() + negScale.intZ(); + final Vector3 translation = new Vector3(0.0, -negScale.intY(), 0.0); + for (float y = 0.0f; y <= yStretch; ++y) { + for (float x = (float)(-xStretch); x <= xStretch; ++x) { + for (float z = (float)(-zStretch); z <= zStretch; ++z) { + final double yTest = y / yStretch * 8.0f; + final double xzPositivePlane = + (1.0f - x / xStretch - z / zStretch) * 8.0f; + final double xzNegativePlane = + (1.0f + x / xStretch - z / zStretch) * 8.0f; + if (x >= 0.0f && z >= 0.0f && + Math.round(xzPositivePlane) == Math.round(yTest)) { + fieldBlocks.add(new Vector3(x, y, z).add(translation)); + fieldBlocks.add(new Vector3(x, y, -z).add(translation)); + } + if (x <= 0.0f && z >= 0.0f && + Math.round(xzNegativePlane) == Math.round(yTest)) { + fieldBlocks.add(new Vector3(x, y, -z).add(translation)); + fieldBlocks.add(new Vector3(x, y, z).add(translation)); + } + if (y == 0.0f && + Math.abs(x) + Math.abs(z) < (xStretch + yStretch) / 2) { + fieldBlocks.add(new Vector3(x, y, z).add(translation)); + } + } + } + } + return fieldBlocks; + } + + @Override + public Set getInteriorPoints(final IFieldInteraction projector) { + final Set fieldBlocks = new HashSet<>(); + final Vector3 posScale = projector.getPositiveScale(); + final Vector3 negScale = projector.getNegativeScale(); + final int xStretch = posScale.intX() + negScale.intX(); + final int yStretch = posScale.intY() + negScale.intY(); + final int zStretch = posScale.intZ() + negScale.intZ(); + final Vector3 translation = new Vector3(0.0, -0.4, 0.0); + for (float x = (float)(-xStretch); x <= xStretch; ++x) { + for (float z = (float)(-zStretch); z <= zStretch; ++z) { + for (float y = 0.0f; y <= yStretch; ++y) { + final Vector3 position = new Vector3(x, y, z).add(translation); + if (this.isInField( + projector, + Vector3.add(position, new Vector3((TileEntity)projector)))) { + fieldBlocks.add(position); + } + } + } + } + return fieldBlocks; + } + + @Override + public boolean isInField(final IFieldInteraction projector, + final Vector3 position) { + final Vector3 posScale = projector.getPositiveScale().clone(); + final Vector3 negScale = projector.getNegativeScale().clone(); + final int xStretch = posScale.intX() + negScale.intX(); + final int yStretch = posScale.intY() + negScale.intY(); + final int zStretch = posScale.intZ() + negScale.intZ(); + final Vector3 projectorPos = new Vector3((TileEntity)projector); + projectorPos.add(projector.getTranslation()); + projectorPos.add(new Vector3(0.0, -negScale.intY() + 1, 0.0)); + final Vector3 relativePosition = position.clone().subtract(projectorPos); + CalculationHelper.rotateByAngle(relativePosition, + -projector.getRotationYaw(), + -projector.getRotationPitch()); + final Region3 region = new Region3(negScale.multiply(-1.0), posScale); + return region.isIn(relativePosition) && relativePosition.y > 0.0 && + 1.0 - Math.abs(relativePosition.x) / xStretch - + Math.abs(relativePosition.z) / zStretch > + relativePosition.y / yStretch; + } + + @SideOnly(Side.CLIENT) + @Override + public void render(final IProjector projector, final double x, final double y, + final double z, final float f, final long ticks) { + final Tessellator tessellator = Tessellator.instance; + GL11.glPushMatrix(); + GL11.glRotatef(180.0f, 0.0f, 0.0f, 1.0f); + final float height = 0.5f; + final float width = 0.3f; + final int uvMaxX = 2; + final int uvMaxY = 2; + final Vector3 translation = new Vector3(0.0, -0.4, 0.0); + tessellator.startDrawing(6); + tessellator.setColorRGBA(72, 198, 255, 255); + tessellator.addVertexWithUV(0.0 + translation.x, 0.0 + translation.y, + 0.0 + translation.z, 0.0, 0.0); + tessellator.addVertexWithUV(-width + translation.x, height + translation.y, + -width + translation.z, (double)(-uvMaxX), + (double)(-uvMaxY)); + tessellator.addVertexWithUV(-width + translation.x, height + translation.y, + width + translation.z, (double)(-uvMaxX), + (double)uvMaxY); + tessellator.addVertexWithUV(width + translation.x, height + translation.y, + width + translation.z, (double)uvMaxX, + (double)uvMaxY); + tessellator.addVertexWithUV(width + translation.x, height + translation.y, + -width + translation.z, (double)uvMaxX, + (double)(-uvMaxY)); + tessellator.addVertexWithUV(-width + translation.x, height + translation.y, + -width + translation.z, (double)(-uvMaxX), + (double)(-uvMaxY)); + tessellator.draw(); + GL11.glPopMatrix(); + } +} diff --git a/src/main/java/mffs/item/module/projector/ItemModuleDisintegration.java b/src/main/java/mffs/item/module/projector/ItemModuleDisintegration.java new file mode 100644 index 0000000..4947d71 --- /dev/null +++ b/src/main/java/mffs/item/module/projector/ItemModuleDisintegration.java @@ -0,0 +1,109 @@ +package mffs.item.module.projector; + +import java.util.HashSet; +import java.util.Set; +import mffs.IDelayedEventHandler; +import mffs.MFFSHelper; +import mffs.ModularForceFieldSystem; +import mffs.base.PacketFxs; +import mffs.api.Blacklist; +import mffs.api.IProjector; +import mffs.base.TileEntityInventory; +import mffs.event.BlockDropDelayedEvent; +import mffs.event.BlockInventoryDropDelayedEvent; +import mffs.item.module.ItemModule; +import mffs.tileentity.TileEntityForceFieldProjector; +import net.minecraft.block.Block; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.IBlockAccess; +import net.minecraftforge.fluids.IFluidBlock; +import universalelectricity.core.vector.Vector3; + +public class ItemModuleDisintegration extends ItemModule { + private int blockCount; + + public ItemModuleDisintegration() { + super("moduleDisintegration"); + this.blockCount = 0; + this.setMaxStackSize(1); + this.setCost(20.0f); + } + + @Override + public boolean onProject(final IProjector projector, + final Set fields) { + this.blockCount = 0; + return false; + } + + @Override + public int onProject(final IProjector projector, final Vector3 position) { + if (projector.getTicks() % 40L == 0L) { + final TileEntity tileEntity = (TileEntity) projector; + final Block block = position.getBlock((IBlockAccess) tileEntity.getWorldObj()); + if (block != Blocks.air) { + if (projector.getModuleCount( + ModularForceFieldSystem.itemModuleCamouflage, new int[0]) > 0) { + final int blockMetadata = position.getBlockMetadata((IBlockAccess) tileEntity.getWorldObj()); + final Set filterStacks = new HashSet<>(); + for (final int i : projector.getModuleSlots()) { + final ItemStack checkStack = projector.getStackInSlot(i); + final Block filterBlock = MFFSHelper.getFilterBlock(checkStack); + if (filterBlock != null) { + filterStacks.add(checkStack); + } + } + boolean contains = false; + for (final ItemStack filterStack : filterStacks) { + if (filterStack.isItemEqual( + new ItemStack(block, 1, blockMetadata))) { + contains = true; + break; + } + } + if (!contains) { + return 1; + } + } + if (Blacklist.disintegrationBlacklist.contains(block) || + block instanceof IFluidBlock) { + return 1; + } + + NBTTagCompound fxsData = new NBTTagCompound(); + + position.writeToNBT(fxsData); + fxsData.setInteger("type", 2); + + ModularForceFieldSystem.channel.sendToAll( + new PacketFxs(new Vector3((TileEntity) projector), fxsData)); + + if (projector.getModuleCount( + ModularForceFieldSystem.itemModuleCollection, new int[0]) > 0) { + ((TileEntityForceFieldProjector) projector) + .getDelayedEvents() + .add(new BlockInventoryDropDelayedEvent( + (IDelayedEventHandler) projector, 39, block, + tileEntity.getWorldObj(), position, + (TileEntityInventory) projector)); + } else { + ((TileEntityForceFieldProjector) projector) + .getDelayedEvents() + .add(new BlockDropDelayedEvent( + (IDelayedEventHandler) projector, 39, block, + tileEntity.getWorldObj(), position)); + } + if (this.blockCount++ >= projector.getModuleCount(ModularForceFieldSystem.itemModuleSpeed, + new int[0]) / + 3) { + return 2; + } + return 1; + } + } + return 1; + } +} diff --git a/src/main/java/mffs/item/module/projector/ItemModuleFusion.java b/src/main/java/mffs/item/module/projector/ItemModuleFusion.java new file mode 100644 index 0000000..194c26a --- /dev/null +++ b/src/main/java/mffs/item/module/projector/ItemModuleFusion.java @@ -0,0 +1,48 @@ +package mffs.item.module.projector; + +import icbm.api.IBlockFrequency; +import java.util.Iterator; +import java.util.Set; +import mffs.api.IFieldInteraction; +import mffs.api.IProjector; +import mffs.api.fortron.IFortronFrequency; +import mffs.base.TileEntityBase; +import mffs.fortron.FrequencyGrid; +import mffs.item.module.ItemModule; +import net.minecraft.tileentity.TileEntity; +import universalelectricity.core.vector.Vector3; + +public class ItemModuleFusion extends ItemModule { + public ItemModuleFusion() { + super("moduleFusion"); + this.setMaxStackSize(1); + this.setCost(1.0f); + } + + @Override + public boolean onProject(final IProjector projector, + final Set fieldBlocks) { + final Set machines = FrequencyGrid.instance().get( + ((IFortronFrequency)projector).getFrequency()); + for (final IBlockFrequency compareProjector : machines) { + if (compareProjector instanceof IProjector && + compareProjector != projector && + ((TileEntity)compareProjector).getWorldObj() == + ((TileEntity)projector).getWorldObj() && + ((TileEntityBase)compareProjector).isActive() && + ((IProjector)compareProjector).getMode() != null) { + final Iterator it = fieldBlocks.iterator(); + while (it.hasNext()) { + final Vector3 position = it.next(); + if (((IProjector)compareProjector) + .getMode() + .isInField((IFieldInteraction)compareProjector, + position.clone())) { + it.remove(); + } + } + } + } + return false; + } +} diff --git a/src/main/java/mffs/item/module/projector/ItemModuleManipulator.java b/src/main/java/mffs/item/module/projector/ItemModuleManipulator.java new file mode 100644 index 0000000..cf90110 --- /dev/null +++ b/src/main/java/mffs/item/module/projector/ItemModuleManipulator.java @@ -0,0 +1,24 @@ +package mffs.item.module.projector; + +import java.util.Iterator; +import java.util.Set; +import mffs.api.IFieldInteraction; +import mffs.item.module.ItemModule; +import net.minecraft.tileentity.TileEntity; +import universalelectricity.core.vector.Vector3; + +public class ItemModuleManipulator extends ItemModule { + public ItemModuleManipulator() { super("moduleManipulator"); } + + @Override + public void onCalculate(final IFieldInteraction projector, + final Set fieldBlocks) { + final Iterator it = fieldBlocks.iterator(); + while (it.hasNext()) { + final Vector3 position = it.next(); + if (position.y < ((TileEntity)projector).yCoord) { + it.remove(); + } + } + } +} diff --git a/src/main/java/mffs/item/module/projector/ItemModuleShock.java b/src/main/java/mffs/item/module/projector/ItemModuleShock.java new file mode 100644 index 0000000..c3ac5a3 --- /dev/null +++ b/src/main/java/mffs/item/module/projector/ItemModuleShock.java @@ -0,0 +1,24 @@ +package mffs.item.module.projector; + +import mffs.ModularForceFieldSystem; +import mffs.item.module.ItemModule; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLiving; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; + +public class ItemModuleShock extends ItemModule { + public ItemModuleShock() { super("moduleShock"); } + + @Override + public boolean onCollideWithForceField(final World world, final int x, + final int y, final int z, + final Entity entity, + final ItemStack moduleStack) { + if (entity instanceof EntityLiving) { + entity.attackEntityFrom(ModularForceFieldSystem.damagefieldShock, + moduleStack.stackSize); + } + return false; + } +} diff --git a/src/main/java/mffs/item/module/projector/ItemModuleSponge.java b/src/main/java/mffs/item/module/projector/ItemModuleSponge.java new file mode 100644 index 0000000..1de44a1 --- /dev/null +++ b/src/main/java/mffs/item/module/projector/ItemModuleSponge.java @@ -0,0 +1,31 @@ +package mffs.item.module.projector; + +import java.util.Set; +import mffs.api.IProjector; +import mffs.item.module.ItemModule; +import net.minecraft.init.Blocks; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; +import net.minecraftforge.fluids.IFluidBlock; +import universalelectricity.core.vector.Vector3; + +public class ItemModuleSponge extends ItemModule { + public ItemModuleSponge() { + super("moduleSponge"); + this.setMaxStackSize(1); + } + + @Override + public boolean onProject(final IProjector projector, + final Set fields) { + if (projector.getTicks() % 60L == 0L) { + final World world = ((TileEntity)projector).getWorldObj(); + for (final Vector3 point : projector.getInteriorPoints()) { + if (point.getBlock(world) instanceof IFluidBlock) { + point.setBlock(world, Blocks.air); + } + } + } + return super.onProject(projector, fields); + } +} diff --git a/src/main/java/mffs/item/module/projector/ItemModuleStablize.java b/src/main/java/mffs/item/module/projector/ItemModuleStablize.java new file mode 100644 index 0000000..13fba0c --- /dev/null +++ b/src/main/java/mffs/item/module/projector/ItemModuleStablize.java @@ -0,0 +1,124 @@ +package mffs.item.module.projector; + +import calclavia.lib.CalculationHelper; +import java.util.HashMap; +import java.util.Set; +import mffs.base.PacketFxs; +import mffs.ModularForceFieldSystem; +import mffs.api.Blacklist; +import mffs.api.IProjector; +import mffs.item.module.ItemModule; +import net.minecraft.block.Block; +import net.minecraft.entity.Entity; +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.minecraftforge.common.util.ForgeDirection; +import net.minecraftforge.fluids.IFluidBlock; +import universalelectricity.core.vector.Vector3; +import universalelectricity.core.vector.VectorHelper; + +public class ItemModuleStablize extends ItemModule { + private int blockCount; + + public ItemModuleStablize() { + super("moduleStabilize"); + this.blockCount = 0; + this.setMaxStackSize(1); + this.setCost(20.0f); + } + + @Override + public boolean onProject(final IProjector projector, + final Set fields) { + this.blockCount = 0; + return false; + } + + @Override + public int onProject(final IProjector projector, final Vector3 position) { + int[] blockInfo = null; + if (projector.getTicks() % 40L == 0L) { + if (projector.getMode() instanceof ItemModeCustom) { + final HashMap fieldBlocks = ((ItemModeCustom) projector.getMode()) + .getFieldBlockMap(projector, projector.getModeStack()); + final Vector3 fieldCenter = new Vector3((TileEntity) projector).add(projector.getTranslation()); + final Vector3 relativePosition = position.clone().subtract(fieldCenter); + CalculationHelper.rotateByAngle(relativePosition, + -projector.getRotationYaw(), + -projector.getRotationPitch()); + blockInfo = fieldBlocks.get(relativePosition.round()); + } + for (int dir = 0; dir < 6; ++dir) { + final ForgeDirection direction = ForgeDirection.getOrientation(dir); + final TileEntity tileEntity = VectorHelper.getTileEntityFromSide( + ((TileEntity) projector).getWorldObj(), + new Vector3((TileEntity) projector), direction); + if (tileEntity instanceof IInventory) { + final IInventory inventory = (IInventory) tileEntity; + for (int i = 0; i < inventory.getSizeInventory(); ++i) { + final ItemStack checkStack = inventory.getStackInSlot(i); + if (checkStack != null && checkStack.getItem() instanceof ItemBlock) { + if (blockInfo != null) { + if (Block.getBlockById(blockInfo[0]) != Block + .getBlockFromItem((ItemBlock) checkStack.getItem())) { + continue; + } + } + try { + if (((TileEntity) projector) + .getWorldObj() + .canPlaceEntityOnSide( + Block.getBlockFromItem( + (ItemBlock) checkStack.getItem()), + position.intX(), position.intY(), position.intZ(), + false, 0, (Entity) null, checkStack)) { + final int metadata = (blockInfo != null) + ? blockInfo[1] + : (checkStack.getHasSubtypes() + ? checkStack.getItemDamage() + : 0); + final Block block = (blockInfo != null) + ? Block.getBlockById(blockInfo[0]) + : null; + if (Blacklist.stabilizationBlacklist.contains(block) || + block instanceof IFluidBlock) { + return 1; + } + ((ItemBlock) checkStack.getItem()) + .placeBlockAt(checkStack, (EntityPlayer) null, + ((TileEntity) projector).getWorldObj(), + position.intX(), position.intY(), + position.intZ(), 0, 0.0f, 0.0f, 0.0f, + metadata); + inventory.decrStackSize(i, 1); + + NBTTagCompound fxsData = new NBTTagCompound(); + + position.writeToNBT(fxsData); + fxsData.setInteger("type", 1); + + ModularForceFieldSystem.channel.sendToAll(new PacketFxs( + new Vector3((TileEntity) projector), fxsData)); + + if (this.blockCount++ >= projector.getModuleCount( + ModularForceFieldSystem.itemModuleSpeed, new int[0]) / + 3) { + return 2; + } + return 1; + } + } catch (final Exception e) { + e.printStackTrace(); + } + } + } + } + } + } + return 1; + } +} diff --git a/src/main/java/mffs/recipe/IRecipeAdapter.java b/src/main/java/mffs/recipe/IRecipeAdapter.java new file mode 100644 index 0000000..3cc4960 --- /dev/null +++ b/src/main/java/mffs/recipe/IRecipeAdapter.java @@ -0,0 +1,14 @@ +package mffs.recipe; + +import net.minecraft.item.ItemStack; +import net.minecraft.item.crafting.IRecipe; + +public interface IRecipeAdapter { + public void setOutput(ItemStack item); + + public void setPattern(String... pattern); + + public void addIngredient(Object... ingredients); + + public IRecipe create(); +} diff --git a/src/main/java/mffs/recipe/RecipeBuilder.java b/src/main/java/mffs/recipe/RecipeBuilder.java new file mode 100644 index 0000000..dbb7b78 --- /dev/null +++ b/src/main/java/mffs/recipe/RecipeBuilder.java @@ -0,0 +1,49 @@ +package mffs.recipe; + +import cpw.mods.fml.common.registry.GameRegistry; +import net.minecraft.block.Block; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; + +public class RecipeBuilder { + IRecipeAdapter adapter; + + public RecipeBuilder(IRecipeAdapter adapter) { this.adapter = adapter; } + + public RecipeBuilder output(ItemStack stack) { + this.adapter.setOutput(stack); + return this; + } + + public RecipeBuilder output(Item item) { + this.adapter.setOutput(new ItemStack(item)); + return this; + } + + public RecipeBuilder output(Block block) { + this.adapter.setOutput(new ItemStack(block)); + return this; + } + + public RecipeBuilder output(Block block, int count) { + this.adapter.setOutput(new ItemStack(block, count)); + return this; + } + + public RecipeBuilder output(Item item, int count) { + this.adapter.setOutput(new ItemStack(item, count)); + return this; + } + + public RecipeBuilder pattern(String... pat) { + this.adapter.setPattern(pat); + return this; + } + + public RecipeBuilder ingredient(Object... i) { + this.adapter.addIngredient(i); + return this; + } + + public void register() { GameRegistry.addRecipe(this.adapter.create()); } +} diff --git a/src/main/java/mffs/recipe/ShapedOreRecipeAdapter.java b/src/main/java/mffs/recipe/ShapedOreRecipeAdapter.java new file mode 100644 index 0000000..c11487f --- /dev/null +++ b/src/main/java/mffs/recipe/ShapedOreRecipeAdapter.java @@ -0,0 +1,41 @@ +package mffs.recipe; + +import java.util.ArrayList; +import net.minecraft.item.ItemStack; +import net.minecraft.item.crafting.IRecipe; +import net.minecraftforge.oredict.ShapedOreRecipe; + +public class ShapedOreRecipeAdapter implements IRecipeAdapter { + ItemStack output; + String[] pattern; + ArrayList ingredients = new ArrayList<>(); + + @Override + public void setOutput(ItemStack item) { + this.output = item; + } + + @Override + public void setPattern(String... pattern) { + this.pattern = pattern; + } + + @Override + public void addIngredient(Object... ingredients) { + this.ingredients.add(ingredients[0]); + this.ingredients.add(ingredients[1]); + } + + @Override + public IRecipe create() { + ArrayList args = new ArrayList<>(); + + for (String pat : this.pattern) + args.add(pat); + + for (Object ing : this.ingredients) + args.add(ing); + + return new ShapedOreRecipe(this.output, args.toArray()); + } +} diff --git a/src/main/java/mffs/recipe/ShapelessOreRecipeAdapter.java b/src/main/java/mffs/recipe/ShapelessOreRecipeAdapter.java new file mode 100644 index 0000000..ee67d0f --- /dev/null +++ b/src/main/java/mffs/recipe/ShapelessOreRecipeAdapter.java @@ -0,0 +1,31 @@ +package mffs.recipe; + +import java.util.ArrayList; +import net.minecraft.item.ItemStack; +import net.minecraft.item.crafting.IRecipe; +import net.minecraftforge.oredict.ShapelessOreRecipe; + +public class ShapelessOreRecipeAdapter implements IRecipeAdapter { + ItemStack output; + ArrayList ingredients = new ArrayList<>(); + + @Override + public void setOutput(ItemStack item) { + this.output = item; + } + + @Override + public void setPattern(String... pattern) { + throw new UnsupportedOperationException("Shapeless recipe has no pattern!"); + } + + @Override + public void addIngredient(Object... ingredients) { + this.ingredients.add(ingredients[0]); + } + + @Override + public IRecipe create() { + return new ShapelessOreRecipe(this.output, this.ingredients.toArray()); + } +} diff --git a/src/main/java/mffs/render/FXBeam.java b/src/main/java/mffs/render/FXBeam.java new file mode 100644 index 0000000..3e28d36 --- /dev/null +++ b/src/main/java/mffs/render/FXBeam.java @@ -0,0 +1,185 @@ +package mffs.render; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.client.Minecraft; +import net.minecraft.client.particle.EntityFX; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.util.MathHelper; +import net.minecraft.util.ResourceLocation; +import net.minecraft.world.World; +import org.lwjgl.opengl.GL11; +import universalelectricity.core.vector.Vector3; + +@SideOnly(Side.CLIENT) +public class FXBeam extends EntityFX { + double movX; + double movY; + double movZ; + private float length; + private float rotYaw; + private float rotPitch; + private float prevYaw; + private float prevPitch; + private Vector3 target; + private float endModifier; + private boolean reverse; + private boolean pulse; + private int rotationSpeed; + private float prevSize; + + public FXBeam(final World par1World, final Vector3 position, + final Vector3 target, final float red, final float green, + final float blue, final int age) { + super(par1World, position.x, position.y, position.z, 0.0, 0.0, 0.0); + this.movX = 0.0; + this.movY = 0.0; + this.movZ = 0.0; + this.length = 0.0f; + this.rotYaw = 0.0f; + this.rotPitch = 0.0f; + this.prevYaw = 0.0f; + this.prevPitch = 0.0f; + this.target = new Vector3(); + this.endModifier = 1.0f; + this.reverse = false; + this.pulse = true; + this.rotationSpeed = 20; + this.prevSize = 0.0f; + this.setRGB(red, green, blue); + this.setSize(0.02f, 0.02f); + ((Entity)this).noClip = true; + ((Entity)this).motionX = 0.0; + ((Entity)this).motionY = 0.0; + ((Entity)this).motionZ = 0.0; + this.target = target; + final float xd = (float)(((Entity)this).posX - this.target.x); + final float yd = (float)(((Entity)this).posY - this.target.y); + final float zd = (float)(((Entity)this).posZ - this.target.z); + this.length = (float)new Vector3((Entity)this).distanceTo(this.target); + final double var7 = MathHelper.sqrt_double((double)(xd * xd + zd * zd)); + this.rotYaw = (float)(Math.atan2(xd, zd) * 180.0 / 3.141592653589793); + this.rotPitch = (float)(Math.atan2(yd, var7) * 180.0 / 3.141592653589793); + this.prevYaw = this.rotYaw; + this.prevPitch = this.rotPitch; + super.particleMaxAge = age; + final EntityLivingBase renderentity = + Minecraft.getMinecraft().renderViewEntity; + int visibleDistance = 50; + if (!Minecraft.getMinecraft().gameSettings.fancyGraphics) { + visibleDistance = 25; + } + if (renderentity.getDistance(((Entity)this).posX, ((Entity)this).posY, + ((Entity)this).posZ) > visibleDistance) { + super.particleMaxAge = 0; + } + } + + public void onUpdate() { + ((Entity)this).prevPosX = ((Entity)this).posX; + ((Entity)this).prevPosY = ((Entity)this).posY; + ((Entity)this).prevPosZ = ((Entity)this).posZ; + this.prevYaw = this.rotYaw; + this.prevPitch = this.rotPitch; + final float xd = (float)(((Entity)this).posX - this.target.x); + final float yd = (float)(((Entity)this).posY - this.target.y); + final float zd = (float)(((Entity)this).posZ - this.target.z); + this.length = MathHelper.sqrt_float(xd * xd + yd * yd + zd * zd); + final double var7 = MathHelper.sqrt_double((double)(xd * xd + zd * zd)); + this.rotYaw = (float)(Math.atan2(xd, zd) * 180.0 / 3.141592653589793); + this.rotPitch = (float)(Math.atan2(yd, var7) * 180.0 / 3.141592653589793); + if (super.particleAge++ >= super.particleMaxAge) { + this.setDead(); + } + } + + public void setRGB(final float r, final float g, final float b) { + super.particleRed = r; + super.particleGreen = g; + super.particleBlue = b; + } + + public void renderParticle(final Tessellator tessellator, final float f, + final float f1, final float f2, final float f3, + final float f4, final float f5) { + tessellator.draw(); + GL11.glPushMatrix(); + final float var9 = 1.0f; + final float slide = (float)((Entity)this).worldObj.getTotalWorldTime(); + final float rot = ((Entity)this).worldObj.provider.getWorldTime() % + (360 / this.rotationSpeed) * this.rotationSpeed + + this.rotationSpeed * f; + float size = 1.0f; + if (this.pulse) { + size = Math.min(super.particleAge / 4.0f, 1.0f); + size = this.prevSize + (size - this.prevSize) * f; + } + float op = 0.5f; + if (this.pulse && super.particleMaxAge - super.particleAge <= 4) { + op = 0.5f - (4 - (super.particleMaxAge - super.particleAge)) * 0.1f; + } + Minecraft.getMinecraft().renderEngine.bindTexture( + new ResourceLocation("mffs", "textures/blocks/fortron.png")); + GL11.glTexParameterf(3553, 10242, 10497.0f); + GL11.glTexParameterf(3553, 10243, 10497.0f); + GL11.glDisable(2884); + float var10 = slide + f; + if (this.reverse) { + var10 *= -1.0f; + } + final float var11 = -var10 * 0.2f - MathHelper.floor_float(-var10 * 0.1f); + GL11.glEnable(3042); + GL11.glBlendFunc(770, 1); + GL11.glDepthMask(false); + final float xx = + (float)(((Entity)this).prevPosX + + (((Entity)this).posX - ((Entity)this).prevPosX) * f - + EntityFX.interpPosX); + final float yy = + (float)(((Entity)this).prevPosY + + (((Entity)this).posY - ((Entity)this).prevPosY) * f - + EntityFX.interpPosY); + final float zz = + (float)(((Entity)this).prevPosZ + + (((Entity)this).posZ - ((Entity)this).prevPosZ) * f - + EntityFX.interpPosZ); + GL11.glTranslated((double)xx, (double)yy, (double)zz); + final float ry = this.prevYaw + (this.rotYaw - this.prevYaw) * f; + final float rp = this.prevPitch + (this.rotPitch - this.prevPitch) * f; + GL11.glRotatef(90.0f, 1.0f, 0.0f, 0.0f); + GL11.glRotatef(180.0f + ry, 0.0f, 0.0f, -1.0f); + GL11.glRotatef(rp, 1.0f, 0.0f, 0.0f); + final double var12 = -0.15 * size; + final double var13 = 0.15 * size; + final double var44b = -0.15 * size * this.endModifier; + final double var17b = 0.15 * size * this.endModifier; + GL11.glRotatef(rot, 0.0f, 1.0f, 0.0f); + for (int t = 0; t < 3; ++t) { + final double var14 = this.length * size * var9; + final double var15 = 0.0; + final double var16 = 1.0; + final double var17 = -1.0f + var11 + t / 3.0f; + final double var18 = this.length * size * var9 + var17; + GL11.glRotatef(60.0f, 0.0f, 1.0f, 0.0f); + tessellator.startDrawingQuads(); + tessellator.setBrightness(200); + tessellator.setColorRGBA_F(super.particleRed, super.particleGreen, + super.particleBlue, op); + tessellator.addVertexWithUV(var44b, var14, 0.0, var16, var18); + tessellator.addVertexWithUV(var12, 0.0, 0.0, var16, var17); + tessellator.addVertexWithUV(var13, 0.0, 0.0, var15, var17); + tessellator.addVertexWithUV(var17b, var14, 0.0, var15, var18); + tessellator.draw(); + } + GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f); + GL11.glDepthMask(true); + GL11.glDisable(3042); + GL11.glEnable(2884); + GL11.glPopMatrix(); + tessellator.startDrawingQuads(); + this.prevSize = size; + Minecraft.getMinecraft().renderEngine.bindTexture(new ResourceLocation("particles")); + } +} diff --git a/src/main/java/mffs/render/FXHologram.java b/src/main/java/mffs/render/FXHologram.java new file mode 100644 index 0000000..098ee1e --- /dev/null +++ b/src/main/java/mffs/render/FXHologram.java @@ -0,0 +1,93 @@ +package mffs.render; + +import calclavia.lib.render.CalclaviaRenderHelper; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import mffs.ModularForceFieldSystem; +import net.minecraft.block.Block; +import net.minecraft.client.Minecraft; +import net.minecraft.client.particle.EntityFX; +import net.minecraft.client.renderer.RenderBlocks; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.texture.TextureMap; +import net.minecraft.entity.Entity; +import net.minecraft.util.ResourceLocation; +import net.minecraft.world.World; +import org.lwjgl.opengl.GL11; +import universalelectricity.core.vector.Vector3; + +@SideOnly(Side.CLIENT) +public class FXHologram extends EntityFX { + private Vector3 targetPosition; + + public FXHologram(final World par1World, final Vector3 position, + final float red, final float green, final float blue, + final int age) { + super(par1World, position.x, position.y, position.z); + this.targetPosition = null; + this.setRBGColorF(red, green, blue); + super.particleMaxAge = age; + ((Entity)this).noClip = true; + } + + public FXHologram setTarget(final Vector3 targetPosition) { + this.targetPosition = targetPosition; + ((Entity)this).motionX = + (this.targetPosition.x - ((Entity)this).posX) / super.particleMaxAge; + ((Entity)this).motionY = + (this.targetPosition.y - ((Entity)this).posY) / super.particleMaxAge; + ((Entity)this).motionZ = + (this.targetPosition.z - ((Entity)this).posZ) / super.particleMaxAge; + return this; + } + + public void onUpdate() { + ((Entity)this).prevPosX = ((Entity)this).posX; + ((Entity)this).prevPosY = ((Entity)this).posY; + ((Entity)this).prevPosZ = ((Entity)this).posZ; + if (super.particleAge++ >= super.particleMaxAge) { + this.setDead(); + return; + } + if (this.targetPosition != null) { + this.moveEntity(((Entity)this).motionX, ((Entity)this).motionY, + ((Entity)this).motionZ); + } + } + + public void renderParticle(final Tessellator tessellator, final float f, + final float f1, final float f2, final float f3, + final float f4, final float f5) { + tessellator.draw(); + GL11.glPushMatrix(); + final float xx = + (float)(((Entity)this).prevPosX + + (((Entity)this).posX - ((Entity)this).prevPosX) * f - + EntityFX.interpPosX); + final float yy = + (float)(((Entity)this).prevPosY + + (((Entity)this).posY - ((Entity)this).prevPosY) * f - + EntityFX.interpPosY); + final float zz = + (float)(((Entity)this).prevPosZ + + (((Entity)this).posZ - ((Entity)this).prevPosZ) * f - + EntityFX.interpPosZ); + GL11.glTranslated((double)xx, (double)yy, (double)zz); + GL11.glScalef(1.01f, 1.01f, 1.01f); + float op = 0.5f; + if (super.particleMaxAge - super.particleAge <= 4) { + op = 0.5f - (5 - (super.particleMaxAge - super.particleAge)) * 0.1f; + } + GL11.glColor4d((double)super.particleRed, (double)super.particleGreen, + (double)super.particleBlue, (double)(op * 2.0f)); + CalclaviaRenderHelper.disableLighting(); + CalclaviaRenderHelper.enableBlending(); + Minecraft.getMinecraft().renderEngine.bindTexture(TextureMap.locationBlocksTexture); + CalclaviaRenderHelper.renderNormalBlockAsItem( + (Block)ModularForceFieldSystem.blockForceField, 0, new RenderBlocks()); + CalclaviaRenderHelper.disableBlending(); + GL11.glPopMatrix(); + tessellator.startDrawingQuads(); + Minecraft.getMinecraft().renderEngine.bindTexture(new ResourceLocation("particles")); + } +} diff --git a/src/main/java/mffs/render/FXHologramMoving.java b/src/main/java/mffs/render/FXHologramMoving.java new file mode 100644 index 0000000..d756dd0 --- /dev/null +++ b/src/main/java/mffs/render/FXHologramMoving.java @@ -0,0 +1,79 @@ +package mffs.render; + +import calclavia.lib.render.CalclaviaRenderHelper; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import mffs.ModularForceFieldSystem; +import net.minecraft.block.Block; +import net.minecraft.client.Minecraft; +import net.minecraft.client.particle.EntityFX; +import net.minecraft.client.renderer.RenderBlocks; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.texture.TextureMap; +import net.minecraft.entity.Entity; +import net.minecraft.util.ResourceLocation; +import net.minecraft.world.World; +import org.lwjgl.opengl.GL11; +import universalelectricity.core.vector.Vector3; + +@SideOnly(Side.CLIENT) +public class FXHologramMoving extends EntityFX { + public FXHologramMoving(final World par1World, final Vector3 position, + final float red, final float green, final float blue, + final int age) { + super(par1World, position.x, position.y, position.z); + this.setRBGColorF(red, green, blue); + super.particleMaxAge = age; + ((Entity)this).noClip = true; + } + + public void onUpdate() { + ((Entity)this).prevPosX = ((Entity)this).posX; + ((Entity)this).prevPosY = ((Entity)this).posY; + ((Entity)this).prevPosZ = ((Entity)this).posZ; + if (super.particleAge++ >= super.particleMaxAge) { + this.setDead(); + } + } + + public void renderParticle(final Tessellator tessellator, final float f, + final float f1, final float f2, final float f3, + final float f4, final float f5) { + tessellator.draw(); + GL11.glPushMatrix(); + final float xx = + (float)(((Entity)this).prevPosX + + (((Entity)this).posX - ((Entity)this).prevPosX) * f - + EntityFX.interpPosX); + final float yy = + (float)(((Entity)this).prevPosY + + (((Entity)this).posY - ((Entity)this).prevPosY) * f - + EntityFX.interpPosY); + final float zz = + (float)(((Entity)this).prevPosZ + + (((Entity)this).posZ - ((Entity)this).prevPosZ) * f - + EntityFX.interpPosZ); + GL11.glTranslated((double)xx, (double)yy, (double)zz); + GL11.glScalef(1.01f, 1.01f, 1.01f); + final double completion = super.particleAge / (double)super.particleMaxAge; + GL11.glTranslated(0.0, (completion - 1.0) / 2.0, 0.0); + GL11.glScaled(1.0, completion, 1.0); + float op = 0.5f; + if (super.particleMaxAge - super.particleAge <= 4) { + op = 0.5f - (5 - (super.particleMaxAge - super.particleAge)) * 0.1f; + } + GL11.glColor4d((double)super.particleRed, (double)super.particleGreen, + (double)super.particleBlue, (double)(op * 2.0f)); + CalclaviaRenderHelper.disableLighting(); + CalclaviaRenderHelper.enableBlending(); + Minecraft.getMinecraft().renderEngine.bindTexture(TextureMap.locationBlocksTexture); + CalclaviaRenderHelper.renderNormalBlockAsItem( + (Block)ModularForceFieldSystem.blockForceField, 0, new RenderBlocks()); + CalclaviaRenderHelper.disableBlending(); + CalclaviaRenderHelper.enableLighting(); + GL11.glPopMatrix(); + tessellator.startDrawingQuads(); + Minecraft.getMinecraft().renderEngine.bindTexture( + new ResourceLocation("particles")); + } +} diff --git a/src/main/java/mffs/render/RenderBlockHandler.java b/src/main/java/mffs/render/RenderBlockHandler.java new file mode 100644 index 0000000..7c921aa --- /dev/null +++ b/src/main/java/mffs/render/RenderBlockHandler.java @@ -0,0 +1,84 @@ +package mffs.render; + +import calclavia.lib.render.CalclaviaRenderHelper; +import cpw.mods.fml.client.FMLClientHandler; +import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler; +import cpw.mods.fml.client.registry.RenderingRegistry; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import mffs.block.BlockCoercionDeriver; +import mffs.block.BlockForceFieldProjector; +import mffs.block.BlockForceManipulator; +import mffs.block.BlockFortronCapacitor; +import net.minecraft.block.Block; +import net.minecraft.client.renderer.RenderBlocks; +import net.minecraft.util.ResourceLocation; +import net.minecraft.world.IBlockAccess; +import org.lwjgl.opengl.GL11; + +@SideOnly(Side.CLIENT) +public class RenderBlockHandler implements ISimpleBlockRenderingHandler { + public static final int ID; + + @Override + public void renderInventoryBlock(final Block block, final int metadata, + final int modelID, + final RenderBlocks renderer) { + if (modelID == RenderBlockHandler.ID) { + GL11.glPushMatrix(); + if (block instanceof BlockFortronCapacitor) { + FMLClientHandler.instance().getClient().renderEngine.bindTexture( + new ResourceLocation("mffs", + "textures/models/fortronCapacitor_on.png")); + GL11.glTranslated(0.5, 1.9, 0.5); + GL11.glRotatef(180.0f, 0.0f, 0.0f, 1.0f); + GL11.glScalef(1.3f, 1.3f, 1.3f); + RenderFortronCapacitor.MODEL.render(0.0625f); + } else if (block instanceof BlockForceFieldProjector) { + FMLClientHandler.instance().getClient().renderEngine.bindTexture( + new ResourceLocation("mffs", "textures/models/projector_on.png")); + GL11.glTranslated(0.5, 1.5, 0.5); + GL11.glRotatef(180.0f, 0.0f, 0.0f, 1.0f); + RenderForceFieldProjector.MODEL.render(0.0f, 0.0625f); + } else if (block instanceof BlockCoercionDeriver) { + FMLClientHandler.instance().getClient().renderEngine.bindTexture( + new ResourceLocation("mffs", + "textures/models/coercionDeriver_on.png")); + GL11.glTranslated(0.5, 1.9, 0.5); + GL11.glRotatef(180.0f, 0.0f, 0.0f, 1.0f); + GL11.glScalef(1.3f, 1.3f, 1.3f); + RenderCoercionDeriver.MODEL.render(0.0f, 0.0625f); + } else if (block instanceof BlockForceManipulator) { + FMLClientHandler.instance().getClient().renderEngine.bindTexture( + new ResourceLocation("mffs", + "textures/models/forceManipulator_on.png")); + GL11.glTranslated(0.5, 1.4, 0.5); + GL11.glRotatef(180.0f, 0.0f, 0.0f, 1.0f); + RenderForceManipulator.MODEL.render(0.0625f); + } + GL11.glPopMatrix(); + } else { + CalclaviaRenderHelper.renderNormalBlockAsItem(block, metadata, renderer); + } + } + + @Override + public boolean renderWorldBlock(final IBlockAccess iBlockAccess, final int x, + final int y, final int z, final Block block, + final int modelID, + final RenderBlocks renderer) { + return false; + } + + @Override + public boolean shouldRender3DInInventory(int arg0) { + return true; + } + + @Override + public int getRenderId() { + return RenderBlockHandler.ID; + } + + static { ID = RenderingRegistry.getNextAvailableRenderId(); } +} diff --git a/src/main/java/mffs/render/RenderCoercionDeriver.java b/src/main/java/mffs/render/RenderCoercionDeriver.java new file mode 100644 index 0000000..9fc01c0 --- /dev/null +++ b/src/main/java/mffs/render/RenderCoercionDeriver.java @@ -0,0 +1,39 @@ +package mffs.render; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import mffs.base.TileEntityBase; +import mffs.render.model.ModelCoercionDeriver; +import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.ResourceLocation; +import org.lwjgl.opengl.GL11; + +@SideOnly(Side.CLIENT) +public class RenderCoercionDeriver extends TileEntitySpecialRenderer { + public static final String TEXTURE_ON = "coercionDeriver_on.png"; + public static final String TEXTURE_OFF = "coercionDeriver_off.png"; + public static final ModelCoercionDeriver MODEL; + + @Override + public void renderTileEntityAt(final TileEntity t, final double x, + final double y, final double z, + final float f) { + final TileEntityBase tileEntity = (TileEntityBase)t; + if (tileEntity.isActive()) { + this.bindTexture(new ResourceLocation( + "mffs", "textures/models/coercionDeriver_on.png")); + } else { + this.bindTexture(new ResourceLocation( + "mffs", "textures/models/coercionDeriver_off.png")); + } + GL11.glPushMatrix(); + GL11.glTranslated(x + 0.5, y + 1.95, z + 0.5); + GL11.glRotatef(180.0f, 0.0f, 0.0f, 1.0f); + GL11.glScalef(1.3f, 1.3f, 1.3f); + RenderCoercionDeriver.MODEL.render(tileEntity.animation, 0.0625f); + GL11.glPopMatrix(); + } + + static { MODEL = new ModelCoercionDeriver(); } +} diff --git a/src/main/java/mffs/render/RenderForceField.java b/src/main/java/mffs/render/RenderForceField.java new file mode 100644 index 0000000..0535fca --- /dev/null +++ b/src/main/java/mffs/render/RenderForceField.java @@ -0,0 +1,137 @@ +package mffs.render; + +import calclavia.lib.render.CalclaviaRenderHelper; +import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler; +import cpw.mods.fml.client.registry.RenderingRegistry; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import mffs.ModularForceFieldSystem; +import mffs.tileentity.TileEntityForceField; +import net.minecraft.block.Block; +import net.minecraft.client.renderer.RenderBlocks; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.IBlockAccess; + +@SideOnly(Side.CLIENT) +public class RenderForceField implements ISimpleBlockRenderingHandler { + public static final int ID; + + @Override + public void renderInventoryBlock(final Block block, final int metadata, + final int modelID, + final RenderBlocks renderer) { + CalclaviaRenderHelper.renderNormalBlockAsItem(block, metadata, renderer); + } + + @Override + public boolean renderWorldBlock(final IBlockAccess iBlockAccess, final int x, + final int y, final int z, final Block block, + final int modelId, + final RenderBlocks renderer) { + int renderType = 0; + final TileEntity tileEntity = iBlockAccess.getTileEntity(x, y, z); + if (tileEntity instanceof TileEntityForceField) { + final ItemStack checkStack = ((TileEntityForceField) tileEntity).camoStack; + if (checkStack != null) { + final Block checkBlock = Block.getBlockFromItem(checkStack.getItem()); + if (checkBlock != null) { + renderType = checkBlock.getRenderType(); + } + } + } + ModularForceFieldSystem.LOGGER.fine("Render block: " + block.getUnlocalizedName()); + if (renderType >= 0) { + switch (renderType) { + case 4: { + renderer.renderBlockLiquid(block, x, y, z); + break; + } + case 31: { + renderer.renderBlockLog(block, x, y, z); + break; + } + case 1: { + renderer.renderCrossedSquares(block, x, y, z); + break; + } + case 20: { + renderer.renderBlockVine(block, x, y, z); + break; + } + case 39: { + renderer.renderBlockQuartz(block, x, y, z); + break; + } + case 5: { + renderer.renderBlockRedstoneWire(block, x, y, z); + break; + } + case 13: { + renderer.renderBlockCactus(block, x, y, z); + break; + } + case 23: { + renderer.renderBlockLilyPad(block, x, y, z); + break; + } + case 6: { + renderer.renderBlockCrops(block, x, y, z); + break; + } + case 8: { + renderer.renderBlockLadder(block, x, y, z); + break; + } + case 7: { + renderer.renderBlockDoor(block, x, y, z); + break; + } + case 12: { + renderer.renderBlockLever(block, x, y, z); + break; + } + case 29: { + renderer.renderBlockTripWireSource(block, x, y, z); + break; + } + case 30: { + renderer.renderBlockTripWire(block, x, y, z); + break; + } + case 14: { + renderer.renderBlockBed(block, x, y, z); + break; + } + case 16: { + renderer.renderPistonBase(block, x, y, z, false); + break; + } + case 17: { + renderer.renderPistonExtension(block, x, y, z, true); + break; + } + default: { + renderer.renderStandardBlock(block, x, y, z); + break; + } + } + return true; + } + return false; + } + + @Override + public boolean shouldRender3DInInventory(int arg0) { + return true; + } + + @Override + public int getRenderId() { + return RenderForceField.ID; + } + + static { + ID = RenderingRegistry.getNextAvailableRenderId(); + } +} diff --git a/src/main/java/mffs/render/RenderForceFieldProjector.java b/src/main/java/mffs/render/RenderForceFieldProjector.java new file mode 100644 index 0000000..e5baf3b --- /dev/null +++ b/src/main/java/mffs/render/RenderForceFieldProjector.java @@ -0,0 +1,119 @@ +package mffs.render; + +import calclavia.lib.render.CalclaviaRenderHelper; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import mffs.Settings; +import mffs.render.model.ModelForceFieldProjector; +import mffs.tileentity.TileEntityForceFieldProjector; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.RenderHelper; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; +import net.minecraft.entity.Entity; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.ResourceLocation; +import org.lwjgl.opengl.GL11; + +@SideOnly(Side.CLIENT) +public class RenderForceFieldProjector extends TileEntitySpecialRenderer { + public static final String TEXTURE_ON = "projector_on.png"; + public static final String TEXTURE_OFF = "projector_off.png"; + public static final ModelForceFieldProjector MODEL; + + @Override + public void renderTileEntityAt(final TileEntity t, final double x, + final double y, final double z, + final float f) { + if (t instanceof TileEntityForceFieldProjector) { + final TileEntityForceFieldProjector tileEntity = + (TileEntityForceFieldProjector)t; + GL11.glPushMatrix(); + GL11.glTranslated(x + 0.5, y + 1.5, z + 0.5); + if (tileEntity.isActive()) { + this.bindTexture( + new ResourceLocation("mffs", "textures/models/projector_on.png")); + } else { + this.bindTexture( + new ResourceLocation("mffs", "textures/models/projector_off.png")); + } + GL11.glRotatef(180.0f, 0.0f, 0.0f, 1.0f); + RenderForceFieldProjector.MODEL.render(tileEntity.animation, 0.0625f); + GL11.glPopMatrix(); + if (tileEntity.getMode() != null) { + final Tessellator tessellator = Tessellator.instance; + RenderHelper.disableStandardItemLighting(); + GL11.glPushMatrix(); + GL11.glTranslated(x + 0.5, y + 0.5, z + 0.5); + final double xDifference = + ((Entity)Minecraft.getMinecraft().thePlayer).posX - + (tileEntity.xCoord + 0.5); + final double zDifference = + ((Entity)Minecraft.getMinecraft().thePlayer).posZ - + (tileEntity.zCoord + 0.5); + final float rotatation = + (float)Math.toDegrees(Math.atan2(zDifference, xDifference)); + GL11.glRotatef(-rotatation + 27.0f, 0.0f, 1.0f, 0.0f); + GL11.glDisable(3553); + GL11.glShadeModel(7425); + GL11.glEnable(3042); + GL11.glBlendFunc(770, 1); + GL11.glDisable(3008); + GL11.glEnable(2884); + GL11.glDepthMask(false); + GL11.glPushMatrix(); + tessellator.startDrawing(6); + final float height = 2.0f; + final float width = 2.0f; + tessellator.setColorRGBA(72, 198, 255, 255); + tessellator.addVertex(0.0, 0.0, 0.0); + tessellator.setColorRGBA_I(0, 0); + tessellator.addVertex(-0.866 * width, (double)height, + (double)(-0.5f * width)); + tessellator.addVertex(0.866 * width, (double)height, + (double)(-0.5f * width)); + tessellator.addVertex(0.0, (double)height, (double)(1.0f * width)); + tessellator.addVertex(-0.866 * width, (double)height, + (double)(-0.5f * width)); + tessellator.draw(); + GL11.glPopMatrix(); + GL11.glDepthMask(true); + GL11.glDisable(2884); + GL11.glDisable(3042); + GL11.glShadeModel(7424); + GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f); + GL11.glEnable(3553); + GL11.glEnable(3008); + RenderHelper.enableStandardItemLighting(); + GL11.glPopMatrix(); + if (Settings.HIGH_GRAPHICS) { + GL11.glPushMatrix(); + GL11.glTranslated(x + 0.5, y + 1.35, z + 0.5); + this.bindTexture( + new ResourceLocation("mffs", "textures/models/force_cube.png")); + CalclaviaRenderHelper.enableBlending(); + CalclaviaRenderHelper.disableLighting(); + GL11.glPushMatrix(); + GL11.glColor4f(1.0f, 1.0f, 1.0f, + (float)Math.sin(tileEntity.getTicks() / 10.0) / 2.0f + + 1.0f); + GL11.glTranslatef(0.0f, + (float)Math.sin(Math.toRadians( + (double)(tileEntity.getTicks() * 3L))) / + 7.0f, + 0.0f); + GL11.glRotatef((float)(tileEntity.getTicks() * 4L), 0.0f, 1.0f, 0.0f); + GL11.glRotatef(36.0f + tileEntity.getTicks() * 4L, 0.0f, 1.0f, 1.0f); + tileEntity.getMode().render(tileEntity, x, y, z, f, + tileEntity.getTicks()); + GL11.glPopMatrix(); + CalclaviaRenderHelper.enableLighting(); + CalclaviaRenderHelper.disableBlending(); + GL11.glPopMatrix(); + } + } + } + } + + static { MODEL = new ModelForceFieldProjector(); } +} diff --git a/src/main/java/mffs/render/RenderForceManipulator.java b/src/main/java/mffs/render/RenderForceManipulator.java new file mode 100644 index 0000000..8495b0f --- /dev/null +++ b/src/main/java/mffs/render/RenderForceManipulator.java @@ -0,0 +1,38 @@ +package mffs.render; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import mffs.base.TileEntityBase; +import mffs.render.model.ModelForceManipulator; +import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.ResourceLocation; +import org.lwjgl.opengl.GL11; + +@SideOnly(Side.CLIENT) +public class RenderForceManipulator extends TileEntitySpecialRenderer { + public static final String TEXTURE_ON = "forceManipulator_on.png"; + public static final String TEXTURE_OFF = "forceManipulator_off.png"; + public static final ModelForceManipulator MODEL; + + @Override + public void renderTileEntityAt(final TileEntity t, final double x, + final double y, final double z, + final float f) { + final TileEntityBase tileEntity = (TileEntityBase)t; + if (tileEntity.isActive()) { + this.bindTexture(new ResourceLocation( + "mffs", "textures/models/forceManipulator_on.png")); + } else { + this.bindTexture(new ResourceLocation( + "mffs", "textures/models/forceManipulator_off.png")); + } + GL11.glPushMatrix(); + GL11.glTranslated(x + 0.5, y + 1.5, z + 0.5); + GL11.glRotatef(180.0f, 0.0f, 0.0f, 1.0f); + RenderForceManipulator.MODEL.render(0.0625f); + GL11.glPopMatrix(); + } + + static { MODEL = new ModelForceManipulator(); } +} diff --git a/src/main/java/mffs/render/RenderFortronCapacitor.java b/src/main/java/mffs/render/RenderFortronCapacitor.java new file mode 100644 index 0000000..f5a850e --- /dev/null +++ b/src/main/java/mffs/render/RenderFortronCapacitor.java @@ -0,0 +1,39 @@ +package mffs.render; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import mffs.base.TileEntityBase; +import mffs.render.model.ModelFortronCapacitor; +import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.ResourceLocation; +import org.lwjgl.opengl.GL11; + +@SideOnly(Side.CLIENT) +public class RenderFortronCapacitor extends TileEntitySpecialRenderer { + public static final String TEXTURE_ON = "fortronCapacitor_on.png"; + public static final String TEXTURE_OFF = "fortronCapacitor_off.png"; + public static final ModelFortronCapacitor MODEL; + + @Override + public void renderTileEntityAt(final TileEntity t, final double x, + final double y, final double z, + final float f) { + final TileEntityBase tileEntity = (TileEntityBase)t; + if (tileEntity.isActive()) { + this.bindTexture(new ResourceLocation( + "mffs", "textures/models/fortronCapacitor_on.png")); + } else { + this.bindTexture(new ResourceLocation( + "mffs", "textures/models/fortronCapacitor_off.png")); + } + GL11.glPushMatrix(); + GL11.glTranslated(x + 0.5, y + 1.95, z + 0.5); + GL11.glRotatef(180.0f, 0.0f, 0.0f, 1.0f); + GL11.glScalef(1.3f, 1.3f, 1.3f); + RenderFortronCapacitor.MODEL.render(0.0625f); + GL11.glPopMatrix(); + } + + static { MODEL = new ModelFortronCapacitor(); } +} diff --git a/src/main/java/mffs/render/RenderIDCard.java b/src/main/java/mffs/render/RenderIDCard.java new file mode 100644 index 0000000..5fa66c7 --- /dev/null +++ b/src/main/java/mffs/render/RenderIDCard.java @@ -0,0 +1,213 @@ +package mffs.render; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import mffs.ModularForceFieldSystem; +import mffs.api.card.ICardIdentification; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.ItemRenderer; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.texture.TextureMap; +import net.minecraft.entity.EntityLiving; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.client.IItemRenderer; +import org.lwjgl.opengl.GL11; +import universalelectricity.core.vector.Vector2; + +@SideOnly(Side.CLIENT) +public class RenderIDCard implements IItemRenderer { + private Minecraft mc; + + public RenderIDCard() { this.mc = Minecraft.getMinecraft(); } + + public void renderItem(final IItemRenderer.ItemRenderType type, + final ItemStack itemStack, final Object... data) { + if (itemStack.getItem() instanceof ICardIdentification) { + final ICardIdentification card = (ICardIdentification)itemStack.getItem(); + GL11.glPushMatrix(); + GL11.glDisable(2884); + this.transform(type); + this.renderItemIcon( + ModularForceFieldSystem.itemCardID.getIcon(itemStack, 0)); + if (type != IItemRenderer.ItemRenderType.INVENTORY) { + GL11.glTranslatef(0.0f, 0.0f, -5.0E-4f); + } + this.renderPlayerFace(this.getSkin(card.getUsername(itemStack))); + if (type != IItemRenderer.ItemRenderType.INVENTORY) { + GL11.glTranslatef(0.0f, 0.0f, 0.002f); + this.renderItemIcon( + ModularForceFieldSystem.itemCardID.getIcon(itemStack, 0)); + } + GL11.glEnable(2884); + GL11.glPopMatrix(); + } + } + + private void transform(final IItemRenderer.ItemRenderType type) { + final float scale = 0.0625f; + if (type != IItemRenderer.ItemRenderType.INVENTORY) { + GL11.glScalef(scale, -scale, -scale); + GL11.glTranslatef(20.0f, -16.0f, 0.0f); + GL11.glRotatef(180.0f, 1.0f, 1.0f, 0.0f); + GL11.glRotatef(-90.0f, 0.0f, 0.0f, 1.0f); + } + if (type == IItemRenderer.ItemRenderType.ENTITY) { + GL11.glTranslatef(20.0f, 0.0f, 0.0f); + GL11.glRotatef(Minecraft.getSystemTime() / 12.0f % 360.0f, 0.0f, 1.0f, + 0.0f); + GL11.glTranslatef(-8.0f, 0.0f, 0.0f); + GL11.glTranslated( + 0.0, 2.0 * Math.sin(Minecraft.getSystemTime() / 512.0 % 360.0), 0.0); + } + } + + private int getSkin(final String name) { + return 0; + // TODO: DAFUQ + // try { + // final String skin = "http://skins.minecraft.net/MinecraftSkins/" + name + + // ".png"; + // final Minecraft mc = Minecraft.getMinecraft(); + // if (!mc.renderEngine.func_82773_c(skin)) { + // mc.renderEngine.func_78356_a(skin, (IImageBuffer)new + // ImageBufferDownload()); + // } + // return mc.renderEngine.func_78350_a(skin, "/mob/char.png"); + // } + // catch (final Exception e) { + // e.printStackTrace(); + // return 0; + // } + } + + private void renderPlayerFace(final int texID) { + final Vector2 translation = new Vector2(9.0, 5.0); + final int xSize = 4; + final int ySize = 4; + final int topLX = translation.intX(); + final int topRX = translation.intX() + xSize; + final int botLX = translation.intX(); + final int botRX = translation.intX() + xSize; + final int topLY = translation.intY(); + final int topRY = translation.intY(); + final int botLY = translation.intY() + ySize; + final int botRY = translation.intY() + ySize; + GL11.glBindTexture(3553, texID); + GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f); + GL11.glBegin(7); + GL11.glTexCoord2f(0.125f, 0.25f); + GL11.glVertex2f((float)topLX, (float)topLY); + GL11.glTexCoord2f(0.125f, 0.5f); + GL11.glVertex2f((float)botLX, (float)botLY); + GL11.glTexCoord2f(0.25f, 0.5f); + GL11.glVertex2f((float)botRX, (float)botRY); + GL11.glTexCoord2f(0.25f, 0.25f); + GL11.glVertex2f((float)topRX, (float)topRY); + GL11.glEnd(); + GL11.glBegin(7); + GL11.glTexCoord2f(0.625f, 0.25f); + GL11.glVertex2f((float)topLX, (float)topLY); + GL11.glTexCoord2f(0.625f, 0.5f); + GL11.glVertex2f((float)botLX, (float)botLY); + GL11.glTexCoord2f(0.75f, 0.5f); + GL11.glVertex2f((float)botRX, (float)botRY); + GL11.glTexCoord2f(0.75f, 0.25f); + GL11.glVertex2f((float)topRX, (float)topRY); + GL11.glEnd(); + } + + private void renderItemIcon(final IIcon icon) { + Minecraft.getMinecraft().renderEngine.bindTexture( + TextureMap.locationItemsTexture); + GL11.glBegin(7); + GL11.glTexCoord2f(icon.getMinU(), icon.getMinV()); + GL11.glVertex2f(0.0f, 0.0f); + GL11.glTexCoord2f(icon.getMinU(), icon.getMaxV()); + GL11.glVertex2f(0.0f, 16.0f); + GL11.glTexCoord2f(icon.getMaxU(), icon.getMaxV()); + GL11.glVertex2f(16.0f, 16.0f); + GL11.glTexCoord2f(icon.getMaxU(), icon.getMinV()); + GL11.glVertex2f(16.0f, 0.0f); + GL11.glEnd(); + } + + //TODO: WTF + //@Override + private void renderItem3D(final EntityLiving par1EntityLiving, + final ItemStack par2ItemStack, final int par3) { + final IIcon icon = par1EntityLiving.getItemIcon(par2ItemStack, par3); + if (icon == null) { + GL11.glPopMatrix(); + return; + } + if (par2ItemStack.getItemSpriteNumber() == 0) { + this.mc.renderEngine.bindTexture(TextureMap.locationBlocksTexture); + } else { + this.mc.renderEngine.bindTexture(TextureMap.locationItemsTexture); + } + final Tessellator tessellator = Tessellator.instance; + final float f = icon.getMinU(); + final float f2 = icon.getMaxU(); + final float f3 = icon.getMinV(); + final float f4 = icon.getMaxV(); + final float f5 = 0.0f; + final float f6 = 0.3f; + GL11.glEnable(32826); + GL11.glTranslatef(-f5, -f6, 0.0f); + final float f7 = 1.5f; + GL11.glScalef(f7, f7, f7); + GL11.glRotatef(50.0f, 0.0f, 1.0f, 0.0f); + GL11.glRotatef(335.0f, 0.0f, 0.0f, 1.0f); + GL11.glTranslatef(-0.9375f, -0.0625f, 0.0f); + ItemRenderer.renderItemIn2D(tessellator, f2, f3, f, f4, icon.getIconWidth(), + icon.getIconHeight(), 0.0625f); + if (par2ItemStack != null && par2ItemStack.hasEffect(0) && par3 == 0) { + GL11.glDepthFunc(514); + GL11.glDisable(2896); + // TODO: WTF + this.mc.renderEngine.bindTexture(new ResourceLocation( + "%blur%/textures/misc/enchanted_item_glint.png")); + GL11.glEnable(3042); + GL11.glBlendFunc(768, 1); + final float f8 = 0.76f; + GL11.glColor4f(0.5f * f8, 0.25f * f8, 0.8f * f8, 1.0f); + GL11.glMatrixMode(5890); + GL11.glPushMatrix(); + final float f9 = 0.125f; + GL11.glScalef(f9, f9, f9); + float f10 = Minecraft.getSystemTime() % 3000L / 3000.0f * 8.0f; + GL11.glTranslatef(f10, 0.0f, 0.0f); + GL11.glRotatef(-50.0f, 0.0f, 0.0f, 1.0f); + ItemRenderer.renderItemIn2D(tessellator, 0.0f, 0.0f, 1.0f, 1.0f, 256, 256, + 0.0625f); + GL11.glPopMatrix(); + GL11.glPushMatrix(); + GL11.glScalef(f9, f9, f9); + f10 = Minecraft.getSystemTime() % 4873L / 4873.0f * 8.0f; + GL11.glTranslatef(-f10, 0.0f, 0.0f); + GL11.glRotatef(10.0f, 0.0f, 0.0f, 1.0f); + ItemRenderer.renderItemIn2D(tessellator, 0.0f, 0.0f, 1.0f, 1.0f, 256, 256, + 0.0625f); + GL11.glPopMatrix(); + GL11.glMatrixMode(5888); + GL11.glDisable(3042); + GL11.glEnable(2896); + GL11.glDepthFunc(515); + } + GL11.glDisable(32826); + } + + public boolean handleRenderType(final ItemStack item, + final IItemRenderer.ItemRenderType type) { + return true; + } + + public boolean + shouldUseRenderHelper(final IItemRenderer.ItemRenderType type, + final ItemStack item, + final IItemRenderer.ItemRendererHelper helper) { + return false; + } +} diff --git a/src/main/java/mffs/render/model/ModelCoercionDeriver.java b/src/main/java/mffs/render/model/ModelCoercionDeriver.java new file mode 100644 index 0000000..d62eae6 --- /dev/null +++ b/src/main/java/mffs/render/model/ModelCoercionDeriver.java @@ -0,0 +1,125 @@ +package mffs.render.model; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.client.model.ModelBase; +import net.minecraft.client.model.ModelRenderer; +import org.lwjgl.opengl.GL11; + +@SideOnly(Side.CLIENT) +public class ModelCoercionDeriver extends ModelBase { + ModelRenderer corner1; + ModelRenderer corner2; + ModelRenderer corner3; + ModelRenderer corner4; + ModelRenderer Bout; + ModelRenderer Baout; + ModelRenderer Fout; + ModelRenderer Tout; + ModelRenderer Core; + ModelRenderer Movingthingright; + ModelRenderer Movingthingleft; + ModelRenderer bottom; + + public ModelCoercionDeriver() { + super.textureWidth = 64; + super.textureHeight = 32; + (this.corner1 = new ModelRenderer((ModelBase)this, 52, 0)) + .addBox(3.0f, 16.0f, 3.0f, 3, 6, 3); + this.corner1.setRotationPoint(0.0f, 0.0f, 0.0f); + this.corner1.setTextureSize(64, 32); + this.corner1.mirror = true; + this.setRotation(this.corner1, 0.0f, 0.0f, 0.0f); + (this.corner2 = new ModelRenderer((ModelBase)this, 52, 0)) + .addBox(-6.0f, 16.0f, 3.0f, 3, 6, 3); + this.corner2.setRotationPoint(0.0f, 0.0f, 0.0f); + this.corner2.setTextureSize(64, 32); + this.corner2.mirror = true; + this.setRotation(this.corner2, 0.0f, 0.0f, 0.0f); + (this.corner3 = new ModelRenderer((ModelBase)this, 52, 0)) + .addBox(-6.0f, 16.0f, -6.0f, 3, 6, 3); + this.corner3.setRotationPoint(0.0f, 0.0f, 0.0f); + this.corner3.setTextureSize(64, 32); + this.corner3.mirror = true; + this.setRotation(this.corner3, 0.0f, 0.0f, 0.0f); + (this.corner4 = new ModelRenderer((ModelBase)this, 52, 0)) + .addBox(3.0f, 16.0f, -6.0f, 3, 6, 3); + this.corner4.setRotationPoint(0.0f, 0.0f, 0.0f); + this.corner4.setTextureSize(64, 32); + this.corner4.mirror = true; + this.setRotation(this.corner4, 0.0f, 0.0f, 0.0f); + (this.Bout = new ModelRenderer((ModelBase)this, 24, 19)) + .addBox(-2.0f, 21.0f, -2.0f, 4, 1, 4); + this.Bout.setRotationPoint(0.0f, 0.0f, 0.0f); + this.Bout.setTextureSize(64, 32); + this.Bout.mirror = true; + this.setRotation(this.Bout, 0.0f, 0.0f, 0.0f); + (this.Baout = new ModelRenderer((ModelBase)this, 24, 14)) + .addBox(-2.0f, 14.0f, 3.0f, 4, 4, 1); + this.Baout.setRotationPoint(0.0f, 2.0f, 0.0f); + this.Baout.setTextureSize(64, 32); + this.Baout.mirror = true; + this.setRotation(this.Baout, 0.0f, 0.0f, 0.0f); + (this.Fout = new ModelRenderer((ModelBase)this, 24, 14)) + .addBox(-2.0f, 14.0f, -4.0f, 4, 4, 1); + this.Fout.setRotationPoint(0.0f, 2.0f, 0.0f); + this.Fout.setTextureSize(64, 32); + this.Fout.mirror = true; + this.setRotation(this.Fout, 0.0f, 0.0f, 0.0f); + (this.Tout = new ModelRenderer((ModelBase)this, 24, 19)) + .addBox(-2.0f, 14.0f, -2.0f, 4, 1, 4); + this.Tout.setRotationPoint(0.0f, 0.0f, 0.0f); + this.Tout.setTextureSize(64, 32); + this.Tout.mirror = true; + this.setRotation(this.Tout, 0.0f, 0.0f, 0.0f); + (this.Core = new ModelRenderer((ModelBase)this, 0, 14)) + .addBox(-3.0f, 15.0f, -3.0f, 6, 6, 6); + this.Core.setRotationPoint(0.0f, 0.0f, 0.0f); + this.Core.setTextureSize(64, 32); + this.Core.mirror = true; + this.setRotation(this.Core, 0.0f, 0.0f, 0.0f); + (this.Movingthingright = new ModelRenderer((ModelBase)this, 46, 23)) + .addBox(-3.0f, -1.0f, -3.0f, 3, 3, 6); + this.Movingthingright.setRotationPoint(-3.0f, 20.0f, 0.0f); + this.Movingthingright.setTextureSize(64, 32); + this.Movingthingright.mirror = true; + this.setRotation(this.Movingthingright, 0.0f, 0.0f, 0.0f); + (this.Movingthingleft = new ModelRenderer((ModelBase)this, 46, 23)) + .addBox(0.0f, -1.0f, -3.0f, 3, 3, 6); + this.Movingthingleft.setRotationPoint(3.0f, 20.0f, 0.0f); + this.Movingthingleft.setTextureSize(64, 32); + this.Movingthingleft.mirror = true; + this.setRotation(this.Movingthingleft, 0.0f, 0.0f, 0.0f); + (this.bottom = new ModelRenderer((ModelBase)this, 0, 0)) + .addBox(-6.0f, 22.0f, -6.0f, 12, 2, 12); + this.bottom.setRotationPoint(0.0f, 0.0f, 0.0f); + this.bottom.setTextureSize(64, 32); + this.bottom.mirror = true; + this.setRotation(this.bottom, 0.0f, 0.0f, 0.0f); + } + + public void render(final float movement, final float f5) { + this.corner1.render(f5); + this.corner2.render(f5); + this.corner3.render(f5); + this.corner4.render(f5); + this.Bout.render(f5); + this.Baout.render(f5); + this.Fout.render(f5); + GL11.glPushMatrix(); + GL11.glRotatef(movement, 0.0f, 1.0f, 0.0f); + this.Tout.render(f5); + GL11.glPopMatrix(); + this.Core.render(f5); + this.Movingthingright.render(f5); + this.Movingthingleft.render(f5); + this.bottom.render(f5); + } + + private void setRotation(final ModelRenderer model, final float x, + final float y, final float z) { + model.rotateAngleX = x; + model.rotateAngleY = y; + model.rotateAngleZ = z; + } +} diff --git a/src/main/java/mffs/render/model/ModelCube.java b/src/main/java/mffs/render/model/ModelCube.java new file mode 100644 index 0000000..0413477 --- /dev/null +++ b/src/main/java/mffs/render/model/ModelCube.java @@ -0,0 +1,28 @@ +package mffs.render.model; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.client.model.ModelBase; +import net.minecraft.client.model.ModelRenderer; + +@SideOnly(Side.CLIENT) +public class ModelCube extends ModelBase { + public static final ModelCube INSTNACE; + private ModelRenderer cube; + + public ModelCube() { + this.cube = new ModelRenderer((ModelBase)this, 0, 0); + final int size = 16; + this.cube.addBox((float)(-size / 2), (float)(-size / 2), (float)(-size / 2), + size, size, size); + this.cube.setTextureSize(112, 70); + this.cube.mirror = true; + } + + public void render() { + final float f = 0.0625f; + this.cube.render(f); + } + + static { INSTNACE = new ModelCube(); } +} diff --git a/src/main/java/mffs/render/model/ModelForceFieldProjector.java b/src/main/java/mffs/render/model/ModelForceFieldProjector.java new file mode 100644 index 0000000..1c40217 --- /dev/null +++ b/src/main/java/mffs/render/model/ModelForceFieldProjector.java @@ -0,0 +1,237 @@ +package mffs.render.model; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.client.model.ModelBase; +import net.minecraft.client.model.ModelRenderer; +import org.lwjgl.opengl.GL11; + +@SideOnly(Side.CLIENT) +public class ModelForceFieldProjector extends ModelBase { + ModelRenderer top; + ModelRenderer axle; + ModelRenderer bottom; + ModelRenderer thingfront; + ModelRenderer thingback; + ModelRenderer thingright; + ModelRenderer thingleft; + ModelRenderer attacherbig1; + ModelRenderer attacherbig2; + ModelRenderer attachersmall3; + ModelRenderer attachersmall4; + ModelRenderer attachersmall2; + ModelRenderer attachersmall_1; + ModelRenderer corner1; + ModelRenderer corner2; + ModelRenderer corner3; + ModelRenderer corner4; + ModelRenderer lense; + ModelRenderer lensesidefront; + ModelRenderer lensesideback; + ModelRenderer lensesideright; + ModelRenderer lensesideleft; + ModelRenderer lensecorner1; + ModelRenderer lensecorner2; + ModelRenderer lensecorner3; + ModelRenderer lensecorner4; + + public ModelForceFieldProjector() { + super.textureWidth = 128; + super.textureHeight = 64; + (this.top = new ModelRenderer((ModelBase)this, 0, 0)) + .addBox(-8.0f, -4.0f, -8.0f, 16, 2, 16); + this.top.setRotationPoint(0.0f, 16.0f, 0.0f); + this.top.setTextureSize(128, 64); + this.top.mirror = true; + this.setRotation(this.top, 0.0f, 0.0f, 0.0f); + (this.axle = new ModelRenderer((ModelBase)this, 16, 26)) + .addBox(-1.0f, -2.0f, -1.0f, 2, 8, 2); + this.axle.setRotationPoint(0.0f, 16.0f, 0.0f); + this.axle.setTextureSize(128, 64); + this.axle.mirror = true; + this.setRotation(this.axle, 0.0f, 0.0f, 0.0f); + (this.bottom = new ModelRenderer((ModelBase)this, 0, 44)) + .addBox(-8.0f, 6.0f, -8.0f, 16, 2, 16); + this.bottom.setRotationPoint(0.0f, 16.0f, 0.0f); + this.bottom.setTextureSize(128, 64); + this.bottom.mirror = true; + this.setRotation(this.bottom, 0.0f, 0.0f, 0.0f); + (this.thingfront = new ModelRenderer((ModelBase)this, 0, 20)) + .addBox(-2.0f, -2.0f, -7.0f, 4, 8, 4); + this.thingfront.setRotationPoint(0.0f, 16.0f, 0.0f); + this.thingfront.setTextureSize(128, 64); + this.thingfront.mirror = true; + this.setRotation(this.thingfront, 0.0f, 0.0f, 0.0f); + (this.thingback = new ModelRenderer((ModelBase)this, 0, 20)) + .addBox(-2.0f, -2.0f, 3.0f, 4, 8, 4); + this.thingback.setRotationPoint(0.0f, 16.0f, 0.0f); + this.thingback.setTextureSize(128, 64); + this.thingback.mirror = true; + this.setRotation(this.thingback, 0.0f, 0.0f, 0.0f); + (this.thingright = new ModelRenderer((ModelBase)this, 0, 20)) + .addBox(-6.0f, -2.0f, -2.0f, 4, 8, 4); + this.thingright.setRotationPoint(0.0f, 16.0f, 0.0f); + this.thingright.setTextureSize(128, 64); + this.thingright.mirror = true; + this.setRotation(this.thingright, 0.0f, 0.0f, 0.0f); + (this.thingleft = new ModelRenderer((ModelBase)this, 0, 20)) + .addBox(2.0f, -2.0f, -2.0f, 4, 8, 4); + this.thingleft.setRotationPoint(0.0f, 16.0f, 0.0f); + this.thingleft.setTextureSize(128, 64); + this.thingleft.mirror = true; + this.setRotation(this.thingleft, 0.0f, 0.0f, 0.0f); + (this.attacherbig1 = new ModelRenderer((ModelBase)this, 16, 20)) + .addBox(-7.0f, -1.0f, -3.0f, 14, 1, 6); + this.attacherbig1.setRotationPoint(0.0f, 16.0f, 0.0f); + this.attacherbig1.setTextureSize(128, 64); + this.attacherbig1.mirror = true; + this.setRotation(this.attacherbig1, 0.0f, 0.0f, 0.0f); + (this.attacherbig2 = new ModelRenderer((ModelBase)this, 16, 20)) + .addBox(-7.0f, 4.0f, -3.0f, 14, 1, 6); + this.attacherbig2.setRotationPoint(0.0f, 16.0f, 0.0f); + this.attacherbig2.setTextureSize(128, 64); + this.attacherbig2.mirror = true; + this.setRotation(this.attacherbig2, 0.0f, 0.0f, 0.0f); + (this.attachersmall3 = new ModelRenderer((ModelBase)this, 16, 36)) + .addBox(-3.0f, -1.0f, -8.0f, 6, 1, 5); + this.attachersmall3.setRotationPoint(0.0f, 16.0f, 0.0f); + this.attachersmall3.setTextureSize(128, 64); + this.attachersmall3.mirror = true; + this.setRotation(this.attachersmall3, 0.0f, 0.0f, 0.0f); + (this.attachersmall4 = new ModelRenderer((ModelBase)this, 16, 36)) + .addBox(-3.0f, 4.0f, -8.0f, 6, 1, 5); + this.attachersmall4.setRotationPoint(0.0f, 16.0f, 0.0f); + this.attachersmall4.setTextureSize(128, 64); + this.attachersmall4.mirror = true; + this.setRotation(this.attachersmall4, 0.0f, 0.0f, 0.0f); + (this.attachersmall2 = new ModelRenderer((ModelBase)this, 16, 36)) + .addBox(-3.0f, 4.0f, 3.0f, 6, 1, 5); + this.attachersmall2.setRotationPoint(0.0f, 16.0f, 0.0f); + this.attachersmall2.setTextureSize(128, 64); + this.attachersmall2.mirror = true; + this.setRotation(this.attachersmall2, 0.0f, 0.0f, 0.0f); + (this.attachersmall_1 = new ModelRenderer((ModelBase)this, 16, 36)) + .addBox(-3.0f, -1.0f, 3.0f, 6, 1, 5); + this.attachersmall_1.setRotationPoint(0.0f, 16.0f, 0.0f); + this.attachersmall_1.setTextureSize(128, 64); + this.attachersmall_1.mirror = true; + this.setRotation(this.attachersmall_1, 0.0f, 0.0f, 0.0f); + (this.corner1 = new ModelRenderer((ModelBase)this, 38, 32)) + .addBox(6.0f, -2.0f, -8.0f, 2, 8, 2); + this.corner1.setRotationPoint(0.0f, 16.0f, 0.0f); + this.corner1.setTextureSize(128, 64); + this.corner1.mirror = true; + this.setRotation(this.corner1, 0.0f, 0.0f, 0.0f); + (this.corner2 = new ModelRenderer((ModelBase)this, 46, 32)) + .addBox(6.0f, -2.0f, 6.0f, 2, 8, 2); + this.corner2.setRotationPoint(0.0f, 16.0f, 0.0f); + this.corner2.setTextureSize(128, 64); + this.corner2.mirror = true; + this.setRotation(this.corner2, 0.0f, 0.0f, 0.0f); + (this.corner3 = new ModelRenderer((ModelBase)this, 0, 32)) + .addBox(-8.0f, -2.0f, 6.0f, 2, 8, 2); + this.corner3.setRotationPoint(0.0f, 16.0f, 0.0f); + this.corner3.setTextureSize(128, 64); + this.corner3.mirror = true; + this.setRotation(this.corner3, 0.0f, 0.0f, 0.0f); + (this.corner4 = new ModelRenderer((ModelBase)this, 8, 32)) + .addBox(-8.0f, -2.0f, -8.0f, 2, 8, 2); + this.corner4.setRotationPoint(0.0f, 16.0f, 0.0f); + this.corner4.setTextureSize(128, 64); + this.corner4.mirror = true; + this.setRotation(this.corner4, 0.0f, 0.0f, 0.0f); + (this.lense = new ModelRenderer((ModelBase)this, 96, 0)) + .addBox(-4.0f, -5.0f, -4.0f, 8, 1, 8); + this.lense.setRotationPoint(0.0f, 16.0f, 0.0f); + this.lense.setTextureSize(128, 64); + this.lense.mirror = true; + this.setRotation(this.lense, 0.0f, 0.0f, 0.0f); + (this.lensesidefront = new ModelRenderer((ModelBase)this, 64, 5)) + .addBox(-3.0f, -6.0f, -5.0f, 6, 2, 1); + this.lensesidefront.setRotationPoint(0.0f, 16.0f, 0.0f); + this.lensesidefront.setTextureSize(128, 64); + this.lensesidefront.mirror = true; + this.setRotation(this.lensesidefront, 0.0f, 0.0f, 0.0f); + (this.lensesideback = new ModelRenderer((ModelBase)this, 64, 5)) + .addBox(-3.0f, -6.0f, 4.0f, 6, 2, 1); + this.lensesideback.setRotationPoint(0.0f, 16.0f, 0.0f); + this.lensesideback.setTextureSize(128, 64); + this.lensesideback.mirror = true; + this.setRotation(this.lensesideback, 0.0f, 0.0f, 0.0f); + (this.lensesideright = new ModelRenderer((ModelBase)this, 64, 8)) + .addBox(-5.0f, -6.0f, -3.0f, 1, 2, 6); + this.lensesideright.setRotationPoint(0.0f, 16.0f, 0.0f); + this.lensesideright.setTextureSize(128, 64); + this.lensesideright.mirror = true; + this.setRotation(this.lensesideright, 0.0f, 0.0f, 0.0f); + (this.lensesideleft = new ModelRenderer((ModelBase)this, 64, 8)) + .addBox(4.0f, -6.0f, -3.0f, 1, 2, 6); + this.lensesideleft.setRotationPoint(0.0f, 16.0f, 0.0f); + this.lensesideleft.setTextureSize(128, 64); + this.lensesideleft.mirror = true; + this.setRotation(this.lensesideleft, 0.0f, 0.0f, 0.0f); + (this.lensecorner1 = new ModelRenderer((ModelBase)this, 64, 16)) + .addBox(3.0f, -6.0f, -4.0f, 1, 2, 1); + this.lensecorner1.setRotationPoint(0.0f, 16.0f, 0.0f); + this.lensecorner1.setTextureSize(128, 64); + this.lensecorner1.mirror = true; + this.setRotation(this.lensecorner1, 0.0f, 0.0f, 0.0f); + (this.lensecorner2 = new ModelRenderer((ModelBase)this, 64, 16)) + .addBox(3.0f, -6.0f, 3.0f, 1, 2, 1); + this.lensecorner2.setRotationPoint(0.0f, 16.0f, 0.0f); + this.lensecorner2.setTextureSize(128, 64); + this.lensecorner2.mirror = true; + this.setRotation(this.lensecorner2, 0.0f, 0.0f, 0.0f); + (this.lensecorner3 = new ModelRenderer((ModelBase)this, 64, 16)) + .addBox(-4.0f, -6.0f, 3.0f, 1, 2, 1); + this.lensecorner3.setRotationPoint(0.0f, 16.0f, 0.0f); + this.lensecorner3.setTextureSize(128, 64); + this.lensecorner3.mirror = true; + this.setRotation(this.lensecorner3, 0.0f, 0.0f, 0.0f); + (this.lensecorner4 = new ModelRenderer((ModelBase)this, 64, 16)) + .addBox(-4.0f, -6.0f, -4.0f, 1, 2, 1); + this.lensecorner4.setRotationPoint(0.0f, 16.0f, 0.0f); + this.lensecorner4.setTextureSize(128, 64); + this.lensecorner4.mirror = true; + this.setRotation(this.lensecorner4, 0.0f, 0.0f, 0.0f); + } + + public void render(final float rotation, final float f5) { + this.top.render(f5); + this.axle.render(f5); + this.bottom.render(f5); + GL11.glPushMatrix(); + GL11.glRotatef(rotation, 0.0f, 1.0f, 0.0f); + this.thingfront.render(f5); + this.attachersmall3.render(f5); + this.thingback.render(f5); + this.thingright.render(f5); + this.thingleft.render(f5); + this.attacherbig1.render(f5); + this.attacherbig2.render(f5); + this.attachersmall4.render(f5); + this.attachersmall2.render(f5); + this.attachersmall_1.render(f5); + GL11.glPopMatrix(); + this.corner1.render(f5); + this.corner2.render(f5); + this.corner3.render(f5); + this.corner4.render(f5); + this.lense.render(f5); + this.lensesidefront.render(f5); + this.lensesideback.render(f5); + this.lensesideright.render(f5); + this.lensesideleft.render(f5); + this.lensecorner1.render(f5); + this.lensecorner2.render(f5); + this.lensecorner3.render(f5); + this.lensecorner4.render(f5); + } + + private void setRotation(final ModelRenderer model, final float x, + final float y, final float z) { + model.rotateAngleX = x; + model.rotateAngleY = y; + model.rotateAngleZ = z; + } +} diff --git a/src/main/java/mffs/render/model/ModelForceManipulator.java b/src/main/java/mffs/render/model/ModelForceManipulator.java new file mode 100644 index 0000000..5f1cca7 --- /dev/null +++ b/src/main/java/mffs/render/model/ModelForceManipulator.java @@ -0,0 +1,94 @@ +package mffs.render.model; + +import net.minecraft.client.model.ModelBase; +import net.minecraft.client.model.ModelRenderer; + +public class ModelForceManipulator extends ModelBase { + ModelRenderer ElectrodePillar; + ModelRenderer ElectrodeBase; + ModelRenderer ElectrodeNode; + ModelRenderer WallBottom; + ModelRenderer WallFront; + ModelRenderer WallBack; + ModelRenderer WallLeft; + ModelRenderer WallRight; + ModelRenderer WallTop; + + public ModelForceManipulator() { + super.textureWidth = 128; + super.textureHeight = 128; + (this.ElectrodePillar = new ModelRenderer((ModelBase)this, 0, 32)) + .addBox(0.0f, 0.0f, 0.0f, 3, 3, 3); + this.ElectrodePillar.setRotationPoint(-1.5f, 19.0f, -1.5f); + this.ElectrodePillar.setTextureSize(128, 128); + this.ElectrodePillar.mirror = true; + this.setRotation(this.ElectrodePillar, 0.0f, 0.0f, 0.0f); + (this.ElectrodeBase = new ModelRenderer((ModelBase)this, 0, 39)) + .addBox(0.0f, 0.0f, 0.0f, 7, 2, 7); + this.ElectrodeBase.setRotationPoint(-3.5f, 21.5f, -3.5f); + this.ElectrodeBase.setTextureSize(128, 128); + this.ElectrodeBase.mirror = true; + this.setRotation(this.ElectrodeBase, 0.0f, 0.0f, 0.0f); + (this.ElectrodeNode = new ModelRenderer((ModelBase)this, 0, 49)) + .addBox(0.0f, 0.0f, 0.0f, 5, 5, 5); + this.ElectrodeNode.setRotationPoint(-2.5f, 15.0f, -2.5f); + this.ElectrodeNode.setTextureSize(128, 128); + this.ElectrodeNode.mirror = true; + this.setRotation(this.ElectrodeNode, 0.0f, 0.0f, 0.0f); + (this.WallBottom = new ModelRenderer((ModelBase)this, 0, 0)) + .addBox(0.0f, 0.0f, 0.0f, 16, 1, 16); + this.WallBottom.setRotationPoint(-8.0f, 23.0f, -8.0f); + this.WallBottom.setTextureSize(128, 128); + this.WallBottom.mirror = true; + this.setRotation(this.WallBottom, 0.0f, 0.0f, 0.0f); + (this.WallFront = new ModelRenderer((ModelBase)this, 65, 0)) + .addBox(0.0f, 0.0f, 0.0f, 16, 15, 1); + this.WallFront.setRotationPoint(-8.0f, 8.0f, -8.0f); + this.WallFront.setTextureSize(128, 128); + this.WallFront.mirror = true; + this.setRotation(this.WallFront, 0.0f, 0.0f, 0.0f); + (this.WallBack = new ModelRenderer((ModelBase)this, 65, 17)) + .addBox(0.0f, 0.0f, 0.0f, 16, 15, 1); + this.WallBack.setRotationPoint(-8.0f, 8.0f, 7.0f); + this.WallBack.setTextureSize(128, 128); + this.WallBack.mirror = true; + this.setRotation(this.WallBack, 0.0f, 0.0f, 0.0f); + (this.WallLeft = new ModelRenderer((ModelBase)this, 30, 50)) + .addBox(0.0f, 0.0f, 0.0f, 1, 15, 14); + this.WallLeft.setRotationPoint(-8.0f, 8.0f, -7.0f); + this.WallLeft.setTextureSize(128, 128); + this.WallLeft.mirror = true; + this.setRotation(this.WallLeft, 0.0f, 0.0f, 0.0f); + (this.WallRight = new ModelRenderer((ModelBase)this, 30, 19)) + .addBox(0.0f, 0.0f, 0.0f, 1, 15, 14); + this.WallRight.setRotationPoint(7.0f, 8.0f, -7.0f); + this.WallRight.setTextureSize(128, 128); + this.WallRight.mirror = true; + this.setRotation(this.WallRight, 0.0f, 0.0f, 0.0f); + (this.WallTop = new ModelRenderer((ModelBase)this, 61, 36)) + .addBox(0.0f, 0.0f, 0.0f, 14, 1, 14); + this.WallTop.setRotationPoint(-7.0f, 8.0f, -7.0f); + this.WallTop.setTextureSize(128, 128); + this.WallTop.mirror = true; + this.setRotation(this.WallTop, 0.0f, 0.0f, 0.0f); + } + + public void render(final float f5) { + this.ElectrodePillar.render(f5); + this.ElectrodeBase.render(f5); + this.ElectrodeNode.render(f5); + this.WallBottom.render(f5); + this.WallFront.render(f5); + this.WallBack.render(f5); + this.WallLeft.render(f5); + this.WallRight.render(f5); + this.WallTop.render(f5); + } + + private void setRotation(final ModelRenderer model, final float x, + final float y, final float z) { + model.rotateAngleX = x; + model.rotateAngleY = y; + model.rotateAngleZ = z; + } +} diff --git a/src/main/java/mffs/render/model/ModelFortronCapacitor.java b/src/main/java/mffs/render/model/ModelFortronCapacitor.java new file mode 100644 index 0000000..b73e1bb --- /dev/null +++ b/src/main/java/mffs/render/model/ModelFortronCapacitor.java @@ -0,0 +1,129 @@ +package mffs.render.model; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.client.model.ModelBase; +import net.minecraft.client.model.ModelRenderer; + +@SideOnly(Side.CLIENT) +public class ModelFortronCapacitor extends ModelBase { + ModelRenderer corner1; + ModelRenderer bottom; + ModelRenderer top; + ModelRenderer Rout; + ModelRenderer corner2; + ModelRenderer corner3; + ModelRenderer corner4; + ModelRenderer Bout; + ModelRenderer Baout; + ModelRenderer Fout; + ModelRenderer Lout; + ModelRenderer Core; + ModelRenderer Tout; + + public ModelFortronCapacitor() { + super.textureWidth = 64; + super.textureHeight = 32; + (this.corner1 = new ModelRenderer((ModelBase)this, 52, 0)) + .addBox(3.0f, 14.0f, 3.0f, 3, 8, 3); + this.corner1.setRotationPoint(0.0f, 0.0f, 0.0f); + this.corner1.setTextureSize(64, 32); + this.corner1.mirror = true; + this.setRotation(this.corner1, 0.0f, 0.0f, 0.0f); + (this.bottom = new ModelRenderer((ModelBase)this, 0, 0)) + .addBox(-6.0f, 22.0f, -6.0f, 12, 2, 12); + this.bottom.setRotationPoint(0.0f, 0.0f, 0.0f); + this.bottom.setTextureSize(64, 32); + this.bottom.mirror = true; + this.setRotation(this.bottom, 0.0f, 0.0f, 0.0f); + (this.top = new ModelRenderer((ModelBase)this, 0, 0)) + .addBox(-6.0f, 12.0f, -6.0f, 12, 2, 12); + this.top.setRotationPoint(0.0f, 0.0f, 0.0f); + this.top.setTextureSize(64, 32); + this.top.mirror = true; + this.setRotation(this.top, 0.0f, 0.0f, 0.0f); + (this.Rout = new ModelRenderer((ModelBase)this, 40, 14)) + .addBox(-4.0f, 14.0f, -2.0f, 1, 4, 4); + this.Rout.setRotationPoint(0.0f, 2.0f, 0.0f); + this.Rout.setTextureSize(64, 32); + this.Rout.mirror = true; + this.setRotation(this.Rout, 0.0f, 0.0f, 0.0f); + (this.corner2 = new ModelRenderer((ModelBase)this, 52, 0)) + .addBox(-6.0f, 14.0f, 3.0f, 3, 8, 3); + this.corner2.setRotationPoint(0.0f, 0.0f, 0.0f); + this.corner2.setTextureSize(64, 32); + this.corner2.mirror = true; + this.setRotation(this.corner2, 0.0f, 0.0f, 0.0f); + (this.corner3 = new ModelRenderer((ModelBase)this, 52, 0)) + .addBox(-6.0f, 14.0f, -6.0f, 3, 8, 3); + this.corner3.setRotationPoint(0.0f, 0.0f, 0.0f); + this.corner3.setTextureSize(64, 32); + this.corner3.mirror = true; + this.setRotation(this.corner3, 0.0f, 0.0f, 0.0f); + (this.corner4 = new ModelRenderer((ModelBase)this, 52, 0)) + .addBox(3.0f, 14.0f, -6.0f, 3, 8, 3); + this.corner4.setRotationPoint(0.0f, 0.0f, 0.0f); + this.corner4.setTextureSize(64, 32); + this.corner4.mirror = true; + this.setRotation(this.corner4, 0.0f, 0.0f, 0.0f); + (this.Bout = new ModelRenderer((ModelBase)this, 24, 19)) + .addBox(-2.0f, 21.0f, -2.0f, 4, 1, 4); + this.Bout.setRotationPoint(0.0f, 0.0f, 0.0f); + this.Bout.setTextureSize(64, 32); + this.Bout.mirror = true; + this.setRotation(this.Bout, 0.0f, 0.0f, 0.0f); + (this.Baout = new ModelRenderer((ModelBase)this, 24, 14)) + .addBox(-2.0f, 14.0f, 3.0f, 4, 4, 1); + this.Baout.setRotationPoint(0.0f, 2.0f, 0.0f); + this.Baout.setTextureSize(64, 32); + this.Baout.mirror = true; + this.setRotation(this.Baout, 0.0f, 0.0f, 0.0f); + (this.Fout = new ModelRenderer((ModelBase)this, 24, 14)) + .addBox(-2.0f, 14.0f, -4.0f, 4, 4, 1); + this.Fout.setRotationPoint(0.0f, 2.0f, 0.0f); + this.Fout.setTextureSize(64, 32); + this.Fout.mirror = true; + this.setRotation(this.Fout, 0.0f, 0.0f, 0.0f); + (this.Lout = new ModelRenderer((ModelBase)this, 40, 14)) + .addBox(3.0f, 14.0f, -2.0f, 1, 4, 4); + this.Lout.setRotationPoint(0.0f, 2.0f, 0.0f); + this.Lout.setTextureSize(64, 32); + this.Lout.mirror = true; + this.setRotation(this.Lout, 0.0f, 0.0f, 0.0f); + (this.Core = new ModelRenderer((ModelBase)this, 0, 14)) + .addBox(-3.0f, 15.0f, -3.0f, 6, 6, 6); + this.Core.setRotationPoint(0.0f, 0.0f, 0.0f); + this.Core.setTextureSize(64, 32); + this.Core.mirror = true; + this.setRotation(this.Core, 0.0f, 0.0f, 0.0f); + (this.Tout = new ModelRenderer((ModelBase)this, 24, 19)) + .addBox(-2.0f, 14.0f, -2.0f, 4, 1, 4); + this.Tout.setRotationPoint(0.0f, 0.0f, 0.0f); + this.Tout.setTextureSize(64, 32); + this.Tout.mirror = true; + this.setRotation(this.Tout, 0.0f, 0.0f, 0.0f); + } + + public void render(final float f5) { + this.corner1.render(f5); + this.bottom.render(f5); + this.top.render(f5); + this.Rout.render(f5); + this.corner2.render(f5); + this.corner3.render(f5); + this.corner4.render(f5); + this.Bout.render(f5); + this.Baout.render(f5); + this.Fout.render(f5); + this.Lout.render(f5); + this.Core.render(f5); + this.Tout.render(f5); + } + + private void setRotation(final ModelRenderer model, final float x, + final float y, final float z) { + model.rotateAngleX = x; + model.rotateAngleY = y; + model.rotateAngleZ = z; + } +} diff --git a/src/main/java/mffs/render/model/ModelPlane.java b/src/main/java/mffs/render/model/ModelPlane.java new file mode 100644 index 0000000..a1c6449 --- /dev/null +++ b/src/main/java/mffs/render/model/ModelPlane.java @@ -0,0 +1,28 @@ +package mffs.render.model; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.client.model.ModelBase; +import net.minecraft.client.model.ModelRenderer; + +@SideOnly(Side.CLIENT) +public class ModelPlane extends ModelBase { + public static final ModelPlane INSTNACE; + private ModelRenderer cube; + + public ModelPlane() { + this.cube = new ModelRenderer((ModelBase)this, 0, 0); + final int size = 16; + this.cube.addBox((float)(-size / 8), (float)(-size / 2), (float)(-size / 2), + size / 6, size, size); + this.cube.setTextureSize(112, 70); + this.cube.mirror = true; + } + + public void render() { + final float f = 0.0625f; + this.cube.render(f); + } + + static { INSTNACE = new ModelPlane(); } +} diff --git a/src/main/java/mffs/render/model/ModelTriangle.java b/src/main/java/mffs/render/model/ModelTriangle.java new file mode 100644 index 0000000..333594d --- /dev/null +++ b/src/main/java/mffs/render/model/ModelTriangle.java @@ -0,0 +1,28 @@ +package mffs.render.model; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.client.model.ModelBase; +import net.minecraft.client.model.ModelRenderer; + +@SideOnly(Side.CLIENT) +public class ModelTriangle extends ModelBase { + public static final ModelTriangle INSTNACE; + private ModelRenderer cube; + + public ModelTriangle() { + this.cube = new ModelRenderer((ModelBase)this, 0, 0); + final int size = 16; + this.cube.addBox((float)(-size / 8), (float)(-size / 2), (float)(-size / 2), + size / 6, size, size); + this.cube.setTextureSize(112, 70); + this.cube.mirror = true; + } + + public void render() { + final float f = 0.0625f; + this.cube.render(f); + } + + static { INSTNACE = new ModelTriangle(); } +} diff --git a/src/main/java/mffs/slot/SlotActive.java b/src/main/java/mffs/slot/SlotActive.java new file mode 100644 index 0000000..2b15294 --- /dev/null +++ b/src/main/java/mffs/slot/SlotActive.java @@ -0,0 +1,21 @@ +package mffs.slot; + +import mffs.base.TileEntityInventory; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; + +public class SlotActive extends SlotBase { + public SlotActive(final TileEntityInventory tileEntity, final int id, + final int par4, final int par5) { + super(tileEntity, id, par4, par5); + } + + @Override + public boolean isItemValid(final ItemStack itemStack) { + return super.isItemValid(itemStack) && !super.tileEntity.isActive(); + } + + public boolean canTakeStack(final EntityPlayer par1EntityPlayer) { + return !super.tileEntity.isActive(); + } +} diff --git a/src/main/java/mffs/slot/SlotBase.java b/src/main/java/mffs/slot/SlotBase.java new file mode 100644 index 0000000..36d9a29 --- /dev/null +++ b/src/main/java/mffs/slot/SlotBase.java @@ -0,0 +1,29 @@ +package mffs.slot; + +import mffs.base.TileEntityInventory; +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; + +public class SlotBase extends Slot { + protected TileEntityInventory tileEntity; + + public SlotBase(final TileEntityInventory tileEntity, final int id, + final int par4, final int par5) { + super((IInventory)tileEntity, id, par4, par5); + this.tileEntity = tileEntity; + } + + public boolean isItemValid(final ItemStack itemStack) { + return this.tileEntity.isItemValidForSlot(super.slotNumber, itemStack); + } + + public int getSlotStackLimit() { + final ItemStack itemStack = + this.tileEntity.getStackInSlot(super.slotNumber); + if (itemStack != null) { + return itemStack.getMaxStackSize(); + } + return this.tileEntity.getInventoryStackLimit(); + } +} diff --git a/src/main/java/mffs/slot/SlotCard.java b/src/main/java/mffs/slot/SlotCard.java new file mode 100644 index 0000000..f2848cd --- /dev/null +++ b/src/main/java/mffs/slot/SlotCard.java @@ -0,0 +1,23 @@ +package mffs.slot; + +import icbm.api.IBlockFrequency; +import icbm.api.IItemFrequency; +import mffs.base.TileEntityFrequency; +import net.minecraft.item.ItemStack; + +public class SlotCard extends SlotBase { + public SlotCard(final TileEntityFrequency tileEntity, final int id, + final int par4, final int par5) { + super(tileEntity, id, par4, par5); + } + + public void onSlotChanged() { + super.onSlotChanged(); + final ItemStack itemStack = this.getStack(); + if (itemStack != null && itemStack.getItem() instanceof IItemFrequency) { + ((IItemFrequency)itemStack.getItem()) + .setFrequency(((IBlockFrequency)super.tileEntity).getFrequency(), + itemStack); + } + } +} diff --git a/src/main/java/mffs/tileentity/ManipulatorCalculationThread.java b/src/main/java/mffs/tileentity/ManipulatorCalculationThread.java new file mode 100644 index 0000000..b6cd707 --- /dev/null +++ b/src/main/java/mffs/tileentity/ManipulatorCalculationThread.java @@ -0,0 +1,47 @@ +package mffs.tileentity; + +import java.util.HashSet; +import java.util.Set; +import universalelectricity.core.vector.Vector3; + +public class ManipulatorCalculationThread extends Thread { + private TileEntityForceManipulator manipulator; + private IThreadCallBack callBack; + + public ManipulatorCalculationThread( + final TileEntityForceManipulator projector) { + this.manipulator = projector; + } + + public ManipulatorCalculationThread(final TileEntityForceManipulator + projector, + final IThreadCallBack callBack) { + this(projector); + this.callBack = callBack; + } + + @Override + public void run() { + this.manipulator.isCalculatingManipulation = true; + try { + final Set mobilizationPoints = + this.manipulator.getInteriorPoints(); + if (this.manipulator.canMove()) { + this.manipulator.manipulationVectors = new HashSet<>(); + for (final Vector3 position : mobilizationPoints) { + this.manipulator.manipulationVectors.add(position.clone()); + } + } + } catch (final Exception e) { + e.printStackTrace(); + } + this.manipulator.isCalculatingManipulation = false; + if (this.callBack != null) { + this.callBack.onThreadComplete(); + } + } + + public interface IThreadCallBack { + void onThreadComplete(); + } +} diff --git a/src/main/java/mffs/tileentity/ProjectorCalculationThread.java b/src/main/java/mffs/tileentity/ProjectorCalculationThread.java new file mode 100644 index 0000000..7956f3a --- /dev/null +++ b/src/main/java/mffs/tileentity/ProjectorCalculationThread.java @@ -0,0 +1,71 @@ +package mffs.tileentity; + +import calclavia.lib.CalculationHelper; +import java.util.Set; +import mffs.ModularForceFieldSystem; +import mffs.api.IFieldInteraction; +import mffs.api.modules.IModule; +import net.minecraft.tileentity.TileEntity; +import universalelectricity.core.vector.Vector3; + +public class ProjectorCalculationThread extends Thread { + private IFieldInteraction projector; + private IThreadCallBack callBack; + + public ProjectorCalculationThread(final IFieldInteraction projector) { + this.projector = projector; + } + + public ProjectorCalculationThread(final IFieldInteraction projector, + final IThreadCallBack callBack) { + this(projector); + this.callBack = callBack; + } + + @Override + public void run() { + this.projector.setCalculating(true); + try { + if (this.projector.getMode() != null) { + Set newField; + if (this.projector.getModuleCount( + ModularForceFieldSystem.itemModuleInvert, new int[0]) > 0) { + newField = this.projector.getMode().getInteriorPoints(this.projector); + } else { + newField = this.projector.getMode().getExteriorPoints(this.projector); + } + final Vector3 translation = this.projector.getTranslation(); + final int rotationYaw = this.projector.getRotationYaw(); + final int rotationPitch = this.projector.getRotationPitch(); + for (final Vector3 position : newField) { + if (rotationYaw != 0 || rotationPitch != 0) { + CalculationHelper.rotateByAngle(position, rotationYaw, + rotationPitch); + } + position.add(new Vector3((TileEntity)this.projector)); + position.add(translation); + if (position.intY() <= + ((TileEntity)this.projector).getWorldObj().getHeight()) { + this.projector.getCalculatedField().add(position.round()); + } + } + for (final IModule module : + this.projector.getModules(this.projector.getModuleSlots())) { + module.onCalculate(this.projector, + this.projector.getCalculatedField()); + } + } + } catch (final Exception e) { + e.printStackTrace(); + } + this.projector.setCalculating(false); + this.projector.setCalculated(true); + if (this.callBack != null) { + this.callBack.onThreadComplete(); + } + } + + public interface IThreadCallBack { + void onThreadComplete(); + } +} diff --git a/src/main/java/mffs/tileentity/TileEntityBiometricIdentifier.java b/src/main/java/mffs/tileentity/TileEntityBiometricIdentifier.java new file mode 100644 index 0000000..164cd7f --- /dev/null +++ b/src/main/java/mffs/tileentity/TileEntityBiometricIdentifier.java @@ -0,0 +1,140 @@ +package mffs.tileentity; + +import java.util.HashSet; +import java.util.Set; +import mffs.ModularForceFieldSystem; +import mffs.Settings; +import mffs.api.card.ICardIdentification; +import mffs.api.security.IBiometricIdentifier; +import mffs.api.security.Permission; +import mffs.base.PacketTile; +import mffs.base.TileEntityFrequency; +import mffs.item.card.ItemCardFrequency; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; + +public class TileEntityBiometricIdentifier + extends TileEntityFrequency implements IBiometricIdentifier { + public static final int SLOT_COPY = 12; + + @Override + public boolean isAccessGranted(final String username, + final Permission permission) { + if (!this.isActive()) { + return true; + } + if (ModularForceFieldSystem.proxy.isOp(username) && Settings.OP_OVERRIDE) { + return true; + } + for (int i = 0; i < this.getSizeInventory(); ++i) { + final ItemStack itemStack = this.getStackInSlot(i); + if (itemStack != null && + itemStack.getItem() instanceof ICardIdentification && + username.equalsIgnoreCase(((ICardIdentification)itemStack.getItem()) + .getUsername(itemStack)) && + ((ICardIdentification)itemStack.getItem()) + .hasPermission(itemStack, permission)) { + return true; + } + } + return username.equalsIgnoreCase(this.getOwner()); + } + + @Override + public void onReceivePacket(PacketTile.Type type, final NBTTagCompound nbt) { + super.onReceivePacket(type, nbt); + if (type == PacketTile.Type.TOGGLE_MODE) { + if (this.getManipulatingCard() != null) { + final ICardIdentification idCard = + (ICardIdentification)this.getManipulatingCard().getItem(); + final int id = nbt.getInteger("buttonId"); + final Permission permission = Permission.getPermission(id); + if (permission != null) { + if (!idCard.hasPermission(this.getManipulatingCard(), permission)) { + idCard.addPermission(this.getManipulatingCard(), permission); + } else { + idCard.removePermission(this.getManipulatingCard(), permission); + } + } else { + ModularForceFieldSystem.LOGGER.severe( + "Error handling security station permission packet: " + id + + " - " + permission); + } + } + } else if (type == PacketTile.Type.STRING && + this.getManipulatingCard() != null) { + final ICardIdentification idCard = + (ICardIdentification)this.getManipulatingCard().getItem(); + idCard.setUsername(this.getManipulatingCard(), nbt.getString("s")); + } + } + + @Override + public boolean isItemValidForSlot(final int slotID, + final ItemStack itemStack) { + if (slotID == 0) { + return itemStack.getItem() instanceof ItemCardFrequency; + } + return itemStack.getItem() instanceof ICardIdentification; + } + + @Override + public String getOwner() { + final ItemStack itemStack = this.getStackInSlot(2); + if (itemStack != null && itemStack.getItem() instanceof + ICardIdentification) { + return ((ICardIdentification)itemStack.getItem()).getUsername(itemStack); + } + return null; + } + + @Override + public void markDirty() { + super.markDirty(); + if (this.getManipulatingCard() != null && this.getStackInSlot(12) != null && + this.getStackInSlot(12).getItem() instanceof ICardIdentification) { + final ICardIdentification masterCard = + (ICardIdentification)this.getManipulatingCard().getItem(); + final ICardIdentification copyCard = + (ICardIdentification)this.getStackInSlot(12).getItem(); + for (final Permission permission : Permission.getPermissions()) { + if (masterCard.hasPermission(this.getManipulatingCard(), permission)) { + copyCard.addPermission(this.getStackInSlot(12), permission); + } else { + copyCard.removePermission(this.getStackInSlot(12), permission); + } + } + } + } + + @Override + public int getSizeInventory() { return 13; } + + @Override + public int getInventoryStackLimit() { + return 1; + } + + @Override + public ItemStack getManipulatingCard() { + if (this.getStackInSlot(1) != null && + this.getStackInSlot(1).getItem() instanceof ICardIdentification) { + return this.getStackInSlot(1); + } + return null; + } + + @Override + public void setActive(final boolean flag) { + if (this.getOwner() != null || !flag) { + super.setActive(flag); + } + } + + @Override + public Set getBiometricIdentifiers() { + final Set set = new HashSet<>(); + set.add(this); + return set; + } +} diff --git a/src/main/java/mffs/tileentity/TileEntityCoercionDeriver.java b/src/main/java/mffs/tileentity/TileEntityCoercionDeriver.java new file mode 100644 index 0000000..9c28110 --- /dev/null +++ b/src/main/java/mffs/tileentity/TileEntityCoercionDeriver.java @@ -0,0 +1,200 @@ +package mffs.tileentity; + +import mffs.ModularForceFieldSystem; +import mffs.Settings; +import mffs.api.modules.IModule; +import mffs.base.PacketTile; +import mffs.base.TileEntityUniversalEnergy; +import mffs.fortron.FortronHelper; +import mffs.item.card.ItemCardFrequency; +import net.minecraft.init.Items; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.network.NetworkManager; +import net.minecraft.network.Packet; +import net.minecraft.network.play.server.S35PacketUpdateTileEntity; +import net.minecraftforge.common.util.ForgeDirection; +import net.minecraftforge.fluids.FluidStack; +import universalelectricity.core.electricity.ElectricityPack; +import universalelectricity.core.item.ElectricItemHelper; +import universalelectricity.core.item.IItemElectric; + +public class TileEntityCoercionDeriver extends TileEntityUniversalEnergy { + public static final int WATTAGE = 1000; + public static final int REQUIRED_TIME = 200; + public static final int MULTIPLE_PRODUCTION = 4; + public static final float FORTRON_UE_RATIO = 6.0f; + public static final int SLOT_FREQUENCY = 0; + public static final int SLOT_BATTERY = 1; + public static final int SLOT_FUEL = 2; + public int processTime; + public boolean isInversed; + + public TileEntityCoercionDeriver() { + this.processTime = 0; + this.isInversed = false; + super.capacityBase = 30; + super.startModuleIndex = 3; + } + + @Override + public void updateEntity() { + super.updateEntity(); + if (!this.getWorldObj().isRemote) { + if (!this.isDisabled() && this.isActive()) { + if (this.isInversed && Settings.ENABLE_ELECTRICITY) { + final double watts = + Math.min(this.getFortronEnergy() * 6.0f, 1000.0f); + final ElectricityPack remainder = this.produce(watts); + double electricItemGiven = 0.0; + if (remainder.getWatts() > 0.0) { + electricItemGiven = ElectricItemHelper.chargeItem( + this.getStackInSlot(1), remainder.getWatts(), + this.getVoltage()); + } + this.requestFortron( + (int)((watts - (remainder.getWatts() - electricItemGiven)) / 6.0), + true); + } else { + super.wattsReceived += ElectricItemHelper.dechargeItem( + this.getStackInSlot(1), 1000.0, this.getVoltage()); + if (super.wattsReceived >= 1000.0 || + (!Settings.ENABLE_ELECTRICITY && + this.isItemValidForSlot(2, this.getStackInSlot(2)))) { + final int production = this.getProductionRate(); + super.fortronTank.fill( + FortronHelper.getFortron( + production + this.getWorldObj().rand.nextInt(production)), + true); + if (this.processTime == 0 && + this.isItemValidForSlot(2, this.getStackInSlot(2))) { + this.decrStackSize(2, 1); + this.processTime = + 200 * Math.max(this.getModuleCount( + ModularForceFieldSystem.itemModuleSpeed, + new int[0]) / + 20, + 1); + } + if (this.processTime > 0) { + --this.processTime; + if (this.processTime < 1) { + this.processTime = 0; + } + } else { + this.processTime = 0; + } + super.wattsReceived -= 1000.0; + } + } + } + } else if (this.isActive()) { + ++super.animation; + } + } + + public int getProductionRate() { + if (!this.isDisabled() && this.isActive() && !this.isInversed) { + int production = 40; + if (this.processTime > 0) { + production *= 4; + } + return production; + } + return 0; + } + + @Override + public int getSizeInventory() { + return 6; + } + + @Override + public ElectricityPack getRequest() { + if (this.canConsume()) { + return new ElectricityPack(1000.0 / this.getVoltage(), this.getVoltage()); + } + return super.getRequest(); + } + + public boolean canConsume() { + return this.isActive() && !this.isInversed && + FortronHelper.getAmount(super.fortronTank) < + super.fortronTank.getCapacity(); + } + + @Override + public Packet getDescriptionPacket() { + NBTTagCompound nbt = new NBTTagCompound(); + + nbt.setBoolean("isInversed", this.isInversed); + nbt.setDouble("wattsReceived", super.wattsReceived); + nbt.setBoolean("isActive", super.isActive); + nbt.setInteger("fortron", this.fortronTank.getFluidAmount()); + + return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, + this.getBlockMetadata(), nbt); + } + + @Override + public void onDataPacket(NetworkManager arg0, + S35PacketUpdateTileEntity arg1) { + NBTTagCompound nbt = arg1.func_148857_g(); + + this.isInversed = nbt.getBoolean("isInversed"); + super.wattsReceived = nbt.getDouble("wattsReceived"); + + this.isActive = nbt.getBoolean("isActive"); + this.fortronTank.setFluid(new FluidStack(FortronHelper.FLUID_FORTRON, nbt.getInteger("fortron"))); + } + + @Override + public void onReceivePacket(PacketTile.Type type, final NBTTagCompound nbt) { + super.onReceivePacket(type, nbt); + if (type == PacketTile.Type.TOGGLE_MODE) { + this.isInversed = !this.isInversed; + } + } + + @Override + public void readFromNBT(final NBTTagCompound nbt) { + super.readFromNBT(nbt); + this.processTime = nbt.getInteger("processTime"); + this.isInversed = nbt.getBoolean("isInversed"); + } + + @Override + public void writeToNBT(final NBTTagCompound nbt) { + super.writeToNBT(nbt); + nbt.setInteger("processTime", this.processTime); + nbt.setBoolean("isInversed", this.isInversed); + } + + @Override + public boolean isItemValidForSlot(final int slotID, + final ItemStack itemStack) { + if (itemStack != null) { + if (slotID >= super.startModuleIndex) { + return itemStack.getItem() instanceof IModule; + } + switch (slotID) { + case 0: { + return itemStack.getItem() instanceof ItemCardFrequency; + } + case 1: { + return itemStack.getItem() instanceof IItemElectric; + } + case 2: { + return itemStack.isItemEqual(new ItemStack(Items.dye, 1, 4)) || + itemStack.isItemEqual(new ItemStack(Items.quartz)); + } + } + } + return false; + } + + @Override + public boolean canConnect(final ForgeDirection direction) { + return true; + } +} diff --git a/src/main/java/mffs/tileentity/TileEntityFieldInteraction.java b/src/main/java/mffs/tileentity/TileEntityFieldInteraction.java new file mode 100644 index 0000000..44d2fb0 --- /dev/null +++ b/src/main/java/mffs/tileentity/TileEntityFieldInteraction.java @@ -0,0 +1,367 @@ +package mffs.tileentity; + +import calclavia.lib.CalculationHelper; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Set; +import mffs.DelayedEvent; +import mffs.IDelayedEventHandler; +import mffs.ModularForceFieldSystem; +import mffs.Settings; +import mffs.api.ICache; +import mffs.api.IFieldInteraction; +import mffs.api.modules.IModule; +import mffs.api.modules.IProjectorMode; +import mffs.base.TileEntityModuleAcceptor; +import net.minecraft.item.ItemStack; +import net.minecraft.world.IBlockAccess; +import net.minecraftforge.common.util.ForgeDirection; +import universalelectricity.core.vector.Vector3; +import universalelectricity.core.vector.VectorHelper; + +public abstract class TileEntityFieldInteraction + extends TileEntityModuleAcceptor + implements IFieldInteraction, IDelayedEventHandler { + protected static final int MODULE_SLOT_ID = 2; + protected boolean isCalculating; + protected boolean isCalculated; + protected final Set calculatedField; + private final List delayedEvents; + private final List quedDelayedEvents; + + public TileEntityFieldInteraction() { + this.isCalculating = false; + this.isCalculated = false; + this.calculatedField = Collections.synchronizedSet(new HashSet<>()); + this.delayedEvents = new ArrayList<>(); + this.quedDelayedEvents = new ArrayList<>(); + } + + @Override + public void updateEntity() { + super.updateEntity(); + if (this.delayedEvents.size() > 0) { + do { + this.quedDelayedEvents.clear(); + final Iterator it = this.delayedEvents.iterator(); + while (it.hasNext()) { + final DelayedEvent evt = it.next(); + evt.update(); + if (evt.ticks <= 0) { + it.remove(); + } + } + this.delayedEvents.addAll(this.quedDelayedEvents); + } while (!this.quedDelayedEvents.isEmpty()); + } + } + + protected void calculateForceField( + final ProjectorCalculationThread.IThreadCallBack callBack) { + if (!this.getWorldObj().isRemote && !this.isCalculating && + this.getMode() != null) { + if (this.getModeStack().getItem() instanceof ICache) { + ((ICache)this.getModeStack().getItem()).clearCache(); + } + this.calculatedField.clear(); + new ProjectorCalculationThread(this, callBack).start(); + } + } + + protected void calculateForceField() { this.calculateForceField(null); } + + @Override + public ItemStack getModeStack() { + if (this.getStackInSlot(2) != null && this.getStackInSlot(2).getItem() + instanceof IProjectorMode) { + return this.getStackInSlot(2); + } + return null; + } + + @Override + public IProjectorMode getMode() { + if (this.getModeStack() != null) { + return (IProjectorMode)this.getModeStack().getItem(); + } + return null; + } + + @Override + public int getSidedModuleCount(final IModule module, + final ForgeDirection... direction) { + int count = 0; + if (direction != null && direction.length > 0) { + for (final ForgeDirection checkDir : direction) { + count += this.getModuleCount(module, + this.getSlotsBasedOnDirection(checkDir)); + } + } else { + for (int i = 0; i < 6; ++i) { + final ForgeDirection checkDir2 = ForgeDirection.getOrientation(i); + count += this.getModuleCount(module, + this.getSlotsBasedOnDirection(checkDir2)); + } + } + return count; + } + + @Override + public int[] getModuleSlots() { + return new int[] {15, 16, 17, 18, 19, 20}; + } + + @Override + public Vector3 getTranslation() { + final String cacheID = "getTranslation"; + if (Settings.USE_CACHE && super.cache.containsKey(cacheID) && + super.cache.get(cacheID) instanceof Vector3) { + return (Vector3) super.cache.get(cacheID); + } + ForgeDirection direction = + this.getDirection((IBlockAccess)this.getWorldObj(), this.xCoord, + this.yCoord, this.zCoord); + if (direction == ForgeDirection.UP || direction == ForgeDirection.DOWN) { + direction = ForgeDirection.NORTH; + } + final int zTranslationNeg = this.getModuleCount( + ModularForceFieldSystem.itemModuleTranslate, + this.getSlotsBasedOnDirection(VectorHelper.getOrientationFromSide( + direction, ForgeDirection.NORTH))); + final int zTranslationPos = this.getModuleCount( + ModularForceFieldSystem.itemModuleTranslate, + this.getSlotsBasedOnDirection(VectorHelper.getOrientationFromSide( + direction, ForgeDirection.SOUTH))); + final int xTranslationNeg = this.getModuleCount( + ModularForceFieldSystem.itemModuleTranslate, + this.getSlotsBasedOnDirection(VectorHelper.getOrientationFromSide( + direction, ForgeDirection.WEST))); + final int xTranslationPos = this.getModuleCount( + ModularForceFieldSystem.itemModuleTranslate, + this.getSlotsBasedOnDirection(VectorHelper.getOrientationFromSide( + direction, ForgeDirection.EAST))); + final int yTranslationPos = + this.getModuleCount(ModularForceFieldSystem.itemModuleTranslate, + this.getSlotsBasedOnDirection(ForgeDirection.UP)); + final int yTranslationNeg = + this.getModuleCount(ModularForceFieldSystem.itemModuleTranslate, + this.getSlotsBasedOnDirection(ForgeDirection.DOWN)); + final Vector3 translation = new Vector3(xTranslationPos - xTranslationNeg, + yTranslationPos - yTranslationNeg, + zTranslationPos - zTranslationNeg); + if (Settings.USE_CACHE) { + super.cache.put(cacheID, translation); + } + return translation; + } + + @Override + public Vector3 getPositiveScale() { + final String cacheID = "getPositiveScale"; + if (Settings.USE_CACHE && super.cache.containsKey(cacheID) && + super.cache.get(cacheID) instanceof Vector3) { + return (Vector3) super.cache.get(cacheID); + } + ForgeDirection direction = + this.getDirection((IBlockAccess)this.getWorldObj(), this.xCoord, + this.yCoord, this.zCoord); + if (direction == ForgeDirection.UP || direction == ForgeDirection.DOWN) { + direction = ForgeDirection.NORTH; + } + int zScalePos = this.getModuleCount( + ModularForceFieldSystem.itemModuleScale, + this.getSlotsBasedOnDirection(VectorHelper.getOrientationFromSide( + direction, ForgeDirection.SOUTH))); + int xScalePos = this.getModuleCount( + ModularForceFieldSystem.itemModuleScale, + this.getSlotsBasedOnDirection(VectorHelper.getOrientationFromSide( + direction, ForgeDirection.EAST))); + int yScalePos = + this.getModuleCount(ModularForceFieldSystem.itemModuleScale, + this.getSlotsBasedOnDirection(ForgeDirection.UP)); + final int omnidirectionalScale = this.getModuleCount( + ModularForceFieldSystem.itemModuleScale, this.getModuleSlots()); + zScalePos += omnidirectionalScale; + xScalePos += omnidirectionalScale; + yScalePos += omnidirectionalScale; + final Vector3 positiveScale = new Vector3(xScalePos, yScalePos, zScalePos); + if (Settings.USE_CACHE) { + super.cache.put(cacheID, positiveScale); + } + return positiveScale; + } + + @Override + public Vector3 getNegativeScale() { + final String cacheID = "getNegativeScale"; + if (Settings.USE_CACHE && super.cache.containsKey(cacheID) && + super.cache.get(cacheID) instanceof Vector3) { + return (Vector3) super.cache.get(cacheID); + } + ForgeDirection direction = + this.getDirection((IBlockAccess)this.getWorldObj(), this.xCoord, + this.yCoord, this.zCoord); + if (direction == ForgeDirection.UP || direction == ForgeDirection.DOWN) { + direction = ForgeDirection.NORTH; + } + int zScaleNeg = this.getModuleCount( + ModularForceFieldSystem.itemModuleScale, + this.getSlotsBasedOnDirection(VectorHelper.getOrientationFromSide( + direction, ForgeDirection.NORTH))); + int xScaleNeg = this.getModuleCount( + ModularForceFieldSystem.itemModuleScale, + this.getSlotsBasedOnDirection(VectorHelper.getOrientationFromSide( + direction, ForgeDirection.WEST))); + int yScaleNeg = + this.getModuleCount(ModularForceFieldSystem.itemModuleScale, + this.getSlotsBasedOnDirection(ForgeDirection.DOWN)); + final int omnidirectionalScale = this.getModuleCount( + ModularForceFieldSystem.itemModuleScale, this.getModuleSlots()); + zScaleNeg += omnidirectionalScale; + xScaleNeg += omnidirectionalScale; + yScaleNeg += omnidirectionalScale; + final Vector3 negativeScale = new Vector3(xScaleNeg, yScaleNeg, zScaleNeg); + if (Settings.USE_CACHE) { + super.cache.put(cacheID, negativeScale); + } + return negativeScale; + } + + @Override + public int getRotationYaw() { + final String cacheID = "getRotationYaw"; + if (Settings.USE_CACHE && super.cache.containsKey(cacheID) && + super.cache.get(cacheID) instanceof Integer) { + return (int) super.cache.get(cacheID); + } + final ForgeDirection direction = + this.getDirection((IBlockAccess)this.getWorldObj(), this.xCoord, + this.yCoord, this.zCoord); + int horizontalRotation = + this.getModuleCount( + ModularForceFieldSystem.itemModuleRotate, + this.getSlotsBasedOnDirection(VectorHelper.getOrientationFromSide( + direction, ForgeDirection.EAST))) - + this.getModuleCount( + ModularForceFieldSystem.itemModuleRotate, + this.getSlotsBasedOnDirection(VectorHelper.getOrientationFromSide( + direction, ForgeDirection.WEST))) + + this.getModuleCount( + ModularForceFieldSystem.itemModuleRotate, + this.getSlotsBasedOnDirection(VectorHelper.getOrientationFromSide( + direction, ForgeDirection.SOUTH))) - + this.getModuleCount( + ModularForceFieldSystem.itemModuleRotate, + this.getSlotsBasedOnDirection(VectorHelper.getOrientationFromSide( + direction, ForgeDirection.NORTH))); + horizontalRotation *= 2; + if (Settings.USE_CACHE) { + super.cache.put(cacheID, horizontalRotation); + } + return horizontalRotation; + } + + @Override + public int getRotationPitch() { + final String cacheID = "getRotationPitch"; + if (Settings.USE_CACHE && super.cache.containsKey(cacheID) && + super.cache.get(cacheID) instanceof Integer) { + return (int) super.cache.get(cacheID); + } + int verticleRotation = + this.getModuleCount(ModularForceFieldSystem.itemModuleRotate, + this.getSlotsBasedOnDirection(ForgeDirection.UP)) - + this.getModuleCount(ModularForceFieldSystem.itemModuleRotate, + this.getSlotsBasedOnDirection(ForgeDirection.DOWN)); + verticleRotation *= 2; + if (Settings.USE_CACHE) { + super.cache.put(cacheID, verticleRotation); + } + return verticleRotation; + } + + @Override + public Set getInteriorPoints() { + if (Settings.USE_CACHE && super.cache.containsKey("getInteriorPoints") && + super.cache.get("getInteriorPoints") instanceof Set) { + return (Set) super.cache.get("getInteriorPoints"); + } + if (this.getModeStack().getItem() instanceof ICache) { + ((ICache)this.getModeStack().getItem()).clearCache(); + } + final Set newField = this.getMode().getInteriorPoints(this); + final Set returnField = new HashSet<>(); + final Vector3 translation = this.getTranslation(); + final int rotationYaw = this.getRotationYaw(); + final int rotationPitch = this.getRotationPitch(); + for (final Vector3 position : newField) { + final Vector3 newPosition = position.clone(); + if (rotationYaw != 0 || rotationPitch != 0) { + CalculationHelper.rotateByAngle(newPosition, rotationYaw, + rotationPitch); + } + newPosition.add(new Vector3(this)); + newPosition.add(translation); + returnField.add(newPosition); + } + if (Settings.USE_CACHE) { + super.cache.put("getInteriorPoints", returnField); + } + return returnField; + } + + @Override + public int[] getSlotsBasedOnDirection(final ForgeDirection direction) { + switch (direction) { + default: { + return new int[0]; + } + case UP: { + return new int[] {3, 11}; + } + case DOWN: { + return new int[] {6, 14}; + } + case NORTH: { + return new int[] {8, 10}; + } + case SOUTH: { + return new int[] {7, 9}; + } + case WEST: { + return new int[] {4, 5}; + } + case EAST: { + return new int[] {12, 13}; + } + } + } + + @Override + public void setCalculating(final boolean bool) { + this.isCalculating = bool; + } + + @Override + public void setCalculated(final boolean bool) { + this.isCalculated = bool; + } + + @Override + public Set getCalculatedField() { + return this.calculatedField; + } + + @Override + public List getDelayedEvents() { + return this.delayedEvents; + } + + @Override + public List getQuedDelayedEvents() { + return this.quedDelayedEvents; + } +} diff --git a/src/main/java/mffs/tileentity/TileEntityForceField.java b/src/main/java/mffs/tileentity/TileEntityForceField.java new file mode 100644 index 0000000..5e952af --- /dev/null +++ b/src/main/java/mffs/tileentity/TileEntityForceField.java @@ -0,0 +1,107 @@ +package mffs.tileentity; + +import mffs.MFFSHelper; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.network.NetworkManager; +import net.minecraft.network.Packet; +import net.minecraft.network.play.server.S35PacketUpdateTileEntity; +import net.minecraft.world.IBlockAccess; +import universalelectricity.core.vector.Vector3; +import universalelectricity.prefab.tile.TileEntityAdvanced; + +public class TileEntityForceField extends TileEntityAdvanced { + private Vector3 projector; + public ItemStack camoStack; + + public TileEntityForceField() { + this.projector = null; + this.camoStack = null; + } + + public boolean canUpdate() { return false; } + + @Override + public Packet getDescriptionPacket() { + if (this.getProjector() != null) { + NBTTagCompound nbt = new NBTTagCompound(); + + if (this.camoStack != null) { + nbt.setTag("projector", + this.projector.writeToNBT(new NBTTagCompound())); + nbt.setInteger("itemID", Item.getIdFromItem(this.camoStack.getItem())); + nbt.setInteger("itemMetadata", this.camoStack.getItemDamage()); + } + return new S35PacketUpdateTileEntity( + this.xCoord, this.yCoord, this.zCoord, this.getBlockMetadata(), nbt); + } + return null; + } + + @Override + public void onDataPacket(NetworkManager arg0, + S35PacketUpdateTileEntity arg1) { + NBTTagCompound nbt = arg1.func_148857_g(); + + this.setProjector(Vector3.readFromNBT(nbt.getCompoundTag("projector"))); + if (nbt.hasKey("itemID") && nbt.hasKey("itemMetadata")) { + this.camoStack = new ItemStack(Item.getItemById(nbt.getInteger("itemID")), + 1, nbt.getInteger("itemMetadata")); + } + this.getWorldObj().markBlockRangeForRenderUpdate(this.xCoord, this.yCoord, + this.zCoord, this.xCoord, + this.yCoord, this.zCoord); + } + + public void setProjector(final Vector3 position) { + this.projector = position; + if (!this.getWorldObj().isRemote) { + this.refreshCamoBlock(); + } + } + + public TileEntityForceFieldProjector getProjector() { + if (this.getProjectorSafe() != null) { + return this.getProjectorSafe(); + } + if (!this.getWorldObj().isRemote) { + this.getWorldObj().setBlockToAir(this.xCoord, this.yCoord, this.zCoord); + } + return null; + } + + public TileEntityForceFieldProjector getProjectorSafe() { + if (this.projector != null && + this.projector.getTileEntity((IBlockAccess)this.getWorldObj()) + instanceof TileEntityForceFieldProjector && + (this.getWorldObj().isRemote || + ((TileEntityForceFieldProjector)this.projector.getTileEntity( + (IBlockAccess)this.getWorldObj())) + .getCalculatedField() + .contains(new Vector3(this)))) { + return (TileEntityForceFieldProjector)this.projector.getTileEntity( + (IBlockAccess)this.getWorldObj()); + } + return null; + } + + public void refreshCamoBlock() { + if (this.getProjectorSafe() != null) { + this.camoStack = + MFFSHelper.getCamoBlock(this.getProjector(), new Vector3(this)); + } + } + + public void readFromNBT(final NBTTagCompound nbt) { + super.readFromNBT(nbt); + this.projector = Vector3.readFromNBT(nbt.getCompoundTag("projector")); + } + + public void writeToNBT(final NBTTagCompound nbt) { + super.writeToNBT(nbt); + if (this.getProjector() != null) { + nbt.setTag("projector", this.projector.writeToNBT(new NBTTagCompound())); + } + } +} diff --git a/src/main/java/mffs/tileentity/TileEntityForceFieldProjector.java b/src/main/java/mffs/tileentity/TileEntityForceFieldProjector.java new file mode 100644 index 0000000..bbcf623 --- /dev/null +++ b/src/main/java/mffs/tileentity/TileEntityForceFieldProjector.java @@ -0,0 +1,272 @@ +package mffs.tileentity; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import java.util.HashSet; +import java.util.Set; +import mffs.ModularForceFieldSystem; +import mffs.Settings; +import mffs.api.ICache; +import mffs.api.IProjector; +import mffs.api.modules.IModule; +import mffs.api.modules.IProjectorMode; +import mffs.block.BlockForceField; +import mffs.card.ItemCard; +import net.minecraft.block.Block; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.world.IBlockAccess; +import universalelectricity.core.vector.Vector3; + +public class TileEntityForceFieldProjector extends TileEntityFieldInteraction + implements IProjector, ProjectorCalculationThread.IThreadCallBack { + protected final Set forceFields; + + public TileEntityForceFieldProjector() { + this.forceFields = new HashSet<>(); + super.capacityBase = 50; + super.startModuleIndex = 1; + } + + @Override + public void initiate() { + super.initiate(); + this.calculateForceField(); + } + + @Override + public void onFxsPacket(NBTTagCompound data) { + Vector3 otherPos = Vector3.readFromNBT(data); + int type = data.getInteger("type"); + + Vector3 vector = otherPos.add(0.5); + final Vector3 root = new Vector3(this).add(0.5); + if (type == 1) { + ModularForceFieldSystem.proxy.renderBeam(this.getWorldObj(), root, vector, + 0.6f, 0.6f, 1.0f, 40); + ModularForceFieldSystem.proxy.renderHologramMoving( + this.getWorldObj(), vector, 1.0f, 1.0f, 1.0f, 50); + } else if (type == 2) { + ModularForceFieldSystem.proxy.renderBeam(this.getWorldObj(), vector, root, + 1.0f, 0.0f, 0.0f, 40); + ModularForceFieldSystem.proxy.renderHologramMoving( + this.getWorldObj(), vector, 1.0f, 0.0f, 0.0f, 50); + } + } + + @Override + protected void calculateForceField( + final ProjectorCalculationThread.IThreadCallBack callBack) { + if (!this.getWorldObj().isRemote && !super.isCalculating && + this.getMode() != null) { + this.forceFields.clear(); + } + super.calculateForceField(callBack); + } + + @Override + public void onThreadComplete() { + this.destroyField(); + } + + @Override + public void updateEntity() { + super.updateEntity(); + if (this.isActive() && this.getMode() != null && + this.requestFortron(this.getFortronCost(), false) >= this.getFortronCost()) { + this.consumeCost(); + if (!this.getWorldObj().isRemote) { + if (super.ticks % 10L == 0L) { + if (!super.isCalculated) { + this.calculateForceField(); + } else { + this.projectField(); + } + } + } else if (this.isActive()) { + super.animation += this.getFortronCost() / 3; + } + if (super.ticks % 40L == 0L && + this.getModuleCount(ModularForceFieldSystem.itemModuleSilence, + new int[0]) <= 0) { + this.getWorldObj().playSoundEffect( + this.xCoord + 0.5, this.yCoord + 0.5, this.zCoord + 0.5, + "mffs:field", 0.6f, + 1.0f - this.getWorldObj().rand.nextFloat() * 0.1f); + } + } else if (!this.getWorldObj().isRemote) { + this.destroyField(); + } + } + + @Override + public int getFortronCost() { + return super.getFortronCost() + 5; + } + + @Override + public float getAmplifier() { + return (float) Math.max( + Math.min(this.getCalculatedField().size() / 1000, 10), 1); + } + + @Override + public void markDirty() { + super.markDirty(); + this.destroyField(); + } + + @Override + public void projectField() { + Label_0636: { + if (!this.getWorldObj().isRemote && super.isCalculated && + !super.isCalculating) { + if (this.forceFields.size() <= 0 && this.getModeStack().getItem() instanceof ICache) { + ((ICache) this.getModeStack().getItem()).clearCache(); + } + int constructionCount = 0; + final int constructionSpeed = Math.min( + this.getProjectionSpeed(), Settings.MAX_FORCE_FIELDS_PER_TICK); + final HashSet fieldToBeProjected = new HashSet<>(); + fieldToBeProjected.addAll(super.calculatedField); + for (final IModule module : this.getModules(this.getModuleSlots())) { + if (module.onProject(this, fieldToBeProjected)) { + return; + } + } + Label_0158: for (final Vector3 vector : super.calculatedField) { + if (fieldToBeProjected.contains(vector)) { + if (constructionCount > constructionSpeed) { + break; + } + final Block block = vector.getBlock((IBlockAccess) this.getWorldObj()); + if ((block != null && + (this.getModuleCount( + ModularForceFieldSystem.itemModuleDisintegration, + new int[0]) <= 0 || + block.getBlockHardness(this.getWorldObj(), vector.intX(), + vector.intY(), + vector.intZ()) == -1.0f) + && + !block.getMaterial().isLiquid() && block != Blocks.snow && + block != Blocks.vine && block != Blocks.tallgrass && + block != Blocks.deadbush && + !block.isReplaceable(this.getWorldObj(), vector.intX(), + vector.intY(), vector.intZ())) + || + block == ModularForceFieldSystem.blockForceField || + vector.equals(new Vector3(this)) || + !this.getWorldObj() + .getChunkFromBlockCoords(vector.intX(), vector.intZ()).isChunkLoaded) { + continue; + } + for (final IModule module2 : this.getModules(this.getModuleSlots())) { + final int flag = module2.onProject(this, vector.clone()); + if (flag == 1) { + continue Label_0158; + } + if (flag == 2) { + break Label_0636; + } + } + this.getWorldObj().setBlock( + vector.intX(), vector.intY(), vector.intZ(), + ModularForceFieldSystem.blockForceField, 0, 2); + final TileEntity tileEntity = this.getWorldObj().getTileEntity( + vector.intX(), vector.intY(), vector.intZ()); + if (tileEntity instanceof TileEntityForceField) { + ((TileEntityForceField) tileEntity).setProjector(new Vector3(this)); + } + this.requestFortron(1, true); + this.forceFields.add(vector); + ++constructionCount; + } else { + final Block block = vector.getBlock((IBlockAccess) this.getWorldObj()); + if (block != ModularForceFieldSystem.blockForceField || + ((BlockForceField) block) + .getProjector((IBlockAccess) this.getWorldObj(), + vector.intX(), vector.intY(), + vector.intZ()) != this) { + continue; + } + this.getWorldObj().setBlockToAir(vector.intX(), vector.intY(), + vector.intZ()); + } + } + } + } + } + + @Override + public void destroyField() { + if (!this.getWorldObj().isRemote && super.isCalculated && + !super.isCalculating) { + final HashSet copiedSet = new HashSet<>(); + copiedSet.addAll(super.calculatedField); + for (final Vector3 vector : copiedSet) { + final Block block = vector.getBlock((IBlockAccess) this.getWorldObj()); + if (block == ModularForceFieldSystem.blockForceField) { + this.getWorldObj().setBlock(vector.intX(), vector.intY(), + vector.intZ(), Blocks.air, 0, 3); + } + } + } + this.forceFields.clear(); + super.calculatedField.clear(); + super.isCalculated = false; + } + + @Override + public void invalidate() { + this.destroyField(); + super.invalidate(); + } + + @Override + public int getProjectionSpeed() { + return 28 + + 28 * this.getModuleCount(ModularForceFieldSystem.itemModuleSpeed, + this.getModuleSlots()); + } + + @Override + public int getSizeInventory() { + return 21; + } + + @Override + public boolean isItemValidForSlot(final int slotID, + final ItemStack itemStack) { + if (slotID == 0 || slotID == 1) { + return itemStack.getItem() instanceof ItemCard; + } + if (slotID == 2) { + return itemStack.getItem() instanceof IProjectorMode; + } + return slotID >= 15 || itemStack.getItem() instanceof IModule; + } + + @Override + public Set getCards() { + final Set cards = new HashSet<>(); + cards.add(super.getCard()); + cards.add(this.getStackInSlot(1)); + return cards; + } + + @SideOnly(Side.CLIENT) + public AxisAlignedBB getRenderBoundingBox() { + return AxisAlignedBB.getBoundingBox( + (double) this.xCoord, (double) this.yCoord, (double) this.zCoord, + (double) (this.xCoord + 1), (double) (this.yCoord + 2), + (double) (this.zCoord + 1)); + } + + @Override + public long getTicks() { + return super.ticks; + } +} diff --git a/src/main/java/mffs/tileentity/TileEntityForceManipulator.java b/src/main/java/mffs/tileentity/TileEntityForceManipulator.java new file mode 100644 index 0000000..f9b6550 --- /dev/null +++ b/src/main/java/mffs/tileentity/TileEntityForceManipulator.java @@ -0,0 +1,381 @@ +package mffs.tileentity; + +import dan200.computercraft.api.lua.ILuaContext; +import dan200.computercraft.api.lua.LuaException; +import dan200.computercraft.api.peripheral.IComputerAccess; +import java.util.List; +import java.util.Set; +import mffs.ModularForceFieldSystem; +import mffs.Settings; +import mffs.api.Blacklist; +import mffs.api.ISpecialForceManipulation; +import mffs.api.modules.IModule; +import mffs.api.modules.IProjectorMode; +import mffs.base.PacketFxs; +import mffs.base.PacketTile; +import mffs.card.ItemCard; +import mffs.event.BlockPreMoveDelayedEvent; +import mffs.fortron.FortronHelper; +import net.minecraft.block.Block; +import net.minecraft.block.BlockLiquid; +import net.minecraft.entity.Entity; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTBase; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.network.NetworkManager; +import net.minecraft.network.Packet; +import net.minecraft.network.play.server.S35PacketUpdateTileEntity; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.world.IBlockAccess; +import net.minecraftforge.common.util.ForgeDirection; +import net.minecraftforge.fluids.FluidStack; +import universalelectricity.core.vector.Vector3; + +public class TileEntityForceManipulator extends TileEntityFieldInteraction { + public static final int ANIMATION_TIME = 20; + public Vector3 anchor; + public int displayMode; + public boolean isCalculatingManipulation; + public Set manipulationVectors; + public boolean doAnchor; + + public TileEntityForceManipulator() { + this.anchor = null; + this.displayMode = 1; + this.isCalculatingManipulation = false; + this.manipulationVectors = null; + this.doAnchor = true; + } + + @Override + public void updateEntity() { + super.updateEntity(); + if (this.anchor == null) { + this.anchor = new Vector3(); + } + if (this.getMode() != null && Settings.ENABLE_MANIPULATOR) { + if (!this.getWorldObj().isRemote && this.manipulationVectors != null && + !this.isCalculatingManipulation) { + final ForgeDirection dir = this.getDirection((IBlockAccess) this.getWorldObj(), this.xCoord, + this.yCoord, this.zCoord); + final NBTTagCompound nbt = new NBTTagCompound(); + final NBTTagList nbtList = new NBTTagList(); + int i = 0; + for (final Vector3 position : this.manipulationVectors) { + if (this.moveBlock(position, dir) && this.isBlockVisible(position) && + i < Settings.MAX_FORCE_FIELDS_PER_TICK) { + nbtList.appendTag( + (NBTBase) position.writeToNBT(new NBTTagCompound())); + ++i; + } + } + nbt.setByte("type", (byte) 2); + nbt.setTag("list", (NBTBase) nbtList); + ModularForceFieldSystem.channel.sendToAll( + new PacketFxs(new Vector3(this), nbt)); + if (this.doAnchor) { + this.anchor = this.anchor.modifyPositionFromSide(dir); + } + this.updatePushedObjects(0.022f); + this.manipulationVectors = null; + this.markDirty(); + } + if (this.isActive() && super.ticks % 20L == 0L && + this.requestFortron(this.getFortronCost(), false) > 0) { + if (!this.getWorldObj().isRemote) { + this.requestFortron(this.getFortronCost(), true); + new ManipulatorCalculationThread(this).start(); + } + if (this.getModuleCount(ModularForceFieldSystem.itemModuleSilence, + new int[0]) <= 0) { + this.getWorldObj().playSoundEffect( + this.xCoord + 0.5, this.yCoord + 0.5, this.zCoord + 0.5, + "mffs:fieldmove", 0.6f, + 1.0f - this.getWorldObj().rand.nextFloat() * 0.1f); + } + this.setActive(false); + } + if (!this.getWorldObj().isRemote) { + if (!super.isCalculated) { + this.calculateForceField(); + } + if (super.ticks % 120L == 0L && !super.isCalculating && + Settings.HIGH_GRAPHICS && this.getDelayedEvents().size() <= 0 && + this.displayMode > 0) { + final NBTTagCompound nbt2 = new NBTTagCompound(); + final NBTTagList nbtList2 = new NBTTagList(); + int j = 0; + for (final Vector3 position2 : this.getInteriorPoints()) { + if (this.isBlockVisible(position2) && + (this.displayMode == 2 || + position2.getBlock((IBlockAccess) this.getWorldObj()) != Blocks.air) + && + j < Settings.MAX_FORCE_FIELDS_PER_TICK) { + nbtList2.appendTag( + (NBTBase) position2.writeToNBT(new NBTTagCompound())); + ++j; + } + } + nbt2.setByte("type", (byte) 1); + nbt2.setTag("list", (NBTBase) nbtList2); + + ModularForceFieldSystem.channel.sendToAll( + new PacketFxs(new Vector3(this), nbt2)); + } + } + } + } + + public boolean isBlockVisible(final Vector3 position) { + int i = 0; + for (final ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) { + final Vector3 checkPos = position.clone().modifyPositionFromSide(direction); + final Block block = checkPos.getBlock((IBlockAccess) this.getWorldObj()); + if (block != Blocks.air && block.isOpaqueCube()) { + ++i; + } + } + return i < ForgeDirection.VALID_DIRECTIONS.length; + } + + @Override + public void onFxsPacket(NBTTagCompound nbt) { + final byte type = nbt.getByte("type"); + final NBTTagList nbtList = (NBTTagList) nbt.getTag("list"); + for (int i = 0; i < nbtList.tagCount(); ++i) { + final Vector3 vector = Vector3.readFromNBT(nbtList.getCompoundTagAt(i)).add(0.5); + if (type == 1) { + ModularForceFieldSystem.proxy.renderHologram( + this.getWorldObj(), vector, 1.0f, 1.0f, 1.0f, 30, + vector.clone().modifyPositionFromSide( + this.getDirection((IBlockAccess) this.getWorldObj(), this.xCoord, + this.yCoord, this.zCoord))); + } else if (type == 2) { + ModularForceFieldSystem.proxy.renderHologram( + this.getWorldObj(), vector, 1.0f, 0.0f, 0.0f, 30, + vector.clone().modifyPositionFromSide( + this.getDirection((IBlockAccess) this.getWorldObj(), this.xCoord, + this.yCoord, this.zCoord))); + this.updatePushedObjects(0.022f); + } + } + } + + @Override + public void onReceivePacket(PacketTile.Type type, + final NBTTagCompound dataStream) { + super.onReceivePacket(type, dataStream); + if (type == PacketTile.Type.TOGGLE_MODE && !this.getWorldObj().isRemote) { + switch (dataStream.getInteger("buttonId")) { + case 1: + this.anchor = null; + this.markDirty(); + break; + + case 2: + this.displayMode = (this.displayMode + 1) % 3; + break; + + case 3: + this.doAnchor = !this.doAnchor; + break; + default: + break; + } + } + } + + @Override + public int getFortronCost() { + return (int) ((super.getFortronCost() + this.anchor.getMagnitude()) * + 1000.0); + } + + @Override + public void markDirty() { + super.markDirty(); + super.isCalculated = false; + } + + protected boolean canMove() { + final Set mobilizationPoints = this.getInteriorPoints(); + final ForgeDirection dir = this.getDirection((IBlockAccess) this.getWorldObj(), this.xCoord, + this.yCoord, this.zCoord); + Label_0033: for (final Vector3 position : mobilizationPoints) { + if (position.getBlock((IBlockAccess) this.getWorldObj()) != Blocks.air) { + if (Blacklist.forceManipulationBlacklist.contains( + position.getBlock((IBlockAccess) this.getWorldObj()))) { + return false; + } + final TileEntity tileEntity = position.getTileEntity((IBlockAccess) this.getWorldObj()); + if (tileEntity instanceof ISpecialForceManipulation && + !((ISpecialForceManipulation) tileEntity) + .preMove(position.intX(), position.intY(), position.intZ())) { + return false; + } + final Vector3 targetPosition = position.clone().modifyPositionFromSide(dir); + if (targetPosition.getTileEntity((IBlockAccess) this.getWorldObj()) == this) { + return false; + } + for (final Vector3 checkPos : mobilizationPoints) { + if (checkPos.equals(targetPosition)) { + continue Label_0033; + } + } + final Block blockID = targetPosition.getBlock((IBlockAccess) this.getWorldObj()); + if (blockID != Blocks.air && + (!blockID.isReplaceable(this.getWorldObj(), targetPosition.intX(), + targetPosition.intY(), + targetPosition.intZ()) && + !(blockID instanceof BlockLiquid))) { + return false; + } + continue; + } + } + return true; + } + + protected boolean moveBlock(final Vector3 position, + final ForgeDirection direction) { + if (!this.getWorldObj().isRemote) { + final Vector3 newPosition = position.clone().modifyPositionFromSide(direction); + final TileEntity tileEntity = position.getTileEntity((IBlockAccess) this.getWorldObj()); + final Block blockID = position.getBlock((IBlockAccess) this.getWorldObj()); + if (blockID != Blocks.air && tileEntity != this) { + this.getDelayedEvents().add(new BlockPreMoveDelayedEvent( + this, 20, this.getWorldObj(), position, newPosition)); + return true; + } + } + return false; + } + + public void updatePushedObjects(final float amount) { + final ForgeDirection dir = this.getDirection((IBlockAccess) this.getWorldObj(), this.xCoord, + this.yCoord, this.zCoord); + final AxisAlignedBB axisalignedbb = this.getSearchAxisAlignedBB(); + if (axisalignedbb != null) { + final List entities = this.getWorldObj().getEntitiesWithinAABB(Entity.class, axisalignedbb); + for (final Entity entity : entities) { + entity.addVelocity((double) (amount * dir.offsetX), + (double) (amount * dir.offsetY), + (double) (amount * dir.offsetZ)); + } + } + } + + public AxisAlignedBB getSearchAxisAlignedBB() { + final Vector3 positiveScale = new Vector3(this) + .add(this.getTranslation()) + .add(this.getPositiveScale()); + final Vector3 negativeScale = new Vector3(this) + .add(this.getTranslation()) + .subtract(this.getNegativeScale()); + final Vector3 minScale = new Vector3(Math.min(positiveScale.x, negativeScale.x), + Math.min(positiveScale.y, negativeScale.y), + Math.min(positiveScale.z, negativeScale.z)); + final Vector3 maxScale = new Vector3(Math.max(positiveScale.x, negativeScale.x), + Math.max(positiveScale.y, negativeScale.y), + Math.max(positiveScale.z, negativeScale.z)); + return AxisAlignedBB.getBoundingBox( + (double) minScale.intX(), (double) minScale.intY(), + (double) minScale.intZ(), (double) maxScale.intX(), + (double) maxScale.intY(), (double) maxScale.intZ()); + } + + @Override + public boolean isItemValidForSlot(final int slotID, + final ItemStack itemStack) { + if (slotID == 0 || slotID == 1) { + return itemStack.getItem() instanceof ItemCard; + } + if (slotID == 2) { + return itemStack.getItem() instanceof IProjectorMode; + } + return slotID >= 15 || itemStack.getItem() instanceof IModule; + } + + @Override + public void readFromNBT(final NBTTagCompound nbt) { + super.readFromNBT(nbt); + this.anchor = Vector3.readFromNBT(nbt.getCompoundTag("anchor")); + this.displayMode = nbt.getInteger("displayMode"); + this.doAnchor = nbt.getBoolean("doAnchor"); + } + + @Override + public void writeToNBT(final NBTTagCompound nbt) { + super.writeToNBT(nbt); + if (this.anchor != null) { + nbt.setTag("anchor", this.anchor.writeToNBT(new NBTTagCompound())); + } + nbt.setInteger("displayMode", this.displayMode); + nbt.setBoolean("doAnchor", this.doAnchor); + } + + @Override + public Vector3 getTranslation() { + return super.getTranslation().clone().add(this.anchor); + } + + @Override + public int getSizeInventory() { + return 21; + } + + @Override + public String[] getMethodNames() { + return new String[] { "isActivate", "setActivate", "resetAnchor" }; + } + + @Override + public Object[] callMethod(IComputerAccess computer, ILuaContext context, + int method, Object[] arguments) + throws LuaException, InterruptedException { + switch (method) { + case 0: + case 1: + return super.callMethod(computer, context, method, arguments); + + case 2: + this.anchor = null; + return null; + + default: + return null; + } + } + + @Override + public Packet getDescriptionPacket() { + NBTTagCompound nbt = new NBTTagCompound(); + + nbt.setBoolean("isActive", this.isActive); + nbt.setInteger("fortron", this.fortronTank.getFluidAmount()); + if (this.anchor != null) { + nbt.setTag("anchor", this.anchor.writeToNBT(new NBTTagCompound())); + } + nbt.setInteger("displayMode", this.displayMode); + nbt.setBoolean("doAnchor", this.doAnchor); + + return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, + this.getBlockMetadata(), nbt); + } + + @Override + public void onDataPacket(NetworkManager arg0, S35PacketUpdateTileEntity arg1) { + NBTTagCompound nbt = arg1.func_148857_g(); + + this.isActive = nbt.getBoolean("isActive"); + this.fortronTank.setFluid(new FluidStack(FortronHelper.FLUID_FORTRON, nbt.getInteger("fortron"))); + if (nbt.hasKey("anchor")) { + this.anchor = Vector3.readFromNBT(nbt.getCompoundTag("anchor")); + } + this.displayMode = nbt.getInteger("displayMode"); + this.doAnchor = nbt.getBoolean("doAnchor"); + } +} diff --git a/src/main/java/mffs/tileentity/TileEntityFortronCapacitor.java b/src/main/java/mffs/tileentity/TileEntityFortronCapacitor.java new file mode 100644 index 0000000..be6431e --- /dev/null +++ b/src/main/java/mffs/tileentity/TileEntityFortronCapacitor.java @@ -0,0 +1,164 @@ +package mffs.tileentity; + +import icbm.api.IBlockFrequency; +import java.util.HashSet; +import java.util.Set; +import mffs.MFFSHelper; +import mffs.ModularForceFieldSystem; +import mffs.TransferMode; +import mffs.api.card.ICard; +import mffs.api.card.ICardInfinite; +import mffs.api.card.ICardLink; +import mffs.api.fortron.IFortronCapacitor; +import mffs.api.fortron.IFortronFrequency; +import mffs.api.modules.IModule; +import mffs.base.PacketTile; +import mffs.base.TileEntityModuleAcceptor; +import mffs.fortron.FortronHelper; +import mffs.fortron.FrequencyGrid; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.network.NetworkManager; +import net.minecraft.network.Packet; +import net.minecraft.network.play.server.S35PacketUpdateTileEntity; +import net.minecraft.world.IBlockAccess; +import net.minecraftforge.fluids.FluidStack; +import universalelectricity.core.vector.Vector3; + +public class TileEntityFortronCapacitor + extends TileEntityModuleAcceptor implements IFortronCapacitor { + private TransferMode transferMode; + + public TileEntityFortronCapacitor() { + this.transferMode = TransferMode.EQUALIZE; + super.capacityBase = 700; + super.capacityBoost = 10; + super.startModuleIndex = 2; + } + + @Override + public void updateEntity() { + super.updateEntity(); + this.consumeCost(); + if (!this.isDisabled() && this.isActive() && super.ticks % 10L == 0L) { + Set machines = new HashSet<>(); + for (final ItemStack itemStack : this.getCards()) { + if (itemStack != null) { + if (itemStack.getItem() instanceof ICardInfinite) { + this.setFortronEnergy(this.getFortronCapacity()); + } else { + if (!(itemStack.getItem() instanceof ICardLink)) { + continue; + } + final Vector3 linkPosition = + ((ICardLink)itemStack.getItem()).getLink(itemStack); + if (linkPosition == null || + !(linkPosition.getTileEntity((IBlockAccess)this.getWorldObj()) + instanceof IFortronFrequency)) { + continue; + } + machines.add(this); + machines.add((IFortronFrequency)linkPosition.getTileEntity( + (IBlockAccess)this.getWorldObj())); + } + } + } + if (machines.size() < 1) { + machines = this.getLinkedDevices(); + } + MFFSHelper.transferFortron(this, machines, this.transferMode, + this.getTransmissionRate()); + } + } + + public float getAmplifier() { return 0.001f; } + + @Override + public Packet getDescriptionPacket() { + NBTTagCompound nbt = new NBTTagCompound(); + + nbt.setInteger("transferMode", this.transferMode.ordinal()); + nbt.setBoolean("isActive", this.isActive); + nbt.setInteger("fortron", this.fortronTank.getFluidAmount()); + + return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, + this.getBlockMetadata(), nbt); + } + + @Override + public void onDataPacket(NetworkManager arg0, + S35PacketUpdateTileEntity arg1) { + NBTTagCompound nbt = arg1.func_148857_g(); + + this.transferMode = TransferMode.values()[nbt.getInteger("transferMode")]; + this.isActive = nbt.getBoolean("isActive"); + this.fortronTank.setFluid( + new FluidStack(FortronHelper.FLUID_FORTRON, nbt.getInteger("fortron"))); + } + + @Override + public void onReceivePacket(PacketTile.Type type, + final NBTTagCompound dataStream) { + super.onReceivePacket(type, dataStream); + if (type == PacketTile.Type.TOGGLE_MODE) { + this.transferMode = this.transferMode.toggle(); + } + } + + public int getSizeInventory() { return 5; } + + @Override + public void readFromNBT(final NBTTagCompound nbt) { + super.readFromNBT(nbt); + this.transferMode = TransferMode.values()[nbt.getInteger("transferMode")]; + } + + @Override + public void writeToNBT(final NBTTagCompound nbttagcompound) { + super.writeToNBT(nbttagcompound); + nbttagcompound.setInteger("transferMode", this.transferMode.ordinal()); + } + + @Override + public Set getLinkedDevices() { + final Set fortronBlocks = new HashSet<>(); + final Set frequencyBlocks = FrequencyGrid.instance().get( + this.getWorldObj(), new Vector3(this), this.getTransmissionRange(), + this.getFrequency()); + for (final IBlockFrequency frequencyBlock : frequencyBlocks) { + if (frequencyBlock instanceof IFortronFrequency) { + fortronBlocks.add((IFortronFrequency)frequencyBlock); + } + } + return fortronBlocks; + } + + public boolean isItemValidForSlot(final int slotID, + final ItemStack itemStack) { + if (slotID == 0 || slotID == 1) { + return itemStack.getItem() instanceof ICard; + } + return itemStack.getItem() instanceof IModule; + } + + public Set getCards() { + final Set cards = new HashSet<>(); + cards.add(super.getCard()); + cards.add(this.getStackInSlot(1)); + return cards; + } + + public TransferMode getTransferMode() { return this.transferMode; } + + @Override + public int getTransmissionRange() { + return 15 + this.getModuleCount(ModularForceFieldSystem.itemModuleScale, + new int[0]); + } + + @Override + public int getTransmissionRate() { + return 250 + 50 * this.getModuleCount( + ModularForceFieldSystem.itemModuleSpeed, new int[0]); + } +} diff --git a/src/main/java/mffs/tileentity/TileEntityInterdictionMatrix.java b/src/main/java/mffs/tileentity/TileEntityInterdictionMatrix.java new file mode 100644 index 0000000..a34637b --- /dev/null +++ b/src/main/java/mffs/tileentity/TileEntityInterdictionMatrix.java @@ -0,0 +1,233 @@ +package mffs.tileentity; + +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import mffs.ModularForceFieldSystem; +import mffs.Settings; +import mffs.api.modules.IInterdictionMatrixModule; +import mffs.api.modules.IModule; +import mffs.api.security.IBiometricIdentifier; +import mffs.api.security.IInterdictionMatrix; +import mffs.api.security.Permission; +import mffs.base.PacketTile; +import mffs.base.TileEntityModuleAcceptor; +import mffs.card.ItemCard; +import mffs.fortron.FortronHelper; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.network.NetworkManager; +import net.minecraft.network.Packet; +import net.minecraft.network.play.server.S35PacketUpdateTileEntity; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.util.ChatComponentText; +import net.minecraftforge.fluids.FluidStack; + +public class TileEntityInterdictionMatrix + extends TileEntityModuleAcceptor implements IInterdictionMatrix { + private boolean isBanMode; + + public TileEntityInterdictionMatrix() { + this.isBanMode = true; + super.capacityBase = 30; + super.startModuleIndex = 2; + super.endModuleIndex = 9; + } + + @Override + public void updateEntity() { + super.updateEntity(); + if (!this.getWorldObj().isRemote && + (this.isActive() || (this.getStackInSlot(0) != null && + this.getStackInSlot(0).getItem() == + ModularForceFieldSystem.itemCardInfinite)) && + super.ticks % 10L == 0L && + this.requestFortron(this.getFortronCost() * 10, false) > 0) { + this.requestFortron(this.getFortronCost() * 10, true); + this.scan(); + } + } + + public float getAmplifier() { + return (float)Math.max(Math.min(this.getActionRange() / 20, 10), 1); + } + + public void scan() { + try { + final IBiometricIdentifier biometricIdentifier = + this.getBiometricIdentifier(); + final AxisAlignedBB emptyBounds = AxisAlignedBB.getBoundingBox( + (double)this.xCoord, (double)this.yCoord, (double)this.zCoord, + (double)(this.xCoord + 1), (double)(this.yCoord + 1), + (double)(this.zCoord + 1)); + final List warningList = + this.getWorldObj().getEntitiesWithinAABB( + EntityLivingBase.class, + emptyBounds.expand((double)this.getWarningRange(), + (double)this.getWarningRange(), + (double)this.getWarningRange())); + final List actionList = + this.getWorldObj().getEntitiesWithinAABB( + EntityLivingBase.class, + emptyBounds.expand((double)this.getActionRange(), + (double)this.getActionRange(), + (double)this.getActionRange())); + for (final EntityLivingBase entityLiving : warningList) { + if (entityLiving instanceof EntityPlayer && + !actionList.contains(entityLiving)) { + final EntityPlayer player = (EntityPlayer)entityLiving; + boolean isGranted = false; + if (biometricIdentifier != null && + biometricIdentifier.isAccessGranted( + player.getDisplayName(), + Permission.BYPASS_INTERDICTION_MATRIX)) { + isGranted = true; + } + if (isGranted || this.getWorldObj().rand.nextInt(3) != 0) { + continue; + } + player.addChatMessage(new ChatComponentText( + "[" + this.getInventoryName() + + "] Warning! You are near the scanning range!")); + } + } + if (this.getWorldObj().rand.nextInt(3) == 0) { + for (final EntityLivingBase entityLiving : actionList) { + this.applyAction(entityLiving); + } + } + } catch (final Exception e) { + ModularForceFieldSystem.LOGGER.severe("Defense Station has an error!"); + e.printStackTrace(); + } + } + + public void applyAction(final EntityLivingBase entityLivingBase) { + if (entityLivingBase instanceof EntityPlayer) { + final EntityPlayer player = (EntityPlayer)entityLivingBase; + final IBiometricIdentifier biometricIdentifier = + this.getBiometricIdentifier(); + if (biometricIdentifier != null && + biometricIdentifier.isAccessGranted( + player.getDisplayName(), Permission.BYPASS_INTERDICTION_MATRIX)) { + return; + } + if (!Settings.INTERACT_CREATIVE && player.capabilities.isCreativeMode) { + return; + } + } + for (final ItemStack itemStack : this.getModuleStacks(new int[0])) { + if (itemStack.getItem() instanceof IInterdictionMatrixModule) { + final IInterdictionMatrixModule module = + (IInterdictionMatrixModule)itemStack.getItem(); + if (module.onDefend(this, entityLivingBase)) { + break; + } + if (((Entity)entityLivingBase).isDead) { + break; + } + continue; + } + } + } + + @Override + public Packet getDescriptionPacket() { + NBTTagCompound nbt = new NBTTagCompound(); + + nbt.setBoolean("isBanMode", this.isBanMode); + nbt.setBoolean("isActive", this.isActive); + nbt.setInteger("fortron", this.fortronTank.getFluidAmount()); + + return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, + this.getBlockMetadata(), nbt); + } + + @Override + public void onDataPacket(NetworkManager arg0, + S35PacketUpdateTileEntity arg1) { + NBTTagCompound nbt = arg1.func_148857_g(); + + this.isBanMode = nbt.getBoolean("isBanMode"); + this.isActive = nbt.getBoolean("isActive"); + this.fortronTank.setFluid(new FluidStack(FortronHelper.FLUID_FORTRON, nbt.getInteger("fortron"))); + } + + @Override + public void onReceivePacket(PacketTile.Type type, + final NBTTagCompound dataStream) { + super.onReceivePacket(type, dataStream); + if (type == PacketTile.Type.TOGGLE_MODE) { + this.isBanMode = !this.isBanMode; + } + } + + public boolean isBanMode() { return this.isBanMode; } + + @Override + public int getActionRange() { + return this.getModuleCount(ModularForceFieldSystem.itemModuleScale, + new int[0]); + } + + @Override + public int getWarningRange() { + return this.getModuleCount(ModularForceFieldSystem.itemModuleWarn, + new int[0]) + + this.getActionRange() + 3; + } + + @Override + public int getSizeInventory() { + return 19; + } + + @Override + public Set getFilteredItems() { + final Set stacks = new HashSet<>(); + for (int i = super.endModuleIndex; i < this.getSizeInventory() - 1; ++i) { + if (this.getStackInSlot(i) != null) { + stacks.add(this.getStackInSlot(i)); + } + } + return stacks; + } + + @Override + public boolean getFilterMode() { + return this.isBanMode; + } + + @Override + public boolean isItemValidForSlot(final int slotID, + final ItemStack itemStack) { + if (slotID == 0 || slotID == 1) { + return itemStack.getItem() instanceof ItemCard; + } + return slotID > super.endModuleIndex || itemStack.getItem() instanceof + IModule; + } + + @Override + public Set getCards() { + final Set cards = new HashSet<>(); + cards.add(super.getCard()); + cards.add(this.getStackInSlot(1)); + return cards; + } + + @Override + public void readFromNBT(final NBTTagCompound nbt) { + super.readFromNBT(nbt); + this.isBanMode = nbt.getBoolean("isBanMode"); + } + + @Override + public void writeToNBT(final NBTTagCompound nbt) { + super.writeToNBT(nbt); + nbt.setBoolean("isBanMode", this.isBanMode); + } +} diff --git a/src/main/java/micdoodle8/mods/galacticraft/api/block/IPartialSealableBlock.java b/src/main/java/micdoodle8/mods/galacticraft/api/block/IPartialSealableBlock.java new file mode 100644 index 0000000..97efdcb --- /dev/null +++ b/src/main/java/micdoodle8/mods/galacticraft/api/block/IPartialSealableBlock.java @@ -0,0 +1,9 @@ +package micdoodle8.mods.galacticraft.api.block; + +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; + +public interface IPartialSealableBlock +{ + public boolean isSealed(World world, int x, int y, int z, ForgeDirection direction); +} diff --git a/src/main/resources/assets/mffs/lang/de_DE.properties b/src/main/resources/assets/mffs/lang/de_DE.properties new file mode 100644 index 0000000..c58560a --- /dev/null +++ b/src/main/resources/assets/mffs/lang/de_DE.properties @@ -0,0 +1,155 @@ +# Modular Force Field System Language Properties +# @author Calclavia and Vexatos + +itemGroup.MFFS=Modular Force Field System + +# Death Messages +death.attack.areaDefense=%1$s ignorierte Warnungen und wurde disintegriert. +death.attack.fieldShock=%1$s wurde von einem Kraftfeld disintegriert. + +# Blocks +tile.mffs\:fortronite.name=Fortronit +tile.mffs\:biometricIdentifier.name=Biometrischer Identifikator +tile.mffs\:interdictionMatrix.name=Interdiktionsmatrix +tile.mffs\:fortronCapacitor.name=Fortron-Speicher +tile.mffs\:projector.name=Kraftfeldprojektor +tile.mffs\:coercionDeriver.name=Zwangsansammler +tile.mffs\:manipulator.name=Kraftmanipulator +tile.mffs\:forceField.name=Kraftfeld + + +# Cards +item.mffs\:cardBlank.name=Leere Karte +item.mffs\:cardInfinite.name=Unendliche Energiekarte +item.mffs\:cardInfinite.tooltip=Die Unendliche Energiekarte ist ein Gegenstand, der nur im Kreativ-Modus zu erhalten ist. Er kann f\u00FCr endlose Energie innerhalb eines Speichers platziert werden. +item.mffs\:cardFrequency.name=Frequenzkarte +item.mffs\:cardFrequency.tooltip=Die Frequenzkarte wird f\u00FCr m\u00FChelose Frequenz\u00FCbertragung genutzt. Mit Shift-rechtsklicken wird die Karte eine zuf\u00E4llige Frequenz generieren. +item.mffs\:cardLink.name=Verbindungskarte +item.mffs\:cardLink.tooltip=Das Rechtsklicken auf einen Block mit dieser Karte wird eine Verbindung zu dieser spezifischen Position kreieren. +item.mffs\:cardIdentification.name=Identificationskarte +item.mffs\:cardIdentification.tooltip=Rechtsklicke mit dieser Karte, um sie biometrisch auf deinen Namen zu sperren. + +#Items +item.mffs\:remoteController.name=Fernbedienung +item.mffs\:fortron.name=Fortron +item.mffs\:focusMatrix.name=Fokusmatrix + +#Fluids +fluid.fortron=Fortron + +#Projection Modes +item.mffs\:modeCube.name=W\u00FCrfelmodus +item.mffs\:modeTube.name=R\u00F6hrenmodus +item.mffs\:modeSphere.name=Kugelmodus +item.mffs\:modePyramid.name=Pyramidenmodus +item.mffs\:modeCylinder.name=Zylindermodus +item.mffs\:modeCustom.name=Spezifischer Modus +item.mffs\:modeCustom.tooltip=Kreiere deinen eigenen Modus, indem du zwei Punkte rechtsklickst, um einen Bereich zu definieren. Shift-rechtsklicke, um den Bereich zu speichern. + +# Modules +## General Modules +item.mffs\:moduleScale.name=Skalierungsmodul +item.mffs\:moduleScale.tooltip=Das Skalierungsmodul erh\u00F6ht die Gr\u00F6\u00DFe oder Reichweite einer bestimmten Komponente. +item.mffs\:moduleTranslate.name=Translationsmodul +item.mffs\:moduleTranslate.tooltip=Das Translationsmodul setzt das Kraftfeld um, platziert es vom Ursprungsort entfernt. +item.mffs\:moduleRotate.name=Rotationsmodul +item.mffs\:moduleRotate.tooltip=Das Rotationsmodul rotiert das Kraftfeld mit einem bestimmten Winkel. + +item.mffs\:moduleCapacity.name=Kapazit\u00E4tsmodul +item.mffs\:moduleCapacity.tooltip=Erh\u00F6ht die Kapazit\u00E4t eines Ger\u00E4ts. +item.mffs\:moduleSpeed.name=Geschwindigkeitsmodul +item.mffs\:moduleSpeed.tooltip=Erh\u00F6ht die Geschwindigkeit eines Ger\u00E4ts. + +## Force Field Projector Modules +item.mffs\:moduleShock.name=Schockmodul +item.mffs\:moduleSponge.name=Schwammmodul +item.mffs\:moduleManipulator.name=Feldmanipulatormodul +item.mffs\:moduleFusion.name=Feldfusionsmodul +item.mffs\:moduleCamouflage.name=Tarnungsmodul +item.mffs\:moduleDisintegration.name=Disintegrationsmodul +item.mffs\:moduleGlow.name=Leuchtmodul +item.mffs\:moduleStabilize.name=Feldstabilisatormodul +item.mffs\:moduleStabilize.tooltip=Stabilisiert das projezierte Kraftfeld und kristallisiert das Feld zu soliden Bl\u00F6cken. Platziere eine Kiste mit Bl\u00F6cken neben dem Projektor, um das Feld zu stabilisieren. +item.mffs\:moduleCollection.name=Sammelmodul +item.mffs\:moduleCollection.tooltip=Das Sammelmodul erlaubt es, die vom Disintegrationsmodul fallen gelassenen Bl\u00F6cke zu sammeln. +item.mffs\:moduleInvert.name=Umkehrmodul +item.mffs\:moduleInvert.tooltip=Kehrt das Feld um, um negativen Raum statt positiven zu nutzen. +item.mffs\:moduleSilence.name=Stillemodul +item.mffs\:moduleSilence.tooltip=Macht das Kraftfeld lautlos und bewahrt es davor, T\u00F6ne zu erzeugen. + +## Interdiction Matrix Modules +item.mffs\:moduleAntiPersonnel.name=Anti-Spieler-Modul +item.mffs\:moduleAntiPersonnel.tooltip=Wird die Interdiktionsmatrix dazu bringen, alle Spieler zu t\u00F6ten. +item.mffs\:moduleAntiFriendly.name=Anti-Friedlich-Modul +item.mffs\:moduleAntiFriendly.tooltip=Wird die Interdiktionsmatrix dazu bringen, alle friedlichen Mobs zu t\u00F6ten. +item.mffs\:moduleAntiHostile.name=Anti-Feindlich-Modul +item.mffs\:moduleAntiHostile.tooltip=Wird die Interdiktionsmatrix dazu bringen, alle feindlichen Mobs zu t\u00F6ten. +item.mffs\:moduleWarn.name=Warnungsmodul +item.mffs\:moduleWarn.tooltip=Sendet dem Eindringling eine Warnung. +item.mffs\:moduleConfiscate.name=Konfiszierungsmodul +item.mffs\:moduleConfiscate.tooltip=Konfisziert die Gegenst\u00E4nde des Eindringlings. +item.mffs\:moduleBlockAccess.name=Blockzugriffsmodul +item.mffs\:moduleBlockAccess.tooltip=Hindert einen Eindringling am Rechtsklicken von Bl\u00F6cken. +item.mffs\:moduleBlockAlter.name=Block\u00E4nderungsmodul +item.mffs\:moduleBlockAlter.tooltip=Hindert einen Eindringling am Platzieren und Zerst\u00F6ren von Bl\u00F6cken. +item.mffs\:moduleAntiSpawn.name=Anti-Spawn-Modul +item.mffs\:moduleAntiSpawn.tooltip=Hindert Dinge am Spawnen in einer bestimmten Region. + +# Multitool +item.mffs\:itemMultiTool.name=Multi-Tool + +# GUI +gui.frequency.name=Frequenz +gui.frequency.tooltip=Maschinen mit der selben Frequenz werden Fortronenergie teilen. +gui.progress.name=Fortschitt +gui.fortron.name=Fortron +gui.fortron.tooltip=Fortron ist der Typ von Energie, der in MFFS-Maschinen genutzt wird. +gui.upgrade.name=Upgrade +gui.matrix.name=Matrix +gui.matrix.tooltip=Die Projektionsmatrix wird genutzt, um festzulegen, wie die Projektion kreiert werden soll. +gui.master.name=Master +gui.master.tooltip=Die Master-Karte wird den Spieler auf der Karte als Besitzer des Biometrischen Identifikators bezeichnen. + +# Capacitor +gui.linkedDevice.name=Verbundene Ger\u00E4te +gui.linkedDevice.tooltip=Die Anzahl der Ger\u00E4te, die mit dieser Maschine verbunden sind. +gui.range.name=Reichweite +gui.range.tooltip=Die Reichweite kann mit einem Skalierungsmodul erh\u00F6ht werden. +gui.transmissionRate.name=\u00DCbertragungsrate +gui.transmissionRate.tooltip=Die Rate, mit der dieser Speicher Fortronenergie \u00FCbertragen kann. + +## Transfer Modes +gui.transferModeEqualize.name=Angleichen +gui.transferModeEqualize.tooltip=Teile Fortronenergie mit Maschinen basierend auf dem Prozentsatz des Speichers der Maschine. +gui.transferModeDistribute.name=Aufteilen +gui.transferModeDistribute.tooltip=Teile Fortronenergie mit Maschinen basierend auf der gespeicherten Menge der Maschine. +gui.transferModeDrain.name=Leeren +gui.transferModeDrain.tooltip=Leert die Energie aus dem Speicher und teilt sie gleichm\u00E4\u00DFig mit verbundenen Maschinen. +gui.transferModeFill.name=F\u00FCllen +gui.transferModeFill.tooltip=F\u00FCllt die Energie des Speichers. Teilt \u00FCberlaufende Energie gleichm\u00E4\u00DFig auf. + +# Permissions +gui.rights.name=Rechte +gui.rights.tooltip=Weise hier der Karte links Rechte zu. +gui.warp.name=Warp +gui.warp.tooltip=Erlaubt es dem Spieler, das Kraftfeld zu durchqueren und zu \u00FCbergehen. +gui.blockPlaceAccess.name=Block\u00E4nderung +gui.blockPlaceAccess.tooltip=Erlaubt es dem Spieler, Bl\u00F6cke zu platzieren und zu zerst\u00F6ren. +gui.blockAccess.name=Blockzugriff +gui.blockAccess.tooltip=Erlaubt es dem Spieler, mit Bl\u00F6cken zu interagieren und ihre GUIs zu \u00F6ffnen. +gui.configure.name=Konfigurieren +gui.configure.tooltip=Erlaubt es dem Spieler, den Biometrischen Identifikator zu konfigurieren. +gui.bypassDefense.name=Verteidigung umgehen +gui.bypassDefense.tooltip=Erlaubt es dem Spieler, die Einschr\u00E4nkungen der Interdiktionsmatrix zu umgehen. +gui.bypassConfiscation.name=Konfiszierung umgehen +gui.bypassConfiscation.tooltip=Erlaubt es dem Spieler, die Konfiszierung der Interdiktionsmatrix zu Umgehen. +gui.remoteControl.name=Fernsteuerung +gui.remoteControl.tooltip=Erlaubt es dem Spieler, eine Fernbedienung in der defensiven Region zu nutzen. + +# Interdiction Matrix +gui.filterMode.name=Filtermodus +gui.filterMode.tooltip=Der Modus, in dem Gegenst\u00E4nde und Bl\u00F6cke gefiltert werden. +gui.warn.name=Warnung +gui.warn.tooltip=Die Reichweite, in der die Interdiktionsmatrix dem Spieler eine Warnung geben wird. +gui.action.name=Aktion +gui.action.tooltip=Die Reichweite, in der die Interdiktionsmatrix die angepassten Aktionen auf einen Spieler anwenden wird. diff --git a/src/main/resources/assets/mffs/lang/en_US.properties b/src/main/resources/assets/mffs/lang/en_US.properties new file mode 100644 index 0000000..6281e03 --- /dev/null +++ b/src/main/resources/assets/mffs/lang/en_US.properties @@ -0,0 +1,155 @@ +# Modular Force Field System Language Properties +# @author Calclavia, LordMZTE + +itemGroup.MFFS=Modular Force Field System + +# Death Messages +death.attack.areaDefense=%1$s disregarded warnings and was disintegrated. +death.attack.fieldShock=%1$s was disintegrated by a force field. + +# Blocks +tile.mffs\:fortronite.name=Fortronite +tile.mffs\:biometricIdentifier.name=Biometric Identifier +tile.mffs\:interdictionMatrix.name=Interdiction Matrix +tile.mffs\:fortronCapacitor.name=Fortron Capacitor +tile.mffs\:projector.name=Force Field Projector +tile.mffs\:coercionDeriver.name=Coercion Deriver +tile.mffs\:manipulator.name=Force Manipulator +tile.mffs\:forceField.name=Force Field + + +# Cards +item.mffs\:cardBlank.name=Blank Card +item.mffs\:cardInfinite.name=Infinite Power Card +item.mffs\:cardInfinite.tooltip=The infinite power card is a creative-only item that can be placed inside a capacitor for infinite energy. +item.mffs\:cardFrequency.name=Frequency Card +item.mffs\:cardFrequency.tooltip=The frequency card is used for ease of frequency transmission. Shift-right clicking the card will generate a random frequency. +item.mffs\:cardLink.name=Link Card +item.mffs\:cardLink.tooltip=Right clicking the link card on a block will create a link to that specific position. +item.mffs\:cardIdentification.name=Identification Card +item.mffs\:cardIdentification.tooltip=Right click on the ID card to biometrically lock it to your name. + +#Items +item.mffs\:remoteController.name=Remote Controller +item.mffs\:fortron.name=Fortron +item.mffs\:focusMatrix.name=Focus Matrix + +#Fluids +fluid.fortron=Fortron + +#Projection Modes +item.mffs\:modeCube.name=Cube Mode +item.mffs\:modeTube.name=Tube Mode +item.mffs\:modeSphere.name=Sphere Mode +item.mffs\:modePyramid.name=Pyramid Mode +item.mffs\:modeCylinder.name=Cylinder Mode +item.mffs\:modeCustom.name=Custom Mode +item.mffs\:modeCustom.tooltip=Create your own mode by right clicking two points to define an area. Shift right click to save the area. + +# Modules +## General Modules +item.mffs\:moduleScale.name=Scale Module +item.mffs\:moduleScale.tooltip=The scale module increases the scale of a certain component. +item.mffs\:moduleTranslate.name=Translation Module +item.mffs\:moduleTranslate.tooltip=The translation module translates the field, displacing it away from the origin. +item.mffs\:moduleRotate.name=Rotation Module +item.mffs\:moduleRotate.tooltip=The rotation module rotates a field with a specific angle. + +item.mffs\:moduleCapacity.name=Capacity Module +item.mffs\:moduleCapacity.tooltip=Increases the capacity of a device. +item.mffs\:moduleSpeed.name=Speed Module +item.mffs\:moduleSpeed.tooltip=Increases the speed of a device. + +## Force Field Projector Modules +item.mffs\:moduleShock.name=Shock Module +item.mffs\:moduleSponge.name=Sponge Module +item.mffs\:moduleManipulator.name=Dome Module +item.mffs\:moduleFusion.name=Field Fusion Module +item.mffs\:moduleCamouflage.name=Camouflage Module +item.mffs\:moduleDisintegration.name=Disintegration Module +item.mffs\:moduleGlow.name=Glow Module +item.mffs\:moduleStabilize.name=Field Stabilizer Module +item.mffs\:moduleStabilize.tooltip=Stabilizes the projected force field and crystallizes the field into solid blocks. Place a chest next the projector with blocks to stablize the field. +item.mffs\:moduleCollection.name=Collection Module +item.mffs\:moduleCollection.tooltip=Collection module allows you to collect dropped blocks from the disintegration module. +item.mffs\:moduleInvert.name=Invert Module +item.mffs\:moduleInvert.tooltip=Inverts the field to use negative space instead of the positive space. +item.mffs\:moduleSilence.name=Silence Module +item.mffs\:moduleSilence.tooltip=Silences the force field and prevents it from making sound. + +## Interdiction Matrix Modules +item.mffs\:moduleAntiPersonnel.name=Anti-Personnel Module +item.mffs\:moduleAntiPersonnel.tooltip=Will cause Interdiction Matrix to kill all players. +item.mffs\:moduleAntiFriendly.name=Anti-Friendly Module +item.mffs\:moduleAntiFriendly.tooltip=Will cause Interdiction Matrix to kill all friendly mobs. +item.mffs\:moduleAntiHostile.name=Anti-Hostile Module +item.mffs\:moduleAntiHostile.tooltip=Will cause Interdiction Matrix to kill all hostile mobs. +item.mffs\:moduleWarn.name=Warn Module +item.mffs\:moduleWarn.tooltip=Sends a warning to the intruder. +item.mffs\:moduleConfiscate.name=Confiscate Module +item.mffs\:moduleConfiscate.tooltip=Confiscates the intruder's items. +item.mffs\:moduleBlockAccess.name=Block Access Module +item.mffs\:moduleBlockAccess.tooltip=Prevents an intruder from right clicking on blocks. +item.mffs\:moduleBlockAlter.name=Block Alter Module +item.mffs\:moduleBlockAlter.tooltip=Prevents an intruder from placing or breaking blocks. +item.mffs\:moduleAntiSpawn.name=Anti-Spawn Module +item.mffs\:moduleAntiSpawn.tooltip=Prevents entities from spawning in a specific region. + +# Multitool +item.mffs\:itemMultiTool.name=Multi-Tool + +# GUI +gui.frequency.name=Frequency +gui.frequency.tooltip=Machines with the same frequency will share Fortron energy. +gui.progress.name=Progress +gui.fortron.name=Fortron +gui.fortron.tooltip=Fortron is the type of force energy used in MFFS machines. +gui.upgrade.name=Upgrade +gui.matrix.name=Matrix +gui.matrix.tooltip=The projection matrix is used to determine how the projection should be created. +gui.master.name=Master +gui.master.tooltip=The Master Card will denote the player in the card owner of the Biometric Identifier. + +# Capacitor +gui.linkedDevice.name=Linked Device +gui.linkedDevice.tooltip=The amount of devices linked to this machine. +gui.range.name=Range +gui.range.tooltip=The range can be upgraded with a range module. +gui.transmissionRate.name=Transmission Rate +gui.transmissionRate.tooltip=The rate in which this capacitor can transfer fortron energy. + +## Transfer Modes +gui.transferModeEqualize.name=Equalize +gui.transferModeEqualize.tooltip=Spread fortron energy with machines based on the machine's capacity percentage. +gui.transferModeDistribute.name=Distribute +gui.transferModeDistribute.tooltip=Spread fortron energy evenly based on the energy amount. +gui.transferModeDrain.name=Drain +gui.transferModeDrain.tooltip=Drains out the capacitor's energy and equalizes them to linked machines. +gui.transferModeFill.name=Fill +gui.transferModeFill.tooltip=Fills up the capacitor's energy. Equalizes the overflowing energy. + +# Permissions +gui.rights.name=Rights +gui.rights.tooltip=Assign rights to the card to your left here. +gui.warp.name=Warp +gui.warp.tooltip=Allow the player to go through and bypass force fields. +gui.blockPlaceAccess.name=Block Alter +gui.blockPlaceAccess.tooltip=Allow the player to place and break blocks. +gui.blockAccess.name=Block Access +gui.blockAccess.tooltip=Allow the player to interact and open GUIs in blocks. +gui.configure.name=Configure +gui.configure.tooltip=Allow the player to configure the Biometric Identifier. +gui.bypassDefense.name=Bypass Defense +gui.bypassDefense.tooltip=Allow the player to bypass Interdiction Matrix restrictions. +gui.bypassConfiscation.name=Bypass Confiscation +gui.bypassConfiscation.tooltip=Allow the player to bypass the Interdiction Matrix confiscation. +gui.remoteControl.name=Remote Control +gui.remoteControl.tooltip=Allow the player to use the remote control within defensive region. + +# Interdiction Matrix +gui.filterMode.name=Filter Mode +gui.filterMode.tooltip=The mode in which to filter out items and blocks. +gui.warn.name=Warning +gui.warn.tooltip=The range in which the Interdiction Matrix will give the player a warning. +gui.action.name=Action +gui.action.tooltip=The range in which the Interdiction Matrix will apply the modulated actions to the player. diff --git a/src/main/resources/assets/mffs/lang/zh_CN.properties b/src/main/resources/assets/mffs/lang/zh_CN.properties new file mode 100644 index 0000000..9725749 --- /dev/null +++ b/src/main/resources/assets/mffs/lang/zh_CN.properties @@ -0,0 +1,144 @@ +# Modular Force Field System Language Properties for zh_CN +# @author Fr0stbyteR + +itemGroup.MFFS=\u529B\u573A\u62A4\u76FE + +# Death Messages +death.attack.areaDefense=%1$s \u65E0\u89C6\u8B66\u544A \u76EE\u6807\u5DF2\u88AB\u6467\u6BC1 +death.attack.fieldShock=%1$s \u5DF2\u88AB\u7ACB\u573A\u62A4\u76FE\u6467\u6BC1 + +# Blocks +tile.mffs\:fortronite.name=\u529B\u573A\u7535\u5B50\u77FF +tile.mffs\:biometricIdentifier.name=\u751F\u7269\u8BC6\u522B\u5668 +tile.mffs\:interdictionMatrix.name=\u9632\u5FA1\u77E9\u9635 +tile.mffs\:fortronCapacitor.name=\u529b\u573a\u7535\u5b58\u7535\u7bb1 +tile.mffs\:projector.name=\u529B\u573A\u6620\u5C04\u5668 +tile.mffs\:coercionDeriver.name=\u529B\u573A\u7535\u5B50\u8F6C\u6362\u5668 +tile.mffs\:forceField.name=\u529B\u573A + +# Cards +item.mffs\:cardBlank.name=\u7A7A\u767D\u5361 +item.mffs\:cardInfinite.name=\u65E0\u9650\u80FD\u91CF\u5361 +item.mffs\:cardInfinite.tooltip=\u53EA\u80FD\u5728\u521B\u9020\u6A21\u5F0F\u4E0B\u5F97\u5230 \u653e\u5165\u5b58\u7535\u7bb1\u53ef\u4ee5\u5f97\u5230\u65e0\u9650\u80fd\u91cf +item.mffs\:cardFrequency.name=\u9891\u7387\u5361 +item.mffs\:cardFrequency.tooltip=\u7528\u4E8E\u8F6C\u6362\u9891\u7387 Shift+\u9F20\u6807\u5DE6\u952E\u751F\u6210\u968F\u673A\u9891\u7387 +item.mffs\:cardLink.name=\u94FE\u63A5\u5361 +item.mffs\:cardLink.tooltip=\u9F20\u6807\u53F3\u952E\u70B9\u51FB\u65B9\u5757\u4E0A\u7684\u94FE\u63A5\u5361\u4EE5\u94FE\u63A5\u5230\u6B64\u4F4D\u7F6E +item.mffs\:cardIdentification.name=ID\u5361 +item.mffs\:cardIdentification.tooltip=\u9F20\u6807\u53F3\u952E\u4EE5\u9501\u5B9A\u73A9\u5BB6\u8EAB\u4EFD + +#Items +item.mffs\:remoteController.name=\u9065\u63A7\u5668 +item.mffs\:fortron.name=\u529B\u573A\u7535\u5B50 +item.mffs\:focusMatrix.name=\u805A\u7126\u77E9\u9635 + +#Projection Modes +item.mffs\:modeCube.name=\u7ACB\u65B9\u4F53\u6A21\u5F0F +item.mffs\:modeTube.name=\u7BA1\u9053\u6A21\u5F0F +item.mffs\:modeSphere.name=\u7403\u72B6\u6A21\u5F0F +item.mffs\:modePyramid.name=\u91D1\u5B57\u5854\u6A21\u5F0F +item.mffs\:modeCylinder.name=\u5706\u67F1\u4F53\u6A21\u5F0F +item.mffs\:modeCustom.name=\u81EA\u5B9A\u4E49\u6A21\u5F0F +item.mffs\:modeCustom.tooltip=\u9F20\u6807\u53F3\u952E\u4EFB\u610F\u4E24\u70B9\u9009\u5B9A\u533A\u57DF Shift+\u9F20\u6807\u53F3\u952E\u70B9\u51FB\u6765\u4FDD\u5B58\u533A\u57DF + +# Modules +## General Modules +item.mffs\:moduleScale.name=\u62D3\u5C55\u6A21\u5757 +item.mffs\:moduleScale.tooltip=\u62D3\u5C55\u76EE\u6807\u7EC4\u4EF6\u7684\u89C4\u6A21 +item.mffs\:moduleTranslate.name=\u5E73\u79FB\u6A21\u5757 +item.mffs\:moduleTranslate.tooltip=\u5E73\u79FB\u4E00\u5757\u7ACB\u573A\u533A\u57DF +item.mffs\:moduleRotate.name=\u65CB\u8F6C\u6A21\u5757 +item.mffs\:moduleRotate.tooltip=\u5C06\u4E00\u5757\u533A\u57DF\u65CB\u8F6C\u6307\u5B9A\u89D2\u5EA6 + +item.mffs\:moduleCapacity.name=\u5BB9\u91CF\u6A21\u5757 +item.mffs\:moduleCapacity.tooltip=\u589E\u52A0\u8BBE\u5907\u5BB9\u91CF +item.mffs\:moduleSpeed.name=\u901F\u5EA6\u6A21\u5757 +item.mffs\:moduleSpeed.tooltip=\u52A0\u5FEB\u8BBE\u5907\u901F\u5EA6 + +## Force Field Projector Modules +item.mffs\:moduleShock.name=\u9707\u8361\u6A21\u5757 +item.mffs\:moduleSponge.name=\u6D41\u4F53\u6A21\u5757 +item.mffs\:moduleManipulator.name=\u529B\u573A\u64CD\u4F5C\u6A21\u5757 +item.mffs\:moduleFusion.name=\u529B\u573A\u878D\u5408\u6A21\u5757 +item.mffs\:moduleCamouflage.name=\u4F2A\u88C5\u6A21\u5757 +item.mffs\:moduleDisintegration.name=\u5206\u89E3\u6A21\u5757 +item.mffs\:moduleGlow.name=\u53D1\u5149\u6A21\u5757 +item.mffs\:moduleStabilize.name=\u529B\u573A\u56FA\u5316\u6A21\u5757 +item.mffs\:moduleStabilize.tooltip=\u5C06\u529B\u573A\u56FA\u5316 \u5728\u751F\u6210\u5668\u8FB9\u653E\u7F6E\u7BB1\u5B50\u6765\u63D0\u4F9B\u56FA\u5316\u7528\u7684\u65B9\u5757 + +## Interdiction Matrix Modules +item.mffs\:moduleAntiPersonnel.name=\u7981\u6B62\u73A9\u5BB6\u6A21\u5757 +item.mffs\:moduleAntiPersonnel.tooltip=\u4F7F\u9632\u5FA1\u77E9\u9635\u7981\u6B62\u73A9\u5BB6\u8FDB\u5165 +item.mffs\:moduleAntiFriendly.name=\u7981\u6B62\u52A8\u7269\u6A21\u5757 +item.mffs\:moduleAntiFriendly.tooltip=\u4F7F\u9632\u5FA1\u77E9\u9635\u7981\u6B62\u52A8\u7269\u8FDB\u5165 +item.mffs\:moduleAntiHostile.name=\u7981\u6B62\u602A\u7269\u6A21\u5757 +item.mffs\:moduleAntiHostile.tooltip=\u4F7F\u9632\u5FA1\u77E9\u9635\u7981\u6B62\u602A\u7269\u8FDB\u5165 +item.mffs\:moduleWarn.name=\u8B66\u544A\u6A21\u5757 +item.mffs\:moduleWarn.tooltip=\u5411\u5165\u4FB5\u8005\u53D1\u9001\u8B66\u544A +item.mffs\:moduleConfiscate.name=\u6536\u7F34\u6A21\u5757 +item.mffs\:moduleConfiscate.tooltip=\u6536\u7F34\u5165\u4FB5\u8005\u7684\u7269\u54C1 +item.mffs\:moduleBlockAccess.name=\u7981\u6B62\u4F7F\u7528\u6A21\u5757 +item.mffs\:moduleBlockAccess.tooltip=\u7981\u6B62\u5165\u4FB5\u8005\u4F7F\u7528\u65B9\u5757 +item.mffs\:moduleBlockAlter.name=\u7981\u6B62\u64CD\u4F5C\u6A21\u5757 +item.mffs\:moduleBlockAlter.tooltip=\u7981\u6B62\u5165\u4FB5\u8005\u653E\u7F6E\u6216\u7834\u574F\u65B9\u5757 +item.mffs\:moduleAntiSpawn.name=\u7981\u6B62\u751F\u6210\u6A21\u5757 +item.mffs\:moduleAntiSpawn.tooltip=\u7981\u6B62\u751F\u6210\u52A8\u7269/\u602A\u7269 + +# Multitool +item.mffs\:itemMultiTool.name=\u591A\u529F\u80FD\u5DE5\u5177 + +# GUI +gui.frequency.name=\u9891\u7387 +gui.frequency.tooltip=\u540C\u9891\u7387\u7684\u8BBE\u5907\u5C06\u5171\u7528\u529B\u573A\u7535\u5B50 +gui.progress.name=\u8FDB\u5EA6 +gui.fortron.name=\u529B\u573A\u7535\u5B50 +gui.fortron.tooltip=\u529B\u573A\u7535\u5B50\u662F\u7ACB\u573A\u62A4\u76FE\u4F7F\u7528\u7684\u80FD\u6E90 +gui.upgrade.name=\u5347\u7EA7 +gui.matrix.name=\u77E9\u9635 +gui.matrix.tooltip=\u6620\u5C04\u77E9\u9635\u80FD\u51B3\u5B9A\u529B\u573A\u7684\u751F\u6210\u65B9\u5F0F +gui.master.name=\u62E5\u6709\u8005 +gui.master.tooltip=\u62E5\u6709\u8005\u5361\u53EF\u4EE5\u8BB0\u5F55\u751F\u7269\u8BC6\u522B\u5668\u4E2D\u5361\u7247\u7684\u62E5\u6709\u8005 + +# Capacitor +gui.linkedDevice.name=\u8FDE\u63A5\u6570 +gui.linkedDevice.tooltip=\u8FDE\u63A5\u7684\u8BBE\u5907\u6570 +gui.range.name=\u8303\u56F4 +gui.range.tooltip=\u53EF\u4F7F\u7528\u8303\u56F4\u6A21\u5757\u5347\u7EA7 +gui.transmissionRate.name=\u4F20\u8F93\u5EF6\u8FDF +gui.transmissionRate.tooltip=\u5B58\u7535\u5668\u4F20\u8F93\u529B\u573A\u7535\u5B50\u7684\u5EF6\u8FDF + +## Transfer Modes +gui.transferModeEqualize.name=\u5E73\u8861 +gui.transferModeEqualize.tooltip=\u6839\u636E\u8BBE\u5907\u7684\u5BB9\u91CF\u767E\u5206\u6BD4\u4F20\u8F93\u529B\u573A\u7535\u5B50\u80FD\u91CF +gui.transferModeDistribute.name=\u5747\u4E00 +gui.transferModeDistribute.tooltip=\u5411\u6240\u6709\u8BBE\u5907\u4F20\u8F93\u76F8\u7B49\u80FD\u91CF +gui.transferModeDrain.name=\u5FEB\u901F +gui.transferModeDrain.tooltip=\u5FEB\u901F\u8F93\u51FA\u80FD\u91CF\u5E76\u5E73\u8861\u5206\u914D\u7ED9\u8BBE\u5907 +gui.transferModeFill.name=\u586B\u5145 +gui.transferModeFill.tooltip=\u5145\u6ee1\u5b58\u7535\u7bb1 \u518D\u8F93\u51FA\u591A\u4F59\u80FD\u91CF + +# Permissions +gui.rights.name=\u6743\u9650 +gui.rights.tooltip=\u5411\u5361\u7247\u5199\u5165\u6743\u9650 +gui.warp.name=\u5141\u8BB8 +gui.warp.tooltip=\u5141\u8BB8\u73A9\u5BB6\u7A7F\u8FC7\u529B\u573A +gui.blockPlaceAccess.name=\u65B9\u5757\u64CD\u4F5C +gui.blockPlaceAccess.tooltip=\u5141\u8BB8\u73A9\u5BB6\u9632\u6B62\u548C\u7834\u574F\u65B9\u5757 +gui.blockAccess.name=\u4F7F\u7528\u65B9\u5757 +gui.blockAccess.tooltip=\u5141\u8BB8\u73A9\u5BB6\u4F7F\u7528\u65B9\u5757 +gui.configure.name=\u8C03\u6574 +gui.configure.tooltip=\u5141\u8BB8\u73A9\u5BB6\u8BBE\u7F6E\u751F\u7269\u8BC6\u522B\u5668 +gui.bypassDefense.name=\u9632\u5FA1\u5FFD\u7565 +gui.bypassDefense.tooltip=\u751F\u7269\u9650\u5236\u5C06\u5FFD\u7565\u8BE5\u73A9\u5BB6 +gui.bypassConfiscation.name=\u6536\u7F34\u5FFD\u7565 +gui.bypassConfiscation.tooltip=\u6536\u7F34\u7CFB\u7EDF\u5C06\u5FFD\u7565\u8BE5\u73A9\u5BB6 +gui.remoteControl.name=\u9065\u63A7 +gui.remoteControl.tooltip=\u5141\u8BB8\u73A9\u5BB6\u5728\u529B\u573A\u5185\u9065\u63A7 + +# Interdiction Matrix +gui.filterMode.name=\u7B5B\u9009 +gui.filterMode.tooltip=\u7B5B\u9009\u51FA\u7269\u54C1\u548C\u65B9\u5757 +gui.warn.name=\u8B66\u544A +gui.warn.tooltip=\u7ED9\u73A9\u5BB6\u8B66\u544A +gui.action.name=\u884C\u52A8 +gui.action.tooltip=\u5C06\u5BF9\u73A9\u5BB6\u8FDB\u884C\u6240\u914D\u7F6E\u7684\u884C\u52A8 \ No newline at end of file diff --git a/src/main/resources/assets/mffs/sounds.json b/src/main/resources/assets/mffs/sounds.json new file mode 100644 index 0000000..adb629d --- /dev/null +++ b/src/main/resources/assets/mffs/sounds.json @@ -0,0 +1,52 @@ +{ + "field": { + "category": "master", + "sounds": [ + { + "name": "field1", + "stream": false + }, + { + "name": "field2", + "stream": false + }, + { + "name": "field3", + "stream": false + }, + { + "name": "field4", + "stream": false + }, + { + "name": "field5", + "stream": false + } + ] + }, + "fieldmove": { + "category": "master", + "sounds": [ + { + "name": "fieldmove1", + "stream": false + }, + { + "name": "fieldmove2", + "stream": false + }, + { + "name": "fieldmove3", + "stream": false + }, + { + "name": "fieldmove4", + "stream": false + }, + { + "name": "fieldmove5", + "stream": false + } + ] + } +} diff --git a/src/main/resources/assets/mffs/sounds/field1.ogg b/src/main/resources/assets/mffs/sounds/field1.ogg new file mode 100644 index 0000000..52a9720 Binary files /dev/null and b/src/main/resources/assets/mffs/sounds/field1.ogg differ diff --git a/src/main/resources/assets/mffs/sounds/field2.ogg b/src/main/resources/assets/mffs/sounds/field2.ogg new file mode 100644 index 0000000..75c83a5 Binary files /dev/null and b/src/main/resources/assets/mffs/sounds/field2.ogg differ diff --git a/src/main/resources/assets/mffs/sounds/field3.ogg b/src/main/resources/assets/mffs/sounds/field3.ogg new file mode 100644 index 0000000..8b99374 Binary files /dev/null and b/src/main/resources/assets/mffs/sounds/field3.ogg differ diff --git a/src/main/resources/assets/mffs/sounds/field4.ogg b/src/main/resources/assets/mffs/sounds/field4.ogg new file mode 100644 index 0000000..61d77d8 Binary files /dev/null and b/src/main/resources/assets/mffs/sounds/field4.ogg differ diff --git a/src/main/resources/assets/mffs/sounds/field5.ogg b/src/main/resources/assets/mffs/sounds/field5.ogg new file mode 100644 index 0000000..33221db Binary files /dev/null and b/src/main/resources/assets/mffs/sounds/field5.ogg differ diff --git a/src/main/resources/assets/mffs/sounds/fieldmove1.ogg b/src/main/resources/assets/mffs/sounds/fieldmove1.ogg new file mode 100644 index 0000000..2f35253 Binary files /dev/null and b/src/main/resources/assets/mffs/sounds/fieldmove1.ogg differ diff --git a/src/main/resources/assets/mffs/sounds/fieldmove2.ogg b/src/main/resources/assets/mffs/sounds/fieldmove2.ogg new file mode 100644 index 0000000..8428e51 Binary files /dev/null and b/src/main/resources/assets/mffs/sounds/fieldmove2.ogg differ diff --git a/src/main/resources/assets/mffs/sounds/fieldmove3.ogg b/src/main/resources/assets/mffs/sounds/fieldmove3.ogg new file mode 100644 index 0000000..7405d7b Binary files /dev/null and b/src/main/resources/assets/mffs/sounds/fieldmove3.ogg differ diff --git a/src/main/resources/assets/mffs/sounds/fieldmove4.ogg b/src/main/resources/assets/mffs/sounds/fieldmove4.ogg new file mode 100644 index 0000000..d108fa8 Binary files /dev/null and b/src/main/resources/assets/mffs/sounds/fieldmove4.ogg differ diff --git a/src/main/resources/assets/mffs/sounds/fieldmove5.ogg b/src/main/resources/assets/mffs/sounds/fieldmove5.ogg new file mode 100644 index 0000000..5a409eb Binary files /dev/null and b/src/main/resources/assets/mffs/sounds/fieldmove5.ogg differ diff --git a/src/main/resources/assets/mffs/textures/blocks/biometricIdentifier.png b/src/main/resources/assets/mffs/textures/blocks/biometricIdentifier.png new file mode 100644 index 0000000..d62dcbb Binary files /dev/null and b/src/main/resources/assets/mffs/textures/blocks/biometricIdentifier.png differ diff --git a/src/main/resources/assets/mffs/textures/blocks/biometricIdentifier_on.png b/src/main/resources/assets/mffs/textures/blocks/biometricIdentifier_on.png new file mode 100644 index 0000000..e3e465e Binary files /dev/null and b/src/main/resources/assets/mffs/textures/blocks/biometricIdentifier_on.png differ diff --git a/src/main/resources/assets/mffs/textures/blocks/biometricIdentifier_top.png b/src/main/resources/assets/mffs/textures/blocks/biometricIdentifier_top.png new file mode 100644 index 0000000..f73fe83 Binary files /dev/null and b/src/main/resources/assets/mffs/textures/blocks/biometricIdentifier_top.png differ diff --git a/src/main/resources/assets/mffs/textures/blocks/biometricIdentifier_top_on.png b/src/main/resources/assets/mffs/textures/blocks/biometricIdentifier_top_on.png new file mode 100644 index 0000000..a0bde8e Binary files /dev/null and b/src/main/resources/assets/mffs/textures/blocks/biometricIdentifier_top_on.png differ diff --git a/src/main/resources/assets/mffs/textures/blocks/forceField.png b/src/main/resources/assets/mffs/textures/blocks/forceField.png new file mode 100644 index 0000000..8749ec9 Binary files /dev/null and b/src/main/resources/assets/mffs/textures/blocks/forceField.png differ diff --git a/src/main/resources/assets/mffs/textures/blocks/forceField.png.mcmeta b/src/main/resources/assets/mffs/textures/blocks/forceField.png.mcmeta new file mode 100644 index 0000000..097faab --- /dev/null +++ b/src/main/resources/assets/mffs/textures/blocks/forceField.png.mcmeta @@ -0,0 +1,33 @@ +{ + "animation": { + "width": 1, + "height": 24, + "frametime": 6, + "frames": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12, + 13, + 14, + 15, + 16, + 17, + 18, + 19, + 20, + 21, + 22, + 23 + ] + } +} diff --git a/src/main/resources/assets/mffs/textures/blocks/fortron.png b/src/main/resources/assets/mffs/textures/blocks/fortron.png new file mode 100644 index 0000000..184f7fa Binary files /dev/null and b/src/main/resources/assets/mffs/textures/blocks/fortron.png differ diff --git a/src/main/resources/assets/mffs/textures/blocks/interdictionMatrix.png b/src/main/resources/assets/mffs/textures/blocks/interdictionMatrix.png new file mode 100644 index 0000000..588c53c Binary files /dev/null and b/src/main/resources/assets/mffs/textures/blocks/interdictionMatrix.png differ diff --git a/src/main/resources/assets/mffs/textures/blocks/interdictionMatrix_on.png b/src/main/resources/assets/mffs/textures/blocks/interdictionMatrix_on.png new file mode 100644 index 0000000..cb6efea Binary files /dev/null and b/src/main/resources/assets/mffs/textures/blocks/interdictionMatrix_on.png differ diff --git a/src/main/resources/assets/mffs/textures/blocks/interdictionMatrix_top.png b/src/main/resources/assets/mffs/textures/blocks/interdictionMatrix_top.png new file mode 100644 index 0000000..b760b29 Binary files /dev/null and b/src/main/resources/assets/mffs/textures/blocks/interdictionMatrix_top.png differ diff --git a/src/main/resources/assets/mffs/textures/blocks/interdictionMatrix_top_on.png b/src/main/resources/assets/mffs/textures/blocks/interdictionMatrix_top_on.png new file mode 100644 index 0000000..e8ef1ed Binary files /dev/null and b/src/main/resources/assets/mffs/textures/blocks/interdictionMatrix_top_on.png differ diff --git a/src/main/resources/assets/mffs/textures/blocks/machine.png b/src/main/resources/assets/mffs/textures/blocks/machine.png new file mode 100644 index 0000000..7a7eee7 Binary files /dev/null and b/src/main/resources/assets/mffs/textures/blocks/machine.png differ diff --git a/src/main/resources/assets/mffs/textures/gui/gui_base.png b/src/main/resources/assets/mffs/textures/gui/gui_base.png new file mode 100644 index 0000000..5f91f63 Binary files /dev/null and b/src/main/resources/assets/mffs/textures/gui/gui_base.png differ diff --git a/src/main/resources/assets/mffs/textures/gui/gui_button.png b/src/main/resources/assets/mffs/textures/gui/gui_button.png new file mode 100644 index 0000000..5748dd2 Binary files /dev/null and b/src/main/resources/assets/mffs/textures/gui/gui_button.png differ diff --git a/src/main/resources/assets/mffs/textures/gui/gui_components.png b/src/main/resources/assets/mffs/textures/gui/gui_components.png new file mode 100644 index 0000000..303f293 Binary files /dev/null and b/src/main/resources/assets/mffs/textures/gui/gui_components.png differ diff --git a/src/main/resources/assets/mffs/textures/items/cardBlank.png b/src/main/resources/assets/mffs/textures/items/cardBlank.png new file mode 100644 index 0000000..ed17d9d Binary files /dev/null and b/src/main/resources/assets/mffs/textures/items/cardBlank.png differ diff --git a/src/main/resources/assets/mffs/textures/items/cardFrequency.png b/src/main/resources/assets/mffs/textures/items/cardFrequency.png new file mode 100644 index 0000000..b6e86ed Binary files /dev/null and b/src/main/resources/assets/mffs/textures/items/cardFrequency.png differ diff --git a/src/main/resources/assets/mffs/textures/items/cardIdentification.png b/src/main/resources/assets/mffs/textures/items/cardIdentification.png new file mode 100644 index 0000000..9506919 Binary files /dev/null and b/src/main/resources/assets/mffs/textures/items/cardIdentification.png differ diff --git a/src/main/resources/assets/mffs/textures/items/cardInfinite.png b/src/main/resources/assets/mffs/textures/items/cardInfinite.png new file mode 100644 index 0000000..b083a9d Binary files /dev/null and b/src/main/resources/assets/mffs/textures/items/cardInfinite.png differ diff --git a/src/main/resources/assets/mffs/textures/items/cardLink.png b/src/main/resources/assets/mffs/textures/items/cardLink.png new file mode 100644 index 0000000..b8edaa2 Binary files /dev/null and b/src/main/resources/assets/mffs/textures/items/cardLink.png differ diff --git a/src/main/resources/assets/mffs/textures/items/focusMatrix.png b/src/main/resources/assets/mffs/textures/items/focusMatrix.png new file mode 100644 index 0000000..0f54b35 Binary files /dev/null and b/src/main/resources/assets/mffs/textures/items/focusMatrix.png differ diff --git a/src/main/resources/assets/mffs/textures/items/fortron.png b/src/main/resources/assets/mffs/textures/items/fortron.png new file mode 100644 index 0000000..184f7fa Binary files /dev/null and b/src/main/resources/assets/mffs/textures/items/fortron.png differ diff --git a/src/main/resources/assets/mffs/textures/items/modeCube.png b/src/main/resources/assets/mffs/textures/items/modeCube.png new file mode 100644 index 0000000..ef34ee9 Binary files /dev/null and b/src/main/resources/assets/mffs/textures/items/modeCube.png differ diff --git a/src/main/resources/assets/mffs/textures/items/modeCustom.png b/src/main/resources/assets/mffs/textures/items/modeCustom.png new file mode 100644 index 0000000..3987cd0 Binary files /dev/null and b/src/main/resources/assets/mffs/textures/items/modeCustom.png differ diff --git a/src/main/resources/assets/mffs/textures/items/modeCylinder.png b/src/main/resources/assets/mffs/textures/items/modeCylinder.png new file mode 100644 index 0000000..56114f1 Binary files /dev/null and b/src/main/resources/assets/mffs/textures/items/modeCylinder.png differ diff --git a/src/main/resources/assets/mffs/textures/items/modePyramid.png b/src/main/resources/assets/mffs/textures/items/modePyramid.png new file mode 100644 index 0000000..03b2259 Binary files /dev/null and b/src/main/resources/assets/mffs/textures/items/modePyramid.png differ diff --git a/src/main/resources/assets/mffs/textures/items/modeSphere.png b/src/main/resources/assets/mffs/textures/items/modeSphere.png new file mode 100644 index 0000000..c4cd5dc Binary files /dev/null and b/src/main/resources/assets/mffs/textures/items/modeSphere.png differ diff --git a/src/main/resources/assets/mffs/textures/items/modeTube.png b/src/main/resources/assets/mffs/textures/items/modeTube.png new file mode 100644 index 0000000..55db5e7 Binary files /dev/null and b/src/main/resources/assets/mffs/textures/items/modeTube.png differ diff --git a/src/main/resources/assets/mffs/textures/items/moduleAntiFriendly.png b/src/main/resources/assets/mffs/textures/items/moduleAntiFriendly.png new file mode 100644 index 0000000..586e052 Binary files /dev/null and b/src/main/resources/assets/mffs/textures/items/moduleAntiFriendly.png differ diff --git a/src/main/resources/assets/mffs/textures/items/moduleAntiHostile.png b/src/main/resources/assets/mffs/textures/items/moduleAntiHostile.png new file mode 100644 index 0000000..d6cc305 Binary files /dev/null and b/src/main/resources/assets/mffs/textures/items/moduleAntiHostile.png differ diff --git a/src/main/resources/assets/mffs/textures/items/moduleAntiPersonnel.png b/src/main/resources/assets/mffs/textures/items/moduleAntiPersonnel.png new file mode 100644 index 0000000..69211cb Binary files /dev/null and b/src/main/resources/assets/mffs/textures/items/moduleAntiPersonnel.png differ diff --git a/src/main/resources/assets/mffs/textures/items/moduleAntiSpawn.png b/src/main/resources/assets/mffs/textures/items/moduleAntiSpawn.png new file mode 100644 index 0000000..92b47e6 Binary files /dev/null and b/src/main/resources/assets/mffs/textures/items/moduleAntiSpawn.png differ diff --git a/src/main/resources/assets/mffs/textures/items/moduleBlockAccess.png b/src/main/resources/assets/mffs/textures/items/moduleBlockAccess.png new file mode 100644 index 0000000..346e875 Binary files /dev/null and b/src/main/resources/assets/mffs/textures/items/moduleBlockAccess.png differ diff --git a/src/main/resources/assets/mffs/textures/items/moduleBlockAlter.png b/src/main/resources/assets/mffs/textures/items/moduleBlockAlter.png new file mode 100644 index 0000000..d5cb19f Binary files /dev/null and b/src/main/resources/assets/mffs/textures/items/moduleBlockAlter.png differ diff --git a/src/main/resources/assets/mffs/textures/items/moduleCamouflage.png b/src/main/resources/assets/mffs/textures/items/moduleCamouflage.png new file mode 100644 index 0000000..cee45ae Binary files /dev/null and b/src/main/resources/assets/mffs/textures/items/moduleCamouflage.png differ diff --git a/src/main/resources/assets/mffs/textures/items/moduleCapacity.png b/src/main/resources/assets/mffs/textures/items/moduleCapacity.png new file mode 100644 index 0000000..fe4df5b Binary files /dev/null and b/src/main/resources/assets/mffs/textures/items/moduleCapacity.png differ diff --git a/src/main/resources/assets/mffs/textures/items/moduleCollection.png b/src/main/resources/assets/mffs/textures/items/moduleCollection.png new file mode 100644 index 0000000..09166ad Binary files /dev/null and b/src/main/resources/assets/mffs/textures/items/moduleCollection.png differ diff --git a/src/main/resources/assets/mffs/textures/items/moduleConfiscate.png b/src/main/resources/assets/mffs/textures/items/moduleConfiscate.png new file mode 100644 index 0000000..5f7f059 Binary files /dev/null and b/src/main/resources/assets/mffs/textures/items/moduleConfiscate.png differ diff --git a/src/main/resources/assets/mffs/textures/items/moduleDisintegration.png b/src/main/resources/assets/mffs/textures/items/moduleDisintegration.png new file mode 100644 index 0000000..9d5c499 Binary files /dev/null and b/src/main/resources/assets/mffs/textures/items/moduleDisintegration.png differ diff --git a/src/main/resources/assets/mffs/textures/items/moduleFusion.png b/src/main/resources/assets/mffs/textures/items/moduleFusion.png new file mode 100644 index 0000000..37caaf4 Binary files /dev/null and b/src/main/resources/assets/mffs/textures/items/moduleFusion.png differ diff --git a/src/main/resources/assets/mffs/textures/items/moduleGlow.png b/src/main/resources/assets/mffs/textures/items/moduleGlow.png new file mode 100644 index 0000000..0895fbd Binary files /dev/null and b/src/main/resources/assets/mffs/textures/items/moduleGlow.png differ diff --git a/src/main/resources/assets/mffs/textures/items/moduleInvert.png b/src/main/resources/assets/mffs/textures/items/moduleInvert.png new file mode 100644 index 0000000..0326547 Binary files /dev/null and b/src/main/resources/assets/mffs/textures/items/moduleInvert.png differ diff --git a/src/main/resources/assets/mffs/textures/items/moduleManipulator.png b/src/main/resources/assets/mffs/textures/items/moduleManipulator.png new file mode 100644 index 0000000..3b603e4 Binary files /dev/null and b/src/main/resources/assets/mffs/textures/items/moduleManipulator.png differ diff --git a/src/main/resources/assets/mffs/textures/items/moduleRotate.png b/src/main/resources/assets/mffs/textures/items/moduleRotate.png new file mode 100644 index 0000000..1cbccd1 Binary files /dev/null and b/src/main/resources/assets/mffs/textures/items/moduleRotate.png differ diff --git a/src/main/resources/assets/mffs/textures/items/moduleScale.png b/src/main/resources/assets/mffs/textures/items/moduleScale.png new file mode 100644 index 0000000..fe60e48 Binary files /dev/null and b/src/main/resources/assets/mffs/textures/items/moduleScale.png differ diff --git a/src/main/resources/assets/mffs/textures/items/moduleShock.png b/src/main/resources/assets/mffs/textures/items/moduleShock.png new file mode 100644 index 0000000..c41a466 Binary files /dev/null and b/src/main/resources/assets/mffs/textures/items/moduleShock.png differ diff --git a/src/main/resources/assets/mffs/textures/items/moduleSilence.png b/src/main/resources/assets/mffs/textures/items/moduleSilence.png new file mode 100644 index 0000000..7ca9423 Binary files /dev/null and b/src/main/resources/assets/mffs/textures/items/moduleSilence.png differ diff --git a/src/main/resources/assets/mffs/textures/items/moduleSpeed.png b/src/main/resources/assets/mffs/textures/items/moduleSpeed.png new file mode 100644 index 0000000..9260640 Binary files /dev/null and b/src/main/resources/assets/mffs/textures/items/moduleSpeed.png differ diff --git a/src/main/resources/assets/mffs/textures/items/moduleSponge.png b/src/main/resources/assets/mffs/textures/items/moduleSponge.png new file mode 100644 index 0000000..634a04d Binary files /dev/null and b/src/main/resources/assets/mffs/textures/items/moduleSponge.png differ diff --git a/src/main/resources/assets/mffs/textures/items/moduleStabilize.png b/src/main/resources/assets/mffs/textures/items/moduleStabilize.png new file mode 100644 index 0000000..adac387 Binary files /dev/null and b/src/main/resources/assets/mffs/textures/items/moduleStabilize.png differ diff --git a/src/main/resources/assets/mffs/textures/items/moduleTranslate.png b/src/main/resources/assets/mffs/textures/items/moduleTranslate.png new file mode 100644 index 0000000..8c38c67 Binary files /dev/null and b/src/main/resources/assets/mffs/textures/items/moduleTranslate.png differ diff --git a/src/main/resources/assets/mffs/textures/items/moduleWarn.png b/src/main/resources/assets/mffs/textures/items/moduleWarn.png new file mode 100644 index 0000000..ecd8f4d Binary files /dev/null and b/src/main/resources/assets/mffs/textures/items/moduleWarn.png differ diff --git a/src/main/resources/assets/mffs/textures/items/remoteController.png b/src/main/resources/assets/mffs/textures/items/remoteController.png new file mode 100644 index 0000000..fc132cc Binary files /dev/null and b/src/main/resources/assets/mffs/textures/items/remoteController.png differ diff --git a/src/main/resources/assets/mffs/textures/models/coercionDeriver_off.png b/src/main/resources/assets/mffs/textures/models/coercionDeriver_off.png new file mode 100644 index 0000000..df924b7 Binary files /dev/null and b/src/main/resources/assets/mffs/textures/models/coercionDeriver_off.png differ diff --git a/src/main/resources/assets/mffs/textures/models/coercionDeriver_on.png b/src/main/resources/assets/mffs/textures/models/coercionDeriver_on.png new file mode 100644 index 0000000..9d03c9a Binary files /dev/null and b/src/main/resources/assets/mffs/textures/models/coercionDeriver_on.png differ diff --git a/src/main/resources/assets/mffs/textures/models/forceManipulator_off.png b/src/main/resources/assets/mffs/textures/models/forceManipulator_off.png new file mode 100644 index 0000000..d8b3990 Binary files /dev/null and b/src/main/resources/assets/mffs/textures/models/forceManipulator_off.png differ diff --git a/src/main/resources/assets/mffs/textures/models/forceManipulator_on.png b/src/main/resources/assets/mffs/textures/models/forceManipulator_on.png new file mode 100644 index 0000000..cfda3ba Binary files /dev/null and b/src/main/resources/assets/mffs/textures/models/forceManipulator_on.png differ diff --git a/src/main/resources/assets/mffs/textures/models/force_cube.png b/src/main/resources/assets/mffs/textures/models/force_cube.png new file mode 100644 index 0000000..7791dc8 Binary files /dev/null and b/src/main/resources/assets/mffs/textures/models/force_cube.png differ diff --git a/src/main/resources/assets/mffs/textures/models/fortronCapacitor_off.png b/src/main/resources/assets/mffs/textures/models/fortronCapacitor_off.png new file mode 100644 index 0000000..41fb566 Binary files /dev/null and b/src/main/resources/assets/mffs/textures/models/fortronCapacitor_off.png differ diff --git a/src/main/resources/assets/mffs/textures/models/fortronCapacitor_on.png b/src/main/resources/assets/mffs/textures/models/fortronCapacitor_on.png new file mode 100644 index 0000000..f0df739 Binary files /dev/null and b/src/main/resources/assets/mffs/textures/models/fortronCapacitor_on.png differ diff --git a/src/main/resources/assets/mffs/textures/models/projector_off.png b/src/main/resources/assets/mffs/textures/models/projector_off.png new file mode 100644 index 0000000..99d340f Binary files /dev/null and b/src/main/resources/assets/mffs/textures/models/projector_off.png differ diff --git a/src/main/resources/assets/mffs/textures/models/projector_on.png b/src/main/resources/assets/mffs/textures/models/projector_on.png new file mode 100644 index 0000000..2b2ff68 Binary files /dev/null and b/src/main/resources/assets/mffs/textures/models/projector_on.png differ diff --git a/src/main/resources/mffs_at.cfg b/src/main/resources/mffs_at.cfg new file mode 100644 index 0000000..fc27bfa --- /dev/null +++ b/src/main/resources/mffs_at.cfg @@ -0,0 +1,2 @@ +public net.minecraft.world.chunk.Chunk func_76615_h(III)V # relightBlock +public net.minecraft.world.chunk.Chunk func_76595_e(II)V # propagateSkylightOcclusion