添加基础雷达data access
This commit is contained in:
parent
c055a204ec
commit
0ba08773ec
6 changed files with 158 additions and 79 deletions
|
@ -2,6 +2,7 @@ package com.atsuishio.superbwarfare.block.entity;
|
||||||
|
|
||||||
import com.atsuishio.superbwarfare.init.ModBlockEntities;
|
import com.atsuishio.superbwarfare.init.ModBlockEntities;
|
||||||
import com.atsuishio.superbwarfare.menu.FuMO25Menu;
|
import com.atsuishio.superbwarfare.menu.FuMO25Menu;
|
||||||
|
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;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
|
@ -30,11 +31,40 @@ public class FuMO25BlockEntity extends BlockEntity implements MenuProvider {
|
||||||
public static final int DEFAULT_RANGE = 96;
|
public static final int DEFAULT_RANGE = 96;
|
||||||
public static final int MAX_RANGE = 128;
|
public static final int MAX_RANGE = 128;
|
||||||
|
|
||||||
|
public static final int MAX_DATA_COUNT = 3;
|
||||||
|
|
||||||
private LazyOptional<EnergyStorage> energyHandler;
|
private LazyOptional<EnergyStorage> energyHandler;
|
||||||
|
|
||||||
public FuncType type = FuncType.NORMAL;
|
public FuncType type = FuncType.NORMAL;
|
||||||
public int time = 0;
|
public int time = 0;
|
||||||
|
|
||||||
|
protected final ContainerEnergyData dataAccess = new ContainerEnergyData() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long get(int pIndex) {
|
||||||
|
return switch (pIndex) {
|
||||||
|
case 0 -> FuMO25BlockEntity.this.energyHandler.map(EnergyStorage::getEnergyStored).orElse(0);
|
||||||
|
case 1 -> FuMO25BlockEntity.this.type.ordinal();
|
||||||
|
case 2 -> FuMO25BlockEntity.this.time;
|
||||||
|
default -> 0;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void set(int pIndex, long pValue) {
|
||||||
|
switch (pIndex) {
|
||||||
|
case 0 -> FuMO25BlockEntity.this.energyHandler.ifPresent(handler -> handler.receiveEnergy((int) pValue, false));
|
||||||
|
case 1 -> FuMO25BlockEntity.this.type = FuncType.values()[(int) pValue];
|
||||||
|
case 2 -> FuMO25BlockEntity.this.time = (int) pValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getCount() {
|
||||||
|
return MAX_DATA_COUNT;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
public FuMO25BlockEntity(BlockPos pPos, BlockState pBlockState) {
|
public FuMO25BlockEntity(BlockPos pPos, BlockState pBlockState) {
|
||||||
super(ModBlockEntities.FUMO_25.get(), pPos, pBlockState);
|
super(ModBlockEntities.FUMO_25.get(), pPos, pBlockState);
|
||||||
this.energyHandler = LazyOptional.of(() -> new EnergyStorage(MAX_ENERGY));
|
this.energyHandler = LazyOptional.of(() -> new EnergyStorage(MAX_ENERGY));
|
||||||
|
@ -70,14 +100,14 @@ public class FuMO25BlockEntity extends BlockEntity implements MenuProvider {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Component getDisplayName() {
|
public Component getDisplayName() {
|
||||||
return Component.translatable("container.superbwarfare.fumo_25");
|
return Component.literal("");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public AbstractContainerMenu createMenu(int pContainerId, Inventory pPlayerInventory, Player pPlayer) {
|
public AbstractContainerMenu createMenu(int pContainerId, Inventory pPlayerInventory, Player pPlayer) {
|
||||||
if (this.level == null) return null;
|
if (this.level == null) return null;
|
||||||
return new FuMO25Menu(pContainerId, pPlayerInventory, ContainerLevelAccess.create(this.level, this.getBlockPos()));
|
return new FuMO25Menu(pContainerId, pPlayerInventory, ContainerLevelAccess.create(this.level, this.getBlockPos()), this.dataAccess);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package com.atsuishio.superbwarfare.client.screens;
|
package com.atsuishio.superbwarfare.client.screens;
|
||||||
|
|
||||||
import com.atsuishio.superbwarfare.ModUtils;
|
import com.atsuishio.superbwarfare.ModUtils;
|
||||||
|
import com.atsuishio.superbwarfare.block.entity.FuMO25BlockEntity;
|
||||||
import com.atsuishio.superbwarfare.menu.FuMO25Menu;
|
import com.atsuishio.superbwarfare.menu.FuMO25Menu;
|
||||||
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;
|
||||||
|
@ -27,6 +28,22 @@ public class FuMO25Screen extends AbstractContainerScreen<FuMO25Menu> {
|
||||||
int i = (this.width - this.imageWidth) / 2;
|
int i = (this.width - this.imageWidth) / 2;
|
||||||
int j = (this.height - this.imageHeight) / 2;
|
int j = (this.height - this.imageHeight) / 2;
|
||||||
pGuiGraphics.blit(TEXTURE, i, j, 0, 0, this.imageWidth, this.imageHeight, 358, 328);
|
pGuiGraphics.blit(TEXTURE, i, j, 0, 0, this.imageWidth, this.imageHeight, 358, 328);
|
||||||
|
|
||||||
|
// 扫描盘
|
||||||
|
renderScan(pGuiGraphics, pPartialTick);
|
||||||
|
|
||||||
|
// 网格线
|
||||||
|
pGuiGraphics.blit(TEXTURE, i + 8, j + 11, 0, 167, 147, 147, 358, 328);
|
||||||
|
|
||||||
|
// FE
|
||||||
|
long energy = FuMO25Screen.this.menu.getEnergy();
|
||||||
|
float energyRate = (float) energy / (float) FuMO25BlockEntity.MAX_ENERGY;
|
||||||
|
pGuiGraphics.blit(TEXTURE, i + 278, j + 39, 178, 167, (int) (54 * energyRate), 16, 358, 328);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void renderScan(GuiGraphics guiGraphics, float partialTick) {
|
||||||
|
if (FuMO25Screen.this.menu.getEnergy() <= 0) return;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,41 +1,25 @@
|
||||||
package com.atsuishio.superbwarfare.menu;
|
package com.atsuishio.superbwarfare.menu;
|
||||||
|
|
||||||
import com.atsuishio.superbwarfare.ModUtils;
|
|
||||||
import com.atsuishio.superbwarfare.block.entity.ChargingStationBlockEntity;
|
import com.atsuishio.superbwarfare.block.entity.ChargingStationBlockEntity;
|
||||||
import com.atsuishio.superbwarfare.init.ModMenuTypes;
|
import com.atsuishio.superbwarfare.init.ModMenuTypes;
|
||||||
import com.atsuishio.superbwarfare.network.dataslot.ContainerEnergyData;
|
import com.atsuishio.superbwarfare.network.dataslot.ContainerEnergyData;
|
||||||
import com.atsuishio.superbwarfare.network.dataslot.ContainerEnergyDataSlot;
|
|
||||||
import com.atsuishio.superbwarfare.network.dataslot.SimpleEnergyData;
|
import com.atsuishio.superbwarfare.network.dataslot.SimpleEnergyData;
|
||||||
import com.atsuishio.superbwarfare.network.message.ContainerDataMessage;
|
|
||||||
import com.google.common.collect.Lists;
|
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
|
||||||
import net.minecraft.world.Container;
|
import net.minecraft.world.Container;
|
||||||
import net.minecraft.world.SimpleContainer;
|
import net.minecraft.world.SimpleContainer;
|
||||||
import net.minecraft.world.entity.player.Inventory;
|
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.inventory.AbstractContainerMenu;
|
|
||||||
import net.minecraft.world.inventory.Slot;
|
import net.minecraft.world.inventory.Slot;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.item.crafting.RecipeType;
|
import net.minecraft.world.item.crafting.RecipeType;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
import net.minecraftforge.common.ForgeHooks;
|
import net.minecraftforge.common.ForgeHooks;
|
||||||
import net.minecraftforge.common.capabilities.ForgeCapabilities;
|
import net.minecraftforge.common.capabilities.ForgeCapabilities;
|
||||||
import net.minecraftforge.event.entity.player.PlayerContainerEvent;
|
|
||||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
|
||||||
import net.minecraftforge.fml.common.Mod;
|
|
||||||
import net.minecraftforge.network.PacketDistributor;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
public class ChargingStationMenu extends EnergyMenu {
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.FORGE)
|
|
||||||
public class ChargingStationMenu extends AbstractContainerMenu {
|
|
||||||
|
|
||||||
private final Container container;
|
private final Container container;
|
||||||
private final ContainerEnergyData containerData;
|
private final ContainerEnergyData containerData;
|
||||||
protected final Level level;
|
protected final Level level;
|
||||||
private final List<ContainerEnergyDataSlot> containerEnergyDataSlots = Lists.newArrayList();
|
|
||||||
private final List<ServerPlayer> usingPlayers = new ArrayList<>();
|
|
||||||
|
|
||||||
public static final int X_OFFSET = 0;
|
public static final int X_OFFSET = 0;
|
||||||
public static final int Y_OFFSET = 0;
|
public static final int Y_OFFSET = 0;
|
||||||
|
@ -45,7 +29,7 @@ public class ChargingStationMenu extends AbstractContainerMenu {
|
||||||
}
|
}
|
||||||
|
|
||||||
public ChargingStationMenu(int id, Inventory inventory, Container container, ContainerEnergyData containerData) {
|
public ChargingStationMenu(int id, Inventory inventory, Container container, ContainerEnergyData containerData) {
|
||||||
super(ModMenuTypes.CHARGING_STATION_MENU.get(), id);
|
super(ModMenuTypes.CHARGING_STATION_MENU.get(), id, containerData);
|
||||||
|
|
||||||
checkContainerSize(container, 2);
|
checkContainerSize(container, 2);
|
||||||
|
|
||||||
|
@ -65,35 +49,6 @@ public class ChargingStationMenu extends AbstractContainerMenu {
|
||||||
for (int k = 0; k < 9; ++k) {
|
for (int k = 0; k < 9; ++k) {
|
||||||
this.addSlot(new Slot(inventory, k, 8 + k * 18 + X_OFFSET, 142 + Y_OFFSET));
|
this.addSlot(new Slot(inventory, k, 8 + k * 18 + X_OFFSET, 142 + Y_OFFSET));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < containerData.getCount(); ++i) {
|
|
||||||
this.containerEnergyDataSlots.add(ContainerEnergyDataSlot.forContainer(containerData, i));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void broadcastChanges() {
|
|
||||||
List<ContainerDataMessage.Pair> pairs = new ArrayList<>();
|
|
||||||
for (int i = 0; i < containerEnergyDataSlots.size(); ++i) {
|
|
||||||
ContainerEnergyDataSlot dataSlot = containerEnergyDataSlots.get(i);
|
|
||||||
if (dataSlot.checkAndClearUpdateFlag())
|
|
||||||
pairs.add(new ContainerDataMessage.Pair(i, dataSlot.get()));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!pairs.isEmpty()) {
|
|
||||||
PacketDistributor.PacketTarget target = PacketDistributor.NMLIST.with(usingPlayers.stream().map(serverPlayer -> serverPlayer.connection.connection)::toList);
|
|
||||||
ModUtils.PACKET_HANDLER.send(target, new ContainerDataMessage(this.containerId, pairs));
|
|
||||||
}
|
|
||||||
|
|
||||||
super.broadcastChanges();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setData(int id, int data) {
|
|
||||||
containerEnergyDataSlots.get(id).set(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setData(int id, long data) {
|
|
||||||
containerEnergyDataSlots.get(id).set(data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -171,25 +126,4 @@ public class ChargingStationMenu extends AbstractContainerMenu {
|
||||||
return super.mayPlace(pStack);
|
return super.mayPlace(pStack);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
|
||||||
public static void onContainerOpened(PlayerContainerEvent.Open event) {
|
|
||||||
if (event.getContainer() instanceof ChargingStationMenu menu && event.getEntity() instanceof ServerPlayer serverPlayer) {
|
|
||||||
menu.usingPlayers.add(serverPlayer);
|
|
||||||
|
|
||||||
List<ContainerDataMessage.Pair> toSync = new ArrayList<>();
|
|
||||||
for (int i = 0; i < menu.containerEnergyDataSlots.size(); ++i) {
|
|
||||||
toSync.add(new ContainerDataMessage.Pair(i, menu.containerEnergyDataSlots.get(i).get()));
|
|
||||||
}
|
|
||||||
|
|
||||||
ModUtils.PACKET_HANDLER.send(PacketDistributor.PLAYER.with(() -> serverPlayer), new ContainerDataMessage(menu.containerId, toSync));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@SubscribeEvent
|
|
||||||
public static void onContainerClosed(PlayerContainerEvent.Close event) {
|
|
||||||
if (event.getContainer() instanceof ChargingStationMenu menu && event.getEntity() instanceof ServerPlayer serverPlayer) {
|
|
||||||
menu.usingPlayers.remove(serverPlayer);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,82 @@
|
||||||
|
package com.atsuishio.superbwarfare.menu;
|
||||||
|
|
||||||
|
import com.atsuishio.superbwarfare.ModUtils;
|
||||||
|
import com.atsuishio.superbwarfare.network.dataslot.ContainerEnergyData;
|
||||||
|
import com.atsuishio.superbwarfare.network.dataslot.ContainerEnergyDataSlot;
|
||||||
|
import com.atsuishio.superbwarfare.network.message.ContainerDataMessage;
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
|
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||||
|
import net.minecraft.world.inventory.MenuType;
|
||||||
|
import net.minecraftforge.event.entity.player.PlayerContainerEvent;
|
||||||
|
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||||
|
import net.minecraftforge.fml.common.Mod;
|
||||||
|
import net.minecraftforge.network.PacketDistributor;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.FORGE)
|
||||||
|
public abstract class EnergyMenu extends AbstractContainerMenu {
|
||||||
|
|
||||||
|
private final List<ContainerEnergyDataSlot> containerEnergyDataSlots = Lists.newArrayList();
|
||||||
|
private final List<ServerPlayer> usingPlayers = new ArrayList<>();
|
||||||
|
|
||||||
|
public EnergyMenu(@Nullable MenuType<?> pMenuType, int pContainerId) {
|
||||||
|
super(pMenuType, pContainerId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EnergyMenu(@Nullable MenuType<?> pMenuType, int id, ContainerEnergyData containerData) {
|
||||||
|
super(pMenuType, id);
|
||||||
|
|
||||||
|
for (int i = 0; i < containerData.getCount(); ++i) {
|
||||||
|
this.containerEnergyDataSlots.add(ContainerEnergyDataSlot.forContainer(containerData, i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void broadcastChanges() {
|
||||||
|
List<ContainerDataMessage.Pair> pairs = new ArrayList<>();
|
||||||
|
for (int i = 0; i < this.containerEnergyDataSlots.size(); ++i) {
|
||||||
|
ContainerEnergyDataSlot dataSlot = this.containerEnergyDataSlots.get(i);
|
||||||
|
if (dataSlot.checkAndClearUpdateFlag())
|
||||||
|
pairs.add(new ContainerDataMessage.Pair(i, dataSlot.get()));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!pairs.isEmpty()) {
|
||||||
|
PacketDistributor.PacketTarget target = PacketDistributor.NMLIST.with(this.usingPlayers.stream().map(serverPlayer -> serverPlayer.connection.connection)::toList);
|
||||||
|
ModUtils.PACKET_HANDLER.send(target, new ContainerDataMessage(this.containerId, pairs));
|
||||||
|
}
|
||||||
|
|
||||||
|
super.broadcastChanges();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setData(int id, int data) {
|
||||||
|
this.containerEnergyDataSlots.get(id).set(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setData(int id, long data) {
|
||||||
|
this.containerEnergyDataSlots.get(id).set(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public static void onContainerOpened(PlayerContainerEvent.Open event) {
|
||||||
|
if (event.getContainer() instanceof EnergyMenu menu && event.getEntity() instanceof ServerPlayer serverPlayer) {
|
||||||
|
menu.usingPlayers.add(serverPlayer);
|
||||||
|
|
||||||
|
List<ContainerDataMessage.Pair> toSync = new ArrayList<>();
|
||||||
|
for (int i = 0; i < menu.containerEnergyDataSlots.size(); ++i) {
|
||||||
|
toSync.add(new ContainerDataMessage.Pair(i, menu.containerEnergyDataSlots.get(i).get()));
|
||||||
|
}
|
||||||
|
ModUtils.PACKET_HANDLER.send(PacketDistributor.PLAYER.with(() -> serverPlayer), new ContainerDataMessage(menu.containerId, toSync));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public static void onContainerClosed(PlayerContainerEvent.Close event) {
|
||||||
|
if (event.getContainer() instanceof EnergyMenu menu && event.getEntity() instanceof ServerPlayer serverPlayer) {
|
||||||
|
menu.usingPlayers.remove(serverPlayer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,24 +1,27 @@
|
||||||
package com.atsuishio.superbwarfare.menu;
|
package com.atsuishio.superbwarfare.menu;
|
||||||
|
|
||||||
|
import com.atsuishio.superbwarfare.block.entity.FuMO25BlockEntity;
|
||||||
import com.atsuishio.superbwarfare.init.ModBlocks;
|
import com.atsuishio.superbwarfare.init.ModBlocks;
|
||||||
import com.atsuishio.superbwarfare.init.ModItems;
|
import com.atsuishio.superbwarfare.init.ModItems;
|
||||||
import com.atsuishio.superbwarfare.init.ModMenuTypes;
|
import com.atsuishio.superbwarfare.init.ModMenuTypes;
|
||||||
|
import com.atsuishio.superbwarfare.network.dataslot.ContainerEnergyData;
|
||||||
|
import com.atsuishio.superbwarfare.network.dataslot.SimpleEnergyData;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.world.Container;
|
import net.minecraft.world.Container;
|
||||||
import net.minecraft.world.SimpleContainer;
|
import net.minecraft.world.SimpleContainer;
|
||||||
import net.minecraft.world.entity.player.Inventory;
|
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.inventory.AbstractContainerMenu;
|
|
||||||
import net.minecraft.world.inventory.ContainerLevelAccess;
|
import net.minecraft.world.inventory.ContainerLevelAccess;
|
||||||
import net.minecraft.world.inventory.Slot;
|
import net.minecraft.world.inventory.Slot;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
public class FuMO25Menu extends AbstractContainerMenu {
|
public class FuMO25Menu extends EnergyMenu {
|
||||||
|
|
||||||
protected final Container container;
|
protected final Container container;
|
||||||
protected final ContainerLevelAccess access;
|
protected final ContainerLevelAccess access;
|
||||||
|
protected final ContainerEnergyData containerData;
|
||||||
|
|
||||||
private int posX = Integer.MIN_VALUE;
|
private int posX = Integer.MIN_VALUE;
|
||||||
private int posY = Integer.MIN_VALUE;
|
private int posY = Integer.MIN_VALUE;
|
||||||
|
@ -28,20 +31,21 @@ public class FuMO25Menu extends AbstractContainerMenu {
|
||||||
public static final int Y_OFFSET = 0;
|
public static final int Y_OFFSET = 0;
|
||||||
|
|
||||||
public FuMO25Menu(int pContainerId, Inventory pPlayerInventory) {
|
public FuMO25Menu(int pContainerId, Inventory pPlayerInventory) {
|
||||||
this(pContainerId, pPlayerInventory, new SimpleContainer(1), ContainerLevelAccess.NULL);
|
this(pContainerId, pPlayerInventory, new SimpleContainer(1), ContainerLevelAccess.NULL, new SimpleEnergyData(FuMO25BlockEntity.MAX_DATA_COUNT));
|
||||||
}
|
}
|
||||||
|
|
||||||
public FuMO25Menu(int pContainerId, Inventory pPlayerInventory, ContainerLevelAccess access) {
|
public FuMO25Menu(int pContainerId, Inventory pPlayerInventory, ContainerLevelAccess access, ContainerEnergyData containerData) {
|
||||||
this(pContainerId, pPlayerInventory, new SimpleContainer(1), access);
|
this(pContainerId, pPlayerInventory, new SimpleContainer(1), access, containerData);
|
||||||
}
|
}
|
||||||
|
|
||||||
public FuMO25Menu(int pContainerId, Inventory inventory, Container container, ContainerLevelAccess access) {
|
public FuMO25Menu(int pContainerId, Inventory inventory, Container container, ContainerLevelAccess access, ContainerEnergyData containerData) {
|
||||||
super(ModMenuTypes.FUMO_25_MENU.get(), pContainerId);
|
super(ModMenuTypes.FUMO_25_MENU.get(), pContainerId, containerData);
|
||||||
|
|
||||||
checkContainerSize(container, 1);
|
checkContainerSize(container, 1);
|
||||||
|
|
||||||
this.container = container;
|
this.container = container;
|
||||||
this.access = access;
|
this.access = access;
|
||||||
|
this.containerData = containerData;
|
||||||
|
|
||||||
this.addSlot(new ParaSlot(container, 0, 278, 60));
|
this.addSlot(new ParaSlot(container, 0, 278, 60));
|
||||||
|
|
||||||
|
@ -145,6 +149,18 @@ public class FuMO25Menu extends AbstractContainerMenu {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public long getEnergy() {
|
||||||
|
return this.containerData.get(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getFuncType() {
|
||||||
|
return this.containerData.get(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getTime() {
|
||||||
|
return this.containerData.get(2);
|
||||||
|
}
|
||||||
|
|
||||||
static class ParaSlot extends Slot {
|
static class ParaSlot extends Slot {
|
||||||
|
|
||||||
public ParaSlot(Container pContainer, int pSlot, int pX, int pY) {
|
public ParaSlot(Container pContainer, int pSlot, int pX, int pY) {
|
||||||
|
|
|
@ -4,7 +4,7 @@ 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.menu.EnergyMenu;
|
||||||
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;
|
||||||
|
@ -58,7 +58,7 @@ public class ClientPacketHandler {
|
||||||
if (ctx.get().getDirection().getReceptionSide() == LogicalSide.CLIENT) {
|
if (ctx.get().getDirection().getReceptionSide() == LogicalSide.CLIENT) {
|
||||||
Minecraft mc = Minecraft.getInstance();
|
Minecraft mc = Minecraft.getInstance();
|
||||||
if (mc.player != null && mc.player.containerMenu.containerId == containerId) {
|
if (mc.player != null && mc.player.containerMenu.containerId == containerId) {
|
||||||
data.forEach(p -> ((ChargingStationMenu) mc.player.containerMenu).setData(p.id, p.data));
|
data.forEach(p -> ((EnergyMenu) mc.player.containerMenu).setData(p.id, p.data));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue