Skip to content

Commit

Permalink
Started Bamboo Mat
Browse files Browse the repository at this point in the history
- Fixed Avocado Trees
- Fixed Bamboo Mat model
- Started Bamboo Mat GUI
  • Loading branch information
Nyancatpig committed Apr 30, 2022
1 parent 13fbbc3 commit c01c12a
Show file tree
Hide file tree
Showing 21 changed files with 582 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,18 @@

import com.mojang.logging.LogUtils;
import com.ncpbails.culturaldelights.block.ModBlocks;
import com.ncpbails.culturaldelights.block.entity.ModBlockEntities;
import com.ncpbails.culturaldelights.item.ModItems;
import com.ncpbails.culturaldelights.screen.BambooMatScreen;
import com.ncpbails.culturaldelights.screen.ModMenuTypes;
import net.minecraft.client.gui.screens.MenuScreens;
import net.minecraft.client.renderer.ItemBlockRenderTypes;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.world.level.block.Blocks;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import org.slf4j.Logger;
Expand All @@ -30,17 +37,40 @@ public CulturalDelights()

ModItems.register(eventBus);
ModBlocks.register(eventBus);
ModBlockEntities.register(eventBus);
ModMenuTypes.register(eventBus);

eventBus.addListener(this::setup);

eventBus.addListener(this::clientSetup);
// Register ourselves for server and other game events we are interested in
MinecraftForge.EVENT_BUS.register(this);
}

private void clientSetup(final FMLClientSetupEvent event) {
ItemBlockRenderTypes.setRenderLayer(ModBlocks.BAMBOO_MAT.get(), RenderType.cutoutMipped());
ItemBlockRenderTypes.setRenderLayer(ModBlocks.WILD_CUCUMBERS.get(), RenderType.cutoutMipped());
ItemBlockRenderTypes.setRenderLayer(ModBlocks.WILD_CORN.get(), RenderType.cutoutMipped());
ItemBlockRenderTypes.setRenderLayer(ModBlocks.WILD_EGGPLANTS.get(), RenderType.cutoutMipped());
ItemBlockRenderTypes.setRenderLayer(ModBlocks.AVOCADO_LEAVES.get(), RenderType.cutoutMipped());
ItemBlockRenderTypes.setRenderLayer(ModBlocks.AVOCADO_SAPLING.get(), RenderType.cutoutMipped());
//ItemBlockRenderTypes.setRenderLayer(ModBlocks.AVOCADO_PIT.get(), RenderType.cutoutMipped());
ItemBlockRenderTypes.setRenderLayer(ModBlocks.CUCUMBERS.get(), RenderType.cutoutMipped());
ItemBlockRenderTypes.setRenderLayer(ModBlocks.EGGPLANTS.get(), RenderType.cutoutMipped());
ItemBlockRenderTypes.setRenderLayer(ModBlocks.WHITE_EGGPLANTS.get(), RenderType.cutoutMipped());
ItemBlockRenderTypes.setRenderLayer(ModBlocks.CORN.get(), RenderType.cutoutMipped());
ItemBlockRenderTypes.setRenderLayer(ModBlocks.CORN_UPPER.get(), RenderType.cutoutMipped());


MenuScreens.register(ModMenuTypes.BAMBOO_MAT_MENU.get(), BambooMatScreen::new);

//ModItemProperties.addCustomItemProperties();
}

private void setup(final FMLCommonSetupEvent event)
{
// some preinit code
LOGGER.info("HELLO FROM PREINIT");
LOGGER.info("DIRT BLOCK >> {}", Blocks.DIRT.getRegistryName());

}
}
56 changes: 28 additions & 28 deletions src/main/java/com/ncpbails/culturaldelights/block/ModBlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.ncpbails.culturaldelights.CulturalDelights;
import com.ncpbails.culturaldelights.block.custom.*;
import com.ncpbails.culturaldelights.item.ModItems;
import com.ncpbails.culturaldelights.world.feature.tree.AvocadoPitGrower;
import com.ncpbails.culturaldelights.world.feature.tree.AvocadoTreeGrower;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
Expand Down Expand Up @@ -34,20 +35,20 @@ public class ModBlocks {
.strength(0, 1f).noOcclusion()), FarmersDelight.CREATIVE_TAB, false, 0);

public static final RegistryObject<Block> BAMBOO_MAT = registerBlock("bamboo_mat",
() -> new Block(BlockBehaviour.Properties.of(Material.BAMBOO, MaterialColor.COLOR_GREEN)
() -> new BambooMatBlock(BlockBehaviour.Properties.of(Material.BAMBOO, MaterialColor.COLOR_GREEN)
.strength(0, 1f).noOcclusion()), FarmersDelight.CREATIVE_TAB, true, 0);

public static final RegistryObject<Block> WILD_CUCUMBERS = registerBlock("wild_cucumbers",
() -> new Block(BlockBehaviour.Properties.of(Material.WOOD, MaterialColor.COLOR_GREEN)
.strength(0, 0f).noOcclusion()), FarmersDelight.CREATIVE_TAB, false, 0);
() -> new Block(BlockBehaviour.Properties.copy(vectorwing.farmersdelight.common.registry.ModBlocks.WILD_BEETROOTS.get())
.noOcclusion()), FarmersDelight.CREATIVE_TAB, false, 0);

public static final RegistryObject<Block> WILD_CORN = registerBlock("wild_corn",
() -> new Block(BlockBehaviour.Properties.of(Material.WOOD, MaterialColor.COLOR_GREEN)
.strength(0, 0f).noOcclusion()), FarmersDelight.CREATIVE_TAB, false, 0);
() -> new Block(BlockBehaviour.Properties.copy(vectorwing.farmersdelight.common.registry.ModBlocks.WILD_BEETROOTS.get())
.noOcclusion()), FarmersDelight.CREATIVE_TAB, false, 0);

public static final RegistryObject<Block> WILD_EGGPLANTS = registerBlock("wild_eggplants",
() -> new Block(BlockBehaviour.Properties.of(Material.WOOD, MaterialColor.COLOR_GREEN)
.strength(0, 0f).noOcclusion()), FarmersDelight.CREATIVE_TAB, false, 0);
() -> new Block(BlockBehaviour.Properties.copy(vectorwing.farmersdelight.common.registry.ModBlocks.WILD_BEETROOTS.get())
.noOcclusion()), FarmersDelight.CREATIVE_TAB, false, 0);

public static final RegistryObject<Block> AVOCADO_LOG = registerBlock("avocado_log",
() -> new RotatedPillarBlock(BlockBehaviour.Properties.copy(Blocks.JUNGLE_LOG)) {
Expand All @@ -70,15 +71,14 @@ public class ModBlocks {
}, FarmersDelight.CREATIVE_TAB, true, 0);

public static final RegistryObject<Block> AVOCADO_LEAVES = registerBlock("avocado_leaves",
() -> new LeavesBlock(BlockBehaviour.Properties.of(Material.LEAVES, MaterialColor.COLOR_GREEN)
.strength(0, 0.2f).noOcclusion()) {
() -> new LeavesBlock(BlockBehaviour.Properties.copy(Blocks.JUNGLE_LEAVES)) {
@Override public boolean isFlammable(BlockState state, BlockGetter world, BlockPos pos, Direction face) { return true; }
@Override public int getFlammability(BlockState state, BlockGetter world, BlockPos pos, Direction face) { return 60; }
@Override public int getFireSpreadSpeed(BlockState state, BlockGetter world, BlockPos pos, Direction face) { return 30; }
}, FarmersDelight.CREATIVE_TAB, true, 0);

public static final RegistryObject<Block> AVOCADO_SAPLING = registerBlock("avocado_sapling",
() -> new SaplingBlock(new AvocadoTreeGrower(), BlockBehaviour.Properties.copy(Blocks.OAK_SAPLING)), FarmersDelight.CREATIVE_TAB, false, 0);
() -> new SaplingBlock(new AvocadoTreeGrower(), BlockBehaviour.Properties.copy(Blocks.OAK_SAPLING)), FarmersDelight.CREATIVE_TAB, true, 0);

public static final RegistryObject<Block> CUCUMBERS = registerBlockWithoutBlockItem("cucumbers",
() -> new CucumbersBlock(BlockBehaviour.Properties.copy(Blocks.WHEAT).noOcclusion()));
Expand All @@ -89,38 +89,38 @@ public class ModBlocks {
public static final RegistryObject<Block> EGGPLANTS = registerBlockWithoutBlockItem("eggplants",
() -> new EggplantsBlock(BlockBehaviour.Properties.copy(Blocks.WHEAT).noOcclusion()));

public static final RegistryObject<Block> CORN = registerBlock("corn",
() -> new CornBlock(BlockBehaviour.Properties.copy(Blocks.WHEAT).noOcclusion()), FarmersDelight.CREATIVE_TAB, false, 0);
public static final RegistryObject<Block> CORN = registerBlockWithoutBlockItem("corn",
() -> new CornBlock(BlockBehaviour.Properties.copy(Blocks.WHEAT).noOcclusion()));

public static final RegistryObject<Block> CORN_UPPER = registerBlock("corn_upper",
() -> new CornUpperBlock(BlockBehaviour.Properties.copy(Blocks.WHEAT).noOcclusion()), FarmersDelight.CREATIVE_TAB, false, 0);
public static final RegistryObject<Block> CORN_UPPER = registerBlockWithoutBlockItem("corn_upper",
() -> new CornUpperBlock(BlockBehaviour.Properties.copy(Blocks.WHEAT).noOcclusion()));

//public static final RegistryObject<Block> AVOCADO_PIT = registerBlock("avocado_pit",
// () -> new AvocadoPitBlock(new AvocadoPit(), (BlockBehaviour.Properties.copy(Blocks.OAK_SAPLING).noOcclusion()), FarmersDelight.CREATIVE_TAB, false, 0);
public static final RegistryObject<Block> AVOCADO_PIT = registerBlock("avocado_pit",
() -> new AvocadoPitBlock(new AvocadoPitGrower(), BlockBehaviour.Properties.copy(Blocks.OAK_SAPLING)), FarmersDelight.CREATIVE_TAB, false, 0);

public static final RegistryObject<Block> AVOCADO_CRATE = registerBlock("avocado_crate",
() -> new Block(BlockBehaviour.Properties.of(Material.WOOD, MaterialColor.COLOR_GREEN)
.strength(2, 3f)), FarmersDelight.CREATIVE_TAB, false, 0);
() -> new Block(BlockBehaviour.Properties.copy(vectorwing.farmersdelight.common.registry.ModBlocks.CARROT_CRATE.get()))
, FarmersDelight.CREATIVE_TAB, false, 0);

public static final RegistryObject<Block> CUCUMBER_CRATE = registerBlock("cucumber_crate",
() -> new Block(BlockBehaviour.Properties.of(Material.WOOD, MaterialColor.COLOR_GREEN)
.strength(2, 3f)), FarmersDelight.CREATIVE_TAB, false, 0);
() -> new Block(BlockBehaviour.Properties.copy(vectorwing.farmersdelight.common.registry.ModBlocks.CARROT_CRATE.get()))
, FarmersDelight.CREATIVE_TAB, false, 0);

public static final RegistryObject<Block> PICKLE_CRATE = registerBlock("pickle_crate",
() -> new Block(BlockBehaviour.Properties.of(Material.WOOD, MaterialColor.COLOR_GREEN)
.strength(2, 3f)), FarmersDelight.CREATIVE_TAB, false, 0);
() -> new Block(BlockBehaviour.Properties.copy(vectorwing.farmersdelight.common.registry.ModBlocks.CARROT_CRATE.get()))
, FarmersDelight.CREATIVE_TAB, false, 0);

public static final RegistryObject<Block> CORN_COB_CRATE = registerBlock("corn_cob_crate",
() -> new Block(BlockBehaviour.Properties.of(Material.WOOD, MaterialColor.COLOR_GREEN)
.strength(2, 3f)), FarmersDelight.CREATIVE_TAB, false, 0);
() -> new Block(BlockBehaviour.Properties.copy(vectorwing.farmersdelight.common.registry.ModBlocks.CARROT_CRATE.get()))
, FarmersDelight.CREATIVE_TAB, false, 0);

public static final RegistryObject<Block> EGGPLANT_CRATE = registerBlock("eggplant_crate",
() -> new Block(BlockBehaviour.Properties.of(Material.WOOD, MaterialColor.COLOR_GREEN)
.strength(2, 3f)), FarmersDelight.CREATIVE_TAB, false, 0);
() -> new Block(BlockBehaviour.Properties.copy(vectorwing.farmersdelight.common.registry.ModBlocks.CARROT_CRATE.get()))
, FarmersDelight.CREATIVE_TAB, false, 0);

public static final RegistryObject<Block> WHITE_EGGPLANT_CRATE = registerBlock("white_eggplant_crate",
() -> new Block(BlockBehaviour.Properties.of(Material.WOOD, MaterialColor.COLOR_GREEN)
.strength(2, 3f)), FarmersDelight.CREATIVE_TAB, false, 0);
() -> new Block(BlockBehaviour.Properties.copy(vectorwing.farmersdelight.common.registry.ModBlocks.CARROT_CRATE.get()))
, FarmersDelight.CREATIVE_TAB, false, 0);



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@

public class AvocadoPitBlock extends SaplingBlock {

private static final VoxelShape SHAPE_PIT = (VoxelShape) Stream.of(
Block.box(6, 0, 6, 10, 3, 10)
);
private static final VoxelShape SHAPE_PIT = Block.box(6, 0, 6, 10, 3, 10);

public AvocadoPitBlock(AbstractTreeGrower treeIn, Properties properties) {
super(treeIn, properties);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,35 @@
package com.ncpbails.culturaldelights.block.custom;


import com.ncpbails.culturaldelights.block.entity.ModBlockEntities;
import com.ncpbails.culturaldelights.block.entity.custom.BambooMatBlockEntity;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Mirror;
import net.minecraft.world.level.block.Rotation;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.*;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityTicker;
import net.minecraft.world.level.block.entity.BlockEntityType;
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.DirectionProperty;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraftforge.network.NetworkHooks;
import org.jetbrains.annotations.Nullable;

import javax.annotation.Nullable;
import java.util.Optional;
import java.util.stream.Stream;

public class BambooMatBlock extends Block {
public class BambooMatBlock extends BaseEntityBlock {
public static final DirectionProperty FACING = BlockStateProperties.HORIZONTAL_FACING;

public BambooMatBlock(Properties properties) {
Expand Down Expand Up @@ -55,4 +65,50 @@ public BlockState mirror(BlockState pState, Mirror pMirror) {
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> pBuilder) {
pBuilder.add(FACING);
}
}

/* BLOCK ENTITY */

@Override
public RenderShape getRenderShape(BlockState pState) {
return RenderShape.MODEL;
}

@Override
public void onRemove(BlockState pState, Level pLevel, BlockPos pPos, BlockState pNewState, boolean pIsMoving) {
if (pState.getBlock() != pNewState.getBlock()) {
BlockEntity blockEntity = pLevel.getBlockEntity(pPos);
if (blockEntity instanceof BambooMatBlockEntity) {
((BambooMatBlockEntity) blockEntity).drops();
}
}
super.onRemove(pState, pLevel, pPos, pNewState, pIsMoving);
}

@Override
public InteractionResult use(BlockState pState, Level pLevel, BlockPos pPos,
Player pPlayer, InteractionHand pHand, BlockHitResult pHit) {
if (!pLevel.isClientSide()) {
BlockEntity entity = pLevel.getBlockEntity(pPos);
if(entity instanceof BambooMatBlockEntity) {
NetworkHooks.openGui(((ServerPlayer)pPlayer), (BambooMatBlockEntity)entity, pPos);
} else {
throw new IllegalStateException("Our Container provider is missing!");
}
}

return InteractionResult.sidedSuccess(pLevel.isClientSide());
}

@Nullable
@Override
public BlockEntity newBlockEntity(BlockPos pPos, BlockState pState) {
return new BambooMatBlockEntity(pPos, pState);
}

@Nullable
@Override
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level pLevel, BlockState pState, BlockEntityType<T> pBlockEntityType) {
return createTickerHelper(pBlockEntityType, ModBlockEntities.BAMBOO_MAT_BLOCK_ENTITY.get(),
BambooMatBlockEntity::tick);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.ncpbails.culturaldelights.block.entity;

import com.ncpbails.culturaldelights.CulturalDelights;
import com.ncpbails.culturaldelights.block.ModBlocks;
import com.ncpbails.culturaldelights.block.entity.custom.BambooMatBlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegistryObject;

public class ModBlockEntities {

public static final DeferredRegister<BlockEntityType<?>> BLOCK_ENTITIES =
DeferredRegister.create(ForgeRegistries.BLOCK_ENTITIES, CulturalDelights.MOD_ID);

public static final RegistryObject<BlockEntityType<BambooMatBlockEntity>> BAMBOO_MAT_BLOCK_ENTITY =
BLOCK_ENTITIES.register("bamboo_mat_block_entity", () ->
BlockEntityType.Builder.of(BambooMatBlockEntity::new,
ModBlocks.BAMBOO_MAT.get()).build(null));


public static void register(IEventBus eventBus) {
BLOCK_ENTITIES.register(eventBus);
}
}
Loading

0 comments on commit c01c12a

Please sign in to comment.