Skip to content

Commit

Permalink
feat: add redstone interaction to catalyst and caloric emitter
Browse files Browse the repository at this point in the history
Closes #169
  • Loading branch information
klikli-dev committed Jan 29, 2024
1 parent 38c5532 commit 4b285ca
Show file tree
Hide file tree
Showing 13 changed files with 178 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
// 1.20.4 2024-01-21T08:36:42.314088 Books: theurgy
// 1.20.4 2024-01-29T10:24:54.8769931 Books: theurgy
945f222b9db8c0781d05b5a13138c18620a0edc3 data/theurgy/modonomicon/books/the_hermetica/book.json
f44f61550bc8611d61016c6476b88448c0fe9f00 data/theurgy/modonomicon/books/the_hermetica/categories/apparatus.json
49226efd8791cdb701bf00d7af65fff59b8c6df6 data/theurgy/modonomicon/books/the_hermetica/categories/getting_started.json
1ed94d5ea5ec162931bc3f2d3ab7f53538649c35 data/theurgy/modonomicon/books/the_hermetica/entries/apparatus/calcination_oven.json
b5da837625577ec5594a17f064852d1cbb5b0bb1 data/theurgy/modonomicon/books/the_hermetica/entries/apparatus/caloric_flux_emitter.json
2f59e88b9b435092031224a05c90299f3992dc04 data/theurgy/modonomicon/books/the_hermetica/entries/apparatus/caloric_flux_emitter.json
682a5c691e10f6473336416cc18d1de384b72cdf data/theurgy/modonomicon/books/the_hermetica/entries/apparatus/digestion_vat.json
c6fe308150d65ff1b3b425a5d53896ccd13512f7 data/theurgy/modonomicon/books/the_hermetica/entries/apparatus/distiller.json
4b8335bf55ef3327003dbbab63b04e5261c8b1a7 data/theurgy/modonomicon/books/the_hermetica/entries/apparatus/fermentation_vat.json
64c59edc930e6004fc41dc845c1fcae7054d00c6 data/theurgy/modonomicon/books/the_hermetica/entries/apparatus/how_to.json
bdc02955ce9e92d1cf9653c17eab3bdb735f8cc1 data/theurgy/modonomicon/books/the_hermetica/entries/apparatus/incubator.json
e8ae6458c06a97d4af9ba06b61d7a1fbff6ec55c data/theurgy/modonomicon/books/the_hermetica/entries/apparatus/intro.json
e6d2cb3e87278172be31ced360585a0a60d6469a data/theurgy/modonomicon/books/the_hermetica/entries/apparatus/liquefaction_cauldron.json
50d3e3934abca7b63ec248cb2388bd61608ab550 data/theurgy/modonomicon/books/the_hermetica/entries/apparatus/mercury_catalyst.json
1379d3e06ffe00c07ca88b66727af8ee03568976 data/theurgy/modonomicon/books/the_hermetica/entries/apparatus/mercury_catalyst.json
6030e1795985c3c00c23355a7c959f3ef902c62f data/theurgy/modonomicon/books/the_hermetica/entries/apparatus/mercury_flux.json
11eab5bee6905778c93c363dac2b9b222091f13b data/theurgy/modonomicon/books/the_hermetica/entries/apparatus/pyromantic_brazier.json
0c53e8692e28132185f384964c77f6bdf95ab549 data/theurgy/modonomicon/books/the_hermetica/entries/apparatus/reformation_array.json
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// 1.20.4 2024-01-16T15:38:38.1712209 Block States: theurgy
// 1.20.4 2024-01-29T10:24:54.8834977 Block States: theurgy
ef875fc2604f4f19d7604536c66d3d2c26163879 assets/theurgy/blockstates/calcination_oven.json
35782a4ebfe09e4f246b30170c9cec57e31cdcee assets/theurgy/blockstates/caloric_flux_emitter.json
fa912507f89d2fe9ac05c8b057aed16d83f0d96c assets/theurgy/blockstates/caloric_flux_emitter.json
92ebf87f417e3426f30d3e42eeafd933e446eb23 assets/theurgy/blockstates/deepslate_sal_ammoniac_ore.json
aa5b831a5365636dbec64150a2508554d45e7c65 assets/theurgy/blockstates/digestion_vat.json
efc838dc92770522219889024bec42cc52fb93bd assets/theurgy/blockstates/distiller.json
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// 1.20.4 2024-01-27T08:06:31.2341441 Languages: en_us
fe8ef516da63fa8669dd7ee023113f0ef1e5becd assets/theurgy/lang/en_us.json
// 1.20.4 2024-01-29T10:24:54.88551 Languages: en_us
49743472b33ae5364ddc2ffced3da3b8a3351d97 assets/theurgy/lang/en_us.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,53 @@
{
"variants": {
"facing=down": {
"enabled=false,facing=down": {
"model": "theurgy:block/caloric_flux_emitter",
"x": 180
},
"facing=east": {
"enabled=false,facing=east": {
"model": "theurgy:block/caloric_flux_emitter",
"x": 90,
"y": 90
},
"facing=north": {
"enabled=false,facing=north": {
"model": "theurgy:block/caloric_flux_emitter",
"x": 90
},
"facing=south": {
"enabled=false,facing=south": {
"model": "theurgy:block/caloric_flux_emitter",
"x": 90,
"y": 180
},
"facing=up": {
"enabled=false,facing=up": {
"model": "theurgy:block/caloric_flux_emitter"
},
"facing=west": {
"enabled=false,facing=west": {
"model": "theurgy:block/caloric_flux_emitter",
"x": 90,
"y": 270
},
"enabled=true,facing=down": {
"model": "theurgy:block/caloric_flux_emitter",
"x": 180
},
"enabled=true,facing=east": {
"model": "theurgy:block/caloric_flux_emitter",
"x": 90,
"y": 90
},
"enabled=true,facing=north": {
"model": "theurgy:block/caloric_flux_emitter",
"x": 90
},
"enabled=true,facing=south": {
"model": "theurgy:block/caloric_flux_emitter",
"x": 90,
"y": 180
},
"enabled=true,facing=up": {
"model": "theurgy:block/caloric_flux_emitter"
},
"enabled=true,facing=west": {
"model": "theurgy:block/caloric_flux_emitter",
"x": 90,
"y": 270
Expand Down
4 changes: 4 additions & 0 deletions src/generated/resources/assets/theurgy/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@
"book.theurgy.the_hermetica.apparatus.caloric_flux_emitter.description": "Efficiently powering alchemical Apparatus",
"book.theurgy.the_hermetica.apparatus.caloric_flux_emitter.intro.text": "This devices converts raw mercury flux into [#](ad03fc)Caloric Flux[#](), or simply: transferable heat. It can be used to power other alchemical apparatuses that would usually need a [](item://theurgy:pyromantic_brazier) below them.\n",
"book.theurgy.the_hermetica.apparatus.caloric_flux_emitter.name": "Caloric Flux Emitter",
"book.theurgy.the_hermetica.apparatus.caloric_flux_emitter.redstone.text": "By default the block is enabled.\n\\\n\\\nYou can disable it with an active redstone signal.\n\\\n\\\nWhen disabled, the emitter will not send caloric flux to the target block.\n",
"book.theurgy.the_hermetica.apparatus.caloric_flux_emitter.redstone.title": "Redstone",
"book.theurgy.the_hermetica.apparatus.caloric_flux_emitter.usage.text": "Right-click the target block with the [](item://theurgy:caloric_flux_emitter) until it is highlighted. Then place the Emitter onto a Mercury Flux source, such as a [](item://theurgy:mercury_catalyst).\\\nThe maximum range is **8** blocks.\\\nAs long as mercury flux is provided to it, the emitter will send caloric flux to the target block and keep it heated.\n",
"book.theurgy.the_hermetica.apparatus.caloric_flux_emitter.usage.title": "Usage",
"book.theurgy.the_hermetica.apparatus.digestion_vat.description": "Convert Alchemical Niter from one tier to another",
Expand Down Expand Up @@ -135,6 +137,8 @@
"book.theurgy.the_hermetica.apparatus.mercury_catalyst.description": "Accessing Raw Energy",
"book.theurgy.the_hermetica.apparatus.mercury_catalyst.intro.text": "This apparatus slowly converts [](item://theurgy:mercury_shard) into [#](ad03fc)Mercury Flux[#](), which can be used as a source of Energy. It is the first step towards using the Energy contained in matter.\n",
"book.theurgy.the_hermetica.apparatus.mercury_catalyst.name": "Mercury Catalyst",
"book.theurgy.the_hermetica.apparatus.mercury_catalyst.redstone.text": "By default the block is enabled.\n\\\n\\\nYou can disable it with an active redstone signal.\n\\\n\\\nWhen disabled, the catalyst will **still** convert mercury shards into mercury flux, but it will not output it to neighboring blocks.\n",
"book.theurgy.the_hermetica.apparatus.mercury_catalyst.redstone.title": "Redstone",
"book.theurgy.the_hermetica.apparatus.mercury_catalyst.usage.text": "Place the [](item://theurgy:mercury_catalyst), then insert [](item://theurgy:mercury_shard) by right-clicking the Catalyst with it. It will begin to slowly fill up with [#](ad03fc)Mercury Flux[#]().\n\\\n\\\nIts sides will turn more and more blue as it fills up.\n",
"book.theurgy.the_hermetica.apparatus.mercury_catalyst.usage.title": "Usage",
"book.theurgy.the_hermetica.apparatus.mercury_flux.description": "Raw Energy Manipulation",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@
"title": "book.theurgy.the_hermetica.apparatus.caloric_flux_emitter.usage.title",
"use_markdown_in_title": false
},
{
"type": "modonomicon:text",
"anchor": "",
"show_title_separator": true,
"text": "book.theurgy.the_hermetica.apparatus.caloric_flux_emitter.redstone.text",
"title": "book.theurgy.the_hermetica.apparatus.caloric_flux_emitter.redstone.title",
"use_markdown_in_title": false
},
{
"type": "modonomicon:crafting_recipe",
"anchor": "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@
"title": "book.theurgy.the_hermetica.apparatus.mercury_catalyst.usage.title",
"use_markdown_in_title": false
},
{
"type": "modonomicon:text",
"anchor": "",
"show_title_separator": true,
"text": "book.theurgy.the_hermetica.apparatus.mercury_catalyst.redstone.text",
"title": "book.theurgy.the_hermetica.apparatus.mercury_catalyst.redstone.title",
"use_markdown_in_title": false
},
{
"type": "modonomicon:crafting_recipe",
"anchor": "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
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.BlockStateProperties;
import net.minecraft.world.level.block.state.properties.BooleanProperty;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;
import org.jetbrains.annotations.NotNull;
Expand All @@ -31,6 +33,8 @@
public class CaloricFluxEmitterBlock extends DirectionalBlock implements EntityBlock {

public static final MapCodec<CaloricFluxEmitterBlock> CODEC = simpleCodec(CaloricFluxEmitterBlock::new);

public static final BooleanProperty ENABLED = BlockStateProperties.ENABLED;
private static final int SHAPE_LENGTH = 4;
private static final Map<Direction, VoxelShape> SHAPES = Maps.newEnumMap(
ImmutableMap.<Direction, VoxelShape>builder()
Expand All @@ -47,7 +51,7 @@ public class CaloricFluxEmitterBlock extends DirectionalBlock implements EntityB
public CaloricFluxEmitterBlock(Properties pProperties) {
super(pProperties);
this.selectionBehaviour = new CaloricFluxEmitterSelectionBehaviour();
this.registerDefaultState(this.stateDefinition.any().setValue(FACING, Direction.UP));
this.registerDefaultState(this.stateDefinition.any().setValue(FACING, Direction.UP).setValue(ENABLED, true));
}

public SelectionBehaviour<CaloricFluxEmitterSelectedPoint> selectionBehaviour() {
Expand All @@ -64,16 +68,20 @@ public SelectionBehaviour<CaloricFluxEmitterSelectedPoint> selectionBehaviour()
@Override
public BlockState getStateForPlacement(BlockPlaceContext pContext) {
Direction direction = pContext.getClickedFace();
BlockState blockstate = pContext.getLevel().getBlockState(pContext.getClickedPos().relative(direction.getOpposite()));
return blockstate.is(this) && blockstate.getValue(FACING) == direction ?
this.defaultBlockState().setValue(FACING, direction.getOpposite()) : this.defaultBlockState().setValue(FACING, direction);
BlockState oppositeState = pContext.getLevel().getBlockState(pContext.getClickedPos().relative(direction.getOpposite()));

var placementState = this.defaultBlockState().setValue(ENABLED, true);

return oppositeState.is(this) && oppositeState.getValue(FACING) == direction ?
placementState.setValue(FACING, direction.getOpposite()) : placementState.setValue(FACING, direction);
}


@SuppressWarnings("deprecation")
@Override
public void neighborChanged(BlockState pState, Level pLevel, BlockPos pPos, Block pBlock, BlockPos pFromPos, boolean pIsMoving) {
super.neighborChanged(pState, pLevel, pPos, pBlock, pFromPos, pIsMoving);
this.checkPoweredState(pLevel, pPos, pState, Block.UPDATE_INVISIBLE);

if (!this.canSurvive(pState, pLevel, pPos)) {
pLevel.destroyBlock(pPos, true);
Expand All @@ -88,6 +96,22 @@ public boolean canSurvive(BlockState pState, LevelReader pLevel, BlockPos pPos)
return facingNeighborState.isFaceSturdy(pLevel, pPos, facing);
}

@SuppressWarnings("deprecation")
@Override
public void onPlace(BlockState pState, Level pLevel, BlockPos pPos, BlockState pOldState, boolean pIsMoving) {
if (!pOldState.is(pState.getBlock())) {
this.checkPoweredState(pLevel, pPos, pState, Block.UPDATE_CLIENTS);
}
}

private void checkPoweredState(Level pLevel, BlockPos pPos, BlockState pState, int pFlags) {
boolean enabled = !pLevel.hasNeighborSignal(pPos);
if (enabled != pState.getValue(ENABLED)) {
pLevel.setBlock(pPos, pState.setValue(ENABLED, enabled), pFlags);
}

}

@SuppressWarnings("deprecation")
@Override
public @NotNull BlockState rotate(BlockState state, Rotation rot) {
Expand All @@ -102,7 +126,7 @@ public boolean canSurvive(BlockState pState, LevelReader pLevel, BlockPos pPos)

@Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> pBuilder) {
pBuilder.add(FACING);
pBuilder.add(FACING, ENABLED);
}

@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import net.minecraft.nbt.NbtOps;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -51,6 +52,9 @@ public void tickServer() {
if (this.getLevel().getGameTime() % TICK_INTERVAL != 0)
return; //slow tick

if(!this.getBlockState().getValue(BlockStateProperties.ENABLED))
return; //disabled with active redstone

if (this.selectedPoints.isEmpty())
return;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,39 @@
import com.klikli_dev.theurgy.content.behaviour.itemhandler.OneSlotItemHandlerBehaviour;
import com.klikli_dev.theurgy.registry.BlockEntityRegistry;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.BlockAndTintGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.EntityBlock;
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.BlockStateProperties;
import net.minecraft.world.level.block.state.properties.BooleanProperty;
import net.minecraft.world.phys.BlockHitResult;
import org.jetbrains.annotations.Nullable;


public class MercuryCatalystBlock extends Block implements EntityBlock {

public static final BooleanProperty ENABLED = BlockStateProperties.ENABLED;

protected ItemHandlerBehaviour itemHandlerBehaviour;

public MercuryCatalystBlock(Properties pProperties) {
super(pProperties);

this.itemHandlerBehaviour = new OneSlotItemHandlerBehaviour();
this.registerDefaultState(this.stateDefinition.any().setValue(ENABLED, true));
}

public static int getBlockColor(BlockState pState, BlockAndTintGetter pLevel, BlockPos pPos, int pTintIndex) {
Expand Down Expand Up @@ -86,6 +95,43 @@ public InteractionResult use(BlockState pState, Level pLevel, BlockPos pPos, Pla
return InteractionResult.PASS;
}

@Nullable
@Override
public BlockState getStateForPlacement(BlockPlaceContext pContext) {
return this.defaultBlockState().setValue(ENABLED, true);
}


@SuppressWarnings("deprecation")
@Override
public void neighborChanged(BlockState pState, Level pLevel, BlockPos pPos, Block pBlock, BlockPos pFromPos, boolean pIsMoving) {
super.neighborChanged(pState, pLevel, pPos, pBlock, pFromPos, pIsMoving);

this.checkPoweredState(pLevel, pPos, pState, Block.UPDATE_INVISIBLE);
}


@SuppressWarnings("deprecation")
@Override
public void onPlace(BlockState pState, Level pLevel, BlockPos pPos, BlockState pOldState, boolean pIsMoving) {
if (!pOldState.is(pState.getBlock())) {
this.checkPoweredState(pLevel, pPos, pState, Block.UPDATE_CLIENTS);
}
}

private void checkPoweredState(Level pLevel, BlockPos pPos, BlockState pState, int pFlags) {
boolean enabled = !pLevel.hasNeighborSignal(pPos);
if (enabled != pState.getValue(ENABLED)) {
pLevel.setBlock(pPos, pState.setValue(ENABLED, enabled), pFlags);
}

}

@Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> pBuilder) {
pBuilder.add(ENABLED);
}

@Nullable
@Override
public BlockEntity newBlockEntity(BlockPos pPos, BlockState pState) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.neoforged.neoforge.items.ItemStackHandler;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -98,7 +99,9 @@ public void tickServer() {
this.craftingBehaviour.tickServer(true, hasInput);

if (this.getLevel().getGameTime() % PUSH_TICK_INTERVAL == 0) {
this.pushMercuryFlux();
if(this.getBlockState().getValue(BlockStateProperties.ENABLED)){
this.pushMercuryFlux();
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,23 @@ protected void generatePages() {
this.itemLink(ItemRegistry.MERCURY_CATALYST.get())
);

this.page("redstone", () -> BookTextPageModel.create()
.withTitle(this.context().pageTitle())
.withText(this.context().pageText())
);
this.pageTitle("Redstone");
this.pageText(
"""
By default the block is enabled.
\\
\\
You can disable it with an active redstone signal.
\\
\\
When disabled, the emitter will not send caloric flux to the target block.
"""
);

this.page("recipe", () -> BookCraftingRecipePageModel.create()
.withRecipeId1(Theurgy.loc("crafting/shaped/caloric_flux_emitter_from_campfire"))
.withRecipeId2(Theurgy.loc("crafting/shaped/caloric_flux_emitter_from_lava_bucket")));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,26 @@ protected void generatePages() {
this.itemLink(ItemRegistry.MERCURY_SHARD.get())
);

this.page("redstone", () -> BookTextPageModel.create()
.withTitle(this.context().pageTitle())
.withText(this.context().pageText())
);
this.pageTitle("Redstone");
this.pageText(
"""
By default the block is enabled.
\\
\\
You can disable it with an active redstone signal.
\\
\\
When disabled, the catalyst will **still** convert mercury shards into mercury flux, but it will not output it to neighboring blocks.
"""
);

this.page("recipe", () -> BookCraftingRecipePageModel.create()
.withRecipeId1(Theurgy.loc("crafting/shaped/mercury_catalyst")));
.withRecipeId1(Theurgy.loc("crafting/shaped/mercury_catalyst"))
);
}

@Override
Expand Down

0 comments on commit 4b285ca

Please sign in to comment.