优化代码

This commit is contained in:
17146 2025-02-03 23:42:47 +08:00
parent 2f926cadda
commit 90c234018d
9 changed files with 42 additions and 25 deletions

View file

@ -18,6 +18,7 @@ import net.minecraftforge.network.NetworkHooks;
import net.minecraftforge.network.PlayMessages;
public class FlareDecoyEntity extends Entity {
public FlareDecoyEntity(EntityType<? extends FlareDecoyEntity> type, Level world) {
super(type, world);
}
@ -37,12 +38,10 @@ public class FlareDecoyEntity extends Entity {
@Override
protected void readAdditionalSaveData(CompoundTag compoundTag) {
}
@Override
protected void addAdditionalSaveData(CompoundTag compoundTag) {
}
@Override
@ -66,11 +65,11 @@ public class FlareDecoyEntity extends Entity {
}
public void decoyShoot(Entity entity, Vec3 shootVec, float pVelocity, float pInaccuracy) {
Vec3 vec3 = shootVec.normalize().add(this.random.triangle(0.0, 0.0172275 * (double)pInaccuracy), this.random.triangle(0.0, 0.0172275 * (double)pInaccuracy), this.random.triangle(0.0, 0.0172275 * (double)pInaccuracy)).scale((double)pVelocity);
Vec3 vec3 = shootVec.normalize().add(this.random.triangle(0.0, 0.0172275 * (double) pInaccuracy), this.random.triangle(0.0, 0.0172275 * (double) pInaccuracy), this.random.triangle(0.0, 0.0172275 * (double) pInaccuracy)).scale((double) pVelocity);
this.setDeltaMovement(entity.getDeltaMovement().scale(0.75).add(vec3));
double d0 = vec3.horizontalDistance();
this.setYRot((float)(Mth.atan2(vec3.x, vec3.z) * 57.2957763671875));
this.setXRot((float)(Mth.atan2(vec3.y, d0) * 57.2957763671875));
this.setYRot((float) (Mth.atan2(vec3.x, vec3.z) * 57.2957763671875));
this.setXRot((float) (Mth.atan2(vec3.y, d0) * 57.2957763671875));
this.yRotO = this.getYRot();
this.xRotO = this.getXRot();
}

View file

@ -35,6 +35,7 @@ import software.bernie.geckolib.core.animation.AnimatableManager;
import software.bernie.geckolib.util.GeckoLibUtil;
public class GunGrenadeEntity extends ThrowableItemProjectile implements GeoEntity {
private float monsterMultiplier = 0.0f;
private float damage = 40.0f;
private float explosionDamage = 80f;
@ -61,6 +62,7 @@ public class GunGrenadeEntity extends ThrowableItemProjectile implements GeoEnti
public void setMonsterMultiplier(float monsterMultiplier) {
this.monsterMultiplier = monsterMultiplier;
}
public void charged(boolean charged) {
this.charged = charged;
}
@ -165,5 +167,4 @@ public class GunGrenadeEntity extends ThrowableItemProjectile implements GeoEnti
public AnimatableInstanceCache getAnimatableInstanceCache() {
return this.cache;
}
}

View file

@ -308,10 +308,10 @@ public class Ah6Entity extends ContainerMobileEntity implements GeoEntity, IHeli
diffX = Math.clamp(-60f, 60f, Mth.wrapDegrees(passenger.getXRot() - this.getXRot()));
if (rightInputDown) {
holdTick ++;
holdTick++;
this.entityData.set(DELTA_ROT, this.entityData.get(DELTA_ROT) - 2f * Math.min(holdTick, 7) * this.entityData.get(PROPELLER_ROT));
} else if (this.leftInputDown) {
holdTick ++;
holdTick++;
this.entityData.set(DELTA_ROT, this.entityData.get(DELTA_ROT) + 2f * Math.min(holdTick, 7) * this.entityData.get(PROPELLER_ROT));
} else {
holdTick = 0;
@ -617,7 +617,6 @@ public class Ah6Entity extends ContainerMobileEntity implements GeoEntity, IHeli
ModUtils.PACKET_HANDLER.send(PacketDistributor.PLAYER.with(() -> serverPlayer), new ShakeClientMessage(6, 5, 7, this.getX(), this.getEyeY(), this.getZ()));
}
}
} else if (entityData.get(WEAPON_TYPE) == 1 && this.getEntityData().get(LOADED_ROCKET) > 0) {
x = 1.7f;
y = 0.62f;

View file

@ -12,12 +12,14 @@ import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.HasCustomInventoryScreen;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.vehicle.ContainerEntity;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.HopperBlockEntity;
import net.minecraft.world.level.gameevent.GameEvent;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.ForgeCapabilities;
@ -26,6 +28,8 @@ import net.minecraftforge.items.wrapper.InvWrapper;
import org.jetbrains.annotations.Nullable;
import org.joml.Math;
import java.util.List;
public class ContainerMobileEntity extends MobileVehicleEntity implements HasCustomInventoryScreen, ContainerEntity {
public static final int CONTAINER_SIZE = 102;
@ -75,11 +79,13 @@ public class ContainerMobileEntity extends MobileVehicleEntity implements HasCus
super.remove(pReason);
}
@Override
public void baseTick() {
super.baseTick();
// pickUpItem();
if (this.canPickUpItems()) {
this.pickUpItems();
}
for (var stack : this.getItemStacks()) {
int neededEnergy = this.getMaxEnergy() - this.getEnergy();
@ -99,16 +105,20 @@ public class ContainerMobileEntity extends MobileVehicleEntity implements HasCus
this.refreshDimensions();
}
// public void pickUpItem() {
// List<ItemEntity> list = this.level().getEntitiesOfClass(ItemEntity.class, this.getBoundingBox().inflate(0.2F, 0.1, 0.2F));
// if (!list.isEmpty()) {
// for (ItemEntity entity : list) {
// if (!this.level().isClientSide) {
// HopperBlockEntity.addItem(this, entity);
// }
// }
// }
// }
public boolean canPickUpItems() {
return false;
}
public void pickUpItems() {
List<ItemEntity> list = this.level().getEntitiesOfClass(ItemEntity.class, this.getBoundingBox().inflate(0.2F, 0.1, 0.2F));
if (!list.isEmpty()) {
for (ItemEntity entity : list) {
if (!this.level().isClientSide) {
HopperBlockEntity.addItem(this, entity);
}
}
}
}
@Override
public void openCustomInventoryScreen(Player pPlayer) {

View file

@ -13,7 +13,10 @@ public interface IArmedVehicleEntity {
boolean canShoot(Player player);
int getAmmoCount(Player player);
boolean banHand();
boolean hidePassenger();
int zoomFov();
}

View file

@ -3,9 +3,14 @@ package com.atsuishio.superbwarfare.entity.vehicle;
import net.minecraft.world.phys.Vec3;
public interface ILandArmorEntity extends IArmedVehicleEntity {
float turretYRotO();
float turretYRot();
float turretXRotO();
float turretXRot();
Vec3 getBarrelVec(float ticks);
}

View file

@ -1,6 +1,8 @@
package com.atsuishio.superbwarfare.entity.vehicle;
public interface MultiWeaponVehicleEntity extends IArmedVehicleEntity {
void changeWeapon(int scroll);
int getWeaponType();
}

View file

@ -10,6 +10,7 @@ import net.minecraft.world.inventory.Slot;
import net.minecraft.world.item.ItemStack;
public class VehicleMenu extends AbstractContainerMenu {
private final Container container;
private final int containerRows;
@ -77,6 +78,4 @@ public class VehicleMenu extends AbstractContainerMenu {
public boolean stillValid(Player pPlayer) {
return this.container.stillValid(pPlayer);
}
}

View file

@ -34,7 +34,6 @@ public class SwitchVehicleWeaponMessage {
if (player.getVehicle() instanceof MultiWeaponVehicleEntity multiWeaponVehicle && multiWeaponVehicle.isDriver(player)) {
multiWeaponVehicle.changeWeapon(Mth.clamp(message.scroll > 0 ? Mth.ceil(message.scroll) : Mth.floor(message.scroll), -1, 1));
}
});
context.get().setPacketHandled(true);
}