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