更改前置版本,修复光剑附魔
This commit is contained in:
parent
27cecb76cb
commit
23df8f7a2f
7 changed files with 21 additions and 89 deletions
|
@ -34,7 +34,7 @@ repositories {
|
|||
}
|
||||
|
||||
dependencies {
|
||||
implementation fg.deobf('software.bernie.geckolib:geckolib-forge-1.20.1:4.4.4')
|
||||
implementation fg.deobf('software.bernie.geckolib:geckolib-forge-1.20.1:4.4.6')
|
||||
}
|
||||
|
||||
minecraft {
|
||||
|
|
|
@ -47,7 +47,7 @@ public class ClientEventHandler {
|
|||
public static void computeCameraAngles(ViewportEvent.ComputeCameraAngles event) {
|
||||
ClientLevel level = Minecraft.getInstance().level;
|
||||
Entity entity = event.getCamera().getEntity();
|
||||
if (level != null && entity instanceof LivingEntity living) {
|
||||
if (level != null && entity instanceof LivingEntity living && living.getMainHandItem().is(TargetModTags.Items.GUN)) {
|
||||
handleWeaponCrossHair(living);
|
||||
handleWeaponSway(living);
|
||||
handleWeaponMove(living);
|
||||
|
@ -374,24 +374,24 @@ public class ClientEventHandler {
|
|||
|
||||
@SubscribeEvent
|
||||
public static void onFovUpdate(ViewportEvent.ComputeFov event) {
|
||||
if (!event.usedConfiguredFov()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = Minecraft.getInstance().player;
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
|
||||
if (player == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (stack.is(TargetModTags.Items.GUN)) {
|
||||
if (!event.usedConfiguredFov()) {
|
||||
return;
|
||||
}
|
||||
|
||||
double p = player.getPersistentData().getDouble("zoom_pos");
|
||||
|
||||
double zoom = stack.getOrCreateTag().getDouble("zoom") + stack.getOrCreateTag().getDouble("custom_zoom");
|
||||
|
||||
if (stack.is(TargetModTags.Items.GUN)) {
|
||||
event.setFOV(event.getFOV() / (1.0 + p * (zoom - 1)));
|
||||
player.getPersistentData().putDouble("fov", event.getFOV());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -29,12 +29,13 @@ public class GunEventHandler {
|
|||
@SubscribeEvent
|
||||
public static void onPlayerTick(TickEvent.PlayerTickEvent event) {
|
||||
Player player = event.player;
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
|
||||
if (player == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.phase == TickEvent.Phase.END) {
|
||||
if (event.phase == TickEvent.Phase.END && stack.is(TargetModTags.Items.GUN)) {
|
||||
handleGunFire(player);
|
||||
handleMiniGunFire(player);
|
||||
}
|
||||
|
|
|
@ -48,12 +48,13 @@ public class PlayerEventHandler {
|
|||
@SubscribeEvent
|
||||
public static void onPlayerTick(TickEvent.PlayerTickEvent event) {
|
||||
Player player = event.player;
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
|
||||
if (player == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.phase == TickEvent.Phase.END) {
|
||||
if (event.phase == TickEvent.Phase.END && stack.is(TargetModTags.Items.GUN)) {
|
||||
handlePlayerProne(player);
|
||||
handlePlayerSprint(player);
|
||||
handleWeaponLevel(player);
|
||||
|
|
|
@ -1,22 +0,0 @@
|
|||
package net.mcreator.target.init;
|
||||
|
||||
import net.mcreator.target.entity.AnimatedEntity;
|
||||
import net.minecraftforge.event.entity.living.LivingEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
|
||||
@Mod.EventBusSubscriber
|
||||
public class EntityAnimationFactory {
|
||||
@SubscribeEvent
|
||||
public static void onEntityTick(LivingEvent.LivingTickEvent event) {
|
||||
if (event == null || event.getEntity() == null) return;
|
||||
|
||||
if (event.getEntity() instanceof AnimatedEntity entity) {
|
||||
String animation = entity.getSyncedAnimation();
|
||||
if (!animation.equals("undefined")) {
|
||||
entity.setAnimation("undefined");
|
||||
entity.setAnimationProcedure(animation);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,53 +0,0 @@
|
|||
package net.mcreator.target.init;
|
||||
|
||||
import net.mcreator.target.item.AnimatedItem;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.ItemInHandRenderer;
|
||||
import net.minecraft.world.item.ArmorItem;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraftforge.event.TickEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import software.bernie.geckolib.animatable.GeoItem;
|
||||
|
||||
@Mod.EventBusSubscriber
|
||||
public class ItemAnimationFactory {
|
||||
public static void disableUseAnim() {
|
||||
try {
|
||||
ItemInHandRenderer renderer = Minecraft.getInstance().gameRenderer.itemInHandRenderer;
|
||||
renderer.mainHandHeight = 1F;
|
||||
renderer.oMainHandHeight = 1F;
|
||||
renderer.offHandHeight = 1F;
|
||||
renderer.oOffHandHeight = 1F;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static void setAnimationState(ItemStack itemStack, boolean isClientSide) {
|
||||
if (!itemStack.getOrCreateTag().getString("gecko_animation").isEmpty() && !(itemStack.getItem() instanceof ArmorItem)) {
|
||||
String animation = itemStack.getOrCreateTag().getString("gecko_animation");
|
||||
itemStack.getOrCreateTag().putString("gecko_animation", "");
|
||||
|
||||
if (itemStack.getItem() instanceof AnimatedItem animatable && isClientSide) {
|
||||
animatable.setAnimationProcedure(animation);
|
||||
disableUseAnim();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void animatedItems(TickEvent.PlayerTickEvent event) {
|
||||
ItemStack mainHandItemStack = event.player.getMainHandItem();
|
||||
Item mainHandItem = mainHandItemStack.getItem();
|
||||
ItemStack offhandItemStack = event.player.getOffhandItem();
|
||||
Item offhandItem = offhandItemStack.getItem();
|
||||
|
||||
if (event.phase == TickEvent.Phase.START && (mainHandItem instanceof GeoItem || offhandItem instanceof GeoItem)) {
|
||||
boolean isClientSide = event.player.level().isClientSide();
|
||||
setAnimationState(mainHandItemStack, isClientSide);
|
||||
setAnimationState(offhandItemStack, isClientSide);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -109,6 +109,11 @@ public class LightSaber extends SwordItem implements GeoItem, AnimatedItem {
|
|||
return 22;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnchantable(ItemStack stack) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canApplyAtEnchantingTable(ItemStack stack, Enchantment enchantment) {
|
||||
return enchantment.category == EnchantmentCategory.BREAKABLE || enchantment.category == EnchantmentCategory.WEAPON;
|
||||
|
|
Loading…
Add table
Reference in a new issue