Posted January 31, 20232 yr public class SmokeBombItem extends Item { public SmokeBombItem(Properties pProperties) { super(pProperties); } @Override public InteractionResultHolder<ItemStack> use(Level pLevel, Player pPlayer, InteractionHand pUsedHand) { MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance(); ArrayList<EntityType<Player>> list = Lists.newArrayList(server.getPlayerList().getPlayers()); for (EntityType<Player> playerIn : list) //for each player in the player list { pPlayer.addEffect(new MobEffectInstance(MobEffects.BLINDNESS, 300)); } return super.use(pLevel, pPlayer, pUsedHand); } } Any ideas on how to fix this code?
February 1, 20232 yr First, use a code block, this is really difficult to read. Second, you can get the server from the server level, but you can't know if you're on the server level until you check it via Level#isClientSide. Third, you can use Level#getNearbyPlayers to get nearby players in the specified bounding box.
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.