net.minecraft.entity.EntityType Java Examples

The following examples show how to use net.minecraft.entity.EntityType. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Protocol_1_10.java    From multiconnect with MIT License 6 votes vote down vote up
private static Entity changeEntityType(Entity entity, EntityType<?> newType) {
    ClientWorld world = (ClientWorld) entity.world;
    Entity destEntity = newType.create(world);
    if (destEntity == null) {
        return entity;
    }

    // copy the entity
    destEntity.fromTag(entity.toTag(new CompoundTag()));
    destEntity.trackedX = entity.trackedX;
    destEntity.trackedY = entity.trackedY;
    destEntity.trackedZ = entity.trackedZ;

    // replace entity in world and exchange entity id
    int entityId = entity.getEntityId();
    world.removeEntity(entityId);
    destEntity.setEntityId(entityId);
    world.addEntity(entityId, destEntity);

    // exchange data tracker (this may be part of a series of data tracker updates, need the same data tracker instance)
    DataTrackerManager.transferDataTracker(entity, destEntity);
    return destEntity;
}
 
Example #2
Source File: SkeletonEntityMixin.java    From carpet-extra with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void onStruckByLightning(LightningEntity lightning)
{
    if (!this.world.isClient && !this.removed && CarpetExtraSettings.renewableWitherSkeletons)
    {
        WitherSkeletonEntity witherSkelly = new WitherSkeletonEntity(EntityType.WITHER_SKELETON, this.world);
        witherSkelly.refreshPositionAndAngles(this.getX(), this.getY(), this.getZ(), this.yaw, this.pitch);
        witherSkelly.initialize(this.world, this.world.getLocalDifficulty(new BlockPos(witherSkelly)), SpawnType.CONVERSION, (EntityData) null, (CompoundTag) null);
        witherSkelly.setAiDisabled(this.isAiDisabled());
        
        if (this.hasCustomName())
        {
            witherSkelly.setCustomName(this.getCustomName());
            witherSkelly.setCustomNameVisible(this.isCustomNameVisible());
        }
        
        this.world.spawnEntity(witherSkelly);
        this.remove();
    }
    else
    {
        super.onStruckByLightning(lightning);
    }
}
 
Example #3
Source File: Protocol_1_10.java    From multiconnect with MIT License 6 votes vote down vote up
private void mutateEntityTypeRegistry(ISimpleRegistry<EntityType<?>> registry) {
    //registry.purge(EntityType.ELDER_GUARDIAN);
    //registry.purge(EntityType.WITHER_SKELETON);
    //registry.purge(EntityType.STRAY);
    //registry.purge(EntityType.HUSK);
    //registry.purge(EntityType.ZOMBIE_VILLAGER);
    //registry.purge(EntityType.SKELETON_HORSE);
    //registry.purge(EntityType.ZOMBIE_HORSE);
    //registry.purge(EntityType.DONKEY);
    //registry.purge(EntityType.MULE);
    registry.purge(EntityType.EVOKER_FANGS);
    registry.purge(EntityType.EVOKER);
    registry.purge(EntityType.VEX);
    registry.purge(EntityType.VINDICATOR);
    registry.purge(EntityType.LLAMA);
    registry.purge(EntityType.LLAMA_SPIT);
}
 
Example #4
Source File: SpiderLairFeature.java    From the-hallow with MIT License 6 votes vote down vote up
@Override
public boolean generate(IWorld iWorld, ChunkGenerator<? extends ChunkGeneratorConfig> chunkGenerator, Random random, BlockPos pos, DefaultFeatureConfig defaultFeatureConfig) {
	if (iWorld.getBlockState(pos.down()).getBlock() == HallowedBlocks.DECEASED_GRASS_BLOCK) {
		setSpawner(iWorld, pos, EntityType.SPIDER);
		
		for (int i = 0; i < 64; ++i) {
			BlockPos pos_2 = pos.add(random.nextInt(6) - random.nextInt(6), random.nextInt(3) - random.nextInt(3), random.nextInt(6) - random.nextInt(6));
			if (iWorld.isAir(pos_2) || iWorld.getBlockState(pos_2).getBlock() == HallowedBlocks.DECEASED_GRASS_BLOCK) {
				iWorld.setBlockState(pos_2, Blocks.COBWEB.getDefaultState(), 2);
			}
		}
		
		BlockPos chestPos = pos.add(random.nextInt(4) - random.nextInt(4), 0, random.nextInt(4) - random.nextInt(4));
		iWorld.setBlockState(chestPos, StructurePiece.method_14916(iWorld, chestPos, Blocks.CHEST.getDefaultState()), 2);
		LootableContainerBlockEntity.setLootTable(iWorld, random, chestPos, TheHallow.id("chests/spider_lair"));
		
		return true;
	} else {
		return false;
	}
}
 
Example #5
Source File: SpawnHelperMixin.java    From fabric-carpet with MIT License 6 votes vote down vote up
@Redirect(method = "spawnEntitiesInChunk", at = @At(
        value = "INVOKE",
        target = "Lnet/minecraft/entity/EntityType;create(Lnet/minecraft/world/World;)Lnet/minecraft/entity/Entity;"
))
private static Entity create(EntityType<?> entityType, World world_1)
{
    if (CarpetSettings.lagFreeSpawning)
    {
        Map<EntityType, Entity> precookedMobs = ((WorldInterface)world_1).getPrecookedMobs();
        if (precookedMobs.containsKey(entityType))
            //this mob has been <init>'s but not used yet
            return precookedMobs.get(entityType);
        Entity e = entityType.create(world_1);
        precookedMobs.put(entityType, e);
        return e;
    }
    return entityType.create(world_1);
}
 
Example #6
Source File: HallowedEvents.java    From the-hallow with MIT License 6 votes vote down vote up
public static void init() {
	WitchTickCallback.EVENT.register((witch) -> {
		if (!witch.hasStatusEffect(StatusEffects.WATER_BREATHING)) {
			if (witch.getEntityWorld().hasRain(witch.getBlockPos().up())) {
				witch.damage(DamageSource.DROWN, 4.0F);
			} else if (witch.checkWaterState() && !witch.updateMovementInFluid(HallowedTags.Fluids.WITCH_WATER)) {
				witch.damage(DamageSource.DROWN, 4.0F);
			}
		}
		return ActionResult.PASS;
	});
	
	LootTableLoadingCallback.EVENT.register(((resourceManager, lootManager, id, supplier, setter) -> {
		if (id.equals(EntityType.WITCH.getLootTableId())) {
			supplier.withPool(FabricLootPoolBuilder.builder().withCondition(RandomChanceLootCondition.builder(0.01f)).withEntry(ItemEntry.builder(HallowedItems.GOLDEN_CANDY_CORN)));
		}
	}));
}
 
Example #7
Source File: MixinEntityTypeBuilder.java    From patchwork-api with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Inject(method = "build", at = @At("RETURN"))
private void onBuildReturn(String id, CallbackInfoReturnable<EntityType> cir) {
	PatchworkEntityTypeExtensions type = (PatchworkEntityTypeExtensions) cir.getReturnValue();

	if (updateInterval != null) {
		type.patchwork$setUpdateInterval(updateInterval);
	}

	if (trackingRange != null) {
		type.patchwork$setTrackingRange(trackingRange);
	}

	if (shouldRecieveVelocityUpdates != null) {
		type.patchwork$setShouldReceiveVelocityUpdates(shouldRecieveVelocityUpdates);
	}
}
 
Example #8
Source File: MixinSpawnEggItem.java    From patchwork-api with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public String getCreatorModId(ItemStack itemStack) {
	final Item item = itemStack.getItem();
	Identifier defaultId = Registry.ITEM.getDefaultId();
	Identifier id = Registry.ITEM.getId(item);

	if (defaultId.equals(id) && item != Registry.ITEM.get(defaultId)) {
		return null;
	} else {
		final String namespace = id.getNamespace();

		if ("minecraft".equals(namespace)) {
			final EntityType<?> type = ((SpawnEggItem) item).getEntityType(itemStack.getTag());
			id = Registry.ENTITY_TYPE.getId(type);
			defaultId = Registry.ENTITY_TYPE.getDefaultId();

			if (defaultId.equals(id) && type != Registry.ENTITY_TYPE.get(defaultId)) {
				return namespace;
			}

			return id.getNamespace();
		}

		return namespace;
	}
}
 
Example #9
Source File: MixinSpawnHelper.java    From patchwork-api with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Inject(method = "canSpawn(Lnet/minecraft/entity/SpawnRestriction$Location;Lnet/minecraft/world/CollisionView;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/entity/EntityType;)Z",
		at = @At(value = "INVOKE", target = "net/minecraft/world/CollisionView.getBlockState(Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/block/BlockState;"),
		cancellable = true)
private static void handleCustomSpawnRestrictionLocation(SpawnRestriction.Location location, CollisionView world, BlockPos pos, EntityType<?> type, CallbackInfoReturnable<Boolean> callback) {
	PatchworkSpawnRestrictionLocation patchworkLocation = (PatchworkSpawnRestrictionLocation) (Object) location;

	if (patchworkLocation.patchwork_useVanillaBehavior()) {
		return;
	}

	callback.setReturnValue(patchworkLocation.canSpawnAt(world, pos, type));
}
 
Example #10
Source File: MobAI.java    From fabric-carpet with MIT License 5 votes vote down vote up
public static List<String> availbleTypes()
{
    Set<EntityType> types = new HashSet<>();
    for (TrackingType type: TrackingType.values())
    {
        types.addAll(type.types);
    }
    return types.stream().map(t -> Registry.ENTITY_TYPE.getId(t).getPath()).collect(Collectors.toList());
}
 
Example #11
Source File: TntEntityMixin.java    From fabric-carpet with MIT License 5 votes vote down vote up
@Inject(method = "<init>(Lnet/minecraft/entity/EntityType;Lnet/minecraft/world/World;)V", at = @At("RETURN"))
private void initTNTLoggerPrime(EntityType<? extends TntEntity> entityType_1, World world_1, CallbackInfo ci)
{
    if (LoggerRegistry.__tnt && !world_1.isClient)
    {
        logHelper = new TNTLogHelper();
    }
}
 
Example #12
Source File: FeatureUtils.java    From the-hallow with MIT License 5 votes vote down vote up
default void setSpawner(IWorld world, BlockPos pos, EntityType<?> entity) {
	world.setBlockState(pos, Blocks.SPAWNER.getDefaultState(), 2);
	BlockEntity be = world.getBlockEntity(pos);
	if (be instanceof MobSpawnerBlockEntity) {
		((MobSpawnerBlockEntity) be).getLogic().setEntityId(entity);
	}
}
 
Example #13
Source File: EvolvedZombieEntity.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
public EvolvedZombieEntity(EntityType<? extends EvolvedZombieEntity> entityType, World world) {
    super(entityType, world);
    this.setHealth(20);
    this.initGoals();
    this.setCanPickUpLoot(true);
    this.brain.setDefaultActivity(Activity.CORE);
    HashSet<Activity> otherActivities = new HashSet<>();
    otherActivities.add(Activity.IDLE);
    this.brain.setCoreActivities(otherActivities);
}
 
Example #14
Source File: SpawnReporter.java    From fabric-carpet with MIT License 5 votes vote down vote up
public static List<BaseText> recent_spawns(World world, EntityCategory creature_type)
{
    List<BaseText> lst = new ArrayList<>();
    if ((track_spawns == 0L))
    {
        lst.add(Messenger.s("Spawn tracking not started"));
        return lst;
    }
    String type_code = creature_type.getName();
    
    lst.add(Messenger.s(String.format("Recent %s spawns:",type_code)));
    for (Pair<EntityType, BlockPos> pair : spawned_mobs.get(Pair.of(world.getDimension().getType(),creature_type)).keySet())
    {
        lst.add( Messenger.c(
                "w  - ",
                Messenger.tp("wb",pair.getRight()),
                String.format("w : %s", pair.getLeft().getName().getString())
                ));
    }
    
    if (lst.size()==1)
    {
        lst.add(Messenger.s(" - Nothing spawned yet, sorry."));
    }
    return lst;

}
 
Example #15
Source File: MixinEntity.java    From patchwork-api with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Inject(method = "<init>", at = @At("RETURN"))
public void hookConstructor(EntityType<?> type, World world, CallbackInfo ci) {
	Entity entity = (Entity) (Object) this;

	this.standingEyeHeight = EntityEvents.getEyeHeight(entity, EntityPose.STANDING, dimensions, getEyeHeight(EntityPose.STANDING, dimensions));

	EntityEvents.onEntityConstruct(entity);
}
 
Example #16
Source File: MixinClientPlayNetworkHandler.java    From multiconnect with MIT License 5 votes vote down vote up
@Inject(method = "onEntitySpawn", at = @At("TAIL"))
private void onOnEntitySpawn(EntitySpawnS2CPacket packet, CallbackInfo ci) {
    if (ConnectionInfo.protocolVersion <= Protocols.V1_13_2) {
        if (packet.getEntityTypeId() == EntityType.ITEM
                || packet.getEntityTypeId() == EntityType.ARROW
                || packet.getEntityTypeId() == EntityType.SPECTRAL_ARROW
                || packet.getEntityTypeId() == EntityType.TRIDENT) {
            onVelocityUpdate(new EntityVelocityUpdateS2CPacket(packet.getId(),
                    new Vec3d(packet.getVelocityX(), packet.getVelocityY(), packet.getVelocityZ())));
        }
    }
}
 
Example #17
Source File: MixinEntityTypeBuilder.java    From patchwork-api with GNU Lesser General Public License v2.1 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Inject(method = "build", at = @At("RETURN"))
private void onBuildReturn(String id, CallbackInfoReturnable<EntityType<T>> callback) {
	ClientEntitySpawner<T> spawner = (ClientEntitySpawner<T>) callback.getReturnValue();

	spawner.patchwork$setCustomClientFactory(this.customClientFactory);
}
 
Example #18
Source File: FMLPlayMessages.java    From patchwork-api with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static void handle(SpawnEntity msg, PacketContext context) {
	PatchworkNetworking.enqueueWork(context.getTaskQueue(), () -> {
		EntityType<?> type = Registry.ENTITY_TYPE.get(msg.typeId);

		if (type.equals(Registry.ENTITY_TYPE.get(Registry.ENTITY_TYPE.getDefaultId()))) {
			throw new RuntimeException(String.format("Could not spawn entity (id %d) with unknown type at (%f, %f, %f)", msg.entityId, msg.posX, msg.posY, msg.posZ));
		}

		ClientWorld world = MinecraftClient.getInstance().world;

		Entity entity = ((ClientEntitySpawner<?>) type).customClientSpawn(msg, world);

		if (entity == null) {
			return;
		}

		entity.updateTrackedPosition(msg.posX, msg.posY, msg.posZ);
		entity.updatePositionAndAngles(msg.posX, msg.posY, msg.posZ, (msg.yaw * 360) / 256.0F, (msg.pitch * 360) / 256.0F);
		entity.setHeadYaw((msg.headYaw * 360) / 256.0F);
		entity.setYaw((msg.headYaw * 360) / 256.0F);

		entity.setEntityId(msg.entityId);
		entity.setUuid(msg.uuid);
		world.addEntity(msg.entityId, entity);
		entity.setVelocity(msg.velX / 8000.0, msg.velY / 8000.0, msg.velZ / 8000.0);

		if (entity instanceof IEntityAdditionalSpawnData) {
			((IEntityAdditionalSpawnData) entity).readSpawnData(msg.buf);
		}
	});
}
 
Example #19
Source File: MixinShearsItem.java    From patchwork-api with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public boolean useOnEntity(ItemStack stack, PlayerEntity playerIn, LivingEntity entity, Hand hand) {
	if (entity.world.isClient) {
		return false;
	}

	// Avoid duplicating vanilla interactions
	if (this == Items.SHEARS) {
		EntityType<?> type = entity.getType();

		if (type == EntityType.MOOSHROOM || type == EntityType.SHEEP || type == EntityType.SNOW_GOLEM) {
			return false;
		}
	}

	if (entity instanceof IShearable) {
		IShearable target = (IShearable) entity;
		BlockPos pos = entity.getBlockPos();

		if (target.isShearable(stack, entity.world, pos)) {
			Shearables.shearEntity(stack, entity.world, pos, target);
		}

		return true;
	}

	return false;
}
 
Example #20
Source File: MixinMooshroomEntity.java    From patchwork-api with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public List<ItemStack> onSheared(ItemStack item, IWorld world, BlockPos pos, int fortune) {
	List<ItemStack> drops = new ArrayList<>();
	this.world.addParticle(ParticleTypes.EXPLOSION, this.x, this.y + (double) (this.getHeight() / 2.0F), this.z, 0.0D, 0.0D, 0.0D);

	if (!this.world.isClient) {
		this.remove();

		CowEntity cow = EntityType.COW.create(this.world);
		cow.refreshPositionAndAngles(this.x, this.y, this.z, this.yaw, this.pitch);
		cow.setHealth(this.getHealth());
		cow.field_6283 = this.field_6283;

		if (this.hasCustomName()) {
			cow.setCustomName(this.getCustomName());
		}

		this.world.spawnEntity(cow);
		Block mushroom = this.getMooshroomType().getMushroomState().getBlock();

		// TODO: Fixes forge bug where shearing brown mooshrooms always drop red mushrooms (Fixed in 1.15)
		for (int i = 0; i < 5; ++i) {
			drops.add(new ItemStack(mushroom));
		}

		this.playSound(SoundEvents.ENTITY_MOOSHROOM_SHEAR, 1.0F, 1.0F);
	}

	return drops;
}
 
Example #21
Source File: EntitySpawnGlobalS2CPacket_1_15_2.java    From multiconnect with MIT License 5 votes vote down vote up
@Override
public void apply(ClientPlayPacketListener listener) {
    NetworkThreadUtils.forceMainThread(this, listener, MinecraftClient.getInstance());
    if (entityTypeId == 1) {
        LightningEntity lightning = EntityType.LIGHTNING_BOLT.create(MinecraftClient.getInstance().world);
        if (lightning == null) {
            return;
        }
        lightning.setPos(x, y, z);
        listener.onEntitySpawn(new EntitySpawnS2CPacket(lightning));
    }
}
 
Example #22
Source File: LivingEntity_scarpetEventsMixin.java    From fabric-carpet with MIT License 4 votes vote down vote up
public LivingEntity_scarpetEventsMixin(EntityType<?> type, World world)
{
    super(type, world);
}
 
Example #23
Source File: ArmorStandEntity_scarpetMarkerMixin.java    From fabric-carpet with MIT License 4 votes vote down vote up
protected ArmorStandEntity_scarpetMarkerMixin(EntityType<? extends LivingEntity> entityType_1, World world_1)
{
    super(entityType_1, world_1);
}
 
Example #24
Source File: MixinLivingEntity.java    From multiconnect with MIT License 4 votes vote down vote up
public MixinLivingEntity(EntityType<?> type, World world) {
    super(type, world);
}
 
Example #25
Source File: PlayerEntityMixin.java    From carpet-extra with GNU Lesser General Public License v3.0 4 votes vote down vote up
protected PlayerEntityMixin(EntityType<? extends LivingEntity> entityType, World world)
{
    super(entityType, world);
}
 
Example #26
Source File: ChickenEntityMixin.java    From carpet-extra with GNU Lesser General Public License v3.0 4 votes vote down vote up
protected ChickenEntityMixin(EntityType<? extends AnimalEntity> entityType_1, World world_1)
{
    super(entityType_1, world_1);
}
 
Example #27
Source File: SpiderEntityMixin.java    From carpet-extra with GNU Lesser General Public License v3.0 4 votes vote down vote up
protected SpiderEntityMixin(EntityType<? extends HostileEntity> type, World world)
{
    super(type, world);
}
 
Example #28
Source File: HopperMinecartEntity_transferItemsOutFeatureMixin.java    From carpet-extra with GNU Lesser General Public License v3.0 4 votes vote down vote up
public HopperMinecartEntity_transferItemsOutFeatureMixin(EntityType<? extends HopperMinecartEntity> entityType_1, World world_1) {
    super(entityType_1, world_1);
    this.currentBlockPos = BlockPos.ORIGIN;
}
 
Example #29
Source File: FunctionsImpl.java    From Sandbox with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public Entity.Type entityTypeEntityFunction(Entity e) {
    return (Entity.Type) EntityType.fromTag(WrappingUtil.convert(e).toTag(new net.minecraft.nbt.CompoundTag())).orElse(null);
}
 
Example #30
Source File: LivingEntityMixin.java    From carpet-extra with GNU Lesser General Public License v3.0 4 votes vote down vote up
public LivingEntityMixin(EntityType<?> entityType_1, World world_1)
{
    super(entityType_1, world_1);
}