Jump to content

dee12452

Members
  • Posts

    75
  • Joined

  • Last visited

  • Days Won

    2

Everything posted by dee12452

  1. Ah gotchya. What if instead you spawn block entities that once loaded into a chunk, rolled the dice first (despawn if false), then did the raycasting in its surroundings? That should stop the generation problems. You might get some more in-game lag as the player explores to other chunks, but depending on implementation it might not be bad or too noticeable. public class VolcanoCheckSpawnBlockEntity extends BlockEntity implements ITickingBlockEntity { @Override public void onLoad() { // Roll dice. Not a spot? Do nothing and despawn // Do raycast otherwise, spawn volcano features if viable. } } Now this ^ is from my 1.20.2 mod so it might not be the same. If you don't have an onLoad() to override, you could just do it on tick and just make sure to do the work here on the first tick.
  2. getDeltaMovement is they way to go, however it's only populated properly on the client. Therefore any modifications to the player based upon their speed can be done on the client, but if there's an interaction with another entity you have to send a message over the network if(player.level().isClientSide) { System.out.println(player.getDeltaMovement().x); // Works! }
  3. Dang, what exactly are you trying to do? Why are you doing 4 raycasts of that magnitude? That's a big set of operations.
  4. Yeah Player movement is controlled by the client. I just checked and you're right, seems like some of the values to calculate speed (attributes / getDeltaMovement) don't get properly synced server-side. More than likely you'll have to use some janky networking. I hate using the PlayerTick for things but I'm having a hard time thinking of a better alternative. @SubscribeEvent public static void onPlayerTick(TickEvent.PlayerTickEvent event) { if(event.side == LogicalSide.SERVER) return; final var player = event.player; final var onPos = player.getOnPos(); final var level = player.level(); if(level.getBlockState(onPos).getBlock() instanceof YourModdedBlock block && isPlayerMovingFastEnough(player)) { // TODO: SimpleChannel.sendMessage(...); send player speed and blockPos, and handle on the server what to do } } private static boolean isPlayerMovingFastEnough(Player player) { return false; // You implement this, not sure what exactly you're looking for. i.e. player.getSpeed() > <some_value>? }
  5. Does level.clip(...) exist in 1.18.x? If so you could use that!
  6. I don't think there's a simple entity.canBeSee() function per say, but you have some options. You could do what the Enderman class does here EnderMan.class boolean isLookingAtMe(Player p_32535_) { ItemStack itemstack = (ItemStack)p_32535_.getInventory().armor.get(3); if (ForgeHooks.shouldSuppressEnderManAnger(this, p_32535_, itemstack)) { return false; } else { Vec3 vec3 = p_32535_.getViewVector(1.0F).normalize(); Vec3 vec31 = new Vec3(this.getX() - p_32535_.getX(), this.getEyeY() - p_32535_.getEyeY(), this.getZ() - p_32535_.getZ()); double d0 = vec31.length(); vec31 = vec31.normalize(); double d1 = vec3.dot(vec31); return d1 > 1.0 - 0.025 / d0 ? p_32535_.hasLineOfSight(this) : false; } } Maybe tho, this will fit your needs? `player.hasLineOfSight(entity)` Alternatively you could do a raycast either using level.clip(...) or your own implementation using AABB's. A little more complicated but you have more control and tinkering power if needed
  7. I'm on 1.20.2, so this event might not exist for you, but I'm listening to this event: net.minecraftforge.client.event.InputEvent.Key Then doing if(event.getAction() == InputConstants.PRESS && event.getKey() == Minecraft.getInstance().options.keyJump.getKey().getValue()) { // do something on jump pressed } and it's working great. If you want to keep using TickEvent.ClientTickEvent, you could do .isDown() instead of .consumeClick()
  8. BlockState has a .hasProperty() method, so I'd imagine this would work public boolean blockHasAge(BlockState blockState) { return blockState.hasProperty(MyModBlockProperties.AGE); }
  9. Can you post your Screen and BlockEntity implementation? Looks like there's an NPE when rendering the screen, so I'd bet the problem is in your Screen implementation. The initialization of your BlockEntity doesn't tell us much. Also, did you make sure to register your Screen?
  10. Also, if you're planning on committing to mod development, might be a good idea to start being able to read your own crash reports. It'll save you a lot of time, and you don't have to come back here and wait for someone to respond lol. What I find to help is start by finding your own package name and look up and down from there. This is the place that helped me identify your problem. Good luck! detailed walkthrough of the error, its code path and all known details is as follows: --------------------------------------------------------------------------------------- -- Head -- Thread: Render thread Suspected Mod: Pigmano (pigmano), Version: 0.1-1.20.1 at TRANSFORMER/[email protected]/net.citroncactus.pigmano.item.ModCreativeModeTabs.lambda$static$1(ModCreativeModeTabs.java:24) Stacktrace: at net.minecraftforge.common.ForgeHooks.lambda$onCreativeModeTabBuildContents$17(ForgeHooks.java:1631) ~[forge-1.20.1-47.2.20_mapped_parchment_2023.06.26-1.20.1-recomp.jar%23190%23197!/:?] {re:classloading} at net.minecraft.world.item.CreativeModeTab$Output.accept(CreativeModeTab.java:414) ~[forge-1.20.1-47.2.20_mapped_parchment_2023.06.26-1.20.1-recomp.jar%23191!/:?] {re:classloading,pl:accesstransformer:B} at net.citroncactus.pigmano.item.ModCreativeModeTabs.lambda$static$1(ModCreativeModeTabs.java:24) ~[%23196!/:?] {re:classloading} at net.minecraftforge.common.ForgeHooks.onCreativeModeTabBuildContents(ForgeHooks.java:1629) ~[forge-1.20.1-47.2.20_mapped_parchment_2023.06.26-1.20.1-recomp.jar%23190%23197!/:?] {re:classloading}
  11. Here's your problem: line 24 in `src/main/java/net/citroncactus/pigmano/item/ModCreativeModeTabs.java` pOutput.accept(ModBlocks.reinforced_concrete.get()); You're feeding this consumer a Block, not an Item. Creative Mode tabs only can register items. To fix this, make a BlockItem from your Block and plug the result of that here instead. Something like this in ModItems.java: public static final RegistryObject<Item> reinforced_concrete = ITEMS.register("reinforced_concrete", () -> new BlockItem(ModBlocks.reinforced_concrete.get(), new Item.Properties())) ;
  12. You're right, lots easier than using the iterator. That's what I was looking for in my previous post.
  13. I agree, this code is a lot harder than ModLoader, but it's good, cuz it helps us learn. Anyways, until they implement that armor method ben is talking about, I will fix your code for you. public class TickHandler implements ITickHandler { public EnumSet<TickType> ticks() { return EnumSet.of(TickType.SERVER); } public void tickStart(EnumSet<TickType> type, Object... tickData) { } public void tickEnd(EnumSet<TickType> type, Object... tickData) { onPlayerTickInGame(TickType.SERVER); } public void onRenderTick() { } public void onTickInGUI() { } public String getLabel() { return "YourMod server ticks"; } public void onPlayerTickInGame(TickType SERVER) { ArrayList par3 = (ArrayList)MinecraftServer.getServer().getConfigurationManager().playerEntityList; Iterator player = par3.iterator(); while(player.hasNext()) { EntityPlayer p = (EntityPlayer)player.next(); ItemStack boots = p.inventory.armorInventory[0]; ItemStack legs = p.inventory.armorInventory[1]; ItemStack chest = p.inventory.armorInventory[2]; ItemStack helm = p.inventory.armorInventory[3]; if(boots == null || legs == null || chest == null || helm == null) { return; } else if(boots.itemID == YourMod.YourBoots.itemID && legs.itemID == YourMod.YourLegs.itemID && chest.itemID == YourMod.YourChest.itemID && helm.itemID == YourMod.YourHelmet.itemID) { //do stuff, I suggest test this out, try p.fallDamage = 0F; and tell me if this works good luck! } } } } Make sure to change all the places it says YourMod to your mod! Good luck my friend! edit: I edited it so that it checks server ticks only, not client ticks, for performance's sake
  14. Oh yes, it is an argument, and the world object is the second argument. I understand now.
  15. Ok cool. Well thank you diesieben, I didn't know a whole lot about this tick stuff, or forge code in general. And, I hate to say this, but I'm still stuck. you did say I think that you think that I know more than I really do about this code (haha). Here let me share my tick class with you so I can ask what to do next: package CaustCraft; import java.util.EnumSet; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.server.MinecraftServer; import cpw.mods.fml.client.FMLClientHandler; import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.ITickHandler; import cpw.mods.fml.common.TickType; public class ServerTickHandler implements ITickHandler { public EnumSet<TickType> ticks() { return EnumSet.of(TickType.SERVER, TickType.PLAYER); } public void tickStart(EnumSet<TickType> type, Object... tickData) { } public void tickEnd(EnumSet<TickType> type, Object... tickData) { // TODO Auto-generated method stub if(type.contains(TickType.SERVER)) { //nothing yet } if(type.contains(TickType.PLAYER)) { onTickInGame(); } } public void onRenderTick() { } public void onTickInGUI() { } public String getLabel() { // TODO Auto-generated method stub return "Caustcraft server ticks"; } public void onTickInGame() { //CREATE PLAYER INSTANCES? //CHECK FOR SLOTS //DO STUFF } } now, from here, how would I use this tick.PLAYER to cast an entityPlayer and check armor slots? Or am I doing something wrong and misunderstanding everything completely? And again, thank you for helping
  16. Hm, I did not understand all these tick types actually. Good to know! But, where would I change this tickType? In my ServerTickHandler class? Or should I create a new class for this type of tick and register it as well? And also, I am aware of the onUpdate method. It has a use in many of my item classes that have special abilities. However, when I try to use this method for armor abilities, it either does nothing or gives me an error. That is why I am working with tick handlers: to check to see if a player is wearing a suit of armor, and grant abilities based off of that. However I'm stuck on how to get both the OnUpdate method and a tick handler to check armor slots in a player's inventory.
  17. I actually had this problem at one point. Block1ID = config.get("Block IDs" (same), "Block 1 ID"(different), 800(different)).getInt(); Block2ID = config.get("Block IDs" (same), "Block 2 ID"(different), 801(different)).getInt(); make sure when you have the places where (different) is, different; this was where I had issues since I was a copy and paster also, make sure these configs are in the preinits and that you have declared the Block1ID and Block2ID before the preinit this is all I can say since no code was provided
  18. So I finally made a server handler for ticks and it does work. this method will produce the correct output for both ssp and smp: public void onTickInGame() { System.out.println("It Works"); } but I need to create an instance for a player here for special abilities involving items and armor. How would I go about doing this? I know that EntityPlayer p = FMLClientHandler.instance().getClient().thePlayer; will give me an instance of a player and work for ssp, but it will crash a server on start up because it is client-sided. Don't I need some sort of array list of players in the world? How could I do this and have it client and server-sided? Any help is appreciated!
  19. Ah ok, I was rendering the entities in my main class, not in the client proxy, that makes sense. Thank you!
  20. So I got my mod finished and it works for my client load-up: great. But then I launch the server and I get this ugly error and it involves the server loading client-sided only things (at least I think) Here is the error: can anyone tell me what i should do, or if I need to add code to my question. Any help is appreciated!
  21. Well just because I've seen setBlockWithNotify more often to be honest. Would setBlock be easier to work with in this case then?
  22. So, I am trying to make an item that checks to see if there is water(still water) in front of the player and place an ice carpet so the player can "walk" on water. Only thing is I'm having trouble with making this carpet. Here is the code so far public void onUpdate(ItemStack par1ItemStack, World worldObj, Entity player, int par4, boolean par5) { if (player instanceof EntityPlayer) { EntityPlayer thePlayer = (EntityPlayer)player; worldObj.playerEntities.add(thePlayer); worldObj.updateAllPlayersSleepingFlag(); if(worldObj.getBlockId((int) thePlayer.posX + 1, (int) thePlayer.posY - 2, (int) thePlayer.posZ + 1) == Block.waterStill.blockID) { worldObj.setBlockWithNotify((int) thePlayer.posX - 1, (int) thePlayer.posY - 2, (int) thePlayer.posZ - 1, Block.ice.blockID); worldObj.setBlockWithNotify((int) thePlayer.posX, (int) thePlayer.posY - 2, (int) thePlayer.posZ, Block.ice.blockID); worldObj.setBlockWithNotify((int) thePlayer.posX - 2, (int) thePlayer.posY - 2, (int) thePlayer.posZ - 2, Block.ice.blockID); worldObj.setBlockWithNotify((int) thePlayer.posX + 1, (int) thePlayer.posY - 2, (int) thePlayer.posZ + 1, Block.ice.blockID); worldObj.setBlockWithNotify((int) thePlayer.posX + 2, (int) thePlayer.posY - 2, (int) thePlayer.posZ + 2, Block.ice.blockID); } } } Obviously the carpet isn't anywhere near good. the Ice isn't being placed properly near the player. I've been messing around with it for about an hour now and was wondering if there was a specific set of coordinates I could use rather than trial and error over and over again. Thanks in advance!
  23. Oh my lord it worked!!!! I was looking in the world file to find a way of doing this and this was it! 3 days of work finally complete thank you so much!!!
  24. Hello forge community, I am currently in the making of my first mod and ran into trouble here. I need to make it so that when a boolean variable is true, the method will consume items from a player's inventory. But, onUpdate contains an Entity parameter and not an EntityPlayer parameter. Is there a way I can go around this, like typecast or something? I looked into tick handlers and I got lost there as well. Maybe even a different way of consuming items in the inventory for a set duration would be great too. Thanks for the help!
  25. Please tell, how did you fix it? I keep running into it over and over again. Edit: never mind, fixed it!
×
×
  • Create New...

Important Information

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