diff --git a/src/main/java/com/uncreativebunch/magicmod/block/ModBlocks.java b/src/main/java/com/uncreativebunch/magicmod/block/ModBlocks.java index d221ae9..3eb060c 100644 --- a/src/main/java/com/uncreativebunch/magicmod/block/ModBlocks.java +++ b/src/main/java/com/uncreativebunch/magicmod/block/ModBlocks.java @@ -1,8 +1,10 @@ package com.uncreativebunch.magicmod.block; import com.uncreativebunch.magicmod.MagicMod; +import com.uncreativebunch.magicmod.block.crafting.MagicalCrafterBlock; import net.minecraft.block.AbstractBlock; import net.minecraft.block.Block; +import net.minecraft.block.SlabBlock; import net.minecraft.item.BlockItem; import net.minecraft.item.Item; import net.minecraft.registry.Registries; @@ -19,7 +21,7 @@ public class ModBlocks { public static final Block MAGICAL_CRAFTING_TABLE = register( "magical_crafting_table", - Block::new, + MagicalCrafterBlock::new, AbstractBlock.Settings .create() .sounds(BlockSoundGroup.AMETHYST_BLOCK), @@ -60,7 +62,7 @@ public class ModBlocks { Registry.register(Registries.ITEM, itemKey, blockItem); } - // Finally return the block we want to register. + // Return the block we want to register. return Registry.register(Registries.BLOCK, blockKey, block); } diff --git a/src/main/java/com/uncreativebunch/magicmod/block/crafting/MagicalCrafterBlock.java b/src/main/java/com/uncreativebunch/magicmod/block/crafting/MagicalCrafterBlock.java new file mode 100644 index 0000000..275a177 --- /dev/null +++ b/src/main/java/com/uncreativebunch/magicmod/block/crafting/MagicalCrafterBlock.java @@ -0,0 +1,47 @@ +package com.uncreativebunch.magicmod.block.crafting; + +import com.uncreativebunch.magicmod.MagicMod; +import net.minecraft.block.AbstractBlock; +import net.minecraft.block.BlockState; +import net.minecraft.block.SlabBlock; +import net.minecraft.entity.EntityType; +import net.minecraft.entity.LightningEntity; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.util.ActionResult; +import net.minecraft.util.hit.BlockHitResult; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; + +public class MagicalCrafterBlock extends SlabBlock { + + /** + * Creates a new MagicalCrafterBlock. + * @param settings The settings of the block. + */ + public MagicalCrafterBlock(AbstractBlock.Settings settings) { super(settings); } + + /** + * Occurs whenever this block is used. This is intended to open a crafting window in the future. + * @param state The current {@link BlockState} of this block. + * @param world The {@link World} that this block exists in. + * @param pos The {@link BlockPos} that this block is at. + * @param player The {@link PlayerEntity} that used this object. + * @param hit The {@link BlockHitResult} that contains information about this interaction. + * @return Whether the action passed, was canceled, or succeeded. + */ + @Override + protected ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, BlockHitResult hit) { + if (world.isClient) return ActionResult.PASS; + + MagicMod.LOGGER.info("Block was used at location {}", pos.toShortString()); + + MagicMod.LOGGER.info("Electrocuting player..."); + BlockPos playerPos = player.getBlockPos(); + LightningEntity lightningEntity = new LightningEntity(EntityType.LIGHTNING_BOLT, world); + lightningEntity.setPosition(playerPos.toCenterPos()); + world.spawnEntity(lightningEntity); + MagicMod.LOGGER.info("Player electrocuted."); + + return ActionResult.SUCCESS; + } +}