aboutsummaryrefslogtreecommitdiff
path: root/src/Java/gtPlusPlus/core/tileentities
diff options
context:
space:
mode:
authorAlkalus <3060479+draknyte1@users.noreply.github.com>2018-10-22 18:08:13 +0100
committerAlkalus <3060479+draknyte1@users.noreply.github.com>2018-10-22 18:08:13 +0100
commit78eb969baa21cba8738976c0e480d938bbb57e85 (patch)
tree8c0103e5c57fda44255967c394563790bf56eb91 /src/Java/gtPlusPlus/core/tileentities
parenta4d1dde84d4aa78783d36a7348a436ea96c3166b (diff)
downloadGT5-Unofficial-78eb969baa21cba8738976c0e480d938bbb57e85.tar.gz
GT5-Unofficial-78eb969baa21cba8738976c0e480d938bbb57e85.tar.bz2
GT5-Unofficial-78eb969baa21cba8738976c0e480d938bbb57e85.zip
$ Finished Circuit Programmer.
$ Fixed Dev Cape in Dev. % Adjusted some Tech Textures mildly.
Diffstat (limited to 'src/Java/gtPlusPlus/core/tileentities')
-rw-r--r--src/Java/gtPlusPlus/core/tileentities/general/TileEntityCircuitProgrammer.java325
1 files changed, 108 insertions, 217 deletions
diff --git a/src/Java/gtPlusPlus/core/tileentities/general/TileEntityCircuitProgrammer.java b/src/Java/gtPlusPlus/core/tileentities/general/TileEntityCircuitProgrammer.java
index 101b2a2c22..0cda40c616 100644
--- a/src/Java/gtPlusPlus/core/tileentities/general/TileEntityCircuitProgrammer.java
+++ b/src/Java/gtPlusPlus/core/tileentities/general/TileEntityCircuitProgrammer.java
@@ -1,42 +1,30 @@
package gtPlusPlus.core.tileentities.general;
-import java.util.Random;
-
-import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
-import net.minecraft.init.Blocks;
-import net.minecraft.init.Items;
import net.minecraft.inventory.ISidedInventory;
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.tileentity.TileEntity;
-
-import gregtech.api.util.GT_Utility;
-
-import gtPlusPlus.api.objects.Logger;
-import gtPlusPlus.core.block.ModBlocks;
+import gtPlusPlus.api.objects.data.AutoMap;
import gtPlusPlus.core.inventories.InventoryCircuitProgrammer;
-import gtPlusPlus.core.lib.LoadedMods;
-import gtPlusPlus.core.util.math.MathUtils;
-import gtPlusPlus.core.util.minecraft.ItemUtils;
-import net.minecraftforge.common.FishingHooks;
+import gtPlusPlus.core.recipe.common.CI;
+import gtPlusPlus.core.util.minecraft.PlayerUtils;
public class TileEntityCircuitProgrammer extends TileEntity implements ISidedInventory {
private int tickCount = 0;
- private boolean isInWater = false;
private final InventoryCircuitProgrammer inventoryContents;
private String customName;
- private int locationX;
- private int locationY;
- private int locationZ;
- private int waterSides = 0;
- private int baseTickRate = 600 * 5;
+ public int locationX;
+ public int locationY;
+ public int locationZ;
+ private int aCurrentMode = 0;
public TileEntityCircuitProgrammer() {
- this.inventoryContents = new InventoryCircuitProgrammer();// number of slots -
- // without product
- // slot
+ this.inventoryContents = new InventoryCircuitProgrammer();
this.setTileLocation();
}
@@ -52,44 +40,16 @@ public class TileEntityCircuitProgrammer extends TileEntity implements ISidedInv
return false;
}
- public final boolean isSurroundedByWater() {
- this.setTileLocation();
- final Block[] surroundingBlocks = new Block[6];
- if (this.hasWorldObj()) {
- if (!this.getWorldObj().isRemote) {
- surroundingBlocks[0] = this.worldObj.getBlock(this.locationX, this.locationY + 1, this.locationZ); // Above
- surroundingBlocks[1] = this.worldObj.getBlock(this.locationX, this.locationY - 1, this.locationZ); // Below
- surroundingBlocks[2] = this.worldObj.getBlock(this.locationX + 1, this.locationY, this.locationZ);
- surroundingBlocks[3] = this.worldObj.getBlock(this.locationX - 1, this.locationY, this.locationZ);
- surroundingBlocks[4] = this.worldObj.getBlock(this.locationX, this.locationY, this.locationZ + 1);
- surroundingBlocks[5] = this.worldObj.getBlock(this.locationX, this.locationY, this.locationZ - 1);
- int waterCount = 0;
- int trapCount = 0;
- for (final Block checkBlock : surroundingBlocks) {
- if ((checkBlock == Blocks.water) || (checkBlock == Blocks.flowing_water)
- || checkBlock.getUnlocalizedName().toLowerCase().contains("water")
- || (checkBlock == ModBlocks.blockCircuitProgrammer)) {
- if (checkBlock != ModBlocks.blockCircuitProgrammer) {
- waterCount++;
- }
- else {
- waterCount++;
- trapCount++;
- }
- }
- }
- if ((waterCount >= 2) && (trapCount <= 4)) {
- this.waterSides = waterCount;
- return true;
- }
- else if ((waterCount >= 2) && (trapCount > 4)) {
- Logger.WARNING("Too many fish traps surrounding this one.");
- Logger.WARNING("Not adding Loot to the fishtrap at x[" + this.locationX + "] y[" + this.locationY
- + "] z[" + this.locationZ + "] (Ticking for loot every " + this.baseTickRate + " ticks)");
- }
+ //Rename to hasCircuitToConfigure
+ public final boolean hasCircuitToConfigure() {
+ for (ItemStack i : this.getInventory().getInventory()) {
+ if (i == null) {
+ continue;
}
- }
- // Utils.LOG_WARNING("Error finding water");
+ else {
+ return true;
+ }
+ }
return false;
}
@@ -97,165 +57,79 @@ public class TileEntityCircuitProgrammer extends TileEntity implements ISidedInv
return this.inventoryContents;
}
- public boolean tryAddLoot() {
- if (this.getInventory().getInventory() != null) {
- int checkingSlot = 0;
- final ItemStack loot = this.generateLootForCircuitProgrammer().copy();
- try {
- //Utils.LOG_WARNING("Trying to add "+loot.getDisplayName()+" | "+loot.getItemDamage());
- for (final ItemStack contents : this.getInventory().getInventory()) {
-
-
- if (GT_Utility.areStacksEqual(loot, contents)){
- if (contents.stackSize < contents.getMaxStackSize()) {
- //Utils.LOG_WARNING("3-Trying to add one more "+loot.getDisplayName()+"meta: "+loot.getItemDamage()+" to an existing stack of "+contents.getDisplayName()+" with a size of "+contents.stackSize);
- contents.stackSize++;
- this.markDirty();
- return true;
+ public boolean addOutput() {
+ ItemStack[] aInputs = this.getInventory().getInventory().clone();
+ //Check if there is output in slot.
+ Boolean hasOutput = false;
+ if (aInputs[25] != null) {
+ hasOutput = true;
+ }
+ AutoMap<Integer> aValidSlots = new AutoMap<Integer>();
+ int aSlotCount = 0;
+ for (ItemStack i : aInputs) {
+ if (i != null) {
+ aValidSlots.put(aSlotCount);
+ }
+ aSlotCount++;
+ }
+ for (int e : aValidSlots) {
+ boolean doAdd = false;
+ ItemStack g = this.getStackInSlot(e);
+ int aSize = 0;
+ ItemStack aInputStack = null;
+ if (g != null) {
+ if (!hasOutput) {
+ aSize = g.stackSize;
+ doAdd = true;
+ }
+ else {
+ ItemStack f = this.getStackInSlot(25);
+ if (f != null) {
+ if (f.getItemDamage() == e) {
+ aSize = f.stackSize + g.stackSize;
+ if (aSize > 64) {
+ aInputStack = g.copy();
+ aInputStack.stackSize = (aSize-64);
+ }
+ doAdd = true;
}
}
- checkingSlot++;
- }
- checkingSlot = 0;
- for (final ItemStack contents : this.getInventory().getInventory()) {
- if (contents == null) {
- //Utils.LOG_WARNING("Adding Item To Empty Slot. "+(checkingSlot+1));
- this.getInventory().setInventorySlotContents(checkingSlot, loot);
- this.markDirty();
+ else {
+ doAdd = true;
+ aSize = g.stackSize;
+ }
+ }
+ if (doAdd) {
+ ItemStack aOutput = CI.getNumberedCircuit(e);
+ aOutput.stackSize = aSize;
+ if (aOutput != null) {
+ this.setInventorySlotContents(e, aInputStack);
+ this.setInventorySlotContents(25, aOutput);
return true;
}
- checkingSlot++;
}
}
- catch (final NullPointerException n) {
- }
- }
- this.markDirty();
+ continue;
+ }
return false;
}
- private ItemStack generateLootForCircuitProgrammer() {
- final int lootWeight = MathUtils.randInt(0, 100);
- ItemStack loot;
- if (lootWeight <= 5) {
- loot = ItemUtils.getSimpleStack(Items.slime_ball);
- }
- else if (lootWeight <= 10) {
- loot = ItemUtils.getSimpleStack(Items.bone);
- }
- else if (lootWeight <= 15) {
- loot = ItemUtils.getSimpleStack(Blocks.sand);
- }
- else if (lootWeight <= 20) {
- loot = ItemUtils.simpleMetaStack(Items.dye, 0, 1);
- }
- // Junk Loot
- else if (lootWeight <= 23) {
- if (LoadedMods.PamsHarvestcraft) {
- loot = ItemUtils.getItemStackOfAmountFromOreDictNoBroken(seaweed, 1);
- }
- else {
- loot = ItemUtils.getSimpleStack(Blocks.dirt);
- }
- }
- // Pam Fish
- else if (lootWeight <= 99) {
- final Random xstr = new Random();
- loot = FishingHooks.getRandomFishable(xstr, 100);
- }
-
- else if (lootWeight == 100){
- final int rareLoot = MathUtils.randInt(1, 10);
- if (rareLoot <= 4) {
- loot = ItemUtils.getItemStackOfAmountFromOreDictNoBroken("nuggetIron", 1);
- if (loot == null){
- loot = ItemUtils.getItemStackOfAmountFromOreDictNoBroken("ingotIron", 1);
- }
- }
- else if (rareLoot <= 7) {
- loot = ItemUtils.getItemStackOfAmountFromOreDictNoBroken("nuggetGold", 1);
- if (loot == null){
- loot = ItemUtils.getItemStackOfAmountFromOreDictNoBroken("ingotGold", 1);
- }
- }
- else if (rareLoot <= 9){
- loot = ItemUtils.getSimpleStack(Items.emerald);
- }
- else {
- loot = ItemUtils.getSimpleStack(Items.diamond);
- }
- }
- else {
- loot = ItemUtils.getSimpleStack(Blocks.diamond_ore);
- }
- loot.stackSize=1;
- Logger.WARNING("Adding x"+loot.stackSize+" "+loot.getDisplayName()+".");
- return loot;
- }
-
@Override
public void updateEntity() {
try{
if (!this.worldObj.isRemote) {
- this.tickCount++;
- // Utils.LOG_WARNING("Ticking "+this.tickCount);
- // Check if the Tile is within water once per second.
- if ((this.tickCount % 20) == 0) {
- this.isInWater = this.isSurroundedByWater();
- }
- else {
-
- }
-
- if (this.isInWater) {
- this.calculateTickrate();
- }
-
- // Try add some loot once every 30 seconds.
- if ((this.tickCount % this.baseTickRate) == 0) {
- if (this.isInWater) {
- // Add loot
- // Utils.LOG_WARNING("Adding Loot to the fishtrap at
- // x["+this.locationX+"] y["+this.locationY+"]
- // z["+this.locationZ+"] (Ticking for loot every
- // "+this.baseTickRate+" ticks)");
- this.tryAddLoot();
+ if (tickCount % 10 == 0) {
+ if (hasCircuitToConfigure()) {
+ this.addOutput();
this.markDirty();
- }
- else {
- Logger.WARNING("This Trap does not have enough water around it.");
- Logger.WARNING("Not adding Loot to the fishtrap at x[" + this.locationX + "] y[" + this.locationY
- + "] z[" + this.locationZ + "] (Ticking for loot every " + this.baseTickRate + " ticks)");
- this.markDirty();
- }
- this.tickCount = 0;
- }
- if (this.tickCount > (this.baseTickRate + 500)) {
- this.tickCount = 0;
+ }
}
-
- }
+ this.tickCount++;
+ }
}
catch (final Throwable t){}
}
- public void calculateTickrate() {
- int calculateTickrate = 0;
- if (this.waterSides <= 2) {
- calculateTickrate = 0;
- }
- else if ((this.waterSides > 2) && (this.waterSides < 4)) {
- calculateTickrate = 4800;
- }
- else if ((this.waterSides >= 4) && (this.waterSides < 6)) {
- calculateTickrate = 3600;
- }
- else if (this.waterSides == 6) {
- calculateTickrate = 2400;
- }
- this.baseTickRate = calculateTickrate;
- }
-
public boolean anyPlayerInRange() {
return this.worldObj.getClosestPlayer(this.xCoord + 0.5D, this.yCoord + 0.5D, this.zCoord + 0.5D, 32) != null;
}
@@ -277,6 +151,7 @@ public class TileEntityCircuitProgrammer extends TileEntity implements ISidedInv
if (this.hasCustomInventoryName()) {
nbt.setString("CustomName", this.getCustomName());
}
+ nbt.setInteger("aCurrentMode", aCurrentMode);
}
@Override
@@ -287,20 +162,7 @@ public class TileEntityCircuitProgrammer extends TileEntity implements ISidedInv
if (nbt.hasKey("CustomName", 8)) {
this.setCustomName(nbt.getString("CustomName"));
}
- }
-
- final static String prefix = "food";
- final static String suffix = "raw";
- final static String seaweed = "cropSeaweed";
- final static String greenheartFish = "Greenheartfish";
- private static final String[] harvestcraftFish = { "Anchovy", "Bass", "Carp", "Catfish", "Charr", "Clam", "Crab",
- "Crayfish", "Eel", "Frog", "Grouper", "Herring", "Jellyfish", "Mudfish", "Octopus", "Perch", "Scallop",
- "Shrimp", "Snail", "Snapper", "Tilapia", "Trout", "Tuna", "Turtle", "Walleye" };
-
- public static void pamsHarvestCraftCompat() {
- for (int i = 0; i < harvestcraftFish.length; i++) {
-
- }
+ aCurrentMode = nbt.getInteger("aCurrentMode");
}
@Override
@@ -371,12 +233,12 @@ public class TileEntityCircuitProgrammer extends TileEntity implements ISidedInv
@Override
public boolean canInsertItem(final int p_102007_1_, final ItemStack p_102007_2_, final int p_102007_3_) {
- return false;
+ return p_102007_1_ >= 0 && p_102007_1_ <= 24;
}
@Override
public boolean canExtractItem(final int p_102008_1_, final ItemStack p_102008_2_, final int p_102008_3_) {
- return true;
+ return p_102008_1_ == 25;
}
public String getCustomName() {
@@ -389,7 +251,7 @@ public class TileEntityCircuitProgrammer extends TileEntity implements ISidedInv
@Override
public String getInventoryName() {
- return this.hasCustomInventoryName() ? this.customName : "container.fishtrap";
+ return this.hasCustomInventoryName() ? this.customName : "container.circuitprogrammer";
}
@Override
@@ -397,4 +259,33 @@ public class TileEntityCircuitProgrammer extends TileEntity implements ISidedInv
return (this.customName != null) && !this.customName.equals("");
}
+ @Override
+ public Packet getDescriptionPacket() {
+ final NBTTagCompound tag = new NBTTagCompound();
+ this.writeToNBT(tag);
+ return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, this.blockMetadata, tag);
+ }
+
+ @Override
+ public void onDataPacket(final NetworkManager net, final S35PacketUpdateTileEntity pkt) {
+ final NBTTagCompound tag = pkt.func_148857_g();
+ this.readFromNBT(tag);
+ }
+
+ public boolean onScrewdriverRightClick(byte side, EntityPlayer player, int x, int y, int z) {
+ try {
+ if (aCurrentMode == 24) {
+ aCurrentMode = 0;
+ }
+ else {
+ aCurrentMode++;
+ }
+ PlayerUtils.messagePlayer(player, "Now configuring units for type "+aCurrentMode+".");
+ return true;
+ }
+ catch (Throwable t) {
+ return false;
+ }
+ }
+
}