移除二段跳和瞄准procedure
This commit is contained in:
parent
4c59702669
commit
311fe83c15
7 changed files with 81 additions and 143 deletions
|
@ -1,6 +1,8 @@
|
||||||
package net.mcreator.target;
|
package net.mcreator.target;
|
||||||
|
|
||||||
import net.mcreator.target.init.*;
|
import net.mcreator.target.init.*;
|
||||||
|
import net.mcreator.target.network.DoubleJumpMessage;
|
||||||
|
import net.mcreator.target.network.ZoomMessage;
|
||||||
import net.minecraft.network.FriendlyByteBuf;
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraftforge.common.MinecraftForge;
|
import net.minecraftforge.common.MinecraftForge;
|
||||||
|
@ -8,6 +10,7 @@ import net.minecraftforge.event.TickEvent;
|
||||||
import net.minecraftforge.eventbus.api.IEventBus;
|
import net.minecraftforge.eventbus.api.IEventBus;
|
||||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||||
import net.minecraftforge.fml.common.Mod;
|
import net.minecraftforge.fml.common.Mod;
|
||||||
|
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
|
||||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||||
import net.minecraftforge.network.NetworkEvent;
|
import net.minecraftforge.network.NetworkEvent;
|
||||||
import net.minecraftforge.network.NetworkRegistry;
|
import net.minecraftforge.network.NetworkRegistry;
|
||||||
|
@ -28,23 +31,21 @@ public class TargetMod {
|
||||||
public static final String ATTRIBUTE_MODIFIER = "target_attribute_modifier";
|
public static final String ATTRIBUTE_MODIFIER = "target_attribute_modifier";
|
||||||
|
|
||||||
public TargetMod() {
|
public TargetMod() {
|
||||||
MinecraftForge.EVENT_BUS.register(this);
|
|
||||||
IEventBus bus = FMLJavaModLoadingContext.get().getModEventBus();
|
IEventBus bus = FMLJavaModLoadingContext.get().getModEventBus();
|
||||||
|
|
||||||
TargetModSounds.REGISTRY.register(bus);
|
TargetModSounds.REGISTRY.register(bus);
|
||||||
TargetModBlocks.REGISTRY.register(bus);
|
TargetModBlocks.REGISTRY.register(bus);
|
||||||
|
|
||||||
TargetModItems.register(bus);
|
TargetModItems.register(bus);
|
||||||
|
|
||||||
TargetModEntities.REGISTRY.register(bus);
|
TargetModEntities.REGISTRY.register(bus);
|
||||||
TargetCustomModEntities.ENTITY_TYPES.register(bus);
|
TargetCustomModEntities.ENTITY_TYPES.register(bus);
|
||||||
|
|
||||||
TargetModTabs.TABS.register(bus);
|
TargetModTabs.TABS.register(bus);
|
||||||
|
|
||||||
TargetModMobEffects.REGISTRY.register(bus);
|
TargetModMobEffects.REGISTRY.register(bus);
|
||||||
|
|
||||||
TargetModParticleTypes.REGISTRY.register(bus);
|
TargetModParticleTypes.REGISTRY.register(bus);
|
||||||
|
|
||||||
TargetModMenus.REGISTRY.register(bus);
|
TargetModMenus.REGISTRY.register(bus);
|
||||||
|
|
||||||
|
bus.addListener(this::onCommonSetup);
|
||||||
|
|
||||||
|
MinecraftForge.EVENT_BUS.register(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final String PROTOCOL_VERSION = "1";
|
private static final String PROTOCOL_VERSION = "1";
|
||||||
|
@ -75,4 +76,10 @@ public class TargetMod {
|
||||||
workQueue.removeAll(actions);
|
workQueue.removeAll(actions);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void onCommonSetup(final FMLCommonSetupEvent event) {
|
||||||
|
addNetworkMessage(ZoomMessage.class, ZoomMessage::buffer, ZoomMessage::new, ZoomMessage::handler);
|
||||||
|
addNetworkMessage(DoubleJumpMessage.class, DoubleJumpMessage::buffer, DoubleJumpMessage::new, DoubleJumpMessage::handler);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,8 +41,10 @@ public class TargetModKeyMappings {
|
||||||
public void setDown(boolean isDown) {
|
public void setDown(boolean isDown) {
|
||||||
super.setDown(isDown);
|
super.setDown(isDown);
|
||||||
if (isDownOld != isDown && isDown) {
|
if (isDownOld != isDown && isDown) {
|
||||||
TargetMod.PACKET_HANDLER.sendToServer(new DoubleJumpMessage(0, 0));
|
TargetMod.PACKET_HANDLER.sendToServer(new DoubleJumpMessage(0));
|
||||||
DoubleJumpMessage.pressAction(Minecraft.getInstance().player, 0, 0);
|
if (Minecraft.getInstance().player != null) {
|
||||||
|
DoubleJumpMessage.pressAction(Minecraft.getInstance().player, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
isDownOld = isDown;
|
isDownOld = isDown;
|
||||||
}
|
}
|
||||||
|
@ -68,12 +70,12 @@ public class TargetModKeyMappings {
|
||||||
super.setDown(isDown);
|
super.setDown(isDown);
|
||||||
if (isDownOld != isDown && isDown) {
|
if (isDownOld != isDown && isDown) {
|
||||||
TargetMod.PACKET_HANDLER.sendToServer(new ZoomMessage(0, 0));
|
TargetMod.PACKET_HANDLER.sendToServer(new ZoomMessage(0, 0));
|
||||||
ZoomMessage.pressAction(Minecraft.getInstance().player, 0, 0);
|
ZoomMessage.pressAction(Minecraft.getInstance().player, 0);
|
||||||
ZOOM_LASTPRESS = System.currentTimeMillis();
|
ZOOM_LASTPRESS = System.currentTimeMillis();
|
||||||
} else if (isDownOld != isDown) {
|
} else if (isDownOld != isDown) {
|
||||||
int dt = (int) (System.currentTimeMillis() - ZOOM_LASTPRESS);
|
int dt = (int) (System.currentTimeMillis() - ZOOM_LASTPRESS);
|
||||||
TargetMod.PACKET_HANDLER.sendToServer(new ZoomMessage(1, dt));
|
TargetMod.PACKET_HANDLER.sendToServer(new ZoomMessage(1, dt));
|
||||||
ZoomMessage.pressAction(Minecraft.getInstance().player, 1, dt);
|
ZoomMessage.pressAction(Minecraft.getInstance().player, 1);
|
||||||
}
|
}
|
||||||
isDownOld = isDown;
|
isDownOld = isDown;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,58 +1,65 @@
|
||||||
package net.mcreator.target.network;
|
package net.mcreator.target.network;
|
||||||
|
|
||||||
import net.mcreator.target.TargetMod;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.mcreator.target.procedures.DoublejumpProcedure;
|
|
||||||
import net.minecraft.network.FriendlyByteBuf;
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import net.minecraft.sounds.SoundSource;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
import net.minecraft.world.phys.Vec3;
|
||||||
import net.minecraftforge.fml.common.Mod;
|
|
||||||
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
|
|
||||||
import net.minecraftforge.network.NetworkEvent;
|
import net.minecraftforge.network.NetworkEvent;
|
||||||
|
import net.minecraftforge.registries.ForgeRegistries;
|
||||||
|
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD)
|
|
||||||
public class DoubleJumpMessage {
|
public class DoubleJumpMessage {
|
||||||
int type, pressedms;
|
private final int type;
|
||||||
|
|
||||||
public DoubleJumpMessage(int type, int pressedms) {
|
public DoubleJumpMessage(int type) {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.pressedms = pressedms;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public DoubleJumpMessage(FriendlyByteBuf buffer) {
|
public DoubleJumpMessage(FriendlyByteBuf buffer) {
|
||||||
this.type = buffer.readInt();
|
this.type = buffer.readInt();
|
||||||
this.pressedms = buffer.readInt();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void buffer(DoubleJumpMessage message, FriendlyByteBuf buffer) {
|
public static void buffer(DoubleJumpMessage message, FriendlyByteBuf buffer) {
|
||||||
buffer.writeInt(message.type);
|
buffer.writeInt(message.type);
|
||||||
buffer.writeInt(message.pressedms);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void handler(DoubleJumpMessage message, Supplier<NetworkEvent.Context> contextSupplier) {
|
public static void handler(DoubleJumpMessage message, Supplier<NetworkEvent.Context> contextSupplier) {
|
||||||
NetworkEvent.Context context = contextSupplier.get();
|
NetworkEvent.Context context = contextSupplier.get();
|
||||||
context.enqueueWork(() -> pressAction(context.getSender(), message.type, message.pressedms));
|
context.enqueueWork(() -> {
|
||||||
|
if (context.getSender() != null) {
|
||||||
|
pressAction(context.getSender(), message.type);
|
||||||
|
}
|
||||||
|
});
|
||||||
context.setPacketHandled(true);
|
context.setPacketHandled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void pressAction(Player entity, int type, int pressedms) {
|
public static void pressAction(Player entity, int type) {
|
||||||
Level world = entity.level();
|
Level level = entity.level();
|
||||||
double x = entity.getX();
|
double x = entity.getX();
|
||||||
double y = entity.getY();
|
double y = entity.getY();
|
||||||
double z = entity.getZ();
|
double z = entity.getZ();
|
||||||
// security measure to prevent arbitrary chunk generation
|
|
||||||
if (!world.hasChunkAt(entity.blockPosition()))
|
|
||||||
return;
|
|
||||||
if (type == 0) {
|
|
||||||
|
|
||||||
DoublejumpProcedure.execute(world, x, y, z, entity);
|
if (!level.hasChunkAt(entity.blockPosition())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type == 0) {
|
||||||
|
if ((entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).playerdoublejump) {
|
||||||
|
entity.setDeltaMovement(new Vec3((1 * entity.getLookAngle().x), 0.8, (1 * entity.getLookAngle().z)));
|
||||||
|
if (!level.isClientSide()) {
|
||||||
|
level.playSound(null, BlockPos.containing(x, y, z), ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation("target:doublejump")), SoundSource.BLOCKS, 1, 1);
|
||||||
|
} else {
|
||||||
|
level.playLocalSound(x, y, z, ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation("target:doublejump")), SoundSource.BLOCKS, 1, 1, false);
|
||||||
|
}
|
||||||
|
entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
||||||
|
capability.playerdoublejump = false;
|
||||||
|
capability.syncPlayerVariables(entity);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
|
||||||
public static void registerMessage(FMLCommonSetupEvent event) {
|
|
||||||
TargetMod.addNetworkMessage(DoubleJumpMessage.class, DoubleJumpMessage::buffer, DoubleJumpMessage::new, DoubleJumpMessage::handler);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,63 +1,65 @@
|
||||||
package net.mcreator.target.network;
|
package net.mcreator.target.network;
|
||||||
|
|
||||||
import net.mcreator.target.TargetMod;
|
|
||||||
import net.mcreator.target.procedures.OutZoomProcedure;
|
|
||||||
import net.mcreator.target.procedures.ToZoomProcedure;
|
|
||||||
import net.minecraft.network.FriendlyByteBuf;
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
|
||||||
import net.minecraftforge.fml.common.Mod;
|
|
||||||
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
|
|
||||||
import net.minecraftforge.network.NetworkEvent;
|
import net.minecraftforge.network.NetworkEvent;
|
||||||
|
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD)
|
|
||||||
public class ZoomMessage {
|
public class ZoomMessage {
|
||||||
int type, pressedms;
|
private final int type;
|
||||||
|
private final int pressedMs;
|
||||||
|
|
||||||
public ZoomMessage(int type, int pressedms) {
|
public ZoomMessage(int type, int pressedMs) {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.pressedms = pressedms;
|
this.pressedMs = pressedMs;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ZoomMessage(FriendlyByteBuf buffer) {
|
public ZoomMessage(FriendlyByteBuf buffer) {
|
||||||
this.type = buffer.readInt();
|
this.type = buffer.readInt();
|
||||||
this.pressedms = buffer.readInt();
|
this.pressedMs = buffer.readInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void buffer(ZoomMessage message, FriendlyByteBuf buffer) {
|
public static void buffer(ZoomMessage message, FriendlyByteBuf buffer) {
|
||||||
buffer.writeInt(message.type);
|
buffer.writeInt(message.type);
|
||||||
buffer.writeInt(message.pressedms);
|
buffer.writeInt(message.pressedMs);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void handler(ZoomMessage message, Supplier<NetworkEvent.Context> contextSupplier) {
|
public static void handler(ZoomMessage message, Supplier<NetworkEvent.Context> contextSupplier) {
|
||||||
NetworkEvent.Context context = contextSupplier.get();
|
NetworkEvent.Context context = contextSupplier.get();
|
||||||
context.enqueueWork(() -> pressAction(context.getSender(), message.type, message.pressedms));
|
context.enqueueWork(() -> {
|
||||||
|
if (context.getSender() != null) {
|
||||||
|
pressAction(context.getSender(), message.type);
|
||||||
|
}
|
||||||
|
});
|
||||||
context.setPacketHandled(true);
|
context.setPacketHandled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void pressAction(Player entity, int type, int pressedms) {
|
public static void pressAction(Player entity, int type) {
|
||||||
Level world = entity.level();
|
Level world = entity.level();
|
||||||
double x = entity.getX();
|
|
||||||
double y = entity.getY();
|
|
||||||
double z = entity.getZ();
|
|
||||||
// security measure to prevent arbitrary chunk generation
|
|
||||||
if (!world.hasChunkAt(entity.blockPosition()))
|
|
||||||
return;
|
|
||||||
if (type == 0) {
|
|
||||||
|
|
||||||
ToZoomProcedure.execute(entity);
|
if (!world.hasChunkAt(entity.blockPosition())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type == 0) {
|
||||||
|
entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
||||||
|
capability.zoom = true;
|
||||||
|
capability.syncPlayerVariables(entity);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
if (type == 1) {
|
if (type == 1) {
|
||||||
|
entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
||||||
|
capability.zoom = false;
|
||||||
|
capability.syncPlayerVariables(entity);
|
||||||
|
});
|
||||||
|
entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
||||||
|
capability.zooming = false;
|
||||||
|
capability.syncPlayerVariables(entity);
|
||||||
|
});
|
||||||
|
entity.getPersistentData().putDouble("miaozhunshijian", 0);
|
||||||
|
|
||||||
OutZoomProcedure.execute(entity);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
|
||||||
public static void registerMessage(FMLCommonSetupEvent event) {
|
|
||||||
TargetMod.addNetworkMessage(ZoomMessage.class, ZoomMessage::buffer, ZoomMessage::new, ZoomMessage::handler);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,35 +0,0 @@
|
||||||
package net.mcreator.target.procedures;
|
|
||||||
|
|
||||||
import net.mcreator.target.network.TargetModVariables;
|
|
||||||
import net.minecraft.core.BlockPos;
|
|
||||||
import net.minecraft.resources.ResourceLocation;
|
|
||||||
import net.minecraft.sounds.SoundSource;
|
|
||||||
import net.minecraft.world.entity.Entity;
|
|
||||||
import net.minecraft.world.level.Level;
|
|
||||||
import net.minecraft.world.level.LevelAccessor;
|
|
||||||
import net.minecraft.world.phys.Vec3;
|
|
||||||
import net.minecraftforge.registries.ForgeRegistries;
|
|
||||||
|
|
||||||
public class DoublejumpProcedure {
|
|
||||||
public static void execute(LevelAccessor world, double x, double y, double z, Entity entity) {
|
|
||||||
if (entity == null)
|
|
||||||
return;
|
|
||||||
if ((entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).playerdoublejump) {
|
|
||||||
entity.setDeltaMovement(new Vec3((1 * entity.getLookAngle().x), 0.8, (1 * entity.getLookAngle().z)));
|
|
||||||
if (world instanceof Level _level) {
|
|
||||||
if (!_level.isClientSide()) {
|
|
||||||
_level.playSound(null, BlockPos.containing(x, y, z), ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation("target:doublejump")), SoundSource.BLOCKS, 1, 1);
|
|
||||||
} else {
|
|
||||||
_level.playLocalSound(x, y, z, ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation("target:doublejump")), SoundSource.BLOCKS, 1, 1, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
{
|
|
||||||
boolean _setval = false;
|
|
||||||
entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
|
||||||
capability.playerdoublejump = _setval;
|
|
||||||
capability.syncPlayerVariables(entity);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,27 +0,0 @@
|
||||||
package net.mcreator.target.procedures;
|
|
||||||
|
|
||||||
import net.minecraft.world.entity.Entity;
|
|
||||||
|
|
||||||
import net.mcreator.target.network.TargetModVariables;
|
|
||||||
|
|
||||||
public class OutZoomProcedure {
|
|
||||||
public static void execute(Entity entity) {
|
|
||||||
if (entity == null)
|
|
||||||
return;
|
|
||||||
{
|
|
||||||
boolean _setval = false;
|
|
||||||
entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
|
||||||
capability.zoom = _setval;
|
|
||||||
capability.syncPlayerVariables(entity);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
{
|
|
||||||
boolean _setval = false;
|
|
||||||
entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
|
||||||
capability.zooming = _setval;
|
|
||||||
capability.syncPlayerVariables(entity);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
entity.getPersistentData().putDouble("miaozhunshijian", 0);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,18 +0,0 @@
|
||||||
package net.mcreator.target.procedures;
|
|
||||||
|
|
||||||
import net.mcreator.target.network.TargetModVariables;
|
|
||||||
import net.minecraft.world.entity.Entity;
|
|
||||||
|
|
||||||
public class ToZoomProcedure {
|
|
||||||
public static void execute(Entity entity) {
|
|
||||||
if (entity == null)
|
|
||||||
return;
|
|
||||||
{
|
|
||||||
boolean _setval = true;
|
|
||||||
entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
|
||||||
capability.zoom = _setval;
|
|
||||||
capability.syncPlayerVariables(entity);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Add table
Reference in a new issue