优化代码

This commit is contained in:
17146 2024-08-15 14:59:37 +08:00
parent 75ed202791
commit 4032d4537a
9 changed files with 34 additions and 56 deletions

View file

@ -2,8 +2,7 @@ package net.mcreator.superbwarfare.client;
import com.mojang.blaze3d.platform.InputConstants;
import net.mcreator.superbwarfare.ModUtils;
import net.mcreator.superbwarfare.entity.Mk42Entity;
import net.mcreator.superbwarfare.entity.Mle1934Entity;
import net.mcreator.superbwarfare.entity.ICannonEntity;
import net.mcreator.superbwarfare.entity.MortarEntity;
import net.mcreator.superbwarfare.init.ModItems;
import net.mcreator.superbwarfare.init.ModMobEffects;
@ -76,7 +75,7 @@ public class ClickHandler {
event.setCanceled(true);
ModUtils.PACKET_HANDLER.sendToServer(new DroneFireMessage(0));
}
if (player.getVehicle() != null && (player.getVehicle() instanceof Mk42Entity || player.getVehicle() instanceof Mle1934Entity)) {
if (player.getVehicle() != null && (player.getVehicle() instanceof ICannonEntity)) {
event.setCanceled(true);
ModUtils.PACKET_HANDLER.sendToServer(new VehicleFireMessage(0));
return;
@ -91,7 +90,7 @@ public class ClickHandler {
if (Minecraft.getInstance().player.hasEffect(ModMobEffects.SHOCK.get())) {
event.setCanceled(true);
}
if (player.getMainHandItem().is(ModTags.Items.GUN) || (player.isPassenger() && (player.getVehicle() instanceof Mk42Entity || player.getVehicle() instanceof Mle1934Entity))) {
if (player.getMainHandItem().is(ModTags.Items.GUN) || (player.isPassenger() && (player.getVehicle() instanceof ICannonEntity))) {
event.setCanceled(true);
ModUtils.PACKET_HANDLER.sendToServer(new ZoomMessage(0));
}

View file

@ -2,8 +2,7 @@ package net.mcreator.superbwarfare.client.screens;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import net.mcreator.superbwarfare.entity.Mk42Entity;
import net.mcreator.superbwarfare.entity.Mle1934Entity;
import net.mcreator.superbwarfare.entity.ICannonEntity;
import net.mcreator.superbwarfare.init.ModItems;
import net.mcreator.superbwarfare.network.ModVariables;
import net.minecraft.client.CameraType;
@ -17,8 +16,9 @@ import net.minecraftforge.eventbus.api.EventPriority;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
@Mod.EventBusSubscriber({Dist.CLIENT})
@Mod.EventBusSubscriber(value = Dist.CLIENT)
public class M79UIOverlay {
@SubscribeEvent(priority = EventPriority.NORMAL)
public static void eventHandler(RenderGuiEvent.Pre event) {
int w = event.getWindow().getGuiScaledWidth();
@ -44,7 +44,7 @@ public class M79UIOverlay {
if (player == null) return false;
return !player.isSpectator()
&& player.getMainHandItem().getItem() == ModItems.M_79.get()
&& (Minecraft.getInstance().options.getCameraType() == CameraType.FIRST_PERSON || (player.isPassenger() && (player.getVehicle() instanceof Mk42Entity || player.getVehicle() instanceof Mle1934Entity)))
&& (Minecraft.getInstance().options.getCameraType() == CameraType.FIRST_PERSON || (player.isPassenger() && player.getVehicle() instanceof ICannonEntity))
&& !player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).map(c -> c.zooming).orElse(false);
}
@ -52,6 +52,6 @@ public class M79UIOverlay {
if (player == null) return false;
return !player.isSpectator()
&& !(player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new ModVariables.PlayerVariables())).zoom
&& player.isPassenger() && (player.getVehicle() instanceof Mk42Entity || player.getVehicle() instanceof Mle1934Entity);
&& player.isPassenger() && player.getVehicle() instanceof ICannonEntity;
}
}

View file

@ -2,8 +2,8 @@ package net.mcreator.superbwarfare.client.screens;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import net.mcreator.superbwarfare.entity.Mk42Entity;
import net.mcreator.superbwarfare.entity.Mle1934Entity;
import net.mcreator.superbwarfare.ModUtils;
import net.mcreator.superbwarfare.entity.ICannonEntity;
import net.mcreator.superbwarfare.item.gun.GunItem;
import net.mcreator.superbwarfare.network.ModVariables;
import net.mcreator.superbwarfare.tools.RenderTool;
@ -35,7 +35,7 @@ public class Mk42UIOverlay {
RenderSystem.setShaderColor(1, 1, 1, 1);
if (shouldRenderCrossHair(player)) {
RenderTool.preciseBlit(event.getGuiGraphics(),
new ResourceLocation("superbwarfare:textures/screens/mk_42_rex.png"),
new ResourceLocation(ModUtils.MODID, "textures/screens/mk_42_rex.png"),
(float) w / 2 - (float) TEXTURE_WIDTH / 10f, (float) h / 2 - (float) TEXTURE_HEIGHT / 10f,
0, 0, TEXTURE_WIDTH / 5f, TEXTURE_HEIGHT / 5f, TEXTURE_WIDTH / 5f, TEXTURE_HEIGHT / 5f);
}
@ -50,8 +50,7 @@ public class Mk42UIOverlay {
if (player == null) return false;
return !player.isSpectator()
&& !(player.getMainHandItem().getItem() instanceof GunItem)
// && Minecraft.getInstance().options.getCameraType() == CameraType.FIRST_PERSON
&& (player.getVehicle() != null && (player.getVehicle() instanceof Mk42Entity || player.getVehicle() instanceof Mle1934Entity))
&& (player.getVehicle() != null && (player.getVehicle() instanceof ICannonEntity))
&& (player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new ModVariables.PlayerVariables())).zoom;
}
}

View file

@ -46,9 +46,7 @@ import software.bernie.geckolib.core.object.PlayState;
import software.bernie.geckolib.util.GeckoLibUtil;
public class Mk42Entity extends PathfinderMob implements GeoEntity, ICannonEntity {
public static final EntityDataAccessor<Boolean> SHOOT = SynchedEntityData.defineId(Mk42Entity.class, EntityDataSerializers.BOOLEAN);
public static final EntityDataAccessor<String> ANIMATION = SynchedEntityData.defineId(Mk42Entity.class, EntityDataSerializers.STRING);
public static final EntityDataAccessor<String> TEXTURE = SynchedEntityData.defineId(Mk42Entity.class, EntityDataSerializers.STRING);
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
public String animationprocedure = "empty";
@ -67,9 +65,7 @@ public class Mk42Entity extends PathfinderMob implements GeoEntity, ICannonEntit
@Override
protected void defineSynchedData() {
super.defineSynchedData();
this.entityData.define(SHOOT, false);
this.entityData.define(ANIMATION, "undefined");
this.entityData.define(TEXTURE, "sherman");
}
@Override
@ -77,14 +73,6 @@ public class Mk42Entity extends PathfinderMob implements GeoEntity, ICannonEntit
return 2.16F;
}
public void setTexture(String texture) {
this.entityData.set(TEXTURE, texture);
}
public String getTexture() {
return this.entityData.get(TEXTURE);
}
@Override
public boolean canCollideWith(Entity entity) {
return true;
@ -167,14 +155,11 @@ public class Mk42Entity extends PathfinderMob implements GeoEntity, ICannonEntit
@Override
public void addAdditionalSaveData(CompoundTag compound) {
super.addAdditionalSaveData(compound);
compound.putString("Texture", this.getTexture());
}
@Override
public void readAdditionalSaveData(CompoundTag compound) {
super.readAdditionalSaveData(compound);
if (compound.contains("Texture"))
this.setTexture(compound.getString("Texture"));
}
@Override
@ -373,7 +358,7 @@ public class Mk42Entity extends PathfinderMob implements GeoEntity, ICannonEntit
.add(Attributes.KNOCKBACK_RESISTANCE, 1);
}
private PlayState movementPredicate(AnimationState event) {
private PlayState movementPredicate(AnimationState<Mk42Entity> event) {
if (this.animationprocedure.equals("empty")) {
if (this.getFirstPassenger() != null) {
@ -393,7 +378,7 @@ public class Mk42Entity extends PathfinderMob implements GeoEntity, ICannonEntit
return PlayState.STOP;
}
private PlayState procedurePredicate(AnimationState event) {
private PlayState procedurePredicate(AnimationState<Mk42Entity> event) {
if (!animationprocedure.equals("empty") && event.getController().getAnimationState() == AnimationController.State.STOPPED) {
event.getController().setAnimation(RawAnimation.begin().thenPlay(this.animationprocedure));
if (event.getController().getAnimationState() == AnimationController.State.STOPPED) {

View file

@ -210,16 +210,14 @@ public class ProjectileEntity extends Entity implements IEntityAdditionalSpawnDa
float BodyHeight = entity.getBbHeight();
if ((eyeHeight - 0.35) < hitBoxPos.y && hitBoxPos.y < (eyeHeight + 0.4) && !(entity instanceof ClaymoreEntity
|| entity instanceof MortarEntity
|| entity instanceof Mle1934Entity
|| entity instanceof Mk42Entity
|| entity instanceof ICannonEntity
|| entity instanceof DroneEntity
)) {
headshot = true;
}
if (hitBoxPos.y < (0.33 * BodyHeight) && !(entity instanceof ClaymoreEntity
|| entity instanceof MortarEntity
|| entity instanceof Mle1934Entity
|| entity instanceof Mk42Entity
|| entity instanceof ICannonEntity
|| entity instanceof DroneEntity
)) {
legshot = true;

View file

@ -41,7 +41,6 @@ import software.bernie.geckolib.core.object.PlayState;
import software.bernie.geckolib.util.GeckoLibUtil;
public class SenpaiEntity extends Monster implements GeoEntity, AnimatedEntity {
public static final EntityDataAccessor<Boolean> SHOOT = SynchedEntityData.defineId(SenpaiEntity.class, EntityDataSerializers.BOOLEAN);
public static final EntityDataAccessor<String> ANIMATION = SynchedEntityData.defineId(SenpaiEntity.class, EntityDataSerializers.STRING);
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
@ -60,7 +59,6 @@ public class SenpaiEntity extends Monster implements GeoEntity, AnimatedEntity {
@Override
protected void defineSynchedData() {
super.defineSynchedData();
this.entityData.define(SHOOT, false);
this.entityData.define(ANIMATION, "undefined");
}
@ -97,11 +95,13 @@ public class SenpaiEntity extends Monster implements GeoEntity, AnimatedEntity {
protected void dropCustomDeathLoot(DamageSource source, int looting, boolean recentlyHitIn) {
super.dropCustomDeathLoot(source, looting, recentlyHitIn);
if (Math.random() < 0.01) {
double random = Math.random();
if (random < 0.01) {
this.spawnAtLocation(new ItemStack(Items.ENCHANTED_GOLDEN_APPLE));
} else if (0.01 <= Math.random() && Math.random() < 0.2) {
} else if (random < 0.2) {
this.spawnAtLocation(new ItemStack(Items.GOLDEN_APPLE));
} else if (Math.random() >= 0.2) {
} else {
this.spawnAtLocation(new ItemStack(Items.APPLE));
}
}

View file

@ -31,7 +31,7 @@ public class Mk42Model extends GeoModel<Mk42Entity> {
if (distance < 32) {
return new ResourceLocation(ModUtils.MODID, "geo/sherman.geo.json");
} else if (distance < 64){
} else if (distance < 64) {
return new ResourceLocation(ModUtils.MODID, "geo/sherman_lod1.geo.json");
} else {
return new ResourceLocation(ModUtils.MODID, "geo/sherman_lod2.geo.json");
@ -45,9 +45,9 @@ public class Mk42Model extends GeoModel<Mk42Entity> {
@Override
public void setCustomAnimations(Mk42Entity animatable, long instanceId, AnimationState animationState) {
CoreGeoBone barrle = getAnimationProcessor().getBone("maingun");
CoreGeoBone bone = getAnimationProcessor().getBone("maingun");
EntityModelData entityData = (EntityModelData) animationState.getData(DataTickets.ENTITY_MODEL_DATA);
barrle.setRotX((entityData.headPitch()) * Mth.DEG_TO_RAD);
bone.setRotX((entityData.headPitch()) * Mth.DEG_TO_RAD);
CoreGeoBone camera = getAnimationProcessor().getBone("camera");
@ -57,6 +57,5 @@ public class Mk42Model extends GeoModel<Mk42Entity> {
gunner.getPersistentData().putDouble("cannon_camera_rot_x", Mth.RAD_TO_DEG * camera.getRotX());
gunner.getPersistentData().putDouble("cannon_camera_rot_y", Mth.RAD_TO_DEG * camera.getRotY());
gunner.getPersistentData().putDouble("cannon_camera_rot_z", Mth.RAD_TO_DEG * camera.getRotZ());
}
}

View file

@ -1,8 +1,7 @@
package net.mcreator.superbwarfare.event;
import net.mcreator.superbwarfare.entity.DroneEntity;
import net.mcreator.superbwarfare.entity.Mk42Entity;
import net.mcreator.superbwarfare.entity.Mle1934Entity;
import net.mcreator.superbwarfare.entity.ICannonEntity;
import net.mcreator.superbwarfare.init.ModItems;
import net.mcreator.superbwarfare.init.ModMobEffects;
import net.mcreator.superbwarfare.init.ModTags;
@ -60,7 +59,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 && entity.isPassenger() && (entity.getVehicle() instanceof Mk42Entity || entity.getVehicle() instanceof Mle1934Entity)) {
if (level != null && entity instanceof LivingEntity living && entity.isPassenger() && entity.getVehicle() instanceof ICannonEntity) {
handleCannonCamera(event, living);
}
if (level != null && entity instanceof LivingEntity living
@ -470,7 +469,7 @@ public class ClientEventHandler {
player.getPersistentData().putDouble("fov", event.getFOV());
return;
}
if (player.isPassenger() && (player.getVehicle() instanceof Mk42Entity || player.getVehicle() instanceof Mle1934Entity)) {
if (player.isPassenger() && player.getVehicle() instanceof ICannonEntity) {
if ((player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new ModVariables.PlayerVariables())).zoom) {
event.setFOV(event.getFOV() / 5);
}
@ -492,7 +491,7 @@ public class ClientEventHandler {
return;
}
if (mc.player.getMainHandItem().is(ModTags.Items.GUN) || (mc.player.getVehicle() != null && (mc.player.getVehicle() instanceof Mk42Entity || mc.player.getVehicle() instanceof Mle1934Entity))) {
if (mc.player.getMainHandItem().is(ModTags.Items.GUN) || (mc.player.getVehicle() != null && mc.player.getVehicle() instanceof ICannonEntity)) {
event.setCanceled(true);
}

View file

@ -1,7 +1,6 @@
package net.mcreator.superbwarfare.network.message;
import net.mcreator.superbwarfare.entity.Mk42Entity;
import net.mcreator.superbwarfare.entity.Mle1934Entity;
import net.mcreator.superbwarfare.entity.ICannonEntity;
import net.mcreator.superbwarfare.init.ModSounds;
import net.mcreator.superbwarfare.network.ModVariables;
import net.mcreator.superbwarfare.tools.SoundTool;
@ -16,7 +15,6 @@ import java.util.function.Supplier;
public class ZoomMessage {
private final int type;
public ZoomMessage(int type) {
this.type = type;
}
@ -52,12 +50,13 @@ public class ZoomMessage {
capability.syncPlayerVariables(entity);
});
if (entity.isPassenger() && (entity.getVehicle() instanceof Mk42Entity || entity.getVehicle() instanceof Mle1934Entity)) {
if (entity.isPassenger() && entity.getVehicle() instanceof ICannonEntity) {
if (entity instanceof ServerPlayer serverPlayer) {
SoundTool.playLocalSound(serverPlayer, ModSounds.CANNON_ZOOM_IN.get(), 2, 1);
}
}
}
if (type == 1) {
entity.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
capability.zoom = false;
@ -68,7 +67,7 @@ public class ZoomMessage {
capability.syncPlayerVariables(entity);
});
if (entity.isPassenger() && (entity.getVehicle() instanceof Mk42Entity || entity.getVehicle() instanceof Mle1934Entity)) {
if (entity.isPassenger() && entity.getVehicle() instanceof ICannonEntity) {
if (entity instanceof ServerPlayer serverPlayer) {
SoundTool.playLocalSound(serverPlayer, ModSounds.CANNON_ZOOM_OUT.get(), 2, 1);
}