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;
}
});
}
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);
}
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;
}
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());
});
}
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());
});
}
Aggregations