Skip to content

Commit

Permalink
1.20 corridors (#206)
Browse files Browse the repository at this point in the history
Co-authored-by: MagicMaan <[email protected]>
Co-authored-by: Craig (Jeryn) <[email protected]>
  • Loading branch information
3 people authored Mar 25, 2024
1 parent 81c8561 commit 0f60374
Show file tree
Hide file tree
Showing 354 changed files with 1,575 additions and 4,292 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,4 @@ run/
/common/bin/
/fabric/bin/main/
/forge/bin/main/
/forge/src/generated/
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import whocraft.tardis_refined.common.tardis.themes.ShellTheme;
import whocraft.tardis_refined.common.world.ChunkGenerators;
import whocraft.tardis_refined.common.world.Features;
import whocraft.tardis_refined.registry.ARSStructurePieceRegistry;
import whocraft.tardis_refined.patterns.ConsolePatterns;
import whocraft.tardis_refined.patterns.ShellPatterns;
import whocraft.tardis_refined.registry.*;
Expand Down Expand Up @@ -70,6 +71,8 @@ public static void init() {
ShellPatterns.registerDefaultPatterns();
TardisHums.registerDefaultHums();

ARSStructurePieceRegistry.register();
ManipulatorCrafting.registerRecipes();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package whocraft.tardis_refined.client;

import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.Tesselator;
import com.mojang.math.Transformation;
import net.minecraft.ChatFormatting;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Font;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import whocraft.tardis_refined.common.GravityUtil;
import whocraft.tardis_refined.constants.ModMessages;

public class GravityOverlay {

public static void renderOverlay(PoseStack poseStack) {
Minecraft mc = Minecraft.getInstance();
Font fontRenderer = mc.font;

if (GravityUtil.isInGravityShaft(mc.player) && !mc.getDebugOverlay().showDebugScreen()) {
poseStack.pushPose();
poseStack.scale(1.2f, 1.2f, 1.2f);

int x = 5;
int y = 5;

MutableComponent ascendKey = Component.translatable(mc.options.keyJump.getDefaultKey().getName());
MutableComponent descendKey = Component.translatable(mc.options.keyShift.getDefaultKey().getName());

MultiBufferSource.BufferSource renderImpl = MultiBufferSource.immediate(Tesselator.getInstance().getBuilder());
fontRenderer.drawInBatch(Component.translatable(ModMessages.ASCEND_KEY, ascendKey).getString(), x, y, ChatFormatting.WHITE.getColor(), true, Transformation.identity().getMatrix(), renderImpl, Font.DisplayMode.NORMAL, 0, 15728880);
fontRenderer.drawInBatch(Component.translatable(Component.translatable(ModMessages.DESCEND_KEY, descendKey).getString()), x, y + fontRenderer.lineHeight, ChatFormatting.WHITE.getColor(), true, Transformation.identity().getMatrix(), renderImpl, Font.DisplayMode.NORMAL, 0, 15728880);
renderImpl.endBatch();

poseStack.popPose();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import whocraft.tardis_refined.client.sounds.HumSoundManager;
import whocraft.tardis_refined.client.sounds.LoopingSound;
import whocraft.tardis_refined.client.sounds.QuickSimpleSound;
import whocraft.tardis_refined.common.GravityUtil;
import whocraft.tardis_refined.common.hum.HumEntry;
import whocraft.tardis_refined.common.hum.TardisHums;
import whocraft.tardis_refined.common.network.messages.sync.SyncTardisClientDataMessage;
Expand All @@ -34,6 +35,7 @@
import java.util.Map;

import static whocraft.tardis_refined.common.util.TardisHelper.isInArsArea;
import static whocraft.tardis_refined.constants.TardisDimensionConstants.ARS_TREE_CENTER;

public class TardisClientData {
public static int FOG_TICK_DELTA = 0; // This is for the fading in and out of the fog.
Expand Down Expand Up @@ -287,11 +289,16 @@ public void tickClientside() {

if (isInArsArea(Minecraft.getInstance().player.blockPosition())) {
if (!soundManager.isActive(LoopingSound.ARS_HUMMING)) {
LoopingSound.ARS_HUMMING.setLocation(new Vec3(1024, 100, 16));
LoopingSound.ARS_HUMMING.setLocation(ARS_TREE_CENTER);
soundManager.play(LoopingSound.ARS_HUMMING);
}
}

if (isThisTardis && isFlying()) {
if (!soundManager.isActive(LoopingSound.FLIGHT_LOOP)) {
soundManager.play(LoopingSound.FLIGHT_LOOP);
}
}

if (isThisTardis && humEntry != null && !humEntry.getSound().toString().equals(HumSoundManager.getCurrentRawSound().getLocation().toString()) || !soundManager.isActive(HumSoundManager.getCurrentSound())) {
HumSoundManager.playHum(SoundEvent.createVariableRangeEvent(humEntry.getSound()));
Expand Down Expand Up @@ -435,6 +442,18 @@ public static void tickClientData(Minecraft client) {
return;
}

SoundManager soundManager = Minecraft.getInstance().getSoundManager();

if (LoopingSound.ARS_HUMMING == null) {
LoopingSound.setupSounds();
}

if (GravityUtil.isInGravityShaft(Minecraft.getInstance().player)) {
if (!soundManager.isActive(LoopingSound.GRAVITY_LOOP)) {
soundManager.play(LoopingSound.GRAVITY_LOOP);
}
}

TardisClientData.getAllEntries().forEach((levelResourceKey, tardisClientData) -> tardisClientData.tickClientside());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ private ResourceLocation texture(ShellPattern pattern, boolean isEmmissive) {
return isEmmissive ? pattern.exteriorDoorTexture().emissiveTexture() : pattern.exteriorDoorTexture().texture();
}


ModelPart fade_value;

float initAlpha = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Font;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.blockentity.SignRenderer;
import net.minecraft.client.renderer.entity.EntityRendererProvider;
import net.minecraft.client.renderer.entity.NoopRenderer;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.util.FormattedCharSequence;
import net.minecraft.world.level.block.entity.SignBlockEntity;
import net.minecraft.world.phys.EntityHitResult;
import net.minecraft.world.phys.HitResult;
import org.joml.Matrix4f;
Expand Down Expand Up @@ -44,13 +47,11 @@ public void render(ControlEntity entity, float f, float g, PoseStack poseStack,

@Override
protected void renderNameTag(ControlEntity entity, Component component, PoseStack poseStack, MultiBufferSource multiBufferSource, int packedLightCoords) {
MutableComponent textComponent = component.copy();
textComponent.withStyle(style -> style
.applyFormats(ChatFormatting.BOLD, (entity.level().getGameTime() % 60 == 0) ? ChatFormatting.GOLD : ChatFormatting.YELLOW)
);


double distanceSquared = this.entityRenderDispatcher.distanceToSqr(entity);
if (!(distanceSquared > 4096.0)) {

boolean isSolid = !entity.isDiscrete();
float boundingBoxHeight = entity.getNameTagOffsetY();
int verticalTextOffset = 35;
Expand All @@ -62,15 +63,18 @@ protected void renderNameTag(ControlEntity entity, Component component, PoseStac
poseStack.scale(-scale, -scale, scale);

Matrix4f textMatrix = poseStack.last().pose();
float textBackgroundOpacity = Minecraft.getInstance().options.getBackgroundOpacity(0.5F);

int textColor = (int) (textBackgroundOpacity * 255.0F) << 24;


Font font = this.getFont();
float textHorizontalPosition = (float) (-font.width(component) / 2);

font.drawInBatch(textComponent, textHorizontalPosition, (float) verticalTextOffset, 553648127, false, textMatrix, multiBufferSource, Font.DisplayMode.SEE_THROUGH, textColor, packedLightCoords);
FormattedCharSequence sequence = component.getVisualOrderText();

font.drawInBatch8xOutline(sequence, textHorizontalPosition, (float) verticalTextOffset, 16777215, 0, textMatrix, multiBufferSource, packedLightCoords);

if (isSolid) {
font.drawInBatch(textComponent, textHorizontalPosition, (float) verticalTextOffset, -1, false, textMatrix, multiBufferSource, Font.DisplayMode.NORMAL, 0, packedLightCoords);
font.drawInBatch8xOutline(sequence, textHorizontalPosition, (float) verticalTextOffset, 16777215, 0, textMatrix, multiBufferSource, packedLightCoords);
}

poseStack.popPose();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@
import net.minecraft.world.phys.Vec3;
import org.jetbrains.annotations.NotNull;
import whocraft.tardis_refined.client.TardisClientData;
import whocraft.tardis_refined.common.GravityUtil;
import whocraft.tardis_refined.registry.SoundRegistry;

public class LoopingSound extends AbstractTickableSoundInstance {

public static LoopingSound ARS_HUMMING = null;
public static LoopingSound FLIGHT_LOOP = null;
public static LoopingSound GRAVITY_LOOP = null;
public LoopingSound(@NotNull SoundEvent soundEvent, SoundSource soundSource) {
super(soundEvent, soundSource, SoundInstance.createUnseededRandom());
attenuation = Attenuation.NONE;
Expand Down Expand Up @@ -78,11 +80,23 @@ public void tick() {
} else {
volume = 0F;
}

if (tardisClientData.getFuel() == 0f) {
volume = 0F;
}

}

if (tardisClientData.getFuel() == 0f) {
volume = 0F;

if(this == LoopingSound.GRAVITY_LOOP){
if (GravityUtil.isInGravityShaft(Minecraft.getInstance().player)) {
LoopingSound.GRAVITY_LOOP.setLocation(player.position());
volume = 0.5F;
} else {
volume = 0F;
}
}

}

@Override
Expand Down
103 changes: 103 additions & 0 deletions common/src/main/java/whocraft/tardis_refined/common/GravityUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package whocraft.tardis_refined.common;

import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.Minecraft;
import net.minecraft.client.Options;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.core.BlockPos;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.util.RandomSource;
import net.minecraft.world.entity.Pose;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import whocraft.tardis_refined.common.block.device.AntiGravityBlock;
import whocraft.tardis_refined.registry.DimensionTypes;

import static net.minecraft.core.BlockPos.betweenClosed;

public class GravityUtil {


private static final int MAX_Y = 30; // The most a shaft can carry a player up
private static final double ACCELERATION = 0.2;
public static boolean isInAntiGrav(Player playerBox, AABB box, Level level) {
if(level.dimensionTypeId() != DimensionTypes.TARDIS) return false;
for (BlockPos pos : betweenClosed(new BlockPos((int) box.maxX, (int) box.maxY, (int) box.maxZ), new BlockPos((int) box.minX, (int) box.minY, (int) box.minZ))) {
BlockState blockState = level.getBlockState(pos);
if (blockState.getBlock() instanceof AntiGravityBlock) {
int space = blockState.getValue(AntiGravityBlock.SPACE);
if (space > 0 && level.getBlockState(pos.above()).isAir()) {
AABB myGravBox = GravityUtil.createGravityBoxFromLevel(level, pos, space);
spawnParticlesWithinAABB(level, myGravBox);
if (myGravBox.intersects(playerBox.getBoundingBox()) && playerBox.blockPosition().getY() >= pos.getY()) {
return true;
}
}
}
}
return false;
}


private static void spawnParticlesWithinAABB(Level level, AABB box) {
RandomSource randomSource = level.random;
for (int i = 0; i < 2; i++) {
double x = box.minX + (box.maxX - box.minX) * randomSource.nextDouble();
double y = box.minY + (box.maxY - box.minY) * randomSource.nextDouble();
double z = box.minZ + (box.maxZ - box.minZ) * randomSource.nextDouble();
level.addParticle(ParticleTypes.ASH, x, y, z, 0, 0.2, 0);
}
}


public static AABB createGravityBoxFromLevel(Level level, BlockPos blockPos, int range) {
if (level != null) {
return new AABB(blockPos).inflate(range, MAX_Y, range);
}
return null;
}


public static boolean isInGravityShaft(Player player) {
return isInAntiGrav(player, player.getBoundingBox().inflate(20, MAX_Y, 20), player.level());
}

@Environment(EnvType.CLIENT)
public static void moveGravity(Player player, CallbackInfo info) {
Vec3 deltaMovement = player.getDeltaMovement();
Minecraft minecraft = Minecraft.getInstance();
Options options = minecraft.options;

if (isInGravityShaft(player)) {
player.resetFallDistance();
player.setNoGravity(true);
player.setPose(Pose.STANDING);

if (options.keyJump.isDown()) {
player.setDeltaMovement(deltaMovement.add(0, easeMovement(), 0));
info.cancel();
} else if (options.keyShift.isDown()) {
player.setDeltaMovement(deltaMovement.add(0, -easeMovement(), 0));
info.cancel();
} else {
player.setDeltaMovement(deltaMovement.x, 0, deltaMovement.z);
}
} else {
player.setNoGravity(false);
}
}


private static double easeMovement() {
double smoothedMovement = Math.abs(GravityUtil.ACCELERATION);
return smoothedMovement * smoothedMovement * smoothedMovement;
}



}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package whocraft.tardis_refined.common.block.device;

import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.RenderShape;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.block.state.properties.IntegerProperty;
import net.minecraft.world.phys.BlockHitResult;
import org.jetbrains.annotations.NotNull;
import whocraft.tardis_refined.common.items.ScrewdriverItem;

public class AntiGravityBlock extends Block {

public static final IntegerProperty SPACE = IntegerProperty.create("space", 0, 5);

public static final int DISABLED_SPACE = 0;
public static final int MAX_SPACE = 5;
public AntiGravityBlock(Properties properties) {
super(properties);
this.registerDefaultState(this.stateDefinition.any().setValue(SPACE, DISABLED_SPACE));
}

@Override
public RenderShape getRenderShape(BlockState state) {
return RenderShape.MODEL;
}

@Override
public BlockState getStateForPlacement(@NotNull BlockPlaceContext context) {
BlockState state = super.getStateForPlacement(context);
return state.setValue(SPACE, DISABLED_SPACE);
}



@Override
protected void createBlockStateDefinition(StateDefinition.@NotNull Builder<Block, BlockState> builder) {
super.createBlockStateDefinition(builder);
builder.add(SPACE);
}

@Override
public InteractionResult use(BlockState blockState, Level level, BlockPos blockPos, Player player, InteractionHand interactionHand, BlockHitResult blockHitResult) {

if(!level.isClientSide && interactionHand == InteractionHand.MAIN_HAND && player.getItemInHand(interactionHand).getItem() instanceof ScrewdriverItem) {
int space = blockState.getValue(SPACE);
int newSpace = space + 1;
if (newSpace > MAX_SPACE) {
newSpace = DISABLED_SPACE;
}
player.swing(interactionHand, true);

level.setBlockAndUpdate(blockPos, blockState.setValue(SPACE, newSpace));
return super.use(blockState, level, blockPos, player, interactionHand, blockHitResult);
}
return super.use(blockState, level, blockPos, player, interactionHand, blockHitResult);
}
}
Loading

0 comments on commit 0f60374

Please sign in to comment.