Skip to content

Commit

Permalink
Tachometer and Stressometer, general fixes all around the mod
Browse files Browse the repository at this point in the history
  • Loading branch information
Patbox committed Feb 19, 2024
1 parent 2adf44a commit 95607b9
Show file tree
Hide file tree
Showing 61 changed files with 922 additions and 103 deletions.
20 changes: 10 additions & 10 deletions changelog-next.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
- Added Wireless Redstone Receiver and Transmitter - allows you to remotely transmit redstone pulses in a range of 64 blocks! Uses 2 item channel system.
- Added Portable Redstone Transmitter - allows you to active Redstone Receivers from your inventory!
- Added Hologram Projector - new display block that can show a hologram of Items/Block/Other data in world! Configurable with a Wrench.
- Added Workbench - Crafting Table that keeps its items after closing. The classic for any modded experience.
- Added Ender Dust and Ender infused Amethyst Shard - new ingredient items.
- Added sounds to Wrench actions.
- Removed recipes for Electric Motor/Generator. Both of these items were unfinished and require extra work.
- Piston movable blocks now move smoothly instead of vanishing.
- Changed crafting behaviour of Mechanical Mixer. It will not try to fill all available slots.
- Tweaked existing recipes and added few new ones!
- Added Tachometer (measures rotations per minute) and Stressometer (measures stress units left).
Both require connection to some display (Hologram Projector, Nixie Tube) to display their values.
- Added option to force everything to display as text in Hologram Projector.
- Mechanical Placers can now use selected items on blocks.
- Hoppers, Pistons, Redstone Repeater, Redstone Comparator, Dispensers and Droppers are now rotable with wrench.
- Added breaking particles to all the blocks that didn't have them.
- Fixed some bugs with displaying Holograms Projectors.
- All crafting-machines should now work with hoppers.


Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ public class FactoryBlockEntities {
public static final BlockEntityType<CreativeMotorBlockEntity> CREATIVE_MOTOR = register("creative_motor",
FabricBlockEntityTypeBuilder.create(CreativeMotorBlockEntity::new).addBlock(FactoryBlocks.CREATIVE_MOTOR));
public static final BlockEntityType<ChanneledDataBlockEntity> PROVIDER_DATA_CACHE = register("provider_data_cache", FabricBlockEntityTypeBuilder
.create(ChanneledDataBlockEntity::new).addBlocks(FactoryBlocks.ITEM_COUNTER, FactoryBlocks.REDSTONE_INPUT, FactoryBlocks.REDSTONE_OUTPUT));
.create(ChanneledDataBlockEntity::new).addBlocks(FactoryBlocks.ITEM_COUNTER, FactoryBlocks.REDSTONE_INPUT, FactoryBlocks.REDSTONE_OUTPUT,
FactoryBlocks.TACHOMETER, FactoryBlocks.STRESSOMETER));

public static final BlockEntityType<HologramProjectorBlockEntity> HOLOGRAM_PROJECTOR = register("hologram_projector", FabricBlockEntityTypeBuilder
.create(HologramProjectorBlockEntity::new).addBlocks(FactoryBlocks.HOLOGRAM_PROJECTOR));
Expand Down
8 changes: 3 additions & 5 deletions src/main/java/eu/pb4/polyfactory/block/FactoryBlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,9 @@
import eu.pb4.polyfactory.block.creative.CreativeMotorBlock;
import eu.pb4.polyfactory.block.data.CableBlock;
import eu.pb4.polyfactory.block.data.output.HologramProjectorBlock;
import eu.pb4.polyfactory.block.data.providers.TinyPotatoSpringBlock;
import eu.pb4.polyfactory.block.data.providers.*;
import eu.pb4.polyfactory.block.data.output.NixieTubeControllerBlock;
import eu.pb4.polyfactory.block.data.output.RedstoneOutputBlock;
import eu.pb4.polyfactory.block.data.providers.ItemReaderBlock;
import eu.pb4.polyfactory.block.data.providers.DataProviderBlock;
import eu.pb4.polyfactory.block.data.providers.BlockObserverBlock;
import eu.pb4.polyfactory.block.data.providers.RedstoneInputBlock;
import eu.pb4.polyfactory.block.electric.ElectricGeneratorBlock;
import eu.pb4.polyfactory.block.electric.ElectricMotorBlock;
import eu.pb4.polyfactory.block.electric.WitherSkullGeneratorBlock;
Expand Down Expand Up @@ -86,6 +82,8 @@ public class FactoryBlocks {
public static final WirelessRedstoneBlock WIRELESS_REDSTONE_RECEIVER = register("wireless_redstone_receiver", new WirelessRedstoneBlock.Receiver(AbstractBlock.Settings.copy(ITEM_COUNTER)));
public static final WirelessRedstoneBlock WIRELESS_REDSTONE_TRANSMITTER = register("wireless_redstone_transmitter", new WirelessRedstoneBlock.Transmitter(AbstractBlock.Settings.copy(ITEM_COUNTER)));

public static final RotationMeterBlock TACHOMETER = register("tachometer", new RotationMeterBlock.Speed(Block.Settings.create().hardness(2).nonOpaque()));
public static final RotationMeterBlock STRESSOMETER = register("stressometer", new RotationMeterBlock.Stress(Block.Settings.create().hardness(2).nonOpaque()));
public static final ElectricMotorBlock ELECTRIC_MOTOR = register("electric_motor", new ElectricMotorBlock(Block.Settings.create().hardness(2).nonOpaque()));
public static final ElectricGeneratorBlock ELECTRIC_GENERATOR = register("electric_generator", new ElectricGeneratorBlock(Block.Settings.create().hardness(2).nonOpaque()));
public static final WitherSkullGeneratorBlock WITHER_SKULL_GENERATOR = register("wither_skull_generator", new WitherSkullGeneratorBlock(Block.Settings.create().hardness(2).nonOpaque()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
public abstract class AxisAndFacingBlock extends Block implements WrenchableBlock, FactoryBlock {
public static final DirectionProperty FACING = Properties.FACING;
public static final BooleanProperty FIRST_AXIS = BooleanProperty.of("first_axis");
private static final WrenchAction FIRST_AXIS_ACTION = WrenchAction.of("axis", (World world, BlockPos pos, Direction side, BlockState state) -> {
public static final WrenchAction FIRST_AXIS_ACTION = WrenchAction.of("axis", (World world, BlockPos pos, Direction side, BlockState state) -> {
return getAxis(state).asString();
}, WrenchApplyAction.ofProperty(FIRST_AXIS));

Expand Down
5 changes: 5 additions & 0 deletions src/main/java/eu/pb4/polyfactory/block/data/CableBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,11 @@ public Block getPolymerBlock(BlockState state) {
return Blocks.STRUCTURE_VOID;
}

@Override
public BlockState getPolymerBreakEventBlockState(BlockState state, ServerPlayerEntity player) {
return Blocks.BARRIER.getDefaultState();
}

public static int getModelId(BlockState state) {
int i = 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,17 @@
import eu.pb4.polyfactory.data.ItemStackData;
import eu.pb4.polyfactory.item.wrench.WrenchAction;
import eu.pb4.polyfactory.item.wrench.WrenchApplyAction;
import eu.pb4.polyfactory.item.wrench.WrenchValueGetter;
import eu.pb4.polyfactory.item.wrench.WrenchableBlock;
import eu.pb4.polyfactory.nodes.data.ChannelReceiverDirectionNode;
import eu.pb4.polyfactory.util.FactoryUtil;
import eu.pb4.polymer.virtualentity.api.ElementHolder;
import eu.pb4.polymer.virtualentity.api.attachment.BlockBoundAttachment;
import eu.pb4.polymer.virtualentity.api.attachment.HolderAttachment;
import eu.pb4.polymer.virtualentity.api.elements.BlockDisplayElement;
import eu.pb4.polymer.virtualentity.api.elements.DisplayElement;
import eu.pb4.polymer.virtualentity.api.elements.ItemDisplayElement;
import eu.pb4.polymer.virtualentity.api.elements.TextDisplayElement;
import net.minecraft.block.Block;
import net.minecraft.block.BlockEntityProvider;
import net.minecraft.block.BlockState;
import net.minecraft.block.*;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.client.render.model.json.ModelTransformationMode;
import net.minecraft.entity.decoration.Brightness;
Expand All @@ -36,10 +34,12 @@
import net.minecraft.network.packet.s2c.play.ParticleS2CPacket;
import net.minecraft.particle.DustColorTransitionParticleEffect;
import net.minecraft.particle.ParticleEffect;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.*;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.MathHelper;
Expand All @@ -59,7 +59,6 @@ public class HologramProjectorBlock extends DataNetworkBlock implements FactoryB
public static final BooleanProperty ACTIVE = BooleanProperty.of("active");
public static final DirectionProperty FACING = Properties.FACING;
public static final IntProperty FRONT = IntProperty.of("front", 0, 3);

private static final WrenchAction CHANGE_ROTATION = WrenchAction.of("front", (world, pos, side, state) -> {
var axis = state.get(FACING).getAxis();
if (axis == Direction.Axis.Y) {
Expand All @@ -79,17 +78,23 @@ public class HologramProjectorBlock extends DataNetworkBlock implements FactoryB

public static final WrenchAction SCALE = WrenchAction.ofBlockEntity("scale", HologramProjectorBlockEntity.class,
x -> String.format(Locale.ROOT, "%.1f", x.scale()),
(x, n) -> x.setScale(1 + (4 + (x.scale() - 1) + (n ? 0.5f : -0.5f)) % 4)
(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,
x -> String.format(Locale.ROOT,"%.1f", x.offset()),
(x, n) -> x.setOffset((1.5f + x.offset() + (n ? 0.1f : -0.1f)) % 1.5f)
(x, n) -> x.setOffset(FactoryUtil.wrap(x.offset() + (n ? 0.1f : -0.1f), 0.1f, 1.5f))
);

public static final WrenchAction ROTATION_DISPLAY = WrenchAction.ofBlockEntity("rotation", HologramProjectorBlockEntity.class,
x -> Math.round(x.rotationDisplay() * MathHelper.DEGREES_PER_RADIAN) + "°",
(x, n) -> x.setRotationDisplay((MathHelper.TAU + x.rotationDisplay() + MathHelper.RADIANS_PER_DEGREE * (n ? 5 : -5)) % MathHelper.TAU)
(x, n) -> x.setRotationDisplay(FactoryUtil.wrap(x.rotationDisplay() + 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, n) -> x.setForceText(!x.forceText())
);

public HologramProjectorBlock(Settings settings) {
Expand Down Expand Up @@ -139,7 +144,8 @@ public List<WrenchAction> getWrenchActions() {
CHANGE_ROTATION,
SCALE,
OFFSET,
ROTATION_DISPLAY
ROTATION_DISPLAY,
FORCE_TEXT
);
}

Expand All @@ -148,6 +154,11 @@ public BlockState rotate(BlockState state, BlockRotation rotation) {
return FactoryUtil.transform(state, rotation::rotate, FACING);
}*/

@Override
public BlockState getPolymerBreakEventBlockState(BlockState state, ServerPlayerEntity player) {
return Blocks.IRON_BLOCK.getDefaultState();
}

@Override
public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) {
tickWater(state, world, pos);
Expand Down Expand Up @@ -197,12 +208,16 @@ public static class Model extends BlockModel {
private static final Random RANDOM = Random.create();
private final LodItemDisplayElement base;
private DisplayElement currentDisplay;
private DisplayElement currentDisplayExtra;
private Direction facing;
private boolean active;
private Direction.Axis axis;
private float scale;
private float offset;
private float rotationDisplay;
private float extraScale = 1;
private boolean forceText = false;
private DataContainer lastData;

public Model(BlockState state) {
this.base = LodItemDisplayElement.createSimple(state.get(ACTIVE) ? ACTIVE_MODEL : LodItemDisplayElement.getModel(state.getBlock().asItem()));
Expand Down Expand Up @@ -258,7 +273,10 @@ private void updateStatePos(BlockState state) {
this.base.setYaw(y);
this.base.setPitch(p);
if (this.currentDisplay != null) {
applyPositionTransformation(this.currentDisplay, this.facing);
applyPositionTransformation(this.currentDisplay, this.facing, 0);
}
if (this.currentDisplayExtra != null) {
applyPositionTransformation(this.currentDisplayExtra, this.facing, 1);
}
}

Expand All @@ -279,8 +297,15 @@ public void notifyUpdate(HolderAttachment.UpdateType updateType) {
}

public void setData(DataContainer data) {
DisplayElement newDisplay;
if (data instanceof ItemStackData stackData) {
if (data.equals(this.lastData)) {
return;
}
this.lastData = data;

this.extraScale = 1;
DisplayElement newDisplay = null;
DisplayElement newDisplayExtra = null;
if (data instanceof ItemStackData stackData && !this.forceText) {
if (this.currentDisplay instanceof ItemDisplayElement e) {
e.setItem(stackData.stack());
e.tick();
Expand All @@ -289,82 +314,136 @@ public void setData(DataContainer data) {
var i = new ItemDisplayElement(stackData.stack());
i.setModelTransformation(ModelTransformationMode.GUI);
newDisplay = i;
} else if (data instanceof BlockStateData blockStateData) {
if (this.currentDisplay instanceof BlockDisplayElement e) {
} else if (data instanceof BlockStateData blockStateData && !this.forceText) {
var asItem = (blockStateData.state().getBlock() instanceof FactoryBlock
|| blockStateData.state().getBlock() instanceof SkullBlock)
&& blockStateData.state().getBlock().asItem() != null;
if (this.currentDisplay instanceof BlockDisplayElement e && !asItem) {
e.setBlockState(blockStateData.state());
e.tick();
return;
} else if (this.currentDisplay instanceof ItemDisplayElement e && asItem) {
e.setItem(LodItemDisplayElement.getModel(blockStateData.state().getBlock().asItem()));
e.tick();
this.extraScale = 2;
return;
}
if (asItem) {
var i = new ItemDisplayElement(LodItemDisplayElement.getModel(blockStateData.state().getBlock().asItem()));
i.setModelTransformation(ModelTransformationMode.FIXED);
this.extraScale = 2;
newDisplay = i;
} else {
newDisplay = new BlockDisplayElement(blockStateData.state());
}
newDisplay = new BlockDisplayElement(blockStateData.state());
} else if (!data.isEmpty()) {
var t = new TextDisplayElement(Text.literal(String.join("\n", data.asString().lines().limit(4).toList())));
var text = Text.literal(String.join("\n", data.asString().lines().limit(4).toList())).formatted(Formatting.AQUA);
if (this.currentDisplay instanceof TextDisplayElement display && this.currentDisplayExtra instanceof TextDisplayElement displayExtra) {
display.setText(text);
display.tick();
displayExtra.setText(text);
displayExtra.tick();
return;
}
var t = new TextDisplayElement(text);
t.setBackground(0);
t.setShadow(true);
t.setLineWidth(60);
newDisplay = t;
} else {
newDisplay = null;
t = new TextDisplayElement(text);
t.setBackground(0);
t.setShadow(true);
t.setLineWidth(60);
newDisplayExtra = t;
}

if (this.currentDisplay != null) {
this.removeElement(this.currentDisplay);
}

if (this.currentDisplayExtra != null) {
this.removeElement(this.currentDisplayExtra);
}

this.currentDisplay = newDisplay;

if (newDisplay != null) {
this.applyInitialTransformation(newDisplay);
this.applyInitialTransformation(newDisplay, 0);
this.addElement(newDisplay);
}

this.currentDisplayExtra = newDisplayExtra;

if (newDisplayExtra != null) {
this.applyInitialTransformation(newDisplayExtra, 1);
this.addElement(newDisplayExtra);
}
}

private void applyInitialTransformation(DisplayElement display) {
private void applyInitialTransformation(DisplayElement display, int id) {
display.setDisplaySize(0,0);
display.setInterpolationDuration(4);
display.setViewRange(0.8f);
display.setBrightness(new Brightness(15, 15));
applyPositionTransformation(display, this.facing);
applyPositionTransformation(display, this.facing, id);
}

private void applyDynamicTransformation(DisplayElement display) {
private void applyDynamicTransformation(DisplayElement display, int id) {
mat.identity();
if (display instanceof BlockDisplayElement) {
mat.translate(-this.scale / 2, -this.scale / 2, 0);
}

mat.rotate(Direction.get(Direction.AxisDirection.POSITIVE, this.facing.getAxis()).getRotationQuaternion());
if (display instanceof TextDisplayElement) {
if (display instanceof TextDisplayElement && id == 0) {
mat.rotateY(MathHelper.PI);
}
mat.rotateY((float) (MathHelper.HALF_PI * blockState().get(FRONT)));

mat.rotateZ((this.facing.getDirection() == Direction.AxisDirection.POSITIVE ? 0 : MathHelper.PI));

if (display instanceof BlockDisplayElement) {
mat.translate(-this.scale / 2, -this.scale / 2, 0);
}

mat.translate(0, this.offset + this.scale / 2, 0);
if (display instanceof TextDisplayElement t) {
mat.translate(0, -t.getText().getString().lines().count() * this.scale * (7 / 16f), 0);
}
mat.rotateZ(this.rotationDisplay);

mat.scale(new Vector3f(this.scale, this.scale, display instanceof TextDisplayElement ? 1 : 0.005f));
mat.scale(new Vector3f(this.scale, this.scale, display instanceof TextDisplayElement ? 1 : 0.01f).mul(this.extraScale));
display.setTransformation(mat);
}

private void applyPositionTransformation(DisplayElement display, Direction facing) {
private void applyPositionTransformation(DisplayElement display, Direction facing, int id) {
//var vec = new Vector3f(0, 0.5f, 0).rotate(facing.getRotationQuaternion());
//display.setOffset(new Vec3d(vec));
//display.setYaw(this.base.getYaw());
//display.setPitch(this.base.getPitch());


applyDynamicTransformation(display);
applyDynamicTransformation(display, id);
}

public void setTransform(float scale, float offset, float rotationDisplay) {
public void setTransform(float scale, float offset, float rotationDisplay, boolean forceText) {
var textChange = forceText != this.forceText;
this.scale = scale;
this.offset = offset;
this.forceText = forceText;
this.rotationDisplay = rotationDisplay;
if (this.currentDisplay != null) {
applyDynamicTransformation(this.currentDisplay);

if (textChange) {
if (this.lastData != null) {
var oldData = this.lastData;
this.lastData = null;
this.setData(oldData);
}
} else {
if (this.currentDisplay != null) {
applyDynamicTransformation(this.currentDisplay, 0);
}

if (this.currentDisplayExtra != null) {
applyDynamicTransformation(this.currentDisplayExtra, 1);
}
}
}
}
Expand Down
Loading

0 comments on commit 95607b9

Please sign in to comment.