Follow along with the video below to see how to install our site as a web app on your home screen.
Примечание: This feature may not be available in some browsers.
public class CustomLivingDrops {
public static double rand;
@ForgeSubscribe
public void dropPig(LivingDropsEvent event) {
if (event.source.getDamageType().equals("player")) {
rand = Math.random();
if (event.entityLiving instanceof EntityPig) {
if (rand < 0.25D) {
event.entityLiving.dropItem(Item.leather.itemID, 1);
}
}
}
}
}
public static double rand;
public Random r = new Random();
@ForgeSubscribe
public void DropHandler(LivingDropsEvent event) {
if(event.entityLiving instanceof EntityPigZombie) {
event.entityLiving.entityDropItem(new ItemStack(vazkii.tinkerer.common.item.ModItems.kamiResource.itemID, 1, 6), r.nextInt(40));
}
}
Спасибо, не учёл, что нужно сделать проверку исходит ли урон от игрока или от внешнего объекта.Volkula написал(а):Код:public class CustomLivingDrops { public static double rand; @ForgeSubscribe public void dropPig(LivingDropsEvent event) { if (event.source.getDamageType().equals("player")) { rand = Math.random(); if (event.entityLiving instanceof EntityPig) { if (rand < 0.25D) { event.entityLiving.dropItem(Item.leather.itemID, 1); } } } } }
То есть представленные выше варианты не являются корректными, и нужно делать рандомDragon2488 написал(а):И в итоге получил херню из за того что рандом на сервере и клиенте разный. делай рандом с сидом.
Math.random()*WorldSeed;
По моему на 1.6.4 такого нетуDragon2488 написал(а):Ты перешел свои границы. world.getRNG
Dragon2488 написал(а):И в итоге получил херню из за того что рандом на сервере и клиенте разный.
for(int i1 = 0; i1 < mobData.getItemsData().size(); i1++) {
MobItem item = mobData.getItemsData().get(i1);
double random = Math.random();
double randomFor = (double) item.getDropChance() / 100;
if(random < randomFor) {
int count = MathHelper.getRandomIntegerInRange(new Random(), item.getCountFrom(), item.getCountTo());
eventEntity.entityDropItem(new ItemStack(item.getID(), count, item.getMetaData()), 1.0F);
}
}
this.disableXpDrop((EntityLivingBase) eventEntity);
double random = Math.random();
double randomFor = (double) mobData.getXpDropChance() / 100;
if(random < randomFor) {
int count = MathHelper.getRandomIntegerInRange(new Random(), mobData.getXpDropFrom(), mobData.getXpDropTo());
while (count > 0)
{
int j = EntityXPOrb.getXPSplit(i);
count -= j;
eventEntity.worldObj.spawnEntityInWorld(new EntityXPOrb(eventEntity.worldObj, eventEntity.posX, eventEntity.posY, eventEntity.posZ, count));
}
}