net.minecraft.entity.mob.MobEntity Java Examples

The following examples show how to use net.minecraft.entity.mob.MobEntity. 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: MobEspHack.java    From Wurst7 with GNU General Public License v3.0 6 votes vote down vote up
private void renderBoxes(double partialTicks)
{
	double extraSize = boxSize.getSelected().extraSize;
	
	for(MobEntity e : mobs)
	{
		GL11.glPushMatrix();
		
		GL11.glTranslated(e.prevX + (e.getX() - e.prevX) * partialTicks,
			e.prevY + (e.getY() - e.prevY) * partialTicks,
			e.prevZ + (e.getZ() - e.prevZ) * partialTicks);
		
		GL11.glScaled(e.getWidth() + extraSize, e.getHeight() + extraSize,
			e.getWidth() + extraSize);
		
		float f = MC.player.distanceTo(e) / 20F;
		GL11.glColor4f(2 - f, f, 0, 0.5F);
		
		GL11.glCallList(mobBox);
		
		GL11.glPopMatrix();
	}
}
 
Example #2
Source File: MobEspHack.java    From Wurst7 with GNU General Public License v3.0 6 votes vote down vote up
private void renderTracers(double partialTicks)
{
	Vec3d start =
		RotationUtils.getClientLookVec().add(RenderUtils.getCameraPos());
	
	GL11.glBegin(GL11.GL_LINES);
	for(MobEntity e : mobs)
	{
		Vec3d end = e.getBoundingBox().getCenter()
			.subtract(new Vec3d(e.getX(), e.getY(), e.getZ())
				.subtract(e.prevX, e.prevY, e.prevZ)
				.multiply(1 - partialTicks));
		
		float f = MC.player.distanceTo(e) / 20F;
		GL11.glColor4f(2 - f, f, 0, 0.5F);
		
		GL11.glVertex3d(start.x, start.y, start.z);
		GL11.glVertex3d(end.x, end.y, end.z);
	}
	GL11.glEnd();
}
 
Example #3
Source File: SpawnReporter.java    From fabric-carpet with MIT License 6 votes vote down vote up
public static void registerSpawn(DimensionType dim, MobEntity mob, EntityCategory cat, BlockPos pos)
{
    if (lower_spawning_limit != null)
    {
        if (!( (lower_spawning_limit.getX() <= pos.getX() && pos.getX() <= upper_spawning_limit.getX()) &&
             (lower_spawning_limit.getY() <= pos.getY() && pos.getY() <= upper_spawning_limit.getY()) && 
             (lower_spawning_limit.getZ() <= pos.getZ() && pos.getZ() <= upper_spawning_limit.getZ())
           ))
        {
            return;
        }
    }
    Pair<DimensionType, EntityCategory> key = Pair.of(mob.dimension, cat);
    long count = spawn_stats.get(key).getOrDefault(mob.getType(), 0L);
    spawn_stats.get(key).put(mob.getType(), count + 1);
    spawned_mobs.get(key).put(Pair.of(mob.getType(), pos));
    local_spawns.put(cat, local_spawns.get(cat)+1);
}
 
Example #4
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/server/world/ServerWorld;spawnEntity(Lnet/minecraft/entity/Entity;)Z"
))
private static boolean spawnEntity(ServerWorld world, Entity entity_1)
{
    if (CarpetSettings.lagFreeSpawning)
        // we used the mob - next time we will create a new one when needed
        ((WorldInterface) world).getPrecookedMobs().remove(entity_1.getType());

    if (SpawnReporter.track_spawns > 0L && SpawnReporter.local_spawns != null)
    {
        SpawnReporter.registerSpawn(
                world.dimension.getType(),
                (MobEntity) entity_1,
                entity_1.getType().getCategory(),
                entity_1.getBlockPos());
    }
    if (!SpawnReporter.mock_spawns)
        return world.spawnEntity(entity_1);
    return false;
}
 
Example #5
Source File: SpawnReporter.java    From fabric-carpet with MIT License 6 votes vote down vote up
public static List<BaseText> printEntitiesByType(EntityCategory cat, World worldIn, boolean all) //Class<?> entityType)
{
    List<BaseText> lst = new ArrayList<>();
    lst.add( Messenger.s(String.format("Loaded entities for %s class:", get_type_string(cat))));
    for (Entity entity : ((ServerWorld)worldIn).getEntities(null, (e) -> e.getType().getCategory()==cat))
    {
        boolean persistent = entity instanceof MobEntity && ( ((MobEntity) entity).isPersistent() || ((MobEntity) entity).cannotDespawn());
        if (!all && persistent)
            continue;

        EntityType type = entity.getType();
        BlockPos pos = entity.getBlockPos();
        lst.add( Messenger.c(
                "w  - ",
                Messenger.tp(persistent?"gb":"wb",pos),
                String.format(persistent?"g : %s":"w : %s", type.getName().getString())
        ));

    }
    if (lst.size()==1)
    {
        lst.add(Messenger.s(" - Empty."));
    }
    return lst;
}
 
Example #6
Source File: MobEntityMixin_RealTime.java    From Galaxy with GNU Affero General Public License v3.0 5 votes vote down vote up
@Redirect(
    method = "tickNewAi",
    at = @At(
        value = "FIELD",
        target = "Lnet/minecraft/entity/mob/MobEntity;despawnCounter:I",
        opcode = Opcodes.PUTFIELD
    )
)
private void realTimeImpl$adjustForRealTimeEntityDespawnAge(final MobEntity self, final int modifier) {
    final int ticks = (int) ((RealTimeTrackingBridge) self.getEntityWorld()).realTimeBridge$getRealTimeTicks();
    this.despawnCounter += ticks;
}
 
Example #7
Source File: MixinSpawnHelper.java    From patchwork-api with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Redirect(method = "spawnEntitiesInChunk", at = @At(value = "INVOKE", target = "net/minecraft/entity/mob/MobEntity.initialize(Lnet/minecraft/world/IWorld;Lnet/minecraft/world/LocalDifficulty;Lnet/minecraft/entity/SpawnType;Lnet/minecraft/entity/EntityData;Lnet/minecraft/nbt/CompoundTag;)Lnet/minecraft/entity/EntityData;"))
private static EntityData hookSpecialSpawn(MobEntity entity, IWorld world, LocalDifficulty localDifficulty, SpawnType spawnType, EntityData data, CompoundTag tag) {
	if (!EntityEvents.doSpecialSpawn(entity, world, entity.x, entity.y, entity.z, null, spawnType)) {
		return entity.initialize(world, localDifficulty, spawnType, data, tag);
	} else {
		return data;
	}
}
 
Example #8
Source File: MixinEntityType.java    From patchwork-api with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Inject(method = SPAWN, at = @At(value = "INVOKE", target = "net/minecraft/world/World.spawnEntity(Lnet/minecraft/entity/Entity;)Z"), cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD)
private void hookMobSpawns(World world, @Nullable CompoundTag itemTag, @Nullable Text name, @Nullable PlayerEntity player, BlockPos pos, SpawnType type, boolean alignPosition, boolean bl, CallbackInfoReturnable<Entity> callback, Entity entity) {
	if (!(entity instanceof MobEntity)) {
		return;
	}

	MobEntity mob = (MobEntity) entity;

	if (EntityEvents.doSpecialSpawn(mob, world, pos.getX(), pos.getY(), pos.getZ(), null, type)) {
		callback.setReturnValue(null);
	}
}
 
Example #9
Source File: PerimeterDiagnostics.java    From fabric-carpet with MIT License 5 votes vote down vote up
private PerimeterDiagnostics(ServerWorld server, EntityCategory ctype, MobEntity el)
{
    this.sle = null;
    this.worldServer = server;
    this.ctype = ctype;
    this.el = el;
}
 
Example #10
Source File: EntityEvents.java    From patchwork-api with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static boolean canEntitySpawnNaturally(MobEntity entity, IWorld world, double x, double y, double z, MobSpawnerLogic spawner, SpawnType spawnType, double sqDistanceFromPlayer) {
	Result result = canEntitySpawn(entity, world, x, y, z, spawner, spawnType);

	if (result == Result.DEFAULT) {
		// Vanilla logic, but inverted since we're checking if it CAN spawn instead of if it CAN'T
		return !(sqDistanceFromPlayer > 16384.0D && entity.canImmediatelyDespawn(sqDistanceFromPlayer)) && entity.canSpawn(world, SpawnType.NATURAL) && entity.canSpawn(world);
	} else {
		return result == Result.ALLOW;
	}
}
 
Example #11
Source File: EntityEvents.java    From patchwork-api with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static boolean canEntitySpawnFromSpawner(MobEntity entity, World world, double x, double y, double z, MobSpawnerLogic spawner) {
	Result result = canEntitySpawn(entity, world, x, y, z, spawner, SpawnType.SPAWNER);

	if (result == Result.DEFAULT) {
		// Vanilla logic, but inverted since we're checking if it CAN spawn instead of if it CAN'T
		return entity.canSpawn(world, SpawnType.SPAWNER) && entity.canSpawn(world);
	} else {
		return result == Result.ALLOW;
	}
}
 
Example #12
Source File: EntityEvents.java    From patchwork-api with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static Result canEntitySpawn(MobEntity entity, IWorld world, double x, double y, double z, MobSpawnerLogic spawner, SpawnType spawnType) {
	if (entity == null) {
		return Result.DEFAULT;
	}

	LivingSpawnEvent.CheckSpawn event = new LivingSpawnEvent.CheckSpawn(entity, world, x, y, z, spawner, spawnType);
	MinecraftForge.EVENT_BUS.post(event);
	return event.getResult();
}
 
Example #13
Source File: LivingSpawnEvent.java    From patchwork-api with GNU Lesser General Public License v2.1 5 votes vote down vote up
public LivingSpawnEvent(MobEntity entity, IWorld world, double x, double y, double z) {
	super(entity);
	this.world = world;
	this.x = x;
	this.y = y;
	this.z = z;
}
 
Example #14
Source File: MobEspHack.java    From Wurst7 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onUpdate()
{
	mobs.clear();
	
	Stream<MobEntity> stream =
		StreamSupport.stream(MC.world.getEntities().spliterator(), false)
			.filter(e -> e instanceof MobEntity).map(e -> (MobEntity)e)
			.filter(e -> !e.removed && e.getHealth() > 0);
	
	if(filterInvisible.isChecked())
		stream = stream.filter(e -> !e.isInvisible());
	
	mobs.addAll(stream.collect(Collectors.toList()));
}
 
Example #15
Source File: SpawnHelperMixin.java    From fabric-carpet with MIT License 5 votes vote down vote up
@Redirect(method = "spawnEntitiesInChunk", at = @At(
        value = "INVOKE",
        target = "Lnet/minecraft/entity/mob/MobEntity;initialize(Lnet/minecraft/world/IWorld;Lnet/minecraft/world/LocalDifficulty;Lnet/minecraft/entity/SpawnType;Lnet/minecraft/entity/EntityData;Lnet/minecraft/nbt/CompoundTag;)Lnet/minecraft/entity/EntityData;"
))
private static EntityData spawnEntity(MobEntity mobEntity, IWorld iWorld_1, LocalDifficulty localDifficulty_1, SpawnType spawnType_1, EntityData entityData_1, CompoundTag compoundTag_1)
{
    if (!SpawnReporter.mock_spawns)
        return mobEntity.initialize(iWorld_1, localDifficulty_1, spawnType_1, entityData_1, compoundTag_1);
    return null;
}
 
Example #16
Source File: EntityTrackerEntry_leashFixMixin.java    From fabric-carpet with MIT License 4 votes vote down vote up
@Inject(method = "sendPackets", at = @At("RETURN"))
private void sendLeashPackets(Consumer<Packet<?>> consumer_1, CallbackInfo ci)
{
    if (CarpetSettings.leadFix)
    {
        if (entity instanceof MobEntity)
        {
            consumer_1.accept( new EntityAttachS2CPacket(entity, ((MobEntity) entity).getHoldingEntity()));
        }
    }
}
 
Example #17
Source File: MixinSpawnHelper.java    From patchwork-api with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Redirect(method = "spawnEntitiesInChunk", at = @At(value = "INVOKE", target = "net/minecraft/entity/mob/MobEntity.canSpawn(Lnet/minecraft/world/CollisionView;)Z"))
private static boolean disableVanillaLogic(MobEntity entity, CollisionView world) {
	return true;
}
 
Example #18
Source File: MixinMobSpawnerLogic.java    From patchwork-api with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Redirect(method = "update", at = @At(value = "INVOKE", target = "net/minecraft/entity/mob/MobEntity.canSpawn(Lnet/minecraft/world/CollisionView;)Z"))
private boolean makeTheOtherMethodNotMessItUp(MobEntity on, CollisionView world) {
	return true;
}
 
Example #19
Source File: MixinMobSpawnerLogic.java    From patchwork-api with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Redirect(method = "update", at = @At(value = "INVOKE", target = "net/minecraft/entity/mob/MobEntity.canSpawn(Lnet/minecraft/world/IWorld;Lnet/minecraft/entity/SpawnType;)Z"))
private boolean spawnTestRedirect(MobEntity on, IWorld world, SpawnType type) {
	MobSpawnerLogic spawner = (MobSpawnerLogic) (Object) this;

	return EntityEvents.canEntitySpawnFromSpawner(on, (World) world, on.x, on.y, on.z, spawner);
}
 
Example #20
Source File: MoonVillagerEntity.java    From Galacticraft-Rewoven with MIT License 4 votes vote down vote up
public static DefaultAttributeContainer.Builder createMoonVillagerAttributes() {
    return MobEntity.createMobAttributes().add(EntityAttributes.GENERIC_MOVEMENT_SPEED, 0.5D).add(EntityAttributes.GENERIC_FOLLOW_RANGE, 48.0D);
}
 
Example #21
Source File: MixinSpawnHelper.java    From patchwork-api with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Redirect(method = "spawnEntitiesInChunk", at = @At(value = "INVOKE", target = "net/minecraft/entity/mob/MobEntity.canSpawn(Lnet/minecraft/world/IWorld;Lnet/minecraft/entity/SpawnType;)Z"))
private static boolean hookCheckSpawn(MobEntity entity, IWorld world, SpawnType spawnType) {
	return EntityEvents.canEntitySpawnNaturally(entity, entity.world, entity.x, entity.y, entity.x, null, spawnType, playerDistanceStore);
}
 
Example #22
Source File: MixinSpawnHelper.java    From patchwork-api with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Redirect(method = "spawnEntitiesInChunk", at = @At(value = "INVOKE", target = "net/minecraft/entity/mob/MobEntity.canImmediatelyDespawn(D)Z"))
private static boolean disableVanillaLogicAndCaptureDistance(MobEntity entity, double distFromPlayer) {
	playerDistanceStore = distFromPlayer;
	return false;
}
 
Example #23
Source File: EntityEvents.java    From patchwork-api with GNU Lesser General Public License v2.1 4 votes vote down vote up
public static boolean doSpecialSpawn(MobEntity entity, IWorld world, double x, double y, double z, MobSpawnerLogic spawner, SpawnType spawnType) {
	return MinecraftForge.EVENT_BUS.post(new LivingSpawnEvent.SpecialSpawn(entity, world, x, y, z, spawner, spawnType));
}
 
Example #24
Source File: ProphuntEspHack.java    From Wurst7 with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onRender(float partialTicks)
{
	// GL settings
	GL11.glEnable(GL11.GL_BLEND);
	GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
	GL11.glEnable(GL11.GL_LINE_SMOOTH);
	GL11.glLineWidth(2);
	GL11.glDisable(GL11.GL_TEXTURE_2D);
	GL11.glEnable(GL11.GL_CULL_FACE);
	GL11.glDisable(GL11.GL_DEPTH_TEST);
	GL11.glDisable(GL11.GL_LIGHTING);
	
	GL11.glPushMatrix();
	RenderUtils.applyRenderOffset();
	
	// set color
	float alpha = 0.5F + 0.25F * MathHelper
		.sin(System.currentTimeMillis() % 1000 / 500F * (float)Math.PI);
	GL11.glColor4f(1, 0, 0, alpha);
	
	// draw boxes
	for(Entity entity : MC.world.getEntities())
	{
		if(!(entity instanceof MobEntity))
			continue;
		
		if(!entity.isInvisible())
			continue;
		
		if(MC.player.squaredDistanceTo(entity) < 0.25)
			continue;
		
		GL11.glPushMatrix();
		GL11.glTranslated(entity.getX(), entity.getY(), entity.getZ());
		
		RenderUtils.drawOutlinedBox(FAKE_BLOCK_BOX);
		RenderUtils.drawSolidBox(FAKE_BLOCK_BOX);
		
		GL11.glPopMatrix();
	}
	
	GL11.glPopMatrix();
	
	// GL resets
	GL11.glColor4f(1, 1, 1, 1);
	GL11.glEnable(GL11.GL_DEPTH_TEST);
	GL11.glEnable(GL11.GL_TEXTURE_2D);
	GL11.glDisable(GL11.GL_BLEND);
	GL11.glDisable(GL11.GL_LINE_SMOOTH);
}
 
Example #25
Source File: SpawnRestrictionInvoker.java    From the-hallow with MIT License 4 votes vote down vote up
@Invoker
public static <T extends MobEntity> void invokeRegister(EntityType<T> type, SpawnRestriction.Location location, Heightmap.Type heightmapType, SpawnRestriction.SpawnPredicate<T> restriction) {
	throw new UnsupportedOperationException();
}
 
Example #26
Source File: LivingSpawnEvent.java    From patchwork-api with GNU Lesser General Public License v2.1 3 votes vote down vote up
/**
 * @param entity the spawning entity
 * @param world the world to spawn in
 * @param x x coordinate
 * @param y y coordinate
 * @param z z coordinate
 * @param spawner the spawner that spawned this entity, or null if this spawn is
 *        coming from a world spawn or other non-spawner source
 */
public SpecialSpawn(MobEntity entity, IWorld world, double x, double y, double z,
		@Nullable MobSpawnerLogic spawner, SpawnType type) {
	super(entity, world, x, y, z);
	this.spawner = spawner;
	this.type = type;
}
 
Example #27
Source File: LivingSpawnEvent.java    From patchwork-api with GNU Lesser General Public License v2.1 3 votes vote down vote up
/**
 * CheckSpawn is fired when an Entity is about to be spawned.
 *
 * @param entity the spawning entity
 * @param world the world to spawn in
 * @param x x coordinate
 * @param y y coordinate
 * @param z z coordinate
 * @param spawner the spawner that spawned this entity null if it this spawn is
 *               coming from a world spawn or other non-spawner source
 */
public CheckSpawn(MobEntity entity, IWorld world, double x, double y, double z,
		@Nullable MobSpawnerLogic spawner, SpawnType type) {
	super(entity, world, x, y, z);
	this.spawner = spawner;
	this.type = type;
}
 
Example #28
Source File: IForgeItem.java    From patchwork-api with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * Determines if the specific ItemStack can be placed in the specified armor
 * slot, for the entity.
 *
 * @param stack     The ItemStack
 * @param armorType Equipment slot to be verified.
 * @param entity    The entity trying to equip the armor
 * @return True if the given ItemStack can be inserted in the slot
 */
default boolean canEquip(ItemStack stack, EquipmentSlot armorType, Entity entity) {
	return MobEntity.getPreferredEquipmentSlot(stack) == armorType;
}
 
Example #29
Source File: IForgeItem.java    From patchwork-api with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * Called every tick from {@link net.minecraft.entity.passive.HorseEntity#tick()}
 * on the item in the armor slot.
 *
 * @param stack the armor itemstack
 * @param world the world the horse is in
 * @param horse the horse wearing this armor
 */
default void onHorseArmorTick(ItemStack stack, World world, MobEntity horse) {
}
 
Example #30
Source File: IForgeBlockState.java    From patchwork-api with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * Get the {@link PathNodeType} for this block. Return {@code null} for vanilla behavior.
 *
 * @return the {@link PathNodeType}
 */
@Nullable
default PathNodeType getAiPathNodeType(BlockView world, BlockPos pos, @Nullable MobEntity entity) {
	return patchwork$getForgeBlock().getAiPathNodeType(getBlockState(), world, pos, entity);
}