移除player tick procedure
This commit is contained in:
parent
d387264771
commit
bebf0bc3fd
2 changed files with 35 additions and 59 deletions
|
@ -2,8 +2,11 @@ package net.mcreator.target.event;
|
||||||
|
|
||||||
import net.mcreator.target.init.TargetModTags;
|
import net.mcreator.target.init.TargetModTags;
|
||||||
import net.mcreator.target.network.TargetModVariables;
|
import net.mcreator.target.network.TargetModVariables;
|
||||||
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
import net.minecraft.world.level.Level;
|
||||||
|
import net.minecraftforge.event.TickEvent;
|
||||||
import net.minecraftforge.event.entity.player.PlayerEvent;
|
import net.minecraftforge.event.entity.player.PlayerEvent;
|
||||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||||
import net.minecraftforge.fml.common.Mod;
|
import net.minecraftforge.fml.common.Mod;
|
||||||
|
@ -30,4 +33,36 @@ public class PlayerEventHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public static void onPlayerTick(TickEvent.PlayerTickEvent event) {
|
||||||
|
Player player = event.player;
|
||||||
|
|
||||||
|
if (player == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event.phase == TickEvent.Phase.END) {
|
||||||
|
Level level = player.level();
|
||||||
|
|
||||||
|
if (player.getBbHeight() <= 1) {
|
||||||
|
player.getPersistentData().putDouble("prone", 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (player.isShiftKeyDown() && level.getBlockState(BlockPos.containing(player.getX() + 0.7 * player.getLookAngle().x, player.getY() + 0.5, player.getZ() + 0.7 * player.getLookAngle().z)).canOcclude()
|
||||||
|
&& !level.getBlockState(BlockPos.containing(player.getX() + 0.7 * player.getLookAngle().x, player.getY() + 1.5, player.getZ() + 0.7 * player.getLookAngle().z)).canOcclude()) {
|
||||||
|
player.getPersistentData().putDouble("prone", 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (player.getPersistentData().getDouble("prone") > 0) {
|
||||||
|
player.getPersistentData().putDouble("prone", (player.getPersistentData().getDouble("prone") - 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean flag = !(player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).refresh;
|
||||||
|
|
||||||
|
player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
||||||
|
capability.refresh = flag;
|
||||||
|
capability.syncPlayerVariables(player);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,59 +0,0 @@
|
||||||
package net.mcreator.target.procedures;
|
|
||||||
|
|
||||||
import net.mcreator.target.network.TargetModVariables;
|
|
||||||
import net.minecraft.core.BlockPos;
|
|
||||||
import net.minecraft.world.entity.Entity;
|
|
||||||
import net.minecraft.world.entity.player.Player;
|
|
||||||
import net.minecraft.world.level.LevelAccessor;
|
|
||||||
import net.minecraftforge.event.TickEvent;
|
|
||||||
import net.minecraftforge.eventbus.api.Event;
|
|
||||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
|
||||||
import net.minecraftforge.fml.common.Mod;
|
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
|
|
||||||
@Mod.EventBusSubscriber
|
|
||||||
public class PlayertickProcedure {
|
|
||||||
@SubscribeEvent
|
|
||||||
public static void onPlayerTick(TickEvent.PlayerTickEvent event) {
|
|
||||||
if (event.phase == TickEvent.Phase.END) {
|
|
||||||
execute(event, event.player.level(), event.player);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void execute(LevelAccessor world, Entity entity) {
|
|
||||||
execute(null, world, entity);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void execute(@Nullable Event event, LevelAccessor world, Entity entity) {
|
|
||||||
if (entity == null)
|
|
||||||
return;
|
|
||||||
if (entity instanceof Player && entity.getBbHeight() <= 1) {
|
|
||||||
entity.getPersistentData().putDouble("prone", 3);
|
|
||||||
}
|
|
||||||
if (entity.isShiftKeyDown() && world.getBlockState(BlockPos.containing(entity.getX() + 0.7 * entity.getLookAngle().x, entity.getY() + 0.5, entity.getZ() + 0.7 * entity.getLookAngle().z)).canOcclude()
|
|
||||||
&& !world.getBlockState(BlockPos.containing(entity.getX() + 0.7 * entity.getLookAngle().x, entity.getY() + 1.5, entity.getZ() + 0.7 * entity.getLookAngle().z)).canOcclude()) {
|
|
||||||
entity.getPersistentData().putDouble("prone", 3);
|
|
||||||
}
|
|
||||||
if (entity.getPersistentData().getDouble("prone") > 0) {
|
|
||||||
entity.getPersistentData().putDouble("prone", (entity.getPersistentData().getDouble("prone") - 1));
|
|
||||||
}
|
|
||||||
if (!(entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).refresh) {
|
|
||||||
{
|
|
||||||
boolean _setval = true;
|
|
||||||
entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
|
||||||
capability.refresh = _setval;
|
|
||||||
capability.syncPlayerVariables(entity);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
{
|
|
||||||
boolean _setval = false;
|
|
||||||
entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
|
||||||
capability.refresh = _setval;
|
|
||||||
capability.syncPlayerVariables(entity);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Add table
Reference in a new issue