-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# Conflicts: # gradle.properties
- Loading branch information
Showing
19 changed files
with
405 additions
and
115 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
83 changes: 83 additions & 0 deletions
83
src/main/java/net/frozenblock/lib/item/api/PlaceInAirBlockItem.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,83 @@ | ||
/* | ||
* Copyright (C) 2024 FrozenBlock | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package net.frozenblock.lib.item.api; | ||
|
||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.core.Direction; | ||
import net.minecraft.util.Mth; | ||
import net.minecraft.world.InteractionHand; | ||
import net.minecraft.world.InteractionResult; | ||
import net.minecraft.world.InteractionResultHolder; | ||
import net.minecraft.world.entity.player.Player; | ||
import net.minecraft.world.entity.projectile.ProjectileUtil; | ||
import net.minecraft.world.item.BlockItem; | ||
import net.minecraft.world.item.Item; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.item.context.BlockPlaceContext; | ||
import net.minecraft.world.level.Level; | ||
import net.minecraft.world.level.block.Block; | ||
import net.minecraft.world.phys.AABB; | ||
import net.minecraft.world.phys.BlockHitResult; | ||
import net.minecraft.world.phys.EntityHitResult; | ||
import net.minecraft.world.phys.Vec3; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class PlaceInAirBlockItem extends BlockItem { | ||
|
||
public PlaceInAirBlockItem(Block block, Item.Properties properties) { | ||
super(block, properties); | ||
} | ||
|
||
@Override | ||
@NotNull | ||
public InteractionResultHolder<ItemStack> use(@NotNull Level level, @NotNull Player player, InteractionHand hand) { | ||
ItemStack itemStack = player.getItemInHand(hand); | ||
|
||
double blockInteractionRange = player.blockInteractionRange(); | ||
|
||
Vec3 lookAngle = player.getLookAngle(); | ||
Vec3 playerPos = player.getEyePosition(); | ||
Vec3 placementPos = playerPos.add( | ||
lookAngle.scale(blockInteractionRange) | ||
); | ||
|
||
AABB entityPickBox = player.getBoundingBox().expandTowards(lookAngle.scale(blockInteractionRange)).inflate(1D, 1D, 1D); | ||
EntityHitResult entityHitResult = ProjectileUtil.getEntityHitResult( | ||
player, | ||
playerPos, | ||
placementPos, | ||
entityPickBox, | ||
entityx -> !entityx.isSpectator() && entityx.isPickable(), | ||
Mth.square(blockInteractionRange) | ||
); | ||
|
||
if (entityHitResult == null) { | ||
BlockPos pos = BlockPos.containing(placementPos); | ||
|
||
if (level.isInWorldBounds(pos) && level.getWorldBorder().isWithinBounds(pos) && level.getBlockState(pos).canBeReplaced()) { | ||
Direction reflectedFacingDirection = Direction.getNearest(lookAngle); | ||
BlockPlaceContext context = new BlockPlaceContext(player, hand, itemStack, new BlockHitResult(pos.getCenter(), reflectedFacingDirection, pos, false)); | ||
InteractionResult result = this.useOn(context); | ||
if (result.consumesAction()) { | ||
return InteractionResultHolder.sidedSuccess(itemStack, !level.isClientSide()); | ||
} | ||
} | ||
} | ||
return super.use(level, player, hand); | ||
} | ||
} |
102 changes: 102 additions & 0 deletions
102
src/main/java/net/frozenblock/lib/item/mixin/client/LevelRendererMixin.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,102 @@ | ||
/* | ||
* Copyright (C) 2024 FrozenBlock | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package net.frozenblock.lib.item.mixin.client; | ||
|
||
import com.llamalad7.mixinextras.injector.ModifyExpressionValue; | ||
import com.llamalad7.mixinextras.injector.wrapoperation.Operation; | ||
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; | ||
import com.llamalad7.mixinextras.sugar.Local; | ||
import com.llamalad7.mixinextras.sugar.Share; | ||
import com.llamalad7.mixinextras.sugar.ref.LocalBooleanRef; | ||
import com.mojang.blaze3d.vertex.PoseStack; | ||
import com.mojang.blaze3d.vertex.VertexConsumer; | ||
import net.fabricmc.api.EnvType; | ||
import net.fabricmc.api.Environment; | ||
import net.frozenblock.lib.item.api.PlaceInAirBlockItem; | ||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.client.renderer.LevelRenderer; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import net.minecraft.world.phys.HitResult; | ||
import net.minecraft.world.phys.shapes.Shapes; | ||
import net.minecraft.world.phys.shapes.VoxelShape; | ||
import org.spongepowered.asm.mixin.Final; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
|
||
@Environment(EnvType.CLIENT) | ||
@Mixin(LevelRenderer.class) | ||
public abstract class LevelRendererMixin { | ||
|
||
@Shadow | ||
@Final | ||
private Minecraft minecraft; | ||
|
||
@ModifyExpressionValue( | ||
method = "renderLevel", | ||
at = @At( | ||
value = "INVOKE", | ||
target = "Lnet/minecraft/world/phys/HitResult;getType()Lnet/minecraft/world/phys/HitResult$Type;" | ||
) | ||
) | ||
public HitResult.Type frozenLib$useBlockTypeIfPlaceableInAir( | ||
HitResult.Type original, | ||
@Share("frozenLib$canPlaceInAir") LocalBooleanRef canPlaceInAir | ||
) { | ||
if (this.minecraft.player != null && original == HitResult.Type.MISS) { | ||
if (this.minecraft.player.getMainHandItem().getItem() instanceof PlaceInAirBlockItem || this.minecraft.player.getOffhandItem().getItem() instanceof PlaceInAirBlockItem) { | ||
canPlaceInAir.set(true); | ||
return HitResult.Type.BLOCK; | ||
} | ||
} | ||
|
||
canPlaceInAir.set(false); | ||
return original; | ||
} | ||
|
||
@ModifyExpressionValue( | ||
method = "renderLevel", | ||
at = @At( | ||
value = "INVOKE", | ||
target = "Lnet/minecraft/world/level/block/state/BlockState;isAir()Z" | ||
) | ||
) | ||
public boolean frozenLib$overrideAirCheck( | ||
boolean original, | ||
@Share("frozenLib$canPlaceInAir") LocalBooleanRef canPlaceInAir | ||
) { | ||
return original && !canPlaceInAir.get(); | ||
} | ||
|
||
@WrapOperation( | ||
method = "renderHitOutline", | ||
at = @At( | ||
value = "INVOKE", | ||
target = "Lnet/minecraft/client/renderer/LevelRenderer;renderShape(Lcom/mojang/blaze3d/vertex/PoseStack;Lcom/mojang/blaze3d/vertex/VertexConsumer;Lnet/minecraft/world/phys/shapes/VoxelShape;DDDFFFF)V" | ||
) | ||
) | ||
private void frozenLib$renderOutlineForAir( | ||
PoseStack poseStack, VertexConsumer vertexConsumer, VoxelShape voxelShape, double d, double e, double f, float g, float h, float i, float j, Operation<Void> original, | ||
@Local(argsOnly = true) BlockState blockState | ||
) { | ||
if (blockState.isAir()) voxelShape = Shapes.block(); | ||
|
||
original.call(poseStack, vertexConsumer, voxelShape, d, e, f, g, h, i, j); | ||
} | ||
|
||
} |
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
27 changes: 27 additions & 0 deletions
27
src/main/java/net/frozenblock/lib/recipe/api/ShapelessRecipeBuilderExtension.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,27 @@ | ||
/* | ||
* Copyright (C) 2024 FrozenBlock | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package net.frozenblock.lib.recipe.api; | ||
|
||
import net.minecraft.core.component.DataComponentPatch; | ||
import net.minecraft.data.recipes.ShapedRecipeBuilder; | ||
import net.minecraft.data.recipes.ShapelessRecipeBuilder; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public interface ShapelessRecipeBuilderExtension { | ||
ShapelessRecipeBuilder frozenLib$patch(@Nullable DataComponentPatch tag); | ||
} |
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
Oops, something went wrong.