优化部分代码
This commit is contained in:
parent
ed538bc7ce
commit
714e452d53
7 changed files with 55 additions and 84 deletions
|
@ -1,8 +1,14 @@
|
|||
package net.mcreator.target.mixins;
|
||||
|
||||
import net.mcreator.target.entity.DroneEntity;
|
||||
import net.mcreator.target.entity.Mk42Entity;
|
||||
import net.mcreator.target.init.TargetModItems;
|
||||
import net.minecraft.client.Camera;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
@ -12,6 +18,35 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
|||
|
||||
@Mixin(Camera.class)
|
||||
public abstract class CameraMixin {
|
||||
@Shadow(aliases = "Lnet/minecraft/client/Camera;setRotation(FF)V")
|
||||
protected abstract void setRotation(float p_90573_, float p_90574_);
|
||||
|
||||
@Shadow(aliases = "Lnet/minecraft/client/Camera;setPosition(DDD)V")
|
||||
protected abstract void setPosition(double p_90585_, double p_90586_, double p_90587_);
|
||||
|
||||
@Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Camera;setRotation(FF)V", ordinal = 0),
|
||||
method = "setup(Lnet/minecraft/world/level/BlockGetter;Lnet/minecraft/world/entity/Entity;ZZF)V",
|
||||
cancellable = true)
|
||||
private void onSetup(BlockGetter level, Entity entity, boolean detached, boolean mirrored, float partialTicks, CallbackInfo info) {
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
Player player = mc.player;
|
||||
|
||||
if (player != null) {
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
|
||||
if (stack.is(TargetModItems.MONITOR.get()) && stack.getOrCreateTag().getBoolean("Using") && stack.getOrCreateTag().getBoolean("Linked")) {
|
||||
DroneEntity drone = player.level().getEntitiesOfClass(DroneEntity.class, player.getBoundingBox().inflate(512))
|
||||
.stream().filter(e -> e.getStringUUID().equals(stack.getOrCreateTag().getString("LinkedDrone"))).findFirst().orElse(null);
|
||||
|
||||
if (drone != null) {
|
||||
setRotation(drone.getViewYRot(partialTicks), drone.getViewXRot(partialTicks));
|
||||
setPosition(Mth.lerp(partialTicks, drone.xo, drone.getX()) + 0.18 * drone.getLookAngle().x, Mth.lerp(partialTicks, drone.yo, drone.getY()) + 0.075, Mth.lerp(partialTicks, drone.zo, drone.getZ()) + 0.18 * drone.getLookAngle().z);
|
||||
info.cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "setup", at = @At("TAIL"))
|
||||
public void ia$setup(BlockGetter area, Entity entity, boolean thirdPerson, boolean inverseView, float tickDelta, CallbackInfo ci) {
|
||||
if (thirdPerson && entity.getVehicle() instanceof Mk42Entity) {
|
||||
|
|
|
@ -1,51 +0,0 @@
|
|||
package net.mcreator.target.mixins;
|
||||
|
||||
import net.mcreator.target.entity.DroneEntity;
|
||||
import net.mcreator.target.init.TargetModItems;
|
||||
import net.minecraft.client.Camera;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(Camera.class)
|
||||
public abstract class MixinCamera {
|
||||
|
||||
@Shadow(aliases = "Lnet/minecraft/client/Camera;setRotation(FF)V")
|
||||
protected abstract void setRotation(float p_90573_, float p_90574_);
|
||||
|
||||
@Shadow(aliases = "Lnet/minecraft/client/Camera;setPosition(DDD)V")
|
||||
protected abstract void setPosition(double p_90585_, double p_90586_, double p_90587_);
|
||||
|
||||
@Inject(
|
||||
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Camera;setRotation(FF)V", ordinal = 0),
|
||||
method = "setup(Lnet/minecraft/world/level/BlockGetter;Lnet/minecraft/world/entity/Entity;ZZF)V",
|
||||
cancellable = true)
|
||||
private void onSetup(BlockGetter level, Entity entity, boolean detached, boolean mirrored, float partialTicks, CallbackInfo info) {
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
Player player = mc.player;
|
||||
|
||||
if (player != null) {
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
|
||||
if (stack.is(TargetModItems.MONITOR.get()) && stack.getOrCreateTag().getBoolean("Using") && stack.getOrCreateTag().getBoolean("Linked")) {
|
||||
DroneEntity drone = player.level().getEntitiesOfClass(DroneEntity.class, player.getBoundingBox().inflate(512))
|
||||
.stream().filter(e -> e.getStringUUID().equals(stack.getOrCreateTag().getString("LinkedDrone"))).findFirst().orElse(null);
|
||||
|
||||
if (drone != null) {
|
||||
setRotation(drone.getViewYRot(partialTicks), drone.getViewXRot(partialTicks));
|
||||
setPosition(Mth.lerp(partialTicks, drone.xo, drone.getX()) + 0.18 * drone.getLookAngle().x, Mth.lerp(partialTicks, drone.yo, drone.getY()) + 0.075, Mth.lerp(partialTicks, drone.zo, drone.getZ()) + 0.18 * drone.getLookAngle().z);
|
||||
info.cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,13 +1,10 @@
|
|||
package net.mcreator.target.network.message;
|
||||
|
||||
import net.mcreator.target.entity.DroneEntity;
|
||||
import net.mcreator.target.entity.Mk42Entity;
|
||||
import net.mcreator.target.init.TargetModItems;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraftforge.network.NetworkEvent;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
@ -31,22 +28,20 @@ public class DroneFireMessage {
|
|||
NetworkEvent.Context context = contextSupplier.get();
|
||||
context.enqueueWork(() -> {
|
||||
if (context.getSender() != null) {
|
||||
pressAction(context.getSender(), message.type);
|
||||
}
|
||||
});
|
||||
context.setPacketHandled(true);
|
||||
}
|
||||
Player player = context.getSender();
|
||||
|
||||
public static void pressAction(Player player, int type) {
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (stack.is(TargetModItems.MONITOR.get()) && stack.getOrCreateTag().getBoolean("Using") && stack.getOrCreateTag().getBoolean("Linked")) {
|
||||
DroneEntity drone = player.level().getEntitiesOfClass(DroneEntity.class, player.getBoundingBox().inflate(512))
|
||||
.stream().filter(e -> e.getStringUUID().equals(stack.getOrCreateTag().getString("LinkedDrone"))).findFirst().orElse(null);
|
||||
if (drone != null) {
|
||||
if (type == 0) {
|
||||
drone.getPersistentData().putBoolean("firing",true);
|
||||
if (message.type == 0) {
|
||||
drone.getPersistentData().putBoolean("firing", true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
context.setPacketHandled(true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@ import net.minecraft.core.BlockPos;
|
|||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
import net.minecraftforge.items.ItemHandlerHelper;
|
||||
import net.minecraftforge.network.NetworkEvent;
|
||||
|
||||
|
@ -53,7 +52,7 @@ public class GunRecycleGuiButtonMessage {
|
|||
|
||||
public static void handleButtonAction(Player player, int buttonID, int x, int y, int z) {
|
||||
// security measure to prevent arbitrary chunk generation
|
||||
if (!player.level().hasChunkAt(new BlockPos(x, y, z))) return;
|
||||
if (!player.level().isLoaded(new BlockPos(x, y, z))) return;
|
||||
|
||||
if (buttonID == 0) {
|
||||
dismantleGun(player);
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package net.mcreator.target.network.message;
|
||||
|
||||
import net.mcreator.target.TargetMod;
|
||||
import net.mcreator.target.init.TargetModTags;
|
||||
import net.mcreator.target.tools.TraceTool;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
|
@ -11,10 +11,7 @@ import net.minecraft.world.entity.player.Player;
|
|||
import net.minecraft.world.level.ClipContext;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
import net.minecraft.world.phys.EntityHitResult;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import net.minecraft.core.Direction;
|
||||
|
||||
import net.minecraftforge.network.NetworkEvent;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
@ -50,21 +47,18 @@ public class InteractMessage {
|
|||
if (!level.isLoaded(player.blockPosition()))
|
||||
return;
|
||||
if (type == 0) {
|
||||
|
||||
if (player.getMainHandItem().is(TargetModTags.Items.GUN)) {
|
||||
|
||||
double block_range = player.getBlockReach();
|
||||
double entity_range = player.getBlockReach();
|
||||
|
||||
Vec3 looking = Vec3.atLowerCornerOf(player.level().clip(new ClipContext(player.getEyePosition(), player.getEyePosition().add(player.getLookAngle().scale(block_range)), ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, player)).getBlockPos());
|
||||
BlockPos _bp = BlockPos.containing(looking.x(), looking.y(), looking.z());
|
||||
player.level().getBlockState(_bp).use(player.level(), player, InteractionHand.MAIN_HAND, BlockHitResult.miss(new Vec3(_bp.getX(), _bp.getY(), _bp.getZ()), Direction.UP, _bp));
|
||||
BlockPos blockPos = BlockPos.containing(looking.x(), looking.y(), looking.z());
|
||||
player.level().getBlockState(blockPos).use(player.level(), player, InteractionHand.MAIN_HAND, BlockHitResult.miss(new Vec3(blockPos.getX(), blockPos.getY(), blockPos.getZ()), Direction.UP, blockPos));
|
||||
|
||||
|
||||
Entity ent_looking = TraceTool.findLookingEntity(player, entity_range);
|
||||
if (ent_looking == null)
|
||||
Entity lookingEntity = TraceTool.findLookingEntity(player, entity_range);
|
||||
if (lookingEntity == null)
|
||||
return;
|
||||
player.interactOn(ent_looking,InteractionHand.MAIN_HAND);
|
||||
player.interactOn(lookingEntity, InteractionHand.MAIN_HAND);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ public class ZoomMessage {
|
|||
public static void pressAction(Player entity, int type) {
|
||||
Level world = entity.level();
|
||||
|
||||
if (!world.hasChunkAt(entity.blockPosition())) {
|
||||
if (!world.isLoaded(entity.blockPosition())) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
],
|
||||
"client": [
|
||||
"ItemInHandLayerMixin",
|
||||
"MixinCamera",
|
||||
"CameraMixin",
|
||||
"KeyMappingMixin",
|
||||
"GameRendererMixin",
|
||||
|
|
Loading…
Add table
Reference in a new issue