Search in sources :

Example 6 with EntityItemFrame

use of net.minecraft.entity.item.EntityItemFrame in project minecolonies by Minecolonies.

the class AbstractEntityAIStructure method spawnEntity.

/**
     * Iterates through all entities and spawns them
     * Suppressing Sonar Rule Squid:S3047
     * The rule thinks we can merge the two forge loops iterating over resources
     * But in this case the rule does not apply because that would destroy the logic.
     */
@SuppressWarnings(MULTIPLE_LOOPS_OVER_THE_SAME_SET_SHOULD_BE_COMBINED)
private Boolean spawnEntity(@NotNull final Structure.StructureBlock currentBlock) {
    final Template.EntityInfo entityInfo = currentBlock.entity;
    if (entityInfo == null) {
        return true;
    }
    final Entity entity = getEntityFromEntityInfoOrNull(entityInfo);
    if (entity != null && !isEntityAtPosition(entity, world)) {
        final List<ItemStack> request = new ArrayList<>();
        if (entity instanceof EntityItemFrame) {
            final ItemStack stack = ((EntityItemFrame) entity).getDisplayedItem();
            if (stack != null) {
                stack.setCount(stack.getCount() + 1);
                request.add(stack);
            }
            request.add(new ItemStack(Items.ITEM_FRAME, 1));
        } else if (entity instanceof EntityArmorStand) {
            request.add(entity.getPickedResult(new RayTraceResult(worker)));
            entity.getArmorInventoryList().forEach(request::add);
        } else {
            request.add(entity.getPickedResult(new RayTraceResult(worker)));
        }
        if (!Configurations.builderInfiniteResources) {
            for (final ItemStack stack : request) {
                if (checkOrRequestItems(stack)) {
                    return false;
                }
            }
            //Surpress
            for (final ItemStack stack : request) {
                if (stack == null) {
                    continue;
                }
                final int slot = worker.findFirstSlotInInventoryWith(stack.getItem(), stack.getItemDamage());
                if (slot != -1) {
                    new InvWrapper(getInventory()).extractItem(slot, 1, false);
                    reduceNeededResources(stack);
                }
            }
        }
        entity.setUniqueId(UUID.randomUUID());
        entity.setLocationAndAngles(entity.posX, entity.posY, entity.posZ, entity.rotationYaw, entity.rotationPitch);
        if (!world.spawnEntity(entity)) {
            Log.getLogger().info("Failed to spawn entity");
        }
    }
    return true;
}
Also used : Entity(net.minecraft.entity.Entity) EntityItemFrame(net.minecraft.entity.item.EntityItemFrame) InvWrapper(net.minecraftforge.items.wrapper.InvWrapper) ArrayList(java.util.ArrayList) RayTraceResult(net.minecraft.util.math.RayTraceResult) EntityArmorStand(net.minecraft.entity.item.EntityArmorStand) ItemStack(net.minecraft.item.ItemStack) Template(net.minecraft.world.gen.structure.template.Template)

Example 7 with EntityItemFrame

use of net.minecraft.entity.item.EntityItemFrame in project ArsMagica2 by Mithion.

the class AMEventHandler method onEntityConstructing.

@SubscribeEvent
public void onEntityConstructing(EntityConstructing event) {
    if (event.entity instanceof EntityLivingBase) {
        event.entity.registerExtendedProperties(ExtendedProperties.identifier, new ExtendedProperties());
        ((EntityLivingBase) event.entity).getAttributeMap().registerAttribute(ArsMagicaApi.maxManaBonus);
        ((EntityLivingBase) event.entity).getAttributeMap().registerAttribute(ArsMagicaApi.maxBurnoutBonus);
        ((EntityLivingBase) event.entity).getAttributeMap().registerAttribute(ArsMagicaApi.xpGainModifier);
        ((EntityLivingBase) event.entity).getAttributeMap().registerAttribute(ArsMagicaApi.burnoutReductionRate);
        ((EntityLivingBase) event.entity).getAttributeMap().registerAttribute(ArsMagicaApi.manaRegenTimeModifier);
        if (event.entity instanceof EntityPlayer) {
            event.entity.registerExtendedProperties(RiftStorage.identifier, new RiftStorage());
            event.entity.registerExtendedProperties(AffinityData.identifier, new AffinityData());
            event.entity.registerExtendedProperties(SkillData.identifier, new SkillData((EntityPlayer) event.entity));
        }
    } else if (event.entity instanceof EntityItemFrame) {
        AMCore.proxy.itemFrameWatcher.startWatchingFrame((EntityItemFrame) event.entity);
    }
}
Also used : RiftStorage(am2.playerextensions.RiftStorage) SkillData(am2.playerextensions.SkillData) EntityItemFrame(net.minecraft.entity.item.EntityItemFrame) AffinityData(am2.playerextensions.AffinityData) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ExtendedProperties(am2.playerextensions.ExtendedProperties) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Aggregations

EntityItemFrame (net.minecraft.entity.item.EntityItemFrame)7 ItemStack (net.minecraft.item.ItemStack)4 BlockPos (net.minecraft.util.math.BlockPos)3 ArrayList (java.util.ArrayList)2 Entity (net.minecraft.entity.Entity)2 EntityArmorStand (net.minecraft.entity.item.EntityArmorStand)2 RayTraceResult (net.minecraft.util.math.RayTraceResult)2 AffinityData (am2.playerextensions.AffinityData)1 ExtendedProperties (am2.playerextensions.ExtendedProperties)1 RiftStorage (am2.playerextensions.RiftStorage)1 SkillData (am2.playerextensions.SkillData)1 BuildingBuilder (com.minecolonies.coremod.colony.buildings.BuildingBuilder)1 SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)1 GenericBlock (mcjty.lib.container.GenericBlock)1 DimletKey (mcjty.rftoolsdim.dimensions.dimlets.DimletKey)1 RarityRandomSelector (mcjty.rftoolsdim.varia.RarityRandomSelector)1 Block (net.minecraft.block.Block)1 EntityMob (net.minecraft.entity.monster.EntityMob)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 TileEntity (net.minecraft.tileentity.TileEntity)1