-
-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
merge/1.18 in with the facade changes
- Loading branch information
Showing
41 changed files
with
703 additions
and
388 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/main/java/com/lothrazar/cyclic/block/cable/TileCableBase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/main/java/com/lothrazar/cyclic/block/facade/IBlockFacade.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
43
src/main/java/com/lothrazar/cyclic/block/facade/ITileFacade.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
src/main/java/com/lothrazar/cyclic/block/facade/RenderCableFacade.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/main/java/com/lothrazar/cyclic/block/facade/light/BlockLightFacade.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
Oops, something went wrong.