Finished the infrastructure for Alchemy Array crafting. Updated some Utils so that they work more generally. Added the ability for a delay to be present for effects.

This commit is contained in:
WayofTime 2015-12-23 20:19:06 -05:00
parent 63c3853776
commit c54aa5d00e
7 changed files with 140 additions and 46 deletions

View file

@ -18,6 +18,10 @@ public class AlchemyArrayEffectCrafting extends AlchemyArrayEffect {
@Override
public boolean update(TileEntity tile, int ticksActive) {
//TODO: Add recipe rechecking to verify nothing screwy is going on.
if(tile.getWorld().isRemote) {
return false;
}
BlockPos pos = tile.getPos();
ItemStack output = outputStack.copy();

View file

@ -120,6 +120,17 @@ public class AlchemyArrayRecipeRegistry {
return null;
}
public static AlchemyCircleRenderer getAlchemyCircleRenderer(ItemStack inputStack) {
for (Entry<ItemStack, AlchemyArrayRecipe> entry : recipes.entrySet()) {
AlchemyArrayRecipe arrayRecipe = entry.getValue();
if (arrayRecipe.doesInputMatchRecipe(inputStack)) {
return arrayRecipe.circleRenderer;
}
}
return defaultRenderer;
}
@Getter
@ToString
@EqualsAndHashCode
@ -132,6 +143,9 @@ public class AlchemyArrayRecipeRegistry {
public AlchemyArrayRecipe(ItemStack inputStack, ItemStack catalystStack, AlchemyArrayEffect arrayEffect, AlchemyCircleRenderer circleRenderer) {
this.inputStack = inputStack;
catalystMap.put(catalystStack, arrayEffect);
this.circleRenderer = circleRenderer;
}
/**

View file

@ -7,9 +7,12 @@ import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumWorldBlockLayer;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
@ -17,6 +20,8 @@ import net.minecraftforge.fml.relauncher.SideOnly;
import WayofTime.bloodmagic.BloodMagic;
import WayofTime.bloodmagic.api.Constants;
import WayofTime.bloodmagic.tile.TileAlchemyArray;
import WayofTime.bloodmagic.tile.TileAlchemyArray;
import WayofTime.bloodmagic.util.Utils;
public class BlockAlchemyArray extends BlockContainer {
@ -25,6 +30,7 @@ public class BlockAlchemyArray extends BlockContainer {
setUnlocalizedName(Constants.Mod.MODID + ".alchemyArray");
setCreativeTab(BloodMagic.tabBloodMagic);
this.setHardness(0.1f);
}
@Override
@ -48,6 +54,28 @@ public class BlockAlchemyArray extends BlockContainer {
this.setBlockBounds(0, 0, 0, 1, 0.1f, 1);
}
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumFacing side, float hitX, float hitY, float hitZ) {
TileAlchemyArray array = (TileAlchemyArray) world.getTileEntity(pos);
if (array == null || player.isSneaking())
return false;
ItemStack playerItem = player.getCurrentEquippedItem();
if (playerItem != null) {
if (array.getStackInSlot(0) == null) {
Utils.insertItemToTile(array, player, 0);
} else {
Utils.insertItemToTile(array, player, 1);
array.attemptCraft();
}
}
world.markBlockForUpdate(pos);
return true;
}
@Override
public int quantityDropped(Random random) {
return 0;
@ -62,4 +90,13 @@ public class BlockAlchemyArray extends BlockContainer {
public TileEntity createNewTileEntity(World worldIn, int meta) {
return new TileAlchemyArray();
}
@Override
public void breakBlock(World world, BlockPos blockPos, IBlockState blockState) {
TileAlchemyArray alchemyArray = (TileAlchemyArray) world.getTileEntity(blockPos);
if (alchemyArray != null)
alchemyArray.dropItems();
super.breakBlock(world, blockPos, blockState);
}
}

View file

@ -1,19 +1,20 @@
package WayofTime.bloodmagic.client.render;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import WayofTime.bloodmagic.api.alchemyCrafting.AlchemyCircleRenderer;
import WayofTime.bloodmagic.api.registry.AlchemyArrayRecipeRegistry;
import WayofTime.bloodmagic.tile.TileAlchemyArray;
public class RenderAlchemyArray extends TileEntitySpecialRenderer
{
public class RenderAlchemyArray extends TileEntitySpecialRenderer {
@Override
public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float partialTicks, int destroyStage)
{
if (tileEntity instanceof TileAlchemyArray)
{
AlchemyCircleRenderer renderer = new AlchemyCircleRenderer(new ResourceLocation("bloodmagic", "textures/models/AlchemyArrays/SightSigil.png")); //Temporary renderer for testing
public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float partialTicks, int destroyStage) {
if (tileEntity instanceof TileAlchemyArray) {
ItemStack inputStack = ((TileAlchemyArray)tileEntity).getStackInSlot(0);
AlchemyCircleRenderer renderer = AlchemyArrayRecipeRegistry.getAlchemyCircleRenderer(inputStack);
renderer.renderAt(tileEntity, x, y, z);
}
}

View file

@ -1,17 +1,20 @@
package WayofTime.bloodmagic.registry;
import WayofTime.bloodmagic.api.altar.EnumAltarTier;
import WayofTime.bloodmagic.api.registry.AlchemyArrayRecipeRegistry;
import WayofTime.bloodmagic.api.registry.AltarRecipeRegistry;
import WayofTime.bloodmagic.api.registry.OrbRegistry;
import WayofTime.bloodmagic.api.ritual.EnumRuneType;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
public class ModRecipes {
public static void init() {
addAltarRecipes();
addAlchemyArrayRecipes();
}
public static void addAltarRecipes() {
@ -43,4 +46,8 @@ public class ModRecipes {
AltarRecipeRegistry.registerRecipe(new AltarRecipeRegistry.AltarRecipe(new ItemStack(ModBlocks.crystal), OrbRegistry.getOrbStack(ModItems.orbTranscendent), EnumAltarTier.SIX, 200000, 100, 200, false));
AltarRecipeRegistry.registerRecipe(new AltarRecipeRegistry.AltarRecipe(new ItemStack(Blocks.glowstone), EnumRuneType.DAWN.getScribeStack(), EnumAltarTier.SIX, 200000, 100, 200, false));
}
public static void addAlchemyArrayRecipes() {
AlchemyArrayRecipeRegistry.registerCraftingRecipe(new ItemStack(Items.redstone), new ItemStack(ModItems.slate), new ItemStack(Items.diamond), new ResourceLocation("bloodmagic", "textures/models/AlchemyArrays/LavaSigil.png"));
}
}

View file

@ -5,9 +5,13 @@ import net.minecraft.network.NetworkManager;
import net.minecraft.network.Packet;
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
import net.minecraft.util.ITickable;
import WayofTime.bloodmagic.api.alchemyCrafting.AlchemyArrayEffect;
import WayofTime.bloodmagic.api.registry.AlchemyArrayRecipeRegistry;
public class TileAlchemyArray extends TileInventory implements ITickable {
public class TileAlchemyArray extends TileInventory implements ITickable{
public boolean isActive = false;
public int activeCounter = 0;
public TileAlchemyArray() {
super(2, "alchemyArray");
@ -16,29 +20,53 @@ public class TileAlchemyArray extends TileInventory implements ITickable{
@Override
public void readFromNBT(NBTTagCompound tagCompound) {
super.readFromNBT(tagCompound);
this.isActive = tagCompound.getBoolean("isActive");
this.activeCounter = tagCompound.getInteger("activeCounter");
}
@Override
public void writeToNBT(NBTTagCompound tagCompound) {
super.writeToNBT(tagCompound);
tagCompound.setBoolean("isActive", isActive);
tagCompound.setInteger("activeCounter", activeCounter);
}
@Override
public void update() {
if (isActive && attemptCraft()) {
activeCounter++;
} else {
isActive = false;
activeCounter = 0;
}
}
public boolean attemptCraft() {
AlchemyArrayEffect effect = AlchemyArrayRecipeRegistry.getAlchemyArrayEffect(this.getStackInSlot(0), this.getStackInSlot(1));
if (effect != null) {
isActive = true;
if (effect.update(this, 0)) {
this.decrStackSize(0, 1);
this.decrStackSize(1, 1);
this.worldObj.setBlockToAir(getPos());
}
return true;
}
return false;
}
@Override
public Packet getDescriptionPacket()
{
public Packet getDescriptionPacket() {
NBTTagCompound nbttagcompound = new NBTTagCompound();
writeToNBT(nbttagcompound);
return new S35PacketUpdateTileEntity(pos, this.getBlockMetadata(), nbttagcompound);
}
@Override
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity packet)
{
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity packet) {
super.onDataPacket(net, packet);
readFromNBT(packet.getNbtCompound());
}

View file

@ -1,14 +1,13 @@
package WayofTime.bloodmagic.util;
import WayofTime.bloodmagic.api.altar.EnumAltarComponent;
import WayofTime.bloodmagic.registry.ModBlocks;
import WayofTime.bloodmagic.tile.TileInventory;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import WayofTime.bloodmagic.api.altar.EnumAltarComponent;
import WayofTime.bloodmagic.registry.ModBlocks;
import WayofTime.bloodmagic.tile.TileInventory;
public class Utils {
@ -34,15 +33,19 @@ public class Utils {
* @param player - The player to take the item from.
*/
public static boolean insertItemToTile(TileInventory tile, EntityPlayer player) {
if (tile.getStackInSlot(0) == null && player.getHeldItem() != null) {
return insertItemToTile(tile, player, 0);
}
public static boolean insertItemToTile(TileInventory tile, EntityPlayer player, int slot) {
if (tile.getStackInSlot(slot) == null && player.getHeldItem() != null) {
ItemStack input = player.getHeldItem().copy();
input.stackSize = 1;
player.getHeldItem().stackSize--;
tile.setInventorySlotContents(0, input);
tile.setInventorySlotContents(slot, input);
return true;
} else if (tile.getStackInSlot(0) != null && player.getHeldItem() == null) {
} else if (tile.getStackInSlot(slot) != null && player.getHeldItem() == null) {
if (!tile.getWorld().isRemote) {
EntityItem invItem = new EntityItem(tile.getWorld(), player.posX, player.posY + 0.25, player.posZ, tile.getStackInSlot(0));
EntityItem invItem = new EntityItem(tile.getWorld(), player.posX, player.posY + 0.25, player.posZ, tile.getStackInSlot(slot));
tile.getWorld().spawnEntityInWorld(invItem);
}
tile.clear();