mirror of
https://github.com/GTNewHorizons/EnderIO.git
synced 2026-11-15 09:34:50 +00:00
Compare commits
3
Commits
mu
...
2.10.11-pre
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2429c610e4 | ||
|
|
6ffd54baf6 | ||
|
|
48beb6e2fc |
No files matched your search
@@ -1,19 +1,21 @@
|
||||
package crazypants.enderio.machine.farm;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.BitSet;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.enchantment.Enchantment;
|
||||
import net.minecraft.enchantment.EnchantmentHelper;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemShears;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.world.EnumSkyBlock;
|
||||
@@ -31,7 +33,6 @@ import crazypants.enderio.ModObject;
|
||||
import crazypants.enderio.config.Config;
|
||||
import crazypants.enderio.machine.AbstractPoweredTaskEntity;
|
||||
import crazypants.enderio.machine.ContinuousTask;
|
||||
import crazypants.enderio.machine.IMachineRecipe.ResultStack;
|
||||
import crazypants.enderio.machine.IPoweredTask;
|
||||
import crazypants.enderio.machine.SlotDefinition;
|
||||
import crazypants.enderio.machine.farm.farmers.FarmersCommune;
|
||||
@@ -48,6 +49,8 @@ public class TileFarmStation extends AbstractPoweredTaskEntity implements IRange
|
||||
private static final int TICKS_PER_WORK = 20;
|
||||
private boolean showingRange;
|
||||
|
||||
private final List<ItemStack> harvestBuffer = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public World getWorld() {
|
||||
return worldObj;
|
||||
@@ -424,6 +427,38 @@ public class TileFarmStation extends AbstractPoweredTaskEntity implements IRange
|
||||
wasActive = isActive();
|
||||
worldObj.updateLightByType(EnumSkyBlock.Block, xCoord, yCoord, zCoord);
|
||||
}
|
||||
tryMoveFromBuffer();
|
||||
}
|
||||
|
||||
private void tryMoveFromBuffer() {
|
||||
if (harvestBuffer.isEmpty() || worldObj.isRemote) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<ItemStack> toRemove = new ArrayList<>();
|
||||
for (ItemStack stack : harvestBuffer) {
|
||||
if (stack == null || stack.stackSize <= 0) {
|
||||
toRemove.add(stack);
|
||||
continue;
|
||||
}
|
||||
|
||||
ItemStack remaining = tryInsertToInputSlots(stack);
|
||||
if (remaining != null && remaining.stackSize > 0) {
|
||||
remaining = tryInsertToOutputSlots(remaining);
|
||||
}
|
||||
|
||||
if (remaining == null || remaining.stackSize == 0) {
|
||||
toRemove.add(stack);
|
||||
} else {
|
||||
stack.stackSize = remaining.stackSize;
|
||||
}
|
||||
}
|
||||
|
||||
harvestBuffer.removeAll(toRemove);
|
||||
|
||||
if (!toRemove.isEmpty()) {
|
||||
markDirty();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -445,9 +480,18 @@ public class TileFarmStation extends AbstractPoweredTaskEntity implements IRange
|
||||
setNotification("noPower");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isBufferNotEmpty() || isOutputFull()) {
|
||||
setNotification("outputFull");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean isBufferNotEmpty() {
|
||||
return !harvestBuffer.isEmpty();
|
||||
}
|
||||
|
||||
protected void doTick() {
|
||||
|
||||
if (sendNotification && shouldDoWorkThisTick(TICKS_PER_WORK)) {
|
||||
@@ -488,7 +532,7 @@ public class TileFarmStation extends AbstractPoweredTaskEntity implements IRange
|
||||
block = worldObj.getBlock(bc.x, bc.y, bc.z);
|
||||
}
|
||||
|
||||
if (isOutputFull()) {
|
||||
if (isOutputFull() || isBufferNotEmpty()) {
|
||||
setNotification("outputFull");
|
||||
return;
|
||||
}
|
||||
@@ -507,10 +551,8 @@ public class TileFarmStation extends AbstractPoweredTaskEntity implements IRange
|
||||
new TargetPoint(worldObj.provider.dimensionId, bc.x, bc.y, bc.z, Config.farmParticlesMaxRange));
|
||||
for (EntityItem ei : harvest.getDrops()) {
|
||||
if (ei != null) {
|
||||
insertHarvestDrop(ei, bc);
|
||||
if (!ei.isDead) {
|
||||
worldObj.spawnEntityInWorld(ei);
|
||||
}
|
||||
addToBuffer(ei.getEntityItem().copy());
|
||||
ei.setDead();
|
||||
}
|
||||
}
|
||||
return;
|
||||
@@ -552,6 +594,99 @@ public class TileFarmStation extends AbstractPoweredTaskEntity implements IRange
|
||||
}
|
||||
}
|
||||
|
||||
private void addToBuffer(ItemStack stack) {
|
||||
if (stack == null || stack.stackSize <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (ItemStack bufStack : harvestBuffer) {
|
||||
if (bufStack.isItemEqual(stack) && ItemStack.areItemStackTagsEqual(bufStack, stack)) {
|
||||
int canAdd = bufStack.stackSize;
|
||||
if (canAdd > 0) {
|
||||
int addAmount = Math.min(canAdd, stack.stackSize);
|
||||
bufStack.stackSize += addAmount;
|
||||
stack.stackSize -= addAmount;
|
||||
|
||||
if (stack.stackSize <= 0) {
|
||||
markDirty();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
harvestBuffer.add(stack.copy());
|
||||
markDirty();
|
||||
}
|
||||
|
||||
private ItemStack tryInsertToInputSlots(ItemStack stack) {
|
||||
if (stack == null || stack.stackSize <= 0) {
|
||||
return stack;
|
||||
}
|
||||
|
||||
for (int i = minSupSlot; i <= maxSupSlot; i++) {
|
||||
if (stack.stackSize <= 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
ItemStack slotStack = inventory[i];
|
||||
int stackLimit = getInventoryStackLimit(i);
|
||||
|
||||
if (isItemValidForSlot(i, stack)) {
|
||||
if (slotStack == null) {
|
||||
if (!isSlotLocked(i) || (inventory[i] != null && inventory[i].isItemEqual(stack))) {
|
||||
int amount = Math.min(stack.stackSize, stackLimit);
|
||||
inventory[i] = stack.copy();
|
||||
inventory[i].stackSize = amount;
|
||||
stack.stackSize -= amount;
|
||||
markDirty();
|
||||
}
|
||||
} else if (slotStack.isItemEqual(stack) && ItemStack.areItemStackTagsEqual(slotStack, stack)) {
|
||||
int canAdd = Math.min(stackLimit - slotStack.stackSize, stack.stackSize);
|
||||
if (canAdd > 0) {
|
||||
slotStack.stackSize += canAdd;
|
||||
stack.stackSize -= canAdd;
|
||||
markDirty();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return stack.stackSize > 0 ? stack : null;
|
||||
}
|
||||
|
||||
private ItemStack tryInsertToOutputSlots(ItemStack stack) {
|
||||
if (stack == null || stack.stackSize <= 0) {
|
||||
return stack;
|
||||
}
|
||||
|
||||
for (int i = slotDefinition.minOutputSlot; i <= slotDefinition.maxOutputSlot; i++) {
|
||||
if (stack.stackSize <= 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
ItemStack slotStack = inventory[i];
|
||||
int stackLimit = 64;
|
||||
|
||||
if (slotStack == null) {
|
||||
int amount = Math.min(stack.stackSize, stackLimit);
|
||||
inventory[i] = stack.copy();
|
||||
inventory[i].stackSize = amount;
|
||||
stack.stackSize -= amount;
|
||||
markDirty();
|
||||
} else if (slotStack.isItemEqual(stack) && ItemStack.areItemStackTagsEqual(slotStack, stack)) {
|
||||
int canAdd = Math.min(stackLimit - slotStack.stackSize, stack.stackSize);
|
||||
if (canAdd > 0) {
|
||||
slotStack.stackSize += canAdd;
|
||||
stack.stackSize -= canAdd;
|
||||
markDirty();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return stack.stackSize > 0 ? stack : null;
|
||||
}
|
||||
|
||||
private int bonemealCooldown = 5; // no need to persist this
|
||||
|
||||
private boolean hasBonemeal() {
|
||||
@@ -652,68 +787,6 @@ public class TileFarmStation extends AbstractPoweredTaskEntity implements IRange
|
||||
return minSupSlot + 3;
|
||||
}
|
||||
|
||||
private void insertHarvestDrop(Entity entity, BlockCoord bc) {
|
||||
if (!worldObj.isRemote) {
|
||||
if (entity instanceof EntityItem && !entity.isDead) {
|
||||
EntityItem item = (EntityItem) entity;
|
||||
ItemStack stack = item.getEntityItem().copy();
|
||||
int numInserted = insertResult(stack, bc);
|
||||
stack.stackSize -= numInserted;
|
||||
item.setEntityItemStack(stack);
|
||||
if (stack.stackSize == 0) {
|
||||
item.setDead();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int insertResult(ItemStack stack, BlockCoord bc) {
|
||||
|
||||
int slot = bc != null ? getSupplySlotForCoord(bc) : minSupSlot;
|
||||
int[] slots = new int[NUM_SUPPLY_SLOTS];
|
||||
int k = 0;
|
||||
for (int j = slot; j <= maxSupSlot; j++) {
|
||||
slots[k++] = j;
|
||||
}
|
||||
for (int j = minSupSlot; j < slot; j++) {
|
||||
slots[k++] = j;
|
||||
}
|
||||
|
||||
int origSize = stack.stackSize;
|
||||
stack = stack.copy();
|
||||
|
||||
int inserted = 0;
|
||||
for (int j = 0; j < slots.length && inserted < stack.stackSize; j++) {
|
||||
int i = slots[j];
|
||||
ItemStack curStack = inventory[i];
|
||||
int inventoryStackLimit = getInventoryStackLimit(i);
|
||||
if (isItemValidForSlot(i, stack) && (curStack == null || curStack.stackSize < inventoryStackLimit)) {
|
||||
if (curStack == null) {
|
||||
if (stack.stackSize < inventoryStackLimit) {
|
||||
inventory[i] = stack.copy();
|
||||
inserted = stack.stackSize;
|
||||
} else {
|
||||
inventory[i] = stack.copy();
|
||||
inserted = inventoryStackLimit;
|
||||
inventory[i].stackSize = inserted;
|
||||
}
|
||||
} else if (curStack.isItemEqual(stack)) {
|
||||
inserted = Math.min(inventoryStackLimit - curStack.stackSize, stack.stackSize);
|
||||
inventory[i].stackSize += inserted;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stack.stackSize -= inserted;
|
||||
if (inserted >= origSize) {
|
||||
return origSize;
|
||||
}
|
||||
|
||||
ResultStack[] in = new ResultStack[] { new ResultStack(stack) };
|
||||
mergeResults(in);
|
||||
return origSize - (in[0].item == null ? 0 : in[0].item.stackSize);
|
||||
}
|
||||
|
||||
private @Nonnull BlockCoord getNextCoord() {
|
||||
|
||||
int size = getFarmSize();
|
||||
@@ -752,11 +825,6 @@ public class TileFarmStation extends AbstractPoweredTaskEntity implements IRange
|
||||
return EnderIO.blockFarmStation.getLocalizedName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomInventoryName() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMachineName() {
|
||||
return ModObject.blockFarmStation.unlocalisedName;
|
||||
@@ -811,6 +879,17 @@ public class TileFarmStation extends AbstractPoweredTaskEntity implements IRange
|
||||
} else if (slotLayoutVersion == 2) {
|
||||
inventory = (new ArrayMappingTool<ItemStack>("TTTSSSSOOOOOOC", "TTTBBSSSSOOOOOOC")).map(inventory);
|
||||
}
|
||||
|
||||
if (nbtRoot.hasKey("HarvestBuffer")) {
|
||||
NBTTagList bufferList = nbtRoot.getTagList("HarvestBuffer", 10);
|
||||
for (int i = 0; i < bufferList.tagCount(); i++) {
|
||||
NBTTagCompound itemTag = bufferList.getCompoundTagAt(i);
|
||||
ItemStack stack = ItemStack.loadItemStackFromNBT(itemTag);
|
||||
if (stack != null && stack.stackSize > 0) {
|
||||
harvestBuffer.add(stack);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
IPoweredTask createTask() {
|
||||
@@ -834,6 +913,18 @@ public class TileFarmStation extends AbstractPoweredTaskEntity implements IRange
|
||||
nbtRoot.setIntArray("lockedSlots", locked);
|
||||
}
|
||||
nbtRoot.setInteger("slotLayoutVersion", 3);
|
||||
|
||||
if (!harvestBuffer.isEmpty()) {
|
||||
NBTTagList bufferList = new NBTTagList();
|
||||
for (ItemStack stack : harvestBuffer) {
|
||||
if (stack != null && stack.stackSize > 0) {
|
||||
NBTTagCompound itemTag = new NBTTagCompound();
|
||||
stack.writeToNBT(itemTag);
|
||||
bufferList.appendTag(itemTag);
|
||||
}
|
||||
}
|
||||
nbtRoot.setTag("HarvestBuffer", bufferList);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package crazypants.enderio.material;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
@@ -9,6 +10,7 @@ import net.minecraft.enchantment.EnchantmentHelper;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.util.MathHelper;
|
||||
|
||||
@@ -20,6 +22,7 @@ import cpw.mods.fml.relauncher.SideOnly;
|
||||
import crazypants.enderio.EnderIO;
|
||||
import crazypants.enderio.EnderIOTab;
|
||||
import crazypants.enderio.ModObject;
|
||||
import crazypants.enderio.config.Config;
|
||||
import crazypants.enderio.power.BasicCapacitor;
|
||||
import crazypants.enderio.power.Capacitors;
|
||||
import crazypants.enderio.power.ICapacitor;
|
||||
@@ -103,13 +106,46 @@ public class ItemCapacitor extends Item implements ICapacitorItem {
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List<String> par3List,
|
||||
boolean par4) {
|
||||
String space = " ";
|
||||
EnumChatFormatting reset = EnumChatFormatting.RESET;
|
||||
if (par1ItemStack != null && par1ItemStack.getItemDamage() > 0 && par1ItemStack.getItemDamage() != 7) {
|
||||
par3List.add(EnderIO.lang.localize("machine.tooltip.upgrade"));
|
||||
ICapacitor capacitor = getCapacitor(par1ItemStack);
|
||||
par3List.add(EnumChatFormatting.GREEN + EnderIO.lang.localize("machine.tooltip.upgrade.name"));
|
||||
if (SpecialTooltipHandler.showAdvancedTooltips()) {
|
||||
SpecialTooltipHandler.addDetailedTooltipFromResources(par3List, "enderio.machine.tooltip.upgrade");
|
||||
addUpgrades(par3List, capacitor, space, reset);
|
||||
addRangeUpgrade(par3List, capacitor, space, reset);
|
||||
} else {
|
||||
SpecialTooltipHandler.addShowDetailsTooltip(par3List);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void addUpgrades(List<String> list, ICapacitor capacitor, String space, EnumChatFormatting reset) {
|
||||
DecimalFormat formatter = new DecimalFormat("#,###");
|
||||
String tierString = EnumChatFormatting.AQUA + EnderIO.lang.localize("machine.tooltip.upgrade.tier");
|
||||
String maxEnergyStorageString = EnumChatFormatting.AQUA
|
||||
+ EnderIO.lang.localize("machine.tooltip.upgrade.energystorage");
|
||||
String maxEnergyReceivedString = EnumChatFormatting.AQUA
|
||||
+ EnderIO.lang.localize("machine.tooltip.upgrade.energyreceived");
|
||||
String maxEnergyExtractedString = EnumChatFormatting.AQUA
|
||||
+ EnderIO.lang.localize("machine.tooltip.upgrade.energyextracted");
|
||||
String upgrades = EnumChatFormatting.GOLD + EnderIO.lang.localize("machine.tooltip.upgrade");
|
||||
String maxEnergyStorage = formatter.format(capacitor.getMaxEnergyStored());
|
||||
int tier = capacitor.getTier();
|
||||
String maxEnergyReceived = formatter.format(capacitor.getMaxEnergyReceived());
|
||||
String maxEnergyExtracted = formatter.format(capacitor.getMaxEnergyExtracted());
|
||||
list.add(upgrades);
|
||||
list.add(space + tierString + reset + tier);
|
||||
list.add(space + maxEnergyReceivedString + reset + maxEnergyReceived);
|
||||
list.add(space + maxEnergyExtractedString + reset + maxEnergyExtracted);
|
||||
list.add(space + maxEnergyStorageString + reset + maxEnergyStorage);
|
||||
}
|
||||
|
||||
public void addRangeUpgrade(List<String> list, ICapacitor capacitor, String space, EnumChatFormatting reset) {
|
||||
String farmStation = EnumChatFormatting.AQUA + EnderIO.lang.localize("machine.tooltip.upgrade.farmstation");
|
||||
String rangeUpgrade = EnumChatFormatting.GOLD + EnderIO.lang.localize("machine.tooltip.upgrade.range");
|
||||
int range = Config.farmBonusSize * capacitor.getTier() - 1 + 2;
|
||||
list.add(rangeUpgrade);
|
||||
list.add(space + farmStation + reset + range);
|
||||
}
|
||||
}
|
||||
@@ -373,9 +373,14 @@ enderio.endergeticCapacitor.name=Endergetic Capacitor
|
||||
enderio.endergisedCapacitor.name=Endergised Capacitor
|
||||
enderio.totemicCapacitor.name=Totemic Capacitor
|
||||
|
||||
enderio.machine.tooltip.upgrade=Machine Upgrade
|
||||
enderio.machine.tooltip.upgrade.tooltip.detailed.line1=Increases energy storage and
|
||||
enderio.machine.tooltip.upgrade.tooltip.detailed.line2=speed / range of machines
|
||||
enderio.machine.tooltip.upgrade.name=Machine Upgrade
|
||||
enderio.machine.tooltip.upgrade=Upgrades:
|
||||
enderio.machine.tooltip.upgrade.tier=Tier:
|
||||
enderio.machine.tooltip.upgrade.energyreceived=Max Energy Received:
|
||||
enderio.machine.tooltip.upgrade.energyextracted=Max Energy Extracted:
|
||||
enderio.machine.tooltip.upgrade.farmstation=Farming station radius:
|
||||
enderio.machine.tooltip.upgrade.energystorage=Max energy storage:
|
||||
enderio.machine.tooltip.upgrade.range=Range upgrade:
|
||||
enderio.machine.tooltip.clearConfig=This will clear all stored info!
|
||||
|
||||
#Machines
|
||||
|
||||
Reference in new issue
Block a user