-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8f0ad9e
commit 41ec0e2
Showing
30 changed files
with
1,402 additions
and
174 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
86 changes: 86 additions & 0 deletions
86
src/main/java/net/limit/cubliminal/block/custom/FluxCapacitorBlock.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,86 @@ | ||
package net.limit.cubliminal.block.custom; | ||
|
||
import com.mojang.serialization.MapCodec; | ||
import net.limit.cubliminal.block.entity.FluxCapacitorBlockEntity; | ||
import net.limit.cubliminal.init.CubliminalBlockEntities; | ||
import net.limit.cubliminal.init.CubliminalSounds; | ||
import net.minecraft.block.*; | ||
import net.minecraft.block.entity.BlockEntity; | ||
import net.minecraft.block.entity.BlockEntityTicker; | ||
import net.minecraft.block.entity.BlockEntityType; | ||
import net.minecraft.item.ItemPlacementContext; | ||
import net.minecraft.sound.SoundCategory; | ||
import net.minecraft.state.StateManager; | ||
import net.minecraft.state.property.BooleanProperty; | ||
import net.minecraft.state.property.EnumProperty; | ||
import net.minecraft.state.property.Properties; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.util.math.Direction; | ||
import net.minecraft.world.World; | ||
import net.minecraft.world.WorldAccess; | ||
import net.minecraft.world.block.WireOrientation; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public class FluxCapacitorBlock extends BlockWithEntity implements BlockEntityProvider { | ||
public static final MapCodec<FluxCapacitorBlock> CODEC = FluxCapacitorBlock.createCodec(FluxCapacitorBlock::new); | ||
public static final BooleanProperty POWERED = Properties.POWERED; | ||
public static final EnumProperty<Direction> FACING = HorizontalFacingBlock.FACING; | ||
public FluxCapacitorBlock(Settings settings) { | ||
super(settings); | ||
this.setDefaultState(this.stateManager.getDefaultState().with(POWERED, false).with(FACING, Direction.NORTH)); | ||
} | ||
|
||
@Override | ||
protected MapCodec<? extends BlockWithEntity> getCodec() { | ||
return CODEC; | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public BlockEntity createBlockEntity(BlockPos pos, BlockState state) { | ||
return new FluxCapacitorBlockEntity(pos, state); | ||
} | ||
|
||
@Override | ||
public BlockRenderType getRenderType(BlockState state) { | ||
return BlockRenderType.MODEL; | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(World world, BlockState state, BlockEntityType<T> type) { | ||
return validateTicker(type, CubliminalBlockEntities.FLUX_CAPACITOR_BLOCK_ENTITY, FluxCapacitorBlockEntity::tick); | ||
} | ||
|
||
@Override | ||
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) { | ||
builder.add(POWERED, FACING); | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public BlockState getPlacementState(ItemPlacementContext ctx) { | ||
return this.getDefaultState().with(FACING, ctx.getHorizontalPlayerFacing().getOpposite()) | ||
.with(POWERED, shouldBePowered(ctx.getWorld(), ctx.getBlockPos())); | ||
} | ||
|
||
@Override | ||
protected void neighborUpdate(BlockState state, World world, BlockPos pos, Block sourceBlock, @Nullable WireOrientation wireOrientation, boolean notify) { | ||
if (shouldBePowered(world, pos)) { | ||
world.setBlockState(pos, state.with(POWERED, true)); | ||
} | ||
} | ||
|
||
protected boolean shouldBePowered(World world, BlockPos pos) { | ||
return world.isReceivingRedstonePower(pos) && world.getBlockState(pos.up()) | ||
.equals(Blocks.LIGHTNING_ROD.getDefaultState().with(LightningRodBlock.POWERED, true)); | ||
} | ||
|
||
@Override | ||
public void onBroken(WorldAccess world, BlockPos pos, BlockState state) { | ||
if (!world.isClient()) { | ||
CubliminalSounds.clientStopSound(world.getServer().getOverworld().getPlayers(), | ||
SoundCategory.BLOCKS, CubliminalSounds.FLUX_CAPACITOR.value().id()); | ||
} | ||
} | ||
} |
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
100 changes: 100 additions & 0 deletions
100
src/main/java/net/limit/cubliminal/block/entity/FluxCapacitorBlockEntity.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,100 @@ | ||
package net.limit.cubliminal.block.entity; | ||
|
||
import net.limit.cubliminal.block.custom.FluxCapacitorBlock; | ||
import net.limit.cubliminal.client.hud.NoClippingHudOverlay; | ||
import net.limit.cubliminal.init.CubliminalBlockEntities; | ||
import net.limit.cubliminal.init.CubliminalSounds; | ||
import net.limit.cubliminal.util.NoClipEngine; | ||
import net.minecraft.block.Block; | ||
import net.minecraft.block.BlockState; | ||
import net.minecraft.block.entity.BlockEntity; | ||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.entity.Entity; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.nbt.NbtCompound; | ||
import net.minecraft.predicate.entity.EntityPredicates; | ||
import net.minecraft.registry.RegistryWrapper; | ||
import net.minecraft.sound.SoundCategory; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.util.math.Direction; | ||
import net.minecraft.world.World; | ||
|
||
import java.util.function.Predicate; | ||
|
||
public class FluxCapacitorBlockEntity extends BlockEntity { | ||
|
||
public FluxCapacitorBlockEntity(BlockPos pos, BlockState state) { | ||
super(CubliminalBlockEntities.FLUX_CAPACITOR_BLOCK_ENTITY, pos, state); | ||
} | ||
|
||
private boolean canBreakReality; | ||
private int realityTicks; | ||
|
||
|
||
@Override | ||
protected void writeNbt(NbtCompound nbt, RegistryWrapper.WrapperLookup registryLookup) { | ||
super.writeNbt(nbt, registryLookup); | ||
nbt.putInt("RealityTicks", this.realityTicks); | ||
} | ||
|
||
@Override | ||
protected void readNbt(NbtCompound nbt, RegistryWrapper.WrapperLookup registryLookup) { | ||
super.readNbt(nbt, registryLookup); | ||
this.realityTicks = nbt.getInt("RealityTicks"); | ||
} | ||
|
||
|
||
public static void tick(World world, BlockPos pos, BlockState state, FluxCapacitorBlockEntity entity) { | ||
if (state.get(FluxCapacitorBlock.POWERED) && !entity.canBreakReality) { | ||
entity.canBreakReality = true; | ||
world.playSoundAtBlockCenter(pos, CubliminalSounds.FLUX_CAPACITOR.value(), | ||
SoundCategory.BLOCKS, 1.0f, 1.0f, false); | ||
} | ||
if (entity.canBreakReality) { | ||
entity.breakReality(world, state); | ||
} | ||
} | ||
|
||
|
||
@Override | ||
public boolean onSyncedBlockEvent(int type, int data) { | ||
if (type == 1) { | ||
return true; | ||
} else return super.onSyncedBlockEvent(type, data); | ||
} | ||
|
||
public void breakReality(World world, BlockState state) { | ||
if (this.realityTicks > 279) { | ||
world.setBlockState(pos, state.with(FluxCapacitorBlock.POWERED, false)); | ||
this.canBreakReality = false; | ||
this.realityTicks = 0; | ||
} else { | ||
++this.realityTicks; | ||
if (this.realityTicks == 220) { | ||
if (world.isClient) { | ||
NoClippingHudOverlay.INSTANCE.setAux_renderOverlay(false); | ||
} else { | ||
for (PlayerEntity player : world.getPlayers().stream().filter(Predicate.not(PlayerEntity::isSpectator)).toList()) { | ||
NoClipEngine.noClip(player); | ||
} | ||
} | ||
} else if (world.isClient && this.realityTicks == 100 && | ||
!MinecraftClient.getInstance().player.isSpectator()) { | ||
NoClippingHudOverlay.INSTANCE.setAux_renderOverlay(true); | ||
} | ||
} | ||
} | ||
|
||
public int getRealityTicks() { | ||
return this.realityTicks; | ||
} | ||
|
||
public boolean canBreakReality() { | ||
return this.canBreakReality; | ||
} | ||
|
||
@Override | ||
public NbtCompound toInitialChunkDataNbt(RegistryWrapper.WrapperLookup registryLookup) { | ||
return this.createNbt(registryLookup); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
src/main/java/net/limit/cubliminal/client/CubliminalRenderLayers.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 net.limit.cubliminal.client; | ||
|
||
import net.fabricmc.api.EnvType; | ||
import net.fabricmc.api.Environment; | ||
import net.limit.cubliminal.Cubliminal; | ||
import net.minecraft.client.gl.ShaderProgramKey; | ||
import net.minecraft.client.gl.ShaderProgramKeys; | ||
import net.minecraft.client.render.RenderLayer; | ||
import net.minecraft.client.render.RenderPhase; | ||
import net.minecraft.client.render.VertexFormat; | ||
import net.minecraft.client.render.VertexFormats; | ||
|
||
@Environment(EnvType.CLIENT) | ||
public class CubliminalRenderLayers { | ||
public static final ShaderProgramKey RENDERTYPE_CUBLIMINAL_MANILA_SKYBOX = ShaderProgramKeys.register("rendertype_cubliminal_manila_skybox", VertexFormats.POSITION_COLOR_TEXTURE_OVERLAY_LIGHT_NORMAL); | ||
|
||
public static final RenderPhase.ShaderProgram MANILA_PROGRAM = new RenderPhase.ShaderProgram(RENDERTYPE_CUBLIMINAL_MANILA_SKYBOX); | ||
|
||
public static final RenderLayer MANILA = RenderLayer.of("manila", VertexFormats.POSITION, | ||
VertexFormat.DrawMode.QUADS, 1536, false, false, | ||
RenderLayer.MultiPhaseParameters.builder().program(MANILA_PROGRAM).texture( | ||
RenderPhase.Textures.create() | ||
.add(Cubliminal.id("textures/sky/manila_" + 0 + ".png"), false, false) | ||
.add(Cubliminal.id("textures/sky/manila_" + 1 + ".png"), false, false) | ||
.add(Cubliminal.id("textures/sky/manila_" + 2 + ".png"), false, false) | ||
.add(Cubliminal.id("textures/sky/manila_" + 3 + ".png"), false, false) | ||
.add(Cubliminal.id("textures/sky/manila_" + 4 + ".png"), false, false) | ||
.add(Cubliminal.id("textures/sky/manila_" + 5 + ".png"), false, false) | ||
.build()).build(false)); | ||
|
||
|
||
public static final ShaderProgramKey RENDERTYPE_BLOOM_DOT = ShaderProgramKeys.register("rendertype_bloom_dot", VertexFormats.POSITION_COLOR); | ||
|
||
public static final RenderPhase.ShaderProgram BLOOM_PROGRAM = new RenderPhase.ShaderProgram(RENDERTYPE_BLOOM_DOT); | ||
|
||
public static final RenderLayer BLOOM = RenderLayer.of("bloom", VertexFormats.POSITION_COLOR_LIGHT, | ||
VertexFormat.DrawMode.QUADS, 1536, false, false, | ||
RenderLayer.MultiPhaseParameters.builder().program(BLOOM_PROGRAM).build(false)); | ||
|
||
|
||
public static void init() { | ||
} | ||
} |
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
Oops, something went wrong.