Lots more moved
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.helpers;
|
||||
|
||||
import alexiil.mc.lib.attributes.item.FixedItemInv;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import appeng.api.networking.IGridNode;
|
||||
import appeng.api.networking.security.IActionSource;
|
||||
|
||||
public interface IContainerCraftingPacket {
|
||||
|
||||
/**
|
||||
* @return gain access to network infrastructure.
|
||||
*/
|
||||
IGridNode getNetworkNode();
|
||||
|
||||
/**
|
||||
* @param string name of inventory
|
||||
*
|
||||
* @return the inventory of the part/tile by name.
|
||||
*/
|
||||
FixedItemInv getInventoryByName(String string);
|
||||
|
||||
/**
|
||||
* @return who are we?
|
||||
*/
|
||||
IActionSource getActionSource();
|
||||
|
||||
/**
|
||||
* @return consume items?
|
||||
*/
|
||||
boolean useRealItems();
|
||||
|
||||
/**
|
||||
* @return array of view cells
|
||||
*/
|
||||
ItemStack[] getViewCells();
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.helpers;
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.util.math.Direction;
|
||||
|
||||
import appeng.api.implementations.IUpgradeableHost;
|
||||
import appeng.api.networking.crafting.ICraftingProvider;
|
||||
import appeng.api.networking.crafting.ICraftingRequester;
|
||||
|
||||
public interface IInterfaceHost extends ICraftingProvider, IUpgradeableHost, ICraftingRequester {
|
||||
|
||||
DualityInterface getInterfaceDuality();
|
||||
|
||||
EnumSet<Direction> getTargets();
|
||||
|
||||
BlockEntity getBlockEntity();
|
||||
|
||||
void saveChanges();
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.helpers;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public interface IMouseWheelItem {
|
||||
|
||||
void onWheel(ItemStack is, boolean up);
|
||||
}
|
||||
@@ -0,0 +1,138 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2017, tyra314, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.helpers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
import net.minecraft.text.LiteralText;
|
||||
import net.minecraft.text.MutableText;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Formatting;
|
||||
|
||||
import appeng.util.Platform;
|
||||
|
||||
public class InvalidPatternHelper {
|
||||
|
||||
private final List<PatternIngredient> outputs = new ArrayList<>();
|
||||
private final List<PatternIngredient> inputs = new ArrayList<>();
|
||||
private final boolean isCrafting;
|
||||
private final boolean canSubstitute;
|
||||
|
||||
public InvalidPatternHelper(final ItemStack is) {
|
||||
final CompoundTag encodedValue = is.getTag();
|
||||
|
||||
if (encodedValue == null) {
|
||||
throw new IllegalArgumentException("No pattern here!");
|
||||
}
|
||||
|
||||
final ListTag inTag = encodedValue.getList("in", 10);
|
||||
final ListTag outTag = encodedValue.getList("out", 10);
|
||||
this.isCrafting = encodedValue.getBoolean("crafting");
|
||||
|
||||
this.canSubstitute = this.isCrafting && encodedValue.getBoolean("substitute");
|
||||
|
||||
for (int i = 0; i < outTag.size(); i++) {
|
||||
this.outputs.add(new PatternIngredient(outTag.getCompound(i)));
|
||||
}
|
||||
|
||||
for (int i = 0; i < inTag.size(); i++) {
|
||||
CompoundTag in = inTag.getCompound(i);
|
||||
|
||||
// skip empty slots in the crafting grid
|
||||
if (in.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
this.inputs.add(new PatternIngredient(in));
|
||||
}
|
||||
}
|
||||
|
||||
public List<PatternIngredient> getOutputs() {
|
||||
return this.outputs;
|
||||
}
|
||||
|
||||
public List<PatternIngredient> getInputs() {
|
||||
return this.inputs;
|
||||
}
|
||||
|
||||
public boolean isCraftable() {
|
||||
return this.isCrafting;
|
||||
}
|
||||
|
||||
public boolean canSubstitute() {
|
||||
return this.canSubstitute;
|
||||
}
|
||||
|
||||
public class PatternIngredient {
|
||||
private String id;
|
||||
private int count;
|
||||
private int damage;
|
||||
|
||||
private ItemStack stack;
|
||||
|
||||
public PatternIngredient(CompoundTag tag) {
|
||||
this.stack = ItemStack.fromTag(tag);
|
||||
|
||||
if (this.stack.isEmpty()) {
|
||||
this.id = tag.getString("id");
|
||||
this.count = tag.getByte("Count");
|
||||
this.damage = Math.max(0, tag.getShort("Damage"));
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isValid() {
|
||||
return !this.stack.isEmpty();
|
||||
}
|
||||
|
||||
public Text getName() {
|
||||
return this.isValid() ? Platform.getItemDisplayName(this.stack)
|
||||
: new LiteralText(this.id + '@' + this.getDamage());
|
||||
}
|
||||
|
||||
public int getDamage() {
|
||||
return this.isValid() ? this.stack.getDamage() : this.damage;
|
||||
}
|
||||
|
||||
public int getCount() {
|
||||
return this.isValid() ? this.stack.getCount() : this.count;
|
||||
}
|
||||
|
||||
public ItemStack getItem() {
|
||||
if (!this.isValid()) {
|
||||
throw new IllegalArgumentException("There is no valid ItemStack for this PatternIngredient");
|
||||
}
|
||||
|
||||
return this.stack;
|
||||
}
|
||||
|
||||
public Text getFormattedToolTip() {
|
||||
MutableText result = new LiteralText(this.getCount() + " ").append(this.getName());
|
||||
|
||||
if (!this.isValid()) {
|
||||
result.formatted(Formatting.RED);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.helpers;
|
||||
|
||||
public enum InventoryAction {
|
||||
// standard vanilla mechanics.
|
||||
PICKUP_OR_SET_DOWN, SPLIT_OR_PLACE_SINGLE, CREATIVE_DUPLICATE, SHIFT_CLICK,
|
||||
|
||||
// crafting term
|
||||
CRAFT_STACK, CRAFT_ITEM, CRAFT_SHIFT,
|
||||
|
||||
// fluid term
|
||||
FILL_ITEM, EMPTY_ITEM,
|
||||
|
||||
// extra...
|
||||
MOVE_REGION, PICKUP_SINGLE, UPDATE_HAND, ROLL_UP, ROLL_DOWN, AUTO_CRAFT, PLACE_SINGLE
|
||||
}
|
||||
@@ -0,0 +1,232 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.helpers;
|
||||
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.networking.IGrid;
|
||||
import appeng.api.networking.crafting.ICraftingGrid;
|
||||
import appeng.api.networking.crafting.ICraftingJob;
|
||||
import appeng.api.networking.crafting.ICraftingLink;
|
||||
import appeng.api.networking.crafting.ICraftingRequester;
|
||||
import appeng.api.networking.security.IActionSource;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.util.InventoryAdaptor;
|
||||
|
||||
public class MultiCraftingTracker {
|
||||
|
||||
private final int size;
|
||||
private final ICraftingRequester owner;
|
||||
|
||||
private Future<ICraftingJob>[] jobs = null;
|
||||
private ICraftingLink[] links = null;
|
||||
|
||||
public MultiCraftingTracker(final ICraftingRequester o, final int size) {
|
||||
this.owner = o;
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
public void readFromNBT(final CompoundTag extra) {
|
||||
for (int x = 0; x < this.size; x++) {
|
||||
final CompoundTag link = extra.getCompound("links-" + x);
|
||||
|
||||
if (link != null && !link.isEmpty()) {
|
||||
this.setLink(x, AEApi.instance().storage().loadCraftingLink(link, this.owner));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void writeToNBT(final CompoundTag extra) {
|
||||
for (int x = 0; x < this.size; x++) {
|
||||
final ICraftingLink link = this.getLink(x);
|
||||
|
||||
if (link != null) {
|
||||
final CompoundTag ln = new CompoundTag();
|
||||
link.writeToNBT(ln);
|
||||
extra.put("links-" + x, ln);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean handleCrafting(final int x, final long itemToCraft, final IAEItemStack ais, final InventoryAdaptor d,
|
||||
final World w, final IGrid g, final ICraftingGrid cg, final IActionSource mySrc) {
|
||||
if (ais != null && d.simulateAdd(ais.createItemStack()).isEmpty()) {
|
||||
final Future<ICraftingJob> craftingJob = this.getJob(x);
|
||||
|
||||
if (this.getLink(x) != null) {
|
||||
return false;
|
||||
} else if (craftingJob != null) {
|
||||
|
||||
try {
|
||||
ICraftingJob job = null;
|
||||
if (craftingJob.isDone()) {
|
||||
job = craftingJob.get();
|
||||
}
|
||||
|
||||
if (job != null) {
|
||||
final ICraftingLink link = cg.submitJob(job, this.owner, null, false, mySrc);
|
||||
|
||||
this.setJob(x, null);
|
||||
|
||||
if (link != null) {
|
||||
this.setLink(x, link);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} catch (final InterruptedException e) {
|
||||
// :P
|
||||
} catch (final ExecutionException e) {
|
||||
// :P
|
||||
}
|
||||
} else {
|
||||
if (this.getLink(x) == null) {
|
||||
final IAEItemStack aisC = ais.copy();
|
||||
aisC.setStackSize(itemToCraft);
|
||||
|
||||
this.setJob(x, cg.beginCraftingJob(w, g, mySrc, aisC, null));
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public ImmutableSet<ICraftingLink> getRequestedJobs() {
|
||||
if (this.links == null) {
|
||||
return ImmutableSet.of();
|
||||
}
|
||||
|
||||
return ImmutableSet.copyOf(new NonNullArrayIterator<>(this.links));
|
||||
}
|
||||
|
||||
public void jobStateChange(final ICraftingLink link) {
|
||||
if (this.links != null) {
|
||||
for (int x = 0; x < this.links.length; x++) {
|
||||
if (this.links[x] == link) {
|
||||
this.setLink(x, null);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int getSlot(final ICraftingLink link) {
|
||||
if (this.links != null) {
|
||||
for (int x = 0; x < this.links.length; x++) {
|
||||
if (this.links[x] == link) {
|
||||
return x;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
void cancel() {
|
||||
if (this.links != null) {
|
||||
for (final ICraftingLink l : this.links) {
|
||||
if (l != null) {
|
||||
l.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
this.links = null;
|
||||
}
|
||||
|
||||
if (this.jobs != null) {
|
||||
for (final Future<ICraftingJob> l : this.jobs) {
|
||||
if (l != null) {
|
||||
l.cancel(true);
|
||||
}
|
||||
}
|
||||
|
||||
this.jobs = null;
|
||||
}
|
||||
}
|
||||
|
||||
boolean isBusy(final int slot) {
|
||||
return this.getLink(slot) != null || this.getJob(slot) != null;
|
||||
}
|
||||
|
||||
private ICraftingLink getLink(final int slot) {
|
||||
if (this.links == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return this.links[slot];
|
||||
}
|
||||
|
||||
private void setLink(final int slot, final ICraftingLink l) {
|
||||
if (this.links == null) {
|
||||
this.links = new ICraftingLink[this.size];
|
||||
}
|
||||
|
||||
this.links[slot] = l;
|
||||
|
||||
boolean hasStuff = false;
|
||||
for (int x = 0; x < this.links.length; x++) {
|
||||
final ICraftingLink g = this.links[x];
|
||||
|
||||
if (g == null || g.isCanceled() || g.isDone()) {
|
||||
this.links[x] = null;
|
||||
} else {
|
||||
hasStuff = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!hasStuff) {
|
||||
this.links = null;
|
||||
}
|
||||
}
|
||||
|
||||
private Future<ICraftingJob> getJob(final int slot) {
|
||||
if (this.jobs == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return this.jobs[slot];
|
||||
}
|
||||
|
||||
private void setJob(final int slot, final Future<ICraftingJob> l) {
|
||||
if (this.jobs == null) {
|
||||
this.jobs = new Future[this.size];
|
||||
}
|
||||
|
||||
this.jobs[slot] = l;
|
||||
|
||||
boolean hasStuff = false;
|
||||
|
||||
for (final Future<ICraftingJob> job : this.jobs) {
|
||||
if (job != null) {
|
||||
hasStuff = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!hasStuff) {
|
||||
this.jobs = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.helpers;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
public class NonNullArrayIterator<E> implements Iterator<E> {
|
||||
|
||||
private final E[] g;
|
||||
private int offset = 0;
|
||||
|
||||
public NonNullArrayIterator(final E[] o) {
|
||||
this.g = o;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
while (this.offset < this.g.length && this.g[this.offset] == null) {
|
||||
this.offset++;
|
||||
}
|
||||
|
||||
return this.offset != this.g.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public E next() {
|
||||
final E result = this.g[this.offset];
|
||||
this.offset++;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,393 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.helpers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.inventory.CraftingInventory;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.recipe.CraftingRecipe;
|
||||
import net.minecraft.recipe.RecipeType;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.networking.crafting.ICraftingPatternDetails;
|
||||
import appeng.api.storage.channels.IItemStorageChannel;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.container.ContainerNull;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.item.AEItemStack;
|
||||
|
||||
public class PatternHelper implements ICraftingPatternDetails, Comparable<PatternHelper> {
|
||||
|
||||
private final ItemStack patternItem;
|
||||
private final CraftingInventory crafting = new CraftingInventory(new ContainerNull(), 3, 3);
|
||||
private final CraftingInventory testFrame = new CraftingInventory(new ContainerNull(), 3, 3);
|
||||
private final ItemStack correctOutput;
|
||||
private final CraftingRecipe standardRecipe;
|
||||
private final IAEItemStack[] condensedInputs;
|
||||
private final IAEItemStack[] condensedOutputs;
|
||||
private final IAEItemStack[] inputs;
|
||||
private final IAEItemStack[] outputs;
|
||||
private final boolean isCrafting;
|
||||
private final boolean canSubstitute;
|
||||
private final Set<TestLookup> failCache = new HashSet<>();
|
||||
private final Set<TestLookup> passCache = new HashSet<>();
|
||||
private final IAEItemStack pattern;
|
||||
private int priority = 0;
|
||||
|
||||
public PatternHelper(final ItemStack is, final World w) {
|
||||
final CompoundTag encodedValue = is.getTag();
|
||||
|
||||
if (encodedValue == null) {
|
||||
throw new IllegalArgumentException("No pattern here!");
|
||||
}
|
||||
|
||||
final ListTag inTag = encodedValue.getList("in", 10);
|
||||
final ListTag outTag = encodedValue.getList("out", 10);
|
||||
this.isCrafting = encodedValue.getBoolean("crafting");
|
||||
|
||||
this.canSubstitute = this.isCrafting && encodedValue.getBoolean("substitute");
|
||||
this.patternItem = is;
|
||||
this.pattern = AEItemStack.fromItemStack(is);
|
||||
|
||||
final List<IAEItemStack> in = new ArrayList<>();
|
||||
final List<IAEItemStack> out = new ArrayList<>();
|
||||
|
||||
for (int x = 0; x < inTag.size(); x++) {
|
||||
CompoundTag ingredient = inTag.getCompound(x);
|
||||
final ItemStack gs = ItemStack.fromTag(ingredient);
|
||||
|
||||
if (!ingredient.isEmpty() && gs.isEmpty()) {
|
||||
throw new IllegalArgumentException("No pattern here!");
|
||||
}
|
||||
|
||||
this.crafting.setStack(x, gs);
|
||||
|
||||
if (!gs.isEmpty() && (!this.isCrafting || !gs.hasTag())) {
|
||||
this.markItemAs(x, gs, TestStatus.ACCEPT);
|
||||
}
|
||||
|
||||
in.add(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createStack(gs));
|
||||
this.testFrame.setStack(x, gs);
|
||||
}
|
||||
|
||||
if (this.isCrafting) {
|
||||
this.standardRecipe = w.getRecipeManager().getFirstMatch(RecipeType.CRAFTING, this.crafting, w).orElse(null);
|
||||
|
||||
if (this.standardRecipe != null) {
|
||||
this.correctOutput = this.standardRecipe.craft(this.crafting);
|
||||
out.add(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)
|
||||
.createStack(this.correctOutput));
|
||||
} else {
|
||||
throw new IllegalStateException("No pattern here!");
|
||||
}
|
||||
} else {
|
||||
this.standardRecipe = null;
|
||||
this.correctOutput = ItemStack.EMPTY;
|
||||
|
||||
for (int x = 0; x < outTag.size(); x++) {
|
||||
CompoundTag resultItemTag = outTag.getCompound(x);
|
||||
final ItemStack gs = ItemStack.fromTag(resultItemTag);
|
||||
|
||||
if (!resultItemTag.isEmpty() && gs.isEmpty()) {
|
||||
throw new IllegalArgumentException("No pattern here!");
|
||||
}
|
||||
|
||||
if (!gs.isEmpty()) {
|
||||
out.add(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createStack(gs));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.outputs = out.toArray(new IAEItemStack[0]);
|
||||
this.inputs = in.toArray(new IAEItemStack[0]);
|
||||
|
||||
final Map<IAEItemStack, IAEItemStack> tmpOutputs = new HashMap<>();
|
||||
|
||||
for (final IAEItemStack io : this.outputs) {
|
||||
if (io == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
final IAEItemStack g = tmpOutputs.get(io);
|
||||
|
||||
if (g == null) {
|
||||
tmpOutputs.put(io, io.copy());
|
||||
} else {
|
||||
g.add(io);
|
||||
}
|
||||
}
|
||||
|
||||
final Map<IAEItemStack, IAEItemStack> tmpInputs = new HashMap<>();
|
||||
|
||||
for (final IAEItemStack io : this.inputs) {
|
||||
if (io == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
final IAEItemStack g = tmpInputs.get(io);
|
||||
|
||||
if (g == null) {
|
||||
tmpInputs.put(io, io.copy());
|
||||
} else {
|
||||
g.add(io);
|
||||
}
|
||||
}
|
||||
|
||||
if (tmpOutputs.isEmpty() || tmpInputs.isEmpty()) {
|
||||
throw new IllegalStateException("No pattern here!");
|
||||
}
|
||||
|
||||
this.condensedInputs = new IAEItemStack[tmpInputs.size()];
|
||||
int offset = 0;
|
||||
|
||||
for (final IAEItemStack io : tmpInputs.values()) {
|
||||
this.condensedInputs[offset] = io;
|
||||
offset++;
|
||||
}
|
||||
|
||||
offset = 0;
|
||||
this.condensedOutputs = new IAEItemStack[tmpOutputs.size()];
|
||||
|
||||
for (final IAEItemStack io : tmpOutputs.values()) {
|
||||
this.condensedOutputs[offset] = io;
|
||||
offset++;
|
||||
}
|
||||
}
|
||||
|
||||
private void markItemAs(final int slotIndex, final ItemStack i, final TestStatus b) {
|
||||
if (b == TestStatus.TEST || i.hasTag()) {
|
||||
return;
|
||||
}
|
||||
|
||||
(b == TestStatus.ACCEPT ? this.passCache : this.failCache).add(new TestLookup(slotIndex, i));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getPattern() {
|
||||
return this.patternItem;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean isValidItemForSlot(final int slotIndex, final ItemStack i, final World w) {
|
||||
if (!this.isCrafting) {
|
||||
throw new IllegalStateException("Only crafting recipes supported.");
|
||||
}
|
||||
|
||||
final TestStatus result = this.getStatus(slotIndex, i);
|
||||
|
||||
switch (result) {
|
||||
case ACCEPT:
|
||||
return true;
|
||||
case DECLINE:
|
||||
return false;
|
||||
case TEST:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
for (int x = 0; x < this.crafting.size(); x++) {
|
||||
this.testFrame.setStack(x, this.crafting.getStack(x));
|
||||
}
|
||||
|
||||
this.testFrame.setStack(slotIndex, i);
|
||||
|
||||
// If we cannot substitute, the items must match exactly
|
||||
if (!canSubstitute && slotIndex < inputs.length) {
|
||||
if (!inputs[slotIndex].isSameType(i)) {
|
||||
this.markItemAs(slotIndex, i, TestStatus.DECLINE);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.standardRecipe.matches(this.testFrame, w)) {
|
||||
final ItemStack testOutput = this.standardRecipe.craft(this.testFrame);
|
||||
|
||||
if (Platform.itemComparisons().isSameItem(this.correctOutput, testOutput)) {
|
||||
this.testFrame.setStack(slotIndex, this.crafting.getStack(slotIndex));
|
||||
this.markItemAs(slotIndex, i, TestStatus.ACCEPT);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
this.markItemAs(slotIndex, i, TestStatus.DECLINE);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCraftable() {
|
||||
return this.isCrafting;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack[] getInputs() {
|
||||
return this.inputs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack[] getCondensedInputs() {
|
||||
return this.condensedInputs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack[] getCondensedOutputs() {
|
||||
return this.condensedOutputs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack[] getOutputs() {
|
||||
return this.outputs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canSubstitute() {
|
||||
return this.canSubstitute;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getOutput(final CraftingInventory craftingInv, final World w) {
|
||||
if (!this.isCrafting) {
|
||||
throw new IllegalStateException("Only crafting recipes supported.");
|
||||
}
|
||||
|
||||
for (int x = 0; x < craftingInv.size(); x++) {
|
||||
if (!this.isValidItemForSlot(x, craftingInv.getStack(x), w)) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.outputs != null && this.outputs.length > 0) {
|
||||
return this.outputs[0].createItemStack();
|
||||
}
|
||||
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
private TestStatus getStatus(final int slotIndex, final ItemStack i) {
|
||||
if (this.crafting.getStack(slotIndex).isEmpty()) {
|
||||
return i.isEmpty() ? TestStatus.ACCEPT : TestStatus.DECLINE;
|
||||
}
|
||||
|
||||
if (i.isEmpty()) {
|
||||
return TestStatus.DECLINE;
|
||||
}
|
||||
|
||||
if (i.hasTag()) {
|
||||
return TestStatus.TEST;
|
||||
}
|
||||
|
||||
if (this.passCache.contains(new TestLookup(slotIndex, i))) {
|
||||
return TestStatus.ACCEPT;
|
||||
}
|
||||
|
||||
if (this.failCache.contains(new TestLookup(slotIndex, i))) {
|
||||
return TestStatus.DECLINE;
|
||||
}
|
||||
|
||||
return TestStatus.TEST;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPriority() {
|
||||
return this.priority;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPriority(final int priority) {
|
||||
this.priority = priority;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(final PatternHelper o) {
|
||||
return Integer.compare(o.priority, this.priority);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return this.pattern.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object obj) {
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (this.getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final PatternHelper other = (PatternHelper) obj;
|
||||
|
||||
if (this.pattern != null && other.pattern != null) {
|
||||
return this.pattern.equals(other.pattern);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private enum TestStatus {
|
||||
ACCEPT, DECLINE, TEST
|
||||
}
|
||||
|
||||
private static final class TestLookup {
|
||||
|
||||
private final int slot;
|
||||
private final int ref;
|
||||
private final int hash;
|
||||
|
||||
public TestLookup(final int slot, final ItemStack i) {
|
||||
this(slot, i.getItem(), i.getDamage());
|
||||
}
|
||||
|
||||
public TestLookup(final int slot, final Item item, final int dmg) {
|
||||
this.slot = slot;
|
||||
this.ref = (dmg << Platform.DEF_OFFSET) | (Item.getRawId(item) & 0xffff);
|
||||
final int offset = 3 * slot;
|
||||
this.hash = (this.ref << offset) | (this.ref >> (offset + 32));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return this.hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object obj) {
|
||||
final boolean equality;
|
||||
|
||||
if (obj instanceof TestLookup) {
|
||||
final TestLookup b = (TestLookup) obj;
|
||||
|
||||
equality = b.slot == this.slot && b.ref == this.ref;
|
||||
} else {
|
||||
equality = false;
|
||||
}
|
||||
|
||||
return equality;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.helpers;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.Map;
|
||||
|
||||
import appeng.api.config.SecurityPermissions;
|
||||
import appeng.api.networking.security.ISecurityRegistry;
|
||||
|
||||
public class PlayerSecurityWrapper implements ISecurityRegistry {
|
||||
|
||||
private final Map<Integer, EnumSet<SecurityPermissions>> target;
|
||||
|
||||
public PlayerSecurityWrapper(final Map<Integer, EnumSet<SecurityPermissions>> playerPerms) {
|
||||
this.target = playerPerms;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addPlayer(final int playerID, final EnumSet<SecurityPermissions> permissions) {
|
||||
this.target.put(playerID, permissions);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.helpers;
|
||||
|
||||
import net.minecraft.network.PacketByteBuf;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
import appeng.api.util.AEColor;
|
||||
|
||||
public class Splotch {
|
||||
|
||||
private final Direction side;
|
||||
private final boolean lumen;
|
||||
private final AEColor color;
|
||||
private final int pos;
|
||||
|
||||
public Splotch(final AEColor col, final boolean lit, final Direction side, final Vec3d position) {
|
||||
this.color = col;
|
||||
this.lumen = lit;
|
||||
|
||||
final double x;
|
||||
final double y;
|
||||
|
||||
if (side == Direction.SOUTH || side == Direction.NORTH) {
|
||||
x = position.x;
|
||||
y = position.y;
|
||||
}
|
||||
|
||||
else if (side == Direction.UP || side == Direction.DOWN) {
|
||||
x = position.x;
|
||||
y = position.z;
|
||||
}
|
||||
|
||||
else {
|
||||
x = position.y;
|
||||
y = position.z;
|
||||
}
|
||||
|
||||
final int a = (int) (x * 0xF);
|
||||
final int b = (int) (y * 0xF);
|
||||
this.pos = a | (b << 4);
|
||||
|
||||
this.side = side;
|
||||
}
|
||||
|
||||
public Splotch(final PacketByteBuf data) {
|
||||
|
||||
this.pos = data.readByte();
|
||||
final int val = data.readByte();
|
||||
|
||||
this.side = Direction.values()[val & 0x07];
|
||||
this.color = AEColor.values()[(val >> 3) & 0x0F];
|
||||
this.lumen = ((val >> 7) & 0x01) > 0;
|
||||
}
|
||||
|
||||
public void writeToStream(final PacketByteBuf stream) {
|
||||
stream.writeByte(this.pos);
|
||||
final int val = this.getSide().ordinal() | (this.getColor().ordinal() << 3) | (this.isLumen() ? 0x80 : 0x00);
|
||||
stream.writeByte(val);
|
||||
}
|
||||
|
||||
public float x() {
|
||||
return (this.pos & 0x0f) / 15.0f;
|
||||
}
|
||||
|
||||
public float y() {
|
||||
return ((this.pos >> 4) & 0x0f) / 15.0f;
|
||||
}
|
||||
|
||||
public int getSeed() {
|
||||
final int val = this.getSide().ordinal() | (this.getColor().ordinal() << 3) | (this.isLumen() ? 0x80 : 0x00);
|
||||
return Math.abs(this.pos + val);
|
||||
}
|
||||
|
||||
public Direction getSide() {
|
||||
return this.side;
|
||||
}
|
||||
|
||||
public AEColor getColor() {
|
||||
return this.color;
|
||||
}
|
||||
|
||||
public boolean isLumen() {
|
||||
return this.lumen;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,291 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2015, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.helpers;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.AccessRestriction;
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.config.PowerMultiplier;
|
||||
import appeng.api.features.ILocatable;
|
||||
import appeng.api.features.IWirelessTermHandler;
|
||||
import appeng.api.implementations.guiobjects.IPortableCell;
|
||||
import appeng.api.implementations.tiles.IWirelessAccessPoint;
|
||||
import appeng.api.networking.IGrid;
|
||||
import appeng.api.networking.IGridNode;
|
||||
import appeng.api.networking.IMachineSet;
|
||||
import appeng.api.networking.security.IActionHost;
|
||||
import appeng.api.networking.security.IActionSource;
|
||||
import appeng.api.networking.storage.IStorageGrid;
|
||||
import appeng.api.storage.IMEMonitor;
|
||||
import appeng.api.storage.IMEMonitorHandlerReceiver;
|
||||
import appeng.api.storage.IStorageChannel;
|
||||
import appeng.api.storage.channels.IItemStorageChannel;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.storage.data.IAEStack;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
import appeng.api.util.DimensionalCoord;
|
||||
import appeng.api.util.IConfigManager;
|
||||
import appeng.container.interfaces.IInventorySlotAware;
|
||||
import appeng.tile.networking.WirelessBlockEntity;
|
||||
|
||||
public class WirelessTerminalGuiObject implements IPortableCell, IActionHost, IInventorySlotAware {
|
||||
|
||||
private final ItemStack effectiveItem;
|
||||
private final IWirelessTermHandler wth;
|
||||
private final String encryptionKey;
|
||||
private final PlayerEntity myPlayer;
|
||||
private IGrid targetGrid;
|
||||
private IStorageGrid sg;
|
||||
private IMEMonitor<IAEItemStack> itemStorage;
|
||||
private IWirelessAccessPoint myWap;
|
||||
private double sqRange = Double.MAX_VALUE;
|
||||
private double myRange = Double.MAX_VALUE;
|
||||
private final int inventorySlot;
|
||||
|
||||
public WirelessTerminalGuiObject(final IWirelessTermHandler wh, final ItemStack is, final PlayerEntity ep,
|
||||
int inventorySlot) {
|
||||
this.encryptionKey = wh.getEncryptionKey(is);
|
||||
this.effectiveItem = is;
|
||||
this.myPlayer = ep;
|
||||
this.wth = wh;
|
||||
this.inventorySlot = inventorySlot;
|
||||
|
||||
ILocatable obj = null;
|
||||
|
||||
try {
|
||||
final long encKey = Long.parseLong(this.encryptionKey);
|
||||
obj = AEApi.instance().registries().locatable().getLocatableBy(encKey);
|
||||
} catch (final NumberFormatException err) {
|
||||
// :P
|
||||
}
|
||||
|
||||
if (obj instanceof IActionHost) {
|
||||
final IGridNode n = ((IActionHost) obj).getActionableNode();
|
||||
if (n != null) {
|
||||
this.targetGrid = n.getGrid();
|
||||
if (this.targetGrid != null) {
|
||||
this.sg = this.targetGrid.getCache(IStorageGrid.class);
|
||||
if (this.sg != null) {
|
||||
this.itemStorage = this.sg
|
||||
.getInventory(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public double getRange() {
|
||||
return this.myRange;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends IAEStack<T>> IMEMonitor<T> getInventory(IStorageChannel<T> channel) {
|
||||
return this.sg.getInventory(channel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addListener(final IMEMonitorHandlerReceiver<IAEItemStack> l, final Object verificationToken) {
|
||||
if (this.itemStorage != null) {
|
||||
this.itemStorage.addListener(l, verificationToken);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeListener(final IMEMonitorHandlerReceiver<IAEItemStack> l) {
|
||||
if (this.itemStorage != null) {
|
||||
this.itemStorage.removeListener(l);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemList<IAEItemStack> getAvailableItems(final IItemList<IAEItemStack> out) {
|
||||
if (this.itemStorage != null) {
|
||||
return this.itemStorage.getAvailableItems(out);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemList<IAEItemStack> getStorageList() {
|
||||
if (this.itemStorage != null) {
|
||||
return this.itemStorage.getStorageList();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AccessRestriction getAccess() {
|
||||
if (this.itemStorage != null) {
|
||||
return this.itemStorage.getAccess();
|
||||
}
|
||||
return AccessRestriction.NO_ACCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPrioritized(final IAEItemStack input) {
|
||||
if (this.itemStorage != null) {
|
||||
return this.itemStorage.isPrioritized(input);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canAccept(final IAEItemStack input) {
|
||||
if (this.itemStorage != null) {
|
||||
return this.itemStorage.canAccept(input);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPriority() {
|
||||
if (this.itemStorage != null) {
|
||||
return this.itemStorage.getPriority();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlot() {
|
||||
if (this.itemStorage != null) {
|
||||
return this.itemStorage.getSlot();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean validForPass(final int i) {
|
||||
return this.itemStorage.validForPass(i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack injectItems(final IAEItemStack input, final Actionable type, final IActionSource src) {
|
||||
if (this.itemStorage != null) {
|
||||
return this.itemStorage.injectItems(input, type, src);
|
||||
}
|
||||
return input;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack extractItems(final IAEItemStack request, final Actionable mode, final IActionSource src) {
|
||||
if (this.itemStorage != null) {
|
||||
return this.itemStorage.extractItems(request, mode, src);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IStorageChannel getChannel() {
|
||||
if (this.itemStorage != null) {
|
||||
return this.itemStorage.getChannel();
|
||||
}
|
||||
return AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double extractAEPower(final double amt, final Actionable mode, final PowerMultiplier usePowerMultiplier) {
|
||||
if (this.wth != null && this.effectiveItem != null) {
|
||||
if (mode == Actionable.SIMULATE) {
|
||||
return this.wth.hasPower(this.myPlayer, amt, this.effectiveItem) ? amt : 0;
|
||||
}
|
||||
return this.wth.usePower(this.myPlayer, amt, this.effectiveItem) ? amt : 0;
|
||||
}
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItemStack() {
|
||||
return this.effectiveItem;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IConfigManager getConfigManager() {
|
||||
return this.wth.getConfigManager(this.effectiveItem);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IGridNode getActionableNode() {
|
||||
this.rangeCheck();
|
||||
if (this.myWap != null) {
|
||||
return this.myWap.getActionableNode();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean rangeCheck() {
|
||||
this.sqRange = this.myRange = Double.MAX_VALUE;
|
||||
|
||||
if (this.targetGrid != null && this.itemStorage != null) {
|
||||
if (this.myWap != null) {
|
||||
if (this.myWap.getGrid() == this.targetGrid) {
|
||||
if (this.testWap(this.myWap)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
final IMachineSet tw = this.targetGrid.getMachines(WirelessBlockEntity.class);
|
||||
|
||||
this.myWap = null;
|
||||
|
||||
for (final IGridNode n : tw) {
|
||||
final IWirelessAccessPoint wap = (IWirelessAccessPoint) n.getMachine();
|
||||
if (this.testWap(wap)) {
|
||||
this.myWap = wap;
|
||||
}
|
||||
}
|
||||
|
||||
return this.myWap != null;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean testWap(final IWirelessAccessPoint wap) {
|
||||
double rangeLimit = wap.getRange();
|
||||
rangeLimit *= rangeLimit;
|
||||
|
||||
final DimensionalCoord dc = wap.getLocation();
|
||||
|
||||
if (dc.getWorld() == this.myPlayer.world) {
|
||||
final double offX = dc.x - this.myPlayer.getX();
|
||||
final double offY = dc.y - this.myPlayer.getY();
|
||||
final double offZ = dc.z - this.myPlayer.getZ();
|
||||
|
||||
final double r = offX * offX + offY * offY + offZ * offZ;
|
||||
if (r < rangeLimit && this.sqRange > r) {
|
||||
if (wap.isActive()) {
|
||||
this.sqRange = r;
|
||||
this.myRange = Math.sqrt(r);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventorySlot() {
|
||||
return this.inventorySlot;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user