Skip to content

Commit

Permalink
Convert Redstone Input/Output, add Spray Can, fix models
Browse files Browse the repository at this point in the history
  • Loading branch information
Patbox committed Feb 28, 2024
1 parent e962cff commit fdb6afe
Show file tree
Hide file tree
Showing 53 changed files with 454 additions and 159 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ dependencies {
modImplementation include('eu.pb4:sidebar-api:0.3.0+1.20.3')
modImplementation include('eu.pb4:sgui:1.4.1+1.20.4')
modImplementation include('com.kneelawk:graphlib:1.4.0+1.20.4')
modImplementation include('eu.pb4:factorytools:0.1.4+1.20.4')
modImplementation include('eu.pb4:factorytools:0.1.5+1.20.4')

// Temp hack to allow development
//modImplementation include('com.kneelawk:graphlib:1.99.99+1.20.local')
Expand Down
10 changes: 7 additions & 3 deletions changelog-next.txt
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
- 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.
- Reworked general "data provider/receiver blocks" (Item Counter, Nixie Tube Controller, Block Observer, Item Reader):
- Added Spray Can. It can be used to recolor Cables, Nixie Tubes, Lamps and most vanilla colored blocks.
You can create it in Mechanical Press with Empty Bucket and Copper Ingot. You can fill it with dye by putting it in the inventory (like bundles), with 8 charges per dye.
- Reworked general "data provider/receiver blocks" (Item Counter, Nixie Tube Controller, Block Observer, Item Reader, Redstone Input/Output):
- Instead of having single directional input/output, you need to place cable inside of it.
- The cable connects the same way as regular one, excluding the direction data-block is facing.
- Existing blocks will convert to the new ones, without any changes in connection until you change them yourself.
- Improved Hologram Projectors:
- Added option to force everything to display as text.
- Added option to change pitch and yaw aside of just roll of hologram.
- Fixed some bugs with displaying holograms.
- Mechanical Placers can now use selected items on blocks.
- Improved placement of Windmills to always point to connected side.
- Improved physics of players effected by fans.
- Improved placement of Windmills to always point to connected side.
- Added new advancements!
- Hoppers, Pistons, Redstone Repeater, Redstone Comparator, Dispensers and Droppers can be rotated by using Wrench.
- Added breaking particles to all the blocks that didn't have them.
- All crafting-machines should now work with hoppers.
- Fixed dynamic blocks not having correct visuals sometimes.
- Changed multiple textures and models:
- Most notably: Item Splitter, Cables and Ender-Amethyst Crystal,
- Most notably: Item Splitter, Cables, Wireless Redstone Input/Output, Treated Kelp and Ender-Amethyst Crystal


Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.google.common.collect.Maps;
import com.kneelawk.graphlib.api.graph.user.BlockNode;
import eu.pb4.factorytools.api.virtualentity.BlockModel;
import eu.pb4.factorytools.api.virtualentity.ItemDisplayElementUtil;
import eu.pb4.polyfactory.advancement.FactoryTriggers;
import eu.pb4.factorytools.api.advancement.TriggerCriterion;
import eu.pb4.factorytools.api.block.FactoryBlock;
Expand Down Expand Up @@ -50,6 +51,7 @@

public abstract class AbstractCableBlock extends NetworkBlock implements FactoryBlock, BlockEntityProvider, CableConnectable, NetworkComponent.Data, NetworkComponent.Energy {
public static final int DEFAULT_COLOR = 0xbbbbbb;
public static final BooleanProperty HAS_CABLE = BooleanProperty.of("has_cable");

public static final BooleanProperty NORTH = Properties.NORTH;
public static final BooleanProperty EAST = Properties.EAST;
Expand Down Expand Up @@ -109,7 +111,7 @@ public ItemStack getPickStack(WorldView world, BlockPos pos, BlockState state) {
return stack;
}

protected boolean setColor(BlockState state, World world, BlockPos pos, int color) {
public boolean setColor(BlockState state, World world, BlockPos pos, int color) {
color = FactoryItems.CABLE.downSampleColor(color);
if (world.getBlockEntity(pos) instanceof ColorProvider provider && provider.getColor() != color) {
provider.setColor(color);
Expand Down Expand Up @@ -246,13 +248,17 @@ public boolean canCableConnect(WorldAccess world, int cableColor, BlockPos pos,
return true;
}

public boolean hasCable(BlockState state) {
return true;
}

public static class BaseCableModel extends BlockModel {
private final ItemDisplayElement cable;
private int color = AbstractCableBlock.DEFAULT_COLOR;
private BlockState state;

public BaseCableModel(BlockState state, boolean addCable) {
this.cable = LodItemDisplayElement.createSimple();
this.cable = ItemDisplayElementUtil.createSimple();
this.cable.setViewRange(0.5f);
this.state = state;
updateModel();
Expand All @@ -278,8 +284,9 @@ protected void setState(BlockState blockState) {
updateModel();
}

protected boolean hasCable(BlockState state) {
return true;

protected final boolean hasCable(BlockState state) {
return ((AbstractCableBlock) state.getBlock()).hasCable(state);
}

protected void updateModel() {
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/eu/pb4/polyfactory/block/data/CableBlock.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package eu.pb4.polyfactory.block.data;

import eu.pb4.factorytools.api.virtualentity.ItemDisplayElementUtil;
import eu.pb4.factorytools.api.virtualentity.LodItemDisplayElement;
import eu.pb4.polyfactory.block.FactoryBlocks;
import eu.pb4.polyfactory.block.data.util.GenericCabledDataBlock;
Expand Down Expand Up @@ -97,7 +98,7 @@ public static final class Model extends BaseCableModel {

private Model(BlockState state) {
super(state, true);
this.frame = LodItemDisplayElement.createSimple(FactoryItems.FRAME);
this.frame = ItemDisplayElementUtil.createSimple(FactoryItems.FRAME);
this.frame.setScale(new Vector3f(2));
this.frame.setViewRange(0.8f);
if (state.get(FRAMED)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import eu.pb4.factorytools.api.block.FactoryBlock;
import eu.pb4.factorytools.api.resourcepack.BaseItemProvider;
import eu.pb4.factorytools.api.virtualentity.BlockModel;
import eu.pb4.factorytools.api.virtualentity.ItemDisplayElementUtil;
import eu.pb4.factorytools.api.virtualentity.LodItemDisplayElement;
import eu.pb4.mapcanvas.api.font.DefaultFonts;
import eu.pb4.polyfactory.advancement.FactoryTriggers;
Expand Down Expand Up @@ -234,7 +235,7 @@ public static class Model extends BlockModel {
0.2f);

private static final Random RANDOM = Random.create();
private final LodItemDisplayElement base;
private final ItemDisplayElement base;
private DisplayElement currentDisplay;
private DisplayElement currentDisplayExtra;
private Direction facing;
Expand All @@ -252,7 +253,7 @@ public static class Model extends BlockModel {
private float extraOffset;

public Model(BlockState state) {
this.base = LodItemDisplayElement.createSimple(state.get(ACTIVE) ? ACTIVE_MODEL : LodItemDisplayElement.getModel(state.getBlock().asItem()));
this.base = ItemDisplayElementUtil.createSimple(state.get(ACTIVE) ? ACTIVE_MODEL : LodItemDisplayElement.getModel(state.getBlock().asItem()));
this.base.setScale(new Vector3f(2));

updateStatePos(state);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,24 @@

import com.kneelawk.graphlib.api.graph.user.BlockNode;
import eu.pb4.factorytools.api.advancement.TriggerCriterion;
import eu.pb4.factorytools.api.block.RedstoneConnectable;
import eu.pb4.factorytools.api.virtualentity.BlockModel;
import eu.pb4.factorytools.api.virtualentity.ItemDisplayElementUtil;
import eu.pb4.polyfactory.advancement.FactoryTriggers;
import eu.pb4.polyfactory.block.FactoryBlocks;
import eu.pb4.polyfactory.block.data.DataReceiver;
import eu.pb4.polyfactory.block.data.util.GenericCabledDataBlock;
import eu.pb4.polyfactory.block.data.util.GenericDirectionalDataBlock;
import eu.pb4.factorytools.api.block.RedstoneConnectable;
import eu.pb4.polyfactory.data.DataContainer;
import eu.pb4.factorytools.api.virtualentity.BlockModel;
import eu.pb4.factorytools.api.virtualentity.LodItemDisplayElement;
import eu.pb4.polyfactory.nodes.data.ChannelReceiverDirectionNode;
import eu.pb4.polyfactory.nodes.data.ChannelReceiverSelectiveSideNode;
import eu.pb4.polyfactory.util.FactoryUtil;
import eu.pb4.polymer.resourcepack.api.PolymerModelData;
import eu.pb4.polymer.resourcepack.api.PolymerResourcePackUtils;
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.ItemDisplayElement;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
Expand All @@ -42,19 +45,14 @@

import static eu.pb4.polyfactory.util.FactoryUtil.id;

public class RedstoneOutputBlock extends GenericDirectionalDataBlock implements DataReceiver, RedstoneConnectable {
public class RedstoneOutputBlock extends GenericCabledDataBlock implements DataReceiver, RedstoneConnectable {
public static final IntProperty POWER = Properties.POWER;

public RedstoneOutputBlock(Settings settings) {
super(settings);
this.setDefaultState(this.getDefaultState().with(POWER, 0));
}

@Override
public @Nullable BlockState getPlacementState(ItemPlacementContext ctx) {
return this.getDefaultState().with(FACING, ctx.getPlayerLookDirection());
}

@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
super.appendProperties(builder);
Expand All @@ -73,7 +71,7 @@ public int getWeakRedstonePower(BlockState state, BlockView world, BlockPos pos,

@Override
public Collection<BlockNode> createDataNodes(BlockState state, ServerWorld world, BlockPos pos) {
return List.of(new ChannelReceiverDirectionNode(state.get(FACING).getOpposite(), getChannel(world, pos)));
return List.of(new ChannelReceiverSelectiveSideNode(getDirections(state), getChannel(world, pos)));
}

@Override
Expand Down Expand Up @@ -104,22 +102,18 @@ public boolean canRedstoneConnect(BlockState state, @Nullable Direction dir) {
return state.get(FACING).getOpposite() == dir;
}

public static class Model extends BlockModel {
public static class Model extends GenericCabledDataBlock.Model {
public static final PolymerModelData OUTPUT_OVERLAY = PolymerResourcePackUtils.requestModel(Items.LEATHER_HELMET, id("block/redstone_output_overlay"));
public static final PolymerModelData INPUT_OVERLAY = PolymerResourcePackUtils.requestModel(Items.LEATHER_HELMET, id("block/redstone_input_overlay"));
private final LodItemDisplayElement base;
private final LodItemDisplayElement overlay;
private final ItemDisplayElement overlay;

public Model(BlockState state) {
this.base = LodItemDisplayElement.createSimple(state.getBlock().asItem());
this.overlay = LodItemDisplayElement.createSimple(createOverlay(state));
//this.overlay.setBrightness(new Brightness(state.get(POWER), 0));
this.base.setScale(new Vector3f(2));
this.overlay.setScale(new Vector3f(2));
super(state);
this.overlay = ItemDisplayElementUtil.createSimple(createOverlay(state));
this.overlay.setScale(new Vector3f(2.005f));
this.overlay.setViewRange(0.6f);

updateStatePos(state);
this.addElement(this.base);
this.addElement(this.overlay);
}

Expand All @@ -133,34 +127,20 @@ private ItemStack createOverlay(BlockState state) {
return stack;
}

private void updateStatePos(BlockState state) {
var dir = state.get(FACING);
float p = -90;
float y = 0;

if (dir.getAxis() != Direction.Axis.Y) {
p = 0;
y = dir.asRotation();
} else if (dir == Direction.DOWN) {
p = 90;
@Override
protected void updateStatePos(BlockState state) {
super.updateStatePos(state);
if (this.overlay != null) {
this.overlay.setYaw(this.base.getYaw());
this.overlay.setPitch(this.base.getPitch());
}


this.base.setYaw(y);
this.base.setPitch(p);
this.overlay.setYaw(y);
this.overlay.setPitch(p);
}

@Override
public void notifyUpdate(HolderAttachment.UpdateType updateType) {
if (updateType == BlockBoundAttachment.BLOCK_STATE_UPDATE) {
var state = this.blockState();
updateStatePos(state);
this.overlay.setItem(createOverlay(state));
this.base.tick();
this.overlay.tick();
}
protected void setState(BlockState blockState) {
super.setState(blockState);
this.overlay.setItem(createOverlay(blockState));
this.overlay.tick();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package eu.pb4.polyfactory.block.data.providers;

import eu.pb4.factorytools.api.virtualentity.BlockModel;
import eu.pb4.factorytools.api.virtualentity.ItemDisplayElementUtil;
import eu.pb4.factorytools.api.virtualentity.LodItemDisplayElement;
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.ItemDisplayElement;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
Expand Down Expand Up @@ -101,15 +103,15 @@ public BlockState getPolymerBreakEventBlockState(BlockState state, ServerPlayerE
}

public static class Model extends BaseCableModel {
private final LodItemDisplayElement base;
private final LodItemDisplayElement book;
private final ItemDisplayElement base;
private final ItemDisplayElement book;

private Model(BlockState state) {
super(state, state.get(HAS_CABLE));
this.base = LodItemDisplayElement.createSimple(state.getBlock().asItem());
this.base = ItemDisplayElementUtil.createSimple(state.getBlock().asItem());
this.base.setScale(new Vector3f(2));

this.book = LodItemDisplayElement.createSimple();
this.book = ItemDisplayElementUtil.createSimple();
this.book.setScale(new Vector3f(0.5f));
this.book.setDisplaySize(1, 1);
this.book.setTranslation(new Vector3f(0, 0, 0.35f));
Expand All @@ -119,11 +121,6 @@ private Model(BlockState state) {
this.addElement(this.book);
}

@Override
protected boolean hasCable(BlockState state) {
return state.get(HAS_CABLE);
}

private void updateStatePos(BlockState state) {
var dir = state.get(FACING);
float p = -90;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import net.minecraft.world.WorldAccess;
import org.jetbrains.annotations.Nullable;

public class RedstoneInputBlock extends DataProviderBlock implements RedstoneConnectable {
public class RedstoneInputBlock extends CabledDataProviderBlock implements RedstoneConnectable {
public static final IntProperty POWER = RedstoneOutputBlock.POWER;

public RedstoneInputBlock(AbstractBlock.Settings settings) {
Expand All @@ -42,7 +42,7 @@ protected void appendProperties(StateManager.Builder<Block, BlockState> builder)

@Nullable
public BlockState getPlacementState(ItemPlacementContext ctx) {
return this.getDefaultState().with(FACING, ctx.getPlayerLookDirection()).with(POWER, clamp(ctx.getWorld().getReceivedRedstonePower(ctx.getBlockPos())));
return super.getPlacementState(ctx).with(POWER, clamp(ctx.getWorld().getReceivedRedstonePower(ctx.getBlockPos())));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.kneelawk.graphlib.api.graph.user.BlockNode;
import eu.pb4.factorytools.api.block.FactoryBlock;
import eu.pb4.factorytools.api.virtualentity.ItemDisplayElementUtil;
import eu.pb4.factorytools.api.virtualentity.LodItemDisplayElement;
import eu.pb4.polyfactory.block.data.CableConnectable;
import eu.pb4.polyfactory.block.data.ChannelContainer;
Expand Down Expand Up @@ -201,11 +202,11 @@ public String asString() {

public static final class Model extends RotationAwareModel {
private final ItemDisplayElement axle;
private final LodItemDisplayElement base;
private final ItemDisplayElement base;

public Model(BlockState state) {
this.axle = LodItemDisplayElement.createSimple(AxleBlock.Model.ITEM_MODEL, this.getUpdateRate(), 0.3f, 0.6f);
this.base = LodItemDisplayElement.createSimple(state.getBlock().asItem());
this.base = ItemDisplayElementUtil.createSimple(state.getBlock().asItem());
this.base.setScale(new Vector3f(2));

updateStatePos(state);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.kneelawk.graphlib.api.graph.user.BlockNode;
import eu.pb4.factorytools.api.block.FactoryBlock;
import eu.pb4.factorytools.api.virtualentity.ItemDisplayElementUtil;
import eu.pb4.polyfactory.advancement.FactoryTriggers;
import eu.pb4.factorytools.api.advancement.TriggerCriterion;
import eu.pb4.factorytools.api.block.BarrierBasedWaterloggable;
Expand All @@ -21,6 +22,7 @@
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.ItemDisplayElement;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
Expand Down Expand Up @@ -169,15 +171,15 @@ public Collection<BlockNode> createDataNodes(BlockState state, ServerWorld world
public static final class Model extends BlockModel {
public static final ItemStack BASE_MODEL = BaseItemProvider.requestModel(id("block/tiny_potato_spring_base"));
public static final ItemStack TATER_MODEL = BaseItemProvider.requestModel(id("block/tiny_potato_spring"));
private final LodItemDisplayElement base;
private final ItemDisplayElement base;
private final LodItemDisplayElement tater;
private float extraRotation = 0;

private int animationTimer = -1;
private float interactionYaw;

private Model(ServerWorld world, BlockPos pos, BlockState state) {
this.base = LodItemDisplayElement.createSimple(BASE_MODEL);
this.base = ItemDisplayElementUtil.createSimple(BASE_MODEL);
this.tater = LodItemDisplayElement.createSimple(TATER_MODEL, 1);
this.tater.setTranslation(new Vector3f(0, -6f / 16, 0));
//this.tater.setOffset(new Vec3d(0, 2f / 16, 0));
Expand Down
Loading

0 comments on commit fdb6afe

Please sign in to comment.