Search in sources :

Example 1 with TEWritingTable

use of WayofTime.alchemicalWizardry.common.tileEntity.TEWritingTable in project BloodMagic by WayofTime.

the class RitualEffectAutoAlchemy method performEffect.

@Override
public void performEffect(IMasterRitualStone ritualStone) {
    String owner = ritualStone.getOwner();
    int currentEssence = SoulNetworkHandler.getCurrentEssence(owner);
    World world = ritualStone.getWorld();
    int x = ritualStone.getXCoord();
    int y = ritualStone.getYCoord();
    int z = ritualStone.getZCoord();
    if (currentEssence < this.getCostPerRefresh() * 6) {
        SoulNetworkHandler.causeNauseaToPlayer(owner);
    } else {
        boolean hasPotentia = this.canDrainReagent(ritualStone, ReagentRegistry.potentiaReagent, potentiaDrain, false);
        int flag = 0;
        TileEntity topEntity = world.getTileEntity(x, y + 1, z);
        if (!(topEntity instanceof IBloodAltar) || !(topEntity instanceof IBloodAltar)) {
            return;
        }
        IBloodAltar altar = (IBloodAltar) topEntity;
        ItemStack targetStack = ((IInventory) altar).getStackInSlot(0);
        if (targetStack == null) {
            return;
        }
        ItemStack[] recipe = AlchemyRecipeRegistry.getRecipeForItemStack(targetStack);
        if (recipe != null) {
            TEWritingTable alchemyEntity;
            IInventory outputInv = null;
            IInventory inputInv1 = null;
            IInventory inputInv2 = null;
            TileEntity northEntity = world.getTileEntity(x, y, z - 1);
            TileEntity southEntity = world.getTileEntity(x, y, z + 1);
            TileEntity eastEntity = world.getTileEntity(x + 1, y, z);
            TileEntity westEntity = world.getTileEntity(x - 1, y, z);
            if (northEntity instanceof TEWritingTable) {
                alchemyEntity = (TEWritingTable) northEntity;
                if (southEntity instanceof IInventory && !(southEntity instanceof TEWritingTable)) {
                    outputInv = (IInventory) southEntity;
                }
                if (eastEntity instanceof IInventory && !(eastEntity instanceof TEWritingTable)) {
                    inputInv1 = (IInventory) eastEntity;
                }
                if (westEntity instanceof IInventory && !(westEntity instanceof TEWritingTable)) {
                    inputInv2 = (IInventory) westEntity;
                }
            } else if (southEntity instanceof TEWritingTable) {
                alchemyEntity = (TEWritingTable) southEntity;
                if (northEntity instanceof IInventory && !(northEntity instanceof TEWritingTable)) {
                    outputInv = (IInventory) northEntity;
                }
                if (eastEntity instanceof IInventory && !(eastEntity instanceof TEWritingTable)) {
                    inputInv1 = (IInventory) eastEntity;
                }
                if (westEntity instanceof IInventory && !(westEntity instanceof TEWritingTable)) {
                    inputInv2 = (IInventory) westEntity;
                }
            } else if (eastEntity instanceof TEWritingTable) {
                alchemyEntity = (TEWritingTable) eastEntity;
                if (westEntity instanceof IInventory && !(westEntity instanceof TEWritingTable)) {
                    outputInv = (IInventory) westEntity;
                }
                if (northEntity instanceof IInventory && !(northEntity instanceof TEWritingTable)) {
                    inputInv1 = (IInventory) northEntity;
                }
                if (southEntity instanceof IInventory && !(southEntity instanceof TEWritingTable)) {
                    inputInv2 = (IInventory) southEntity;
                }
            } else if (westEntity instanceof TEWritingTable) {
                alchemyEntity = (TEWritingTable) westEntity;
                if (eastEntity instanceof IInventory && !(eastEntity instanceof TEWritingTable)) {
                    outputInv = (IInventory) eastEntity;
                }
                if (northEntity instanceof IInventory && !(northEntity instanceof TEWritingTable)) {
                    inputInv1 = (IInventory) northEntity;
                }
                if (southEntity instanceof IInventory && !(southEntity instanceof TEWritingTable)) {
                    inputInv2 = (IInventory) southEntity;
                }
            } else {
                return;
            }
            if (alchemyEntity != null && hasPotentia) {
                alchemyEntity.setAccelerationTime(5);
                if (alchemyEntity.isWorking()) {
                    this.canDrainReagent(ritualStone, ReagentRegistry.potentiaReagent, potentiaDrain, true);
                }
            }
            if (outputInv != null) {
                ItemStack outputStack = alchemyEntity.getStackInSlot(6);
                if (outputStack != null) {
                    for (int i = 0; i < outputInv.getSizeInventory(); i++) {
                        ItemStack curStack = outputInv.getStackInSlot(i);
                        if (curStack == null) {
                            ItemStack copyStack = outputStack.copy();
                            copyStack.stackSize = 1;
                            outputStack.stackSize--;
                            if (outputStack.stackSize <= 0) {
                                alchemyEntity.setInventorySlotContents(6, null);
                            } else {
                                alchemyEntity.setInventorySlotContents(6, outputStack);
                            }
                            outputInv.setInventorySlotContents(i, copyStack);
                            flag++;
                            break;
                        } else if (curStack.isItemEqual(outputStack) && curStack.stackSize < curStack.getMaxStackSize() && ItemStack.areItemStackTagsEqual(outputStack, curStack)) {
                            outputStack.stackSize--;
                            if (outputStack.stackSize <= 0) {
                                alchemyEntity.setInventorySlotContents(6, null);
                            } else {
                                alchemyEntity.setInventorySlotContents(6, outputStack);
                            }
                            curStack.stackSize++;
                            outputInv.setInventorySlotContents(i, curStack);
                            flag++;
                            break;
                        }
                    }
                }
                for (int i = 0; i < 5; i++) {
                    ItemStack recItem;
                    if (recipe.length <= i) {
                        recItem = null;
                    } else {
                        recItem = recipe[i];
                    }
                    ItemStack alchStack = alchemyEntity.getStackInSlot(i + 1);
                    if ((recItem == null && alchStack != null) || (alchStack != null && !(areItemStacksEqualWithWildcard(recItem, alchStack)))) {
                        for (int j = 0; j < outputInv.getSizeInventory(); j++) {
                            ItemStack curStack = outputInv.getStackInSlot(j);
                            if (curStack == null) {
                                ItemStack copyStack = alchStack.copy();
                                copyStack.stackSize = 1;
                                alchStack.stackSize--;
                                if (alchStack.stackSize <= 0) {
                                    alchemyEntity.setInventorySlotContents(i + 1, null);
                                } else {
                                    alchemyEntity.setInventorySlotContents(i + 1, alchStack);
                                }
                                outputInv.setInventorySlotContents(j, copyStack);
                                flag++;
                                break;
                            } else if (curStack.isItemEqual(alchStack) && curStack.stackSize < curStack.getMaxStackSize() && ItemStack.areItemStackTagsEqual(alchStack, curStack)) {
                                alchStack.stackSize--;
                                if (alchStack.stackSize <= 0) {
                                    alchemyEntity.setInventorySlotContents(i + 1, null);
                                } else {
                                    alchemyEntity.setInventorySlotContents(i + 1, alchStack);
                                }
                                curStack.stackSize++;
                                outputInv.setInventorySlotContents(j, curStack);
                                flag++;
                                break;
                            }
                        }
                        continue;
                    }
                }
            }
            if (world.getWorldTime() % 10 == 0) {
                if (flag == 0 && inputInv1 != null) {
                    for (int i = 0; i < recipe.length; i++) {
                        ItemStack recItem = recipe[i];
                        if (recItem == null) {
                            continue;
                        }
                        ItemStack alchStack = alchemyEntity.getStackInSlot(i + 1);
                        if (alchStack != null && ((!areItemStacksEqualWithWildcard(recItem, alchStack)) || alchStack.stackSize >= (fillToOne ? 1 : alchStack.getMaxStackSize()))) {
                            continue;
                        }
                        for (int j = 0; j < inputInv1.getSizeInventory(); j++) {
                            ItemStack curItem = inputInv1.getStackInSlot(j);
                            if (curItem == null) {
                                continue;
                            }
                            if (!inputInv1.isItemValidForSlot(j, curItem) || (inputInv1 instanceof ISidedInventory && !((ISidedInventory) inputInv1).canExtractItem(j, curItem, ForgeDirection.DOWN.ordinal()))) {
                                continue;
                            }
                            if (areItemStacksEqualWithWildcard(recItem, curItem)) {
                                if (alchStack == null) {
                                    ItemStack copyStack = recItem.copy();
                                    copyStack.stackSize = 1;
                                    alchemyEntity.setInventorySlotContents(i + 1, copyStack);
                                    curItem.stackSize--;
                                    if (curItem.stackSize <= 0) {
                                        inputInv1.setInventorySlotContents(j, null);
                                    } else {
                                        inputInv1.setInventorySlotContents(j, curItem);
                                    }
                                    flag++;
                                    break;
                                } else {
                                    alchStack.stackSize++;
                                    alchemyEntity.setInventorySlotContents(i + 1, alchStack);
                                    curItem.stackSize--;
                                    if (curItem.stackSize <= 0) {
                                        inputInv1.setInventorySlotContents(j, null);
                                    } else {
                                        inputInv1.setInventorySlotContents(j, curItem);
                                    }
                                    flag++;
                                    break;
                                }
                            }
                        }
                    }
                }
                if (flag == 0 && inputInv2 != null) {
                    for (int i = 0; i < recipe.length; i++) {
                        ItemStack recItem = recipe[i];
                        if (recItem == null) {
                            continue;
                        }
                        ItemStack alchStack = alchemyEntity.getStackInSlot(i + 1);
                        if (alchStack != null && ((!areItemStacksEqualWithWildcard(recItem, alchStack)) || alchStack.stackSize >= (fillToOne ? 1 : alchStack.getMaxStackSize()))) {
                            continue;
                        }
                        for (int j = 0; j < inputInv2.getSizeInventory(); j++) {
                            ItemStack curItem = inputInv2.getStackInSlot(j);
                            if (curItem == null) {
                                continue;
                            }
                            if (areItemStacksEqualWithWildcard(recItem, curItem)) {
                                if (alchStack == null) {
                                    ItemStack copyStack = recItem.copy();
                                    copyStack.stackSize = 1;
                                    alchemyEntity.setInventorySlotContents(i + 1, copyStack);
                                    curItem.stackSize--;
                                    if (curItem.stackSize <= 0) {
                                        inputInv2.setInventorySlotContents(j, null);
                                    } else {
                                        inputInv2.setInventorySlotContents(j, curItem);
                                    }
                                    flag++;
                                    break;
                                } else {
                                    alchStack.stackSize++;
                                    alchemyEntity.setInventorySlotContents(i + 1, alchStack);
                                    curItem.stackSize--;
                                    if (curItem.stackSize <= 0) {
                                        inputInv2.setInventorySlotContents(j, null);
                                    } else {
                                        inputInv2.setInventorySlotContents(j, curItem);
                                    }
                                    flag++;
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
        if (flag > 0) {
            world.markBlockForUpdate(x, y, z + 1);
            world.markBlockForUpdate(x, y, z - 1);
            world.markBlockForUpdate(x + 1, y, z);
            world.markBlockForUpdate(x - 1, y, z);
            SoulNetworkHandler.syphonFromNetwork(owner, this.getCostPerRefresh() * flag);
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IInventory(net.minecraft.inventory.IInventory) ISidedInventory(net.minecraft.inventory.ISidedInventory) TEWritingTable(WayofTime.alchemicalWizardry.common.tileEntity.TEWritingTable) World(net.minecraft.world.World) ItemStack(net.minecraft.item.ItemStack) IBloodAltar(WayofTime.alchemicalWizardry.api.tile.IBloodAltar)

Example 2 with TEWritingTable

use of WayofTime.alchemicalWizardry.common.tileEntity.TEWritingTable in project BloodMagic by WayofTime.

the class RenderWritingTable method renderTileEntityAt.

@Override
public void renderTileEntityAt(TileEntity tileEntity, double d0, double d1, double d2, float f) {
    if (tileEntity instanceof TEWritingTable) {
        TEWritingTable tileAltar = (TEWritingTable) tileEntity;
        GL11.glDisable(GL11.GL_LIGHTING);
        GL11.glPushMatrix();
        GL11.glTranslatef((float) d0 + 0.5F, (float) d1 + 1.5F, (float) d2 + 0.5F);
        ResourceLocation test = new ResourceLocation("alchemicalwizardry:textures/models/WritingTable.png");
        FMLClientHandler.instance().getClient().renderEngine.bindTexture(test);
        GL11.glPushMatrix();
        GL11.glRotatef(180F, 0.0F, 0.0F, 1.0F);
        this.modelWritingTable.render(null, 0.0F, 0.0F, -0.1F, 0.0F, 0.0F, 0.0625F);
        GL11.glPopMatrix();
        GL11.glPopMatrix();
        for (int i = 1; i <= 6; i++) {
            GL11.glPushMatrix();
            GL11.glEnable(GL11.GL_LIGHTING);
            if (tileAltar.getStackInSlot(i) != null) {
                float scaleFactor = getGhostItemScaleFactor(tileAltar.getStackInSlot(i));
                float rotationAngle = Minecraft.getMinecraft().gameSettings.fancyGraphics ? (float) (720.0 * (System.currentTimeMillis() & 0x3FFFL) / 0x3FFFL) : 0;
                EntityItem ghostEntityItem = new EntityItem(tileAltar.getWorldObj());
                ghostEntityItem.hoverStart = 0.0F;
                ghostEntityItem.setEntityItemStack(tileAltar.getStackInSlot(i));
                float displacementX = getXDisplacementForSlot(i);
                float displacementY = getYDisplacementForSlot(i);
                float displacementZ = getZDisplacementForSlot(i);
                if (ghostEntityItem.getEntityItem().getItem() instanceof ItemBlock) {
                    GL11.glTranslatef((float) d0 + 0.5F + displacementX, (float) d1 + displacementY + 0.7F, (float) d2 + 0.5F + displacementZ);
                } else {
                    GL11.glTranslatef((float) d0 + 0.5F + displacementX, (float) d1 + displacementY + 0.6F, (float) d2 + 0.5F + displacementZ);
                }
                GL11.glScalef(scaleFactor, scaleFactor, scaleFactor);
                GL11.glRotatef(rotationAngle, 0.0F, 1.0F, 0.0F);
                customRenderItem.doRender(ghostEntityItem, 0, 0, 0, 0, 0);
            }
            GL11.glPopMatrix();
        }
    }
}
Also used : ResourceLocation(net.minecraft.util.ResourceLocation) TEWritingTable(WayofTime.alchemicalWizardry.common.tileEntity.TEWritingTable) ItemBlock(net.minecraft.item.ItemBlock) EntityItem(net.minecraft.entity.item.EntityItem)

Aggregations

TEWritingTable (WayofTime.alchemicalWizardry.common.tileEntity.TEWritingTable)2 IBloodAltar (WayofTime.alchemicalWizardry.api.tile.IBloodAltar)1 EntityItem (net.minecraft.entity.item.EntityItem)1 IInventory (net.minecraft.inventory.IInventory)1 ISidedInventory (net.minecraft.inventory.ISidedInventory)1 ItemBlock (net.minecraft.item.ItemBlock)1 ItemStack (net.minecraft.item.ItemStack)1 TileEntity (net.minecraft.tileentity.TileEntity)1 ResourceLocation (net.minecraft.util.ResourceLocation)1 World (net.minecraft.world.World)1