dee12452
Members-
Posts
75 -
Joined
-
Last visited
-
Days Won
2
Everything posted by dee12452
-
@SubscribeEvent public static void onVanillaEvent(VanillaGameEvent event) { final var level = event.getLevel(); final var v3 = event.getEventPosition(); final var vec3i = new Vec3i((int) v3.x, (int) v3.y, (int) v3.z); final var blockPos = new BlockPos(vec3i); final var block = event.getLevel().getBlockState(blockPos).getBlock(); if(event.getVanillaEvent().equals(GameEvent.BLOCK_ACTIVATE) && block instanceOf PressurePlateBlock) { // Your Code Here } }
-
player.getRandom().nextIntBetweenInclusive(-1, 1);
-
Gotchya, well this will be your best friend then if you're down to read through it and try to understand it. Networking in 1.20.2+ got a fairly large change. https://docs.minecraftforge.net/en/1.20.x/networking/simpleimpl/ I could post my mod's 1.20.2 networking code with an example but it's going to be a lot because it's a lot to setup. Lemme know if you'd prefer that though, I don't mind.
-
Brother, sendParticles literally calls addParticle. This is forge's implementation of handling sendParticle once it gets back to the client public void handleParticleEvent(ClientboundLevelParticlesPacket p_105026_) { PacketUtils.ensureRunningOnSameThread(p_105026_, this, this.minecraft); if (p_105026_.getCount() == 0) { double d0 = (double)(p_105026_.getMaxSpeed() * p_105026_.getXDist()); double d2 = (double)(p_105026_.getMaxSpeed() * p_105026_.getYDist()); double d4 = (double)(p_105026_.getMaxSpeed() * p_105026_.getZDist()); try { this.level.addParticle(p_105026_.getParticle(), p_105026_.isOverrideLimiter(), p_105026_.getX(), p_105026_.getY(), p_105026_.getZ(), d0, d2, d4); } catch (Throwable var17) { LOGGER.warn("Could not spawn particle effect {}", p_105026_.getParticle()); } } else { for(int i = 0; i < p_105026_.getCount(); ++i) { double d1 = this.random.nextGaussian() * (double)p_105026_.getXDist(); double d3 = this.random.nextGaussian() * (double)p_105026_.getYDist(); double d5 = this.random.nextGaussian() * (double)p_105026_.getZDist(); double d6 = this.random.nextGaussian() * (double)p_105026_.getMaxSpeed(); double d7 = this.random.nextGaussian() * (double)p_105026_.getMaxSpeed(); double d8 = this.random.nextGaussian() * (double)p_105026_.getMaxSpeed(); try { this.level.addParticle(p_105026_.getParticle(), p_105026_.isOverrideLimiter(), p_105026_.getX() + d1, p_105026_.getY() + d3, p_105026_.getZ() + d5, d6, d7, d8); } catch (Throwable var16) { LOGGER.warn("Could not spawn particle effect {}", p_105026_.getParticle()); return; } } } } The last 4 of the `ServerLevel#sendParticles` function represent `xDist; yDist; zDist; maxSpeed;` of this ^ respectively. So this should in theory allow for you to mostly set a speed. If you need more control, send a custom clientbound packet over the Network that directly calls level.addParticle the way you need exactly...
-
You're right, you're gunna have to use an event instead. @SubscribeEvent public static void onInteractBlock(PlayerInteractEvent.RightClickBlock event) { final var level = event.getLevel(); if(level.isClientSide) return; // Note this is fired both client and server side final var itemUsed = event.getItemStack().getItem(); final var blockUsed = level.getBlockState(event.getHitVec().getBlockPos()).getBlock(); if(blockUsed instanceof DoorBlock && itemUsed instanceof MyCustomItem item) { item.doCustomThing(); } } ^ this worked for me
-
Have you tried `spawnParticle`? https://docs.minecraftforge.net/en/1.14.x/effects/particles/#:~:text=To make a particle appear,nothing%2C without throwing any errors.
-
So 2 things: 1. You'll need some way to check if it's the first time the Player has logged into the server. You make a custom Player capability that gets saved only server-side that keeps track of if this is the Player's first time on the server. This is Forge's docs on Capabilities: https://docs.minecraftforge.net/en/1.20.x/datastorage/capabilities/ Kind of complicated at first but pretty much every mod is going to need their own Capability, so it'd be good to get familiar sooner rather than later. 2. Use PlayerLoggedInEvent instead @SubscribeEvent public static void onPlayerLoggedIn(PlayerEvent.PlayerLoggedInEvent event) { final var player = (ServerPlayer) event.getEntity(); final var serverPlayerCap = Capabilities.serverPlayer(player); if(serverPlayerCap.isFirstLogin()) { player.getInventory().add(new ItemStack(Items.YOUR_ITEM_HERE.get(), 1)); } }
-
1.20.1-Accessing LegacyRandomSource from multiple threads
dee12452 replied to gdrfgdrf123's topic in Modder Support
You’re probably calling level.getRandom() somewhere, likely on the client side. Either use a living entity’s random, or the random that’s passed in to the function of one of your block’s animate / tick functions -
Make your config screen public class MyConfigScreen extends Screen { //... } Then in your Client event subscriber @SubscribeEvent public static void onFMLClientSetupEvent(FMLClientSetupEvent event) { ModLoadingContext.get().registerExtensionPoint( ConfigScreenHandler.ConfigScreenFactory.class, () -> new ConfigScreenHandler.ConfigScreenFactory((mc, prevScreen) -> new MyConfigScreen(){}) ); }
-
If those other methods are being called, I'd imagine the block and its block entity are being placed in the world correctly. At this point I'd just try and follow this as closely as possible, and continue to do debugging https://docs.minecraftforge.net/en/1.18.x/blockentities/ as I can't tell you what the problem is without seeing the whole codebase and playing around with it myself. FWIW though you could do most of your work on onLoad though so that's somewhere you could at least start in the meantime.
-
I mean that all looks good. Have you tried doing any debugging into where the hold up is? Have you made sure that the block is in the world / can you see it (if it's being rendered)? If you can, use your IDE to start stepping through some of this code, such as does it even get to this line in GlobalBlockEntityTicker.Java? `if (!(blockEntity instanceof ITickingBlockEntity tickingEntity))` If not, some `System.out.println(xxx);` might also do the trick. Good luck
-
Probably need to show us some code at this point then
-
Is `onUsingTick` available in the version of forge you’re using? If so, that’s the easy way to go about it.
-
How about Subscribe to the MouseButton event? That's what I'm using. ex: public class ClientEventSubscriber { /** * Subscribe to Forge-defined events * <p> * These events will be derived from Event */ @EventBusSubscriber(modid = MOD_ID, bus = EventBusSubscriber.Bus.FORGE, value = Dist.CLIENT) public static class ForgeBus { @SubscribeEvent public static void onMouseClickPreEvent(InputEvent.MouseButton.Pre event) { final boolean isLeftClick = event.getButton() == GLFW.GLFW_MOUSE_BUTTON_LEFT; } } } Alternatively you could do on ClientTick `Minecraft.getInstance().mouseHandler.isLeftPressed()`
-
I know what ur saying, this is what I'd suggest you do to get around this. ITickingBlockEntity.java public interface ITickingBlockEntity { /** * Client + Server tick callback. * * @param level the server level * @param pos the block pos * @param state the block state */ void tick(Level level, BlockPos pos, BlockState state); } GlobalBlockTicker.java public class GlobalBlockEntityTicker { private GlobalBlockEntityTicker() {} public static <T extends BlockEntity> void ticker(Level level, BlockPos pos, BlockState state, T blockEntity) { if(!(blockEntity instanceof ITickingBlockEntity tickingEntity)) { return; } tickingEntity.tick(level, pos, state); } } VolcanoBlock.java (or whatever it is named) public class VolcanoBlock extends Block implements EntityBlock { // ... constructor and stuff @Nullable @Override public <T extends BlockEntity> BlockEntityTicker<T> getTicker(@NotNull Level level, @NotNull BlockState state, @NotNull BlockEntityType<T> type ) { return GlobalBlockEntityTicker::ticker; } } VolcanoBlockEntity.java (or whatever it is named) public class VolcanoBlockEntity extends BlockEntity implements ITickingBlockEntity { // Constructor and stuff @Override public void tick(Level level, BlockPos pos, BlockState state) { // Non static tick method! } }
-
Well the blockentity code to check for generation I would think would only run once the player is close enough to it in the world. You might have to do more research on how that’d work exactly and if that’s a solution that could work with the calcs you’re running to determine volcano viability. It might lag an exploring player significantly and make the game unplayable. Only other option I can think of is just changing world gen to just mend the areas you spawn a volcano to be viable rather than checking if the area is viable if that makes sense. Good luck!
-
1.20.1 [1.20.1] [SOLVED] Mod Config Screen disables keys after exiting
dee12452 replied to Zeher_Monkey's topic in Modder Support
Awesome! -
1.20.1 [1.20.1] [SOLVED] Mod Config Screen disables keys after exiting
dee12452 replied to Zeher_Monkey's topic in Modder Support
Oh man, so I skimmed through what I thought to be relevant and I didn't see a smoking gun. My guess is a widget such as an EditBox is taking and keeping key presses but I'm not 100% on that. Sorry I can't be more helpful at this point, I think for you at this point it's unfortunately going to be a game of needle in the haystack -
Oh shoot you're right, that's my own interface in my project lol. Try following this guide (specifically for a ticking block entity) https://docs.minecraftforge.net/en/1.18.x/blockentities/ Here's the meat If you need a ticking BlockEntity, for example to keep track of the progress during a smelting process, another method must be implemented and overridden within EntityBlock: EntityBlock#getTicker(Level, BlockState, BlockEntityType). This can implement different tickers depending on which logical side the user is on, or just implement one general ticker. In either case, a BlockEntityTicker must be returned. Since this is a functional interface, it can just take in a method representing the ticker instead: // Inside some Block subclass @Nullable @Override public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level level, BlockState state, BlockEntityType<T> type) { return type == MyBlockEntityTypes.MYBE.get() ? MyBlockEntity::tick : null; } // Inside MyBlockEntity public static void tick(Level level, BlockPos pos, BlockState state, T blockEntity) { // Do stuff }
-
1.20.1 [1.20.1] [SOLVED] Mod Config Screen disables keys after exiting
dee12452 replied to Zeher_Monkey's topic in Modder Support
I gotchya. So I copied your code and removed all the things that I don't have access to in this post (i.e. any of the CosmosOptionListTextEntry) and I didn't get the issue you're talking about. Can you post the implementation of `CosmosOptionListTextEntry`? The problem might be in there. -
Ok I'm sorry, as I was responding I realized that registering screens is only relevant to MenuScreens, i.e. screens that connect to a menu implementation which sounds like this isn't the case. You can disregard registration of this screen as long as it's not connected to a menu (i.e. a class that extends AbstractContainerMenu)
-
1.20.1 [1.20.1] [SOLVED] Mod Config Screen disables keys after exiting
dee12452 replied to Zeher_Monkey's topic in Modder Support
Alright you might have to unfortunately take a big step back. What if you comment out every piece of functionality in your custom screen, so as much as possible till it’s basically a blank screen that does nothing, and add one thing back at a time until the problem pops up? I am also curious, when and how does this screen appear to the player? That may have something to do with it. -
[1.20.1] [SOLVED] Checking if a block has a property
dee12452 replied to A tired guy's topic in Modder Support
Hm not sure what you're asking for then. Can you give a pseudocode example or explain differently what your intention is here? -
1.20.1 [1.20.1] [SOLVED] Mod Config Screen disables keys after exiting
dee12452 replied to Zeher_Monkey's topic in Modder Support
Yeh you might be on to something. Have you tried not setting the screen on close? Screen default behavior pops the gui anyways so not sure it's needed Screen.java public void onClose() { this.minecraft.popGuiLayer(); } Although it could be this also being a problem @Override public boolean keyPressed(int mouseX, int mouseY, int ticks) { if (this.CURRENT_SCREEN == "blocks") { return this.EDIT_BOX_BLOCKS.getEditBox().keyPressed(mouseX, mouseY, ticks); } else if (this.CURRENT_SCREEN == "items") { return this.EDIT_BOX_ITEMS.getEditBox().keyPressed(mouseX, mouseY, ticks); } else if (this.CURRENT_SCREEN == "commands") { return this.EDIT_BOX_COMMANDS.getEditBox().keyPressed(mouseX, mouseY, ticks); } return super.keyPressed(mouseX, mouseY, ticks); } I'd suggest starting by changing onClose to just @Override public void onClose() { ConfigurationManager.save(); super.onClose(); } and see if that fixes it. If not try commenting out your `keyPressed` function to see if that was it.