Search in sources :

Example 46 with OreDictItemData

use of gregapi.oredict.OreDictItemData in project gregtech6 by GregTech6.

the class ToolCompat method prospectStone.

public static boolean prospectStone(Block aBlock, byte aMeta, long aQuality, List<String> aChatReturn, World aWorld, byte aSide, int aX, int aY, int aZ) {
    Block tBlock;
    int tX = aX, tY = aY, tZ = aZ, tQuality = (int) UT.Code.bind(1, 20, aQuality + 4);
    for (int i = 0, j = tQuality; i < j; i++) {
        tX -= OFFX[aSide];
        tY -= OFFY[aSide];
        tZ -= OFFZ[aSide];
        // The Strings in this do not want to be localized, and not even Backup Lang wants to work.
        tBlock = aWorld.getBlock(tX, tY, tZ);
        if (tBlock == Blocks.lava || tBlock == Blocks.flowing_lava) {
            if (aChatReturn != null)
                aChatReturn.add("There is Lava behind this Rock");
            break;
        }
        if (tBlock instanceof BlockLiquid || tBlock instanceof IFluidBlock) {
            if (aChatReturn != null)
                aChatReturn.add("There is a Fluid behind this Rock");
            break;
        }
        if (tBlock instanceof BlockSilverfish || !WD.hasCollide(aWorld, tX, tY, tZ, tBlock)) {
            if (aChatReturn != null)
                aChatReturn.add("There is an Air Pocket behind this Rock");
            break;
        }
        if (i < 4)
            if (tBlock != aBlock || aMeta != aWorld.getBlockMetadata(tX, tY, tZ)) {
                if (aChatReturn != null)
                    aChatReturn.add("Material is changing behind this Rock");
                break;
            }
    }
    Random tRandom = new Random(aX ^ aY ^ aZ ^ aSide);
    for (int i = 0, j = 1 + 2 * tQuality, k = tQuality * tQuality; i < k; i++) {
        tX = aX - tQuality + tRandom.nextInt(j);
        tY = aY - tQuality + tRandom.nextInt(j);
        tZ = aZ - tQuality + tRandom.nextInt(j);
        tBlock = aWorld.getBlock(tX, tY, tZ);
        if (tBlock != NB && tBlock != Blocks.obsidian && tBlock != BlocksGT.RockOres) {
            OreDictItemData tAssotiation = OM.anyassociation((tBlock instanceof IBlockRetrievable ? ((IBlockRetrievable) tBlock).getItemStackFromBlock(aWorld, tX, tY, tZ, SIDE_INVALID) : ST.make(tBlock, 1, aWorld.getBlockMetadata(tX, tY, tZ))));
            if (tAssotiation != null && tAssotiation.mPrefix.containsAny(TD.Prefix.STANDARD_ORE, TD.Prefix.DENSE_ORE)) {
                if (aChatReturn != null)
                    aChatReturn.add("Found traces of " + tAssotiation.mMaterial.mMaterial.getLocal());
                return T;
            }
        }
    }
    if (aChatReturn != null && aChatReturn.isEmpty())
        aChatReturn.add("No traces of Ore found");
    return T;
}
Also used : Random(java.util.Random) OreDictItemData(gregapi.oredict.OreDictItemData) IFluidBlock(net.minecraftforge.fluids.IFluidBlock) IFluidBlock(net.minecraftforge.fluids.IFluidBlock)

Example 47 with OreDictItemData

use of gregapi.oredict.OreDictItemData in project gregtech6 by GregTech6.

the class GT_Proxy method onPlayerInteraction.

@SubscribeEvent
public void onPlayerInteraction(PlayerInteractEvent aEvent) {
    if (aEvent.entityPlayer == null || aEvent.entityPlayer.worldObj == null || aEvent.action == null || aEvent.world.provider == null)
        return;
    String aName = aEvent.entityPlayer.getCommandSenderName(), aNameLowercase = aName.toLowerCase();
    if (!aEvent.world.isRemote && CHECKED_PLAYERS.add(aName)) {
        if (mSupporterListSilver.contains(aEvent.entityPlayer.getUniqueID().toString()) || mSupporterListGold.contains(aEvent.entityPlayer.getUniqueID().toString()) || mSupporterListSilver.contains(aNameLowercase) || mSupporterListGold.contains(aNameLowercase)) {
            if (!MultiTileEntityCertificate.ALREADY_RECEIVED.contains(aNameLowercase)) {
                if (UT.Inventories.addStackToPlayerInventoryOrDrop(aEvent.entityPlayer, MultiTileEntityCertificate.getCertificate(1, aName), F)) {
                    MultiTileEntityCertificate.ALREADY_RECEIVED.add(aNameLowercase);
                    UT.Entities.sendchat(aEvent.entityPlayer, CHAT_GREG + "Thank you, " + aName + ", for Supporting GregTech! Here, have a Certificate. ;)");
                }
            }
        }
    }
    ItemStack aStack = aEvent.entityPlayer.getCurrentEquippedItem();
    if (aStack != null && aStack.stackSize > 0) {
        if (aEvent.action == PlayerInteractEvent.Action.RIGHT_CLICK_AIR) {
            if (aStack.getItem() == Items.glass_bottle) {
                aEvent.setCanceled(T);
                if (aEvent.world.isRemote) {
                    GT_API.api_proxy.sendUseItemPacket(aEvent.entityPlayer, aEvent.world, aStack);
                    return;
                }
                MovingObjectPosition tTarget = WD.getMOP(aEvent.world, aEvent.entityPlayer, T);
                if (tTarget == null || tTarget.typeOfHit != MovingObjectPosition.MovingObjectType.BLOCK || !aEvent.world.canMineBlock(aEvent.entityPlayer, tTarget.blockX, tTarget.blockY, tTarget.blockZ) || !aEvent.entityPlayer.canPlayerEdit(tTarget.blockX, tTarget.blockY, tTarget.blockZ, tTarget.sideHit, aStack))
                    return;
                Block tBlock = aEvent.world.getBlock(tTarget.blockX, tTarget.blockY, tTarget.blockZ);
                if (tBlock == Blocks.water || tBlock == Blocks.flowing_water) {
                    if (aEvent.world.getBlockMetadata(tTarget.blockX, tTarget.blockY, tTarget.blockZ) != 0)
                        return;
                    for (int i = 0; i < 3 && aStack.stackSize > 0; i++) {
                        if (aStack.stackSize == 1) {
                            aEvent.entityPlayer.inventory.mainInventory[aEvent.entityPlayer.inventory.currentItem] = ST.make(Items.potionitem, 1, 0);
                        } else {
                            ST.use(aEvent.entityPlayer, aStack);
                            UT.Inventories.addStackToPlayerInventoryOrDrop(aEvent.entityPlayer, ST.make(Items.potionitem, 1, 0), F);
                        }
                    }
                    if (!WD.infiniteWater(aEvent.world, tTarget.blockX, tTarget.blockY, tTarget.blockZ))
                        aEvent.world.setBlockToAir(tTarget.blockX, tTarget.blockY, tTarget.blockZ);
                    ST.update(aEvent.entityPlayer);
                    return;
                }
                if (tBlock == BlocksGT.River || WD.waterstream(tBlock)) {
                    ItemStack tStack = FL.fill(FL.Water.make(Integer.MAX_VALUE), aStack, F, T, F, T);
                    if (tStack == null)
                        return;
                    ST.use(aEvent.entityPlayer, aStack);
                    UT.Inventories.addStackToPlayerInventoryOrDrop(aEvent.entityPlayer, tStack, F);
                    return;
                }
                if (tBlock == BlocksGT.Ocean) {
                    ItemStack tStack = FL.fill(FL.Ocean.make(Integer.MAX_VALUE), aStack, F, T, F, T);
                    if (tStack == null)
                        return;
                    ST.use(aEvent.entityPlayer, aStack);
                    UT.Inventories.addStackToPlayerInventoryOrDrop(aEvent.entityPlayer, tStack, F);
                    return;
                }
                if (tBlock == BlocksGT.Swamp) {
                    ItemStack tStack = FL.fill(FL.Dirty_Water.make(Integer.MAX_VALUE), aStack, F, T, F, T);
                    if (tStack == null)
                        return;
                    ST.use(aEvent.entityPlayer, aStack);
                    UT.Inventories.addStackToPlayerInventoryOrDrop(aEvent.entityPlayer, tStack, F);
                    return;
                }
                return;
            }
            if (aStack.getItem() == Items.bucket) {
                MovingObjectPosition tTarget = WD.getMOP(aEvent.world, aEvent.entityPlayer, T);
                if (tTarget != null && tTarget.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) {
                    Block tBlock = aEvent.world.getBlock(tTarget.blockX, tTarget.blockY, tTarget.blockZ);
                    if (tBlock instanceof BlockWaterlike && tBlock != BlocksGT.River)
                        aEvent.setCanceled(T);
                }
                return;
            }
        }
        if (aEvent.action == PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK) {
            if (IL.ERE_Spray_Repellant.equal(aStack, T, T)) {
                if (!aEvent.world.isRemote && aStack.getItem().onItemUse(aStack, aEvent.entityPlayer, aEvent.world, aEvent.x, aEvent.y, aEvent.z, aEvent.face, 0.5F, 0.5F, 0.5F)) {
                    aEvent.setCanceled(T);
                    UT.Inventories.addStackToPlayerInventoryOrDrop(aEvent.entityPlayer, IL.Spray_Empty.get(1), aEvent.world, aEvent.x, aEvent.y, aEvent.z);
                    return;
                }
            } else if (aStack.getItem() == Items.flint_and_steel) {
                if (!aEvent.world.isRemote && !UT.Entities.hasInfiniteItems(aEvent.entityPlayer) && RNGSUS.nextInt(100) >= mFlintChance) {
                    aEvent.setCanceled(T);
                    aStack.damageItem(1, aEvent.entityPlayer);
                    if (aStack.getItemDamage() >= aStack.getMaxDamage())
                        ST.use(aEvent.entityPlayer, aStack);
                    return;
                }
                List<String> tChatReturn = new ArrayListNoNulls<>();
                long tDamage = IBlockToolable.Util.onToolClick(TOOL_igniter, aStack.getItemDamage() * 10000, 1, aEvent.entityPlayer, tChatReturn, aEvent.entityPlayer.inventory, aEvent.entityPlayer.isSneaking(), aStack, aEvent.world, (byte) aEvent.face, aEvent.x, aEvent.y, aEvent.z, 0.5F, 0.5F, 0.5F);
                UT.Entities.sendchat(aEvent.entityPlayer, tChatReturn, F);
                if (tDamage > 0) {
                    aEvent.setCanceled(T);
                    UT.Sounds.send(aEvent.world, SFX.MC_IGNITE, 1.0F, 1.0F, aEvent.x, aEvent.y, aEvent.z);
                    if (!UT.Entities.hasInfiniteItems(aEvent.entityPlayer)) {
                        aStack.damageItem(UT.Code.bindInt(UT.Code.units(tDamage, 10000, 1, T)), aEvent.entityPlayer);
                        if (aStack.getItemDamage() >= aStack.getMaxDamage())
                            ST.use(aEvent.entityPlayer, aStack);
                    }
                    return;
                }
            } else if (IL.Food_Toast_Sliced.equal(aStack, F, T) || IL.Food_Toasted_Sliced.equal(aStack, F, T)) {
                int tUsed = Math.min(16, aStack.stackSize);
                if (!aEvent.world.isRemote && aEvent.entityPlayer.isSneaking() && MultiTileEntityRegistry.getRegistry("gt.multitileentity").getItem(32105, ST.save("sandwich.0", ST.amount(tUsed, aStack))).tryPlaceItemIntoWorld(aEvent.entityPlayer, aEvent.world, aEvent.x, aEvent.y, aEvent.z, (byte) aEvent.face, 0.5F, 0.5F, 0.5F)) {
                    ST.use(aEvent.entityPlayer, aStack, tUsed);
                    aEvent.setCanceled(T);
                }
            } else if (aStack.getItem() == Items.stick || IL.Stick.equal(aStack) || OM.is("stickAnyNormalWood", aStack)) {
                if (!aEvent.world.isRemote && aEvent.entityPlayer.isSneaking() && MultiTileEntityRegistry.getRegistry("gt.multitileentity").getItem(32073).tryPlaceItemIntoWorld(aEvent.entityPlayer, aEvent.world, aEvent.x, aEvent.y, aEvent.z, (byte) aEvent.face, 0.5F, 0.5F, 0.5F)) {
                    ST.use(aEvent.entityPlayer, aStack);
                    aEvent.setCanceled(T);
                }
            } else if (aStack.getItem() == Items.flint) {
                if (!aEvent.world.isRemote && aEvent.entityPlayer.isSneaking() && MultiTileEntityRegistry.getRegistry("gt.multitileentity").getItem(32074, ST.save(NBT_VALUE, ST.amount(1, aStack))).tryPlaceItemIntoWorld(aEvent.entityPlayer, aEvent.world, aEvent.x, aEvent.y, aEvent.z, (byte) aEvent.face, 0.5F, 0.5F, 0.5F)) {
                    ST.use(aEvent.entityPlayer, aStack);
                    aEvent.setCanceled(T);
                }
            } else {
                if (!aEvent.world.isRemote && aEvent.entityPlayer.isSneaking() && ST.block(aStack) == NB) {
                    OreDictItemData tData = OM.anyassociation_(aStack);
                    if (tData != null) {
                        if (tData.mPrefix == OP.rockGt || tData.mPrefix == OP.oreRaw) {
                            if (MultiTileEntityRegistry.getRegistry("gt.multitileentity").getItem(32074, ST.save(NBT_VALUE, ST.amount(1, aStack))).tryPlaceItemIntoWorld(aEvent.entityPlayer, aEvent.world, aEvent.x, aEvent.y, aEvent.z, (byte) aEvent.face, 0.5F, 0.5F, 0.5F)) {
                                ST.use(aEvent.entityPlayer, aStack);
                                aEvent.setCanceled(T);
                            }
                        }
                        if (tData.mPrefix == OP.ingot)
                            if (!MD.BOTA.mLoaded || tData.mMaterial.mMaterial.mOriginalMod != MD.BOTA || Blocks.beacon != aEvent.world.getBlock(aEvent.x, aEvent.y, aEvent.z)) {
                                if (MultiTileEntityRegistry.getRegistry("gt.multitileentity").getItem(32084, ST.save(NBT_VALUE, aStack)).tryPlaceItemIntoWorld(aEvent.entityPlayer, aEvent.world, aEvent.x, aEvent.y, aEvent.z, (byte) aEvent.face, 0.5F, 0.5F, 0.5F)) {
                                    ST.use(aEvent.entityPlayer, aStack, aStack.stackSize);
                                    aEvent.setCanceled(T);
                                }
                            }
                        if (tData.mPrefix == OP.plate) {
                            if (MultiTileEntityRegistry.getRegistry("gt.multitileentity").getItem(32085, ST.save(NBT_VALUE, aStack)).tryPlaceItemIntoWorld(aEvent.entityPlayer, aEvent.world, aEvent.x, aEvent.y, aEvent.z, (byte) aEvent.face, 0.5F, 0.5F, 0.5F)) {
                                ST.use(aEvent.entityPlayer, aStack, aStack.stackSize);
                                aEvent.setCanceled(T);
                            }
                        }
                        if (tData.mPrefix == OP.plateGem) {
                            if (MultiTileEntityRegistry.getRegistry("gt.multitileentity").getItem(32086, ST.save(NBT_VALUE, aStack)).tryPlaceItemIntoWorld(aEvent.entityPlayer, aEvent.world, aEvent.x, aEvent.y, aEvent.z, (byte) aEvent.face, 0.5F, 0.5F, 0.5F)) {
                                ST.use(aEvent.entityPlayer, aStack, aStack.stackSize);
                                aEvent.setCanceled(T);
                            }
                        }
                        if (tData.mPrefix == OP.scrapGt) {
                            if (MultiTileEntityRegistry.getRegistry("gt.multitileentity").getItem(32103, ST.save(NBT_VALUE, aStack)).tryPlaceItemIntoWorld(aEvent.entityPlayer, aEvent.world, aEvent.x, aEvent.y, aEvent.z, (byte) aEvent.face, 0.5F, 0.5F, 0.5F)) {
                                ST.use(aEvent.entityPlayer, aStack, aStack.stackSize);
                                aEvent.setCanceled(T);
                            }
                        }
                    }
                }
            }
        }
    } else {
        if (aEvent.action == PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK) {
            if (aEvent.entityPlayer.isBurning()) {
                List<String> tChatReturn = new ArrayListNoNulls<>();
                long tDamage = IBlockToolable.Util.onToolClick(TOOL_igniter, Long.MAX_VALUE, 1, aEvent.entityPlayer, tChatReturn, aEvent.entityPlayer.inventory, aEvent.entityPlayer.isSneaking(), NI, aEvent.world, (byte) aEvent.face, aEvent.x, aEvent.y, aEvent.z, 0.5F, 0.5F, 0.5F);
                UT.Entities.sendchat(aEvent.entityPlayer, tChatReturn, F);
                if (tDamage > 0) {
                    UT.Sounds.send(aEvent.world, SFX.MC_IGNITE, 1.0F, 1.0F, aEvent.x, aEvent.y, aEvent.z);
                    aEvent.setCanceled(T);
                }
            }
        }
    }
}
Also used : MovingObjectPosition(net.minecraft.util.MovingObjectPosition) OreDictItemData(gregapi.oredict.OreDictItemData) Block(net.minecraft.block.Block) BlockWaterlike(gregtech.blocks.fluids.BlockWaterlike) List(java.util.List) ItemStack(net.minecraft.item.ItemStack) ArrayListNoNulls(gregapi.code.ArrayListNoNulls) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Example 48 with OreDictItemData

use of gregapi.oredict.OreDictItemData in project gregtech6 by GregTech6.

the class OM method data.

public static OreDictItemData data(String aOre) {
    OreDictPrefix tPrefix = OreDictPrefix.get(aOre);
    if (tPrefix == null)
        return null;
    OreDictMaterial tMaterial = OreDictMaterial.MATERIAL_MAP.get(aOre.replaceFirst(tPrefix.mNameInternal, ""));
    if (tMaterial == null)
        return null;
    return new OreDictItemData(tPrefix, tMaterial);
}
Also used : OreDictMaterial(gregapi.oredict.OreDictMaterial) OreDictPrefix(gregapi.oredict.OreDictPrefix) OreDictItemData(gregapi.oredict.OreDictItemData)

Example 49 with OreDictItemData

use of gregapi.oredict.OreDictItemData in project gregtech6 by GregTech6.

the class RecipeMapChisel method findRecipe.

@Override
public Recipe findRecipe(IHasWorldAndCoords aTileEntity, Recipe aRecipe, boolean aNotUnificated, long aSize, ItemStack aSpecialSlot, FluidStack[] aFluids, ItemStack... aInputs) {
    Recipe rRecipe = super.findRecipe(aTileEntity, aRecipe, aNotUnificated, aSize, aSpecialSlot, aFluids, aInputs);
    if (aInputs == null || aInputs.length < 1 || aInputs[0] == null || GAPI_POST.mFinishedServerStarted <= 0)
        return rRecipe;
    if (rRecipe == null) {
        OreDictItemData tData = OM.anyassociation(aInputs[0]);
        if (tData != null && (tData.mPrefix == OP.blockSolid || (tData.mPrefix.contains(TD.Prefix.STORAGE_BASED) && !tData.mPrefix.contains(TD.Prefix.IS_CONTAINER)))) {
            List<ItemStack> tList = OreDictManager.getOres(tData.toString(), T);
            int tSize = tList.size();
            if (tSize > 0) {
                ItemStack tOutput = ST.amount(1, tList.get(0));
                tSize--;
                for (int i = 0; i < tSize; i++) if (ST.equal(aInputs[0], tList.get(i))) {
                    tOutput = ST.amount(1, tList.get(i + 1));
                    break;
                }
                return new Recipe(F, F, T, ST.array(ST.amount(1, aInputs[0])), ST.array(tOutput), null, null, null, null, 96, 12, 0);
            }
        }
    }
    return rRecipe;
}
Also used : Recipe(gregapi.recipes.Recipe) OreDictItemData(gregapi.oredict.OreDictItemData) ItemStack(net.minecraft.item.ItemStack)

Example 50 with OreDictItemData

use of gregapi.oredict.OreDictItemData in project gregtech6 by GregTech6.

the class AdvancedCrafting1ToY method matches.

@Override
public boolean matches(InventoryCrafting aGrid, World aWorld) {
    ItemStack tStack = null;
    OreDictMaterial rMaterial = null;
    int tInventorySize = aGrid.getSizeInventory(), tCounter = 0, tEmpty = 0;
    if (tInventorySize < 1 + mEmpty)
        return F;
    for (int i = 0; i < tInventorySize; i++) {
        tStack = aGrid.getStackInSlot(i);
        if (ST.valid(tStack)) {
            OreDictItemData tData = OM.anydata_(tStack);
            if (tData == null || tData.mPrefix != mInput)
                return F;
            if (rMaterial == null)
                rMaterial = tData.mMaterial.mMaterial;
            else if (rMaterial != tData.mMaterial.mMaterial)
                return F;
            tCounter++;
            continue;
        }
        if (tCounter == 0)
            tEmpty++;
        if (i - tCounter + 1 + mEmpty - tEmpty >= tInventorySize)
            return F;
    }
    return rMaterial != null && tCounter == 1 && tEmpty % mInput.mShapelessManagersSingle.size() == mEmpty && hasOutputFor(rMaterial);
}
Also used : OreDictMaterial(gregapi.oredict.OreDictMaterial) OreDictItemData(gregapi.oredict.OreDictItemData) ItemStack(net.minecraft.item.ItemStack)

Aggregations

OreDictItemData (gregapi.oredict.OreDictItemData)64 ItemStack (net.minecraft.item.ItemStack)41 OreDictMaterial (gregapi.oredict.OreDictMaterial)20 FluidStack (net.minecraftforge.fluids.FluidStack)16 ArrayListNoNulls (gregapi.code.ArrayListNoNulls)12 OreDictMaterialStack (gregapi.oredict.OreDictMaterialStack)11 EntityPlayer (net.minecraft.entity.player.EntityPlayer)10 Recipe (gregapi.recipes.Recipe)9 Block (net.minecraft.block.Block)9 SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)5 List (java.util.List)5 OreDictPrefix (gregapi.oredict.OreDictPrefix)4 IOreDictListenerEvent (gregapi.oredict.event.IOreDictListenerEvent)4 OreDictListenerEvent_Names (gregapi.oredict.event.OreDictListenerEvent_Names)4 HashSetNoNulls (gregapi.code.HashSetNoNulls)3 IItemContainer (gregapi.code.IItemContainer)3 ItemStackContainer (gregapi.code.ItemStackContainer)3 PacketDeathPoint (gregapi.network.packets.PacketDeathPoint)3 EntityLivingBase (net.minecraft.entity.EntityLivingBase)3 Item (net.minecraft.item.Item)3