Compare commits

..

14 Commits

Author SHA1 Message Date
Jottyfan
83267ea506 blockstacker without menu
Some checks failed
build / build (21) (push) Has been cancelled
2024-11-30 18:44:28 +01:00
Jottyfan
f59ceb8883 added drill
Some checks are pending
build / build (21) (push) Waiting to run
2024-11-30 00:31:23 +01:00
Jörg Henke
c5c4c4d8a6 corrected loot table for grass crop drops
Some checks failed
build / build (21) (push) Has been cancelled
2024-11-27 22:32:15 +01:00
Jottyfan
4fc53e92d1 improved loot table builder
Some checks failed
build / build (21) (push) Has been cancelled
2024-11-26 18:25:27 +01:00
Jottyfan
b063cd6ef2 experiments with loot table changes
Some checks are pending
build / build (21) (push) Waiting to run
2024-11-26 08:57:24 +01:00
Jottyfan
346ee85ca3 added crops - but loot table does not work yet 2024-11-25 21:10:27 +01:00
Jottyfan
4e4742ae11 added kelpstack 2024-11-24 21:46:28 +01:00
Jottyfan
529f40395e added ores 2024-11-23 23:04:56 +01:00
Jottyfan
6d2c1967fa added tools 2024-11-23 19:31:37 +01:00
Jottyfan
7993693d9c added itemhoarder with block entity 2024-11-21 21:42:29 +01:00
Jottyfan
451f19ea73 added lavahoarder 2024-11-20 21:55:49 +01:00
Jottyfan
04f87a977e added monster hoarder 2024-11-17 17:48:32 +01:00
Jottyfan
062d75fa93 added rooten flesh stripes and carrot stack 2024-11-16 18:25:22 +01:00
Jottyfan
fb6867f25b added ingots and oxidized copper powder 2024-11-16 00:43:40 +01:00
329 changed files with 5787 additions and 44 deletions

View File

@@ -9,7 +9,7 @@ yarn_mappings=1.21.3+build.2
loader_version=0.16.9 loader_version=0.16.9
# Mod Properties # Mod Properties
mod_version=1.21.3.0 mod_version=1.21.3.1
maven_group=de.jottyfan.quickiemod maven_group=de.jottyfan.quickiemod
archives_base_name=quickiemod archives_base_name=quickiemod

View File

@@ -6,11 +6,21 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import de.jottyfan.quickiemod.block.ModBlocks; import de.jottyfan.quickiemod.block.ModBlocks;
import de.jottyfan.quickiemod.blockentity.ModBlockentity;
import de.jottyfan.quickiemod.event.EventBlockBreak;
import de.jottyfan.quickiemod.feature.ModFeatures;
import de.jottyfan.quickiemod.item.ModItems; import de.jottyfan.quickiemod.item.ModItems;
import de.jottyfan.quickiemod.tab.ModTabs; import de.jottyfan.quickiemod.itemgroup.ModItemGroup;
import net.fabricmc.api.ModInitializer; import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.event.player.PlayerBlockBreakEvents;
import net.fabricmc.fabric.api.loot.v3.LootTableEvents;
import net.fabricmc.fabric.api.registry.CompostingChanceRegistry;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.Items;
import net.minecraft.loot.LootPool;
import net.minecraft.loot.condition.SurvivesExplosionLootCondition;
import net.minecraft.loot.entry.ItemEntry;
/** /**
* *
@@ -21,10 +31,43 @@ public class Quickiemod implements ModInitializer {
public static final String MOD_ID = "quickiemod"; public static final String MOD_ID = "quickiemod";
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID); public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
private void registerComposterItems() {
CompostingChanceRegistry.INSTANCE.add(ModItems.ITEM_COTTONSEED, 0.5f);
CompostingChanceRegistry.INSTANCE.add(ModItems.ITEM_COTTON, 0.75f);
CompostingChanceRegistry.INSTANCE.add(ModItems.ITEM_CANOLASEED, 0.5f);
CompostingChanceRegistry.INSTANCE.add(ModItems.ITEM_CANOLA, 0.75f);
}
private void registerLootTableChanges() {
LootTableEvents.MODIFY.register((key, tableBuilder, source, registries) -> {
if (source.isBuiltin()) {
if ("minecraft:blocks/short_grass".equals(key.getValue().toString())) {
tableBuilder.pool(LootPool.builder()
.with(ItemEntry.builder(ModItems.ITEM_COTTONSEED).weight(1))
.with(ItemEntry.builder(Items.AIR).weight(4))
.conditionally(SurvivesExplosionLootCondition.builder()));
} else if ("minecraft:blocks/tall_grass".equals(key.getValue().toString())) {
tableBuilder.pool(LootPool.builder()
.with(ItemEntry.builder(ModItems.ITEM_CANOLASEED).weight(1))
.with(ItemEntry.builder(Items.AIR).weight(7))
.conditionally(SurvivesExplosionLootCondition.builder()));
}
}
});
}
@Override @Override
public void onInitialize() { public void onInitialize() {
ModBlockentity.registerModBlockentities();
List<Item> items = ModItems.registerModItems(); List<Item> items = ModItems.registerModItems();
List<Block> blocks = ModBlocks.registerModBlocks(); List<Block> blocks = ModBlocks.registerModBlocks();
ModTabs.registerTab(items, blocks); ModFeatures.registerFeatures();
registerComposterItems();
registerLootTableChanges();
ModItemGroup.registerItemGroup(items, blocks);
PlayerBlockBreakEvents.AFTER.register((world, player, pos, state, blockEntity) -> {
Block oldBlock = state.getBlock();
new EventBlockBreak().doBreakBlock(world, pos, state, player, oldBlock);
});
} }
} }

View File

@@ -1,6 +1,9 @@
package de.jottyfan.quickiemod; package de.jottyfan.quickiemod;
import de.jottyfan.quickiemod.block.ModBlocks;
import net.fabricmc.api.ClientModInitializer; import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap;
import net.minecraft.client.render.RenderLayer;
/** /**
* *
@@ -11,6 +14,7 @@ public class QuickiemodClient implements ClientModInitializer {
@Override @Override
public void onInitializeClient() { public void onInitializeClient() {
BlockRenderLayerMap.INSTANCE.putBlock(ModBlocks.BLOCK_COTTONPLANT, RenderLayer.getCutout());
BlockRenderLayerMap.INSTANCE.putBlock(ModBlocks.BLOCK_CANOLAPLANT, RenderLayer.getCutout());
} }
} }

View File

@@ -17,4 +17,9 @@ public abstract class AbstractIdentifiedBlock extends Block {
super(AbstractBlock.Settings.create().registryKey(RegistryKey.of(RegistryKeys.BLOCK, identifier))); super(AbstractBlock.Settings.create().registryKey(RegistryKey.of(RegistryKeys.BLOCK, identifier)));
} }
public AbstractIdentifiedBlock(Identifier identifier, float strength, float hardness) {
super(AbstractBlock.Settings.create().strength(strength).hardness(hardness).requiresTool()
.registryKey(RegistryKey.of(RegistryKeys.BLOCK, identifier)));
}
} }

View File

@@ -0,0 +1,45 @@
package de.jottyfan.quickiemod.block;
import java.util.Arrays;
import java.util.List;
import com.mojang.serialization.MapCodec;
import net.minecraft.block.BlockState;
import net.minecraft.block.FallingBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.loot.context.LootWorldContext.Builder;
import net.minecraft.util.Identifier;
import net.minecraft.world.explosion.Explosion;
/**
*
* @author jotty
*
*/
public class BlockBreakByTool extends AbstractIdentifiedBlock {
private final ItemStack[] drops;
public BlockBreakByTool(Identifier identifier, float strength, float hardness, ItemStack[] drops) {
super(identifier, strength, hardness);
this.drops = drops;
}
@Override
public List<ItemStack> getDroppedStacks(BlockState state, Builder builder) {
return Arrays.asList(drops);
}
@Override
public boolean shouldDropItemsOnExplosion(Explosion explosion) {
return true;
}
@Override
protected MapCodec<? extends FallingBlock> getCodec() {
// TODO Auto-generated method stub
return null;
}
}

View File

@@ -0,0 +1,48 @@
package de.jottyfan.quickiemod.block;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
import com.mojang.serialization.MapCodec;
import de.jottyfan.quickiemod.item.ModItems;
import net.minecraft.block.AbstractBlock;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.FallingBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.loot.context.LootWorldContext.Builder;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.util.Identifier;
/**
*
* @author jotty
*
*/
public class BlockDirtSalpeter extends FallingBlock {
public BlockDirtSalpeter(Identifier identifier) {
super(AbstractBlock.Settings.create().hardness(3.1f).registryKey(RegistryKey.of(RegistryKeys.BLOCK, identifier)));
}
@Override
public List<ItemStack> getDroppedStacks(BlockState blockState, Builder builder) {
Integer count = (Double.valueOf(new Random().nextDouble() * 10).intValue() / 4) + 1;
boolean spawnBoneMeal = new Random().nextDouble() > 0.5f;
ItemStack boneMealStack = new ItemStack(Items.BONE_MEAL);
ItemStack salpeterStack = new ItemStack(ModItems.ITEM_SALPETER, count);
ItemStack dirtStack = new ItemStack(Blocks.DIRT);
ItemStack[] spawnies = spawnBoneMeal ? new ItemStack[] { boneMealStack, salpeterStack, dirtStack }
: new ItemStack[] { salpeterStack, dirtStack };
return Arrays.asList(spawnies);
}
@Override
protected MapCodec<? extends FallingBlock> getCodec() {
return null;
}
}

View File

@@ -0,0 +1,112 @@
package de.jottyfan.quickiemod.block;
import java.util.HashMap;
import java.util.Map;
import com.mojang.serialization.MapCodec;
import de.jottyfan.quickiemod.blockentity.DrillBlockEntity;
import de.jottyfan.quickiemod.item.ModItems;
import net.minecraft.block.AbstractBlock;
import net.minecraft.block.Block;
import net.minecraft.block.BlockEntityProvider;
import net.minecraft.block.BlockState;
import net.minecraft.block.FallingBlock;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.BlockEntityTicker;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.entity.ItemEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.state.StateManager.Builder;
import net.minecraft.state.property.EnumProperty;
import net.minecraft.state.property.IntProperty;
import net.minecraft.text.Text;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Identifier;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.World;
/**
*
* @author jotty
*
*/
public class BlockDrill extends FallingBlock implements BlockEntityProvider {
private static final Integer MAX_FUEL = 255;
public static final IntProperty FUEL = IntProperty.of("fuel", 0, MAX_FUEL);
public static final EnumProperty<Direction> DIRECTION = EnumProperty.of("direction", Direction.class, Direction.values());
public BlockDrill(Identifier identifier, Direction direction) {
super(AbstractBlock.Settings.create().hardness(2.5f).registryKey(RegistryKey.of(RegistryKeys.BLOCK, identifier)));
setDefaultState(getDefaultState().with(FUEL, 0).with(DIRECTION, direction));
}
@Override
public BlockEntity createBlockEntity(BlockPos pos, BlockState blockState) {
return new DrillBlockEntity(pos, blockState);
}
@Override
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(World world, BlockState state,
BlockEntityType<T> type) {
return (world1, pos, state1, be) -> DrillBlockEntity.tick(world1, pos, state1, be);
}
@Override
protected MapCodec<? extends FallingBlock> getCodec() {
// TODO Auto-generated method stub
return null;
}
@Override
public BlockState onBreak(World world, BlockPos pos, BlockState state, PlayerEntity player) {
Integer fuelLeft = state.get(FUEL);
world.spawnEntity(
new ItemEntity(world, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(ModItems.ITEM_CANOLABOTTLE, fuelLeft)));
return super.onBreak(world, pos, state, player);
}
@Override
protected void appendProperties(Builder<Block, BlockState> builder) {
builder.add(FUEL).add(DIRECTION);
}
@Override
protected ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, BlockHitResult hit) {
Map<Item, Integer> loadings = new HashMap<>();
loadings.put(ModItems.ITEM_CANOLABOTTLE, 8);
loadings.put(ModItems.ITEM_CANOLABOTTLESTACK, 72);
ItemStack stack = player.getStackInHand(player.getActiveHand());
Item item = stack.getItem();
if (stack.isEmpty() || !loadings.containsKey(item)) {
if (world.isClient()) {
player.sendMessage(Text.translatable("msg.drill.fuelinfo", state.get(FUEL)), false);
}
} else {
Integer fuelWeight = loadings.get(item);
if (fuelWeight != null) {
Integer load = MAX_FUEL - state.get(FUEL);
if (load < fuelWeight) {
fuelWeight = load;
}
world.setBlockState(pos, state.with(FUEL, state.get(FUEL) + fuelWeight));
if (item.equals(ModItems.ITEM_CANOLABOTTLE)) {
world.spawnEntity(
new ItemEntity(world, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(Items.GLASS_BOTTLE, 1)));
} else if (item.equals(ModItems.ITEM_CANOLABOTTLESTACK)) {
world.spawnEntity(
new ItemEntity(world, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(Items.GLASS_BOTTLE, 9)));
}
stack.decrement(1);
}
}
return ActionResult.PASS;
}
}

View File

@@ -0,0 +1,135 @@
package de.jottyfan.quickiemod.block;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Random;
import java.util.Set;
import net.minecraft.block.AbstractBlock;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.entity.ExperienceOrbEntity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.loot.context.LootWorldContext.Builder;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.tick.OrderedTick;
/**
*
* @author jotty
*
*/
public class BlockEmptyLavahoarder extends Block {
public BlockEmptyLavahoarder(Identifier identifier) {
super(AbstractBlock.Settings.create().hardness(2.5f).registryKey(RegistryKey.of(RegistryKeys.BLOCK, identifier)));
}
@Override
public List<ItemStack> getDroppedStacks(BlockState state, Builder builder) {
List<ItemStack> list = new ArrayList<>();
list.add(new ItemStack(ModBlocks.BLOCK_EMPTYLAVAHOARDER));
return list;
}
@Override
protected void scheduledTick(BlockState state, ServerWorld world, BlockPos pos,
net.minecraft.util.math.random.Random random) {
boolean found = BlockLavahoarder.suckLava(world, pos.north());
found = found || BlockLavahoarder.suckLava(world, pos.south());
found = found || BlockLavahoarder.suckLava(world, pos.east());
found = found || BlockLavahoarder.suckLava(world, pos.west());
found = found || BlockLavahoarder.suckLava(world, pos.up());
found = found || BlockLavahoarder.suckLava(world, pos.down());
if (found) {
world.setBlockState(pos, ModBlocks.BLOCK_LAVAHOARDER.getDefaultState());
world.getBlockTickScheduler().scheduleTick(OrderedTick.create(ModBlocks.BLOCK_LAVAHOARDER, pos));
} else {
world.getBlockTickScheduler().scheduleTick(OrderedTick.create(this, pos));
}
}
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());
}
if (amount > 0) {
world.setBlockState(pos, ModBlocks.BLOCK_LAVAHOARDER.getDefaultState());
world.getBlockTickScheduler().scheduleTick(OrderedTick.create(ModBlocks.BLOCK_LAVAHOARDER, pos));
int count = 0;
Random random = new Random();
for (int i = 0; i < amount; i++) {
if (random.nextFloat() < 0.0125) {
count++;
}
}
BlockPos up = pos.up();
if (count > 0) {
BlockLavahoarder.spawnRandomItems(world, up, count);
world.spawnEntity(new ExperienceOrbEntity(world, (double) pos.getX() + 0.5D, (double) pos.getY() + 0.5D,
(double) pos.getZ() + 0.5D, count));
}
} else {
world.getBlockTickScheduler().scheduleTick(OrderedTick.create(this, pos));
}
}
}

View File

@@ -0,0 +1,95 @@
package de.jottyfan.quickiemod.block;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import de.jottyfan.quickiemod.blockentity.ItemHoarderBlockEntity;
import net.minecraft.block.AbstractBlock;
import net.minecraft.block.Block;
import net.minecraft.block.BlockEntityProvider;
import net.minecraft.block.BlockRenderType;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.BlockEntityTicker;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.loot.context.LootWorldContext.Builder;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.text.Style;
import net.minecraft.text.Text;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Formatting;
import net.minecraft.util.Identifier;
import net.minecraft.util.ItemScatterer;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
/**
*
* @author jotty
*
*/
public class BlockItemhoarder extends Block implements BlockEntityProvider {
public BlockItemhoarder(Identifier identifier) {
super(AbstractBlock.Settings.create().hardness(2.5f).registryKey(RegistryKey.of(RegistryKeys.BLOCK, identifier)));
}
@Override
public BlockEntity createBlockEntity(BlockPos pos, BlockState blockState) {
return new ItemHoarderBlockEntity(pos, blockState);
}
@Override
public BlockRenderType getRenderType(BlockState state) {
return BlockRenderType.MODEL;
}
@Override
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(World world, BlockState state,
BlockEntityType<T> type) {
return (world1, pos, state1, be) -> ItemHoarderBlockEntity.tick(world1, pos, state1, be);
}
@Override
public List<ItemStack> getDroppedStacks(BlockState state, Builder builder) {
List<ItemStack> list = new ArrayList<>();
list.add(new ItemStack(ModBlocks.BLOCK_ITEMHOARDER));
return list;
}
@Override
public BlockState onBreak(World world, BlockPos pos, BlockState state, PlayerEntity player) {
BlockEntity blockEntity = world.getBlockEntity(pos);
if (blockEntity instanceof ItemHoarderBlockEntity) {
ItemHoarderBlockEntity ihbe = (ItemHoarderBlockEntity) blockEntity;
for (ItemStack stack : ihbe.getStacks()) {
ItemScatterer.spawn(world, pos.getX(), pos.getY(), pos.getZ(), stack);
}
}
return super.onBreak(world, pos, state, player);
}
@Override
protected ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, BlockHitResult hit) {
if (!world.isClient) {
BlockEntity blockEntity = world.getBlockEntity(pos);
if (blockEntity instanceof ItemHoarderBlockEntity) {
ItemHoarderBlockEntity ihbe = (ItemHoarderBlockEntity) blockEntity;
player.sendMessage(
Text.translatable("msg.itemhoarder.summary", new SimpleDateFormat("dd.MM.yyyy HH:mm:ss").format(new Date()))
.setStyle(Style.EMPTY.withColor(Formatting.BOLD)),
false);
for (Text text : ihbe.getSummary()) {
player.sendMessage(text, false);
}
}
}
return ActionResult.SUCCESS;
}
}

View File

@@ -0,0 +1,135 @@
package de.jottyfan.quickiemod.block;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import de.jottyfan.quickiemod.item.ModItems;
import net.minecraft.block.AbstractBlock;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
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.LootWorldContext.Builder;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.Identifier;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.tick.OrderedTick;
/**
*
* @author jotty
*
*/
public class BlockLavahoarder extends Block {
public BlockLavahoarder(Identifier identifier) {
super(AbstractBlock.Settings.create().hardness(2.5f).luminance(state -> 15)
.registryKey(RegistryKey.of(RegistryKeys.BLOCK, identifier)));
}
@Override
public List<ItemStack> getDroppedStacks(BlockState state, Builder builder) {
List<ItemStack> list = new ArrayList<>();
list.add(new ItemStack(ModBlocks.BLOCK_LAVAHOARDER));
return list;
}
public static final void spawnRandomItems(World world, BlockPos pos, Integer count) {
Integer which = new Random().nextInt(10);
if (which < 1) {
world.spawnEntity(new ItemEntity(world, pos.getX(), pos.getY(), pos.getZ(),
new ItemStack(Items.DIAMOND, new Random().nextInt(count + 2))));
} else if (which < 2) {
world.spawnEntity(new ItemEntity(world, pos.getX(), pos.getY(), pos.getZ(),
new ItemStack(Items.EMERALD, new Random().nextInt(count + 1))));
} else if (which < 3) {
world.spawnEntity(new ItemEntity(world, pos.getX(), pos.getY(), pos.getZ(),
new ItemStack(Items.RAW_GOLD, new Random().nextInt(count))));
} else if (which < 4) {
world.spawnEntity(new ItemEntity(world, pos.getX(), pos.getY(), pos.getZ(),
new ItemStack(Items.RAW_IRON, new Random().nextInt(count + 1))));
} else if (which < 5) {
world.spawnEntity(new ItemEntity(world, pos.getX(), pos.getY(), pos.getZ(),
new ItemStack(Items.RAW_COPPER, new Random().nextInt(count + 2))));
} else if (which < 6) {
world.spawnEntity(new ItemEntity(world, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(Items.OBSIDIAN)));
} else if (which < 7) {
world.spawnEntity(new ItemEntity(world, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(Items.LAPIS_LAZULI)));
} else if (which < 8) {
world.spawnEntity(new ItemEntity(world, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(ModItems.ITEM_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(World world, BlockPos pos) {
if (world == null) {
return false;
} else if (Blocks.LAVA.equals(world.getBlockState(pos).getBlock())) {
world.setBlockState(pos, Blocks.AIR.getDefaultState());
BlockPos up = pos.up();
Random random = new Random();
if (random.nextFloat() > 0.9f) {
spawnRandomItems(world, up, 2);
}
return true;
}
return false;
}
@Override
protected void scheduledTick(BlockState state, ServerWorld world, BlockPos pos,
net.minecraft.util.math.random.Random random) {
suckLava(world, pos.north());
suckLava(world, pos.south());
suckLava(world, pos.east());
suckLava(world, pos.west());
suckLava(world, pos.up());
suckLava(world, pos.down());
world.getBlockTickScheduler().scheduleTick(OrderedTick.create(this, pos));
}
@Override
protected ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, BlockHitResult hit) {
if (!world.isClient) {
Hand hand = player.getActiveHand();
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);
if (emptyBucketStack.getCount() < 1) {
player.setStackInHand(hand, lavaBucketStack);
} else {
player.setStackInHand(hand, emptyBucketStack);
world.spawnEntity(new ItemEntity(world, pos.getX(), pos.getY(), pos.getZ(), lavaBucketStack));
}
spawnRandomItems(world, pos, 2);
world.setBlockState(pos, ModBlocks.BLOCK_EMPTYLAVAHOARDER.getDefaultState());
world.getBlockTickScheduler().scheduleTick(OrderedTick.create(ModBlocks.BLOCK_EMPTYLAVAHOARDER, pos));
}
}
return ActionResult.SUCCESS; // forbid to empty the just filled lava bucket
}
@Override
public void onPlaced(World world, BlockPos pos, BlockState state, LivingEntity placer, ItemStack itemStack) {
world.getBlockTickScheduler().scheduleTick(OrderedTick.create(this, pos));
}
}

View File

@@ -0,0 +1,89 @@
package de.jottyfan.quickiemod.block;
import java.util.List;
import net.minecraft.block.AbstractBlock;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.mob.HostileEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvents;
import net.minecraft.state.StateManager.Builder;
import net.minecraft.state.property.IntProperty;
import net.minecraft.text.Text;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Identifier;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Box;
import net.minecraft.util.math.random.Random;
import net.minecraft.world.World;
import net.minecraft.world.tick.OrderedTick;
/**
*
* @author jotty
*
*/
public class BlockMonsterhoarder extends Block {
private static final IntProperty SUCKRADIUS = IntProperty.of("suckradius", 1, 15);
public BlockMonsterhoarder(Identifier identifier) {
super(AbstractBlock.Settings.create().hardness(2.5f).luminance(state -> state.get(BlockMonsterhoarder.SUCKRADIUS))
.registryKey(RegistryKey.of(RegistryKeys.BLOCK, identifier)));
setDefaultState(getDefaultState().with(SUCKRADIUS, 8));
}
@Override
protected void appendProperties(Builder<Block, BlockState> builder) {
builder.add(SUCKRADIUS);
super.appendProperties(builder);
}
@Override
protected ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, BlockHitResult hit) {
if (!world.isClient()) {
world.setBlockState(pos, state.cycle(SUCKRADIUS));
} else {
player.sendMessage(Text.translatable("msg.monsterhoarder.size", state.get(SUCKRADIUS)), false);
}
return ActionResult.SUCCESS;
}
@Override
protected void scheduledTick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
if (!world.isClient) {
Box box = new Box(pos).expand(Double.valueOf(state.get(SUCKRADIUS)));
List<Entity> entities = world.getOtherEntities(null, box);
for (Entity entity : entities) {
if (entity instanceof HostileEntity hostile) {
if (hostile.isFireImmune()) {
if (world instanceof ServerWorld serverWorld) {
hostile.kill(serverWorld);
}
} else {
hostile.setOnFireFor(90);
}
}
}
}
world.getBlockTickScheduler().scheduleTick(OrderedTick.create(this, pos));
}
@Override
public void onPlaced(World world, BlockPos pos, BlockState state, LivingEntity placer, ItemStack itemStack) {
if (!world.isClient) {
world.getBlockTickScheduler().scheduleTick(OrderedTick.create(this, pos));
world.playSound(null, pos, SoundEvents.UI_TOAST_CHALLENGE_COMPLETE, SoundCategory.PLAYERS, 1f, 1f);
}
super.onPlaced(world, pos, state, placer, itemStack);
}
}

View File

@@ -0,0 +1,33 @@
package de.jottyfan.quickiemod.block;
import java.util.Arrays;
import java.util.List;
import de.jottyfan.quickiemod.block.help.IntProviderHelper;
import de.jottyfan.quickiemod.item.ModItems;
import net.minecraft.block.BlockState;
import net.minecraft.block.ExperienceDroppingBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.loot.context.LootWorldContext.Builder;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.util.Identifier;
/**
*
* @author jotty
*
*/
public class BlockOreDeepslateSulphor extends ExperienceDroppingBlock {
public BlockOreDeepslateSulphor(Identifier identifier) {
super(IntProviderHelper.of(0, 2), Settings.create().strength(2.5f).hardness(1.9f).sounds(BlockSoundGroup.SOUL_SAND)
.requiresTool().registryKey(RegistryKey.of(RegistryKeys.BLOCK, identifier)));
}
@Override
public List<ItemStack> getDroppedStacks(BlockState state, Builder builder) {
return Arrays.asList(new ItemStack[] { new ItemStack(ModItems.ITEM_SULFOR, 4) });
}
}

View File

@@ -0,0 +1,33 @@
package de.jottyfan.quickiemod.block;
import java.util.Arrays;
import java.util.List;
import de.jottyfan.quickiemod.block.help.IntProviderHelper;
import de.jottyfan.quickiemod.item.ModItems;
import net.minecraft.block.BlockState;
import net.minecraft.block.ExperienceDroppingBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.loot.context.LootWorldContext.Builder;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.util.Identifier;
/**
*
* @author jotty
*
*/
public class BlockOreNetherSulphor extends ExperienceDroppingBlock {
public BlockOreNetherSulphor(Identifier identifier) {
super(IntProviderHelper.of(0, 2), Settings.create().strength(2.5f).hardness(2.1f).sounds(BlockSoundGroup.SOUL_SAND)
.requiresTool().registryKey(RegistryKey.of(RegistryKeys.BLOCK, identifier)));
}
@Override
public List<ItemStack> getDroppedStacks(BlockState state, Builder builder) {
return Arrays.asList(new ItemStack[] { new ItemStack(ModItems.ITEM_SULFOR) });
}
}

View File

@@ -0,0 +1,34 @@
package de.jottyfan.quickiemod.block;
import java.util.Arrays;
import java.util.List;
import de.jottyfan.quickiemod.block.help.IntProviderHelper;
import de.jottyfan.quickiemod.item.ModItems;
import net.minecraft.block.BlockState;
import net.minecraft.block.ExperienceDroppingBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.loot.context.LootWorldContext.Builder;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.random.Random;
/**
*
* @author jotty
*
*/
public class BlockOreSalpeter extends ExperienceDroppingBlock {
public BlockOreSalpeter(Identifier identifier) {
super(IntProviderHelper.of(0, 2), Settings.create().strength(2.5f).hardness(3.1f).sounds(BlockSoundGroup.SOUL_SAND)
.requiresTool().registryKey(RegistryKey.of(RegistryKeys.BLOCK, identifier)));
}
@Override
public List<ItemStack> getDroppedStacks(BlockState state, Builder builder) {
return Arrays.asList(new ItemStack[] { new ItemStack(ModItems.ITEM_SALPETER, 2 + Random.create().nextInt(3)) });
}
}

View File

@@ -0,0 +1,34 @@
package de.jottyfan.quickiemod.block;
import java.util.Arrays;
import java.util.List;
import de.jottyfan.quickiemod.block.help.IntProviderHelper;
import de.jottyfan.quickiemod.item.ModItems;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.ExperienceDroppingBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.loot.context.LootWorldContext.Builder;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.random.Random;
/**
*
* @author jotty
*
*/
public class BlockOreSandSalpeter extends ExperienceDroppingBlock {
public BlockOreSandSalpeter(Identifier identifier) {
super(IntProviderHelper.of(0, 2), Settings.create().strength(2.5f).hardness(2.9f).sounds(BlockSoundGroup.SOUL_SAND).requiresTool().registryKey(RegistryKey.of(RegistryKeys.BLOCK, identifier)));
}
@Override
public List<ItemStack> getDroppedStacks(BlockState state, Builder builder) {
return Arrays.asList(new ItemStack[] { new ItemStack(ModItems.ITEM_SALPETER, 7 + Random.create().nextInt(4)), new ItemStack(Blocks.SAND) });
}
}

View File

@@ -0,0 +1,33 @@
package de.jottyfan.quickiemod.block;
import java.util.Arrays;
import java.util.List;
import de.jottyfan.quickiemod.block.help.IntProviderHelper;
import de.jottyfan.quickiemod.item.ModItems;
import net.minecraft.block.BlockState;
import net.minecraft.block.ExperienceDroppingBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.loot.context.LootWorldContext.Builder;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.util.Identifier;
/**
*
* @author jotty
*
*/
public class BlockOreSulphor extends ExperienceDroppingBlock {
public BlockOreSulphor(Identifier identifier) {
super(IntProviderHelper.of(0, 2), Settings.create().strength(2.5f).hardness(1.9f).sounds(BlockSoundGroup.SOUL_SAND)
.requiresTool().registryKey(RegistryKey.of(RegistryKeys.BLOCK, identifier)));
}
@Override
public List<ItemStack> getDroppedStacks(BlockState state, Builder builder) {
return Arrays.asList(new ItemStack[] { new ItemStack(ModItems.ITEM_SULFOR) });
}
}

View File

@@ -0,0 +1,79 @@
package de.jottyfan.quickiemod.block;
import java.util.List;
import java.util.Random;
import net.minecraft.block.AbstractBlock;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.CropBlock;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemConvertible;
import net.minecraft.item.ItemStack;
import net.minecraft.loot.context.LootWorldContext.Builder;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Identifier;
import net.minecraft.util.ItemScatterer;
import net.minecraft.util.collection.DefaultedList;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
/**
*
* @author jotty
*
*/
public class BlockPlant extends CropBlock {
private Item seed;
private Item fruit;
public BlockPlant(Identifier identifier, Item seed, Item fruit) {
super(AbstractBlock.Settings.copy(Blocks.WHEAT).registryKey(RegistryKey.of(RegistryKeys.BLOCK, identifier)));
this.seed = seed;
this.fruit = fruit;
}
@Override
public List<ItemStack> getDroppedStacks(BlockState state, Builder builder) {
DefaultedList<ItemStack> list = DefaultedList.of();
list.add(new ItemStack(getSeedsItem())); // the one from the seed
if (isMature(state)) {
list.add(new ItemStack(getSeedsItem(), new Random().nextInt(2)));
list.add(new ItemStack(fruit, new Random().nextFloat() > 0.9f ? 2 : 1));
}
return list;
}
private void spawnHarvested(World world, BlockPos pos, BlockState state) {
DefaultedList<ItemStack> list = DefaultedList.of();
getDroppedStacks(state, null).forEach(itemStack -> {
list.add(itemStack);
});
ItemScatterer.spawn(world, pos, list);
}
@Override
public BlockState onBreak(World world, BlockPos pos, BlockState state, PlayerEntity player) {
spawnHarvested(world, pos, state);
return super.onBreak(world, pos, state, player);
}
@Override
protected ItemConvertible getSeedsItem() {
return seed;
}
@Override
protected ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, BlockHitResult hit) {
if (!world.isClient && isMature(state)) {
spawnHarvested(world, pos, state);
world.setBlockState(pos, state.with(AGE, 0));
}
return ActionResult.PASS;
}
}

View File

@@ -0,0 +1,43 @@
package de.jottyfan.quickiemod.block;
import java.util.Arrays;
import java.util.List;
import com.mojang.serialization.MapCodec;
import de.jottyfan.quickiemod.item.ModItems;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.FallingBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.loot.context.LootWorldContext.Builder;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.random.Random;
/**
*
* @author jotty
*
*/
public class BlockSandSalpeter extends FallingBlock {
public BlockSandSalpeter(Identifier identifier) {
super(Settings.create().strength(2.5f).hardness(3.1f).sounds(BlockSoundGroup.SOUL_SAND).requiresTool()
.registryKey(RegistryKey.of(RegistryKeys.BLOCK, identifier)));
}
@Override
public List<ItemStack> getDroppedStacks(BlockState state, Builder builder) {
return Arrays.asList(new ItemStack[] { new ItemStack(ModItems.ITEM_SALPETER, 3 + Random.create().nextInt(2)),
new ItemStack(Blocks.SAND) });
}
@Override
protected MapCodec<? extends FallingBlock> getCodec() {
// TODO Auto-generated method stub
return null;
}
}

View File

@@ -0,0 +1,22 @@
package de.jottyfan.quickiemod.block;
import net.minecraft.block.AbstractBlock;
import net.minecraft.block.Block;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.util.Identifier;
/**
*
* @author jotty
*
*/
public class BlockSlippery extends Block {
public BlockSlippery(Identifier identifier, float hardness, float slipperiness, BlockSoundGroup soundGroup) {
super(AbstractBlock.Settings.create().hardness(hardness).slipperiness(slipperiness).breakInstantly()
.sounds(soundGroup).registryKey(RegistryKey.of(RegistryKeys.BLOCK, identifier)));
}
}

View File

@@ -0,0 +1,117 @@
package de.jottyfan.quickiemod.block;
import com.mojang.serialization.MapCodec;
import de.jottyfan.quickiemod.blockentity.BlockStackerEntity;
import de.jottyfan.quickiemod.blockentity.ModBlockentity;
import net.minecraft.block.AbstractBlock;
import net.minecraft.block.BlockEntityProvider;
import net.minecraft.block.BlockRenderType;
import net.minecraft.block.BlockState;
import net.minecraft.block.BlockWithEntity;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.BlockEntityTicker;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.screen.ScreenHandler;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Identifier;
import net.minecraft.util.ItemScatterer;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.World;
/**
*
* @author jotty
*
*/
public class BlockStacker extends BlockWithEntity implements BlockEntityProvider {
private final Direction source;
private final Direction dest;
public BlockStacker(Identifier identifier, Direction source, Direction dest) {
super(AbstractBlock.Settings.create().hardness(2.5f).registryKey(RegistryKey.of(RegistryKeys.BLOCK, identifier)));
this.source = source;
this.dest = dest;
}
@Override
public BlockRenderType getRenderType(BlockState state) {
return BlockRenderType.MODEL;
}
/**
* define the source offset
*
* @return the direction of the source offset (1 block beside)
*/
public Direction getSourceOffset() {
return source;
}
/**
* define the dest offset
*
* @return the direction of the dest offset (1 block beside)
*/
public Direction getDestOffset() {
return dest;
}
@Override
public BlockEntity createBlockEntity(BlockPos pos, BlockState state) {
return new BlockStackerEntity(pos, state);
}
@Override
protected MapCodec<? extends BlockWithEntity> getCodec() {
// TODO Auto-generated method stub
return null;
}
@Override
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(World world, BlockState state,
BlockEntityType<T> type) {
return validateTicker(type, ModBlockentity.BLOCKSTACKER_BLOCKENTITY,
(world1, pos, state1, be) -> BlockStackerEntity.tick(world1, pos, state1, be));
}
@Override
protected ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, BlockHitResult hit) {
// if (!world.isClient) {
// NamedScreenHandlerFactory screenHandlerFactory = state.createScreenHandlerFactory(world, pos);
// if (screenHandlerFactory != null) {
// player.openHandledScreen(screenHandlerFactory);
// }
// }
return ActionResult.SUCCESS;
}
@Override
public void onStateReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean moved) {
if (state.getBlock() != newState.getBlock()) {
BlockEntity blockEntity = world.getBlockEntity(pos);
if (blockEntity instanceof BlockStackerEntity) {
ItemScatterer.spawn(world, pos, (BlockStackerEntity) blockEntity);
// update comparators
world.updateComparators(pos, this);
}
super.onStateReplaced(state, world, pos, newState, moved);
}
}
@Override
public boolean hasComparatorOutput(BlockState state) {
return true;
}
@Override
public int getComparatorOutput(BlockState state, World world, BlockPos pos) {
return ScreenHandler.calculateComparatorOutput(world.getBlockEntity(pos));
}
}

View File

@@ -14,7 +14,9 @@ import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry; import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKey; import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys; import net.minecraft.registry.RegistryKeys;
import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import net.minecraft.util.math.Direction;
/** /**
* *
@@ -27,10 +29,70 @@ public class ModBlocks {
ModIdentifiers.BLOCK_QUICKIEPOWDER, new ItemStack[] { new ItemStack(ModItems.ITEM_QUICKIEPOWDER, 9) })); ModIdentifiers.BLOCK_QUICKIEPOWDER, new ItemStack[] { new ItemStack(ModItems.ITEM_QUICKIEPOWDER, 9) }));
public static final Block BLOCK_SPEEDPOWDER = registerBlock(ModIdentifiers.BLOCK_SPEEDPOWDER, new BlockPowder( public static final Block BLOCK_SPEEDPOWDER = registerBlock(ModIdentifiers.BLOCK_SPEEDPOWDER, new BlockPowder(
ModIdentifiers.BLOCK_SPEEDPOWDER, new ItemStack[] { new ItemStack(ModItems.ITEM_SPEEDPOWDER, 9) })); ModIdentifiers.BLOCK_SPEEDPOWDER, new ItemStack[] { new ItemStack(ModItems.ITEM_SPEEDPOWDER, 9) }));
public static final Block BLOCK_SALPETER = registerBlock(ModIdentifiers.BLOCK_SALPETER, new BlockBreakByTool(
ModIdentifiers.BLOCK_SALPETER, 1.5f, 1.5f, new ItemStack[] { new ItemStack(ModItems.ITEM_SALPETER, 9) }));
public static final Block BLOCK_SULFOR = registerBlock(ModIdentifiers.BLOCK_SULFOR, new BlockBreakByTool(
ModIdentifiers.BLOCK_SULFOR, 1.5f, 1.5f, new ItemStack[] { new ItemStack(ModItems.ITEM_SULFOR, 9) }));
public static final Block BLOCK_MONSTERHOARDER = registerBlock(ModIdentifiers.BLOCK_MONSTERHOARDER,
new BlockMonsterhoarder(ModIdentifiers.BLOCK_MONSTERHOARDER));
public static final Block BLOCK_LAVAHOARDER = registerBlock(ModIdentifiers.BLOCK_LAVAHOARDER,
new BlockLavahoarder(ModIdentifiers.BLOCK_LAVAHOARDER));
public static final Block BLOCK_EMPTYLAVAHOARDER = registerBlock(ModIdentifiers.BLOCK_EMPTYLAVAHOARDER,
new BlockEmptyLavahoarder(ModIdentifiers.BLOCK_EMPTYLAVAHOARDER));
public static final Block BLOCK_ITEMHOARDER = registerBlock(ModIdentifiers.BLOCK_ITEMHOARDER,
new BlockItemhoarder(ModIdentifiers.BLOCK_ITEMHOARDER));
public static final Block BLOCK_DIRTSALPETER = registerBlock(ModIdentifiers.BLOCK_DIRTSALPETER,
new BlockDirtSalpeter(ModIdentifiers.BLOCK_DIRTSALPETER));
public static final Block BLOCK_OREDEEPSLATESULFOR = registerBlock(ModIdentifiers.BLOCK_OREDEEPSLATESULFOR,
new BlockOreDeepslateSulphor(ModIdentifiers.BLOCK_OREDEEPSLATESULFOR));
public static final Block BLOCK_ORENETHERSULFOR = registerBlock(ModIdentifiers.BLOCK_ORENETHERSULFOR,
new BlockOreNetherSulphor(ModIdentifiers.BLOCK_ORENETHERSULFOR));
public static final Block BLOCK_ORESALPETER = registerBlock(ModIdentifiers.BLOCK_ORESALPETER,
new BlockOreSalpeter(ModIdentifiers.BLOCK_ORESALPETER));
public static final Block BLOCK_ORESANDSALPETER = registerBlock(ModIdentifiers.BLOCK_ORESANDSALPETER,
new BlockOreSandSalpeter(ModIdentifiers.BLOCK_ORESANDSALPETER));
public static final Block BLOCK_ORESULFOR = registerBlock(ModIdentifiers.BLOCK_ORESULFOR,
new BlockOreSulphor(ModIdentifiers.BLOCK_ORESULFOR));
public static final Block BLOCK_SANDSALPETER = registerBlock(ModIdentifiers.BLOCK_SANDSALPETER,
new BlockSandSalpeter(ModIdentifiers.BLOCK_SANDSALPETER));
public static final Block BLOCK_KELPSTACK = registerBlock(ModIdentifiers.BLOCK_KELPSTACK,
new BlockSlippery(ModIdentifiers.BLOCK_KELPSTACK, 0.1f, 1.0f, BlockSoundGroup.WET_GRASS));
public static final Block BLOCK_COTTONPLANT = registerBlock(ModIdentifiers.BLOCK_COTTONPLANT,
new BlockPlant(ModIdentifiers.BLOCK_COTTONPLANT, ModItems.ITEM_COTTONSEED, ModItems.ITEM_COTTON), false);
public static final Block BLOCK_CANOLAPLANT = registerBlock(ModIdentifiers.BLOCK_CANOLAPLANT,
new BlockPlant(ModIdentifiers.BLOCK_CANOLAPLANT, ModItems.ITEM_CANOLASEED, ModItems.ITEM_CANOLA), false);
public static final Block BLOCK_DRILL_DOWN = registerBlock(ModIdentifiers.BLOCK_DRILLDOWN,
new BlockDrill(ModIdentifiers.BLOCK_DRILLDOWN, Direction.DOWN));
public static final Block BLOCK_DRILL_EAST = registerBlock(ModIdentifiers.BLOCK_DRILLEAST,
new BlockDrill(ModIdentifiers.BLOCK_DRILLEAST, Direction.EAST));
public static final Block BLOCK_DRILL_SOUTH = registerBlock(ModIdentifiers.BLOCK_DRILLSOUTH,
new BlockDrill(ModIdentifiers.BLOCK_DRILLSOUTH, Direction.SOUTH));
public static final Block BLOCK_DRILL_WEST = registerBlock(ModIdentifiers.BLOCK_DRILLWEST,
new BlockDrill(ModIdentifiers.BLOCK_DRILLWEST, Direction.WEST));
public static final Block BLOCK_DRILL_NORTH = registerBlock(ModIdentifiers.BLOCK_DRILLNORTH,
new BlockDrill(ModIdentifiers.BLOCK_DRILLNORTH, Direction.NORTH));
public static final Block BLOCK_STACKER_DOWN = registerBlock(ModIdentifiers.BLOCK_STACKERDOWN,
new BlockStacker(ModIdentifiers.BLOCK_STACKERDOWN, Direction.UP, Direction.DOWN));
public static final Block BLOCK_STACKER_EAST = registerBlock(ModIdentifiers.BLOCK_STACKEREAST,
new BlockStacker(ModIdentifiers.BLOCK_STACKEREAST, Direction.WEST, Direction.EAST));
public static final Block BLOCK_STACKER_SOUTH = registerBlock(ModIdentifiers.BLOCK_STACKERSOUTH,
new BlockStacker(ModIdentifiers.BLOCK_STACKERSOUTH, Direction.NORTH, Direction.SOUTH));
public static final Block BLOCK_STACKER_WEST = registerBlock(ModIdentifiers.BLOCK_STACKERWEST,
new BlockStacker(ModIdentifiers.BLOCK_STACKERWEST, Direction.EAST, Direction.WEST));
public static final Block BLOCK_STACKER_NORTH = registerBlock(ModIdentifiers.BLOCK_STACKERNORTH,
new BlockStacker(ModIdentifiers.BLOCK_STACKERNORTH, Direction.SOUTH, Direction.NORTH));
public static final Block BLOCK_STACKER_UP = registerBlock(ModIdentifiers.BLOCK_STACKERUP,
new BlockStacker(ModIdentifiers.BLOCK_STACKERUP, Direction.DOWN, Direction.UP));
private static final Block registerBlock(Identifier identifier, Block block) { private static final Block registerBlock(Identifier identifier, Block block) {
return registerBlock(identifier, block, true);
}
private static final Block registerBlock(Identifier identifier, Block block, boolean registerAsItem) {
if (registerAsItem) {
Registry.register(Registries.ITEM, identifier, new BlockItem(block, new Item.Settings() Registry.register(Registries.ITEM, identifier, new BlockItem(block, new Item.Settings()
.registryKey(RegistryKey.of(RegistryKeys.ITEM, identifier)).useBlockPrefixedTranslationKey())); .registryKey(RegistryKey.of(RegistryKeys.ITEM, identifier)).useBlockPrefixedTranslationKey()));
}
return Registry.register(Registries.BLOCK, identifier, block); return Registry.register(Registries.BLOCK, identifier, block);
} }
@@ -40,6 +102,31 @@ public class ModBlocks {
List<Block> blocks = new ArrayList<>(); List<Block> blocks = new ArrayList<>();
blocks.add(BLOCK_QUICKIEPOWDER); blocks.add(BLOCK_QUICKIEPOWDER);
blocks.add(BLOCK_SPEEDPOWDER); blocks.add(BLOCK_SPEEDPOWDER);
blocks.add(BLOCK_SALPETER);
blocks.add(BLOCK_SULFOR);
blocks.add(BLOCK_MONSTERHOARDER);
blocks.add(BLOCK_EMPTYLAVAHOARDER);
blocks.add(BLOCK_LAVAHOARDER);
blocks.add(BLOCK_ITEMHOARDER);
blocks.add(BLOCK_DIRTSALPETER);
blocks.add(BLOCK_OREDEEPSLATESULFOR);
blocks.add(BLOCK_ORENETHERSULFOR);
blocks.add(BLOCK_ORESALPETER);
blocks.add(BLOCK_ORESANDSALPETER);
blocks.add(BLOCK_ORESULFOR);
blocks.add(BLOCK_SANDSALPETER);
blocks.add(BLOCK_KELPSTACK);
blocks.add(BLOCK_DRILL_DOWN);
blocks.add(BLOCK_DRILL_EAST);
blocks.add(BLOCK_DRILL_SOUTH);
blocks.add(BLOCK_DRILL_WEST);
blocks.add(BLOCK_DRILL_NORTH);
blocks.add(BLOCK_STACKER_DOWN);
blocks.add(BLOCK_STACKER_EAST);
blocks.add(BLOCK_STACKER_SOUTH);
blocks.add(BLOCK_STACKER_WEST);
blocks.add(BLOCK_STACKER_NORTH);
blocks.add(BLOCK_STACKER_UP);
return blocks; return blocks;
} }
} }

View File

@@ -0,0 +1,37 @@
package de.jottyfan.quickiemod.block.help;
import net.minecraft.util.math.intprovider.IntProvider;
import net.minecraft.util.math.intprovider.IntProviderType;
import net.minecraft.util.math.random.Random;
/**
*
* @author jotty
*
*/
public class IntProviderHelper {
public static final IntProvider of(Integer min, Integer max) {
return new IntProvider() {
@Override
public IntProviderType<?> getType() {
return IntProviderType.CONSTANT;
}
@Override
public int getMin() {
return min;
}
@Override
public int getMax() {
return max;
}
@Override
public int get(Random random) {
return random.nextBetween(min, max);
}
};
}
}

View File

@@ -0,0 +1,261 @@
package de.jottyfan.quickiemod.blockentity;
import java.util.ArrayList;
import java.util.List;
import de.jottyfan.quickiemod.Quickiemod;
import de.jottyfan.quickiemod.block.BlockStacker;
import de.jottyfan.quickiemod.container.BlockStackerScreenHandler;
import de.jottyfan.quickiemod.container.ImplementedInventory;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.LootableContainerBlockEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.Inventories;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.registry.RegistryWrapper.WrapperLookup;
import net.minecraft.screen.NamedScreenHandlerFactory;
import net.minecraft.screen.ScreenHandler;
import net.minecraft.text.Text;
import net.minecraft.util.collection.DefaultedList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
/**
*
* @author jotty
*
*/
public class BlockStackerEntity extends BlockEntity implements NamedScreenHandlerFactory, ImplementedInventory {
private final DefaultedList<ItemStack> inventory = DefaultedList.ofSize(BlockStackerScreenHandler.SLOTSIZE, ItemStack.EMPTY);
public BlockStackerEntity(BlockPos blockPos, BlockState blockState) {
super(ModBlockentity.BLOCKSTACKER_BLOCKENTITY, blockPos, blockState);
}
@Override
public DefaultedList<ItemStack> getItems() {
return inventory;
}
public List<ItemStack> getWhiteList() {
int counter = 0;
List<ItemStack> list = new ArrayList<>();
for (ItemStack stack : inventory) {
counter++;
if (counter < 10) { // first 9 items are whitelist items
list.add(stack);
}
}
return list;
}
public List<ItemStack> getBlackList() {
int counter = 0;
List<ItemStack> list = new ArrayList<>();
for (ItemStack stack : inventory) {
counter++;
if (counter > 9) { // second 9 items are blacklist items
list.add(stack);
}
}
return list;
}
@Override
public ScreenHandler createMenu(int syncId, PlayerInventory playerInventory, PlayerEntity player) {
return new BlockStackerScreenHandler(syncId, playerInventory, this);
}
@Override
public Text getDisplayName() {
return Text.translatable(getCachedState().getBlock().getTranslationKey());
}
@Override
protected void readNbt(NbtCompound nbt, WrapperLookup registryLookup) {
super.readNbt(nbt, registryLookup);
Inventories.readNbt(nbt, inventory, registryLookup);
}
@Override
protected void writeNbt(NbtCompound nbt, WrapperLookup registryLookup) {
Inventories.writeNbt(nbt, inventory, registryLookup);
super.writeNbt(nbt, registryLookup);
}
/**
* if whitelist, return true if current == pattern; return false otherwise
*
* @param current the current item stack
* @param pattern the item stack to compare with
* @param whitelist if true, filter only current == pattern, if false, filter
* all but that
* @return true or false
*/
public static final Boolean filter(ItemStack current, ItemStack pattern, Boolean whitelist) {
Boolean matches = pattern.getItem().equals(current.getItem());
return whitelist ? matches : !matches;
}
public static void tick(World world, BlockPos pos, BlockState state, BlockStackerEntity entity) {
if (!world.isClient) {
pos.down();
BlockStacker block = (BlockStacker) state.getBlock();
BlockEntity source = world.getBlockEntity(pos.offset(block.getSourceOffset()));
BlockEntity dest = world.getBlockEntity(pos.offset(block.getDestOffset()));
Boolean sourceIsLootable = source instanceof LootableContainerBlockEntity;
Boolean destIsLootable = dest instanceof LootableContainerBlockEntity;
if (sourceIsLootable && destIsLootable) {
LootableContainerBlockEntity lootableSource = (LootableContainerBlockEntity) source;
LootableContainerBlockEntity lootableDest = (LootableContainerBlockEntity) dest;
transferOneStack(lootableSource, lootableDest, entity.getWhiteList(), entity.getBlackList());
}
}
}
private static final Boolean transferOneStack(LootableContainerBlockEntity source, LootableContainerBlockEntity dest, List<ItemStack> whiteList, List<ItemStack> blackList) {
// whitelist behaviour
List<Item> checked = new ArrayList<>();
// this way, we block whitelist items that are in the blacklist
for (ItemStack stack : blackList) {
if (stack != null && !stack.isEmpty()) {
checked.add(stack.getItem());
}
}
Boolean found = false;
if (hasItems(whiteList)) {
Item matchItem = findNextItem(whiteList, checked);
while(!found && matchItem != null) {
checked.add(matchItem);
List<Item> matchItems = new ArrayList<>();
matchItems.add(matchItem);
found = transferOneStack(source, dest, matchItems, true);
matchItem = findNextItem(whiteList, checked);
}
} else {
// transport all but the items of the blacklist
found = transferOneStack(source, dest, checked, false);
}
return found;
}
private static final Boolean transferOneStack(LootableContainerBlockEntity source, LootableContainerBlockEntity dest,
List<Item> ignoreItems, Boolean whitelist) {
Boolean result = false;
Integer sourceSlot = findItemStackPos(source, ignoreItems, whitelist);
if (sourceSlot != null && !Items.AIR.equals(source.getStack(sourceSlot).getItem())) {
ItemStack sourceStack = source.getStack(sourceSlot);
Integer destSlot = findItemStackPos(dest, sourceStack);
if (destSlot != null) {
Integer occupied = dest.getStack(destSlot).getCount();
Integer free = dest.getStack(destSlot).getMaxCount() - occupied;
Integer candidates = source.getStack(sourceSlot).getCount();
Integer travellers = candidates > free ? free : candidates;
if (travellers > 0) {
Quickiemod.LOGGER.debug("transfer {}/{} of {} from slot {} to slot {} on top of {} ones", travellers, candidates,
source.getStack(sourceSlot).getItem().toString(), sourceSlot, destSlot, occupied);
source.getStack(sourceSlot).decrement(travellers);
if (source.getStack(sourceSlot).getCount() < 1) {
source.removeStack(sourceSlot); // make empty slots really empty
}
dest.getStack(destSlot).increment(travellers);
result = true;
}
} else {
Integer destFreeSlot = findItemStackPos(dest, true);
if (destFreeSlot != null) {
Quickiemod.LOGGER.debug("transfer all of {} from slot {} to slot {}", source.getStack(sourceSlot).getItem().toString(),
sourceSlot, destSlot);
dest.setStack(destFreeSlot, source.removeStack(sourceSlot));
result = true;
}
}
}
return result;
}
private static final Boolean hasItems(List<ItemStack> list) {
Boolean result = false;
for (ItemStack stack : list) {
result = result || (stack != null && !stack.isEmpty() && stack.getCount() > 0);
}
return result;
}
private static final Item findNextItem(List<ItemStack> inventory, List<Item> exclude) {
for (ItemStack stack : inventory) {
if (!stack.isEmpty()) {
Item item = stack.getItem();
if (!exclude.contains(item)) {
return item;
}
}
}
return null;
}
private static final Integer findItemStackPos(LootableContainerBlockEntity lcbe, ItemStack sourceStack) {
Integer counter = lcbe.size();
while (counter > 0) {
counter--;
ItemStack stack = lcbe.getStack(counter);
if (sourceStack.getItem().equals(stack.getItem())) {
if (stack.getCount() < stack.getMaxCount()) {
return counter;
}
}
}
return null;
}
private static final Integer findItemStackPos(LootableContainerBlockEntity lcbe, Boolean empty) {
Integer counter = lcbe.size();
while (counter > 0) {
counter--;
ItemStack stack = lcbe.getStack(counter);
if (empty.equals(ItemStack.EMPTY.equals(stack))) {
return counter;
}
}
return null;
}
private static final Integer findItemStackPos(LootableContainerBlockEntity lcbe, List<Item> filterItems, Boolean whitelist) {
if (whitelist == null) {
whitelist = true;
Quickiemod.LOGGER.error("whitelist is null");
}
if (filterItems == null || filterItems.size() < 1) {
if (whitelist) {
return null;
} else {
return findItemStackPos(lcbe, false);
}
} else {
Integer counter = lcbe.size();
while (counter > 0) {
counter--;
ItemStack stack = lcbe.getStack(counter);
Boolean found = whitelist ? filterItems.contains(stack.getItem()) : !filterItems.contains(stack.getItem());
if (found) {
return counter;
}
}
return null;
}
}
@Override
public int size() {
return inventory.size();
}
}

View File

@@ -0,0 +1,143 @@
package de.jottyfan.quickiemod.blockentity;
import java.util.ArrayList;
import java.util.List;
import de.jottyfan.quickiemod.block.BlockDrill;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.World;
/**
*
* @author jotty
*
*/
public class DrillBlockEntity extends BlockEntity {
private static final Integer MAXDRILLSTEP = 20;
private Integer drillstep;
private final Integer maxDrillStep;
public DrillBlockEntity(BlockPos pos, BlockState state) {
super(ModBlockentity.DRILL_BLOCKENTITY, pos, state);
this.maxDrillStep = MAXDRILLSTEP;
}
public static void tick(World world, BlockPos pos, BlockState state, BlockEntity be) {
if (be instanceof DrillBlockEntity dbe) {
Direction dir = state.get(BlockDrill.DIRECTION);
List<BlockPos> list = new ArrayList<>();
if (Direction.DOWN.equals(dir)) {
list = downFrom(pos);
} else if (Direction.EAST.equals(dir)) {
list = directedFrom(pos.east());
} else if (Direction.SOUTH.equals(dir)) {
list = directedFrom(pos.south());
} else if (Direction.WEST.equals(dir)) {
list = directedFrom(pos.west());
} else if (Direction.NORTH.equals(dir)) {
list = directedFrom(pos.north());
}
DrillBlockEntity.tick(world, pos, state, dbe, MAXDRILLSTEP, list);
}
}
public static final List<BlockPos> directedFrom(BlockPos pos) {
// Quickiemod.LOGGER.info("directed");
List<BlockPos> list = new ArrayList<>();
list.add(pos);
list.add(pos.up());
list.add(pos.up().up());
list.add(pos.up().up().up());
list.add(pos.down()); // must be last position
return list;
}
public static final List<BlockPos> downFrom(BlockPos pos) {
// Quickiemod.LOGGER.info("down");
List<BlockPos> list = new ArrayList<>();
Integer tracesMod = pos.getY() % 8;
tracesMod = tracesMod < 0 ? tracesMod * -1 : tracesMod; // lower that 0 makes it negative
if (tracesMod != 0) {
list.add(pos.north());
}
if (tracesMod != 1) {
list.add(pos.north().west());
}
if (tracesMod != 2) {
list.add(pos.west());
}
if (tracesMod != 3) {
list.add(pos.south().west());
}
if (tracesMod != 4) {
list.add(pos.south());
}
if (tracesMod != 5) {
list.add(pos.south().east());
}
if (tracesMod != 6) {
list.add(pos.east());
}
if (tracesMod != 7) {
list.add(pos.north().east());
}
list.add(pos.down()); // must be last position
return list;
}
protected static final void moveBlockWithEntity(BlockPos from, BlockPos to, World world) {
BlockEntity be = world.getBlockEntity(from);
BlockState bs = world.getBlockState(from);
if (be != null) {
world.setBlockState(from, Blocks.AIR.getDefaultState());
Integer newFuel = bs.get(BlockDrill.FUEL) - 1;
world.setBlockState(to, bs.with(BlockDrill.FUEL, newFuel));
world.removeBlockEntity(from);
}
}
protected static final Boolean drill(BlockPos pos, List<BlockPos> toList, World world) {
Boolean lastSuccess = false;
for (BlockPos to : toList) {
if (!world.getBlockState(to).isOf(Blocks.BEDROCK)) {
world.breakBlock(to, true);
lastSuccess = pos.down() != to; // no need for the falling one
} else {
lastSuccess = false; // in case that the last one is a bedrock
}
}
return lastSuccess;
}
public static void tick(World world, BlockPos pos, BlockState state, DrillBlockEntity be, Integer maxDrillStep,
List<BlockPos> drillPosition) {
if (state.get(BlockDrill.FUEL) > 0) {
if (be.getDrillstep() < 1) {
be.setDrillstep(maxDrillStep);
if (drill(pos, drillPosition, world)) {
moveBlockWithEntity(pos, drillPosition.get(drillPosition.size() - 1), world);
}
} else {
be.doDrillstep();
}
}
}
public void doDrillstep() {
setDrillstep(getDrillstep() - 1);
}
public Integer getDrillstep() {
return drillstep == null ? maxDrillStep : drillstep;
}
public void setDrillstep(Integer drillstep) {
this.drillstep = drillstep;
}
}

View File

@@ -0,0 +1,154 @@
package de.jottyfan.quickiemod.blockentity;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.LootableContainerBlockEntity;
import net.minecraft.entity.Entity;
import net.minecraft.entity.Entity.RemovalReason;
import net.minecraft.entity.ItemEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.Inventories;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.registry.RegistryWrapper.WrapperLookup;
import net.minecraft.screen.ScreenHandler;
import net.minecraft.text.Text;
import net.minecraft.util.collection.DefaultedList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Box;
import net.minecraft.world.World;
/**
*
* @author jotty
*
*/
public class ItemHoarderBlockEntity extends LootableContainerBlockEntity {
private DefaultedList<ItemStack> stacks;
private float suckradius;
public ItemHoarderBlockEntity(BlockPos pos, BlockState state) {
super(ModBlockentity.ITEM_HOARDER_BLOCKENTITY, pos, state);
stacks = DefaultedList.ofSize(54, ItemStack.EMPTY);
setSuckradius(4f);
}
// TODO: see https://fabricmc.net/wiki/tutorial:containers for a real chest
public final static boolean setStackToSlots(ItemStack stack, List<ItemStack> stacks) {
for (ItemStack slot : stacks) {
if (slot.getItem().equals(stack.getItem())) {
slot.increment(stack.getCount());
return true;
}
} // if not found, seek for an empty stack instead
for (ItemStack slot : stacks) {
if (slot.isEmpty()) {
Integer index = stacks.indexOf(slot);
stacks.set(index, stack.copy());
return true;
}
}
return false;
}
public static void tick(World world, BlockPos pos, BlockState state, BlockEntity be) {
if (be instanceof ItemHoarderBlockEntity) {
ItemHoarderBlockEntity ihbe = (ItemHoarderBlockEntity) be;
Box box = new Box(pos).expand(ihbe.getSuckradius());
List<Entity> entities = world.getOtherEntities(null, box);
for (Entity entity : entities) {
if (entity instanceof ItemEntity) {
ItemEntity itemEntity = (ItemEntity) entity;
if (itemEntity.isAlive()) {
ItemStack stack = itemEntity.getStack();
if (stack != null) {
if (ItemHoarderBlockEntity.setStackToSlots(stack, ihbe.getStacks())) {
itemEntity.remove(RemovalReason.DISCARDED);
} // else inventory is full
}
}
}
}
}
}
@Override
protected void writeNbt(NbtCompound nbt, WrapperLookup registryLookup) {
super.writeNbt(nbt, registryLookup);
if (!this.writeLootTable(nbt)) {
Inventories.writeNbt(nbt, this.stacks, registryLookup);
}
}
@Override
protected void readNbt(NbtCompound nbt, WrapperLookup registryLookup) {
super.readNbt(nbt, registryLookup);
this.stacks = DefaultedList.ofSize(this.size(), ItemStack.EMPTY);
if (!this.readLootTable(nbt)) {
Inventories.readNbt(nbt, this.stacks, registryLookup);
}
}
public List<ItemStack> getStacks() {
return stacks;
}
@Override
public int size() {
return 54; // container chest size (9 * 6)
}
@Override
protected DefaultedList<ItemStack> getHeldStacks() {
return stacks;
}
@Override
protected void setHeldStacks(DefaultedList<ItemStack> list) {
this.stacks = list;
}
@Override
protected ScreenHandler createScreenHandler(int syncId, PlayerInventory playerInventory) {
// TODO: implement, see https://fabricmc.net/wiki/tutorial:containers
return null;
}
@Override
protected Text getContainerName() {
return Text.translatable("container.itemhoarder");
}
/**
* get a summary of content for the chat box
*
* @return the summary
*/
public List<Text> getSummary() {
List<Text> list = new ArrayList<>();
for (ItemStack stack : stacks) {
Item item = stack.getItem();
if (item != Items.AIR) {
Text text = Text.of(String.format("%dx %s", stack.getCount(), Text.translatable(stack.getItem().getTranslationKey())));
list.add(text);
}
}
return list;
}
public float getSuckradius() {
return suckradius;
}
public void setSuckradius(float suckradius) {
this.suckradius = suckradius;
}
}

View File

@@ -0,0 +1,31 @@
package de.jottyfan.quickiemod.blockentity;
import de.jottyfan.quickiemod.block.ModBlocks;
import de.jottyfan.quickiemod.identifier.ModIdentifiers;
import net.fabricmc.fabric.api.object.builder.v1.block.entity.FabricBlockEntityTypeBuilder;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
/**
*
* @author jotty
*
*/
public class ModBlockentity {
public static final BlockEntityType<ItemHoarderBlockEntity> ITEM_HOARDER_BLOCKENTITY = Registry.register(
Registries.BLOCK_ENTITY_TYPE, ModIdentifiers.BLOCKENTITY_ITEMHOARDER,
FabricBlockEntityTypeBuilder.create(ItemHoarderBlockEntity::new, ModBlocks.BLOCK_ITEMHOARDER).build());
public static final BlockEntityType<DrillBlockEntity> DRILL_BLOCKENTITY = Registry.register(
Registries.BLOCK_ENTITY_TYPE, ModIdentifiers.BLOCKENTITY_DRILL,
FabricBlockEntityTypeBuilder.create(DrillBlockEntity::new, ModBlocks.BLOCK_DRILL_DOWN, ModBlocks.BLOCK_DRILL_EAST,
ModBlocks.BLOCK_DRILL_SOUTH, ModBlocks.BLOCK_DRILL_WEST, ModBlocks.BLOCK_DRILL_NORTH).build());
public static final BlockEntityType<BlockStackerEntity> BLOCKSTACKER_BLOCKENTITY = Registry.register(
Registries.BLOCK_ENTITY_TYPE, ModIdentifiers.BLOCKENTITY_BLOCKSTACKER,
FabricBlockEntityTypeBuilder.create(BlockStackerEntity::new, ModBlocks.BLOCK_STACKER_DOWN,
ModBlocks.BLOCK_STACKER_EAST, ModBlocks.BLOCK_STACKER_SOUTH, ModBlocks.BLOCK_STACKER_WEST,
ModBlocks.BLOCK_STACKER_NORTH, ModBlocks.BLOCK_STACKER_UP).build());
public static final void registerModBlockentities() {
};
}

View File

@@ -0,0 +1,30 @@
package de.jottyfan.quickiemod.container;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.inventory.SimpleInventory;
import net.minecraft.sound.SoundEvents;
/**
*
* @author jotty
*
*/
public class BlockStackerInventory extends SimpleInventory {
public BlockStackerInventory(Integer slotsize) {
super(slotsize);
}
@Override
public void onOpen(PlayerEntity player) {
super.onOpen(player);
player.playSound(SoundEvents.BLOCK_CHEST_OPEN, 1f, 1f);
}
@Override
public void onClose(PlayerEntity player) {
super.onClose(player);
player.playSound(SoundEvents.BLOCK_CHEST_CLOSE, 1f, 1f);
}
}

View File

@@ -0,0 +1,44 @@
package de.jottyfan.quickiemod.container;
import de.jottyfan.quickiemod.Quickiemod;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.ingame.HandledScreen;
import net.minecraft.client.gui.screen.ingame.ScreenHandlerProvider;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
/**
*
* @author jotty
*
*/
@Environment(EnvType.CLIENT)
public class BlockStackerScreen extends HandledScreen<BlockStackerScreenHandler>
implements ScreenHandlerProvider<BlockStackerScreenHandler> {
private final static Identifier TEXTURE = Identifier.of(Quickiemod.MOD_ID, "textures/gui/blockstacker.png");
private final Integer containerHeight = 222;
private final Integer containerWidth = 176;
public BlockStackerScreen(BlockStackerScreenHandler handler, PlayerInventory inventory, Text title) {
super(handler, inventory, title);
}
@Override
public void render(DrawContext drawContext, int mouseX, int mouseY, float partialTicks) {
this.renderInGameBackground(drawContext);
super.render(drawContext, mouseX, mouseY, partialTicks);
this.drawMouseoverTooltip(drawContext, mouseX, mouseY);
}
@Override
protected void drawBackground(DrawContext context, float delta, int mouseX, int mouseY) {
// context.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
int guiX = (this.width - this.containerWidth) / 2;
int guiY = (this.height - this.containerHeight) / 2;
super.renderInGameBackground(context);
// context.drawTexture(TEXTURE, guiX, guiY, 0f, 0f, containerWidth, containerHeight, 0, 0);
}
}

View File

@@ -0,0 +1,97 @@
package de.jottyfan.quickiemod.container;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.Inventory;
import net.minecraft.item.ItemStack;
import net.minecraft.screen.NamedScreenHandlerFactory;
import net.minecraft.screen.ScreenHandler;
import net.minecraft.screen.slot.Slot;
/**
*
* @author jotty
*
*/
public class BlockStackerScreenHandler extends ScreenHandler {
public static final Integer SLOTSIZE = 18;
private final Inventory inventory;
/**
* client constructor
*
* @param syncId
* @param playerInventory
*/
public BlockStackerScreenHandler(int syncId, PlayerInventory playerInventory) {
this(syncId, playerInventory, new BlockStackerInventory(SLOTSIZE));
}
/**
* server constructor
*
* @param syncId
* @param playerInventory
* @param inventory
*/
public BlockStackerScreenHandler(int syncId, PlayerInventory playerInventory, Inventory inventory) {
super(ScreenHandlerTypes.BLOCKSTACKER_SCREEN_HANDLER, syncId);
checkSize(inventory, SLOTSIZE);
this.inventory = inventory;
inventory.onOpen(playerInventory.player);
int m;
int l;
// whitelist
for (m = 0; m < 3; ++m) {
for (l = 0; l < 3; ++l) {
this.addSlot(new Slot(inventory, l + m * 3, 8 + l * 18, 17 + m * 18));
}
}
// blacklist
for (m = 0; m < 3; ++m) {
for (l = 0; l < 3; ++l) {
this.addSlot(new Slot(inventory, l + m * 3 + 9, 116 + l * 18, 17 + m * 18));
}
}
for (m = 0; m < 3; ++m) {
for (l = 0; l < 9; ++l) {
this.addSlot(new Slot(playerInventory, l + m * 9 + 9, 8 + l * 18, 84 + m * 18));
}
}
for (m = 0; m < 9; ++m) {
this.addSlot(new Slot(playerInventory, m, 8 + m * 18, 142));
}
}
@Override
public boolean canUse(PlayerEntity player) {
return this.inventory.canPlayerUse(player);
}
@Override
public ItemStack quickMove(PlayerEntity player, int invSlot) {
ItemStack newStack = ItemStack.EMPTY;
Slot slot = this.slots.get(invSlot);
if (slot != null && slot.hasStack()) {
ItemStack originalStack = slot.getStack();
newStack = originalStack.copy();
if (invSlot < this.inventory.size()) {
if (!this.insertItem(originalStack, this.inventory.size(), this.slots.size(), true)) {
return ItemStack.EMPTY;
}
} else if (!this.insertItem(originalStack, 0, this.inventory.size(), false)) {
return ItemStack.EMPTY;
}
if (originalStack.isEmpty()) {
slot.setStack(ItemStack.EMPTY);
} else {
slot.markDirty();
}
}
return newStack;
}
}

View File

@@ -0,0 +1,133 @@
package de.jottyfan.quickiemod.container;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.inventory.Inventories;
import net.minecraft.inventory.Inventory;
import net.minecraft.item.ItemStack;
import net.minecraft.util.collection.DefaultedList;
/**
*
* @author jotty
*
* @see https://fabricmc.net/wiki/tutorial:inventory
*
*/
public interface ImplementedInventory extends Inventory {
/**
* Retrieves the item list of this inventory.
* Must return the same instance every time it's called.
*/
DefaultedList<ItemStack> getItems();
/**
* Creates an inventory from the item list.
*/
static ImplementedInventory of(DefaultedList<ItemStack> items) {
return () -> items;
}
/**
* Creates a new inventory with the specified size.
*/
static ImplementedInventory ofSize(int size) {
return of(DefaultedList.ofSize(size, ItemStack.EMPTY));
}
/**
* Returns the inventory size.
*/
@Override
default int size() {
return getItems().size();
}
/**
* Checks if the inventory is empty.
* @return true if this inventory has only empty stacks, false otherwise.
*/
@Override
default boolean isEmpty() {
for (int i = 0; i < size(); i++) {
ItemStack stack = getStack(i);
if (!stack.isEmpty()) {
return false;
}
}
return true;
}
/**
* Retrieves the item in the slot.
*/
@Override
default ItemStack getStack(int slot) {
return getItems().get(slot);
}
/**
* Removes items from an inventory slot.
* @param slot The slot to remove from.
* @param count How many items to remove. If there are less items in the slot than what are requested,
* takes all items in that slot.
*/
@Override
default ItemStack removeStack(int slot, int count) {
ItemStack result = Inventories.splitStack(getItems(), slot, count);
if (!result.isEmpty()) {
markDirty();
}
return result;
}
/**
* Removes all items from an inventory slot.
* @param slot The slot to remove from.
*/
@Override
default ItemStack removeStack(int slot) {
return Inventories.removeStack(getItems(), slot);
}
/**
* Replaces the current stack in an inventory slot with the provided stack.
* @param slot The inventory slot of which to replace the itemstack.
* @param stack The replacing itemstack. If the stack is too big for
* this inventory ({@link Inventory#getMaxCountPerStack()}),
* it gets resized to this inventory's maximum amount.
*/
@Override
default void setStack(int slot, ItemStack stack) {
getItems().set(slot, stack);
if (stack.getCount() > stack.getMaxCount()) {
stack.setCount(stack.getMaxCount());
}
}
/**
* Clears the inventory.
*/
@Override
default void clear() {
getItems().clear();
}
/**
* Marks the state as dirty.
* Must be called after changes in the inventory, so that the game can properly save
* the inventory contents and notify neighboring blocks of inventory changes.
*/
@Override
default void markDirty() {
// Override if you want behavior.
}
/**
* @return true if the player can use the inventory, false otherwise.
*/
@Override
default boolean canPlayerUse(PlayerEntity player) {
return true;
}
}

View File

@@ -0,0 +1,14 @@
package de.jottyfan.quickiemod.container;
import net.minecraft.resource.featuretoggle.FeatureFlags;
import net.minecraft.screen.ScreenHandlerType;
/**
*
* @author jotty
*
*/
public class ScreenHandlerTypes {
public static final ScreenHandlerType<BlockStackerScreenHandler> BLOCKSTACKER_SCREEN_HANDLER = new ScreenHandlerType<>(BlockStackerScreenHandler::new,
FeatureFlags.VANILLA_FEATURES);
}

View File

@@ -0,0 +1,192 @@
package de.jottyfan.quickiemod.event;
import java.util.ArrayList;
import java.util.List;
import de.jottyfan.quickiemod.item.HarvestRange;
import de.jottyfan.quickiemod.item.ModItems;
import de.jottyfan.quickiemod.item.ToolRangeable;
import de.jottyfan.quickiemod.item.ToolSpeedpowderAxe;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.entity.EquipmentSlot;
import net.minecraft.entity.ExperienceOrbEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
/**
*
* @author jotty
*
*/
public class EventBlockBreak {
private enum BlockBreakDirection {
UPWARDS, ALL;
}
public void doBreakBlock(World world, BlockPos blockPos, BlockState blockState, PlayerEntity playerEntity, Block oldBlock) {
ItemStack mainHandItemStack = playerEntity.getEquippedStack(EquipmentSlot.MAINHAND);
if (mainHandItemStack != null) {
Item item = mainHandItemStack.getItem();
if (item instanceof ToolRangeable) {
ToolRangeable tool = (ToolRangeable) item;
if (!world.getBlockState(blockPos).getBlock().equals(oldBlock)) {
// recreate old block to make it breakable; otherwise, the recursive algorithm stops directly
world.setBlockState(blockPos, oldBlock.getDefaultState());
}
int handled = handleRangeableTools(tool, mainHandItemStack, world, oldBlock, blockPos, playerEntity);
if (handled >= 255) {
// reward for using rangeable tool very successful
world.spawnEntity(
new ExperienceOrbEntity(world, blockPos.getX(), blockPos.getY(), blockPos.getZ(), handled / 255));
}
}
}
}
/**
* handle the rangeable tools break event
*
* @param tool the tool that has been used
* @param itemStack the item stack
* @param world the world
* @param block the block to break
* @param pos the position of the current block
* @param player the current player
* @return number of affected blocks
*/
private int handleRangeableTools(ToolRangeable tool, ItemStack itemStack, World world, Block currentBlock,
BlockPos pos, PlayerEntity player) {
List<Block> validBlocks = tool.getBlockList(currentBlock);
HarvestRange range = tool.getRange(itemStack);
List<String> visitedBlocks = new ArrayList<>();
if (tool instanceof ToolSpeedpowderAxe) {
return breakBlockRecursive(visitedBlocks, world, validBlocks, pos, tool, range, BlockBreakDirection.UPWARDS,
player, true);
} else if (ModItems.TOOL_SPEEDPOWDERPICKAXE.getName().equals(tool.getName())) {
return breakBlockRecursive(visitedBlocks, world, validBlocks, pos, tool, range, BlockBreakDirection.ALL,
player, false);
} else if (ModItems.TOOL_SPEEDPOWDERSHOVEL.getName().equals(tool.getName())) {
return breakBlockRecursive(visitedBlocks, world, validBlocks, pos, tool, range, BlockBreakDirection.ALL,
player, false);
} else if (ModItems.TOOL_SPEEDPOWDERHOE.getName().equals(tool.getName())) {
return breakBlockRecursive(visitedBlocks, world, validBlocks, pos, tool, range, BlockBreakDirection.ALL,
player, false);
} else if (ModItems.TOOL_QUICKIEPOWDERAXE.getName().equals(tool.getName())) {
return breakBlockRecursive(visitedBlocks, world, validBlocks, pos, tool, range, BlockBreakDirection.UPWARDS,
player, true);
} else if (ModItems.TOOL_QUICKIEPOWDERPICKAXE.getName().equals(tool.getName())) {
return breakBlockRecursive(visitedBlocks, world, validBlocks, pos, tool, range, BlockBreakDirection.ALL,
player, false);
} else if (ModItems.TOOL_QUICKIEPOWDERSHOVEL.getName().equals(tool.getName())) {
return breakBlockRecursive(visitedBlocks, world, validBlocks, pos, tool, range, BlockBreakDirection.ALL,
player, false);
} else if (ModItems.TOOL_QUICKIEPOWDERHOE.getName().equals(tool.getName())) {
return breakBlockRecursive(visitedBlocks, world, validBlocks, pos, tool, range, BlockBreakDirection.ALL,
player, false);
} else {
return 0;
}
}
/**
* break block recursively;
*
* @param visitedBlocks the positions of visited blocks
* @param world the world
* @param validBlocks the blocks to break
* @param tool the tool used
* @param range the range left over
* @param pos the position
* @param blockBreakDirection the direction for the recursive call
* @param player the player
* @return number of affected blocks
*/
private int breakBlockRecursive(List<String> visitedBlocks, World world, List<Block> validBlocks, BlockPos pos,
ToolRangeable tool, HarvestRange range, BlockBreakDirection blockBreakDirection, PlayerEntity player,
boolean breakLeaves) {
boolean ignoreSpawn = visitedBlocks.size() < 1; // with this, the already broken block can be omitted to spawn
if (visitedBlocks.contains(pos.toString())) {
return 0;
} else if (validBlocks == null) {
return 0;
} else {
visitedBlocks.add(pos.toString());
}
Integer affected = 0;
BlockState blockState = world.getBlockState(pos);
if (tool.canBreakNeighbors(blockState)) {
Block currentBlock = blockState.getBlock();
if (validBlocks.contains(currentBlock)) {
if (!ignoreSpawn) {
Block.dropStacks(blockState, world, pos); // includes xorbs
}
affected += 1;
world.setBlockState(pos, Blocks.AIR.getDefaultState());
if (range == null || range.getxRange() > 1 || range.getyRange() > 1 || range.getzRange() > 1) {
HarvestRange nextRadius = range == null ? null : range.addXYZ(-1);
affected += breakBlockRecursive(visitedBlocks, world, validBlocks, pos.north(), tool, nextRadius,
blockBreakDirection, player, breakLeaves);
affected += breakBlockRecursive(visitedBlocks, world, validBlocks, pos.north().east(), tool, nextRadius,
blockBreakDirection, player, breakLeaves);
affected += breakBlockRecursive(visitedBlocks, world, validBlocks, pos.north().west(), tool, nextRadius,
blockBreakDirection, player, breakLeaves);
affected += breakBlockRecursive(visitedBlocks, world, validBlocks, pos.south(), tool, nextRadius,
blockBreakDirection, player, breakLeaves);
affected += breakBlockRecursive(visitedBlocks, world, validBlocks, pos.south().east(), tool, nextRadius,
blockBreakDirection, player, breakLeaves);
affected += breakBlockRecursive(visitedBlocks, world, validBlocks, pos.south().west(), tool, nextRadius,
blockBreakDirection, player, breakLeaves);
affected += breakBlockRecursive(visitedBlocks, world, validBlocks, pos.east(), tool, nextRadius,
blockBreakDirection, player, breakLeaves);
affected += breakBlockRecursive(visitedBlocks, world, validBlocks, pos.west(), tool, nextRadius,
blockBreakDirection, player, breakLeaves);
affected += breakBlockRecursive(visitedBlocks, world, validBlocks, pos.up(), tool, nextRadius,
blockBreakDirection, player, breakLeaves);
affected += breakBlockRecursive(visitedBlocks, world, validBlocks, pos.up().north(), tool, nextRadius,
blockBreakDirection, player, breakLeaves);
affected += breakBlockRecursive(visitedBlocks, world, validBlocks, pos.up().north().east(), tool, nextRadius,
blockBreakDirection, player, breakLeaves);
affected += breakBlockRecursive(visitedBlocks, world, validBlocks, pos.up().north().west(), tool, nextRadius,
blockBreakDirection, player, breakLeaves);
affected += breakBlockRecursive(visitedBlocks, world, validBlocks, pos.up().east(), tool, nextRadius,
blockBreakDirection, player, breakLeaves);
affected += breakBlockRecursive(visitedBlocks, world, validBlocks, pos.up().west(), tool, nextRadius,
blockBreakDirection, player, breakLeaves);
affected += breakBlockRecursive(visitedBlocks, world, validBlocks, pos.up().south().east(), tool, nextRadius,
blockBreakDirection, player, breakLeaves);
affected += breakBlockRecursive(visitedBlocks, world, validBlocks, pos.up().south().west(), tool, nextRadius,
blockBreakDirection, player, breakLeaves);
affected += breakBlockRecursive(visitedBlocks, world, validBlocks, pos.up().south(), tool, nextRadius,
blockBreakDirection, player, breakLeaves);
if (BlockBreakDirection.ALL.equals(blockBreakDirection)) {
affected += breakBlockRecursive(visitedBlocks, world, validBlocks, pos.down(), tool, nextRadius,
blockBreakDirection, player, breakLeaves);
affected += breakBlockRecursive(visitedBlocks, world, validBlocks, pos.down().north(), tool, nextRadius,
blockBreakDirection, player, breakLeaves);
affected += breakBlockRecursive(visitedBlocks, world, validBlocks, pos.down().south(), tool, nextRadius,
blockBreakDirection, player, breakLeaves);
affected += breakBlockRecursive(visitedBlocks, world, validBlocks, pos.down().east(), tool, nextRadius,
blockBreakDirection, player, breakLeaves);
affected += breakBlockRecursive(visitedBlocks, world, validBlocks, pos.down().west(), tool, nextRadius,
blockBreakDirection, player, breakLeaves);
affected += breakBlockRecursive(visitedBlocks, world, validBlocks, pos.down().north().east(), tool,
nextRadius, blockBreakDirection, player, breakLeaves);
affected += breakBlockRecursive(visitedBlocks, world, validBlocks, pos.down().north().west(), tool,
nextRadius, blockBreakDirection, player, breakLeaves);
affected += breakBlockRecursive(visitedBlocks, world, validBlocks, pos.down().south().east(), tool,
nextRadius, blockBreakDirection, player, breakLeaves);
affected += breakBlockRecursive(visitedBlocks, world, validBlocks, pos.down().south().west(), tool,
nextRadius, blockBreakDirection, player, breakLeaves);
}
}
}
}
return affected;
}
}

View File

@@ -0,0 +1,66 @@
package de.jottyfan.quickiemod.feature;
import de.jottyfan.quickiemod.Quickiemod;
import net.fabricmc.fabric.api.biome.v1.BiomeModifications;
import net.fabricmc.fabric.api.biome.v1.BiomeSelectors;
import net.fabricmc.fabric.api.biome.v1.ModificationPhase;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.util.Identifier;
import net.minecraft.world.gen.GenerationStep;
import net.minecraft.world.gen.feature.ConfiguredFeature;
import net.minecraft.world.gen.feature.PlacedFeature;
/**
*
* @author jotty
*
*/
public class ModFeatures {
public static final RegistryKey<ConfiguredFeature<?, ?>> CF_ORESULFUR = genCf("oresulphor");
public static final RegistryKey<ConfiguredFeature<?, ?>> CF_OREDEEPSLATESULFUR = genCf("oredepslatesulphor");
public static final RegistryKey<ConfiguredFeature<?, ?>> CF_ORESALPETER = genCf("oresalpeter");
public static final RegistryKey<ConfiguredFeature<?, ?>> CF_ORENETHERSULPHOR = genCf("orenethersulphore");
public static final RegistryKey<ConfiguredFeature<?, ?>> CF_BLOCKSULPHOR = genCf("blocksulphor");
public static final RegistryKey<ConfiguredFeature<?, ?>> CF_DIRTSALPETER = genCf("dirtsalpeter");
public static final RegistryKey<ConfiguredFeature<?, ?>> CF_SANDSALPETER = genCf("sandsalpeter");
public static final RegistryKey<ConfiguredFeature<?, ?>> CF_ORESANDSALPETER = genCf("oresandsalpeter");
public static final RegistryKey<PlacedFeature> PF_ORESULPHOR = genPf("oresulphor");
public static final RegistryKey<PlacedFeature> PF_OREDEEPSLATESULPHOR = genPf("oredeepslatesulphor");
public static final RegistryKey<PlacedFeature> PF_ORESALPETER = genPf("oresalpeter");
public static final RegistryKey<PlacedFeature> PF_ORENETHERSULPHOR = genPf("orenethersulphor");
public static final RegistryKey<PlacedFeature> PF_BLOCKSULPHOR = genPf("blocksulphor");
public static final RegistryKey<PlacedFeature> PF_DIRTSALPETER = genPf("dirtsalpeter");
public static final RegistryKey<PlacedFeature> PF_SANDSALPETER = genPf("sandsalpeter");
public static final RegistryKey<PlacedFeature> PF_ORESANDSALPETER = genPf("oresandsalpeter");
private static final RegistryKey<ConfiguredFeature<?, ?>> genCf(String name) {
return RegistryKey.of(RegistryKeys.CONFIGURED_FEATURE, Identifier.of(Quickiemod.MOD_ID, name));
}
private static final RegistryKey<PlacedFeature> genPf(String name) {
return RegistryKey.of(RegistryKeys.PLACED_FEATURE, Identifier.of(Quickiemod.MOD_ID, name));
}
public static final void registerFeatures() {
// Overworld features
BiomeModifications.create(Identifier.of(Quickiemod.MOD_ID, "features")).add(ModificationPhase.ADDITIONS,
BiomeSelectors.foundInOverworld(), (bsc, bmc) -> {
bmc.getGenerationSettings().addFeature(GenerationStep.Feature.UNDERGROUND_ORES, PF_ORESULPHOR);
bmc.getGenerationSettings().addFeature(GenerationStep.Feature.UNDERGROUND_ORES, PF_ORESALPETER);
bmc.getGenerationSettings().addFeature(GenerationStep.Feature.UNDERGROUND_ORES, PF_DIRTSALPETER);
bmc.getGenerationSettings().addFeature(GenerationStep.Feature.UNDERGROUND_ORES, PF_SANDSALPETER);
bmc.getGenerationSettings().addFeature(GenerationStep.Feature.UNDERGROUND_ORES, PF_ORESANDSALPETER);
bmc.getGenerationSettings().addFeature(GenerationStep.Feature.UNDERGROUND_ORES, PF_OREDEEPSLATESULPHOR);
});
// Nether features
BiomeModifications.create(Identifier.of(Quickiemod.MOD_ID, "nether_features")).add(ModificationPhase.ADDITIONS,
BiomeSelectors.foundInTheNether(), (bsc, bmc) -> {
bmc.getGenerationSettings().addFeature(GenerationStep.Feature.UNDERGROUND_ORES, PF_ORENETHERSULPHOR);
bmc.getGenerationSettings().addFeature(GenerationStep.Feature.UNDERGROUND_ORES, PF_BLOCKSULPHOR);
});
}
}

View File

@@ -12,6 +12,66 @@ public class ModIdentifiers {
public static final Identifier ITEM_STUB = Identifier.of(Quickiemod.MOD_ID, "stub"); public static final Identifier ITEM_STUB = Identifier.of(Quickiemod.MOD_ID, "stub");
public static final Identifier ITEM_SPEEDPOWDER = Identifier.of(Quickiemod.MOD_ID, "speedpowder"); public static final Identifier ITEM_SPEEDPOWDER = Identifier.of(Quickiemod.MOD_ID, "speedpowder");
public static final Identifier ITEM_QUICKIEPOWDER = Identifier.of(Quickiemod.MOD_ID, "quickiepowder"); public static final Identifier ITEM_QUICKIEPOWDER = Identifier.of(Quickiemod.MOD_ID, "quickiepowder");
public static final Identifier ITEM_SALPETER = Identifier.of(Quickiemod.MOD_ID, "salpeter");
public static final Identifier ITEM_SULFOR = Identifier.of(Quickiemod.MOD_ID, "sulphor");
public static final Identifier ITEM_OXIDIZEDCOPPERPOWDER = Identifier.of(Quickiemod.MOD_ID, "oxidizedcopperpowder");
public static final Identifier ITEM_SPEEDINGOT = Identifier.of(Quickiemod.MOD_ID, "speedingot");
public static final Identifier ITEM_QUICKIEINGOT = Identifier.of(Quickiemod.MOD_ID, "quickieingot");
public static final Identifier ITEM_CARROTSTACK = Identifier.of(Quickiemod.MOD_ID, "carrotstack");
public static final Identifier ITEM_ROTTENFLESHSTRIPES = Identifier.of(Quickiemod.MOD_ID, "rotten_flesh_stripes");
public static final Identifier ITEM_COTTON = Identifier.of(Quickiemod.MOD_ID, "cotton");
public static final Identifier ITEM_COTTONPLANT = Identifier.of(Quickiemod.MOD_ID, "cottonplant");
public static final Identifier ITEM_COTTONSEED = Identifier.of(Quickiemod.MOD_ID, "cottonseed");
public static final Identifier ITEM_CANOLA = Identifier.of(Quickiemod.MOD_ID, "canola");
public static final Identifier ITEM_CANOLAPLANT = Identifier.of(Quickiemod.MOD_ID, "canolaplant");
public static final Identifier ITEM_CANOLASEED = Identifier.of(Quickiemod.MOD_ID, "canolaseed");
public static final Identifier ITEM_CANOLABOTTLE = Identifier.of(Quickiemod.MOD_ID, "canolabottle");
public static final Identifier ITEM_CANOLABOTTLESTACK = Identifier.of(Quickiemod.MOD_ID, "canolabottlestack");
public static final Identifier TOOL_SPEEDPOWDERAXE = Identifier.of(Quickiemod.MOD_ID, "speedpowderaxe");
public static final Identifier TOOL_SPEEDPOWDERHOE = Identifier.of(Quickiemod.MOD_ID, "speedpowderhoe");
public static final Identifier TOOL_SPEEDPOWDERPICKAXE = Identifier.of(Quickiemod.MOD_ID, "speedpowderpickaxe");
public static final Identifier TOOL_SPEEDPOWDERSHEARS = Identifier.of(Quickiemod.MOD_ID, "speedpowdershears");
public static final Identifier TOOL_SPEEDPOWDERSHOVEL = Identifier.of(Quickiemod.MOD_ID, "speedpowdershovel");
public static final Identifier TOOL_SPEEDPOWDERWATERHOE = Identifier.of(Quickiemod.MOD_ID, "speedpowderwaterhoe");
public static final Identifier TOOL_QUICKIEPOWDERAXE = Identifier.of(Quickiemod.MOD_ID, "quickiepowderaxe");
public static final Identifier TOOL_QUICKIEPOWDERHOE = Identifier.of(Quickiemod.MOD_ID, "quickiepowderhoe");
public static final Identifier TOOL_QUICKIEPOWDERPICKAXE = Identifier.of(Quickiemod.MOD_ID, "quickiepowderpickaxe");
public static final Identifier TOOL_QUICKIEPOWDERSHOVEL = Identifier.of(Quickiemod.MOD_ID, "quickiepowdershovel");
public static final Identifier TOOL_QUICKIEPOWDERWATERHOE = Identifier.of(Quickiemod.MOD_ID, "quickiepowderwaterhoe");
public static final Identifier BLOCK_QUICKIEPOWDER = Identifier.of(Quickiemod.MOD_ID, "blockquickiepowder"); public static final Identifier BLOCK_QUICKIEPOWDER = Identifier.of(Quickiemod.MOD_ID, "blockquickiepowder");
public static final Identifier BLOCK_SPEEDPOWDER = Identifier.of(Quickiemod.MOD_ID, "blockspeedpowder"); public static final Identifier BLOCK_SPEEDPOWDER = Identifier.of(Quickiemod.MOD_ID, "blockspeedpowder");
public static final Identifier BLOCK_SALPETER = Identifier.of(Quickiemod.MOD_ID, "blocksalpeter");
public static final Identifier BLOCK_SULFOR = Identifier.of(Quickiemod.MOD_ID, "blocksulphor");
public static final Identifier BLOCK_MONSTERHOARDER = Identifier.of(Quickiemod.MOD_ID, "monsterhoarder");
public static final Identifier BLOCK_LAVAHOARDER = Identifier.of(Quickiemod.MOD_ID, "lavahoarder");
public static final Identifier BLOCK_EMPTYLAVAHOARDER = Identifier.of(Quickiemod.MOD_ID, "emptylavahoarder");
public static final Identifier BLOCK_ITEMHOARDER = Identifier.of(Quickiemod.MOD_ID, "itemhoarder");
public static final Identifier BLOCK_DIRTSALPETER = Identifier.of(Quickiemod.MOD_ID, "dirtsalpeter");
public static final Identifier BLOCK_OREDEEPSLATESULFOR = Identifier.of(Quickiemod.MOD_ID, "oredeepslatesulphor");
public static final Identifier BLOCK_ORENETHERSULFOR = Identifier.of(Quickiemod.MOD_ID, "orenethersulphor");
public static final Identifier BLOCK_ORESALPETER = Identifier.of(Quickiemod.MOD_ID, "oresalpeter");
public static final Identifier BLOCK_ORESANDSALPETER = Identifier.of(Quickiemod.MOD_ID, "oresandsalpeter");
public static final Identifier BLOCK_ORESULFOR = Identifier.of(Quickiemod.MOD_ID, "oresulphor");
public static final Identifier BLOCK_SANDSALPETER = Identifier.of(Quickiemod.MOD_ID, "sandsalpeter");
public static final Identifier BLOCK_KELPSTACK = Identifier.of(Quickiemod.MOD_ID, "kelpstack");
public static final Identifier BLOCK_COTTONPLANT = Identifier.of(Quickiemod.MOD_ID, "blockcottonplant");
public static final Identifier BLOCK_CANOLAPLANT = Identifier.of(Quickiemod.MOD_ID, "blockcanolaplant");
public static final Identifier BLOCK_DRILLDOWN = Identifier.of(Quickiemod.MOD_ID, "drill");
public static final Identifier BLOCK_DRILLEAST = Identifier.of(Quickiemod.MOD_ID, "drilleast");
public static final Identifier BLOCK_DRILLSOUTH = Identifier.of(Quickiemod.MOD_ID, "drillsouth");
public static final Identifier BLOCK_DRILLWEST = Identifier.of(Quickiemod.MOD_ID, "drillwest");
public static final Identifier BLOCK_DRILLNORTH = Identifier.of(Quickiemod.MOD_ID, "drillnorth");
public static final Identifier BLOCK_STACKERDOWN = Identifier.of(Quickiemod.MOD_ID, "blockstackerdown");
public static final Identifier BLOCK_STACKEREAST = Identifier.of(Quickiemod.MOD_ID, "blockstackereast");
public static final Identifier BLOCK_STACKERSOUTH = Identifier.of(Quickiemod.MOD_ID, "blockstackersouth");
public static final Identifier BLOCK_STACKERWEST = Identifier.of(Quickiemod.MOD_ID, "blockstackerwest");
public static final Identifier BLOCK_STACKERNORTH = Identifier.of(Quickiemod.MOD_ID, "blockstackernorth");
public static final Identifier BLOCK_STACKERUP = Identifier.of(Quickiemod.MOD_ID, "blockstackerup");
public static final Identifier BLOCKENTITY_ITEMHOARDER = Identifier.of(Quickiemod.MOD_ID, "itemhoarderblockentity");
public static final Identifier BLOCKENTITY_BLOCKSTACKER = Identifier.of(Quickiemod.MOD_ID, "blockstackerblockentity");
public static final Identifier BLOCKENTITY_DRILL = Identifier.of(Quickiemod.MOD_ID, "drillblockentity");
public static final Identifier BLOCKSTACKERUP = Identifier.of(Quickiemod.MOD_ID, "blockstackerblockentity");
} }

View File

@@ -0,0 +1,110 @@
package de.jottyfan.quickiemod.item;
import java.io.Serializable;
/**
*
* @author jotty
*
*/
public class HarvestRange implements Serializable {
private static final long serialVersionUID = 1L;
private int xRange;
private int yRange;
private int zRange;
public HarvestRange(int xyzRange) {
super();
this.xRange = xyzRange;
this.yRange = xyzRange;
this.zRange = xyzRange;
}
public HarvestRange(int[] xyzRange) {
super();
this.xRange = xyzRange[0];
this.yRange = xyzRange[1];
this.zRange = xyzRange[2];
}
public HarvestRange(int xRange, int yRange, int zRange) {
super();
this.xRange = xRange;
this.yRange = yRange;
this.zRange = zRange;
}
@Override
public String toString() {
StringBuilder buf = new StringBuilder();
buf.append(xRange).append(":");
buf.append(yRange).append(":");
buf.append(zRange).append(":");
return buf.toString();
}
/**
* add i to x, y and z and return the resulting class as a new one
*
* @param i
* the summand
* @return the new class
*/
public HarvestRange addXYZ(int i) {
return new HarvestRange(xRange + i, yRange + i, zRange + i);
}
/**
* get range as int array
*
* @return the int array
*/
public int[] getRangeAsArray() {
return new int[] {xRange, yRange, zRange};
}
/**
* @return the xRange
*/
public int getxRange() {
return xRange;
}
/**
* @param xRange
* the xRange to set
*/
public void setxRange(int xRange) {
this.xRange = xRange;
}
/**
* @return the yRange
*/
public int getyRange() {
return yRange;
}
/**
* @param yRange
* the yRange to set
*/
public void setyRange(int yRange) {
this.yRange = yRange;
}
/**
* @return the zRange
*/
public int getzRange() {
return zRange;
}
/**
* @param zRange
* the zRange to set
*/
public void setzRange(int zRange) {
this.zRange = zRange;
}
}

View File

@@ -0,0 +1,45 @@
package de.jottyfan.quickiemod.item;
import de.jottyfan.quickiemod.Quickiemod;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.item.ItemUsageContext;
import net.minecraft.registry.Registries;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
/**
*
* @author jotty
*
*/
public class ItemSeed extends Item64Stack {
private Identifier plant;
public ItemSeed(Identifier identifier, Identifier plant) {
super(identifier);
this.plant = plant;
}
@Override
public ActionResult useOnBlock(ItemUsageContext context) {
BlockPos pos = context.getBlockPos();
World world = context.getWorld();
if (this.asItem().equals(context.getStack().getItem())) {
BlockState state = world.getBlockState(pos);
if (Registries.BLOCK.containsId(plant)) {
if (Blocks.FARMLAND.equals(state.getBlock()) && world.getBlockState(pos.up()).isAir()) {
world.setBlockState(pos.up(), Registries.BLOCK.get(plant).getDefaultState());
context.getStack().decrement(1);
} else {
Quickiemod.LOGGER.error("could not find block {} in Registries...", plant.toShortTranslationKey());
}
}
}
return super.useOnBlock(context);
}
}

View File

@@ -16,9 +16,65 @@ import net.minecraft.util.Identifier;
* *
*/ */
public class ModItems { public class ModItems {
public static final Item ITEM_STUB = registerItem(ModIdentifiers.ITEM_STUB, new Item64Stack(ModIdentifiers.ITEM_STUB)); public static final Item ITEM_STUB = registerItem(ModIdentifiers.ITEM_STUB,
public static final Item ITEM_SPEEDPOWDER = registerItem(ModIdentifiers.ITEM_SPEEDPOWDER, new Item64Stack(ModIdentifiers.ITEM_SPEEDPOWDER)); new Item64Stack(ModIdentifiers.ITEM_STUB));
public static final Item ITEM_QUICKIEPOWDER = registerItem(ModIdentifiers.ITEM_QUICKIEPOWDER, new Item64Stack(ModIdentifiers.ITEM_QUICKIEPOWDER)); public static final Item ITEM_SPEEDPOWDER = registerItem(ModIdentifiers.ITEM_SPEEDPOWDER,
new Item64Stack(ModIdentifiers.ITEM_SPEEDPOWDER));
public static final Item ITEM_QUICKIEPOWDER = registerItem(ModIdentifiers.ITEM_QUICKIEPOWDER,
new Item64Stack(ModIdentifiers.ITEM_QUICKIEPOWDER));
public static final Item ITEM_SALPETER = registerItem(ModIdentifiers.ITEM_SALPETER,
new Item64Stack(ModIdentifiers.ITEM_SALPETER));
public static final Item ITEM_SULFOR = registerItem(ModIdentifiers.ITEM_SULFOR,
new Item64Stack(ModIdentifiers.ITEM_SULFOR));
public static final Item ITEM_OXIDIZEDCOPPERPOWDER = registerItem(ModIdentifiers.ITEM_OXIDIZEDCOPPERPOWDER,
new Item64Stack(ModIdentifiers.ITEM_OXIDIZEDCOPPERPOWDER));
public static final Item ITEM_SPEEDINGOT = registerItem(ModIdentifiers.ITEM_SPEEDINGOT,
new Item64Stack(ModIdentifiers.ITEM_SPEEDINGOT));
public static final Item ITEM_QUICKIEINGOT = registerItem(ModIdentifiers.ITEM_QUICKIEINGOT,
new Item64Stack(ModIdentifiers.ITEM_QUICKIEINGOT));
public static final Item ITEM_CARROTSTACK = registerItem(ModIdentifiers.ITEM_CARROTSTACK,
new Item64Stack(ModIdentifiers.ITEM_CARROTSTACK));
public static final Item ITEM_ROTTENFLESHSTRIPES = registerItem(ModIdentifiers.ITEM_ROTTENFLESHSTRIPES,
new Item64Stack(ModIdentifiers.ITEM_ROTTENFLESHSTRIPES));
public static final Item ITEM_COTTON = registerItem(ModIdentifiers.ITEM_COTTON,
new Item64Stack(ModIdentifiers.ITEM_COTTON));
public static final Item ITEM_COTTONPLANT = registerItem(ModIdentifiers.ITEM_COTTONPLANT,
new Item64Stack(ModIdentifiers.BLOCK_COTTONPLANT));
public static final Item ITEM_COTTONSEED = registerItem(ModIdentifiers.ITEM_COTTONSEED,
new ItemSeed(ModIdentifiers.ITEM_COTTONSEED, ModIdentifiers.BLOCK_COTTONPLANT));
public static final Item ITEM_CANOLA = registerItem(ModIdentifiers.ITEM_CANOLA,
new Item64Stack(ModIdentifiers.ITEM_CANOLA));
public static final Item ITEM_CANOLAPLANT = registerItem(ModIdentifiers.ITEM_CANOLAPLANT,
new Item64Stack(ModIdentifiers.BLOCK_CANOLAPLANT));
public static final Item ITEM_CANOLASEED = registerItem(ModIdentifiers.ITEM_CANOLASEED,
new ItemSeed(ModIdentifiers.ITEM_CANOLASEED, ModIdentifiers.BLOCK_CANOLAPLANT));
public static final Item ITEM_CANOLABOTTLE = registerItem(ModIdentifiers.ITEM_CANOLABOTTLE,
new Item64Stack(ModIdentifiers.ITEM_CANOLABOTTLE));
public static final Item ITEM_CANOLABOTTLESTACK = registerItem(ModIdentifiers.ITEM_CANOLABOTTLESTACK,
new Item64Stack(ModIdentifiers.ITEM_CANOLABOTTLESTACK));
public static final Item TOOL_SPEEDPOWDERAXE = registerItem(ModIdentifiers.TOOL_SPEEDPOWDERAXE,
new ToolSpeedpowderAxe(ModIdentifiers.TOOL_SPEEDPOWDERAXE));
public static final Item TOOL_SPEEDPOWDERHOE = registerItem(ModIdentifiers.TOOL_SPEEDPOWDERHOE,
new ToolSpeedpowderHoe(ModIdentifiers.TOOL_SPEEDPOWDERHOE));
public static final Item TOOL_SPEEDPOWDERPICKAXE = registerItem(ModIdentifiers.TOOL_SPEEDPOWDERPICKAXE,
new ToolSpeedpowderPickaxe(ModIdentifiers.TOOL_SPEEDPOWDERPICKAXE));
public static final Item TOOL_SPEEDPOWDERSHEARS = registerItem(ModIdentifiers.TOOL_SPEEDPOWDERSHEARS,
new ToolSpeedpowderShears(ModIdentifiers.TOOL_SPEEDPOWDERSHEARS));
public static final Item TOOL_SPEEDPOWDERSHOVEL = registerItem(ModIdentifiers.TOOL_SPEEDPOWDERSHOVEL,
new ToolSpeedpowderShovel(ModIdentifiers.TOOL_SPEEDPOWDERSHOVEL));
public static final Item TOOL_SPEEDPOWDERWATERHOE = registerItem(ModIdentifiers.TOOL_SPEEDPOWDERWATERHOE,
new ToolSpeedpowderWaterHoe(ModIdentifiers.TOOL_SPEEDPOWDERWATERHOE));
public static final Item TOOL_QUICKIEPOWDERAXE = registerItem(ModIdentifiers.TOOL_QUICKIEPOWDERAXE,
new ToolQuickiepowderAxe(ModIdentifiers.TOOL_QUICKIEPOWDERAXE));
public static final Item TOOL_QUICKIEPOWDERHOE = registerItem(ModIdentifiers.TOOL_QUICKIEPOWDERHOE,
new ToolQuickiepowderHoe(ModIdentifiers.TOOL_QUICKIEPOWDERHOE));
public static final Item TOOL_QUICKIEPOWDERPICKAXE = registerItem(ModIdentifiers.TOOL_QUICKIEPOWDERPICKAXE,
new ToolQuickiepowderPickaxe(ModIdentifiers.TOOL_QUICKIEPOWDERPICKAXE));
public static final Item TOOL_QUICKIEPOWDERSHOVEL = registerItem(ModIdentifiers.TOOL_QUICKIEPOWDERSHOVEL,
new ToolQuickiepowderShovel(ModIdentifiers.TOOL_QUICKIEPOWDERSHOVEL));
public static final Item TOOL_QUICKIEPOWDERWATERHOE = registerItem(ModIdentifiers.TOOL_QUICKIEPOWDERWATERHOE,
new ToolQuickiepowderWaterHoe(ModIdentifiers.TOOL_QUICKIEPOWDERWATERHOE));
private static final Item registerItem(Identifier identifier, Item item) { private static final Item registerItem(Identifier identifier, Item item) {
return Registry.register(Registries.ITEM, identifier, item); return Registry.register(Registries.ITEM, identifier, item);
@@ -31,6 +87,31 @@ public class ModItems {
items.add(ITEM_STUB); items.add(ITEM_STUB);
items.add(ITEM_SPEEDPOWDER); items.add(ITEM_SPEEDPOWDER);
items.add(ITEM_QUICKIEPOWDER); items.add(ITEM_QUICKIEPOWDER);
items.add(ITEM_SALPETER);
items.add(ITEM_SULFOR);
items.add(ITEM_OXIDIZEDCOPPERPOWDER);
items.add(ITEM_SPEEDINGOT);
items.add(ITEM_QUICKIEINGOT);
items.add(ITEM_CARROTSTACK);
items.add(ITEM_ROTTENFLESHSTRIPES);
items.add(ITEM_COTTON);
items.add(ITEM_COTTONSEED);
items.add(ITEM_CANOLA);
items.add(ITEM_CANOLASEED);
items.add(ITEM_CANOLABOTTLE);
items.add(ITEM_CANOLABOTTLESTACK);
items.add(TOOL_SPEEDPOWDERPICKAXE);
items.add(TOOL_SPEEDPOWDERAXE);
items.add(TOOL_SPEEDPOWDERSHOVEL);
items.add(TOOL_SPEEDPOWDERHOE);
items.add(TOOL_SPEEDPOWDERWATERHOE);
items.add(TOOL_SPEEDPOWDERSHEARS);
items.add(TOOL_QUICKIEPOWDERPICKAXE);
items.add(TOOL_QUICKIEPOWDERAXE);
items.add(TOOL_QUICKIEPOWDERSHOVEL);
items.add(TOOL_QUICKIEPOWDERHOE);
items.add(TOOL_QUICKIEPOWDERWATERHOE);
return items; return items;
} }
} }

View File

@@ -0,0 +1,30 @@
package de.jottyfan.quickiemod.item;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ToolMaterial;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.tag.BlockTags;
import net.minecraft.registry.tag.ItemTags;
import net.minecraft.util.Identifier;
/**
*
* @author jotty
*
*/
public class ToolQuickiepowderAxe extends ToolRangeableAxe {
private final static ToolMaterial MATERIAL = new ToolMaterial(BlockTags.INCORRECT_FOR_DIAMOND_TOOL, 2400, 7f, 1f, 15, ItemTags.DIAMOND_TOOL_MATERIALS);
public ToolQuickiepowderAxe(Identifier identifier) {
super(MATERIAL, 7F, -3.1F, new Item.Settings().useItemPrefixedTranslationKey().registryKey(RegistryKey.of(RegistryKeys.ITEM, identifier)));
}
@Override
public HarvestRange getRange(ItemStack stack) {
// TODO: get the range from the stack
return new HarvestRange(64, 128, 64); // trees bigger than that are too heavy for one small axe...
}
}

View File

@@ -0,0 +1,24 @@
package de.jottyfan.quickiemod.item;
import net.minecraft.item.Item;
import net.minecraft.item.ToolMaterial;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.tag.BlockTags;
import net.minecraft.registry.tag.ItemTags;
import net.minecraft.util.Identifier;
/**
*
* @author jotty
*
*/
public class ToolQuickiepowderHoe extends ToolRangeableHoe {
public static final Integer DEFAULT_PLOW_RANGE = 4;
private final static ToolMaterial MATERIAL = new ToolMaterial(BlockTags.INCORRECT_FOR_DIAMOND_TOOL, 2400, 7f, 1f, 15, ItemTags.DIAMOND_TOOL_MATERIALS);
public ToolQuickiepowderHoe(Identifier identifier) {
super(MATERIAL, 7F, -3.1f, new Item.Settings().useItemPrefixedTranslationKey().registryKey(RegistryKey.of(RegistryKeys.ITEM, identifier)), new HarvestRange(DEFAULT_PLOW_RANGE));
}
}

View File

@@ -0,0 +1,64 @@
package de.jottyfan.quickiemod.item;
import java.util.List;
import com.google.common.collect.Lists;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.PickaxeItem;
import net.minecraft.item.ToolMaterial;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.tag.BlockTags;
import net.minecraft.registry.tag.ItemTags;
import net.minecraft.util.Identifier;
/**
*
* @author jotty
*
*/
public class ToolQuickiepowderPickaxe extends PickaxeItem implements ToolRangeable {
public static final int[] DEFAULT_HARVEST_RANGE = new int[] { 6, 6, 6 };
private final static ToolMaterial MATERIAL = new ToolMaterial(BlockTags.INCORRECT_FOR_DIAMOND_TOOL, 2400, 7f, 1f, 15, ItemTags.DIAMOND_TOOL_MATERIALS);
public ToolQuickiepowderPickaxe(Identifier identifier) {
super(MATERIAL, 7F, -3.1F, new Item.Settings().useItemPrefixedTranslationKey().registryKey(RegistryKey.of(RegistryKeys.ITEM, identifier)));
}
@Override
public boolean isCorrectForDrops(ItemStack stack, BlockState state) {
return super.isCorrectForDrops(stack, state);
}
@Override
public HarvestRange getRange(ItemStack stack) {
return new HarvestRange(DEFAULT_HARVEST_RANGE);
}
@Override
public boolean canBreakNeighbors(BlockState blockIn) {
return new ItemStack(this).isSuitableFor(blockIn);
}
@Override
public List<Block> getBlockList(Block block) {
return Lists.newArrayList(block);
}
// @Override
// public ActionResult<ItemStack> onItemRightClick(World worldIn, PlayerEntity playerIn, Hand handIn) {
// CommonToolCode.onItemRightClick(worldIn, playerIn, handIn);
// return super.onItemRightClick(worldIn, playerIn, handIn);
// }
//
// @Override
// public void addInformation(ItemStack stack, World worldIn, List<ITextComponent> tooltip, ITooltipFlag flagIn) {
// CommonToolCode.addInformation(stack, worldIn, tooltip, flagIn);
// super.addInformation(stack, worldIn, tooltip, flagIn);
// }
}

View File

@@ -0,0 +1,102 @@
package de.jottyfan.quickiemod.item;
import java.util.List;
import com.google.common.collect.Lists;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemUsageContext;
import net.minecraft.item.ShovelItem;
import net.minecraft.item.ToolMaterial;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.tag.BlockTags;
import net.minecraft.registry.tag.ItemTags;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.World;
/**
*
* @author jotty
*
*/
public class ToolQuickiepowderShovel extends ShovelItem implements ToolRangeable {
public static final Integer DEFAULT_HARVEST_RANGE = 6;
private final static ToolMaterial MATERIAL = new ToolMaterial(BlockTags.INCORRECT_FOR_DIAMOND_TOOL, 2400, 7f, 1f, 15, ItemTags.DIAMOND_TOOL_MATERIALS);
public HarvestRange range;
public ToolQuickiepowderShovel(Identifier identifier) {
super(MATERIAL, 7F, -3.1F, new Item.Settings().useItemPrefixedTranslationKey().registryKey(RegistryKey.of(RegistryKeys.ITEM, identifier)));
this.range = new HarvestRange(DEFAULT_HARVEST_RANGE);
}
private void createPathOnGrass(World world, BlockPos pos, Direction side) {
BlockState blockState = world.getBlockState(pos);
if (blockState.isAir()) {
// try to find one underneath
pos = pos.down();
blockState = world.getBlockState(pos);
} else if (!world.getBlockState(pos.up()).isAir()) {
pos = pos.up();
blockState = world.getBlockState(pos);
}
if (side != Direction.DOWN) {
BlockState blockState2 = (BlockState) PATH_STATES.get(blockState.getBlock());
if (blockState2 != null && world.getBlockState(pos.up()).isAir()) {
if (!world.isClient) {
world.setBlockState(pos, blockState2, 11);
}
}
}
}
@Override
public ActionResult useOnBlock(ItemUsageContext context) {
World world = context.getWorld();
BlockPos pos = context.getBlockPos();
BlockPos[] positions = new BlockPos[] { pos.north().north().west().west(), pos.north().north().west(),
pos.north().north(), pos.north().north().east(), pos.north().north().east().east(), pos.north().west().west(),
pos.north().west(), pos.north(), pos.north().east(), pos.north().east().east(), pos.west().west(), pos.west(),
pos, pos.east(), pos.east().east(), pos.south().west().west(), pos.south().west(), pos.south(),
pos.south().east(), pos.south().east().east(), pos.south().south().west().west(), pos.south().south().west(),
pos.south().south(), pos.south().south().east(), pos.south().south().east().east() };
for (BlockPos p : positions) {
createPathOnGrass(world, p, context.getSide());
}
return super.useOnBlock(context);
}
@Override
public HarvestRange getRange(ItemStack stack) {
// TODO: get range from stack
return range;
}
@Override
public boolean canBreakNeighbors(BlockState blockState) {
return new ItemStack(this).isSuitableFor(blockState);
}
@Override
public List<Block> getBlockList(Block block) {
return Lists.newArrayList(block);
}
// @Override
// public ActionResult<ItemStack> onItemRightClick(World worldIn, PlayerEntity playerIn, Hand handIn) {
// CommonToolCode.onItemRightClick(worldIn, playerIn, handIn);
// return super.onItemRightClick(worldIn, playerIn, handIn);
// }
//
// @Override
// public void addInformation(ItemStack stack, World worldIn, List<ITextComponent> tooltip, ITooltipFlag flagIn) {
// CommonToolCode.addInformation(stack, worldIn, tooltip, flagIn);
// super.addInformation(stack, worldIn, tooltip, flagIn);
// }
}

View File

@@ -0,0 +1,43 @@
package de.jottyfan.quickiemod.item;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.entity.ItemEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemUsageContext;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
/**
*
* @author jotty
*
*/
public class ToolQuickiepowderWaterHoe extends ToolQuickiepowderHoe {
public ToolQuickiepowderWaterHoe(Identifier identifier) {
super(identifier);
}
@Override
public ActionResult useOnBlock(ItemUsageContext context) {
ActionResult res = super.useOnBlock(context);
if (!ActionResult.PASS.equals(res)) {
BlockPos pos = context.getBlockPos();
World world = context.getWorld();
BlockState oldBlockState = world.getBlockState(pos);
world.setBlockState(pos, Blocks.WATER.getDefaultState());
Hand hand = context.getHand();
PlayerEntity player = context.getPlayer();
ItemStack oldTool = player.getStackInHand(hand);
ItemStack newTool = new ItemStack(ModItems.TOOL_QUICKIEPOWDERHOE);
newTool.setDamage(oldTool.getDamage());
world.spawnEntity(new ItemEntity(world, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(oldBlockState.getBlock())));
player.setStackInHand(hand, newTool);
}
return res;
}
}

View File

@@ -0,0 +1,46 @@
package de.jottyfan.quickiemod.item;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.item.ItemStack;
import net.minecraft.text.Text;
/**
*
* @author jotty
*
*/
public interface ToolRangeable {
/**
* dummy to have a getName method that comes with the item
*
* @return the name
*/
public Text getName();
/**
* @param stack the item stack that keeps the range
* @return range of blocks to be harvested
*/
public HarvestRange getRange(ItemStack stack);
/**
* check if this block state is one that affects the neighbor blocks to break
* also if they are from the same type
*
* @param blockState the block state of the current block
* @return true or false
*/
public boolean canBreakNeighbors(BlockState blockState);
/**
* get list of blocks that belong together (could be useful for stripped logs)
*
* @param block of the set
* @return the list of blocks or null if not found
*/
public List<Block> getBlockList(Block block);
}

View File

@@ -0,0 +1,63 @@
package de.jottyfan.quickiemod.item;
import java.util.List;
import com.google.common.collect.Lists;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.LeavesBlock;
import net.minecraft.item.AxeItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ToolMaterial;
import net.minecraft.registry.tag.BlockTags;
/**
*
* @author jotty
*
*/
public abstract class ToolRangeableAxe extends AxeItem implements ToolRangeable {
protected ToolRangeableAxe(ToolMaterial material, float attackDamage, float attackSpeed, Item.Settings settings) {
super(material, attackDamage, attackSpeed, settings);
}
@Override
public HarvestRange getRange(ItemStack stack) {
// TODO: get the range from the stack
return new HarvestRange(16, 32, 16);
}
/**
* check if the block is a leaves block
*
* @param blockIn the block
* @return true or false
*/
private boolean isLeavesBlock(BlockState blockIn) {
boolean vanillaLeaves = blockIn.getBlock() instanceof LeavesBlock;
boolean terrestriaLeaves = false;
try {
Class<?> extendedLeavesBlock = Class.forName("com.terraformersmc.terraform.leaves.block.ExtendedLeavesBlock");
terrestriaLeaves = extendedLeavesBlock.isInstance(blockIn.getBlock());
} catch (ClassNotFoundException e) {
// no terrestria mod available, so ignore this
// using this approach instead of the instanceof functionality, we don't need to refer to terrestria
// and omit a crash on installations that do not have or want terrestria available
}
boolean blockTagLeaves = blockIn.isIn(BlockTags.LEAVES);
return vanillaLeaves || terrestriaLeaves || blockTagLeaves;
}
@Override
public boolean canBreakNeighbors(BlockState blockIn) {
return new ItemStack(this).isSuitableFor(blockIn) || isLeavesBlock(blockIn) || blockIn.isIn(BlockTags.LOGS);
}
@Override
public List<Block> getBlockList(Block block) {
return Lists.newArrayList(block);
}
}

View File

@@ -0,0 +1,97 @@
package de.jottyfan.quickiemod.item;
import java.util.List;
import com.google.common.collect.Lists;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.CropBlock;
import net.minecraft.item.HoeItem;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemUsageContext;
import net.minecraft.item.ToolMaterial;
import net.minecraft.util.ActionResult;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Vec3i;
import net.minecraft.world.World;
/**
*
* @author jotty
*
*/
public abstract class ToolRangeableHoe extends HoeItem implements ToolRangeable {
public HarvestRange range;
public ToolRangeableHoe(ToolMaterial material, float attackDamage, float attackSpeed, Settings settings, HarvestRange range) {
super(material, attackDamage, attackSpeed, settings);
this.range = range;
}
@Override
public ActionResult useOnBlock(ItemUsageContext context) {
ActionResult res = super.useOnBlock(context);
boolean isCrop = context.getWorld().getBlockState(context.getBlockPos()).getBlock() instanceof CropBlock;
if (!ActionResult.PASS.equals(res) || isCrop) {
for (int x = -this.range.getxRange(); x <= this.range.getxRange(); x++) {
for (int y = -this.range.getyRange(); y <= this.range.getyRange(); y++) {
for (int z = -this.range.getzRange(); z <= this.range.getzRange(); z++) {
if (!isCrop) {
removePossibleGrass(context.getWorld(), new BlockPos(x, y, z));
BlockHitResult bhr = new BlockHitResult(context.getHitPos(), Direction.UP,
context.getBlockPos().add(new Vec3i(x, y, z)), false);
ItemUsageContext ctx = new ItemUsageContext(context.getPlayer(), context.getHand(), bhr);
super.useOnBlock(ctx);
} else {
harvestIfPossible(context.getBlockPos().add(x, y, z), context.getWorld());
}
}
}
}
}
return res;
}
private void removePossibleGrass(World world, BlockPos pos) {
Block block = world.getBlockState(pos).getBlock();
Boolean grassFound = Blocks.FERN.equals(block) || Blocks.LARGE_FERN.equals(block)
|| Blocks.SHORT_GRASS.equals(block) || Blocks.TALL_GRASS.equals(block);
if (grassFound) {
world.breakBlock(pos, true);
}
}
private void harvestIfPossible(BlockPos pos, World world) {
BlockState blockState = world.getBlockState(pos);
Block block = blockState.getBlock();
if (block instanceof CropBlock) {
CropBlock cBlock = (CropBlock) block;
if (cBlock.isMature(blockState)) {
Block.dropStacks(blockState, world, pos);
world.setBlockState(pos, cBlock.withAge(0));
}
}
}
@Override
public HarvestRange getRange(ItemStack stack) {
// TODO: get range from stack
return range;
}
@Override
public boolean canBreakNeighbors(BlockState blockState) {
return new ItemStack(this).isSuitableFor(blockState) || Blocks.TALL_GRASS.equals(blockState.getBlock())
|| Blocks.FERN.equals(blockState.getBlock()) || Blocks.LARGE_FERN.equals(blockState.getBlock());
}
@Override
public List<Block> getBlockList(Block block) {
return Lists.newArrayList(block);
}
}

View File

@@ -0,0 +1,30 @@
package de.jottyfan.quickiemod.item;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ToolMaterial;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.tag.BlockTags;
import net.minecraft.registry.tag.ItemTags;
import net.minecraft.util.Identifier;
/**
*
* @author jotty
*
*/
public class ToolSpeedpowderAxe extends ToolRangeableAxe {
private final static ToolMaterial MATERIAL = new ToolMaterial(BlockTags.INCORRECT_FOR_DIAMOND_TOOL, 800, 7f, 1f, 15, ItemTags.DIAMOND_TOOL_MATERIALS);
public ToolSpeedpowderAxe(Identifier identifier) {
super(MATERIAL, 7f, -3.1f, new Item.Settings().useItemPrefixedTranslationKey().registryKey(RegistryKey.of(RegistryKeys.ITEM, identifier)));
}
@Override
public HarvestRange getRange(ItemStack stack) {
// TODO: get the range from the stack
return new HarvestRange(32, 64, 32);
}
}

View File

@@ -0,0 +1,24 @@
package de.jottyfan.quickiemod.item;
import net.minecraft.item.Item;
import net.minecraft.item.ToolMaterial;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.tag.BlockTags;
import net.minecraft.registry.tag.ItemTags;
import net.minecraft.util.Identifier;
/**
*
* @author jotty
*
*/
public class ToolSpeedpowderHoe extends ToolRangeableHoe {
public static final Integer DEFAULT_PLOW_RANGE = 2;
private final static ToolMaterial MATERIAL = new ToolMaterial(BlockTags.INCORRECT_FOR_DIAMOND_TOOL, 800, 7f, 1f, 15, ItemTags.DIAMOND_TOOL_MATERIALS);
public ToolSpeedpowderHoe(Identifier identifier) {
super(MATERIAL, 7F, -3.1F, new Item.Settings().useItemPrefixedTranslationKey().registryKey(RegistryKey.of(RegistryKeys.ITEM, identifier)), new HarvestRange(DEFAULT_PLOW_RANGE));
}
}

View File

@@ -0,0 +1,59 @@
package de.jottyfan.quickiemod.item;
import java.util.List;
import com.google.common.collect.Lists;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.PickaxeItem;
import net.minecraft.item.ToolMaterial;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.tag.BlockTags;
import net.minecraft.registry.tag.ItemTags;
import net.minecraft.util.Identifier;
/**
*
* @author jotty
*
*/
public class ToolSpeedpowderPickaxe extends PickaxeItem implements ToolRangeable {
public static final int[] DEFAULT_HARVEST_RANGE = new int[] { 3, 3, 3 };
private final static ToolMaterial MATERIAL = new ToolMaterial(BlockTags.INCORRECT_FOR_DIAMOND_TOOL, 800, 7.0F, 1.0F, 15, ItemTags.DIAMOND_TOOL_MATERIALS);
public ToolSpeedpowderPickaxe(Identifier identifier) {
super(MATERIAL, 7F, -3.1F, new Item.Settings().useItemPrefixedTranslationKey().registryKey(RegistryKey.of(RegistryKeys.ITEM, identifier)));
}
@Override
public HarvestRange getRange(ItemStack stack) {
return new HarvestRange(DEFAULT_HARVEST_RANGE);
}
@Override
public boolean canBreakNeighbors(BlockState blockIn) {
return new ItemStack(this).isSuitableFor(blockIn);
}
@Override
public List<Block> getBlockList(Block block) {
return Lists.newArrayList(block);
}
// @Override
// public ActionResult<ItemStack> onItemRightClick(World worldIn, PlayerEntity playerIn, Hand handIn) {
// CommonToolCode.onItemRightClick(worldIn, playerIn, handIn);
// return super.onItemRightClick(worldIn, playerIn, handIn);
// }
//
// @Override
// public void addInformation(ItemStack stack, World worldIn, List<ITextComponent> tooltip, ITooltipFlag flagIn) {
// CommonToolCode.addInformation(stack, worldIn, tooltip, flagIn);
// super.addInformation(stack, worldIn, tooltip, flagIn);
// }
}

View File

@@ -0,0 +1,99 @@
package de.jottyfan.quickiemod.item;
import java.util.Random;
import net.minecraft.component.DataComponentTypes;
import net.minecraft.entity.ItemEntity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.passive.ChickenEntity;
import net.minecraft.entity.passive.CowEntity;
import net.minecraft.entity.passive.HorseEntity;
import net.minecraft.entity.passive.SheepEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.item.ShearsItem;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.util.ActionResult;
import net.minecraft.util.DyeColor;
import net.minecraft.util.Hand;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.Vec3d;
/**
*
* @author jotty
*
*/
public class ToolSpeedpowderShears extends ShearsItem {
public ToolSpeedpowderShears(Identifier identifier) {
super(new Item.Settings().component(DataComponentTypes.TOOL, ShearsItem.createToolComponent()).useItemPrefixedTranslationKey().registryKey(RegistryKey.of(RegistryKeys.ITEM, identifier)));
}
@Override
public ActionResult useOnEntity(ItemStack stack, PlayerEntity user, LivingEntity entity, Hand hand) {
Vec3d pos = entity.getPos();
Integer amount = 3 + new Random().nextInt(4);
if (entity instanceof SheepEntity) {
SheepEntity sheep = (SheepEntity) entity;
if (sheep.isShearable()) {
sheep.setSheared(true);
sheep.playAmbientSound();
DyeColor color = sheep.getColor();
Item item = Items.WHITE_WOOL;
if (color.equals(DyeColor.BLACK)) {
item = Items.BLACK_WOOL;
} else if (color.equals(DyeColor.GRAY)) {
item = Items.GRAY_WOOL;
} else if (color.equals(DyeColor.LIGHT_GRAY)) {
item = Items.LIGHT_GRAY_WOOL;
} else if (color.equals(DyeColor.BROWN)) {
item = Items.BROWN_WOOL;
} else if (color.equals(DyeColor.BLUE)) {
item = Items.BLUE_WOOL;
} else if (color.equals(DyeColor.LIGHT_BLUE)) {
item = Items.LIGHT_BLUE_WOOL;
} else if (color.equals(DyeColor.GREEN)) {
item = Items.GREEN_WOOL;
} else if (color.equals(DyeColor.LIME)) {
item = Items.LIME_WOOL;
} else if (color.equals(DyeColor.CYAN)) {
item = Items.CYAN_WOOL;
} else if (color.equals(DyeColor.MAGENTA)) {
item = Items.MAGENTA_WOOL;
} else if (color.equals(DyeColor.ORANGE)) {
item = Items.ORANGE_WOOL;
} else if (color.equals(DyeColor.PINK)) {
item = Items.PINK_WOOL;
} else if (color.equals(DyeColor.PURPLE)) {
item = Items.PURPLE_WOOL;
} else if (color.equals(DyeColor.RED)) {
item = Items.RED_WOOL;
} else if (color.equals(DyeColor.YELLOW)) {
item = Items.YELLOW_WOOL;
}
user.getWorld().spawnEntity(new ItemEntity(user.getWorld(), pos.getX(), pos.getY(), pos.getZ(), new ItemStack(item, amount)));
return ActionResult.SUCCESS;
}
} else if (entity instanceof HorseEntity) {
HorseEntity horse = (HorseEntity) entity;
horse.playAmbientSound();
user.getWorld().spawnEntity(new ItemEntity(user.getWorld(), pos.getX(), pos.getY(), pos.getZ(), new ItemStack(Items.LEATHER, amount)));
return ActionResult.SUCCESS;
} else if (entity instanceof CowEntity) {
CowEntity cow = (CowEntity) entity;
cow.playAmbientSound();
user.getWorld().spawnEntity(new ItemEntity(user.getWorld(), pos.getX(), pos.getY(), pos.getZ(), new ItemStack(Items.LEATHER, amount)));
return ActionResult.SUCCESS;
} else if (entity instanceof ChickenEntity) {
ChickenEntity cow = (ChickenEntity) entity;
cow.playAmbientSound();
user.getWorld().spawnEntity(new ItemEntity(user.getWorld(), pos.getX(), pos.getY(), pos.getZ(), new ItemStack(Items.FEATHER, amount)));
return ActionResult.SUCCESS;
}
return ActionResult.PASS;
}
}

View File

@@ -0,0 +1,101 @@
package de.jottyfan.quickiemod.item;
import java.util.List;
import com.google.common.collect.Lists;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemUsageContext;
import net.minecraft.item.ShovelItem;
import net.minecraft.item.ToolMaterial;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.tag.BlockTags;
import net.minecraft.registry.tag.ItemTags;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.World;
/**
*
* @author jotty
*
*/
public class ToolSpeedpowderShovel extends ShovelItem implements ToolRangeable {
public static final Integer DEFAULT_HARVEST_RANGE = 3;
private final static ToolMaterial MATERIAL = new ToolMaterial(BlockTags.INCORRECT_FOR_DIAMOND_TOOL, 800, 7f, 1f, 15, ItemTags.DIAMOND_TOOL_MATERIALS);
public HarvestRange range;
public ToolSpeedpowderShovel(Identifier identifier) {
super(MATERIAL, 7F, -3.1F, new Item.Settings().useItemPrefixedTranslationKey().registryKey(RegistryKey.of(RegistryKeys.ITEM, identifier)));
this.range = new HarvestRange(DEFAULT_HARVEST_RANGE);
}
private void createPathOnGrass(World world, BlockPos pos, Direction side) {
BlockState blockState = world.getBlockState(pos);
if (blockState.isAir()) {
// try to find one underneath
pos = pos.down();
blockState = world.getBlockState(pos);
} else if (!world.getBlockState(pos.up()).isAir()) {
pos = pos.up();
blockState = world.getBlockState(pos);
}
if (side != Direction.DOWN) {
BlockState blockState2 = (BlockState) PATH_STATES.get(blockState.getBlock());
if (blockState2 != null && world.getBlockState(pos.up()).isAir()) {
if (!world.isClient) {
world.setBlockState(pos, blockState2, 11);
}
}
}
}
@Override
public ActionResult useOnBlock(ItemUsageContext context) {
World world = context.getWorld();
BlockPos pos = context.getBlockPos();
createPathOnGrass(world, pos.north(), context.getSide());
createPathOnGrass(world, pos.north().east(), context.getSide());
createPathOnGrass(world, pos.north().west(), context.getSide());
createPathOnGrass(world, pos.east(), context.getSide());
createPathOnGrass(world, pos.west(), context.getSide());
createPathOnGrass(world, pos.south(), context.getSide());
createPathOnGrass(world, pos.south().east(), context.getSide());
createPathOnGrass(world, pos.south().west(), context.getSide());
return super.useOnBlock(context);
}
@Override
public HarvestRange getRange(ItemStack stack) {
// TODO: get range from stack
return range;
}
@Override
public boolean canBreakNeighbors(BlockState blockState) {
return new ItemStack(this).isSuitableFor(blockState);
}
@Override
public List<Block> getBlockList(Block block) {
return Lists.newArrayList(block);
}
// @Override
// public ActionResult<ItemStack> onItemRightClick(World worldIn, PlayerEntity playerIn, Hand handIn) {
// CommonToolCode.onItemRightClick(worldIn, playerIn, handIn);
// return super.onItemRightClick(worldIn, playerIn, handIn);
// }
//
// @Override
// public void addInformation(ItemStack stack, World worldIn, List<ITextComponent> tooltip, ITooltipFlag flagIn) {
// CommonToolCode.addInformation(stack, worldIn, tooltip, flagIn);
// super.addInformation(stack, worldIn, tooltip, flagIn);
// }
}

View File

@@ -0,0 +1,43 @@
package de.jottyfan.quickiemod.item;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.entity.ItemEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemUsageContext;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
/**
*
* @author jotty
*
*/
public class ToolSpeedpowderWaterHoe extends ToolSpeedpowderHoe {
public ToolSpeedpowderWaterHoe(Identifier identifier) {
super(identifier);
}
@Override
public ActionResult useOnBlock(ItemUsageContext context) {
ActionResult res = super.useOnBlock(context);
if (!ActionResult.PASS.equals(res)) {
BlockPos pos = context.getBlockPos();
World world = context.getWorld();
BlockState oldBlockState = world.getBlockState(pos);
world.setBlockState(pos, Blocks.WATER.getDefaultState());
Hand hand = context.getHand();
PlayerEntity player = context.getPlayer();
ItemStack oldTool = player.getStackInHand(hand);
ItemStack newTool = new ItemStack(ModItems.TOOL_SPEEDPOWDERHOE);
newTool.setDamage(oldTool.getDamage());
world.spawnEntity(new ItemEntity(world, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(oldBlockState.getBlock())));
player.setStackInHand(hand, newTool);
}
return res;
}
}

View File

@@ -1,4 +1,4 @@
package de.jottyfan.quickiemod.tab; package de.jottyfan.quickiemod.itemgroup;
import java.util.List; import java.util.List;
@@ -20,9 +20,9 @@ import net.minecraft.util.Identifier;
* @author jotty * @author jotty
* *
*/ */
public class ModTabs { public class ModItemGroup {
public static final void registerTab(List<Item> items, List<Block> blocks) { public static final void registerItemGroup(List<Item> items, List<Block> blocks) {
Registry.register(Registries.ITEM_GROUP, Registry.register(Registries.ITEM_GROUP,
RegistryKey.of(RegistryKeys.ITEM_GROUP, Identifier.of(Quickiemod.MOD_ID, "itemgroup")), RegistryKey.of(RegistryKeys.ITEM_GROUP, Identifier.of(Quickiemod.MOD_ID, "itemgroup")),
FabricItemGroup.builder().icon(() -> new ItemStack(ModItems.ITEM_SPEEDPOWDER)) FabricItemGroup.builder().icon(() -> new ItemStack(ModItems.ITEM_SPEEDPOWDER))

View File

@@ -1,15 +0,0 @@
package de.jottyfan.quickiemod.mixin;
import net.minecraft.server.MinecraftServer;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(MinecraftServer.class)
public class ExampleMixin {
@Inject(at = @At("HEAD"), method = "loadWorld")
private void init(CallbackInfo info) {
// This code is injected into the start of MinecraftServer.loadWorld()V
}
}

View File

@@ -0,0 +1,28 @@
package de.jottyfan.quickiemod.util;
import de.jottyfan.quickiemod.Quickiemod;
import net.minecraft.block.Block;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.tag.TagKey;
import net.minecraft.util.Identifier;
/**
*
* @author jotty
*
*/
public class ModTags {
public static final class Blocks {
public static final TagKey<Block> SPEEDPOWDER_TOOL = createTag("speedpowder_tool");
public static final TagKey<Block> QUICKIEPOWDER_TOOL = createTag("quickiepowder_tool");
private static final TagKey<Block> createTag(String name) {
return TagKey.of(RegistryKeys.BLOCK, Identifier.of(Quickiemod.MOD_ID, name));
}
}
public static final class Items {
}
}

View File

@@ -0,0 +1,12 @@
{
"variants": {
"age=0": { "model": "quickiemod:block/canolaplant0" },
"age=1": { "model": "quickiemod:block/canolaplant1" },
"age=2": { "model": "quickiemod:block/canolaplant2" },
"age=3": { "model": "quickiemod:block/canolaplant3" },
"age=4": { "model": "quickiemod:block/canolaplant4" },
"age=5": { "model": "quickiemod:block/canolaplant5" },
"age=6": { "model": "quickiemod:block/canolaplant6" },
"age=7": { "model": "quickiemod:block/canolaplant7" }
}
}

View File

@@ -0,0 +1,12 @@
{
"variants": {
"age=0": { "model": "quickiemod:block/cottonplant0" },
"age=1": { "model": "quickiemod:block/cottonplant1" },
"age=2": { "model": "quickiemod:block/cottonplant2" },
"age=3": { "model": "quickiemod:block/cottonplant3" },
"age=4": { "model": "quickiemod:block/cottonplant4" },
"age=5": { "model": "quickiemod:block/cottonplant5" },
"age=6": { "model": "quickiemod:block/cottonplant6" },
"age=7": { "model": "quickiemod:block/cottonplant7" }
}
}

View File

@@ -0,0 +1,7 @@
{
"variants": {
"": {
"model": "quickiemod:block/blocksalpeter"
}
}
}

View File

@@ -0,0 +1,7 @@
{
"variants": {
"": {
"model": "quickiemod:block/blockstackerdown"
}
}
}

View File

@@ -0,0 +1,7 @@
{
"variants": {
"": {
"model": "quickiemod:block/blockstackereast"
}
}
}

View File

@@ -0,0 +1,7 @@
{
"variants": {
"": {
"model": "quickiemod:block/blockstackernorth"
}
}
}

View File

@@ -0,0 +1,7 @@
{
"variants": {
"": {
"model": "quickiemod:block/blockstackersouth"
}
}
}

View File

@@ -0,0 +1,7 @@
{
"variants": {
"": {
"model": "quickiemod:block/blockstackerup"
}
}
}

View File

@@ -0,0 +1,7 @@
{
"variants": {
"": {
"model": "quickiemod:block/blockstackerwest"
}
}
}

View File

@@ -0,0 +1,7 @@
{
"variants": {
"": {
"model": "quickiemod:block/blocksulphor"
}
}
}

View File

@@ -0,0 +1,7 @@
{
"variants": {
"": {
"model": "quickiemod:block/dirtsalpeter"
}
}
}

View File

@@ -0,0 +1,7 @@
{
"variants": {
"": {
"model": "quickiemod:block/drill"
}
}
}

View File

@@ -0,0 +1,7 @@
{
"variants": {
"": {
"model": "quickiemod:block/drilleast"
}
}
}

View File

@@ -0,0 +1,7 @@
{
"variants": {
"": {
"model": "quickiemod:block/drillnorth"
}
}
}

View File

@@ -0,0 +1,7 @@
{
"variants": {
"": {
"model": "quickiemod:block/drillsouth"
}
}
}

View File

@@ -0,0 +1,7 @@
{
"variants": {
"": {
"model": "quickiemod:block/drillwest"
}
}
}

View File

@@ -0,0 +1,7 @@
{
"variants": {
"": {
"model": "quickiemod:block/emptylavahoarder"
}
}
}

View File

@@ -0,0 +1,7 @@
{
"variants": {
"": {
"model": "quickiemod:block/itemhoarder"
}
}
}

View File

@@ -0,0 +1,7 @@
{
"variants": {
"": {
"model": "quickiemod:block/kelpstack"
}
}
}

View File

@@ -0,0 +1,7 @@
{
"variants": {
"": {
"model": "quickiemod:block/lavahoarder"
}
}
}

View File

@@ -0,0 +1,7 @@
{
"variants": {
"": {
"model": "quickiemod:block/monsterhoarder"
}
}
}

View File

@@ -0,0 +1,7 @@
{
"variants": {
"": {
"model": "quickiemod:block/oredeepslatesulphor"
}
}
}

View File

@@ -0,0 +1,7 @@
{
"variants": {
"": {
"model": "quickiemod:block/orenethersulphor"
}
}
}

View File

@@ -0,0 +1,7 @@
{
"variants": {
"": {
"model": "quickiemod:block/oresalpeter"
}
}
}

View File

@@ -0,0 +1,7 @@
{
"variants": {
"": {
"model": "quickiemod:block/oresandsalpeter"
}
}
}

View File

@@ -0,0 +1,7 @@
{
"variants": {
"": {
"model": "quickiemod:block/oresulphor"
}
}
}

View File

@@ -0,0 +1,7 @@
{
"variants": {
"": {
"model": "quickiemod:block/sandsalpeter"
}
}
}

View File

@@ -69,8 +69,8 @@
"block.quickiemod.itemhoarder": "Itemsauger", "block.quickiemod.itemhoarder": "Itemsauger",
"block.quickiemod.monsterhoarder": "Monstersauger", "block.quickiemod.monsterhoarder": "Monstersauger",
"block.quickiemod.kelpstack": "Seegrassbündel", "block.quickiemod.kelpstack": "Seegrassbündel",
"block.quickiemod.cottonplant": "Baumwollpflanze", "block.quickiemod.blockcottonplant": "Baumwollpflanze",
"block.quickiemod.canolaplant": "Canolapflanze", "block.quickiemod.blockcanolaplant": "Canolapflanze",
"block.quickiemod.blocksulphor": "Schwefelblock", "block.quickiemod.blocksulphor": "Schwefelblock",
"block.quickiemod.blocksalpeter": "Salpeterblock", "block.quickiemod.blocksalpeter": "Salpeterblock",
"block.quickiemod.blockspeedpowder": "Fluchtpulverblock", "block.quickiemod.blockspeedpowder": "Fluchtpulverblock",
@@ -103,6 +103,7 @@
"msg.buildingplan.failonblock": "Der Bau wurde abgelehnt, es ist im Weg: %s", "msg.buildingplan.failonblock": "Der Bau wurde abgelehnt, es ist im Weg: %s",
"msg.buildingplan.failonplayer": "Der Bau wurde abgelehnt, um Spieler %s nicht zu gefährden.", "msg.buildingplan.failonplayer": "Der Bau wurde abgelehnt, um Spieler %s nicht zu gefährden.",
"msg.itemhoarder.summary": "Der Itemsauger enthält: %s", "msg.itemhoarder.summary": "Der Itemsauger enthält: %s",
"msg.monsterhoarder.size": "Der Radius für diesen Monstersauger beträgt jetzt %d.",
"msg.notyetimplemented": "leider noch nicht verfügbar", "msg.notyetimplemented": "leider noch nicht verfügbar",
"msg.backpack.transfer.filled": "Der Rucksack wurde befüllt.", "msg.backpack.transfer.filled": "Der Rucksack wurde befüllt.",
"msg.backpack.transfer.cleared": "Der Rucksackinhalt wurde soweit möglich geleert.", "msg.backpack.transfer.cleared": "Der Rucksackinhalt wurde soweit möglich geleert.",

View File

@@ -69,8 +69,8 @@
"block.quickiemod.itemhoarder": "item hoarder", "block.quickiemod.itemhoarder": "item hoarder",
"block.quickiemod.monsterhoarder": "monster hoarder", "block.quickiemod.monsterhoarder": "monster hoarder",
"block.quickiemod.kelpstack": "kelp bundle", "block.quickiemod.kelpstack": "kelp bundle",
"block.quickiemod.cottonplant": "cotton plant", "block.quickiemod.blockcottonplant": "cotton plant",
"block.quickiemod.canolaplant": "canola plant", "block.quickiemod.blockcanolaplant": "canola plant",
"block.quickiemod.blocksulphor": "block of sulfur", "block.quickiemod.blocksulphor": "block of sulfur",
"block.quickiemod.blocksalpeter": "block of salpeter", "block.quickiemod.blocksalpeter": "block of salpeter",
"block.quickiemod.blockspeedpowder": "block of speedpowder", "block.quickiemod.blockspeedpowder": "block of speedpowder",
@@ -103,6 +103,7 @@
"msg.buildingplan.failonblock": "The building execution was rejected because of %s", "msg.buildingplan.failonblock": "The building execution was rejected because of %s",
"msg.buildingplan.failonplayer": "The building execution was rejected because of %s who could be injured.", "msg.buildingplan.failonplayer": "The building execution was rejected because of %s who could be injured.",
"msg.itemhoarder.summary": "The item hoarder contains: %s", "msg.itemhoarder.summary": "The item hoarder contains: %s",
"msg.monsterhoarder.size": "The radius for this monster hoarder is %d from now on.",
"msg.notyetimplemented": "not yet implemented", "msg.notyetimplemented": "not yet implemented",
"msg.backpack.transfer.filled": "Filled the backpack.", "msg.backpack.transfer.filled": "Filled the backpack.",
"msg.backpack.transfer.cleared": "Cleared the backpack as much as possible.", "msg.backpack.transfer.cleared": "Cleared the backpack as much as possible.",

View File

@@ -0,0 +1,6 @@
{
"parent": "block/cube_all",
"textures": {
"all": "quickiemod:block/blocksalpeter"
}
}

View File

@@ -0,0 +1,8 @@
{
"parent": "minecraft:block/cube_bottom_top",
"textures": {
"bottom": "quickiemod:block/blockstackerout",
"side": "quickiemod:block/blockstackerdown",
"top": "quickiemod:block/blockstackerin"
}
}

View File

@@ -0,0 +1,11 @@
{
"parent": "block/cube_directional",
"textures": {
"up": "quickiemod:block/blockstackerright",
"down": "quickiemod:block/blockstackerleft",
"north": "quickiemod:block/blockstackerleft",
"east": "quickiemod:block/blockstackerout",
"south": "quickiemod:block/blockstackerright",
"west": "quickiemod:block/blockstackerin"
}
}

View File

@@ -0,0 +1,11 @@
{
"parent": "block/cube_directional",
"textures": {
"up": "quickiemod:block/blockstackerup",
"down": "quickiemod:block/blockstackerup",
"north": "quickiemod:block/blockstackerout",
"east": "quickiemod:block/blockstackerup",
"south": "quickiemod:block/blockstackerin",
"west": "quickiemod:block/blockstackerup"
}
}

View File

@@ -0,0 +1,11 @@
{
"parent": "block/cube_directional",
"textures": {
"up": "quickiemod:block/blockstackerdown",
"down": "quickiemod:block/blockstackerdown",
"north": "quickiemod:block/blockstackerin",
"east": "quickiemod:block/blockstackerdown",
"south": "quickiemod:block/blockstackerout",
"west": "quickiemod:block/blockstackerdown"
}
}

View File

@@ -0,0 +1,8 @@
{
"parent": "block/cube_bottom_top",
"textures": {
"bottom": "quickiemod:block/blockstackerin",
"side": "quickiemod:block/blockstackerup",
"top": "quickiemod:block/blockstackerout"
}
}

View File

@@ -0,0 +1,11 @@
{
"parent": "block/cube_directional",
"textures": {
"up": "quickiemod:block/blockstackerleft",
"down": "quickiemod:block/blockstackerright",
"north": "quickiemod:block/blockstackerright",
"east": "quickiemod:block/blockstackerin",
"south": "quickiemod:block/blockstackerleft",
"west": "quickiemod:block/blockstackerout"
}
}

View File

@@ -0,0 +1,6 @@
{
"parent": "block/cube_all",
"textures": {
"all": "quickiemod:block/blocksulphor"
}
}

View File

@@ -0,0 +1,6 @@
{
"parent":"block/cross",
"textures":{
"cross":"quickiemod:block/canolaplant0"
}
}

View File

@@ -0,0 +1,6 @@
{
"parent":"block/cross",
"textures":{
"cross":"quickiemod:block/canolaplant1"
}
}

View File

@@ -0,0 +1,6 @@
{
"parent":"block/cross",
"textures":{
"cross":"quickiemod:block/canolaplant2"
}
}

View File

@@ -0,0 +1,6 @@
{
"parent":"block/cross",
"textures":{
"cross":"quickiemod:block/canolaplant3"
}
}

View File

@@ -0,0 +1,6 @@
{
"parent":"block/cross",
"textures":{
"cross":"quickiemod:block/canolaplant4"
}
}

View File

@@ -0,0 +1,6 @@
{
"parent":"block/cross",
"textures":{
"cross":"quickiemod:block/canolaplant5"
}
}

View File

@@ -0,0 +1,6 @@
{
"parent":"block/cross",
"textures":{
"cross":"quickiemod:block/canolaplant6"
}
}

View File

@@ -0,0 +1,6 @@
{
"parent":"block/cross",
"textures":{
"cross":"quickiemod:block/canolaplant7"
}
}

View File

@@ -0,0 +1,6 @@
{
"parent":"block/cross",
"textures":{
"cross":"quickiemod:block/cottonplant0"
}
}

Some files were not shown because too many files have changed in this diff Show More