Skip to content

Commit

Permalink
add summoning table!
Browse files Browse the repository at this point in the history
it doesn't do anything yet, no, but it's exciting! isn't it?
  • Loading branch information
afamiliarquiet committed Oct 14, 2024
1 parent 291675a commit a740774
Show file tree
Hide file tree
Showing 12 changed files with 199 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.github.afamiliarquiet.familiar_magic.block;

import com.google.common.collect.ImmutableList;
import net.minecraft.MethodsReturnNonnullByDefault;
import net.minecraft.core.BlockPos;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.util.RandomSource;
Expand All @@ -18,8 +19,11 @@
import net.neoforged.neoforge.common.ItemAbility;
import org.jetbrains.annotations.Nullable;

import javax.annotation.ParametersAreNonnullByDefault;
import java.util.List;

@MethodsReturnNonnullByDefault
@ParametersAreNonnullByDefault
public class EnchantedCandleBlock extends CandleBlock {
private static final List<List<Vec3>> FLAME_OFFSETS = ImmutableList.of(
ImmutableList.of(new Vec3(0.46875, 0.875, 0.46875)),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package io.github.afamiliarquiet.familiar_magic.block;

import io.github.afamiliarquiet.familiar_magic.block.entity.SummoningTableBlockEntity;
import io.github.afamiliarquiet.familiar_magic.item.FamiliarItems;
import net.minecraft.core.registries.Registries;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.CandleBlock;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.neoforge.registries.DeferredBlock;
Expand All @@ -17,12 +20,32 @@

public class FamiliarBlocks {
public static final DeferredRegister.Blocks BLOCKS = DeferredRegister.createBlocks(MOD_ID);
public static final DeferredRegister<BlockEntityType<?>> BLOCK_ENTITY_TYPES = DeferredRegister.create(Registries.BLOCK_ENTITY_TYPE, MOD_ID);



public static final DeferredBlock<CandleBlock> ENCHANTED_CANDLE_BLOCK = registerBlockWithItem(
"enchanted_candle",
() -> new EnchantedCandleBlock(BlockBehaviour.Properties.ofFullCopy(Blocks.CANDLE)) // maybe toy with properties later
);

public static final DeferredBlock<SummoningTableBlock> SUMMONING_TABLE_BLOCK = registerBlockWithItem(
"summoning_table",
() -> new SummoningTableBlock(BlockBehaviour.Properties.ofFullCopy(Blocks.ENCHANTING_TABLE))
);

@SuppressWarnings("DataFlowIssue") // totally get it. yeah. it says notnull. but neoforge docs say it's fine so it's fine
public static final Supplier<BlockEntityType<SummoningTableBlockEntity>> SUMMONING_TABLE_BLOCK_ENTITY = BLOCK_ENTITY_TYPES.register(

"summoning_table_block_entity",
() -> BlockEntityType.Builder.of(
SummoningTableBlockEntity::new,
SUMMONING_TABLE_BLOCK.get()
).build(null)
);



private static <T extends Block> DeferredBlock<T> registerBlockWithItem(String name, Supplier<T> block) {
DeferredBlock<T> deferredBlock = BLOCKS.register(name, block);
FamiliarItems.ITEMS.register(name, () -> new BlockItem(deferredBlock.get(), new Item.Properties()));
Expand All @@ -31,5 +54,6 @@ private static <T extends Block> DeferredBlock<T> registerBlockWithItem(String n

public static void register(IEventBus eventBus) {
BLOCKS.register(eventBus);
BLOCK_ENTITY_TYPES.register(eventBus);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package io.github.afamiliarquiet.familiar_magic.block;

import com.mojang.serialization.MapCodec;
import io.github.afamiliarquiet.familiar_magic.block.entity.SummoningTableBlockEntity;
import net.minecraft.MethodsReturnNonnullByDefault;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.block.BaseEntityBlock;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.RenderShape;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.pathfinder.PathComputationType;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;

import javax.annotation.ParametersAreNonnullByDefault;

@MethodsReturnNonnullByDefault
@ParametersAreNonnullByDefault
public class SummoningTableBlock extends BaseEntityBlock {
public static final MapCodec<SummoningTableBlock> CODEC = simpleCodec(SummoningTableBlock::new);
protected static final VoxelShape SHAPE = Block.box(0.0, 0.0, 0.0, 16.0, 12.0, 16.0);

@Override
protected MapCodec<? extends BaseEntityBlock> codec() {
return CODEC;
}

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

protected boolean useShapeForLightOcclusion(BlockState state) {
return true;
}

@Override
protected VoxelShape getShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context) {
return SHAPE;
}

@Override
protected RenderShape getRenderShape(BlockState state) {
return RenderShape.MODEL;
}

@Override
public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
return new SummoningTableBlockEntity(pos, state);
}

@Override
protected boolean isPathfindable(BlockState state, PathComputationType pathComputationType) {
return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package io.github.afamiliarquiet.familiar_magic.block.entity;

import io.github.afamiliarquiet.familiar_magic.block.FamiliarBlocks;
import net.minecraft.MethodsReturnNonnullByDefault;
import net.minecraft.core.BlockPos;
import net.minecraft.core.HolderLookup;
import net.minecraft.core.component.DataComponentMap;
import net.minecraft.core.component.DataComponents;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.world.Nameable;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;

import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;

@MethodsReturnNonnullByDefault
@ParametersAreNonnullByDefault
public class SummoningTableBlockEntity extends BlockEntity implements Nameable {
@Nullable
private Component name;

public SummoningTableBlockEntity(BlockPos pos, BlockState blockState) {
super(FamiliarBlocks.SUMMONING_TABLE_BLOCK_ENTITY.get(), pos, blockState);
}

@Override
protected void saveAdditional(CompoundTag tag, HolderLookup.Provider registries) {
super.saveAdditional(tag, registries);
if (this.name != null) {
tag.putString("CustomName", Component.Serializer.toJson(this.name, registries));
}
}

@Override
protected void loadAdditional(CompoundTag tag, HolderLookup.Provider registries) {
super.loadAdditional(tag, registries);
if (tag.contains("CustomName", 8)) {
this.name = parseCustomNameSafe(tag.getString("CustomName"), registries);
}
}

@Override
public Component getName() {
return name != null ? name : Component.translatable("container.familiar_magic.summon");
}

@Nullable
@Override
public Component getCustomName() {
return this.name;
}

@Override
protected void applyImplicitComponents(BlockEntity.DataComponentInput componentInput) {
super.applyImplicitComponents(componentInput);
this.name = componentInput.get(DataComponents.CUSTOM_NAME);
}

@Override
protected void collectImplicitComponents(DataComponentMap.Builder components) {
super.collectImplicitComponents(components);
components.set(DataComponents.CUSTOM_NAME, this.name);
}

@SuppressWarnings("deprecation") // i mean yeah but also. it's still used in another method so idk
@Override
public void removeComponentsFromTag(CompoundTag tag) {
tag.remove("CustomName");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,33 @@
import net.minecraft.world.item.CreativeModeTabs;
import net.minecraft.world.item.Items;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.common.EventBusSubscriber;
import net.neoforged.neoforge.event.BuildCreativeModeTabContentsEvent;
import net.neoforged.neoforge.registries.DeferredRegister;

import static io.github.afamiliarquiet.familiar_magic.FamiliarMagic.MOD_ID;

@EventBusSubscriber(modid = MOD_ID, bus = EventBusSubscriber.Bus.MOD)
public class FamiliarItems {
public static final DeferredRegister.Items ITEMS = DeferredRegister.createItems(MOD_ID);

public static void register(IEventBus eventBus) {
ITEMS.register(eventBus);
// i feel like i should be able to get away with using the @EventBusSubscriber instead of having to pass it in
// but i guess i have to call something here anyway so whatever
eventBus.addListener(FamiliarItems::mrwBuildCreativeModeTabContents);
}

@SubscribeEvent
private static void mrwBuildCreativeModeTabContents(BuildCreativeModeTabContentsEvent event) {
// // oOOooOOo \\ \\ spoidah

if (event.getTabKey() == CreativeModeTabs.FUNCTIONAL_BLOCKS) {
event.insertBefore(
event.insertAfter(
Items.CANDLE.getDefaultInstance(),
FamiliarBlocks.ENCHANTED_CANDLE_BLOCK.toStack(),
CreativeModeTab.TabVisibility.PARENT_AND_SEARCH_TABS
);
event.insertAfter(
Items.ENCHANTING_TABLE.getDefaultInstance(),
FamiliarBlocks.SUMMONING_TABLE_BLOCK.toStack(),
CreativeModeTab.TabVisibility.PARENT_AND_SEARCH_TABS
);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"variants": {
"": {
"model": "familiar_magic:block/summoning_table"
}
}
}
4 changes: 3 additions & 1 deletion src/main/resources/assets/familiar_magic/lang/en_us.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{
"block.familiar_magic.enchanted_candle": "Enchanted Candle"
"block.familiar_magic.enchanted_candle": "Enchanted Candle",
"block.familiar_magic.summoning_table": "Summoning Table",
"container.familiar_magic.summon": "Summon"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"parent": "minecraft:block/block",
"textures": {
"particle": "familiar_magic:block/summoning_table_bottom",
"bottom": "familiar_magic:block/summoning_table_bottom",
"top": "familiar_magic:block/summoning_table_top",
"side": "familiar_magic:block/summoning_table_side"
},
"elements": [
{ "from": [ 0, 0, 0 ],
"to": [ 16, 12, 16 ],
"faces": {
"down": { "uv": [ 0, 0, 16, 16 ], "texture": "#bottom", "cullface": "down" },
"up": { "uv": [ 0, 0, 16, 16 ], "texture": "#top" },
"north": { "uv": [ 0, 4, 16, 16 ], "texture": "#side", "cullface": "north" },
"south": { "uv": [ 0, 4, 16, 16 ], "texture": "#side", "cullface": "south" },
"west": { "uv": [ 0, 4, 16, 16 ], "texture": "#side", "cullface": "west" },
"east": { "uv": [ 0, 4, 16, 16 ], "texture": "#side", "cullface": "east" }
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"parent": "familiar_magic:block/summoning_table"
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 a740774

Please sign in to comment.