code cleanup
This commit is contained in:
@@ -4,6 +4,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
|
import de.jottyfan.minecraft.item.QuicklyItems;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.server.level.ServerLevel;
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import net.minecraft.util.RandomSource;
|
import net.minecraft.util.RandomSource;
|
||||||
@@ -11,6 +12,7 @@ import net.minecraft.world.InteractionHand;
|
|||||||
import net.minecraft.world.InteractionResult;
|
import net.minecraft.world.InteractionResult;
|
||||||
import net.minecraft.world.entity.item.ItemEntity;
|
import net.minecraft.world.entity.item.ItemEntity;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
|
import net.minecraft.world.item.Item;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.item.Items;
|
import net.minecraft.world.item.Items;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
@@ -39,28 +41,29 @@ public class BlockLavahoarder extends Block {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static final void spawnRandomItems(Level level, BlockPos pos, Integer count) {
|
public static final void spawnRandomItems(Level level, BlockPos pos, Integer count) {
|
||||||
Integer which = new Random().nextInt(10);
|
Integer which = level.getRandom().nextInt(10);
|
||||||
|
ItemStack stack = null;
|
||||||
if (which < 1) {
|
if (which < 1) {
|
||||||
level.addFreshEntity(new ItemEntity(level, pos.getX(), pos.getY(), pos.getZ(),
|
stack = new ItemStack(Items.DIAMOND, level.getRandom().nextInt(count + 2));
|
||||||
new ItemStack(Items.DIAMOND, new Random().nextInt(count + 2))));
|
|
||||||
} else if (which < 2) {
|
} else if (which < 2) {
|
||||||
level.addFreshEntity(new ItemEntity(level, pos.getX(), pos.getY(), pos.getZ(),
|
stack = new ItemStack(Items.EMERALD, level.getRandom().nextInt(count + 1));
|
||||||
new ItemStack(Items.EMERALD, new Random().nextInt(count + 1))));
|
|
||||||
} else if (which < 3) {
|
} else if (which < 3) {
|
||||||
level.addFreshEntity(new ItemEntity(level, pos.getX(), pos.getY(), pos.getZ(),
|
stack = new ItemStack(Items.RAW_GOLD, level.getRandom().nextInt(count));
|
||||||
new ItemStack(Items.RAW_GOLD, new Random().nextInt(count))));
|
|
||||||
} else if (which < 4) {
|
} else if (which < 4) {
|
||||||
level.addFreshEntity(new ItemEntity(level, pos.getX(), pos.getY(), pos.getZ(),
|
stack = new ItemStack(Items.RAW_IRON, level.getRandom().nextInt(count + 1));
|
||||||
new ItemStack(Items.RAW_IRON, new Random().nextInt(count + 1))));
|
|
||||||
} else if (which < 5) {
|
} else if (which < 5) {
|
||||||
level.addFreshEntity(new ItemEntity(level, pos.getX(), pos.getY(), pos.getZ(),
|
stack = new ItemStack(Items.RAW_COPPER, level.getRandom().nextInt(count + 2));
|
||||||
new ItemStack(Items.RAW_COPPER, new Random().nextInt(count + 2))));
|
|
||||||
} else if (which < 6) {
|
} else if (which < 6) {
|
||||||
level.addFreshEntity(new ItemEntity(level, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(Items.OBSIDIAN)));
|
stack = new ItemStack(Items.OBSIDIAN);
|
||||||
} else if (which < 7) {
|
} else if (which < 7) {
|
||||||
level.addFreshEntity(new ItemEntity(level, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(Items.LAPIS_LAZULI)));
|
stack = new ItemStack(Items.LAPIS_LAZULI);
|
||||||
// } else if (which < 8) {
|
} else if (which < 8) {
|
||||||
// level.addFreshEntity(new ItemEntity(level, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(QuicklyItems.SULFOR)));
|
stack = new ItemStack(QuicklyItems.RAWTURQUOISE);
|
||||||
|
// } else if (which < 9) {
|
||||||
|
// stack = new ItemStack(QuicklyItems.SULFOR);
|
||||||
|
}
|
||||||
|
if (stack != null) {
|
||||||
|
level.addFreshEntity(new ItemEntity(level, pos.getX(), pos.getY(), pos.getZ(), stack));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
47
src/main/java/de/jottyfan/minecraft/block/BlockOre.java
Normal file
47
src/main/java/de/jottyfan/minecraft/block/BlockOre.java
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
package de.jottyfan.minecraft.block;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.sounds.SoundEvent;
|
||||||
|
import net.minecraft.sounds.SoundSource;
|
||||||
|
import net.minecraft.world.entity.projectile.Projectile;
|
||||||
|
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.state.BlockState;
|
||||||
|
import net.minecraft.world.level.storage.loot.LootParams.Builder;
|
||||||
|
import net.minecraft.world.phys.BlockHitResult;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author jotty
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class BlockOre extends Block {
|
||||||
|
|
||||||
|
private SoundEvent soundEvent;
|
||||||
|
private ItemStack dropItems;
|
||||||
|
|
||||||
|
public BlockOre(Properties properties, SoundEvent soundEvent, ItemStack dropItems) {
|
||||||
|
super(properties.requiresCorrectToolForDrops());
|
||||||
|
this.soundEvent = soundEvent;
|
||||||
|
this.dropItems = dropItems;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected List<ItemStack> getDrops(BlockState state, Builder builder) {
|
||||||
|
ItemStack droppable = dropItems == null ? new ItemStack(this.asItem()) : dropItems;
|
||||||
|
return Arrays.asList(new ItemStack[] { droppable });
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onProjectileHit(final Level level, final BlockState state, final BlockHitResult hitResult,
|
||||||
|
final Projectile projectile) {
|
||||||
|
if (!level.isClientSide() && soundEvent != null) {
|
||||||
|
BlockPos hitPos = hitResult.getBlockPos();
|
||||||
|
level.playSound(null, hitPos, soundEvent, SoundSource.BLOCKS, 1.0F, 0.5F + level.getRandom().nextFloat() * 1.2F);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
package de.jottyfan.minecraft.block;
|
|
||||||
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import de.jottyfan.minecraft.item.QuicklyItems;
|
|
||||||
import net.minecraft.world.item.ItemStack;
|
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
|
||||||
import net.minecraft.world.level.storage.loot.LootParams.Builder;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author jotty
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class BlockOreDeepslateTurquoise extends BlockOreTurquoise {
|
|
||||||
|
|
||||||
public BlockOreDeepslateTurquoise(Properties properties) {
|
|
||||||
super(properties);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected List<ItemStack> getDrops(BlockState state, Builder builder) {
|
|
||||||
return Arrays.asList(new ItemStack[] { new ItemStack(QuicklyItems.RAWTURQUOISE, 2) });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
package de.jottyfan.minecraft.block;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import de.jottyfan.minecraft.item.QuicklyItems;
|
|
||||||
import net.minecraft.world.item.ItemStack;
|
|
||||||
import net.minecraft.world.level.block.AmethystBlock;
|
|
||||||
import net.minecraft.world.level.block.SoundType;
|
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
|
||||||
import net.minecraft.world.level.storage.loot.LootParams.Builder;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author jotty
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class BlockOreTurquoise extends AmethystBlock {
|
|
||||||
|
|
||||||
public BlockOreTurquoise(Properties properties) {
|
|
||||||
super(properties.strength(3.0f).sound(SoundType.AMETHYST).requiresCorrectToolForDrops());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected List<ItemStack> getDrops(BlockState state, Builder builder) {
|
|
||||||
return Arrays.asList(new ItemStack[] { new ItemStack(QuicklyItems.RAWTURQUOISE) });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -3,15 +3,18 @@ package de.jottyfan.minecraft.block;
|
|||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
import de.jottyfan.minecraft.Quickly;
|
import de.jottyfan.minecraft.Quickly;
|
||||||
|
import de.jottyfan.minecraft.item.QuicklyItems;
|
||||||
import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents;
|
import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents;
|
||||||
import net.minecraft.core.Registry;
|
import net.minecraft.core.Registry;
|
||||||
import net.minecraft.core.registries.BuiltInRegistries;
|
import net.minecraft.core.registries.BuiltInRegistries;
|
||||||
import net.minecraft.core.registries.Registries;
|
import net.minecraft.core.registries.Registries;
|
||||||
import net.minecraft.resources.Identifier;
|
import net.minecraft.resources.Identifier;
|
||||||
import net.minecraft.resources.ResourceKey;
|
import net.minecraft.resources.ResourceKey;
|
||||||
|
import net.minecraft.sounds.SoundEvents;
|
||||||
import net.minecraft.world.item.BlockItem;
|
import net.minecraft.world.item.BlockItem;
|
||||||
import net.minecraft.world.item.CreativeModeTabs;
|
import net.minecraft.world.item.CreativeModeTabs;
|
||||||
import net.minecraft.world.item.Item;
|
import net.minecraft.world.item.Item;
|
||||||
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.level.block.Block;
|
import net.minecraft.world.level.block.Block;
|
||||||
import net.minecraft.world.level.block.Blocks;
|
import net.minecraft.world.level.block.Blocks;
|
||||||
import net.minecraft.world.level.block.SoundType;
|
import net.minecraft.world.level.block.SoundType;
|
||||||
@@ -26,19 +29,21 @@ public class QuicklyBlocks {
|
|||||||
public static final Block KELPBUNDLE = registerBlock("kelpbundle",
|
public static final Block KELPBUNDLE = registerBlock("kelpbundle",
|
||||||
Properties.of().instabreak().sound(SoundType.WET_GRASS).strength(0.1f).friction(0.95f));
|
Properties.of().instabreak().sound(SoundType.WET_GRASS).strength(0.1f).friction(0.95f));
|
||||||
public static final Block TURQUOISEBLOCK = registerBlock("blockturquoise", Properties.of().strength(1.5f));
|
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 ORETURQUOISE = registerBlock("oreturquoise",
|
||||||
|
properties -> new BlockOre(properties.strength(3.0f).sound(SoundType.AMETHYST), SoundEvents.AMETHYST_BLOCK_CHIME,
|
||||||
|
new ItemStack(QuicklyItems.RAWTURQUOISE)));
|
||||||
public static final Block OREDEEPSLATETURQUOISE = registerBlock("oredeepslateturquoise",
|
public static final Block OREDEEPSLATETURQUOISE = registerBlock("oredeepslateturquoise",
|
||||||
properties -> new BlockOreDeepslateTurquoise(properties));
|
properties -> new BlockOre(properties, SoundEvents.AMETHYST_BLOCK_CHIME,
|
||||||
|
new ItemStack(QuicklyItems.RAWTURQUOISE, 2)));
|
||||||
public static final Block COTTONPLANT = registerBlock("blockcottonplant", Properties.ofFullCopy(Blocks.WHEAT),
|
public static final Block COTTONPLANT = registerBlock("blockcottonplant", Properties.ofFullCopy(Blocks.WHEAT),
|
||||||
properties -> new BlockPlant(properties, "cottonseed", "cotton"));
|
properties -> new BlockPlant(properties, "cottonseed", "cotton"));
|
||||||
public static final Block CANOLAPLANT = registerBlock("blockcanolaplant", Properties.ofFullCopy(Blocks.WHEAT),
|
public static final Block CANOLAPLANT = registerBlock("blockcanolaplant", Properties.ofFullCopy(Blocks.WHEAT),
|
||||||
properties -> new BlockPlant(properties, "canolaseed", "canola"));
|
properties -> new BlockPlant(properties, "canolaseed", "canola"));
|
||||||
public static final Block LAVAHOARDER = registerBlock("lavahoarder", Properties.of().strength(2.5f).lightLevel(state -> 15),
|
public static final Block LAVAHOARDER = registerBlock("lavahoarder",
|
||||||
properties -> new BlockLavahoarder(properties));
|
Properties.of().strength(2.5f).lightLevel(state -> 15), properties -> new BlockLavahoarder(properties));
|
||||||
public static final Block EMPTYLAVAHOARDER = registerBlock("emptylavahoarder", Properties.of().strength(2.5f),
|
public static final Block EMPTYLAVAHOARDER = registerBlock("emptylavahoarder", Properties.of().strength(2.5f),
|
||||||
properties -> new BlockEmptyLavahoarder(properties));
|
properties -> new BlockEmptyLavahoarder(properties));
|
||||||
|
|
||||||
|
|
||||||
private static final Block registerBlock(String name, Properties properties) {
|
private static final Block registerBlock(String name, Properties properties) {
|
||||||
return QuicklyBlocks.registerBlock(name, properties, p -> new Block(p));
|
return QuicklyBlocks.registerBlock(name, properties, p -> new Block(p));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,19 +24,16 @@ import net.minecraft.world.level.block.Blocks;
|
|||||||
*/
|
*/
|
||||||
public class Stub extends Item {
|
public class Stub extends Item {
|
||||||
|
|
||||||
// @formatter:off
|
|
||||||
private static final Map<Block, Item> SLASH_MAP = Map.of(
|
|
||||||
Blocks.HAY_BLOCK, Items.WHEAT,
|
|
||||||
Blocks.DRIED_KELP_BLOCK, Items.DRIED_KELP,
|
|
||||||
QuicklyBlocks.KELPBUNDLE, Items.KELP);
|
|
||||||
// @formatter:on
|
|
||||||
|
|
||||||
public Stub(Properties properties) {
|
public Stub(Properties properties) {
|
||||||
super(properties.stacksTo(64));
|
super(properties.stacksTo(64));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InteractionResult useOn(UseOnContext context) {
|
public InteractionResult useOn(UseOnContext context) {
|
||||||
|
Map<Block, Item> SLASH_MAP = Map.of(
|
||||||
|
Blocks.HAY_BLOCK, Items.WHEAT,
|
||||||
|
Blocks.DRIED_KELP_BLOCK, Items.DRIED_KELP,
|
||||||
|
QuicklyBlocks.KELPBUNDLE, Items.KELP);
|
||||||
Level level = context.getLevel();
|
Level level = context.getLevel();
|
||||||
BlockPos pos = context.getClickedPos();
|
BlockPos pos = context.getClickedPos();
|
||||||
Block clickedBlock = level.getBlockState(pos).getBlock();
|
Block clickedBlock = level.getBlockState(pos).getBlock();
|
||||||
|
|||||||
Reference in New Issue
Block a user