Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
- Add block drops
- Add BE inventory drops
- Add blocks to `mineable` tags
  • Loading branch information
falseresync committed Jan 8, 2024
1 parent 76cac09 commit d1de22a
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.BlockEntityTicker;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.block.entity.CampfireBlockEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.Identifier;
import net.minecraft.util.ItemScatterer;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
Expand Down Expand Up @@ -74,6 +76,17 @@ public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEnt
return super.onUse(state, world, pos, player, hand, hit);
}

@Override
public void onStateReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean moved) {
if (!state.isOf(newState.getBlock())) {
if (world.getBlockEntity(pos) instanceof EnergizedWorktableBlockEntity worktable) {
ItemScatterer.spawn(world, pos, worktable.getInventory());
}

super.onStateReplaced(state, world, pos, newState, moved);
}
}

@Override
public Identifier getId() {
return ID;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.mojang.serialization.MapCodec;
import dev.falseresync.wizcraft.common.Wizcraft;
import dev.falseresync.wizcraft.common.block.entity.EnergizedWorktableBlockEntity;
import dev.falseresync.wizcraft.common.block.entity.LensingPedestalBlockEntity;
import dev.falseresync.wizcraft.api.HasId;
import dev.falseresync.wizcraft.common.WizUtil;
Expand All @@ -14,6 +15,7 @@
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.Identifier;
import net.minecraft.util.ItemScatterer;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.shape.VoxelShape;
Expand Down Expand Up @@ -67,6 +69,17 @@ public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEnt
return super.onUse(state, world, pos, player, hand, hit);
}

@Override
public void onStateReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean moved) {
if (!state.isOf(newState.getBlock())) {
if (world.getBlockEntity(pos) instanceof LensingPedestalBlockEntity pedestal) {
ItemScatterer.spawn(world, pos, pedestal.getInventory());
}

super.onStateReplaced(state, world, pos, newState, moved);
}
}

@Override
public Identifier getId() {
return ID;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class WizBlocks {

static {
LENS = r("lens", new Block(FabricBlockSettings.copyOf(Blocks.GLASS).luminance(1)));
ENERGIZED_WORKTABLE = r(new EnergizedWorktableBlock(FabricBlockSettings.copyOf(Blocks.CRAFTING_TABLE)));
ENERGIZED_WORKTABLE = r(new EnergizedWorktableBlock(FabricBlockSettings.copyOf(Blocks.CRAFTING_TABLE).requiresTool()));
LENSING_PEDESTAL = r(new LensingPedestalBlock(FabricBlockSettings.copyOf(Blocks.BRICK_WALL)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ public NbtCompound toInitialChunkDataNbt() {
return createNbt();
}

public SimpleInventory getInventory() {
return inventory;
}

public InventoryStorage getStorage() {
return storage;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ public NbtCompound toInitialChunkDataNbt() {
return createNbt();
}

public SimpleInventory getInventory() {
return inventory;
}

public InventoryStorage getStorage() {
return storage;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package dev.falseresync.wizcraft.datagen;

import dev.falseresync.wizcraft.common.block.WizBlocks;
import dev.falseresync.wizcraft.common.item.WizItems;
import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput;
import net.fabricmc.fabric.api.datagen.v1.provider.FabricBlockLootTableProvider;

public class WizBlockLootTableProvider extends FabricBlockLootTableProvider {
protected WizBlockLootTableProvider(FabricDataOutput dataOutput) {
super(dataOutput);
}

@Override
public void generate() {
addDrop(WizBlocks.ENERGIZED_WORKTABLE, drops(WizItems.ENERGIZED_WORKTABLE));
addDrop(WizBlocks.LENSING_PEDESTAL, drops(WizItems.LENSING_PEDESTAL));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package dev.falseresync.wizcraft.datagen;

import dev.falseresync.wizcraft.common.block.WizBlocks;
import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput;
import net.fabricmc.fabric.api.datagen.v1.provider.FabricTagProvider;
import net.minecraft.registry.RegistryWrapper;
import net.minecraft.registry.tag.BlockTags;

import java.util.concurrent.CompletableFuture;

public class WizBlockTagProvider extends FabricTagProvider.BlockTagProvider {
public WizBlockTagProvider(FabricDataOutput output, CompletableFuture<RegistryWrapper.WrapperLookup> registriesFuture) {
super(output, registriesFuture);
}

@Override
protected void configure(RegistryWrapper.WrapperLookup arg) {
getOrCreateTagBuilder(BlockTags.AXE_MINEABLE)
.add(WizBlocks.ENERGIZED_WORKTABLE);
getOrCreateTagBuilder(BlockTags.PICKAXE_MINEABLE)
.add(WizBlocks.ENERGIZED_WORKTABLE)
.add(WizBlocks.LENSING_PEDESTAL);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@ public void onInitializeDataGenerator(FabricDataGenerator fabricDataGenerator) {
var pack = fabricDataGenerator.createPack();
pack.addProvider(WizModelProvider::new);
pack.addProvider(WizRecipeProvider::new);
pack.addProvider(WizBlockLootTableProvider::new);
pack.addProvider(WizBlockTagProvider::new);
}
}

0 comments on commit d1de22a

Please sign in to comment.