Skip to content

Commit

Permalink
Finish Note Block
Browse files Browse the repository at this point in the history
c
  • Loading branch information
Napero committed Dec 27, 2022
1 parent ae754f9 commit e6e8a58
Show file tree
Hide file tree
Showing 11 changed files with 95 additions and 31 deletions.
5 changes: 5 additions & 0 deletions src/main/java/fr/hugman/mubble/MubbleClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,17 @@
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap;
import net.fabricmc.fabric.api.client.rendering.v1.BlockEntityRendererRegistry;
import net.minecraft.client.render.RenderLayer;

@Environment(EnvType.CLIENT)
public class MubbleClient implements ClientModInitializer {
@Override
public void onInitializeClient() {
BlockRenderLayerMap.INSTANCE.putBlock(SuperMarioContent.RED_BEEP_BLOCK, RenderLayer.getCutout());
BlockRenderLayerMap.INSTANCE.putBlock(SuperMarioContent.BLUE_BEEP_BLOCK, RenderLayer.getCutout());

BlockEntityRendererRegistry.register(SuperMarioContent.BUMPED_BLOCK_ENTITY_TYPE, BumpedBlockEntityRenderer::new);
}
}
73 changes: 56 additions & 17 deletions src/main/java/fr/hugman/mubble/block/BeepBlock.java
Original file line number Diff line number Diff line change
@@ -1,50 +1,89 @@
package fr.hugman.mubble.block;

import fr.hugman.mubble.Mubble;
import fr.hugman.mubble.registry.SuperMarioContent;
//Komerish is a cool dude. (sometimes (all the ((some)time))

import net.minecraft.SharedConstants;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.ShapeContext;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.BooleanProperty;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.random.Random;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.util.shape.VoxelShapes;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;

public class BeepBlock extends Block {
private static final int COOLDOWN = SharedConstants.TICKS_PER_SECOND * 4;
public static final BooleanProperty FRAME = BooleanProperty.of("frame");

public BeepBlock(Settings settings) {
public final int offset;

public BeepBlock(Settings settings, int offset) {
super(settings);
setDefaultState(getDefaultState().with(FRAME, false));
this.offset = offset;
this.setDefaultState(getDefaultState().with(FRAME, false));
}

@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
builder.add(FRAME);
}

@Override
public boolean isTranslucent(BlockState state, BlockView world, BlockPos pos) {
return state.get(FRAME);
}

@Override
public VoxelShape getCollisionShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
return state.get(FRAME) ? VoxelShapes.empty() : VoxelShapes.fullCube();
}

@Override
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
if(context.isHolding(this.asItem())) return VoxelShapes.fullCube();
return state.get(FRAME) ? VoxelShapes.empty() : VoxelShapes.fullCube();
}

@Override
public float getAmbientOcclusionLightLevel(BlockState state, BlockView world, BlockPos pos) {
return state.get(FRAME) ? 1.0F : super.getAmbientOcclusionLightLevel(state, world, pos);
}

@Nullable
@Override
public BlockState getPlacementState(ItemPlacementContext ctx) {
return getStateAtTime(ctx.getWorld().getTime());
}

@Override
public void onBlockAdded(BlockState state, World world, BlockPos pos, BlockState oldState, boolean notify) {
world.scheduleBlockTick(pos, state.getBlock(), (int) (80 - world.getTime() %80));
world.scheduleBlockTick(pos, state.getBlock(), this.getNextUpdateTickDelta(world.getTime()));
}

@Override
public void scheduledTick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
if(!world.isClient()) {
this.trigger(world, pos, state);
Mubble.LOGGER.info("SPIN ME!");
world.scheduleBlockTick(pos, state.getBlock(), (int) (80 - world.getTime()%80));
long worldTime = world.getTime();
world.setBlockState(pos, getStateAtTime(worldTime));
world.scheduleBlockTick(pos, state.getBlock(), this.getNextUpdateTickDelta(worldTime));
}
}
public void trigger(World world, BlockPos pos, BlockState state) {
////////////////world.setBlockState(pos, SuperMarioContent.BEEP_BLOCK_FRAME.getDefaultState(), Block.NOTIFY_LISTENERS);
if (! state.get(FRAME)) {
world.setBlockState(pos, state.with(FRAME, true));
}
else {
world.setBlockState(pos, state.with(FRAME, false));
}

public int getNextUpdateTickDelta(long worldTime) {
int delta = (int) (COOLDOWN - worldTime);
if(delta == 0) return COOLDOWN;
else return delta % COOLDOWN;
}
}

public BlockState getStateAtTime(long worldTime) {
boolean frame = (int) ((worldTime + this.offset) % (COOLDOWN * 2)) < COOLDOWN;
return this.getDefaultState().with(FRAME, frame);
}
}
17 changes: 10 additions & 7 deletions src/main/java/fr/hugman/mubble/registry/SuperMarioContent.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package fr.hugman.mubble.registry;

import fr.hugman.dawn.DawnFactory;
import fr.hugman.dawn.Registrar;
import fr.hugman.dawn.block.DawnBlockSettings;
import fr.hugman.mubble.Mubble;
Expand All @@ -22,27 +23,28 @@ public class SuperMarioContent {
public static final QuestionBlock QUESTION_BLOCK = new QuestionBlock(DawnBlockSettings.copy(Blocks.IRON_BLOCK).mapColor(MapColor.YELLOW).item());
public static final Block EMPTY_BLOCK = new EmptyBlock(DawnBlockSettings.copy(Blocks.IRON_BLOCK).mapColor(MapColor.BROWN).item());
public static final Block BRICK_BLOCK = new Block(DawnBlockSettings.copy(Blocks.BRICKS).mapColor(MapColor.BROWN).item());
public static final Block GOLD_BLOCK = new Block(DawnBlockSettings.copy(Blocks.BRICKS).mapColor(MapColor.YELLOW).item());
public static final Block GOLD_BLOCK = new Block(DawnBlockSettings.copy(Blocks.BRICKS).mapColor(MapColor.YELLOW).item());
public static final NoteBlock NOTE_BLOCK = new NoteBlock(SoundEvents.BLOCK_NOTE_BLOCK_HARP.value(), SoundEvents.BLOCK_NOTE_BLOCK_HARP.value(), DawnBlockSettings.copy(Blocks.QUARTZ_BLOCK).mapColor(MapColor.WHITE).item());
public static final Block BUMPED_BLOCK = new BumpedBlock(DawnBlockSettings.copy(Blocks.BRICKS).mapColor(MapColor.BROWN).strength(-1, 3600000).dropsNothing().nonOpaque());
public static final SnakeBlock SNAKE_BLOCK = new SnakeBlock(DawnBlockSettings.copy(Blocks.IRON_BLOCK).mapColor(MapColor.LIME).item());
public static final BeepBlock RED_BEEP_BLOCK = new BeepBlock(DawnBlockSettings.copy(Blocks.GLASS).mapColor(MapColor.RED).item());
public static final BeepBlockFrame BEEP_BLOCK_FRAME = new BeepBlockFrame(DawnBlockSettings.copy(Blocks.IRON_BLOCK).mapColor(MapColor.LIGHT_GRAY).nonOpaque().noCollision().item());
public static final SnakeBlock SNAKE_BLOCK = new SnakeBlock(DawnBlockSettings.copy(Blocks.IRON_BLOCK).mapColor(MapColor.LIME).item());
public static final BeepBlock RED_BEEP_BLOCK = new BeepBlock(DawnBlockSettings.copy(Blocks.GLASS).mapColor(MapColor.RED).item(), 0);
public static final BeepBlock BLUE_BEEP_BLOCK = new BeepBlock(DawnBlockSettings.copy(Blocks.GLASS).mapColor(MapColor.BLUE).item(), 80);

public static final BlockEntityType<BumpedBlockEntity> BUMPED_BLOCK_ENTITY_TYPE = FabricBlockEntityTypeBuilder
.create(BumpedBlockEntity::new, BUMPED_BLOCK)
.build();


public static void init() {
Registrar.add(Mubble.id("question_block"), QUESTION_BLOCK);
Registrar.add(Mubble.id("empty_block"), EMPTY_BLOCK);
Registrar.add(Mubble.id("brick_block"), BRICK_BLOCK);
Registrar.add(Mubble.id("gold_block"), GOLD_BLOCK);
Registrar.add(Mubble.id("note_block"), NOTE_BLOCK);
Registrar.add(Mubble.id("bumped_block"), BUMPED_BLOCK);
Registrar.add(Mubble.id("snake_block"), SNAKE_BLOCK);
Registrar.add(Mubble.id("red_beep_block"), RED_BEEP_BLOCK);
Registrar.add(Mubble.id("beep_block_frame"), BEEP_BLOCK_FRAME);
Registrar.add(Mubble.id("blue_beep_block"), BLUE_BEEP_BLOCK);

Registrar.add(Mubble.id("bumped_block"), BUMPED_BLOCK);
Registry.register(Registries.BLOCK_ENTITY_TYPE, Mubble.id("bumped_block"), BUMPED_BLOCK_ENTITY_TYPE);
}

Expand All @@ -57,6 +59,7 @@ public static void init() {
entries.add(SuperMarioContent.NOTE_BLOCK);
entries.add(SuperMarioContent.SNAKE_BLOCK);
entries.add(SuperMarioContent.RED_BEEP_BLOCK);
entries.add(SuperMarioContent.BLUE_BEEP_BLOCK);
})
.build();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"variants": {
"frame=false": { "model": "mubble:block/blue_beep_block" },
"frame=true": { "model": "mubble:block/beep_block_frame" }
}
}

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"variants": {
"": {
"model": "mubble:block/red_beep_block"
}
"frame=false": { "model": "mubble:block/red_beep_block" },
"frame=true": { "model": "mubble:block/beep_block_frame" }
}
}

2 changes: 1 addition & 1 deletion src/main/resources/assets/mubble/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
"block.mubble.bumped_block": "Bumped Block",
"block.mubble.snake_block": "Snake Block",
"block.mubble.red_beep_block": "Red Beep Block",
"block.mubble.beep_block_frame": "Beep Block Frame"
"block.mubble.blue_beep_block": "Blue Beep Block"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"parent": "minecraft:block/cube_all",
"textures": {
"all": "mubble:block/blue_beep_block"
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"parent": "mubble:block/blue_beep_block"
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
"mubble:note_block",
"mubble:snake_block",
"mubble:red_beep_block",
"mubble:beep_block_frame"
"mubble:blue_beep_block"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
"mubble:note_block",
"mubble:snake_block",
"mubble:red_beep_block",
"mubble:beep_block_frame"
"mubble:blue_beep_block"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"entries": [
{
"type": "minecraft:item",
"name": "mubble:red_beep_block"
"name": "mubble:blue_beep_block"
}
],
"conditions": [
Expand Down

0 comments on commit e6e8a58

Please sign in to comment.