added monster hoarder
This commit is contained in:
@@ -0,0 +1,109 @@
|
||||
package de.jottyfan.minecraft.block;
|
||||
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import de.jottyfan.minecraft.Quickly;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.util.RandomSource;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.entity.monster.Monster;
|
||||
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.state.BlockState;
|
||||
import net.minecraft.world.level.block.state.StateDefinition.Builder;
|
||||
import net.minecraft.world.level.block.state.properties.IntegerProperty;
|
||||
import net.minecraft.world.phys.AABB;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
import net.minecraft.world.ticks.ScheduledTick;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author jotty
|
||||
*
|
||||
*/
|
||||
public class BlockMonsterhoarder extends Block {
|
||||
|
||||
private static final Integer MINSUCKRADIUS = 2;
|
||||
private static final Integer MAXSUCKRADIUS = 20;
|
||||
private static final Integer MINBURNTICKS = 10;
|
||||
private static final Integer MAXBURNTICKS = 200;
|
||||
private static final IntegerProperty SUCKRADIUS = IntegerProperty.create("suckradius", MINSUCKRADIUS, MAXSUCKRADIUS);
|
||||
private static final IntegerProperty BURNTICKS = IntegerProperty.create("burnticks", MINBURNTICKS, MAXBURNTICKS);
|
||||
|
||||
public BlockMonsterhoarder(Properties properties) {
|
||||
super(properties.strength(2.5f).lightLevel(state -> state.getValue(SUCKRADIUS)));
|
||||
registerDefaultState(stateDefinition.any().setValue(SUCKRADIUS, MINSUCKRADIUS).setValue(BURNTICKS, MINBURNTICKS));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void createBlockStateDefinition(Builder<Block, BlockState> builder) {
|
||||
builder.add(SUCKRADIUS, BURNTICKS);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected InteractionResult useItemOn(ItemStack itemStack, BlockState state, Level level, BlockPos pos, Player player,
|
||||
InteractionHand hand, BlockHitResult hitResult) {
|
||||
if (Items.WATER_BUCKET.equals(itemStack.getItem())) {
|
||||
level.setBlock(pos, state.setValue(SUCKRADIUS, MINSUCKRADIUS), UPDATE_ALL);
|
||||
player.setItemInHand(hand, new ItemStack(Items.BUCKET));
|
||||
} else if (Items.TORCH.equals(itemStack.getItem())) {
|
||||
level.setBlock(pos, state.cycle(SUCKRADIUS), UPDATE_ALL);
|
||||
itemStack.shrink(1);
|
||||
} else if (Items.SOUL_TORCH.equals(itemStack.getItem())) {
|
||||
int newBurnTicks = state.getValue(BURNTICKS) + 10;
|
||||
newBurnTicks = newBurnTicks < MAXBURNTICKS ? newBurnTicks : MAXBURNTICKS;
|
||||
level.setBlock(pos, state.setValue(BURNTICKS, newBurnTicks), UPDATE_ALL);
|
||||
itemStack.shrink(1);
|
||||
} else if (Items.REDSTONE_TORCH.equals(itemStack.getItem())) {
|
||||
level.setBlock(pos, state.cycle(SUCKRADIUS), UPDATE_ALL);
|
||||
} else if (Items.COPPER_TORCH.equals(itemStack.getItem())) {
|
||||
level.setBlock(pos, state.setValue(BURNTICKS, MINBURNTICKS), UPDATE_ALL);
|
||||
itemStack.shrink(1);
|
||||
} else {
|
||||
int suckRadius = state.getValue(SUCKRADIUS);
|
||||
int burnTicks = state.getValue(BURNTICKS);
|
||||
Component message = Component.translatable("info.block.monsterhoarder", suckRadius, burnTicks);
|
||||
if (player instanceof ServerPlayer serverPlayer) {
|
||||
serverPlayer.displayClientMessage(message, true);
|
||||
}
|
||||
}
|
||||
return InteractionResult.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tick(BlockState state, ServerLevel level, BlockPos pos, RandomSource random) {
|
||||
if (!level.isClientSide()) {
|
||||
AABB checkArea = new AABB(pos).inflate(state.getValue(SUCKRADIUS));
|
||||
for (Monster monster : level.getEntitiesOfClass(Monster.class, checkArea)) {
|
||||
if (monster.fireImmune()) {
|
||||
monster.kill(level);
|
||||
} else {
|
||||
monster.igniteForTicks(state.getValue(BURNTICKS));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (level instanceof ServerLevel serverLevel) {
|
||||
serverLevel.getBlockTicks()
|
||||
.schedule(new ScheduledTick<>(this, pos, level.getGameTime() + 20, 1));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlacedBy(Level level, BlockPos pos, BlockState state, @Nullable LivingEntity by, ItemStack itemStack) {
|
||||
if (level instanceof ServerLevel serverLevel) {
|
||||
serverLevel.getBlockTicks()
|
||||
.schedule(new ScheduledTick<>(this, pos, level.getGameTime() + 20, 1));
|
||||
level.playSound(null, pos, SoundEvents.UI_TOAST_CHALLENGE_COMPLETE, SoundSource.PLAYERS, 1f, 1f);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -47,6 +47,8 @@ public class QuicklyBlocks {
|
||||
properties -> new BlockDrops(properties, new ItemStack(QuicklyItems.QUICKIEPOWDER, 9)));
|
||||
public static final Block SPEEDPOWDER = registerBlock("blockspeedpowder",
|
||||
properties -> new BlockDrops(properties, new ItemStack(QuicklyItems.SPEEDPOWDER, 9)));
|
||||
public static final Block MONSTERHOARDER = registerBlock("monsterhoarder",
|
||||
properties -> new BlockMonsterhoarder(properties));
|
||||
|
||||
private static final Block registerBlock(String name, Properties properties) {
|
||||
return QuicklyBlocks.registerBlock(name, properties, p -> new Block(p));
|
||||
@@ -75,6 +77,7 @@ public class QuicklyBlocks {
|
||||
block.accept(EMPTYLAVAHOARDER);
|
||||
block.accept(SPEEDPOWDER);
|
||||
block.accept(QUICKIEPOWDER);
|
||||
block.accept(MONSTERHOARDER);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"variants": {
|
||||
"": {
|
||||
"model": "quickly:block/monsterhoarder"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"model": {
|
||||
"type": "minecraft:model",
|
||||
"model": "quickly:block/monsterhoarder"
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
{
|
||||
"info.block.monsterhoarder": "Radius: %s, Brenndauer: %s Ticks",
|
||||
"item.quickly.blockcanolaplant": "Rapspflanze",
|
||||
"item.quickly.blockcottonplant": "Baumwollpflanze",
|
||||
"item.quickly.blockquickiepowder": "Eilpulverblock",
|
||||
@@ -15,8 +16,10 @@
|
||||
"item.quickly.cotton": "Baumwolle",
|
||||
"item.quickly.cottonseed": "Baumwollsaat",
|
||||
"item.quickly.emptylavahoarder": "Lavasauger",
|
||||
"item.quickly.itemhoarder": "Itemsauger",
|
||||
"item.quickly.kelpbundle": "Seegrassbündel",
|
||||
"item.quickly.lavahoarder": "voller Lavasauger",
|
||||
"item.quickly.monsterhoarder": "Monstersauger",
|
||||
"item.quickly.oredeepslateturquoise": "Türkistiefenerz",
|
||||
"item.quickly.oreturquoise": "Türkiserz",
|
||||
"item.quickly.oxidizedcopperpowder": "oxidiertes Kupferpulver",
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
{
|
||||
"info.block.monsterhoarder": "radius: %s, burn ticks: %s",
|
||||
"item.quickly.blockcanolaplant": "canola plant",
|
||||
"item.quickly.blockcottonplant": "cotton plant",
|
||||
"item.quickly.blockquickiepowder": "quickie powder block",
|
||||
@@ -15,8 +16,10 @@
|
||||
"item.quickly.cotton": "cotton",
|
||||
"item.quickly.cottonseed": "cotton seed",
|
||||
"item.quickly.emptylavahoarder": "lava hoarder",
|
||||
"item.quickly.itemhoarder": "item hoarder",
|
||||
"item.quickly.kelpbundle": "kelp bundle",
|
||||
"item.quickly.lavahoarder": "filled lava hoarder",
|
||||
"item.quickly.monsterhoarder": "monster 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/monsterhoarder"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"parent": "quickly:block/monsterhoarder",
|
||||
"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: 2.3 KiB |
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"type": "minecraft:crafting_shaped",
|
||||
"pattern": [
|
||||
"tct",
|
||||
"clc",
|
||||
"tct"
|
||||
],
|
||||
"key": {
|
||||
"t": "quickly:turquoiseingot",
|
||||
"l": "minecraft:copper_lantern",
|
||||
"c": "quickly:copperstub"
|
||||
},
|
||||
"result": {
|
||||
"id": "quickly:monsterhoarder",
|
||||
"count": 1
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user