Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

NutronStar45

Members
  • Joined

  • Last visited

  1. Do I just send a packet to the server?
  2. How to get the key bindings of a player from the server side?
  3. I thought Minecraft is a client-side only class?
  4. How to get the key bindings of a player?
  5. I've changed my mind, as overriding vanilla blocks can cause compatibility issues
  6. How to get the block/entity a player is looking at? Edit: From server side
  7. You had a typo, it's "render_type", not "rendertype"
  8. Thank you, now it works!
  9. I'm making the resource pack of my mod, and I want to make my block look like torches, but I can't figure out why the textures appear opaque. Here's my model file: { "parent": "minecraft:block/template_torch", "textures": { "torch": "minecraft:block/torch" } }
  10. I'm making unlit torches, and I want to override the minecraft:torch block, but I get this error: `java.lang.RuntimeException: Invalid vanilla replacement`. Can I override vanilla blocks and block states? If so, how to do it? Here's my `TorchBlock.java`: package com.nutronstar45.chem.block.custom; import net.minecraft.core.BlockPos; import net.minecraft.core.particles.ParticleOptions; import net.minecraft.core.particles.ParticleTypes; import net.minecraft.util.RandomSource; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.state.BlockBehaviour; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.StateDefinition; import net.minecraft.world.level.block.state.properties.BlockStateProperties; import net.minecraft.world.level.block.state.properties.BooleanProperty; public class TorchBlock extends net.minecraft.world.level.block.TorchBlock { public static final BooleanProperty LIT = BlockStateProperties.LIT; public TorchBlock(BlockBehaviour.Properties properties, ParticleOptions particle) { super(properties, particle); this.registerDefaultState(this.stateDefinition.any().setValue(LIT, false)); } @Override public void animateTick(BlockState blockState, Level level, BlockPos blockPos, RandomSource random) { double flameX = (double)blockPos.getX() + 0.5D; double flameY = (double)blockPos.getY() + 0.7D; double flameZ = (double)blockPos.getZ() + 0.5D; level.addParticle(ParticleTypes.SMOKE, flameX, flameY, flameZ, 0.0D, 0.0D, 0.0D); level.addParticle(this.flameParticle, flameX, flameY, flameZ, 0.0D, 0.0D, 0.0D); } @Override protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) { builder.add(LIT); } } Here's my `ModBlocks.java`: package com.nutronstar45.chem.block; import com.nutronstar45.chem.Chem; import com.nutronstar45.chem.block.custom.StickBlock; import com.nutronstar45.chem.block.custom.TorchBlock; import com.nutronstar45.chem.block.custom.WallStickBlock; import net.minecraft.core.particles.ParticleTypes; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.SoundType; import net.minecraft.world.level.block.state.BlockBehaviour; import net.minecraft.world.level.material.Material; import net.minecraftforge.eventbus.api.IEventBus; import net.minecraftforge.registries.DeferredRegister; import net.minecraftforge.registries.ForgeRegistries; import net.minecraftforge.registries.RegistryObject; public class ModBlocks { public static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, Chem.MODID); public static final DeferredRegister<Block> VANILLA_BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, "minecraft"); public static final RegistryObject<Block> STICK = VANILLA_BLOCKS.register( "stick", () -> new StickBlock( BlockBehaviour.Properties.of(Material.DECORATION).noCollission().instabreak().sound(SoundType.WOOD))); public static final RegistryObject<Block> TORCH = VANILLA_BLOCKS.register( "torch", () -> new TorchBlock( BlockBehaviour.Properties.of(Material.DECORATION).noCollission().instabreak().lightLevel( blockState -> 14 ).sound(SoundType.WOOD), ParticleTypes.FLAME)); public static final RegistryObject<Block> WALL_STICK = VANILLA_BLOCKS.register( "wall_stick", () -> new WallStickBlock( BlockBehaviour.Properties.of(Material.DECORATION).noCollission().instabreak().sound(SoundType.WOOD).lootFrom(STICK))); public static void register(IEventBus eventBus) { VANILLA_BLOCKS.register(eventBus); BLOCKS.register(eventBus); } } Here's my `Chem.java`: package com.nutronstar45.chem; import com.nutronstar45.chem.block.ModBlocks; import com.nutronstar45.chem.item.ModItems; import com.nutronstar45.chem.sound.ModSoundEvents; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.eventbus.api.IEventBus; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; @Mod(Chem.MODID) public class Chem { public static final String MODID = "chem"; public Chem() { IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus(); ModBlocks.register(modEventBus); ModItems.register(modEventBus); ModSoundEvents.register(modEventBus); MinecraftForge.EVENT_BUS.register(this); } }
  11. runClient doesn't work when I right click runClient.launch, Run As, and 1 runClient in Eclipse, it had worked before. Running `gradlew runClient` in Terminal starts a Minecraft instance.
  12. Just realized that I didn't create particles, maybe I will do that later.
  13. I solved the problem, but I think there is a better solution. StickItem.java: package com.nutronstar45.chem.item.custom; import com.nutronstar45.chem.block.ModBlocks; import com.nutronstar45.chem.item.ModItems; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.tags.BlockTags; import net.minecraft.world.InteractionHand; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.BlockItem; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.HitResult; public class StickItem extends BlockItem { private static final int START_FIRE_TIME = 30; private int ticksUntilFire; public StickItem(Properties properties) { super(ModBlocks.STICK.get(), properties); } private boolean targetingPlanks(Player player) { BlockHitResult targetedBlock = (BlockHitResult)player.pick(5.0D, 0.0F, false); Direction direction = targetedBlock.getDirection(); BlockPos blockPos = targetedBlock.getBlockPos(); BlockState blockState = player.getLevel().getBlockState(blockPos); return targetedBlock.getType() == HitResult.Type.BLOCK && direction.getName() == "up" && blockState.is(BlockTags.PLANKS); } // Fires when a player is holding a Stick public void tick(Player player, boolean isKeyUseDown) { if (!player.getLevel().isClientSide()) { if (isKeyUseDown && targetingPlanks(player)) { if (ticksUntilFire > 0) { --ticksUntilFire; } else { startFire(player); ticksUntilFire = START_FIRE_TIME; } } else { ticksUntilFire = START_FIRE_TIME; } } } private void startFire(Player player) { player.getItemInHand(InteractionHand.MAIN_HAND).shrink(1); player.addItem(new ItemStack(ModItems.STICK_ON_FIRE.get())); } } ModEvents.java: package com.nutronstar45.chem.event; import com.nutronstar45.chem.Chem; import com.nutronstar45.chem.item.custom.StickItem; import net.minecraft.client.KeyMapping; import net.minecraft.client.Minecraft; import net.minecraftforge.event.TickEvent.Phase; import net.minecraftforge.event.TickEvent.PlayerTickEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; @Mod.EventBusSubscriber(modid = Chem.MODID) public class ModEvents { @SubscribeEvent public static void onPlayerTick(PlayerTickEvent event) { Minecraft instance = Minecraft.getInstance(); KeyMapping keyUse = instance.options.keyUse; if (event.player.getMainHandItem().getItem() instanceof StickItem) { StickItem stickItem = (StickItem)event.player.getMainHandItem().getItem(); if (event.phase == Phase.START) { stickItem.tick(event.player, keyUse.isDown()); } } } }

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.