modrinth Posted August 11, 2023 Posted August 11, 2023 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. Quote
Draco18s Posted August 11, 2023 Posted August 11, 2023 On 8/11/2023 at 2:01 AM, modrinth said: boolean FlashSwitch = false; Expand 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. Quote 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.
modrinth Posted August 11, 2023 Author Posted August 11, 2023 (edited) 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 August 11, 2023 by modrinth Quote
modrinth Posted August 11, 2023 Author Posted August 11, 2023 On 8/11/2023 at 2:13 AM, 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. Expand New to these forums, i didn't know how to reply either way ^ Quote
modrinth Posted August 11, 2023 Author Posted August 11, 2023 On 8/11/2023 at 2:24 AM, 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. Expand Nevermind i just figured out that i can make transparent blocks with AirBlock, that saves alot of time. Quote
Recommended Posts
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.