mirror of
https://github.com/RoBaertschi/EnvironmentTech.git
synced 2025-04-19 23:03:28 +00:00
fixed up the env collector, still WIP
This commit is contained in:
parent
bd31a84c53
commit
687de6b267
@ -1,7 +1,9 @@
|
||||
package robaertschi.environmenttech.client.screen;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
|
||||
import net.minecraft.client.renderer.GameRenderer;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
@ -14,7 +16,7 @@ public class EnvCollectorScreen extends AbstractContainerScreen<EnvCollectorMenu
|
||||
|
||||
public EnvCollectorScreen(EnvCollectorMenu pMenu, Inventory pPlayerInventory, Component pTitle) {
|
||||
super(pMenu, pPlayerInventory, pTitle);
|
||||
// this.inventoryLabelY = this.imageHeight - 110;
|
||||
this.inventoryLabelY = this.imageHeight - 94;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -22,5 +24,19 @@ public class EnvCollectorScreen extends AbstractContainerScreen<EnvCollectorMenu
|
||||
int relX = (this.width - this.imageWidth) / 2;
|
||||
int relY = (this.height - this.imageHeight) / 2;
|
||||
pGuiGraphics.blit(GUI, relX, relY, 0, 0, this.imageWidth, this.imageHeight);
|
||||
|
||||
pGuiGraphics.blit(ProgressArrowComponent.SPRITE,
|
||||
relX + 78, relY + 35,
|
||||
0, 0,
|
||||
ProgressArrowComponent.getScaledProgress(menu.getProgress(), menu.getMaxProgress()),16,
|
||||
24,
|
||||
16
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(@NotNull GuiGraphics pGuiGraphics, int pMouseX, int pMouseY, float pPartialTick) {
|
||||
super.render(pGuiGraphics, pMouseX, pMouseY, pPartialTick);
|
||||
this.renderTooltip(pGuiGraphics, pMouseX, pMouseY);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,21 @@
|
||||
package robaertschi.environmenttech.client.screen;
|
||||
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.Mth;
|
||||
import robaertschi.environmenttech.EnvironmentTech;
|
||||
|
||||
public class ProgressArrowComponent {
|
||||
public static final ResourceLocation SPRITE = EnvironmentTech.id("textures/gui/sprites/component/progress_arrow.png");
|
||||
|
||||
public static void draw(GuiGraphics guiGraphics, int x, int y, int progress) {
|
||||
int j1 = Mth.ceil(progress * 22.0F);
|
||||
guiGraphics.blit(SPRITE, x, y, 1, 0, 0, 0, 0, 22, 16);
|
||||
}
|
||||
|
||||
public static int getScaledProgress(int progress, int maxProgress) {
|
||||
int progressArrowSize = 24; // This is the height in pixels of your arrow
|
||||
|
||||
return maxProgress != 0 && progress != 0 ? progress * progressArrowSize / maxProgress : 0;
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
package robaertschi.environmenttech.level;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.minecraft.world.level.chunk.LevelChunk;
|
||||
import net.minecraft.world.level.chunk.status.ChunkStatus;
|
||||
import net.neoforged.bus.api.SubscribeEvent;
|
||||
@ -10,6 +11,7 @@ import robaertschi.environmenttech.EnvironmentTech;
|
||||
import robaertschi.environmenttech.data.attachments.ETAttachments;
|
||||
|
||||
@EventBusSubscriber(modid = EnvironmentTech.MODID)
|
||||
@Slf4j(topic = "EnvironmentTech/ChunkData")
|
||||
public class ETChunkEvents {
|
||||
@SubscribeEvent()
|
||||
public static void onChunkLoad(ChunkEvent.Load event) {
|
||||
@ -19,11 +21,11 @@ public class ETChunkEvents {
|
||||
return;
|
||||
}
|
||||
int random = event.getLevel().getRandom().nextIntBetweenInclusive(Config.minEnvForNewChunk, Config.maxEnvForNewChunk);
|
||||
EnvironmentTech.LOGGER.debug("New Chunk at pos {}, set random to {}", event.getChunk().getPos(), random);
|
||||
log.debug("New Chunk at pos {}, set random to {}", event.getChunk().getPos(), random);
|
||||
event.getChunk().setData(ETAttachments.ENV, (long)random);
|
||||
} else if (!event.getChunk().hasData(ETAttachments.ENV)) {
|
||||
int random = event.getLevel().getRandom().nextIntBetweenInclusive(Config.minEnvForNewChunk, Config.maxEnvForNewChunk);
|
||||
EnvironmentTech.LOGGER.debug("Chunk without data at pos {}, set random to {}",event.getChunk().getPos(), random);
|
||||
log.debug("Chunk without data at pos {}, set random to {}",event.getChunk().getPos(), random);
|
||||
event.getChunk().setData(ETAttachments.ENV, (long)random);
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package robaertschi.environmenttech.level.block;
|
||||
import com.mojang.serialization.MapCodec;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.network.RegistryFriendlyByteBuf;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
@ -66,18 +67,7 @@ public class EnvCollectorBlock extends BaseEntityBlock {
|
||||
if (!pLevel.isClientSide) {
|
||||
BlockEntity be = pLevel.getBlockEntity(pPos);
|
||||
if (be instanceof EnvCollectorBlockEntity) {
|
||||
MenuProvider containerProvider = new MenuProvider() {
|
||||
@Override
|
||||
public @NotNull Component getDisplayName() {
|
||||
return Component.translatable("environmenttech.screen.env_collector");
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull AbstractContainerMenu createMenu(int pContainerId, Inventory pPlayerInventory, Player pPlayer) {
|
||||
return new EnvCollectorMenu(pContainerId, pPlayer, pPos);
|
||||
}
|
||||
};
|
||||
pPlayer.openMenu(containerProvider, buf -> buf.writeBlockPos(pPos));
|
||||
pPlayer.openMenu((MenuProvider) be, pPos);
|
||||
} else {
|
||||
throw new IllegalStateException("Our named container provider is missing!");
|
||||
}
|
||||
|
@ -5,7 +5,17 @@ import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.HolderLookup;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.Connection;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.protocol.Packet;
|
||||
import net.minecraft.network.protocol.game.ClientGamePacketListener;
|
||||
import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.MenuProvider;
|
||||
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.ContainerData;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
@ -20,10 +30,11 @@ import robaertschi.environmenttech.data.capabilities.EnvStorage;
|
||||
import robaertschi.environmenttech.data.capabilities.EnvType;
|
||||
import robaertschi.environmenttech.data.recipes.ETRecipes;
|
||||
import robaertschi.environmenttech.data.recipes.EnvCollectorRecipe;
|
||||
import robaertschi.environmenttech.menu.EnvCollectorMenu;
|
||||
|
||||
import static robaertschi.environmenttech.EnvironmentTech.MODID;
|
||||
|
||||
public class EnvCollectorBlockEntity extends BlockEntity {
|
||||
public class EnvCollectorBlockEntity extends BlockEntity implements MenuProvider {
|
||||
public static final int SLOT_INPUT = 0;
|
||||
public static final int SLOT_INPUT_COUNT = 1;
|
||||
|
||||
@ -36,8 +47,11 @@ public class EnvCollectorBlockEntity extends BlockEntity {
|
||||
private final ItemStackHandler inventory = new ItemStackHandler(2) {
|
||||
@Override
|
||||
protected void onContentsChanged(int slot) {
|
||||
super.onContentsChanged(slot);
|
||||
EnvCollectorBlockEntity.this.setChanged();
|
||||
assert level != null;
|
||||
if (!level.isClientSide()) {
|
||||
level.sendBlockUpdated(getBlockPos(), getBlockState(), getBlockState(), 3);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -53,12 +67,21 @@ public class EnvCollectorBlockEntity extends BlockEntity {
|
||||
private final EnvStorage envStorage = new EnvStorage(EnvType.Chunk, 64, 0, 1) {
|
||||
@Override
|
||||
public void onContentsChanged() {
|
||||
super.onContentsChanged();
|
||||
EnvCollectorBlockEntity.this.setChanged();
|
||||
assert level != null;
|
||||
if (!level.isClientSide()) {
|
||||
level.sendBlockUpdated(getBlockPos(), getBlockState(), getBlockState(), 3);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@Getter
|
||||
private ContainerData data;
|
||||
|
||||
@Getter
|
||||
private int progress = 0;
|
||||
@Getter
|
||||
private int maxProgress = 10;
|
||||
// Every 20 ticks, we take ENV from the current Chunk
|
||||
private int takeEnv = 0;
|
||||
@Nullable
|
||||
@ -67,6 +90,29 @@ public class EnvCollectorBlockEntity extends BlockEntity {
|
||||
|
||||
public EnvCollectorBlockEntity(BlockPos pos, BlockState state) {
|
||||
super(ETBlockEntities.ENV_COLLECTOR_BLOCK_ENTITY.get(), pos, state);
|
||||
this.data = new ContainerData() {
|
||||
@Override
|
||||
public int get(int pIndex) {
|
||||
return switch(pIndex) {
|
||||
case 0 -> EnvCollectorBlockEntity.this.progress;
|
||||
case 1 -> EnvCollectorBlockEntity.this.maxProgress;
|
||||
default -> 0;
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(int pIndex, int pValue) {
|
||||
switch (pIndex) {
|
||||
case 0 -> EnvCollectorBlockEntity.this.progress = pValue;
|
||||
case 1 -> EnvCollectorBlockEntity.this.maxProgress = pValue;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return 2;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -118,18 +164,20 @@ public class EnvCollectorBlockEntity extends BlockEntity {
|
||||
}
|
||||
|
||||
if (hasRecipe(level)) {
|
||||
if (progress > 0 && progress < 60) {
|
||||
if (progress > 0 && progress < getMaxProgress()) {
|
||||
progress++;
|
||||
} else if (progress > 0) {
|
||||
produce(level);
|
||||
progress = 0;
|
||||
} else {
|
||||
} else if (getOutputItem().getCount() < getOutputItem().getMaxStackSize()){
|
||||
assert currentRecipe != null;
|
||||
if (envStorage.getEnvStored() >= currentRecipe.envUsed()) {
|
||||
envStorage.setEnvStored(envStorage.getEnvStored() - currentRecipe.envUsed());
|
||||
// if (envStorage.getEnvStored() >= currentRecipe.envUsed()) {
|
||||
// envStorage.setEnvStored(envStorage.getEnvStored() - currentRecipe.envUsed());
|
||||
// progress = 1;
|
||||
// }
|
||||
|
||||
progress = 1;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -138,7 +186,13 @@ public class EnvCollectorBlockEntity extends BlockEntity {
|
||||
getInputItem().setCount(getInputItem().getCount() - 1);
|
||||
// Is safe, as hasRecipe already checked
|
||||
assert currentRecipe != null;
|
||||
|
||||
if (getOutputItem().isEmpty()) {
|
||||
setOutputItem(currentRecipe.assemble(recipeWrapper, level.registryAccess()));
|
||||
} else {
|
||||
getOutputItem().setCount(getOutputItem().getCount() + 1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private boolean hasRecipe(Level level) {
|
||||
@ -156,4 +210,31 @@ public class EnvCollectorBlockEntity extends BlockEntity {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Packet<ClientGamePacketListener> getUpdatePacket() {
|
||||
return ClientboundBlockEntityDataPacket.create(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull CompoundTag getUpdateTag(HolderLookup.@NotNull Provider pRegistries) {
|
||||
return saveWithoutMetadata(pRegistries);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDataPacket(@NotNull Connection net, @NotNull ClientboundBlockEntityDataPacket pkt, HolderLookup.@NotNull Provider lookupProvider) {
|
||||
super.onDataPacket(net, pkt, lookupProvider);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Component getDisplayName() {
|
||||
return Component.translatable("screen.environmenttech.env_collector");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public AbstractContainerMenu createMenu(int pContainerId, @NotNull Inventory pPlayerInventory, @NotNull Player pPlayer) {
|
||||
return new EnvCollectorMenu(pContainerId, pPlayer, this, data);
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ public class ETMenus {
|
||||
public static final DeferredRegister<MenuType<?>> MENUS = DeferredRegister.create(BuiltInRegistries.MENU, MODID);
|
||||
|
||||
public static final DeferredHolder<MenuType<?>, MenuType<EnvCollectorMenu>> ENV_COLLECTOR_MENU = MENUS.register("env_collector", () ->
|
||||
IMenuTypeExtension.create((windowId, inv, data) -> new EnvCollectorMenu(windowId, inv.player, data.readBlockPos())));
|
||||
IMenuTypeExtension.create((windowId, inv, data) -> new EnvCollectorMenu(windowId, inv.player, data)));
|
||||
|
||||
public static void init(IEventBus modEventBus) {
|
||||
MENUS.register(modEventBus);
|
||||
|
@ -1,13 +1,11 @@
|
||||
package robaertschi.environmenttech.menu;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.world.Container;
|
||||
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.ContainerLevelAccess;
|
||||
import net.minecraft.world.inventory.MenuType;
|
||||
import net.minecraft.world.inventory.Slot;
|
||||
import net.minecraft.world.inventory.*;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.neoforged.neoforge.items.SlotItemHandler;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@ -20,16 +18,30 @@ import static robaertschi.environmenttech.level.block.entity.EnvCollectorBlockEn
|
||||
|
||||
public class EnvCollectorMenu extends AbstractContainerMenu {
|
||||
|
||||
private final BlockPos pos;
|
||||
private final EnvCollectorBlockEntity blockEntity;
|
||||
private final ContainerData data;
|
||||
|
||||
public EnvCollectorMenu(int pContainerId, Player player, BlockPos pos) {
|
||||
super(ETMenus.ENV_COLLECTOR_MENU.get(), pContainerId);
|
||||
this.pos = pos;
|
||||
if (player.level().getBlockEntity(pos) instanceof EnvCollectorBlockEntity envCollector) {
|
||||
addSlot(new SlotItemHandler(envCollector.getInventory(), 0, 55, 35));
|
||||
addSlot(new SlotItemHandler(envCollector.getInventory(), 1, 114, 33));
|
||||
public EnvCollectorMenu(int pContainerId, Player player, FriendlyByteBuf buf) {
|
||||
this(pContainerId, player, (EnvCollectorBlockEntity) player.level().getBlockEntity(buf.readBlockPos()), new SimpleContainerData(2));
|
||||
}
|
||||
layoutPlayerInventorySlots(player.getInventory(), 10, 70);
|
||||
|
||||
public EnvCollectorMenu(int pContainerId, Player player, EnvCollectorBlockEntity blockEntity, ContainerData data) {
|
||||
super(ETMenus.ENV_COLLECTOR_MENU.get(), pContainerId);
|
||||
this.blockEntity = blockEntity;
|
||||
this.data = data;
|
||||
addSlot(new SlotItemHandler(blockEntity.getInventory(), 0, 54, 34));
|
||||
addSlot(new SlotItemHandler(blockEntity.getInventory(), 1, 116, 35));
|
||||
layoutPlayerInventorySlots(player.getInventory(), 8, 84);
|
||||
|
||||
addDataSlots(data);
|
||||
}
|
||||
|
||||
public int getProgress() {
|
||||
return data.get(0);
|
||||
}
|
||||
|
||||
public int getMaxProgress() {
|
||||
return data.get(1);
|
||||
}
|
||||
|
||||
private int addSlotRange(Container playerInventory, int index, int x, int y, int amount, int dx) {
|
||||
@ -99,6 +111,6 @@ public class EnvCollectorMenu extends AbstractContainerMenu {
|
||||
|
||||
@Override
|
||||
public boolean stillValid(@NotNull Player pPlayer) {
|
||||
return stillValid(ContainerLevelAccess.create(pPlayer.level(), pos), pPlayer, ETBlocks.ENV_COLLECTOR_BLOCK.get());
|
||||
return stillValid(ContainerLevelAccess.create(pPlayer.level(), blockEntity.getBlockPos()), pPlayer, ETBlocks.ENV_COLLECTOR_BLOCK.get());
|
||||
}
|
||||
}
|
||||
|
@ -2,5 +2,6 @@
|
||||
"item.environmenttech.env_detector": "ENV Detector",
|
||||
"item.environmenttech.environmental_essence": "Environmental Essence",
|
||||
|
||||
"itemGroup.environmenttech": "Environment Tech"
|
||||
"itemGroup.environmenttech": "Environment Tech",
|
||||
"screen.environmenttech.env_collector": "ENV Collector"
|
||||
}
|
Binary file not shown.
Before Width: | Height: | Size: 171 B |
Binary file not shown.
After Width: | Height: | Size: 214 B |
Loading…
x
Reference in New Issue
Block a user