2016-08-03 04:01:47 +02:00
|
|
|
/*
|
|
|
|
* This file ("TileEntityEmpowerer.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
|
|
|
|
*
|
|
|
|
* © 2015-2016 Ellpeck
|
|
|
|
*/
|
|
|
|
|
|
|
|
package de.ellpeck.actuallyadditions.mod.tile;
|
|
|
|
|
|
|
|
import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI;
|
|
|
|
import de.ellpeck.actuallyadditions.api.recipe.EmpowererRecipe;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.util.AssetUtil;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.util.ItemUtil;
|
2016-11-16 20:31:16 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
|
2016-08-03 04:01:47 +02:00
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
import net.minecraft.tileentity.TileEntity;
|
|
|
|
import net.minecraft.util.EnumFacing;
|
|
|
|
import net.minecraft.util.EnumParticleTypes;
|
|
|
|
import net.minecraft.util.math.BlockPos;
|
|
|
|
import net.minecraft.world.WorldServer;
|
|
|
|
|
2016-08-31 20:58:56 +02:00
|
|
|
import java.util.ArrayList;
|
2016-08-03 04:01:47 +02:00
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
public class TileEntityEmpowerer extends TileEntityInventoryBase{
|
|
|
|
|
|
|
|
private int processTime;
|
|
|
|
|
|
|
|
public TileEntityEmpowerer(){
|
|
|
|
super(1, "empowerer");
|
|
|
|
}
|
|
|
|
|
2016-10-21 00:13:21 +02:00
|
|
|
public static List<EmpowererRecipe> getRecipesForInput(ItemStack input){
|
|
|
|
List<EmpowererRecipe> recipesThatWork = new ArrayList<EmpowererRecipe>();
|
2016-11-16 20:31:16 +01:00
|
|
|
if(StackUtil.isValid(input)){
|
2016-09-12 20:45:29 +02:00
|
|
|
for(EmpowererRecipe recipe : ActuallyAdditionsAPI.EMPOWERER_RECIPES){
|
2016-11-16 20:31:16 +01:00
|
|
|
if(StackUtil.isValid(recipe.input) && recipe.input.isItemEqual(input)){
|
2016-10-21 00:13:21 +02:00
|
|
|
recipesThatWork.add(recipe);
|
2016-09-12 20:45:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-10-21 00:13:21 +02:00
|
|
|
return recipesThatWork;
|
2016-09-12 20:45:29 +02:00
|
|
|
}
|
|
|
|
|
2016-08-03 04:01:47 +02:00
|
|
|
@Override
|
|
|
|
public void updateEntity(){
|
|
|
|
super.updateEntity();
|
|
|
|
|
|
|
|
if(!this.worldObj.isRemote){
|
2016-11-20 20:13:26 +01:00
|
|
|
List<EmpowererRecipe> recipes = getRecipesForInput(this.slots.get(0));
|
2016-10-21 00:13:21 +02:00
|
|
|
if(!recipes.isEmpty()){
|
|
|
|
for(EmpowererRecipe recipe : recipes){
|
|
|
|
TileEntityDisplayStand[] modifierStands = this.getFittingModifiers(recipe, recipe.time);
|
|
|
|
if(modifierStands != null){ //Meaning the display stands around match all the criteria
|
|
|
|
|
|
|
|
this.processTime++;
|
|
|
|
boolean done = this.processTime >= recipe.time;
|
|
|
|
|
|
|
|
for(TileEntityDisplayStand stand : modifierStands){
|
|
|
|
stand.storage.extractEnergy(recipe.energyPerStand/recipe.time, false);
|
|
|
|
|
|
|
|
if(done){
|
|
|
|
stand.decrStackSize(0, 1);
|
|
|
|
}
|
|
|
|
|
2016-11-07 19:58:34 +01:00
|
|
|
AssetUtil.shootParticles(this.worldObj, stand.getPos().getX(), stand.getPos().getY()+0.45F, stand.getPos().getZ(), this.pos.getX(), this.pos.getY(), this.pos.getZ(), recipe.particleColor, 8, 0.5F, 1F);
|
2016-08-03 04:01:47 +02:00
|
|
|
}
|
|
|
|
|
2016-11-07 19:58:34 +01:00
|
|
|
if(this.processTime%5 == 0 && this.worldObj instanceof WorldServer){
|
2016-10-21 00:13:21 +02:00
|
|
|
((WorldServer)this.worldObj).spawnParticle(EnumParticleTypes.FIREWORKS_SPARK, false, this.pos.getX()+0.5, this.pos.getY()+1.1, this.pos.getZ()+0.5, 3, 0, 0, 0, 0.1D);
|
2016-08-08 21:39:00 +02:00
|
|
|
}
|
2016-08-03 04:01:47 +02:00
|
|
|
|
2016-10-21 00:13:21 +02:00
|
|
|
if(done){
|
2016-11-07 19:58:34 +01:00
|
|
|
((WorldServer)this.worldObj).spawnParticle(EnumParticleTypes.END_ROD, false, this.pos.getX()+0.5, this.pos.getY()+1.1, this.pos.getZ()+0.5, 300, 0, 0, 0, 0.25D);
|
2016-08-03 04:06:41 +02:00
|
|
|
|
2016-11-20 20:13:26 +01:00
|
|
|
this.slots.set(0, recipe.output.copy());
|
2016-10-21 00:13:21 +02:00
|
|
|
this.markDirty();
|
2016-08-03 04:01:47 +02:00
|
|
|
|
2016-10-21 00:13:21 +02:00
|
|
|
this.processTime = 0;
|
|
|
|
}
|
2016-08-03 04:01:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
this.processTime = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private TileEntityDisplayStand[] getFittingModifiers(EmpowererRecipe recipe, int powerDivider){
|
|
|
|
TileEntityDisplayStand[] modifierStands = new TileEntityDisplayStand[4];
|
2016-08-31 20:58:56 +02:00
|
|
|
List<ItemStack> itemsStillNeeded = new ArrayList<ItemStack>(Arrays.asList(recipe.modifier1, recipe.modifier2, recipe.modifier3, recipe.modifier4));
|
2016-08-03 04:01:47 +02:00
|
|
|
|
|
|
|
for(int i = 0; i < EnumFacing.HORIZONTALS.length; i++){
|
|
|
|
EnumFacing facing = EnumFacing.HORIZONTALS[i];
|
2016-08-03 13:36:42 +02:00
|
|
|
BlockPos offset = this.pos.offset(facing, 3);
|
2016-08-03 04:01:47 +02:00
|
|
|
TileEntity tile = this.worldObj.getTileEntity(offset);
|
|
|
|
|
2016-11-16 20:31:16 +01:00
|
|
|
if(tile instanceof TileEntityDisplayStand){
|
2016-08-03 04:01:47 +02:00
|
|
|
TileEntityDisplayStand stand = (TileEntityDisplayStand)tile;
|
|
|
|
ItemStack standItem = stand.getStackInSlot(0);
|
2016-08-31 20:58:56 +02:00
|
|
|
int containPlace = ItemUtil.getPlaceAt(itemsStillNeeded, standItem, true);
|
|
|
|
if(stand.storage.getEnergyStored() >= recipe.energyPerStand/powerDivider && containPlace != -1){
|
2016-08-03 04:01:47 +02:00
|
|
|
modifierStands[i] = stand;
|
2016-08-31 20:58:56 +02:00
|
|
|
itemsStillNeeded.remove(containPlace);
|
2016-08-03 04:01:47 +02:00
|
|
|
}
|
|
|
|
else{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return modifierStands;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void writeSyncableNBT(NBTTagCompound compound, NBTType type){
|
|
|
|
super.writeSyncableNBT(compound, type);
|
|
|
|
if(type == NBTType.SAVE_TILE){
|
|
|
|
compound.setInteger("ProcessTime", this.processTime);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void readSyncableNBT(NBTTagCompound compound, NBTType type){
|
|
|
|
super.readSyncableNBT(compound, type);
|
|
|
|
if(type == NBTType.SAVE_TILE){
|
|
|
|
this.processTime = compound.getInteger("ProcessTime");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean shouldSyncSlots(){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void markDirty(){
|
|
|
|
super.markDirty();
|
|
|
|
this.sendUpdate();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isItemValidForSlot(int index, ItemStack stack){
|
2016-10-21 00:13:21 +02:00
|
|
|
return !getRecipesForInput(stack).isEmpty();
|
2016-08-03 04:01:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canInsertItem(int index, ItemStack stack, EnumFacing direction){
|
|
|
|
return this.isItemValidForSlot(index, stack);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canExtractItem(int index, ItemStack stack, EnumFacing direction){
|
2016-10-31 22:36:42 +01:00
|
|
|
return getRecipesForInput(stack).isEmpty();
|
2016-08-03 04:01:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getInventoryStackLimit(){
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|