19 Commits

Author SHA1 Message Date
7a9021790f added quickiepowder shears 2025-06-20 23:17:35 +02:00
b9ae4bcd52 switched to 1.21.6 2025-06-18 22:58:37 +02:00
c06c231dce added item stub slash action 2025-05-03 15:49:53 +02:00
2fedfdc700 first 1.21.5 version 2025-03-29 22:12:42 +01:00
17a11ce56a fixed exception on too many items in a slot 2025-02-08 17:27:49 +01:00
81e45c56ce fixes drill harvesting bug - drills can be mined again 2024-12-15 15:01:18 +01:00
c2558a5324 added recipe for quickiepowder generation out of mossy blocks 2024-12-14 19:11:06 +01:00
46a21b03c0 fixed block breaking bug 2024-12-12 23:18:34 +01:00
4ae1e998b0 fixes bug with recreation of block 2024-12-11 22:37:52 +01:00
06db4df2cb version 1.21.4 2024-12-04 00:55:58 +01:00
0c744ef52b fixed bug on using rangeable tools 2024-12-01 00:05:36 +01:00
4c5dea1756 upgrade to 1.21.3 2024-11-30 18:50:09 +01:00
0079c721cc 1.21.1 support 2024-08-11 18:56:15 +02:00
7e299caed0 using all chests for recipes instead of standard chest only 2024-07-23 09:32:25 +02:00
0338c7c5ef added block stacker without gui 2024-06-28 21:51:16 +02:00
72b9c7dece fixed recipes, working tools 2024-06-15 14:45:22 +02:00
caef9eed83 upgraded to minecraft 2.21 2024-06-14 20:07:34 +02:00
9f869668c9 added speedpowder shears 2024-06-13 20:41:32 +02:00
cc17c5b0c5 added speed powder shears 2024-06-13 20:33:20 +02:00
332 changed files with 4629 additions and 2564 deletions

View File

@ -12,11 +12,7 @@
<attribute name="gradle_used_by_scope" value="main,test"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-21/"/>
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
<classpathentry kind="output" path="bin/default"/>
</classpath>

View File

@ -1,5 +1,5 @@
#
#Sat Jun 01 10:37:20 CEST 2024
#Mon Jun 24 21:17:32 CEST 2024
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=21

View File

@ -1,5 +1,5 @@
plugins {
id 'fabric-loom' version '1.6-SNAPSHOT'
id 'fabric-loom' version '1.10-SNAPSHOT'
id 'maven-publish'
}

View File

@ -4,14 +4,14 @@ org.gradle.parallel=true
# Fabric Properties
# check these on https://fabricmc.net/develop
minecraft_version=1.20.6
yarn_mappings=1.20.6+build.3
loader_version=0.15.11
minecraft_version=1.21.6
yarn_mappings=1.21.6+build.1
loader_version=0.16.14
# Mod Properties
mod_version=1.20.6.0
mod_version=1.21.6.1
maven_group=de.jottyfan.quickiemod
archives_base_name=quickiemod
# Dependencies
fabric_version=0.100.0+1.20.6
fabric_version=0.127.1+1.21.6

View File

@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME

7
gradlew vendored
View File

@ -15,6 +15,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
#
##############################################################################
#
@ -55,7 +57,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
@ -84,7 +86,8 @@ done
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
' "$PWD" ) || exit
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum

2
gradlew.bat vendored
View File

@ -13,6 +13,8 @@
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@rem SPDX-License-Identifier: Apache-2.0
@rem
@if "%DEBUG%"=="" @echo off
@rem ##########################################################################

View File

@ -1,28 +0,0 @@
package de.jottyfan.quickiemod;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import de.jottyfan.quickiemod.init.RegistryManager;
import net.fabricmc.api.ModInitializer;
/**
*
* @author jotty
*
*/
public class QuickieMod implements ModInitializer {
public static final String MODID = "quickiemod";
private static final Logger LOGGER = LoggerFactory.getLogger(MODID);
@Override
public void onInitialize() {
LOGGER.info("loading {}", MODID);
RegistryManager.registerBlockEntityTypes();
RegistryManager.registerItems();
RegistryManager.registerBlocks();
RegistryManager.registerFeatures();
RegistryManager.registerItemGroup();
}
}

View File

@ -1,22 +0,0 @@
package de.jottyfan.quickiemod;
import de.jottyfan.quickiemod.blocks.QuickieBlocks;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap;
import net.minecraft.client.render.RenderLayer;
/**
*
* @author jotty
*
*/
@Environment(EnvType.CLIENT)
public class QuickieModClient implements ClientModInitializer {
@Override
public void onInitializeClient() {
BlockRenderLayerMap.INSTANCE.putBlock(QuickieBlocks.COTTONPLANT.getBlock(), RenderLayer.getCutout());
BlockRenderLayerMap.INSTANCE.putBlock(QuickieBlocks.CANOLAPLANT.getBlock(), RenderLayer.getCutout());
}
}

View File

@ -0,0 +1,77 @@
package de.jottyfan.quickiemod;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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.itemgroup.ModItemGroup;
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.item.Item;
import net.minecraft.item.Items;
import net.minecraft.loot.LootPool;
import net.minecraft.loot.condition.SurvivesExplosionLootCondition;
import net.minecraft.loot.entry.ItemEntry;
/**
*
* @author jotty
*
*/
public class Quickiemod implements ModInitializer {
public static final String MOD_ID = "quickiemod";
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
public void onInitialize() {
ModBlockentity.registerModBlockentities();
List<Item> items = ModItems.registerModItems();
List<Block> blocks = ModBlocks.registerModBlocks();
ModFeatures.registerFeatures();
registerComposterItems();
registerLootTableChanges();
ModItemGroup.registerItemGroup(items, blocks);
PlayerBlockBreakEvents.BEFORE.register((world, player, pos, state, blockEntity) -> {
Block oldBlock = state.getBlock();
if (new EventBlockBreak().doBreakBlock(world, pos, state, player, oldBlock)) {
return false;
} else {
return true;
}
});
}
}

View File

@ -0,0 +1,20 @@
package de.jottyfan.quickiemod;
import de.jottyfan.quickiemod.block.ModBlocks;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.rendering.v1.BlockRenderLayerMap;
import net.minecraft.client.render.BlockRenderLayer;
/**
*
* @author jotty
*
*/
public class QuickiemodClient implements ClientModInitializer {
@Override
public void onInitializeClient() {
BlockRenderLayerMap.putBlock(ModBlocks.BLOCK_COTTONPLANT, BlockRenderLayer.CUTOUT);
BlockRenderLayerMap.putBlock(ModBlocks.BLOCK_CANOLAPLANT, BlockRenderLayer.CUTOUT);
}
}

View File

@ -1,8 +1,5 @@
package de.jottyfan.quickiemod;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import net.fabricmc.fabric.api.datagen.v1.DataGeneratorEntrypoint;
import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator;
@ -11,13 +8,10 @@ import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator;
* @author jotty
*
*/
public class QuickieModDataGenerator implements DataGeneratorEntrypoint {
private static final Logger LOGGER = LoggerFactory.getLogger(QuickieMod.MODID);
public class QuickiemodDataGenerator implements DataGeneratorEntrypoint {
@Override
public void onInitializeDataGenerator(FabricDataGenerator fabricDataGenerator) {
// TODO: implement
LOGGER.debug("initializing data generator");
}
}

View File

@ -0,0 +1,25 @@
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.util.Identifier;
/**
*
* @author jotty
*
*/
public abstract class AbstractIdentifiedBlock extends Block {
public AbstractIdentifiedBlock(Identifier 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

@ -1,16 +1,15 @@
package de.jottyfan.quickiemod.blocks;
package de.jottyfan.quickiemod.block;
import java.util.Arrays;
import java.util.List;
import com.mojang.serialization.MapCodec;
import de.jottyfan.quickiemod.items.QuickieItems;
import net.minecraft.block.AbstractBlock;
import net.minecraft.block.BlockState;
import net.minecraft.block.FallingBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.loot.context.LootContextParameterSet.Builder;
import net.minecraft.loot.context.LootWorldContext.Builder;
import net.minecraft.util.Identifier;
import net.minecraft.world.explosion.Explosion;
/**
@ -18,15 +17,19 @@ import net.minecraft.world.explosion.Explosion;
* @author jotty
*
*/
public class BlockSpeedpowder extends FallingBlock {
public class BlockBreakByTool extends AbstractIdentifiedBlock {
public BlockSpeedpowder() {
super(AbstractBlock.Settings.create().luminance(state -> 12));
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(new ItemStack[] { new ItemStack(QuickieItems.SPEEDPOWDER.getItem(), 9) });
return Arrays.asList(drops);
}
@Override

View File

@ -1,4 +1,4 @@
package de.jottyfan.quickiemod.blocks;
package de.jottyfan.quickiemod.block;
import java.util.Arrays;
import java.util.List;
@ -6,14 +6,19 @@ import java.util.Random;
import com.mojang.serialization.MapCodec;
import de.jottyfan.quickiemod.items.QuickieItems;
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.LootContextParameterSet.Builder;
import net.minecraft.loot.context.LootWorldContext.Builder;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.BlockView;
/**
*
@ -22,8 +27,8 @@ import net.minecraft.loot.context.LootContextParameterSet.Builder;
*/
public class BlockDirtSalpeter extends FallingBlock {
public BlockDirtSalpeter() {
super(AbstractBlock.Settings.create().hardness(3.1f));
public BlockDirtSalpeter(Identifier identifier) {
super(AbstractBlock.Settings.create().hardness(3.1f).registryKey(RegistryKey.of(RegistryKeys.BLOCK, identifier)));
}
@Override
@ -31,7 +36,7 @@ public class BlockDirtSalpeter extends FallingBlock {
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(QuickieItems.SALPETER.getItem(), count);
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 };
@ -40,7 +45,11 @@ public class BlockDirtSalpeter extends FallingBlock {
@Override
protected MapCodec<? extends FallingBlock> getCodec() {
// TODO Auto-generated method stub
return null;
}
@Override
public int getColor(BlockState state, BlockView world, BlockPos pos) {
return 0;
}
}

View File

@ -0,0 +1,131 @@
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.BlockView;
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(0.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);
Direction dir = state.get(DIRECTION);
world.spawnEntity(
new ItemEntity(world, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(ModItems.ITEM_CANOLABOTTLE, fuelLeft)));
Block thisBlock = ModBlocks.BLOCK_DRILL_DOWN;
if (Direction.EAST.equals(dir)) {
thisBlock = ModBlocks.BLOCK_DRILL_EAST;
} else if (Direction.SOUTH.equals(dir)) {
thisBlock = ModBlocks.BLOCK_DRILL_SOUTH;
} else if (Direction.WEST.equals(dir)) {
thisBlock = ModBlocks.BLOCK_DRILL_WEST;
} else if (Direction.NORTH.equals(dir)) {
thisBlock = ModBlocks.BLOCK_DRILL_NORTH;
}
world.spawnEntity(new ItemEntity(world, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(thisBlock)));
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;
}
@Override
public int getColor(BlockState state, BlockView world, BlockPos pos) {
return 0;
}
}

View File

@ -1,4 +1,4 @@
package de.jottyfan.quickiemod.blocks;
package de.jottyfan.quickiemod.block;
import java.util.ArrayList;
import java.util.HashSet;
@ -6,50 +6,57 @@ import java.util.List;
import java.util.Random;
import java.util.Set;
import de.jottyfan.quickiemod.blockentity.EmptyLavaHoarderBlockEntity;
import net.minecraft.block.AbstractBlock;
import net.minecraft.block.Block;
import net.minecraft.block.BlockEntityProvider;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.BlockEntityTicker;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.entity.ExperienceOrbEntity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.loot.context.LootContextParameterSet.Builder;
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 implements BlockEntityProvider {
public class BlockEmptyLavahoarder extends Block {
public BlockEmptyLavahoarder() {
super(AbstractBlock.Settings.create().hardness(2.5f));
}
@Override
public BlockEntity createBlockEntity(BlockPos pos, BlockState blockState) {
return new EmptyLavaHoarderBlockEntity(pos, blockState);
}
@Override
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(World world, BlockState state, BlockEntityType<T> type){
return (world1, pos, state1, be) -> EmptyLavaHoarderBlockEntity.tick(world1, pos, state1, be);
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(QuickieBlocks.EMPTYLAVAHOARDER.getBlock()));
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(":");
@ -106,7 +113,8 @@ public class BlockEmptyLavahoarder extends Block implements BlockEntityProvider
world.setBlockState(blockPosOf(p), Blocks.AIR.getDefaultState());
}
if (amount > 0) {
world.setBlockState(pos, QuickieBlocks.LAVAHOARDER.getBlock().getDefaultState());
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++) {
@ -116,9 +124,12 @@ public class BlockEmptyLavahoarder extends Block implements BlockEntityProvider
}
BlockPos up = pos.up();
if (count > 0) {
EmptyLavaHoarderBlockEntity.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));
}
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

@ -1,4 +1,4 @@
package de.jottyfan.quickiemod.blocks;
package de.jottyfan.quickiemod.block;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
@ -16,11 +16,14 @@ 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.LootContextParameterSet.Builder;
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;
@ -33,8 +36,8 @@ import net.minecraft.world.World;
*/
public class BlockItemhoarder extends Block implements BlockEntityProvider {
public BlockItemhoarder() {
super(AbstractBlock.Settings.create().hardness(2.5f));
public BlockItemhoarder(Identifier identifier) {
super(AbstractBlock.Settings.create().hardness(2.5f).registryKey(RegistryKey.of(RegistryKeys.BLOCK, identifier)));
}
@Override
@ -56,7 +59,7 @@ public class BlockItemhoarder extends Block implements BlockEntityProvider {
@Override
public List<ItemStack> getDroppedStacks(BlockState state, Builder builder) {
List<ItemStack> list = new ArrayList<>();
list.add(new ItemStack(QuickieBlocks.ITEMHOARDER.getBlock()));
list.add(new ItemStack(ModBlocks.BLOCK_ITEMHOARDER));
return list;
}

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", 2, 20);
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

@ -1,28 +1,41 @@
package de.jottyfan.quickiemod.blocks;
package de.jottyfan.quickiemod.block;
import java.util.List;
import java.util.Random;
import de.jottyfan.quickiemod.items.QuickieItems;
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.LootContextParameterSet.Builder;
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;
public class BlockCottonplant extends CropBlock {
/**
*
* @author jotty
*
*/
public class BlockPlant extends CropBlock {
public BlockCottonplant() {
super(AbstractBlock.Settings.copy(Blocks.WHEAT));
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
@ -31,7 +44,7 @@ public class BlockCottonplant extends CropBlock {
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(QuickieItems.COTTON.getItem(), new Random().nextFloat() > 0.9f ? 2 : 1));
list.add(new ItemStack(fruit, new Random().nextFloat() > 0.9f ? 2 : 1));
}
return list;
}
@ -52,7 +65,7 @@ public class BlockCottonplant extends CropBlock {
@Override
protected ItemConvertible getSeedsItem() {
return QuickieItems.COTTONSEED.getItem();
return seed;
}
@Override

View File

@ -0,0 +1,55 @@
package de.jottyfan.quickiemod.block;
import java.util.Arrays;
import java.util.List;
import com.mojang.serialization.MapCodec;
import net.minecraft.block.AbstractBlock;
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.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.BlockView;
import net.minecraft.world.explosion.Explosion;
/**
*
* @author jotty
*
*/
public class BlockPowder extends FallingBlock {
private final ItemStack[] drops;
public BlockPowder(Identifier identifier, ItemStack[] drops) {
super(AbstractBlock.Settings.create().luminance(state -> 12).registryKey(RegistryKey.of(RegistryKeys.BLOCK, identifier)));
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;
}
@Override
public int getColor(BlockState state, BlockView world, BlockPos pos) {
// TODO Auto-generated method stub
return 0;
}
}

View File

@ -0,0 +1,51 @@
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.BlockPos;
import net.minecraft.util.math.random.Random;
import net.minecraft.world.BlockView;
/**
*
* @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;
}
@Override
public int getColor(BlockState state, BlockView world, BlockPos pos) {
// TODO Auto-generated method stub
return 0;
}
}

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,118 @@
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.server.world.ServerWorld;
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
protected void onStateReplaced(BlockState state, ServerWorld world, BlockPos pos, boolean moved) {
if (state.getBlock() != world.getBlockState(pos).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, 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

@ -0,0 +1,132 @@
package de.jottyfan.quickiemod.block;
import java.util.ArrayList;
import java.util.List;
import de.jottyfan.quickiemod.Quickiemod;
import de.jottyfan.quickiemod.identifier.ModIdentifiers;
import de.jottyfan.quickiemod.item.ModItems;
import net.minecraft.block.Block;
import net.minecraft.item.BlockItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
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.Direction;
/**
*
* @author jotty
*
*/
public class ModBlocks {
public static final Block BLOCK_QUICKIEPOWDER = registerBlock(ModIdentifiers.BLOCK_QUICKIEPOWDER, new BlockPowder(
ModIdentifiers.BLOCK_QUICKIEPOWDER, new ItemStack[] { new ItemStack(ModItems.ITEM_QUICKIEPOWDER, 9) }));
public static final Block BLOCK_SPEEDPOWDER = registerBlock(ModIdentifiers.BLOCK_SPEEDPOWDER, new BlockPowder(
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) {
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()
.registryKey(RegistryKey.of(RegistryKeys.ITEM, identifier)).useBlockPrefixedTranslationKey()));
}
return Registry.register(Registries.BLOCK, identifier, block);
}
public static final List<Block> registerModBlocks() {
Quickiemod.LOGGER.info(String.format("registering blocks for %s", Quickiemod.MOD_ID));
List<Block> blocks = new ArrayList<>();
blocks.add(BLOCK_QUICKIEPOWDER);
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;
}
}

View File

@ -0,0 +1,16 @@
package de.jottyfan.quickiemod.block;
import net.minecraft.util.Identifier;
/**
*
* @author jotty
*
*/
public class StandardBlock extends AbstractIdentifiedBlock {
public StandardBlock(Identifier identifier) {
super(identifier);
}
}

View File

@ -1,4 +1,4 @@
package de.jottyfan.quickiemod.blocks.help;
package de.jottyfan.quickiemod.block.help;
import net.minecraft.util.math.intprovider.IntProvider;
import net.minecraft.util.math.intprovider.IntProviderType;

View File

@ -1,32 +0,0 @@
package de.jottyfan.quickiemod.blockentity;
import de.jottyfan.quickiemod.blocks.QuickieBlocks;
import de.jottyfan.quickiemod.init.BlockEntityIdentity;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
/**
*
* @author jotty
*
*/
public class BlockEntityTypes {
public static final BlockEntityType<EmptyLavaHoarderBlockEntity> EMPTYLAVAHOARDER = Registry.register(Registries.BLOCK_ENTITY_TYPE,
BlockEntityIdentity.EMPTYLAVALHOARDER, BlockEntityType.Builder
.create(EmptyLavaHoarderBlockEntity::new, QuickieBlocks.EMPTYLAVAHOARDER.getBlock(), QuickieBlocks.LAVAHOARDER.getBlock()).build(null));
public static final BlockEntityType<ItemHoarderBlockEntity> ITEMHOARDER = Registry.register(Registries.BLOCK_ENTITY_TYPE, BlockEntityIdentity.ITEMHOARDER,
BlockEntityType.Builder.create(ItemHoarderBlockEntity::new, QuickieBlocks.ITEMHOARDER.getBlock()).build(null));
public static final BlockEntityType<MonsterHoarderBlockEntity> MONSTERHOARDER = Registry.register(Registries.BLOCK_ENTITY_TYPE,
BlockEntityIdentity.MONSTERHOARDER, BlockEntityType.Builder.create(MonsterHoarderBlockEntity::new, QuickieBlocks.MONSTERHOARDER.getBlock()).build(null));
public static final BlockEntityType<DrillBlockDownEntity> DRILL_DOWN = Registry.register(Registries.BLOCK_ENTITY_TYPE, BlockEntityIdentity.DRILL_DOWN,
BlockEntityType.Builder.create(DrillBlockDownEntity::new, QuickieBlocks.DRILL_DOWN.getBlock()).build(null));
public static final BlockEntityType<DrillBlockEastEntity> DRILL_EAST = Registry.register(Registries.BLOCK_ENTITY_TYPE, BlockEntityIdentity.DRILL_EAST,
BlockEntityType.Builder.create(DrillBlockEastEntity::new, QuickieBlocks.DRILL_EAST.getBlock()).build(null));
public static final BlockEntityType<DrillBlockSouthEntity> DRILL_SOUTH = Registry.register(Registries.BLOCK_ENTITY_TYPE, BlockEntityIdentity.DRILL_SOUTH,
BlockEntityType.Builder.create(DrillBlockSouthEntity::new, QuickieBlocks.DRILL_SOUTH.getBlock()).build(null));
public static final BlockEntityType<DrillBlockWestEntity> DRILL_WEST = Registry.register(Registries.BLOCK_ENTITY_TYPE, BlockEntityIdentity.DRILL_WEST,
BlockEntityType.Builder.create(DrillBlockWestEntity::new, QuickieBlocks.DRILL_WEST.getBlock()).build(null));
public static final BlockEntityType<DrillBlockNorthEntity> DRILL_NORTH = Registry.register(Registries.BLOCK_ENTITY_TYPE, BlockEntityIdentity.DRILL_NORTH,
BlockEntityType.Builder.create(DrillBlockNorthEntity::new, QuickieBlocks.DRILL_NORTH.getBlock()).build(null));
}

View File

@ -1,64 +0,0 @@
package de.jottyfan.quickiemod.blockentity;
import java.util.ArrayList;
import java.util.List;
import de.jottyfan.quickiemod.blocks.QuickieBlocks;
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.LivingEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.loot.context.LootContextParameterSet.Builder;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvents;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
/**
*
* @author jotty
*
*/
public class BlockMonsterhoarder extends Block implements BlockEntityProvider {
public BlockMonsterhoarder() {
super(AbstractBlock.Settings.create().hardness(2.5f).luminance(state -> 15));
}
@Override
public BlockEntity createBlockEntity(BlockPos pos, BlockState blockState) {
return new MonsterHoarderBlockEntity(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) -> MonsterHoarderBlockEntity.tick(world1, pos, state1, be);
}
@Override
public List<ItemStack> getDroppedStacks(BlockState state, Builder builder) {
List<ItemStack> list = new ArrayList<>();
list.add(new ItemStack(QuickieBlocks.MONSTERHOARDER.getBlock()));
return list;
}
@Override
public void onPlaced(World world, BlockPos pos, BlockState state, LivingEntity placer, ItemStack itemStack) {
if (!world.isClient) {
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,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.screen.NamedScreenHandlerFactory;
import net.minecraft.screen.ScreenHandler;
import net.minecraft.storage.ReadView;
import net.minecraft.storage.WriteView;
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 readData(ReadView view) {
super.readData(view);
Inventories.readData(view, inventory);
}
@Override
protected void writeData(WriteView view) {
Inventories.writeData(view, inventory);
super.writeData(view);
}
/**
* 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

@ -1,62 +0,0 @@
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.util.math.BlockPos;
import net.minecraft.world.World;
/**
*
* @author jotty
*
*/
public class DrillBlockDownEntity extends DrillBlockEntity {
private static final Integer MAXDRILLSTEP = 20;
public DrillBlockDownEntity(BlockPos pos, BlockState state) {
super(BlockEntityTypes.DRILL_DOWN, pos, state, MAXDRILLSTEP);
}
public static void tick(World world, BlockPos pos, BlockState state, BlockEntity be) {
if (be instanceof DrillBlockDownEntity) {
DrillBlockDownEntity dbe = (DrillBlockDownEntity) be;
DrillBlockEntity.tick(world, pos, state, dbe, MAXDRILLSTEP, generateBlockPos(pos));
}
}
public static final List<BlockPos> generateBlockPos(BlockPos pos) {
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;
}
}

View File

@ -1,36 +0,0 @@
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.util.math.BlockPos;
import net.minecraft.world.World;
/**
*
* @author jotty
*
*/
public class DrillBlockEastEntity extends DrillBlockEntity {
private static final Integer MAXDRILLSTEP = 24;
public DrillBlockEastEntity(BlockPos pos, BlockState state) {
super(BlockEntityTypes.DRILL_EAST, pos, state, MAXDRILLSTEP);
}
public static void tick(World world, BlockPos pos, BlockState state, BlockEntity be) {
if (be instanceof DrillBlockEastEntity) {
DrillBlockEastEntity dbe = (DrillBlockEastEntity) be;
List<BlockPos> list = new ArrayList<>();
list.add(pos.east());
list.add(pos.east().up());
list.add(pos.east().up().up());
list.add(pos.east().up().up().up());
list.add(pos.east().down()); // must be last position
DrillBlockEntity.tick(world, pos, state, dbe, MAXDRILLSTEP, list);
}
}
}

View File

@ -1,23 +1,94 @@
package de.jottyfan.quickiemod.blockentity;
import java.util.ArrayList;
import java.util.List;
import de.jottyfan.quickiemod.blocks.QuickieBlocks;
import de.jottyfan.quickiemod.blocks.help.DrillBlock;
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.block.entity.BlockEntityType;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.World;
public abstract class DrillBlockEntity extends BlockEntity {
/**
*
* @author jotty
*
*/
public class DrillBlockEntity extends BlockEntity {
private static final Integer MAXDRILLSTEP = 20;
private Integer drillstep;
private final Integer maxDrillStep;
public DrillBlockEntity(BlockEntityType<?> type, BlockPos pos, BlockState state, Integer maxDrillStep) {
super(type, pos, state);
this.maxDrillStep = 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) {
@ -25,9 +96,8 @@ public abstract class DrillBlockEntity extends BlockEntity {
BlockState bs = world.getBlockState(from);
if (be != null) {
world.setBlockState(from, Blocks.AIR.getDefaultState());
Integer newFuel = bs.get(DrillBlock.FUEL) - 1;
world.setBlockState(to, bs.with(DrillBlock.FUEL, newFuel));
world.addBlockEntity(be);
Integer newFuel = bs.get(BlockDrill.FUEL) - 1;
world.setBlockState(to, bs.with(BlockDrill.FUEL, newFuel));
world.removeBlockEntity(from);
}
}
@ -35,11 +105,11 @@ public abstract class DrillBlockEntity extends BlockEntity {
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.getBlockState(to).isOf(QuickieBlocks.DRILLSTOP.getBlock())) {
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 or a drillstop
lastSuccess = false; // in case that the last one is a bedrock
}
}
return lastSuccess;
@ -47,7 +117,7 @@ public abstract class DrillBlockEntity extends BlockEntity {
public static void tick(World world, BlockPos pos, BlockState state, DrillBlockEntity be, Integer maxDrillStep,
List<BlockPos> drillPosition) {
if (state.get(DrillBlock.FUEL) > 0) {
if (state.get(BlockDrill.FUEL) > 0) {
if (be.getDrillstep() < 1) {
be.setDrillstep(maxDrillStep);
if (drill(pos, drillPosition, world)) {

View File

@ -1,36 +0,0 @@
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.util.math.BlockPos;
import net.minecraft.world.World;
/**
*
* @author jotty
*
*/
public class DrillBlockNorthEntity extends DrillBlockEntity {
private static final Integer MAXDRILLSTEP = 24;
public DrillBlockNorthEntity(BlockPos pos, BlockState state) {
super(BlockEntityTypes.DRILL_NORTH, pos, state, MAXDRILLSTEP);
}
public static void tick(World world, BlockPos pos, BlockState state, BlockEntity be) {
if (be instanceof DrillBlockNorthEntity) {
DrillBlockNorthEntity dbe = (DrillBlockNorthEntity) be;
List<BlockPos> list = new ArrayList<>();
list.add(pos.north());
list.add(pos.north().up());
list.add(pos.north().up().up());
list.add(pos.north().up().up().up());
list.add(pos.north().down()); // must be last position
DrillBlockEntity.tick(world, pos, state, dbe, MAXDRILLSTEP, list);
}
}
}

View File

@ -1,35 +0,0 @@
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.util.math.BlockPos;
import net.minecraft.world.World;
/**
*
* @author jotty
*
*/
public class DrillBlockSouthEntity extends DrillBlockEntity {
private static final Integer MAXDRILLSTEP = 24;
public DrillBlockSouthEntity(BlockPos pos, BlockState state) {
super(BlockEntityTypes.DRILL_SOUTH, pos, state, MAXDRILLSTEP);
}
public static void tick(World world, BlockPos pos, BlockState state, BlockEntity be) {
if (be instanceof DrillBlockSouthEntity) {
DrillBlockSouthEntity dbe = (DrillBlockSouthEntity) be;
List<BlockPos> list = new ArrayList<>();
list.add(pos.south());
list.add(pos.south().up());
list.add(pos.south().up().up());
list.add(pos.south().up().up().up());
list.add(pos.south().down()); // must be last position
DrillBlockEntity.tick(world, pos, state, dbe, MAXDRILLSTEP, list);
}
}
}

View File

@ -1,36 +0,0 @@
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.util.math.BlockPos;
import net.minecraft.world.World;
/**
*
* @author jotty
*
*/
public class DrillBlockWestEntity extends DrillBlockEntity {
private static final Integer MAXDRILLSTEP = 24;
public DrillBlockWestEntity(BlockPos pos, BlockState state) {
super(BlockEntityTypes.DRILL_WEST, pos, state, MAXDRILLSTEP);
}
public static void tick(World world, BlockPos pos, BlockState state, BlockEntity be) {
if (be instanceof DrillBlockWestEntity) {
DrillBlockWestEntity dbe = (DrillBlockWestEntity) be;
List<BlockPos> list = new ArrayList<>();
list.add(pos.west());
list.add(pos.west().up());
list.add(pos.west().up().up());
list.add(pos.west().up().up().up());
list.add(pos.west().down()); // must be last position
DrillBlockEntity.tick(world, pos, state, dbe, MAXDRILLSTEP, list);
}
}
}

View File

@ -1,84 +0,0 @@
package de.jottyfan.quickiemod.blockentity;
import java.util.Random;
import de.jottyfan.quickiemod.blocks.QuickieBlocks;
import de.jottyfan.quickiemod.items.QuickieItems;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.ItemEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
/**
*
* @author jotty
*
*/
public class EmptyLavaHoarderBlockEntity extends BlockEntity {
public EmptyLavaHoarderBlockEntity(BlockPos pos, BlockState state) {
super(BlockEntityTypes.EMPTYLAVAHOARDER, pos, state);
}
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(QuickieItems.SULPHOR.getItem())));
}
}
/**
* sucks the lava that touches the block
*
* @param world the world
* @param pos the pos
* @return true if lava was found
*/
private 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;
}
public static void tick(World world, BlockPos pos, BlockState state, BlockEntity be) {
if (be instanceof EmptyLavaHoarderBlockEntity) {
EmptyLavaHoarderBlockEntity elhbe = (EmptyLavaHoarderBlockEntity) be;
boolean found = elhbe.suckLava(world, pos.north());
found = found || elhbe.suckLava(world, pos.south());
found = found || elhbe.suckLava(world, pos.east());
found = found || elhbe.suckLava(world, pos.west());
found = found || elhbe.suckLava(world, pos.up());
found = found || elhbe.suckLava(world, pos.down());
if (found) {
world.setBlockState(pos, QuickieBlocks.LAVAHOARDER.getBlock().getDefaultState());
}
}
}
}

View File

@ -3,7 +3,6 @@ package de.jottyfan.quickiemod.blockentity;
import java.util.ArrayList;
import java.util.List;
import de.jottyfan.quickiemod.text.PrefixedText;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.LootableContainerBlockEntity;
@ -15,9 +14,9 @@ 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.storage.ReadView;
import net.minecraft.storage.WriteView;
import net.minecraft.text.Text;
import net.minecraft.util.collection.DefaultedList;
import net.minecraft.util.math.BlockPos;
@ -30,22 +29,31 @@ import net.minecraft.world.World;
*
*/
public class ItemHoarderBlockEntity extends LootableContainerBlockEntity {
private DefaultedList<ItemStack> stacks;
private float suckradius;
public ItemHoarderBlockEntity(BlockPos pos, BlockState state) {
super(BlockEntityTypes.ITEMHOARDER, pos, state);
super(ModBlockentity.ITEM_HOARDER_BLOCKENTITY, pos, state);
stacks = DefaultedList.ofSize(54, ItemStack.EMPTY);
setSuckradius(4f); // TODO: make it level up - able and start with 2
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) {
Integer sum = stack.getCount() + slot.getCount();
if (slot.getItem().equals(stack.getItem())) {
if (slot.getItem().getMaxCount() >= sum) {
slot.increment(stack.getCount());
return true;
} else {
Integer transferSize = 64 - stack.getCount();
stack.setCount(stack.getCount() - transferSize);
slot.setCount(64);
// to not return sth. here so that the next loop will sum up the result
}
}
} // if not found, seek for an empty stack instead
for (ItemStack slot : stacks) {
@ -80,19 +88,19 @@ public class ItemHoarderBlockEntity extends LootableContainerBlockEntity {
}
@Override
protected void writeNbt(NbtCompound nbt, WrapperLookup registryLookup) {
super.writeNbt(nbt, registryLookup);
if (!this.writeLootTable(nbt)) {
Inventories.writeNbt(nbt, this.stacks, registryLookup);
protected void writeData(WriteView view) {
super.writeData(view);
if (!this.writeLootTable(view)) {
Inventories.writeData(view, this.stacks);
}
}
@Override
protected void readNbt(NbtCompound nbt, WrapperLookup registryLookup) {
super.readNbt(nbt, registryLookup);
protected void readData(ReadView view) {
super.readData(view);
this.stacks = DefaultedList.ofSize(this.size(), ItemStack.EMPTY);
if (!this.readLootTable(nbt)) {
Inventories.readNbt(nbt, this.stacks, registryLookup);
if (!this.readLootTable(view)){
Inventories.readData(view, this.stacks);
}
}
@ -136,8 +144,7 @@ public class ItemHoarderBlockEntity extends LootableContainerBlockEntity {
for (ItemStack stack : stacks) {
Item item = stack.getItem();
if (item != Items.AIR) {
Text text = PrefixedText.instance(String.format("%dx ", stack.getCount()).concat("%s"),
Text.translatable(stack.getTranslationKey()));
Text text = Text.of(String.format("%dx %s", stack.getCount(), Text.translatable(stack.getItem().getTranslationKey())));
list.add(text);
}
}

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

@ -1,51 +0,0 @@
package de.jottyfan.quickiemod.blockentity;
import java.util.List;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.Entity;
import net.minecraft.entity.mob.HostileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Box;
import net.minecraft.world.World;
/**
*
* @author jotty
*
*/
public class MonsterHoarderBlockEntity extends BlockEntity {
private float suckradius;
public MonsterHoarderBlockEntity(BlockPos pos, BlockState state) {
super(BlockEntityTypes.MONSTERHOARDER, pos, state);
setSuckradius(8f); // TODO: make it level up - able and start with 2
}
public static void tick(World world, BlockPos pos, BlockState state, BlockEntity be) {
if (be instanceof MonsterHoarderBlockEntity) {
MonsterHoarderBlockEntity mhbe = (MonsterHoarderBlockEntity) be;
Box box = new Box(pos).expand(mhbe.getSuckradius());
List<Entity> entities = world.getOtherEntities(null, box);
for (Entity entity : entities) {
if (entity instanceof HostileEntity) {
if (entity.isFireImmune()) {
entity.kill();
} else {
entity.setOnFireFor(90);
}
}
}
}
}
public float getSuckradius() {
return suckradius;
}
public void setSuckradius(float suckradius) {
this.suckradius = suckradius;
}
}

View File

@ -1,66 +0,0 @@
package de.jottyfan.quickiemod.blocks;
import java.util.List;
import java.util.Random;
import de.jottyfan.quickiemod.items.QuickieItems;
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.ItemConvertible;
import net.minecraft.item.ItemStack;
import net.minecraft.loot.context.LootContextParameterSet.Builder;
import net.minecraft.util.ActionResult;
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;
public class BlockCanolaplant extends CropBlock {
public BlockCanolaplant() {
super(AbstractBlock.Settings.copy(Blocks.WHEAT));
}
@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(QuickieItems.CANOLA.getItem(), 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 QuickieItems.CANOLASEED.getItem();
}
@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

@ -1,61 +0,0 @@
package de.jottyfan.quickiemod.blocks;
import java.util.ArrayList;
import java.util.List;
import com.mojang.serialization.MapCodec;
import de.jottyfan.quickiemod.blockentity.DrillBlockDownEntity;
import de.jottyfan.quickiemod.blocks.help.DrillBlock;
import net.minecraft.block.AbstractBlock;
import net.minecraft.block.BlockEntityProvider;
import net.minecraft.block.BlockRenderType;
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.item.ItemStack;
import net.minecraft.loot.context.LootContextParameterSet.Builder;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
/**
*
* @author jotty
*
*/
public class BlockDrillDown extends DrillBlock implements BlockEntityProvider {
public BlockDrillDown() {
super(AbstractBlock.Settings.create().hardness(2.5f));
}
@Override
public BlockEntity createBlockEntity(BlockPos pos, BlockState blockState) {
return new DrillBlockDownEntity(pos, blockState);
}
@Override
public List<ItemStack> getDroppedStacks(BlockState state, Builder builder) {
List<ItemStack> list = new ArrayList<>();
list.add(new ItemStack(QuickieBlocks.DRILL_DOWN.getBlock()));
return list;
}
@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) -> DrillBlockDownEntity.tick(world1, pos, state1, be);
}
@Override
protected MapCodec<? extends FallingBlock> getCodec() {
return null; // TODO: what to return here?
}
}

View File

@ -1,61 +0,0 @@
package de.jottyfan.quickiemod.blocks;
import java.util.ArrayList;
import java.util.List;
import com.mojang.serialization.MapCodec;
import de.jottyfan.quickiemod.blockentity.DrillBlockEastEntity;
import de.jottyfan.quickiemod.blocks.help.DrillBlock;
import net.minecraft.block.AbstractBlock;
import net.minecraft.block.BlockEntityProvider;
import net.minecraft.block.BlockRenderType;
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.item.ItemStack;
import net.minecraft.loot.context.LootContextParameterSet.Builder;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
/**
*
* @author jotty
*
*/
public class BlockDrillEast extends DrillBlock implements BlockEntityProvider {
public BlockDrillEast() {
super(AbstractBlock.Settings.create().hardness(2.5f));
}
@Override
public BlockEntity createBlockEntity(BlockPos pos, BlockState blockState) {
return new DrillBlockEastEntity(pos, blockState);
}
@Override
public List<ItemStack> getDroppedStacks(BlockState state, Builder builder) {
List<ItemStack> list = new ArrayList<>();
list.add(new ItemStack(QuickieBlocks.DRILL_EAST.getBlock()));
return list;
}
@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) -> DrillBlockEastEntity.tick(world1, pos, state1, be);
}
@Override
protected MapCodec<? extends FallingBlock> getCodec() {
// TODO Auto-generated method stub
return null;
}
}

View File

@ -1,61 +0,0 @@
package de.jottyfan.quickiemod.blocks;
import java.util.ArrayList;
import java.util.List;
import com.mojang.serialization.MapCodec;
import de.jottyfan.quickiemod.blockentity.DrillBlockNorthEntity;
import de.jottyfan.quickiemod.blocks.help.DrillBlock;
import net.minecraft.block.AbstractBlock;
import net.minecraft.block.BlockEntityProvider;
import net.minecraft.block.BlockRenderType;
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.item.ItemStack;
import net.minecraft.loot.context.LootContextParameterSet.Builder;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
/**
*
* @author jotty
*
*/
public class BlockDrillNorth extends DrillBlock implements BlockEntityProvider {
public BlockDrillNorth() {
super(AbstractBlock.Settings.create().hardness(2.5f));
}
@Override
public BlockEntity createBlockEntity(BlockPos pos, BlockState blockState) {
return new DrillBlockNorthEntity(pos, blockState);
}
@Override
public List<ItemStack> getDroppedStacks(BlockState state, Builder builder) {
List<ItemStack> list = new ArrayList<>();
list.add(new ItemStack(QuickieBlocks.DRILL_NORTH.getBlock()));
return list;
}
@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) -> DrillBlockNorthEntity.tick(world1, pos, state1, be);
}
@Override
protected MapCodec<? extends FallingBlock> getCodec() {
// TODO Auto-generated method stub
return null;
}
}

View File

@ -1,61 +0,0 @@
package de.jottyfan.quickiemod.blocks;
import java.util.ArrayList;
import java.util.List;
import com.mojang.serialization.MapCodec;
import de.jottyfan.quickiemod.blockentity.DrillBlockSouthEntity;
import de.jottyfan.quickiemod.blocks.help.DrillBlock;
import net.minecraft.block.AbstractBlock;
import net.minecraft.block.BlockEntityProvider;
import net.minecraft.block.BlockRenderType;
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.item.ItemStack;
import net.minecraft.loot.context.LootContextParameterSet.Builder;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
/**
*
* @author jotty
*
*/
public class BlockDrillSouth extends DrillBlock implements BlockEntityProvider {
public BlockDrillSouth() {
super(AbstractBlock.Settings.create().hardness(2.5f));
}
@Override
public BlockEntity createBlockEntity(BlockPos pos, BlockState blockState) {
return new DrillBlockSouthEntity(pos, blockState);
}
@Override
public List<ItemStack> getDroppedStacks(BlockState state, Builder builder) {
List<ItemStack> list = new ArrayList<>();
list.add(new ItemStack(QuickieBlocks.DRILL_SOUTH.getBlock()));
return list;
}
@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) -> DrillBlockSouthEntity.tick(world1, pos, state1, be);
}
@Override
protected MapCodec<? extends FallingBlock> getCodec() {
// TODO Auto-generated method stub
return null;
}
}

View File

@ -1,61 +0,0 @@
package de.jottyfan.quickiemod.blocks;
import java.util.ArrayList;
import java.util.List;
import com.mojang.serialization.MapCodec;
import de.jottyfan.quickiemod.blockentity.DrillBlockWestEntity;
import de.jottyfan.quickiemod.blocks.help.DrillBlock;
import net.minecraft.block.AbstractBlock;
import net.minecraft.block.BlockEntityProvider;
import net.minecraft.block.BlockRenderType;
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.item.ItemStack;
import net.minecraft.loot.context.LootContextParameterSet.Builder;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
/**
*
* @author jotty
*
*/
public class BlockDrillWest extends DrillBlock implements BlockEntityProvider {
public BlockDrillWest() {
super(AbstractBlock.Settings.create().hardness(2.5f));
}
@Override
public BlockEntity createBlockEntity(BlockPos pos, BlockState blockState) {
return new DrillBlockWestEntity(pos, blockState);
}
@Override
public List<ItemStack> getDroppedStacks(BlockState state, Builder builder) {
List<ItemStack> list = new ArrayList<>();
list.add(new ItemStack(QuickieBlocks.DRILL_WEST.getBlock()));
return list;
}
@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) -> DrillBlockWestEntity.tick(world1, pos, state1, be);
}
@Override
protected MapCodec<? extends FallingBlock> getCodec() {
// TODO Auto-generated method stub
return null;
}
}

View File

@ -1,30 +0,0 @@
package de.jottyfan.quickiemod.blocks;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.block.AbstractBlock;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.item.ItemStack;
import net.minecraft.loot.context.LootContextParameterSet.Builder;
/**
*
* @author jotty
*
*/
public class BlockDrillstop extends Block {
public BlockDrillstop() {
super(AbstractBlock.Settings.create().hardness(2.5f));
}
@Override
public List<ItemStack> getDroppedStacks(BlockState state, Builder builder) {
List<ItemStack> list = new ArrayList<>();
list.add(new ItemStack(QuickieBlocks.DRILLSTOP.getBlock()));
return list;
}
}

View File

@ -1,38 +0,0 @@
package de.jottyfan.quickiemod.blocks;
import java.util.Arrays;
import java.util.List;
import com.mojang.serialization.MapCodec;
import net.minecraft.block.AbstractBlock;
import net.minecraft.block.BlockState;
import net.minecraft.block.FallingBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.loot.context.LootContextParameterSet.Builder;
import net.minecraft.sound.BlockSoundGroup;
/**
*
* @author jotty
*
*/
public class BlockKelpstack extends FallingBlock {
public BlockKelpstack() {
super(AbstractBlock.Settings.create().hardness(0.1f).slipperiness(1.0f)
.breakInstantly().sounds(BlockSoundGroup.WET_GRASS));
}
@Override
public List<ItemStack> getDroppedStacks(BlockState blockState, Builder builder) {
return Arrays.asList(new ItemStack[] { new ItemStack(Items.KELP, 9) });
}
@Override
protected MapCodec<? extends FallingBlock> getCodec() {
// TODO Auto-generated method stub
return null;
}
}

View File

@ -1,81 +0,0 @@
package de.jottyfan.quickiemod.blocks;
import java.util.ArrayList;
import java.util.List;
import de.jottyfan.quickiemod.blockentity.EmptyLavaHoarderBlockEntity;
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.ItemEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.loot.context.LootContextParameterSet.Builder;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
/**
*
* @author jotty
*
*/
public class BlockLavahoarder extends Block implements BlockEntityProvider {
public BlockLavahoarder() {
super(AbstractBlock.Settings.create().hardness(2.5f).luminance(state -> 15));
}
@Override
public BlockEntity createBlockEntity(BlockPos pos, BlockState blockState) {
return new EmptyLavaHoarderBlockEntity(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) -> EmptyLavaHoarderBlockEntity.tick(world1, pos, state1, be);
}
@Override
public List<ItemStack> getDroppedStacks(BlockState state, Builder builder) {
List<ItemStack> list = new ArrayList<>();
list.add(new ItemStack(QuickieBlocks.LAVAHOARDER.getBlock()));
return list;
}
@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));
}
EmptyLavaHoarderBlockEntity.spawnRandomItems(world, pos, 2);
world.setBlockState(pos, QuickieBlocks.EMPTYLAVAHOARDER.getBlock().getDefaultState());
}
}
return ActionResult.SUCCESS; // forbid to empty the just filled lava bucket
}
}

View File

@ -1,64 +0,0 @@
package de.jottyfan.quickiemod.blocks;
import java.util.ArrayList;
import java.util.List;
import de.jottyfan.quickiemod.blockentity.MonsterHoarderBlockEntity;
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.LivingEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.loot.context.LootContextParameterSet.Builder;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvents;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
/**
*
* @author jotty
*
*/
public class BlockMonsterhoarder extends Block implements BlockEntityProvider {
public BlockMonsterhoarder() {
super(AbstractBlock.Settings.create().hardness(2.5f).luminance(state -> 15));
}
@Override
public BlockEntity createBlockEntity(BlockPos pos, BlockState blockState) {
return new MonsterHoarderBlockEntity(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) -> MonsterHoarderBlockEntity.tick(world1, pos, state1, be);
}
@Override
public List<ItemStack> getDroppedStacks(BlockState state, Builder builder) {
List<ItemStack> list = new ArrayList<>();
list.add(new ItemStack(QuickieBlocks.MONSTERHOARDER.getBlock()));
return list;
}
@Override
public void onPlaced(World world, BlockPos pos, BlockState state, LivingEntity placer, ItemStack itemStack) {
if (!world.isClient) {
world.playSound(null, pos, SoundEvents.UI_TOAST_CHALLENGE_COMPLETE, SoundCategory.PLAYERS, 1f, 1f);
}
super.onPlaced(world, pos, state, placer, itemStack);
}
}

View File

@ -1,30 +0,0 @@
package de.jottyfan.quickiemod.blocks;
import java.util.Arrays;
import java.util.List;
import de.jottyfan.quickiemod.blocks.help.IntProviderHelper;
import de.jottyfan.quickiemod.items.QuickieItems;
import net.minecraft.block.AbstractBlock;
import net.minecraft.block.BlockState;
import net.minecraft.block.ExperienceDroppingBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.loot.context.LootContextParameterSet.Builder;
/**
*
* @author jotty
*
*/
public class BlockOreDeepslateSulphor extends ExperienceDroppingBlock {
public BlockOreDeepslateSulphor() {
super(IntProviderHelper.of(0, 2), AbstractBlock.Settings.create().hardness(1.9f).requiresTool());
}
@Override
public List<ItemStack> getDroppedStacks(BlockState state, Builder builder) {
return Arrays.asList(new ItemStack[] { new ItemStack(QuickieItems.SULPHOR.getItem(), 4) });
}
}

View File

@ -1,29 +0,0 @@
package de.jottyfan.quickiemod.blocks;
import java.util.Arrays;
import java.util.List;
import de.jottyfan.quickiemod.blocks.help.IntProviderHelper;
import de.jottyfan.quickiemod.items.QuickieItems;
import net.minecraft.block.AbstractBlock;
import net.minecraft.block.BlockState;
import net.minecraft.block.ExperienceDroppingBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.loot.context.LootContextParameterSet.Builder;
/**
*
* @author jotty
*
*/
public class BlockOreNetherSulphor extends ExperienceDroppingBlock {
public BlockOreNetherSulphor() {
super(IntProviderHelper.of(0, 2), AbstractBlock.Settings.create().hardness(2.1f).requiresTool());
}
@Override
public List<ItemStack> getDroppedStacks(BlockState state, Builder builder) {
return Arrays.asList(new ItemStack[] { new ItemStack(QuickieItems.SULPHOR.getItem()) });
}
}

View File

@ -1,30 +0,0 @@
package de.jottyfan.quickiemod.blocks;
import java.util.Arrays;
import java.util.List;
import de.jottyfan.quickiemod.blocks.help.IntProviderHelper;
import de.jottyfan.quickiemod.items.QuickieItems;
import net.minecraft.block.AbstractBlock;
import net.minecraft.block.BlockState;
import net.minecraft.block.ExperienceDroppingBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.loot.context.LootContextParameterSet.Builder;
import net.minecraft.util.math.random.Random;
/**
*
* @author jotty
*
*/
public class BlockOreSalpeter extends ExperienceDroppingBlock {
public BlockOreSalpeter() {
super(IntProviderHelper.of(0, 2), AbstractBlock.Settings.create().hardness(3.1f).requiresTool());
}
@Override
public List<ItemStack> getDroppedStacks(BlockState state, Builder builder) {
return Arrays.asList(new ItemStack[] { new ItemStack(QuickieItems.SALPETER.getItem(), 2 + Random.create().nextInt(3)) });
}
}

View File

@ -1,31 +0,0 @@
package de.jottyfan.quickiemod.blocks;
import java.util.Arrays;
import java.util.List;
import de.jottyfan.quickiemod.blocks.help.IntProviderHelper;
import de.jottyfan.quickiemod.items.QuickieItems;
import net.minecraft.block.AbstractBlock;
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.LootContextParameterSet.Builder;
import net.minecraft.util.math.random.Random;
/**
*
* @author jotty
*
*/
public class BlockOreSandSalpeter extends ExperienceDroppingBlock {
public BlockOreSandSalpeter() {
super(IntProviderHelper.of(0, 2), AbstractBlock.Settings.create().hardness(2.9f).requiresTool());
}
@Override
public List<ItemStack> getDroppedStacks(BlockState state, Builder builder) {
return Arrays.asList(new ItemStack[] { new ItemStack(QuickieItems.SALPETER.getItem(), 7 + Random.create().nextInt(4)), new ItemStack(Blocks.SAND) });
}
}

View File

@ -1,30 +0,0 @@
package de.jottyfan.quickiemod.blocks;
import java.util.Arrays;
import java.util.List;
import de.jottyfan.quickiemod.blocks.help.IntProviderHelper;
import de.jottyfan.quickiemod.items.QuickieItems;
import net.minecraft.block.AbstractBlock;
import net.minecraft.block.BlockState;
import net.minecraft.block.ExperienceDroppingBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.loot.context.LootContextParameterSet.Builder;
/**
*
* @author jotty
*
*/
public class BlockOreSulphor extends ExperienceDroppingBlock {
public BlockOreSulphor() {
super(IntProviderHelper.of(0, 2), AbstractBlock.Settings.create().hardness(1.9f).requiresTool());
}
@Override
public List<ItemStack> getDroppedStacks(BlockState state, Builder builder) {
return Arrays.asList(new ItemStack[] { new ItemStack(QuickieItems.SULPHOR.getItem()) });
}
}

View File

@ -1,42 +0,0 @@
package de.jottyfan.quickiemod.blocks;
import java.util.Arrays;
import java.util.List;
import com.mojang.serialization.MapCodec;
import de.jottyfan.quickiemod.items.QuickieItems;
import net.minecraft.block.AbstractBlock;
import net.minecraft.block.BlockState;
import net.minecraft.block.FallingBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.loot.context.LootContextParameterSet.Builder;
import net.minecraft.world.explosion.Explosion;
/**
*
* @author jotty
*
*/
public class BlockQuickiepowder extends FallingBlock {
public BlockQuickiepowder() {
super(AbstractBlock.Settings.create().luminance(state -> 12));
}
@Override
public List<ItemStack> getDroppedStacks(BlockState state, Builder builder) {
return Arrays.asList(new ItemStack[] { new ItemStack(QuickieItems.QUICKIEPOWDER.getItem(), 9) });
}
@Override
public boolean shouldDropItemsOnExplosion(Explosion explosion) {
return true;
}
@Override
protected MapCodec<? extends FallingBlock> getCodec() {
// TODO Auto-generated method stub
return null;
}
}

View File

@ -1,29 +0,0 @@
package de.jottyfan.quickiemod.blocks;
import java.util.Arrays;
import java.util.List;
import de.jottyfan.quickiemod.blocks.help.IntProviderHelper;
import de.jottyfan.quickiemod.items.QuickieItems;
import net.minecraft.block.AbstractBlock;
import net.minecraft.block.BlockState;
import net.minecraft.block.ExperienceDroppingBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.loot.context.LootContextParameterSet.Builder;
/**
*
* @author jotty
*
*/
public class BlockSalpeter extends ExperienceDroppingBlock {
public BlockSalpeter() {
super(IntProviderHelper.of(0, 2), AbstractBlock.Settings.create().hardness(0.5f));
}
@Override
public List<ItemStack> getDroppedStacks(BlockState state, Builder builder) {
return Arrays.asList(new ItemStack[] { new ItemStack(QuickieItems.SALPETER.getItem(), 9) });
}
}

View File

@ -1,38 +0,0 @@
package de.jottyfan.quickiemod.blocks;
import java.util.Arrays;
import java.util.List;
import com.mojang.serialization.MapCodec;
import de.jottyfan.quickiemod.items.QuickieItems;
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.loot.context.LootContextParameterSet.Builder;
import net.minecraft.util.math.random.Random;
/**
*
* @author jotty
*
*/
public class BlockSandSalpeter extends FallingBlock {
public BlockSandSalpeter() {
super(AbstractBlock.Settings.create().hardness(3.1f).requiresTool());
}
@Override
public List<ItemStack> getDroppedStacks(BlockState state, Builder builder) {
return Arrays.asList(new ItemStack[] { new ItemStack(QuickieItems.SALPETER.getItem(), 3 + Random.create().nextInt(2)), new ItemStack(Blocks.SAND) });
}
@Override
protected MapCodec<? extends FallingBlock> getCodec() {
// TODO Auto-generated method stub
return null;
}
}

View File

@ -1,29 +0,0 @@
package de.jottyfan.quickiemod.blocks;
import java.util.Arrays;
import java.util.List;
import de.jottyfan.quickiemod.blocks.help.IntProviderHelper;
import de.jottyfan.quickiemod.items.QuickieItems;
import net.minecraft.block.AbstractBlock;
import net.minecraft.block.BlockState;
import net.minecraft.block.ExperienceDroppingBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.loot.context.LootContextParameterSet.Builder;
/**
*
* @author jotty
*
*/
public class BlockSulphor extends ExperienceDroppingBlock {
public BlockSulphor() {
super(IntProviderHelper.of(0, 2), AbstractBlock.Settings.create().hardness(0.5f));
}
@Override
public List<ItemStack> getDroppedStacks(BlockState state, Builder builder) {
return Arrays.asList(new ItemStack[] { new ItemStack(QuickieItems.SULPHOR.getItem(), 9) });
}
}

View File

@ -1,63 +0,0 @@
package de.jottyfan.quickiemod.blocks;
import net.minecraft.block.Block;
/**
*
* @author jotty
*
*/
public enum QuickieBlocks {
// @formatter:off
DRILL_DOWN(new BlockDrillDown(), "drill"),
DRILL_EAST(new BlockDrillEast(), "drilleast"),
DRILL_SOUTH(new BlockDrillSouth(), "drillsouth"),
DRILL_WEST(new BlockDrillWest(), "drillwest"),
DRILL_NORTH(new BlockDrillNorth(), "drillnorth"),
DRILLSTOP(new BlockDrillstop(), "drillstop"),
MONSTERHOARDER(new BlockMonsterhoarder(), "monsterhoarder"),
ITEMHOARDER(new BlockItemhoarder(), "itemhoarder"),
LAVAHOARDER(new BlockLavahoarder(), "lavahoarder", false),
EMPTYLAVAHOARDER(new BlockEmptyLavahoarder(), "emptylavahoarder"),
KELPSTACK(new BlockKelpstack(), "kelpstack"),
COTTONPLANT(new BlockCottonplant(), "cottonplant", false),
CANOLAPLANT(new BlockCanolaplant(), "canolaplant", false),
DIRTSALPETER(new BlockDirtSalpeter(), "dirtsalpeter"),
ORE_NETHER_SULPHOR(new BlockOreNetherSulphor(), "orenethersulphor"),
ORE_SALPETER(new BlockOreSalpeter(), "oresalpeter"),
ORE_SAND_SALPETER(new BlockSandSalpeter(), "oresandsalpeter"),
ORE_SULPHOR(new BlockOreSulphor(), "oresulphor"),
ORE_DEEPSLATESULPHOR(new BlockOreDeepslateSulphor(), "oredeepslatesulphor"),
SANDSALPETER(new BlockSandSalpeter(), "sandsalpeter"),
BLOCKSULPHOR(new BlockSulphor(), "blocksulphor"),
BLOCKSALPETER(new BlockSalpeter(), "blocksalpeter"),
BLOCKSPEEDPOWDER(new BlockSpeedpowder(), "blockspeedpowder"),
BLOCKQUICKIEPOWDER(new BlockQuickiepowder(), "blockquickiepowder");
// @formatter:on
private final Block block;
private final String name;
private final Boolean add2BlockPanel;
private QuickieBlocks(Block block, String name) {
this(block, name, true);
}
private QuickieBlocks(Block block, String name, Boolean add2BlockPanel) {
this.block = block;
this.name = name;
this.add2BlockPanel = add2BlockPanel;
}
public final Block getBlock() {
return block;
}
public final String getName() {
return name;
}
public final Boolean getAdd2BlockPanel() {
return add2BlockPanel;
}
}

View File

@ -1,78 +0,0 @@
package de.jottyfan.quickiemod.blocks.help;
import java.util.HashMap;
import java.util.Map;
import de.jottyfan.quickiemod.items.QuickieItems;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.FallingBlock;
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.state.property.IntProperty;
import net.minecraft.text.Text;
import net.minecraft.util.ActionResult;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
/**
*
* @author jotty
*
*/
public abstract class DrillBlock extends FallingBlock {
private static final Integer MAX_FUEL = 255;
public static final IntProperty FUEL = IntProperty.of("fuel", 0, MAX_FUEL);
public DrillBlock(Settings settings) {
super(settings);
setDefaultState(getDefaultState().with(FUEL, 0));
}
@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(QuickieItems.CANOLABOTTLE.getItem(), fuelLeft)));
return super.onBreak(world, pos, state, player);
}
@Override
protected void appendProperties(net.minecraft.state.StateManager.Builder<Block, BlockState> builder) {
builder.add(FUEL);
}
@Override
protected ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, BlockHitResult hit) {
Map<Item, Integer> loadings = new HashMap<>();
loadings.put(QuickieItems.CANOLABOTTLE.getItem(), 8);
loadings.put(QuickieItems.CANOLABOTTLESTACK.getItem(), 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)));
}
} else {
Integer fuelWeight = loadings.get(item);
if (fuelWeight != null) {
Integer load = MAX_FUEL - state.get(FUEL);
if (load < fuelWeight) {
// Integer numberOfTooMuchLoad = fuelWeight - load;
fuelWeight = load;
}
world.setBlockState(pos, state.with(FUEL, state.get(FUEL) + fuelWeight));
if (item.equals(QuickieItems.CANOLABOTTLE.getItem())) {
world.spawnEntity(new ItemEntity(world, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(Items.GLASS_BOTTLE, 1)));
} else if (item.equals(QuickieItems.CANOLABOTTLESTACK.getItem())) {
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,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,215 @@
package de.jottyfan.quickiemod.event;
import java.util.ArrayList;
import java.util.List;
import de.jottyfan.quickiemod.Quickiemod;
import de.jottyfan.quickiemod.item.HarvestRange;
import de.jottyfan.quickiemod.item.ModItems;
import de.jottyfan.quickiemod.item.ToolRangeable;
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;
}
/**
* break surrounding block if item is of ToolRangeable
*
* @param world
* @param blockPos
* @param blockState
* @param playerEntity
* @param oldBlock
* @return true if this range breaking routine has been used, false otherwise
*/
public boolean 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;
// not needed when added to before block break
// if (!world.getBlockState(blockPos).getBlock().equals(oldBlock)) {
// // recreate old block to make it breakable; otherwise, the recursive algorithm stops directly
// // this leads to the BUG that blocks with no neighbour will respawn and drop -> unlimited items.
// 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));
}
return handled > 0; // this way, a rangeable pickaxe can break a dirt block
} else {
return false;
}
} else {
return false;
}
}
/**
* 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);
if (tool instanceof Item) {
Item toolItem = (Item) tool; // a rangeable tool should always be an item
List<String> visitedBlocks = new ArrayList<>();
if (ModItems.TOOL_SPEEDPOWDERAXE.getName().equals(toolItem.getName())) {
return breakBlockRecursive(visitedBlocks, world, validBlocks, pos, tool, range, BlockBreakDirection.UPWARDS,
player, true);
} else if (ModItems.TOOL_SPEEDPOWDERPICKAXE.getName().equals(toolItem.getName())) {
return breakBlockRecursive(visitedBlocks, world, validBlocks, pos, tool, range, BlockBreakDirection.ALL,
player, false);
} else if (ModItems.TOOL_SPEEDPOWDERSHOVEL.getName().equals(toolItem.getName())) {
return breakBlockRecursive(visitedBlocks, world, validBlocks, pos, tool, range, BlockBreakDirection.ALL,
player, false);
} else if (ModItems.TOOL_SPEEDPOWDERHOE.getName().equals(toolItem.getName())) {
return breakBlockRecursive(visitedBlocks, world, validBlocks, pos, tool, range, BlockBreakDirection.ALL,
player, false);
} else if (ModItems.TOOL_QUICKIEPOWDERAXE.getName().equals(toolItem.getName())) {
return breakBlockRecursive(visitedBlocks, world, validBlocks, pos, tool, range, BlockBreakDirection.UPWARDS,
player, true);
} else if (ModItems.TOOL_QUICKIEPOWDERPICKAXE.getName().equals(toolItem.getName())) {
return breakBlockRecursive(visitedBlocks, world, validBlocks, pos, tool, range, BlockBreakDirection.ALL,
player, false);
} else if (ModItems.TOOL_QUICKIEPOWDERSHOVEL.getName().equals(toolItem.getName())) {
return breakBlockRecursive(visitedBlocks, world, validBlocks, pos, tool, range, BlockBreakDirection.ALL,
player, false);
} else if (ModItems.TOOL_QUICKIEPOWDERHOE.getName().equals(toolItem.getName())) {
return breakBlockRecursive(visitedBlocks, world, validBlocks, pos, tool, range, BlockBreakDirection.ALL,
player, false);
} else {
return 0;
}
} else {
Quickiemod.LOGGER.warn("using a tool that is not an item - no rangeable operations are possible.");
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

@ -0,0 +1,78 @@
package de.jottyfan.quickiemod.identifier;
import de.jottyfan.quickiemod.Quickiemod;
import net.minecraft.util.Identifier;
/**
*
* @author jotty
*
*/
public class ModIdentifiers {
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_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 TOOL_QUICKIEPOWDERSHEARS = Identifier.of(Quickiemod.MOD_ID, "quickiepowdershears");
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_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

@ -1,22 +0,0 @@
package de.jottyfan.quickiemod.init;
import de.jottyfan.quickiemod.QuickieMod;
import net.minecraft.util.Identifier;
/**
*
* @author jotty
*
*/
public class BlockEntityIdentity {
public static final Identifier ITEMHOARDER = new Identifier(QuickieMod.MODID, "itemhoarderblockentity");
public static final Identifier BLOCKSPREADER = new Identifier(QuickieMod.MODID, "blockspreaderblockentity");
public static final Identifier BLOCKSTACKERUP = new Identifier(QuickieMod.MODID, "blockstackerblockentity");
public static final Identifier MONSTERHOARDER = new Identifier(QuickieMod.MODID, "monsterhoarderblockentity");
public static final Identifier EMPTYLAVALHOARDER = new Identifier(QuickieMod.MODID, "emptylavahoarderblockentity");
public static final Identifier DRILL_DOWN = new Identifier(QuickieMod.MODID, "drillblockdownblockentity");
public static final Identifier DRILL_EAST = new Identifier(QuickieMod.MODID, "drillblockeastblockentity");
public static final Identifier DRILL_SOUTH = new Identifier(QuickieMod.MODID, "drillblocksouthblockentity");
public static final Identifier DRILL_WEST = new Identifier(QuickieMod.MODID, "drillblockwestblockentity");
public static final Identifier DRILL_NORTH = new Identifier(QuickieMod.MODID, "drillblocknorthblockentity");
}

View File

@ -1,66 +0,0 @@
package de.jottyfan.quickiemod.init;
import java.util.function.BiConsumer;
import de.jottyfan.quickiemod.QuickieMod;
import net.fabricmc.fabric.api.biome.v1.BiomeModificationContext;
import net.fabricmc.fabric.api.biome.v1.BiomeSelectionContext;
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 FeaturesManager {
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, new Identifier(QuickieMod.MODID, name));
}
private static final RegistryKey<PlacedFeature> genPf(String name) {
return RegistryKey.of(RegistryKeys.PLACED_FEATURE, new Identifier(QuickieMod.MODID, name));
}
protected static final BiConsumer<BiomeSelectionContext, BiomeModificationContext> overworldOres() {
return (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);
};
}
protected static final BiConsumer<BiomeSelectionContext, BiomeModificationContext> netherOres() {
return (bsc, bmc) -> {
bmc.getGenerationSettings().addFeature(GenerationStep.Feature.UNDERGROUND_ORES, PF_ORENETHERSULPHOR);
bmc.getGenerationSettings().addFeature(GenerationStep.Feature.UNDERGROUND_ORES, PF_BLOCKSULPHOR);
};
}
}

View File

@ -1,83 +0,0 @@
package de.jottyfan.quickiemod.init;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import de.jottyfan.quickiemod.QuickieMod;
import de.jottyfan.quickiemod.blockentity.BlockEntityTypes;
import de.jottyfan.quickiemod.blocks.QuickieBlocks;
import de.jottyfan.quickiemod.items.QuickieItems;
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.fabricmc.fabric.api.itemgroup.v1.FabricItemGroup;
import net.fabricmc.fabric.api.registry.FuelRegistry;
import net.minecraft.block.ComposterBlock;
import net.minecraft.item.BlockItem;
import net.minecraft.item.Item.Settings;
import net.minecraft.item.ItemStack;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
/**
*
* @author jotty
*
*/
public class RegistryManager {
private static final Logger LOGGER = LoggerFactory.getLogger(QuickieMod.MODID);
public static final void registerItemGroup() {
Registry.register(Registries.ITEM_GROUP, RegistryKey.of(RegistryKeys.ITEM_GROUP, new Identifier(QuickieMod.MODID, "itemgroups")),
FabricItemGroup.builder().icon(() -> new ItemStack(QuickieItems.ROTTEN_FLESH_STRIPES.getItem())).displayName(Text.literal(QuickieMod.MODID))
.entries((enabledFeatures, stacks) -> {
for (QuickieItems i : QuickieItems.values()) {
stacks.add(new ItemStack(i.getItem()));
}
for (QuickieBlocks b : QuickieBlocks.values()) {
if (b.getAdd2BlockPanel()) {
stacks.add(new ItemStack(b.getBlock()));
}
}
}).build());
}
public static final void registerItems() {
LOGGER.debug("registering items");
for (QuickieItems i : QuickieItems.values()) {
Registry.register(Registries.ITEM, new Identifier(QuickieMod.MODID, i.getName()), i.getItem());
}
ComposterBlock.ITEM_TO_LEVEL_INCREASE_CHANCE.put(QuickieItems.COTTONSEED.getItem(), 0.5f);
ComposterBlock.ITEM_TO_LEVEL_INCREASE_CHANCE.put(QuickieItems.COTTON.getItem(), 0.75f);
ComposterBlock.ITEM_TO_LEVEL_INCREASE_CHANCE.put(QuickieItems.CANOLASEED.getItem(), 0.5f);
ComposterBlock.ITEM_TO_LEVEL_INCREASE_CHANCE.put(QuickieItems.CANOLA.getItem(), 0.75f);
FuelRegistry.INSTANCE.add(QuickieItems.SULPHOR.getItem(), 200);
FuelRegistry.INSTANCE.add(QuickieBlocks.BLOCKSULPHOR.getBlock(), 2000);
}
public static final void registerBlocks() {
LOGGER.debug("registering blocks");
for (QuickieBlocks b : QuickieBlocks.values()) {
Registry.register(Registries.BLOCK, new Identifier(QuickieMod.MODID, b.getName()), b.getBlock());
Registry.register(Registries.ITEM, new Identifier(QuickieMod.MODID, b.getName()), new BlockItem(b.getBlock(), new Settings()));
}
}
public static final void registerFeatures() {
// Overworld features
BiomeModifications.create(new Identifier(QuickieMod.MODID, "features")).add(ModificationPhase.ADDITIONS, BiomeSelectors.foundInOverworld(),
FeaturesManager.overworldOres());
// Nether features
BiomeModifications.create(new Identifier(QuickieMod.MODID, "nether_features")).add(ModificationPhase.ADDITIONS, BiomeSelectors.foundInTheNether(),
FeaturesManager.netherOres());
}
public static final void registerBlockEntityTypes() {
new BlockEntityTypes();
}
}

View File

@ -0,0 +1,20 @@
package de.jottyfan.quickiemod.item;
import net.minecraft.item.Item;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.util.Identifier;
/**
*
* @author jotty
*
*/
public abstract class AbstractIdentifiedItem extends Item {
public AbstractIdentifiedItem(Identifier identifier, Integer maxCount) {
super(new Item.Settings().maxCount(maxCount).useItemPrefixedTranslationKey()
.registryKey(RegistryKey.of(RegistryKeys.ITEM, identifier)));
}
}

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,16 @@
package de.jottyfan.quickiemod.item;
import net.minecraft.util.Identifier;
/**
*
* @author jotty
*
*/
public class Item64Stack extends AbstractIdentifiedItem {
public Item64Stack(Identifier identifier) {
super(identifier, 64);
}
}

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

@ -0,0 +1,54 @@
package de.jottyfan.quickiemod.item;
import java.util.Map;
import java.util.Random;
import de.jottyfan.quickiemod.block.ModBlocks;
import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
import net.minecraft.entity.ItemEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemUsageContext;
import net.minecraft.item.Items;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvents;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
public class ItemStub extends AbstractIdentifiedItem {
public ItemStub(Identifier identifier) {
super(identifier, 64);
}
@Override
public ActionResult useOnBlock(ItemUsageContext context) {
Map<Block, Item> SLASH_MAP = Map.of(
Blocks.HAY_BLOCK, Items.WHEAT,
Blocks.DRIED_KELP_BLOCK, Items.DRIED_KELP,
ModBlocks.BLOCK_KELPSTACK, Items.KELP);
World world = context.getWorld();
BlockPos pos = context.getBlockPos();
Block clickedBlock = world.getBlockState(pos).getBlock();
if (SLASH_MAP.containsKey(clickedBlock)) {
if (!world.isClient()) {
world.setBlockState(pos, Blocks.AIR.getDefaultState());
world.playSound(null, pos, SoundEvents.ITEM_HOE_TILL,
SoundCategory.BLOCKS);
for (int i = 0; i < 9; i++) {
ItemStack stack = new ItemStack(SLASH_MAP.get(clickedBlock));
float xScatter = new Random().nextFloat();
float yScatter = new Random().nextFloat();
ItemEntity entity = new ItemEntity(world, pos.getX(), pos.getY(), pos.getZ(),
stack, xScatter, yScatter, 0.2);
world.spawnEntity(entity);
}
}
}
return ActionResult.SUCCESS;
}
}

View File

@ -0,0 +1,120 @@
package de.jottyfan.quickiemod.item;
import java.util.ArrayList;
import java.util.List;
import de.jottyfan.quickiemod.Quickiemod;
import de.jottyfan.quickiemod.identifier.ModIdentifiers;
import net.minecraft.item.Item;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.util.Identifier;
/**
*
* @author jotty
*
*/
public class ModItems {
public static final Item ITEM_STUB = registerItem(ModIdentifiers.ITEM_STUB,
new ItemStub(ModIdentifiers.ITEM_STUB));
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));
public static final Item TOOL_QUICKIEPOWDERSHEARS = registerItem(ModIdentifiers.TOOL_QUICKIEPOWDERSHEARS,
new ToolSpeedpowderShears(ModIdentifiers.TOOL_QUICKIEPOWDERSHEARS));
private static final Item registerItem(Identifier identifier, Item item) {
return Registry.register(Registries.ITEM, identifier, item);
}
public static final List<Item> registerModItems() {
Quickiemod.LOGGER.debug(String.format("registering item %s", Quickiemod.MOD_ID));
List<Item> items = new ArrayList<>();
items.add(ITEM_STUB);
items.add(ITEM_SPEEDPOWDER);
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);
items.add(TOOL_QUICKIEPOWDERSHEARS);
return items;
}
}

View File

@ -1,21 +0,0 @@
package de.jottyfan.quickiemod.item;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemUsageContext;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.world.World;
/**
*
* @author jotty
*
*/
public class ModdedItemUsageContext extends ItemUsageContext {
public ModdedItemUsageContext(World world, PlayerEntity player, Hand hand, ItemStack stack, BlockHitResult hit) {
super(world, player, hand, stack, hit);
}
}

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,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.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 ToolQuickiepowderPickaxe extends Item 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(new Item.Settings().pickaxe(MATERIAL, 7F, -3.1F).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.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 ToolQuickiepowderShears extends ShearsItem {
public ToolQuickiepowderShears(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();
horse.setBaby(true);
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();
cow.setBaby(true);
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 chicken = (ChickenEntity) entity;
chicken.playAmbientSound();
chicken.setBaby(true);
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,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,38 @@
package de.jottyfan.quickiemod.item;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.item.ItemStack;
/**
*
* @author jotty
*
*/
public interface ToolRangeable {
/**
* @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,58 @@
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.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 Item 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(new Item.Settings().pickaxe(MATERIAL, 7F, -3.1F).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,102 @@
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 = 1 + 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();
horse.setBaby(true);
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();
cow.setBaby(true);
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 chicken = (ChickenEntity) entity;
chicken.playAmbientSound();
chicken.setBaby(true);
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;
}
}

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