Added the possibility for different types of lenses to be conversion lenses

This commit is contained in:
Ellpeck 2016-05-14 14:14:06 +02:00
parent e0cf180358
commit 64966ad66e
11 changed files with 168 additions and 122 deletions

View file

@ -13,8 +13,8 @@ package de.ellpeck.actuallyadditions.api;
import de.ellpeck.actuallyadditions.api.booklet.BookletPage;
import de.ellpeck.actuallyadditions.api.booklet.IBookletEntry;
import de.ellpeck.actuallyadditions.api.internal.IMethodHandler;
import de.ellpeck.actuallyadditions.api.lens.LensConversion;
import de.ellpeck.actuallyadditions.api.recipe.*;
import de.ellpeck.actuallyadditions.api.recipe.CoffeeIngredient;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
@ -154,9 +154,15 @@ public class ActuallyAdditionsAPI{
* @param input The input as an ItemStack
* @param output The output as an ItemStack
* @param energyUse The amount of RF used per conversion
* @param type The type of lens used for the conversion. To use the default type, use method below.
* Note how this always has to be the same instance of the lens type that the item also has for it to work!
*/
public static void addReconstructorLensConversionRecipe(ItemStack input, ItemStack output, int energyUse, LensConversion type){
reconstructorLensConversionRecipes.add(new LensConversionRecipe(input, output, energyUse, type));
}
public static void addReconstructorLensConversionRecipe(ItemStack input, ItemStack output, int energyUse){
reconstructorLensConversionRecipes.add(new LensConversionRecipe(input, output, energyUse));
addReconstructorLensConversionRecipe(input, output, energyUse, LensConversion.DEFAULT_CONVERSION);
}
/**
@ -165,9 +171,15 @@ public class ActuallyAdditionsAPI{
* @param input The input's OreDictionary name
* @param output The output's OreDictionary name
* @param energyUse The amount of RF used per conversion
* @param type The type of lens used for the conversion. To use the default type, use method below
* Note how this always has to be the same instance of the lens type that the item also has for it to work!
*/
public static void addReconstructorLensConversionRecipe(String input, String output, int energyUse, LensConversion type){
reconstructorLensConversionRecipes.add(new LensConversionRecipe(input, output, energyUse, type));
}
public static void addReconstructorLensConversionRecipe(String input, String output, int energyUse){
reconstructorLensConversionRecipes.add(new LensConversionRecipe(input, output, energyUse));
addReconstructorLensConversionRecipe(input, output, energyUse, LensConversion.DEFAULT_CONVERSION);
}
/**

View file

@ -10,6 +10,7 @@
package de.ellpeck.actuallyadditions.api.internal;
import de.ellpeck.actuallyadditions.api.lens.Lens;
import net.minecraft.world.World;
/**
@ -49,4 +50,6 @@ public interface IAtomicReconstructor{
* Gets the amount of energy the Reconstructor has stored in its RF storage
*/
int getEnergy();
Lens getLens();
}

View file

@ -1,9 +1,10 @@
package de.ellpeck.actuallyadditions.api.internal;
import de.ellpeck.actuallyadditions.api.recipe.CoffeeIngredient;
import net.minecraft.block.state.IBlockState;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.math.BlockPos;
/**
* This is the internal method handler.
@ -21,4 +22,6 @@ public interface IMethodHandler{
void addEffectToStack(ItemStack stack, PotionEffect effect);
PotionEffect[] getEffectsFromStack(ItemStack stack);
boolean invokeConversionLens(IBlockState hitState, BlockPos hitBlock, IAtomicReconstructor tile);
}

View file

@ -17,7 +17,6 @@ import net.minecraft.util.math.BlockPos;
/**
* This is the base class for a Reconstructor Lens Type (NOT THE ITEM!)
* You need to call register() to register the type
*/
public abstract class Lens{

View file

@ -0,0 +1,46 @@
/*
* This file ("LensNone.java") is part of the Actually Additions Mod for Minecraft.
* It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at
* http://ellpeck.de/actaddlicense/
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
* © 2016 Ellpeck
*/
package de.ellpeck.actuallyadditions.api.lens;
import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI;
import de.ellpeck.actuallyadditions.api.internal.IAtomicReconstructor;
import net.minecraft.block.state.IBlockState;
import net.minecraft.util.math.BlockPos;
/**
* This is the base class for a Reconstructor Lens Type that converts two items
* via the ActuallyAdditionsAPI.reconstructorLensConversionRecipes list.
*
* If you want to make a new type of conversion, just use your type in the recipe
* If you want to use the default type of conversion, use DEFAULT_CONVERSION below.
*/
public class LensConversion extends Lens{
public static final LensConversion DEFAULT_CONVERSION = new LensConversion();
@SuppressWarnings("unchecked")
@Override
public boolean invoke(IBlockState hitState, BlockPos hitBlock, IAtomicReconstructor tile){
return ActuallyAdditionsAPI.methodHandler.invokeConversionLens(hitState, hitBlock, tile);
}
@Override
public float[] getColor(){
return new float[]{27F/255F, 109F/255F, 1F};
}
@Override
public int getDistance(){
return 10;
}
}

View file

@ -10,6 +10,7 @@
package de.ellpeck.actuallyadditions.api.recipe;
import de.ellpeck.actuallyadditions.api.lens.LensConversion;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
@ -20,21 +21,24 @@ import java.util.List;
public class LensConversionRecipe{
public int energyUse;
public LensConversion type;
private String input;
private String output;
private ItemStack inputStack;
private ItemStack outputStack;
public LensConversionRecipe(ItemStack input, ItemStack output, int energyUse){
public LensConversionRecipe(ItemStack input, ItemStack output, int energyUse, LensConversion type){
this.inputStack = input;
this.outputStack = output;
this.energyUse = energyUse;
this.type = type;
}
public LensConversionRecipe(String input, String output, int energyUse){
public LensConversionRecipe(String input, String output, int energyUse, LensConversion type){
this.input = input;
this.output = output;
this.energyUse = energyUse;
this.type = type;
}
public List<ItemStack> getOutputs(){

View file

@ -4,6 +4,8 @@ import cofh.api.energy.IEnergyContainerItem;
import de.canitzp.rarmor.api.InventoryBase;
import de.canitzp.rarmor.api.modules.IRarmorModule;
import de.ellpeck.actuallyadditions.api.internal.IAtomicReconstructor;
import de.ellpeck.actuallyadditions.api.lens.Lens;
import de.ellpeck.actuallyadditions.api.lens.LensConversion;
import de.ellpeck.actuallyadditions.mod.items.base.ItemBase;
import de.ellpeck.actuallyadditions.mod.items.lens.Lenses;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityAtomicReconstructor;
@ -58,7 +60,7 @@ public class ItemRarmorModuleReconstructor extends ItemBase implements IRarmorMo
public void onModuleTickInArmor(World world, EntityPlayer player, ItemStack armorChestplate, ItemStack module, InventoryBase inventory){
if(!world.isRemote && player.isSneaking() && player.onGround){
if(world.getTotalWorldTime()%50 == 0){
RayTraceResult result = WorldUtil.getNearestPositionWithAir(world, player, Lenses.LENS_NONE.getDistance());
RayTraceResult result = WorldUtil.getNearestPositionWithAir(world, player, Lenses.LENS_CONVERSION.getDistance());
if(result != null){
BlockPos pos = result.getBlockPos();
if(pos != null){
@ -66,10 +68,10 @@ public class ItemRarmorModuleReconstructor extends ItemBase implements IRarmorMo
int energyUse = TileEntityAtomicReconstructor.ENERGY_USE*2;
if(fake.getEnergy() >= energyUse){
Lenses.LENS_NONE.invoke(world.getBlockState(pos), pos, fake);
Lenses.LENS_CONVERSION.invoke(world.getBlockState(pos), pos, fake);
EnumFacing hit = result.sideHit;
TileEntityAtomicReconstructor.shootLaser(world, player.posX-player.width/2, player.posY+player.getYOffset()+player.getEyeHeight()/2, player.posZ-player.width/2, pos.getX()+hit.getFrontOffsetX(), pos.getY()+hit.getFrontOffsetY(), pos.getZ()+hit.getFrontOffsetZ(), Lenses.LENS_NONE);
TileEntityAtomicReconstructor.shootLaser(world, player.posX-player.width/2, player.posY+player.getYOffset()+player.getEyeHeight()/2, player.posZ-player.width/2, pos.getX()+hit.getFrontOffsetX(), pos.getY()+hit.getFrontOffsetY(), pos.getZ()+hit.getFrontOffsetZ(), Lenses.LENS_CONVERSION);
fake.extractEnergy(energyUse);
}
@ -119,6 +121,11 @@ public class ItemRarmorModuleReconstructor extends ItemBase implements IRarmorMo
return 0;
}
}
@Override
public Lens getLens(){
return Lenses.LENS_CONVERSION;
}
};
}
}

View file

@ -1,108 +0,0 @@
/*
* This file ("LensNone.java") is part of the Actually Additions Mod for Minecraft.
* It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at
* http://ellpeck.de/actaddlicense/
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
* © 2016 Ellpeck
*/
package de.ellpeck.actuallyadditions.mod.items.lens;
import de.ellpeck.actuallyadditions.api.internal.IAtomicReconstructor;
import de.ellpeck.actuallyadditions.api.lens.Lens;
import de.ellpeck.actuallyadditions.api.recipe.LensConversionRecipe;
import de.ellpeck.actuallyadditions.mod.config.ConfigValues;
import de.ellpeck.actuallyadditions.mod.util.PosUtil;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import java.util.ArrayList;
import java.util.List;
public class LensConversion extends Lens{
@SuppressWarnings("unchecked")
@Override
public boolean invoke(IBlockState hitState, BlockPos hitBlock, IAtomicReconstructor tile){
if(hitBlock != null && !PosUtil.getBlock(hitBlock, tile.getWorldObject()).isAir(hitState, tile.getWorldObject(), hitBlock)){
int range = 2;
//Converting the Blocks
for(int reachX = -range; reachX < range+1; reachX++){
for(int reachZ = -range; reachZ < range+1; reachZ++){
for(int reachY = -range; reachY < range+1; reachY++){
BlockPos pos = new BlockPos(hitBlock.getX()+reachX, hitBlock.getY()+reachY, hitBlock.getZ()+reachZ);
List<LensConversionRecipe> recipes = LensRecipeHandler.getRecipesFor(new ItemStack(PosUtil.getBlock(pos, tile.getWorldObject()), 1, PosUtil.getMetadata(pos, tile.getWorldObject())));
for(LensConversionRecipe recipe : recipes){
if(recipe != null && tile.getEnergy() >= recipe.energyUse){
List<ItemStack> outputs = recipe.getOutputs();
if(outputs != null && !outputs.isEmpty()){
ItemStack output = outputs.get(0);
if(output.getItem() instanceof ItemBlock){
if(!ConfigValues.lessBlockBreakingEffects){
tile.getWorldObject().playAuxSFX(2001, pos, Block.getStateId(tile.getWorldObject().getBlockState(pos)));
}
PosUtil.setBlock(pos, tile.getWorldObject(), Block.getBlockFromItem(output.getItem()), output.getItemDamage(), 2);
}
else{
EntityItem item = new EntityItem(tile.getWorldObject(), pos.getX()+0.5, pos.getY()+0.5, pos.getZ()+0.5, output.copy());
tile.getWorldObject().spawnEntityInWorld(item);
}
tile.extractEnergy(recipe.energyUse);
break;
}
}
}
}
}
}
//Converting the Items
ArrayList<EntityItem> items = (ArrayList<EntityItem>)tile.getWorldObject().getEntitiesWithinAABB(EntityItem.class, new AxisAlignedBB(hitBlock.getX()-range, hitBlock.getY()-range, hitBlock.getZ()-range, hitBlock.getX()+range, hitBlock.getY()+range, hitBlock.getZ()+range));
for(EntityItem item : items){
ItemStack stack = item.getEntityItem();
if(!item.isDead && stack != null){
List<LensConversionRecipe> recipes = LensRecipeHandler.getRecipesFor(stack);
for(LensConversionRecipe recipe : recipes){
if(recipe != null && tile.getEnergy() >= recipe.energyUse){
List<ItemStack> outputs = recipe.getOutputs();
if(outputs != null && !outputs.isEmpty()){
ItemStack outputCopy = outputs.get(0).copy();
outputCopy.stackSize = stack.stackSize;
item.setDead();
EntityItem newItem = new EntityItem(tile.getWorldObject(), item.posX, item.posY, item.posZ, outputCopy);
tile.getWorldObject().spawnEntityInWorld(newItem);
tile.extractEnergy(recipe.energyUse);
break;
}
}
}
}
}
return true;
}
return false;
}
@Override
public float[] getColor(){
return new float[]{27F/255F, 109F/255F, 1F};
}
@Override
public int getDistance(){
return 10;
}
}

View file

@ -11,10 +11,11 @@
package de.ellpeck.actuallyadditions.mod.items.lens;
import de.ellpeck.actuallyadditions.api.lens.Lens;
import de.ellpeck.actuallyadditions.api.lens.LensConversion;
public class Lenses{
public static final Lens LENS_NONE = new LensConversion();
public static final LensConversion LENS_CONVERSION = LensConversion.DEFAULT_CONVERSION;
public static final Lens LENS_DETONATION = new LensDetonation();
public static final Lens LENS_DEATH = new LensDeath();
public static final Lens LENS_COLOR = new LensColor();

View file

@ -4,16 +4,28 @@ import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI;
import de.ellpeck.actuallyadditions.api.booklet.BookletPage;
import de.ellpeck.actuallyadditions.api.booklet.IBookletChapter;
import de.ellpeck.actuallyadditions.api.booklet.IBookletEntry;
import de.ellpeck.actuallyadditions.api.internal.IAtomicReconstructor;
import de.ellpeck.actuallyadditions.api.internal.IEntrySet;
import de.ellpeck.actuallyadditions.api.internal.IMethodHandler;
import de.ellpeck.actuallyadditions.api.recipe.CoffeeIngredient;
import de.ellpeck.actuallyadditions.api.recipe.LensConversionRecipe;
import de.ellpeck.actuallyadditions.mod.booklet.entry.EntrySet;
import de.ellpeck.actuallyadditions.mod.config.ConfigValues;
import de.ellpeck.actuallyadditions.mod.items.lens.LensRecipeHandler;
import de.ellpeck.actuallyadditions.mod.util.PosUtil;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import java.util.ArrayList;
import java.util.List;
public class MethodHandler implements IMethodHandler{
@ -101,4 +113,69 @@ public class MethodHandler implements IMethodHandler{
}
return effects.size() > 0 ? effects.toArray(new PotionEffect[effects.size()]) : null;
}
@Override
public boolean invokeConversionLens(IBlockState hitState, BlockPos hitBlock, IAtomicReconstructor tile){
if(hitBlock != null && !PosUtil.getBlock(hitBlock, tile.getWorldObject()).isAir(hitState, tile.getWorldObject(), hitBlock)){
int range = 2;
//Converting the Blocks
for(int reachX = -range; reachX < range+1; reachX++){
for(int reachZ = -range; reachZ < range+1; reachZ++){
for(int reachY = -range; reachY < range+1; reachY++){
BlockPos pos = new BlockPos(hitBlock.getX()+reachX, hitBlock.getY()+reachY, hitBlock.getZ()+reachZ);
List<LensConversionRecipe> recipes = LensRecipeHandler.getRecipesFor(new ItemStack(PosUtil.getBlock(pos, tile.getWorldObject()), 1, PosUtil.getMetadata(pos, tile.getWorldObject())));
for(LensConversionRecipe recipe : recipes){
if(recipe != null && recipe.type == tile.getLens() && tile.getEnergy() >= recipe.energyUse){
List<ItemStack> outputs = recipe.getOutputs();
if(outputs != null && !outputs.isEmpty()){
ItemStack output = outputs.get(0);
if(output.getItem() instanceof ItemBlock){
if(!ConfigValues.lessBlockBreakingEffects){
tile.getWorldObject().playAuxSFX(2001, pos, Block.getStateId(tile.getWorldObject().getBlockState(pos)));
}
PosUtil.setBlock(pos, tile.getWorldObject(), Block.getBlockFromItem(output.getItem()), output.getItemDamage(), 2);
}
else{
EntityItem item = new EntityItem(tile.getWorldObject(), pos.getX()+0.5, pos.getY()+0.5, pos.getZ()+0.5, output.copy());
tile.getWorldObject().spawnEntityInWorld(item);
}
tile.extractEnergy(recipe.energyUse);
break;
}
}
}
}
}
}
//Converting the Items
ArrayList<EntityItem> items = (ArrayList<EntityItem>)tile.getWorldObject().getEntitiesWithinAABB(EntityItem.class, new AxisAlignedBB(hitBlock.getX()-range, hitBlock.getY()-range, hitBlock.getZ()-range, hitBlock.getX()+range, hitBlock.getY()+range, hitBlock.getZ()+range));
for(EntityItem item : items){
ItemStack stack = item.getEntityItem();
if(!item.isDead && stack != null){
List<LensConversionRecipe> recipes = LensRecipeHandler.getRecipesFor(stack);
for(LensConversionRecipe recipe : recipes){
if(recipe != null && recipe.type == tile.getLens() && tile.getEnergy() >= recipe.energyUse){
List<ItemStack> outputs = recipe.getOutputs();
if(outputs != null && !outputs.isEmpty()){
ItemStack outputCopy = outputs.get(0).copy();
outputCopy.stackSize = stack.stackSize;
item.setDead();
EntityItem newItem = new EntityItem(tile.getWorldObject(), item.posX, item.posY, item.posZ, outputCopy);
tile.getWorldObject().spawnEntityInWorld(newItem);
tile.extractEnergy(recipe.energyUse);
break;
}
}
}
}
}
return true;
}
return false;
}
}

View file

@ -15,6 +15,7 @@ import cofh.api.energy.IEnergyReceiver;
import de.ellpeck.actuallyadditions.api.internal.IAtomicReconstructor;
import de.ellpeck.actuallyadditions.api.lens.ILensItem;
import de.ellpeck.actuallyadditions.api.lens.Lens;
import de.ellpeck.actuallyadditions.api.lens.LensConversion;
import de.ellpeck.actuallyadditions.mod.config.ConfigValues;
import de.ellpeck.actuallyadditions.mod.items.lens.Lenses;
import de.ellpeck.actuallyadditions.mod.misc.SoundHandler;
@ -104,7 +105,7 @@ public class TileEntityAtomicReconstructor extends TileEntityInventoryBase imple
this.storage.extractEnergy(ENERGY_USE, false);
//The Lens the Reconstructor currently has installed
Lens currentLens = this.getCurrentLens();
Lens currentLens = this.getLens();
int distance = currentLens.getDistance();
for(int i = 0; i < distance; i++){
BlockPos hitBlock = WorldUtil.getCoordsFromSide(sideToManipulate, this.pos, i);
@ -120,13 +121,14 @@ public class TileEntityAtomicReconstructor extends TileEntityInventoryBase imple
}
}
public Lens getCurrentLens(){
@Override
public Lens getLens(){
if(this.slots[0] != null){
if(this.slots[0].getItem() instanceof ILensItem){
return ((ILensItem)this.slots[0].getItem()).getLens();
}
}
return this.counter >= 500 ? Lenses.LENS_DISRUPTION : Lenses.LENS_NONE;
return this.counter >= 500 ? Lenses.LENS_DISRUPTION : Lenses.LENS_CONVERSION;
}
@Override