August 20, 20214 yr Author here: package drgmystery.darklight.events; import net.minecraft.item.Item; import net.minecraft.block.Blocks; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; import net.minecraft.item.ItemUseContext; import net.minecraft.util.ActionResult; import net.minecraft.util.ActionResultType; import net.minecraft.util.Hand; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; public class DarklightPlaceTest extends Item{ } @Override public ActionResult<ItemStack> useOn(PlayerEntity player, World world, Hand hand, BlockPos Pos){ if(!world.isClientSide){ ; double x = player.position().x(); double y = player.position().y(); double z = player.position().z(); BlockPos blockPos = new BlockPos(x, y, z); world.setBlockAndUpdate(blockPos, Blocks.DIAMOND_BLOCK.defaultBlockState()); } return ActionResult.pass(null); } @Override public ActionResultType useOn(ItemUseContext p_195939_1_) { // TODO Auto-generated method stub return super.useOn(p_195939_1_); } } edit: sorry I only read: what has been generated the error? Edited August 20, 20214 yr by DoctorG_Mystery
August 20, 20214 yr Author The method above is mine, the one below is auto gen, I can't use it because I can't write in the "PlayerEntity player, World world, Hand hand, BlockPos Pos" because then the override error comes back or gives Is there a possibility to declare the PlayerEntity etc. differently?
August 20, 20214 yr Author I never used overriding before. I never need it or it was do automaticly. because I never used overriding before I ever can declare a methode parameter without some problems like this
August 20, 20214 yr Author errors at this points: if(!world.isClientSide){ double x = player.position().x(); double y = player.position().y(); double z = player.position().z(); BlockPos blockPos = new BlockPos(x, y, z); world.setBlockAndUpdate(blockPos, Blocks.DIAMOND_BLOCK.defaultBlockState()); }
August 20, 20214 yr Author look better so? PlayerEntity player = null; World world = null; Hand hand = null; if(!world.isClientSide){ ; double x = player.position().x(); double y = player.position().y(); double z = player.position().z(); BlockPos blockPos = new BlockPos(x, y, z); world.setBlockAndUpdate(blockPos, Blocks.DIAMOND_BLOCK.defaultBlockState()); }
August 20, 20214 yr Author no errors more PlayerEntity player; World world; Hand hand; @Override public ActionResultType useOn(ItemUseContext p_195939_1_) { if(!world.isClientSide){ ; double x = player.position().x(); double y = player.position().y(); double z = player.position().z(); BlockPos blockPos = new BlockPos(x, y, z); world.setBlockAndUpdate(blockPos, Blocks.DIAMOND_BLOCK.defaultBlockState()); } return super.useOn(p_195939_1_); }
August 21, 20214 yr You can't just get the values from nowhere... use the parameter of the method, all the things you need are stored in that ItemUseContext, the placer (can be null!), world....etc
August 21, 20214 yr Author I make now a private final PlayerEntity player; private final Hand ... there issn't any errors and that is also what is in ItemUseContext
August 21, 20214 yr Author I wanted to add that I am doing "learning by doing" and not only understand Forge mobing but also Java as well as the IDE Eclipse, so when I look very stupid (and I feel stupid to myself because I sometimes don't check it what you mean) so sorry for that and thank you for your time for my problem with Probgarmmiren ^^
August 21, 20214 yr Author I try to declare the player, hand and world and @poopoodice said in ItemUseContext is all I need
August 21, 20214 yr Author I try to declare it because the functions world hand and player will not work Edited August 21, 20214 yr by DoctorG_Mystery
August 21, 20214 yr Author If I type in the useOn methode: PlayerEntity Player; ... there is an error because it isn't initialized
August 21, 20214 yr Author look: I am doing "learning by doing" and not only understand Forge mobing but also Java as well as the IDE Eclipse tell me a keyword then i can learn it but if i don't know what to learn then i can't learn it Edited August 21, 20214 yr by DoctorG_Mystery
August 21, 20214 yr Author maybe I now It but I don't now the keywords and because that I don't understand you, besides, I do not code with prescribed code in Library form
August 21, 20214 yr Author I see what data if gives me I see the data I want I can declare it in my class but I can't initializ "= null;" remove the error but is wrong
August 21, 20214 yr Author it makes no sense we already have 74 replies and we haven't gone any further I think we should close the thread and forget about the whole thing.
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.