use of eu.usrv.yamcore.persisteddata.PersistedDataBase 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();
}
}
Aggregations