diff --git a/build.gradle b/build.gradle index 6c041ab..9661e10 100644 --- a/build.gradle +++ b/build.gradle @@ -14,8 +14,8 @@ apply plugin: 'eclipse' apply plugin: 'maven-publish' version = '1.0' -group = 'com.yourname.modid' // http://maven.apache.org/guides/mini/guide-naming-conventions.html -archivesBaseName = 'modid' +group = 'com.punkcraft.zombiedrop' // http://maven.apache.org/guides/mini/guide-naming-conventions.html +archivesBaseName = 'zombiedrop' sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = '1.8' // Need this here so eclipse task generates correctly. @@ -45,16 +45,16 @@ dependencies { minecraft 'net.minecraftforge:forge:1.12.2-14.23.5.2860' } -// Example for how to get properties into the manifest for reading by the runtime.. +// ZombieDrop for how to get properties into the manifest for reading by the runtime.. jar { manifest { attributes([ - "Specification-Title": "examplemod", - "Specification-Vendor": "examplemodsareus", + "Specification-Title": "zombiedropmod", + "Specification-Vendor": "zombiedropmodsareus", "Specification-Version": "1", // We are version 1 of ourselves "Implementation-Title": project.name, "Implementation-Version": "${version}", - "Implementation-Vendor" :"examplemodsareus", + "Implementation-Vendor" :"zombiedropmodsareus", "Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ") ]) } diff --git a/src/main/java/com/punkcraft/example/Example.java b/src/main/java/com/punkcraft/example/Example.java deleted file mode 100644 index b530012..0000000 --- a/src/main/java/com/punkcraft/example/Example.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.punkcraft.example; - -import net.minecraftforge.fml.common.Mod; -import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; -import net.minecraftforge.fml.common.event.FMLInitializationEvent; - - -@Mod(modid = Example.MODID, name = Example.NAME, version = Example.VERSION) -public class Example { - public static final String MODID = "example"; - public static final String NAME = "Example"; - public static final String VERSION = "1.0"; - - @Mod.EventHandler - public void init(FMLInitializationEvent event) { - } - - @Mod.EventHandler - public void preInit(FMLPreInitializationEvent event) { - } - - -} diff --git a/src/main/java/com/punkcraft/zombiedrop/ServerEventHandler.java b/src/main/java/com/punkcraft/zombiedrop/ServerEventHandler.java new file mode 100644 index 0000000..bb6e505 --- /dev/null +++ b/src/main/java/com/punkcraft/zombiedrop/ServerEventHandler.java @@ -0,0 +1,47 @@ +package com.punkcraft.zombiedrop; + +import net.minecraft.entity.monster.EntityZombie; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.DamageSource; +import net.minecraft.world.World; +import net.minecraft.entity.item.EntityItem; +import net.minecraftforge.event.entity.living.LivingDropsEvent; +import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.relauncher.Side; + +@Mod.EventBusSubscriber(value = Side.SERVER, modid = ZombieDrop.MODID) +public class ServerEventHandler { + + /** + * Обработчик события дропа предметов. + */ + @SubscribeEvent + public static void onLivingDrops(LivingDropsEvent event) { + // Проверяем, что убитая сущность - это зомби + if (event.getEntityLiving() instanceof EntityZombie) { + EntityZombie zombie = (EntityZombie) event.getEntityLiving(); + DamageSource source = event.getSource(); + + // Проверяем, что зомби был убит игроком или мобом + if (source.getTrueSource() != null || source.isExplosion()) { + // Генерируем случайное число от 0 до 99 + int random = zombie.world.rand.nextInt(100); + + // Если число меньше 4, добавляем эндерпёрл в дроп + if (random < 4) { + ItemStack enderPearl = new ItemStack(Item.getItemById(368), 1); // ID эндерпёрла: 368 + World world = zombie.world; + double x = zombie.posX; + double y = zombie.posY; + double z = zombie.posZ; + + // Создаем EntityItem и добавляем его в дроп + EntityItem entityItem = new EntityItem(world, x, y, z, enderPearl); + event.getDrops().add(entityItem); + } + } + } + } +} diff --git a/src/main/java/com/punkcraft/zombiedrop/ZombieDrop.java b/src/main/java/com/punkcraft/zombiedrop/ZombieDrop.java new file mode 100644 index 0000000..a562996 --- /dev/null +++ b/src/main/java/com/punkcraft/zombiedrop/ZombieDrop.java @@ -0,0 +1,26 @@ +package com.punkcraft.zombiedrop; + +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.common.event.FMLInitializationEvent; +import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; +import net.minecraftforge.fml.relauncher.Side; + +@Mod(modid = ZombieDrop.MODID, name = ZombieDrop.NAME, version = ZombieDrop.VERSION) +public class ZombieDrop { + public static final String MODID = "zombiedrop"; + public static final String NAME = "ZombieDrop"; + public static final String VERSION = "1.0"; + + @Mod.EventHandler + public void preInit(FMLPreInitializationEvent event) { + // Регистрируем слушатель событий только на серверной стороне + if (event.getSide() == Side.SERVER) { + MinecraftForge.EVENT_BUS.register(new ServerEventHandler()); + } + } + + @Mod.EventHandler + public void init(FMLInitializationEvent event) { + } +} diff --git a/src/main/resources/mcmod.info b/src/main/resources/mcmod.info index 4e65d29..2e79d21 100644 --- a/src/main/resources/mcmod.info +++ b/src/main/resources/mcmod.info @@ -1,7 +1,7 @@ [ { - "modid": "example", - "name": "Example", + "modid": "zombiedrop", + "name": "ZombieDrop", "description": "", "version": "${version}", "mcversion": "${mcversion}",