Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

Hello community.

 

I am trying to check if a certain player is around, and if so, then spawn a lightning bolt on the coordinates of the EntityCreeper. This is what I have right now.

 

package test.proxies;

import java.util.EnumSet;

import net.minecraft.entity.effect.EntityLightningBolt;
import net.minecraft.entity.monster.EntityCreeper;
import net.minecraft.entity.player.EntityPlayer;
import cpw.mods.fml.common.ITickHandler;
import cpw.mods.fml.common.TickType;

public class ServerTickHandler implements ITickHandler {

private void onPlayerTick(EntityPlayer player){
	EntityCreeper target = new EntityCreeper(player.worldObj);
	chargeCreepers(player, target);
}

private void chargeCreepers(EntityPlayer player, EntityCreeper target) {
	if(Math.abs(target.posX - player.posX) < 20 && Math.abs(target.posZ - player.posZ) < 20 && target.canEntityBeSeen(player)){
		player.worldObj.spawnEntityInWorld(new EntityLightningBolt(player.worldObj, target.posX, target.posY, target.posZ));
	}
}

@Override
public void tickStart(EnumSet<TickType> type, Object... tickData) {
	if(type.equals(EnumSet.of(TickType.PLAYER))){
		onPlayerTick((EntityPlayer) tickData[0]);
	}

}

@Override
public void tickEnd(EnumSet<TickType> type, Object... tickData) {
	// TODO Auto-generated method stub

}

@Override
public EnumSet<TickType> ticks() {
	return EnumSet.of(TickType.PLAYER, TickType.SERVER);
}

@Override
public String getLabel() {
	// TODO Auto-generated method stub
	return null;
}

}

 

There is probably some elementary mistake I am overlooking.

You're making a new instance of EntityCreeper, instead of retrieving an existing one in the world. Use World.getEntitiesWithinAABB() to retrieve entitities of a certain type from a certain bounding box. Look at MobSpawnerBaseLogic to see it in action. There it's used to determine if there are too many entities of the spawned entity for the mob spawner to not spawn anymore.

 

When you'll use the right AABB, you can also throw away the distance check (unless you want a spherical range).

Author of PneumaticCraft, MineChess, Minesweeper Mod and Sokoban Mod. Visit www.minemaarten.com to take a look at them.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.