DoctorG_Mystery Posted August 20, 2021 Author Posted August 20, 2021 (edited) 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, 2021 by DoctorG_Mystery Quote
DoctorG_Mystery Posted August 20, 2021 Author Posted August 20, 2021 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? Quote
DoctorG_Mystery Posted August 20, 2021 Author Posted August 20, 2021 yes but less often with java more with c, c++, c# and Phyton Quote
DoctorG_Mystery Posted August 20, 2021 Author Posted August 20, 2021 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 Quote
DoctorG_Mystery Posted August 20, 2021 Author Posted August 20, 2021 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()); } Quote
DoctorG_Mystery Posted August 20, 2021 Author Posted August 20, 2021 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()); } Quote
DoctorG_Mystery Posted August 20, 2021 Author Posted August 20, 2021 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_); } Quote
poopoodice Posted August 21, 2021 Posted August 21, 2021 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 Quote
DoctorG_Mystery Posted August 21, 2021 Author Posted August 21, 2021 I make now a private final PlayerEntity player; private final Hand ... there issn't any errors and that is also what is in ItemUseContext Quote
DoctorG_Mystery Posted August 21, 2021 Author Posted August 21, 2021 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 ^^ Quote
DoctorG_Mystery Posted August 21, 2021 Author Posted August 21, 2021 I try to declare the player, hand and world and @poopoodice said in ItemUseContext is all I need Quote
DoctorG_Mystery Posted August 21, 2021 Author Posted August 21, 2021 (edited) I try to declare it because the functions world hand and player will not work Edited August 21, 2021 by DoctorG_Mystery Quote
DoctorG_Mystery Posted August 21, 2021 Author Posted August 21, 2021 If I type in the useOn methode: PlayerEntity Player; ... there is an error because it isn't initialized Quote
DoctorG_Mystery Posted August 21, 2021 Author Posted August 21, 2021 (edited) 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, 2021 by DoctorG_Mystery Quote
DoctorG_Mystery Posted August 21, 2021 Author Posted August 21, 2021 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 Quote
DoctorG_Mystery Posted August 21, 2021 Author Posted August 21, 2021 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 Quote
DoctorG_Mystery Posted August 21, 2021 Author Posted August 21, 2021 and doesn't it have to be a static method to call it? Quote
DoctorG_Mystery Posted August 21, 2021 Author Posted August 21, 2021 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. 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.