diff --git a/src/generated/resources/assets/exdeorum/lang/en_us.json b/src/generated/resources/assets/exdeorum/lang/en_us.json index 4f527d21..7ac9a366 100644 --- a/src/generated/resources/assets/exdeorum/lang/en_us.json +++ b/src/generated/resources/assets/exdeorum/lang/en_us.json @@ -146,6 +146,7 @@ "gui.exdeorum.redstone_control.unpowered": "Unpowered", "info.exdeorum.crimson_nylium_spores": "Use on netherrack to turn it into a crimson nylium block.", "info.exdeorum.grass_seeds": "Use on dirt to turn it into a grass block.", + "info.exdeorum.mechanical_hammer": "The Mechanical Hammer is a machine that, when supplied with Forge Energy (FE), will hammer blocks without a player having to do it themselves. It can operate without a hammer, but adding any hammer will double the speed, and efficiency enchantments on the hammer will further increase speed. It also supports three different modes of redstone control. Since Ex Deorum does not provide a way to generate FE, you will need another mod to provide power.", "info.exdeorum.mechanical_sieve": "The Mechanical Sieve is a machine that, when supplied with a mesh and Forge Energy (FE), will sift blocks without a player having to do it themselves. It also supports three different modes of redstone control. Since Ex Deorum does not provide a way to generate FE, you will need another mod to provide power.", "info.exdeorum.mycelium_spores": "Use on dirt to turn it into mycelium.", "info.exdeorum.sculk_core": "Use a sculk core on a Sculk Shrieker to enable it to spawn Wardens. Normally, Sculk Shriekers placed by players cannot spawn Wardens, so this item is useful for obtaining Sculk items in a SkyBlock world.", diff --git a/src/generated/resources/data/exdeorum/advancements/recipes/misc/mechanical_hammer.json b/src/generated/resources/data/exdeorum/advancements/recipes/misc/mechanical_hammer.json new file mode 100644 index 00000000..376331ae --- /dev/null +++ b/src/generated/resources/data/exdeorum/advancements/recipes/misc/mechanical_hammer.json @@ -0,0 +1,35 @@ +{ + "parent": "minecraft:recipes/root", + "criteria": { + "has_item": { + "conditions": { + "items": [ + { + "items": [ + "minecraft:hopper" + ] + } + ] + }, + "trigger": "minecraft:inventory_changed" + }, + "has_the_recipe": { + "conditions": { + "recipe": "exdeorum:mechanical_hammer" + }, + "trigger": "minecraft:recipe_unlocked" + } + }, + "requirements": [ + [ + "has_item", + "has_the_recipe" + ] + ], + "rewards": { + "recipes": [ + "exdeorum:mechanical_hammer" + ] + }, + "sends_telemetry_event": true +} \ No newline at end of file diff --git a/src/generated/resources/data/exdeorum/loot_tables/blocks/mechanical_hammer.json b/src/generated/resources/data/exdeorum/loot_tables/blocks/mechanical_hammer.json index 96c595e8..674d4b46 100644 --- a/src/generated/resources/data/exdeorum/loot_tables/blocks/mechanical_hammer.json +++ b/src/generated/resources/data/exdeorum/loot_tables/blocks/mechanical_hammer.json @@ -11,6 +11,11 @@ "entries": [ { "type": "minecraft:item", + "functions": [ + { + "function": "exdeorum:machine" + } + ], "name": "exdeorum:mechanical_hammer" } ], diff --git a/src/generated/resources/data/exdeorum/recipes/mechanical_hammer.json b/src/generated/resources/data/exdeorum/recipes/mechanical_hammer.json new file mode 100644 index 00000000..8313165b --- /dev/null +++ b/src/generated/resources/data/exdeorum/recipes/mechanical_hammer.json @@ -0,0 +1,27 @@ +{ + "type": "minecraft:crafting_shaped", + "category": "misc", + "key": { + "#": { + "item": "minecraft:iron_block" + }, + "H": { + "item": "minecraft:hopper" + }, + "I": { + "item": "minecraft:iron_ingot" + }, + "T": { + "tag": "exdeorum:hammers" + } + }, + "pattern": [ + "III", + "ITI", + "#H#" + ], + "result": { + "item": "exdeorum:mechanical_hammer" + }, + "show_notification": true +} \ No newline at end of file diff --git a/src/main/java/thedarkcolour/exdeorum/block/MechanicalHammerBlock.java b/src/main/java/thedarkcolour/exdeorum/block/MechanicalHammerBlock.java index 05dd2eec..dd1565c0 100644 --- a/src/main/java/thedarkcolour/exdeorum/block/MechanicalHammerBlock.java +++ b/src/main/java/thedarkcolour/exdeorum/block/MechanicalHammerBlock.java @@ -18,21 +18,40 @@ package thedarkcolour.exdeorum.block; +import net.minecraft.ChatFormatting; import net.minecraft.core.BlockPos; +import net.minecraft.network.chat.Component; +import net.minecraft.world.entity.item.ItemEntity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.BlockItem; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.TooltipFlag; +import net.minecraft.world.item.context.BlockPlaceContext; +import net.minecraft.world.level.BlockGetter; +import net.minecraft.world.level.GameRules; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.HorizontalDirectionalBlock; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntityTicker; import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.StateDefinition; import net.minecraft.world.level.block.state.properties.BooleanProperty; +import net.minecraft.world.level.block.state.properties.DirectionProperty; +import net.minecraftforge.items.ItemStackHandler; import org.jetbrains.annotations.Nullable; import thedarkcolour.exdeorum.blockentity.MechanicalHammerBlockEntity; +import thedarkcolour.exdeorum.blockentity.MechanicalSieveBlockEntity; +import thedarkcolour.exdeorum.config.EConfig; +import thedarkcolour.exdeorum.data.TranslationKeys; import thedarkcolour.exdeorum.registry.EBlockEntities; +import java.util.List; + public class MechanicalHammerBlock extends EBlock { public static final BooleanProperty RUNNING = BooleanProperty.create("running"); + public static final DirectionProperty FACING = HorizontalDirectionalBlock.FACING; public MechanicalHammerBlock(Properties properties) { super(properties, EBlockEntities.MECHANICAL_HAMMER); @@ -42,7 +61,7 @@ public class MechanicalHammerBlock extends EBlock { @Override protected void createBlockStateDefinition(StateDefinition.Builder builder) { - builder.add(RUNNING); + builder.add(RUNNING, FACING); } @SuppressWarnings("unchecked") @@ -52,7 +71,49 @@ public class MechanicalHammerBlock extends EBlock { return type == EBlockEntities.MECHANICAL_HAMMER.get() && !level.isClientSide ? (BlockEntityTicker) new MechanicalHammerBlockEntity.ServerTicker<>() : null; } - // todo creative drop and tooltip + @Override + public void appendHoverText(ItemStack stack, @Nullable BlockGetter level, List tooltip, TooltipFlag flag) { + var nbt = BlockItem.getBlockEntityData(stack); + if (nbt != null) { + var inventoryNbt = nbt.getCompound("inventory"); + var inventory = new ItemStackHandler(); + inventory.deserializeNBT(inventoryNbt); + var hammer = inventory.getStackInSlot(MechanicalHammerBlockEntity.HAMMER_SLOT); + if (!hammer.isEmpty()) { + tooltip.add(Component.translatable(TranslationKeys.MECHANICAL_HAMMER_HAMMER_LABEL).withStyle(ChatFormatting.GRAY).append(Component.translatable(hammer.getDescriptionId()))); + } + var energy = nbt.getInt("energy"); + tooltip.add(Component.translatable(TranslationKeys.ENERGY).withStyle(ChatFormatting.GRAY).append(Component.translatable(TranslationKeys.FRACTION_DISPLAY, energy, EConfig.SERVER.mechanicalSieveEnergyStorage.get())).append(" FE")); + } + } + + @Override + public void playerWillDestroy(Level level, BlockPos pos, BlockState pState, Player player) { + if (!level.isClientSide && player.isCreative() && level.getGameRules().getBoolean(GameRules.RULE_DOBLOCKDROPS)) { + if (level.getBlockEntity(pos) instanceof MechanicalHammerBlockEntity sieve) { + if (!sieve.inventory.getStackInSlot(MechanicalHammerBlockEntity.HAMMER_SLOT).isEmpty()) { + var stack = new ItemStack(this); + BlockItem.setBlockEntityData(stack, EBlockEntities.MECHANICAL_HAMMER.get(), sieve.saveWithoutMetadata()); + var itemEntity = new ItemEntity(level, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, stack); + itemEntity.setDefaultPickUpDelay(); + level.addFreshEntity(itemEntity); + } + } + } + + super.playerWillDestroy(level, pos, pState, player); + } + + @Override + public BlockState getStateForPlacement(BlockPlaceContext context) { + var nbt = BlockItem.getBlockEntityData(context.getItemInHand()); + var state = defaultBlockState(); + if (nbt != null && nbt.contains("progress") && nbt.getInt("progress") != MechanicalHammerBlockEntity.NOT_RUNNING) { + state = state.setValue(RUNNING, true); + } + + return state.setValue(FACING, context.getHorizontalDirection().getOpposite()); + } @Override public void onPlace(BlockState state, Level level, BlockPos pos, BlockState oldState, boolean isMoving) { diff --git a/src/main/java/thedarkcolour/exdeorum/blockentity/AbstractMachineBlockEntity.java b/src/main/java/thedarkcolour/exdeorum/blockentity/AbstractMachineBlockEntity.java index 73072078..3007c4d4 100644 --- a/src/main/java/thedarkcolour/exdeorum/blockentity/AbstractMachineBlockEntity.java +++ b/src/main/java/thedarkcolour/exdeorum/blockentity/AbstractMachineBlockEntity.java @@ -149,6 +149,8 @@ public abstract class AbstractMachineBlockEntity> implements BlockEntityTicker { @Override public void tick(Level level, BlockPos pos, BlockState state, M machine) { @@ -163,6 +165,8 @@ public abstract class AbstractMachineBlockEntity { private static final Component TITLE = Component.translatable(TranslationKeys.MECHANICAL_HAMMER_SCREEN_TITLE); private static final int INPUT_SLOT = 0; - private static final int HAMMER_SLOT = 1; + public static final int HAMMER_SLOT = 1; private static final int OUTPUT_SLOT = 2; public static final int TOTAL_PROGRESS = 10_000_000; // process should take 200 ticks or 10 seconds with no efficiency @@ -111,6 +111,13 @@ public class MechanicalHammerBlockEntity extends AbstractMachineBlockEntity(); diff --git a/src/main/java/thedarkcolour/exdeorum/data/BlockLoot.java b/src/main/java/thedarkcolour/exdeorum/data/BlockLoot.java index 7b3487a0..f154bf65 100644 --- a/src/main/java/thedarkcolour/exdeorum/data/BlockLoot.java +++ b/src/main/java/thedarkcolour/exdeorum/data/BlockLoot.java @@ -65,6 +65,11 @@ class BlockLoot extends BlockLootSubProvider { .setRolls(ConstantValue.exactly(1.0F)) .add(LootItem.lootTableItem(EItems.MECHANICAL_SIEVE.get()) .apply(MachineLootFunction.machineLoot()))))); + add(EBlocks.MECHANICAL_HAMMER.get(), LootTable.lootTable() + .withPool(applyExplosionCondition(EItems.MECHANICAL_HAMMER.get(), LootPool.lootPool() + .setRolls(ConstantValue.exactly(1.0F)) + .add(LootItem.lootTableItem(EItems.MECHANICAL_HAMMER.get()) + .apply(MachineLootFunction.machineLoot()))))); } @Override diff --git a/src/main/java/thedarkcolour/exdeorum/data/English.java b/src/main/java/thedarkcolour/exdeorum/data/English.java index 3b0edb2c..99328e6d 100644 --- a/src/main/java/thedarkcolour/exdeorum/data/English.java +++ b/src/main/java/thedarkcolour/exdeorum/data/English.java @@ -31,6 +31,7 @@ class English { english.add(TranslationKeys.VOID_WORLD_TYPE, "Void World"); english.add(TranslationKeys.FRACTION_DISPLAY, ": %s / %s"); english.add(TranslationKeys.MECHANICAL_SIEVE_MESH_LABEL, "Mesh: "); + english.add(TranslationKeys.MECHANICAL_HAMMER_HAMMER_LABEL, "Hammer: "); english.add(TranslationKeys.ENERGY, "Energy"); english.add(TranslationKeys.ROOT_ADVANCEMENT_TITLE, "Don't Look Down..."); @@ -55,6 +56,7 @@ class English { english.add(TranslationKeys.CRIMSON_NYLIUM_SPORES_JEI_INFO, "Use on netherrack to turn it into a crimson nylium block."); english.add(TranslationKeys.SCULK_CORE_JEI_INFO, "Use a sculk core on a Sculk Shrieker to enable it to spawn Wardens. Normally, Sculk Shriekers placed by players cannot spawn Wardens, so this item is useful for obtaining Sculk items in a SkyBlock world."); english.add(TranslationKeys.MECHANICAL_SIEVE_JEI_INFO, "The Mechanical Sieve is a machine that, when supplied with a mesh and Forge Energy (FE), will sift blocks without a player having to do it themselves. It also supports three different modes of redstone control. Since Ex Deorum does not provide a way to generate FE, you will need another mod to provide power."); + english.add(TranslationKeys.MECHANICAL_HAMMER_JEI_INFO, "The Mechanical Hammer is a machine that, when supplied with Forge Energy (FE), will hammer blocks without a player having to do it themselves. It can operate without a hammer, but adding any hammer will double the speed, and efficiency enchantments on the hammer will further increase speed. It also supports three different modes of redstone control. Since Ex Deorum does not provide a way to generate FE, you will need another mod to provide power."); english.add(TranslationKeys.BARREL_COMPOST_CATEGORY_TITLE, "Barrel Compost"); english.add(TranslationKeys.BARREL_COMPOST_RECIPE_VOLUME, "Compost: %s"); diff --git a/src/main/java/thedarkcolour/exdeorum/data/TranslationKeys.java b/src/main/java/thedarkcolour/exdeorum/data/TranslationKeys.java index 3632c768..cfcce5ce 100644 --- a/src/main/java/thedarkcolour/exdeorum/data/TranslationKeys.java +++ b/src/main/java/thedarkcolour/exdeorum/data/TranslationKeys.java @@ -27,6 +27,7 @@ public class TranslationKeys { // ": %s / %s" public static final String FRACTION_DISPLAY = "item." + ExDeorum.ID + ".watering_can_fluid_display"; public static final String MECHANICAL_SIEVE_MESH_LABEL = "item." + ExDeorum.ID + ".mechanical_sieve.mesh_label"; + public static final String MECHANICAL_HAMMER_HAMMER_LABEL = "item." + ExDeorum.ID + ".mechanical_hammer.hammer_label"; public static final String ENERGY = "gui." + ExDeorum.ID + ".energy_label"; // Advancements @@ -53,6 +54,7 @@ public class TranslationKeys { public static final String CRIMSON_NYLIUM_SPORES_JEI_INFO = "info." + ExDeorum.ID + ".crimson_nylium_spores"; public static final String SCULK_CORE_JEI_INFO = "info." + ExDeorum.ID + ".sculk_core"; public static final String MECHANICAL_SIEVE_JEI_INFO = "info." + ExDeorum.ID + ".mechanical_sieve"; + public static final String MECHANICAL_HAMMER_JEI_INFO = "info." + ExDeorum.ID + ".mechanical_hammer"; // JEI recipe categories public static final String BARREL_COMPOST_CATEGORY_TITLE = "gui." + ExDeorum.ID + ".category.barrel_compost"; diff --git a/src/main/java/thedarkcolour/exdeorum/data/recipe/Recipes.java b/src/main/java/thedarkcolour/exdeorum/data/recipe/Recipes.java index b914ce89..3917f50d 100644 --- a/src/main/java/thedarkcolour/exdeorum/data/recipe/Recipes.java +++ b/src/main/java/thedarkcolour/exdeorum/data/recipe/Recipes.java @@ -291,6 +291,16 @@ public class Recipes { recipe.pattern("I I"); MKRecipeProvider.unlockedByHaving(recipe, Items.HOPPER); }); + recipes.shapedCrafting(RecipeCategory.MISC, EItems.MECHANICAL_HAMMER.get(), recipe -> { + recipe.define('#', Items.IRON_BLOCK); + recipe.define('H', Items.HOPPER); + recipe.define('T', EItemTags.HAMMERS); + recipe.define('I', Items.IRON_INGOT); + recipe.pattern("III"); + recipe.pattern("ITI"); + recipe.pattern("#H#"); + MKRecipeProvider.unlockedByHaving(recipe, Items.HOPPER); + }); } private static void modUShaped(MKRecipeProvider recipes, String modid, RegistryObject sides, RegistryObject middle, RegistryObject result) {