pick 97420a31d The big reformat of 2020
This commit is contained in:
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.parts.misc;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
@@ -46,317 +45,271 @@ import appeng.me.storage.ITickingMonitor;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.item.AEItemStack;
|
||||
|
||||
|
||||
/**
|
||||
* Wraps an Item Handler in such a way that it can be used as an IMEInventory for items.
|
||||
* Wraps an Item Handler in such a way that it can be used as an IMEInventory
|
||||
* for items.
|
||||
*/
|
||||
class ItemHandlerAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<IAEItemStack>, ITickingMonitor
|
||||
{
|
||||
private final Map<IMEMonitorHandlerReceiver<IAEItemStack>, Object> listeners = new HashMap<>();
|
||||
private IActionSource mySource;
|
||||
private final IItemHandler itemHandler;
|
||||
private final IGridProxyable proxyable;
|
||||
private final InventoryCache cache;
|
||||
class ItemHandlerAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<IAEItemStack>, ITickingMonitor {
|
||||
private final Map<IMEMonitorHandlerReceiver<IAEItemStack>, Object> listeners = new HashMap<>();
|
||||
private IActionSource mySource;
|
||||
private final IItemHandler itemHandler;
|
||||
private final IGridProxyable proxyable;
|
||||
private final InventoryCache cache;
|
||||
|
||||
ItemHandlerAdapter( IItemHandler itemHandler, IGridProxyable proxy )
|
||||
{
|
||||
this.itemHandler = itemHandler;
|
||||
this.proxyable = proxy;
|
||||
this.cache = new InventoryCache( this.itemHandler );
|
||||
}
|
||||
ItemHandlerAdapter(IItemHandler itemHandler, IGridProxyable proxy) {
|
||||
this.itemHandler = itemHandler;
|
||||
this.proxyable = proxy;
|
||||
this.cache = new InventoryCache(this.itemHandler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack injectItems( IAEItemStack iox, Actionable type, IActionSource src )
|
||||
{
|
||||
ItemStack orgInput = iox.createItemStack();
|
||||
ItemStack remaining = orgInput;
|
||||
@Override
|
||||
public IAEItemStack injectItems(IAEItemStack iox, Actionable type, IActionSource src) {
|
||||
ItemStack orgInput = iox.createItemStack();
|
||||
ItemStack remaining = orgInput;
|
||||
|
||||
int slotCount = this.itemHandler.getSlots();
|
||||
boolean simulate = ( type == Actionable.SIMULATE );
|
||||
int slotCount = this.itemHandler.getSlots();
|
||||
boolean simulate = (type == Actionable.SIMULATE);
|
||||
|
||||
// This uses a brute force approach and tries to jam it in every slot the inventory exposes.
|
||||
for( int i = 0; i < slotCount && !remaining.isEmpty(); i++ )
|
||||
{
|
||||
remaining = this.itemHandler.insertItem( i, remaining, simulate );
|
||||
}
|
||||
// This uses a brute force approach and tries to jam it in every slot the
|
||||
// inventory exposes.
|
||||
for (int i = 0; i < slotCount && !remaining.isEmpty(); i++) {
|
||||
remaining = this.itemHandler.insertItem(i, remaining, simulate);
|
||||
}
|
||||
|
||||
// At this point, we still have some items left...
|
||||
if( remaining == orgInput )
|
||||
{
|
||||
// The stack remained unmodified, target inventory is full
|
||||
return iox;
|
||||
}
|
||||
// At this point, we still have some items left...
|
||||
if (remaining == orgInput) {
|
||||
// The stack remained unmodified, target inventory is full
|
||||
return iox;
|
||||
}
|
||||
|
||||
if( type == Actionable.MODULATE )
|
||||
{
|
||||
try
|
||||
{
|
||||
this.proxyable.getProxy().getTick().alertDevice( this.proxyable.getProxy().getNode() );
|
||||
}
|
||||
catch( GridAccessException ex )
|
||||
{
|
||||
// meh
|
||||
}
|
||||
}
|
||||
if (type == Actionable.MODULATE) {
|
||||
try {
|
||||
this.proxyable.getProxy().getTick().alertDevice(this.proxyable.getProxy().getNode());
|
||||
} catch (GridAccessException ex) {
|
||||
// meh
|
||||
}
|
||||
}
|
||||
|
||||
return AEItemStack.fromItemStack( remaining );
|
||||
}
|
||||
return AEItemStack.fromItemStack(remaining);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack extractItems( IAEItemStack request, Actionable mode, IActionSource src )
|
||||
{
|
||||
@Override
|
||||
public IAEItemStack extractItems(IAEItemStack request, Actionable mode, IActionSource src) {
|
||||
|
||||
ItemStack requestedItemStack = request.createItemStack();
|
||||
int remainingSize = requestedItemStack.getCount();
|
||||
ItemStack requestedItemStack = request.createItemStack();
|
||||
int remainingSize = requestedItemStack.getCount();
|
||||
|
||||
// Use this to gather the requested items
|
||||
ItemStack gathered = ItemStack.EMPTY;
|
||||
// Use this to gather the requested items
|
||||
ItemStack gathered = ItemStack.EMPTY;
|
||||
|
||||
final boolean simulate = ( mode == Actionable.SIMULATE );
|
||||
final boolean simulate = (mode == Actionable.SIMULATE);
|
||||
|
||||
for( int i = 0; i < this.itemHandler.getSlots(); i++ )
|
||||
{
|
||||
ItemStack stackInInventorySlot = this.itemHandler.getStackInSlot( i );
|
||||
for (int i = 0; i < this.itemHandler.getSlots(); i++) {
|
||||
ItemStack stackInInventorySlot = this.itemHandler.getStackInSlot(i);
|
||||
|
||||
if( !Platform.itemComparisons().isSameItem( stackInInventorySlot, requestedItemStack ) )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (!Platform.itemComparisons().isSameItem(stackInInventorySlot, requestedItemStack)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ItemStack extracted;
|
||||
int stackSizeCurrentSlot = stackInInventorySlot.getCount();
|
||||
int remainingCurrentSlot = Math.min( remainingSize, stackSizeCurrentSlot );
|
||||
ItemStack extracted;
|
||||
int stackSizeCurrentSlot = stackInInventorySlot.getCount();
|
||||
int remainingCurrentSlot = Math.min(remainingSize, stackSizeCurrentSlot);
|
||||
|
||||
// We have to loop here because according to the docs, the handler shouldn't return a stack with size >
|
||||
// maxSize, even if we request more. So even if it returns a valid stack, it might have more stuff.
|
||||
do
|
||||
{
|
||||
extracted = this.itemHandler.extractItem( i, remainingCurrentSlot, simulate );
|
||||
if( !extracted.isEmpty() )
|
||||
{
|
||||
if( extracted.getCount() > remainingCurrentSlot )
|
||||
{
|
||||
// Something broke. It should never return more than we requested...
|
||||
// We're going to silently eat the remainder
|
||||
AELog.warn( "Mod that provided item handler %s is broken. Returned %s items while only requesting %d.",
|
||||
this.itemHandler.getClass().getName(), extracted.toString(), remainingCurrentSlot );
|
||||
extracted.setCount( remainingCurrentSlot );
|
||||
}
|
||||
// We have to loop here because according to the docs, the handler shouldn't
|
||||
// return a stack with size >
|
||||
// maxSize, even if we request more. So even if it returns a valid stack, it
|
||||
// might have more stuff.
|
||||
do {
|
||||
extracted = this.itemHandler.extractItem(i, remainingCurrentSlot, simulate);
|
||||
if (!extracted.isEmpty()) {
|
||||
if (extracted.getCount() > remainingCurrentSlot) {
|
||||
// Something broke. It should never return more than we requested...
|
||||
// We're going to silently eat the remainder
|
||||
AELog.warn(
|
||||
"Mod that provided item handler %s is broken. Returned %s items while only requesting %d.",
|
||||
this.itemHandler.getClass().getName(), extracted.toString(), remainingCurrentSlot);
|
||||
extracted.setCount(remainingCurrentSlot);
|
||||
}
|
||||
|
||||
// We're just gonna use the first stack we get our hands on as the template for the rest.
|
||||
// In case some stupid itemhandler (aka forge) returns an internal state we have to do a second
|
||||
// expensive copy again.
|
||||
if( gathered.isEmpty() )
|
||||
{
|
||||
gathered = extracted.copy();
|
||||
}
|
||||
else
|
||||
{
|
||||
gathered.grow( extracted.getCount() );
|
||||
}
|
||||
remainingCurrentSlot -= extracted.getCount();
|
||||
}
|
||||
}
|
||||
while( !extracted.isEmpty() && remainingCurrentSlot > 0 );
|
||||
// We're just gonna use the first stack we get our hands on as the template for
|
||||
// the rest.
|
||||
// In case some stupid itemhandler (aka forge) returns an internal state we have
|
||||
// to do a second
|
||||
// expensive copy again.
|
||||
if (gathered.isEmpty()) {
|
||||
gathered = extracted.copy();
|
||||
} else {
|
||||
gathered.grow(extracted.getCount());
|
||||
}
|
||||
remainingCurrentSlot -= extracted.getCount();
|
||||
}
|
||||
} while (!extracted.isEmpty() && remainingCurrentSlot > 0);
|
||||
|
||||
remainingSize -= stackSizeCurrentSlot - remainingCurrentSlot;
|
||||
remainingSize -= stackSizeCurrentSlot - remainingCurrentSlot;
|
||||
|
||||
// Done?
|
||||
if( remainingSize <= 0 )
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Done?
|
||||
if (remainingSize <= 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if( !gathered.isEmpty() )
|
||||
{
|
||||
if( mode == Actionable.MODULATE )
|
||||
{
|
||||
try
|
||||
{
|
||||
this.proxyable.getProxy().getTick().alertDevice( this.proxyable.getProxy().getNode() );
|
||||
}
|
||||
catch( GridAccessException ex )
|
||||
{
|
||||
// meh
|
||||
}
|
||||
}
|
||||
if (!gathered.isEmpty()) {
|
||||
if (mode == Actionable.MODULATE) {
|
||||
try {
|
||||
this.proxyable.getProxy().getTick().alertDevice(this.proxyable.getProxy().getNode());
|
||||
} catch (GridAccessException ex) {
|
||||
// meh
|
||||
}
|
||||
}
|
||||
|
||||
return AEItemStack.fromItemStack( gathered );
|
||||
}
|
||||
return AEItemStack.fromItemStack(gathered);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickRateModulation onTick()
|
||||
{
|
||||
List<IAEItemStack> changes = this.cache.update();
|
||||
if( !changes.isEmpty() )
|
||||
{
|
||||
this.postDifference( changes );
|
||||
return TickRateModulation.URGENT;
|
||||
}
|
||||
else
|
||||
{
|
||||
return TickRateModulation.SLOWER;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public TickRateModulation onTick() {
|
||||
List<IAEItemStack> changes = this.cache.update();
|
||||
if (!changes.isEmpty()) {
|
||||
this.postDifference(changes);
|
||||
return TickRateModulation.URGENT;
|
||||
} else {
|
||||
return TickRateModulation.SLOWER;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setActionSource( final IActionSource mySource )
|
||||
{
|
||||
this.mySource = mySource;
|
||||
}
|
||||
@Override
|
||||
public void setActionSource(final IActionSource mySource) {
|
||||
this.mySource = mySource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemList<IAEItemStack> getAvailableItems( IItemList<IAEItemStack> out )
|
||||
{
|
||||
return this.cache.getAvailableItems( out );
|
||||
}
|
||||
@Override
|
||||
public IItemList<IAEItemStack> getAvailableItems(IItemList<IAEItemStack> out) {
|
||||
return this.cache.getAvailableItems(out);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemStorageChannel getChannel()
|
||||
{
|
||||
return AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class );
|
||||
}
|
||||
@Override
|
||||
public IItemStorageChannel getChannel() {
|
||||
return AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addListener( final IMEMonitorHandlerReceiver<IAEItemStack> l, final Object verificationToken )
|
||||
{
|
||||
this.listeners.put( l, verificationToken );
|
||||
}
|
||||
@Override
|
||||
public void addListener(final IMEMonitorHandlerReceiver<IAEItemStack> l, final Object verificationToken) {
|
||||
this.listeners.put(l, verificationToken);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeListener( final IMEMonitorHandlerReceiver<IAEItemStack> l )
|
||||
{
|
||||
this.listeners.remove( l );
|
||||
}
|
||||
@Override
|
||||
public void removeListener(final IMEMonitorHandlerReceiver<IAEItemStack> l) {
|
||||
this.listeners.remove(l);
|
||||
}
|
||||
|
||||
private void postDifference( Iterable<IAEItemStack> a )
|
||||
{
|
||||
final Iterator<Map.Entry<IMEMonitorHandlerReceiver<IAEItemStack>, Object>> i = this.listeners.entrySet().iterator();
|
||||
while( i.hasNext() )
|
||||
{
|
||||
final Map.Entry<IMEMonitorHandlerReceiver<IAEItemStack>, Object> l = i.next();
|
||||
final IMEMonitorHandlerReceiver<IAEItemStack> key = l.getKey();
|
||||
if( key.isValid( l.getValue() ) )
|
||||
{
|
||||
key.postChange( this, a, this.mySource );
|
||||
}
|
||||
else
|
||||
{
|
||||
i.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
private void postDifference(Iterable<IAEItemStack> a) {
|
||||
final Iterator<Map.Entry<IMEMonitorHandlerReceiver<IAEItemStack>, Object>> i = this.listeners.entrySet()
|
||||
.iterator();
|
||||
while (i.hasNext()) {
|
||||
final Map.Entry<IMEMonitorHandlerReceiver<IAEItemStack>, Object> l = i.next();
|
||||
final IMEMonitorHandlerReceiver<IAEItemStack> key = l.getKey();
|
||||
if (key.isValid(l.getValue())) {
|
||||
key.postChange(this, a, this.mySource);
|
||||
} else {
|
||||
i.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class InventoryCache
|
||||
{
|
||||
private IAEItemStack[] cachedAeStacks = new IAEItemStack[0];
|
||||
private final IItemHandler itemHandler;
|
||||
private static class InventoryCache {
|
||||
private IAEItemStack[] cachedAeStacks = new IAEItemStack[0];
|
||||
private final IItemHandler itemHandler;
|
||||
|
||||
public InventoryCache( IItemHandler itemHandler )
|
||||
{
|
||||
this.itemHandler = itemHandler;
|
||||
}
|
||||
public InventoryCache(IItemHandler itemHandler) {
|
||||
this.itemHandler = itemHandler;
|
||||
}
|
||||
|
||||
public IItemList<IAEItemStack> getAvailableItems( IItemList<IAEItemStack> out )
|
||||
{
|
||||
Arrays.stream( this.cachedAeStacks ).forEach( out::add );
|
||||
return out;
|
||||
}
|
||||
public IItemList<IAEItemStack> getAvailableItems(IItemList<IAEItemStack> out) {
|
||||
Arrays.stream(this.cachedAeStacks).forEach(out::add);
|
||||
return out;
|
||||
}
|
||||
|
||||
public List<IAEItemStack> update()
|
||||
{
|
||||
final List<IAEItemStack> changes = new ArrayList<>();
|
||||
final int slots = this.itemHandler.getSlots();
|
||||
public List<IAEItemStack> update() {
|
||||
final List<IAEItemStack> changes = new ArrayList<>();
|
||||
final int slots = this.itemHandler.getSlots();
|
||||
|
||||
// Make room for new slots
|
||||
if( slots > this.cachedAeStacks.length )
|
||||
{
|
||||
this.cachedAeStacks = Arrays.copyOf( this.cachedAeStacks, slots );
|
||||
}
|
||||
// Make room for new slots
|
||||
if (slots > this.cachedAeStacks.length) {
|
||||
this.cachedAeStacks = Arrays.copyOf(this.cachedAeStacks, slots);
|
||||
}
|
||||
|
||||
for( int slot = 0; slot < slots; slot++ )
|
||||
{
|
||||
// Save the old stuff
|
||||
final IAEItemStack oldAeIS = this.cachedAeStacks[slot];
|
||||
final ItemStack newIS = this.itemHandler.getStackInSlot( slot );
|
||||
for (int slot = 0; slot < slots; slot++) {
|
||||
// Save the old stuff
|
||||
final IAEItemStack oldAeIS = this.cachedAeStacks[slot];
|
||||
final ItemStack newIS = this.itemHandler.getStackInSlot(slot);
|
||||
|
||||
this.handlePossibleSlotChanges( slot, oldAeIS, newIS, changes );
|
||||
}
|
||||
this.handlePossibleSlotChanges(slot, oldAeIS, newIS, changes);
|
||||
}
|
||||
|
||||
// Handle cases where the number of slots actually is lower now than before
|
||||
if( slots < this.cachedAeStacks.length )
|
||||
{
|
||||
for( int slot = slots; slot < this.cachedAeStacks.length; slot++ )
|
||||
{
|
||||
final IAEItemStack aeStack = this.cachedAeStacks[slot];
|
||||
// Handle cases where the number of slots actually is lower now than before
|
||||
if (slots < this.cachedAeStacks.length) {
|
||||
for (int slot = slots; slot < this.cachedAeStacks.length; slot++) {
|
||||
final IAEItemStack aeStack = this.cachedAeStacks[slot];
|
||||
|
||||
if( aeStack != null )
|
||||
{
|
||||
final IAEItemStack a = aeStack.copy();
|
||||
a.setStackSize( -a.getStackSize() );
|
||||
changes.add( a );
|
||||
}
|
||||
}
|
||||
if (aeStack != null) {
|
||||
final IAEItemStack a = aeStack.copy();
|
||||
a.setStackSize(-a.getStackSize());
|
||||
changes.add(a);
|
||||
}
|
||||
}
|
||||
|
||||
// Reduce the cache size
|
||||
this.cachedAeStacks = Arrays.copyOf( this.cachedAeStacks, slots );
|
||||
}
|
||||
// Reduce the cache size
|
||||
this.cachedAeStacks = Arrays.copyOf(this.cachedAeStacks, slots);
|
||||
}
|
||||
|
||||
return changes;
|
||||
}
|
||||
return changes;
|
||||
}
|
||||
|
||||
private void handlePossibleSlotChanges( int slot, IAEItemStack oldAeIS, ItemStack newIS, List<IAEItemStack> changes )
|
||||
{
|
||||
if( oldAeIS != null && oldAeIS.isSameType( newIS ) )
|
||||
{
|
||||
this.handleStackSizeChanged( slot, oldAeIS, newIS, changes );
|
||||
}
|
||||
else
|
||||
{
|
||||
this.handleItemChanged( slot, oldAeIS, newIS, changes );
|
||||
}
|
||||
}
|
||||
private void handlePossibleSlotChanges(int slot, IAEItemStack oldAeIS, ItemStack newIS,
|
||||
List<IAEItemStack> changes) {
|
||||
if (oldAeIS != null && oldAeIS.isSameType(newIS)) {
|
||||
this.handleStackSizeChanged(slot, oldAeIS, newIS, changes);
|
||||
} else {
|
||||
this.handleItemChanged(slot, oldAeIS, newIS, changes);
|
||||
}
|
||||
}
|
||||
|
||||
private void handleStackSizeChanged( int slot, IAEItemStack oldAeIS, ItemStack newIS, List<IAEItemStack> changes )
|
||||
{
|
||||
// Still the same item, but amount might have changed
|
||||
final long diff = newIS.getCount() - oldAeIS.getStackSize();
|
||||
private void handleStackSizeChanged(int slot, IAEItemStack oldAeIS, ItemStack newIS,
|
||||
List<IAEItemStack> changes) {
|
||||
// Still the same item, but amount might have changed
|
||||
final long diff = newIS.getCount() - oldAeIS.getStackSize();
|
||||
|
||||
if( diff != 0 )
|
||||
{
|
||||
final IAEItemStack stack = oldAeIS.copy();
|
||||
stack.setStackSize( newIS.getCount() );
|
||||
if (diff != 0) {
|
||||
final IAEItemStack stack = oldAeIS.copy();
|
||||
stack.setStackSize(newIS.getCount());
|
||||
|
||||
this.cachedAeStacks[slot] = stack;
|
||||
this.cachedAeStacks[slot] = stack;
|
||||
|
||||
final IAEItemStack a = stack.copy();
|
||||
a.setStackSize( diff );
|
||||
changes.add( a );
|
||||
}
|
||||
}
|
||||
final IAEItemStack a = stack.copy();
|
||||
a.setStackSize(diff);
|
||||
changes.add(a);
|
||||
}
|
||||
}
|
||||
|
||||
private void handleItemChanged( int slot, IAEItemStack oldAeIS, ItemStack newIS, List<IAEItemStack> changes )
|
||||
{
|
||||
// Completely different item
|
||||
this.cachedAeStacks[slot] = AEItemStack.fromItemStack( newIS );
|
||||
private void handleItemChanged(int slot, IAEItemStack oldAeIS, ItemStack newIS, List<IAEItemStack> changes) {
|
||||
// Completely different item
|
||||
this.cachedAeStacks[slot] = AEItemStack.fromItemStack(newIS);
|
||||
|
||||
// If we had a stack previously in this slot, notify the network about its disappearance
|
||||
if( oldAeIS != null )
|
||||
{
|
||||
oldAeIS.setStackSize( -oldAeIS.getStackSize() );
|
||||
changes.add( oldAeIS );
|
||||
}
|
||||
// If we had a stack previously in this slot, notify the network about its
|
||||
// disappearance
|
||||
if (oldAeIS != null) {
|
||||
oldAeIS.setStackSize(-oldAeIS.getStackSize());
|
||||
changes.add(oldAeIS);
|
||||
}
|
||||
|
||||
// Notify the network about the new stack. Note that this is null if newIS was null
|
||||
if( this.cachedAeStacks[slot] != null )
|
||||
{
|
||||
changes.add( this.cachedAeStacks[slot] );
|
||||
}
|
||||
}
|
||||
}
|
||||
// Notify the network about the new stack. Note that this is null if newIS was
|
||||
// null
|
||||
if (this.cachedAeStacks[slot] != null) {
|
||||
changes.add(this.cachedAeStacks[slot]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.parts.misc;
|
||||
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
@@ -50,206 +49,172 @@ import appeng.core.AppEng;
|
||||
import appeng.items.parts.PartModels;
|
||||
import appeng.parts.PartModel;
|
||||
|
||||
public class PartCableAnchor implements IPart {
|
||||
|
||||
public class PartCableAnchor implements IPart
|
||||
{
|
||||
@PartModels
|
||||
public static final PartModel DEFAULT_MODELS = new PartModel(false,
|
||||
new ResourceLocation(AppEng.MOD_ID, "part/cable_anchor"));
|
||||
|
||||
@PartModels
|
||||
public static final PartModel DEFAULT_MODELS = new PartModel( false, new ResourceLocation( AppEng.MOD_ID, "part/cable_anchor" ) );
|
||||
@PartModels
|
||||
public static final PartModel FACADE_MODELS = new PartModel(false,
|
||||
new ResourceLocation(AppEng.MOD_ID, "part/cable_anchor_short"));
|
||||
|
||||
@PartModels
|
||||
public static final PartModel FACADE_MODELS = new PartModel( false, new ResourceLocation( AppEng.MOD_ID, "part/cable_anchor_short" ) );
|
||||
private ItemStack is = ItemStack.EMPTY;
|
||||
private IPartHost host = null;
|
||||
private AEPartLocation mySide = AEPartLocation.UP;
|
||||
|
||||
private ItemStack is = ItemStack.EMPTY;
|
||||
private IPartHost host = null;
|
||||
private AEPartLocation mySide = AEPartLocation.UP;
|
||||
public PartCableAnchor(final ItemStack is) {
|
||||
this.is = is;
|
||||
}
|
||||
|
||||
public PartCableAnchor( final ItemStack is )
|
||||
{
|
||||
this.is = is;
|
||||
}
|
||||
@Override
|
||||
public void getBoxes(final IPartCollisionHelper bch) {
|
||||
if (this.host != null && this.host.getFacadeContainer().getFacade(this.mySide) != null) {
|
||||
bch.addBox(7, 7, 10, 9, 9, 14);
|
||||
} else {
|
||||
bch.addBox(7, 7, 10, 9, 9, 16);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getBoxes( final IPartCollisionHelper bch )
|
||||
{
|
||||
if( this.host != null && this.host.getFacadeContainer().getFacade( this.mySide ) != null )
|
||||
{
|
||||
bch.addBox( 7, 7, 10, 9, 9, 14 );
|
||||
}
|
||||
else
|
||||
{
|
||||
bch.addBox( 7, 7, 10, 9, 9, 16 );
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public ItemStack getItemStack(final PartItemStack wrenched) {
|
||||
return this.is;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItemStack( final PartItemStack wrenched )
|
||||
{
|
||||
return this.is;
|
||||
}
|
||||
@Override
|
||||
public boolean requireDynamicRender() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean requireDynamicRender()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean isSolid() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSolid()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean canConnectRedstone() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canConnectRedstone()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public void writeToNBT(final CompoundNBT data) {
|
||||
|
||||
@Override
|
||||
public void writeToNBT( final CompoundNBT data )
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
public void readFromNBT(final CompoundNBT data) {
|
||||
|
||||
@Override
|
||||
public void readFromNBT( final CompoundNBT data )
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
public int getLightLevel() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLightLevel()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@Override
|
||||
public boolean isLadder(final LivingEntity entity) {
|
||||
return this.mySide.yOffset == 0 && (entity.collidedHorizontally || !entity.onGround);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLadder( final LivingEntity entity )
|
||||
{
|
||||
return this.mySide.yOffset == 0 && ( entity.collidedHorizontally || !entity.onGround );
|
||||
}
|
||||
@Override
|
||||
public void onNeighborChanged(IBlockReader w, BlockPos pos, BlockPos neighbor) {
|
||||
|
||||
@Override
|
||||
public void onNeighborChanged( IBlockReader w, BlockPos pos, BlockPos neighbor )
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
public int isProvidingStrongPower() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int isProvidingStrongPower()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@Override
|
||||
public int isProvidingWeakPower() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int isProvidingWeakPower()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@Override
|
||||
public void writeToStream(final PacketBuffer data) throws IOException {
|
||||
|
||||
@Override
|
||||
public void writeToStream( final PacketBuffer data ) throws IOException
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
public boolean readFromStream(final PacketBuffer data) throws IOException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean readFromStream( final PacketBuffer data ) throws IOException
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public IGridNode getGridNode() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IGridNode getGridNode()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public void onEntityCollision(final Entity entity) {
|
||||
|
||||
@Override
|
||||
public void onEntityCollision( final Entity entity )
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
public void removeFromWorld() {
|
||||
|
||||
@Override
|
||||
public void removeFromWorld()
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
public void addToWorld() {
|
||||
|
||||
@Override
|
||||
public void addToWorld()
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
public IGridNode getExternalFacingNode() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IGridNode getExternalFacingNode()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public void setPartHostInfo(final AEPartLocation side, final IPartHost host, final TileEntity tile) {
|
||||
this.host = host;
|
||||
this.mySide = side;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPartHostInfo( final AEPartLocation side, final IPartHost host, final TileEntity tile )
|
||||
{
|
||||
this.host = host;
|
||||
this.mySide = side;
|
||||
}
|
||||
@Override
|
||||
public boolean onActivate(final PlayerEntity player, final Hand hand, final Vec3d pos) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onActivate( final PlayerEntity player, final Hand hand, final Vec3d pos )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean onShiftActivate(final PlayerEntity player, final Hand hand, final Vec3d pos) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onShiftActivate( final PlayerEntity player, final Hand hand, final Vec3d pos )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public void getDrops(final List<ItemStack> drops, final boolean wrenched) {
|
||||
|
||||
@Override
|
||||
public void getDrops( final List<ItemStack> drops, final boolean wrenched )
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
public float getCableConnectionLength(AECableType cable) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getCableConnectionLength( AECableType cable )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@Override
|
||||
public void animateTick(final World world, final BlockPos pos, final Random r) {
|
||||
|
||||
@Override
|
||||
public void animateTick( final World world, final BlockPos pos, final Random r )
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
public void onPlacement(final PlayerEntity player, final Hand hand, final ItemStack held,
|
||||
final AEPartLocation side) {
|
||||
|
||||
@Override
|
||||
public void onPlacement( final PlayerEntity player, final Hand hand, final ItemStack held, final AEPartLocation side )
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
public boolean canBePlacedOn(final BusSupport what) {
|
||||
return what == BusSupport.CABLE || what == BusSupport.DENSE_CABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBePlacedOn( final BusSupport what )
|
||||
{
|
||||
return what == BusSupport.CABLE || what == BusSupport.DENSE_CABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPartModel getStaticModels()
|
||||
{
|
||||
if( this.host != null && this.host.getFacadeContainer().getFacade( this.mySide ) != null )
|
||||
{
|
||||
return FACADE_MODELS;
|
||||
}
|
||||
else
|
||||
{
|
||||
return DEFAULT_MODELS;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public IPartModel getStaticModels() {
|
||||
if (this.host != null && this.host.getFacadeContainer().getFacade(this.mySide) != null) {
|
||||
return FACADE_MODELS;
|
||||
} else {
|
||||
return DEFAULT_MODELS;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,13 +18,9 @@
|
||||
|
||||
package appeng.parts.misc;
|
||||
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
|
||||
import appeng.container.ContainerLocator;
|
||||
import appeng.container.ContainerOpener;
|
||||
import appeng.container.implementations.ContainerInterface;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
@@ -63,8 +59,10 @@ import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.storage.data.IAEStack;
|
||||
import appeng.api.util.AECableType;
|
||||
import appeng.api.util.IConfigManager;
|
||||
import appeng.container.ContainerLocator;
|
||||
import appeng.container.ContainerOpener;
|
||||
import appeng.container.implementations.ContainerInterface;
|
||||
import appeng.core.AppEng;
|
||||
|
||||
import appeng.helpers.DualityInterface;
|
||||
import appeng.helpers.IInterfaceHost;
|
||||
import appeng.helpers.IPriorityHost;
|
||||
@@ -77,243 +75,206 @@ import appeng.util.inv.IAEAppEngInventory;
|
||||
import appeng.util.inv.IInventoryDestination;
|
||||
import appeng.util.inv.InvOperation;
|
||||
|
||||
public class PartInterface extends PartBasicState implements IGridTickable, IStorageMonitorable, IInventoryDestination,
|
||||
IInterfaceHost, IAEAppEngInventory, IPriorityHost {
|
||||
|
||||
public class PartInterface extends PartBasicState implements IGridTickable, IStorageMonitorable, IInventoryDestination, IInterfaceHost, IAEAppEngInventory, IPriorityHost
|
||||
{
|
||||
public static final ResourceLocation MODEL_BASE = new ResourceLocation(AppEng.MOD_ID, "part/interface_base");
|
||||
|
||||
public static final ResourceLocation MODEL_BASE = new ResourceLocation( AppEng.MOD_ID, "part/interface_base" );
|
||||
@PartModels
|
||||
public static final PartModel MODELS_OFF = new PartModel(MODEL_BASE,
|
||||
new ResourceLocation(AppEng.MOD_ID, "part/interface_off"));
|
||||
|
||||
@PartModels
|
||||
public static final PartModel MODELS_OFF = new PartModel( MODEL_BASE, new ResourceLocation( AppEng.MOD_ID, "part/interface_off" ) );
|
||||
@PartModels
|
||||
public static final PartModel MODELS_ON = new PartModel(MODEL_BASE,
|
||||
new ResourceLocation(AppEng.MOD_ID, "part/interface_on"));
|
||||
|
||||
@PartModels
|
||||
public static final PartModel MODELS_ON = new PartModel( MODEL_BASE, new ResourceLocation( AppEng.MOD_ID, "part/interface_on" ) );
|
||||
@PartModels
|
||||
public static final PartModel MODELS_HAS_CHANNEL = new PartModel(MODEL_BASE,
|
||||
new ResourceLocation(AppEng.MOD_ID, "part/interface_has_channel"));
|
||||
|
||||
@PartModels
|
||||
public static final PartModel MODELS_HAS_CHANNEL = new PartModel( MODEL_BASE, new ResourceLocation( AppEng.MOD_ID, "part/interface_has_channel" ) );
|
||||
private final DualityInterface duality = new DualityInterface(this.getProxy(), this);
|
||||
|
||||
private final DualityInterface duality = new DualityInterface( this.getProxy(), this );
|
||||
@Reflected
|
||||
public PartInterface(final ItemStack is) {
|
||||
super(is);
|
||||
}
|
||||
|
||||
@Reflected
|
||||
public PartInterface( final ItemStack is )
|
||||
{
|
||||
super( is );
|
||||
}
|
||||
@MENetworkEventSubscribe
|
||||
public void stateChange(final MENetworkChannelsChanged c) {
|
||||
this.duality.notifyNeighbors();
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void stateChange( final MENetworkChannelsChanged c )
|
||||
{
|
||||
this.duality.notifyNeighbors();
|
||||
}
|
||||
@MENetworkEventSubscribe
|
||||
public void stateChange(final MENetworkPowerStatusChange c) {
|
||||
this.duality.notifyNeighbors();
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void stateChange( final MENetworkPowerStatusChange c )
|
||||
{
|
||||
this.duality.notifyNeighbors();
|
||||
}
|
||||
@Override
|
||||
public void getBoxes(final IPartCollisionHelper bch) {
|
||||
bch.addBox(2, 2, 14, 14, 14, 16);
|
||||
bch.addBox(5, 5, 12, 11, 11, 14);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getBoxes( final IPartCollisionHelper bch )
|
||||
{
|
||||
bch.addBox( 2, 2, 14, 14, 14, 16 );
|
||||
bch.addBox( 5, 5, 12, 11, 11, 14 );
|
||||
}
|
||||
@Override
|
||||
public int getInstalledUpgrades(final Upgrades u) {
|
||||
return this.duality.getInstalledUpgrades(u);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInstalledUpgrades( final Upgrades u )
|
||||
{
|
||||
return this.duality.getInstalledUpgrades( u );
|
||||
}
|
||||
@Override
|
||||
public void gridChanged() {
|
||||
this.duality.gridChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void gridChanged()
|
||||
{
|
||||
this.duality.gridChanged();
|
||||
}
|
||||
@Override
|
||||
public void readFromNBT(final CompoundNBT data) {
|
||||
super.readFromNBT(data);
|
||||
this.duality.readFromNBT(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT( final CompoundNBT data )
|
||||
{
|
||||
super.readFromNBT( data );
|
||||
this.duality.readFromNBT( data );
|
||||
}
|
||||
@Override
|
||||
public void writeToNBT(final CompoundNBT data) {
|
||||
super.writeToNBT(data);
|
||||
this.duality.writeToNBT(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT( final CompoundNBT data )
|
||||
{
|
||||
super.writeToNBT( data );
|
||||
this.duality.writeToNBT( data );
|
||||
}
|
||||
@Override
|
||||
public void addToWorld() {
|
||||
super.addToWorld();
|
||||
this.duality.initialize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addToWorld()
|
||||
{
|
||||
super.addToWorld();
|
||||
this.duality.initialize();
|
||||
}
|
||||
@Override
|
||||
public void getDrops(final List<ItemStack> drops, final boolean wrenched) {
|
||||
this.duality.addDrops(drops);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getDrops( final List<ItemStack> drops, final boolean wrenched )
|
||||
{
|
||||
this.duality.addDrops( drops );
|
||||
}
|
||||
@Override
|
||||
public float getCableConnectionLength(AECableType cable) {
|
||||
return 4;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getCableConnectionLength( AECableType cable )
|
||||
{
|
||||
return 4;
|
||||
}
|
||||
@Override
|
||||
public IConfigManager getConfigManager() {
|
||||
return this.duality.getConfigManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IConfigManager getConfigManager()
|
||||
{
|
||||
return this.duality.getConfigManager();
|
||||
}
|
||||
@Override
|
||||
public IItemHandler getInventoryByName(final String name) {
|
||||
return this.duality.getInventoryByName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemHandler getInventoryByName( final String name )
|
||||
{
|
||||
return this.duality.getInventoryByName( name );
|
||||
}
|
||||
@Override
|
||||
public boolean onPartActivate(final PlayerEntity p, final Hand hand, final Vec3d pos) {
|
||||
if (Platform.isServer()) {
|
||||
ContainerOpener.openContainer(ContainerInterface.TYPE, p, ContainerLocator.forPart(this));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPartActivate( final PlayerEntity p, final Hand hand, final Vec3d pos )
|
||||
{
|
||||
if( Platform.isServer() )
|
||||
{
|
||||
ContainerOpener.openContainer(ContainerInterface.TYPE, p, ContainerLocator.forPart(this));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean canInsert(final ItemStack stack) {
|
||||
return this.duality.canInsert(stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInsert( final ItemStack stack )
|
||||
{
|
||||
return this.duality.canInsert( stack );
|
||||
}
|
||||
@Override
|
||||
public <T extends IAEStack<T>> IMEMonitor<T> getInventory(IStorageChannel<T> channel) {
|
||||
return this.duality.getInventory(channel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends IAEStack<T>> IMEMonitor<T> getInventory( IStorageChannel<T> channel )
|
||||
{
|
||||
return this.duality.getInventory( channel );
|
||||
}
|
||||
@Override
|
||||
public TickingRequest getTickingRequest(final IGridNode node) {
|
||||
return this.duality.getTickingRequest(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickingRequest getTickingRequest( final IGridNode node )
|
||||
{
|
||||
return this.duality.getTickingRequest( node );
|
||||
}
|
||||
@Override
|
||||
public TickRateModulation tickingRequest(final IGridNode node, final int ticksSinceLastCall) {
|
||||
return this.duality.tickingRequest(node, ticksSinceLastCall);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickRateModulation tickingRequest( final IGridNode node, final int ticksSinceLastCall )
|
||||
{
|
||||
return this.duality.tickingRequest( node, ticksSinceLastCall );
|
||||
}
|
||||
@Override
|
||||
public void onChangeInventory(final IItemHandler inv, final int slot, final InvOperation mc,
|
||||
final ItemStack removedStack, final ItemStack newStack) {
|
||||
this.duality.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.duality.onChangeInventory( inv, slot, mc, removedStack, newStack );
|
||||
}
|
||||
@Override
|
||||
public DualityInterface getInterfaceDuality() {
|
||||
return this.duality;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DualityInterface getInterfaceDuality()
|
||||
{
|
||||
return this.duality;
|
||||
}
|
||||
@Override
|
||||
public EnumSet<Direction> getTargets() {
|
||||
return EnumSet.of(this.getSide().getFacing());
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumSet<Direction> getTargets()
|
||||
{
|
||||
return EnumSet.of( this.getSide().getFacing() );
|
||||
}
|
||||
@Override
|
||||
public TileEntity getTileEntity() {
|
||||
return super.getHost().getTile();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity getTileEntity()
|
||||
{
|
||||
return super.getHost().getTile();
|
||||
}
|
||||
@Override
|
||||
public boolean pushPattern(final ICraftingPatternDetails patternDetails, final CraftingInventory table) {
|
||||
return this.duality.pushPattern(patternDetails, table);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean pushPattern( final ICraftingPatternDetails patternDetails, final CraftingInventory table )
|
||||
{
|
||||
return this.duality.pushPattern( patternDetails, table );
|
||||
}
|
||||
@Override
|
||||
public boolean isBusy() {
|
||||
return this.duality.isBusy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBusy()
|
||||
{
|
||||
return this.duality.isBusy();
|
||||
}
|
||||
@Override
|
||||
public void provideCrafting(final ICraftingProviderHelper craftingTracker) {
|
||||
this.duality.provideCrafting(craftingTracker);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void provideCrafting( final ICraftingProviderHelper craftingTracker )
|
||||
{
|
||||
this.duality.provideCrafting( craftingTracker );
|
||||
}
|
||||
@Override
|
||||
public ImmutableSet<ICraftingLink> getRequestedJobs() {
|
||||
return this.duality.getRequestedJobs();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImmutableSet<ICraftingLink> getRequestedJobs()
|
||||
{
|
||||
return this.duality.getRequestedJobs();
|
||||
}
|
||||
@Override
|
||||
public IAEItemStack injectCraftedItems(final ICraftingLink link, final IAEItemStack items, final Actionable mode) {
|
||||
return this.duality.injectCraftedItems(link, items, mode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack injectCraftedItems( final ICraftingLink link, final IAEItemStack items, final Actionable mode )
|
||||
{
|
||||
return this.duality.injectCraftedItems( link, items, mode );
|
||||
}
|
||||
@Override
|
||||
public void jobStateChange(final ICraftingLink link) {
|
||||
this.duality.jobStateChange(link);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void jobStateChange( final ICraftingLink link )
|
||||
{
|
||||
this.duality.jobStateChange( link );
|
||||
}
|
||||
@Override
|
||||
public int getPriority() {
|
||||
return this.duality.getPriority();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPriority()
|
||||
{
|
||||
return this.duality.getPriority();
|
||||
}
|
||||
@Override
|
||||
public void setPriority(final int newValue) {
|
||||
this.duality.setPriority(newValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPriority( final int newValue )
|
||||
{
|
||||
this.duality.setPriority( newValue );
|
||||
}
|
||||
@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;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public <T> LazyOptional<T> getCapability(Capability<T> capabilityClass) {
|
||||
return this.duality.getCapability(capabilityClass, this.getSide().getFacing());
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> LazyOptional<T> getCapability(Capability<T> capabilityClass )
|
||||
{
|
||||
return this.duality.getCapability( capabilityClass, this.getSide().getFacing() );
|
||||
}
|
||||
@Override
|
||||
public ItemStack getItemStackRepresentation() {
|
||||
return AEApi.instance().definitions().parts().iface().maybeStack(1).orElse(ItemStack.EMPTY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItemStackRepresentation()
|
||||
{
|
||||
return AEApi.instance().definitions().parts().iface().maybeStack( 1 ).orElse( ItemStack.EMPTY );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContainerType<?> getContainerType()
|
||||
{
|
||||
return ContainerInterface.TYPE;
|
||||
}
|
||||
@Override
|
||||
public ContainerType<?> getContainerType() {
|
||||
return ContainerInterface.TYPE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.parts.misc;
|
||||
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
@@ -28,47 +27,38 @@ import appeng.helpers.Reflected;
|
||||
import appeng.items.parts.PartModels;
|
||||
import appeng.parts.PartModel;
|
||||
|
||||
public class PartInvertedToggleBus extends PartToggleBus {
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_BASE = new ResourceLocation(AppEng.MOD_ID,
|
||||
"part/inverted_toggle_bus_base");
|
||||
|
||||
public class PartInvertedToggleBus extends PartToggleBus
|
||||
{
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_BASE = new ResourceLocation( AppEng.MOD_ID, "part/inverted_toggle_bus_base" );
|
||||
public static final PartModel MODELS_OFF = new PartModel(MODEL_BASE, MODEL_STATUS_OFF);
|
||||
public static final PartModel MODELS_ON = new PartModel(MODEL_BASE, MODEL_STATUS_ON);
|
||||
public static final PartModel MODELS_HAS_CHANNEL = new PartModel(MODEL_BASE, MODEL_STATUS_HAS_CHANNEL);
|
||||
|
||||
public static final PartModel MODELS_OFF = new PartModel( MODEL_BASE, MODEL_STATUS_OFF );
|
||||
public static final PartModel MODELS_ON = new PartModel( MODEL_BASE, MODEL_STATUS_ON );
|
||||
public static final PartModel MODELS_HAS_CHANNEL = new PartModel( MODEL_BASE, MODEL_STATUS_HAS_CHANNEL );
|
||||
@Reflected
|
||||
public PartInvertedToggleBus(final ItemStack is) {
|
||||
super(is);
|
||||
this.getProxy().setIdlePowerUsage(0.0);
|
||||
this.getOuterProxy().setIdlePowerUsage(0.0);
|
||||
this.getProxy().setFlags();
|
||||
this.getOuterProxy().setFlags();
|
||||
}
|
||||
|
||||
@Reflected
|
||||
public PartInvertedToggleBus( final ItemStack is )
|
||||
{
|
||||
super( is );
|
||||
this.getProxy().setIdlePowerUsage( 0.0 );
|
||||
this.getOuterProxy().setIdlePowerUsage( 0.0 );
|
||||
this.getProxy().setFlags();
|
||||
this.getOuterProxy().setFlags();
|
||||
}
|
||||
@Override
|
||||
protected boolean getIntention() {
|
||||
return !super.getIntention();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean getIntention()
|
||||
{
|
||||
return !super.getIntention();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPartModel getStaticModels()
|
||||
{
|
||||
if( this.hasRedstoneFlag() && this.isActive() && this.isPowered() )
|
||||
{
|
||||
return MODELS_HAS_CHANNEL;
|
||||
}
|
||||
else if( this.hasRedstoneFlag() && this.isPowered() )
|
||||
{
|
||||
return MODELS_ON;
|
||||
}
|
||||
else
|
||||
{
|
||||
return MODELS_OFF;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public IPartModel getStaticModels() {
|
||||
if (this.hasRedstoneFlag() && this.isActive() && this.isPowered()) {
|
||||
return MODELS_HAS_CHANNEL;
|
||||
} else if (this.hasRedstoneFlag() && this.isPowered()) {
|
||||
return MODELS_ON;
|
||||
} else {
|
||||
return MODELS_OFF;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,196 +1,171 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2018, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.parts.misc;
|
||||
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import appeng.api.config.Settings;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IBlockReader;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.networking.events.MENetworkCellArrayUpdate;
|
||||
import appeng.api.networking.events.MENetworkChannelsChanged;
|
||||
import appeng.api.networking.events.MENetworkEventSubscribe;
|
||||
import appeng.api.networking.events.MENetworkPowerStatusChange;
|
||||
import appeng.api.networking.ticking.IGridTickable;
|
||||
import appeng.api.parts.IPartCollisionHelper;
|
||||
import appeng.api.storage.ICellContainer;
|
||||
import appeng.api.storage.ICellInventory;
|
||||
import appeng.api.storage.IMEInventoryHandler;
|
||||
import appeng.api.storage.IStorageChannel;
|
||||
import appeng.api.storage.channels.IItemStorageChannel;
|
||||
import appeng.api.util.AECableType;
|
||||
import appeng.api.util.IConfigManager;
|
||||
import appeng.helpers.IPriorityHost;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.parts.automation.PartUpgradeable;
|
||||
|
||||
|
||||
/**
|
||||
* @author BrockWS
|
||||
* @version rv6 - 22/05/2018
|
||||
* @since rv6 22/05/2018
|
||||
*/
|
||||
public abstract class PartSharedStorageBus extends PartUpgradeable implements IGridTickable, ICellContainer, IPriorityHost
|
||||
{
|
||||
private boolean wasActive = false;
|
||||
private int priority = 0;
|
||||
|
||||
public PartSharedStorageBus( ItemStack is )
|
||||
{
|
||||
super( is );
|
||||
}
|
||||
|
||||
protected void updateStatus()
|
||||
{
|
||||
final boolean currentActive = this.getProxy().isActive();
|
||||
if( this.wasActive != currentActive )
|
||||
{
|
||||
this.wasActive = currentActive;
|
||||
try
|
||||
{
|
||||
this.getProxy().getGrid().postEvent( new MENetworkCellArrayUpdate() );
|
||||
this.getHost().markForUpdate();
|
||||
}
|
||||
catch( final GridAccessException ignore )
|
||||
{
|
||||
// :P
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void updateChannels( final MENetworkChannelsChanged changedChannels )
|
||||
{
|
||||
this.updateStatus();
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to get this parts storage channel
|
||||
*
|
||||
* @return Storage channel
|
||||
*/
|
||||
public IStorageChannel getStorageChannel()
|
||||
{
|
||||
return AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class );
|
||||
}
|
||||
|
||||
protected abstract void resetCache();
|
||||
|
||||
protected abstract void resetCache( boolean fullReset );
|
||||
|
||||
@Override
|
||||
public List<IMEInventoryHandler> getCellArray( final IStorageChannel channel )
|
||||
{
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void blinkCell( int slot )
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveChanges( ICellInventory<?> cellInventory )
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPriority()
|
||||
{
|
||||
return this.priority;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPriority( final int newValue )
|
||||
{
|
||||
this.priority = newValue;
|
||||
this.getHost().markForSave();
|
||||
this.resetCache( true );
|
||||
}
|
||||
|
||||
@Override
|
||||
@MENetworkEventSubscribe
|
||||
public void powerRender( final MENetworkPowerStatusChange c )
|
||||
{
|
||||
this.updateStatus();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void upgradesChanged()
|
||||
{
|
||||
super.upgradesChanged();
|
||||
this.resetCache( true );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateSetting(final IConfigManager manager, final Settings settingName, final Enum<?> newValue )
|
||||
{
|
||||
this.resetCache( true );
|
||||
this.getHost().markForSave();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNeighborChanged( IBlockReader w, BlockPos pos, BlockPos neighbor )
|
||||
{
|
||||
if( pos.offset( this.getSide().getFacing() ).equals( neighbor ) )
|
||||
{
|
||||
this.resetCache( false );
|
||||
}
|
||||
}
|
||||
|
||||
@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.priority );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getBoxes( final IPartCollisionHelper bch )
|
||||
{
|
||||
bch.addBox( 3, 3, 15, 13, 13, 16 );
|
||||
bch.addBox( 2, 2, 14, 14, 14, 15 );
|
||||
bch.addBox( 5, 5, 12, 11, 11, 14 );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getUpgradeSlots()
|
||||
{
|
||||
return 5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getCableConnectionLength( AECableType cable )
|
||||
{
|
||||
return 4;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2018, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.parts.misc;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IBlockReader;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.Settings;
|
||||
import appeng.api.networking.events.MENetworkCellArrayUpdate;
|
||||
import appeng.api.networking.events.MENetworkChannelsChanged;
|
||||
import appeng.api.networking.events.MENetworkEventSubscribe;
|
||||
import appeng.api.networking.events.MENetworkPowerStatusChange;
|
||||
import appeng.api.networking.ticking.IGridTickable;
|
||||
import appeng.api.parts.IPartCollisionHelper;
|
||||
import appeng.api.storage.ICellContainer;
|
||||
import appeng.api.storage.ICellInventory;
|
||||
import appeng.api.storage.IMEInventoryHandler;
|
||||
import appeng.api.storage.IStorageChannel;
|
||||
import appeng.api.storage.channels.IItemStorageChannel;
|
||||
import appeng.api.util.AECableType;
|
||||
import appeng.api.util.IConfigManager;
|
||||
import appeng.helpers.IPriorityHost;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.parts.automation.PartUpgradeable;
|
||||
|
||||
/**
|
||||
* @author BrockWS
|
||||
* @version rv6 - 22/05/2018
|
||||
* @since rv6 22/05/2018
|
||||
*/
|
||||
public abstract class PartSharedStorageBus extends PartUpgradeable
|
||||
implements IGridTickable, ICellContainer, IPriorityHost {
|
||||
private boolean wasActive = false;
|
||||
private int priority = 0;
|
||||
|
||||
public PartSharedStorageBus(ItemStack is) {
|
||||
super(is);
|
||||
}
|
||||
|
||||
protected void updateStatus() {
|
||||
final boolean currentActive = this.getProxy().isActive();
|
||||
if (this.wasActive != currentActive) {
|
||||
this.wasActive = currentActive;
|
||||
try {
|
||||
this.getProxy().getGrid().postEvent(new MENetworkCellArrayUpdate());
|
||||
this.getHost().markForUpdate();
|
||||
} catch (final GridAccessException ignore) {
|
||||
// :P
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void updateChannels(final MENetworkChannelsChanged changedChannels) {
|
||||
this.updateStatus();
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to get this parts storage channel
|
||||
*
|
||||
* @return Storage channel
|
||||
*/
|
||||
public IStorageChannel getStorageChannel() {
|
||||
return AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class);
|
||||
}
|
||||
|
||||
protected abstract void resetCache();
|
||||
|
||||
protected abstract void resetCache(boolean fullReset);
|
||||
|
||||
@Override
|
||||
public List<IMEInventoryHandler> getCellArray(final IStorageChannel channel) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void blinkCell(int slot) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveChanges(ICellInventory<?> cellInventory) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPriority() {
|
||||
return this.priority;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPriority(final int newValue) {
|
||||
this.priority = newValue;
|
||||
this.getHost().markForSave();
|
||||
this.resetCache(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@MENetworkEventSubscribe
|
||||
public void powerRender(final MENetworkPowerStatusChange c) {
|
||||
this.updateStatus();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void upgradesChanged() {
|
||||
super.upgradesChanged();
|
||||
this.resetCache(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateSetting(final IConfigManager manager, final Settings settingName, final Enum<?> newValue) {
|
||||
this.resetCache(true);
|
||||
this.getHost().markForSave();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNeighborChanged(IBlockReader w, BlockPos pos, BlockPos neighbor) {
|
||||
if (pos.offset(this.getSide().getFacing()).equals(neighbor)) {
|
||||
this.resetCache(false);
|
||||
}
|
||||
}
|
||||
|
||||
@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.priority);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getBoxes(final IPartCollisionHelper bch) {
|
||||
bch.addBox(3, 3, 15, 13, 13, 16);
|
||||
bch.addBox(2, 2, 14, 14, 14, 15);
|
||||
bch.addBox(5, 5, 12, 11, 11, 14);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getUpgradeSlots() {
|
||||
return 5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getCableConnectionLength(AECableType cable) {
|
||||
return 4;
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.parts.misc;
|
||||
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
@@ -47,183 +46,154 @@ import appeng.me.helpers.AENetworkProxy;
|
||||
import appeng.parts.PartBasicState;
|
||||
import appeng.parts.PartModel;
|
||||
|
||||
public class PartToggleBus extends PartBasicState {
|
||||
|
||||
public class PartToggleBus extends PartBasicState
|
||||
{
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_BASE = new ResourceLocation(AppEng.MOD_ID, "part/toggle_bus_base");
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_STATUS_OFF = new ResourceLocation(AppEng.MOD_ID,
|
||||
"part/toggle_bus_status_off");
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_STATUS_ON = new ResourceLocation(AppEng.MOD_ID,
|
||||
"part/toggle_bus_status_on");
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_STATUS_HAS_CHANNEL = new ResourceLocation(AppEng.MOD_ID,
|
||||
"part/toggle_bus_status_has_channel");
|
||||
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_BASE = new ResourceLocation( AppEng.MOD_ID, "part/toggle_bus_base" );
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_STATUS_OFF = new ResourceLocation( AppEng.MOD_ID, "part/toggle_bus_status_off" );
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_STATUS_ON = new ResourceLocation( AppEng.MOD_ID, "part/toggle_bus_status_on" );
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_STATUS_HAS_CHANNEL = new ResourceLocation( AppEng.MOD_ID, "part/toggle_bus_status_has_channel" );
|
||||
public static final IPartModel MODELS_OFF = new PartModel(MODEL_BASE, MODEL_STATUS_OFF);
|
||||
public static final IPartModel MODELS_ON = new PartModel(MODEL_BASE, MODEL_STATUS_ON);
|
||||
public static final IPartModel MODELS_HAS_CHANNEL = new PartModel(MODEL_BASE, MODEL_STATUS_HAS_CHANNEL);
|
||||
|
||||
public static final IPartModel MODELS_OFF = new PartModel( MODEL_BASE, MODEL_STATUS_OFF );
|
||||
public static final IPartModel MODELS_ON = new PartModel( MODEL_BASE, MODEL_STATUS_ON );
|
||||
public static final IPartModel MODELS_HAS_CHANNEL = new PartModel( MODEL_BASE, MODEL_STATUS_HAS_CHANNEL );
|
||||
private static final int REDSTONE_FLAG = 4;
|
||||
private final AENetworkProxy outerProxy = new AENetworkProxy(this, "outer", ItemStack.EMPTY, true);
|
||||
private IGridConnection connection;
|
||||
private boolean hasRedstone = false;
|
||||
|
||||
private static final int REDSTONE_FLAG = 4;
|
||||
private final AENetworkProxy outerProxy = new AENetworkProxy( this, "outer", ItemStack.EMPTY, true );
|
||||
private IGridConnection connection;
|
||||
private boolean hasRedstone = false;
|
||||
@Reflected
|
||||
public PartToggleBus(final ItemStack is) {
|
||||
super(is);
|
||||
|
||||
@Reflected
|
||||
public PartToggleBus( final ItemStack is )
|
||||
{
|
||||
super( is );
|
||||
this.getProxy().setIdlePowerUsage(0.0);
|
||||
this.getOuterProxy().setIdlePowerUsage(0.0);
|
||||
this.getProxy().setFlags();
|
||||
this.getOuterProxy().setFlags();
|
||||
}
|
||||
|
||||
this.getProxy().setIdlePowerUsage( 0.0 );
|
||||
this.getOuterProxy().setIdlePowerUsage( 0.0 );
|
||||
this.getProxy().setFlags();
|
||||
this.getOuterProxy().setFlags();
|
||||
}
|
||||
@Override
|
||||
protected int populateFlags(final int cf) {
|
||||
return cf | (this.getIntention() ? REDSTONE_FLAG : 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int populateFlags( final int cf )
|
||||
{
|
||||
return cf | ( this.getIntention() ? REDSTONE_FLAG : 0 );
|
||||
}
|
||||
public boolean hasRedstoneFlag() {
|
||||
return (this.getClientFlags() & REDSTONE_FLAG) == REDSTONE_FLAG;
|
||||
}
|
||||
|
||||
public boolean hasRedstoneFlag()
|
||||
{
|
||||
return ( this.getClientFlags() & REDSTONE_FLAG ) == REDSTONE_FLAG;
|
||||
}
|
||||
protected boolean getIntention() {
|
||||
return this.getHost().hasRedstone(this.getSide());
|
||||
}
|
||||
|
||||
protected boolean getIntention()
|
||||
{
|
||||
return this.getHost().hasRedstone( this.getSide() );
|
||||
}
|
||||
@Override
|
||||
public AECableType getCableConnectionType(final AEPartLocation dir) {
|
||||
return AECableType.GLASS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AECableType getCableConnectionType( final AEPartLocation dir )
|
||||
{
|
||||
return AECableType.GLASS;
|
||||
}
|
||||
@Override
|
||||
public void getBoxes(final IPartCollisionHelper bch) {
|
||||
bch.addBox(6, 6, 11, 10, 10, 16);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getBoxes( final IPartCollisionHelper bch )
|
||||
{
|
||||
bch.addBox( 6, 6, 11, 10, 10, 16 );
|
||||
}
|
||||
@Override
|
||||
public void onNeighborChanged(IBlockReader w, BlockPos pos, BlockPos neighbor) {
|
||||
final boolean oldHasRedstone = this.hasRedstone;
|
||||
this.hasRedstone = this.getHost().hasRedstone(this.getSide());
|
||||
|
||||
@Override
|
||||
public void onNeighborChanged( IBlockReader w, BlockPos pos, BlockPos neighbor )
|
||||
{
|
||||
final boolean oldHasRedstone = this.hasRedstone;
|
||||
this.hasRedstone = this.getHost().hasRedstone( this.getSide() );
|
||||
if (this.hasRedstone != oldHasRedstone) {
|
||||
this.updateInternalState();
|
||||
this.getHost().markForUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
if( this.hasRedstone != oldHasRedstone )
|
||||
{
|
||||
this.updateInternalState();
|
||||
this.getHost().markForUpdate();
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void readFromNBT(final CompoundNBT extra) {
|
||||
super.readFromNBT(extra);
|
||||
this.getOuterProxy().readFromNBT(extra);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT( final CompoundNBT extra )
|
||||
{
|
||||
super.readFromNBT( extra );
|
||||
this.getOuterProxy().readFromNBT( extra );
|
||||
}
|
||||
@Override
|
||||
public void writeToNBT(final CompoundNBT extra) {
|
||||
super.writeToNBT(extra);
|
||||
this.getOuterProxy().writeToNBT(extra);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT( final CompoundNBT extra )
|
||||
{
|
||||
super.writeToNBT( extra );
|
||||
this.getOuterProxy().writeToNBT( extra );
|
||||
}
|
||||
@Override
|
||||
public void removeFromWorld() {
|
||||
super.removeFromWorld();
|
||||
this.getOuterProxy().remove();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeFromWorld()
|
||||
{
|
||||
super.removeFromWorld();
|
||||
this.getOuterProxy().remove();
|
||||
}
|
||||
@Override
|
||||
public void addToWorld() {
|
||||
super.addToWorld();
|
||||
this.getOuterProxy().onReady();
|
||||
this.hasRedstone = this.getHost().hasRedstone(this.getSide());
|
||||
this.updateInternalState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addToWorld()
|
||||
{
|
||||
super.addToWorld();
|
||||
this.getOuterProxy().onReady();
|
||||
this.hasRedstone = this.getHost().hasRedstone( this.getSide() );
|
||||
this.updateInternalState();
|
||||
}
|
||||
@Override
|
||||
public void setPartHostInfo(final AEPartLocation side, final IPartHost host, final TileEntity tile) {
|
||||
super.setPartHostInfo(side, host, tile);
|
||||
this.outerProxy.setValidSides(EnumSet.of(side.getFacing()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPartHostInfo( final AEPartLocation side, final IPartHost host, final TileEntity tile )
|
||||
{
|
||||
super.setPartHostInfo( side, host, tile );
|
||||
this.outerProxy.setValidSides( EnumSet.of( side.getFacing() ) );
|
||||
}
|
||||
@Override
|
||||
public IGridNode getExternalFacingNode() {
|
||||
return this.getOuterProxy().getNode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IGridNode getExternalFacingNode()
|
||||
{
|
||||
return this.getOuterProxy().getNode();
|
||||
}
|
||||
@Override
|
||||
public float getCableConnectionLength(AECableType cable) {
|
||||
return 5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getCableConnectionLength( AECableType cable )
|
||||
{
|
||||
return 5;
|
||||
}
|
||||
@Override
|
||||
public void onPlacement(final PlayerEntity player, final Hand hand, final ItemStack held,
|
||||
final AEPartLocation side) {
|
||||
super.onPlacement(player, hand, held, side);
|
||||
this.getOuterProxy().setOwner(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlacement( final PlayerEntity player, final Hand hand, final ItemStack held, final AEPartLocation side )
|
||||
{
|
||||
super.onPlacement( player, hand, held, side );
|
||||
this.getOuterProxy().setOwner( player );
|
||||
}
|
||||
private void updateInternalState() {
|
||||
final boolean intention = this.getIntention();
|
||||
if (intention == (this.connection == null)) {
|
||||
if (this.getProxy().getNode() != null && this.getOuterProxy().getNode() != null) {
|
||||
if (intention) {
|
||||
try {
|
||||
this.connection = AEApi.instance().grid().createGridConnection(this.getProxy().getNode(),
|
||||
this.getOuterProxy().getNode());
|
||||
} catch (final FailedConnectionException e) {
|
||||
// :(
|
||||
AELog.debug(e);
|
||||
}
|
||||
} else {
|
||||
this.connection.destroy();
|
||||
this.connection = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateInternalState()
|
||||
{
|
||||
final boolean intention = this.getIntention();
|
||||
if( intention == ( this.connection == null ) )
|
||||
{
|
||||
if( this.getProxy().getNode() != null && this.getOuterProxy().getNode() != null )
|
||||
{
|
||||
if( intention )
|
||||
{
|
||||
try
|
||||
{
|
||||
this.connection = AEApi.instance().grid().createGridConnection( this.getProxy().getNode(), this.getOuterProxy().getNode() );
|
||||
}
|
||||
catch( final FailedConnectionException e )
|
||||
{
|
||||
// :(
|
||||
AELog.debug( e );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.connection.destroy();
|
||||
this.connection = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
AENetworkProxy getOuterProxy() {
|
||||
return this.outerProxy;
|
||||
}
|
||||
|
||||
AENetworkProxy getOuterProxy()
|
||||
{
|
||||
return this.outerProxy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPartModel getStaticModels()
|
||||
{
|
||||
if( this.hasRedstoneFlag() && this.isActive() && this.isPowered() )
|
||||
{
|
||||
return MODELS_HAS_CHANNEL;
|
||||
}
|
||||
else if( this.hasRedstoneFlag() && this.isPowered() )
|
||||
{
|
||||
return MODELS_ON;
|
||||
}
|
||||
else
|
||||
{
|
||||
return MODELS_OFF;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public IPartModel getStaticModels() {
|
||||
if (this.hasRedstoneFlag() && this.isActive() && this.isPowered()) {
|
||||
return MODELS_HAS_CHANNEL;
|
||||
} else if (this.hasRedstoneFlag() && this.isPowered()) {
|
||||
return MODELS_ON;
|
||||
} else {
|
||||
return MODELS_OFF;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user