Skip to content

Commit

Permalink
Add Maker Glove and correct bumpable placements
Browse files Browse the repository at this point in the history
  • Loading branch information
Hugman76 committed Jan 31, 2023
1 parent 48964ac commit a8af36b
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 8 deletions.
36 changes: 35 additions & 1 deletion src/main/java/fr/hugman/mubble/block/BumpableBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.BlockEntityTicker;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.block.entity.DispenserBlockEntity;
import net.minecraft.client.MinecraftClient;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.inventory.Inventory;
import net.minecraft.item.ItemStack;
import net.minecraft.screen.ScreenHandler;
import net.minecraft.sound.SoundCategory;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.BooleanProperty;
Expand Down Expand Up @@ -87,7 +91,7 @@ public <T extends BlockEntity> BlockEntityTicker<T> getTicker(World world, Block

@Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
if(!player.getStackInHand(hand).isIn(SuperMario.CAN_OPEN_BUMPABLE_BLOCKS)) {
if(!player.getStackInHand(hand).isOf(SuperMario.MAKER_GLOVE)) {
return ActionResult.PASS;
}
if(world.isClient) {
Expand All @@ -101,6 +105,36 @@ public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEnt
return ActionResult.CONSUME;
}

@Override
public void onPlaced(World world, BlockPos pos, BlockState state, LivingEntity placer, ItemStack stack) {
if(stack.hasCustomName() && world.getBlockEntity(pos) instanceof BumpableBlockEntity bumpable) {
bumpable.setCustomName(stack.getName());
}
}

@Override
public void onStateReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean moved) {
if (state.isOf(newState.getBlock())) {
return;
}
BlockEntity blockEntity = world.getBlockEntity(pos);
if (blockEntity instanceof BumpableBlockEntity bumpable) {
ItemScatterer.spawn(world, pos, bumpable);
world.updateComparators(pos, this);
}
super.onStateReplaced(state, world, pos, newState, moved);
}

@Override
public boolean hasComparatorOutput(BlockState state) {
return true;
}

@Override
public int getComparatorOutput(BlockState state, World world, BlockPos pos) {
return ScreenHandler.calculateComparatorOutput(world.getBlockEntity(pos));
}

/*=============*/
/* RENDERING */
/*=============*/
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/fr/hugman/mubble/registry/SuperMario.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
import net.minecraft.util.Rarity;

public class SuperMario {
// ITEMS
public static final Item MAKER_GLOVE = new Item(new DawnItemSettings().maxCount(1));

// BLOCKS
public static final EmptyBlock EMPTY_BLOCK = new EmptyBlock(DawnBlockSettings.copy(Blocks.IRON_BLOCK).mapColor(MapColor.BROWN).item());
public static final DecoratedBumpableBlock QUESTION_BLOCK = new DecoratedBumpableBlock(new ItemStack(Items.GOLD_NUGGET), EMPTY_BLOCK.getDefaultState(), DawnBlockSettings.copy(Blocks.IRON_BLOCK).mapColor(MapColor.YELLOW).item());
Expand All @@ -51,6 +54,8 @@ public class SuperMario {
public static final CapeFeatherItem SUPER_CAPE_FEATHER = new CapeFeatherItem(new Item.Settings().rarity(Rarity.EPIC), true);

public static void init(Registrar r) {
r.add("maker_glove", MAKER_GLOVE);

r.add("empty_block", EMPTY_BLOCK);
r.add("question_block", QUESTION_BLOCK);
r.add("brick_block", BRICK_BLOCK);
Expand All @@ -74,6 +79,7 @@ public static void init(Registrar r) {
.displayName(Text.translatable("item_group.mubble.super_mario"))
.icon(() -> new ItemStack(SuperMario.QUESTION_BLOCK))
.entries((enabledFeatures, entries, operatorEnabled) -> {
entries.add(SuperMario.MAKER_GLOVE);
entries.add(SuperMario.QUESTION_BLOCK);
entries.add(SuperMario.EMPTY_BLOCK);
entries.add(SuperMario.BRICK_BLOCK);
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/assets/mubble/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

"item_group.mubble.super_mario": "Super Mario",

"item.mubble.maker_glove": "Maker Glove",

"block.mubble.question_block": "? Block",
"block.mubble.exclamation_block": "! Block",
"block.mubble.empty_block": "Empty Block",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"parent": "minecraft:block/cube_column",
"textures": {
"side": "mubble:block/snake_block/side",
"end": "mubble:block/snake_block/end"
"side": "mubble:block/snake_block/normal/side",
"end": "mubble:block/snake_block/normal/end"
}
}
6 changes: 6 additions & 0 deletions src/main/resources/assets/mubble/models/item/maker_glove.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "mubble:item/maker_glove"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

This file was deleted.

0 comments on commit a8af36b

Please sign in to comment.