Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New block features: comparator output and more vertical block facings #2441

Merged
merged 5 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ dependencies {

// optional dependencies & mods for testing compat

implementation fg.deobf("curse.maven:jade-324717:3910873")

implementation fg.deobf("curse.maven:mantle-74924:3482897")
implementation fg.deobf("curse.maven:tinkers-construct-74072:3482903")
implementation fg.deobf("curse.maven:cucumber-272335:3507886")
Expand Down
20 changes: 19 additions & 1 deletion examples/config/cyclic.toml
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@
#####################################################################################
[cyclic.logging]
#Unblock info logs; very spammy; can be useful for testing certain issues
info = true
info = false

#####################################################################################
#Fluid cost for various machines
Expand Down Expand Up @@ -418,6 +418,24 @@
#####################################################################################
[cyclic.energy]

[cyclic.energy.cables]

[cyclic.energy.cables.fluid]
# How many buckets of buffer fluid the fluid cable can hold (for each direction. for example 2 here means 2000ub in each face)
#Range: 1 ~ 32
buffer = 16
# How many fluid units per tick can flow through these cables each tick (1 bucket = 1000) including normal flow and extraction mode
#Range: > 100
flow = 16000

[cyclic.energy.cables.energy]
# How much buffer the energy cables hold (must not be smaller than flow)
#Range: > 1
buffer = 32000
# How fast energy flows in these cables (must not be greater than buffer)
#Range: > 100
flow = 32000

#####################################################################################
#Energy cost for various machines, either per use of an action or per tick (twenty ticks per second). Setting as zero (0) lets machine run for free
#####################################################################################
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/com/lothrazar/cyclic/base/BlockBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import net.minecraft.util.SoundEvents;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.util.text.TranslationTextComponent;
Expand Down Expand Up @@ -192,4 +193,16 @@ private static boolean hasCapabilityDir(Direction facing, IWorld world, BlockPos
}
return false;
}

//for comparators that dont use item inventories
protected int calcRedstoneFromFluid(TileEntity tileEntity) {
IFluidHandler fluid = tileEntity.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY).orElse(null);
if (fluid.getFluidInTank(0).isEmpty()) {
return 0;
}
float cap = fluid.getTankCapacity(0);
float amt = fluid.getFluidInTank(0).getAmount();
float f = amt / cap;
return MathHelper.floor(f * 14.0F) + 1;
}
}
36 changes: 36 additions & 0 deletions src/main/java/com/lothrazar/cyclic/base/TileEntityBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,21 @@ public void setLitProperty(boolean lit) {
}
}

// was getTargetCenter
protected BlockPos getFacingShapeCenter(int radiusIn) {
BlockPos center = null;
if (this.getCurrentFacing() != null) {
if (this.getCurrentFacing().getAxis().isVertical()) {
//vertical center point
center = this.getCurrentFacingPos(1);
}
else { //horizontal center point
center = this.getCurrentFacingPos(radiusIn + 1);
}
}
return center;
}

public Direction getCurrentFacing() {
if (this.getBlockState().hasProperty(BlockStateProperties.FACING)) {
return this.getBlockState().get(BlockStateProperties.FACING);
Expand Down Expand Up @@ -508,6 +523,10 @@ public void setFluid(FluidStack fluid) {}
@Deprecated
@Override
public int getSizeInventory() {
IItemHandler invo = this.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY).orElse(null);
if (invo != null) {
return invo.getSlots();
}
return 0;
}

Expand All @@ -520,6 +539,13 @@ public boolean isEmpty() {
@Deprecated
@Override
public ItemStack getStackInSlot(int index) {
IItemHandler invo = this.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY).orElse(null);
try {
if (invo != null && index < invo.getSlots()) {
return invo.getStackInSlot(index);
}
}
catch (Exception e) {}
return ItemStack.EMPTY;
}

Expand Down Expand Up @@ -588,4 +614,14 @@ public void exportEnergyAllSides() {
moveEnergy(exportToSide, MENERGY / 2);
}
}

public boolean getBlockStateVertical() {
if (this.getBlockState().hasProperty(BlockStateProperties.FACING))
return this.getBlockState().get(BlockStateProperties.FACING).getAxis().isVertical();
return false;
}

public void updateComparatorOutputLevel() {
world.updateComparatorOutputLevel(pos, this.getBlockState().getBlock());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,20 @@
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.common.ForgeConfigSpec.IntValue;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.energy.CapabilityEnergy;
import net.minecraftforge.energy.IEnergyStorage;

public class TileCableEnergy extends TileCableBase implements ITickableTileEntity {

private static final int MAX = 32000;
final CustomEnergyStorage energy = new CustomEnergyStorage(MAX, MAX);
private final LazyOptional<IEnergyStorage> energyCap = LazyOptional.of(() -> energy);
//
public static IntValue BUFFERSIZE;
public static IntValue TRANSFER_RATE;
//
final CustomEnergyStorage energy;// = new CustomEnergyStorage(MAX, MAX);
private final LazyOptional<IEnergyStorage> energyCap;// = LazyOptional.of(() -> energy);
private final ConcurrentHashMap<Direction, LazyOptional<IEnergyStorage>> flow = new ConcurrentHashMap<>();
private final Map<Direction, Integer> mapIncomingEnergy = Maps.newHashMap();
private int energyLastSynced = -1; //fluid tanks have 'onchanged', energy caps do not
Expand All @@ -36,6 +40,8 @@ public TileCableEnergy() {
for (Direction f : Direction.values()) {
mapIncomingEnergy.put(f, 0);
}
energy = new CustomEnergyStorage(BUFFERSIZE.get(), TRANSFER_RATE.get());
energyCap = LazyOptional.of(() -> energy);
}

@Override
Expand Down Expand Up @@ -109,7 +115,7 @@ private void tickCableFlow() {
continue;
}
if (!this.isEnergyIncomingFromFace(outgoingSide)) {
moveEnergy(outgoingSide, MAX);
moveEnergy(outgoingSide, TRANSFER_RATE.get());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.StringTextComponent;
import net.minecraftforge.common.ForgeConfigSpec.IntValue;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.fluids.FluidAttributes;
Expand All @@ -40,15 +41,16 @@ public boolean isItemValid(int slot, ItemStack stack) {
return stack.getItem() == ItemRegistry.filter_data;
}
};
public static final int CAPACITY = 16 * FluidAttributes.BUCKET_VOLUME;
public static final int FLOW_RATE = CAPACITY; //normal non-extract flow
public static final int EXTRACT_RATE = CAPACITY;
private final FluidTank fluidTank = new FluidTankBase(this, CAPACITY, fluidStack -> FilterCardItem.filterAllowsExtract(filter.getStackInSlot(0), fluidStack));
private final LazyOptional<IFluidHandler> fluidCap = LazyOptional.of(() -> fluidTank);
public static IntValue BUFFERSIZE;
public static IntValue TRANSFER_RATE;
private final FluidTank fluidTank;
private final LazyOptional<IFluidHandler> fluidCap;
private final ConcurrentHashMap<Direction, LazyOptional<IFluidHandler>> flow = new ConcurrentHashMap<>();

public TileCableFluid() {
super(TileRegistry.fluid_pipeTile);
fluidTank = new FluidTankBase(this, BUFFERSIZE.get() * FluidAttributes.BUCKET_VOLUME, fluidStack -> FilterCardItem.filterAllowsExtract(filter.getStackInSlot(0), fluidStack));
fluidCap = LazyOptional.of(() -> fluidTank);
}

@Override
Expand Down Expand Up @@ -92,7 +94,7 @@ private void tryExtract(Direction extractSide) {
return;
}
//first try standard fluid transfer
if (UtilFluid.tryFillPositionFromTank(world, pos, extractSide, tankTarget, EXTRACT_RATE)) {
if (UtilFluid.tryFillPositionFromTank(world, pos, extractSide, tankTarget, TRANSFER_RATE.get())) {
return;
}
//handle special cases
Expand All @@ -112,7 +114,7 @@ private void normalFlow() {
if (connection.isExtraction() || connection.isBlocked()) {
continue;
}
this.moveFluids(outgoingSide, pos.offset(outgoingSide), FLOW_RATE, fluidTank);
this.moveFluids(outgoingSide, pos.offset(outgoingSide), TRANSFER_RATE.get(), fluidTank);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ public TileEntity createTileEntity(BlockState state, IBlockReader world) {
@Override
public void onBlockPlacedBy(World world, BlockPos pos, BlockState state, LivingEntity entity, ItemStack stack) {
if (entity != null) {
world.setBlockState(pos, state.with(BlockStateProperties.HORIZONTAL_FACING, UtilBlockstates.getFacingFromEntityHorizontal(pos, entity)), 2);
world.setBlockState(pos, state.with(BlockStateProperties.FACING, UtilBlockstates.getFacingFromEntity(pos, entity)), 2);
}
}

@Override
protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder) {
builder.add(BlockStateProperties.HORIZONTAL_FACING).add(LIT);
builder.add(BlockStateProperties.FACING).add(LIT);
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package com.lothrazar.cyclic.block.collectfluid;

import com.lothrazar.cyclic.config.ClientConfigCyclic;
import com.lothrazar.cyclic.data.PreviewOutlineType;
import com.lothrazar.cyclic.util.UtilRender;
import com.mojang.blaze3d.matrix.MatrixStack;
import net.minecraft.client.renderer.IRenderTypeBuffer;
import net.minecraft.client.renderer.tileentity.TileEntityRenderer;
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.vector.Vector3d;

public class RenderFluidCollect extends TileEntityRenderer<TileFluidCollect> {

Expand All @@ -15,8 +18,14 @@ public RenderFluidCollect(TileEntityRendererDispatcher d) {

@Override
public void render(TileFluidCollect te, float v, MatrixStack matrix, IRenderTypeBuffer ibuffer, int partialTicks, int destroyStage) {
if (1 == te.getField(TileFluidCollect.Fields.RENDER.ordinal())) {
int previewType = te.getField(TileFluidCollect.Fields.RENDER.ordinal());
if (PreviewOutlineType.SHADOW.ordinal() == previewType) {
UtilRender.renderOutline(te.getPos(), te.getShapeHollow(), matrix, 0.4F, ClientConfigCyclic.getColor(te));
}
else if (PreviewOutlineType.WIREFRAME.ordinal() == previewType) {
for (BlockPos crd : te.getShapeHollow()) {
UtilRender.createBox(matrix, crd, Vector3d.copy(te.getPos()));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.lothrazar.cyclic.base.FluidTankBase;
import com.lothrazar.cyclic.base.TileEntityBase;
import com.lothrazar.cyclic.capability.CustomEnergyStorage;
import com.lothrazar.cyclic.data.PreviewOutlineType;
import com.lothrazar.cyclic.registry.TileRegistry;
import com.lothrazar.cyclic.util.UtilShape;
import java.util.List;
Expand All @@ -16,6 +17,7 @@
import net.minecraft.inventory.container.INamedContainerProvider;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.state.properties.BlockStateProperties;
import net.minecraft.tileentity.ITickableTileEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Direction;
Expand Down Expand Up @@ -49,7 +51,7 @@ static enum Fields {
FluidTankBase tank;
private final LazyOptional<FluidTankBase> tankWrapper = LazyOptional.of(() -> tank);
private int shapeIndex = 0; // current index of shape array
private int size = 4 * 2;
private int radius = 4 * 2;
private int height = 4;
BlockPos targetPos = null;
static final int MAX = 64000;
Expand Down Expand Up @@ -81,9 +83,11 @@ public void tick() {
return;
}
ItemStack stack = inventory.getStackInSlot(0);
if (stack.isEmpty() || Block.getBlockFromItem(stack.getItem()) == Blocks.AIR) {
return;
}
// if (stack.isEmpty() || Block.getBlockFromItem(stack.getItem()) == Blocks.AIR) {
// return;
// }
//use air if its empty
BlockState newState = Block.getBlockFromItem(stack.getItem()).getDefaultState();
this.setLitProperty(true);
List<BlockPos> shape = this.getShapeFilled();
if (shape.size() == 0) {
Expand All @@ -99,7 +103,7 @@ public void tick() {
int result = tank.fill(fstack, FluidAction.SIMULATE);
if (result == FluidAttributes.BUCKET_VOLUME) {
//we got enough
if (world.setBlockState(targetPos, Block.getBlockFromItem(stack.getItem()).getDefaultState())) {
if (world.setBlockState(targetPos, newState)) {
//build the block, shrink the item
stack.shrink(1);
//drink fluid
Expand All @@ -125,16 +129,24 @@ public AxisAlignedBB getRenderBoundingBox() {
return TileEntity.INFINITE_EXTENT_AABB;
}

private BlockPos getTargetCenter() {
//move center over that much, not including exact horizontal
return this.getCurrentFacingPos(size + 1); //this.getPos().offset(this.getCurrentFacing(), size + 1);
private int heightWithDirection() {
Direction blockFacing = this.getBlockState().get(BlockStateProperties.FACING);
int diff = 1; // directionIsUp ? 1 : -1;
if (blockFacing.getAxis().isVertical()) {
diff = (blockFacing == Direction.UP) ? 1 : -1;
}
return diff * height;
}

//for render
public List<BlockPos> getShapeHollow() {
BlockPos ctr = getTargetCenter();
List<BlockPos> shape = UtilShape.squareHorizontalHollow(ctr.down(height), this.size);
shape = UtilShape.repeatShapeByHeight(shape, height);
BlockPos center = getFacingShapeCenter(radius);
List<BlockPos> shape = UtilShape.squareHorizontalHollow(center, this.radius);
//
int heightWithDirection = heightWithDirection();
if (heightWithDirection != 0) {
shape = UtilShape.repeatShapeByHeight(shape, heightWithDirection);
}
if (targetPos != null) {
shape.add(targetPos);
}
Expand All @@ -143,9 +155,12 @@ public List<BlockPos> getShapeHollow() {

//for harvest
public List<BlockPos> getShapeFilled() {
BlockPos ctr = getTargetCenter();
List<BlockPos> shape = UtilShape.squareHorizontalFull(ctr.down(height), this.size);
shape = UtilShape.repeatShapeByHeight(shape, height - 1);
BlockPos center = getFacingShapeCenter(radius);
int heightWithDirection = heightWithDirection();
List<BlockPos> shape = UtilShape.squareHorizontalFull(center, this.radius);
if (heightWithDirection != 0) {
shape = UtilShape.repeatShapeByHeight(shape, heightWithDirection);
}
return shape;
}

Expand Down Expand Up @@ -215,13 +230,13 @@ public void setField(int field, int value) {
this.setNeedsRedstone(value);
break;
case RENDER:
this.render = value % 2;
this.render = value % PreviewOutlineType.values().length;
break;
case HEIGHT:
height = Math.min(value, MAX_HEIGHT);
break;
case SIZE:
size = Math.min(value, MAX_SIZE);
radius = Math.min(value, MAX_SIZE);
break;
}
}
Expand All @@ -236,7 +251,7 @@ public int getField(int field) {
case HEIGHT:
return height;
case SIZE:
return size;
return radius;
}
return 0;
}
Expand Down
Loading
Loading