Relocate Source to proper directory.
This commit is contained in:
@@ -0,0 +1,143 @@
|
||||
package appeng.tile.grindstone;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import appeng.api.implementations.tiles.ICrankable;
|
||||
import appeng.helpers.ICustomCollision;
|
||||
import appeng.tile.AEBaseTile;
|
||||
import appeng.tile.TileEvent;
|
||||
import appeng.tile.events.TileEventType;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public class TileCrank extends AEBaseTile implements ICustomCollision
|
||||
{
|
||||
|
||||
final int ticksPerRotation = 18;
|
||||
|
||||
// sided values..
|
||||
public float visibleRotation = 0;
|
||||
public int charge = 0;
|
||||
|
||||
public int hits = 0;
|
||||
public int rotation = 0;
|
||||
|
||||
@TileEvent(TileEventType.TICK)
|
||||
public void Tick_TileCrank()
|
||||
{
|
||||
if ( rotation > 0 )
|
||||
{
|
||||
visibleRotation -= 360 / (ticksPerRotation);
|
||||
charge++;
|
||||
if ( charge >= ticksPerRotation )
|
||||
{
|
||||
charge -= ticksPerRotation;
|
||||
ICrankable g = getGrinder();
|
||||
if ( g != null )
|
||||
g.applyTurn();
|
||||
}
|
||||
|
||||
rotation--;
|
||||
}
|
||||
}
|
||||
|
||||
@TileEvent(TileEventType.NETWORK_READ)
|
||||
public boolean readFromStream_TileCrank(ByteBuf data) throws java.io.IOException
|
||||
{
|
||||
rotation = data.readInt();
|
||||
return false;
|
||||
}
|
||||
|
||||
@TileEvent(TileEventType.NETWORK_WRITE)
|
||||
public void writeToStream_TileCrank(ByteBuf data) throws java.io.IOException
|
||||
{
|
||||
data.writeInt( rotation );
|
||||
}
|
||||
|
||||
public ICrankable getGrinder()
|
||||
{
|
||||
if ( Platform.isClient() )
|
||||
return null;
|
||||
|
||||
ForgeDirection grinder = getUp().getOpposite();
|
||||
TileEntity te = worldObj.getTileEntity( xCoord + grinder.offsetX, yCoord + grinder.offsetY, zCoord + grinder.offsetZ );
|
||||
if ( te instanceof ICrankable )
|
||||
return (ICrankable) te;
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOrientation(ForgeDirection inForward, ForgeDirection inUp)
|
||||
{
|
||||
super.setOrientation( inForward, inUp );
|
||||
getBlockType().onNeighborBlockChange( worldObj, xCoord, yCoord, zCoord, Platform.air );
|
||||
}
|
||||
|
||||
/**
|
||||
* return true if this should count towards stats.
|
||||
*/
|
||||
public boolean power()
|
||||
{
|
||||
if ( Platform.isClient() )
|
||||
return false;
|
||||
|
||||
if ( rotation < 3 )
|
||||
{
|
||||
ICrankable g = getGrinder();
|
||||
if ( g != null )
|
||||
{
|
||||
if ( g.canTurn() )
|
||||
{
|
||||
hits = 0;
|
||||
rotation += ticksPerRotation;
|
||||
this.markForUpdate();
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
hits++;
|
||||
if ( hits > 10 )
|
||||
{
|
||||
worldObj.func_147480_a( xCoord, yCoord, zCoord, false );
|
||||
// worldObj.destroyBlock( xCoord, yCoord, zCoord, false );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<AxisAlignedBB> getSelectedBoundingBoxesFromPool(World w, int x, int y, int z, Entity e, boolean isVisual)
|
||||
{
|
||||
double xOff = -0.15 * getUp().offsetX;
|
||||
double yOff = -0.15 * getUp().offsetY;
|
||||
double zOff = -0.15 * getUp().offsetZ;
|
||||
return Arrays
|
||||
.asList( new AxisAlignedBB[] { AxisAlignedBB.getBoundingBox( xOff + 0.15, yOff + 0.15, zOff + 0.15, xOff + 0.85, yOff + 0.85, zOff + 0.85 ) } );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCollidingBlockToList(World w, int x, int y, int z, AxisAlignedBB bb, List out, Entity e)
|
||||
{
|
||||
double xOff = -0.15 * getUp().offsetX;
|
||||
double yOff = -0.15 * getUp().offsetY;
|
||||
double zOff = -0.15 * getUp().offsetZ;
|
||||
out.add( AxisAlignedBB.getBoundingBox( xOff + (double) 0.15, yOff + (double) 0.15, zOff + (double) 0.15,// ahh
|
||||
xOff + (double) 0.85, yOff + (double) 0.85, zOff + (double) 0.85 ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean requiresTESR()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,164 @@
|
||||
package appeng.tile.grindstone;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.features.IGrinderEntry;
|
||||
import appeng.api.implementations.tiles.ICrankable;
|
||||
import appeng.api.util.WorldCoord;
|
||||
import appeng.tile.AEBaseInvTile;
|
||||
import appeng.tile.inventory.AppEngInternalInventory;
|
||||
import appeng.tile.inventory.InvOperation;
|
||||
import appeng.util.InventoryAdaptor;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.inv.WrapperInventoryRange;
|
||||
|
||||
public class TileGrinder extends AEBaseInvTile implements ICrankable
|
||||
{
|
||||
|
||||
int points;
|
||||
|
||||
final int inputs[] = new int[] { 0, 1, 2 };
|
||||
final int sides[] = new int[] { 0, 1, 2, 3, 4, 5 };
|
||||
AppEngInternalInventory inv = new AppEngInternalInventory( this, 7 );
|
||||
|
||||
@Override
|
||||
public void setOrientation(ForgeDirection inForward, ForgeDirection inUp)
|
||||
{
|
||||
super.setOrientation( inForward, inUp );
|
||||
getBlockType().onNeighborBlockChange( worldObj, xCoord, yCoord, zCoord, Platform.air );
|
||||
}
|
||||
|
||||
private void addItem(InventoryAdaptor sia, ItemStack output)
|
||||
{
|
||||
if ( output == null )
|
||||
return;
|
||||
|
||||
ItemStack notAdded = sia.addItems( output );
|
||||
if ( notAdded != null )
|
||||
{
|
||||
WorldCoord wc = new WorldCoord( xCoord, yCoord, zCoord );
|
||||
|
||||
wc.add( getForward(), 1 );
|
||||
|
||||
List<ItemStack> out = new ArrayList();
|
||||
out.add( notAdded );
|
||||
|
||||
Platform.spawnDrops( worldObj, wc.x, wc.y, wc.z, out );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInsertItem(int i, ItemStack itemstack, int j)
|
||||
{
|
||||
if ( AEApi.instance().registries().grinder().getRecipeForInput( itemstack ) == null )
|
||||
return false;
|
||||
|
||||
return i >= 0 && i <= 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canExtractItem(int i, ItemStack itemstack, int j)
|
||||
{
|
||||
return i >= 3 && i <= 5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventory getInternalInventory()
|
||||
{
|
||||
return inv;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getAccessibleSlotsBySide(ForgeDirection side)
|
||||
{
|
||||
return sides;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChangeInventory(IInventory inv, int slot, InvOperation mc, ItemStack removed, ItemStack added)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canTurn()
|
||||
{
|
||||
if ( Platform.isClient() )
|
||||
return false;
|
||||
|
||||
if ( null == this.getStackInSlot( 6 ) ) // Add if there isn't one...
|
||||
{
|
||||
IInventory src = new WrapperInventoryRange( this, inputs, true );
|
||||
for (int x = 0; x < src.getSizeInventory(); x++)
|
||||
{
|
||||
ItemStack item = src.getStackInSlot( x );
|
||||
if ( item == null )
|
||||
continue;
|
||||
|
||||
IGrinderEntry r = AEApi.instance().registries().grinder().getRecipeForInput( item );
|
||||
if ( r != null )
|
||||
{
|
||||
if ( item.stackSize >= r.getInput().stackSize )
|
||||
{
|
||||
item.stackSize -= r.getInput().stackSize;
|
||||
ItemStack ais = item.copy();
|
||||
ais.stackSize = r.getInput().stackSize;
|
||||
|
||||
if ( item.stackSize <= 0 )
|
||||
item = null;
|
||||
|
||||
src.setInventorySlotContents( x, item );
|
||||
this.setInventorySlotContents( 6, ais );
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyTurn()
|
||||
{
|
||||
if ( Platform.isClient() )
|
||||
return;
|
||||
|
||||
points++;
|
||||
|
||||
ItemStack processing = this.getStackInSlot( 6 );
|
||||
IGrinderEntry r = AEApi.instance().registries().grinder().getRecipeForInput( processing );
|
||||
if ( r != null )
|
||||
{
|
||||
if ( r.getEnergyCost() > points )
|
||||
return;
|
||||
|
||||
points = 0;
|
||||
InventoryAdaptor sia = InventoryAdaptor.getAdaptor( new WrapperInventoryRange( this, 3, 3, true ), ForgeDirection.EAST );
|
||||
|
||||
addItem( sia, r.getOutput() );
|
||||
|
||||
float chance = (Platform.getRandomInt() % 2000) / 2000.0f;
|
||||
if ( chance <= r.getOptionalChance() )
|
||||
addItem( sia, r.getOptionalOutput() );
|
||||
|
||||
chance = (Platform.getRandomInt() % 2000) / 2000.0f;
|
||||
if ( chance <= r.getSecondOptionalChance() )
|
||||
addItem( sia, r.getSecondOptionalOutput() );
|
||||
|
||||
this.setInventorySlotContents( 6, null );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canCrankAttach(ForgeDirection directionToCrank)
|
||||
{
|
||||
return getUp().equals( directionToCrank );
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user