Skip to content

Commit

Permalink
Rename it to Arithmetic Operator and make it accessible in vanilla. M…
Browse files Browse the repository at this point in the history
…ake some previously hardcoded things translatable
  • Loading branch information
Patbox committed Apr 11, 2024
1 parent b26e241 commit 56285d3
Show file tree
Hide file tree
Showing 23 changed files with 150 additions and 74 deletions.
28 changes: 21 additions & 7 deletions changelog-next.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
- Added Turntable - Rotate entities on top!
- Added Steel Button - Fastest button in the game (5 ticks of activation).
- Added "alt actions" to Wrenches:
- Can be used by pressing F / item hand swap key.
- Instead of swapping hands, it will perform alternative action on a block.
- Currently only one available is making direction setting face the player.
- By default falls back to the main action.
- Added Arithmetic Operator:
- New "data" block!
- It has two inputs and an output, with all of them having configurable channel and direction, while still allowing overlap.
- Can be used to execute operations such as addition, subtraction, multiplication and division.
- Can operate in 4 modes: Integer, Decimal, Boolean and String.
- Added Turntable:
- Currently can be used to rotate entities on top of it.
- Crafted with a Wooden Slab and an Axle.
- Added Steel Button:
- Fastest button in the game (5 ticks of activation).
- Crafted with a single Steel Ingot.
- Wrench changes:
- Added "alt actions" to Wrenches:
- Can be used by pressing F / item hand swap key.
- Instead of swapping hands, it will perform alternative action on a block.
- Currently only one available is making direction setting face the player.
- By default falls back to the main action.
- Added translations for many wrench action values!
- Recipe changes:
- Steel Gear recipe now gives 3 gears instead of 2.
- Large Steel Gear recipe requires now only a single Steel Ingot instead of two.
- New textures: Steel Alloy Mixture.
- You can now put Potato on a Spring on your head.
- Tweaked how cables/data is handled:
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ org.gradle.parallel=true
loader_version=0.15.0

# Mod Properties
mod_version = 0.3.4
mod_version = 0.3.5
maven_group = eu.pb4
archives_base_name = polyfactory

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public class FactoryBlockEntities {
public static final BlockEntityType<ItemReaderBlockEntity> ITEM_READER = register("item_reader", FabricBlockEntityTypeBuilder
.create(ItemReaderBlockEntity::new).addBlock(FactoryBlocks.ITEM_READER));
public static final BlockEntityType<DoubleInputTransformerBlockEntity> DOUBLE_INPUT_TRANSFORMER = register("double_input_transformer", FabricBlockEntityTypeBuilder
.create(DoubleInputTransformerBlockEntity::new).addBlocks(FactoryBlocks.DATA_ARITHMETICS));
.create(DoubleInputTransformerBlockEntity::new).addBlocks(FactoryBlocks.ARITHMETIC_OPERATOR));

public static final BlockEntityType<WorkbenchBlockEntity> WORKBENCH = register("workbench", FabricBlockEntityTypeBuilder
.create(WorkbenchBlockEntity::new).addBlock(FactoryBlocks.WORKBENCH));
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/eu/pb4/polyfactory/block/FactoryBlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import eu.pb4.polyfactory.block.creative.CreativeContainerBlock;
import eu.pb4.polyfactory.block.creative.CreativeMotorBlock;
import eu.pb4.polyfactory.block.data.AbstractCableBlock;
import eu.pb4.polyfactory.block.data.ArithmeticOperatorBlock;
import eu.pb4.polyfactory.block.data.CableBlock;
import eu.pb4.polyfactory.block.data.DataArithmeticsBlock;
import eu.pb4.polyfactory.block.data.output.*;
import eu.pb4.polyfactory.block.data.providers.*;
import eu.pb4.polyfactory.block.electric.ElectricGeneratorBlock;
Expand Down Expand Up @@ -72,8 +72,8 @@ public class FactoryBlocks {
public static final RedstoneOutputBlock REDSTONE_OUTPUT = register("redstone_output", new RedstoneOutputBlock(AbstractBlock.Settings.copy(ITEM_COUNTER)));
public static final ItemReaderBlock ITEM_READER = register("item_reader", new ItemReaderBlock(AbstractBlock.Settings.copy(ITEM_COUNTER)));
public static final BlockObserverBlock BLOCK_OBSERVER = register("block_observer", new BlockObserverBlock(AbstractBlock.Settings.copy(ITEM_COUNTER)));
public static final DataArithmeticsBlock DATA_ARITHMETICS = register("data_arithmetics",
new DataArithmeticsBlock(AbstractBlock.Settings.copy(ITEM_COUNTER)));
public static final ArithmeticOperatorBlock ARITHMETIC_OPERATOR = register("arithmetic_operator",
new ArithmeticOperatorBlock(AbstractBlock.Settings.copy(ITEM_COUNTER)));

public static final HologramProjectorBlock HOLOGRAM_PROJECTOR = register("hologram_projector", new HologramProjectorBlock(AbstractBlock.Settings.copy(SPLITTER)));
public static final NixieTubeBlock NIXIE_TUBE = register("nixie_tube", new NixieTubeBlock(Block.Settings.copy(Blocks.GLASS).nonOpaque()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import net.minecraft.state.property.BooleanProperty;
import net.minecraft.state.property.DirectionProperty;
import net.minecraft.state.property.Properties;
import net.minecraft.text.Text;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.World;
Expand All @@ -22,7 +23,7 @@ public abstract class AxisAndFacingBlock extends Block implements WrenchableBloc
public static final DirectionProperty FACING = Properties.FACING;
public static final BooleanProperty FIRST_AXIS = BooleanProperty.of("first_axis");
public static final WrenchAction FIRST_AXIS_ACTION = WrenchAction.of("axis", (World world, BlockPos pos, Direction side, BlockState state) -> {
return getAxis(state).asString();
return Text.literal(getAxis(state).asString());
}, WrenchApplyAction.ofProperty(FIRST_AXIS));

public AxisAndFacingBlock(Settings settings) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,87 +1,83 @@
package eu.pb4.polyfactory.block.data;

import com.google.common.collect.ImmutableList;
import com.kneelawk.graphlib.api.graph.NodeHolder;
import eu.pb4.polyfactory.data.*;
import eu.pb4.polyfactory.item.wrench.WrenchAction;
import eu.pb4.polyfactory.nodes.DirectionNode;
import eu.pb4.polyfactory.nodes.FactoryNodes;
import eu.pb4.polyfactory.nodes.data.DataProviderNode;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.EnumProperty;
import net.minecraft.text.Text;
import net.minecraft.util.StringIdentifiable;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

import java.util.Collections;
import java.util.List;
import java.util.Locale;

public class DataArithmeticsBlock extends DoubleInputTransformerBlock {
public static final EnumProperty<Action> ACTION = EnumProperty.of("action", Action.class);
public class ArithmeticOperatorBlock extends DoubleInputTransformerBlock {
public static final EnumProperty<Operation> OPERATION = EnumProperty.of("operation", Operation.class);
public static final EnumProperty<Mode> MODE = EnumProperty.of("mode", Mode.class);

public static final List<WrenchAction> WRENCH_ACTIONS = ImmutableList.<WrenchAction>builder()
.addAll(DoubleInputTransformerBlock.WRENCH_ACTIONS)
.add(WrenchAction.of("action", ACTION))
.add(WrenchAction.of("mode", MODE))
.add(WrenchAction.of("operation", OPERATION, t -> Text.translatable("item.polyfactory.wrench.action.operation.arithmetic." + t.asString())))
.add(WrenchAction.of("mode", MODE, t -> Text.translatable("item.polyfactory.wrench.action.mode.arithmetic." + t.asString())))
.build();

public DataArithmeticsBlock(Settings settings) {
public ArithmeticOperatorBlock(Settings settings) {
super(settings);
this.setDefaultState(this.getDefaultState().with(ACTION, Action.ADD).with(MODE, Mode.INTEGER));
this.setDefaultState(this.getDefaultState().with(OPERATION, Operation.ADDITION).with(MODE, Mode.INTEGER));
}

@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
super.appendProperties(builder);
builder.add(ACTION, MODE);
builder.add(OPERATION, MODE);
}

@Override
public void onStateReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean moved) {
super.onStateReplaced(state, world, pos, newState, moved);
if (state.isOf(newState.getBlock()) && (state.get(MODE) != newState.get(MODE) || state.get(ACTION) != newState.get(ACTION))
if (state.isOf(newState.getBlock()) && (state.get(MODE) != newState.get(MODE) || state.get(OPERATION) != newState.get(OPERATION))
&& world instanceof ServerWorld serverWorld && world.getBlockEntity(pos) instanceof DoubleInputTransformerBlockEntity be) {
sendData(world, newState.get(FACING_OUTPUT), pos, this.transformData(be.lastInput1(), be.lastInput2(), serverWorld, pos, newState, be));
}
}

@Override
protected DataContainer transformData(DataContainer input1, DataContainer input2, ServerWorld world, BlockPos selfPos, BlockState selfState, DoubleInputTransformerBlockEntity be) {
var action = selfState.get(ACTION);
var action = selfState.get(OPERATION);
var mode = selfState.get(MODE);

return switch (action) {
case ADD -> switch (mode) {
case ADDITION -> switch (mode) {
case INTEGER -> new LongData(input1.asLong() + input2.asLong());
case DECIMAL -> new DoubleData(input1.asDouble() + input2.asDouble());
case BOOLEAN -> new BoolData(input1.isTrue() || input2.isTrue());
case STRING -> StringData.ofLimited(input1.asString() + input2.asString());
};
case SUBTRACT -> switch (mode) {
case SUBTRACTION -> switch (mode) {
case INTEGER -> new LongData(input1.asLong() - input2.asLong());
case DECIMAL -> new DoubleData(input1.asDouble() - input2.asDouble());
case BOOLEAN -> new BoolData(input1.isTrue() && !input2.isTrue());
case STRING -> StringData.ofLimited(input1.asString().replace(input2.asString(), ""));
};
case MULTIPLY -> switch (mode) {
case MULTIPLICATION -> switch (mode) {
case INTEGER -> new LongData(input1.asLong() * input2.asLong());
case DECIMAL -> new DoubleData(input1.asDouble() * input2.asDouble());
case BOOLEAN -> new BoolData(input1.isTrue() && input2.isTrue());
case STRING -> StringData.EMPTY;
};
case DIVIDE -> switch (mode) {
case DIVISION -> switch (mode) {
case INTEGER -> input2.asLong() != 0 ? new LongData(input1.asLong() / input2.asLong()) : LongData.ZERO;
case DECIMAL -> new DoubleData(input1.asDouble() / input2.asDouble());
case BOOLEAN -> new BoolData(!input1.isTrue() && !input2.isTrue());
case STRING -> StringData.EMPTY;
};

case DIVIDE_REST -> switch (mode) {
case MODULO -> switch (mode) {
case INTEGER -> input2.asLong() != 0 ? new LongData(input1.asLong() % input2.asLong()) : LongData.ZERO;
case DECIMAL -> new DoubleData(input1.asDouble() % input2.asDouble());
case BOOLEAN -> new BoolData(!input1.isTrue() || !input2.isTrue());
Expand All @@ -90,12 +86,12 @@ protected DataContainer transformData(DataContainer input1, DataContainer input2
};
}

public enum Action implements StringIdentifiable {
ADD,
SUBTRACT,
MULTIPLY,
DIVIDE,
DIVIDE_REST
public enum Operation implements StringIdentifiable {
ADDITION,
SUBTRACTION,
MULTIPLICATION,
DIVISION,
MODULO
;

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import net.minecraft.network.packet.s2c.play.ParticleS2CPacket;
import net.minecraft.particle.DustColorTransitionParticleEffect;
import net.minecraft.particle.ParticleEffect;
import net.minecraft.screen.ScreenTexts;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.state.StateManager;
Expand Down Expand Up @@ -74,45 +75,45 @@ public class HologramProjectorBlock extends DataNetworkBlock implements FactoryB
for (var i = 0; i < state.get(FRONT); i++) {
rot = rot.rotateClockwise(axis);
}
return rot.asString();
return FactoryUtil.asText(rot);
} else {
var rot = Direction.UP;
for (var i = 0; i < state.get(FRONT); i++) {
rot = rot.rotateCounterclockwise(axis);
}
return rot.asString();
return FactoryUtil.asText(rot);
}
}, WrenchApplyAction.ofProperty(FRONT));

public static final WrenchAction SCALE = WrenchAction.ofBlockEntity("scale", HologramProjectorBlockEntity.class,
public static final WrenchAction SCALE = WrenchAction.ofBlockEntityString("scale", HologramProjectorBlockEntity.class,
x -> String.format(Locale.ROOT, "%.1f", x.scale()),
(x, n) -> x.setScale(FactoryUtil.wrap(x.scale() + (n ? 0.5f : -0.5f), 1, 5) )
);

public static final WrenchAction OFFSET = WrenchAction.ofBlockEntity("offset", HologramProjectorBlockEntity.class,
public static final WrenchAction OFFSET = WrenchAction.ofBlockEntityString("offset", HologramProjectorBlockEntity.class,
x -> String.format(Locale.ROOT,"%.1f", x.offset()),
(x, n) -> x.setOffset(FactoryUtil.wrap(x.offset() + (n ? 0.1f : -0.1f), 0.1f, 1.5f))
);

public static final WrenchAction CHANGE_PITCH = WrenchAction.ofBlockEntity("pitch", HologramProjectorBlockEntity.class,
public static final WrenchAction CHANGE_PITCH = WrenchAction.ofBlockEntityString("pitch", HologramProjectorBlockEntity.class,
x -> Math.round(x.pitch() * MathHelper.DEGREES_PER_RADIAN) + "°",
(x, n) -> x.setPitch(FactoryUtil.wrap(x.pitch() + MathHelper.RADIANS_PER_DEGREE * (n ? 5 : -5),
0, MathHelper.TAU - MathHelper.RADIANS_PER_DEGREE * 5))
);

public static final WrenchAction CHANGE_YAW = WrenchAction.ofBlockEntity("yaw", HologramProjectorBlockEntity.class,
public static final WrenchAction CHANGE_YAW = WrenchAction.ofBlockEntityString("yaw", HologramProjectorBlockEntity.class,
x -> Math.round(x.yaw() * MathHelper.DEGREES_PER_RADIAN) + "°",
(x, n) -> x.setYaw(FactoryUtil.wrap(x.yaw() + MathHelper.RADIANS_PER_DEGREE * (n ? 5 : -5),
0, MathHelper.TAU - MathHelper.RADIANS_PER_DEGREE * 5))
);
public static final WrenchAction CHANGE_ROLL = WrenchAction.ofBlockEntity("roll", HologramProjectorBlockEntity.class,
public static final WrenchAction CHANGE_ROLL = WrenchAction.ofBlockEntityString("roll", HologramProjectorBlockEntity.class,
x -> Math.round(x.roll() * MathHelper.DEGREES_PER_RADIAN) + "°",
(x, n) -> x.setRoll(FactoryUtil.wrap(x.roll() + MathHelper.RADIANS_PER_DEGREE * (n ? 5 : -5),
0, MathHelper.TAU - MathHelper.RADIANS_PER_DEGREE * 5))
);

public static final WrenchAction FORCE_TEXT = WrenchAction.ofBlockEntity("force_text", HologramProjectorBlockEntity.class,
x -> Boolean.toString(x.forceText()),
x -> ScreenTexts.onOrOff(x.forceText()),
(x, n) -> x.setForceText(!x.forceText())
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.BlockEntityTicker;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.screen.ScreenTexts;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.BooleanProperty;
import net.minecraft.state.property.Properties;
import net.minecraft.text.Text;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.BlockView;
Expand All @@ -34,11 +36,11 @@ public class NixieTubeControllerBlock extends GenericCabledDataBlock implements
public static final BooleanProperty POWERED = Properties.POWERED;

public static final WrenchAction SCROLL_LOOP = WrenchAction.ofBlockEntity("scroll_loop", NixieTubeControllerBlockEntity.class,
x -> "" + x.scrollLoop(),
x -> ScreenTexts.onOrOff(x.scrollLoop()),
(x, n) -> x.setScrollLoop(!x.scrollLoop())
);
public static final WrenchAction SCROLL_SPEED = WrenchAction.ofBlockEntity("scroll_speed", NixieTubeControllerBlockEntity.class,
x -> String.format(Locale.ROOT,"%.2f char/sec", x.scrollSpeed() == 0 ? 0 : (20f / x.scrollSpeed())),
x -> Text.translatable("text.polyfactory.char_per_sec", String.format(Locale.ROOT,"%.2f", x.scrollSpeed() == 0 ? 0 : (20f / x.scrollSpeed()))),
(x, n) -> x.setScrollSpeed(FactoryUtil.wrap(x.scrollSpeed() + (n ? 1 : -1), 0, 80))
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
public abstract class GenericCabledDataBlock extends AbstractCableBlock implements WrenchableBlock, BlockEntityProvider, CableConnectable {
public static final DirectionProperty FACING = Properties.FACING;

public final WrenchAction facingAction = WrenchAction.of("facing", WrenchValueGetter.ofProperty(Properties.FACING),
public final WrenchAction facingAction = WrenchAction.of("facing", WrenchValueGetter.ofProperty(Properties.FACING, FactoryUtil::asText),
WrenchApplyAction.ofState(
(player, world, pos, side, state, next) -> {
var oldDir = state.get(FACING);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import net.minecraft.client.render.model.json.ModelTransformationMode;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.item.ItemStack;
import net.minecraft.screen.ScreenTexts;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.state.StateManager;
Expand All @@ -57,7 +58,7 @@ public class FanBlock extends RotationalNetworkBlock implements FactoryBlock, Ro
public static final BooleanProperty ENABLED = Properties.ENABLED;
public static final BooleanProperty REVERSE = BooleanProperty.of("reverse");

public static final WrenchAction REVERSE_ACTION = WrenchAction.of("reverse", REVERSE);
public static final WrenchAction REVERSE_ACTION = WrenchAction.of("reverse", REVERSE, ScreenTexts::onOrOff);

public FanBlock(Settings settings) {
super(settings);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import net.minecraft.state.property.DirectionProperty;
import net.minecraft.state.property.EnumProperty;
import net.minecraft.state.property.Properties;
import net.minecraft.text.Text;
import net.minecraft.util.*;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.*;
Expand All @@ -54,7 +55,7 @@ public class FunnelBlock extends Block implements FactoryBlock, MovingItemConsum
public static final EnumProperty<ConveyorLikeDirectional.TransferMode> MODE = EnumProperty.of("mode", ConveyorLikeDirectional.TransferMode.class,
ConveyorLikeDirectional.TransferMode.FROM_CONVEYOR, ConveyorLikeDirectional.TransferMode.TO_CONVEYOR);

private static final WrenchAction MODE_ACTION = WrenchAction.of("mode", MODE);
private static final WrenchAction MODE_ACTION = WrenchAction.of("mode", MODE, t -> Text.translatable("item.polyfactory.wrench.action.mode.transfer_mode." + t.asString()));

public FunnelBlock(Settings settings) {
super(settings);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ protected void configure(RegistryWrapper.WrapperLookup arg) {
.add(FactoryBlocks.WIRELESS_REDSTONE_RECEIVER)
.add(FactoryBlocks.WIRELESS_REDSTONE_TRANSMITTER)
.add(FactoryBlocks.HOLOGRAM_PROJECTOR)
.add(FactoryBlocks.ARITHMETIC_OPERATOR)
.add(FactoryBlocks.METAL_GRID)
.add(FactoryBlocks.ITEM_READER)
.add(FactoryBlocks.BLOCK_OBSERVER)
Expand Down
Loading

0 comments on commit 56285d3

Please sign in to comment.