added lavahoarder
This commit is contained in:
parent
28c1ae42f4
commit
842f04baca
@ -0,0 +1,107 @@
|
|||||||
|
package de.jottyfan.minecraft.quickiefabric.blocks;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
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.util.math.BlockPos;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author jotty
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class BlockLavahoarder extends Block {
|
||||||
|
|
||||||
|
public BlockLavahoarder() {
|
||||||
|
super(FabricBlockSettings.of(Material.STONE).hardness(2.5f));
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,5 @@
|
|||||||
package de.jottyfan.minecraft.quickiefabric.blocks;
|
package de.jottyfan.minecraft.quickiefabric.blocks;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author jotty
|
* @author jotty
|
||||||
@ -11,4 +12,5 @@ public class QuickieBlocks {
|
|||||||
public static final BlockOreSandSalpeter ORE_SAND_SALPETER = new BlockOreSandSalpeter();
|
public static final BlockOreSandSalpeter ORE_SAND_SALPETER = new BlockOreSandSalpeter();
|
||||||
public static final BlockOreSulphor ORE_SULPHOR = new BlockOreSulphor();
|
public static final BlockOreSulphor ORE_SULPHOR = new BlockOreSulphor();
|
||||||
public static final BlockSandSalpeter SAND_SALPETER = new BlockSandSalpeter();
|
public static final BlockSandSalpeter SAND_SALPETER = new BlockSandSalpeter();
|
||||||
|
public static final BlockLavahoarder LAVAHOARDER = new BlockLavahoarder();
|
||||||
}
|
}
|
||||||
|
@ -56,6 +56,7 @@ public class RegistryManager {
|
|||||||
stacks.add(new ItemStack(QuickieBlocks.ORE_SAND_SALPETER));
|
stacks.add(new ItemStack(QuickieBlocks.ORE_SAND_SALPETER));
|
||||||
stacks.add(new ItemStack(QuickieBlocks.ORE_SULPHOR));
|
stacks.add(new ItemStack(QuickieBlocks.ORE_SULPHOR));
|
||||||
stacks.add(new ItemStack(QuickieBlocks.SAND_SALPETER));
|
stacks.add(new ItemStack(QuickieBlocks.SAND_SALPETER));
|
||||||
|
stacks.add(new ItemStack(QuickieBlocks.LAVAHOARDER));
|
||||||
}).build();
|
}).build();
|
||||||
|
|
||||||
private static final void registerBlock(Block block, String name) {
|
private static final void registerBlock(Block block, String name) {
|
||||||
@ -75,6 +76,7 @@ public class RegistryManager {
|
|||||||
registerBlock(QuickieBlocks.ORE_SAND_SALPETER, "oresandsalpeter");
|
registerBlock(QuickieBlocks.ORE_SAND_SALPETER, "oresandsalpeter");
|
||||||
registerBlock(QuickieBlocks.ORE_SULPHOR, "oresulphor");
|
registerBlock(QuickieBlocks.ORE_SULPHOR, "oresulphor");
|
||||||
registerBlock(QuickieBlocks.SAND_SALPETER, "sandsalpeter");
|
registerBlock(QuickieBlocks.SAND_SALPETER, "sandsalpeter");
|
||||||
|
registerBlock(QuickieBlocks.LAVAHOARDER, "lavahoarder");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final void registerItems() {
|
public static final void registerItems() {
|
||||||
|
@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"variants": {
|
||||||
|
"": {
|
||||||
|
"model": "quickiefabric:block/lavahoarder"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"parent": "block/cube_all",
|
||||||
|
"textures": {
|
||||||
|
"all": "quickiefabric:block/lavahoarder"
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"parent": "quickiefabric:block/lavahoarder",
|
||||||
|
"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: 709 B |
@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
"type": "minecraft:crafting_shaped",
|
||||||
|
"pattern": [
|
||||||
|
"ooo",
|
||||||
|
"oso",
|
||||||
|
"ooo"
|
||||||
|
],
|
||||||
|
"key": {
|
||||||
|
"o": {
|
||||||
|
"item": "minecraft:obsidian"
|
||||||
|
},
|
||||||
|
"s": {
|
||||||
|
"item": "quickiefabric:speedpowder"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"result": {
|
||||||
|
"item": "quickiefabric:lavahoarder",
|
||||||
|
"count": 1
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user