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

So I'm trying to create a lighter, so On and Off. Here is my code

package icelock.iceblocks.item.custom;

import com.mojang.brigadier.ParseResults;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.components.ChatComponent;
import net.minecraft.client.gui.screens.debug.GameModeSwitcherScreen;
import net.minecraft.client.sounds.SoundEngine;
import net.minecraft.client.telemetry.TelemetryProperty;
import net.minecraft.commands.*;
import net.minecraft.commands.arguments.GameModeArgument;
import net.minecraft.core.Direction;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceKey;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.commands.GameModeCommand;
import net.minecraft.server.commands.OpCommand;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.level.ServerPlayerGameMode;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
import net.minecraft.server.*;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Abilities;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.level.GameRules;
import net.minecraft.world.level.GameType;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.storage.LevelResource;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.client.event.CustomizeGuiOverlayEvent;
import net.minecraftforge.common.ForgeConfig;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.player.PlayerEvent;
import net.minecraftforge.server.console.TerminalHandler;
import net.minecraft.commands.CommandSourceStack;

import java.nio.file.Path;

public class FlashLight extends Item {
public FlashLight(Properties pProperties) {
super(pProperties);
}
boolean FlashSwitch = false;
Vec3 pos1 = null;
Vec3 pos2 = null;
Direction Dir = null;
boolean ON = false;

@Override
public InteractionResult useOn(UseOnContext pContext) {
if (!pContext.getLevel().isClientSide) {
Boolean ShiftDown = pContext.isSecondaryUseActive();
Player player = pContext.getPlayer();
MinecraftServer server = pContext.getPlayer().getServer();
if (FlashSwitch) {
pos1 = pContext.getPlayer().getEyePosition();
FlashSwitch = !FlashSwitch;
player.displayClientMessage(Component.literal("§cOff"),true);
ON = false;
} else if (!FlashSwitch) {
FlashSwitch = !FlashSwitch;
player.displayClientMessage(Component.literal("§eOn"),true);
ON = true;

while (ON) {
Dir = pContext.getPlayer().getDirection();
if (Dir.equals(Direction.NORTH)){
player.displayClientMessage(Component.literal("§eNORTH"),true);
} else if (Dir.equals(Direction.EAST)){
player.displayClientMessage(Component.literal("§eEAST"),true);
} else if (Dir.equals(Direction.SOUTH)){
player.displayClientMessage(Component.literal("§eSOUTH"),true);
} else if (Dir.equals(Direction.WEST)){
player.displayClientMessage(Component.literal("§eWEST"),true);
}
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}


}
}
}
return InteractionResult.SUCCESS;
}
}
This barely works, the switch between on and off doesnt work, and when i turn directions it doesnt display the direction im facing, please help ASAP.

11 minutes ago, modrinth said:

boolean FlashSwitch = false;

Blocks and items are singletons, this value is shared across all "instances" of your item. You have to store this data in an ItemStack's capability.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

  • Author

That's not really the problem, i have a separate item with the exact same on and off switch and it works perfectly fine. The problem is something with the loop i presume, as without it the switch works perfectly fine. I'll explain what i need the item to do, first off blocks cant be transparent (or at-least that's what i think) so i thought of setting the block behind the player to a black block with a light level of like 6 or something. I need to detect the direction the player is facing at all times so i can set the block behind them to a light block.

Edited by modrinth

  • Author
27 minutes ago, Draco18s said:

Blocks and items are singletons, this value is shared across all "instances" of your item. You have to store this data in an ItemStack's capability.

New to these forums, i didn't know how to reply either way ^

  • Author
43 minutes ago, modrinth said:

That's not really the problem, i have a separate item with the exact same on and off switch and it works perfectly fine. The problem is something with the loop i presume, as without it the switch works perfectly fine. I'll explain what i need the item to do, first off blocks cant be transparent (or at-least that's what i think) so i thought of setting the block behind the player to a black block with a light level of like 6 or something. I need to detect the direction the player is facing at all times so i can set the block behind them to a light block.

Nevermind i just figured out that i can make transparent blocks with AirBlock, that saves alot of time.

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.