Skip to content

Commit

Permalink
Minor refactoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
shartte committed Mar 7, 2024
1 parent 901800e commit 9841392
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 93 deletions.
4 changes: 2 additions & 2 deletions src/main/java/appeng/api/stacks/AEFluidKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,12 @@ public boolean hasTag() {

@Override
public void writeToPacket(FriendlyByteBuf data) {
data.writeVarInt(BuiltInRegistries.FLUID.getId(fluid));
data.writeId(BuiltInRegistries.FLUID, fluid);
data.writeNbt(tag);
}

public static AEFluidKey fromPacket(FriendlyByteBuf data) {
var fluid = BuiltInRegistries.FLUID.byId(data.readVarInt());
var fluid = data.readById(BuiltInRegistries.FLUID);
var tag = data.readNbt();
return new AEFluidKey(fluid, tag);
}
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/appeng/recipes/entropy/EntropyRecipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -207,12 +207,12 @@ public record BlockInput(Block block, Map<String, PropertyValueMatcher> properti
.apply(builder, BlockInput::new));

public static void toNetwork(FriendlyByteBuf buffer, BlockInput input) {
buffer.writeVarInt(BuiltInRegistries.BLOCK.getId(input.block));
buffer.writeId(BuiltInRegistries.BLOCK, input.block);
buffer.writeMap(input.properties, FriendlyByteBuf::writeUtf, PropertyValueMatcher::toNetwork);
}

public static BlockInput fromNetwork(FriendlyByteBuf buffer) {
var block = BuiltInRegistries.BLOCK.byId(buffer.readVarInt());
var block = buffer.readById(BuiltInRegistries.BLOCK);
var properties = buffer.readMap(FriendlyByteBuf::readUtf, PropertyValueMatcher::fromNetwork);
return new BlockInput(block, properties);
}
Expand All @@ -226,12 +226,12 @@ public record FluidInput(Fluid fluid, Map<String, PropertyValueMatcher> properti
.apply(builder, FluidInput::new));

public static void toNetwork(FriendlyByteBuf buffer, FluidInput input) {
buffer.writeVarInt(BuiltInRegistries.FLUID.getId(input.fluid));
buffer.writeId(BuiltInRegistries.FLUID, input.fluid);
buffer.writeMap(input.properties, FriendlyByteBuf::writeUtf, PropertyValueMatcher::toNetwork);
}

public static FluidInput fromNetwork(FriendlyByteBuf buffer) {
var fluid = BuiltInRegistries.FLUID.byId(buffer.readVarInt());
var fluid = buffer.readById(BuiltInRegistries.FLUID);
var properties = buffer.readMap(FriendlyByteBuf::readUtf, PropertyValueMatcher::fromNetwork);
return new FluidInput(fluid, properties);
}
Expand Down Expand Up @@ -284,13 +284,13 @@ public BlockState apply(BlockState originalBlockState) {
}

public static void toNetwork(FriendlyByteBuf buffer, BlockOutput output) {
buffer.writeVarInt(BuiltInRegistries.BLOCK.getId(output.block));
buffer.writeId(BuiltInRegistries.BLOCK, output.block);
buffer.writeBoolean(output.keepProperties);
buffer.writeMap(output.properties, FriendlyByteBuf::writeUtf, (fbb, value) -> fbb.writeUtf(value));
}

public static BlockOutput fromNetwork(FriendlyByteBuf buffer) {
var block = BuiltInRegistries.BLOCK.byId(buffer.readVarInt());
var block = buffer.readById(BuiltInRegistries.BLOCK);
var keepProperties = buffer.readBoolean();
var properties = buffer.readMap(FriendlyByteBuf::readUtf, fbb -> fbb.readUtf());
return new BlockOutput(block, keepProperties, properties);
Expand Down Expand Up @@ -322,13 +322,13 @@ public FluidState apply(FluidState originalFluidState) {
}

public static void toNetwork(FriendlyByteBuf buffer, FluidOutput output) {
buffer.writeVarInt(BuiltInRegistries.FLUID.getId(output.fluid));
buffer.writeId(BuiltInRegistries.FLUID, output.fluid);
buffer.writeBoolean(output.keepProperties);
buffer.writeMap(output.properties, FriendlyByteBuf::writeUtf, (fbb, value) -> fbb.writeUtf(value));
}

public static FluidOutput fromNetwork(FriendlyByteBuf buffer) {
var fluid = BuiltInRegistries.FLUID.byId(buffer.readVarInt());
var fluid = buffer.readById(BuiltInRegistries.FLUID);
var keepProperties = buffer.readBoolean();
var properties = buffer.readMap(FriendlyByteBuf::readUtf, fbb -> fbb.readUtf());
return new FluidOutput(fluid, keepProperties, properties);
Expand Down
83 changes: 0 additions & 83 deletions src/main/java/appeng/util/InteractionUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,9 @@

package appeng.util;

import java.util.List;

import net.minecraft.util.Mth;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.ClipContext;
import net.minecraft.world.level.ClipContext.Block;
import net.minecraft.world.level.ClipContext.Fluid;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.EntityHitResult;
import net.minecraft.world.phys.HitResult;
import net.minecraft.world.phys.Vec3;

import appeng.datagen.providers.tags.ConventionTags;
Expand Down Expand Up @@ -96,76 +85,4 @@ public static LookDirection getPlayerRay(Player playerIn, double reachDistance)

return new LookDirection(from, to);
}

public static HitResult rayTrace(Player p, boolean hitBlocks, boolean hitEntities) {
final Level level = p.getCommandSenderWorld();

final float f = 1.0F;
float f1 = p.xRotO + (p.getXRot() - p.xRotO) * f;
final float f2 = p.yRotO + (p.getYRot() - p.yRotO) * f;
final double d0 = p.xo + (p.getX() - p.xo) * f;
final double d1 = p.yo + (p.getY() - p.yo) * f + 1.62D - p.getMyRidingOffset(p);
final double d2 = p.zo + (p.getZ() - p.zo) * f;
final Vec3 vec3 = new Vec3(d0, d1, d2);
final float f3 = Mth.cos(-f2 * 0.017453292F - (float) Math.PI);
final float f4 = Mth.sin(-f2 * 0.017453292F - (float) Math.PI);
final float f5 = -Mth.cos(-f1 * 0.017453292F);
final float f6 = Mth.sin(-f1 * 0.017453292F);
final float f7 = f4 * f5;
final float f8 = f3 * f5;
final double d3 = 32.0D;

final Vec3 vec31 = vec3.add(f7 * d3, f6 * d3, f8 * d3);

final AABB bb = new AABB(Math.min(vec3.x, vec31.x), Math.min(vec3.y, vec31.y),
Math.min(vec3.z, vec31.z), Math.max(vec3.x, vec31.x), Math.max(vec3.y, vec31.y),
Math.max(vec3.z, vec31.z)).inflate(16, 16, 16);

Entity entity = null;
double closest = 9999999.0D;
if (hitEntities) {
final List<Entity> list = level.getEntities(p, bb);

for (Entity entity1 : list) {
if (entity1.isAlive() && entity1 != p && !(entity1 instanceof ItemEntity)) {
// prevent killing / flying of mounts.
if (entity1.hasIndirectPassenger(p)) {
continue;
}

f1 = 0.3F;
// FIXME: Three different bounding boxes available, should double-check
final AABB boundingBox = entity1.getBoundingBox().inflate(f1, f1, f1);
final Vec3 rtResult = boundingBox.clip(vec3, vec31).orElse(null);

if (rtResult != null) {
final double nd = vec3.distanceToSqr(rtResult);

if (nd < closest) {
entity = entity1;
closest = nd;
}
}
}
}
}

HitResult pos = null;
Vec3 vec = null;

if (hitBlocks) {
vec = new Vec3(d0, d1, d2);
// FIXME: passing p as entity here might be incorrect
pos = level.clip(new ClipContext(vec3, vec31, Block.COLLIDER,
Fluid.ANY, p));
}

if (entity != null && pos != null && pos.getLocation().distanceToSqr(vec) > closest) {
pos = new EntityHitResult(entity);
} else if (entity != null && pos == null) {
pos = new EntityHitResult(entity);
}

return pos;
}
}

0 comments on commit 9841392

Please sign in to comment.