pick 97420a31d The big reformat of 2020

This commit is contained in:
yueh
2020-06-16 21:41:28 +02:00
parent 5304b3febe
commit 5225ea426b
2252 changed files with 95466 additions and 118582 deletions
@@ -18,7 +18,6 @@
package appeng.container.slot;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -56,277 +55,239 @@ import appeng.util.inv.WrapperCursorItemHandler;
import appeng.util.inv.WrapperInvItemHandler;
import appeng.util.item.AEItemStack;
public class SlotCraftingTerm extends AppEngCraftingSlot {
public class SlotCraftingTerm extends AppEngCraftingSlot
{
private final IItemHandler craftInv;
private final IItemHandler pattern;
private final IItemHandler craftInv;
private final IItemHandler pattern;
private final IActionSource mySrc;
private final IEnergySource energySrc;
private final IStorageMonitorable storage;
private final IContainerCraftingPacket container;
private final IActionSource mySrc;
private final IEnergySource energySrc;
private final IStorageMonitorable storage;
private final IContainerCraftingPacket container;
public SlotCraftingTerm(final PlayerEntity player, final IActionSource mySrc, final IEnergySource energySrc,
final IStorageMonitorable storage, final IItemHandler cMatrix, final IItemHandler secondMatrix,
final IItemHandler output, final int x, final int y, final IContainerCraftingPacket ccp) {
super(player, cMatrix, output, 0, x, y);
this.energySrc = energySrc;
this.storage = storage;
this.mySrc = mySrc;
this.pattern = cMatrix;
this.craftInv = secondMatrix;
this.container = ccp;
}
public SlotCraftingTerm( final PlayerEntity player, final IActionSource mySrc, final IEnergySource energySrc, final IStorageMonitorable storage, final IItemHandler cMatrix, final IItemHandler secondMatrix, final IItemHandler output, final int x, final int y, final IContainerCraftingPacket ccp )
{
super( player, cMatrix, output, 0, x, y );
this.energySrc = energySrc;
this.storage = storage;
this.mySrc = mySrc;
this.pattern = cMatrix;
this.craftInv = secondMatrix;
this.container = ccp;
}
public IItemHandler getCraftingMatrix() {
return this.craftInv;
}
public IItemHandler getCraftingMatrix()
{
return this.craftInv;
}
@Override
public boolean canTakeStack(final PlayerEntity par1PlayerEntity) {
return false;
}
@Override
public boolean canTakeStack( final PlayerEntity par1PlayerEntity )
{
return false;
}
@Override
public ItemStack onTake(final PlayerEntity p, final ItemStack is) {
return is;
}
@Override
public ItemStack onTake( final PlayerEntity p, final ItemStack is )
{
return is;
}
public void doClick(final InventoryAction action, final PlayerEntity who) {
if (this.getStack().isEmpty()) {
return;
}
if (Platform.isClient()) {
return;
}
public void doClick( final InventoryAction action, final PlayerEntity who )
{
if( this.getStack().isEmpty() )
{
return;
}
if( Platform.isClient() )
{
return;
}
final IMEMonitor<IAEItemStack> inv = this.storage
.getInventory(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class));
final int howManyPerCraft = this.getStack().getCount();
int maxTimesToCraft = 0;
final IMEMonitor<IAEItemStack> inv = this.storage.getInventory( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) );
final int howManyPerCraft = this.getStack().getCount();
int maxTimesToCraft = 0;
InventoryAdaptor ia = null;
if (action == InventoryAction.CRAFT_SHIFT) // craft into player inventory...
{
ia = InventoryAdaptor.getAdaptor(who);
maxTimesToCraft = (int) Math.floor((double) this.getStack().getMaxStackSize() / (double) howManyPerCraft);
} else if (action == InventoryAction.CRAFT_STACK) // craft into hand, full stack
{
ia = new AdaptorItemHandler(new WrapperCursorItemHandler(who.inventory));
maxTimesToCraft = (int) Math.floor((double) this.getStack().getMaxStackSize() / (double) howManyPerCraft);
} else
// pick up what was crafted...
{
ia = new AdaptorItemHandler(new WrapperCursorItemHandler(who.inventory));
maxTimesToCraft = 1;
}
InventoryAdaptor ia = null;
if( action == InventoryAction.CRAFT_SHIFT ) // craft into player inventory...
{
ia = InventoryAdaptor.getAdaptor( who );
maxTimesToCraft = (int) Math.floor( (double) this.getStack().getMaxStackSize() / (double) howManyPerCraft );
}
else if( action == InventoryAction.CRAFT_STACK ) // craft into hand, full stack
{
ia = new AdaptorItemHandler( new WrapperCursorItemHandler( who.inventory ) );
maxTimesToCraft = (int) Math.floor( (double) this.getStack().getMaxStackSize() / (double) howManyPerCraft );
}
else
// pick up what was crafted...
{
ia = new AdaptorItemHandler( new WrapperCursorItemHandler( who.inventory ) );
maxTimesToCraft = 1;
}
maxTimesToCraft = this.capCraftingAttempts(maxTimesToCraft);
maxTimesToCraft = this.capCraftingAttempts( maxTimesToCraft );
if (ia == null) {
return;
}
if( ia == null )
{
return;
}
final ItemStack rs = this.getStack().copy();
if (rs.isEmpty()) {
return;
}
final ItemStack rs = this.getStack().copy();
if( rs.isEmpty() )
{
return;
}
for (int x = 0; x < maxTimesToCraft; x++) {
if (ia.simulateAdd(rs).isEmpty()) {
final IItemList<IAEItemStack> all = inv.getStorageList();
final ItemStack extra = ia.addItems(this.craftItem(who, rs, inv, all));
if (!extra.isEmpty()) {
final List<ItemStack> drops = new ArrayList<>();
drops.add(extra);
Platform.spawnDrops(who.world,
new BlockPos((int) who.getPosX(), (int) who.getPosY(), (int) who.getPosZ()), drops);
return;
}
}
}
}
for( int x = 0; x < maxTimesToCraft; x++ )
{
if( ia.simulateAdd( rs ).isEmpty() )
{
final IItemList<IAEItemStack> all = inv.getStorageList();
final ItemStack extra = ia.addItems( this.craftItem( who, rs, inv, all ) );
if( !extra.isEmpty() )
{
final List<ItemStack> drops = new ArrayList<>();
drops.add( extra );
Platform.spawnDrops( who.world, new BlockPos( (int) who.getPosX(), (int) who.getPosY(), (int) who.getPosZ() ), drops );
return;
}
}
}
}
// TODO: This is really hacky and NEEDS to be solved with a full container/gui
// refactoring.
protected IRecipe<CraftingInventory> findRecipe(CraftingInventory ic, World world) {
if (this.container instanceof ContainerCraftingTerm) {
final ContainerCraftingTerm containerTerminal = (ContainerCraftingTerm) this.container;
final IRecipe<CraftingInventory> recipe = containerTerminal.getCurrentRecipe();
// TODO: This is really hacky and NEEDS to be solved with a full container/gui refactoring.
protected IRecipe<CraftingInventory> findRecipe( CraftingInventory ic, World world )
{
if( this.container instanceof ContainerCraftingTerm )
{
final ContainerCraftingTerm containerTerminal = (ContainerCraftingTerm) this.container;
final IRecipe<CraftingInventory> recipe = containerTerminal.getCurrentRecipe();
if (recipe != null && recipe.matches(ic, world)) {
return containerTerminal.getCurrentRecipe();
}
}
if( recipe != null && recipe.matches( ic, world ) )
{
return containerTerminal.getCurrentRecipe();
}
}
return world.getRecipeManager().getRecipe(IRecipeType.CRAFTING, ic, world).orElse(null);
}
return world.getRecipeManager().getRecipe( IRecipeType.CRAFTING, ic, world ).orElse(null);
}
// TODO: This is really hacky and NEEDS to be solved with a full container/gui
// refactoring.
@Override
protected NonNullList<ItemStack> getRemainingItems(CraftingInventory ic, World world) {
if (this.container instanceof ContainerCraftingTerm) {
final ContainerCraftingTerm containerTerminal = (ContainerCraftingTerm) this.container;
final IRecipe<CraftingInventory> recipe = containerTerminal.getCurrentRecipe();
// TODO: This is really hacky and NEEDS to be solved with a full container/gui refactoring.
@Override
protected NonNullList<ItemStack> getRemainingItems( CraftingInventory ic, World world )
{
if( this.container instanceof ContainerCraftingTerm )
{
final ContainerCraftingTerm containerTerminal = (ContainerCraftingTerm) this.container;
final IRecipe<CraftingInventory> recipe = containerTerminal.getCurrentRecipe();
if (recipe != null && recipe.matches(ic, world)) {
return containerTerminal.getCurrentRecipe().getRemainingItems(ic);
}
}
if( recipe != null && recipe.matches( ic, world ) )
{
return containerTerminal.getCurrentRecipe().getRemainingItems( ic );
}
}
return world.getRecipeManager().getRecipe(IRecipeType.CRAFTING, ic, world).map(r -> r.getRemainingItems(ic))
.orElse(NonNullList.create());
}
return world.getRecipeManager().getRecipe(IRecipeType.CRAFTING, ic, world)
.map(r -> r.getRemainingItems(ic))
.orElse(NonNullList.create());
}
private int capCraftingAttempts(final int maxTimesToCraft) {
return maxTimesToCraft;
}
private int capCraftingAttempts( final int maxTimesToCraft )
{
return maxTimesToCraft;
}
private ItemStack craftItem(final PlayerEntity p, final ItemStack request, final IMEMonitor<IAEItemStack> inv,
final IItemList all) {
// update crafting matrix...
ItemStack is = this.getStack();
private ItemStack craftItem( final PlayerEntity p, final ItemStack request, final IMEMonitor<IAEItemStack> inv, final IItemList all )
{
// update crafting matrix...
ItemStack is = this.getStack();
if (!is.isEmpty() && ItemStack.areItemsEqual(request, is)) {
final ItemStack[] set = new ItemStack[this.getPattern().getSlots()];
// Safeguard for empty slots in the inventory for now
Arrays.fill(set, ItemStack.EMPTY);
if( !is.isEmpty() && ItemStack.areItemsEqual( request, is ) )
{
final ItemStack[] set = new ItemStack[this.getPattern().getSlots()];
// Safeguard for empty slots in the inventory for now
Arrays.fill( set, ItemStack.EMPTY );
// add one of each item to the items on the board...
if (Platform.isServer()) {
final CraftingInventory ic = new CraftingInventory(new ContainerNull(), 3, 3);
for (int x = 0; x < 9; x++) {
ic.setInventorySlotContents(x, this.getPattern().getStackInSlot(x));
}
// add one of each item to the items on the board...
if( Platform.isServer() )
{
final CraftingInventory ic = new CraftingInventory( new ContainerNull(), 3, 3 );
for( int x = 0; x < 9; x++ )
{
ic.setInventorySlotContents( x, this.getPattern().getStackInSlot( x ) );
}
final IRecipe<CraftingInventory> r = this.findRecipe(ic, p.world);
final IRecipe<CraftingInventory> r = this.findRecipe( ic, p.world );
if (r == null) {
final Item target = request.getItem();
if (target.isDamageable() && target.isRepairable(request)) {
boolean isBad = false;
for (int x = 0; x < ic.getSizeInventory(); x++) {
final ItemStack pis = ic.getStackInSlot(x);
if (pis.isEmpty()) {
continue;
}
if (pis.getItem() != target) {
isBad = true;
}
}
if (!isBad) {
super.onTake(p, is);
// actually necessary to cleanup this case...
p.openContainer.onCraftMatrixChanged(new WrapperInvItemHandler(this.craftInv));
return request;
}
}
return ItemStack.EMPTY;
}
if( r == null )
{
final Item target = request.getItem();
if( target.isDamageable() && target.isRepairable(request) )
{
boolean isBad = false;
for( int x = 0; x < ic.getSizeInventory(); x++ )
{
final ItemStack pis = ic.getStackInSlot( x );
if( pis.isEmpty() )
{
continue;
}
if( pis.getItem() != target )
{
isBad = true;
}
}
if( !isBad )
{
super.onTake( p, is );
// actually necessary to cleanup this case...
p.openContainer.onCraftMatrixChanged( new WrapperInvItemHandler( this.craftInv ) );
return request;
}
}
return ItemStack.EMPTY;
}
is = r.getCraftingResult(ic);
is = r.getCraftingResult( ic );
if (inv != null) {
for (int x = 0; x < this.getPattern().getSlots(); x++) {
if (!this.getPattern().getStackInSlot(x).isEmpty()) {
set[x] = Platform.extractItemsByRecipe(this.energySrc, this.mySrc, inv, p.world, r, is, ic,
this.getPattern().getStackInSlot(x), x, all, Actionable.MODULATE,
ItemViewCell.createFilter(this.container.getViewCells()));
ic.setInventorySlotContents(x, set[x]);
}
}
}
}
if( inv != null )
{
for( int x = 0; x < this.getPattern().getSlots(); x++ )
{
if( !this.getPattern().getStackInSlot( x ).isEmpty() )
{
set[x] = Platform.extractItemsByRecipe( this.energySrc, this.mySrc, inv, p.world, r, is, ic, this.getPattern().getStackInSlot( x ),
x, all, Actionable.MODULATE, ItemViewCell.createFilter( this.container.getViewCells() ) );
ic.setInventorySlotContents( x, set[x] );
}
}
}
}
if (this.preCraft(p, inv, set, is)) {
this.makeItem(p, is);
if( this.preCraft( p, inv, set, is ) )
{
this.makeItem( p, is );
this.postCraft(p, inv, set, is);
}
this.postCraft( p, inv, set, is );
}
p.openContainer.onCraftMatrixChanged(new WrapperInvItemHandler(this.craftInv));
p.openContainer.onCraftMatrixChanged( new WrapperInvItemHandler( this.craftInv ) );
return is;
}
return is;
}
return ItemStack.EMPTY;
}
return ItemStack.EMPTY;
}
private boolean preCraft(final PlayerEntity p, final IMEMonitor<IAEItemStack> inv, final ItemStack[] set,
final ItemStack result) {
return true;
}
private boolean preCraft( final PlayerEntity p, final IMEMonitor<IAEItemStack> inv, final ItemStack[] set, final ItemStack result )
{
return true;
}
private void makeItem(final PlayerEntity p, final ItemStack is) {
super.onTake(p, is);
}
private void makeItem( final PlayerEntity p, final ItemStack is )
{
super.onTake( p, is );
}
private void postCraft(final PlayerEntity p, final IMEMonitor<IAEItemStack> inv, final ItemStack[] set,
final ItemStack result) {
final List<ItemStack> drops = new ArrayList<>();
private void postCraft( final PlayerEntity p, final IMEMonitor<IAEItemStack> inv, final ItemStack[] set, final ItemStack result )
{
final List<ItemStack> drops = new ArrayList<>();
// add one of each item to the items on the board...
if (Platform.isServer()) {
// set new items onto the crafting table...
for (int x = 0; x < this.craftInv.getSlots(); x++) {
if (this.craftInv.getStackInSlot(x).isEmpty()) {
ItemHandlerUtil.setStackInSlot(this.craftInv, x, set[x]);
} else if (!set[x].isEmpty()) {
// eek! put it back!
final IAEItemStack fail = inv.injectItems(AEItemStack.fromItemStack(set[x]), Actionable.MODULATE,
this.mySrc);
if (fail != null) {
drops.add(fail.createItemStack());
}
}
}
}
// add one of each item to the items on the board...
if( Platform.isServer() )
{
// set new items onto the crafting table...
for( int x = 0; x < this.craftInv.getSlots(); x++ )
{
if( this.craftInv.getStackInSlot( x ).isEmpty() )
{
ItemHandlerUtil.setStackInSlot( this.craftInv, x, set[x] );
}
else if( !set[x].isEmpty() )
{
// eek! put it back!
final IAEItemStack fail = inv.injectItems( AEItemStack.fromItemStack( set[x] ), Actionable.MODULATE, this.mySrc );
if( fail != null )
{
drops.add( fail.createItemStack() );
}
}
}
}
if (drops.size() > 0) {
Platform.spawnDrops(p.world, new BlockPos((int) p.getPosX(), (int) p.getPosY(), (int) p.getPosZ()), drops);
}
}
if( drops.size() > 0 )
{
Platform.spawnDrops( p.world, new BlockPos( (int) p.getPosX(), (int) p.getPosY(), (int) p.getPosZ() ), drops );
}
}
IItemHandler getPattern()
{
return this.pattern;
}
IItemHandler getPattern() {
return this.pattern;
}
}