Skip to content

Commit

Permalink
Set player direction before mining
Browse files Browse the repository at this point in the history
  • Loading branch information
Kotori316 committed Feb 11, 2024
1 parent 3c45a86 commit b86f4a4
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 18 deletions.
14 changes: 13 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,15 @@ repositories {
}
}

maven {
name = "CoFH"
url = uri("https://maven.covers1624.net/")
content {
includeModule("com.teamcofh", "cofh_core")
includeModule("com.teamcofh", "ensorcellation")
}
}

maven {
name = "Azure-SLP"
url = uri("https://pkgs.dev.azure.com/Kotori316/minecraft/_packaging/mods/maven/v1")
Expand Down Expand Up @@ -268,6 +277,9 @@ dependencies {
compileOnly(fg.deobf(group: "curse.maven", name: "ic2-classic-242942", version: project.ic2ClassicId))
// testCompileOnly(fg.deobf(group: "curse.maven", name: "ic2-classic-242942", version: project.ic2ClassicId))
}
// Ensorcellation by CoFH
runtimeOnly(fg.deobf("com.teamcofh:cofh_core:1.20.1-11.0.0.51") { transitive(false) })
runtimeOnly(fg.deobf("com.teamcofh:ensorcellation:1.20.1-5.0.0.21") { transitive(false) })

// Test Dependencies.
// Required these libraries to execute the tests.
Expand Down Expand Up @@ -408,7 +420,7 @@ String getShortChangelog(boolean includeVersion) {
Stream.of(version, ""),
content
).collect(Collectors.joining(System.lineSeparator()))
}else{
} else {
content.collect(Collectors.joining(System.lineSeparator()))
}

Expand Down
18 changes: 17 additions & 1 deletion src/main/scala/com/yogpc/qp/machines/QuarryFakePlayer.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package com.yogpc.qp.machines;

import com.mojang.authlib.GameProfile;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.common.util.FakePlayer;
import net.minecraftforge.common.util.FakePlayerFactory;

Expand All @@ -10,7 +14,19 @@
public class QuarryFakePlayer {
private static final GameProfile profile = new GameProfile(UUID.fromString("ce6c3b8d-11ba-4b32-90d5-e5d30167fca7"), "[QuarryPlus]");

public static FakePlayer get(ServerLevel serverLevel) {
private static FakePlayer get(ServerLevel serverLevel) {
return FakePlayerFactory.get(serverLevel, profile);
}

public static FakePlayer getAndSetPosition(ServerLevel serverLevel, BlockPos pos, ItemStack stack) {
FakePlayer player = get(serverLevel);
player.setPos(Vec3.atCenterOf(pos.above(2)));
player.setXRot(90f);
player.setYRot(90f);
player.setYHeadRot(90f);
if (stack != null) {
player.setItemInHand(InteractionHand.MAIN_HAND, stack);
}
return player;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.MenuProvider;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntitySelector;
Expand Down Expand Up @@ -301,8 +300,7 @@ public ServerLevel getTargetWorld() {
public BreakResult breakOneBlock(BlockPos targetPos, boolean requireEnergy) {
var targetWorld = getTargetWorld();
var pickaxe = getPickaxe();
var fakePlayer = QuarryFakePlayer.get(targetWorld);
fakePlayer.setItemInHand(InteractionHand.MAIN_HAND, pickaxe);
var fakePlayer = QuarryFakePlayer.getAndSetPosition(targetWorld, targetPos, pickaxe);
// Check breakable
var state = targetWorld.getBlockState(targetPos);
var breakEvent = new BlockEvent.BreakEvent(targetWorld, targetPos, state, fakePlayer);
Expand Down Expand Up @@ -344,8 +342,7 @@ public BreakResult breakOneBlock(BlockPos targetPos, boolean requireEnergy) {
BreakResult breakBlocks(int x, int z) {
var targetWorld = getTargetWorld();
var pickaxe = getPickaxe();
var fakePlayer = QuarryFakePlayer.get(targetWorld);
fakePlayer.setItemInHand(InteractionHand.MAIN_HAND, pickaxe);
var fakePlayer = QuarryFakePlayer.getAndSetPosition(targetWorld, getBlockPos(), pickaxe);
var aabb = new AABB(x - 5, digMinY - 5, z - 5, x + 5, getBlockPos().getY() - 1, z + 5);
targetWorld.getEntitiesOfClass(ItemEntity.class, aabb, Predicate.not(i -> i.getItem().isEmpty()))
.forEach(i -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ void work() {
continue; // The block is in deny list or unbreakable.
}

var fakePlayer = QuarryFakePlayer.get(level);
var fakePlayer = QuarryFakePlayer.getAndSetPosition(level, pos, null);
var event = new BlockEvent.BreakEvent(level, pos, state, fakePlayer);
if (MinecraftForge.EVENT_BUS.post(event)) {
TraceQuarryWork.blockRemoveFailed(this, getBlockPos(), pos, state, BreakResult.FAIL_EVENT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.enchantment.Enchantments;
Expand Down Expand Up @@ -60,8 +59,7 @@ public void tick() {

if (state.isAir() || state.is(Holder.BLOCK_DUMMY)) continue;
var pickaxe = EnchantmentLevel.HasEnchantments.super.getPickaxe();
var fakePlayer = QuarryFakePlayer.get((ServerLevel) level);
fakePlayer.setItemInHand(InteractionHand.MAIN_HAND, pickaxe);
var fakePlayer = QuarryFakePlayer.getAndSetPosition((ServerLevel) level, targetPos, pickaxe);
var breakEvent = new BlockEvent.BreakEvent(level, targetPos, state, fakePlayer);
MinecraftForge.EVENT_BUS.post(breakEvent);
if (breakEvent.isCanceled()) continue;
Expand Down
5 changes: 2 additions & 3 deletions src/main/scala/com/yogpc/qp/machines/placer/PlacerTile.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,7 @@ void breakBlock() {
BlockPos pos = getTargetPos();
BlockState state = level.getBlockState(pos);
if (state.getDestroySpeed(level, pos) < 0) return; // Unbreakable.
Player fake = QuarryFakePlayer.get(((ServerLevel) level));
fake.setItemInHand(InteractionHand.MAIN_HAND, getSilkPickaxe());
Player fake = QuarryFakePlayer.getAndSetPosition(((ServerLevel) level), pos, getSilkPickaxe());
List<ItemStack> drops = InvUtils.getBlockDrops(state, ((ServerLevel) level), pos, level.getBlockEntity(pos), fake, fake.getMainHandItem());
level.removeBlock(pos, false);
drops.stream().map(s -> ItemHandlerHelper.insertItem(this.itemHandler, s, false)) // Return not-inserted items.
Expand All @@ -131,7 +130,7 @@ boolean placeBlock() {
BlockPos pos = getTargetPos();
Vec3 hitPos = DIRECTION_VEC3D_MAP.get(facing.getOpposite()).add(pos.getX(), pos.getY(), pos.getZ());
BlockHitResult rayTrace = new BlockHitResult(hitPos, facing.getOpposite(), pos, false);
Player fake = QuarryFakePlayer.get(((ServerLevel) level));
Player fake = QuarryFakePlayer.getAndSetPosition(((ServerLevel) level), pos, null);

AtomicBoolean result = new AtomicBoolean(false);
findEntry(inventory,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public void tick(Level world, BlockPos quarryPos, BlockState state, TileQuarry q
Set<BlockPos> fluidPoses = countFluid(targetWorld, original, quarry.getArea());
TraceQuarryWork.progress(quarry, quarryPos, original, "Remove %d fluids".formatted(fluidPoses.size()));
if (quarry.useEnergy(PowerManager.getBreakBlockFluidEnergy(quarry) * fluidPoses.size(), PowerTile.Reason.REMOVE_FLUID, true)) {
var fakePlayer = QuarryFakePlayer.get(targetWorld);
var fakePlayer = QuarryFakePlayer.getAndSetPosition(targetWorld, original, null);
for (BlockPos fluidPos : fluidPoses) {
var blockState = targetWorld.getBlockState(fluidPos);
if (blockState.getBlock() instanceof LiquidBlock) {
Expand Down
4 changes: 1 addition & 3 deletions src/main/scala/com/yogpc/qp/machines/quarry/TileQuarry.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntitySelector;
import net.minecraft.world.entity.ExperienceOrb;
Expand Down Expand Up @@ -217,8 +216,7 @@ public BreakResult breakBlock(BlockPos targetPos, boolean requireEnergy) {
}));
}
var pickaxe = getPickaxe();
var fakePlayer = QuarryFakePlayer.get(targetWorld);
fakePlayer.setItemInHand(InteractionHand.MAIN_HAND, pickaxe);
var fakePlayer = QuarryFakePlayer.getAndSetPosition(targetWorld, targetPos, pickaxe);
// Check breakable
var state = targetWorld.getBlockState(targetPos);
var breakEvent = new BlockEvent.BreakEvent(targetWorld, targetPos, state, fakePlayer);
Expand Down

0 comments on commit b86f4a4

Please sign in to comment.