-
Posts
16 -
Joined
-
Last visited
Recent Profile Visitors
The recent visitors block is disabled and is not being shown to other users.
NutronStar45's Achievements

Tree Puncher (2/8)
1
Reputation
-
How to get the key bindings of a player?
NutronStar45 replied to NutronStar45's topic in Modder Support
Do I just send a packet to the server? -
How to get the key bindings of a player?
NutronStar45 replied to NutronStar45's topic in Modder Support
I thought Minecraft is a client-side only class? -
Get the block/entity a player is looking at
NutronStar45 replied to NutronStar45's topic in Modder Support
And? -
How to get the key bindings of a player?
-
[1.19] Overriding vanilla block and replace block states
NutronStar45 replied to NutronStar45's topic in Modder Support
I've changed my mind, as overriding vanilla blocks can cause compatibility issues -
How to get the block/entity a player is looking at? Edit: From server side
-
You had a typo, it's "render_type", not "rendertype"
-
Thank you, now it works!
-
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" } }
-
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); } }
-
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()); } } } }