Skip to content

Commit

Permalink
So much to fix up
Browse files Browse the repository at this point in the history
  • Loading branch information
jamioflan committed Aug 19, 2024
1 parent bf279e7 commit 7df0180
Show file tree
Hide file tree
Showing 40 changed files with 451 additions and 564 deletions.
76 changes: 37 additions & 39 deletions src/main/java/com/flansmod/client/ClientActionManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@
import net.minecraft.client.Minecraft;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.TickEvent;
import net.minecraftforge.eventbus.api.IEventBus;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.api.distmarker.OnlyIn;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.neoforge.client.event.ClientTickEvent;
import net.neoforged.neoforge.common.NeoForge;
import net.neoforged.neoforge.event.tick.LevelTickEvent;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -35,7 +36,7 @@ public ClientActionManager()

public void HookClient(IEventBus modEventBus)
{
MinecraftForge.EVENT_BUS.addListener(this::ClientTick);
NeoForge.EVENT_BUS.addListener(this::ClientTick);
}

@OnlyIn(Dist.CLIENT)
Expand Down Expand Up @@ -181,48 +182,45 @@ private void OnClientVerifyShots()

}

public void ClientTick(TickEvent.ClientTickEvent tickEvent)
public void ClientTick(ClientTickEvent.Pre tickEvent)
{
if(tickEvent.phase == TickEvent.Phase.START)
List<UUID> invalidIDs = new ArrayList<>();
for(var kvp : ActionStacks.entrySet())
{
List<UUID> invalidIDs = new ArrayList<>();
for(var kvp : ActionStacks.entrySet())
UUID gunID = kvp.getKey();
ActionStack actionStack = kvp.getValue();
GunContext gunContext = GunContext.of(gunID);
if(gunContext.IsValid())
{
UUID gunID = kvp.getKey();
ActionStack actionStack = kvp.getValue();
GunContext gunContext = GunContext.of(gunID);
if(gunContext.IsValid())
{
if (actionStack.IsValid())
actionStack.OnTick(Minecraft.getInstance().level, gunContext);
}
else
{
actionStack.Clear(gunContext);
invalidIDs.add(gunID);
}
if (actionStack.IsValid())
actionStack.OnTick(Minecraft.getInstance().level, gunContext);
}
else
{
actionStack.Clear(gunContext);
invalidIDs.add(gunID);
}
}

for(UUID invalidID : invalidIDs)
ActionStacks.remove(invalidID);
for(UUID invalidID : invalidIDs)
ActionStacks.remove(invalidID);

Player player = Minecraft.getInstance().player;
if(player != null)
Player player = Minecraft.getInstance().player;
if(player != null)
{
ShooterContext shooterContext = ShooterContext.of(player);
for (int i = 0; i < player.getInventory().getContainerSize(); i++)
{
ShooterContext shooterContext = ShooterContext.of(player);
for (int i = 0; i < player.getInventory().getContainerSize(); i++)
if (player.getInventory().getItem(i).getItem() instanceof GunItem)
{
if (player.getInventory().getItem(i).getItem() instanceof GunItem)
UUID gunID = FlanItem.GetGunID(player.getInventory().getItem(i));
if(gunID != FlanItem.InvalidGunUUID)
{
UUID gunID = FlanItem.GetGunID(player.getInventory().getItem(i));
if(gunID != FlanItem.InvalidGunUUID)
{
GunContext gunContext = GunContext.of(shooterContext, gunID);
ActionStack actionStack = GetActionStack(gunID);
boolean equipped = (i == player.getInventory().selected)
|| (i == Inventory.SLOT_OFFHAND);
actionStack.UpdateEquipped(gunContext, equipped);
}
GunContext gunContext = GunContext.of(shooterContext, gunID);
ActionStack actionStack = GetActionStack(gunID);
boolean equipped = (i == player.getInventory().selected)
|| (i == Inventory.SLOT_OFFHAND);
actionStack.UpdateEquipped(gunContext, equipped);
}
}
}
Expand Down
6 changes: 0 additions & 6 deletions src/main/java/com/flansmod/client/ClientInventoryManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,9 @@

import com.flansmod.common.crafting.temporary.TemporaryWorkbench;
import net.minecraft.client.Minecraft;
import net.minecraft.core.BlockPos;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.player.Player;
import net.minecraftforge.network.NetworkHooks;

import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.List;

public class ClientInventoryManager
{
Expand Down
38 changes: 18 additions & 20 deletions src/main/java/com/flansmod/client/FlansModClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,29 +35,27 @@
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.item.ItemDisplayContext;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.client.event.ModelEvent;
import net.minecraftforge.client.event.RegisterClientReloadListenersEvent;
import net.minecraftforge.client.event.RegisterShadersEvent;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.TickEvent;
import net.minecraftforge.event.level.LevelEvent;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.fml.util.ObfuscationReflectionHelper;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.api.distmarker.OnlyIn;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.common.EventBusSubscriber;
import net.neoforged.fml.common.Mod;
import net.neoforged.fml.event.lifecycle.FMLClientSetupEvent;
import net.neoforged.fml.loading.FMLLoader;
import net.neoforged.fml.util.ObfuscationReflectionHelper;
import net.neoforged.neoforge.client.event.*;
import net.neoforged.neoforge.common.NeoForge;
import net.neoforged.neoforge.common.NeoForgeMod;
import net.neoforged.neoforge.event.level.LevelEvent;

import javax.annotation.Nullable;
import java.lang.reflect.Field;
import java.lang.reflect.Method;

@OnlyIn(Dist.CLIENT)
@Mod.EventBusSubscriber(value = Dist.CLIENT, bus = Mod.EventBusSubscriber.Bus.MOD, modid = FlansMod.MODID)
@EventBusSubscriber(value = Dist.CLIENT, bus = EventBusSubscriber.Bus.MOD, modid = FlansMod.MODID)
public class FlansModClient
{
public static final ClientInventoryManager INVENTORY_MANAGER = new ClientInventoryManager();
Expand Down Expand Up @@ -105,7 +103,7 @@ public class FlansModClient
@SubscribeEvent
public static void ClientInit(final FMLClientSetupEvent event)
{
IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();
IEventBus modEventBus = FML.bus;
ACTIONS_CLIENT.HookClient(modEventBus);
MODEL_REGISTRATION.Hook(modEventBus);
modEventBus.register(ANIMATIONS);
Expand All @@ -122,8 +120,8 @@ public static void ClientInit(final FMLClientSetupEvent event)
// Entity Renderers
EntityRenderers.register(FlansMod.ENT_TYPE_BULLET.get(), BulletEntityRenderer::new);

MinecraftForge.EVENT_BUS.addListener(FlansModClient::RenderTick);
MinecraftForge.EVENT_BUS.addListener(FlansModClient::OnLevelLoad);
NeoForge.EVENT_BUS.addListener(FlansModClient::RenderTick);
NeoForge.EVENT_BUS.addListener(FlansModClient::OnLevelLoad);
}

public static void OnLevelLoad(LevelEvent.Load event)
Expand Down Expand Up @@ -190,7 +188,7 @@ public static void ShaderRegistryEvent(RegisterShadersEvent event)
}
}

public static void RenderTick(TickEvent.RenderTickEvent event)
public static void RenderTick(RenderLevelStageEvent event)
{
PREV_FRAME_NS = THIS_FRAME_NS;
THIS_FRAME_NS = Util.getNanos();
Expand Down
56 changes: 26 additions & 30 deletions src/main/java/com/flansmod/client/RecoilManager.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package com.flansmod.client;

import com.flansmod.util.Maths;
import com.flansmod.util.MinecraftHelpers;
import net.minecraft.client.Minecraft;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.phys.Vec2;
import net.minecraftforge.client.event.ViewportEvent;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.TickEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.neoforge.client.event.ClientTickEvent;
import net.neoforged.neoforge.client.event.RenderLevelStageEvent;
import net.neoforged.neoforge.client.event.ViewportEvent;
import net.neoforged.neoforge.common.NeoForge;

import javax.annotation.Nonnull;

Expand All @@ -27,7 +26,7 @@ public class RecoilManager

public RecoilManager()
{
MinecraftForge.EVENT_BUS.register(this);
NeoForge.EVENT_BUS.register(this);
}

public void AddRecoil(float magYaw, float magPitch)
Expand All @@ -43,39 +42,36 @@ public void OnPlayerLookInput(Vec2 delta)
@SubscribeEvent
public void OnCameraEvent(@Nonnull ViewportEvent.ComputeCameraAngles event)
{
event.setYaw(event.getYaw() + GetRecoilYaw(Minecraft.getInstance().getPartialTick()));
event.setPitch(event.getPitch() - GetRecoilPitch(Minecraft.getInstance().getPartialTick()));
event.setYaw(event.getYaw() + GetRecoilYaw(Minecraft.getInstance().getTimer().getGameTimeDeltaTicks()));
event.setPitch(event.getPitch() - GetRecoilPitch(Minecraft.getInstance().getTimer().getGameTimeDeltaTicks()));
}

@SubscribeEvent
public void OnRenderTick(@Nonnull TickEvent.RenderTickEvent event)
public void OnRenderTick(@Nonnull RenderLevelStageEvent event)
{

}

@SubscribeEvent
public void OnClientTick(@Nonnull TickEvent.ClientTickEvent event)
public void OnClientTick(@Nonnull ClientTickEvent.Post event)
{
if(event.phase == TickEvent.Phase.END)
{
RecoilStacksYawLast = RecoilStacksYaw;
RecoilStacksPitchLast = RecoilStacksPitch;
RecoilStacksYawLast = RecoilStacksYaw;
RecoilStacksPitchLast = RecoilStacksPitch;

float dYaw = RecoilPendingYaw * 0.5f;
float dPitch = RecoilPendingPitch * 0.5f;
//Player player = Minecraft.getInstance().player;
//if (player != null)
//{
// player.setXRot(player.getXRot() - dPitch);
// player.setYRot(player.getYRot() - dYaw);
//}
RecoilStacksYaw += dYaw;
RecoilStacksPitch += dPitch;
RecoilStacksYaw *= 0.75f;
RecoilStacksPitch *= 0.75f;
float dYaw = RecoilPendingYaw * 0.5f;
float dPitch = RecoilPendingPitch * 0.5f;
//Player player = Minecraft.getInstance().player;
//if (player != null)
//{
// player.setXRot(player.getXRot() - dPitch);
// player.setYRot(player.getYRot() - dYaw);
//}
RecoilStacksYaw += dYaw;
RecoilStacksPitch += dPitch;
RecoilStacksYaw *= 0.75f;
RecoilStacksPitch *= 0.75f;

RecoilPendingYaw -= dYaw;
RecoilPendingPitch -= dPitch;
}
RecoilPendingYaw -= dYaw;
RecoilPendingPitch -= dPitch;
}
}
Loading

0 comments on commit 7df0180

Please sign in to comment.