Search in sources :

Example 1 with CustomDrop

use of com.dreammaster.modcustomdrops.CustomDrops.CustomDrop in project NewHorizonsCoreMod by GTNewHorizons.

the class CustomDropsFactory method createCustomDropEntry.

public CustomDrop createCustomDropEntry(String pMobClassName) {
    CustomDrop cdr = new CustomDrop();
    cdr.mEntityClassName = pMobClassName;
    return cdr;
}
Also used : CustomDrop(com.dreammaster.modcustomdrops.CustomDrops.CustomDrop)

Example 2 with CustomDrop

use of com.dreammaster.modcustomdrops.CustomDrops.CustomDrop in project NewHorizonsCoreMod by GTNewHorizons.

the class CustomDropsHandler method HandleCustomDrops.

/*
     * @SubscribeEvent public void
     * LivingDeathEvent(net.minecraftforge.event.entity.living.LivingDeathEvent
     * pEvent) { try { EntityLivingBase tEntity = pEvent.entityLiving; UUID
     * tUUID = null; EntityPlayer tEP = null;
     * 
     * if (pEvent.source.getEntity() != null) { if (pEvent.source.getEntity()
     * instanceof EntityPlayer) { tEP = (EntityPlayer)pEvent.source.getEntity();
     * tUUID = tEP.getUniqueID(); if (_mDeathDebugPlayers.contains(tUUID))
     * PlayerChatHelper.SendInfo(tEP, String.format("Killed entity: [%s]",
     * tEntity.getClass().getName())); } }
     * 
     * if (tEP == null) // Not doing anything, only players are valid return; if
     * (tEP instanceof net.minecraftforge.common.util.FakePlayer) // Nope, no
     * fakeplayers return;
     * 
     * CustomDrop tCustomDrop = _mCustomDrops.FindDropEntry(tEntity); if
     * (tCustomDrop == null) return; // no custom drop defined for this mob,
     * skipping
     * 
     * HandleCustomDrops(tCustomDrop, tEntity, tEP); } catch (Exception e) {
     * e.printStackTrace(); } }
     */
private void HandleCustomDrops(CustomDrop tCustomDrop, EntityLivingBase tEntity, EntityPlayer tEP, ArrayList<EntityItem> pDropList) {
    try {
        if (_mPersistedDB == null) {
            _mPersistedDB = new PersistedDataBase(DimensionManager.getCurrentSaveRootDirectory(), "CustomDrops.dat", Refstrings.COLLECTIONID);
        }
        for (Drop dr : tCustomDrop.getDrops()) {
            String tDropID = dr.getIdentifier();
            String tUserID = tEP.getUniqueID().toString();
            String tFinalDropID = String.format("%s.%s", tUserID, tDropID);
            int tFinalAmount = dr.getAmount();
            if (MainRegistry.Rnd.nextInt(100) > dr.getChance())
                continue;
            // Is this drop limited?
            if (dr.getLimitedDropCount() > 0) {
                // if it is, check if player already got this item. If so,
                // skip this drop
                int tDropCount = _mPersistedDB.getValueAsInt(tFinalDropID, 0);
                if (tDropCount >= dr.getLimitedDropCount())
                    continue;
                else {
                    // Player will get the drop this time, increase his
                    // counter
                    _mPersistedDB.setValue(tFinalDropID, ++tDropCount);
                }
            }
            if (dr.getIsRandomAmount())
                tFinalAmount = 1 + MainRegistry.Rnd.nextInt(dr.getAmount() - 1);
            ItemStack tDropStack = ItemDescriptor.fromString(dr.getItemName()).getItemStackwNBT(tFinalAmount, dr.mTag);
            if (tDropStack == null)
                _mLogger.error(String.format("CustomDrop ID %s failed to drop"));
            else {
                EntityItem tDropEntity = new EntityItem(tEntity.worldObj, tEntity.posX, tEntity.posY, tEntity.posZ, tDropStack);
                pDropList.add(tDropEntity);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : PersistedDataBase(eu.usrv.yamcore.persisteddata.PersistedDataBase) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem) Drop(com.dreammaster.modcustomdrops.CustomDrops.CustomDrop.Drop) CustomDrop(com.dreammaster.modcustomdrops.CustomDrops.CustomDrop)

Example 3 with CustomDrop

use of com.dreammaster.modcustomdrops.CustomDrops.CustomDrop in project NewHorizonsCoreMod by GTNewHorizons.

the class CustomDropsHandler method onMobDrops.

@SubscribeEvent
public void onMobDrops(LivingDropsEvent pEvent) {
    try {
        EntityLivingBase tEntity = pEvent.entityLiving;
        UUID tUUID = null;
        EntityPlayer tEP = null;
        if (pEvent.source.getEntity() != null) {
            if (pEvent.source.getEntity() instanceof EntityPlayer) {
                tEP = (EntityPlayer) pEvent.source.getEntity();
                tUUID = tEP.getUniqueID();
                if (_mDeathDebugPlayers.contains(tUUID))
                    PlayerChatHelper.SendInfo(tEP, String.format("Killed entity: [%s]", tEntity.getClass().getName()));
            }
        }
        if (// Not doing anything, only players are valid
        tEP == null)
            return;
        if (// Nope,
        tEP instanceof net.minecraftforge.common.util.FakePlayer)
            // fakeplayers
            return;
        CustomDrop tCustomDrop = _mCustomDrops.FindDropEntry(tEntity);
        // no custom drop defined for this
        if (tCustomDrop == null)
            return;
        // mob, skipping
        HandleCustomDrops(tCustomDrop, tEntity, tEP, pEvent.drops);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : CustomDrop(com.dreammaster.modcustomdrops.CustomDrops.CustomDrop) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityPlayer(net.minecraft.entity.player.EntityPlayer) UUID(java.util.UUID) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Example 4 with CustomDrop

use of com.dreammaster.modcustomdrops.CustomDrops.CustomDrop in project NewHorizonsCoreMod by GTNewHorizons.

the class CustomDropsHandler method VerifyConfig.

private boolean VerifyConfig(CustomDrops pDropListToCheck) {
    boolean tSuccess = true;
    for (CustomDrop X : pDropListToCheck.getCustomDrops()) {
        for (Drop Y : X.getDrops()) {
            if (ItemDescriptor.fromString(Y.getItemName()) == null) {
                _mLogger.error(String.format("In ItemDropID: [%s], can't find item [%s]", Y.getIdentifier(), Y.getItemName()));
                tSuccess = false;
            }
            if (Y.mTag != null && !Y.mTag.isEmpty()) {
                try {
                    NBTTagCompound tNBT = (NBTTagCompound) JsonToNBT.func_150315_a(Y.mTag);
                    if (tNBT == null)
                        tSuccess = false;
                } catch (Exception e) {
                    _mLogger.error(String.format("In ItemDropID: [%s], NBTTag is invalid", Y.getIdentifier()));
                    tSuccess = false;
                }
            }
        }
    }
    return tSuccess;
}
Also used : CustomDrop(com.dreammaster.modcustomdrops.CustomDrops.CustomDrop) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Drop(com.dreammaster.modcustomdrops.CustomDrops.CustomDrop.Drop) CustomDrop(com.dreammaster.modcustomdrops.CustomDrops.CustomDrop)

Example 5 with CustomDrop

use of com.dreammaster.modcustomdrops.CustomDrops.CustomDrop in project NewHorizonsCoreMod by GTNewHorizons.

the class CustomDropsHandler method InitSampleConfig.

public void InitSampleConfig() {
    Drop pigDiamondLimitedDrop = _mCfF.createDrop("minecraft:diamond", "sample_Pig_DiamondDrop", "{Lore: [\"Oh, shiny!\"]}", 1, false, 100, 5);
    Drop pigCakeUnlimitedDrop = _mCfF.createDrop("minecraft:cake", "sample_Pig_CakeDrop", 1, false, 100, 0);
    Drop pigRandomCharcoalDrop = _mCfF.createDrop("minecraft:coal:1", "sample_Pig_CharcoalDrop", 5, true, 100, 0);
    CustomDrop pigDrop = _mCfF.createCustomDropEntry("eu.usrv.dummyEntity.ImbaSampleDragon");
    pigDrop.getDrops().add(pigDiamondLimitedDrop);
    pigDrop.getDrops().add(pigCakeUnlimitedDrop);
    pigDrop.getDrops().add(pigRandomCharcoalDrop);
    _mCustomDrops = new CustomDrops();
    _mCustomDrops.getCustomDrops().add(pigDrop);
}
Also used : CustomDrop(com.dreammaster.modcustomdrops.CustomDrops.CustomDrop) Drop(com.dreammaster.modcustomdrops.CustomDrops.CustomDrop.Drop) CustomDrop(com.dreammaster.modcustomdrops.CustomDrops.CustomDrop)

Aggregations

CustomDrop (com.dreammaster.modcustomdrops.CustomDrops.CustomDrop)5 Drop (com.dreammaster.modcustomdrops.CustomDrops.CustomDrop.Drop)3 SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)1 PersistedDataBase (eu.usrv.yamcore.persisteddata.PersistedDataBase)1 UUID (java.util.UUID)1 EntityLivingBase (net.minecraft.entity.EntityLivingBase)1 EntityItem (net.minecraft.entity.item.EntityItem)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 ItemStack (net.minecraft.item.ItemStack)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1