实现了快艇的物品存储
This commit is contained in:
parent
8dcfff022e
commit
2242c3551f
15 changed files with 301 additions and 19 deletions
|
@ -1,6 +1,6 @@
|
||||||
package com.atsuishio.superbwarfare.block;
|
package com.atsuishio.superbwarfare.block;
|
||||||
|
|
||||||
import com.atsuishio.superbwarfare.block.menu.ReforgingTableMenu;
|
import com.atsuishio.superbwarfare.menu.ReforgingTableMenu;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.core.Direction;
|
import net.minecraft.core.Direction;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package com.atsuishio.superbwarfare.block.entity;
|
package com.atsuishio.superbwarfare.block.entity;
|
||||||
|
|
||||||
import com.atsuishio.superbwarfare.block.menu.ChargingStationMenu;
|
|
||||||
import com.atsuishio.superbwarfare.entity.IChargeEntity;
|
import com.atsuishio.superbwarfare.entity.IChargeEntity;
|
||||||
import com.atsuishio.superbwarfare.init.ModBlockEntities;
|
import com.atsuishio.superbwarfare.init.ModBlockEntities;
|
||||||
|
import com.atsuishio.superbwarfare.menu.ChargingStationMenu;
|
||||||
import com.atsuishio.superbwarfare.network.dataslot.ContainerEnergyData;
|
import com.atsuishio.superbwarfare.network.dataslot.ContainerEnergyData;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.core.Direction;
|
import net.minecraft.core.Direction;
|
||||||
|
|
|
@ -2,7 +2,7 @@ package com.atsuishio.superbwarfare.client.screens;
|
||||||
|
|
||||||
import com.atsuishio.superbwarfare.ModUtils;
|
import com.atsuishio.superbwarfare.ModUtils;
|
||||||
import com.atsuishio.superbwarfare.block.entity.ChargingStationBlockEntity;
|
import com.atsuishio.superbwarfare.block.entity.ChargingStationBlockEntity;
|
||||||
import com.atsuishio.superbwarfare.block.menu.ChargingStationMenu;
|
import com.atsuishio.superbwarfare.menu.ChargingStationMenu;
|
||||||
import net.minecraft.client.gui.GuiGraphics;
|
import net.minecraft.client.gui.GuiGraphics;
|
||||||
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
|
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
package com.atsuishio.superbwarfare.client.screens;
|
package com.atsuishio.superbwarfare.client.screens;
|
||||||
|
|
||||||
|
import com.atsuishio.superbwarfare.ModUtils;
|
||||||
|
import com.atsuishio.superbwarfare.menu.ReforgingTableMenu;
|
||||||
import com.atsuishio.superbwarfare.network.message.GunReforgeMessage;
|
import com.atsuishio.superbwarfare.network.message.GunReforgeMessage;
|
||||||
import com.atsuishio.superbwarfare.network.message.SetPerkLevelMessage;
|
import com.atsuishio.superbwarfare.network.message.SetPerkLevelMessage;
|
||||||
import com.mojang.blaze3d.systems.RenderSystem;
|
|
||||||
import com.atsuishio.superbwarfare.ModUtils;
|
|
||||||
import com.atsuishio.superbwarfare.block.menu.ReforgingTableMenu;
|
|
||||||
import com.atsuishio.superbwarfare.perk.Perk;
|
import com.atsuishio.superbwarfare.perk.Perk;
|
||||||
|
import com.mojang.blaze3d.systems.RenderSystem;
|
||||||
import net.minecraft.client.gui.GuiGraphics;
|
import net.minecraft.client.gui.GuiGraphics;
|
||||||
import net.minecraft.client.gui.components.AbstractButton;
|
import net.minecraft.client.gui.components.AbstractButton;
|
||||||
import net.minecraft.client.gui.narration.NarrationElementOutput;
|
import net.minecraft.client.gui.narration.NarrationElementOutput;
|
||||||
|
|
|
@ -0,0 +1,46 @@
|
||||||
|
package com.atsuishio.superbwarfare.client.screens;
|
||||||
|
|
||||||
|
import com.atsuishio.superbwarfare.ModUtils;
|
||||||
|
import com.atsuishio.superbwarfare.menu.SpeedboatMenu;
|
||||||
|
import net.minecraft.client.gui.GuiGraphics;
|
||||||
|
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
|
||||||
|
import net.minecraft.network.chat.Component;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import net.minecraft.world.entity.player.Inventory;
|
||||||
|
import net.minecraftforge.api.distmarker.Dist;
|
||||||
|
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||||
|
|
||||||
|
@OnlyIn(Dist.CLIENT)
|
||||||
|
public class SpeedboatScreen extends AbstractContainerScreen<SpeedboatMenu> {
|
||||||
|
|
||||||
|
private static final ResourceLocation TEXTURE = ModUtils.loc("textures/gui/speedboat.png");
|
||||||
|
|
||||||
|
public SpeedboatScreen(SpeedboatMenu pMenu, Inventory pPlayerInventory, Component pTitle) {
|
||||||
|
super(pMenu, pPlayerInventory, pTitle);
|
||||||
|
imageWidth = 320;
|
||||||
|
imageHeight = 222;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void renderBg(GuiGraphics pGuiGraphics, float pPartialTick, int pMouseX, int pMouseY) {
|
||||||
|
int i = (this.width - this.imageWidth) / 2;
|
||||||
|
int j = (this.height - this.imageHeight) / 2;
|
||||||
|
pGuiGraphics.blit(TEXTURE, i, j, 0, 0, this.imageWidth, this.imageHeight, 328, 328);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void render(GuiGraphics pGuiGraphics, int pMouseX, int pMouseY, float pPartialTick) {
|
||||||
|
this.renderBackground(pGuiGraphics);
|
||||||
|
super.render(pGuiGraphics, pMouseX, pMouseY, pPartialTick);
|
||||||
|
this.renderTooltip(pGuiGraphics, pMouseX, pMouseY);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void init() {
|
||||||
|
super.init();
|
||||||
|
this.titleLabelX = 8;
|
||||||
|
this.titleLabelY = 5;
|
||||||
|
this.inventoryLabelX = 80;
|
||||||
|
this.inventoryLabelY = 128;
|
||||||
|
}
|
||||||
|
}
|
|
@ -6,6 +6,7 @@ import com.atsuishio.superbwarfare.config.server.ExplosionDestroyConfig;
|
||||||
import com.atsuishio.superbwarfare.entity.projectile.ProjectileEntity;
|
import com.atsuishio.superbwarfare.entity.projectile.ProjectileEntity;
|
||||||
import com.atsuishio.superbwarfare.init.*;
|
import com.atsuishio.superbwarfare.init.*;
|
||||||
import com.atsuishio.superbwarfare.item.ContainerBlockItem;
|
import com.atsuishio.superbwarfare.item.ContainerBlockItem;
|
||||||
|
import com.atsuishio.superbwarfare.menu.SpeedboatMenu;
|
||||||
import com.atsuishio.superbwarfare.network.ModVariables;
|
import com.atsuishio.superbwarfare.network.ModVariables;
|
||||||
import com.atsuishio.superbwarfare.network.message.ShakeClientMessage;
|
import com.atsuishio.superbwarfare.network.message.ShakeClientMessage;
|
||||||
import com.atsuishio.superbwarfare.tools.CustomExplosion;
|
import com.atsuishio.superbwarfare.tools.CustomExplosion;
|
||||||
|
@ -13,42 +14,53 @@ import com.atsuishio.superbwarfare.tools.EntityFindUtil;
|
||||||
import com.atsuishio.superbwarfare.tools.ParticleTool;
|
import com.atsuishio.superbwarfare.tools.ParticleTool;
|
||||||
import com.atsuishio.superbwarfare.tools.SoundTool;
|
import com.atsuishio.superbwarfare.tools.SoundTool;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.core.Direction;
|
||||||
|
import net.minecraft.core.NonNullList;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.network.protocol.Packet;
|
import net.minecraft.network.protocol.Packet;
|
||||||
import net.minecraft.network.protocol.game.ClientGamePacketListener;
|
import net.minecraft.network.protocol.game.ClientGamePacketListener;
|
||||||
import net.minecraft.network.syncher.EntityDataAccessor;
|
import net.minecraft.network.syncher.EntityDataAccessor;
|
||||||
import net.minecraft.network.syncher.EntityDataSerializers;
|
import net.minecraft.network.syncher.EntityDataSerializers;
|
||||||
import net.minecraft.network.syncher.SynchedEntityData;
|
import net.minecraft.network.syncher.SynchedEntityData;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.server.level.ServerLevel;
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
import net.minecraft.sounds.SoundEvent;
|
import net.minecraft.sounds.SoundEvent;
|
||||||
import net.minecraft.sounds.SoundSource;
|
import net.minecraft.sounds.SoundSource;
|
||||||
import net.minecraft.util.Mth;
|
import net.minecraft.util.Mth;
|
||||||
|
import net.minecraft.world.ContainerHelper;
|
||||||
|
import net.minecraft.world.Containers;
|
||||||
import net.minecraft.world.InteractionHand;
|
import net.minecraft.world.InteractionHand;
|
||||||
import net.minecraft.world.InteractionResult;
|
import net.minecraft.world.InteractionResult;
|
||||||
import net.minecraft.world.damagesource.DamageSource;
|
import net.minecraft.world.damagesource.DamageSource;
|
||||||
import net.minecraft.world.damagesource.DamageTypes;
|
import net.minecraft.world.damagesource.DamageTypes;
|
||||||
import net.minecraft.world.entity.AreaEffectCloud;
|
import net.minecraft.world.entity.*;
|
||||||
import net.minecraft.world.entity.Entity;
|
|
||||||
import net.minecraft.world.entity.EntityType;
|
|
||||||
import net.minecraft.world.entity.MoverType;
|
|
||||||
import net.minecraft.world.entity.item.ItemEntity;
|
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.player.Player;
|
||||||
import net.minecraft.world.entity.projectile.Projectile;
|
import net.minecraft.world.entity.projectile.Projectile;
|
||||||
import net.minecraft.world.entity.projectile.ThrownPotion;
|
import net.minecraft.world.entity.projectile.ThrownPotion;
|
||||||
|
import net.minecraft.world.entity.vehicle.ContainerEntity;
|
||||||
|
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.level.Explosion;
|
import net.minecraft.world.level.Explosion;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
import net.minecraft.world.level.block.Blocks;
|
import net.minecraft.world.level.block.Blocks;
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
import net.minecraft.world.level.entity.EntityTypeTest;
|
import net.minecraft.world.level.entity.EntityTypeTest;
|
||||||
|
import net.minecraft.world.level.gameevent.GameEvent;
|
||||||
import net.minecraft.world.phys.AABB;
|
import net.minecraft.world.phys.AABB;
|
||||||
import net.minecraft.world.phys.Vec3;
|
import net.minecraft.world.phys.Vec3;
|
||||||
|
import net.minecraftforge.common.capabilities.Capability;
|
||||||
|
import net.minecraftforge.common.capabilities.ForgeCapabilities;
|
||||||
|
import net.minecraftforge.common.util.LazyOptional;
|
||||||
import net.minecraftforge.fluids.FluidType;
|
import net.minecraftforge.fluids.FluidType;
|
||||||
|
import net.minecraftforge.items.wrapper.InvWrapper;
|
||||||
import net.minecraftforge.network.NetworkHooks;
|
import net.minecraftforge.network.NetworkHooks;
|
||||||
import net.minecraftforge.network.PacketDistributor;
|
import net.minecraftforge.network.PacketDistributor;
|
||||||
import net.minecraftforge.network.PlayMessages;
|
import net.minecraftforge.network.PlayMessages;
|
||||||
import net.minecraftforge.registries.ForgeRegistries;
|
import net.minecraftforge.registries.ForgeRegistries;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.joml.Math;
|
import org.joml.Math;
|
||||||
import software.bernie.geckolib.animatable.GeoEntity;
|
import software.bernie.geckolib.animatable.GeoEntity;
|
||||||
import software.bernie.geckolib.core.animatable.instance.AnimatableInstanceCache;
|
import software.bernie.geckolib.core.animatable.instance.AnimatableInstanceCache;
|
||||||
|
@ -61,7 +73,8 @@ import software.bernie.geckolib.util.GeckoLibUtil;
|
||||||
|
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
|
||||||
public class SpeedboatEntity extends Entity implements GeoEntity, IChargeEntity, IVehicleEntity {
|
public class SpeedboatEntity extends Entity implements GeoEntity, IChargeEntity, IVehicleEntity, HasCustomInventoryScreen, ContainerEntity {
|
||||||
|
|
||||||
public static final EntityDataAccessor<Float> HEALTH = SynchedEntityData.defineId(SpeedboatEntity.class, EntityDataSerializers.FLOAT);
|
public static final EntityDataAccessor<Float> HEALTH = SynchedEntityData.defineId(SpeedboatEntity.class, EntityDataSerializers.FLOAT);
|
||||||
public static final EntityDataAccessor<Float> ENERGY = SynchedEntityData.defineId(SpeedboatEntity.class, EntityDataSerializers.FLOAT);
|
public static final EntityDataAccessor<Float> ENERGY = SynchedEntityData.defineId(SpeedboatEntity.class, EntityDataSerializers.FLOAT);
|
||||||
public static final EntityDataAccessor<Float> ROT_Y = SynchedEntityData.defineId(SpeedboatEntity.class, EntityDataSerializers.FLOAT);
|
public static final EntityDataAccessor<Float> ROT_Y = SynchedEntityData.defineId(SpeedboatEntity.class, EntityDataSerializers.FLOAT);
|
||||||
|
@ -73,6 +86,10 @@ public class SpeedboatEntity extends Entity implements GeoEntity, IChargeEntity,
|
||||||
|
|
||||||
public static final float MAX_HEALTH = CannonConfig.SPEEDBOAT_HP.get();
|
public static final float MAX_HEALTH = CannonConfig.SPEEDBOAT_HP.get();
|
||||||
public static final float MAX_ENERGY = CannonConfig.SPEEDBOAT_MAX_ENERGY.get().floatValue();
|
public static final float MAX_ENERGY = CannonConfig.SPEEDBOAT_MAX_ENERGY.get().floatValue();
|
||||||
|
public static final int CONTAINER_SIZE = 102;
|
||||||
|
|
||||||
|
private NonNullList<ItemStack> items = NonNullList.withSize(CONTAINER_SIZE, ItemStack.EMPTY);
|
||||||
|
private LazyOptional<?> itemHandler = LazyOptional.of(() -> new InvWrapper(this));
|
||||||
|
|
||||||
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
|
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
|
||||||
private int lerpSteps;
|
private int lerpSteps;
|
||||||
|
@ -115,6 +132,7 @@ public class SpeedboatEntity extends Entity implements GeoEntity, IChargeEntity,
|
||||||
compound.putFloat("Health", this.entityData.get(HEALTH));
|
compound.putFloat("Health", this.entityData.get(HEALTH));
|
||||||
compound.putFloat("Energy", this.entityData.get(ENERGY));
|
compound.putFloat("Energy", this.entityData.get(ENERGY));
|
||||||
compound.putString("LastAttacker", this.entityData.get(LAST_ATTACKER_UUID));
|
compound.putString("LastAttacker", this.entityData.get(LAST_ATTACKER_UUID));
|
||||||
|
ContainerHelper.saveAllItems(compound, this.getItemStacks());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -128,6 +146,7 @@ public class SpeedboatEntity extends Entity implements GeoEntity, IChargeEntity,
|
||||||
if (compound.contains("LastAttacker")) {
|
if (compound.contains("LastAttacker")) {
|
||||||
this.entityData.set(LAST_ATTACKER_UUID, compound.getString("LastAttacker"));
|
this.entityData.set(LAST_ATTACKER_UUID, compound.getString("LastAttacker"));
|
||||||
}
|
}
|
||||||
|
ContainerHelper.loadAllItems(compound, this.getItemStacks());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -163,6 +182,15 @@ public class SpeedboatEntity extends Entity implements GeoEntity, IChargeEntity,
|
||||||
return super.getPassengersRidingOffset() - 1.3;
|
return super.getPassengersRidingOffset() - 1.3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void remove(Entity.RemovalReason pReason) {
|
||||||
|
if (!this.level().isClientSide && pReason.shouldDestroy()) {
|
||||||
|
Containers.dropContents(this.level(), this, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
super.remove(pReason);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hurt(DamageSource source, float amount) {
|
public boolean hurt(DamageSource source, float amount) {
|
||||||
if (this.level() instanceof ServerLevel serverLevel) {
|
if (this.level() instanceof ServerLevel serverLevel) {
|
||||||
|
@ -222,8 +250,10 @@ public class SpeedboatEntity extends Entity implements GeoEntity, IChargeEntity,
|
||||||
}
|
}
|
||||||
this.discard();
|
this.discard();
|
||||||
return InteractionResult.sidedSuccess(this.level().isClientSide());
|
return InteractionResult.sidedSuccess(this.level().isClientSide());
|
||||||
|
} else {
|
||||||
|
player.openMenu(this);
|
||||||
|
return !player.level().isClientSide ? InteractionResult.CONSUME : InteractionResult.SUCCESS;
|
||||||
}
|
}
|
||||||
return InteractionResult.PASS;
|
|
||||||
} else {
|
} else {
|
||||||
player.startRiding(this);
|
player.startRiding(this);
|
||||||
return InteractionResult.sidedSuccess(this.level().isClientSide());
|
return InteractionResult.sidedSuccess(this.level().isClientSide());
|
||||||
|
@ -603,4 +633,124 @@ public class SpeedboatEntity extends Entity implements GeoEntity, IChargeEntity,
|
||||||
public void charge(int amount) {
|
public void charge(int amount) {
|
||||||
this.entityData.set(ENERGY, Math.min(this.entityData.get(ENERGY) + amount, MAX_ENERGY));
|
this.entityData.set(ENERGY, Math.min(this.entityData.get(ENERGY) + amount, MAX_ENERGY));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void openCustomInventoryScreen(Player pPlayer) {
|
||||||
|
pPlayer.openMenu(this);
|
||||||
|
if (!pPlayer.level().isClientSide) {
|
||||||
|
this.gameEvent(GameEvent.CONTAINER_OPEN, pPlayer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public ResourceLocation getLootTable() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setLootTable(@Nullable ResourceLocation pLootTable) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getLootTableSeed() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setLootTableSeed(long pLootTableSeed) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NonNullList<ItemStack> getItemStacks() {
|
||||||
|
return this.items;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void clearItemStacks() {
|
||||||
|
this.items.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getContainerSize() {
|
||||||
|
return CONTAINER_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ItemStack getItem(int pSlot) {
|
||||||
|
return this.items.get(pSlot);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ItemStack removeItem(int pSlot, int pAmount) {
|
||||||
|
return ContainerHelper.removeItem(this.items, pSlot, pAmount);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ItemStack removeItemNoUpdate(int pSlot) {
|
||||||
|
ItemStack itemstack = this.getItemStacks().get(pSlot);
|
||||||
|
if (itemstack.isEmpty()) {
|
||||||
|
return ItemStack.EMPTY;
|
||||||
|
} else {
|
||||||
|
this.getItemStacks().set(pSlot, ItemStack.EMPTY);
|
||||||
|
return itemstack;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setItem(int pSlot, ItemStack pStack) {
|
||||||
|
this.getItemStacks().set(pSlot, pStack);
|
||||||
|
if (!pStack.isEmpty() && pStack.getCount() > this.getMaxStackSize()) {
|
||||||
|
pStack.setCount(this.getMaxStackSize());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setChanged() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean stillValid(Player pPlayer) {
|
||||||
|
return !this.isRemoved() && this.position().closerThan(pPlayer.position(), 8.0D);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void clearContent() {
|
||||||
|
this.getItemStacks().clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public AbstractContainerMenu createMenu(int pContainerId, Inventory pPlayerInventory, Player pPlayer) {
|
||||||
|
if (pPlayer.isSpectator()) {
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
return new SpeedboatMenu(pContainerId, pPlayerInventory, this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <T> LazyOptional<T> getCapability(Capability<T> capability, @Nullable Direction facing) {
|
||||||
|
if (this.isAlive() && capability == ForgeCapabilities.ITEM_HANDLER) {
|
||||||
|
return itemHandler.cast();
|
||||||
|
}
|
||||||
|
return super.getCapability(capability, facing);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void invalidateCaps() {
|
||||||
|
super.invalidateCaps();
|
||||||
|
itemHandler.invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void reviveCaps() {
|
||||||
|
super.reviveCaps();
|
||||||
|
itemHandler = LazyOptional.of(() -> new InvWrapper(this));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void stopOpen(Player pPlayer) {
|
||||||
|
this.level().gameEvent(GameEvent.CONTAINER_CLOSE, this.position(), GameEvent.Context.of(pPlayer));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
package com.atsuishio.superbwarfare.init;
|
package com.atsuishio.superbwarfare.init;
|
||||||
|
|
||||||
import com.atsuishio.superbwarfare.ModUtils;
|
import com.atsuishio.superbwarfare.ModUtils;
|
||||||
import com.atsuishio.superbwarfare.block.menu.ChargingStationMenu;
|
import com.atsuishio.superbwarfare.menu.ChargingStationMenu;
|
||||||
import com.atsuishio.superbwarfare.block.menu.ReforgingTableMenu;
|
import com.atsuishio.superbwarfare.menu.ReforgingTableMenu;
|
||||||
|
import com.atsuishio.superbwarfare.menu.SpeedboatMenu;
|
||||||
import net.minecraft.world.inventory.MenuType;
|
import net.minecraft.world.inventory.MenuType;
|
||||||
import net.minecraftforge.common.extensions.IForgeMenuType;
|
import net.minecraftforge.common.extensions.IForgeMenuType;
|
||||||
import net.minecraftforge.registries.DeferredRegister;
|
import net.minecraftforge.registries.DeferredRegister;
|
||||||
|
@ -19,4 +20,7 @@ public class ModMenuTypes {
|
||||||
public static final RegistryObject<MenuType<ChargingStationMenu>> CHARGING_STATION_MENU =
|
public static final RegistryObject<MenuType<ChargingStationMenu>> CHARGING_STATION_MENU =
|
||||||
REGISTRY.register("charging_station_menu",
|
REGISTRY.register("charging_station_menu",
|
||||||
() -> IForgeMenuType.create((windowId, inv, data) -> new ChargingStationMenu(windowId, inv)));
|
() -> IForgeMenuType.create((windowId, inv, data) -> new ChargingStationMenu(windowId, inv)));
|
||||||
|
public static final RegistryObject<MenuType<SpeedboatMenu>> SPEEDBOAT_MENU =
|
||||||
|
REGISTRY.register("speedboat_menu",
|
||||||
|
() -> IForgeMenuType.create((windowId, inv, data) -> new SpeedboatMenu(windowId, inv)));
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package com.atsuishio.superbwarfare.init;
|
||||||
|
|
||||||
import com.atsuishio.superbwarfare.client.screens.ChargingStationScreen;
|
import com.atsuishio.superbwarfare.client.screens.ChargingStationScreen;
|
||||||
import com.atsuishio.superbwarfare.client.screens.ReforgingTableScreen;
|
import com.atsuishio.superbwarfare.client.screens.ReforgingTableScreen;
|
||||||
|
import com.atsuishio.superbwarfare.client.screens.SpeedboatScreen;
|
||||||
import net.minecraft.client.gui.screens.MenuScreens;
|
import net.minecraft.client.gui.screens.MenuScreens;
|
||||||
import net.minecraftforge.api.distmarker.Dist;
|
import net.minecraftforge.api.distmarker.Dist;
|
||||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||||
|
@ -16,6 +17,7 @@ public class ModScreens {
|
||||||
event.enqueueWork(() -> {
|
event.enqueueWork(() -> {
|
||||||
MenuScreens.register(ModMenuTypes.REFORGING_TABLE_MENU.get(), ReforgingTableScreen::new);
|
MenuScreens.register(ModMenuTypes.REFORGING_TABLE_MENU.get(), ReforgingTableScreen::new);
|
||||||
MenuScreens.register(ModMenuTypes.CHARGING_STATION_MENU.get(), ChargingStationScreen::new);
|
MenuScreens.register(ModMenuTypes.CHARGING_STATION_MENU.get(), ChargingStationScreen::new);
|
||||||
|
MenuScreens.register(ModMenuTypes.SPEEDBOAT_MENU.get(), SpeedboatScreen::new);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package com.atsuishio.superbwarfare.block.menu;
|
package com.atsuishio.superbwarfare.menu;
|
||||||
|
|
||||||
import com.atsuishio.superbwarfare.ModUtils;
|
import com.atsuishio.superbwarfare.ModUtils;
|
||||||
import com.atsuishio.superbwarfare.block.entity.ChargingStationBlockEntity;
|
import com.atsuishio.superbwarfare.block.entity.ChargingStationBlockEntity;
|
|
@ -1,4 +1,4 @@
|
||||||
package com.atsuishio.superbwarfare.block.menu;
|
package com.atsuishio.superbwarfare.menu;
|
||||||
|
|
||||||
import com.atsuishio.superbwarfare.init.ModBlocks;
|
import com.atsuishio.superbwarfare.init.ModBlocks;
|
||||||
import com.atsuishio.superbwarfare.init.ModMenuTypes;
|
import com.atsuishio.superbwarfare.init.ModMenuTypes;
|
|
@ -0,0 +1,80 @@
|
||||||
|
package com.atsuishio.superbwarfare.menu;
|
||||||
|
|
||||||
|
import com.atsuishio.superbwarfare.entity.SpeedboatEntity;
|
||||||
|
import com.atsuishio.superbwarfare.init.ModMenuTypes;
|
||||||
|
import net.minecraft.world.Container;
|
||||||
|
import net.minecraft.world.SimpleContainer;
|
||||||
|
import net.minecraft.world.entity.player.Inventory;
|
||||||
|
import net.minecraft.world.entity.player.Player;
|
||||||
|
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||||
|
import net.minecraft.world.inventory.Slot;
|
||||||
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
|
||||||
|
public class SpeedboatMenu extends AbstractContainerMenu {
|
||||||
|
|
||||||
|
private final Container container;
|
||||||
|
private final int containerRows;
|
||||||
|
|
||||||
|
public static final int X_OFFSET = 72;
|
||||||
|
public static final int Y_OFFSET = 20;
|
||||||
|
|
||||||
|
public SpeedboatMenu(int pContainerId, Inventory pPlayerInventory) {
|
||||||
|
this(pContainerId, pPlayerInventory, new SimpleContainer(SpeedboatEntity.CONTAINER_SIZE));
|
||||||
|
}
|
||||||
|
|
||||||
|
public SpeedboatMenu(int pContainerId, Inventory pPlayerInventory, Container pContainer) {
|
||||||
|
super(ModMenuTypes.SPEEDBOAT_MENU.get(), pContainerId);
|
||||||
|
|
||||||
|
checkContainerSize(pContainer, SpeedboatEntity.CONTAINER_SIZE);
|
||||||
|
this.container = pContainer;
|
||||||
|
this.containerRows = 6;
|
||||||
|
pContainer.startOpen(pPlayerInventory.player);
|
||||||
|
int i = (this.containerRows - 4) * 18;
|
||||||
|
|
||||||
|
for (int j = 0; j < this.containerRows; ++j) {
|
||||||
|
for (int k = 0; k < 17; ++k) {
|
||||||
|
this.addSlot(new Slot(pContainer, k + j * 9, 8 + k * 18, 18 + j * 18));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int l = 0; l < 3; ++l) {
|
||||||
|
for (int j = 0; j < 9; ++j) {
|
||||||
|
this.addSlot(new Slot(pPlayerInventory, j + l * 9 + 9, 8 + j * 18 + X_OFFSET, 84 + l * 18 + Y_OFFSET + i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int k = 0; k < 9; ++k) {
|
||||||
|
this.addSlot(new Slot(pPlayerInventory, k, 8 + k * 18 + X_OFFSET, 142 + Y_OFFSET + i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ItemStack quickMoveStack(Player pPlayer, int pIndex) {
|
||||||
|
ItemStack itemstack = ItemStack.EMPTY;
|
||||||
|
Slot slot = this.slots.get(pIndex);
|
||||||
|
if (slot.hasItem()) {
|
||||||
|
ItemStack itemstack1 = slot.getItem();
|
||||||
|
itemstack = itemstack1.copy();
|
||||||
|
if (pIndex < this.containerRows * 17) {
|
||||||
|
if (!this.moveItemStackTo(itemstack1, this.containerRows * 17, this.slots.size(), true)) {
|
||||||
|
return ItemStack.EMPTY;
|
||||||
|
}
|
||||||
|
} else if (!this.moveItemStackTo(itemstack1, 0, this.containerRows * 17, false)) {
|
||||||
|
return ItemStack.EMPTY;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (itemstack1.isEmpty()) {
|
||||||
|
slot.setByPlayer(ItemStack.EMPTY);
|
||||||
|
} else {
|
||||||
|
slot.setChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return itemstack;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean stillValid(Player pPlayer) {
|
||||||
|
return this.container.stillValid(pPlayer);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,10 +1,10 @@
|
||||||
package com.atsuishio.superbwarfare.network;
|
package com.atsuishio.superbwarfare.network;
|
||||||
|
|
||||||
import com.atsuishio.superbwarfare.block.menu.ChargingStationMenu;
|
|
||||||
import com.atsuishio.superbwarfare.client.screens.CrossHairOverlay;
|
import com.atsuishio.superbwarfare.client.screens.CrossHairOverlay;
|
||||||
import com.atsuishio.superbwarfare.client.screens.DroneUIOverlay;
|
import com.atsuishio.superbwarfare.client.screens.DroneUIOverlay;
|
||||||
import com.atsuishio.superbwarfare.config.client.KillMessageConfig;
|
import com.atsuishio.superbwarfare.config.client.KillMessageConfig;
|
||||||
import com.atsuishio.superbwarfare.event.KillMessageHandler;
|
import com.atsuishio.superbwarfare.event.KillMessageHandler;
|
||||||
|
import com.atsuishio.superbwarfare.menu.ChargingStationMenu;
|
||||||
import com.atsuishio.superbwarfare.network.message.ClientIndicatorMessage;
|
import com.atsuishio.superbwarfare.network.message.ClientIndicatorMessage;
|
||||||
import com.atsuishio.superbwarfare.network.message.ContainerDataMessage;
|
import com.atsuishio.superbwarfare.network.message.ContainerDataMessage;
|
||||||
import com.atsuishio.superbwarfare.network.message.GunsDataMessage;
|
import com.atsuishio.superbwarfare.network.message.GunsDataMessage;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package com.atsuishio.superbwarfare.network.message;
|
package com.atsuishio.superbwarfare.network.message;
|
||||||
|
|
||||||
import com.atsuishio.superbwarfare.block.menu.ReforgingTableMenu;
|
import com.atsuishio.superbwarfare.menu.ReforgingTableMenu;
|
||||||
import net.minecraft.network.FriendlyByteBuf;
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package com.atsuishio.superbwarfare.network.message;
|
package com.atsuishio.superbwarfare.network.message;
|
||||||
|
|
||||||
import com.atsuishio.superbwarfare.block.menu.ReforgingTableMenu;
|
import com.atsuishio.superbwarfare.menu.ReforgingTableMenu;
|
||||||
import com.atsuishio.superbwarfare.perk.Perk;
|
import com.atsuishio.superbwarfare.perk.Perk;
|
||||||
import net.minecraft.network.FriendlyByteBuf;
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 1.5 KiB |
Loading…
Add table
Reference in a new issue