pick 97420a31d The big reformat of 2020
This commit is contained in:
@@ -18,42 +18,35 @@
|
||||
|
||||
package appeng.parts.automation;
|
||||
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.BlockItem;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import appeng.api.config.Upgrades;
|
||||
import appeng.util.inv.IAEAppEngInventory;
|
||||
|
||||
public class BlockUpgradeInventory extends UpgradeInventory {
|
||||
private final Block block;
|
||||
|
||||
public class BlockUpgradeInventory extends UpgradeInventory
|
||||
{
|
||||
private final Block block;
|
||||
public BlockUpgradeInventory(final Block block, final IAEAppEngInventory parent, final int s) {
|
||||
super(parent, s);
|
||||
this.block = block;
|
||||
}
|
||||
|
||||
public BlockUpgradeInventory( final Block block, final IAEAppEngInventory parent, final int s )
|
||||
{
|
||||
super( parent, s );
|
||||
this.block = block;
|
||||
}
|
||||
@Override
|
||||
public int getMaxInstalled(final Upgrades upgrades) {
|
||||
int max = 0;
|
||||
|
||||
@Override
|
||||
public int getMaxInstalled( final Upgrades upgrades )
|
||||
{
|
||||
int max = 0;
|
||||
for (final ItemStack is : upgrades.getSupported().keySet()) {
|
||||
final Item encodedItem = is.getItem();
|
||||
|
||||
for( final ItemStack is : upgrades.getSupported().keySet() )
|
||||
{
|
||||
final Item encodedItem = is.getItem();
|
||||
if (encodedItem instanceof BlockItem && Block.getBlockFromItem(encodedItem) == this.block) {
|
||||
max = upgrades.getSupported().get(is);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if( encodedItem instanceof BlockItem && Block.getBlockFromItem( encodedItem ) == this.block )
|
||||
{
|
||||
max = upgrades.getSupported().get( is );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return max;
|
||||
}
|
||||
return max;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,39 +18,32 @@
|
||||
|
||||
package appeng.parts.automation;
|
||||
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import appeng.api.config.Upgrades;
|
||||
import appeng.api.definitions.IItemDefinition;
|
||||
import appeng.util.inv.IAEAppEngInventory;
|
||||
|
||||
public final class DefinitionUpgradeInventory extends UpgradeInventory {
|
||||
private final IItemDefinition definition;
|
||||
|
||||
public final class DefinitionUpgradeInventory extends UpgradeInventory
|
||||
{
|
||||
private final IItemDefinition definition;
|
||||
public DefinitionUpgradeInventory(final IItemDefinition definition, final IAEAppEngInventory parent, final int s) {
|
||||
super(parent, s);
|
||||
|
||||
public DefinitionUpgradeInventory( final IItemDefinition definition, final IAEAppEngInventory parent, final int s )
|
||||
{
|
||||
super( parent, s );
|
||||
this.definition = definition;
|
||||
}
|
||||
|
||||
this.definition = definition;
|
||||
}
|
||||
@Override
|
||||
public int getMaxInstalled(final Upgrades upgrades) {
|
||||
int max = 0;
|
||||
|
||||
@Override
|
||||
public int getMaxInstalled( final Upgrades upgrades )
|
||||
{
|
||||
int max = 0;
|
||||
for (final ItemStack stack : upgrades.getSupported().keySet()) {
|
||||
if (this.definition.isSameAs(stack)) {
|
||||
max = upgrades.getSupported().get(stack);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for( final ItemStack stack : upgrades.getSupported().keySet() )
|
||||
{
|
||||
if( this.definition.isSameAs( stack ) )
|
||||
{
|
||||
max = upgrades.getSupported().get( stack );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return max;
|
||||
}
|
||||
return max;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
|
||||
package appeng.parts.automation;
|
||||
|
||||
|
||||
import appeng.api.config.Settings;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
@@ -11,6 +9,7 @@ import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IBlockReader;
|
||||
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.config.Settings;
|
||||
import appeng.api.networking.security.IActionSource;
|
||||
import appeng.api.parts.IPart;
|
||||
import appeng.api.parts.IPartCollisionHelper;
|
||||
@@ -25,242 +24,211 @@ import appeng.api.util.AEPartLocation;
|
||||
import appeng.api.util.IConfigManager;
|
||||
import appeng.helpers.IPriorityHost;
|
||||
|
||||
public abstract class PartAbstractFormationPlane<T extends IAEStack<T>> extends PartUpgradeable
|
||||
implements ICellContainer, IPriorityHost, IMEInventory<T> {
|
||||
|
||||
public abstract class PartAbstractFormationPlane<T extends IAEStack<T>> extends PartUpgradeable implements ICellContainer, IPriorityHost, IMEInventory<T>
|
||||
{
|
||||
private boolean wasActive = false;
|
||||
private int priority = 0;
|
||||
protected boolean blocked = false;
|
||||
|
||||
private boolean wasActive = false;
|
||||
private int priority = 0;
|
||||
protected boolean blocked = false;
|
||||
public PartAbstractFormationPlane(ItemStack is) {
|
||||
super(is);
|
||||
}
|
||||
|
||||
public PartAbstractFormationPlane( ItemStack is )
|
||||
{
|
||||
super( is );
|
||||
}
|
||||
protected abstract void updateHandler();
|
||||
|
||||
protected abstract void updateHandler();
|
||||
@Override
|
||||
protected int getUpgradeSlots() {
|
||||
return 5;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getUpgradeSlots()
|
||||
{
|
||||
return 5;
|
||||
}
|
||||
@Override
|
||||
public void upgradesChanged() {
|
||||
this.updateHandler();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void upgradesChanged()
|
||||
{
|
||||
this.updateHandler();
|
||||
}
|
||||
@Override
|
||||
public void updateSetting(final IConfigManager manager, final Settings settingName, final Enum<?> newValue) {
|
||||
this.updateHandler();
|
||||
this.getHost().markForSave();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateSetting(final IConfigManager manager, final Settings settingName, final Enum<?> newValue )
|
||||
{
|
||||
this.updateHandler();
|
||||
this.getHost().markForSave();
|
||||
}
|
||||
public void stateChanged() {
|
||||
final boolean currentActive = this.getProxy().isActive();
|
||||
if (this.wasActive != currentActive) {
|
||||
this.wasActive = currentActive;
|
||||
this.updateHandler();
|
||||
this.getHost().markForUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
public void stateChanged()
|
||||
{
|
||||
final boolean currentActive = this.getProxy().isActive();
|
||||
if( this.wasActive != currentActive )
|
||||
{
|
||||
this.wasActive = currentActive;
|
||||
this.updateHandler();
|
||||
this.getHost().markForUpdate();
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void getBoxes(final IPartCollisionHelper bch) {
|
||||
int minX = 1;
|
||||
int minY = 1;
|
||||
int maxX = 15;
|
||||
int maxY = 15;
|
||||
|
||||
@Override
|
||||
public void getBoxes( final IPartCollisionHelper bch )
|
||||
{
|
||||
int minX = 1;
|
||||
int minY = 1;
|
||||
int maxX = 15;
|
||||
int maxY = 15;
|
||||
final IPartHost host = this.getHost();
|
||||
if (host != null) {
|
||||
final TileEntity te = host.getTile();
|
||||
|
||||
final IPartHost host = this.getHost();
|
||||
if( host != null )
|
||||
{
|
||||
final TileEntity te = host.getTile();
|
||||
final BlockPos pos = te.getPos();
|
||||
|
||||
final BlockPos pos = te.getPos();
|
||||
final Direction e = bch.getWorldX();
|
||||
final Direction u = bch.getWorldY();
|
||||
|
||||
final Direction e = bch.getWorldX();
|
||||
final Direction u = bch.getWorldY();
|
||||
if (this.isTransitionPlane(te.getWorld().getTileEntity(pos.offset(e.getOpposite())), this.getSide())) {
|
||||
minX = 0;
|
||||
}
|
||||
|
||||
if( this.isTransitionPlane( te.getWorld().getTileEntity( pos.offset( e.getOpposite() ) ), this.getSide() ) )
|
||||
{
|
||||
minX = 0;
|
||||
}
|
||||
if (this.isTransitionPlane(te.getWorld().getTileEntity(pos.offset(e)), this.getSide())) {
|
||||
maxX = 16;
|
||||
}
|
||||
|
||||
if( this.isTransitionPlane( te.getWorld().getTileEntity( pos.offset( e ) ), this.getSide() ) )
|
||||
{
|
||||
maxX = 16;
|
||||
}
|
||||
if (this.isTransitionPlane(te.getWorld().getTileEntity(pos.offset(u.getOpposite())), this.getSide())) {
|
||||
minY = 0;
|
||||
}
|
||||
|
||||
if( this.isTransitionPlane( te.getWorld().getTileEntity( pos.offset( u.getOpposite() ) ), this.getSide() ) )
|
||||
{
|
||||
minY = 0;
|
||||
}
|
||||
if (this.isTransitionPlane(te.getWorld().getTileEntity(pos.offset(u)), this.getSide())) {
|
||||
maxY = 16;
|
||||
}
|
||||
}
|
||||
|
||||
if( this.isTransitionPlane( te.getWorld().getTileEntity( pos.offset( u ) ), this.getSide() ) )
|
||||
{
|
||||
maxY = 16;
|
||||
}
|
||||
}
|
||||
bch.addBox(5, 5, 14, 11, 11, 15);
|
||||
bch.addBox(minX, minY, 15, maxX, maxY, 16);
|
||||
}
|
||||
|
||||
bch.addBox( 5, 5, 14, 11, 11, 15 );
|
||||
bch.addBox( minX, minY, 15, maxX, maxY, 16 );
|
||||
}
|
||||
public PlaneConnections getConnections() {
|
||||
|
||||
public PlaneConnections getConnections()
|
||||
{
|
||||
final Direction facingRight, facingUp;
|
||||
AEPartLocation location = this.getSide();
|
||||
switch (location) {
|
||||
case UP:
|
||||
facingRight = Direction.EAST;
|
||||
facingUp = Direction.NORTH;
|
||||
break;
|
||||
case DOWN:
|
||||
facingRight = Direction.WEST;
|
||||
facingUp = Direction.NORTH;
|
||||
break;
|
||||
case NORTH:
|
||||
facingRight = Direction.WEST;
|
||||
facingUp = Direction.UP;
|
||||
break;
|
||||
case SOUTH:
|
||||
facingRight = Direction.EAST;
|
||||
facingUp = Direction.UP;
|
||||
break;
|
||||
case WEST:
|
||||
facingRight = Direction.SOUTH;
|
||||
facingUp = Direction.UP;
|
||||
break;
|
||||
case EAST:
|
||||
facingRight = Direction.NORTH;
|
||||
facingUp = Direction.UP;
|
||||
break;
|
||||
default:
|
||||
case INTERNAL:
|
||||
return PlaneConnections.of(false, false, false, false);
|
||||
}
|
||||
|
||||
final Direction facingRight, facingUp;
|
||||
AEPartLocation location = this.getSide();
|
||||
switch( location )
|
||||
{
|
||||
case UP:
|
||||
facingRight = Direction.EAST;
|
||||
facingUp = Direction.NORTH;
|
||||
break;
|
||||
case DOWN:
|
||||
facingRight = Direction.WEST;
|
||||
facingUp = Direction.NORTH;
|
||||
break;
|
||||
case NORTH:
|
||||
facingRight = Direction.WEST;
|
||||
facingUp = Direction.UP;
|
||||
break;
|
||||
case SOUTH:
|
||||
facingRight = Direction.EAST;
|
||||
facingUp = Direction.UP;
|
||||
break;
|
||||
case WEST:
|
||||
facingRight = Direction.SOUTH;
|
||||
facingUp = Direction.UP;
|
||||
break;
|
||||
case EAST:
|
||||
facingRight = Direction.NORTH;
|
||||
facingUp = Direction.UP;
|
||||
break;
|
||||
default:
|
||||
case INTERNAL:
|
||||
return PlaneConnections.of( false, false, false, false );
|
||||
}
|
||||
boolean left = false, right = false, down = false, up = false;
|
||||
|
||||
boolean left = false, right = false, down = false, up = false;
|
||||
final IPartHost host = this.getHost();
|
||||
if (host != null) {
|
||||
final TileEntity te = host.getTile();
|
||||
|
||||
final IPartHost host = this.getHost();
|
||||
if( host != null )
|
||||
{
|
||||
final TileEntity te = host.getTile();
|
||||
final BlockPos pos = te.getPos();
|
||||
|
||||
final BlockPos pos = te.getPos();
|
||||
if (this.isTransitionPlane(te.getWorld().getTileEntity(pos.offset(facingRight.getOpposite())),
|
||||
this.getSide())) {
|
||||
left = true;
|
||||
}
|
||||
|
||||
if( this.isTransitionPlane( te.getWorld().getTileEntity( pos.offset( facingRight.getOpposite() ) ), this.getSide() ) )
|
||||
{
|
||||
left = true;
|
||||
}
|
||||
if (this.isTransitionPlane(te.getWorld().getTileEntity(pos.offset(facingRight)), this.getSide())) {
|
||||
right = true;
|
||||
}
|
||||
|
||||
if( this.isTransitionPlane( te.getWorld().getTileEntity( pos.offset( facingRight ) ), this.getSide() ) )
|
||||
{
|
||||
right = true;
|
||||
}
|
||||
if (this.isTransitionPlane(te.getWorld().getTileEntity(pos.offset(facingUp.getOpposite())),
|
||||
this.getSide())) {
|
||||
down = true;
|
||||
}
|
||||
|
||||
if( this.isTransitionPlane( te.getWorld().getTileEntity( pos.offset( facingUp.getOpposite() ) ), this.getSide() ) )
|
||||
{
|
||||
down = true;
|
||||
}
|
||||
if (this.isTransitionPlane(te.getWorld().getTileEntity(pos.offset(facingUp)), this.getSide())) {
|
||||
up = true;
|
||||
}
|
||||
}
|
||||
|
||||
if( this.isTransitionPlane( te.getWorld().getTileEntity( pos.offset( facingUp ) ), this.getSide() ) )
|
||||
{
|
||||
up = true;
|
||||
}
|
||||
}
|
||||
return PlaneConnections.of(up, right, down, left);
|
||||
}
|
||||
|
||||
return PlaneConnections.of( up, right, down, left );
|
||||
}
|
||||
@Override
|
||||
public void onNeighborChanged(IBlockReader w, BlockPos pos, BlockPos neighbor) {
|
||||
if (pos.offset(this.getSide().getFacing()).equals(neighbor)) {
|
||||
final TileEntity te = this.getHost().getTile();
|
||||
final AEPartLocation side = this.getSide();
|
||||
|
||||
@Override
|
||||
public void onNeighborChanged( IBlockReader w, BlockPos pos, BlockPos neighbor )
|
||||
{
|
||||
if( pos.offset( this.getSide().getFacing() ).equals( neighbor ) )
|
||||
{
|
||||
final TileEntity te = this.getHost().getTile();
|
||||
final AEPartLocation side = this.getSide();
|
||||
final BlockPos tePos = te.getPos().offset(side.getFacing());
|
||||
|
||||
final BlockPos tePos = te.getPos().offset( side.getFacing() );
|
||||
this.blocked = !w.getBlockState(tePos).getMaterial().isReplaceable();
|
||||
}
|
||||
}
|
||||
|
||||
this.blocked = !w.getBlockState( tePos ).getMaterial().isReplaceable();
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public float getCableConnectionLength(AECableType cable) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getCableConnectionLength( AECableType cable )
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
protected boolean isTransitionPlane(final TileEntity blockTileEntity, final AEPartLocation side) {
|
||||
if (blockTileEntity instanceof IPartHost) {
|
||||
final IPart p = ((IPartHost) blockTileEntity).getPart(side);
|
||||
return p != null && this.getClass() == p.getClass();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected boolean isTransitionPlane( final TileEntity blockTileEntity, final AEPartLocation side )
|
||||
{
|
||||
if( blockTileEntity instanceof IPartHost )
|
||||
{
|
||||
final IPart p = ( (IPartHost) blockTileEntity ).getPart( side );
|
||||
return p != null && this.getClass() == p.getClass();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public T extractItems(final T request, final Actionable mode, final IActionSource src) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T extractItems( final T request, final Actionable mode, final IActionSource src )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public IItemList<T> getAvailableItems(final IItemList<T> out) {
|
||||
return out;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemList<T> getAvailableItems( final IItemList<T> out )
|
||||
{
|
||||
return out;
|
||||
}
|
||||
@Override
|
||||
public void readFromNBT(final CompoundNBT data) {
|
||||
super.readFromNBT(data);
|
||||
this.priority = data.getInt("priority");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT( final CompoundNBT data )
|
||||
{
|
||||
super.readFromNBT( data );
|
||||
this.priority = data.getInt( "priority" );
|
||||
}
|
||||
@Override
|
||||
public void writeToNBT(final CompoundNBT data) {
|
||||
super.writeToNBT(data);
|
||||
data.putInt("priority", this.getPriority());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT( final CompoundNBT data )
|
||||
{
|
||||
super.writeToNBT( data );
|
||||
data.putInt( "priority", this.getPriority() );
|
||||
}
|
||||
@Override
|
||||
public int getPriority() {
|
||||
return this.priority;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPriority()
|
||||
{
|
||||
return this.priority;
|
||||
}
|
||||
@Override
|
||||
public void setPriority(final int newValue) {
|
||||
this.priority = newValue;
|
||||
this.getHost().markForSave();
|
||||
this.updateHandler();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPriority( final int newValue )
|
||||
{
|
||||
this.priority = newValue;
|
||||
this.getHost().markForSave();
|
||||
this.updateHandler();
|
||||
}
|
||||
@Override
|
||||
public void blinkCell(final int slot) {
|
||||
// :P
|
||||
}
|
||||
|
||||
@Override
|
||||
public void blinkCell( final int slot )
|
||||
{
|
||||
// :P
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveChanges( final ICellInventory<?> cell )
|
||||
{
|
||||
// nope!
|
||||
}
|
||||
@Override
|
||||
public void saveChanges(final ICellInventory<?> cell) {
|
||||
// nope!
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -18,11 +18,6 @@
|
||||
|
||||
package appeng.parts.automation;
|
||||
|
||||
|
||||
import appeng.container.ContainerLocator;
|
||||
import appeng.container.ContainerOpener;
|
||||
import appeng.container.implementations.ContainerUpgradeable;
|
||||
import appeng.fluids.container.ContainerFluidInterface;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
@@ -57,10 +52,13 @@ import appeng.api.storage.IMEMonitor;
|
||||
import appeng.api.storage.channels.IItemStorageChannel;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.util.AECableType;
|
||||
import appeng.container.ContainerLocator;
|
||||
import appeng.container.ContainerOpener;
|
||||
import appeng.container.implementations.ContainerUpgradeable;
|
||||
import appeng.core.AELog;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.core.settings.TickRates;
|
||||
|
||||
import appeng.fluids.container.ContainerFluidInterface;
|
||||
import appeng.helpers.MultiCraftingTracker;
|
||||
import appeng.helpers.Reflected;
|
||||
import appeng.items.parts.PartModels;
|
||||
@@ -71,309 +69,256 @@ import appeng.util.InventoryAdaptor;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.item.AEItemStack;
|
||||
|
||||
public class PartExportBus extends PartSharedItemBus implements ICraftingRequester {
|
||||
|
||||
public class PartExportBus extends PartSharedItemBus implements ICraftingRequester
|
||||
{
|
||||
public static final ResourceLocation MODEL_BASE = new ResourceLocation(AppEng.MOD_ID, "part/export_bus_base");
|
||||
|
||||
public static final ResourceLocation MODEL_BASE = new ResourceLocation( AppEng.MOD_ID, "part/export_bus_base" );
|
||||
@PartModels
|
||||
public static final IPartModel MODELS_OFF = new PartModel(MODEL_BASE,
|
||||
new ResourceLocation(AppEng.MOD_ID, "part/export_bus_off"));
|
||||
|
||||
@PartModels
|
||||
public static final IPartModel MODELS_OFF = new PartModel( MODEL_BASE, new ResourceLocation( AppEng.MOD_ID, "part/export_bus_off" ) );
|
||||
@PartModels
|
||||
public static final IPartModel MODELS_ON = new PartModel(MODEL_BASE,
|
||||
new ResourceLocation(AppEng.MOD_ID, "part/export_bus_on"));
|
||||
|
||||
@PartModels
|
||||
public static final IPartModel MODELS_ON = new PartModel( MODEL_BASE, new ResourceLocation( AppEng.MOD_ID, "part/export_bus_on" ) );
|
||||
@PartModels
|
||||
public static final IPartModel MODELS_HAS_CHANNEL = new PartModel(MODEL_BASE,
|
||||
new ResourceLocation(AppEng.MOD_ID, "part/export_bus_has_channel"));
|
||||
|
||||
@PartModels
|
||||
public static final IPartModel MODELS_HAS_CHANNEL = new PartModel( MODEL_BASE, new ResourceLocation( AppEng.MOD_ID, "part/export_bus_has_channel" ) );
|
||||
private final MultiCraftingTracker craftingTracker = new MultiCraftingTracker(this, 9);
|
||||
private final IActionSource mySrc;
|
||||
private long itemToSend = 1;
|
||||
private boolean didSomething = false;
|
||||
private int nextSlot = 0;
|
||||
|
||||
private final MultiCraftingTracker craftingTracker = new MultiCraftingTracker( this, 9 );
|
||||
private final IActionSource mySrc;
|
||||
private long itemToSend = 1;
|
||||
private boolean didSomething = false;
|
||||
private int nextSlot = 0;
|
||||
@Reflected
|
||||
public PartExportBus(final ItemStack is) {
|
||||
super(is);
|
||||
|
||||
@Reflected
|
||||
public PartExportBus( final ItemStack is )
|
||||
{
|
||||
super( is );
|
||||
this.getConfigManager().registerSetting(Settings.REDSTONE_CONTROLLED, RedstoneMode.IGNORE);
|
||||
this.getConfigManager().registerSetting(Settings.FUZZY_MODE, FuzzyMode.IGNORE_ALL);
|
||||
this.getConfigManager().registerSetting(Settings.CRAFT_ONLY, YesNo.NO);
|
||||
this.getConfigManager().registerSetting(Settings.SCHEDULING_MODE, SchedulingMode.DEFAULT);
|
||||
this.mySrc = new MachineSource(this);
|
||||
}
|
||||
|
||||
this.getConfigManager().registerSetting( Settings.REDSTONE_CONTROLLED, RedstoneMode.IGNORE );
|
||||
this.getConfigManager().registerSetting( Settings.FUZZY_MODE, FuzzyMode.IGNORE_ALL );
|
||||
this.getConfigManager().registerSetting( Settings.CRAFT_ONLY, YesNo.NO );
|
||||
this.getConfigManager().registerSetting( Settings.SCHEDULING_MODE, SchedulingMode.DEFAULT );
|
||||
this.mySrc = new MachineSource( this );
|
||||
}
|
||||
@Override
|
||||
public void readFromNBT(final CompoundNBT extra) {
|
||||
super.readFromNBT(extra);
|
||||
this.craftingTracker.readFromNBT(extra);
|
||||
this.nextSlot = extra.getInt("nextSlot");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT( final CompoundNBT extra )
|
||||
{
|
||||
super.readFromNBT( extra );
|
||||
this.craftingTracker.readFromNBT( extra );
|
||||
this.nextSlot = extra.getInt( "nextSlot" );
|
||||
}
|
||||
@Override
|
||||
public void writeToNBT(final CompoundNBT extra) {
|
||||
super.writeToNBT(extra);
|
||||
this.craftingTracker.writeToNBT(extra);
|
||||
extra.putInt("nextSlot", this.nextSlot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT( final CompoundNBT extra )
|
||||
{
|
||||
super.writeToNBT( extra );
|
||||
this.craftingTracker.writeToNBT( extra );
|
||||
extra.putInt( "nextSlot", this.nextSlot );
|
||||
}
|
||||
@Override
|
||||
protected TickRateModulation doBusWork() {
|
||||
if (!this.getProxy().isActive() || !this.canDoBusWork()) {
|
||||
return TickRateModulation.IDLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TickRateModulation doBusWork()
|
||||
{
|
||||
if( !this.getProxy().isActive() || !this.canDoBusWork() )
|
||||
{
|
||||
return TickRateModulation.IDLE;
|
||||
}
|
||||
this.itemToSend = this.calculateItemsToSend();
|
||||
this.didSomething = false;
|
||||
|
||||
this.itemToSend = this.calculateItemsToSend();
|
||||
this.didSomething = false;
|
||||
try {
|
||||
final InventoryAdaptor destination = this.getHandler();
|
||||
final IMEMonitor<IAEItemStack> inv = this.getProxy().getStorage()
|
||||
.getInventory(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class));
|
||||
final IEnergyGrid energy = this.getProxy().getEnergy();
|
||||
final ICraftingGrid cg = this.getProxy().getCrafting();
|
||||
final FuzzyMode fzMode = (FuzzyMode) this.getConfigManager().getSetting(Settings.FUZZY_MODE);
|
||||
final SchedulingMode schedulingMode = (SchedulingMode) this.getConfigManager()
|
||||
.getSetting(Settings.SCHEDULING_MODE);
|
||||
|
||||
try
|
||||
{
|
||||
final InventoryAdaptor destination = this.getHandler();
|
||||
final IMEMonitor<IAEItemStack> inv = this.getProxy()
|
||||
.getStorage()
|
||||
.getInventory(
|
||||
AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) );
|
||||
final IEnergyGrid energy = this.getProxy().getEnergy();
|
||||
final ICraftingGrid cg = this.getProxy().getCrafting();
|
||||
final FuzzyMode fzMode = (FuzzyMode) this.getConfigManager().getSetting( Settings.FUZZY_MODE );
|
||||
final SchedulingMode schedulingMode = (SchedulingMode) this.getConfigManager().getSetting( Settings.SCHEDULING_MODE );
|
||||
if (destination != null) {
|
||||
int x = 0;
|
||||
|
||||
if( destination != null )
|
||||
{
|
||||
int x = 0;
|
||||
for (x = 0; x < this.availableSlots() && this.itemToSend > 0; x++) {
|
||||
final int slotToExport = this.getStartingSlot(schedulingMode, x);
|
||||
|
||||
for( x = 0; x < this.availableSlots() && this.itemToSend > 0; x++ )
|
||||
{
|
||||
final int slotToExport = this.getStartingSlot( schedulingMode, x );
|
||||
final IAEItemStack ais = this.getConfig().getAEStackInSlot(slotToExport);
|
||||
|
||||
final IAEItemStack ais = this.getConfig().getAEStackInSlot( slotToExport );
|
||||
if (ais == null || this.itemToSend <= 0 || this.craftOnly()) {
|
||||
if (this.isCraftingEnabled()) {
|
||||
this.didSomething = this.craftingTracker.handleCrafting(slotToExport, this.itemToSend, ais,
|
||||
destination, this.getTile().getWorld(), this.getProxy().getGrid(), cg, this.mySrc)
|
||||
|| this.didSomething;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if( ais == null || this.itemToSend <= 0 || this.craftOnly() )
|
||||
{
|
||||
if( this.isCraftingEnabled() )
|
||||
{
|
||||
this.didSomething = this.craftingTracker.handleCrafting( slotToExport, this.itemToSend, ais, destination, this.getTile().getWorld(),
|
||||
this.getProxy().getGrid(), cg, this.mySrc ) || this.didSomething;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
final long before = this.itemToSend;
|
||||
|
||||
final long before = this.itemToSend;
|
||||
if (this.getInstalledUpgrades(Upgrades.FUZZY) > 0) {
|
||||
for (final IAEItemStack o : ImmutableList.copyOf(inv.getStorageList().findFuzzy(ais, fzMode))) {
|
||||
this.pushItemIntoTarget(destination, energy, inv, o);
|
||||
if (this.itemToSend <= 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
this.pushItemIntoTarget(destination, energy, inv, ais);
|
||||
}
|
||||
|
||||
if( this.getInstalledUpgrades( Upgrades.FUZZY ) > 0 )
|
||||
{
|
||||
for( final IAEItemStack o : ImmutableList.copyOf( inv.getStorageList().findFuzzy( ais, fzMode ) ) )
|
||||
{
|
||||
this.pushItemIntoTarget( destination, energy, inv, o );
|
||||
if( this.itemToSend <= 0 )
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.pushItemIntoTarget( destination, energy, inv, ais );
|
||||
}
|
||||
if (this.itemToSend == before && this.isCraftingEnabled()) {
|
||||
this.didSomething = this.craftingTracker.handleCrafting(slotToExport, this.itemToSend, ais,
|
||||
destination, this.getTile().getWorld(), this.getProxy().getGrid(), cg, this.mySrc)
|
||||
|| this.didSomething;
|
||||
}
|
||||
}
|
||||
|
||||
if( this.itemToSend == before && this.isCraftingEnabled() )
|
||||
{
|
||||
this.didSomething = this.craftingTracker.handleCrafting( slotToExport, this.itemToSend, ais, destination, this.getTile().getWorld(),
|
||||
this.getProxy().getGrid(), cg, this.mySrc ) || this.didSomething;
|
||||
}
|
||||
}
|
||||
this.updateSchedulingMode(schedulingMode, x);
|
||||
} else {
|
||||
return TickRateModulation.SLEEP;
|
||||
}
|
||||
} catch (final GridAccessException e) {
|
||||
// :P
|
||||
}
|
||||
|
||||
this.updateSchedulingMode( schedulingMode, x );
|
||||
}
|
||||
else
|
||||
{
|
||||
return TickRateModulation.SLEEP;
|
||||
}
|
||||
}
|
||||
catch( final GridAccessException e )
|
||||
{
|
||||
// :P
|
||||
}
|
||||
return this.didSomething ? TickRateModulation.FASTER : TickRateModulation.SLOWER;
|
||||
}
|
||||
|
||||
return this.didSomething ? TickRateModulation.FASTER : TickRateModulation.SLOWER;
|
||||
}
|
||||
@Override
|
||||
public void getBoxes(final IPartCollisionHelper bch) {
|
||||
bch.addBox(4, 4, 12, 12, 12, 14);
|
||||
bch.addBox(5, 5, 14, 11, 11, 15);
|
||||
bch.addBox(6, 6, 15, 10, 10, 16);
|
||||
bch.addBox(6, 6, 11, 10, 10, 12);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getBoxes( final IPartCollisionHelper bch )
|
||||
{
|
||||
bch.addBox( 4, 4, 12, 12, 12, 14 );
|
||||
bch.addBox( 5, 5, 14, 11, 11, 15 );
|
||||
bch.addBox( 6, 6, 15, 10, 10, 16 );
|
||||
bch.addBox( 6, 6, 11, 10, 10, 12 );
|
||||
}
|
||||
@Override
|
||||
public float getCableConnectionLength(AECableType cable) {
|
||||
return 5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getCableConnectionLength( AECableType cable )
|
||||
{
|
||||
return 5;
|
||||
}
|
||||
@Override
|
||||
public boolean onPartActivate(final PlayerEntity player, final Hand hand, final Vec3d pos) {
|
||||
if (Platform.isServer()) {
|
||||
ContainerOpener.openContainer(ContainerUpgradeable.TYPE, player, ContainerLocator.forPart(this));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPartActivate( final PlayerEntity player, final Hand hand, final Vec3d pos )
|
||||
{
|
||||
if( Platform.isServer() )
|
||||
{
|
||||
ContainerOpener.openContainer(ContainerUpgradeable.TYPE, player, ContainerLocator.forPart(this));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public TickingRequest getTickingRequest(final IGridNode node) {
|
||||
return new TickingRequest(TickRates.ExportBus.getMin(), TickRates.ExportBus.getMax(), this.isSleeping(), false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickingRequest getTickingRequest( final IGridNode node )
|
||||
{
|
||||
return new TickingRequest( TickRates.ExportBus.getMin(), TickRates.ExportBus.getMax(), this.isSleeping(), false );
|
||||
}
|
||||
@Override
|
||||
public RedstoneMode getRSMode() {
|
||||
return (RedstoneMode) this.getConfigManager().getSetting(Settings.REDSTONE_CONTROLLED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedstoneMode getRSMode()
|
||||
{
|
||||
return (RedstoneMode) this.getConfigManager().getSetting( Settings.REDSTONE_CONTROLLED );
|
||||
}
|
||||
@Override
|
||||
public TickRateModulation tickingRequest(final IGridNode node, final int ticksSinceLastCall) {
|
||||
return this.doBusWork();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickRateModulation tickingRequest( final IGridNode node, final int ticksSinceLastCall )
|
||||
{
|
||||
return this.doBusWork();
|
||||
}
|
||||
@Override
|
||||
public ImmutableSet<ICraftingLink> getRequestedJobs() {
|
||||
return this.craftingTracker.getRequestedJobs();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImmutableSet<ICraftingLink> getRequestedJobs()
|
||||
{
|
||||
return this.craftingTracker.getRequestedJobs();
|
||||
}
|
||||
@Override
|
||||
public IAEItemStack injectCraftedItems(final ICraftingLink link, final IAEItemStack items, final Actionable mode) {
|
||||
final InventoryAdaptor d = this.getHandler();
|
||||
|
||||
@Override
|
||||
public IAEItemStack injectCraftedItems( final ICraftingLink link, final IAEItemStack items, final Actionable mode )
|
||||
{
|
||||
final InventoryAdaptor d = this.getHandler();
|
||||
try {
|
||||
if (d != null && this.getProxy().isActive()) {
|
||||
final IEnergyGrid energy = this.getProxy().getEnergy();
|
||||
final double power = items.getStackSize();
|
||||
|
||||
try
|
||||
{
|
||||
if( d != null && this.getProxy().isActive() )
|
||||
{
|
||||
final IEnergyGrid energy = this.getProxy().getEnergy();
|
||||
final double power = items.getStackSize();
|
||||
if (energy.extractAEPower(power, mode, PowerMultiplier.CONFIG) > power - 0.01) {
|
||||
if (mode == Actionable.MODULATE) {
|
||||
return AEItemStack.fromItemStack(d.addItems(items.createItemStack()));
|
||||
}
|
||||
return AEItemStack.fromItemStack(d.simulateAdd(items.createItemStack()));
|
||||
}
|
||||
}
|
||||
} catch (final GridAccessException e) {
|
||||
AELog.debug(e);
|
||||
}
|
||||
|
||||
if( energy.extractAEPower( power, mode, PowerMultiplier.CONFIG ) > power - 0.01 )
|
||||
{
|
||||
if( mode == Actionable.MODULATE )
|
||||
{
|
||||
return AEItemStack.fromItemStack( d.addItems( items.createItemStack() ) );
|
||||
}
|
||||
return AEItemStack.fromItemStack( d.simulateAdd( items.createItemStack() ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
catch( final GridAccessException e )
|
||||
{
|
||||
AELog.debug( e );
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
return items;
|
||||
}
|
||||
@Override
|
||||
public void jobStateChange(final ICraftingLink link) {
|
||||
this.craftingTracker.jobStateChange(link);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void jobStateChange( final ICraftingLink link )
|
||||
{
|
||||
this.craftingTracker.jobStateChange( link );
|
||||
}
|
||||
@Override
|
||||
protected boolean isSleeping() {
|
||||
return this.getHandler() == null || super.isSleeping();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isSleeping()
|
||||
{
|
||||
return this.getHandler() == null || super.isSleeping();
|
||||
}
|
||||
private boolean craftOnly() {
|
||||
return this.getConfigManager().getSetting(Settings.CRAFT_ONLY) == YesNo.YES;
|
||||
}
|
||||
|
||||
private boolean craftOnly()
|
||||
{
|
||||
return this.getConfigManager().getSetting( Settings.CRAFT_ONLY ) == YesNo.YES;
|
||||
}
|
||||
private boolean isCraftingEnabled() {
|
||||
return this.getInstalledUpgrades(Upgrades.CRAFTING) > 0;
|
||||
}
|
||||
|
||||
private boolean isCraftingEnabled()
|
||||
{
|
||||
return this.getInstalledUpgrades( Upgrades.CRAFTING ) > 0;
|
||||
}
|
||||
private void pushItemIntoTarget(final InventoryAdaptor d, final IEnergyGrid energy,
|
||||
final IMEInventory<IAEItemStack> inv, IAEItemStack ais) {
|
||||
final ItemStack is = ais.createItemStack();
|
||||
is.setCount((int) this.itemToSend);
|
||||
|
||||
private void pushItemIntoTarget( final InventoryAdaptor d, final IEnergyGrid energy, final IMEInventory<IAEItemStack> inv, IAEItemStack ais )
|
||||
{
|
||||
final ItemStack is = ais.createItemStack();
|
||||
is.setCount( (int) this.itemToSend );
|
||||
final ItemStack o = d.simulateAdd(is);
|
||||
final long canFit = o.isEmpty() ? this.itemToSend : this.itemToSend - o.getCount();
|
||||
|
||||
final ItemStack o = d.simulateAdd( is );
|
||||
final long canFit = o.isEmpty() ? this.itemToSend : this.itemToSend - o.getCount();
|
||||
if (canFit > 0) {
|
||||
ais = ais.copy();
|
||||
ais.setStackSize(canFit);
|
||||
final IAEItemStack itemsToAdd = Platform.poweredExtraction(energy, inv, ais, this.mySrc);
|
||||
|
||||
if( canFit > 0 )
|
||||
{
|
||||
ais = ais.copy();
|
||||
ais.setStackSize( canFit );
|
||||
final IAEItemStack itemsToAdd = Platform.poweredExtraction( energy, inv, ais, this.mySrc );
|
||||
if (itemsToAdd != null) {
|
||||
this.itemToSend -= itemsToAdd.getStackSize();
|
||||
|
||||
if( itemsToAdd != null )
|
||||
{
|
||||
this.itemToSend -= itemsToAdd.getStackSize();
|
||||
final ItemStack failed = d.addItems(itemsToAdd.createItemStack());
|
||||
if (!failed.isEmpty()) {
|
||||
ais.setStackSize(failed.getCount());
|
||||
inv.injectItems(ais, Actionable.MODULATE, this.mySrc);
|
||||
} else {
|
||||
this.didSomething = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final ItemStack failed = d.addItems( itemsToAdd.createItemStack() );
|
||||
if( !failed.isEmpty() )
|
||||
{
|
||||
ais.setStackSize( failed.getCount() );
|
||||
inv.injectItems( ais, Actionable.MODULATE, this.mySrc );
|
||||
}
|
||||
else
|
||||
{
|
||||
this.didSomething = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
private int getStartingSlot(final SchedulingMode schedulingMode, final int x) {
|
||||
if (schedulingMode == SchedulingMode.RANDOM) {
|
||||
return Platform.getRandom().nextInt(this.availableSlots());
|
||||
}
|
||||
|
||||
private int getStartingSlot( final SchedulingMode schedulingMode, final int x )
|
||||
{
|
||||
if( schedulingMode == SchedulingMode.RANDOM )
|
||||
{
|
||||
return Platform.getRandom().nextInt( this.availableSlots() );
|
||||
}
|
||||
if (schedulingMode == SchedulingMode.ROUNDROBIN) {
|
||||
return (this.nextSlot + x) % this.availableSlots();
|
||||
}
|
||||
|
||||
if( schedulingMode == SchedulingMode.ROUNDROBIN )
|
||||
{
|
||||
return ( this.nextSlot + x ) % this.availableSlots();
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
return x;
|
||||
}
|
||||
private void updateSchedulingMode(final SchedulingMode schedulingMode, final int x) {
|
||||
if (schedulingMode == SchedulingMode.ROUNDROBIN) {
|
||||
this.nextSlot = (this.nextSlot + x) % this.availableSlots();
|
||||
}
|
||||
}
|
||||
|
||||
private void updateSchedulingMode( final SchedulingMode schedulingMode, final int x )
|
||||
{
|
||||
if( schedulingMode == SchedulingMode.ROUNDROBIN )
|
||||
{
|
||||
this.nextSlot = ( this.nextSlot + x ) % this.availableSlots();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPartModel getStaticModels()
|
||||
{
|
||||
if( this.isActive() && this.isPowered() )
|
||||
{
|
||||
return MODELS_HAS_CHANNEL;
|
||||
}
|
||||
else if( this.isPowered() )
|
||||
{
|
||||
return MODELS_ON;
|
||||
}
|
||||
else
|
||||
{
|
||||
return MODELS_OFF;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public IPartModel getStaticModels() {
|
||||
if (this.isActive() && this.isPowered()) {
|
||||
return MODELS_HAS_CHANNEL;
|
||||
} else if (this.isPowered()) {
|
||||
return MODELS_ON;
|
||||
} else {
|
||||
return MODELS_OFF;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,15 +18,13 @@
|
||||
|
||||
package appeng.parts.automation;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import appeng.container.ContainerLocator;
|
||||
import appeng.container.ContainerOpener;
|
||||
import appeng.container.implementations.ContainerFormationPlane;
|
||||
import appeng.fluids.container.ContainerFluidInterface;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.item.ItemEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
@@ -68,8 +66,11 @@ import appeng.api.storage.channels.IItemStorageChannel;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
import appeng.api.util.AEPartLocation;
|
||||
import appeng.container.ContainerLocator;
|
||||
import appeng.container.ContainerOpener;
|
||||
import appeng.container.implementations.ContainerFormationPlane;
|
||||
import appeng.core.AEConfig;
|
||||
|
||||
import appeng.fluids.container.ContainerFluidInterface;
|
||||
import appeng.items.parts.PartModels;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.me.storage.MEInventoryHandler;
|
||||
@@ -79,336 +80,289 @@ import appeng.util.inv.InvOperation;
|
||||
import appeng.util.prioritylist.FuzzyPriorityList;
|
||||
import appeng.util.prioritylist.PrecisePriorityList;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
public class PartFormationPlane extends PartAbstractFormationPlane<IAEItemStack> {
|
||||
|
||||
private static final PlaneModels MODELS = new PlaneModels("part/formation_plane", "part/formation_plane_on");
|
||||
|
||||
public class PartFormationPlane extends PartAbstractFormationPlane<IAEItemStack>
|
||||
{
|
||||
@PartModels
|
||||
public static List<IPartModel> getModels() {
|
||||
return MODELS.getModels();
|
||||
}
|
||||
|
||||
private static final PlaneModels MODELS = new PlaneModels( "part/formation_plane", "part/formation_plane_on" );
|
||||
private final MEInventoryHandler<IAEItemStack> myHandler = new MEInventoryHandler<>(this,
|
||||
AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class));
|
||||
private final AppEngInternalAEInventory Config = new AppEngInternalAEInventory(this, 63);
|
||||
|
||||
@PartModels
|
||||
public static List<IPartModel> getModels()
|
||||
{
|
||||
return MODELS.getModels();
|
||||
}
|
||||
public PartFormationPlane(final ItemStack is) {
|
||||
super(is);
|
||||
|
||||
private final MEInventoryHandler<IAEItemStack> myHandler = new MEInventoryHandler<>( this, AEApi.instance()
|
||||
.storage()
|
||||
.getStorageChannel( IItemStorageChannel.class ) );
|
||||
private final AppEngInternalAEInventory Config = new AppEngInternalAEInventory( this, 63 );
|
||||
this.getConfigManager().registerSetting(Settings.FUZZY_MODE, FuzzyMode.IGNORE_ALL);
|
||||
this.getConfigManager().registerSetting(Settings.PLACE_BLOCK, YesNo.YES);
|
||||
this.updateHandler();
|
||||
}
|
||||
|
||||
public PartFormationPlane( final ItemStack is )
|
||||
{
|
||||
super( is );
|
||||
@Override
|
||||
protected void updateHandler() {
|
||||
this.myHandler.setBaseAccess(AccessRestriction.WRITE);
|
||||
this.myHandler.setWhitelist(
|
||||
this.getInstalledUpgrades(Upgrades.INVERTER) > 0 ? IncludeExclude.BLACKLIST : IncludeExclude.WHITELIST);
|
||||
this.myHandler.setPriority(this.getPriority());
|
||||
|
||||
this.getConfigManager().registerSetting( Settings.FUZZY_MODE, FuzzyMode.IGNORE_ALL );
|
||||
this.getConfigManager().registerSetting( Settings.PLACE_BLOCK, YesNo.YES );
|
||||
this.updateHandler();
|
||||
}
|
||||
final IItemList<IAEItemStack> priorityList = AEApi.instance().storage()
|
||||
.getStorageChannel(IItemStorageChannel.class).createList();
|
||||
|
||||
@Override
|
||||
protected void updateHandler()
|
||||
{
|
||||
this.myHandler.setBaseAccess( AccessRestriction.WRITE );
|
||||
this.myHandler.setWhitelist( this.getInstalledUpgrades( Upgrades.INVERTER ) > 0 ? IncludeExclude.BLACKLIST : IncludeExclude.WHITELIST );
|
||||
this.myHandler.setPriority( this.getPriority() );
|
||||
final int slotsToUse = 18 + this.getInstalledUpgrades(Upgrades.CAPACITY) * 9;
|
||||
for (int x = 0; x < this.Config.getSlots() && x < slotsToUse; x++) {
|
||||
final IAEItemStack is = this.Config.getAEStackInSlot(x);
|
||||
if (is != null) {
|
||||
priorityList.add(is);
|
||||
}
|
||||
}
|
||||
|
||||
final IItemList<IAEItemStack> priorityList = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList();
|
||||
if (this.getInstalledUpgrades(Upgrades.FUZZY) > 0) {
|
||||
this.myHandler.setPartitionList(new FuzzyPriorityList<IAEItemStack>(priorityList,
|
||||
(FuzzyMode) this.getConfigManager().getSetting(Settings.FUZZY_MODE)));
|
||||
} else {
|
||||
this.myHandler.setPartitionList(new PrecisePriorityList<IAEItemStack>(priorityList));
|
||||
}
|
||||
|
||||
final int slotsToUse = 18 + this.getInstalledUpgrades( Upgrades.CAPACITY ) * 9;
|
||||
for( int x = 0; x < this.Config.getSlots() && x < slotsToUse; x++ )
|
||||
{
|
||||
final IAEItemStack is = this.Config.getAEStackInSlot( x );
|
||||
if( is != null )
|
||||
{
|
||||
priorityList.add( is );
|
||||
}
|
||||
}
|
||||
try {
|
||||
this.getProxy().getGrid().postEvent(new MENetworkCellArrayUpdate());
|
||||
} catch (final GridAccessException e) {
|
||||
// :P
|
||||
}
|
||||
}
|
||||
|
||||
if( this.getInstalledUpgrades( Upgrades.FUZZY ) > 0 )
|
||||
{
|
||||
this.myHandler.setPartitionList(
|
||||
new FuzzyPriorityList<IAEItemStack>( priorityList, (FuzzyMode) this.getConfigManager().getSetting( Settings.FUZZY_MODE ) ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
this.myHandler.setPartitionList( new PrecisePriorityList<IAEItemStack>( priorityList ) );
|
||||
}
|
||||
@Override
|
||||
public void onChangeInventory(final IItemHandler inv, final int slot, final InvOperation mc,
|
||||
final ItemStack removedStack, final ItemStack newStack) {
|
||||
super.onChangeInventory(inv, slot, mc, removedStack, newStack);
|
||||
|
||||
try
|
||||
{
|
||||
this.getProxy().getGrid().postEvent( new MENetworkCellArrayUpdate() );
|
||||
}
|
||||
catch( final GridAccessException e )
|
||||
{
|
||||
// :P
|
||||
}
|
||||
}
|
||||
if (inv == this.Config) {
|
||||
this.updateHandler();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChangeInventory( final IItemHandler inv, final int slot, final InvOperation mc, final ItemStack removedStack, final ItemStack newStack )
|
||||
{
|
||||
super.onChangeInventory( inv, slot, mc, removedStack, newStack );
|
||||
@Override
|
||||
public void readFromNBT(final CompoundNBT data) {
|
||||
super.readFromNBT(data);
|
||||
this.Config.readFromNBT(data, "config");
|
||||
this.updateHandler();
|
||||
}
|
||||
|
||||
if( inv == this.Config )
|
||||
{
|
||||
this.updateHandler();
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void writeToNBT(final CompoundNBT data) {
|
||||
super.writeToNBT(data);
|
||||
this.Config.writeToNBT(data, "config");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT( final CompoundNBT data )
|
||||
{
|
||||
super.readFromNBT( data );
|
||||
this.Config.readFromNBT( data, "config" );
|
||||
this.updateHandler();
|
||||
}
|
||||
@Override
|
||||
public IItemHandler getInventoryByName(final String name) {
|
||||
if (name.equals("config")) {
|
||||
return this.Config;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT( final CompoundNBT data )
|
||||
{
|
||||
super.writeToNBT( data );
|
||||
this.Config.writeToNBT( data, "config" );
|
||||
}
|
||||
return super.getInventoryByName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemHandler getInventoryByName( final String name )
|
||||
{
|
||||
if( name.equals( "config" ) )
|
||||
{
|
||||
return this.Config;
|
||||
}
|
||||
@Override
|
||||
@MENetworkEventSubscribe
|
||||
public void powerRender(final MENetworkPowerStatusChange c) {
|
||||
this.stateChanged();
|
||||
}
|
||||
|
||||
return super.getInventoryByName( name );
|
||||
}
|
||||
@MENetworkEventSubscribe
|
||||
public void updateChannels(final MENetworkChannelsChanged changedChannels) {
|
||||
this.stateChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
@MENetworkEventSubscribe
|
||||
public void powerRender( final MENetworkPowerStatusChange c )
|
||||
{
|
||||
this.stateChanged();
|
||||
}
|
||||
@Override
|
||||
public boolean onPartActivate(final PlayerEntity player, final Hand hand, final Vec3d pos) {
|
||||
if (Platform.isServer()) {
|
||||
ContainerOpener.openContainer(ContainerFormationPlane.TYPE, player, ContainerLocator.forPart(this));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void updateChannels( final MENetworkChannelsChanged changedChannels )
|
||||
{
|
||||
this.stateChanged();
|
||||
}
|
||||
@Override
|
||||
public List<IMEInventoryHandler> getCellArray(final IStorageChannel channel) {
|
||||
if (this.getProxy().isActive()
|
||||
&& channel == AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)) {
|
||||
final List<IMEInventoryHandler> handler = new ArrayList<>(1);
|
||||
handler.add(this.myHandler);
|
||||
return handler;
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPartActivate( final PlayerEntity player, final Hand hand, final Vec3d pos )
|
||||
{
|
||||
if( Platform.isServer() )
|
||||
{
|
||||
ContainerOpener.openContainer(ContainerFormationPlane.TYPE, player, ContainerLocator.forPart(this));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public IAEItemStack injectItems(final IAEItemStack input, final Actionable type, final IActionSource src) {
|
||||
if (this.blocked || input == null || input.getStackSize() <= 0) {
|
||||
return input;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IMEInventoryHandler> getCellArray( final IStorageChannel channel )
|
||||
{
|
||||
if( this.getProxy().isActive() && channel == AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) )
|
||||
{
|
||||
final List<IMEInventoryHandler> handler = new ArrayList<>( 1 );
|
||||
handler.add( this.myHandler );
|
||||
return handler;
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
final YesNo placeBlock = (YesNo) this.getConfigManager().getSetting(Settings.PLACE_BLOCK);
|
||||
|
||||
@Override
|
||||
public IAEItemStack injectItems( final IAEItemStack input, final Actionable type, final IActionSource src )
|
||||
{
|
||||
if( this.blocked || input == null || input.getStackSize() <= 0 )
|
||||
{
|
||||
return input;
|
||||
}
|
||||
final ItemStack is = input.createItemStack();
|
||||
final Item i = is.getItem();
|
||||
|
||||
final YesNo placeBlock = (YesNo) this.getConfigManager().getSetting( Settings.PLACE_BLOCK );
|
||||
long maxStorage = Math.min(input.getStackSize(), is.getMaxStackSize());
|
||||
boolean worked = false;
|
||||
|
||||
final ItemStack is = input.createItemStack();
|
||||
final Item i = is.getItem();
|
||||
final TileEntity te = this.getHost().getTile();
|
||||
final World w = te.getWorld();
|
||||
final AEPartLocation side = this.getSide();
|
||||
|
||||
long maxStorage = Math.min( input.getStackSize(), is.getMaxStackSize() );
|
||||
boolean worked = false;
|
||||
final BlockPos placePos = te.getPos().offset(side.getFacing());
|
||||
|
||||
final TileEntity te = this.getHost().getTile();
|
||||
final World w = te.getWorld();
|
||||
final AEPartLocation side = this.getSide();
|
||||
if (w.getBlockState(placePos).getMaterial().isReplaceable()) {
|
||||
if (placeBlock == YesNo.YES && (i instanceof BlockItem || i instanceof IPlantable
|
||||
|| i instanceof FireworkStarItem || i instanceof FireworkRocketItem || i instanceof IPartItem)) {
|
||||
final PlayerEntity player = Platform.getPlayer((ServerWorld) w);
|
||||
Platform.configurePlayer(player, side, this.getTile());
|
||||
Hand hand = player.getActiveHand();
|
||||
player.setHeldItem(hand, is);
|
||||
|
||||
final BlockPos placePos = te.getPos().offset( side.getFacing() );
|
||||
maxStorage = is.getCount();
|
||||
worked = true;
|
||||
if (type == Actionable.MODULATE) {
|
||||
// The side the plane is attached to will be considered the look direction
|
||||
// in terms of placing an item
|
||||
Direction lookDirection = side.getFacing();
|
||||
|
||||
if( w.getBlockState( placePos ).getMaterial().isReplaceable() )
|
||||
{
|
||||
if( placeBlock == YesNo.YES && ( i instanceof BlockItem || i instanceof IPlantable || i instanceof FireworkStarItem || i instanceof FireworkRocketItem || i instanceof IPartItem ) )
|
||||
{
|
||||
final PlayerEntity player = Platform.getPlayer( (ServerWorld) w );
|
||||
Platform.configurePlayer( player, side, this.getTile() );
|
||||
Hand hand = player.getActiveHand();
|
||||
player.setHeldItem( hand, is );
|
||||
// FIXME No idea what any of this is _supposed_ to do, comment badly needed
|
||||
if (i instanceof IPlantable || i instanceof WallOrFloorItem) {
|
||||
boolean Worked = false;
|
||||
|
||||
maxStorage = is.getCount();
|
||||
worked = true;
|
||||
if( type == Actionable.MODULATE )
|
||||
{
|
||||
// The side the plane is attached to will be considered the look direction
|
||||
// in terms of placing an item
|
||||
Direction lookDirection = side.getFacing();
|
||||
// Up or Down, Attempt 1??
|
||||
if (side.xOffset == 0 && side.zOffset == 0) {
|
||||
Worked = i.onItemUse(new DirectionalPlaceContext(w, placePos.offset(side.getFacing()),
|
||||
lookDirection, is, side.getFacing())) == ActionResultType.SUCCESS;
|
||||
}
|
||||
|
||||
// FIXME No idea what any of this is _supposed_ to do, comment badly needed
|
||||
if ( i instanceof IPlantable || i instanceof WallOrFloorItem )
|
||||
{
|
||||
boolean Worked = false;
|
||||
// Up or Down, Attempt 2??
|
||||
if (!Worked && side.xOffset == 0 && side.zOffset == 0) {
|
||||
Worked = i.onItemUse(new DirectionalPlaceContext(w,
|
||||
placePos.offset(side.getFacing().getOpposite()), lookDirection, is,
|
||||
side.getFacing().getOpposite())) == ActionResultType.SUCCESS;
|
||||
}
|
||||
|
||||
// Up or Down, Attempt 1??
|
||||
if( side.xOffset == 0 && side.zOffset == 0 )
|
||||
{
|
||||
Worked = i.onItemUse( new DirectionalPlaceContext(w, placePos.offset( side.getFacing() ), lookDirection, is, side.getFacing()) ) == ActionResultType.SUCCESS;
|
||||
}
|
||||
// Horizontal, attempt 1??
|
||||
if (!Worked && side.yOffset == 0) {
|
||||
Worked = i.onItemUse(new DirectionalPlaceContext(w, placePos.offset(Direction.DOWN),
|
||||
lookDirection, is, Direction.DOWN)) == ActionResultType.SUCCESS;
|
||||
}
|
||||
|
||||
// Up or Down, Attempt 2??
|
||||
if( !Worked && side.xOffset == 0 && side.zOffset == 0 )
|
||||
{
|
||||
Worked = i.onItemUse( new DirectionalPlaceContext(w, placePos.offset( side.getFacing().getOpposite() ), lookDirection, is, side.getFacing().getOpposite()) )
|
||||
== ActionResultType.SUCCESS;
|
||||
}
|
||||
if (!Worked) {
|
||||
i.onItemUse(new DirectionalPlaceContext(w, placePos, lookDirection, is,
|
||||
lookDirection.getOpposite()));
|
||||
}
|
||||
|
||||
// Horizontal, attempt 1??
|
||||
if( !Worked && side.yOffset == 0 )
|
||||
{
|
||||
Worked = i.onItemUse( new DirectionalPlaceContext(w, placePos.offset( Direction.DOWN ), lookDirection, is, Direction.DOWN) ) == ActionResultType.SUCCESS;
|
||||
}
|
||||
maxStorage -= is.getCount();
|
||||
} else {
|
||||
i.onItemUse(new DirectionalPlaceContext(w, placePos, lookDirection, is,
|
||||
lookDirection.getOpposite()));
|
||||
maxStorage -= is.getCount();
|
||||
}
|
||||
} else {
|
||||
maxStorage = 1;
|
||||
}
|
||||
|
||||
if( !Worked )
|
||||
{
|
||||
i.onItemUse( new DirectionalPlaceContext(w, placePos, lookDirection, is, lookDirection.getOpposite()) );
|
||||
}
|
||||
// Safe keeping
|
||||
player.setHeldItem(hand, ItemStack.EMPTY);
|
||||
} else {
|
||||
worked = true;
|
||||
|
||||
maxStorage -= is.getCount();
|
||||
}
|
||||
else
|
||||
{
|
||||
i.onItemUse( new DirectionalPlaceContext(w, placePos, lookDirection, is, lookDirection.getOpposite()) );
|
||||
maxStorage -= is.getCount();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
maxStorage = 1;
|
||||
}
|
||||
final int sum = this.countEntitesAround(w, placePos);
|
||||
|
||||
// Safe keeping
|
||||
player.setHeldItem( hand, ItemStack.EMPTY );
|
||||
}
|
||||
else
|
||||
{
|
||||
worked = true;
|
||||
if (sum < AEConfig.instance().getFormationPlaneEntityLimit()) {
|
||||
if (type == Actionable.MODULATE) {
|
||||
is.setCount((int) maxStorage);
|
||||
final double x = (side.xOffset != 0 ? 0 : .7 * (Platform.getRandomFloat() - .5)) + side.xOffset
|
||||
+ .5 + te.getPos().getX();
|
||||
final double y = (side.yOffset != 0 ? 0 : .7 * (Platform.getRandomFloat() - .5)) + side.yOffset
|
||||
+ .5 + te.getPos().getY();
|
||||
final double z = (side.zOffset != 0 ? 0 : .7 * (Platform.getRandomFloat() - .5)) + side.zOffset
|
||||
+ .5 + te.getPos().getZ();
|
||||
|
||||
final int sum = this.countEntitesAround( w, placePos );
|
||||
final ItemEntity ei = new ItemEntity(w, x, y, z, is.copy());
|
||||
|
||||
if( sum < AEConfig.instance().getFormationPlaneEntityLimit() )
|
||||
{
|
||||
if( type == Actionable.MODULATE )
|
||||
{
|
||||
is.setCount( (int) maxStorage );
|
||||
final double x = ( side.xOffset != 0 ? 0 : .7 * ( Platform.getRandomFloat() - .5 ) ) + side.xOffset + .5 + te.getPos().getX();
|
||||
final double y = ( side.yOffset != 0 ? 0 : .7 * ( Platform.getRandomFloat() - .5 ) ) + side.yOffset + .5 + te.getPos().getY();
|
||||
final double z = ( side.zOffset != 0 ? 0 : .7 * ( Platform.getRandomFloat() - .5 ) ) + side.zOffset + .5 + te.getPos().getZ();
|
||||
Entity result = ei;
|
||||
|
||||
final ItemEntity ei = new ItemEntity( w, x, y, z, is.copy() );
|
||||
ei.setMotion(side.xOffset * 0.2, side.yOffset * 0.2, side.zOffset * 0.2);
|
||||
|
||||
Entity result = ei;
|
||||
if (is.getItem().hasCustomEntity(is)) {
|
||||
result = is.getItem().createEntity(w, ei, is);
|
||||
if (result != null) {
|
||||
ei.remove();
|
||||
} else {
|
||||
result = ei;
|
||||
}
|
||||
}
|
||||
|
||||
ei.setMotion( side.xOffset * 0.2, side.yOffset * 0.2, side.zOffset * 0.2 );
|
||||
if (!w.addEntity(result)) {
|
||||
result.remove();
|
||||
worked = false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
worked = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( is.getItem().hasCustomEntity( is ) )
|
||||
{
|
||||
result = is.getItem().createEntity( w, ei, is );
|
||||
if( result != null )
|
||||
{
|
||||
ei.remove();
|
||||
}
|
||||
else
|
||||
{
|
||||
result = ei;
|
||||
}
|
||||
}
|
||||
this.blocked = !w.getBlockState(placePos).getMaterial().isReplaceable();
|
||||
|
||||
if( !w.addEntity( result ) )
|
||||
{
|
||||
result.remove();
|
||||
worked = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
worked = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (worked) {
|
||||
final IAEItemStack out = input.copy();
|
||||
out.decStackSize(maxStorage);
|
||||
if (out.getStackSize() == 0) {
|
||||
return null;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
this.blocked = !w.getBlockState( placePos ).getMaterial().isReplaceable();
|
||||
return input;
|
||||
}
|
||||
|
||||
if( worked )
|
||||
{
|
||||
final IAEItemStack out = input.copy();
|
||||
out.decStackSize( maxStorage );
|
||||
if( out.getStackSize() == 0 )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
@Override
|
||||
public IStorageChannel<IAEItemStack> getChannel() {
|
||||
return AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class);
|
||||
}
|
||||
|
||||
return input;
|
||||
}
|
||||
@Override
|
||||
public IPartModel getStaticModels() {
|
||||
return MODELS.getModel(this.isPowered(), this.isActive());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IStorageChannel<IAEItemStack> getChannel()
|
||||
{
|
||||
return AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class );
|
||||
}
|
||||
@Nonnull
|
||||
@Override
|
||||
public IModelData getModelData() {
|
||||
return new PlaneModelData(getConnections());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPartModel getStaticModels()
|
||||
{
|
||||
return MODELS.getModel( this.isPowered(), this.isActive() );
|
||||
}
|
||||
@Override
|
||||
public ItemStack getItemStackRepresentation() {
|
||||
return AEApi.instance().definitions().parts().formationPlane().maybeStack(1).orElse(ItemStack.EMPTY);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public IModelData getModelData() {
|
||||
return new PlaneModelData(getConnections());
|
||||
}
|
||||
@Override
|
||||
public ContainerType<?> getContainerType() {
|
||||
return ContainerFormationPlane.TYPE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItemStackRepresentation()
|
||||
{
|
||||
return AEApi.instance().definitions().parts().formationPlane().maybeStack( 1 ).orElse( ItemStack.EMPTY );
|
||||
}
|
||||
private int countEntitesAround(World world, BlockPos pos) {
|
||||
final AxisAlignedBB t = new AxisAlignedBB(pos).grow(8);
|
||||
final List<Entity> list = world.getEntitiesWithinAABB(Entity.class, t);
|
||||
|
||||
@Override
|
||||
public ContainerType<?> getContainerType()
|
||||
{
|
||||
return ContainerFormationPlane.TYPE;
|
||||
}
|
||||
return list.size();
|
||||
}
|
||||
|
||||
private int countEntitesAround( World world, BlockPos pos )
|
||||
{
|
||||
final AxisAlignedBB t = new AxisAlignedBB( pos ).grow( 8 );
|
||||
final List<Entity> list = world.getEntitiesWithinAABB( Entity.class, t );
|
||||
|
||||
return list.size();
|
||||
}
|
||||
|
||||
private class ForcedItemUseContext extends ItemUseContext {
|
||||
protected ForcedItemUseContext(World worldIn, @Nullable PlayerEntity player, Hand handIn, ItemStack heldItem, BlockRayTraceResult rayTraceResultIn) {
|
||||
super(worldIn, player, handIn, heldItem, rayTraceResultIn);
|
||||
}
|
||||
}
|
||||
private class ForcedItemUseContext extends ItemUseContext {
|
||||
protected ForcedItemUseContext(World worldIn, @Nullable PlayerEntity player, Hand handIn, ItemStack heldItem,
|
||||
BlockRayTraceResult rayTraceResultIn) {
|
||||
super(worldIn, player, handIn, heldItem, rayTraceResultIn);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,13 +18,12 @@
|
||||
|
||||
package appeng.parts.automation;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import appeng.api.parts.IPart;
|
||||
import appeng.api.parts.IPartHost;
|
||||
import appeng.api.parts.IPartModel;
|
||||
import appeng.api.util.AEPartLocation;
|
||||
import appeng.items.parts.PartModels;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.enchantment.EnchantmentHelper;
|
||||
import net.minecraft.enchantment.Enchantments;
|
||||
@@ -34,71 +33,65 @@ import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.server.ServerWorld;
|
||||
import net.minecraftforge.client.model.data.IModelData;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.List;
|
||||
import appeng.api.parts.IPart;
|
||||
import appeng.api.parts.IPartHost;
|
||||
import appeng.api.parts.IPartModel;
|
||||
import appeng.api.util.AEPartLocation;
|
||||
import appeng.items.parts.PartModels;
|
||||
|
||||
public class PartIdentityAnnihilationPlane extends PartAnnihilationPlane {
|
||||
|
||||
public class PartIdentityAnnihilationPlane extends PartAnnihilationPlane
|
||||
{
|
||||
private static final PlaneModels MODELS = new PlaneModels("part/identity_annihilation_plane",
|
||||
"part/identity_annihilation_plane_on");
|
||||
|
||||
private static final PlaneModels MODELS = new PlaneModels( "part/identity_annihilation_plane", "part/identity_annihilation_plane_on" );
|
||||
@PartModels
|
||||
public static List<IPartModel> getModels() {
|
||||
return MODELS.getModels();
|
||||
}
|
||||
|
||||
@PartModels
|
||||
public static List<IPartModel> getModels()
|
||||
{
|
||||
return MODELS.getModels();
|
||||
}
|
||||
private static final float SILK_TOUCH_FACTOR = 16;
|
||||
|
||||
private static final float SILK_TOUCH_FACTOR = 16;
|
||||
public PartIdentityAnnihilationPlane(final ItemStack is) {
|
||||
super(is);
|
||||
}
|
||||
|
||||
public PartIdentityAnnihilationPlane( final ItemStack is )
|
||||
{
|
||||
super( is );
|
||||
}
|
||||
@Override
|
||||
protected boolean isAnnihilationPlane(final TileEntity blockTileEntity, final AEPartLocation side) {
|
||||
if (blockTileEntity instanceof IPartHost) {
|
||||
final IPart p = ((IPartHost) blockTileEntity).getPart(side);
|
||||
return p != null && p.getClass() == this.getClass();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isAnnihilationPlane( final TileEntity blockTileEntity, final AEPartLocation side )
|
||||
{
|
||||
if( blockTileEntity instanceof IPartHost )
|
||||
{
|
||||
final IPart p = ( (IPartHost) blockTileEntity ).getPart( side );
|
||||
return p != null && p.getClass() == this.getClass();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
protected float calculateEnergyUsage(final ServerWorld w, final BlockPos pos, final List<ItemStack> items) {
|
||||
final float requiredEnergy = super.calculateEnergyUsage(w, pos, items);
|
||||
|
||||
@Override
|
||||
protected float calculateEnergyUsage(final ServerWorld w, final BlockPos pos, final List<ItemStack> items )
|
||||
{
|
||||
final float requiredEnergy = super.calculateEnergyUsage( w, pos, items );
|
||||
return requiredEnergy * SILK_TOUCH_FACTOR;
|
||||
}
|
||||
|
||||
return requiredEnergy * SILK_TOUCH_FACTOR;
|
||||
}
|
||||
@Override
|
||||
protected ItemStack createHarvestTool(BlockState state) {
|
||||
ItemStack harvestTool = super.createHarvestTool(state);
|
||||
|
||||
@Override
|
||||
protected ItemStack createHarvestTool(BlockState state) {
|
||||
ItemStack harvestTool = super.createHarvestTool(state);
|
||||
// For silk touch purposes, enchant the fake tool
|
||||
if (harvestTool != null) {
|
||||
EnchantmentHelper.setEnchantments(ImmutableMap.of(Enchantments.SILK_TOUCH, 1), harvestTool);
|
||||
}
|
||||
|
||||
// For silk touch purposes, enchant the fake tool
|
||||
if (harvestTool != null) {
|
||||
EnchantmentHelper.setEnchantments(ImmutableMap.of(
|
||||
Enchantments.SILK_TOUCH, 1
|
||||
), harvestTool);
|
||||
}
|
||||
return harvestTool;
|
||||
}
|
||||
|
||||
return harvestTool;
|
||||
}
|
||||
@Override
|
||||
public IPartModel getStaticModels() {
|
||||
return MODELS.getModel(this.isPowered(), this.isActive());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPartModel getStaticModels()
|
||||
{
|
||||
return MODELS.getModel( this.isPowered(), this.isActive() );
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public IModelData getModelData() {
|
||||
return new PlaneModelData(getConnections());
|
||||
}
|
||||
@Nonnull
|
||||
@Override
|
||||
public IModelData getModelData() {
|
||||
return new PlaneModelData(getConnections());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,14 +18,9 @@
|
||||
|
||||
package appeng.parts.automation;
|
||||
|
||||
|
||||
import appeng.container.ContainerLocator;
|
||||
import appeng.container.ContainerOpener;
|
||||
import appeng.container.implementations.ContainerUpgradeable;
|
||||
import appeng.fluids.container.ContainerFluidInterface;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
@@ -48,8 +43,12 @@ import appeng.api.storage.IMEMonitor;
|
||||
import appeng.api.storage.channels.IItemStorageChannel;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.util.AECableType;
|
||||
import appeng.container.ContainerLocator;
|
||||
import appeng.container.ContainerOpener;
|
||||
import appeng.container.implementations.ContainerUpgradeable;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.core.settings.TickRates;
|
||||
import appeng.fluids.container.ContainerFluidInterface;
|
||||
import appeng.helpers.Reflected;
|
||||
import appeng.items.parts.PartModels;
|
||||
import appeng.me.GridAccessException;
|
||||
@@ -60,270 +59,219 @@ import appeng.util.Platform;
|
||||
import appeng.util.inv.IInventoryDestination;
|
||||
import appeng.util.item.AEItemStack;
|
||||
|
||||
public class PartImportBus extends PartSharedItemBus implements IInventoryDestination {
|
||||
|
||||
public class PartImportBus extends PartSharedItemBus implements IInventoryDestination
|
||||
{
|
||||
public static final ResourceLocation MODEL_BASE = new ResourceLocation(AppEng.MOD_ID, "part/import_bus_base");
|
||||
@PartModels
|
||||
public static final IPartModel MODELS_OFF = new PartModel(MODEL_BASE,
|
||||
new ResourceLocation(AppEng.MOD_ID, "part/import_bus_off"));
|
||||
@PartModels
|
||||
public static final IPartModel MODELS_ON = new PartModel(MODEL_BASE,
|
||||
new ResourceLocation(AppEng.MOD_ID, "part/import_bus_on"));
|
||||
@PartModels
|
||||
public static final IPartModel MODELS_HAS_CHANNEL = new PartModel(MODEL_BASE,
|
||||
new ResourceLocation(AppEng.MOD_ID, "part/import_bus_has_channel"));
|
||||
|
||||
public static final ResourceLocation MODEL_BASE = new ResourceLocation( AppEng.MOD_ID, "part/import_bus_base" );
|
||||
@PartModels
|
||||
public static final IPartModel MODELS_OFF = new PartModel( MODEL_BASE, new ResourceLocation( AppEng.MOD_ID, "part/import_bus_off" ) );
|
||||
@PartModels
|
||||
public static final IPartModel MODELS_ON = new PartModel( MODEL_BASE, new ResourceLocation( AppEng.MOD_ID, "part/import_bus_on" ) );
|
||||
@PartModels
|
||||
public static final IPartModel MODELS_HAS_CHANNEL = new PartModel( MODEL_BASE, new ResourceLocation( AppEng.MOD_ID, "part/import_bus_has_channel" ) );
|
||||
private final IActionSource source;
|
||||
private int itemsToSend; // used in tickingRequest
|
||||
private boolean worked; // used in tickingRequest
|
||||
|
||||
private final IActionSource source;
|
||||
private int itemsToSend; // used in tickingRequest
|
||||
private boolean worked; // used in tickingRequest
|
||||
@Reflected
|
||||
public PartImportBus(final ItemStack is) {
|
||||
super(is);
|
||||
|
||||
@Reflected
|
||||
public PartImportBus( final ItemStack is )
|
||||
{
|
||||
super( is );
|
||||
this.getConfigManager().registerSetting(Settings.REDSTONE_CONTROLLED, RedstoneMode.IGNORE);
|
||||
this.getConfigManager().registerSetting(Settings.FUZZY_MODE, FuzzyMode.IGNORE_ALL);
|
||||
this.source = new MachineSource(this);
|
||||
}
|
||||
|
||||
this.getConfigManager().registerSetting( Settings.REDSTONE_CONTROLLED, RedstoneMode.IGNORE );
|
||||
this.getConfigManager().registerSetting( Settings.FUZZY_MODE, FuzzyMode.IGNORE_ALL );
|
||||
this.source = new MachineSource( this );
|
||||
}
|
||||
@Override
|
||||
public boolean canInsert(final ItemStack stack) {
|
||||
if (stack.isEmpty() || stack.getItem() == Items.AIR) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInsert( final ItemStack stack )
|
||||
{
|
||||
if( stack.isEmpty() || stack.getItem() == Items.AIR )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
final IMEMonitor<IAEItemStack> inv = this.getProxy().getStorage()
|
||||
.getInventory(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class));
|
||||
|
||||
try
|
||||
{
|
||||
final IMEMonitor<IAEItemStack> inv = this.getProxy()
|
||||
.getStorage()
|
||||
.getInventory(
|
||||
AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) );
|
||||
final IAEItemStack out = inv.injectItems(
|
||||
AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createStack(stack),
|
||||
Actionable.SIMULATE, this.source);
|
||||
if (out == null) {
|
||||
return true;
|
||||
}
|
||||
return out.getStackSize() != stack.getCount();
|
||||
} catch (GridAccessException ex) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
final IAEItemStack out = inv.injectItems( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createStack( stack ),
|
||||
Actionable.SIMULATE,
|
||||
this.source );
|
||||
if( out == null )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return out.getStackSize() != stack.getCount();
|
||||
}
|
||||
catch( GridAccessException ex )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void getBoxes(final IPartCollisionHelper bch) {
|
||||
bch.addBox(6, 6, 11, 10, 10, 13);
|
||||
bch.addBox(5, 5, 13, 11, 11, 14);
|
||||
bch.addBox(4, 4, 14, 12, 12, 16);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getBoxes( final IPartCollisionHelper bch )
|
||||
{
|
||||
bch.addBox( 6, 6, 11, 10, 10, 13 );
|
||||
bch.addBox( 5, 5, 13, 11, 11, 14 );
|
||||
bch.addBox( 4, 4, 14, 12, 12, 16 );
|
||||
}
|
||||
@Override
|
||||
public float getCableConnectionLength(AECableType cable) {
|
||||
return 5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getCableConnectionLength( AECableType cable )
|
||||
{
|
||||
return 5;
|
||||
}
|
||||
@Override
|
||||
public boolean onPartActivate(final PlayerEntity player, final Hand hand, final Vec3d pos) {
|
||||
if (Platform.isServer()) {
|
||||
ContainerOpener.openContainer(ContainerUpgradeable.TYPE, player, ContainerLocator.forPart(this));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPartActivate( final PlayerEntity player, final Hand hand, final Vec3d pos )
|
||||
{
|
||||
if( Platform.isServer() )
|
||||
{
|
||||
ContainerOpener.openContainer(ContainerUpgradeable.TYPE, player, ContainerLocator.forPart(this));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public TickingRequest getTickingRequest(final IGridNode node) {
|
||||
return new TickingRequest(TickRates.ImportBus.getMin(), TickRates.ImportBus.getMax(), this.isSleeping(), false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickingRequest getTickingRequest( final IGridNode node )
|
||||
{
|
||||
return new TickingRequest( TickRates.ImportBus.getMin(), TickRates.ImportBus.getMax(), this.isSleeping(), false );
|
||||
}
|
||||
@Override
|
||||
public TickRateModulation tickingRequest(final IGridNode node, final int ticksSinceLastCall) {
|
||||
return this.doBusWork();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickRateModulation tickingRequest( final IGridNode node, final int ticksSinceLastCall )
|
||||
{
|
||||
return this.doBusWork();
|
||||
}
|
||||
@Override
|
||||
protected TickRateModulation doBusWork() {
|
||||
if (!this.getProxy().isActive() || !this.canDoBusWork()) {
|
||||
return TickRateModulation.IDLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TickRateModulation doBusWork()
|
||||
{
|
||||
if( !this.getProxy().isActive() || !this.canDoBusWork() )
|
||||
{
|
||||
return TickRateModulation.IDLE;
|
||||
}
|
||||
this.worked = false;
|
||||
|
||||
this.worked = false;
|
||||
final InventoryAdaptor myAdaptor = this.getHandler();
|
||||
final FuzzyMode fzMode = (FuzzyMode) this.getConfigManager().getSetting(Settings.FUZZY_MODE);
|
||||
|
||||
final InventoryAdaptor myAdaptor = this.getHandler();
|
||||
final FuzzyMode fzMode = (FuzzyMode) this.getConfigManager().getSetting( Settings.FUZZY_MODE );
|
||||
if (myAdaptor != null) {
|
||||
try {
|
||||
this.itemsToSend = this.calculateItemsToSend();
|
||||
|
||||
if( myAdaptor != null )
|
||||
{
|
||||
try
|
||||
{
|
||||
this.itemsToSend = this.calculateItemsToSend();
|
||||
final IMEMonitor<IAEItemStack> inv = this.getProxy().getStorage()
|
||||
.getInventory(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class));
|
||||
final IEnergyGrid energy = this.getProxy().getEnergy();
|
||||
|
||||
final IMEMonitor<IAEItemStack> inv = this.getProxy()
|
||||
.getStorage()
|
||||
.getInventory(
|
||||
AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) );
|
||||
final IEnergyGrid energy = this.getProxy().getEnergy();
|
||||
boolean Configured = false;
|
||||
for (int x = 0; x < this.availableSlots(); x++) {
|
||||
final IAEItemStack ais = this.getConfig().getAEStackInSlot(x);
|
||||
if (ais != null && this.itemsToSend > 0) {
|
||||
Configured = true;
|
||||
while (this.itemsToSend > 0) {
|
||||
if (this.importStuff(myAdaptor, ais, inv, energy, fzMode)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boolean Configured = false;
|
||||
for( int x = 0; x < this.availableSlots(); x++ )
|
||||
{
|
||||
final IAEItemStack ais = this.getConfig().getAEStackInSlot( x );
|
||||
if( ais != null && this.itemsToSend > 0 )
|
||||
{
|
||||
Configured = true;
|
||||
while( this.itemsToSend > 0 )
|
||||
{
|
||||
if( this.importStuff( myAdaptor, ais, inv, energy, fzMode ) )
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!Configured) {
|
||||
while (this.itemsToSend > 0) {
|
||||
if (this.importStuff(myAdaptor, null, inv, energy, fzMode)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (final GridAccessException e) {
|
||||
// :3
|
||||
}
|
||||
} else {
|
||||
return TickRateModulation.SLEEP;
|
||||
}
|
||||
|
||||
if( !Configured )
|
||||
{
|
||||
while( this.itemsToSend > 0 )
|
||||
{
|
||||
if( this.importStuff( myAdaptor, null, inv, energy, fzMode ) )
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch( final GridAccessException e )
|
||||
{
|
||||
// :3
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return TickRateModulation.SLEEP;
|
||||
}
|
||||
return this.worked ? TickRateModulation.FASTER : TickRateModulation.SLOWER;
|
||||
}
|
||||
|
||||
return this.worked ? TickRateModulation.FASTER : TickRateModulation.SLOWER;
|
||||
}
|
||||
private boolean importStuff(final InventoryAdaptor myAdaptor, final IAEItemStack whatToImport,
|
||||
final IMEMonitor<IAEItemStack> inv, final IEnergySource energy, final FuzzyMode fzMode) {
|
||||
final int toSend = this.calculateMaximumAmountToImport(myAdaptor, whatToImport, inv, fzMode);
|
||||
final ItemStack newItems;
|
||||
|
||||
private boolean importStuff( final InventoryAdaptor myAdaptor, final IAEItemStack whatToImport, final IMEMonitor<IAEItemStack> inv, final IEnergySource energy, final FuzzyMode fzMode )
|
||||
{
|
||||
final int toSend = this.calculateMaximumAmountToImport( myAdaptor, whatToImport, inv, fzMode );
|
||||
final ItemStack newItems;
|
||||
if (this.getInstalledUpgrades(Upgrades.FUZZY) > 0) {
|
||||
newItems = myAdaptor.removeSimilarItems(toSend,
|
||||
whatToImport == null ? ItemStack.EMPTY : whatToImport.getDefinition(), fzMode, this);
|
||||
} else {
|
||||
newItems = myAdaptor.removeItems(toSend,
|
||||
whatToImport == null ? ItemStack.EMPTY : whatToImport.getDefinition(), this);
|
||||
}
|
||||
|
||||
if( this.getInstalledUpgrades( Upgrades.FUZZY ) > 0 )
|
||||
{
|
||||
newItems = myAdaptor.removeSimilarItems( toSend, whatToImport == null ? ItemStack.EMPTY : whatToImport.getDefinition(), fzMode, this );
|
||||
}
|
||||
else
|
||||
{
|
||||
newItems = myAdaptor.removeItems( toSend, whatToImport == null ? ItemStack.EMPTY : whatToImport.getDefinition(), this );
|
||||
}
|
||||
if (!newItems.isEmpty()) {
|
||||
final IAEItemStack aeStack = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)
|
||||
.createStack(newItems);
|
||||
final IAEItemStack failed = Platform.poweredInsert(energy, inv, aeStack, this.source);
|
||||
|
||||
if( !newItems.isEmpty() )
|
||||
{
|
||||
final IAEItemStack aeStack = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createStack( newItems );
|
||||
final IAEItemStack failed = Platform.poweredInsert( energy, inv, aeStack, this.source );
|
||||
if (failed != null) {
|
||||
// try unpowered insert, better be a bit lenient then void items
|
||||
final IAEItemStack spill = inv.injectItems(failed, Actionable.MODULATE, this.source);
|
||||
if (spill != null) {
|
||||
// last resort try to put it back .. lets hope it's a chest type of thing
|
||||
myAdaptor.addItems(spill.createItemStack());
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
this.itemsToSend -= newItems.getCount();
|
||||
this.worked = true;
|
||||
}
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
|
||||
if( failed != null )
|
||||
{
|
||||
// try unpowered insert, better be a bit lenient then void items
|
||||
final IAEItemStack spill = inv.injectItems( failed, Actionable.MODULATE, this.source );
|
||||
if( spill != null )
|
||||
{
|
||||
// last resort try to put it back .. lets hope it's a chest type of thing
|
||||
myAdaptor.addItems( spill.createItemStack() );
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.itemsToSend -= newItems.getCount();
|
||||
this.worked = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
private int calculateMaximumAmountToImport(final InventoryAdaptor myAdaptor, final IAEItemStack whatToImport,
|
||||
final IMEMonitor<IAEItemStack> inv, final FuzzyMode fzMode) {
|
||||
final int toSend = Math.min(this.itemsToSend, 64);
|
||||
final ItemStack itemStackToImport;
|
||||
|
||||
private int calculateMaximumAmountToImport( final InventoryAdaptor myAdaptor, final IAEItemStack whatToImport, final IMEMonitor<IAEItemStack> inv, final FuzzyMode fzMode )
|
||||
{
|
||||
final int toSend = Math.min( this.itemsToSend, 64 );
|
||||
final ItemStack itemStackToImport;
|
||||
if (whatToImport == null) {
|
||||
itemStackToImport = ItemStack.EMPTY;
|
||||
} else {
|
||||
itemStackToImport = whatToImport.getDefinition();
|
||||
}
|
||||
|
||||
if( whatToImport == null )
|
||||
{
|
||||
itemStackToImport = ItemStack.EMPTY;
|
||||
}
|
||||
else
|
||||
{
|
||||
itemStackToImport = whatToImport.getDefinition();
|
||||
}
|
||||
final IAEItemStack itemAmountNotStorable;
|
||||
final ItemStack simResult;
|
||||
if (this.getInstalledUpgrades(Upgrades.FUZZY) > 0) {
|
||||
simResult = myAdaptor.simulateSimilarRemove(toSend, itemStackToImport, fzMode, this);
|
||||
itemAmountNotStorable = inv.injectItems(AEItemStack.fromItemStack(simResult), Actionable.SIMULATE,
|
||||
this.source);
|
||||
} else {
|
||||
simResult = myAdaptor.simulateRemove(toSend, itemStackToImport, this);
|
||||
itemAmountNotStorable = inv.injectItems(AEItemStack.fromItemStack(simResult), Actionable.SIMULATE,
|
||||
this.source);
|
||||
}
|
||||
|
||||
final IAEItemStack itemAmountNotStorable;
|
||||
final ItemStack simResult;
|
||||
if( this.getInstalledUpgrades( Upgrades.FUZZY ) > 0 )
|
||||
{
|
||||
simResult = myAdaptor.simulateSimilarRemove( toSend, itemStackToImport, fzMode, this );
|
||||
itemAmountNotStorable = inv.injectItems( AEItemStack.fromItemStack( simResult ), Actionable.SIMULATE, this.source );
|
||||
}
|
||||
else
|
||||
{
|
||||
simResult = myAdaptor.simulateRemove( toSend, itemStackToImport, this );
|
||||
itemAmountNotStorable = inv.injectItems( AEItemStack.fromItemStack( simResult ), Actionable.SIMULATE, this.source );
|
||||
}
|
||||
if (itemAmountNotStorable != null) {
|
||||
return (int) Math.min(simResult.getCount() - itemAmountNotStorable.getStackSize(), toSend);
|
||||
}
|
||||
|
||||
if( itemAmountNotStorable != null )
|
||||
{
|
||||
return (int) Math.min( simResult.getCount() - itemAmountNotStorable.getStackSize(), toSend );
|
||||
}
|
||||
return toSend;
|
||||
}
|
||||
|
||||
return toSend;
|
||||
}
|
||||
@Override
|
||||
protected boolean isSleeping() {
|
||||
return this.getHandler() == null || super.isSleeping();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isSleeping()
|
||||
{
|
||||
return this.getHandler() == null || super.isSleeping();
|
||||
}
|
||||
@Override
|
||||
public RedstoneMode getRSMode() {
|
||||
return (RedstoneMode) this.getConfigManager().getSetting(Settings.REDSTONE_CONTROLLED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedstoneMode getRSMode()
|
||||
{
|
||||
return (RedstoneMode) this.getConfigManager().getSetting( Settings.REDSTONE_CONTROLLED );
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPartModel getStaticModels()
|
||||
{
|
||||
if( this.isActive() && this.isPowered() )
|
||||
{
|
||||
return MODELS_HAS_CHANNEL;
|
||||
}
|
||||
else if( this.isPowered() )
|
||||
{
|
||||
return MODELS_ON;
|
||||
}
|
||||
else
|
||||
{
|
||||
return MODELS_OFF;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public IPartModel getStaticModels() {
|
||||
if (this.isActive() && this.isPowered()) {
|
||||
return MODELS_HAS_CHANNEL;
|
||||
} else if (this.isPowered()) {
|
||||
return MODELS_ON;
|
||||
} else {
|
||||
return MODELS_OFF;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,13 +18,9 @@
|
||||
|
||||
package appeng.parts.automation;
|
||||
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Random;
|
||||
|
||||
import appeng.container.ContainerLocator;
|
||||
import appeng.container.ContainerOpener;
|
||||
import appeng.container.implementations.ContainerLevelEmitter;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.inventory.CraftingInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -74,8 +70,10 @@ import appeng.api.storage.data.IItemList;
|
||||
import appeng.api.util.AECableType;
|
||||
import appeng.api.util.AEPartLocation;
|
||||
import appeng.api.util.IConfigManager;
|
||||
import appeng.container.ContainerLocator;
|
||||
import appeng.container.ContainerOpener;
|
||||
import appeng.container.implementations.ContainerLevelEmitter;
|
||||
import appeng.core.AppEng;
|
||||
|
||||
import appeng.helpers.Reflected;
|
||||
import appeng.items.parts.PartModels;
|
||||
import appeng.me.GridAccessException;
|
||||
@@ -84,493 +82,417 @@ import appeng.tile.inventory.AppEngInternalAEInventory;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.inv.InvOperation;
|
||||
|
||||
|
||||
public class PartLevelEmitter extends PartUpgradeable implements IEnergyWatcherHost, IStackWatcherHost, ICraftingWatcherHost, IMEMonitorHandlerReceiver<IAEItemStack>, ICraftingProvider
|
||||
{
|
||||
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_BASE_OFF = new ResourceLocation( AppEng.MOD_ID, "part/level_emitter_base_off" );
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_BASE_ON = new ResourceLocation( AppEng.MOD_ID, "part/level_emitter_base_on" );
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_STATUS_OFF = new ResourceLocation( AppEng.MOD_ID, "part/level_emitter_status_off" );
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_STATUS_ON = new ResourceLocation( AppEng.MOD_ID, "part/level_emitter_status_on" );
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_STATUS_HAS_CHANNEL = new ResourceLocation( AppEng.MOD_ID, "part/level_emitter_status_has_channel" );
|
||||
|
||||
public static final PartModel MODEL_OFF_OFF = new PartModel( MODEL_BASE_OFF, MODEL_STATUS_OFF );
|
||||
public static final PartModel MODEL_OFF_ON = new PartModel( MODEL_BASE_OFF, MODEL_STATUS_ON );
|
||||
public static final PartModel MODEL_OFF_HAS_CHANNEL = new PartModel( MODEL_BASE_OFF, MODEL_STATUS_HAS_CHANNEL );
|
||||
public static final PartModel MODEL_ON_OFF = new PartModel( MODEL_BASE_ON, MODEL_STATUS_OFF );
|
||||
public static final PartModel MODEL_ON_ON = new PartModel( MODEL_BASE_ON, MODEL_STATUS_ON );
|
||||
public static final PartModel MODEL_ON_HAS_CHANNEL = new PartModel( MODEL_BASE_ON, MODEL_STATUS_HAS_CHANNEL );
|
||||
|
||||
private static final int FLAG_ON = 4;
|
||||
|
||||
private final AppEngInternalAEInventory config = new AppEngInternalAEInventory( this, 1 );
|
||||
|
||||
private boolean prevState = false;
|
||||
|
||||
private long lastReportedValue = 0;
|
||||
private long reportingValue = 0;
|
||||
|
||||
private IStackWatcher myWatcher;
|
||||
private IEnergyWatcher myEnergyWatcher;
|
||||
private ICraftingWatcher myCraftingWatcher;
|
||||
private double centerX;
|
||||
private double centerY;
|
||||
private double centerZ;
|
||||
|
||||
@Reflected
|
||||
public PartLevelEmitter( final ItemStack is )
|
||||
{
|
||||
super( is );
|
||||
|
||||
this.getConfigManager().registerSetting( Settings.REDSTONE_EMITTER, RedstoneMode.HIGH_SIGNAL );
|
||||
this.getConfigManager().registerSetting( Settings.FUZZY_MODE, FuzzyMode.IGNORE_ALL );
|
||||
this.getConfigManager().registerSetting( Settings.LEVEL_TYPE, LevelType.ITEM_LEVEL );
|
||||
this.getConfigManager().registerSetting( Settings.CRAFT_VIA_REDSTONE, YesNo.NO );
|
||||
}
|
||||
|
||||
public long getReportingValue()
|
||||
{
|
||||
return this.reportingValue;
|
||||
}
|
||||
|
||||
public void setReportingValue( final long v )
|
||||
{
|
||||
this.reportingValue = v;
|
||||
if( this.getConfigManager().getSetting( Settings.LEVEL_TYPE ) == LevelType.ENERGY_LEVEL )
|
||||
{
|
||||
this.configureWatchers();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.updateState();
|
||||
}
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void powerChanged( final MENetworkPowerStatusChange c )
|
||||
{
|
||||
this.updateState();
|
||||
}
|
||||
|
||||
private void updateState()
|
||||
{
|
||||
final boolean isOn = this.isLevelEmitterOn();
|
||||
if( this.prevState != isOn )
|
||||
{
|
||||
this.getHost().markForUpdate();
|
||||
final TileEntity te = this.getHost().getTile();
|
||||
this.prevState = isOn;
|
||||
Platform.notifyBlocksOfNeighbors( te.getWorld(), te.getPos() );
|
||||
Platform.notifyBlocksOfNeighbors( te.getWorld(), te.getPos().offset( this.getSide().getFacing() ) );
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Make private again
|
||||
public boolean isLevelEmitterOn()
|
||||
{
|
||||
if( Platform.isClient() )
|
||||
{
|
||||
return ( this.getClientFlags() & FLAG_ON ) == FLAG_ON;
|
||||
}
|
||||
|
||||
if( !this.getProxy().isActive() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if( this.getInstalledUpgrades( Upgrades.CRAFTING ) > 0 )
|
||||
{
|
||||
try
|
||||
{
|
||||
return this.getProxy().getCrafting().isRequesting( this.config.getAEStackInSlot( 0 ) );
|
||||
}
|
||||
catch( final GridAccessException e )
|
||||
{
|
||||
// :P
|
||||
}
|
||||
|
||||
return this.prevState;
|
||||
}
|
||||
|
||||
final boolean flipState = this.getConfigManager().getSetting( Settings.REDSTONE_EMITTER ) == RedstoneMode.LOW_SIGNAL;
|
||||
return flipState ? this.reportingValue >= this.lastReportedValue + 1 : this.reportingValue < this.lastReportedValue + 1;
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void channelChanged( final MENetworkChannelsChanged c )
|
||||
{
|
||||
this.updateState();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int populateFlags( final int cf )
|
||||
{
|
||||
return cf | ( this.prevState ? FLAG_ON : 0 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateWatcher( final ICraftingWatcher newWatcher )
|
||||
{
|
||||
this.myCraftingWatcher = newWatcher;
|
||||
this.configureWatchers();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestChange( final ICraftingGrid craftingGrid, final IAEItemStack what )
|
||||
{
|
||||
this.updateState();
|
||||
}
|
||||
|
||||
// update the system...
|
||||
private void configureWatchers()
|
||||
{
|
||||
final IAEItemStack myStack = this.config.getAEStackInSlot( 0 );
|
||||
|
||||
if( this.myWatcher != null )
|
||||
{
|
||||
this.myWatcher.reset();
|
||||
}
|
||||
|
||||
if( this.myEnergyWatcher != null )
|
||||
{
|
||||
this.myEnergyWatcher.reset();
|
||||
}
|
||||
|
||||
if( this.myCraftingWatcher != null )
|
||||
{
|
||||
this.myCraftingWatcher.reset();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
this.getProxy().getGrid().postEvent( new MENetworkCraftingPatternChange( this, this.getProxy().getNode() ) );
|
||||
}
|
||||
catch( final GridAccessException e1 )
|
||||
{
|
||||
// :/
|
||||
}
|
||||
|
||||
if( this.getInstalledUpgrades( Upgrades.CRAFTING ) > 0 )
|
||||
{
|
||||
if( this.myCraftingWatcher != null && myStack != null )
|
||||
{
|
||||
this.myCraftingWatcher.add( myStack );
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if( this.getConfigManager().getSetting( Settings.LEVEL_TYPE ) == LevelType.ENERGY_LEVEL )
|
||||
{
|
||||
if( this.myEnergyWatcher != null )
|
||||
{
|
||||
this.myEnergyWatcher.add( this.reportingValue );
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// update to power...
|
||||
this.lastReportedValue = (long) this.getProxy().getEnergy().getStoredPower();
|
||||
this.updateState();
|
||||
|
||||
// no more item stuff..
|
||||
this.getProxy().getStorage().getInventory( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) ).removeListener( this );
|
||||
}
|
||||
catch( final GridAccessException e )
|
||||
{
|
||||
// :P
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if( this.getInstalledUpgrades( Upgrades.FUZZY ) > 0 || myStack == null )
|
||||
{
|
||||
this.getProxy().getStorage().getInventory( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) ).addListener( this, this.getProxy().getGrid() );
|
||||
}
|
||||
else
|
||||
{
|
||||
this.getProxy().getStorage().getInventory( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) ).removeListener( this );
|
||||
|
||||
if( this.myWatcher != null )
|
||||
{
|
||||
this.myWatcher.add( myStack );
|
||||
}
|
||||
}
|
||||
|
||||
this.updateReportingValue( this.getProxy().getStorage().getInventory( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) ) );
|
||||
}
|
||||
catch( final GridAccessException e )
|
||||
{
|
||||
// >.>
|
||||
}
|
||||
}
|
||||
|
||||
private void updateReportingValue( final IMEMonitor<IAEItemStack> monitor )
|
||||
{
|
||||
final IAEItemStack myStack = this.config.getAEStackInSlot( 0 );
|
||||
|
||||
if( myStack == null )
|
||||
{
|
||||
this.lastReportedValue = 0;
|
||||
for( final IAEItemStack st : monitor.getStorageList() )
|
||||
{
|
||||
this.lastReportedValue += st.getStackSize();
|
||||
}
|
||||
}
|
||||
else if( this.getInstalledUpgrades( Upgrades.FUZZY ) > 0 )
|
||||
{
|
||||
this.lastReportedValue = 0;
|
||||
final FuzzyMode fzMode = (FuzzyMode) this.getConfigManager().getSetting( Settings.FUZZY_MODE );
|
||||
final Collection<IAEItemStack> fuzzyList = monitor.getStorageList().findFuzzy( myStack, fzMode );
|
||||
for( final IAEItemStack st : fuzzyList )
|
||||
{
|
||||
this.lastReportedValue += st.getStackSize();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
final IAEItemStack r = monitor.getStorageList().findPrecise( myStack );
|
||||
if( r == null )
|
||||
{
|
||||
this.lastReportedValue = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.lastReportedValue = r.getStackSize();
|
||||
}
|
||||
}
|
||||
|
||||
this.updateState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateWatcher( final IStackWatcher newWatcher )
|
||||
{
|
||||
this.myWatcher = newWatcher;
|
||||
this.configureWatchers();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStackChange( final IItemList o, final IAEStack fullStack, final IAEStack diffStack, final IActionSource src, final IStorageChannel chan )
|
||||
{
|
||||
if( chan == AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) && fullStack.equals( this.config.getAEStackInSlot( 0 ) ) && this.getInstalledUpgrades( Upgrades.FUZZY ) == 0 )
|
||||
{
|
||||
this.lastReportedValue = fullStack.getStackSize();
|
||||
this.updateState();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateWatcher( final IEnergyWatcher newWatcher )
|
||||
{
|
||||
this.myEnergyWatcher = newWatcher;
|
||||
this.configureWatchers();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onThresholdPass( final IEnergyGrid energyGrid )
|
||||
{
|
||||
this.lastReportedValue = (long) energyGrid.getStoredPower();
|
||||
this.updateState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid( final Object effectiveGrid )
|
||||
{
|
||||
try
|
||||
{
|
||||
return this.getProxy().getGrid() == effectiveGrid;
|
||||
}
|
||||
catch( final GridAccessException e )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postChange( final IBaseMonitor<IAEItemStack> monitor, final Iterable<IAEItemStack> change, final IActionSource actionSource )
|
||||
{
|
||||
this.updateReportingValue( (IMEMonitor<IAEItemStack>) monitor );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onListUpdate()
|
||||
{
|
||||
try
|
||||
{
|
||||
this.updateReportingValue( this.getProxy().getStorage().getInventory( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) ) );
|
||||
}
|
||||
catch( final GridAccessException e )
|
||||
{
|
||||
// ;P
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public AECableType getCableConnectionType( final AEPartLocation dir )
|
||||
{
|
||||
return AECableType.SMART;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getBoxes( final IPartCollisionHelper bch )
|
||||
{
|
||||
bch.addBox( 7, 7, 11, 9, 9, 16 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int isProvidingStrongPower()
|
||||
{
|
||||
return this.prevState ? 15 : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int isProvidingWeakPower()
|
||||
{
|
||||
return this.prevState ? 15 : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void animateTick( final World world, final BlockPos pos, final Random r )
|
||||
{
|
||||
if( this.isLevelEmitterOn() )
|
||||
{
|
||||
final AEPartLocation d = this.getSide();
|
||||
|
||||
final double d0 = d.xOffset * 0.45F + ( r.nextFloat() - 0.5F ) * 0.2D;
|
||||
final double d1 = d.yOffset * 0.45F + ( r.nextFloat() - 0.5F ) * 0.2D;
|
||||
final double d2 = d.zOffset * 0.45F + ( r.nextFloat() - 0.5F ) * 0.2D;
|
||||
|
||||
world.addParticle( RedstoneParticleData.REDSTONE_DUST, 0.5 + pos.getX() + d0, 0.5 + pos.getY() + d1, 0.5 + pos.getZ() + d2, 0.0D, 0.0D, 0.0D );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getCableConnectionLength( AECableType cable )
|
||||
{
|
||||
return 16;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPartActivate( final PlayerEntity player, final Hand hand, final Vec3d pos )
|
||||
{
|
||||
if( Platform.isServer() )
|
||||
{
|
||||
ContainerOpener.openContainer(ContainerLevelEmitter.TYPE, player, ContainerLocator.forPart(this));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateSetting(final IConfigManager manager, final Settings settingName, final Enum<?> newValue )
|
||||
{
|
||||
this.configureWatchers();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChangeInventory( final IItemHandler inv, final int slot, final InvOperation mc, final ItemStack removedStack, final ItemStack newStack )
|
||||
{
|
||||
if( inv == this.config )
|
||||
{
|
||||
this.configureWatchers();
|
||||
}
|
||||
|
||||
super.onChangeInventory( inv, slot, mc, removedStack, newStack );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void upgradesChanged()
|
||||
{
|
||||
this.configureWatchers();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canConnectRedstone()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT( final CompoundNBT data )
|
||||
{
|
||||
super.readFromNBT( data );
|
||||
this.lastReportedValue = data.getLong( "lastReportedValue" );
|
||||
this.reportingValue = data.getLong( "reportingValue" );
|
||||
this.prevState = data.getBoolean( "prevState" );
|
||||
this.config.readFromNBT( data, "config" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT( final CompoundNBT data )
|
||||
{
|
||||
super.writeToNBT( data );
|
||||
data.putLong( "lastReportedValue", this.lastReportedValue );
|
||||
data.putLong( "reportingValue", this.reportingValue );
|
||||
data.putBoolean( "prevState", this.prevState );
|
||||
this.config.writeToNBT( data, "config" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemHandler getInventoryByName( final String name )
|
||||
{
|
||||
if( name.equals( "config" ) )
|
||||
{
|
||||
return this.config;
|
||||
}
|
||||
|
||||
return super.getInventoryByName( name );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean pushPattern( final ICraftingPatternDetails patternDetails, final CraftingInventory table )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBusy()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void provideCrafting( final ICraftingProviderHelper craftingTracker )
|
||||
{
|
||||
if( this.getInstalledUpgrades( Upgrades.CRAFTING ) > 0 )
|
||||
{
|
||||
if( this.getConfigManager().getSetting( Settings.CRAFT_VIA_REDSTONE ) == YesNo.YES )
|
||||
{
|
||||
final IAEItemStack what = this.config.getAEStackInSlot( 0 );
|
||||
if( what != null )
|
||||
{
|
||||
craftingTracker.setEmitable( what );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPartModel getStaticModels()
|
||||
{
|
||||
if( this.isActive() && this.isPowered() )
|
||||
{
|
||||
return this.isLevelEmitterOn() ? MODEL_ON_HAS_CHANNEL : MODEL_OFF_HAS_CHANNEL;
|
||||
}
|
||||
else if( this.isPowered() )
|
||||
{
|
||||
return this.isLevelEmitterOn() ? MODEL_ON_ON : MODEL_OFF_ON;
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.isLevelEmitterOn() ? MODEL_ON_OFF : MODEL_OFF_OFF;
|
||||
}
|
||||
}
|
||||
public class PartLevelEmitter extends PartUpgradeable implements IEnergyWatcherHost, IStackWatcherHost,
|
||||
ICraftingWatcherHost, IMEMonitorHandlerReceiver<IAEItemStack>, ICraftingProvider {
|
||||
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_BASE_OFF = new ResourceLocation(AppEng.MOD_ID,
|
||||
"part/level_emitter_base_off");
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_BASE_ON = new ResourceLocation(AppEng.MOD_ID,
|
||||
"part/level_emitter_base_on");
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_STATUS_OFF = new ResourceLocation(AppEng.MOD_ID,
|
||||
"part/level_emitter_status_off");
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_STATUS_ON = new ResourceLocation(AppEng.MOD_ID,
|
||||
"part/level_emitter_status_on");
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_STATUS_HAS_CHANNEL = new ResourceLocation(AppEng.MOD_ID,
|
||||
"part/level_emitter_status_has_channel");
|
||||
|
||||
public static final PartModel MODEL_OFF_OFF = new PartModel(MODEL_BASE_OFF, MODEL_STATUS_OFF);
|
||||
public static final PartModel MODEL_OFF_ON = new PartModel(MODEL_BASE_OFF, MODEL_STATUS_ON);
|
||||
public static final PartModel MODEL_OFF_HAS_CHANNEL = new PartModel(MODEL_BASE_OFF, MODEL_STATUS_HAS_CHANNEL);
|
||||
public static final PartModel MODEL_ON_OFF = new PartModel(MODEL_BASE_ON, MODEL_STATUS_OFF);
|
||||
public static final PartModel MODEL_ON_ON = new PartModel(MODEL_BASE_ON, MODEL_STATUS_ON);
|
||||
public static final PartModel MODEL_ON_HAS_CHANNEL = new PartModel(MODEL_BASE_ON, MODEL_STATUS_HAS_CHANNEL);
|
||||
|
||||
private static final int FLAG_ON = 4;
|
||||
|
||||
private final AppEngInternalAEInventory config = new AppEngInternalAEInventory(this, 1);
|
||||
|
||||
private boolean prevState = false;
|
||||
|
||||
private long lastReportedValue = 0;
|
||||
private long reportingValue = 0;
|
||||
|
||||
private IStackWatcher myWatcher;
|
||||
private IEnergyWatcher myEnergyWatcher;
|
||||
private ICraftingWatcher myCraftingWatcher;
|
||||
private double centerX;
|
||||
private double centerY;
|
||||
private double centerZ;
|
||||
|
||||
@Reflected
|
||||
public PartLevelEmitter(final ItemStack is) {
|
||||
super(is);
|
||||
|
||||
this.getConfigManager().registerSetting(Settings.REDSTONE_EMITTER, RedstoneMode.HIGH_SIGNAL);
|
||||
this.getConfigManager().registerSetting(Settings.FUZZY_MODE, FuzzyMode.IGNORE_ALL);
|
||||
this.getConfigManager().registerSetting(Settings.LEVEL_TYPE, LevelType.ITEM_LEVEL);
|
||||
this.getConfigManager().registerSetting(Settings.CRAFT_VIA_REDSTONE, YesNo.NO);
|
||||
}
|
||||
|
||||
public long getReportingValue() {
|
||||
return this.reportingValue;
|
||||
}
|
||||
|
||||
public void setReportingValue(final long v) {
|
||||
this.reportingValue = v;
|
||||
if (this.getConfigManager().getSetting(Settings.LEVEL_TYPE) == LevelType.ENERGY_LEVEL) {
|
||||
this.configureWatchers();
|
||||
} else {
|
||||
this.updateState();
|
||||
}
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void powerChanged(final MENetworkPowerStatusChange c) {
|
||||
this.updateState();
|
||||
}
|
||||
|
||||
private void updateState() {
|
||||
final boolean isOn = this.isLevelEmitterOn();
|
||||
if (this.prevState != isOn) {
|
||||
this.getHost().markForUpdate();
|
||||
final TileEntity te = this.getHost().getTile();
|
||||
this.prevState = isOn;
|
||||
Platform.notifyBlocksOfNeighbors(te.getWorld(), te.getPos());
|
||||
Platform.notifyBlocksOfNeighbors(te.getWorld(), te.getPos().offset(this.getSide().getFacing()));
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Make private again
|
||||
public boolean isLevelEmitterOn() {
|
||||
if (Platform.isClient()) {
|
||||
return (this.getClientFlags() & FLAG_ON) == FLAG_ON;
|
||||
}
|
||||
|
||||
if (!this.getProxy().isActive()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.getInstalledUpgrades(Upgrades.CRAFTING) > 0) {
|
||||
try {
|
||||
return this.getProxy().getCrafting().isRequesting(this.config.getAEStackInSlot(0));
|
||||
} catch (final GridAccessException e) {
|
||||
// :P
|
||||
}
|
||||
|
||||
return this.prevState;
|
||||
}
|
||||
|
||||
final boolean flipState = this.getConfigManager()
|
||||
.getSetting(Settings.REDSTONE_EMITTER) == RedstoneMode.LOW_SIGNAL;
|
||||
return flipState ? this.reportingValue >= this.lastReportedValue + 1
|
||||
: this.reportingValue < this.lastReportedValue + 1;
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void channelChanged(final MENetworkChannelsChanged c) {
|
||||
this.updateState();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int populateFlags(final int cf) {
|
||||
return cf | (this.prevState ? FLAG_ON : 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateWatcher(final ICraftingWatcher newWatcher) {
|
||||
this.myCraftingWatcher = newWatcher;
|
||||
this.configureWatchers();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestChange(final ICraftingGrid craftingGrid, final IAEItemStack what) {
|
||||
this.updateState();
|
||||
}
|
||||
|
||||
// update the system...
|
||||
private void configureWatchers() {
|
||||
final IAEItemStack myStack = this.config.getAEStackInSlot(0);
|
||||
|
||||
if (this.myWatcher != null) {
|
||||
this.myWatcher.reset();
|
||||
}
|
||||
|
||||
if (this.myEnergyWatcher != null) {
|
||||
this.myEnergyWatcher.reset();
|
||||
}
|
||||
|
||||
if (this.myCraftingWatcher != null) {
|
||||
this.myCraftingWatcher.reset();
|
||||
}
|
||||
|
||||
try {
|
||||
this.getProxy().getGrid().postEvent(new MENetworkCraftingPatternChange(this, this.getProxy().getNode()));
|
||||
} catch (final GridAccessException e1) {
|
||||
// :/
|
||||
}
|
||||
|
||||
if (this.getInstalledUpgrades(Upgrades.CRAFTING) > 0) {
|
||||
if (this.myCraftingWatcher != null && myStack != null) {
|
||||
this.myCraftingWatcher.add(myStack);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.getConfigManager().getSetting(Settings.LEVEL_TYPE) == LevelType.ENERGY_LEVEL) {
|
||||
if (this.myEnergyWatcher != null) {
|
||||
this.myEnergyWatcher.add(this.reportingValue);
|
||||
}
|
||||
|
||||
try {
|
||||
// update to power...
|
||||
this.lastReportedValue = (long) this.getProxy().getEnergy().getStoredPower();
|
||||
this.updateState();
|
||||
|
||||
// no more item stuff..
|
||||
this.getProxy().getStorage()
|
||||
.getInventory(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class))
|
||||
.removeListener(this);
|
||||
} catch (final GridAccessException e) {
|
||||
// :P
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
if (this.getInstalledUpgrades(Upgrades.FUZZY) > 0 || myStack == null) {
|
||||
this.getProxy().getStorage()
|
||||
.getInventory(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class))
|
||||
.addListener(this, this.getProxy().getGrid());
|
||||
} else {
|
||||
this.getProxy().getStorage()
|
||||
.getInventory(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class))
|
||||
.removeListener(this);
|
||||
|
||||
if (this.myWatcher != null) {
|
||||
this.myWatcher.add(myStack);
|
||||
}
|
||||
}
|
||||
|
||||
this.updateReportingValue(this.getProxy().getStorage()
|
||||
.getInventory(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)));
|
||||
} catch (final GridAccessException e) {
|
||||
// >.>
|
||||
}
|
||||
}
|
||||
|
||||
private void updateReportingValue(final IMEMonitor<IAEItemStack> monitor) {
|
||||
final IAEItemStack myStack = this.config.getAEStackInSlot(0);
|
||||
|
||||
if (myStack == null) {
|
||||
this.lastReportedValue = 0;
|
||||
for (final IAEItemStack st : monitor.getStorageList()) {
|
||||
this.lastReportedValue += st.getStackSize();
|
||||
}
|
||||
} else if (this.getInstalledUpgrades(Upgrades.FUZZY) > 0) {
|
||||
this.lastReportedValue = 0;
|
||||
final FuzzyMode fzMode = (FuzzyMode) this.getConfigManager().getSetting(Settings.FUZZY_MODE);
|
||||
final Collection<IAEItemStack> fuzzyList = monitor.getStorageList().findFuzzy(myStack, fzMode);
|
||||
for (final IAEItemStack st : fuzzyList) {
|
||||
this.lastReportedValue += st.getStackSize();
|
||||
}
|
||||
} else {
|
||||
final IAEItemStack r = monitor.getStorageList().findPrecise(myStack);
|
||||
if (r == null) {
|
||||
this.lastReportedValue = 0;
|
||||
} else {
|
||||
this.lastReportedValue = r.getStackSize();
|
||||
}
|
||||
}
|
||||
|
||||
this.updateState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateWatcher(final IStackWatcher newWatcher) {
|
||||
this.myWatcher = newWatcher;
|
||||
this.configureWatchers();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStackChange(final IItemList o, final IAEStack fullStack, final IAEStack diffStack,
|
||||
final IActionSource src, final IStorageChannel chan) {
|
||||
if (chan == AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)
|
||||
&& fullStack.equals(this.config.getAEStackInSlot(0))
|
||||
&& this.getInstalledUpgrades(Upgrades.FUZZY) == 0) {
|
||||
this.lastReportedValue = fullStack.getStackSize();
|
||||
this.updateState();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateWatcher(final IEnergyWatcher newWatcher) {
|
||||
this.myEnergyWatcher = newWatcher;
|
||||
this.configureWatchers();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onThresholdPass(final IEnergyGrid energyGrid) {
|
||||
this.lastReportedValue = (long) energyGrid.getStoredPower();
|
||||
this.updateState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(final Object effectiveGrid) {
|
||||
try {
|
||||
return this.getProxy().getGrid() == effectiveGrid;
|
||||
} catch (final GridAccessException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postChange(final IBaseMonitor<IAEItemStack> monitor, final Iterable<IAEItemStack> change,
|
||||
final IActionSource actionSource) {
|
||||
this.updateReportingValue((IMEMonitor<IAEItemStack>) monitor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onListUpdate() {
|
||||
try {
|
||||
this.updateReportingValue(this.getProxy().getStorage()
|
||||
.getInventory(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)));
|
||||
} catch (final GridAccessException e) {
|
||||
// ;P
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public AECableType getCableConnectionType(final AEPartLocation dir) {
|
||||
return AECableType.SMART;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getBoxes(final IPartCollisionHelper bch) {
|
||||
bch.addBox(7, 7, 11, 9, 9, 16);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int isProvidingStrongPower() {
|
||||
return this.prevState ? 15 : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int isProvidingWeakPower() {
|
||||
return this.prevState ? 15 : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void animateTick(final World world, final BlockPos pos, final Random r) {
|
||||
if (this.isLevelEmitterOn()) {
|
||||
final AEPartLocation d = this.getSide();
|
||||
|
||||
final double d0 = d.xOffset * 0.45F + (r.nextFloat() - 0.5F) * 0.2D;
|
||||
final double d1 = d.yOffset * 0.45F + (r.nextFloat() - 0.5F) * 0.2D;
|
||||
final double d2 = d.zOffset * 0.45F + (r.nextFloat() - 0.5F) * 0.2D;
|
||||
|
||||
world.addParticle(RedstoneParticleData.REDSTONE_DUST, 0.5 + pos.getX() + d0, 0.5 + pos.getY() + d1,
|
||||
0.5 + pos.getZ() + d2, 0.0D, 0.0D, 0.0D);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getCableConnectionLength(AECableType cable) {
|
||||
return 16;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPartActivate(final PlayerEntity player, final Hand hand, final Vec3d pos) {
|
||||
if (Platform.isServer()) {
|
||||
ContainerOpener.openContainer(ContainerLevelEmitter.TYPE, player, ContainerLocator.forPart(this));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateSetting(final IConfigManager manager, final Settings settingName, final Enum<?> newValue) {
|
||||
this.configureWatchers();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChangeInventory(final IItemHandler inv, final int slot, final InvOperation mc,
|
||||
final ItemStack removedStack, final ItemStack newStack) {
|
||||
if (inv == this.config) {
|
||||
this.configureWatchers();
|
||||
}
|
||||
|
||||
super.onChangeInventory(inv, slot, mc, removedStack, newStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void upgradesChanged() {
|
||||
this.configureWatchers();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canConnectRedstone() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(final CompoundNBT data) {
|
||||
super.readFromNBT(data);
|
||||
this.lastReportedValue = data.getLong("lastReportedValue");
|
||||
this.reportingValue = data.getLong("reportingValue");
|
||||
this.prevState = data.getBoolean("prevState");
|
||||
this.config.readFromNBT(data, "config");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(final CompoundNBT data) {
|
||||
super.writeToNBT(data);
|
||||
data.putLong("lastReportedValue", this.lastReportedValue);
|
||||
data.putLong("reportingValue", this.reportingValue);
|
||||
data.putBoolean("prevState", this.prevState);
|
||||
this.config.writeToNBT(data, "config");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemHandler getInventoryByName(final String name) {
|
||||
if (name.equals("config")) {
|
||||
return this.config;
|
||||
}
|
||||
|
||||
return super.getInventoryByName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean pushPattern(final ICraftingPatternDetails patternDetails, final CraftingInventory table) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBusy() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void provideCrafting(final ICraftingProviderHelper craftingTracker) {
|
||||
if (this.getInstalledUpgrades(Upgrades.CRAFTING) > 0) {
|
||||
if (this.getConfigManager().getSetting(Settings.CRAFT_VIA_REDSTONE) == YesNo.YES) {
|
||||
final IAEItemStack what = this.config.getAEStackInSlot(0);
|
||||
if (what != null) {
|
||||
craftingTracker.setEmitable(what);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPartModel getStaticModels() {
|
||||
if (this.isActive() && this.isPowered()) {
|
||||
return this.isLevelEmitterOn() ? MODEL_ON_HAS_CHANNEL : MODEL_OFF_HAS_CHANNEL;
|
||||
} else if (this.isPowered()) {
|
||||
return this.isLevelEmitterOn() ? MODEL_ON_ON : MODEL_OFF_ON;
|
||||
} else {
|
||||
return this.isLevelEmitterOn() ? MODEL_ON_OFF : MODEL_OFF_OFF;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.parts.automation;
|
||||
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
@@ -35,145 +34,119 @@ import appeng.me.GridAccessException;
|
||||
import appeng.tile.inventory.AppEngInternalAEInventory;
|
||||
import appeng.util.InventoryAdaptor;
|
||||
|
||||
public abstract class PartSharedItemBus extends PartUpgradeable implements IGridTickable {
|
||||
|
||||
public abstract class PartSharedItemBus extends PartUpgradeable implements IGridTickable
|
||||
{
|
||||
private final AppEngInternalAEInventory config = new AppEngInternalAEInventory(this, 9);
|
||||
private boolean lastRedstone = false;
|
||||
|
||||
private final AppEngInternalAEInventory config = new AppEngInternalAEInventory( this, 9 );
|
||||
private boolean lastRedstone = false;
|
||||
public PartSharedItemBus(final ItemStack is) {
|
||||
super(is);
|
||||
}
|
||||
|
||||
public PartSharedItemBus( final ItemStack is )
|
||||
{
|
||||
super( is );
|
||||
}
|
||||
@Override
|
||||
public void upgradesChanged() {
|
||||
this.updateState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void upgradesChanged()
|
||||
{
|
||||
this.updateState();
|
||||
}
|
||||
@Override
|
||||
public void readFromNBT(final net.minecraft.nbt.CompoundNBT extra) {
|
||||
super.readFromNBT(extra);
|
||||
this.getConfig().readFromNBT(extra, "config");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT( final net.minecraft.nbt.CompoundNBT extra )
|
||||
{
|
||||
super.readFromNBT( extra );
|
||||
this.getConfig().readFromNBT( extra, "config" );
|
||||
}
|
||||
@Override
|
||||
public void writeToNBT(final net.minecraft.nbt.CompoundNBT extra) {
|
||||
super.writeToNBT(extra);
|
||||
this.getConfig().writeToNBT(extra, "config");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT( final net.minecraft.nbt.CompoundNBT extra )
|
||||
{
|
||||
super.writeToNBT( extra );
|
||||
this.getConfig().writeToNBT( extra, "config" );
|
||||
}
|
||||
@Override
|
||||
public IItemHandler getInventoryByName(final String name) {
|
||||
if (name.equals("config")) {
|
||||
return this.getConfig();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemHandler getInventoryByName( final String name )
|
||||
{
|
||||
if( name.equals( "config" ) )
|
||||
{
|
||||
return this.getConfig();
|
||||
}
|
||||
return super.getInventoryByName(name);
|
||||
}
|
||||
|
||||
return super.getInventoryByName( name );
|
||||
}
|
||||
@Override
|
||||
public void onNeighborChanged(IBlockReader w, BlockPos pos, BlockPos neighbor) {
|
||||
this.updateState();
|
||||
if (this.lastRedstone != this.getHost().hasRedstone(this.getSide())) {
|
||||
this.lastRedstone = !this.lastRedstone;
|
||||
if (this.lastRedstone && this.getRSMode() == RedstoneMode.SIGNAL_PULSE) {
|
||||
this.doBusWork();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNeighborChanged( IBlockReader w, BlockPos pos, BlockPos neighbor )
|
||||
{
|
||||
this.updateState();
|
||||
if( this.lastRedstone != this.getHost().hasRedstone( this.getSide() ) )
|
||||
{
|
||||
this.lastRedstone = !this.lastRedstone;
|
||||
if( this.lastRedstone && this.getRSMode() == RedstoneMode.SIGNAL_PULSE )
|
||||
{
|
||||
this.doBusWork();
|
||||
}
|
||||
}
|
||||
}
|
||||
protected InventoryAdaptor getHandler() {
|
||||
final TileEntity self = this.getHost().getTile();
|
||||
final TileEntity target = this.getTileEntity(self, self.getPos().offset(this.getSide().getFacing()));
|
||||
|
||||
protected InventoryAdaptor getHandler()
|
||||
{
|
||||
final TileEntity self = this.getHost().getTile();
|
||||
final TileEntity target = this.getTileEntity( self, self.getPos().offset( this.getSide().getFacing() ) );
|
||||
return InventoryAdaptor.getAdaptor(target, this.getSide().getFacing().getOpposite());
|
||||
}
|
||||
|
||||
return InventoryAdaptor.getAdaptor( target, this.getSide().getFacing().getOpposite() );
|
||||
}
|
||||
private TileEntity getTileEntity(final TileEntity self, final BlockPos pos) {
|
||||
final World w = self.getWorld();
|
||||
|
||||
private TileEntity getTileEntity( final TileEntity self, final BlockPos pos )
|
||||
{
|
||||
final World w = self.getWorld();
|
||||
if (w.getChunkProvider().isChunkLoaded(new ChunkPos(pos))) {
|
||||
return w.getTileEntity(pos);
|
||||
}
|
||||
|
||||
if( w.getChunkProvider().isChunkLoaded( new ChunkPos( pos ) ) )
|
||||
{
|
||||
return w.getTileEntity( pos );
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
protected int availableSlots() {
|
||||
return Math.min(1 + this.getInstalledUpgrades(Upgrades.CAPACITY) * 4, this.getConfig().getSlots());
|
||||
}
|
||||
|
||||
protected int availableSlots()
|
||||
{
|
||||
return Math.min( 1 + this.getInstalledUpgrades( Upgrades.CAPACITY ) * 4, this.getConfig().getSlots() );
|
||||
}
|
||||
protected int calculateItemsToSend() {
|
||||
switch (this.getInstalledUpgrades(Upgrades.SPEED)) {
|
||||
default:
|
||||
case 0:
|
||||
return 1;
|
||||
case 1:
|
||||
return 8;
|
||||
case 2:
|
||||
return 32;
|
||||
case 3:
|
||||
return 64;
|
||||
case 4:
|
||||
return 96;
|
||||
}
|
||||
}
|
||||
|
||||
protected int calculateItemsToSend()
|
||||
{
|
||||
switch( this.getInstalledUpgrades( Upgrades.SPEED ) )
|
||||
{
|
||||
default:
|
||||
case 0:
|
||||
return 1;
|
||||
case 1:
|
||||
return 8;
|
||||
case 2:
|
||||
return 32;
|
||||
case 3:
|
||||
return 64;
|
||||
case 4:
|
||||
return 96;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Checks if the bus can actually do something.
|
||||
*
|
||||
* Currently this tests if the chunk for the target is actually loaded.
|
||||
*
|
||||
* @return true, if the the bus should do its work.
|
||||
*/
|
||||
protected boolean canDoBusWork() {
|
||||
final TileEntity self = this.getHost().getTile();
|
||||
final BlockPos selfPos = self.getPos().offset(this.getSide().getFacing());
|
||||
final World world = self.getWorld();
|
||||
|
||||
/**
|
||||
* Checks if the bus can actually do something.
|
||||
*
|
||||
* Currently this tests if the chunk for the target is actually loaded.
|
||||
*
|
||||
* @return true, if the the bus should do its work.
|
||||
*/
|
||||
protected boolean canDoBusWork()
|
||||
{
|
||||
final TileEntity self = this.getHost().getTile();
|
||||
final BlockPos selfPos = self.getPos().offset( this.getSide().getFacing() );
|
||||
final World world = self.getWorld();
|
||||
return world != null && world.getChunkProvider().isChunkLoaded(new ChunkPos(selfPos));
|
||||
}
|
||||
|
||||
return world != null && world.getChunkProvider().isChunkLoaded( new ChunkPos( selfPos ) );
|
||||
}
|
||||
private void updateState() {
|
||||
try {
|
||||
if (!this.isSleeping()) {
|
||||
this.getProxy().getTick().wakeDevice(this.getProxy().getNode());
|
||||
} else {
|
||||
this.getProxy().getTick().sleepDevice(this.getProxy().getNode());
|
||||
}
|
||||
} catch (final GridAccessException e) {
|
||||
// :P
|
||||
}
|
||||
}
|
||||
|
||||
private void updateState()
|
||||
{
|
||||
try
|
||||
{
|
||||
if( !this.isSleeping() )
|
||||
{
|
||||
this.getProxy().getTick().wakeDevice( this.getProxy().getNode() );
|
||||
}
|
||||
else
|
||||
{
|
||||
this.getProxy().getTick().sleepDevice( this.getProxy().getNode() );
|
||||
}
|
||||
}
|
||||
catch( final GridAccessException e )
|
||||
{
|
||||
// :P
|
||||
}
|
||||
}
|
||||
protected abstract TickRateModulation doBusWork();
|
||||
|
||||
protected abstract TickRateModulation doBusWork();
|
||||
|
||||
AppEngInternalAEInventory getConfig()
|
||||
{
|
||||
return this.config;
|
||||
}
|
||||
AppEngInternalAEInventory getConfig() {
|
||||
return this.config;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,14 +18,13 @@
|
||||
|
||||
package appeng.parts.automation;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import appeng.api.config.Settings;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
import appeng.api.config.RedstoneMode;
|
||||
import appeng.api.config.Settings;
|
||||
import appeng.api.config.Upgrades;
|
||||
import appeng.api.util.IConfigManager;
|
||||
import appeng.parts.PartBasicState;
|
||||
@@ -34,139 +33,116 @@ import appeng.util.IConfigManagerHost;
|
||||
import appeng.util.inv.IAEAppEngInventory;
|
||||
import appeng.util.inv.InvOperation;
|
||||
|
||||
public abstract class PartUpgradeable extends PartBasicState implements IAEAppEngInventory, IConfigManagerHost {
|
||||
private final IConfigManager manager;
|
||||
private final UpgradeInventory upgrades;
|
||||
|
||||
public abstract class PartUpgradeable extends PartBasicState implements IAEAppEngInventory, IConfigManagerHost
|
||||
{
|
||||
private final IConfigManager manager;
|
||||
private final UpgradeInventory upgrades;
|
||||
public PartUpgradeable(final ItemStack is) {
|
||||
super(is);
|
||||
this.upgrades = new StackUpgradeInventory(this.getItemStack(), this, this.getUpgradeSlots());
|
||||
this.manager = new ConfigManager(this);
|
||||
}
|
||||
|
||||
public PartUpgradeable( final ItemStack is )
|
||||
{
|
||||
super( is );
|
||||
this.upgrades = new StackUpgradeInventory( this.getItemStack(), this, this.getUpgradeSlots() );
|
||||
this.manager = new ConfigManager( this );
|
||||
}
|
||||
protected int getUpgradeSlots() {
|
||||
return 4;
|
||||
}
|
||||
|
||||
protected int getUpgradeSlots()
|
||||
{
|
||||
return 4;
|
||||
}
|
||||
@Override
|
||||
public void updateSetting(final IConfigManager manager, final Settings settingName, final Enum<?> newValue) {
|
||||
|
||||
@Override
|
||||
public void updateSetting(final IConfigManager manager, final Settings settingName, final Enum<?> newValue )
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
public void onChangeInventory(final IItemHandler inv, final int slot, final InvOperation mc,
|
||||
final ItemStack removedStack, final ItemStack newStack) {
|
||||
if (inv == this.upgrades) {
|
||||
this.upgradesChanged();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChangeInventory( final IItemHandler inv, final int slot, final InvOperation mc, final ItemStack removedStack, final ItemStack newStack )
|
||||
{
|
||||
if( inv == this.upgrades )
|
||||
{
|
||||
this.upgradesChanged();
|
||||
}
|
||||
}
|
||||
public void upgradesChanged() {
|
||||
|
||||
public void upgradesChanged()
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
protected boolean isSleeping() {
|
||||
if (this.getInstalledUpgrades(Upgrades.REDSTONE) > 0) {
|
||||
switch (this.getRSMode()) {
|
||||
case IGNORE:
|
||||
return false;
|
||||
|
||||
protected boolean isSleeping()
|
||||
{
|
||||
if( this.getInstalledUpgrades( Upgrades.REDSTONE ) > 0 )
|
||||
{
|
||||
switch( this.getRSMode() )
|
||||
{
|
||||
case IGNORE:
|
||||
return false;
|
||||
case HIGH_SIGNAL:
|
||||
if (this.getHost().hasRedstone(this.getSide())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
case HIGH_SIGNAL:
|
||||
if( this.getHost().hasRedstone( this.getSide() ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
|
||||
break;
|
||||
case LOW_SIGNAL:
|
||||
if (!this.getHost().hasRedstone(this.getSide())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
case LOW_SIGNAL:
|
||||
if( !this.getHost().hasRedstone( this.getSide() ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
|
||||
break;
|
||||
case SIGNAL_PULSE:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
case SIGNAL_PULSE:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public int getInstalledUpgrades(final Upgrades u) {
|
||||
return this.upgrades.getInstalledUpgrades(u);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInstalledUpgrades( final Upgrades u )
|
||||
{
|
||||
return this.upgrades.getInstalledUpgrades( u );
|
||||
}
|
||||
@Override
|
||||
public boolean canConnectRedstone() {
|
||||
return this.upgrades.getMaxInstalled(Upgrades.REDSTONE) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canConnectRedstone()
|
||||
{
|
||||
return this.upgrades.getMaxInstalled( Upgrades.REDSTONE ) > 0;
|
||||
}
|
||||
@Override
|
||||
public void readFromNBT(final net.minecraft.nbt.CompoundNBT extra) {
|
||||
super.readFromNBT(extra);
|
||||
this.manager.readFromNBT(extra);
|
||||
this.upgrades.readFromNBT(extra, "upgrades");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT( final net.minecraft.nbt.CompoundNBT extra )
|
||||
{
|
||||
super.readFromNBT( extra );
|
||||
this.manager.readFromNBT( extra );
|
||||
this.upgrades.readFromNBT( extra, "upgrades" );
|
||||
}
|
||||
@Override
|
||||
public void writeToNBT(final net.minecraft.nbt.CompoundNBT extra) {
|
||||
super.writeToNBT(extra);
|
||||
this.manager.writeToNBT(extra);
|
||||
this.upgrades.writeToNBT(extra, "upgrades");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT( final net.minecraft.nbt.CompoundNBT extra )
|
||||
{
|
||||
super.writeToNBT( extra );
|
||||
this.manager.writeToNBT( extra );
|
||||
this.upgrades.writeToNBT( extra, "upgrades" );
|
||||
}
|
||||
@Override
|
||||
public void getDrops(final List<ItemStack> drops, final boolean wrenched) {
|
||||
for (final ItemStack is : this.upgrades) {
|
||||
if (!is.isEmpty()) {
|
||||
drops.add(is);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getDrops( final List<ItemStack> drops, final boolean wrenched )
|
||||
{
|
||||
for( final ItemStack is : this.upgrades )
|
||||
{
|
||||
if( !is.isEmpty() )
|
||||
{
|
||||
drops.add( is );
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public IConfigManager getConfigManager() {
|
||||
return this.manager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IConfigManager getConfigManager()
|
||||
{
|
||||
return this.manager;
|
||||
}
|
||||
@Override
|
||||
public IItemHandler getInventoryByName(final String name) {
|
||||
if (name.equals("upgrades")) {
|
||||
return this.upgrades;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemHandler getInventoryByName( final String name )
|
||||
{
|
||||
if( name.equals( "upgrades" ) )
|
||||
{
|
||||
return this.upgrades;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public RedstoneMode getRSMode()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
public RedstoneMode getRSMode() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
|
||||
package appeng.parts.automation;
|
||||
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
@@ -29,100 +29,89 @@ import net.minecraft.client.renderer.model.BakedQuad;
|
||||
import net.minecraft.client.renderer.model.ItemOverrideList;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.util.Direction;
|
||||
|
||||
import appeng.client.render.cablebus.CubeBuilder;
|
||||
import net.minecraftforge.client.model.data.IDynamicBakedModel;
|
||||
import net.minecraftforge.client.model.data.IModelData;
|
||||
|
||||
import appeng.client.render.cablebus.CubeBuilder;
|
||||
|
||||
/**
|
||||
* Built-in model for annihilation planes that supports connected textures.
|
||||
*/
|
||||
public class PlaneBakedModel implements IDynamicBakedModel
|
||||
{
|
||||
public class PlaneBakedModel implements IDynamicBakedModel {
|
||||
|
||||
private static final PlaneConnections DEFAULT_PERMUTATION = PlaneConnections.of(false, false, false, false);
|
||||
private static final PlaneConnections DEFAULT_PERMUTATION = PlaneConnections.of(false, false, false, false);
|
||||
|
||||
private final TextureAtlasSprite frontTexture;
|
||||
private final TextureAtlasSprite frontTexture;
|
||||
|
||||
private final Map<PlaneConnections, List<BakedQuad>> quads;
|
||||
private final Map<PlaneConnections, List<BakedQuad>> quads;
|
||||
|
||||
PlaneBakedModel( TextureAtlasSprite frontTexture, TextureAtlasSprite sidesTexture, TextureAtlasSprite backTexture )
|
||||
{
|
||||
this.frontTexture = frontTexture;
|
||||
PlaneBakedModel(TextureAtlasSprite frontTexture, TextureAtlasSprite sidesTexture, TextureAtlasSprite backTexture) {
|
||||
this.frontTexture = frontTexture;
|
||||
|
||||
quads = new HashMap<>(PlaneConnections.PERMUTATIONS.size());
|
||||
// Create all possible permutations (16)
|
||||
for (PlaneConnections permutation : PlaneConnections.PERMUTATIONS) {
|
||||
List<BakedQuad> quads = new ArrayList<>(4 * 6);
|
||||
quads = new HashMap<>(PlaneConnections.PERMUTATIONS.size());
|
||||
// Create all possible permutations (16)
|
||||
for (PlaneConnections permutation : PlaneConnections.PERMUTATIONS) {
|
||||
List<BakedQuad> quads = new ArrayList<>(4 * 6);
|
||||
|
||||
CubeBuilder builder = new CubeBuilder(quads);
|
||||
CubeBuilder builder = new CubeBuilder(quads);
|
||||
|
||||
builder.setTextures(sidesTexture, sidesTexture, frontTexture, backTexture, sidesTexture, sidesTexture);
|
||||
builder.setTextures(sidesTexture, sidesTexture, frontTexture, backTexture, sidesTexture, sidesTexture);
|
||||
|
||||
// Keep the orientation of the X axis in mind here. When looking at a quad facing north from the front,
|
||||
// The X-axis points left
|
||||
int minX = permutation.isRight() ? 0 : 1;
|
||||
int maxX = permutation.isLeft() ? 16 : 15;
|
||||
int minY = permutation.isDown() ? 0 : 1;
|
||||
int maxY = permutation.isUp() ? 16 : 15;
|
||||
// Keep the orientation of the X axis in mind here. When looking at a quad
|
||||
// facing north from the front,
|
||||
// The X-axis points left
|
||||
int minX = permutation.isRight() ? 0 : 1;
|
||||
int maxX = permutation.isLeft() ? 16 : 15;
|
||||
int minY = permutation.isDown() ? 0 : 1;
|
||||
int maxY = permutation.isUp() ? 16 : 15;
|
||||
|
||||
builder.addCube(minX, minY, 0, maxX, maxY, 1);
|
||||
builder.addCube(minX, minY, 0, maxX, maxY, 1);
|
||||
|
||||
this.quads.put(permutation, ImmutableList.copyOf(quads));
|
||||
}
|
||||
}
|
||||
this.quads.put(permutation, ImmutableList.copyOf(quads));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, Random rand, IModelData modelData)
|
||||
{
|
||||
if( side == null )
|
||||
{
|
||||
PlaneConnections connections = DEFAULT_PERMUTATION;
|
||||
if (modelData instanceof PlaneModelData) {
|
||||
connections = ((PlaneModelData) modelData).getConnections();
|
||||
}
|
||||
return this.quads.get(connections);
|
||||
}
|
||||
else
|
||||
{
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, Random rand,
|
||||
IModelData modelData) {
|
||||
if (side == null) {
|
||||
PlaneConnections connections = DEFAULT_PERMUTATION;
|
||||
if (modelData instanceof PlaneModelData) {
|
||||
connections = ((PlaneModelData) modelData).getConnections();
|
||||
}
|
||||
return this.quads.get(connections);
|
||||
} else {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAmbientOcclusion()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean isAmbientOcclusion() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGui3d()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean isGui3d() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean func_230044_c_()
|
||||
{
|
||||
return false;//TODO
|
||||
}
|
||||
@Override
|
||||
public boolean func_230044_c_() {
|
||||
return false;// TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBuiltInRenderer()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean isBuiltInRenderer() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextureAtlasSprite getParticleTexture()
|
||||
{
|
||||
return this.frontTexture;
|
||||
}
|
||||
@Override
|
||||
public TextureAtlasSprite getParticleTexture() {
|
||||
return this.frontTexture;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemOverrideList getOverrides()
|
||||
{
|
||||
return ItemOverrideList.EMPTY;
|
||||
}
|
||||
@Override
|
||||
public ItemOverrideList getOverrides() {
|
||||
return ItemOverrideList.EMPTY;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,123 +18,107 @@
|
||||
|
||||
package appeng.parts.automation;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
|
||||
|
||||
/**
|
||||
* Models in which directions - looking at the front face - a plane (annihilation, formation, etc.) is connected to
|
||||
* other planes of the same type.
|
||||
* Models in which directions - looking at the front face - a plane
|
||||
* (annihilation, formation, etc.) is connected to other planes of the same
|
||||
* type.
|
||||
*/
|
||||
public final class PlaneConnections
|
||||
{
|
||||
public final class PlaneConnections {
|
||||
|
||||
private final boolean up;
|
||||
private final boolean right;
|
||||
private final boolean down;
|
||||
private final boolean left;
|
||||
private final boolean up;
|
||||
private final boolean right;
|
||||
private final boolean down;
|
||||
private final boolean left;
|
||||
|
||||
private static final int BITMASK_UP = 8;
|
||||
private static final int BITMASK_RIGHT = 4;
|
||||
private static final int BITMASK_DOWN = 2;
|
||||
private static final int BITMASK_LEFT = 1;
|
||||
private static final int BITMASK_UP = 8;
|
||||
private static final int BITMASK_RIGHT = 4;
|
||||
private static final int BITMASK_DOWN = 2;
|
||||
private static final int BITMASK_LEFT = 1;
|
||||
|
||||
public static final List<PlaneConnections> PERMUTATIONS = generatePermutations();
|
||||
public static final List<PlaneConnections> PERMUTATIONS = generatePermutations();
|
||||
|
||||
private static List<PlaneConnections> generatePermutations()
|
||||
{
|
||||
List<PlaneConnections> connections = new ArrayList<>( 16 );
|
||||
private static List<PlaneConnections> generatePermutations() {
|
||||
List<PlaneConnections> connections = new ArrayList<>(16);
|
||||
|
||||
for( int i = 0; i < 16; i++ )
|
||||
{
|
||||
boolean up = ( i & BITMASK_UP ) != 0;
|
||||
boolean right = ( i & BITMASK_RIGHT ) != 0;
|
||||
boolean down = ( i & BITMASK_DOWN ) != 0;
|
||||
boolean left = ( i & BITMASK_LEFT ) != 0;
|
||||
for (int i = 0; i < 16; i++) {
|
||||
boolean up = (i & BITMASK_UP) != 0;
|
||||
boolean right = (i & BITMASK_RIGHT) != 0;
|
||||
boolean down = (i & BITMASK_DOWN) != 0;
|
||||
boolean left = (i & BITMASK_LEFT) != 0;
|
||||
|
||||
connections.add( new PlaneConnections( up, right, down, left ) );
|
||||
}
|
||||
connections.add(new PlaneConnections(up, right, down, left));
|
||||
}
|
||||
|
||||
return connections;
|
||||
}
|
||||
return connections;
|
||||
}
|
||||
|
||||
private PlaneConnections( boolean up, boolean right, boolean down, boolean left )
|
||||
{
|
||||
this.up = up;
|
||||
this.right = right;
|
||||
this.down = down;
|
||||
this.left = left;
|
||||
}
|
||||
private PlaneConnections(boolean up, boolean right, boolean down, boolean left) {
|
||||
this.up = up;
|
||||
this.right = right;
|
||||
this.down = down;
|
||||
this.left = left;
|
||||
}
|
||||
|
||||
public static PlaneConnections of( boolean up, boolean right, boolean down, boolean left )
|
||||
{
|
||||
return PERMUTATIONS.get( getIndex( up, right, down, left ) );
|
||||
}
|
||||
public static PlaneConnections of(boolean up, boolean right, boolean down, boolean left) {
|
||||
return PERMUTATIONS.get(getIndex(up, right, down, left));
|
||||
}
|
||||
|
||||
public boolean isUp()
|
||||
{
|
||||
return this.up;
|
||||
}
|
||||
public boolean isUp() {
|
||||
return this.up;
|
||||
}
|
||||
|
||||
public boolean isRight()
|
||||
{
|
||||
return this.right;
|
||||
}
|
||||
public boolean isRight() {
|
||||
return this.right;
|
||||
}
|
||||
|
||||
public boolean isDown()
|
||||
{
|
||||
return this.down;
|
||||
}
|
||||
public boolean isDown() {
|
||||
return this.down;
|
||||
}
|
||||
|
||||
public boolean isLeft()
|
||||
{
|
||||
return this.left;
|
||||
}
|
||||
public boolean isLeft() {
|
||||
return this.left;
|
||||
}
|
||||
|
||||
// The combination of connections expressed as a number ranging from [0,15]
|
||||
public int getIndex()
|
||||
{
|
||||
return getIndex( this.up, this.right, this.down, this.left );
|
||||
}
|
||||
// The combination of connections expressed as a number ranging from [0,15]
|
||||
public int getIndex() {
|
||||
return getIndex(this.up, this.right, this.down, this.left);
|
||||
}
|
||||
|
||||
private static int getIndex( boolean up, boolean right, boolean down, boolean left )
|
||||
{
|
||||
return ( up ? BITMASK_UP : 0 ) + ( right ? BITMASK_RIGHT : 0 ) + ( left ? BITMASK_LEFT : 0 ) + ( down ? BITMASK_DOWN : 0 );
|
||||
}
|
||||
private static int getIndex(boolean up, boolean right, boolean down, boolean left) {
|
||||
return (up ? BITMASK_UP : 0) + (right ? BITMASK_RIGHT : 0) + (left ? BITMASK_LEFT : 0)
|
||||
+ (down ? BITMASK_DOWN : 0);
|
||||
}
|
||||
|
||||
// Returns a suffix that expresses the connection states as a string
|
||||
public String getFilenameSuffix()
|
||||
{
|
||||
String suffix = Integer.toBinaryString( this.getIndex() );
|
||||
return Strings.padStart( suffix, 4, '0' );
|
||||
}
|
||||
// Returns a suffix that expresses the connection states as a string
|
||||
public String getFilenameSuffix() {
|
||||
String suffix = Integer.toBinaryString(this.getIndex());
|
||||
return Strings.padStart(suffix, 4, '0');
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals( Object o )
|
||||
{
|
||||
if( this == o )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if( o == null || this.getClass() != o.getClass() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || this.getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
PlaneConnections that = (PlaneConnections) o;
|
||||
return this.up == that.up && this.right == that.right && this.down == that.down && this.left == that.left;
|
||||
}
|
||||
PlaneConnections that = (PlaneConnections) o;
|
||||
return this.up == that.up && this.right == that.right && this.down == that.down && this.left == that.left;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
int result = ( this.up ? 1 : 0 );
|
||||
result = 31 * result + ( this.right ? 1 : 0 );
|
||||
result = 31 * result + ( this.down ? 1 : 0 );
|
||||
result = 31 * result + ( this.left ? 1 : 0 );
|
||||
return result;
|
||||
}
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = (this.up ? 1 : 0);
|
||||
result = 31 * result + (this.right ? 1 : 0);
|
||||
result = 31 * result + (this.down ? 1 : 0);
|
||||
result = 31 * result + (this.left ? 1 : 0);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,12 +18,12 @@
|
||||
|
||||
package appeng.parts.automation;
|
||||
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
@@ -35,36 +35,36 @@ import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.client.model.IModelConfiguration;
|
||||
import net.minecraftforge.client.model.geometry.IModelGeometry;
|
||||
|
||||
|
||||
/**
|
||||
* Built-in model for annihilation planes that supports connected textures.
|
||||
*/
|
||||
public class PlaneModel implements IModelGeometry<PlaneModel>
|
||||
{
|
||||
public class PlaneModel implements IModelGeometry<PlaneModel> {
|
||||
|
||||
private final Material frontTexture;
|
||||
private final Material sidesTexture;
|
||||
private final Material backTexture;
|
||||
private final Material frontTexture;
|
||||
private final Material sidesTexture;
|
||||
private final Material backTexture;
|
||||
|
||||
public PlaneModel( ResourceLocation frontTexture, ResourceLocation sidesTexture, ResourceLocation backTexture )
|
||||
{
|
||||
this.frontTexture = new Material( AtlasTexture.LOCATION_BLOCKS_TEXTURE, frontTexture );
|
||||
this.sidesTexture = new Material( AtlasTexture.LOCATION_BLOCKS_TEXTURE, sidesTexture );
|
||||
this.backTexture = new Material( AtlasTexture.LOCATION_BLOCKS_TEXTURE, backTexture );
|
||||
}
|
||||
public PlaneModel(ResourceLocation frontTexture, ResourceLocation sidesTexture, ResourceLocation backTexture) {
|
||||
this.frontTexture = new Material(AtlasTexture.LOCATION_BLOCKS_TEXTURE, frontTexture);
|
||||
this.sidesTexture = new Material(AtlasTexture.LOCATION_BLOCKS_TEXTURE, sidesTexture);
|
||||
this.backTexture = new Material(AtlasTexture.LOCATION_BLOCKS_TEXTURE, backTexture);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBakedModel bake(IModelConfiguration owner, ModelBakery bakery, Function<Material, TextureAtlasSprite> spriteGetter, IModelTransform modelTransform, ItemOverrideList overrides, ResourceLocation modelLocation) {
|
||||
TextureAtlasSprite frontSprite = spriteGetter.apply( this.frontTexture );
|
||||
TextureAtlasSprite sidesSprite = spriteGetter.apply( this.sidesTexture );
|
||||
TextureAtlasSprite backSprite = spriteGetter.apply( this.backTexture );
|
||||
@Override
|
||||
public IBakedModel bake(IModelConfiguration owner, ModelBakery bakery,
|
||||
Function<Material, TextureAtlasSprite> spriteGetter, IModelTransform modelTransform,
|
||||
ItemOverrideList overrides, ResourceLocation modelLocation) {
|
||||
TextureAtlasSprite frontSprite = spriteGetter.apply(this.frontTexture);
|
||||
TextureAtlasSprite sidesSprite = spriteGetter.apply(this.sidesTexture);
|
||||
TextureAtlasSprite backSprite = spriteGetter.apply(this.backTexture);
|
||||
|
||||
return new PlaneBakedModel( frontSprite, sidesSprite, backSprite );
|
||||
}
|
||||
return new PlaneBakedModel(frontSprite, sidesSprite, backSprite);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Material> getTextures(IModelConfiguration owner, Function<ResourceLocation, IUnbakedModel> modelGetter, Set<Pair<String, String>> missingTextureErrors) {
|
||||
return Arrays.asList( frontTexture, sidesTexture, backTexture );
|
||||
}
|
||||
@Override
|
||||
public Collection<Material> getTextures(IModelConfiguration owner,
|
||||
Function<ResourceLocation, IUnbakedModel> modelGetter, Set<Pair<String, String>> missingTextureErrors) {
|
||||
return Arrays.asList(frontTexture, sidesTexture, backTexture);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package appeng.parts.automation;
|
||||
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import net.minecraft.resources.IResourceManager;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.client.model.IModelLoader;
|
||||
@@ -20,11 +21,8 @@ public class PlaneModelLoader implements IModelLoader<PlaneModel> {
|
||||
String sidesTexture = modelContents.get("sides").getAsString();
|
||||
String backTexture = modelContents.get("back").getAsString();
|
||||
|
||||
return new PlaneModel(
|
||||
new ResourceLocation(frontTexture),
|
||||
new ResourceLocation(sidesTexture),
|
||||
new ResourceLocation(backTexture)
|
||||
);
|
||||
return new PlaneModel(new ResourceLocation(frontTexture), new ResourceLocation(sidesTexture),
|
||||
new ResourceLocation(backTexture));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.parts.automation;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -33,54 +32,46 @@ import appeng.api.parts.IPartModel;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.parts.PartModel;
|
||||
|
||||
|
||||
/**
|
||||
* Contains a mapping from a Plane's connections to the models to use for that state.
|
||||
* Contains a mapping from a Plane's connections to the models to use for that
|
||||
* state.
|
||||
*/
|
||||
public class PlaneModels
|
||||
{
|
||||
public class PlaneModels {
|
||||
|
||||
public static final ResourceLocation MODEL_CHASSIS_OFF = new ResourceLocation( AppEng.MOD_ID, "part/transition_plane_off" );
|
||||
public static final ResourceLocation MODEL_CHASSIS_ON = new ResourceLocation( AppEng.MOD_ID, "part/transition_plane_on" );
|
||||
public static final ResourceLocation MODEL_CHASSIS_HAS_CHANNEL = new ResourceLocation( AppEng.MOD_ID, "part/transition_plane_has_channel" );
|
||||
public static final ResourceLocation MODEL_CHASSIS_OFF = new ResourceLocation(AppEng.MOD_ID,
|
||||
"part/transition_plane_off");
|
||||
public static final ResourceLocation MODEL_CHASSIS_ON = new ResourceLocation(AppEng.MOD_ID,
|
||||
"part/transition_plane_on");
|
||||
public static final ResourceLocation MODEL_CHASSIS_HAS_CHANNEL = new ResourceLocation(AppEng.MOD_ID,
|
||||
"part/transition_plane_has_channel");
|
||||
|
||||
private final IPartModel modelOff;
|
||||
private final IPartModel modelOff;
|
||||
|
||||
private final IPartModel modelOn;
|
||||
private final IPartModel modelOn;
|
||||
|
||||
private final IPartModel modelHasChannel;
|
||||
private final IPartModel modelHasChannel;
|
||||
|
||||
public PlaneModels( String planeOffLocation, String planeOnLocation )
|
||||
{
|
||||
ResourceLocation planeOff = new ResourceLocation( AppEng.MOD_ID, planeOffLocation );
|
||||
ResourceLocation planeOn = new ResourceLocation( AppEng.MOD_ID, planeOnLocation );
|
||||
public PlaneModels(String planeOffLocation, String planeOnLocation) {
|
||||
ResourceLocation planeOff = new ResourceLocation(AppEng.MOD_ID, planeOffLocation);
|
||||
ResourceLocation planeOn = new ResourceLocation(AppEng.MOD_ID, planeOnLocation);
|
||||
|
||||
this.modelOff = new PartModel( MODEL_CHASSIS_OFF, planeOff );
|
||||
this.modelOn = new PartModel( MODEL_CHASSIS_ON, planeOff );
|
||||
this.modelHasChannel = new PartModel( MODEL_CHASSIS_HAS_CHANNEL, planeOn );
|
||||
}
|
||||
this.modelOff = new PartModel(MODEL_CHASSIS_OFF, planeOff);
|
||||
this.modelOn = new PartModel(MODEL_CHASSIS_ON, planeOff);
|
||||
this.modelHasChannel = new PartModel(MODEL_CHASSIS_HAS_CHANNEL, planeOn);
|
||||
}
|
||||
|
||||
public IPartModel getModel(boolean hasPower, boolean hasChannel)
|
||||
{
|
||||
if( hasPower && hasChannel )
|
||||
{
|
||||
return modelHasChannel;
|
||||
}
|
||||
else if( hasPower )
|
||||
{
|
||||
return modelOn;
|
||||
}
|
||||
else
|
||||
{
|
||||
return modelOff;
|
||||
}
|
||||
}
|
||||
public IPartModel getModel(boolean hasPower, boolean hasChannel) {
|
||||
if (hasPower && hasChannel) {
|
||||
return modelHasChannel;
|
||||
} else if (hasPower) {
|
||||
return modelOn;
|
||||
} else {
|
||||
return modelOff;
|
||||
}
|
||||
}
|
||||
|
||||
public List<IPartModel> getModels()
|
||||
{
|
||||
return ImmutableList.of(
|
||||
modelOff, modelOn, modelHasChannel
|
||||
);
|
||||
}
|
||||
public List<IPartModel> getModels() {
|
||||
return ImmutableList.of(modelOff, modelOn, modelHasChannel);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,37 +18,30 @@
|
||||
|
||||
package appeng.parts.automation;
|
||||
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import appeng.api.config.Upgrades;
|
||||
import appeng.util.inv.IAEAppEngInventory;
|
||||
|
||||
public class StackUpgradeInventory extends UpgradeInventory {
|
||||
private final ItemStack stack;
|
||||
|
||||
public class StackUpgradeInventory extends UpgradeInventory
|
||||
{
|
||||
private final ItemStack stack;
|
||||
public StackUpgradeInventory(final ItemStack stack, final IAEAppEngInventory inventory, final int s) {
|
||||
super(inventory, s);
|
||||
this.stack = stack;
|
||||
}
|
||||
|
||||
public StackUpgradeInventory( final ItemStack stack, final IAEAppEngInventory inventory, final int s )
|
||||
{
|
||||
super( inventory, s );
|
||||
this.stack = stack;
|
||||
}
|
||||
@Override
|
||||
public int getMaxInstalled(final Upgrades upgrades) {
|
||||
int max = 0;
|
||||
|
||||
@Override
|
||||
public int getMaxInstalled( final Upgrades upgrades )
|
||||
{
|
||||
int max = 0;
|
||||
for (final ItemStack is : upgrades.getSupported().keySet()) {
|
||||
if (ItemStack.areItemsEqual(this.stack, is)) {
|
||||
max = upgrades.getSupported().get(is);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for( final ItemStack is : upgrades.getSupported().keySet() )
|
||||
{
|
||||
if( ItemStack.areItemsEqual( this.stack, is ) )
|
||||
{
|
||||
max = upgrades.getSupported().get( is );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return max;
|
||||
}
|
||||
return max;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,10 +18,9 @@
|
||||
|
||||
package appeng.parts.automation;
|
||||
|
||||
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
@@ -33,159 +32,138 @@ import appeng.util.inv.IAEAppEngInventory;
|
||||
import appeng.util.inv.InvOperation;
|
||||
import appeng.util.inv.filter.IAEItemFilter;
|
||||
|
||||
public abstract class UpgradeInventory extends AppEngInternalInventory implements IAEAppEngInventory {
|
||||
private final IAEAppEngInventory parent;
|
||||
|
||||
public abstract class UpgradeInventory extends AppEngInternalInventory implements IAEAppEngInventory
|
||||
{
|
||||
private final IAEAppEngInventory parent;
|
||||
private boolean cached = false;
|
||||
private int fuzzyUpgrades = 0;
|
||||
private int speedUpgrades = 0;
|
||||
private int redstoneUpgrades = 0;
|
||||
private int capacityUpgrades = 0;
|
||||
private int inverterUpgrades = 0;
|
||||
private int craftingUpgrades = 0;
|
||||
|
||||
private boolean cached = false;
|
||||
private int fuzzyUpgrades = 0;
|
||||
private int speedUpgrades = 0;
|
||||
private int redstoneUpgrades = 0;
|
||||
private int capacityUpgrades = 0;
|
||||
private int inverterUpgrades = 0;
|
||||
private int craftingUpgrades = 0;
|
||||
public UpgradeInventory(final IAEAppEngInventory parent, final int s) {
|
||||
super(null, s, 1);
|
||||
this.setTileEntity(this);
|
||||
this.parent = parent;
|
||||
this.setFilter(new UpgradeInvFilter());
|
||||
}
|
||||
|
||||
public UpgradeInventory( final IAEAppEngInventory parent, final int s )
|
||||
{
|
||||
super( null, s, 1 );
|
||||
this.setTileEntity( this );
|
||||
this.parent = parent;
|
||||
this.setFilter( new UpgradeInvFilter() );
|
||||
}
|
||||
@Override
|
||||
protected boolean eventsEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean eventsEnabled()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public int getInstalledUpgrades(final Upgrades u) {
|
||||
if (!this.cached) {
|
||||
this.updateUpgradeInfo();
|
||||
}
|
||||
|
||||
public int getInstalledUpgrades( final Upgrades u )
|
||||
{
|
||||
if( !this.cached )
|
||||
{
|
||||
this.updateUpgradeInfo();
|
||||
}
|
||||
switch (u) {
|
||||
case CAPACITY:
|
||||
return this.capacityUpgrades;
|
||||
case FUZZY:
|
||||
return this.fuzzyUpgrades;
|
||||
case REDSTONE:
|
||||
return this.redstoneUpgrades;
|
||||
case SPEED:
|
||||
return this.speedUpgrades;
|
||||
case INVERTER:
|
||||
return this.inverterUpgrades;
|
||||
case CRAFTING:
|
||||
return this.craftingUpgrades;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
switch( u )
|
||||
{
|
||||
case CAPACITY:
|
||||
return this.capacityUpgrades;
|
||||
case FUZZY:
|
||||
return this.fuzzyUpgrades;
|
||||
case REDSTONE:
|
||||
return this.redstoneUpgrades;
|
||||
case SPEED:
|
||||
return this.speedUpgrades;
|
||||
case INVERTER:
|
||||
return this.inverterUpgrades;
|
||||
case CRAFTING:
|
||||
return this.craftingUpgrades;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
public abstract int getMaxInstalled(Upgrades upgrades);
|
||||
|
||||
public abstract int getMaxInstalled( Upgrades upgrades );
|
||||
private void updateUpgradeInfo() {
|
||||
this.cached = true;
|
||||
this.inverterUpgrades = this.capacityUpgrades = this.redstoneUpgrades = this.speedUpgrades = this.fuzzyUpgrades = this.craftingUpgrades = 0;
|
||||
|
||||
private void updateUpgradeInfo()
|
||||
{
|
||||
this.cached = true;
|
||||
this.inverterUpgrades = this.capacityUpgrades = this.redstoneUpgrades = this.speedUpgrades = this.fuzzyUpgrades = this.craftingUpgrades = 0;
|
||||
for (final ItemStack is : this) {
|
||||
if (is == null || is.getItem() == Items.AIR || !(is.getItem() instanceof IUpgradeModule)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for( final ItemStack is : this )
|
||||
{
|
||||
if( is == null || is.getItem() == Items.AIR || !( is.getItem() instanceof IUpgradeModule ) )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
final Upgrades myUpgrade = ((IUpgradeModule) is.getItem()).getType(is);
|
||||
switch (myUpgrade) {
|
||||
case CAPACITY:
|
||||
this.capacityUpgrades++;
|
||||
break;
|
||||
case FUZZY:
|
||||
this.fuzzyUpgrades++;
|
||||
break;
|
||||
case REDSTONE:
|
||||
this.redstoneUpgrades++;
|
||||
break;
|
||||
case SPEED:
|
||||
this.speedUpgrades++;
|
||||
break;
|
||||
case INVERTER:
|
||||
this.inverterUpgrades++;
|
||||
break;
|
||||
case CRAFTING:
|
||||
this.craftingUpgrades++;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
final Upgrades myUpgrade = ( (IUpgradeModule) is.getItem() ).getType( is );
|
||||
switch( myUpgrade )
|
||||
{
|
||||
case CAPACITY:
|
||||
this.capacityUpgrades++;
|
||||
break;
|
||||
case FUZZY:
|
||||
this.fuzzyUpgrades++;
|
||||
break;
|
||||
case REDSTONE:
|
||||
this.redstoneUpgrades++;
|
||||
break;
|
||||
case SPEED:
|
||||
this.speedUpgrades++;
|
||||
break;
|
||||
case INVERTER:
|
||||
this.inverterUpgrades++;
|
||||
break;
|
||||
case CRAFTING:
|
||||
this.craftingUpgrades++;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
this.capacityUpgrades = Math.min(this.capacityUpgrades, this.getMaxInstalled(Upgrades.CAPACITY));
|
||||
this.fuzzyUpgrades = Math.min(this.fuzzyUpgrades, this.getMaxInstalled(Upgrades.FUZZY));
|
||||
this.redstoneUpgrades = Math.min(this.redstoneUpgrades, this.getMaxInstalled(Upgrades.REDSTONE));
|
||||
this.speedUpgrades = Math.min(this.speedUpgrades, this.getMaxInstalled(Upgrades.SPEED));
|
||||
this.inverterUpgrades = Math.min(this.inverterUpgrades, this.getMaxInstalled(Upgrades.INVERTER));
|
||||
this.craftingUpgrades = Math.min(this.craftingUpgrades, this.getMaxInstalled(Upgrades.CRAFTING));
|
||||
}
|
||||
|
||||
this.capacityUpgrades = Math.min( this.capacityUpgrades, this.getMaxInstalled( Upgrades.CAPACITY ) );
|
||||
this.fuzzyUpgrades = Math.min( this.fuzzyUpgrades, this.getMaxInstalled( Upgrades.FUZZY ) );
|
||||
this.redstoneUpgrades = Math.min( this.redstoneUpgrades, this.getMaxInstalled( Upgrades.REDSTONE ) );
|
||||
this.speedUpgrades = Math.min( this.speedUpgrades, this.getMaxInstalled( Upgrades.SPEED ) );
|
||||
this.inverterUpgrades = Math.min( this.inverterUpgrades, this.getMaxInstalled( Upgrades.INVERTER ) );
|
||||
this.craftingUpgrades = Math.min( this.craftingUpgrades, this.getMaxInstalled( Upgrades.CRAFTING ) );
|
||||
}
|
||||
@Override
|
||||
public void readFromNBT(final CompoundNBT target) {
|
||||
super.readFromNBT(target);
|
||||
this.updateUpgradeInfo();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT( final CompoundNBT target )
|
||||
{
|
||||
super.readFromNBT( target );
|
||||
this.updateUpgradeInfo();
|
||||
}
|
||||
@Override
|
||||
public void saveChanges() {
|
||||
if (this.parent != null) {
|
||||
this.parent.saveChanges();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveChanges()
|
||||
{
|
||||
if( this.parent != null )
|
||||
{
|
||||
this.parent.saveChanges();
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void onChangeInventory(final IItemHandler inv, final int slot, final InvOperation mc,
|
||||
final ItemStack removedStack, final ItemStack newStack) {
|
||||
this.cached = false;
|
||||
if (this.parent != null && Platform.isServer()) {
|
||||
this.parent.onChangeInventory(inv, slot, mc, removedStack, newStack);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChangeInventory( final IItemHandler inv, final int slot, final InvOperation mc, final ItemStack removedStack, final ItemStack newStack )
|
||||
{
|
||||
this.cached = false;
|
||||
if( this.parent != null && Platform.isServer() )
|
||||
{
|
||||
this.parent.onChangeInventory( inv, slot, mc, removedStack, newStack );
|
||||
}
|
||||
}
|
||||
private class UpgradeInvFilter implements IAEItemFilter {
|
||||
|
||||
private class UpgradeInvFilter implements IAEItemFilter
|
||||
{
|
||||
@Override
|
||||
public boolean allowExtract(IItemHandler inv, int slot, int amount) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean allowExtract( IItemHandler inv, int slot, int amount )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean allowInsert( IItemHandler inv, int slot, ItemStack itemstack )
|
||||
{
|
||||
if( itemstack.isEmpty() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
final Item it = itemstack.getItem();
|
||||
if( it instanceof IUpgradeModule )
|
||||
{
|
||||
final Upgrades u = ( (IUpgradeModule) it ).getType( itemstack );
|
||||
if( u != null )
|
||||
{
|
||||
return UpgradeInventory.this.getInstalledUpgrades( u ) < UpgradeInventory.this.getMaxInstalled( u );
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public boolean allowInsert(IItemHandler inv, int slot, ItemStack itemstack) {
|
||||
if (itemstack.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
final Item it = itemstack.getItem();
|
||||
if (it instanceof IUpgradeModule) {
|
||||
final Upgrades u = ((IUpgradeModule) it).getType(itemstack);
|
||||
if (u != null) {
|
||||
return UpgradeInventory.this.getInstalledUpgrades(u) < UpgradeInventory.this.getMaxInstalled(u);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user