Skip to content

Commit

Permalink
merge/1.18 in with the facade changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Lothrazar committed Nov 6, 2024
2 parents 0626bdf + 34ccc89 commit 7b5537d
Show file tree
Hide file tree
Showing 41 changed files with 703 additions and 388 deletions.
10 changes: 10 additions & 0 deletions examples/config/cyclic.toml
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,16 @@
#Range: 1 ~ 128
radius = 16

[cyclic.blocks.facades]
#
# These blocks are not allowed to be used as Facades for blocks because they look weird (used by cables and Glowstone Facade and Soundproofing Facade and others)
itemsNotAllowed = ["minecraft:ladder", "minecraft:double_plant", "minecraft:waterlily", "minecraft:torch", "minecraft:*_torch", "minecraft:redstone", "minecraft:iron_bars", "minecraft:chest", "minecraft:ender_chest", "minecraft:sculk_vein", "minecraft:string", "minecraft:vine", "minecraft:rail", "minecraft:*_rail", "minecraft:brewing_stand", "minecraft:*_dripleaf", "minecraft:*_pane", "minecraft:*_sapling", "minecraft:*_sign", "minecraft:*_door", "minecraft:*_banner", "minecraft:*_shulker_box", "cyclic:*_pipe", "cyclic:*_bars", "storagenetwork:*"]

[cyclic.blocks.facades.cables]
#
# Allow cables to have blocks placed in them as facades (sneak-left-click to set; use empty hand to remove). Set to false to disable facades
enabled = true

[cyclic.blocks.user]
#Power per use user
#Range: 0 ~ 64000
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/com/lothrazar/cyclic/block/BlockCyclic.java
Original file line number Diff line number Diff line change
Expand Up @@ -203,4 +203,16 @@ private static boolean hasCapabilityDir(Direction facing, LevelAccessor world, B
}
return false;
}

//for comparators that dont use item inventories
protected int calcRedstoneFromFluid(BlockEntity tileEntity) {
IFluidHandler fluid = tileEntity.getCapability(ForgeCapabilities.FLUID_HANDLER).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 (int) Math.floor((f * 14.0F)) + 1;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -704,4 +704,8 @@ public void updateComparatorOutputLevel() {
//was updateComparatorOutputLevel()
level.updateNeighbourForOutputSignal(worldPosition, this.getBlockState().getBlock());
}

public void updateComparatorOutputLevelAt(BlockPos target) {
level.updateNeighbourForOutputSignal(target, level.getBlockState(target).getBlock());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.Map;
import com.google.common.collect.Maps;
import com.lothrazar.cyclic.block.BlockCyclic;
import com.lothrazar.cyclic.block.facade.IBlockFacade;
import com.lothrazar.cyclic.data.DataTags;
import com.lothrazar.cyclic.registry.BlockRegistry;
import com.lothrazar.cyclic.registry.SoundRegistry;
Expand Down Expand Up @@ -35,7 +36,7 @@
import net.minecraftforge.event.entity.player.PlayerInteractEvent.RightClickBlock;
import net.minecraftforge.network.NetworkHooks;

public abstract class CableBase extends BlockCyclic implements SimpleWaterloggedBlock {
public abstract class CableBase extends BlockCyclic implements SimpleWaterloggedBlock, IBlockFacade {

public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED;
//regular connections
Expand Down
39 changes: 39 additions & 0 deletions src/main/java/com/lothrazar/cyclic/block/cable/TileCableBase.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.lothrazar.cyclic.block.cable;

import com.lothrazar.cyclic.block.TileBlockEntityCyclic;
import com.lothrazar.cyclic.block.facade.ITileFacade;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;

public abstract class TileCableBase extends TileBlockEntityCyclic implements ITileFacade {

public TileCableBase(BlockEntityType<?> tileEntityTypeIn, BlockPos pos, BlockState state) {
super(tileEntityTypeIn, pos, state);
}

@Override
public void load(CompoundTag tag) {
this.loadFacade(tag);
super.load(tag);
}

@Override
public void saveAdditional(CompoundTag tag) {
this.saveFacade(tag);
super.saveAdditional(tag);
}

private CompoundTag facadeState = null;

@Override
public CompoundTag getFacade() {
return facadeState;
}

@Override
public void setFacade(CompoundTag facadeState) {
this.facadeState = facadeState;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.lothrazar.cyclic.block.cable.CableBase;
import com.lothrazar.cyclic.block.cable.EnumConnectType;
import com.lothrazar.cyclic.block.cable.ShapeCache;
import com.lothrazar.cyclic.config.ConfigRegistry;
import com.lothrazar.cyclic.registry.TileRegistry;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
Expand Down Expand Up @@ -31,6 +32,12 @@ public BlockCableEnergy(Properties properties) {

@Override
public VoxelShape getShape(BlockState state, BlockGetter worldIn, BlockPos pos, CollisionContext context) {
if (ConfigRegistry.CABLE_FACADES.get()) {
VoxelShape facade = this.getFacadeShape(state, worldIn, pos, context);
if (facade != null) {
return facade;
}
}
return ShapeCache.getOrCreate(state, CableBase::createShape);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import java.util.Map;
import com.google.common.collect.Maps;
import com.lothrazar.cyclic.ModCyclic;
import com.lothrazar.cyclic.block.TileBlockEntityCyclic;
import com.lothrazar.cyclic.block.cable.CableBase;
import com.lothrazar.cyclic.block.cable.EnumConnectType;
import com.lothrazar.cyclic.block.cable.TileCableBase;
import com.lothrazar.cyclic.capabilities.block.CustomEnergyStorage;
import com.lothrazar.cyclic.registry.TileRegistry;
import com.lothrazar.cyclic.util.UtilDirection;
Expand All @@ -22,7 +22,7 @@
import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.energy.IEnergyStorage;

public class TileCableEnergy extends TileBlockEntityCyclic {
public class TileCableEnergy extends TileCableBase {

final CustomEnergyStorage energy;
private LazyOptional<IEnergyStorage> energyCap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.lothrazar.cyclic.block.cable.CableBase;
import com.lothrazar.cyclic.block.cable.EnumConnectType;
import com.lothrazar.cyclic.block.cable.ShapeCache;
import com.lothrazar.cyclic.config.ConfigRegistry;
import com.lothrazar.cyclic.registry.MenuTypeRegistry;
import com.lothrazar.cyclic.registry.TileRegistry;
import net.minecraft.ChatFormatting;
Expand Down Expand Up @@ -55,6 +56,12 @@ public void registerClient() {

@Override
public VoxelShape getShape(BlockState state, BlockGetter worldIn, BlockPos pos, CollisionContext context) {
if (ConfigRegistry.CABLE_FACADES.get()) {
VoxelShape facade = this.getFacadeShape(state, worldIn, pos, context);
if (facade != null) {
return facade;
}
}
return ShapeCache.getOrCreate(state, CableBase::createShape);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import com.lothrazar.cyclic.block.TileBlockEntityCyclic;
import com.lothrazar.cyclic.block.cable.CableBase;
import com.lothrazar.cyclic.block.cable.EnumConnectType;
import com.lothrazar.cyclic.block.cable.TileCableBase;
import com.lothrazar.cyclic.capabilities.block.FluidTankBase;
import com.lothrazar.cyclic.item.datacard.filter.FilterCardItem;
import com.lothrazar.cyclic.registry.BlockRegistry;
Expand Down Expand Up @@ -36,7 +36,7 @@
import net.minecraftforge.fluids.capability.IFluidHandler;
import net.minecraftforge.items.ItemStackHandler;

public class TileCableFluid extends TileBlockEntityCyclic implements MenuProvider {
public class TileCableFluid extends TileCableBase implements MenuProvider {

public static IntValue BUFFERSIZE;
public static IntValue TRANSFER_RATE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.lothrazar.cyclic.block.cable.CableBase;
import com.lothrazar.cyclic.block.cable.EnumConnectType;
import com.lothrazar.cyclic.block.cable.ShapeCache;
import com.lothrazar.cyclic.config.ConfigRegistry;
import com.lothrazar.cyclic.registry.MenuTypeRegistry;
import com.lothrazar.cyclic.registry.TileRegistry;
import net.minecraft.client.gui.screens.MenuScreens;
Expand Down Expand Up @@ -39,6 +40,12 @@ public void registerClient() {

@Override
public VoxelShape getShape(BlockState state, BlockGetter worldIn, BlockPos pos, CollisionContext context) {
if (ConfigRegistry.CABLE_FACADES.get()) {
VoxelShape facade = this.getFacadeShape(state, worldIn, pos, context);
if (facade != null) {
return facade;
}
}
return ShapeCache.getOrCreate(state, CableBase::createShape);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import com.lothrazar.cyclic.block.TileBlockEntityCyclic;
import com.lothrazar.cyclic.block.cable.CableBase;
import com.lothrazar.cyclic.block.cable.EnumConnectType;
import com.lothrazar.cyclic.block.cable.TileCableBase;
import com.lothrazar.cyclic.registry.BlockRegistry;
import com.lothrazar.cyclic.registry.ItemRegistry;
import com.lothrazar.cyclic.registry.TileRegistry;
Expand All @@ -28,7 +28,7 @@
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.ItemStackHandler;

public class TileCableItem extends TileBlockEntityCyclic implements MenuProvider {
public class TileCableItem extends TileCableBase implements MenuProvider {

private static final int FLOW_QTY = 64; // fixed, for non-extract motion
private int extractQty = FLOW_QTY; // default
Expand Down
42 changes: 42 additions & 0 deletions src/main/java/com/lothrazar/cyclic/block/facade/IBlockFacade.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.lothrazar.cyclic.block.facade;

import net.minecraft.core.BlockPos;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;

public interface IBlockFacade {

default VoxelShape getFacadeShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext ctx) {
BlockState tfs = getFacadeState(state, level, pos);
if (tfs != null && tfs.getBlock() != state.getBlock()) {
return ctx == null ? tfs.getShape(level, pos) : tfs.getShape(level, pos, ctx);
}
return null;
}

default BlockState getFacadeState(BlockState state, BlockGetter level, BlockPos pos) {
if (level == null) {
return null;
}
ITileFacade tile = this.getTileFacade(level, pos);
if (tile != null && level instanceof Level lvl) {
return tile.getFacadeState(lvl);
}
return null;
}

default ITileFacade getTileFacade(BlockGetter level, BlockPos pos) {
if (level == null) {
return null;
}
BlockEntity tile = level.getBlockEntity(pos);
if (tile instanceof ITileFacade) {
return (ITileFacade) tile;
}
return null;
}
}
43 changes: 43 additions & 0 deletions src/main/java/com/lothrazar/cyclic/block/facade/ITileFacade.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.lothrazar.cyclic.block.facade;

import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtUtils;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState;

public interface ITileFacade {

public static final String NBT_FACADE = "facade";

CompoundTag getFacade();

void setFacade(CompoundTag facadeState);

default BlockState getFacadeState(Level level) {
CompoundTag facadeState = getFacade();
if (level == null || facadeState == null || facadeState.isEmpty()) {
return null; // level is null on world load
}
BlockState stateFound = NbtUtils.readBlockState(facadeState);
return stateFound;
}

default void loadFacade(CompoundTag compound) {
if (compound.contains(NBT_FACADE)) {
this.setFacade(compound.getCompound(NBT_FACADE));
}
else {
this.setFacade(null);
}
}

default void saveFacade(CompoundTag compound) {
CompoundTag facadeState = getFacade();
if (facadeState == null) {
compound.remove(NBT_FACADE);
}
else {
compound.put(NBT_FACADE, facadeState);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.lothrazar.cyclic.block.facade;

import com.lothrazar.cyclic.block.cable.TileCableBase;
import com.lothrazar.cyclic.config.ConfigRegistry;
import com.lothrazar.cyclic.util.FacadeUtil;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.block.BlockRenderDispatcher;
import net.minecraft.client.renderer.block.ModelBlockRenderer;
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
import net.minecraft.world.level.block.state.BlockState;

public class RenderCableFacade implements BlockEntityRenderer<TileCableBase> {

private BlockRenderDispatcher brd;
private ModelBlockRenderer renderer;

public RenderCableFacade(BlockEntityRendererProvider.Context d) {
this.brd = d.getBlockRenderDispatcher();
this.renderer = brd.getModelRenderer();
}

@Override
public boolean shouldRenderOffScreen(TileCableBase te) {
return true;
}

@Override
public void render(TileCableBase te, float v, PoseStack matrixStack, MultiBufferSource ibuffer, int packedLight, int packedOverlay) {
if (te.getFacade() != null
&& ConfigRegistry.CABLE_FACADES.get()) {
BlockState facadeState = te.getFacadeState(te.getLevel());
FacadeUtil.renderBlockState(te.getLevel(), te.getBlockPos(), brd, renderer, ibuffer, matrixStack, facadeState, packedLight, packedOverlay);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.lothrazar.cyclic.block.facade.light;

import com.lothrazar.cyclic.block.BlockCyclic;
import com.lothrazar.cyclic.block.facade.IBlockFacade;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.BlockGetter;
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.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;

public class BlockLightFacade extends BlockCyclic implements IBlockFacade {

private static final VoxelShape THREE = Block.box(6, 6, 6,
10, 10, 10);

public BlockLightFacade(Properties properties) {
super(properties.lightLevel(state -> 15).strength(1F).noOcclusion());
}

@Override
public VoxelShape getShape(BlockState state, BlockGetter worldIn, BlockPos pos, CollisionContext context) { // ISelectionContext
VoxelShape facade = this.getFacadeShape(state, worldIn, pos, context);
if (facade != null) {
return facade;
}
return THREE;
}

@Override
public boolean propagatesSkylightDown(BlockState state, BlockGetter reader, BlockPos pos) {
return true;
}

@Override
public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
return new TileLightFacade(pos, state);
}
}
Loading

0 comments on commit 7b5537d

Please sign in to comment.