-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: MagicMaan <[email protected]> Co-authored-by: Craig (Jeryn) <[email protected]>
- Loading branch information
1 parent
81c8561
commit 0f60374
Showing
354 changed files
with
1,575 additions
and
4,292 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -121,3 +121,4 @@ run/ | |
/common/bin/ | ||
/fabric/bin/main/ | ||
/forge/bin/main/ | ||
/forge/src/generated/ |
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
40 changes: 40 additions & 0 deletions
40
common/src/main/java/whocraft/tardis_refined/client/GravityOverlay.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 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(); | ||
} | ||
} | ||
|
||
} |
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
103 changes: 103 additions & 0 deletions
103
common/src/main/java/whocraft/tardis_refined/common/GravityUtil.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,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; | ||
} | ||
|
||
|
||
|
||
} |
66 changes: 66 additions & 0 deletions
66
common/src/main/java/whocraft/tardis_refined/common/block/device/AntiGravityBlock.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,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); | ||
} | ||
} |
Oops, something went wrong.