为63式火箭炮添加物品栏
This commit is contained in:
parent
2fc4a4a9ce
commit
3ab3a583d1
3 changed files with 20 additions and 63 deletions
|
@ -3,7 +3,7 @@ package com.atsuishio.superbwarfare.entity.vehicle;
|
|||
import com.atsuishio.superbwarfare.Mod;
|
||||
import com.atsuishio.superbwarfare.config.server.ExplosionConfig;
|
||||
import com.atsuishio.superbwarfare.entity.OBBEntity;
|
||||
import com.atsuishio.superbwarfare.entity.vehicle.base.MobileVehicleEntity;
|
||||
import com.atsuishio.superbwarfare.entity.vehicle.base.ContainerMobileVehicleEntity;
|
||||
import com.atsuishio.superbwarfare.init.ModDamageTypes;
|
||||
import com.atsuishio.superbwarfare.item.SmallShellItem;
|
||||
import com.atsuishio.superbwarfare.tools.CustomExplosion;
|
||||
|
@ -18,7 +18,6 @@ import net.minecraft.network.syncher.SynchedEntityData;
|
|||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.Container;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
|
@ -39,7 +38,7 @@ import software.bernie.geckolib.util.GeckoLibUtil;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
public class Type63Entity extends MobileVehicleEntity implements GeoEntity, OBBEntity, Container {
|
||||
public class Type63Entity extends ContainerMobileVehicleEntity implements GeoEntity, OBBEntity {
|
||||
|
||||
public static final EntityDataAccessor<Float> PITCH = SynchedEntityData.defineId(Type63Entity.class, EntityDataSerializers.FLOAT);
|
||||
public static final EntityDataAccessor<Float> YAW = SynchedEntityData.defineId(Type63Entity.class, EntityDataSerializers.FLOAT);
|
||||
|
@ -63,8 +62,6 @@ public class Type63Entity extends MobileVehicleEntity implements GeoEntity, OBBE
|
|||
|
||||
public double interactionTick;
|
||||
|
||||
public ItemStack stack = ItemStack.EMPTY;
|
||||
|
||||
public Type63Entity(EntityType<Type63Entity> type, Level world) {
|
||||
super(type, world);
|
||||
this.barrel0 = new OBB(this.position().toVector3f(), new Vector3f(0.09375f, 0.09375f, 0.0625f), new Quaternionf(), OBB.Part.BODY);
|
||||
|
@ -101,12 +98,17 @@ public class Type63Entity extends MobileVehicleEntity implements GeoEntity, OBBE
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void readAdditionalSaveData(CompoundTag compound) {
|
||||
public void readAdditionalSaveData(CompoundTag compound) {
|
||||
super.readAdditionalSaveData(compound);
|
||||
this.entityData.set(PITCH, compound.getFloat("Pitch"));
|
||||
this.entityData.set(YAW, compound.getFloat("Yaw"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxStackSize(@NotNull ItemStack stack) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull InteractionResult interact(Player player, @NotNull InteractionHand hand) {
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
|
@ -272,56 +274,8 @@ public class Type63Entity extends MobileVehicleEntity implements GeoEntity, OBBE
|
|||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return stack == ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull ItemStack getItem(int slot) {
|
||||
return slot == 0 ? stack : ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull ItemStack removeItem(int slot, int amount) {
|
||||
if (slot != 0 || amount <= 0 || stack.isEmpty()) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
stack.shrink(1);
|
||||
if (stack.isEmpty()) {
|
||||
stack = ItemStack.EMPTY;
|
||||
}
|
||||
return stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull ItemStack removeItemNoUpdate(int slot) {
|
||||
return removeItem(0, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItem(int slot, @NotNull ItemStack stack) {
|
||||
if (slot != 0) return;
|
||||
this.stack = stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setChanged() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean stillValid(@NotNull Player player) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearContent() {
|
||||
this.stack = ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPlaceItem(int slot, @NotNull ItemStack stack) {
|
||||
if (slot != 0) return false;
|
||||
return stack.getItem() instanceof SmallShellItem;
|
||||
}
|
||||
|
||||
|
|
|
@ -29,9 +29,9 @@ import org.joml.Math;
|
|||
|
||||
public abstract class ContainerMobileVehicleEntity extends MobileVehicleEntity implements HasCustomInventoryScreen, ContainerEntity {
|
||||
|
||||
public static final int CONTAINER_SIZE = 102;
|
||||
public static final int DEFAULT_CONTAINER_SIZE = 102;
|
||||
|
||||
private final NonNullList<ItemStack> items = NonNullList.withSize(CONTAINER_SIZE, ItemStack.EMPTY);
|
||||
private final NonNullList<ItemStack> items = NonNullList.withSize(this.getContainerSize(), ItemStack.EMPTY);
|
||||
|
||||
public ContainerMobileVehicleEntity(EntityType<?> pEntityType, Level pLevel) {
|
||||
super(pEntityType, pLevel);
|
||||
|
@ -160,7 +160,7 @@ public abstract class ContainerMobileVehicleEntity extends MobileVehicleEntity i
|
|||
* @param count 要插入的数量
|
||||
*/
|
||||
public void insertItem(Item item, int count) {
|
||||
var rest = InventoryTool.insertItem(this.getItemStacks(), item, count);
|
||||
var rest = InventoryTool.insertItem(this.getItemStacks(), item, count, this.getMaxStackSize());
|
||||
|
||||
if (rest > 0) {
|
||||
var stackToDrop = new ItemStack(item, rest);
|
||||
|
@ -175,7 +175,7 @@ public abstract class ContainerMobileVehicleEntity extends MobileVehicleEntity i
|
|||
|
||||
@Override
|
||||
public int getContainerSize() {
|
||||
return CONTAINER_SIZE;
|
||||
return DEFAULT_CONTAINER_SIZE;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -221,14 +221,17 @@ public abstract class ContainerMobileVehicleEntity extends MobileVehicleEntity i
|
|||
this.getItemStacks().clear();
|
||||
}
|
||||
|
||||
public boolean hasMenu() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public AbstractContainerMenu createMenu(int pContainerId, @NotNull Inventory pPlayerInventory, Player pPlayer) {
|
||||
if (pPlayer.isSpectator()) {
|
||||
return null;
|
||||
} else {
|
||||
if (!pPlayer.isSpectator() && this.hasMenu()) {
|
||||
return new VehicleMenu(pContainerId, pPlayerInventory, this);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -104,9 +104,9 @@ public class InventoryTool {
|
|||
* @param count 要插入的数量
|
||||
* @return 未能成功插入的物品数量
|
||||
*/
|
||||
public static int insertItem(NonNullList<ItemStack> itemList, Item item, int count) {
|
||||
public static int insertItem(NonNullList<ItemStack> itemList, Item item, int count, int maxStackSize) {
|
||||
var defaultStack = new ItemStack(item);
|
||||
var maxStackSize = item.getMaxStackSize(defaultStack);
|
||||
maxStackSize = Math.min(maxStackSize, item.getMaxStackSize(defaultStack));
|
||||
|
||||
for (int i = 0; i < itemList.size(); i++) {
|
||||
var stack = itemList.get(i);
|
||||
|
|
Loading…
Add table
Reference in a new issue