speedpowderaxe works

This commit is contained in:
Jörg Henke 2020-07-30 22:04:12 +02:00
parent f52175c1c4
commit 77bf438714
3 changed files with 151 additions and 168 deletions

View File

@ -1,16 +1,8 @@
package de.jottyfan.minecraft.quickiefabric; package de.jottyfan.minecraft.quickiefabric;
import java.util.ArrayList;
import java.util.List;
import de.jottyfan.minecraft.quickiefabric.blocks.QuickieBlocks;
import de.jottyfan.minecraft.quickiefabric.init.RegistryManager; import de.jottyfan.minecraft.quickiefabric.init.RegistryManager;
import net.fabricmc.api.ModInitializer; import net.fabricmc.api.ModInitializer;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.util.registry.Registry; import net.minecraft.util.registry.Registry;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.gen.feature.OreFeatureConfig;
/** /**
* *
@ -25,31 +17,6 @@ public class QuickieFabric implements ModInitializer {
RegistryManager.registerTools(); RegistryManager.registerTools();
RegistryManager.registerEvents(); RegistryManager.registerEvents();
RegistryManager.registerBlocks(); RegistryManager.registerBlocks();
Registry.BIOME.forEach(this::handleBiome); Registry.BIOME.forEach(RegistryManager::handleBiome);
}
/**
* add the quickiefabric ores to the biome
*
* @param biome
* the biome
*/
private void handleBiome(Biome biome) {
if (biome.getCategory() == Biome.Category.NETHER) {
RegistryManager.generateOreForTarget(biome, OreFeatureConfig.Target.NETHER_ORE_REPLACEABLES, QuickieBlocks.ORE_NETHER_SULPHOR, 24, 10, 0, 0, 128);
} else if (biome.getCategory() != Biome.Category.THEEND) {
} else {
List<BlockState> sandlike = new ArrayList<>();
sandlike.add(Blocks.SAND.getDefaultState());
sandlike.add(Blocks.SANDSTONE.getDefaultState());
sandlike.add(Blocks.SANDSTONE_WALL.getDefaultState());
sandlike.add(Blocks.CHISELED_SANDSTONE.getDefaultState());
List<BlockState> dirtlike = new ArrayList<>();
dirtlike.add(Blocks.DIRT.getDefaultState());
RegistryManager.generateOreForBlocks(biome, sandlike, sandlike, sandlike, QuickieBlocks.SAND_SALPETER, 10, 64, 196, 255);
RegistryManager.generateOreForBlocks(biome, sandlike, sandlike, sandlike, QuickieBlocks.ORE_SAND_SALPETER, 10, 64, 196, 255);
RegistryManager.generateOreForTarget(biome, OreFeatureConfig.Target.NATURAL_STONE, QuickieBlocks.ORE_SULPHOR, 16, 4, 4, 196, 255);
RegistryManager.generateOreForTarget(biome, OreFeatureConfig.Target.NATURAL_STONE, QuickieBlocks.ORE_SALPETER, 12, 10, 4, 196, 255);
}
} }
} }

View File

@ -1,5 +1,23 @@
package de.jottyfan.minecraft.quickiefabric.event; package de.jottyfan.minecraft.quickiefabric.event;
import java.util.ArrayList;
import java.util.List;
import de.jottyfan.minecraft.quickiefabric.tools.HarvestRange;
import de.jottyfan.minecraft.quickiefabric.tools.QuickieTools;
import de.jottyfan.minecraft.quickiefabric.tools.ToolRangeable;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.entity.EquipmentSlot;
import net.minecraft.entity.ExperienceOrbEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
/** /**
* *
* @author jotty * @author jotty
@ -11,123 +29,104 @@ public class EventBlockBreak {
UPWARDS, ALL; UPWARDS, ALL;
} }
public void doBreakBlock(World world, BlockPos blockPos, BlockState blockState, PlayerEntity playerEntity) {
// /** ItemStack mainHandItemStack = playerEntity.getEquippedStack(EquipmentSlot.MAINHAND);
// * TODO: use AttackBlockCallback instead? if (mainHandItemStack != null) {
// * @param event Item item = mainHandItemStack.getItem();
// */ if (item instanceof ToolRangeable) {
// @SubscribeEvent CompoundTag nbt = mainHandItemStack.getTag();
// public void doBreakBlock(BlockEvent.BreakEvent event) { Integer level = nbt != null ? nbt.getInt("level") : 0;
// PlayerEntity player = event.getPlayer(); ToolRangeable tool = (ToolRangeable) item;
// ItemStack mainHandItemStack = player.getHeldItemMainhand(); Block block = blockState.getBlock();
// if (mainHandItemStack != null) { handleRangeableTools(tool, level, world, block, blockPos, playerEntity);
// Item item = mainHandItemStack.getItem(); world.spawnEntity(new ExperienceOrbEntity(world, blockPos.getX(), blockPos.getY(), blockPos.getZ(), 1)); // reward for using rangeable tool
// if (item instanceof ToolRangeable) { }
// CompoundNBT nbt = mainHandItemStack.getTag(); }
// Integer level = nbt != null ? nbt.getInt("level") : 0; }
// ToolRangeable tool = (ToolRangeable) item;
// BlockPos pos = event.getPos(); /**
// World world = event.getWorld().getWorld(); * hande the rangeable tools break event
// BlockState blockState = world.getBlockState(pos); *
// Block block = blockState.getBlock(); * @param tool
// handleRangeableTools(tool, level, world, block, pos, player); * the tool that has been used
// } * @param world
// } * the world
// } * @param block
// * the block to break
// /** * @param pos
// * hande the rangeable tools break event * the position of the current block
// * * @param player
// * @param tool * the current player
// * the tool that has been used */
// * @param world private void handleRangeableTools(ToolRangeable tool, Integer level, World world, Block currentBlock, BlockPos pos, PlayerEntity player) {
// * the world List<Block> validBlocks = tool.getBlockList(currentBlock);
// * @param block HarvestRange range = tool.getRange();
// * the block to break if (range != null) {
// * @param pos range = range.addXYZ(level);
// * the position of the current block }
// * @param player if (QuickieTools.SPEEDPOWDERAXE.equals(tool)) {
// * the current player breakBlockRecursive(new ArrayList<>(), world, validBlocks, pos, tool, range, BlockBreakDirection.UPWARDS, player);
// */ } else if (QuickieTools.SPEEDPOWDERPICKAXE.equals(tool)) {
// private void handleRangeableTools(ToolRangeable tool, Integer level, World world, Block currentBlock, BlockPos pos, breakBlockRecursive(new ArrayList<>(), world, validBlocks, pos, tool, range, BlockBreakDirection.ALL, player);
// PlayerEntity player) { } else if (QuickieTools.SPEEDPOWDERSHOVEL.equals(tool)) {
// List<Block> validBlocks = tool.getBlockList(currentBlock); breakBlockRecursive(new ArrayList<>(), world, validBlocks, pos, tool, range, BlockBreakDirection.ALL, player);
// HarvestRange range = tool.getRange(); }
// if (range != null) { }
// range = range.addXYZ(level);
// } /**
// if (RegistryManager.AXE_SPEEDPOWDER.equals(tool)) { * break block recursively;
// breakBlockRecursive(new ArrayList<>(), world, validBlocks, pos, tool, range, BlockBreakDirection.UPWARDS, player); *
// } else if (RegistryManager.PICKAXE_SPEEDPOWDER.equals(tool)) { * @param visitedBlocks
// breakBlockRecursive(new ArrayList<>(), world, validBlocks, pos, tool, range, BlockBreakDirection.ALL, player); * the positions of visited blocks
// } else if (RegistryManager.SHOVEL_SPEEDPOWDER.equals(tool)) { * @param world
// breakBlockRecursive(new ArrayList<>(), world, validBlocks, pos, tool, range, BlockBreakDirection.ALL, player); * the world
// } * @param validBlocks
// } * the blocks to break
// * @param tool
// /** * the tool used
// * break block recursively; * @param range
// * * the range left over
// * @param visitedBlocks * @param pos
// * the positions of visited blocks * the position
// * @param world * @param blockBreakDirection
// * the world * the direction for the recursive call
// * @param validBlocks * @param player
// * the blocks to break * the player
// * @param tool */
// * the tool used private void breakBlockRecursive(List<String> visitedBlocks, World world, List<Block> validBlocks, BlockPos pos, ToolRangeable tool, HarvestRange range, BlockBreakDirection blockBreakDirection,
// * @param range PlayerEntity player) {
// * the range left over if (visitedBlocks.contains(pos.toString())) {
// * @param pos return; // reduce loops
// * the position } else if (validBlocks == null) {
// * @param blockBreakDirection return; // reduce loops
// * the direction for the recursive call } else {
// * @param player visitedBlocks.add(pos.toString());
// * the player }
// */ BlockState blockState = world.getBlockState(pos);
// private void breakBlockRecursive(List<String> visitedBlocks, World world, List<Block> validBlocks, BlockPos pos, if (tool.canBreakNeigbbors(blockState)) {
// ToolRangeable tool, HarvestRange range, BlockBreakDirection blockBreakDirection, PlayerEntity player) { Block currentBlock = blockState.getBlock();
// if (visitedBlocks.contains(pos.toString())) { if (validBlocks.contains(currentBlock)) {
// return; // reduce loops Block.dropStacks(blockState, world, pos);
// } else if (validBlocks == null) { world.setBlockState(pos, Blocks.AIR.getDefaultState());
// return; // reduce loops currentBlock.onStacksDropped(blockState, world, pos, stack);
// } else { if (range == null || range.getxRange() > 1 || range.getyRange() > 1 || range.getzRange() > 1) {
// visitedBlocks.add(pos.toString()); HarvestRange nextRadius = range == null ? null : range.addXYZ(-1);
// } breakBlockRecursive(visitedBlocks, world, validBlocks, pos.north(), tool, nextRadius, blockBreakDirection, player);
// BlockState blockState = world.getBlockState(pos); breakBlockRecursive(visitedBlocks, world, validBlocks, pos.north().east(), tool, nextRadius, blockBreakDirection, player);
// if (tool.canBreakNeigbbors(blockState)) { breakBlockRecursive(visitedBlocks, world, validBlocks, pos.north().west(), tool, nextRadius, blockBreakDirection, player);
// Block currentBlock = blockState.getBlock(); breakBlockRecursive(visitedBlocks, world, validBlocks, pos.south(), tool, nextRadius, blockBreakDirection, player);
// if (validBlocks.contains(currentBlock)) { breakBlockRecursive(visitedBlocks, world, validBlocks, pos.south().east(), tool, nextRadius, blockBreakDirection, player);
// world.setBlockState(pos, Blocks.AIR.getDefaultState()); breakBlockRecursive(visitedBlocks, world, validBlocks, pos.south().west(), tool, nextRadius, blockBreakDirection, player);
// Block.spawnDrops(blockState, world, pos); breakBlockRecursive(visitedBlocks, world, validBlocks, pos.east(), tool, nextRadius, blockBreakDirection, player);
// if (range == null || range.getxRange() > 1 || range.getyRange() > 1 || range.getzRange() > 1) { breakBlockRecursive(visitedBlocks, world, validBlocks, pos.west(), tool, nextRadius, blockBreakDirection, player);
// HarvestRange nextRadius = range == null ? null : range.addXYZ(-1);
// breakBlockRecursive(visitedBlocks, world, validBlocks, pos.north(), tool, nextRadius, blockBreakDirection, breakBlockRecursive(visitedBlocks, world, validBlocks, pos.up(), tool, nextRadius, blockBreakDirection, player);
// player);
// breakBlockRecursive(visitedBlocks, world, validBlocks, pos.north().east(), tool, nextRadius, if (BlockBreakDirection.ALL.equals(blockBreakDirection)) {
// blockBreakDirection, player); breakBlockRecursive(visitedBlocks, world, validBlocks, pos.down(), tool, nextRadius, blockBreakDirection, player);
// breakBlockRecursive(visitedBlocks, world, validBlocks, pos.north().west(), tool, nextRadius, }
// blockBreakDirection, player); }
// breakBlockRecursive(visitedBlocks, world, validBlocks, pos.south(), tool, nextRadius, blockBreakDirection, }
// player); }
// breakBlockRecursive(visitedBlocks, world, validBlocks, pos.south().east(), tool, nextRadius, }
// blockBreakDirection, player);
// breakBlockRecursive(visitedBlocks, world, validBlocks, pos.south().west(), tool, nextRadius,
// blockBreakDirection, player);
// breakBlockRecursive(visitedBlocks, world, validBlocks, pos.east(), tool, nextRadius, blockBreakDirection,
// player);
// breakBlockRecursive(visitedBlocks, world, validBlocks, pos.west(), tool, nextRadius, blockBreakDirection,
// player);
//
// breakBlockRecursive(visitedBlocks, world, validBlocks, pos.up(), tool, nextRadius, blockBreakDirection,
// player);
//
// if (BlockBreakDirection.ALL.equals(blockBreakDirection)) {
// breakBlockRecursive(visitedBlocks, world, validBlocks, pos.down(), tool, nextRadius, blockBreakDirection,
// player);
// }
// }
// }
// }
// }
} }

View File

@ -1,5 +1,6 @@
package de.jottyfan.minecraft.quickiefabric.init; package de.jottyfan.minecraft.quickiefabric.init;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
@ -7,6 +8,7 @@ import org.apache.logging.log4j.Logger;
import de.jottyfan.minecraft.quickiefabric.blocks.QuickieBlocks; import de.jottyfan.minecraft.quickiefabric.blocks.QuickieBlocks;
import de.jottyfan.minecraft.quickiefabric.event.BreakBlockCallback; import de.jottyfan.minecraft.quickiefabric.event.BreakBlockCallback;
import de.jottyfan.minecraft.quickiefabric.event.EventBlockBreak;
import de.jottyfan.minecraft.quickiefabric.items.QuickieItems; import de.jottyfan.minecraft.quickiefabric.items.QuickieItems;
import de.jottyfan.minecraft.quickiefabric.tools.QuickieTools; import de.jottyfan.minecraft.quickiefabric.tools.QuickieTools;
import net.fabricmc.fabric.api.client.itemgroup.FabricItemGroupBuilder; import net.fabricmc.fabric.api.client.itemgroup.FabricItemGroupBuilder;
@ -82,26 +84,14 @@ public class RegistryManager {
public static final void registerTools() { public static final void registerTools() {
LOGGER.debug("registering quickiefabric tools"); LOGGER.debug("registering quickiefabric tools");
registerItem(QuickieTools.SPEEDPOWDERAXE, "speedpowderaxe"); registerItem(QuickieTools.SPEEDPOWDERAXE, "speedpowderaxe");
registerItem(QuickieTools.SPEEDPOWDERPICKAXE, "speedpowderpickaxe");
registerItem(QuickieTools.SPEEDPOWDERSHOVEL, "speedpowdershovel");
} }
public static final void registerEvents() { public static final void registerEvents() {
LOGGER.debug("registering quickiefabric events"); LOGGER.debug("registering quickiefabric events");
BreakBlockCallback.EVENT.register((world, blockPos, blockState, playerEntity) -> { BreakBlockCallback.EVENT.register((world, blockPos, blockState, playerEntity) -> {
// TODO: add code to break the corresponding surroundings also if hand hold the right tool new EventBlockBreak().doBreakBlock(world, blockPos, blockState, playerEntity);
// return ActionResult.PASS; // if the breaking replaces another event, but this does not appear for the speedpowder tools
LOGGER.info("{} broke block {} at {}", playerEntity.getName().asString(), blockState.getBlock().getTranslationKey(), blockPos.toString());
BlockState blockStateDown = world.getBlockState(blockPos);
if (!blockStateDown.isAir()) { // TODO: because we will only break the same blocks, that check becomes obsolete later
ItemStack itemStack = new ItemStack(blockStateDown.getBlock().asItem());
// spawn entity in world
Block.dropStack(world, blockPos.down(), itemStack);
world.setBlockState(blockPos.down(), Blocks.AIR.getDefaultState());
LOGGER.info("also broke block {} at {}", playerEntity.getName().asString(), blockState.getBlock().getTranslationKey(), blockPos.down().toString());
}
return ActionResult.SUCCESS; return ActionResult.SUCCESS;
}); });
} }
@ -132,4 +122,31 @@ public class RegistryManager {
// ConfiguredPlacement<CountRangeConfig> placement = Placement.COUNT_RANGE.configure(rdc); // ConfiguredPlacement<CountRangeConfig> placement = Placement.COUNT_RANGE.configure(rdc);
// biome.addFeature(GenerationStep.Feature.UNDERGROUND_ORES, Feature.SIMPLE_BLOCK.configure(config).withPlacement(placement)); // biome.addFeature(GenerationStep.Feature.UNDERGROUND_ORES, Feature.SIMPLE_BLOCK.configure(config).withPlacement(placement));
} }
/**
* add the quickiefabric ores to the biome
*
* @param biome
* the biome
*/
public static final void handleBiome(Biome biome) {
if (biome.getCategory() == Biome.Category.NETHER) {
RegistryManager.generateOreForTarget(biome, OreFeatureConfig.Target.NETHER_ORE_REPLACEABLES, QuickieBlocks.ORE_NETHER_SULPHOR, 24, 10, 0, 0, 128);
} else if (biome.getCategory() != Biome.Category.THEEND) {
} else {
List<BlockState> sandlike = new ArrayList<>();
sandlike.add(Blocks.SAND.getDefaultState());
sandlike.add(Blocks.SANDSTONE.getDefaultState());
sandlike.add(Blocks.SANDSTONE_WALL.getDefaultState());
sandlike.add(Blocks.CHISELED_SANDSTONE.getDefaultState());
List<BlockState> dirtlike = new ArrayList<>();
dirtlike.add(Blocks.DIRT.getDefaultState());
RegistryManager.generateOreForBlocks(biome, sandlike, sandlike, sandlike, QuickieBlocks.SAND_SALPETER, 10, 64, 196, 255);
RegistryManager.generateOreForBlocks(biome, sandlike, sandlike, sandlike, QuickieBlocks.ORE_SAND_SALPETER, 10, 64, 196, 255);
RegistryManager.generateOreForTarget(biome, OreFeatureConfig.Target.NATURAL_STONE, QuickieBlocks.ORE_SULPHOR, 16, 4, 4, 196, 255);
RegistryManager.generateOreForTarget(biome, OreFeatureConfig.Target.NATURAL_STONE, QuickieBlocks.ORE_SALPETER, 12, 10, 4, 196, 255);
}
}
} }