added lava hoarder
This commit is contained in:
@@ -0,0 +1,125 @@
|
||||
package de.jottyfan.minecraft.block;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.util.RandomSource;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.storage.loot.LootParams.Builder;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author jotty
|
||||
*
|
||||
*/
|
||||
public class BlockEmptyLavahoarder extends Block {
|
||||
|
||||
public BlockEmptyLavahoarder(Properties properties) {
|
||||
super(properties);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<ItemStack> getDrops(BlockState state, Builder params) {
|
||||
List<ItemStack> list = new ArrayList<>();
|
||||
list.add(new ItemStack(QuicklyBlocks.EMPTYLAVAHOARDER));
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tick(BlockState state, ServerLevel level, BlockPos pos, RandomSource random) {
|
||||
boolean found = BlockLavahoarder.suckLava(level, pos.north());
|
||||
found = found || BlockLavahoarder.suckLava(level, pos.south());
|
||||
found = found || BlockLavahoarder.suckLava(level, pos.east());
|
||||
found = found || BlockLavahoarder.suckLava(level, pos.west());
|
||||
found = found || BlockLavahoarder.suckLava(level, pos.above());
|
||||
found = found || BlockLavahoarder.suckLava(level, pos.below());
|
||||
if (found) {
|
||||
level.setBlock(pos, QuicklyBlocks.LAVAHOARDER.defaultBlockState(), 2);
|
||||
level.scheduleTick(pos, QuicklyBlocks.LAVAHOARDER, 1);
|
||||
} else {
|
||||
level.scheduleTick(pos, this, 1);
|
||||
}
|
||||
}
|
||||
|
||||
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, Level level, Integer counter) {
|
||||
if (counter < 1) {
|
||||
return;
|
||||
} else if (Blocks.LAVA.equals(level.getBlockState(pos).getBlock())) {
|
||||
String p = stringOf(pos);
|
||||
if (!list.contains(p)) {
|
||||
list.add(p);
|
||||
findAllAttachedLavaBlocks(list, pos.above(), level, counter - 1);
|
||||
findAllAttachedLavaBlocks(list, pos.below(), level, counter - 1);
|
||||
findAllAttachedLavaBlocks(list, pos.north(), level, counter - 1);
|
||||
findAllAttachedLavaBlocks(list, pos.south(), level, counter - 1);
|
||||
findAllAttachedLavaBlocks(list, pos.east(), level, counter - 1);
|
||||
findAllAttachedLavaBlocks(list, pos.west(), level, counter - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPlace(BlockState state, Level level, BlockPos pos, BlockState oldState, boolean movedByPiston) {
|
||||
Set<String> positions = new HashSet<>();
|
||||
Integer counter = 8; // TODO: make it level up - able
|
||||
findAllAttachedLavaBlocks(positions, pos.above(), level, counter);
|
||||
findAllAttachedLavaBlocks(positions, pos.below(), level, counter);
|
||||
findAllAttachedLavaBlocks(positions, pos.north(), level, counter);
|
||||
findAllAttachedLavaBlocks(positions, pos.south(), level, counter);
|
||||
findAllAttachedLavaBlocks(positions, pos.east(), level, counter);
|
||||
findAllAttachedLavaBlocks(positions, pos.west(), level, counter);
|
||||
Integer amount = positions.size();
|
||||
for (String p : positions) {
|
||||
level.setBlock(blockPosOf(p), Blocks.AIR.defaultBlockState(), 2);
|
||||
}
|
||||
if (amount > 0) {
|
||||
level.setBlock(pos, QuicklyBlocks.LAVAHOARDER.defaultBlockState(), 2);
|
||||
level.scheduleTick(pos, QuicklyBlocks.LAVAHOARDER, 1);
|
||||
int count = 0;
|
||||
Random random = new Random();
|
||||
for (int i = 0; i < amount; i++) {
|
||||
if (random.nextFloat() < 0.0125) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
if (count > 0) {
|
||||
BlockLavahoarder.spawnRandomItems(level, pos.above(), count);
|
||||
}
|
||||
} else {
|
||||
level.scheduleTick(pos, this, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
125
src/main/java/de/jottyfan/minecraft/block/BlockLavahoarder.java
Normal file
125
src/main/java/de/jottyfan/minecraft/block/BlockLavahoarder.java
Normal file
@@ -0,0 +1,125 @@
|
||||
package de.jottyfan.minecraft.block;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.util.RandomSource;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.entity.item.ItemEntity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.storage.loot.LootParams.Builder;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author jotty
|
||||
*
|
||||
*/
|
||||
public class BlockLavahoarder extends Block {
|
||||
|
||||
public BlockLavahoarder(Properties properties) {
|
||||
super(properties);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<ItemStack> getDrops(BlockState state, Builder params) {
|
||||
List<ItemStack> list = new ArrayList<>();
|
||||
list.add(new ItemStack(QuicklyBlocks.LAVAHOARDER));
|
||||
return list;
|
||||
}
|
||||
|
||||
public static final void spawnRandomItems(Level level, BlockPos pos, Integer count) {
|
||||
Integer which = new Random().nextInt(10);
|
||||
if (which < 1) {
|
||||
level.addFreshEntity(new ItemEntity(level, pos.getX(), pos.getY(), pos.getZ(),
|
||||
new ItemStack(Items.DIAMOND, new Random().nextInt(count + 2))));
|
||||
} else if (which < 2) {
|
||||
level.addFreshEntity(new ItemEntity(level, pos.getX(), pos.getY(), pos.getZ(),
|
||||
new ItemStack(Items.EMERALD, new Random().nextInt(count + 1))));
|
||||
} else if (which < 3) {
|
||||
level.addFreshEntity(new ItemEntity(level, pos.getX(), pos.getY(), pos.getZ(),
|
||||
new ItemStack(Items.RAW_GOLD, new Random().nextInt(count))));
|
||||
} else if (which < 4) {
|
||||
level.addFreshEntity(new ItemEntity(level, pos.getX(), pos.getY(), pos.getZ(),
|
||||
new ItemStack(Items.RAW_IRON, new Random().nextInt(count + 1))));
|
||||
} else if (which < 5) {
|
||||
level.addFreshEntity(new ItemEntity(level, pos.getX(), pos.getY(), pos.getZ(),
|
||||
new ItemStack(Items.RAW_COPPER, new Random().nextInt(count + 2))));
|
||||
} else if (which < 6) {
|
||||
level.addFreshEntity(new ItemEntity(level, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(Items.OBSIDIAN)));
|
||||
} else if (which < 7) {
|
||||
level.addFreshEntity(new ItemEntity(level, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(Items.LAPIS_LAZULI)));
|
||||
// } else if (which < 8) {
|
||||
// level.addFreshEntity(new ItemEntity(level, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(QuicklyItems.SULFOR)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* sucks the lava that touches the block
|
||||
*
|
||||
* @param world the world
|
||||
* @param pos the pos
|
||||
* @return true if lava was found
|
||||
*/
|
||||
public static final boolean suckLava(ServerLevel level, BlockPos pos) {
|
||||
if (level == null) {
|
||||
return false;
|
||||
} else if (Blocks.LAVA.equals(level.getBlockState(pos).getBlock())) {
|
||||
level.setBlock(pos, Blocks.AIR.defaultBlockState(), 2);
|
||||
if (new Random().nextFloat() > 0.9f) {
|
||||
spawnRandomItems(level, pos.above(), 2);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tick(BlockState state, ServerLevel level, BlockPos pos, RandomSource random) {
|
||||
suckLava(level, pos.north());
|
||||
suckLava(level, pos.south());
|
||||
suckLava(level, pos.east());
|
||||
suckLava(level, pos.west());
|
||||
suckLava(level, pos.above());
|
||||
suckLava(level, pos.below());
|
||||
level.scheduleTick(pos, this, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected InteractionResult useWithoutItem(BlockState state, Level level, BlockPos pos, Player player,
|
||||
BlockHitResult hitResult) {
|
||||
if (!level.isClientSide()) {
|
||||
ItemStack handStack = player.getMainHandItem();
|
||||
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);
|
||||
if (emptyBucketStack.getCount() < 1) {
|
||||
player.setItemInHand(InteractionHand.MAIN_HAND, lavaBucketStack);
|
||||
} else {
|
||||
player.setItemInHand(InteractionHand.MAIN_HAND, emptyBucketStack);
|
||||
level.addFreshEntity(new ItemEntity(level, pos.getX(), pos.getY(), pos.getZ(), lavaBucketStack));
|
||||
}
|
||||
spawnRandomItems(level, pos, 2);
|
||||
level.setBlock(pos, QuicklyBlocks.EMPTYLAVAHOARDER.defaultBlockState(), 2);
|
||||
level.scheduleTick(pos, this, 1);
|
||||
}
|
||||
}
|
||||
return InteractionResult.SUCCESS; // forbid to empty the just filled lava bucket
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPlace(BlockState state, Level level, BlockPos pos, BlockState oldState, boolean movedByPiston) {
|
||||
level.scheduleTick(pos, this, 1);
|
||||
}
|
||||
}
|
||||
@@ -28,11 +28,16 @@ public class QuicklyBlocks {
|
||||
public static final Block TURQUOISEBLOCK = registerBlock("blockturquoise", Properties.of().strength(1.5f));
|
||||
public static final Block ORETURQUOISE = registerBlock("oreturquoise", p -> new BlockOreTurquoise(p));
|
||||
public static final Block OREDEEPSLATETURQUOISE = registerBlock("oredeepslateturquoise",
|
||||
p -> new BlockOreDeepslateTurquoise(p));
|
||||
properties -> new BlockOreDeepslateTurquoise(properties));
|
||||
public static final Block COTTONPLANT = registerBlock("blockcottonplant", Properties.ofFullCopy(Blocks.WHEAT),
|
||||
p -> new BlockPlant(p, "cottonseed", "cotton"));
|
||||
properties -> new BlockPlant(properties, "cottonseed", "cotton"));
|
||||
public static final Block CANOLAPLANT = registerBlock("blockcanolaplant", Properties.ofFullCopy(Blocks.WHEAT),
|
||||
p -> new BlockPlant(p, "canolaseed", "canola"));
|
||||
properties -> new BlockPlant(properties, "canolaseed", "canola"));
|
||||
public static final Block LAVAHOARDER = registerBlock("lavahoarder", Properties.of().strength(2.5f).lightLevel(state -> 15),
|
||||
properties -> new BlockLavahoarder(properties));
|
||||
public static final Block EMPTYLAVAHOARDER = registerBlock("emptylavahoarder", Properties.of().strength(2.5f),
|
||||
properties -> new BlockEmptyLavahoarder(properties));
|
||||
|
||||
|
||||
private static final Block registerBlock(String name, Properties properties) {
|
||||
return QuicklyBlocks.registerBlock(name, properties, p -> new Block(p));
|
||||
@@ -58,8 +63,7 @@ public class QuicklyBlocks {
|
||||
block.accept(TURQUOISEBLOCK);
|
||||
block.accept(ORETURQUOISE);
|
||||
block.accept(OREDEEPSLATETURQUOISE);
|
||||
block.accept(COTTONPLANT);
|
||||
block.accept(CANOLAPLANT);
|
||||
block.accept(EMPTYLAVAHOARDER);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"variants": {
|
||||
"": {
|
||||
"model": "quickly:block/emptylavahoarder"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"variants": {
|
||||
"": {
|
||||
"model": "quickly:block/lavahoarder"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"model": {
|
||||
"type": "minecraft:model",
|
||||
"model": "quickly:block/emptylavahoarder"
|
||||
}
|
||||
}
|
||||
6
src/main/resources/assets/quickly/items/lavahoarder.json
Normal file
6
src/main/resources/assets/quickly/items/lavahoarder.json
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"model": {
|
||||
"type": "minecraft:model",
|
||||
"model": "quickly:block/lavahoarder"
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,9 @@
|
||||
"item.quickly.copperstub": "Kupferstummel",
|
||||
"item.quickly.cotton": "Baumwolle",
|
||||
"item.quickly.cottonseed": "Baumwollsaat",
|
||||
"item.quickly.emptylavahoarder": "Lavasauger",
|
||||
"item.quickly.kelpbundle": "Seegrassbündel",
|
||||
"item.quickly.lavahoarder": "voller Lavasauger",
|
||||
"item.quickly.oredeepslateturquoise": "Türkistiefenerz",
|
||||
"item.quickly.oreturquoise": "Türkiserz",
|
||||
"item.quickly.oxidizedcopperpowder": "oxidiertes Kupferpulver",
|
||||
|
||||
@@ -12,7 +12,9 @@
|
||||
"item.quickly.copperstub": "copper stub",
|
||||
"item.quickly.cotton": "cotton",
|
||||
"item.quickly.cottonseed": "cotton seed",
|
||||
"item.quickly.emptylavahoarder": "lava hoarder",
|
||||
"item.quickly.kelpbundle": "kelp bundle",
|
||||
"item.quickly.lavahoarder": "filled lava hoarder",
|
||||
"item.quickly.oredeepslateturquoise": "turquoise deepslate ore",
|
||||
"item.quickly.oreturquoise": "turquoise ore",
|
||||
"item.quickly.oxidizedcopperpowder": "oxidized copper powder",
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"parent": "block/cube_all",
|
||||
"textures": {
|
||||
"all": "quickly:block/emptylavahoarder"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"parent": "block/cube_all",
|
||||
"textures": {
|
||||
"all": "quickly:block/lavahoarder"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"parent": "quickly:block/emptylavahoarder",
|
||||
"display": {
|
||||
"thirdperson": {
|
||||
"rotation": [ 10, -45, 170 ],
|
||||
"translation": [ 0, 1.5, -2.75 ],
|
||||
"scale": [ 0.375, 0.375, 0.375 ]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"parent": "quickly: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: 542 B |
BIN
src/main/resources/assets/quickly/textures/block/lavahoarder.png
Normal file
BIN
src/main/resources/assets/quickly/textures/block/lavahoarder.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 709 B |
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"type": "minecraft:crafting_shaped",
|
||||
"pattern": [
|
||||
"oio",
|
||||
"ibi",
|
||||
"oio"
|
||||
],
|
||||
"key": {
|
||||
"o": "minecraft:obsidian",
|
||||
"i": "quickly:turquoiseingot",
|
||||
"b": "minecraft:bucket"
|
||||
},
|
||||
"result": {
|
||||
"id": "quickly:emptylavahoarder",
|
||||
"count": 1
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user