Jump to content

JohnyK

Members
  • Posts

    4
  • Joined

  • Last visited

JohnyK's Achievements

Tree Puncher

Tree Puncher (2/8)

0

Reputation

  1. Thank you, your answer helped and it is working just like I imagined.
  2. I am trying to create a (client-side) mod which would work almost like using F3 screen, but with custom pictures blit on player HUD (for example showing N/S when player is facing North/South etc.). Currently I am able to blit any image on screen I want, but I don't know, how to access player data for use in some logic to switch between images. I need help in what I should add in the blank space bellow so that the mod will blit on screen 1 if I'm facing South-ish (range -45 to 45 degrees) and 0 otherwise. public class HUDOverlay { private static final ResourceLocation COMPASS_0 = new ResourceLocation(HUDMod.MODID, "textures/compass/0.png"); private static final ResourceLocation COMPASS_1 = new ResourceLocation(HUDMod.MODID, "textures/compass/1.png"); public static final IGuiOverlay COMPASS_OVERLAY = ((gui, guiGraphics, partialTick, screenWidth, screenHeight) -> { int facing_direction = ___?___; if(-45 < facing_direction && facing_direction < 45) { guiGraphics.blit(COMPASS_1, screenWidth/2, 5, 0,0,3,4,3,4); } else { guiGraphics.blit(COMPASS_0, screenWidth/2, 5, 0,0,3,4,3,4); } }); } Essentially I'm asking for help in getting current client data. Thanks for any help.
  3. So I tried implementing what you sent like this: @Override public InteractionResult useOn(UseOnContext pContext) { ServerLevel world = ((ServerLevel) pContext.getLevel()); world.getServer().getCommands().performPrefixedCommand(new CommandSourceStack( CommandSource.NULL, Vec3.ZERO, Vec2.ZERO, world, 4, "", Component.literal(""), world.getServer(), null).withSuppressedOutput(), "execute at @e[type=cod] run summon lightning_bolt"); return InteractionResult.SUCCESS; } but now when I used the item, the game crashed with the following error: class net.minecraft.client.multiplayer.ClientLevel cannot be cast to class net.minecraft.server.level.ServerLevel (net.minecraft.client.multiplayer.ClientLevel and net.minecraft.server.level.ServerLevel are in module [email protected] of loader 'TRANSFORMER' @5377414a) I seems to me that "world.getServer()" returns ClientLevel instead of ServerLevel, but since I'm new to modding and Java, I don't know how to fix it. (I thought, that if I declared "world" to be "ServerLevel", than "world.getServer()" would return ServerLevel not ClientLevel, so I'm lost)
  4. I was trying to create an item which when used summons lightning on all entities of given type (currently trying on cods). It should do essentially the same thing, as if you used the command : /execute at @e[type=cod] run summon lightning_bolt My try on this problem was the following piece of code: @Override public InteractionResult useOn(UseOnContext pContext) { ServerLevel world = ((ServerLevel) pContext.getLevel()); for(LivingEntity entity: pContext.getLevel().getEntities()) { //problem with this line if(entity.getType() == EntityType.COD){ EntityType.LIGHTNING_BOLT.spawn(world, entity.blockPosition(), MobSpawnType.EVENT); } } return InteractionResult.SUCCESS; } but I was stopped by the following error before running the game: 'getEntities()' has protected access in 'net.minecraft.world.level.Level' So what should I do? Is there some other way to iterate over all entities?
×
×
  • Create New...

Important Information

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