enhanced lava hoarder functionality
This commit is contained in:
parent
8b3e4da9c2
commit
beccb5341c
@ -0,0 +1,118 @@
|
||||
package de.jottyfan.minecraft.quickiefabric.blocks;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
import de.jottyfan.minecraft.quickiefabric.items.QuickieItems;
|
||||
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.block.Material;
|
||||
import net.minecraft.entity.ExperienceOrbEntity;
|
||||
import net.minecraft.entity.ItemEntity;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.loot.context.LootContext.Builder;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author jotty
|
||||
*
|
||||
*/
|
||||
public class BlockEmptyLavahoarder extends Block {
|
||||
|
||||
public BlockEmptyLavahoarder() {
|
||||
super(FabricBlockSettings.of(Material.STONE).hardness(2.5f));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemStack> getDroppedStacks(BlockState state, Builder builder) {
|
||||
List<ItemStack> list = new ArrayList<>();
|
||||
list.add(new ItemStack(QuickieBlocks.EMPTYLAVAHOARDER));
|
||||
return list;
|
||||
}
|
||||
|
||||
private static final String stringOf(BlockPos pos) {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
buf.append(pos.getX()).append(":");
|
||||
buf.append(pos.getY()).append(":");
|
||||
buf.append(pos.getZ());
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
private static final BlockPos blockPosOf(String s) {
|
||||
if (s.contains(":")) {
|
||||
String[] parts = s.split(":");
|
||||
if (parts.length > 2) {
|
||||
Integer x = Integer.valueOf(parts[0]);
|
||||
Integer y = Integer.valueOf(parts[1]);
|
||||
Integer z = Integer.valueOf(parts[2]);
|
||||
return new BlockPos(x, y, z);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private void findAllAttachedLavaBlocks(Set<String> list, BlockPos pos, World world, Integer counter) {
|
||||
if (counter < 1) {
|
||||
return;
|
||||
} else if (Blocks.LAVA.equals(world.getBlockState(pos).getBlock())) {
|
||||
String p = stringOf(pos);
|
||||
if (!list.contains(p)) {
|
||||
list.add(p);
|
||||
findAllAttachedLavaBlocks(list, pos.up(), world, counter - 1);
|
||||
findAllAttachedLavaBlocks(list, pos.down(), world, counter - 1);
|
||||
findAllAttachedLavaBlocks(list, pos.north(), world, counter - 1);
|
||||
findAllAttachedLavaBlocks(list, pos.south(), world, counter - 1);
|
||||
findAllAttachedLavaBlocks(list, pos.east(), world, counter - 1);
|
||||
findAllAttachedLavaBlocks(list, pos.west(), world, counter - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlaced(World world, BlockPos pos, BlockState state, LivingEntity placer, ItemStack stack) {
|
||||
Set<String> positions = new HashSet<>();
|
||||
Integer counter = 8; // TODO: make it level up - able
|
||||
findAllAttachedLavaBlocks(positions, pos.up(), world, counter);
|
||||
findAllAttachedLavaBlocks(positions, pos.down(), world, counter);
|
||||
findAllAttachedLavaBlocks(positions, pos.north(), world, counter);
|
||||
findAllAttachedLavaBlocks(positions, pos.south(), world, counter);
|
||||
findAllAttachedLavaBlocks(positions, pos.east(), world, counter);
|
||||
findAllAttachedLavaBlocks(positions, pos.west(), world, counter);
|
||||
Integer amount = positions.size();
|
||||
for (String p : positions) {
|
||||
world.setBlockState(blockPosOf(p), Blocks.AIR.getDefaultState());
|
||||
}
|
||||
Random random = new Random();
|
||||
if (amount > 0) {
|
||||
world.setBlockState(pos, QuickieBlocks.LAVAHOARDER.getDefaultState());
|
||||
int count = 0;
|
||||
for (int i = 0; i < amount; i++) {
|
||||
if (random.nextFloat() < 0.0125) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
BlockPos up = pos.up();
|
||||
if (count > 0) {
|
||||
world.spawnEntity(new ItemEntity(world, up.getX(), up.getY(), up.getZ(), new ItemStack(QuickieItems.SULPHOR, count)));
|
||||
world.spawnEntity(new ItemEntity(world, up.getX(), up.getY(), up.getZ(), new ItemStack(Items.DIAMOND, new Random().nextInt(count))));
|
||||
world.spawnEntity(new ItemEntity(world, up.getX(), up.getY(), up.getZ(), new ItemStack(Items.EMERALD, new Random().nextInt(count))));
|
||||
world.spawnEntity(new ItemEntity(world, up.getX(), up.getY(), up.getZ(), new ItemStack(Items.GOLD_NUGGET, new Random().nextInt(count))));
|
||||
world.spawnEntity(new ItemEntity(world, up.getX(), up.getY(), up.getZ(), new ItemStack(Items.IRON_NUGGET, new Random().nextInt(count))));
|
||||
world.spawnEntity(new ItemEntity(world, up.getX(), up.getY(), up.getZ(), new ItemStack(Items.LAPIS_LAZULI, new Random().nextInt(count))));
|
||||
world.spawnEntity(new ExperienceOrbEntity(world, (double) pos.getX() + 0.5D, (double) pos.getY() + 0.5D, (double) pos.getZ() + 0.5D, count));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,23 +1,21 @@
|
||||
package de.jottyfan.minecraft.quickiefabric.blocks;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
import de.jottyfan.minecraft.quickiefabric.items.QuickieItems;
|
||||
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.block.Material;
|
||||
import net.minecraft.entity.ExperienceOrbEntity;
|
||||
import net.minecraft.entity.ItemEntity;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.loot.context.LootContext.Builder;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
@ -39,79 +37,20 @@ public class BlockLavahoarder extends Block {
|
||||
return list;
|
||||
}
|
||||
|
||||
private static final String stringOf(BlockPos pos) {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
buf.append(pos.getX()).append(":");
|
||||
buf.append(pos.getY()).append(":");
|
||||
buf.append(pos.getZ());
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
private static final BlockPos blockPosOf(String s) {
|
||||
if (s.contains(":")) {
|
||||
String[] parts = s.split(":");
|
||||
if (parts.length > 2) {
|
||||
Integer x = Integer.valueOf(parts[0]);
|
||||
Integer y = Integer.valueOf(parts[1]);
|
||||
Integer z = Integer.valueOf(parts[2]);
|
||||
return new BlockPos(x, y, z);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private void findAllAttachedLavaBlocks(Set<String> list, BlockPos pos, World world, Integer counter) {
|
||||
if (counter < 1) {
|
||||
return;
|
||||
} else if (Blocks.LAVA.equals(world.getBlockState(pos).getBlock())) {
|
||||
String p = stringOf(pos);
|
||||
if (!list.contains(p)) {
|
||||
list.add(p);
|
||||
findAllAttachedLavaBlocks(list, pos.up(), world, counter - 1);
|
||||
findAllAttachedLavaBlocks(list, pos.down(), world, counter - 1);
|
||||
findAllAttachedLavaBlocks(list, pos.north(), world, counter - 1);
|
||||
findAllAttachedLavaBlocks(list, pos.south(), world, counter - 1);
|
||||
findAllAttachedLavaBlocks(list, pos.east(), world, counter - 1);
|
||||
findAllAttachedLavaBlocks(list, pos.west(), world, counter - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlaced(World world, BlockPos pos, BlockState state, LivingEntity placer, ItemStack stack) {
|
||||
Set<String> positions = new HashSet<>();
|
||||
Integer counter = 8; // TODO: make it level up - able
|
||||
findAllAttachedLavaBlocks(positions, pos.up(), world, counter);
|
||||
findAllAttachedLavaBlocks(positions, pos.down(), world, counter);
|
||||
findAllAttachedLavaBlocks(positions, pos.north(), world, counter);
|
||||
findAllAttachedLavaBlocks(positions, pos.south(), world, counter);
|
||||
findAllAttachedLavaBlocks(positions, pos.east(), world, counter);
|
||||
findAllAttachedLavaBlocks(positions, pos.west(), world, counter);
|
||||
Integer amount = positions.size();
|
||||
for (String p : positions) {
|
||||
world.setBlockState(blockPosOf(p), Blocks.AIR.getDefaultState());
|
||||
}
|
||||
Random random = new Random();
|
||||
if (amount > 0) {
|
||||
int count = 0;
|
||||
for (int i = 0; i < amount; i++) {
|
||||
if (random.nextFloat() < 0.0125) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
BlockPos up = pos.up();
|
||||
if (count > 0) {
|
||||
world.spawnEntity(new ItemEntity(world, up.getX(), up.getY(), up.getZ(), new ItemStack(QuickieItems.SULPHOR, count)));
|
||||
world.spawnEntity(new ItemEntity(world, up.getX(), up.getY(), up.getZ(), new ItemStack(Items.DIAMOND, new Random().nextInt(count))));
|
||||
world.spawnEntity(new ItemEntity(world, up.getX(), up.getY(), up.getZ(), new ItemStack(Items.EMERALD, new Random().nextInt(count))));
|
||||
world.spawnEntity(new ItemEntity(world, up.getX(), up.getY(), up.getZ(), new ItemStack(Items.GOLD_NUGGET, new Random().nextInt(count))));
|
||||
world.spawnEntity(new ItemEntity(world, up.getX(), up.getY(), up.getZ(), new ItemStack(Items.IRON_NUGGET, new Random().nextInt(count))));
|
||||
world.spawnEntity(new ItemEntity(world, up.getX(), up.getY(), up.getZ(), new ItemStack(Items.LAPIS_LAZULI, new Random().nextInt(count))));
|
||||
world.spawnEntity(new ExperienceOrbEntity(world, (double) pos.getX() + 0.5D, (double) pos.getY() + 0.5D, (double) pos.getZ() + 0.5D, count));
|
||||
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand,
|
||||
BlockHitResult hit) {
|
||||
if (!world.isClient) {
|
||||
ItemStack handStack = player.getStackInHand(hand);
|
||||
if (handStack != null && Items.BUCKET.equals(handStack.getItem())) {
|
||||
Integer amount = handStack.getCount();
|
||||
ItemStack lavaBucketStack = new ItemStack(Items.LAVA_BUCKET, 1);
|
||||
ItemStack emptyBucketStack = new ItemStack(Items.BUCKET, amount - 1);
|
||||
player.setStackInHand(hand, emptyBucketStack);
|
||||
world.spawnEntity(new ItemEntity(world, pos.getX(), pos.getY(), pos.getZ(), lavaBucketStack));
|
||||
world.setBlockState(pos, QuickieBlocks.EMPTYLAVAHOARDER.getDefaultState());
|
||||
}
|
||||
}
|
||||
return ActionResult.SUCCESS; // forbid to empty the just filled lava bucket
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ public class QuickieBlocks {
|
||||
public static final BlockOreSulphor ORE_SULPHOR = new BlockOreSulphor();
|
||||
public static final BlockSandSalpeter SAND_SALPETER = new BlockSandSalpeter();
|
||||
public static final BlockLavahoarder LAVAHOARDER = new BlockLavahoarder();
|
||||
public static final BlockEmptyLavahoarder EMPTYLAVAHOARDER = new BlockEmptyLavahoarder();
|
||||
public static final BlockItemhoarder ITEMHOARDER = new BlockItemhoarder();
|
||||
public static final BlockMonsterhoarder MONSTERHOARDER = new BlockMonsterhoarder();
|
||||
public static final BlockKelpstack KELPSTACK = new BlockKelpstack();
|
||||
|
@ -121,6 +121,7 @@ public class RegistryManager {
|
||||
stacks.add(new ItemStack(QuickieBlocks.ORE_SULPHOR));
|
||||
stacks.add(new ItemStack(QuickieBlocks.SAND_SALPETER));
|
||||
stacks.add(new ItemStack(QuickieBlocks.LAVAHOARDER));
|
||||
stacks.add(new ItemStack(QuickieBlocks.EMPTYLAVAHOARDER));
|
||||
stacks.add(new ItemStack(QuickieBlocks.ITEMHOARDER));
|
||||
stacks.add(new ItemStack(QuickieBlocks.MONSTERHOARDER));
|
||||
stacks.add(new ItemStack(QuickieBlocks.KELPSTACK));
|
||||
@ -154,6 +155,7 @@ public class RegistryManager {
|
||||
registerBlock(QuickieBlocks.ORE_SULPHOR, "oresulphor");
|
||||
registerBlock(QuickieBlocks.SAND_SALPETER, "sandsalpeter");
|
||||
registerBlock(QuickieBlocks.LAVAHOARDER, "lavahoarder");
|
||||
registerBlock(QuickieBlocks.EMPTYLAVAHOARDER, "emptylavahoarder");
|
||||
registerBlock(QuickieBlocks.ITEMHOARDER, "itemhoarder");
|
||||
registerBlock(QuickieBlocks.MONSTERHOARDER, "monsterhoarder");
|
||||
registerBlock(QuickieBlocks.KELPSTACK, "kelpstack");
|
||||
|
@ -0,0 +1,7 @@
|
||||
{
|
||||
"variants": {
|
||||
"": {
|
||||
"model": "quickiefabric:block/emptylavahoarder"
|
||||
}
|
||||
}
|
||||
}
|
@ -43,7 +43,8 @@
|
||||
"block.quickiefabric.moveup": "Höhenpositionsaddierer",
|
||||
"block.quickiefabric.movedown": "Höhenpositionssubtrahierer",
|
||||
"block.quickiefabric.menu": "Bauplanwerkbank",
|
||||
"block.quickiefabric.lavahoarder": "Lavasauger",
|
||||
"block.quickiefabric.lavahoarder": "voller Lavasauger",
|
||||
"block.quickiefabric.emptylavahoarder": "Lavasauger",
|
||||
"block.quickiefabric.itemhoarder": "Itemsauger",
|
||||
"block.quickiefabric.monsterhoarder": "Monstersauger",
|
||||
"block.quickiefabric.kelpstack": "Seegrassbündel",
|
||||
|
@ -43,7 +43,8 @@
|
||||
"block.quickiefabric.moveup": "height position adder",
|
||||
"block.quickiefabric.movedown": "height position substractor",
|
||||
"block.quickiefabric.menu": "building plan crafting table",
|
||||
"block.quickiefabric.lavahoarder": "lava hoarder",
|
||||
"block.quickiefabric.lavahoarder": "filled lava hoarder",
|
||||
"block.quickiefabric.emptylavahoarder": "lava hoarder",
|
||||
"block.quickiefabric.itemhoarder": "item hoarder",
|
||||
"block.quickiefabric.monsterhoarder": "monster hoarder",
|
||||
"block.quickiefabric.kelpstack": "kelp bundle",
|
||||
|
@ -0,0 +1,6 @@
|
||||
{
|
||||
"parent": "block/cube_all",
|
||||
"textures": {
|
||||
"all": "quickiefabric:block/emptylavahoarder"
|
||||
}
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
{
|
||||
"parent": "quickiefabric:block/emptylavahoarder",
|
||||
"display": {
|
||||
"thirdperson": {
|
||||
"rotation": [ 10, -45, 170 ],
|
||||
"translation": [ 0, 1.5, -2.75 ],
|
||||
"scale": [ 0.375, 0.375, 0.375 ]
|
||||
}
|
||||
}
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 542 B |
Loading…
x
Reference in New Issue
Block a user