Skip to content

Commit

Permalink
De-dawn-ify Mubble
Browse files Browse the repository at this point in the history
  • Loading branch information
Hugman76 committed Jul 25, 2024
1 parent 3a7d1f3 commit dc76280
Show file tree
Hide file tree
Showing 28 changed files with 664 additions and 617 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ repositories {
}

dependencies {
modApi "com.github.DawnTeamMC:DawnAPI:${dawn_version}"
//modApi "com.github.DawnTeamMC:DawnAPI:${dawn_version}"

// modImplementation "me.shedaniel.cloth:cloth-config-fabric:${cloth_version}"
// include "me.shedaniel.cloth:cloth-config-fabric:${cloth_version}"
Expand Down
37 changes: 23 additions & 14 deletions src/main/java/fr/hugman/mubble/Mubble.java
Original file line number Diff line number Diff line change
@@ -1,27 +1,36 @@
package fr.hugman.mubble;

import fr.hugman.dawn.Registrar;
import fr.hugman.mubble.registry.MubbleSounds;
import fr.hugman.mubble.registry.SuperMario;
import com.google.common.reflect.Reflection;
import fr.hugman.mubble.block.MubbleBlockEntityTypes;
import fr.hugman.mubble.block.MubbleBlocks;
import fr.hugman.mubble.item.MubbleItemGroups;
import fr.hugman.mubble.item.MubbleItems;
import fr.hugman.mubble.screen.MubbleScreenHandlerTypes;
import fr.hugman.mubble.sound.MubbleSounds;
import fr.hugman.mubble.world.MubbleGamerules;
import net.fabricmc.api.ModInitializer;
import net.minecraft.util.Identifier;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class Mubble implements ModInitializer {
public static final Registrar REGISTRAR = new Registrar("mubble");
public static final Logger LOGGER = LogManager.getLogger();
public static final String MOD_ID = "mubble";
public static final Logger LOGGER = LogManager.getLogger();

@Override
public void onInitialize() {
MubbleGamerules.init();
MubbleSounds.init();
@Override
public void onInitialize() {
Reflection.initialize(MubbleBlocks.class);
Reflection.initialize(MubbleBlockEntityTypes.class);
Reflection.initialize(MubbleItems.class);
Reflection.initialize(MubbleSounds.class);
Reflection.initialize(MubbleScreenHandlerTypes.class);

SuperMario.init(REGISTRAR);
}
MubbleItemGroups.appendItemGroups();

public static Identifier id(String path) {
return REGISTRAR.id(path);
}
MubbleGamerules.init();
}

public static Identifier id(String path) {
return Identifier.of(MOD_ID, path);
}
}
29 changes: 21 additions & 8 deletions src/main/java/fr/hugman/mubble/MubbleClient.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package fr.hugman.mubble;

import fr.hugman.mubble.block.MubbleBlockEntityTypes;
import fr.hugman.mubble.block.MubbleBlocks;
import fr.hugman.mubble.client.gui.screen.BumpableScreen;
import fr.hugman.mubble.client.render.BumpableBlockEntityRenderer;
import fr.hugman.mubble.registry.SuperMario;
import fr.hugman.mubble.screen.MubbleScreenHandlerTypes;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
Expand All @@ -13,12 +15,23 @@

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

HandledScreens.register(SuperMario.BUMPABLE_BLOCK_SCREEN_HANDLER, BumpableScreen::new);
BlockEntityRendererFactories.register(SuperMario.BUMPABLE_BLOCK_ENTITY_TYPE, BumpableBlockEntityRenderer::new);
}
private static void registerBlockRenderLayers() {
BlockRenderLayerMap.INSTANCE.putBlock(MubbleBlocks.RED_BEEP_BLOCK, RenderLayer.getCutout());
BlockRenderLayerMap.INSTANCE.putBlock(MubbleBlocks.BLUE_BEEP_BLOCK, RenderLayer.getCutout());
}

private static void registerHandledScreens() {
HandledScreens.register(MubbleScreenHandlerTypes.BUMPABLE_BLOCK, BumpableScreen::new);
}

private static void registerBlockEntityRenderers() {
BlockEntityRendererFactories.register(MubbleBlockEntityTypes.BUMPABLE_BLOCK, BumpableBlockEntityRenderer::new);
}
}
9 changes: 2 additions & 7 deletions src/main/java/fr/hugman/mubble/block/BeepBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,10 @@ public BeepBlock(Settings settings, boolean offset) {
this.setDefaultState(getDefaultState().with(FRAME, false));
}

public BeepBlock(MapColor mapColor, boolean offset) {
this(makeSettings(mapColor), offset);

}

public static Settings makeSettings(MapColor mapColor) {
public static Settings settings(MapColor mapColor) {
return AbstractBlock.Settings.create().mapColor(mapColor)
.sounds(BlockSoundGroup.AMETHYST_BLOCK)
.strength(1.5f).requiresTool().item()
.strength(1.5f).requiresTool()
.allowsSpawning(BeepBlock::isNotFrame)
.solidBlock(BeepBlock::isNotFrame)
.suffocates(BeepBlock::isNotFrame)
Expand Down
21 changes: 6 additions & 15 deletions src/main/java/fr/hugman/mubble/block/BumpableBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import com.mojang.serialization.MapCodec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import fr.hugman.mubble.block.entity.BumpableBlockEntity;
import fr.hugman.mubble.registry.MubbleSounds;
import fr.hugman.mubble.registry.SuperMario;
import fr.hugman.mubble.item.MubbleItems;
import fr.hugman.mubble.sound.MubbleSounds;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.block.Block;
Expand Down Expand Up @@ -91,12 +91,12 @@ public BlockEntity createBlockEntity(BlockPos pos, BlockState state) {

@Override
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(World world, BlockState state, BlockEntityType<T> type) {
return validateTicker(type, SuperMario.BUMPABLE_BLOCK_ENTITY_TYPE, (w, p, s, e) -> e.tick(w, p, s));
return validateTicker(type, MubbleBlockEntityTypes.BUMPABLE_BLOCK, (w, p, s, e) -> e.tick(w, p, s));
}

@Override
protected ItemActionResult onUseWithItem(ItemStack stack, BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
if (!player.getStackInHand(hand).isOf(SuperMario.MAKER_GLOVE)) {
if (!player.getStackInHand(hand).isOf(MubbleItems.MAKER_GLOVE)) {
return ItemActionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION;
}

Expand Down Expand Up @@ -216,7 +216,7 @@ public void onHit(World world, BlockState state, Entity entity, BlockHitResult h
}

BlockPos pos = hit.getBlockPos();
world.getBlockEntity(pos, SuperMario.BUMPABLE_BLOCK_ENTITY_TYPE).ifPresent(blockEntity -> {
world.getBlockEntity(pos, MubbleBlockEntityTypes.BUMPABLE_BLOCK).ifPresent(blockEntity -> {
if (this.canBump(world, pos, state, blockEntity, entity, hit)) {
blockEntity.bump(world, pos, state, entity, hit.getSide().getOpposite());
}
Expand All @@ -225,16 +225,7 @@ public void onHit(World world, BlockState state, Entity entity, BlockHitResult h

@Override
public void onProjectileHit(World world, BlockState state, BlockHitResult hit, ProjectileEntity projectile) {
if (world.isClient()) {
return;
}

BlockPos pos = hit.getBlockPos();
world.getBlockEntity(pos, SuperMario.BUMPABLE_BLOCK_ENTITY_TYPE).ifPresent(blockEntity -> {
if (this.canBump(world, pos, state, blockEntity, projectile, hit)) {
blockEntity.bump(world, pos, state, projectile, hit.getSide().getOpposite());
}
});
this.onHit(world, state, projectile, hit);
}

public void loot(World world, BlockPos pos, BumpableBlockEntity blockEntity, boolean atCenter) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
import com.mojang.serialization.MapCodec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import fr.hugman.mubble.block.entity.BumpableBlockEntity;
import fr.hugman.mubble.registry.MubbleSounds;
import fr.hugman.mubble.sound.MubbleSounds;
import net.minecraft.block.BlockState;
import net.minecraft.entity.Entity;
import net.minecraft.item.ItemStack;
import net.minecraft.sound.SoundCategory;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Box;
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/fr/hugman/mubble/block/EmptyBlock.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package fr.hugman.mubble.block;

import fr.hugman.mubble.registry.MubbleSounds;
import fr.hugman.mubble.sound.MubbleSounds;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.entity.Entity;
import net.minecraft.sound.SoundCategory;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

/**
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/fr/hugman/mubble/block/HittableBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,7 @@
* @since v4.0.0
*/
public interface HittableBlock {
double HIT_Y_OFFSET = 0.001;

void onHit(World world, BlockState state, Entity entity, BlockHitResult hit);
}
21 changes: 21 additions & 0 deletions src/main/java/fr/hugman/mubble/block/MubbleBlockEntityTypes.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package fr.hugman.mubble.block;

import com.mojang.datafixers.types.Type;
import fr.hugman.mubble.Mubble;
import fr.hugman.mubble.block.entity.BumpableBlockEntity;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.datafixer.TypeReferences;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.util.Util;

public class MubbleBlockEntityTypes {
// SUPER MARIO
public static final BlockEntityType<BumpableBlockEntity> BUMPABLE_BLOCK = of("bumpable_block", BlockEntityType.Builder.create(BumpableBlockEntity::new, MubbleBlocks.QUESTION_BLOCK, MubbleBlocks.BRICK_BLOCK, MubbleBlocks.GOLD_BLOCK, MubbleBlocks.NOTE_BLOCK, MubbleBlocks.EXCLAMATION_BLOCK));

private static <T extends BlockEntity> BlockEntityType<T> of(String path, BlockEntityType.Builder<T> blockEntityType) {
Type<?> type = Util.getChoiceType(TypeReferences.BLOCK_ENTITY, path);
return Registry.register(Registries.BLOCK_ENTITY_TYPE, Mubble.id(path), blockEntityType.build(type));
}
}
26 changes: 26 additions & 0 deletions src/main/java/fr/hugman/mubble/block/MubbleBlockKeys.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package fr.hugman.mubble.block;

import fr.hugman.mubble.Mubble;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;

public class MubbleBlockKeys {
// SUPER MARIO
public static final RegistryKey<Block> EMPTY_BLOCK = of("empty_block");
public static final RegistryKey<Block> QUESTION_BLOCK = of("question_block");
public static final RegistryKey<Block> BRICK_BLOCK = of("brick_block");
public static final RegistryKey<Block> GOLD_BLOCK = of("gold_block");
public static final RegistryKey<Block> NOTE_BLOCK = of("note_block");
public static final RegistryKey<Block> EXCLAMATION_BLOCK = of("exclamation_block");
public static final RegistryKey<Block> SNAKE_BLOCK = of("snake_block");
public static final RegistryKey<Block> FAST_SNAKE_BLOCK = of("fast_snake_block");
public static final RegistryKey<Block> SLOW_SNAKE_BLOCK = of("slow_snake_block");
public static final RegistryKey<Block> RED_BEEP_BLOCK = of("red_beep_block");
public static final RegistryKey<Block> BLUE_BEEP_BLOCK = of("blue_beep_block");

private static RegistryKey<Block> of(String path) {
return RegistryKey.of(RegistryKeys.BLOCK, Mubble.id(path));
}
}
44 changes: 44 additions & 0 deletions src/main/java/fr/hugman/mubble/block/MubbleBlocks.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package fr.hugman.mubble.block;

import fr.hugman.mubble.sound.MubbleSounds;
import net.minecraft.block.AbstractBlock;
import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
import net.minecraft.block.MapColor;
import net.minecraft.component.DataComponentTypes;
import net.minecraft.component.type.ContainerComponent;
import net.minecraft.item.BlockItem;
import net.minecraft.item.Item;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKey;

public class MubbleBlocks {
// SUPER MARIO
public static final EmptyBlock EMPTY_BLOCK = ofWithItem(MubbleBlockKeys.EMPTY_BLOCK, new EmptyBlock(AbstractBlock.Settings.copy(Blocks.IRON_BLOCK).mapColor(MapColor.BROWN)));
public static final DecoratedBumpableBlock QUESTION_BLOCK = ofWithItem(MubbleBlockKeys.QUESTION_BLOCK, new DecoratedBumpableBlock(EMPTY_BLOCK.getDefaultState(), AbstractBlock.Settings.copy(Blocks.IRON_BLOCK).mapColor(MapColor.YELLOW)), new Item.Settings().component(DataComponentTypes.CONTAINER, ContainerComponent.DEFAULT));
public static final DecoratedBumpableBlock BRICK_BLOCK = ofWithItem(MubbleBlockKeys.BRICK_BLOCK, new DecoratedBumpableBlock(Blocks.AIR.getDefaultState(), AbstractBlock.Settings.copy(Blocks.BRICKS).mapColor(MapColor.BROWN)),new Item.Settings().component(DataComponentTypes.CONTAINER, ContainerComponent.DEFAULT));
public static final DecoratedBumpableBlock GOLD_BLOCK = ofWithItem(MubbleBlockKeys.GOLD_BLOCK, new DecoratedBumpableBlock(Blocks.AIR.getDefaultState(), AbstractBlock.Settings.copy(Blocks.BRICKS).mapColor(MapColor.GOLD)), new Item.Settings().component(DataComponentTypes.CONTAINER, ContainerComponent.DEFAULT));
public static final NoteBlock NOTE_BLOCK = ofWithItem(MubbleBlockKeys.NOTE_BLOCK, new NoteBlock(MubbleSounds.NOTE_BLOCK_JUMP_LOW, MubbleSounds.NOTE_BLOCK_JUMP_HIGH, AbstractBlock.Settings.copy(Blocks.QUARTZ_BLOCK).mapColor(MapColor.WHITE)), new Item.Settings().component(DataComponentTypes.CONTAINER, ContainerComponent.DEFAULT));
public static final DecoratedBumpableBlock EXCLAMATION_BLOCK = ofWithItem(MubbleBlockKeys.EXCLAMATION_BLOCK, new DecoratedBumpableBlock(null, AbstractBlock.Settings.copy(Blocks.IRON_BLOCK).mapColor(MapColor.BLUE)), new Item.Settings().component(DataComponentTypes.CONTAINER, ContainerComponent.DEFAULT));
public static final SnakeBlock SNAKE_BLOCK = ofWithItem(MubbleBlockKeys.SNAKE_BLOCK, new SnakeBlock(AbstractBlock.Settings.copy(Blocks.IRON_BLOCK).mapColor(MapColor.LIME)));
public static final SnakeBlock FAST_SNAKE_BLOCK = ofWithItem(MubbleBlockKeys.FAST_SNAKE_BLOCK, new SnakeBlock(AbstractBlock.Settings.copy(Blocks.IRON_BLOCK).mapColor(MapColor.LAPIS_BLUE)));
public static final SnakeBlock SLOW_SNAKE_BLOCK = ofWithItem(MubbleBlockKeys.SLOW_SNAKE_BLOCK, new SnakeBlock(AbstractBlock.Settings.copy(Blocks.IRON_BLOCK).mapColor(MapColor.RED)));
public static final BeepBlock RED_BEEP_BLOCK = ofWithItem(MubbleBlockKeys.RED_BEEP_BLOCK, new BeepBlock(BeepBlock.settings(MapColor.RED), false));
public static final BeepBlock BLUE_BEEP_BLOCK = ofWithItem(MubbleBlockKeys.BLUE_BEEP_BLOCK, new BeepBlock(BeepBlock.settings(MapColor.BLUE), true));

private static <O extends Block> O of(RegistryKey<Block> key, O block) {
return Registry.register(Registries.BLOCK, key, block);
}

private static <O extends Block> O ofWithItem(RegistryKey<Block> key, O block, Item.Settings settings) {
of(key, block);
Registry.register(Registries.ITEM, key.getValue(), new BlockItem(block, settings));
return block;
}

private static <O extends Block> O ofWithItem(RegistryKey<Block> key, O block) {
return ofWithItem(key, block, new Item.Settings());
}

}
18 changes: 7 additions & 11 deletions src/main/java/fr/hugman/mubble/block/SnakeBlock.java
Original file line number Diff line number Diff line change
@@ -1,26 +1,22 @@
package fr.hugman.mubble.block;

import fr.hugman.mubble.registry.SuperMario;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.entity.Entity;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvents;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.World;

/**
* @author komerish
* @since v4.0.0
*/
public class SnakeBlock extends Block {
public SnakeBlock(Settings settings) {
super(settings);
}
public SnakeBlock(Settings settings) {
super(settings);
}

@Override
public void onSteppedOn(World world, BlockPos pos, BlockState state, Entity entity) {
super.onSteppedOn(world, pos, state, entity);
}
@Override
public void onSteppedOn(World world, BlockPos pos, BlockState state, Entity entity) {
super.onSteppedOn(world, pos, state, entity);
}
}
Loading

0 comments on commit dc76280

Please sign in to comment.