Search in sources :

Example 1 with IEntityDefinition

use of minetweaker.api.entity.IEntityDefinition in project CraftTweaker by CraftTweaker.

the class ForgeEventHandler method mobDrop.

@SubscribeEvent
public void mobDrop(LivingDropsEvent ev) {
    Entity entity = ev.getEntity();
    IEntityDefinition entityDefinition = MineTweakerAPI.game.getEntity(EntityList.getEntityString(ev.getEntity()));
    if (entityDefinition != null) {
        if (!entityDefinition.getDropsToAdd().isEmpty()) {
            entityDefinition.getDropsToAdd().forEach((key, val) -> {
                EntityItem item = null;
                if (val.getMin() == 0 && val.getMax() == 0) {
                    item = new EntityItem(entity.world, entity.posX + 0.5, entity.posY + 0.5, entity.posZ + 0.5, ((ItemStack) key.getInternal()).copy());
                } else {
                    item = new EntityItem(entity.world, entity.posX + 0.5, entity.posY + 0.5, entity.posZ + 0.5, ((ItemStack) key.withAmount(val.getRandom()).getInternal()).copy());
                }
                ev.getDrops().add(item);
            });
        }
        if (ev.getSource().getEntity() instanceof EntityPlayer) {
            if (!entityDefinition.getDropsToAddPlayerOnly().isEmpty()) {
                entityDefinition.getDropsToAddPlayerOnly().forEach((key, val) -> {
                    EntityItem item = null;
                    if (val.getMin() == 0 && val.getMax() == 0) {
                        item = new EntityItem(entity.world, entity.posX + 0.5, entity.posY + 0.5, entity.posZ + 0.5, ((ItemStack) key.getInternal()).copy());
                    } else {
                        item = new EntityItem(entity.world, entity.posX + 0.5, entity.posY + 0.5, entity.posZ + 0.5, ((ItemStack) key.withAmount(val.getRandom()).getInternal()).copy());
                    }
                    ev.getDrops().add(item);
                });
            }
        }
        if (!entityDefinition.getDropsToRemove().isEmpty()) {
            List<EntityItem> removedDrops = new ArrayList<>();
            entityDefinition.getDropsToRemove().forEach(drop -> {
                // if(drop.matches(new MCItemStack()))
                ev.getDrops().forEach(drops -> {
                    if (drop.matches(new MCItemStack(drops.getEntityItem()))) {
                        removedDrops.add(drops);
                    }
                });
            });
            ev.getDrops().removeAll(removedDrops);
        }
    }
}
Also used : MCItemStack(minetweaker.mc1102.item.MCItemStack) IEntityDefinition(minetweaker.api.entity.IEntityDefinition) EntityPlayer(net.minecraft.entity.player.EntityPlayer) MCItemStack(minetweaker.mc1102.item.MCItemStack) IItemStack(minetweaker.api.item.IItemStack) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 2 with IEntityDefinition

use of minetweaker.api.entity.IEntityDefinition in project CraftTweaker by CraftTweaker.

the class ForgeEventHandler method mobDrop.

@SubscribeEvent
public void mobDrop(LivingDropsEvent ev) {
    Entity entity = ev.getEntity();
    IEntityDefinition entityDefinition = MineTweakerAPI.game.getEntity(EntityList.getEntityString(ev.getEntity()));
    if (entityDefinition != null) {
        if (!entityDefinition.getDropsToAdd().isEmpty()) {
            entityDefinition.getDropsToAdd().forEach((key, val) -> {
                EntityItem item = null;
                if (val.getMin() == 0 && val.getMax() == 0) {
                    item = new EntityItem(entity.world, entity.posX + 0.5, entity.posY + 0.5, entity.posZ + 0.5, ((ItemStack) key.getInternal()).copy());
                } else {
                    item = new EntityItem(entity.world, entity.posX + 0.5, entity.posY + 0.5, entity.posZ + 0.5, ((ItemStack) key.withAmount(val.getRandom()).getInternal()).copy());
                }
                ev.getDrops().add(item);
            });
        }
        if (ev.getSource().getEntity() instanceof EntityPlayer) {
            if (!entityDefinition.getDropsToAddPlayerOnly().isEmpty()) {
                entityDefinition.getDropsToAddPlayerOnly().forEach((key, val) -> {
                    EntityItem item = null;
                    if (val.getMin() == 0 && val.getMax() == 0) {
                        item = new EntityItem(entity.world, entity.posX + 0.5, entity.posY + 0.5, entity.posZ + 0.5, ((ItemStack) key.getInternal()).copy());
                    } else {
                        item = new EntityItem(entity.world, entity.posX + 0.5, entity.posY + 0.5, entity.posZ + 0.5, ((ItemStack) key.withAmount(val.getRandom()).getInternal()).copy());
                    }
                    ev.getDrops().add(item);
                });
            }
        }
        if (!entityDefinition.getDropsToRemove().isEmpty()) {
            List<EntityItem> removedDrops = new ArrayList<>();
            entityDefinition.getDropsToRemove().forEach(drop -> {
                // if(drop.matches(new MCItemStack()))
                ev.getDrops().forEach(drops -> {
                    if (drop.matches(new MCItemStack(drops.getEntityItem()))) {
                        removedDrops.add(drops);
                    }
                });
            });
            ev.getDrops().removeAll(removedDrops);
        }
    }
}
Also used : MCItemStack(minetweaker.mc1112.item.MCItemStack) IEntityDefinition(minetweaker.api.entity.IEntityDefinition) EntityPlayer(net.minecraft.entity.player.EntityPlayer) IItemStack(minetweaker.api.item.IItemStack) ItemStack(net.minecraft.item.ItemStack) MCItemStack(minetweaker.mc1112.item.MCItemStack) EntityItem(net.minecraft.entity.item.EntityItem) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 3 with IEntityDefinition

use of minetweaker.api.entity.IEntityDefinition in project CraftTweaker by CraftTweaker.

the class MCGame method getEntity.

@Override
public IEntityDefinition getEntity(String entityName) {
    for (IEntityDefinition ent : getEntities()) {
        if (ent.getName().equalsIgnoreCase(entityName)) {
            return ent;
        }
    }
    boolean needsReloading = false;
    for (ResourceLocation res : ForgeRegistries.ENTITIES.getKeys()) {
        if (res.getResourcePath().equalsIgnoreCase(entityName)) {
            needsReloading = true;
            break;
        }
    }
    if (needsReloading) {
        ENTITY_DEFINITIONS.clear();
        ForgeRegistries.ENTITIES.forEach((entry) -> {
            ENTITY_DEFINITIONS.add(new MCEntityDefinition(entry.getEntityClass(), entry.getName()));
        });
    }
    return getEntities().stream().filter(ent -> ent.getName().equals(entityName)).findFirst().orElse(null);
}
Also used : MCEntityDefinition(minetweaker.mc1112.entity.MCEntityDefinition) IEntityDefinition(minetweaker.api.entity.IEntityDefinition) ResourceLocation(net.minecraft.util.ResourceLocation)

Example 4 with IEntityDefinition

use of minetweaker.api.entity.IEntityDefinition in project CraftTweaker by CraftTweaker.

the class MCGame method getEntity.

@Override
public IEntityDefinition getEntity(String entityName) {
    for (IEntityDefinition ent : getEntities()) {
        if (ent.getName().equalsIgnoreCase(entityName)) {
            return ent;
        }
    }
    boolean needsReloading = false;
    for (String s : EntityList.NAME_TO_CLASS.keySet()) {
        if (s.equalsIgnoreCase(entityName)) {
            needsReloading = true;
            break;
        }
    }
    if (needsReloading) {
        ENTITY_DEFINITIONS.clear();
        EntityList.CLASS_TO_NAME.forEach((key, val) -> {
            ENTITY_DEFINITIONS.add(new MCEntityDefinition(key, val));
        });
    }
    return getEntities().stream().filter(ent -> ent.getName().equals(entityName)).findFirst().orElse(null);
}
Also used : MCEntityDefinition(minetweaker.mc1102.entity.MCEntityDefinition) IEntityDefinition(minetweaker.api.entity.IEntityDefinition)

Aggregations

IEntityDefinition (minetweaker.api.entity.IEntityDefinition)4 IItemStack (minetweaker.api.item.IItemStack)2 EntityItem (net.minecraft.entity.item.EntityItem)2 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 ItemStack (net.minecraft.item.ItemStack)2 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)2 MCEntityDefinition (minetweaker.mc1102.entity.MCEntityDefinition)1 MCItemStack (minetweaker.mc1102.item.MCItemStack)1 MCEntityDefinition (minetweaker.mc1112.entity.MCEntityDefinition)1 MCItemStack (minetweaker.mc1112.item.MCItemStack)1 ResourceLocation (net.minecraft.util.ResourceLocation)1