Skip to content

Commit

Permalink
video 7 done (advanced block)
Browse files Browse the repository at this point in the history
  • Loading branch information
natanmaia95 committed Aug 28, 2024
1 parent ccf97be commit 465bede
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.nateplays.my_neoforge_mod.block;

import com.nateplays.my_neoforge_mod.MyNeoForgeMod;
import com.nateplays.my_neoforge_mod.block.custom.MagicBlock;
import com.nateplays.my_neoforge_mod.item.ModItems;
import net.minecraft.util.valueproviders.UniformInt;
import net.minecraft.world.item.BlockItem;
Expand Down Expand Up @@ -40,7 +41,10 @@ public class ModBlocks {

public static final DeferredBlock<Block> NULBERRY_BUSH = registerBlock("nulberry_bush", NulberryBushBlock::new);


public static final DeferredBlock<Block> MAGIC_BLOCK = registerBlock("magic_block",
() -> new MagicBlock(
BlockBehaviour.Properties.of().strength(1f,2f).sound(SoundType.AMETHYST)
));

private static <T extends Block> DeferredBlock<T> registerBlock(String name, Supplier<T> block) {
DeferredBlock<T> toReturn = BLOCKS.register(name, block);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.nateplays.my_neoforge_mod.block.custom;

import com.nateplays.my_neoforge_mod.item.ModItems;
import net.minecraft.core.BlockPos;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.BlockHitResult;

public class MagicBlock extends Block {

public MagicBlock(Properties properties) {
super(properties);
}

@Override
protected InteractionResult useWithoutItem(BlockState state, Level level, BlockPos pos, Player player, BlockHitResult hitResult) {
// return super.useWithoutItem(state, level, pos, player, hitResult);
level.playSound(player, pos, SoundEvents.AMETHYST_BLOCK_CHIME, SoundSource.BLOCKS, 1f, 1f);
return InteractionResult.SUCCESS;
}

@Override
public void stepOn(Level level, BlockPos pos, BlockState state, Entity entity) {
// yes, item entities can step on blocks
if (entity instanceof ItemEntity itemEntity) {
if (itemEntity.getItem().getItem() == ModItems.MALACHITE_CHUNK.get()) {
itemEntity.setItem(new ItemStack(ModItems.MALACHITE_INGOT.get(), itemEntity.getItem().getCount()));
} else {
entity.setDeltaMovement(entity.getDeltaMovement().add(0, 0.5, 0));
}
}

super.stepOn(level, pos, state, entity);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class ModCreativeModeTabs {
output.accept(ModBlocks.MACHALITE_ORE);
output.accept(ModBlocks.MACHALITE_BLOCK);
output.accept(ModBlocks.NULBERRY_BUSH);
output.accept(ModBlocks.MAGIC_BLOCK);
})
.build());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemNameBlockItem;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.neoforge.registries.DeferredHolder;
import net.neoforged.neoforge.registries.DeferredItem;
import net.neoforged.neoforge.registries.DeferredRegister;

public class ModItems {

public static final DeferredRegister.Items ITEMS = DeferredRegister.createItems(MyNeoForgeMod.MODID);



public static final DeferredItem<Item> EARTH_CRYSTAL = ITEMS.register("earth_crystal",
() -> new Item(new Item.Properties()));
public static final DeferredItem<Item> MALACHITE_CHUNK = ITEMS.register("machalite_chunk",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"variants": {
"": {
"model": "my_neoforge_mod:block/magic_block"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "minecraft:block/cube_all",
"textures": {
"all": "my_neoforge_mod:block/magic_block"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 465bede

Please sign in to comment.