Jump to content

NJSwede

Members
  • Posts

    14
  • Joined

  • Last visited

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

NJSwede's Achievements

Tree Puncher

Tree Puncher (2/8)

0

Reputation

  1. What does gradle display when you run it? That's what I meant by output. Also, although I don't think this is what breaks your build, your base name should only contain lower case letters.
  2. What's the exact command you execute? Can you please post the contents of build.gradle? Can you please post the output of gradle? Most likely, you're not executing the right task (build or assemble) or there's something messed up in your build.gradle. If you post it here, I'm pretty sure we can straighten this out very quickly.
  3. Aaaaah... OK. I knew there was something simple I was overlooking!
  4. Yes, but how do I trigger the code that plays the sound on the client side on a multiplayer server? I guess I need to send a network package to inform the client of the event. Right now, I just have a flag in a static variable, but that obviously breaks if the server and client aren't running in the same process.
  5. This has probably been asked and answered a million times, so feel free to flame me! But anyway, the little enchantment mod I'm playing with has most of its mechanics implemented on the server side. As it should, I believe. However, when certain things happen, I want to play a sound. Now, if I do that on the server side, everyone except the player will hear it. To play it to the player, I need to do it on the client side. My simple question is this: What's the best practice? Do I need to send some kind of network message to the client side informing it about the event or is there a more standard way? I figured there must be... And yes, I've read this https://mcforge.readthedocs.io/en/latest/effects/sounds/ but it doesn't really answer my question.
  6. LOL! Luckily this code is only used for detecting one tree at the time, i.e. answering the question "is this block part of a tree". For counting trees in a birch forest, it's probably way too slow. Thanks for the rest of the pointers. I'll give it a shot!
  7. So this is what I ended up doing: A simple 3D flood fill of the trunk while detecting adjacent leaves of the correct type. I didn't bother to check for a dirt block at the root, since it didn't make much of a difference for what I wanted to do. It would be fairly easy to do. Probably not the most efficient algorithm, but since trees and ore veins are relatively small, it's fast enough. Posting the code for your viewing pleasure. The only thing I wonder if there's a more efficient way of digging out the "persistent" property. https://gist.github.com/prydin/cc48a3ddd645bcd6f73d63bac6aa75b7
  8. Great minds think alike! Sounds like what I was thinking of doing.
  9. @OutCraft is probably close enough for what I'm doing. I'm working on an enchantment that lets you take down a tree in a single strike (I know it's been done a million times, but I'm educating myself). I'd like a safeguard so it doesn't take down an entire log house by mistake, so occasional false positives aren't not that much of an issue.
  10. Hello again! Is there a convenient way to determine whether a log block is part of a tree? I could always scan the surroundings for leaves, but it's not 100% reliable. Does Minecraft even record the presence of a tree or is it just a bunch of log and leaf blocks?
  11. It turned out that ServerPlayerGameMode was accessible after all. All I had to do was to cast my player to a ServerPlayer and ask for the game mode. Calling destroyBlock on that class seems to do all the proper tests and fire the right events. It all works now! Now I can mine an entire vein of diamonds or fell an entire tree in one stroke. Whohooo!
  12. MegaMiner is just my playground mod. Here's the entire MegaMinerEvents class. It's just a static event receiver. package nu.rydin.explodingarrows.common.events; import net.minecraft.core.BlockPos; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.Tag; import net.minecraft.world.entity.player.Player; import net.minecraft.world.level.Level; import net.minecraft.world.level.LevelAccessor; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.state.BlockState; import net.minecraftforge.event.TickEvent; import net.minecraftforge.event.world.BlockEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; import nu.rydin.explodingarrows.common.Main; import nu.rydin.explodingarrows.common.enchantments.ModEnchantments; import java.util.LinkedList; @Mod.EventBusSubscriber(modid = Main.MOD_ID, bus = Mod.EventBusSubscriber.Bus.FORGE) public class MegaMinerEvents { private static final class BlockToBreak { private final BlockPos pos; private final Player player; public BlockToBreak(final BlockPos pos, final Player player) { this.pos = pos; this.player = player; } } private static final LinkedList<BlockToBreak> queue = new LinkedList<>(); @SubscribeEvent public static void onBreakBlock(final BlockEvent.BreakEvent e) { final LevelAccessor world = e.getWorld(); if (world.isClientSide()) { return; } for (final Tag t : e.getPlayer().getMainHandItem().getEnchantmentTags()) { final CompoundTag ct = (CompoundTag) t; if (ct.getString("id") .equals(ModEnchantments.MEGA_MINER.get().getRegistryName().toString())) { MegaMinerEvents.mineNeighborhood(e.getPos(), e.getPlayer(), e.getState().getBlock()); } } } @SubscribeEvent public static void onTick(final TickEvent.ServerTickEvent e) { if (MegaMinerEvents.queue.isEmpty()) { return; } final BlockToBreak b = MegaMinerEvents.queue.removeFirst(); final Level world = b.player.level; final BlockState bs = world.getBlockState(b.pos); bs.getBlock().playerDestroy(world, b.player, b.pos, bs, null, b.player.getMainHandItem()); world.removeBlock(b.pos, true); // MegaMinerEvents.mineNeighborhood(b.pos, b.player, bs.getBlock()); System.out.println(MegaMinerEvents.queue.size()); } private static void mineNeighborhood( final BlockPos pos, final Player player, final Block blockType) { final float x0 = pos.getX(); final float y0 = pos.getY(); final float z0 = pos.getZ(); for (float z = z0 - 1.0F; z <= z0 + 1; z += 1.0) { for (float y = y0 - 1.0F; y <= y0 + 1; y += 1.0) { for (float x = x0 - 1.0F; x <= x0 + 1; x += 1.0) { final BlockState b = player.getLevel().getBlockState(pos); if (b.is(blockType)) { MegaMinerEvents.queue.addLast(new BlockToBreak(pos, player)); } } } } } }
  13. Additional info: It only works sporadically. I guess TickEvent.ServerTickEvent is the wrong place to do this...
  14. Hi! Java veteran, but new to modding. I'm working on ny very first mod experiments and I'm playing with increasing the reach of a pickaxe by following veins of ore and other fun things. Whenever I break a block and have a certain custom enchantment on my pickaxe, I want to break a few additional nearby blocks as well. Seems simple enough. I also want it to kind of "ripple" through the environment, so my thought was to put the blocks to be destroyed on a queue and let a tick event subscriber pick them up, one for each tick. I have this: @SubscribeEvent public static void onTick(final TickEvent e) { if (MegaMinerEvents.queue.isEmpty()) { return; } final BlockToBreak b = MegaMinerEvents.queue.removeFirst(); final BlockState bs = b.world.getBlockState(b.pos); bs.getBlock() .playerDestroy(b.player.getLevel(), b.player, b.pos, bs, null, b.player.getMainHandItem()); b.player.getLevel().removeBlock(b.pos, false); } As you can see, I simply pop a block from the queue every tick and break it. It sort of works. However, I'm wondering if Block::playerDestroy is the right method to call. First of all, it doesn't actually remove the block. Second, it doesn't trigger any events from what I can see. The vanilla game itself is using ServerPlayerGameMode::destroyBlock(), but that method isn't accessible from any context I'm in. So the question is: Is Block::playerDestroy the right method to use? What other things, like sending events and checking things to I need to do if I use that method? Also, is "onTick" the right place to do this? Thanks! NJSwede
×
×
  • Create New...

Important Information

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