Add an atomic reconstructor invoke method to the API

This commit is contained in:
Ellpeck 2017-02-20 13:19:19 +01:00
parent 1487f141bb
commit f01be2a8ad
5 changed files with 45 additions and 25 deletions

View file

@ -10,6 +10,7 @@
package de.ellpeck.actuallyadditions.api.internal; package de.ellpeck.actuallyadditions.api.internal;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
/** /**
@ -18,6 +19,8 @@ import net.minecraft.world.World;
*/ */
public interface IEnergyTile{ public interface IEnergyTile{
BlockPos getPosition();
int getX(); int getX();
int getY(); int getY();

View file

@ -42,6 +42,8 @@ public interface IMethodHandler{
boolean invokeConversionLens(IBlockState hitState, BlockPos hitBlock, IAtomicReconstructor tile); boolean invokeConversionLens(IBlockState hitState, BlockPos hitBlock, IAtomicReconstructor tile);
boolean invokeReconstructor(IAtomicReconstructor tile);
boolean addCrusherRecipes(List<ItemStack> inputs, List<ItemStack> outputOnes, int outputOneAmounts, List<ItemStack> outputTwos, int outputTwoAmounts, int outputTwoChance); boolean addCrusherRecipes(List<ItemStack> inputs, List<ItemStack> outputOnes, int outputOneAmounts, List<ItemStack> outputTwos, int outputTwoAmounts, int outputTwoChance);
IBookletPage generateTextPage(int id); IBookletPage generateTextPage(int id);

View file

@ -16,6 +16,7 @@ import de.ellpeck.actuallyadditions.api.booklet.IBookletEntry;
import de.ellpeck.actuallyadditions.api.booklet.IBookletPage; import de.ellpeck.actuallyadditions.api.booklet.IBookletPage;
import de.ellpeck.actuallyadditions.api.internal.IAtomicReconstructor; import de.ellpeck.actuallyadditions.api.internal.IAtomicReconstructor;
import de.ellpeck.actuallyadditions.api.internal.IMethodHandler; import de.ellpeck.actuallyadditions.api.internal.IMethodHandler;
import de.ellpeck.actuallyadditions.api.lens.Lens;
import de.ellpeck.actuallyadditions.api.recipe.CoffeeIngredient; import de.ellpeck.actuallyadditions.api.recipe.CoffeeIngredient;
import de.ellpeck.actuallyadditions.api.recipe.LensConversionRecipe; import de.ellpeck.actuallyadditions.api.recipe.LensConversionRecipe;
import de.ellpeck.actuallyadditions.mod.booklet.chapter.BookletChapter; import de.ellpeck.actuallyadditions.mod.booklet.chapter.BookletChapter;
@ -27,7 +28,9 @@ import de.ellpeck.actuallyadditions.mod.booklet.page.PageTextOnly;
import de.ellpeck.actuallyadditions.mod.config.values.ConfigStringListValues; import de.ellpeck.actuallyadditions.mod.config.values.ConfigStringListValues;
import de.ellpeck.actuallyadditions.mod.items.lens.LensRecipeHandler; import de.ellpeck.actuallyadditions.mod.items.lens.LensRecipeHandler;
import de.ellpeck.actuallyadditions.mod.recipe.CrusherRecipeRegistry; import de.ellpeck.actuallyadditions.mod.recipe.CrusherRecipeRegistry;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityAtomicReconstructor;
import de.ellpeck.actuallyadditions.mod.util.StackUtil; import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import de.ellpeck.actuallyadditions.mod.util.WorldUtil;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.item.EntityItem;
@ -228,6 +231,31 @@ public class MethodHandler implements IMethodHandler{
return false; return false;
} }
@Override
public boolean invokeReconstructor(IAtomicReconstructor tile){
if(tile.getEnergy() >= TileEntityAtomicReconstructor.ENERGY_USE){
IBlockState state = tile.getWorldObject().getBlockState(tile.getPosition());
EnumFacing sideToManipulate = WorldUtil.getDirectionByPistonRotation(state.getBlock().getMetaFromState(state));
Lens currentLens = tile.getLens();
if(currentLens.canInvoke(tile, sideToManipulate, TileEntityAtomicReconstructor.ENERGY_USE)){
tile.extractEnergy(TileEntityAtomicReconstructor.ENERGY_USE);
int distance = currentLens.getDistance();
for(int i = 0; i < distance; i++){
BlockPos hitBlock = tile.getPosition().offset(sideToManipulate, i+1);
if(currentLens.invoke(tile.getWorldObject().getBlockState(hitBlock), hitBlock, tile) || i >= distance-1){
TileEntityAtomicReconstructor.shootLaser(tile.getWorldObject(), tile.getX(), tile.getY(), tile.getZ(), hitBlock.getX(), hitBlock.getY(), hitBlock.getZ(), currentLens);
break;
}
}
return true;
}
}
return false;
}
@Override @Override
public boolean addCrusherRecipes(List<ItemStack> inputs, List<ItemStack> outputOnes, int outputOneAmounts, List<ItemStack> outputTwos, int outputTwoAmounts, int outputTwoChance){ public boolean addCrusherRecipes(List<ItemStack> inputs, List<ItemStack> outputOnes, int outputOneAmounts, List<ItemStack> outputTwos, int outputTwoAmounts, int outputTwoChance){
boolean hasWorkedOnce = false; boolean hasWorkedOnce = false;

View file

@ -77,7 +77,7 @@ public class TileEntityAtomicReconstructor extends TileEntityInventoryBase imple
if(this.currentTime > 0){ if(this.currentTime > 0){
this.currentTime--; this.currentTime--;
if(this.currentTime <= 0){ if(this.currentTime <= 0){
this.doWork(); ActuallyAdditionsAPI.methodHandler.invokeReconstructor(this);
} }
} }
else{ else{
@ -92,29 +92,6 @@ public class TileEntityAtomicReconstructor extends TileEntityInventoryBase imple
} }
private void doWork(){
if(this.storage.getEnergyStored() >= ENERGY_USE){
IBlockState state = this.world.getBlockState(this.pos);
EnumFacing sideToManipulate = WorldUtil.getDirectionByPistonRotation(state.getBlock().getMetaFromState(state));
//The Lens the Reconstructor currently has installed
Lens currentLens = this.getLens();
if(currentLens.canInvoke(this, sideToManipulate, ENERGY_USE)){
//Extract energy for shooting the laser itself too!
this.storage.extractEnergyInternal(ENERGY_USE, false);
int distance = currentLens.getDistance();
for(int i = 0; i < distance; i++){
BlockPos hitBlock = this.pos.offset(sideToManipulate, i+1);
if(currentLens.invoke(this.world.getBlockState(hitBlock), hitBlock, this) || i >= distance-1){
shootLaser(this.world, this.getX(), this.getY(), this.getZ(), hitBlock.getX(), hitBlock.getY(), hitBlock.getZ(), currentLens);
break;
}
}
}
}
}
@Override @Override
public Lens getLens(){ public Lens getLens(){
if(StackUtil.isValid(this.slots.getStackInSlot(0))){ if(StackUtil.isValid(this.slots.getStackInSlot(0))){
@ -131,6 +108,11 @@ public class TileEntityAtomicReconstructor extends TileEntityInventoryBase imple
return WorldUtil.getDirectionByPistonRotation(state.getBlock().getMetaFromState(state)); return WorldUtil.getDirectionByPistonRotation(state.getBlock().getMetaFromState(state));
} }
@Override
public BlockPos getPosition(){
return this.pos;
}
@Override @Override
public int getX(){ public int getX(){
return this.getPos().getX(); return this.getPos().getX();
@ -188,7 +170,7 @@ public class TileEntityAtomicReconstructor extends TileEntityInventoryBase imple
@Override @Override
public void activateOnPulse(){ public void activateOnPulse(){
this.doWork(); ActuallyAdditionsAPI.methodHandler.invokeReconstructor(this);
} }
@Override @Override

View file

@ -154,6 +154,11 @@ public class TileEntityFarmer extends TileEntityInventoryBase implements IFarmer
return WorldUtil.addToInventory(this.slots, 6, 12, stacks, actuallyDo); return WorldUtil.addToInventory(this.slots, 6, 12, stacks, actuallyDo);
} }
@Override
public BlockPos getPosition(){
return this.pos;
}
@Override @Override
public int getX(){ public int getX(){
return this.pos.getX(); return this.pos.getX();