Search in sources :

Example 41 with EntityType

use of net.minecraft.entity.EntityType in project Scicraft by ScicraftLearn.

the class ExtraDispenserBehavior method registerBehaviors.

/**
 * Main class method
 * Registers all dispenser behaviors
 */
public static void registerBehaviors() {
    /**
     * Register dispenser behavior for shooting out electrons
     * Implements abstract class ProjectileDispenserBehavior to create the correct entity
     *
     * The entity is shot up slight as defined in dispenseSilently in ProjectileDispenserBehavior:
     * direction.getOffsetY() + 0.1F
     */
    DispenserBlock.registerBehavior(Items.ELECTRON, new ProjectileDispenserBehavior() {

        @Override
        protected ProjectileEntity createProjectile(World world, Position position, ItemStack stack) {
            return Util.make(new ElectronEntity(world, position.getX(), position.getY(), position.getZ()), (electronEntity) -> {
                electronEntity.setItem(stack);
            });
        }
    });
    /**
     * Register dispenser behavior for shooting out protons
     * Implements abstract class ProjectileDispenserBehavior to create the correct entity
     *
     * The entity is shot up slight as defined in dispenseSilently in ProjectileDispenserBehavior:
     * direction.getOffsetY() + 0.1F
     */
    DispenserBlock.registerBehavior(Items.PROTON, new ProjectileDispenserBehavior() {

        @Override
        protected ProjectileEntity createProjectile(World world, Position position, ItemStack stack) {
            return Util.make(new ProtonEntity(world, position.getX(), position.getY(), position.getZ()), (protonEntity) -> {
                protonEntity.setItem(stack);
            });
        }
    });
    /**
     * Register dispenser behavior for shooting out neutrons
     * Implements abstract class {@link ProjectileDispenserBehavior} to create the correct entity
     *
     * The entity is shot up slight as defined in dispenseSilently in ProjectileDispenserBehavior:
     * direction.getOffsetY() + 0.1F
     */
    DispenserBlock.registerBehavior(Items.NEUTRON, new ProjectileDispenserBehavior() {

        @Override
        protected ProjectileEntity createProjectile(World world, Position position, ItemStack stack) {
            return Util.make(new NeutronEntity(world, position.getX(), position.getY(), position.getZ()), (neutronEntity) -> {
                neutronEntity.setItem(stack);
            });
        }
    });
    /**
     * Register dispenser behavior for using Entropy Creeper Spawn Egg
     * Implements abstract class {@link ItemDispenserBehavior} to summon the correct entity
     */
    DispenserBlock.registerBehavior(Items.ENTROPY_CREEPER_SPAWN_EGG, new ItemDispenserBehavior() {

        @Override
        protected ItemStack dispenseSilently(BlockPointer pointer, ItemStack stack) {
            Direction direction = pointer.getBlockState().get(DispenserBlock.FACING);
            EntityType entityType = ((SpawnEggItem) stack.getItem()).getEntityType(stack.getNbt());
            try {
                entityType.spawnFromItemStack(pointer.getWorld(), stack, null, pointer.getPos().offset(direction), SpawnReason.DISPENSER, direction != Direction.UP, false);
            } catch (Exception var6) {
                LOGGER.error("Error while dispensing spawn egg from dispenser at {}", pointer.getPos(), var6);
                return ItemStack.EMPTY;
            }
            stack.decrement(1);
            pointer.getWorld().emitGameEvent(GameEvent.ENTITY_PLACE, pointer.getPos());
            return stack;
        }
    });
}
Also used : EntityType(net.minecraft.entity.EntityType) DispenserBehavior(net.minecraft.block.dispenser.DispenserBehavior) PlayerEntity(net.minecraft.entity.player.PlayerEntity) Util(net.minecraft.util.Util) World(net.minecraft.world.World) ProtonEntity(be.uantwerpen.scicraft.entity.ProtonEntity) FluidModificationItem(net.minecraft.item.FluidModificationItem) BlockPointer(net.minecraft.util.math.BlockPointer) BlockHitResult(net.minecraft.util.hit.BlockHitResult) BlockPos(net.minecraft.util.math.BlockPos) ProjectileEntity(net.minecraft.entity.projectile.ProjectileEntity) Direction(net.minecraft.util.math.Direction) ItemStack(net.minecraft.item.ItemStack) NeutronEntity(be.uantwerpen.scicraft.entity.NeutronEntity) Items(be.uantwerpen.scicraft.item.Items) ItemDispenserBehavior(net.minecraft.block.dispenser.ItemDispenserBehavior) ProjectileDispenserBehavior(net.minecraft.block.dispenser.ProjectileDispenserBehavior) SpawnReason(net.minecraft.entity.SpawnReason) SpawnEggItem(net.minecraft.item.SpawnEggItem) ElectronEntity(be.uantwerpen.scicraft.entity.ElectronEntity) DispenserBlock(net.minecraft.block.DispenserBlock) Position(net.minecraft.util.math.Position) GameEvent(net.minecraft.world.event.GameEvent) ProjectileEntity(net.minecraft.entity.projectile.ProjectileEntity) ProtonEntity(be.uantwerpen.scicraft.entity.ProtonEntity) Position(net.minecraft.util.math.Position) NeutronEntity(be.uantwerpen.scicraft.entity.NeutronEntity) ItemDispenserBehavior(net.minecraft.block.dispenser.ItemDispenserBehavior) World(net.minecraft.world.World) ElectronEntity(be.uantwerpen.scicraft.entity.ElectronEntity) Direction(net.minecraft.util.math.Direction) EntityType(net.minecraft.entity.EntityType) ProjectileDispenserBehavior(net.minecraft.block.dispenser.ProjectileDispenserBehavior) ItemStack(net.minecraft.item.ItemStack) BlockPointer(net.minecraft.util.math.BlockPointer)

Example 42 with EntityType

use of net.minecraft.entity.EntityType in project BudschieMorphMod by Budschie.

the class MorphNBTHandler method apply.

@Override
protected void apply(Map<ResourceLocation, JsonElement> objectIn, IResourceManager resourceManagerIn, IProfiler profilerIn) {
    HashMap<EntityType<?>, IMorphNBTHandler> nbtDataHandlers = new HashMap<>();
    MorphManagerHandlers.FALLBACK.setDataHandlers(nbtDataHandlers);
    objectIn.forEach((resourceLocation, json) -> {
        try {
            JsonObject jsonObject = json.getAsJsonObject();
            String entityTypeString = jsonObject.get("entity_type").getAsString();
            // Load in the entity type
            final EntityType<?> entityType = ForgeRegistries.ENTITIES.getValue(new ResourceLocation(entityTypeString));
            if (entityType == null)
                LOGGER.warn("The entity ", entityTypeString, " doesn't exist. Please make sure to only load this when the mod for the entity is present. You can do this by putting this JSON file in \"data/<modname>/morph_nbt\".");
            // Load in the tracked nbt keys as a NBTPath array
            JsonElement tracked = jsonObject.get("tracked_nbt_keys");
            final NBTPath[] trackedNbtKeys = new NBTPath[tracked == null ? 1 : tracked.getAsJsonArray().size() + 1];
            if (tracked != null) {
                for (int i = 0; i < tracked.getAsJsonArray().size(); i++) trackedNbtKeys[i] = NBTPath.valueOf(tracked.getAsJsonArray().get(i).getAsString());
            }
            trackedNbtKeys[trackedNbtKeys.length - 1] = new NBTPath("CustomName");
            JsonElement defaultNBTObject = jsonObject.get("default_nbt");
            final CompoundNBT defaultNBT = defaultNBTObject == null ? new CompoundNBT() : new JsonToNBT(new StringReader(defaultNBTObject.getAsString())).readStruct();
            // Build SpecialDataHandler
            JsonMorphNBTHandler nbtHandler = new JsonMorphNBTHandler(defaultNBT, trackedNbtKeys);
            nbtDataHandlers.put(entityType, nbtHandler);
        } catch (CommandSyntaxException e) {
            e.printStackTrace();
        }
    });
    MorphNBTHandlersLoadedEvent event = new MorphNBTHandlersLoadedEvent(nbtDataHandlers);
    // Fire an event when we are finished...
    MinecraftForge.EVENT_BUS.post(event);
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT) HashMap(java.util.HashMap) JsonObject(com.google.gson.JsonObject) IMorphNBTHandler(de.budschie.bmorph.morph.fallback.IMorphNBTHandler) EntityType(net.minecraft.entity.EntityType) JsonElement(com.google.gson.JsonElement) JsonToNBT(net.minecraft.nbt.JsonToNBT) ResourceLocation(net.minecraft.util.ResourceLocation) StringReader(com.mojang.brigadier.StringReader) CommandSyntaxException(com.mojang.brigadier.exceptions.CommandSyntaxException)

Example 43 with EntityType

use of net.minecraft.entity.EntityType in project trofers by ochotonida.

the class VanillaTrophies method getDisplayInfos.

@Override
public Map<EntityType<?>, DisplayInfo> getDisplayInfos() {
    Map<EntityType<?>, DisplayInfo> result = super.getDisplayInfos();
    result.put(EntityType.GHAST, new DisplayInfo(0, 5, 0, 0.075F));
    result.put(EntityType.SQUID, new DisplayInfo(0, 5, 0, 0.25F));
    result.put(EntityType.PHANTOM, new DisplayInfo(0, 1, 0, 0.25F));
    result.put(EntityType.ELDER_GUARDIAN, new DisplayInfo(0.10625F));
    result.put(EntityType.RAVAGER, new DisplayInfo(0.175F));
    result.put(EntityType.FOX, new DisplayInfo(0.75F, 0, 0.5F, 0, -90, 0, 0.25F));
    result.put(EntityType.COD, new DisplayInfo(-3 / 8F, 1, 0, 0, 0, -90, 0.25F));
    result.put(EntityType.SALMON, new DisplayInfo(-3 / 8F, 1, 0, 0, 0, -90, 0.25F));
    result.put(EntityType.TROPICAL_FISH, new DisplayInfo(-3 / 8F, 1, 0, 0, 0, -90, 0.25F));
    return result;
}
Also used : EntityType(net.minecraft.entity.EntityType) DisplayInfo(trofers.common.trophy.DisplayInfo)

Example 44 with EntityType

use of net.minecraft.entity.EntityType in project Magma-1.16.x by magmafoundation.

the class ForgeHooks method modifyAttributes.

/**
 *  FOR INTERNAL USE ONLY, DO NOT CALL DIRECTLY
 */
@Deprecated
public static void modifyAttributes() {
    ModLoader.get().postEvent(new EntityAttributeCreationEvent(FORGE_ATTRIBUTES));
    Map<EntityType<? extends LivingEntity>, AttributeModifierMap.MutableAttribute> finalMap = new HashMap<>();
    ModLoader.get().postEvent(new EntityAttributeModificationEvent(finalMap));
    finalMap.forEach((k, v) -> {
        AttributeModifierMap modifiers = GlobalEntityTypeAttributes.getSupplier(k);
        AttributeModifierMap.MutableAttribute newMutable = modifiers != null ? new AttributeModifierMap.MutableAttribute(modifiers) : new AttributeModifierMap.MutableAttribute();
        newMutable.combine(v);
        FORGE_ATTRIBUTES.put(k, newMutable.build());
    });
}
Also used : EntityType(net.minecraft.entity.EntityType) LivingEntity(net.minecraft.entity.LivingEntity) EntityAttributeCreationEvent(net.minecraftforge.event.entity.EntityAttributeCreationEvent) HashMap(java.util.HashMap) EntityAttributeModificationEvent(net.minecraftforge.event.entity.EntityAttributeModificationEvent) AttributeModifierMap(net.minecraft.entity.ai.attributes.AttributeModifierMap)

Example 45 with EntityType

use of net.minecraft.entity.EntityType in project LoliServer by Loli-Server.

the class ForgeHooks method modifyAttributes.

/**
 *  FOR INTERNAL USE ONLY, DO NOT CALL DIRECTLY
 */
@Deprecated
public static void modifyAttributes() {
    ModLoader.get().postEvent(new EntityAttributeCreationEvent(FORGE_ATTRIBUTES));
    Map<EntityType<? extends LivingEntity>, AttributeModifierMap.MutableAttribute> finalMap = new HashMap<>();
    ModLoader.get().postEvent(new EntityAttributeModificationEvent(finalMap));
    finalMap.forEach((k, v) -> {
        AttributeModifierMap modifiers = GlobalEntityTypeAttributes.getSupplier(k);
        AttributeModifierMap.MutableAttribute newMutable = modifiers != null ? new AttributeModifierMap.MutableAttribute(modifiers) : new AttributeModifierMap.MutableAttribute();
        newMutable.combine(v);
        FORGE_ATTRIBUTES.put(k, newMutable.build());
    });
}
Also used : EntityType(net.minecraft.entity.EntityType) LivingEntity(net.minecraft.entity.LivingEntity) EntityAttributeCreationEvent(net.minecraftforge.event.entity.EntityAttributeCreationEvent) HashMap(java.util.HashMap) EntityAttributeModificationEvent(net.minecraftforge.event.entity.EntityAttributeModificationEvent) AttributeModifierMap(net.minecraft.entity.ai.attributes.AttributeModifierMap)

Aggregations

EntityType (net.minecraft.entity.EntityType)48 Entity (net.minecraft.entity.Entity)16 ResourceLocation (net.minecraft.util.ResourceLocation)13 LivingEntity (net.minecraft.entity.LivingEntity)11 CompoundNBT (net.minecraft.nbt.CompoundNBT)11 BlockPos (net.minecraft.util.math.BlockPos)11 PlayerEntity (net.minecraft.entity.player.PlayerEntity)9 ItemStack (net.minecraft.item.ItemStack)9 HashMap (java.util.HashMap)6 World (net.minecraft.world.World)5 ArrayList (java.util.ArrayList)4 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)4 EffectInstance (net.minecraft.potion.EffectInstance)4 List (java.util.List)3 Nonnull (javax.annotation.Nonnull)3 MobEntity (net.minecraft.entity.MobEntity)3 TileEntity (net.minecraft.tileentity.TileEntity)3 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)3 IPlacementHandler (com.ldtteam.structurize.placement.handlers.placement.IPlacementHandler)2 Random (java.util.Random)2