优化Tag判断
This commit is contained in:
parent
c08a164e11
commit
5531191121
9 changed files with 50 additions and 71 deletions
|
@ -1,8 +1,7 @@
|
|||
package net.mcreator.target.client;
|
||||
|
||||
import net.mcreator.target.init.TargetModTags;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.tags.ItemTags;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.client.event.RenderGuiOverlayEvent;
|
||||
import net.minecraftforge.client.gui.overlay.VanillaGuiOverlay;
|
||||
|
@ -13,20 +12,13 @@ import net.minecraftforge.fml.common.Mod;
|
|||
public class CrossHairHandler {
|
||||
@SubscribeEvent
|
||||
public static void onRenderOverlay(RenderGuiOverlayEvent.Pre event) {
|
||||
if (event.getOverlay() != VanillaGuiOverlay.CROSSHAIR.type()) {
|
||||
return;
|
||||
}
|
||||
if (event.getOverlay() != VanillaGuiOverlay.CROSSHAIR.type()) return;
|
||||
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
if (mc.player == null) {
|
||||
return;
|
||||
}
|
||||
if (mc.player == null) return;
|
||||
if (!mc.options.getCameraType().isFirstPerson()) return;
|
||||
|
||||
if (!mc.options.getCameraType().isFirstPerson()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ((mc.player.getMainHandItem()).is(ItemTags.create(new ResourceLocation("target:gun")))) {
|
||||
if (mc.player.getMainHandItem().is(TargetModTags.Items.GUN)) {
|
||||
event.setCanceled(true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
package net.mcreator.target.client;
|
||||
|
||||
import net.mcreator.target.init.TargetModTags;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.tags.ItemTags;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
|
@ -15,22 +14,19 @@ public class RenderHandler {
|
|||
|
||||
@SubscribeEvent
|
||||
public static void onFovUpdate(ViewportEvent.ComputeFov event) {
|
||||
if (!event.usedConfiguredFov()) {
|
||||
return;
|
||||
}
|
||||
if (!event.usedConfiguredFov()) return;
|
||||
|
||||
Player player = Minecraft.getInstance().player;
|
||||
if (player == null) return;
|
||||
|
||||
if (player != null) {
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
|
||||
double p = player.getPersistentData().getDouble("zoompos");
|
||||
double zoom = stack.getOrCreateTag().getDouble("zoom");
|
||||
double p = player.getPersistentData().getDouble("zoompos");
|
||||
double zoom = stack.getOrCreateTag().getDouble("zoom");
|
||||
|
||||
if (stack.is(ItemTags.create(new ResourceLocation("target:gun")))) {
|
||||
event.setFOV(event.getFOV() / (1.0 + p * (zoom - 1)));
|
||||
player.getPersistentData().putDouble("fov", event.getFOV());
|
||||
}
|
||||
if (stack.is(TargetModTags.Items.GUN)) {
|
||||
event.setFOV(event.getFOV() / (1.0 + p * (zoom - 1)));
|
||||
player.getPersistentData().putDouble("fov", event.getFOV());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,13 +5,13 @@ import com.mojang.blaze3d.systems.RenderSystem;
|
|||
import com.mojang.blaze3d.vertex.*;
|
||||
import net.mcreator.target.init.TargetModAttributes;
|
||||
import net.mcreator.target.init.TargetModItems;
|
||||
import net.mcreator.target.init.TargetModTags;
|
||||
import net.mcreator.target.network.TargetModVariables;
|
||||
import net.minecraft.client.CameraType;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.client.renderer.GameRenderer;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.tags.ItemTags;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.client.event.RenderGuiEvent;
|
||||
|
@ -27,14 +27,15 @@ public class CrosshairOverlay {
|
|||
int w = event.getWindow().getGuiScaledWidth();
|
||||
int h = event.getWindow().getGuiScaledHeight();
|
||||
Player entity = Minecraft.getInstance().player;
|
||||
if (entity == null) return;
|
||||
|
||||
double spread = entity.getAttribute(TargetModAttributes.SPREAD.get()).getBaseValue();
|
||||
|
||||
double hitind = (entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).hitIndicator;
|
||||
double hitIndicator = (entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).hitIndicator;
|
||||
|
||||
double headind = (entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).headIndicator;
|
||||
double headIndicator = (entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).headIndicator;
|
||||
|
||||
double killind = (entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).killIndicator;
|
||||
double killIndicator = (entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).killIndicator;
|
||||
|
||||
RenderSystem.disableDepthTest();
|
||||
RenderSystem.depthMask(false);
|
||||
|
@ -43,37 +44,37 @@ public class CrosshairOverlay {
|
|||
RenderSystem.blendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
|
||||
RenderSystem.setShaderColor(1, 1, 1, 1);
|
||||
if (shouldRenderCrosshair(entity)) {
|
||||
preciseBlit(event.getGuiGraphics(), new ResourceLocation("target:textures/screens/point.png"), w / 2 + -7.5f, h / 2 + -8, 0, 0, 16, 16, 16, 16);
|
||||
preciseBlit(event.getGuiGraphics(), new ResourceLocation("target:textures/screens/point.png"), w / 2f - 7.5f, h / 2f - 8, 0, 0, 16, 16, 16, 16);
|
||||
|
||||
preciseBlit(event.getGuiGraphics(), new ResourceLocation("target:textures/screens/rexheng.png"), w / 2 + -9.5f - 2.8f * (float) spread, h / 2 + -8, 0, 0, 16, 16, 16, 16);
|
||||
preciseBlit(event.getGuiGraphics(), new ResourceLocation("target:textures/screens/rexheng.png"), w / 2f - 9.5f - 2.8f * (float) spread, h / 2f - 8, 0, 0, 16, 16, 16, 16);
|
||||
|
||||
preciseBlit(event.getGuiGraphics(), new ResourceLocation("target:textures/screens/rexheng.png"), w / 2 + -6.5f + 2.8f * (float) spread, h / 2 + -8, 0, 0, 16, 16, 16, 16);
|
||||
preciseBlit(event.getGuiGraphics(), new ResourceLocation("target:textures/screens/rexheng.png"), w / 2f - 6.5f + 2.8f * (float) spread, h / 2f - 8, 0, 0, 16, 16, 16, 16);
|
||||
|
||||
preciseBlit(event.getGuiGraphics(), new ResourceLocation("target:textures/screens/rexshu.png"), w / 2 + -7.5f, h / 2 + -7 + 2.8f * (float) spread, 0, 0, 16, 16, 16, 16);
|
||||
preciseBlit(event.getGuiGraphics(), new ResourceLocation("target:textures/screens/rexshu.png"), w / 2f - 7.5f, h / 2f - 7 + 2.8f * (float) spread, 0, 0, 16, 16, 16, 16);
|
||||
|
||||
preciseBlit(event.getGuiGraphics(), new ResourceLocation("target:textures/screens/rexshu.png"), w / 2 + -7.5f, h / 2 + -10 - 2.8f * (float) spread, 0, 0, 16, 16, 16, 16);
|
||||
preciseBlit(event.getGuiGraphics(), new ResourceLocation("target:textures/screens/rexshu.png"), w / 2f - 7.5f, h / 2f - 10 - 2.8f * (float) spread, 0, 0, 16, 16, 16, 16);
|
||||
}
|
||||
|
||||
float ww = w / 2 - 7.5f + (float) (2 * (Math.random() - 0.5f));
|
||||
float hh = h / 2 - 8 + (float) (2 * (Math.random() - 0.5f));
|
||||
float m = (float) ((40 - killind) / 5.5f);
|
||||
float ww = w / 2f - 7.5f + (float) (2 * (Math.random() - 0.5f));
|
||||
float hh = h / 2f - 8 + (float) (2 * (Math.random() - 0.5f));
|
||||
float m = (float) ((40 - killIndicator) / 5.5f);
|
||||
|
||||
if (hitind > 0) {
|
||||
if (hitIndicator > 0) {
|
||||
preciseBlit(event.getGuiGraphics(), new ResourceLocation("target:textures/screens/hit_marker.png"), ww, hh, 0, 0, 16, 16, 16, 16);
|
||||
}
|
||||
|
||||
if (headind > 0) {
|
||||
if (headIndicator > 0) {
|
||||
preciseBlit(event.getGuiGraphics(), new ResourceLocation("target:textures/screens/headshotmark.png"), ww, hh, 0, 0, 16, 16, 16, 16);
|
||||
}
|
||||
|
||||
if (killind > 0) {
|
||||
preciseBlit(event.getGuiGraphics(), new ResourceLocation("target:textures/screens/kill_mark1.png"), w / 2 + -7.5f - 2 + m, h / 2 + -8 - 2 + m, 0, 0, 16, 16, 16, 16);
|
||||
if (killIndicator > 0) {
|
||||
preciseBlit(event.getGuiGraphics(), new ResourceLocation("target:textures/screens/kill_mark1.png"), w / 2f - 7.5f - 2 + m, h / 2f - 8 - 2 + m, 0, 0, 16, 16, 16, 16);
|
||||
|
||||
preciseBlit(event.getGuiGraphics(), new ResourceLocation("target:textures/screens/kill_mark2.png"), w / 2 + -7.5f + 2 - m, h / 2 + -8 - 2 + m, 0, 0, 16, 16, 16, 16);
|
||||
preciseBlit(event.getGuiGraphics(), new ResourceLocation("target:textures/screens/kill_mark2.png"), w / 2f - 7.5f + 2 - m, h / 2f - 8 - 2 + m, 0, 0, 16, 16, 16, 16);
|
||||
|
||||
preciseBlit(event.getGuiGraphics(), new ResourceLocation("target:textures/screens/kill_mark3.png"), w / 2 + -7.5f - 2 + m, h / 2 + -8 + 2 - m, 0, 0, 16, 16, 16, 16);
|
||||
preciseBlit(event.getGuiGraphics(), new ResourceLocation("target:textures/screens/kill_mark3.png"), w / 2f - 7.5f - 2 + m, h / 2f - 8 + 2 - m, 0, 0, 16, 16, 16, 16);
|
||||
|
||||
preciseBlit(event.getGuiGraphics(), new ResourceLocation("target:textures/screens/kill_mark4.png"), w / 2 + -7.5f + 2 - m, h / 2 + -8 + 2 - m, 0, 0, 16, 16, 16, 16);
|
||||
preciseBlit(event.getGuiGraphics(), new ResourceLocation("target:textures/screens/kill_mark4.png"), w / 2f - 7.5f + 2 - m, h / 2f - 8 + 2 - m, 0, 0, 16, 16, 16, 16);
|
||||
}
|
||||
|
||||
RenderSystem.depthMask(true);
|
||||
|
@ -109,9 +110,8 @@ public class CrosshairOverlay {
|
|||
if (player == null) return false;
|
||||
|
||||
if (player.isSpectator()) return false;
|
||||
if (!player.getMainHandItem().is(ItemTags.create(new ResourceLocation("target:gun")))
|
||||
|| !(player.getPersistentData().getDouble("zoom_time") < 7)
|
||||
) return false;
|
||||
if (!player.getMainHandItem().is(TargetModTags.Items.GUN) || !(player.getPersistentData().getDouble("zoom_time") < 7))
|
||||
return false;
|
||||
|
||||
return !(player.getMainHandItem().getItem() == TargetModItems.M_79.get())
|
||||
&& Minecraft.getInstance().options.getCameraType() == CameraType.FIRST_PERSON;
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
package net.mcreator.target.event;
|
||||
|
||||
import net.mcreator.target.init.TargetModTags;
|
||||
import net.mcreator.target.network.TargetModVariables;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.tags.ItemTags;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraftforge.event.TickEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
|
@ -16,7 +15,7 @@ public class AimingHandler {
|
|||
if (event.phase == TickEvent.Phase.END && event.player != null) {
|
||||
ItemStack itemstack = event.player.getMainHandItem();
|
||||
|
||||
if (itemstack.is(ItemTags.create(new ResourceLocation("target:gun")))) {
|
||||
if (itemstack.is(TargetModTags.Items.GUN)) {
|
||||
itemstack.getOrCreateTag().putBoolean("aiming", event.player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables()).zooming);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,10 +9,8 @@ import net.minecraft.commands.CommandSourceStack;
|
|||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.tags.ItemTags;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
|
@ -203,7 +201,7 @@ public class PlayerEventHandler {
|
|||
+ new java.text.DecimalFormat("##").format((player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).rifleAmmo) + " " + firemode;
|
||||
}
|
||||
if (stack.is(TargetModTags.Items.HANDGUN)
|
||||
|| stack.is(ItemTags.create(new ResourceLocation("target:smg")))) {
|
||||
|| stack.is(TargetModTags.Items.SMG)) {
|
||||
stack.getOrCreateTag().putDouble("maxammo",
|
||||
((player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).handgunAmmo));
|
||||
return (new java.text.DecimalFormat("##").format(stack.getOrCreateTag().getDouble("ammo"))) + "/"
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
package net.mcreator.target.mixins;
|
||||
|
||||
import net.mcreator.target.init.TargetModTags;
|
||||
import net.minecraft.client.CameraType;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.MouseHandler;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.tags.ItemTags;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
@ -19,23 +18,22 @@ public class MouseHandlerMixin {
|
|||
private double sensitivity(double original) {
|
||||
float additionalAdsSensitivity = 1.0F;
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
boolean flag = false;
|
||||
int flag = 0;
|
||||
float sens = 0.13f;
|
||||
float fov = 0;
|
||||
|
||||
if (mc.player != null && !mc.player.getMainHandItem().isEmpty() && mc.options.getCameraType() == CameraType.FIRST_PERSON) {
|
||||
|
||||
Player player = Minecraft.getInstance().player;
|
||||
ItemStack stack = mc.player.getMainHandItem();
|
||||
|
||||
fov = ((float) player.getPersistentData().getDouble("fov"));
|
||||
float fov = ((float) player.getPersistentData().getDouble("fov"));
|
||||
|
||||
if (stack.is(ItemTags.create(new ResourceLocation("target:gun")))) {
|
||||
if (stack.is(TargetModTags.Items.GUN)) {
|
||||
float modifier = 1.5f * fov / 90;
|
||||
additionalAdsSensitivity = Mth.clamp(1.0F - (1.0F / modifier) / 10F, 0.0F, 1.0F);
|
||||
flag = true;
|
||||
flag = 1;
|
||||
}
|
||||
}
|
||||
return original * additionalAdsSensitivity * (1.0 - sens * (flag ? 1 : 0));
|
||||
return original * additionalAdsSensitivity * (1.0 - sens * flag);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,8 +6,6 @@ import net.mcreator.target.init.TargetModTags;
|
|||
import net.mcreator.target.world.inventory.GunRecycleGuiMenu;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.tags.ItemTags;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
|
@ -72,7 +70,7 @@ public class GunRecycleGuiButtonMessage {
|
|||
var slot0 = menu.get(0);
|
||||
var gun = slot0.getItem();
|
||||
|
||||
if (gun.is(ItemTags.create(new ResourceLocation("target:gun")))) {
|
||||
if (gun.is(TargetModTags.Items.GUN)) {
|
||||
// 普通稀有度
|
||||
var material = switch (gun.getRarity()) {
|
||||
case COMMON -> Items.IRON_INGOT;
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
package net.mcreator.target.procedures;
|
||||
|
||||
import net.mcreator.target.init.TargetModItems;
|
||||
import net.mcreator.target.init.TargetModTags;
|
||||
import net.mcreator.target.network.TargetModVariables;
|
||||
import net.minecraft.commands.CommandSource;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.tags.ItemTags;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
|
||||
public class PressFireProcedure {
|
||||
|
@ -26,7 +25,7 @@ public class PressFireProcedure {
|
|||
var mainHandItem = player.getMainHandItem();
|
||||
var tag = mainHandItem.getOrCreateTag();
|
||||
|
||||
if (mainHandItem.is(ItemTags.create(new ResourceLocation("target:gun")))
|
||||
if (mainHandItem.is(TargetModTags.Items.GUN)
|
||||
&& !(mainHandItem.getItem() == TargetModItems.BOCEK.get())
|
||||
&& !(mainHandItem.getItem() == TargetModItems.MINIGUN.get())
|
||||
&& tag.getDouble("ammo") == 0
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
package net.mcreator.target.world.inventory;
|
||||
|
||||
import net.mcreator.target.init.TargetModMenus;
|
||||
import net.mcreator.target.init.TargetModTags;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.tags.ItemTags;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
|
@ -80,7 +79,7 @@ public class GunRecycleGuiMenu extends AbstractContainerMenu implements Supplier
|
|||
|
||||
@Override
|
||||
public boolean mayPlace(ItemStack stack) {
|
||||
return stack.is(ItemTags.create(new ResourceLocation("target:gun")));
|
||||
return stack.is(TargetModTags.Items.GUN);
|
||||
}
|
||||
}));
|
||||
for (int si = 0; si < 3; ++si)
|
||||
|
|
Loading…
Add table
Reference in a new issue