pick 97420a31d The big reformat of 2020
This commit is contained in:
@@ -18,15 +18,13 @@
|
||||
|
||||
package appeng.helpers;
|
||||
|
||||
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.material.MaterialColor;
|
||||
import net.minecraft.block.material.PushReaction;
|
||||
|
||||
public class AEGlassMaterial {
|
||||
|
||||
public class AEGlassMaterial
|
||||
{
|
||||
|
||||
public static final Material INSTANCE = new Material( MaterialColor.AIR, false, false, true, false, true, false, false, PushReaction.NORMAL );
|
||||
public static final Material INSTANCE = new Material(MaterialColor.AIR, false, false, true, false, true, false,
|
||||
false, PushReaction.NORMAL);
|
||||
|
||||
}
|
||||
|
||||
@@ -18,13 +18,10 @@
|
||||
|
||||
package appeng.helpers;
|
||||
|
||||
|
||||
import appeng.api.implementations.tiles.IColorableTile;
|
||||
import appeng.api.networking.IGridHost;
|
||||
import appeng.api.parts.IPartHost;
|
||||
|
||||
|
||||
public interface AEMultiTile extends IGridHost, IPartHost, IColorableTile
|
||||
{
|
||||
public interface AEMultiTile extends IGridHost, IPartHost, IColorableTile {
|
||||
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -18,41 +18,38 @@
|
||||
|
||||
package appeng.helpers;
|
||||
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
import appeng.api.networking.IGridNode;
|
||||
import appeng.api.networking.security.IActionSource;
|
||||
|
||||
public interface IContainerCraftingPacket {
|
||||
|
||||
public interface IContainerCraftingPacket
|
||||
{
|
||||
/**
|
||||
* @return gain access to network infrastructure.
|
||||
*/
|
||||
IGridNode getNetworkNode();
|
||||
|
||||
/**
|
||||
* @return gain access to network infrastructure.
|
||||
*/
|
||||
IGridNode getNetworkNode();
|
||||
/**
|
||||
* @param string name of inventory
|
||||
*
|
||||
* @return the inventory of the part/tile by name.
|
||||
*/
|
||||
IItemHandler getInventoryByName(String string);
|
||||
|
||||
/**
|
||||
* @param string name of inventory
|
||||
*
|
||||
* @return the inventory of the part/tile by name.
|
||||
*/
|
||||
IItemHandler getInventoryByName( String string );
|
||||
/**
|
||||
* @return who are we?
|
||||
*/
|
||||
IActionSource getActionSource();
|
||||
|
||||
/**
|
||||
* @return who are we?
|
||||
*/
|
||||
IActionSource getActionSource();
|
||||
/**
|
||||
* @return consume items?
|
||||
*/
|
||||
boolean useRealItems();
|
||||
|
||||
/**
|
||||
* @return consume items?
|
||||
*/
|
||||
boolean useRealItems();
|
||||
|
||||
/**
|
||||
* @return array of view cells
|
||||
*/
|
||||
ItemStack[] getViewCells();
|
||||
/**
|
||||
* @return array of view cells
|
||||
*/
|
||||
ItemStack[] getViewCells();
|
||||
}
|
||||
|
||||
@@ -18,13 +18,11 @@
|
||||
|
||||
package appeng.helpers;
|
||||
|
||||
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
|
||||
public interface ICustomNameObject
|
||||
{
|
||||
public interface ICustomNameObject {
|
||||
|
||||
ITextComponent getCustomInventoryName();
|
||||
ITextComponent getCustomInventoryName();
|
||||
|
||||
boolean hasCustomInventoryName();
|
||||
boolean hasCustomInventoryName();
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.helpers;
|
||||
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
@@ -28,15 +27,13 @@ import appeng.api.implementations.IUpgradeableHost;
|
||||
import appeng.api.networking.crafting.ICraftingProvider;
|
||||
import appeng.api.networking.crafting.ICraftingRequester;
|
||||
|
||||
public interface IInterfaceHost extends ICraftingProvider, IUpgradeableHost, ICraftingRequester {
|
||||
|
||||
public interface IInterfaceHost extends ICraftingProvider, IUpgradeableHost, ICraftingRequester
|
||||
{
|
||||
DualityInterface getInterfaceDuality();
|
||||
|
||||
DualityInterface getInterfaceDuality();
|
||||
EnumSet<Direction> getTargets();
|
||||
|
||||
EnumSet<Direction> getTargets();
|
||||
TileEntity getTileEntity();
|
||||
|
||||
TileEntity getTileEntity();
|
||||
|
||||
void saveChanges();
|
||||
void saveChanges();
|
||||
}
|
||||
|
||||
@@ -18,12 +18,9 @@
|
||||
|
||||
package appeng.helpers;
|
||||
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public interface IMouseWheelItem {
|
||||
|
||||
public interface IMouseWheelItem
|
||||
{
|
||||
|
||||
void onWheel( ItemStack is, boolean up );
|
||||
void onWheel(ItemStack is, boolean up);
|
||||
}
|
||||
|
||||
@@ -18,31 +18,27 @@
|
||||
|
||||
package appeng.helpers;
|
||||
|
||||
|
||||
import net.minecraft.inventory.container.ContainerType;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public interface IPriorityHost {
|
||||
|
||||
/**
|
||||
* get current priority.
|
||||
*/
|
||||
int getPriority();
|
||||
|
||||
/**
|
||||
* set new priority
|
||||
*/
|
||||
void setPriority(int newValue);
|
||||
|
||||
public interface IPriorityHost
|
||||
{
|
||||
ItemStack getItemStackRepresentation();
|
||||
|
||||
/**
|
||||
* get current priority.
|
||||
*/
|
||||
int getPriority();
|
||||
|
||||
/**
|
||||
* set new priority
|
||||
*/
|
||||
void setPriority( int newValue );
|
||||
|
||||
ItemStack getItemStackRepresentation();
|
||||
|
||||
/**
|
||||
* Used to show the user interface of this part when returning from the priority GUI.
|
||||
*/
|
||||
ContainerType<?> getContainerType();
|
||||
/**
|
||||
* Used to show the user interface of this part when returning from the priority
|
||||
* GUI.
|
||||
*/
|
||||
ContainerType<?> getContainerType();
|
||||
|
||||
}
|
||||
|
||||
@@ -18,8 +18,9 @@
|
||||
|
||||
package appeng.helpers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import appeng.util.Platform;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.nbt.ListNBT;
|
||||
@@ -27,133 +28,110 @@ import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.StringTextComponent;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public class InvalidPatternHelper {
|
||||
|
||||
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;
|
||||
|
||||
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 CompoundNBT encodedValue = is.getTag();
|
||||
|
||||
public InvalidPatternHelper( final ItemStack is )
|
||||
{
|
||||
final CompoundNBT encodedValue = is.getTag();
|
||||
if (encodedValue == null) {
|
||||
throw new IllegalArgumentException("No pattern here!");
|
||||
}
|
||||
|
||||
if( encodedValue == null )
|
||||
{
|
||||
throw new IllegalArgumentException( "No pattern here!" );
|
||||
}
|
||||
final ListNBT inTag = encodedValue.getList("in", 10);
|
||||
final ListNBT outTag = encodedValue.getList("out", 10);
|
||||
this.isCrafting = encodedValue.getBoolean("crafting");
|
||||
|
||||
final ListNBT inTag = encodedValue.getList( "in", 10 );
|
||||
final ListNBT outTag = encodedValue.getList( "out", 10 );
|
||||
this.isCrafting = encodedValue.getBoolean( "crafting" );
|
||||
this.canSubstitute = this.isCrafting && encodedValue.getBoolean("substitute");
|
||||
|
||||
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 < outTag.size(); i++ )
|
||||
{
|
||||
this.outputs.add( new PatternIngredient( outTag.getCompound( i ) ) );
|
||||
}
|
||||
for (int i = 0; i < inTag.size(); i++) {
|
||||
CompoundNBT in = inTag.getCompound(i);
|
||||
|
||||
for( int i = 0; i < inTag.size(); i++ )
|
||||
{
|
||||
CompoundNBT in = inTag.getCompound( i );
|
||||
// skip empty slots in the crafting grid
|
||||
if (in.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// skip empty slots in the crafting grid
|
||||
if( in.isEmpty() )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
this.inputs.add(new PatternIngredient(in));
|
||||
}
|
||||
}
|
||||
|
||||
this.inputs.add( new PatternIngredient( in ) );
|
||||
}
|
||||
}
|
||||
public List<PatternIngredient> getOutputs() {
|
||||
return this.outputs;
|
||||
}
|
||||
|
||||
public List<PatternIngredient> getOutputs()
|
||||
{
|
||||
return this.outputs;
|
||||
}
|
||||
public List<PatternIngredient> getInputs() {
|
||||
return this.inputs;
|
||||
}
|
||||
|
||||
public List<PatternIngredient> getInputs()
|
||||
{
|
||||
return this.inputs;
|
||||
}
|
||||
public boolean isCraftable() {
|
||||
return this.isCrafting;
|
||||
}
|
||||
|
||||
public boolean isCraftable()
|
||||
{
|
||||
return this.isCrafting;
|
||||
}
|
||||
public boolean canSubstitute() {
|
||||
return this.canSubstitute;
|
||||
}
|
||||
|
||||
public boolean canSubstitute()
|
||||
{
|
||||
return this.canSubstitute;
|
||||
}
|
||||
public class PatternIngredient {
|
||||
private String id;
|
||||
private int count;
|
||||
private int damage;
|
||||
|
||||
public class PatternIngredient
|
||||
{
|
||||
private String id;
|
||||
private int count;
|
||||
private int damage;
|
||||
private ItemStack stack;
|
||||
|
||||
private ItemStack stack;
|
||||
public PatternIngredient(CompoundNBT tag) {
|
||||
this.stack = ItemStack.read(tag);
|
||||
|
||||
public PatternIngredient( CompoundNBT tag )
|
||||
{
|
||||
this.stack = ItemStack.read( tag );
|
||||
if (this.stack.isEmpty()) {
|
||||
this.id = tag.getString("id");
|
||||
this.count = tag.getByte("Count");
|
||||
this.damage = Math.max(0, tag.getShort("Damage"));
|
||||
}
|
||||
}
|
||||
|
||||
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 boolean isValid()
|
||||
{
|
||||
return !this.stack.isEmpty();
|
||||
}
|
||||
public ITextComponent getName() {
|
||||
return this.isValid() ? Platform.getItemDisplayName(this.stack)
|
||||
: new StringTextComponent(this.id + '@' + this.getDamage());
|
||||
}
|
||||
|
||||
public ITextComponent getName()
|
||||
{
|
||||
return this.isValid() ? Platform.getItemDisplayName( this.stack )
|
||||
: new StringTextComponent(this.id + '@' + this.getDamage());
|
||||
}
|
||||
public int getDamage() {
|
||||
return this.isValid() ? this.stack.getDamage() : this.damage;
|
||||
}
|
||||
|
||||
public int getDamage()
|
||||
{
|
||||
return this.isValid() ? this.stack.getDamage() : this.damage;
|
||||
}
|
||||
public int getCount() {
|
||||
return this.isValid() ? this.stack.getCount() : this.count;
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
public ItemStack getItem()
|
||||
{
|
||||
if( !this.isValid() )
|
||||
{
|
||||
throw new IllegalArgumentException( "There is no valid ItemStack for this PatternIngredient" );
|
||||
}
|
||||
return this.stack;
|
||||
}
|
||||
|
||||
return this.stack;
|
||||
}
|
||||
public ITextComponent getFormattedToolTip() {
|
||||
ITextComponent result = new StringTextComponent(this.getCount() + " ").appendSibling(this.getName());
|
||||
|
||||
public ITextComponent getFormattedToolTip()
|
||||
{
|
||||
ITextComponent result = new StringTextComponent( this.getCount() + " " ).appendSibling( this.getName() );
|
||||
if (!this.isValid()) {
|
||||
result.applyTextStyle(TextFormatting.RED);
|
||||
}
|
||||
|
||||
if( !this.isValid() )
|
||||
{
|
||||
result.applyTextStyle(TextFormatting.RED);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,30 +18,16 @@
|
||||
|
||||
package appeng.helpers;
|
||||
|
||||
public enum InventoryAction {
|
||||
// standard vanilla mechanics.
|
||||
PICKUP_OR_SET_DOWN, SPLIT_OR_PLACE_SINGLE, CREATIVE_DUPLICATE, SHIFT_CLICK,
|
||||
|
||||
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,
|
||||
|
||||
// crafting term
|
||||
CRAFT_STACK,
|
||||
CRAFT_ITEM,
|
||||
CRAFT_SHIFT,
|
||||
// fluid term
|
||||
FILL_ITEM, EMPTY_ITEM,
|
||||
|
||||
// fluid term
|
||||
FILL_ITEM,
|
||||
EMPTY_ITEM,
|
||||
|
||||
// extra...
|
||||
MOVE_REGION,
|
||||
PICKUP_SINGLE,
|
||||
UPDATE_HAND,
|
||||
ROLL_UP,
|
||||
ROLL_DOWN,
|
||||
AUTO_CRAFT,
|
||||
PLACE_SINGLE
|
||||
// extra...
|
||||
MOVE_REGION, PICKUP_SINGLE, UPDATE_HAND, ROLL_UP, ROLL_DOWN, AUTO_CRAFT, PLACE_SINGLE
|
||||
}
|
||||
|
||||
@@ -18,55 +18,46 @@
|
||||
|
||||
package appeng.helpers;
|
||||
|
||||
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.world.IBlockReader;
|
||||
|
||||
import appeng.api.util.IOrientable;
|
||||
|
||||
public class LocationRotation implements IOrientable {
|
||||
|
||||
public class LocationRotation implements IOrientable
|
||||
{
|
||||
private final IBlockReader w;
|
||||
private final int x;
|
||||
private final int y;
|
||||
private final int z;
|
||||
|
||||
private final IBlockReader w;
|
||||
private final int x;
|
||||
private final int y;
|
||||
private final int z;
|
||||
public LocationRotation(final IBlockReader world, final int x, final int y, final int z) {
|
||||
this.w = world;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
public LocationRotation( final IBlockReader world, final int x, final int y, final int z )
|
||||
{
|
||||
this.w = world;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
@Override
|
||||
public boolean canBeRotated() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBeRotated()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public Direction getForward() {
|
||||
if (this.getUp().getYOffset() == 0) {
|
||||
return Direction.UP;
|
||||
}
|
||||
return Direction.SOUTH;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Direction getForward()
|
||||
{
|
||||
if( this.getUp().getYOffset() == 0 )
|
||||
{
|
||||
return Direction.UP;
|
||||
}
|
||||
return Direction.SOUTH;
|
||||
}
|
||||
@Override
|
||||
public Direction getUp() {
|
||||
final int num = Math.abs(this.x + this.y + this.z) % 6;
|
||||
return Direction.values()[num];
|
||||
}
|
||||
|
||||
@Override
|
||||
public Direction getUp()
|
||||
{
|
||||
final int num = Math.abs( this.x + this.y + this.z ) % 6;
|
||||
return Direction.values()[num];
|
||||
}
|
||||
@Override
|
||||
public void setOrientation(final Direction forward, final Direction up) {
|
||||
|
||||
@Override
|
||||
public void setOrientation( final Direction forward, final Direction up )
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.helpers;
|
||||
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.state.Property;
|
||||
import net.minecraft.util.Direction;
|
||||
@@ -30,82 +29,68 @@ import net.minecraft.world.World;
|
||||
import appeng.api.util.IOrientable;
|
||||
import appeng.decorative.solid.BlockQuartzPillar;
|
||||
|
||||
public class MetaRotation implements IOrientable {
|
||||
|
||||
public class MetaRotation implements IOrientable
|
||||
{
|
||||
private final Property<Direction> facingProp;
|
||||
private final IBlockReader w;
|
||||
private final BlockPos pos;
|
||||
|
||||
private final Property<Direction> facingProp;
|
||||
private final IBlockReader w;
|
||||
private final BlockPos pos;
|
||||
public MetaRotation(final IBlockReader world, final BlockPos pos, final Property<Direction> facingProp) {
|
||||
this.w = world;
|
||||
this.pos = pos;
|
||||
this.facingProp = facingProp;
|
||||
}
|
||||
|
||||
public MetaRotation( final IBlockReader world, final BlockPos pos, final Property<Direction> facingProp )
|
||||
{
|
||||
this.w = world;
|
||||
this.pos = pos;
|
||||
this.facingProp = facingProp;
|
||||
}
|
||||
@Override
|
||||
public boolean canBeRotated() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBeRotated()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public Direction getForward() {
|
||||
if (this.getUp().getYOffset() == 0) {
|
||||
return Direction.UP;
|
||||
}
|
||||
return Direction.SOUTH;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Direction getForward()
|
||||
{
|
||||
if( this.getUp().getYOffset() == 0 )
|
||||
{
|
||||
return Direction.UP;
|
||||
}
|
||||
return Direction.SOUTH;
|
||||
}
|
||||
@Override
|
||||
public Direction getUp() {
|
||||
final BlockState state = this.w.getBlockState(this.pos);
|
||||
|
||||
@Override
|
||||
public Direction getUp()
|
||||
{
|
||||
final BlockState state = this.w.getBlockState( this.pos );
|
||||
if (this.facingProp != null && state.has(this.facingProp)) {
|
||||
return state.get(this.facingProp);
|
||||
}
|
||||
|
||||
if( this.facingProp != null && state.has(this.facingProp) )
|
||||
{
|
||||
return state.get( this.facingProp );
|
||||
}
|
||||
// TODO 1.10.2-R - Temp
|
||||
if (state.has(BlockQuartzPillar.AXIS)) {
|
||||
Axis a = state.get(BlockQuartzPillar.AXIS);
|
||||
switch (a) {
|
||||
case X:
|
||||
return Direction.EAST;
|
||||
case Z:
|
||||
return Direction.SOUTH;
|
||||
default:
|
||||
case Y:
|
||||
return Direction.UP;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO 1.10.2-R - Temp
|
||||
if (state.has(BlockQuartzPillar.AXIS)) {
|
||||
Axis a = state.get(BlockQuartzPillar.AXIS);
|
||||
switch (a) {
|
||||
case X:
|
||||
return Direction.EAST;
|
||||
case Z:
|
||||
return Direction.SOUTH;
|
||||
default:
|
||||
case Y:
|
||||
return Direction.UP;
|
||||
}
|
||||
}
|
||||
return Direction.UP;
|
||||
}
|
||||
|
||||
return Direction.UP;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOrientation( final Direction forward, final Direction up )
|
||||
{
|
||||
if( this.w instanceof World )
|
||||
{
|
||||
if( this.facingProp != null )
|
||||
{
|
||||
( (World) this.w ).setBlockState( this.pos, this.w.getBlockState( this.pos ).with( this.facingProp, up ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO 1.10.2-R - Temp
|
||||
( (World) this.w ).setBlockState( this.pos, this.w.getBlockState( this.pos ).with( BlockQuartzPillar.AXIS, up.getAxis() ) );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new IllegalStateException( this.w.getClass().getName() + " received, expected World" );
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void setOrientation(final Direction forward, final Direction up) {
|
||||
if (this.w instanceof World) {
|
||||
if (this.facingProp != null) {
|
||||
((World) this.w).setBlockState(this.pos, this.w.getBlockState(this.pos).with(this.facingProp, up));
|
||||
} else {
|
||||
// TODO 1.10.2-R - Temp
|
||||
((World) this.w).setBlockState(this.pos,
|
||||
this.w.getBlockState(this.pos).with(BlockQuartzPillar.AXIS, up.getAxis()));
|
||||
}
|
||||
} else {
|
||||
throw new IllegalStateException(this.w.getClass().getName() + " received, expected World");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.helpers;
|
||||
|
||||
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
@@ -37,255 +36,197 @@ import appeng.api.networking.security.IActionSource;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.util.InventoryAdaptor;
|
||||
|
||||
public class MultiCraftingTracker {
|
||||
|
||||
public class MultiCraftingTracker
|
||||
{
|
||||
private final int size;
|
||||
private final ICraftingRequester owner;
|
||||
|
||||
private final int size;
|
||||
private final ICraftingRequester owner;
|
||||
private Future<ICraftingJob>[] jobs = null;
|
||||
private ICraftingLink[] links = null;
|
||||
|
||||
private Future<ICraftingJob>[] jobs = null;
|
||||
private ICraftingLink[] links = null;
|
||||
public MultiCraftingTracker(final ICraftingRequester o, final int size) {
|
||||
this.owner = o;
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
public MultiCraftingTracker( final ICraftingRequester o, final int size )
|
||||
{
|
||||
this.owner = o;
|
||||
this.size = size;
|
||||
}
|
||||
public void readFromNBT(final CompoundNBT extra) {
|
||||
for (int x = 0; x < this.size; x++) {
|
||||
final CompoundNBT link = extra.getCompound("links-" + x);
|
||||
|
||||
public void readFromNBT( final CompoundNBT extra )
|
||||
{
|
||||
for( int x = 0; x < this.size; x++ )
|
||||
{
|
||||
final CompoundNBT link = extra.getCompound( "links-" + x );
|
||||
if (link != null && !link.isEmpty()) {
|
||||
this.setLink(x, AEApi.instance().storage().loadCraftingLink(link, this.owner));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( link != null && !link.isEmpty() )
|
||||
{
|
||||
this.setLink( x, AEApi.instance().storage().loadCraftingLink( link, this.owner ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
public void writeToNBT(final CompoundNBT extra) {
|
||||
for (int x = 0; x < this.size; x++) {
|
||||
final ICraftingLink link = this.getLink(x);
|
||||
|
||||
public void writeToNBT( final CompoundNBT extra )
|
||||
{
|
||||
for( int x = 0; x < this.size; x++ )
|
||||
{
|
||||
final ICraftingLink link = this.getLink( x );
|
||||
if (link != null) {
|
||||
final CompoundNBT ln = new CompoundNBT();
|
||||
link.writeToNBT(ln);
|
||||
extra.put("links-" + x, ln);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( link != null )
|
||||
{
|
||||
final CompoundNBT ln = new CompoundNBT();
|
||||
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);
|
||||
|
||||
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) {
|
||||
|
||||
if( this.getLink( x ) != null )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if( craftingJob != null )
|
||||
{
|
||||
try {
|
||||
ICraftingJob job = null;
|
||||
if (craftingJob.isDone()) {
|
||||
job = craftingJob.get();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
ICraftingJob job = null;
|
||||
if( craftingJob.isDone() )
|
||||
{
|
||||
job = craftingJob.get();
|
||||
}
|
||||
if (job != null) {
|
||||
final ICraftingLink link = cg.submitJob(job, this.owner, null, false, mySrc);
|
||||
|
||||
if( job != null )
|
||||
{
|
||||
final ICraftingLink link = cg.submitJob( job, this.owner, null, false, mySrc );
|
||||
this.setJob(x, null);
|
||||
|
||||
this.setJob( x, null );
|
||||
if (link != null) {
|
||||
this.setLink(x, link);
|
||||
|
||||
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);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
this.setJob( x, cg.beginCraftingJob( w, g, mySrc, aisC, null ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public ImmutableSet<ICraftingLink> getRequestedJobs() {
|
||||
if (this.links == null) {
|
||||
return ImmutableSet.of();
|
||||
}
|
||||
|
||||
public ImmutableSet<ICraftingLink> getRequestedJobs()
|
||||
{
|
||||
if( this.links == null )
|
||||
{
|
||||
return ImmutableSet.of();
|
||||
}
|
||||
return ImmutableSet.copyOf(new NonNullArrayIterator<>(this.links));
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
void cancel() {
|
||||
if (this.links != null) {
|
||||
for (final ICraftingLink l : this.links) {
|
||||
if (l != null) {
|
||||
l.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
void cancel()
|
||||
{
|
||||
if( this.links != null )
|
||||
{
|
||||
for( final ICraftingLink l : this.links )
|
||||
{
|
||||
if( l != null )
|
||||
{
|
||||
l.cancel();
|
||||
}
|
||||
}
|
||||
this.links = null;
|
||||
}
|
||||
|
||||
this.links = null;
|
||||
}
|
||||
if (this.jobs != null) {
|
||||
for (final Future<ICraftingJob> l : this.jobs) {
|
||||
if (l != null) {
|
||||
l.cancel(true);
|
||||
}
|
||||
}
|
||||
|
||||
if( this.jobs != null )
|
||||
{
|
||||
for( final Future<ICraftingJob> l : this.jobs )
|
||||
{
|
||||
if( l != null )
|
||||
{
|
||||
l.cancel( true );
|
||||
}
|
||||
}
|
||||
this.jobs = null;
|
||||
}
|
||||
}
|
||||
|
||||
this.jobs = null;
|
||||
}
|
||||
}
|
||||
boolean isBusy(final int slot) {
|
||||
return this.getLink(slot) != null || this.getJob(slot) != 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;
|
||||
}
|
||||
|
||||
private ICraftingLink getLink( final int slot )
|
||||
{
|
||||
if( this.links == null )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return this.links[slot];
|
||||
}
|
||||
|
||||
return this.links[slot];
|
||||
}
|
||||
private void setLink(final int slot, final ICraftingLink l) {
|
||||
if (this.links == null) {
|
||||
this.links = new ICraftingLink[this.size];
|
||||
}
|
||||
|
||||
private void setLink( final int slot, final ICraftingLink l )
|
||||
{
|
||||
if( this.links == null )
|
||||
{
|
||||
this.links = new ICraftingLink[this.size];
|
||||
}
|
||||
this.links[slot] = l;
|
||||
|
||||
this.links[slot] = l;
|
||||
boolean hasStuff = false;
|
||||
for (int x = 0; x < this.links.length; x++) {
|
||||
final ICraftingLink g = this.links[x];
|
||||
|
||||
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( g == null || g.isCanceled() || g.isDone() )
|
||||
{
|
||||
this.links[x] = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
hasStuff = true;
|
||||
}
|
||||
}
|
||||
if (!hasStuff) {
|
||||
this.links = null;
|
||||
}
|
||||
}
|
||||
|
||||
if( !hasStuff )
|
||||
{
|
||||
this.links = null;
|
||||
}
|
||||
}
|
||||
private Future<ICraftingJob> getJob(final int slot) {
|
||||
if (this.jobs == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
private Future<ICraftingJob> getJob( final int slot )
|
||||
{
|
||||
if( this.jobs == null )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return this.jobs[slot];
|
||||
}
|
||||
|
||||
return this.jobs[slot];
|
||||
}
|
||||
private void setJob(final int slot, final Future<ICraftingJob> l) {
|
||||
if (this.jobs == null) {
|
||||
this.jobs = new Future[this.size];
|
||||
}
|
||||
|
||||
private void setJob( final int slot, final Future<ICraftingJob> l )
|
||||
{
|
||||
if( this.jobs == null )
|
||||
{
|
||||
this.jobs = new Future[this.size];
|
||||
}
|
||||
this.jobs[slot] = l;
|
||||
|
||||
this.jobs[slot] = l;
|
||||
boolean hasStuff = false;
|
||||
|
||||
boolean hasStuff = false;
|
||||
for (final Future<ICraftingJob> job : this.jobs) {
|
||||
if (job != null) {
|
||||
hasStuff = true;
|
||||
}
|
||||
}
|
||||
|
||||
for( final Future<ICraftingJob> job : this.jobs )
|
||||
{
|
||||
if( job != null )
|
||||
{
|
||||
hasStuff = true;
|
||||
}
|
||||
}
|
||||
|
||||
if( !hasStuff )
|
||||
{
|
||||
this.jobs = null;
|
||||
}
|
||||
}
|
||||
if (!hasStuff) {
|
||||
this.jobs = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,44 +18,36 @@
|
||||
|
||||
package appeng.helpers;
|
||||
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
public class NonNullArrayIterator<E> implements Iterator<E> {
|
||||
|
||||
public class NonNullArrayIterator<E> implements Iterator<E>
|
||||
{
|
||||
private final E[] g;
|
||||
private int offset = 0;
|
||||
|
||||
private final E[] g;
|
||||
private int offset = 0;
|
||||
public NonNullArrayIterator(final E[] o) {
|
||||
this.g = o;
|
||||
}
|
||||
|
||||
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++;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext()
|
||||
{
|
||||
while( this.offset < this.g.length && this.g[this.offset] == null )
|
||||
{
|
||||
this.offset++;
|
||||
}
|
||||
return this.offset != this.g.length;
|
||||
}
|
||||
|
||||
return this.offset != this.g.length;
|
||||
}
|
||||
@Override
|
||||
public E next() {
|
||||
final E result = this.g[this.offset];
|
||||
this.offset++;
|
||||
|
||||
@Override
|
||||
public E next()
|
||||
{
|
||||
final E result = this.g[this.offset];
|
||||
this.offset++;
|
||||
return result;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove()
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
@Override
|
||||
public void remove() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,41 +18,33 @@
|
||||
|
||||
package appeng.helpers;
|
||||
|
||||
|
||||
import net.minecraft.util.Direction;
|
||||
|
||||
import appeng.api.util.IOrientable;
|
||||
|
||||
public class NullRotation implements IOrientable {
|
||||
|
||||
public class NullRotation implements IOrientable
|
||||
{
|
||||
public NullRotation() {
|
||||
|
||||
public NullRotation()
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
public boolean canBeRotated() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBeRotated()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public Direction getForward() {
|
||||
return Direction.SOUTH;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Direction getForward()
|
||||
{
|
||||
return Direction.SOUTH;
|
||||
}
|
||||
@Override
|
||||
public Direction getUp() {
|
||||
return Direction.UP;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Direction getUp()
|
||||
{
|
||||
return Direction.UP;
|
||||
}
|
||||
@Override
|
||||
public void setOrientation(final Direction forward, final Direction up) {
|
||||
|
||||
@Override
|
||||
public void setOrientation( final Direction forward, final Direction up )
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,14 +18,8 @@
|
||||
|
||||
package appeng.helpers;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
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;
|
||||
import net.minecraft.inventory.CraftingInventory;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -35,417 +29,352 @@ import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.nbt.ListNBT;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
||||
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 ICraftingRecipe 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 CompoundNBT encodedValue = is.getTag();
|
||||
|
||||
if( encodedValue == null )
|
||||
{
|
||||
throw new IllegalArgumentException( "No pattern here!" );
|
||||
}
|
||||
|
||||
final ListNBT inTag = encodedValue.getList( "in", 10 );
|
||||
final ListNBT 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++ )
|
||||
{
|
||||
CompoundNBT ingredient = inTag.getCompound( x );
|
||||
final ItemStack gs = ItemStack.read( ingredient );
|
||||
|
||||
if( !ingredient.isEmpty() && gs.isEmpty() )
|
||||
{
|
||||
throw new IllegalArgumentException( "No pattern here!" );
|
||||
}
|
||||
|
||||
this.crafting.setInventorySlotContents( 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.setInventorySlotContents( x, gs );
|
||||
}
|
||||
|
||||
if( this.isCrafting )
|
||||
{
|
||||
this.standardRecipe = w.getRecipeManager().getRecipe( IRecipeType.CRAFTING, this.crafting, w ).orElse( null );
|
||||
|
||||
if( this.standardRecipe != null )
|
||||
{
|
||||
this.correctOutput = this.standardRecipe.getCraftingResult( 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++ )
|
||||
{
|
||||
CompoundNBT resultItemTag = outTag.getCompound( x );
|
||||
final ItemStack gs = ItemStack.read( 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.getSizeInventory(); x++ )
|
||||
{
|
||||
this.testFrame.setInventorySlotContents( x, this.crafting.getStackInSlot( x ) );
|
||||
}
|
||||
|
||||
this.testFrame.setInventorySlotContents( slotIndex, i );
|
||||
|
||||
if( this.standardRecipe.matches( this.testFrame, w ) )
|
||||
{
|
||||
final ItemStack testOutput = this.standardRecipe.getCraftingResult( this.testFrame );
|
||||
|
||||
if( Platform.itemComparisons().isSameItem( this.correctOutput, testOutput ) )
|
||||
{
|
||||
this.testFrame.setInventorySlotContents( slotIndex, this.crafting.getStackInSlot( 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.getSizeInventory(); x++ )
|
||||
{
|
||||
if( !this.isValidItemForSlot( x, craftingInv.getStackInSlot( 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.getStackInSlot( 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.getIdFromItem( 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;
|
||||
}
|
||||
}
|
||||
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 ICraftingRecipe 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 CompoundNBT encodedValue = is.getTag();
|
||||
|
||||
if (encodedValue == null) {
|
||||
throw new IllegalArgumentException("No pattern here!");
|
||||
}
|
||||
|
||||
final ListNBT inTag = encodedValue.getList("in", 10);
|
||||
final ListNBT 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++) {
|
||||
CompoundNBT ingredient = inTag.getCompound(x);
|
||||
final ItemStack gs = ItemStack.read(ingredient);
|
||||
|
||||
if (!ingredient.isEmpty() && gs.isEmpty()) {
|
||||
throw new IllegalArgumentException("No pattern here!");
|
||||
}
|
||||
|
||||
this.crafting.setInventorySlotContents(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.setInventorySlotContents(x, gs);
|
||||
}
|
||||
|
||||
if (this.isCrafting) {
|
||||
this.standardRecipe = w.getRecipeManager().getRecipe(IRecipeType.CRAFTING, this.crafting, w).orElse(null);
|
||||
|
||||
if (this.standardRecipe != null) {
|
||||
this.correctOutput = this.standardRecipe.getCraftingResult(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++) {
|
||||
CompoundNBT resultItemTag = outTag.getCompound(x);
|
||||
final ItemStack gs = ItemStack.read(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.getSizeInventory(); x++) {
|
||||
this.testFrame.setInventorySlotContents(x, this.crafting.getStackInSlot(x));
|
||||
}
|
||||
|
||||
this.testFrame.setInventorySlotContents(slotIndex, i);
|
||||
|
||||
if (this.standardRecipe.matches(this.testFrame, w)) {
|
||||
final ItemStack testOutput = this.standardRecipe.getCraftingResult(this.testFrame);
|
||||
|
||||
if (Platform.itemComparisons().isSameItem(this.correctOutput, testOutput)) {
|
||||
this.testFrame.setInventorySlotContents(slotIndex, this.crafting.getStackInSlot(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.getSizeInventory(); x++) {
|
||||
if (!this.isValidItemForSlot(x, craftingInv.getStackInSlot(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.getStackInSlot(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.getIdFromItem(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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,27 +18,22 @@
|
||||
|
||||
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 {
|
||||
|
||||
public class PlayerSecurityWrapper implements ISecurityRegistry
|
||||
{
|
||||
private final Map<Integer, EnumSet<SecurityPermissions>> target;
|
||||
|
||||
private final Map<Integer, EnumSet<SecurityPermissions>> target;
|
||||
public PlayerSecurityWrapper(final Map<Integer, EnumSet<SecurityPermissions>> playerPerms) {
|
||||
this.target = playerPerms;
|
||||
}
|
||||
|
||||
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 );
|
||||
}
|
||||
@Override
|
||||
public void addPlayer(final int playerID, final EnumSet<SecurityPermissions> permissions) {
|
||||
this.target.put(playerID, permissions);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,19 +18,16 @@
|
||||
|
||||
package appeng.helpers;
|
||||
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
|
||||
/**
|
||||
* Marker interface to help identify invocation of reflection
|
||||
*/
|
||||
@Retention( RetentionPolicy.SOURCE )
|
||||
@Target( { ElementType.CONSTRUCTOR, ElementType.FIELD, ElementType.TYPE, ElementType.METHOD } )
|
||||
public @interface Reflected
|
||||
{
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@Target({ ElementType.CONSTRUCTOR, ElementType.FIELD, ElementType.TYPE, ElementType.METHOD })
|
||||
public @interface Reflected {
|
||||
|
||||
}
|
||||
|
||||
@@ -18,101 +18,86 @@
|
||||
|
||||
package appeng.helpers;
|
||||
|
||||
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
import appeng.api.util.AEColor;
|
||||
|
||||
public class Splotch {
|
||||
|
||||
public class Splotch
|
||||
{
|
||||
private final Direction side;
|
||||
private final boolean lumen;
|
||||
private final AEColor color;
|
||||
private final int pos;
|
||||
|
||||
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;
|
||||
|
||||
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;
|
||||
|
||||
final double x;
|
||||
final double y;
|
||||
if (side == Direction.SOUTH || side == Direction.NORTH) {
|
||||
x = position.x;
|
||||
y = position.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 if( side == Direction.UP || side == Direction.DOWN )
|
||||
{
|
||||
x = position.x;
|
||||
y = position.z;
|
||||
}
|
||||
else {
|
||||
x = position.y;
|
||||
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);
|
||||
|
||||
final int a = (int) ( x * 0xF );
|
||||
final int b = (int) ( y * 0xF );
|
||||
this.pos = a | ( b << 4 );
|
||||
this.side = side;
|
||||
}
|
||||
|
||||
this.side = side;
|
||||
}
|
||||
public Splotch(final PacketBuffer data) {
|
||||
|
||||
public Splotch( final PacketBuffer data )
|
||||
{
|
||||
this.pos = data.readByte();
|
||||
final int val = data.readByte();
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
this.side = Direction.values()[val & 0x07];
|
||||
this.color = AEColor.values()[( val >> 3 ) & 0x0F];
|
||||
this.lumen = ( ( val >> 7 ) & 0x01 ) > 0;
|
||||
}
|
||||
public void writeToStream(final PacketBuffer stream) {
|
||||
stream.writeByte(this.pos);
|
||||
final int val = this.getSide().ordinal() | (this.getColor().ordinal() << 3) | (this.isLumen() ? 0x80 : 0x00);
|
||||
stream.writeByte(val);
|
||||
}
|
||||
|
||||
public void writeToStream( final PacketBuffer 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 x()
|
||||
{
|
||||
return ( this.pos & 0x0f ) / 15.0f;
|
||||
}
|
||||
public float y() {
|
||||
return ((this.pos >> 4) & 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 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 Direction getSide()
|
||||
{
|
||||
return this.side;
|
||||
}
|
||||
public AEColor getColor() {
|
||||
return this.color;
|
||||
}
|
||||
|
||||
public AEColor getColor()
|
||||
{
|
||||
return this.color;
|
||||
}
|
||||
|
||||
public boolean isLumen()
|
||||
{
|
||||
return this.lumen;
|
||||
}
|
||||
public boolean isLumen() {
|
||||
return this.lumen;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.helpers;
|
||||
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
@@ -49,299 +48,245 @@ import appeng.api.util.IConfigManager;
|
||||
import appeng.container.interfaces.IInventorySlotAware;
|
||||
import appeng.tile.networking.TileWireless;
|
||||
|
||||
public class WirelessTerminalGuiObject implements IPortableCell, IActionHost, IInventorySlotAware {
|
||||
|
||||
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;
|
||||
|
||||
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;
|
||||
|
||||
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;
|
||||
|
||||
ILocatable obj = null;
|
||||
try {
|
||||
final long encKey = Long.parseLong(this.encryptionKey);
|
||||
obj = AEApi.instance().registries().locatable().getLocatableBy(encKey);
|
||||
} catch (final NumberFormatException err) {
|
||||
// :P
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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 <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 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 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> 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 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 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 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 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 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 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 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 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 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 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 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 ItemStack getItemStack()
|
||||
{
|
||||
return this.effectiveItem;
|
||||
}
|
||||
@Override
|
||||
public IConfigManager getConfigManager() {
|
||||
return this.wth.getConfigManager(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;
|
||||
}
|
||||
|
||||
@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;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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(TileWireless.class);
|
||||
|
||||
final IMachineSet tw = this.targetGrid.getMachines( TileWireless.class );
|
||||
this.myWap = null;
|
||||
|
||||
this.myWap = null;
|
||||
for (final IGridNode n : tw) {
|
||||
final IWirelessAccessPoint wap = (IWirelessAccessPoint) n.getMachine();
|
||||
if (this.testWap(wap)) {
|
||||
this.myWap = wap;
|
||||
}
|
||||
}
|
||||
|
||||
for( final IGridNode n : tw )
|
||||
{
|
||||
final IWirelessAccessPoint wap = (IWirelessAccessPoint) n.getMachine();
|
||||
if( this.testWap( wap ) )
|
||||
{
|
||||
this.myWap = wap;
|
||||
}
|
||||
}
|
||||
return this.myWap != null;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
return this.myWap != null;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
private boolean testWap(final IWirelessAccessPoint wap) {
|
||||
double rangeLimit = wap.getRange();
|
||||
rangeLimit *= rangeLimit;
|
||||
|
||||
private boolean testWap( final IWirelessAccessPoint wap )
|
||||
{
|
||||
double rangeLimit = wap.getRange();
|
||||
rangeLimit *= rangeLimit;
|
||||
final DimensionalCoord dc = wap.getLocation();
|
||||
|
||||
final DimensionalCoord dc = wap.getLocation();
|
||||
if (dc.getWorld() == this.myPlayer.world) {
|
||||
final double offX = dc.x - this.myPlayer.getPosX();
|
||||
final double offY = dc.y - this.myPlayer.getPosY();
|
||||
final double offZ = dc.z - this.myPlayer.getPosZ();
|
||||
|
||||
if( dc.getWorld() == this.myPlayer.world )
|
||||
{
|
||||
final double offX = dc.x - this.myPlayer.getPosX();
|
||||
final double offY = dc.y - this.myPlayer.getPosY();
|
||||
final double offZ = dc.z - this.myPlayer.getPosZ();
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
@Override
|
||||
public int getInventorySlot() {
|
||||
return this.inventorySlot;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user