Split client and server.
This commit is contained in:
parent
3cb62b0291
commit
c3622cb263
208 changed files with 194 additions and 219 deletions
68
RebornCore/src/client/java/reborncore/RebornCoreClient.java
Normal file
68
RebornCore/src/client/java/reborncore/RebornCoreClient.java
Normal file
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
* This file is part of RebornCore, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2021 TeamReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package reborncore;
|
||||
|
||||
import net.fabricmc.api.ClientModInitializer;
|
||||
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientBlockEntityEvents;
|
||||
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLifecycleEvents;
|
||||
import net.fabricmc.fabric.api.client.item.v1.ItemTooltipCallback;
|
||||
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
|
||||
import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderEvents;
|
||||
import net.fabricmc.fabric.api.event.client.ClientSpriteRegistryCallback;
|
||||
import net.minecraft.client.texture.SpriteAtlasTexture;
|
||||
import reborncore.api.blockentity.UnloadHandler;
|
||||
import reborncore.client.*;
|
||||
import reborncore.common.screen.ScreenIcons;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public class RebornCoreClient implements ClientModInitializer {
|
||||
|
||||
@Override
|
||||
public void onInitializeClient() {
|
||||
RebornFluidRenderManager.setupClient();
|
||||
HolidayRenderManager.setupClient();
|
||||
ClientSpriteRegistryCallback.event(SpriteAtlasTexture.BLOCK_ATLAS_TEXTURE).register((atlasTexture, registry) -> {
|
||||
registry.register(ScreenIcons.HEAD);
|
||||
registry.register(ScreenIcons.CHEST);
|
||||
registry.register(ScreenIcons.LEGS);
|
||||
registry.register(ScreenIcons.FEET);
|
||||
});
|
||||
ClientBoundPacketHandlers.init();
|
||||
HudRenderCallback.EVENT.register(new ItemStackRenderer());
|
||||
ItemTooltipCallback.EVENT.register(new StackToolTipHandler());
|
||||
WorldRenderEvents.BLOCK_OUTLINE.register(new BlockOutlineRenderer());
|
||||
|
||||
/* register UnloadHandler */
|
||||
ClientBlockEntityEvents.BLOCK_ENTITY_UNLOAD.register((blockEntity, world) -> {
|
||||
if (blockEntity instanceof UnloadHandler) ((UnloadHandler) blockEntity).onUnload();
|
||||
});
|
||||
|
||||
ClientLifecycleEvents.CLIENT_STARTED.register(client -> {
|
||||
String strangeMcLang = client.getLanguageManager().getLanguage().getCode();
|
||||
RebornCore.locale = Locale.forLanguageTag(strangeMcLang.substring(0, 2));
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,90 @@
|
|||
/*
|
||||
* This file is part of RebornCore, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2021 TeamReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package reborncore.client;
|
||||
|
||||
import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext;
|
||||
import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderEvents;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.ShapeContext;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.network.ClientPlayerEntity;
|
||||
import net.minecraft.client.render.RenderLayer;
|
||||
import net.minecraft.client.render.WorldRenderer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.shape.VoxelShape;
|
||||
import net.minecraft.util.shape.VoxelShapes;
|
||||
import net.minecraft.world.World;
|
||||
import reborncore.common.misc.MultiBlockBreakingTool;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class BlockOutlineRenderer implements WorldRenderEvents.BlockOutline {
|
||||
|
||||
@Override
|
||||
public boolean onBlockOutline(WorldRenderContext worldRenderContext, WorldRenderContext.BlockOutlineContext context) {
|
||||
List<VoxelShape> shapes = new ArrayList<>();
|
||||
|
||||
World world = context.entity().world;
|
||||
BlockPos targetPos = context.blockPos();
|
||||
|
||||
if (context.entity() == MinecraftClient.getInstance().player) {
|
||||
ClientPlayerEntity clientPlayerEntity = MinecraftClient.getInstance().player;
|
||||
|
||||
ItemStack stack = clientPlayerEntity.getMainHandStack();
|
||||
if (stack.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (stack.getItem() instanceof MultiBlockBreakingTool) {
|
||||
Set<BlockPos> blockPosList = ((MultiBlockBreakingTool) stack.getItem()).getBlocksToBreak(stack, clientPlayerEntity.world, targetPos, clientPlayerEntity);
|
||||
|
||||
for (BlockPos pos : blockPosList) {
|
||||
if (pos.equals(targetPos)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
BlockState blockState = world.getBlockState(pos);
|
||||
shapes.add(blockState.getOutlineShape(world, pos, ShapeContext.of(clientPlayerEntity)).offset(pos.getX() - targetPos.getX(), pos.getY() - targetPos.getY(), pos.getZ() - targetPos.getZ()));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!shapes.isEmpty()) {
|
||||
VoxelShape shape = context.blockState().getOutlineShape(world, targetPos, ShapeContext.of(context.entity()));
|
||||
|
||||
for (VoxelShape voxelShape : shapes) {
|
||||
shape = VoxelShapes.union(shape, voxelShape);
|
||||
}
|
||||
|
||||
WorldRenderer.drawShapeOutline(worldRenderContext.matrixStack(), worldRenderContext.consumers().getBuffer(RenderLayer.getLines()), shape, (double)targetPos.getX() - context.cameraX(), (double)targetPos.getY() - context.cameraY(), (double)targetPos.getZ() - context.cameraZ(), 0.0F, 0.0F, 0.0F, 0.4F);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,158 @@
|
|||
/*
|
||||
* This file is part of RebornCore, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2021 TeamReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package reborncore.client;
|
||||
|
||||
import com.mojang.serialization.Codec;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.gui.hud.ChatHud;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.gui.screen.ingame.HandledScreen;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NbtCompound;
|
||||
import net.minecraft.screen.ScreenHandler;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import reborncore.RebornCore;
|
||||
import reborncore.common.blockentity.FluidConfiguration;
|
||||
import reborncore.common.blockentity.MachineBaseBlockEntity;
|
||||
import reborncore.common.blockentity.SlotConfiguration;
|
||||
import reborncore.common.chunkloading.ChunkLoaderManager;
|
||||
import reborncore.common.network.ExtendedPacketBuffer;
|
||||
import reborncore.common.screen.BuiltScreenHandler;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class ClientBoundPacketHandlers {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(ClientBoundPacketHandlers.class);
|
||||
|
||||
public static void init() {
|
||||
ClientNetworkManager.registerClientBoundHandler(new Identifier("reborncore", "custom_description"), (client, handler, packetBuffer, responseSender) -> {
|
||||
BlockPos pos = packetBuffer.readBlockPos();
|
||||
NbtCompound tagCompound = packetBuffer.readNbt();
|
||||
client.execute(() -> {
|
||||
World world = MinecraftClient.getInstance().world;
|
||||
if (world.isChunkLoaded(pos)) {
|
||||
BlockEntity blockentity = world.getBlockEntity(pos);
|
||||
if (blockentity != null && tagCompound != null) {
|
||||
blockentity.readNbt(tagCompound);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
ClientNetworkManager.registerClientBoundHandler(new Identifier("reborncore", "fluid_config_sync"), (client, handler, packetBuffer, responseSender) -> {
|
||||
BlockPos pos = packetBuffer.readBlockPos();
|
||||
NbtCompound compoundTag = packetBuffer.readNbt();
|
||||
|
||||
client.execute(() -> {
|
||||
FluidConfiguration fluidConfiguration = new FluidConfiguration(compoundTag);
|
||||
if (!MinecraftClient.getInstance().world.isChunkLoaded(pos)) {
|
||||
return;
|
||||
}
|
||||
MachineBaseBlockEntity machineBase = (MachineBaseBlockEntity) MinecraftClient.getInstance().world.getBlockEntity(pos);
|
||||
if (machineBase == null || machineBase.fluidConfiguration == null || fluidConfiguration == null) {
|
||||
RebornCore.LOGGER.error("Failed to sync fluid config data to " + pos);
|
||||
return;
|
||||
}
|
||||
fluidConfiguration.getAllSides().forEach(fluidConfig -> machineBase.fluidConfiguration.updateFluidConfig(fluidConfig));
|
||||
machineBase.fluidConfiguration.setInput(fluidConfiguration.autoInput());
|
||||
machineBase.fluidConfiguration.setOutput(fluidConfiguration.autoOutput());
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
ClientNetworkManager.registerClientBoundHandler(new Identifier("reborncore", "slot_sync"), (client, handler, packetBuffer, responseSender) -> {
|
||||
BlockPos pos = packetBuffer.readBlockPos();
|
||||
NbtCompound compoundTag = packetBuffer.readNbt();
|
||||
|
||||
client.execute(() -> {
|
||||
SlotConfiguration slotConfig = new SlotConfiguration(compoundTag);
|
||||
if (!MinecraftClient.getInstance().world.isChunkLoaded(pos)) {
|
||||
return;
|
||||
}
|
||||
MachineBaseBlockEntity machineBase = (MachineBaseBlockEntity) MinecraftClient.getInstance().world.getBlockEntity(pos);
|
||||
if (machineBase == null || machineBase.getSlotConfiguration() == null || slotConfig == null || slotConfig.getSlotDetails() == null) {
|
||||
RebornCore.LOGGER.error("Failed to sync slot data to " + pos);
|
||||
return;
|
||||
}
|
||||
MinecraftClient.getInstance().execute(() -> slotConfig.getSlotDetails().forEach(slotConfigHolder -> machineBase.getSlotConfiguration().updateSlotDetails(slotConfigHolder)));
|
||||
});
|
||||
});
|
||||
|
||||
ClientNetworkManager.registerClientBoundHandler(new Identifier("reborncore", "send_object"), (client, handler, packetBuffer, responseSender) -> {
|
||||
int size = packetBuffer.readInt();
|
||||
ExtendedPacketBuffer epb = new ExtendedPacketBuffer(packetBuffer);
|
||||
Int2ObjectMap<Object> updatedValues = new Int2ObjectOpenHashMap<>();
|
||||
|
||||
for (int i = 0; i < size; i++) {
|
||||
int id = packetBuffer.readInt();
|
||||
Object value = epb.readObject();
|
||||
updatedValues.put(id, value);
|
||||
}
|
||||
|
||||
String name = packetBuffer.readString(packetBuffer.readInt());
|
||||
|
||||
client.execute(() -> {
|
||||
Screen gui = MinecraftClient.getInstance().currentScreen;
|
||||
if (gui instanceof HandledScreen handledScreen) {
|
||||
ScreenHandler screenHandler = handledScreen.getScreenHandler();
|
||||
if (screenHandler instanceof BuiltScreenHandler builtScreenHandler) {
|
||||
String shName = screenHandler.getClass().getName();
|
||||
if (!shName.equals(name)) {
|
||||
LOGGER.warn("Received packet for {} but screen handler {} is open!", name, shName);
|
||||
return;
|
||||
}
|
||||
|
||||
builtScreenHandler.handleUpdateValues(updatedValues);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
ClientNetworkManager.registerClientBoundHandler(new Identifier("reborncore", "sync_chunks"), ChunkLoaderManager.CODEC, ClientChunkManager::setLoadedChunks);
|
||||
|
||||
ClientNetworkManager.registerClientBoundHandler(new Identifier("reborncore", "no_spam_chat"), (client, handler, buf, responseSender) -> {
|
||||
final int messageId = buf.readInt();
|
||||
final Text text = buf.readText();
|
||||
|
||||
client.execute(() -> {
|
||||
int deleteID = RebornCore.MOD_ID.hashCode() + messageId;
|
||||
ChatHud chat = MinecraftClient.getInstance().inGameHud.getChatHud();
|
||||
chat.addMessage(text, deleteID);
|
||||
});
|
||||
});
|
||||
|
||||
ClientNetworkManager.registerClientBoundHandler(new Identifier("reborncore", "stacks_to_render"), Codec.list(ItemStack.CODEC), ItemStackRenderManager.RENDER_QUEUE::addAll);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
* This file is part of RebornCore, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2021 TeamReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package reborncore.client;
|
||||
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.network.MessageSender;
|
||||
import net.minecraft.network.MessageType;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Util;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
|
||||
public class ClientChatUtils {
|
||||
public static void addHudMessage(Text text) {
|
||||
MinecraftClient.getInstance().inGameHud.onChatMessage(getSystemMessageType(), text, new MessageSender(Util.NIL_UUID, text));
|
||||
}
|
||||
|
||||
private static MessageType getSystemMessageType() {
|
||||
Registry<MessageType> registry = MinecraftClient.getInstance().world.getRegistryManager().get(Registry.MESSAGE_TYPE_KEY);
|
||||
return registry.get(MessageType.SYSTEM);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,106 @@
|
|||
/*
|
||||
* This file is part of RebornCore, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2021 TeamReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package reborncore.client;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.render.*;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import reborncore.common.chunkloading.ChunkLoaderManager;
|
||||
import reborncore.common.network.NetworkManager;
|
||||
import reborncore.common.network.ServerBoundPackets;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class ClientChunkManager {
|
||||
|
||||
private static final List<ChunkLoaderManager.LoadedChunk> loadedChunks = new ArrayList<>();
|
||||
|
||||
public static void setLoadedChunks(List<ChunkLoaderManager.LoadedChunk> chunks) {
|
||||
loadedChunks.clear();
|
||||
loadedChunks.addAll(chunks);
|
||||
}
|
||||
|
||||
public static void toggleLoadedChunks(BlockPos chunkLoader) {
|
||||
if (loadedChunks.size() == 0) {
|
||||
NetworkManager.sendToServer(ServerBoundPackets.requestChunkLoaderChunks(chunkLoader));
|
||||
} else {
|
||||
loadedChunks.clear();
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean hasChunksForLoader(BlockPos pos) {
|
||||
return loadedChunks.stream()
|
||||
.filter(loadedChunk -> loadedChunk.getChunkLoader().equals(pos))
|
||||
.anyMatch(loadedChunk -> loadedChunk.getWorld().equals(ChunkLoaderManager.getWorldName(MinecraftClient.getInstance().world)));
|
||||
}
|
||||
|
||||
public static void render(MatrixStack matrices, VertexConsumerProvider vertexConsumers, double x, double y, double z) {
|
||||
if (loadedChunks.size() == 0) {
|
||||
return;
|
||||
}
|
||||
final MinecraftClient minecraftClient = MinecraftClient.getInstance();
|
||||
|
||||
RenderSystem.enableDepthTest();
|
||||
|
||||
// FIXME 1.17
|
||||
|
||||
/*RenderSystem.shadeModel(7425);
|
||||
RenderSystem.enableAlphaTest();
|
||||
RenderSystem.defaultAlphaFunc();*/
|
||||
|
||||
final Tessellator tessellator = Tessellator.getInstance();
|
||||
final BufferBuilder bufferBuilder = tessellator.getBuffer();
|
||||
|
||||
RenderSystem.disableTexture();
|
||||
RenderSystem.disableBlend();
|
||||
RenderSystem.lineWidth(5.0F);
|
||||
|
||||
bufferBuilder.begin(VertexFormat.DrawMode.LINE_STRIP, VertexFormats.POSITION_COLOR);
|
||||
|
||||
loadedChunks.stream()
|
||||
.filter(loadedChunk -> loadedChunk.getWorld().equals(ChunkLoaderManager.getWorldName(minecraftClient.world)))
|
||||
.forEach(loadedChunk -> {
|
||||
double chunkX = (double) loadedChunk.getChunk().getStartX() - x;
|
||||
double chunkY = (double) loadedChunk.getChunk().getStartZ() - z;
|
||||
|
||||
bufferBuilder.vertex(chunkX + 8, 0.0D - y, chunkY + 8).color(1.0F, 0.0F, 0.0F, 0.0F).next();
|
||||
bufferBuilder.vertex(chunkX + 8, 0.0D - y, chunkY + 8).color(1.0F, 0.0F, 0.0F, 0.5F).next();
|
||||
bufferBuilder.vertex(chunkX + 8, 256.0D - y, chunkY + 8).color(1.0F, 0.0F, 0.0F, 0.5F).next();
|
||||
bufferBuilder.vertex(chunkX + 8, 256.0D - y, chunkY + 8).color(1.0F, 0.0F, 0.0F, 0.0F).next();
|
||||
});
|
||||
|
||||
tessellator.draw();
|
||||
RenderSystem.lineWidth(1.0F);
|
||||
RenderSystem.enableBlend();
|
||||
RenderSystem.enableTexture();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* This file is part of RebornCore, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2021 TeamReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package reborncore.client;
|
||||
|
||||
import com.mojang.serialization.Codec;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
|
||||
import net.minecraft.util.Identifier;
|
||||
import reborncore.common.network.ExtendedPacketBuffer;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class ClientNetworkManager {
|
||||
public static void registerClientBoundHandler(Identifier identifier, ClientPlayNetworking.PlayChannelHandler handler) {
|
||||
ClientPlayNetworking.registerGlobalReceiver(identifier, handler);
|
||||
}
|
||||
|
||||
public static <T> void registerClientBoundHandler(Identifier identifier, Codec<T> codec, Consumer<T> consumer) {
|
||||
registerClientBoundHandler(identifier, (client, handler, buf, responseSender) -> {
|
||||
T value = new ExtendedPacketBuffer(buf).readCodec(codec);
|
||||
client.execute(() -> consumer.accept(value));
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,84 @@
|
|||
/*
|
||||
* This file is part of RebornCore, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2021 TeamReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package reborncore.client;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import net.fabricmc.fabric.api.client.rendering.v1.LivingEntityFeatureRendererRegistrationCallback;
|
||||
import net.minecraft.client.render.RenderLayer;
|
||||
import net.minecraft.client.render.VertexConsumer;
|
||||
import net.minecraft.client.render.VertexConsumerProvider;
|
||||
import net.minecraft.client.render.entity.LivingEntityRenderer;
|
||||
import net.minecraft.client.render.entity.feature.FeatureRenderer;
|
||||
import net.minecraft.client.render.entity.feature.FeatureRendererContext;
|
||||
import net.minecraft.client.render.entity.model.EntityModel;
|
||||
import net.minecraft.client.render.entity.model.PlayerEntityModel;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.Vec3f;
|
||||
import reborncore.common.RebornCoreConfig;
|
||||
import reborncore.common.util.CalenderUtils;
|
||||
|
||||
/**
|
||||
* Created by Mark on 27/11/2016.
|
||||
*/
|
||||
public class HolidayRenderManager {
|
||||
|
||||
public static void setupClient() {
|
||||
if (CalenderUtils.christmas && RebornCoreConfig.easterEggs) {
|
||||
LivingEntityFeatureRendererRegistrationCallback.EVENT.register((entityType, entityRenderer, registrationHelper, context) -> {
|
||||
if (entityRenderer.getModel() instanceof PlayerEntityModel) {
|
||||
registrationHelper.register(new LayerRender(entityRenderer));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private static final ModelSantaHat santaHat = new ModelSantaHat();
|
||||
private static final Identifier TEXTURE = new Identifier("reborncore", "textures/models/santa_hat.png");
|
||||
|
||||
public static class LayerRender <T extends LivingEntity, M extends EntityModel<T>> extends FeatureRenderer<T, M> {
|
||||
|
||||
public LayerRender(FeatureRendererContext<T, M> context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int i, T player, float limbAngle, float limbDistance, float tickDelta, float animationProgress, float headYaw, float headPitch) {
|
||||
RenderSystem.setShaderTexture(0, TEXTURE);
|
||||
VertexConsumer vertexConsumer = vertexConsumerProvider.getBuffer(RenderLayer.getEntitySolid(TEXTURE));
|
||||
matrixStack.push();
|
||||
|
||||
float yaw = player.prevYaw + (player.getYaw() - player.prevYaw) * tickDelta - (player.prevBodyYaw + (player.bodyYaw - player.prevBodyYaw) * tickDelta);
|
||||
float pitch = player.prevPitch + (player.getPitch() - player.prevPitch) * tickDelta;
|
||||
|
||||
matrixStack.multiply(Vec3f.POSITIVE_Y.getDegreesQuaternion(yaw));
|
||||
matrixStack.multiply(Vec3f.POSITIVE_X.getDegreesQuaternion(pitch));
|
||||
santaHat.render(matrixStack, vertexConsumer, i, LivingEntityRenderer.getOverlay(player, 0.0F), 1F, 1F, 1F, 1F);
|
||||
matrixStack.pop();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* This file is part of RebornCore, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2021 TeamReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package reborncore.client;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.Queue;
|
||||
|
||||
public class ItemStackRenderManager {
|
||||
public static final Queue<ItemStack> RENDER_QUEUE = new LinkedList<>();
|
||||
}
|
|
@ -0,0 +1,100 @@
|
|||
/*
|
||||
* This file is part of RebornCore, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2021 TeamReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package reborncore.client;
|
||||
|
||||
import com.mojang.blaze3d.platform.GlStateManager;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.gl.Framebuffer;
|
||||
import net.minecraft.client.gl.SimpleFramebuffer;
|
||||
import net.minecraft.client.render.DiffuseLighting;
|
||||
import net.minecraft.client.texture.NativeImage;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.Matrix4f;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import org.lwjgl.opengl.GL12;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
/**
|
||||
* Initially taken from https://github.com/JamiesWhiteShirt/developer-mode/tree/experimental-item-render
|
||||
* and then ported to 1.15
|
||||
* Thanks 2xsaiko for fixing the lighting + odd issues above
|
||||
*/
|
||||
public class ItemStackRenderer implements HudRenderCallback {
|
||||
|
||||
private static final int SIZE = 512;
|
||||
|
||||
@Override
|
||||
public void onHudRender(MatrixStack matrixStack, float v) {
|
||||
if (!ItemStackRenderManager.RENDER_QUEUE.isEmpty()) {
|
||||
ItemStack itemStack = ItemStackRenderManager.RENDER_QUEUE.remove();
|
||||
Identifier id = Registry.ITEM.getId(itemStack.getItem());
|
||||
MinecraftClient.getInstance().textRenderer.draw(matrixStack, "Rendering " + id + ", " + ItemStackRenderManager.RENDER_QUEUE.size() + " items left", 5, 5, -1);
|
||||
export(id, itemStack);
|
||||
}
|
||||
}
|
||||
|
||||
private void export(Identifier identifier, ItemStack item) {
|
||||
RenderSystem.setProjectionMatrix(Matrix4f.projectionMatrix(0, 16, 0, 16, 1000, 3000));
|
||||
MatrixStack stack = RenderSystem.getModelViewStack();
|
||||
stack.loadIdentity();
|
||||
stack.translate(0, 0, -2000);
|
||||
DiffuseLighting.enableGuiDepthLighting();
|
||||
RenderSystem.applyModelViewMatrix();
|
||||
|
||||
Framebuffer framebuffer = new SimpleFramebuffer(SIZE, SIZE, true, MinecraftClient.IS_SYSTEM_MAC);
|
||||
|
||||
try (NativeImage nativeImage = new NativeImage(SIZE, SIZE, true)) {
|
||||
framebuffer.setClearColor(0, 0, 0, 0);
|
||||
framebuffer.clear(MinecraftClient.IS_SYSTEM_MAC);
|
||||
|
||||
framebuffer.beginWrite(true);
|
||||
GlStateManager._clear(GL12.GL_COLOR_BUFFER_BIT | GL12.GL_DEPTH_BUFFER_BIT, MinecraftClient.IS_SYSTEM_MAC);
|
||||
MinecraftClient.getInstance().getItemRenderer().renderInGui(item, 0, 0);
|
||||
framebuffer.endWrite();
|
||||
|
||||
framebuffer.beginRead();
|
||||
nativeImage.loadFromTextureImage(0, false);
|
||||
nativeImage.mirrorVertically();
|
||||
framebuffer.endRead();
|
||||
|
||||
try {
|
||||
Path path = FabricLoader.getInstance().getGameDir().resolve("item_renderer").resolve(identifier.getNamespace()).resolve(identifier.getPath() + ".png");
|
||||
Files.createDirectories(path.getParent());
|
||||
nativeImage.writeTo(path);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
framebuffer.delete();
|
||||
}
|
||||
}
|
223
RebornCore/src/client/java/reborncore/client/ModelSantaHat.java
Normal file
223
RebornCore/src/client/java/reborncore/client/ModelSantaHat.java
Normal file
|
@ -0,0 +1,223 @@
|
|||
/*
|
||||
* This file is part of RebornCore, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2021 TeamReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
// Date: 27/11/2016 17:33:21
|
||||
// Template version 1.1
|
||||
// Java generated by Techne
|
||||
// Keep in mind that you still need to fill in some blanks
|
||||
// - ZeuX
|
||||
|
||||
package reborncore.client;
|
||||
|
||||
import net.minecraft.client.model.ModelPart;
|
||||
import net.minecraft.client.network.AbstractClientPlayerEntity;
|
||||
import net.minecraft.client.render.VertexConsumer;
|
||||
import net.minecraft.client.render.entity.model.EntityModel;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
public class ModelSantaHat extends EntityModel<AbstractClientPlayerEntity> {
|
||||
private final ModelPart hatBand1;
|
||||
private final ModelPart hatBand2;
|
||||
private final ModelPart hatBand3;
|
||||
private final ModelPart hatBand4;
|
||||
private final ModelPart hatBase1;
|
||||
private final ModelPart hatBand5;
|
||||
private final ModelPart hatBand6;
|
||||
private final ModelPart hatBase2;
|
||||
private final ModelPart hatExtension1;
|
||||
private final ModelPart hatExtension2;
|
||||
private final ModelPart hatExtension3;
|
||||
private final ModelPart hatExtension4;
|
||||
private final ModelPart hatBall1;
|
||||
private final ModelPart hatBall2;
|
||||
private final ModelPart hatBall3;
|
||||
private final ModelPart hatBall4;
|
||||
private final ModelPart hatBall5;
|
||||
private final ModelPart hatBall6;
|
||||
|
||||
public ModelSantaHat() {
|
||||
ModelPart.Cuboid[] hatBand1Cuboids = {
|
||||
new ModelPart.Cuboid(0, 32, -4F, -8F, -5F, 8F, 1F, 1F, 0F, 0F, 0F, true, 64F, 64F)
|
||||
};
|
||||
hatBand1 = new ModelPart(Arrays.asList(hatBand1Cuboids), Collections.emptyMap());
|
||||
hatBand1.setPivot(0F, 0F, 0F);
|
||||
setRotation(hatBand1, 0F, 0F, 0F);
|
||||
|
||||
ModelPart.Cuboid[] hatBand2Cuboids = {
|
||||
new ModelPart.Cuboid(0, 32, -4F, -8F, 4F, 8F, 1F, 1F, 0F, 0F, 0F, true, 64F, 64F)
|
||||
};
|
||||
hatBand2 = new ModelPart(Arrays.asList(hatBand2Cuboids), Collections.emptyMap());
|
||||
hatBand2.setPivot(0F, 0F, 0F);
|
||||
setRotation(hatBand2, 0F, 0F, 0F);
|
||||
|
||||
ModelPart.Cuboid[] hatBand3Cuboids = {
|
||||
new ModelPart.Cuboid(0, 34, -5F, -8F, -4F, 1F, 1F, 8F, 0F, 0F, 0F, true, 64F, 64F)
|
||||
};
|
||||
hatBand3 = new ModelPart(Arrays.asList(hatBand3Cuboids), Collections.emptyMap());
|
||||
hatBand3.setPivot(0F, 0F, 0F);
|
||||
setRotation(hatBand3, 0F, 0F, 0F);
|
||||
|
||||
ModelPart.Cuboid[] hatBand4Cuboids = {
|
||||
new ModelPart.Cuboid(0, 34, 4F, -8F, -4F, 1F, 1F, 8F, 0F, 0F, 0F, true, 64F, 64F)
|
||||
};
|
||||
hatBand4 = new ModelPart(Arrays.asList(hatBand4Cuboids), Collections.emptyMap());
|
||||
hatBand4.setPivot(0F, 0F, 0F);
|
||||
setRotation(hatBand4, 0F, 0F, 0F);
|
||||
|
||||
ModelPart.Cuboid[] hatBase1Cuboids = {
|
||||
new ModelPart.Cuboid(0, 43, -4F, -9F, -4F, 8F, 1F, 8F, 0F, 0F, 0F, true, 64F, 64F)
|
||||
};
|
||||
hatBase1 = new ModelPart(Arrays.asList(hatBase1Cuboids), Collections.emptyMap());
|
||||
hatBase1.setPivot(0F, 0F, 0F);
|
||||
setRotation(hatBase1, 0F, 0F, 0F);
|
||||
|
||||
ModelPart.Cuboid[] hatBand5Cuboids = {
|
||||
new ModelPart.Cuboid(18, 41, 0F, -7F, -5F, 4F, 1F, 1F, 0F, 0F, 0F, true, 64F, 64F)
|
||||
};
|
||||
hatBand5 = new ModelPart(Arrays.asList(hatBand5Cuboids), Collections.emptyMap());
|
||||
hatBand5.setPivot(0F, 0F, 0F);
|
||||
setRotation(hatBand5, 0F, 0F, 0F);
|
||||
|
||||
ModelPart.Cuboid[] hatBand6Cuboids = {
|
||||
new ModelPart.Cuboid(18, 41, -4F, -7F, 0F, 4F, 1F, 1F, 0F, 0F, 0F, true, 64F, 64F)
|
||||
};
|
||||
hatBand6 = new ModelPart(Arrays.asList(hatBand6Cuboids), Collections.emptyMap());
|
||||
hatBand6.setPivot(0F, 0F, 4F);
|
||||
setRotation(hatBand6, 0F, 0F, 0F);
|
||||
|
||||
ModelPart.Cuboid[] hatBase2Cuboids = {
|
||||
new ModelPart.Cuboid(18, 34, -3F, -10F, -3F, 6F, 1F, 6F, 0F, 0F, 0F, true, 64F, 64F)
|
||||
};
|
||||
hatBase2 = new ModelPart(Arrays.asList(hatBase2Cuboids), Collections.emptyMap());
|
||||
hatBase2.setPivot(0F, 0F, 0F);
|
||||
setRotation(hatBase2, 0F, 0.1115358F, 0F);
|
||||
|
||||
ModelPart.Cuboid[] hatExtension1Cuboids = {
|
||||
new ModelPart.Cuboid(0, 52, -3F, -11F, -2F, 4F, 2F, 4F, 0F, 0F, 0F, true, 64F, 64F)
|
||||
};
|
||||
hatExtension1 = new ModelPart(Arrays.asList(hatExtension1Cuboids), Collections.emptyMap());
|
||||
hatExtension1.setPivot(0F, 0F, 0F);
|
||||
setRotation(hatExtension1, 0F, -0.0371786F, 0.0743572F);
|
||||
|
||||
ModelPart.Cuboid[] hatExtension2Cuboids = {
|
||||
new ModelPart.Cuboid(16, 52, -2.4F, -12F, -1.5F, 3F, 2F, 3F, 0F, 0F, 0F, true, 64F, 64F)
|
||||
};
|
||||
hatExtension2 = new ModelPart(Arrays.asList(hatExtension2Cuboids), Collections.emptyMap());
|
||||
hatExtension2.setPivot(0F, 0F, 0F);
|
||||
setRotation(hatExtension2, 0F, 0.0743572F, 0.0743572F);
|
||||
|
||||
ModelPart.Cuboid[] hatExtension3Cuboids = {
|
||||
new ModelPart.Cuboid(28, 52, -3.5F, -13F, -1F, 2F, 2F, 2F, 0F, 0F, 0F, true, 64F, 64F)
|
||||
};
|
||||
hatExtension3 = new ModelPart(Arrays.asList(hatExtension3Cuboids), Collections.emptyMap());
|
||||
hatExtension3.setPivot(0F, 0F, 0F);
|
||||
setRotation(hatExtension3, 0F, 0F, 0.2230717F);
|
||||
|
||||
ModelPart.Cuboid[] hatExtension4Cuboids = {
|
||||
new ModelPart.Cuboid(0, 58, -13F, -6.6F, -1F, 2F, 3F, 2F, 0F, 0F, 0F, true, 64F, 64F)
|
||||
};
|
||||
hatExtension4 = new ModelPart(Arrays.asList(hatExtension4Cuboids), Collections.emptyMap());
|
||||
hatExtension4.setPivot(0F, 0F, 0F);
|
||||
setRotation(hatExtension4, 0F, 0F, 1.264073F);
|
||||
|
||||
ModelPart.Cuboid[] hatBall1Cuboids = {
|
||||
new ModelPart.Cuboid(8, 58, 2F, -14.4F, -1.001F, 2F, 2F, 2F, 0F, 0F, 0F, true, 64F, 64F)
|
||||
};
|
||||
hatBall1 = new ModelPart(Arrays.asList(hatBall1Cuboids), Collections.emptyMap());
|
||||
hatBall1.setPivot(0F, 0F, 0F);
|
||||
setRotation(hatBall1, 0F, 0F, 0F);
|
||||
|
||||
ModelPart.Cuboid[] hatBall2Cuboids = {
|
||||
new ModelPart.Cuboid(16, 57, 2.5F, -14.8F, -0.5F, 1F, 1F, 1F, 0F, 0F, 0F, true, 64F, 64F)
|
||||
};
|
||||
hatBall2 = new ModelPart(Arrays.asList(hatBall2Cuboids), Collections.emptyMap());
|
||||
hatBall2.setPivot(0F, 0F, 0F);
|
||||
setRotation(hatBall2, 0F, 0F, 0F);
|
||||
|
||||
ModelPart.Cuboid[] hatBall3Cuboids = {
|
||||
new ModelPart.Cuboid(16, 57, 2.5F, -13F, -0.5F, 1F, 1F, 1F, 0F, 0F, 0F, true, 64F, 64F)
|
||||
};
|
||||
hatBall3 = new ModelPart(Arrays.asList(hatBall3Cuboids), Collections.emptyMap());
|
||||
hatBall3.setPivot(0F, 0F, 0F);
|
||||
setRotation(hatBall3, 0F, 0F, 0F);
|
||||
|
||||
ModelPart.Cuboid[] hatBall4Cuboids = {
|
||||
new ModelPart.Cuboid(16, 57, 3.4F, -14F, -0.5F, 1F, 1F, 1F, 0F, 0F, 0F, true, 64F, 64F)
|
||||
};
|
||||
hatBall4 = new ModelPart(Arrays.asList(hatBall4Cuboids), Collections.emptyMap());
|
||||
hatBall4.setPivot(0F, 0F, 0F);
|
||||
setRotation(hatBall4, 0F, 0F, 0F);
|
||||
|
||||
ModelPart.Cuboid[] hatBall5Cuboids = {
|
||||
new ModelPart.Cuboid(16, 57, 2.5F, -14F, 0.4F, 1F, 1F, 1F, 0F, 0F, 0F, true, 64F, 64F)
|
||||
};
|
||||
hatBall5 = new ModelPart(Arrays.asList(hatBall5Cuboids), Collections.emptyMap());
|
||||
hatBall5.setPivot(0F, 0F, 0F);
|
||||
setRotation(hatBall5, 0F, 0F, 0F);
|
||||
|
||||
ModelPart.Cuboid[] hatBall6Cuboids = {
|
||||
new ModelPart.Cuboid(16, 57, 2.5F, -14F, -1.4F, 1F, 1F, 1F, 0F, 0F, 0F, true, 64F, 64F)
|
||||
};
|
||||
hatBall6 = new ModelPart(Arrays.asList(hatBall6Cuboids), Collections.emptyMap());
|
||||
hatBall6.setPivot(0F, 0F, 0F);
|
||||
setRotation(hatBall6, 0F, 0F, 0F);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAngles(AbstractClientPlayerEntity entity, float limbAngle, float limbDistance, float age, float headYaw, float headPitch) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(MatrixStack matrixStack, VertexConsumer vertexConsumer, int light, int overlay, float r, float g, float b, float f) {
|
||||
hatBand1.render(matrixStack, vertexConsumer, light, overlay);
|
||||
hatBand2.render(matrixStack, vertexConsumer, light, overlay);
|
||||
hatBand3.render(matrixStack, vertexConsumer, light, overlay);
|
||||
hatBand4.render(matrixStack, vertexConsumer, light, overlay);
|
||||
hatBase1.render(matrixStack, vertexConsumer, light, overlay);
|
||||
hatBand5.render(matrixStack, vertexConsumer, light, overlay);
|
||||
hatBand6.render(matrixStack, vertexConsumer, light, overlay);
|
||||
hatBase2.render(matrixStack, vertexConsumer, light, overlay);
|
||||
hatExtension1.render(matrixStack, vertexConsumer, light, overlay);
|
||||
hatExtension2.render(matrixStack, vertexConsumer, light, overlay);
|
||||
hatExtension3.render(matrixStack, vertexConsumer, light, overlay);
|
||||
hatExtension4.render(matrixStack, vertexConsumer, light, overlay);
|
||||
hatBall1.render(matrixStack, vertexConsumer, light, overlay);
|
||||
hatBall2.render(matrixStack, vertexConsumer, light, overlay);
|
||||
hatBall3.render(matrixStack, vertexConsumer, light, overlay);
|
||||
hatBall4.render(matrixStack, vertexConsumer, light, overlay);
|
||||
hatBall5.render(matrixStack, vertexConsumer, light, overlay);
|
||||
hatBall6.render(matrixStack, vertexConsumer, light, overlay);
|
||||
}
|
||||
|
||||
private void setRotation(ModelPart model, float x, float y, float z) {
|
||||
model.pitch = x;
|
||||
model.yaw = y;
|
||||
model.roll = z;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,95 @@
|
|||
/*
|
||||
* This file is part of RebornCore, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2021 TeamReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package reborncore.client;
|
||||
|
||||
import net.fabricmc.fabric.api.client.render.fluid.v1.FluidRenderHandlerRegistry;
|
||||
import net.fabricmc.fabric.api.event.client.ClientSpriteRegistryCallback;
|
||||
import net.fabricmc.fabric.api.resource.ResourceManagerHelper;
|
||||
import net.fabricmc.fabric.api.resource.ResourceReloadListenerKeys;
|
||||
import net.fabricmc.fabric.api.resource.SimpleSynchronousResourceReloadListener;
|
||||
import net.minecraft.client.texture.Sprite;
|
||||
import net.minecraft.client.texture.SpriteAtlasTexture;
|
||||
import net.minecraft.fluid.Fluid;
|
||||
import net.minecraft.resource.ResourceManager;
|
||||
import net.minecraft.resource.ResourceType;
|
||||
import net.minecraft.util.Identifier;
|
||||
import reborncore.common.fluid.FluidSettings;
|
||||
import reborncore.common.fluid.RebornFluid;
|
||||
import reborncore.common.fluid.RebornFluidManager;
|
||||
import reborncore.common.util.TemporaryLazy;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class RebornFluidRenderManager implements ClientSpriteRegistryCallback, SimpleSynchronousResourceReloadListener {
|
||||
|
||||
private static final Map<Fluid, TemporaryLazy<Sprite[]>> spriteMap = new HashMap<>();
|
||||
|
||||
public static void setupClient() {
|
||||
RebornFluidRenderManager rebornFluidRenderManager = new RebornFluidRenderManager();
|
||||
ClientSpriteRegistryCallback.event(SpriteAtlasTexture.BLOCK_ATLAS_TEXTURE).register(rebornFluidRenderManager);
|
||||
ResourceManagerHelper.get(ResourceType.CLIENT_RESOURCES).registerReloadListener(rebornFluidRenderManager);
|
||||
RebornFluidManager.getFluidStream().forEach(RebornFluidRenderManager::setupFluidRenderer);
|
||||
}
|
||||
|
||||
private static void setupFluidRenderer(RebornFluid fluid) {
|
||||
// Done lazy as we want to ensure we get the sprite at the correct time,
|
||||
// but also don't want to be making these calls every time its required.
|
||||
TemporaryLazy<Sprite[]> sprites = new TemporaryLazy<>(() -> {
|
||||
FluidSettings fluidSettings = fluid.getFluidSettings();
|
||||
return new Sprite[]{RenderUtil.getSprite(fluidSettings.getStillTexture()), RenderUtil.getSprite(fluidSettings.getFlowingTexture())};
|
||||
});
|
||||
|
||||
spriteMap.put(fluid, sprites);
|
||||
FluidRenderHandlerRegistry.INSTANCE.register(fluid, (extendedBlockView, blockPos, fluidState) -> sprites.get());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerSprites(SpriteAtlasTexture spriteAtlasTexture, Registry registry) {
|
||||
Stream.concat(
|
||||
RebornFluidManager.getFluidStream().map(rebornFluid -> rebornFluid.getFluidSettings().getFlowingTexture()),
|
||||
RebornFluidManager.getFluidStream().map(rebornFluid -> rebornFluid.getFluidSettings().getStillTexture())
|
||||
).forEach(registry::register);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Identifier getFabricId() {
|
||||
return new Identifier("reborncore", "fluid_render_manager");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reload(ResourceManager manager) {
|
||||
// Reset the cached fluid sprites
|
||||
spriteMap.forEach((key, value) -> value.reset());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Identifier> getFabricDependencies() {
|
||||
return Collections.singletonList(ResourceReloadListenerKeys.TEXTURES);
|
||||
}
|
||||
}
|
180
RebornCore/src/client/java/reborncore/client/RenderUtil.java
Normal file
180
RebornCore/src/client/java/reborncore/client/RenderUtil.java
Normal file
|
@ -0,0 +1,180 @@
|
|||
/*
|
||||
* This file is part of RebornCore, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2021 TeamReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package reborncore.client;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import net.fabricmc.fabric.api.client.render.fluid.v1.FluidRenderHandler;
|
||||
import net.fabricmc.fabric.api.client.render.fluid.v1.FluidRenderHandlerRegistry;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.render.*;
|
||||
import net.minecraft.client.texture.Sprite;
|
||||
import net.minecraft.client.texture.SpriteAtlasTexture;
|
||||
import net.minecraft.client.texture.TextureManager;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.fluid.Fluid;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import reborncore.common.fluid.FluidValue;
|
||||
import reborncore.common.fluid.container.FluidInstance;
|
||||
import reborncore.common.util.Tank;
|
||||
|
||||
/**
|
||||
* Created by Gigabit101 on 08/08/2016.
|
||||
*/
|
||||
public class RenderUtil {
|
||||
public static final Identifier BLOCK_TEX = SpriteAtlasTexture.BLOCK_ATLAS_TEXTURE;
|
||||
|
||||
public static TextureManager engine() {
|
||||
return MinecraftClient.getInstance().getTextureManager();
|
||||
}
|
||||
|
||||
public static void bindBlockTexture() {
|
||||
RenderSystem.setShaderTexture(0, BLOCK_TEX);
|
||||
}
|
||||
|
||||
public static Sprite getStillTexture(FluidInstance fluid) {
|
||||
if (fluid == null || fluid.getFluid() == null) {
|
||||
return null;
|
||||
}
|
||||
return getStillTexture(fluid.getFluid());
|
||||
}
|
||||
|
||||
public static Sprite getSprite(Identifier identifier) {
|
||||
return MinecraftClient.getInstance().getSpriteAtlas(SpriteAtlasTexture.BLOCK_ATLAS_TEXTURE).apply(identifier);
|
||||
}
|
||||
|
||||
public static Sprite getStillTexture(Fluid fluid) {
|
||||
FluidRenderHandler fluidRenderHandler = FluidRenderHandlerRegistry.INSTANCE.get(fluid);
|
||||
if (fluidRenderHandler != null) {
|
||||
return fluidRenderHandler.getFluidSprites(MinecraftClient.getInstance().world, BlockPos.ORIGIN, fluid.getDefaultState())[0];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void renderGuiTank(Tank tank, double x, double y, double zLevel, double width, double height) {
|
||||
renderGuiTank(tank.getFluidInstance(), tank.getFluidValueCapacity(), tank.getFluidAmount(), x, y, zLevel, width, height);
|
||||
}
|
||||
|
||||
public static void renderGuiTank(FluidInstance fluid, FluidValue capacity, FluidValue amount, double x, double y, double zLevel,
|
||||
double width, double height) {
|
||||
if (fluid == null || fluid.getFluid() == null || fluid.getAmount().lessThanOrEqual(FluidValue.EMPTY)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Sprite icon = getStillTexture(fluid);
|
||||
if (icon == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
int renderAmount = (int) Math.max(Math.min(height, amount.getRawValue() * height / capacity.getRawValue()), 1);
|
||||
int posY = (int) (y + height - renderAmount);
|
||||
|
||||
bindBlockTexture();
|
||||
int color = FluidRenderHandlerRegistry.INSTANCE.get(fluid.getFluid()).getFluidColor(null, null, fluid.getFluid().getDefaultState());
|
||||
float r = (float) (color >> 16 & 0xFF) / 255.0F;
|
||||
float g = (float) (color >> 8 & 0xFF) / 255.0F;
|
||||
float b = (float) (color & 0xFF) / 255.0F;
|
||||
RenderSystem.setShaderColor(r, g, b, 1.0F);
|
||||
|
||||
RenderSystem.enableBlend();
|
||||
RenderLayer.getTranslucent().startDrawing();
|
||||
for (int i = 0; i < width; i += 16) {
|
||||
for (int j = 0; j < renderAmount; j += 16) {
|
||||
int drawWidth = (int) Math.min(width - i, 16);
|
||||
int drawHeight = Math.min(renderAmount - j, 16);
|
||||
|
||||
int drawX = (int) (x + i);
|
||||
int drawY = posY + j;
|
||||
|
||||
float minU = icon.getMinU();
|
||||
float maxU = icon.getMaxU();
|
||||
float minV = icon.getMinV();
|
||||
float maxV = icon.getMaxV();
|
||||
|
||||
Tessellator tessellator = Tessellator.getInstance();
|
||||
BufferBuilder tes = tessellator.getBuffer();
|
||||
tes.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR_TEXTURE_LIGHT_NORMAL);
|
||||
tes.vertex(drawX, drawY + drawHeight, 0)
|
||||
.color(r, g, b, 1.0F)
|
||||
.texture(minU, minV + (maxV - minV) * drawHeight / 16F)
|
||||
.light(LightmapTextureManager.MAX_LIGHT_COORDINATE)
|
||||
.normal(0, 1, 0)
|
||||
.next();
|
||||
tes.vertex(drawX + drawWidth, drawY + drawHeight, 0)
|
||||
.color(r, g, b, 1.0F)
|
||||
.texture(minU + (maxU - minU) * drawWidth / 16F, minV + (maxV - minV) * drawHeight / 16F)
|
||||
.light(LightmapTextureManager.MAX_LIGHT_COORDINATE)
|
||||
.normal(0, 1, 0)
|
||||
.next();
|
||||
tes.vertex(drawX + drawWidth, drawY, 0)
|
||||
.color(r, g, b, 1.0F)
|
||||
.texture(minU + (maxU - minU) * drawWidth / 16F, minV)
|
||||
.light(LightmapTextureManager.MAX_LIGHT_COORDINATE)
|
||||
.normal(0, 1, 0)
|
||||
.next();
|
||||
tes.vertex(drawX, drawY, 0)
|
||||
.color(r, g, b, 1.0F)
|
||||
.texture(minU, minV)
|
||||
.light(LightmapTextureManager.MAX_LIGHT_COORDINATE)
|
||||
.normal(0, 1, 0)
|
||||
.next();
|
||||
tessellator.draw();
|
||||
}
|
||||
}
|
||||
RenderLayer.getTranslucent().endDrawing();
|
||||
RenderSystem.disableBlend();
|
||||
}
|
||||
|
||||
public static void drawGradientRect(MatrixStack matrices, int zLevel, int left, int top, int right, int bottom, int startColor, int endColor) {
|
||||
RenderSystem.disableTexture();
|
||||
RenderSystem.enableBlend();
|
||||
RenderSystem.defaultBlendFunc();
|
||||
RenderSystem.setShader(GameRenderer::getPositionColorShader);
|
||||
|
||||
Tessellator tessellator = Tessellator.getInstance();
|
||||
BufferBuilder bufferBuilder = tessellator.getBuffer();
|
||||
bufferBuilder.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR);
|
||||
|
||||
float f = (startColor >> 24 & 0xFF) / 255.0F;
|
||||
float g = (startColor >> 16 & 0xFF) / 255.0F;
|
||||
float h = (startColor >> 8 & 0xFF) / 255.0F;
|
||||
float i = (startColor & 0xFF) / 255.0F;
|
||||
|
||||
float j = (endColor >> 24 & 0xFF) / 255.0F;
|
||||
float k = (endColor >> 16 & 0xFF) / 255.0F;
|
||||
float l = (endColor >> 8 & 0xFF) / 255.0F;
|
||||
float m = (endColor & 0xFF) / 255.0F;
|
||||
|
||||
bufferBuilder.vertex(matrices.peek().getPositionMatrix(), right, top, zLevel).color(g, h, i, f).next();
|
||||
bufferBuilder.vertex(matrices.peek().getPositionMatrix(), left, top, zLevel).color(g, h, i, f).next();
|
||||
bufferBuilder.vertex(matrices.peek().getPositionMatrix(), left, bottom, zLevel).color(k, l, m, j).next();
|
||||
bufferBuilder.vertex(matrices.peek().getPositionMatrix(), right, bottom, zLevel).color(k, l, m, j).next();
|
||||
|
||||
tessellator.draw();
|
||||
RenderSystem.disableBlend();
|
||||
RenderSystem.enableTexture();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,132 @@
|
|||
/*
|
||||
* This file is part of RebornCore, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2021 TeamReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package reborncore.client;
|
||||
|
||||
import net.fabricmc.fabric.api.client.item.v1.ItemTooltipCallback;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockEntityProvider;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.item.TooltipContext;
|
||||
import net.minecraft.client.resource.language.I18n;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NbtCompound;
|
||||
import net.minecraft.text.MutableText;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Formatting;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import reborncore.RebornCore;
|
||||
import reborncore.api.IListInfoProvider;
|
||||
import reborncore.common.BaseBlockEntityProvider;
|
||||
import reborncore.common.powerSystem.PowerSystem;
|
||||
import reborncore.common.powerSystem.RcEnergyItem;
|
||||
import reborncore.common.util.StringUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class StackToolTipHandler implements ItemTooltipCallback {
|
||||
|
||||
@Override
|
||||
public void getTooltip(ItemStack itemStack, TooltipContext tooltipContext, List<Text> tooltipLines) {
|
||||
Item item = itemStack.getItem();
|
||||
Block block = Block.getBlockFromItem(item);
|
||||
|
||||
if (item instanceof IListInfoProvider) {
|
||||
((IListInfoProvider) item).addInfo(tooltipLines, false, false);
|
||||
}
|
||||
else if (item instanceof RcEnergyItem energyItem) {
|
||||
MutableText line1 = Text.literal(PowerSystem.getLocalizedPowerNoSuffix(energyItem.getStoredEnergy(itemStack)));
|
||||
line1.append("/");
|
||||
line1.append(PowerSystem.getLocalizedPower(energyItem.getEnergyCapacity()));
|
||||
line1.formatted(Formatting.GOLD);
|
||||
|
||||
tooltipLines.add(1, line1);
|
||||
|
||||
if (Screen.hasShiftDown()) {
|
||||
int percentage = percentage(energyItem.getStoredEnergy(itemStack), energyItem.getEnergyCapacity());
|
||||
MutableText line2 = StringUtils.getPercentageText(percentage);
|
||||
line2.append(" ");
|
||||
line2.formatted(Formatting.GRAY);
|
||||
line2.append(I18n.translate("reborncore.gui.tooltip.power_charged"));
|
||||
tooltipLines.add(2, line2);
|
||||
|
||||
double inputRate = energyItem.getEnergyMaxInput();
|
||||
double outputRate = energyItem.getEnergyMaxOutput();
|
||||
|
||||
MutableText line3 = Text.literal("");
|
||||
if (inputRate != 0 && inputRate == outputRate){
|
||||
line3.append(I18n.translate("techreborn.tooltip.transferRate"));
|
||||
line3.append(" : ");
|
||||
line3.formatted(Formatting.GRAY);
|
||||
line3.append(PowerSystem.getLocalizedPower(inputRate));
|
||||
line3.formatted(Formatting.GOLD);
|
||||
}
|
||||
else if(inputRate != 0){
|
||||
line3.append(I18n.translate("reborncore.tooltip.energy.inputRate"));
|
||||
line3.append(" : ");
|
||||
line3.formatted(Formatting.GRAY);
|
||||
line3.append(PowerSystem.getLocalizedPower(inputRate));
|
||||
line3.formatted(Formatting.GOLD);
|
||||
}
|
||||
else if (outputRate !=0){
|
||||
line3.append(I18n.translate("reborncore.tooltip.energy.outputRate"));
|
||||
line3.append(" : ");
|
||||
line3.formatted(Formatting.GRAY);
|
||||
line3.append(PowerSystem.getLocalizedPower(outputRate));
|
||||
line3.formatted(Formatting.GOLD);
|
||||
}
|
||||
tooltipLines.add(3, line3);
|
||||
}
|
||||
}
|
||||
else {
|
||||
try {
|
||||
if ((block instanceof BaseBlockEntityProvider)) {
|
||||
BlockEntity blockEntity = ((BlockEntityProvider) block).createBlockEntity(BlockPos.ORIGIN, block.getDefaultState());
|
||||
boolean hasData = false;
|
||||
if (itemStack.hasNbt() && itemStack.getOrCreateNbt().contains("blockEntity_data")) {
|
||||
NbtCompound blockEntityData = itemStack.getOrCreateNbt().getCompound("blockEntity_data");
|
||||
if (blockEntity != null) {
|
||||
blockEntity.readNbt(blockEntityData);
|
||||
hasData = true;
|
||||
tooltipLines.add(Text.literal(I18n.translate("reborncore.tooltip.has_data")).formatted(Formatting.DARK_GREEN));
|
||||
}
|
||||
}
|
||||
if (blockEntity instanceof IListInfoProvider) {
|
||||
((IListInfoProvider) blockEntity).addInfo(tooltipLines, false, hasData);
|
||||
}
|
||||
}
|
||||
} catch (NullPointerException e) {
|
||||
RebornCore.LOGGER.debug("Failed to load info for " + itemStack.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int percentage(double CurrentValue, double MaxValue) {
|
||||
if (CurrentValue == 0)
|
||||
return 0;
|
||||
return (int) ((CurrentValue * 100.0f) / MaxValue);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,98 @@
|
|||
/*
|
||||
* This file is part of RebornCore, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2021 TeamReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package reborncore.client.gui;
|
||||
|
||||
import com.mojang.blaze3d.platform.GlStateManager;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.gui.widget.ButtonWidget;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Identifier;
|
||||
import reborncore.common.util.Color;
|
||||
|
||||
public class GuiButtonCustomTexture extends ButtonWidget {
|
||||
public int textureU;
|
||||
public int textureV;
|
||||
public String textureName;
|
||||
public String linkedPage;
|
||||
public Text name;
|
||||
public String imagePrefix = "techreborn:textures/manual/elements/";
|
||||
public int buttonHeight;
|
||||
public int buttonWidth;
|
||||
public int buttonU;
|
||||
public int buttonV;
|
||||
public int textureH;
|
||||
public int textureW;
|
||||
|
||||
public GuiButtonCustomTexture(int xPos, int yPos, int u, int v, int buttonWidth, int buttonHeight,
|
||||
String textureName, String linkedPage, Text name, int buttonU, int buttonV, int textureH, int textureW, ButtonWidget.PressAction pressAction) {
|
||||
super(xPos, yPos, buttonWidth, buttonHeight, Text.empty(), pressAction);
|
||||
this.textureU = u;
|
||||
this.textureV = v;
|
||||
this.textureName = textureName;
|
||||
this.name = name;
|
||||
this.linkedPage = linkedPage;
|
||||
this.buttonHeight = height;
|
||||
this.buttonWidth = width;
|
||||
this.buttonU = buttonU;
|
||||
this.buttonV = buttonV;
|
||||
this.textureH = textureH;
|
||||
this.textureW = textureW;
|
||||
}
|
||||
|
||||
public void drawButton(MatrixStack matrixStack, MinecraftClient mc, int mouseX, int mouseY) {
|
||||
if (this.visible) {
|
||||
boolean flag = mouseX >= this.x && mouseY >= this.y && mouseX < this.x + this.width
|
||||
&& mouseY < this.y + this.height;
|
||||
RenderSystem.setShaderTexture(0, WIDGETS_TEXTURE);
|
||||
int u = textureU;
|
||||
int v = textureV;
|
||||
|
||||
if (flag) {
|
||||
u += width;
|
||||
matrixStack.push();
|
||||
RenderSystem.setShaderColor(0f, 0f, 0f, 1f);
|
||||
this.drawTexture(matrixStack, this.x, this.y, u, v, width, height);
|
||||
matrixStack.pop();
|
||||
}
|
||||
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
renderImage(matrixStack, this.x, this.y);
|
||||
drawTextWithShadow(matrixStack, mc.textRenderer, this.name, this.x + 20, this.y + 3,
|
||||
Color.WHITE.getColor());
|
||||
}
|
||||
}
|
||||
|
||||
public void renderImage(MatrixStack matrixStack, int offsetX, int offsetY) {
|
||||
RenderSystem.setShaderTexture(0, new Identifier(imagePrefix + this.textureName + ".png"));
|
||||
|
||||
RenderSystem.enableBlend();
|
||||
RenderSystem.blendFunc(GlStateManager.SrcFactor.SRC_ALPHA, GlStateManager.DstFactor.ONE_MINUS_SRC_ALPHA);
|
||||
RenderSystem.setShaderColor(1F, 1F, 1F, 1F);
|
||||
drawTexture(matrixStack, offsetX, offsetY, this.buttonU, this.buttonV, this.textureW, this.textureH);
|
||||
RenderSystem.disableBlend();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,81 @@
|
|||
/*
|
||||
* This file is part of RebornCore, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2021 TeamReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package reborncore.client.gui;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.gui.widget.ButtonWidget;
|
||||
import net.minecraft.client.render.item.ItemRenderer;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.text.Text;
|
||||
import reborncore.common.util.Color;
|
||||
|
||||
public class GuiButtonItemTexture extends ButtonWidget {
|
||||
|
||||
public int textureU;
|
||||
public int textureV;
|
||||
public ItemStack itemstack;
|
||||
public String LINKED_PAGE;
|
||||
public Text NAME;
|
||||
|
||||
public GuiButtonItemTexture(int xPos, int yPos, int u, int v, int width, int height, ItemStack stack,
|
||||
String linkedPage, Text name, ButtonWidget.PressAction pressAction) {
|
||||
super(xPos, yPos, width, height, Text.empty(), pressAction);
|
||||
textureU = u;
|
||||
textureV = v;
|
||||
itemstack = stack;
|
||||
NAME = name;
|
||||
this.LINKED_PAGE = linkedPage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(MatrixStack matrixStack, int mouseX, int mouseY, float ticks) {
|
||||
if (this.visible) {
|
||||
MinecraftClient mc = MinecraftClient.getInstance();
|
||||
boolean flag = mouseX >= this.x && mouseY >= this.y && mouseX < this.x + this.width
|
||||
&& mouseY < this.y + this.height;
|
||||
RenderSystem.setShaderTexture(0, WIDGETS_TEXTURE);
|
||||
int u = textureU;
|
||||
int v = textureV;
|
||||
if (flag) {
|
||||
u += mc.textRenderer.getWidth(this.NAME) + 25;
|
||||
v += mc.textRenderer.getWidth(this.NAME) + 25;
|
||||
matrixStack.push();
|
||||
RenderSystem.setShaderColor(0f, 0f, 0f, 1f);
|
||||
this.drawTexture(matrixStack, this.x, this.y, u, v, mc.textRenderer.getWidth(this.NAME) + 25, height);
|
||||
matrixStack.pop();
|
||||
}
|
||||
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
//GL11.glEnable(32826); RESCALE_NORMAL_EXT
|
||||
// DiffuseLighting.enable(); FIXME 1.17
|
||||
ItemRenderer itemRenderer = MinecraftClient.getInstance().getItemRenderer();
|
||||
itemRenderer.renderGuiItemIcon(itemstack, this.x, this.y);
|
||||
this.drawTextWithShadow(matrixStack, mc.textRenderer, this.NAME, this.x + 20, this.y + 3,
|
||||
Color.WHITE.getColor());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
* This file is part of RebornCore, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2021 TeamReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package reborncore.client.gui;
|
||||
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import reborncore.client.RenderUtil;
|
||||
|
||||
public class GuiUtil {
|
||||
public static void drawTooltipBox(MatrixStack matrices, int x, int y, int w, int h) {
|
||||
int bg = 0xf0100010;
|
||||
drawGradientRect(matrices, x + 1, y, w - 1, 1, bg, bg);
|
||||
drawGradientRect(matrices, x + 1, y + h, w - 1, 1, bg, bg);
|
||||
drawGradientRect(matrices, x + 1, y + 1, w - 1, h - 1, bg, bg);// center
|
||||
drawGradientRect(matrices, x, y + 1, 1, h - 1, bg, bg);
|
||||
drawGradientRect(matrices, x + w, y + 1, 1, h - 1, bg, bg);
|
||||
int grad1 = 0x505000ff;
|
||||
int grad2 = 0x5028007F;
|
||||
drawGradientRect(matrices, x + 1, y + 2, 1, h - 3, grad1, grad2);
|
||||
drawGradientRect(matrices, x + w - 1, y + 2, 1, h - 3, grad1, grad2);
|
||||
|
||||
drawGradientRect(matrices, x + 1, y + 1, w - 1, 1, grad1, grad1);
|
||||
drawGradientRect(matrices, x + 1, y + h - 1, w - 1, 1, grad2, grad2);
|
||||
}
|
||||
|
||||
public static void drawGradientRect(MatrixStack matrices, int x, int y, int w, int h, int colour1, int colour2) {
|
||||
RenderUtil.drawGradientRect(matrices, 0, x, y, x + w, y + h, colour1, colour2);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,460 @@
|
|||
/*
|
||||
* This file is part of RebornCore, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2021 TeamReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package reborncore.client.gui.builder;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.font.TextRenderer;
|
||||
import net.minecraft.client.gui.Selectable;
|
||||
import net.minecraft.client.gui.screen.ingame.HandledScreen;
|
||||
import net.minecraft.client.gui.widget.ClickableWidget;
|
||||
import net.minecraft.client.resource.language.I18n;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.fluid.Fluid;
|
||||
import net.minecraft.fluid.Fluids;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.screen.ScreenHandler;
|
||||
import net.minecraft.screen.slot.Slot;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Util;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
import reborncore.api.blockentity.IUpgradeable;
|
||||
import reborncore.client.gui.builder.slot.FluidConfigGui;
|
||||
import reborncore.client.gui.builder.slot.GuiTab;
|
||||
import reborncore.client.gui.builder.slot.SlotConfigGui;
|
||||
import reborncore.client.gui.builder.widget.GuiButtonHologram;
|
||||
import reborncore.client.gui.guibuilder.GuiBuilder;
|
||||
import reborncore.common.screen.BuiltScreenHandler;
|
||||
import reborncore.common.screen.slot.PlayerInventorySlot;
|
||||
import reborncore.common.blockentity.MachineBaseBlockEntity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Created by Prospector
|
||||
*/
|
||||
|
||||
public class GuiBase<T extends ScreenHandler> extends HandledScreen<T> {
|
||||
|
||||
public static FluidCellProvider fluidCellProvider = fluid -> ItemStack.EMPTY;
|
||||
public static ItemStack wrenchStack = ItemStack.EMPTY;
|
||||
|
||||
private final List<GuiTab.Builder> tabBuilders = Util.make(new ArrayList<>(), builders -> {
|
||||
builders.add(GuiTab.Builder.builder()
|
||||
.name("reborncore.gui.tooltip.config_slots")
|
||||
.enabled(guiTab -> guiTab.machine().hasSlotConfig())
|
||||
.stack(guiTab -> wrenchStack)
|
||||
.draw(SlotConfigGui::draw)
|
||||
.click(SlotConfigGui::mouseClicked)
|
||||
.mouseReleased(SlotConfigGui::mouseReleased)
|
||||
.hideGuiElements()
|
||||
.keyPressed((guiBase, keyCode, scanCode, modifiers) -> {
|
||||
if (hasControlDown() && keyCode == GLFW.GLFW_KEY_C) {
|
||||
SlotConfigGui.copyToClipboard();
|
||||
return true;
|
||||
} else if (hasControlDown() && keyCode == GLFW.GLFW_KEY_V) {
|
||||
SlotConfigGui.pasteFromClipboard();
|
||||
return true;
|
||||
} else if (keyCode == GLFW.GLFW_KEY_ESCAPE && SlotConfigGui.selectedSlot != -1) {
|
||||
SlotConfigGui.reset();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
})
|
||||
.tips(tips -> {
|
||||
tips.add("reborncore.gui.slotconfigtip.slot");
|
||||
tips.add("reborncore.gui.slotconfigtip.side1");
|
||||
tips.add("reborncore.gui.slotconfigtip.side2");
|
||||
tips.add("reborncore.gui.slotconfigtip.side3");
|
||||
tips.add("reborncore.gui.slotconfigtip.copy1");
|
||||
tips.add("reborncore.gui.slotconfigtip.copy2");
|
||||
})
|
||||
);
|
||||
|
||||
builders.add(GuiTab.Builder.builder()
|
||||
.name("reborncore.gui.tooltip.config_fluids")
|
||||
.enabled(guiTab -> guiTab.machine().showTankConfig())
|
||||
.stack(guiTab -> GuiBase.fluidCellProvider.provide(Fluids.LAVA))
|
||||
.draw(FluidConfigGui::draw)
|
||||
.click(FluidConfigGui::mouseClicked)
|
||||
.mouseReleased(FluidConfigGui::mouseReleased)
|
||||
.hideGuiElements()
|
||||
);
|
||||
|
||||
builders.add(GuiTab.Builder.builder()
|
||||
.name("reborncore.gui.tooltip.config_redstone")
|
||||
.stack(guiTab -> new ItemStack(Items.REDSTONE))
|
||||
.draw(RedstoneConfigGui::draw)
|
||||
.click(RedstoneConfigGui::mouseClicked)
|
||||
);
|
||||
});
|
||||
|
||||
public GuiBuilder builder = new GuiBuilder();
|
||||
public BlockEntity be;
|
||||
@Nullable
|
||||
public BuiltScreenHandler builtScreenHandler;
|
||||
private final int xSize = 176;
|
||||
private final int ySize = 176;
|
||||
|
||||
private GuiTab selectedTab;
|
||||
private List<GuiTab> tabs;
|
||||
|
||||
public boolean upgrades;
|
||||
|
||||
public GuiBase(PlayerEntity player, BlockEntity blockEntity, T screenHandler) {
|
||||
super(screenHandler, player.getInventory(), Text.literal(I18n.translate(blockEntity.getCachedState().getBlock().getTranslationKey())));
|
||||
this.be = blockEntity;
|
||||
this.builtScreenHandler = (BuiltScreenHandler) screenHandler;
|
||||
selectedTab = null;
|
||||
populateSlots();
|
||||
}
|
||||
|
||||
private void populateSlots() {
|
||||
tabs = tabBuilders.stream()
|
||||
.map(builder -> builder.build(getMachine(), this))
|
||||
.filter(GuiTab::enabled)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public int getScreenWidth() {
|
||||
return backgroundWidth;
|
||||
}
|
||||
|
||||
public void drawSlot(MatrixStack matrixStack, int x, int y, Layer layer) {
|
||||
if (layer == Layer.BACKGROUND) {
|
||||
x += this.x;
|
||||
y += this.y;
|
||||
}
|
||||
builder.drawSlot(matrixStack, this, x - 1, y - 1);
|
||||
}
|
||||
|
||||
public void drawOutputSlotBar(MatrixStack matrixStack, int x, int y, int count, Layer layer) {
|
||||
if (layer == Layer.BACKGROUND) {
|
||||
x += this.x;
|
||||
y += this.y;
|
||||
}
|
||||
builder.drawOutputSlotBar(matrixStack, this, x - 4, y - 4, count);
|
||||
}
|
||||
|
||||
public void drawArmourSlots(MatrixStack matrixStack, int x, int y, Layer layer) {
|
||||
if (layer == Layer.BACKGROUND) {
|
||||
x += this.x;
|
||||
y += this.y;
|
||||
}
|
||||
builder.drawSlot(matrixStack, this, x - 1, y - 1);
|
||||
builder.drawSlot(matrixStack, this, x - 1, y - 1 + 18);
|
||||
builder.drawSlot(matrixStack, this, x - 1, y - 1 + 18 + 18);
|
||||
builder.drawSlot(matrixStack, this, x - 1, y - 1 + 18 + 18 + 18);
|
||||
}
|
||||
|
||||
public void drawOutputSlot(MatrixStack matrixStack, int x, int y, Layer layer) {
|
||||
if (layer == Layer.BACKGROUND) {
|
||||
x += this.x;
|
||||
y += this.y;
|
||||
}
|
||||
builder.drawOutputSlot(matrixStack, this, x - 5, y - 5);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
super.init();
|
||||
if (isConfigEnabled()) {
|
||||
SlotConfigGui.init(this);
|
||||
}
|
||||
if (isConfigEnabled() && getMachine().getTank() != null && getMachine().showTankConfig()) {
|
||||
FluidConfigGui.init(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawBackground(MatrixStack matrixStack, float lastFrameDuration, int mouseX, int mouseY) {
|
||||
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
renderBackground(matrixStack);
|
||||
boolean drawPlayerSlots = selectedTab == null && drawPlayerSlots();
|
||||
updateSlotDraw(drawPlayerSlots);
|
||||
builder.drawDefaultBackground(matrixStack, this, x, y, xSize, ySize);
|
||||
if (drawPlayerSlots) {
|
||||
builder.drawPlayerSlots(matrixStack, this, x + backgroundWidth / 2, y + 93, true);
|
||||
}
|
||||
if (tryAddUpgrades() && be instanceof IUpgradeable upgradeable) {
|
||||
if (upgradeable.canBeUpgraded()) {
|
||||
builder.drawUpgrades(matrixStack, this, x - 24, y + 6);
|
||||
upgrades = true;
|
||||
}
|
||||
}
|
||||
int offset = upgrades ? 86 : 6;
|
||||
for (GuiTab slot : tabs) {
|
||||
if (slot.enabled()) {
|
||||
builder.drawSlotTab(matrixStack, this, x - 24, y + offset, slot.stack());
|
||||
offset += 24;
|
||||
}
|
||||
}
|
||||
|
||||
final GuiBase<T> gui = this;
|
||||
getTab().ifPresent(guiTab -> builder.drawSlotConfigTips(matrixStack, gui, x + backgroundWidth / 2, y + 93, mouseX, mouseY, guiTab));
|
||||
|
||||
}
|
||||
|
||||
private void updateSlotDraw(boolean doDraw) {
|
||||
if (builtScreenHandler == null) {
|
||||
return;
|
||||
}
|
||||
for (Slot slot : builtScreenHandler.slots) {
|
||||
if (slot instanceof PlayerInventorySlot) {
|
||||
((PlayerInventorySlot) slot).doDraw = doDraw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean drawPlayerSlots() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean tryAddUpgrades() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
@Override
|
||||
protected void drawForeground(MatrixStack matrixStack, int mouseX, int mouseY) {
|
||||
drawTitle(matrixStack);
|
||||
getTab().ifPresent(guiTab -> guiTab.draw(matrixStack, mouseX, mouseY));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(MatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) {
|
||||
super.render(matrixStack, mouseX, mouseY, partialTicks);
|
||||
this.drawMouseoverTooltip(matrixStack, mouseX, mouseY);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawMouseoverTooltip(MatrixStack matrixStack, int mouseX, int mouseY) {
|
||||
if (isPointWithinBounds(-25, 6, 24, 80, mouseX, mouseY) && upgrades
|
||||
&& this.focusedSlot != null && !this.focusedSlot.hasStack()) {
|
||||
List<Text> list = new ArrayList<>();
|
||||
list.add(Text.translatable("reborncore.gui.tooltip.upgrades"));
|
||||
renderTooltip(matrixStack, list, mouseX, mouseY);
|
||||
}
|
||||
int offset = upgrades ? 82 : 0;
|
||||
for (GuiTab tab : tabs) {
|
||||
if (isPointWithinBounds(-26, 6 + offset, 24, 23, mouseX, mouseY)) {
|
||||
renderTooltip(matrixStack, Collections.singletonList(Text.translatable(tab.name())), mouseX, mouseY);
|
||||
}
|
||||
offset += 24;
|
||||
}
|
||||
|
||||
for (Selectable selectable : selectables) {
|
||||
if (selectable instanceof ClickableWidget clickable) {
|
||||
if (clickable.isHovered()) {
|
||||
clickable.renderTooltip(matrixStack, mouseX, mouseY);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
super.drawMouseoverTooltip(matrixStack, mouseX, mouseY);
|
||||
}
|
||||
|
||||
protected void drawTitle(MatrixStack matrixStack) {
|
||||
drawCentredText(matrixStack, Text.translatable(be.getCachedState().getBlock().getTranslationKey()), 6, 4210752, Layer.FOREGROUND);
|
||||
}
|
||||
|
||||
public void drawCentredText(MatrixStack matrixStack, Text text, int y, int colour, Layer layer) {
|
||||
drawText(matrixStack, text, (backgroundWidth / 2 - getTextRenderer().getWidth(text) / 2), y, colour, layer);
|
||||
}
|
||||
|
||||
protected void drawCentredText(MatrixStack matrixStack, Text text, int y, int colour, int modifier, Layer layer) {
|
||||
drawText(matrixStack, text, (backgroundWidth / 2 - (getTextRenderer().getWidth(text)) / 2) + modifier, y, colour, layer);
|
||||
}
|
||||
|
||||
public void drawText(MatrixStack matrixStack, Text text, int x, int y, int colour, Layer layer) {
|
||||
int factorX = 0;
|
||||
int factorY = 0;
|
||||
if (layer == Layer.BACKGROUND) {
|
||||
factorX = this.x;
|
||||
factorY = this.y;
|
||||
}
|
||||
getTextRenderer().draw(matrixStack, text, x + factorX, y + factorY, colour);
|
||||
RenderSystem.setShaderColor(1F, 1F, 1F, 1F);
|
||||
}
|
||||
|
||||
public GuiButtonHologram addHologramButton(int x, int y, int id, Layer layer) {
|
||||
GuiButtonHologram buttonHologram = new GuiButtonHologram(x + this.x, y + this.y, this, layer, var1 -> {
|
||||
});
|
||||
addSelectableChild(buttonHologram);
|
||||
return buttonHologram;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseClicked(double mouseX, double mouseY, int mouseButton) {
|
||||
if (getTab().map(guiTab -> guiTab.click(mouseX, mouseY, mouseButton)).orElse(false)) {
|
||||
return true;
|
||||
}
|
||||
return super.mouseClicked(mouseX, mouseY, mouseButton);
|
||||
}
|
||||
|
||||
// @Override
|
||||
// protected void mouseClickMove(double mouseX, double mouseY, int clickedMouseButton, long timeSinceLastClick) {
|
||||
// if (isConfigEnabled() && slotConfigType == SlotConfigType.ITEMS && getMachine().hasSlotConfig()) {
|
||||
// GuiSlotConfiguration.mouseClickMove(mouseX, mouseY, clickedMouseButton, timeSinceLastClick, this);
|
||||
// }
|
||||
// if (isConfigEnabled() && slotConfigType == SlotConfigType.FLUIDS && getMachine().showTankConfig()) {
|
||||
// GuiFluidConfiguration.mouseClickMove(mouseX, mouseY, clickedMouseButton, timeSinceLastClick, this);
|
||||
// }
|
||||
// super.mouseClickMove(mouseX, mouseY, clickedMouseButton, timeSinceLastClick);
|
||||
// }
|
||||
|
||||
@Override
|
||||
public boolean mouseReleased(double mouseX, double mouseY, int state) {
|
||||
int offset = 0;
|
||||
if (!upgrades) {
|
||||
offset = 80;
|
||||
}
|
||||
for (GuiTab tab : tabs) {
|
||||
if (isPointWithinBounds(-26, 84 - offset, 30, 23, mouseX, mouseY)) {
|
||||
if (selectedTab == tab) {
|
||||
closeSelectedTab();
|
||||
} else {
|
||||
selectedTab = tab;
|
||||
}
|
||||
SlotConfigGui.reset();
|
||||
break;
|
||||
}
|
||||
offset -= 24;
|
||||
}
|
||||
|
||||
if (getTab().map(guiTab -> guiTab.mouseReleased(mouseX, mouseY, state)).orElse(false)) {
|
||||
return true;
|
||||
}
|
||||
return super.mouseReleased(mouseX, mouseY, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
|
||||
if (getTab().map(guiTab -> guiTab.keyPress(keyCode, scanCode, modifiers)).orElse(false)) {
|
||||
return true;
|
||||
}
|
||||
if (selectedTab != null && keyCode == GLFW.GLFW_KEY_ESCAPE) {
|
||||
closeSelectedTab();
|
||||
return true;
|
||||
}
|
||||
return super.keyPressed(keyCode, scanCode, modifiers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
closeSelectedTab();
|
||||
super.close();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public MachineBaseBlockEntity getMachine() {
|
||||
return (MachineBaseBlockEntity) be;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param rectX {@code int} Top left corner of region
|
||||
* @param rectY {@code int} Top left corner of region
|
||||
* @param rectWidth {@code int} Width of region
|
||||
* @param rectHeight {@code int} Height of region
|
||||
* @param pointX {@code int} Mouse pointer
|
||||
* @param pointY {@code int} Mouse pointer
|
||||
* @return {@code boolean} Returns true if mouse pointer is in region specified
|
||||
*/
|
||||
public boolean isPointInRect(int rectX, int rectY, int rectWidth, int rectHeight, double pointX, double pointY) {
|
||||
return super.isPointWithinBounds(rectX, rectY, rectWidth, rectHeight, pointX, pointY);
|
||||
}
|
||||
|
||||
public enum Layer {
|
||||
BACKGROUND, FOREGROUND
|
||||
}
|
||||
|
||||
public interface FluidCellProvider {
|
||||
ItemStack provide(Fluid fluid);
|
||||
}
|
||||
|
||||
public boolean isConfigEnabled() {
|
||||
return be instanceof MachineBaseBlockEntity && builtScreenHandler != null;
|
||||
}
|
||||
|
||||
public int getGuiLeft() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public int getGuiTop() {
|
||||
return y;
|
||||
}
|
||||
|
||||
public MinecraftClient getMinecraft() {
|
||||
// Just to stop complaints from IDEA
|
||||
if (client == null) {
|
||||
throw new NullPointerException("Minecraft client is null.");
|
||||
}
|
||||
return this.client;
|
||||
}
|
||||
|
||||
public TextRenderer getTextRenderer() {
|
||||
return this.textRenderer;
|
||||
}
|
||||
|
||||
public Optional<GuiTab> getTab() {
|
||||
if (!isConfigEnabled()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
return Optional.ofNullable(selectedTab);
|
||||
}
|
||||
|
||||
public boolean isTabOpen() {
|
||||
return selectedTab != null;
|
||||
}
|
||||
|
||||
public boolean hideGuiElements() {
|
||||
return selectedTab != null && selectedTab.hideGuiElements();
|
||||
}
|
||||
|
||||
public void closeSelectedTab() {
|
||||
selectedTab = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isClickOutsideBounds(double mouseX, double mouseY, int left, int top, int mouseButton) {
|
||||
// Upgrades are normally outside the bounds, so let's pretend we are within the bounds if there is a slot here.
|
||||
return getSlotAt(mouseX, mouseY) == null && super.isClickOutsideBounds(mouseX, mouseY, left, top, mouseButton);
|
||||
}
|
||||
|
||||
public List<GuiTab> getTabs() {
|
||||
return tabs;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,101 @@
|
|||
/*
|
||||
* This file is part of RebornCore, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2021 TeamReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package reborncore.client.gui.builder;
|
||||
|
||||
import net.minecraft.client.render.item.ItemRenderer;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.text.Text;
|
||||
import reborncore.client.RenderUtil;
|
||||
import reborncore.client.gui.guibuilder.GuiBuilder;
|
||||
import reborncore.common.blockentity.RedstoneConfiguration;
|
||||
import reborncore.common.network.IdentifiedPacket;
|
||||
import reborncore.common.network.NetworkManager;
|
||||
import reborncore.common.network.ServerBoundPackets;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public class RedstoneConfigGui {
|
||||
|
||||
public static void draw(MatrixStack matrixStack, GuiBase<?> guiBase, int mouseX, int mouseY) {
|
||||
if (guiBase.getMachine() == null) return;
|
||||
RedstoneConfiguration configuration = guiBase.getMachine().getRedstoneConfiguration();
|
||||
GuiBuilder builder = guiBase.builder;
|
||||
ItemRenderer itemRenderer = guiBase.getMinecraft().getItemRenderer();
|
||||
|
||||
int x = 10;
|
||||
int y = 100;
|
||||
|
||||
int i = 0;
|
||||
int spread = configuration.getElements().size() == 3 ? 27 : 18;
|
||||
for (RedstoneConfiguration.Element element : configuration.getElements()) {
|
||||
itemRenderer.renderInGuiWithOverrides(element.getIcon(), x - 3, y + (i * spread) - 5);
|
||||
|
||||
guiBase.getTextRenderer().draw(matrixStack, Text.translatable("reborncore.gui.fluidconfig." + element.getName()), x + 15, y + (i * spread), -1);
|
||||
|
||||
boolean hovered = withinBounds(guiBase, mouseX, mouseY, x + 92, y + (i * spread) - 2, 63, 15);
|
||||
int color = hovered ? 0xFF8b8b8b : 0x668b8b8b;
|
||||
RenderUtil.drawGradientRect(matrixStack, 0, x + 91, y + (i * spread) - 2, x + 93 + 65, y + (i * spread) + 10, color, color);
|
||||
|
||||
Text name = Text.translatable("reborncore.gui.fluidconfig." + configuration.getState(element).name().toLowerCase(Locale.ROOT));
|
||||
guiBase.drawCentredText(matrixStack, name, y + (i * spread), -1, x + 37, GuiBase.Layer.FOREGROUND);
|
||||
//guiBase.getTextRenderer().drawWithShadow(name, x + 92, y + (i * spread), -1);
|
||||
i++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static boolean mouseClicked(GuiBase<?> guiBase, double mouseX, double mouseY, int mouseButton) {
|
||||
if (guiBase.getMachine() == null) return false;
|
||||
RedstoneConfiguration configuration = guiBase.getMachine().getRedstoneConfiguration();
|
||||
|
||||
int x = 10;
|
||||
int y = 100;
|
||||
|
||||
int i = 0;
|
||||
int spread = configuration.getElements().size() == 3 ? 27 : 18;
|
||||
for (RedstoneConfiguration.Element element : configuration.getElements()) {
|
||||
if (withinBounds(guiBase, (int) mouseX, (int) mouseY, x + 91, y + (i * spread) - 2, 63, 15)) {
|
||||
RedstoneConfiguration.State currentState = configuration.getState(element);
|
||||
int ns = currentState.ordinal() + 1;
|
||||
if (ns >= RedstoneConfiguration.State.values().length) {
|
||||
ns = 0;
|
||||
}
|
||||
RedstoneConfiguration.State nextState = RedstoneConfiguration.State.values()[ns];
|
||||
IdentifiedPacket packet = ServerBoundPackets.createPacketSetRedstoneSate(guiBase.getMachine().getPos(), element, nextState);
|
||||
NetworkManager.sendToServer(packet);
|
||||
return true;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean withinBounds(GuiBase<?> guiBase, int mouseX, int mouseY, int x, int y, int width, int height) {
|
||||
mouseX -= guiBase.getGuiLeft();
|
||||
mouseY -= guiBase.getGuiTop();
|
||||
return (mouseX > x && mouseX < x + width) && (mouseY > y && mouseY < y + height);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,143 @@
|
|||
/*
|
||||
* This file is part of RebornCore, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2021 TeamReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package reborncore.client.gui.builder.slot;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import reborncore.client.gui.builder.GuiBase;
|
||||
import reborncore.client.gui.builder.slot.elements.ConfigFluidElement;
|
||||
import reborncore.client.gui.builder.slot.elements.ElementBase;
|
||||
import reborncore.client.gui.builder.slot.elements.SlotType;
|
||||
import reborncore.common.blockentity.MachineBaseBlockEntity;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class FluidConfigGui {
|
||||
|
||||
static ConfigFluidElement fluidConfigElement;
|
||||
|
||||
public static void init(GuiBase<?> guiBase) {
|
||||
fluidConfigElement = new ConfigFluidElement(guiBase.getMachine().getTank(), SlotType.NORMAL, 35 - guiBase.getGuiLeft() + 50, 35 - guiBase.getGuiTop() - 25, guiBase);
|
||||
}
|
||||
|
||||
public static void draw(MatrixStack matrixStack, GuiBase<?> guiBase, int mouseX, int mouseY) {
|
||||
fluidConfigElement.draw(matrixStack, guiBase);
|
||||
}
|
||||
|
||||
public static List<ConfigFluidElement> getVisibleElements() {
|
||||
return Collections.singletonList(fluidConfigElement);
|
||||
}
|
||||
|
||||
public static boolean mouseClicked(GuiBase<?> guiBase, double mouseX, double mouseY, int mouseButton) {
|
||||
if (mouseButton == 0) {
|
||||
for (ConfigFluidElement configFluidElement : getVisibleElements()) {
|
||||
for (ElementBase element : configFluidElement.elements) {
|
||||
if (element.isInRect(guiBase, element.x, element.y, element.getWidth(guiBase.getMachine()), element.getHeight(guiBase.getMachine()), mouseX, mouseY)) {
|
||||
element.isPressing = true;
|
||||
boolean action = element.onStartPress(guiBase.getMachine(), guiBase, mouseX, mouseY);
|
||||
for (ElementBase e : getVisibleElements()) {
|
||||
if (e != element) {
|
||||
e.isPressing = false;
|
||||
}
|
||||
}
|
||||
if (action) {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
element.isPressing = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return !getVisibleElements().isEmpty();
|
||||
}
|
||||
|
||||
public static void mouseClickMove(double mouseX, double mouseY, int mouseButton, long timeSinceLastClick, GuiBase<?> guiBase) {
|
||||
if (mouseButton == 0) {
|
||||
for (ConfigFluidElement configFluidElement : getVisibleElements()) {
|
||||
for (ElementBase element : configFluidElement.elements) {
|
||||
if (element.isInRect(guiBase, element.x, element.y, element.getWidth(guiBase.getMachine()), element.getHeight(guiBase.getMachine()), mouseX, mouseY)) {
|
||||
element.isDragging = true;
|
||||
boolean action = element.onDrag(guiBase.getMachine(), guiBase, mouseX, mouseY);
|
||||
for (ElementBase e : getVisibleElements()) {
|
||||
if (e != element) {
|
||||
e.isDragging = false;
|
||||
}
|
||||
}
|
||||
if (action) {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
element.isDragging = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean mouseReleased(GuiBase<?> guiBase, double mouseX, double mouseY, int mouseButton) {
|
||||
boolean clicked = false;
|
||||
if (mouseButton == 0) {
|
||||
for (ConfigFluidElement configFluidElement : getVisibleElements()) {
|
||||
if (configFluidElement.isInRect(guiBase, configFluidElement.x, configFluidElement.y, configFluidElement.getWidth(guiBase.getMachine()), configFluidElement.getHeight(guiBase.getMachine()), mouseX, mouseY)) {
|
||||
clicked = true;
|
||||
}
|
||||
for (ElementBase element : Lists.reverse(configFluidElement.elements)) {
|
||||
if (element.isInRect(guiBase, element.x, element.y, element.getWidth(guiBase.getMachine()), element.getHeight(guiBase.getMachine()), mouseX, mouseY)) {
|
||||
element.isReleasing = true;
|
||||
boolean action = element.onRelease(guiBase.getMachine(), guiBase, mouseX, mouseY);
|
||||
for (ElementBase e : getVisibleElements()) {
|
||||
if (e != element) {
|
||||
e.isReleasing = false;
|
||||
}
|
||||
}
|
||||
if (action) {
|
||||
clicked = true;
|
||||
}
|
||||
break;
|
||||
} else {
|
||||
element.isReleasing = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return clicked;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static MachineBaseBlockEntity getMachine() {
|
||||
if (!(MinecraftClient.getInstance().currentScreen instanceof GuiBase<?> base)) {
|
||||
return null;
|
||||
}
|
||||
if (base.be instanceof MachineBaseBlockEntity machineBase) {
|
||||
return machineBase;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,181 @@
|
|||
/*
|
||||
* This file is part of RebornCore, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2021 TeamReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package reborncore.client.gui.builder.slot;
|
||||
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
import reborncore.client.gui.builder.GuiBase;
|
||||
import reborncore.common.blockentity.MachineBaseBlockEntity;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class GuiTab {
|
||||
|
||||
private final Builder builder;
|
||||
private final MachineBaseBlockEntity machineBaseBlockEntity;
|
||||
private final GuiBase<?> guiBase;
|
||||
|
||||
private GuiTab(Builder builder, MachineBaseBlockEntity machineBaseBlockEntity, GuiBase<?> guiBase) {
|
||||
this.builder = builder;
|
||||
this.machineBaseBlockEntity = machineBaseBlockEntity;
|
||||
this.guiBase = guiBase;
|
||||
}
|
||||
|
||||
public String name() {
|
||||
return builder.name;
|
||||
}
|
||||
|
||||
public boolean enabled() {
|
||||
return builder.enabled.apply(this);
|
||||
}
|
||||
|
||||
public ItemStack stack() {
|
||||
return builder.stack.apply(this);
|
||||
}
|
||||
|
||||
public MachineBaseBlockEntity machine() {
|
||||
return machineBaseBlockEntity;
|
||||
}
|
||||
|
||||
public void draw(MatrixStack matrixStack, int x, int y) {
|
||||
builder.draw.draw(matrixStack, guiBase, x, y);
|
||||
}
|
||||
|
||||
public boolean click(double mouseX, double mouseY, int mouseButton) {
|
||||
return builder.click.click(guiBase, mouseX, mouseY, mouseButton);
|
||||
}
|
||||
|
||||
public boolean mouseReleased(double mouseX, double mouseY, int mouseButton) {
|
||||
return builder.mouseReleased.mouseReleased(guiBase, mouseX, mouseY, mouseButton);
|
||||
}
|
||||
|
||||
public boolean keyPress(int keyCode, int scanCode, int modifiers) {
|
||||
return builder.keyPressed.keyPress(guiBase, keyCode, scanCode, modifiers);
|
||||
}
|
||||
|
||||
public List<String> getTips() {
|
||||
List<String> tips = new LinkedList<>();
|
||||
builder.tips.accept(tips);
|
||||
return tips;
|
||||
}
|
||||
|
||||
public boolean hideGuiElements() {
|
||||
return builder.hideGuiElements;
|
||||
}
|
||||
|
||||
public GuiBase<?> gui() {
|
||||
return guiBase;
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
|
||||
private String name;
|
||||
private Function<GuiTab, Boolean> enabled = (tab) -> true;
|
||||
private Function<GuiTab, ItemStack> stack = (tab) -> ItemStack.EMPTY;
|
||||
private Draw draw = (matrixStack, gui, x, y) -> {
|
||||
};
|
||||
private Click click = (guiBase, mouseX, mouseY, mouseButton) -> false;
|
||||
private MouseReleased mouseReleased = (guiBase, mouseX, mouseY, state) -> false;
|
||||
private KeyPressed keyPressed = (guiBase, keyCode, scanCode, modifiers) -> false;
|
||||
private Consumer<List<String>> tips = strings -> {
|
||||
};
|
||||
private boolean hideGuiElements = false;
|
||||
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public Builder name(String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder stack(Function<GuiTab, ItemStack> function) {
|
||||
this.stack = function;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder enabled(Function<GuiTab, Boolean> function) {
|
||||
this.enabled = function;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder draw(Draw draw) {
|
||||
this.draw = draw;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder click(Click click) {
|
||||
this.click = click;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder mouseReleased(MouseReleased mouseReleased) {
|
||||
this.mouseReleased = mouseReleased;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder keyPressed(KeyPressed keyPressed) {
|
||||
this.keyPressed = keyPressed;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder tips(Consumer<List<String>> listConsumer) {
|
||||
this.tips = listConsumer;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder hideGuiElements() {
|
||||
hideGuiElements = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public GuiTab build(MachineBaseBlockEntity blockEntity, GuiBase<?> guiBase) {
|
||||
Validate.notBlank(name, "No name provided");
|
||||
return new GuiTab(this, blockEntity, guiBase);
|
||||
}
|
||||
|
||||
public interface Draw {
|
||||
void draw(MatrixStack matrixStack, GuiBase<?> guiBase, int mouseX, int mouseY);
|
||||
}
|
||||
|
||||
public interface Click {
|
||||
boolean click(GuiBase<?> guiBase, double mouseX, double mouseY, int mouseButton);
|
||||
}
|
||||
|
||||
public interface MouseReleased {
|
||||
boolean mouseReleased(GuiBase<?> guiBase, double mouseX, double mouseY, int state);
|
||||
}
|
||||
|
||||
public interface KeyPressed {
|
||||
boolean keyPress(GuiBase<?> guiBase, int keyCode, int scanCode, int modifiers);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,229 @@
|
|||
/*
|
||||
* This file is part of RebornCore, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2021 TeamReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package reborncore.client.gui.builder.slot;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.screen.slot.Slot;
|
||||
import net.minecraft.text.Text;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import reborncore.client.gui.GuiUtil;
|
||||
import reborncore.client.gui.builder.GuiBase;
|
||||
import reborncore.client.gui.builder.slot.elements.ConfigSlotElement;
|
||||
import reborncore.client.gui.builder.slot.elements.ElementBase;
|
||||
import reborncore.client.gui.builder.slot.elements.SlotType;
|
||||
import reborncore.common.screen.BuiltScreenHandler;
|
||||
import reborncore.common.blockentity.MachineBaseBlockEntity;
|
||||
import reborncore.common.network.NetworkManager;
|
||||
import reborncore.common.network.ServerBoundPackets;
|
||||
import reborncore.client.ClientChatUtils;
|
||||
import reborncore.common.util.Color;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class SlotConfigGui {
|
||||
|
||||
static HashMap<Integer, ConfigSlotElement> slotElementMap = new HashMap<>();
|
||||
|
||||
public static int selectedSlot = 0;
|
||||
|
||||
public static void reset() {
|
||||
selectedSlot = -1;
|
||||
}
|
||||
|
||||
public static void init(GuiBase<?> guiBase) {
|
||||
reset();
|
||||
slotElementMap.clear();
|
||||
|
||||
BuiltScreenHandler container = guiBase.builtScreenHandler;
|
||||
for (Slot slot : container.slots) {
|
||||
if (guiBase.be != slot.inventory) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ConfigSlotElement slotElement = new ConfigSlotElement(guiBase.getMachine().getOptionalInventory().get(), slot.getIndex(), SlotType.NORMAL, slot.x - guiBase.getGuiLeft() + 50, slot.y - guiBase.getGuiTop() - 25, guiBase);
|
||||
slotElementMap.put(slot.getIndex(), slotElement);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void draw(MatrixStack matrixStack, GuiBase<?> guiBase, int mouseX, int mouseY) {
|
||||
BuiltScreenHandler container = guiBase.builtScreenHandler;
|
||||
for (Slot slot : container.slots) {
|
||||
if (guiBase.be != slot.inventory) {
|
||||
continue;
|
||||
}
|
||||
RenderSystem.setShaderColor(1.0F, 0, 0, 1.0F);
|
||||
Color color = new Color(255, 0, 0, 128);
|
||||
GuiUtil.drawGradientRect(matrixStack, slot.x - 1, slot.y - 1, 18, 18, color.getColor(), color.getColor());
|
||||
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
}
|
||||
|
||||
if (selectedSlot != -1) {
|
||||
|
||||
slotElementMap.get(selectedSlot).draw(matrixStack, guiBase);
|
||||
}
|
||||
}
|
||||
|
||||
public static List<ConfigSlotElement> getVisibleElements() {
|
||||
if (selectedSlot == -1) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return slotElementMap.values().stream()
|
||||
.filter(configSlotElement -> configSlotElement.getId() == selectedSlot)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static void copyToClipboard() {
|
||||
MachineBaseBlockEntity machine = getMachine();
|
||||
if (machine == null || machine.getSlotConfiguration() == null) {
|
||||
return;
|
||||
}
|
||||
String json = machine.getSlotConfiguration().toJson(machine.getClass().getCanonicalName());
|
||||
MinecraftClient.getInstance().keyboard.setClipboard(json);
|
||||
ClientChatUtils.addHudMessage(Text.literal("Slot configuration copied to clipboard"));
|
||||
}
|
||||
|
||||
public static void pasteFromClipboard() {
|
||||
MachineBaseBlockEntity machine = getMachine();
|
||||
if (machine == null || machine.getSlotConfiguration() == null) {
|
||||
return;
|
||||
}
|
||||
String json = MinecraftClient.getInstance().keyboard.getClipboard();
|
||||
try {
|
||||
machine.getSlotConfiguration().readJson(json, machine.getClass().getCanonicalName());
|
||||
NetworkManager.sendToServer(ServerBoundPackets.createPacketConfigSave(machine.getPos(), machine.getSlotConfiguration()));
|
||||
ClientChatUtils.addHudMessage(Text.literal("Slot configuration loaded from clipboard"));
|
||||
} catch (UnsupportedOperationException e) {
|
||||
ClientChatUtils.addHudMessage(Text.literal(e.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static MachineBaseBlockEntity getMachine() {
|
||||
if (!(MinecraftClient.getInstance().currentScreen instanceof GuiBase<?> base)) {
|
||||
return null;
|
||||
}
|
||||
if (base.be instanceof MachineBaseBlockEntity machineBase) {
|
||||
return machineBase;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean mouseClicked(GuiBase<?> guiBase, double mouseX, double mouseY, int mouseButton) {
|
||||
if (mouseButton == 0) {
|
||||
for (ConfigSlotElement configSlotElement : getVisibleElements()) {
|
||||
for (ElementBase element : configSlotElement.elements) {
|
||||
if (element.isInRect(guiBase, element.x, element.y, element.getWidth(guiBase.getMachine()), element.getHeight(guiBase.getMachine()), mouseX, mouseY)) {
|
||||
element.isPressing = true;
|
||||
boolean action = element.onStartPress(guiBase.getMachine(), guiBase, mouseX, mouseY);
|
||||
for (ElementBase e : getVisibleElements()) {
|
||||
if (e != element) {
|
||||
e.isPressing = false;
|
||||
}
|
||||
}
|
||||
if (action) {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
element.isPressing = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
BuiltScreenHandler screenHandler = guiBase.builtScreenHandler;
|
||||
|
||||
if (getVisibleElements().isEmpty()) {
|
||||
for (Slot slot : screenHandler.slots) {
|
||||
if (guiBase.be != slot.inventory) {
|
||||
continue;
|
||||
}
|
||||
if (guiBase.isPointInRect(slot.x, slot.y, 18, 18, mouseX, mouseY)) {
|
||||
selectedSlot = slot.getIndex();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return !getVisibleElements().isEmpty();
|
||||
}
|
||||
|
||||
public static void mouseClickMove(double mouseX, double mouseY, int mouseButton, long timeSinceLastClick, GuiBase<?> guiBase) {
|
||||
if (mouseButton == 0) {
|
||||
for (ConfigSlotElement configSlotElement : getVisibleElements()) {
|
||||
for (ElementBase element : configSlotElement.elements) {
|
||||
if (element.isInRect(guiBase, element.x, element.y, element.getWidth(guiBase.getMachine()), element.getHeight(guiBase.getMachine()), mouseX, mouseY)) {
|
||||
element.isDragging = true;
|
||||
boolean action = element.onDrag(guiBase.getMachine(), guiBase, mouseX, mouseY);
|
||||
for (ElementBase e : getVisibleElements()) {
|
||||
if (e != element) {
|
||||
e.isDragging = false;
|
||||
}
|
||||
}
|
||||
if (action) {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
element.isDragging = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean mouseReleased(GuiBase<?> guiBase, double mouseX, double mouseY, int mouseButton) {
|
||||
boolean clicked = false;
|
||||
if (mouseButton == 0) {
|
||||
for (ConfigSlotElement configSlotElement : getVisibleElements()) {
|
||||
if (configSlotElement.isInRect(guiBase, configSlotElement.x, configSlotElement.y, configSlotElement.getWidth(guiBase.getMachine()), configSlotElement.getHeight(guiBase.getMachine()), mouseX, mouseY)) {
|
||||
clicked = true;
|
||||
}
|
||||
for (ElementBase element : Lists.reverse(configSlotElement.elements)) {
|
||||
if (element.isInRect(guiBase, element.x, element.y, element.getWidth(guiBase.getMachine()), element.getHeight(guiBase.getMachine()), mouseX, mouseY)) {
|
||||
element.isReleasing = true;
|
||||
boolean action = element.onRelease(guiBase.getMachine(), guiBase, mouseX, mouseY);
|
||||
for (ElementBase e : getVisibleElements()) {
|
||||
if (e != element) {
|
||||
e.isReleasing = false;
|
||||
}
|
||||
}
|
||||
if (action) {
|
||||
clicked = true;
|
||||
}
|
||||
break;
|
||||
} else {
|
||||
element.isReleasing = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return clicked;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* This file is part of RebornCore, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2021 TeamReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package reborncore.client.gui.builder.slot.elements;
|
||||
|
||||
public class ButtonElement extends ElementBase {
|
||||
@SuppressWarnings("unused")
|
||||
private final Sprite.Button buttonSprite;
|
||||
|
||||
public ButtonElement(int x, int y, Sprite.Button buttonSprite) {
|
||||
super(x, y, buttonSprite.normal());
|
||||
this.buttonSprite = buttonSprite;
|
||||
this.addUpdateAction((gui, element) -> {
|
||||
if (isHovering) {
|
||||
element.container.setSprite(0, buttonSprite.hovered());
|
||||
} else {
|
||||
element.container.setSprite(0, buttonSprite.normal());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,78 @@
|
|||
/*
|
||||
* This file is part of RebornCore, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2021 TeamReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package reborncore.client.gui.builder.slot.elements;
|
||||
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.text.Text;
|
||||
import reborncore.client.gui.builder.GuiBase;
|
||||
import reborncore.common.blockentity.MachineBaseBlockEntity;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class CheckBoxElement extends ElementBase {
|
||||
public Text label;
|
||||
public String type;
|
||||
public int labelColor, slotID;
|
||||
public MachineBaseBlockEntity machineBase;
|
||||
Predicate<CheckBoxElement> ticked;
|
||||
|
||||
private final Sprite.CheckBox checkBoxSprite;
|
||||
|
||||
public CheckBoxElement(Text label, int labelColor, int x, int y, String type, int slotID, Sprite.CheckBox checkBoxSprite, MachineBaseBlockEntity machineBase, Predicate<CheckBoxElement> ticked) {
|
||||
super(x, y, checkBoxSprite.normal());
|
||||
this.checkBoxSprite = checkBoxSprite;
|
||||
this.type = type;
|
||||
this.slotID = slotID;
|
||||
this.machineBase = machineBase;
|
||||
this.label = label;
|
||||
this.labelColor = labelColor;
|
||||
this.ticked = ticked;
|
||||
if (ticked.test(this)) {
|
||||
container.setSprite(0, checkBoxSprite.ticked());
|
||||
} else {
|
||||
container.setSprite(0, checkBoxSprite.normal());
|
||||
}
|
||||
this.addPressAction((element, gui, provider, mouseX, mouseY) -> {
|
||||
if (ticked.test(this)) {
|
||||
element.container.setSprite(0, checkBoxSprite.ticked());
|
||||
} else {
|
||||
element.container.setSprite(0, checkBoxSprite.normal());
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(MatrixStack matrixStack, GuiBase<?> gui) {
|
||||
// super.draw(gui);
|
||||
ISprite sprite = checkBoxSprite.normal();
|
||||
if (ticked.test(this)) {
|
||||
sprite = checkBoxSprite.ticked();
|
||||
}
|
||||
drawSprite(matrixStack, gui, sprite, x, y);
|
||||
drawText(matrixStack, gui, label, x + checkBoxSprite.normal().width + 5, ((y + getHeight(gui.getMachine()) / 2) - (gui.getTextRenderer().fontHeight / 2)), labelColor);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,81 @@
|
|||
/*
|
||||
* This file is part of RebornCore, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2021 TeamReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package reborncore.client.gui.builder.slot.elements;
|
||||
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.text.Text;
|
||||
import reborncore.client.gui.builder.GuiBase;
|
||||
import reborncore.common.util.Tank;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ConfigFluidElement extends ElementBase {
|
||||
SlotType type;
|
||||
Tank tank;
|
||||
public List<ElementBase> elements = new ArrayList<>();
|
||||
boolean filter = false;
|
||||
|
||||
public ConfigFluidElement(Tank tank, SlotType type, int x, int y, GuiBase<?> gui) {
|
||||
super(x, y, type.getButtonSprite());
|
||||
this.type = type;
|
||||
this.tank = tank;
|
||||
|
||||
FluidConfigPopupElement popupElement;
|
||||
|
||||
elements.add(popupElement = new FluidConfigPopupElement(x - 22, y - 22, this));
|
||||
elements.add(new ButtonElement(x + 37, y - 25, Sprite.EXIT_BUTTON).addReleaseAction((element, gui1, provider, mouseX, mouseY) -> {
|
||||
gui.closeSelectedTab();
|
||||
return true;
|
||||
}));
|
||||
|
||||
elements.add(new CheckBoxElement(Text.translatable("reborncore.gui.fluidconfig.pullin"), 0xFFFFFFFF, x - 26, y + 42, "input", 0, Sprite.LIGHT_CHECK_BOX, gui.getMachine(),
|
||||
checkBoxElement -> checkBoxElement.machineBase.fluidConfiguration.autoInput()).addPressAction((element, gui12, provider, mouseX, mouseY) -> {
|
||||
popupElement.updateCheckBox((CheckBoxElement) element, "input", gui12);
|
||||
return true;
|
||||
}));
|
||||
elements.add(new CheckBoxElement(Text.translatable("reborncore.gui.fluidconfig.pumpout"), 0xFFFFFFFF, x - 26, y + 57, "output", 0, Sprite.LIGHT_CHECK_BOX, gui.getMachine(),
|
||||
checkBoxElement -> checkBoxElement.machineBase.fluidConfiguration.autoOutput()).addPressAction((element, gui13, provider, mouseX, mouseY) -> {
|
||||
popupElement.updateCheckBox((CheckBoxElement) element, "output", gui13);
|
||||
return true;
|
||||
}));
|
||||
|
||||
setWidth(85);
|
||||
setHeight(105 + (filter ? 15 : 0));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(MatrixStack matrixStack, GuiBase<?> gui) {
|
||||
super.draw(matrixStack, gui);
|
||||
if (isHovering) {
|
||||
drawSprite(matrixStack, gui, type.getButtonHoverOverlay(), x, y);
|
||||
}
|
||||
elements.forEach(elementBase -> elementBase.draw(matrixStack, gui));
|
||||
}
|
||||
|
||||
public SlotType getType() {
|
||||
return type;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,134 @@
|
|||
/*
|
||||
* This file is part of RebornCore, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2021 TeamReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package reborncore.client.gui.builder.slot.elements;
|
||||
|
||||
import com.mojang.blaze3d.platform.GlStateManager;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.render.item.ItemRenderer;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.inventory.Inventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.text.Text;
|
||||
import reborncore.client.gui.builder.GuiBase;
|
||||
import reborncore.client.gui.builder.slot.SlotConfigGui;
|
||||
import reborncore.common.screen.slot.BaseSlot;
|
||||
import reborncore.common.blockentity.SlotConfiguration;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class ConfigSlotElement extends ElementBase {
|
||||
SlotType type;
|
||||
Inventory inventory;
|
||||
int id;
|
||||
public List<ElementBase> elements = new ArrayList<>();
|
||||
boolean filter = false;
|
||||
|
||||
public ConfigSlotElement(Inventory slotInventory, int slotId, SlotType type, int x, int y, GuiBase<?> gui) {
|
||||
super(x, y, type.getButtonSprite());
|
||||
this.type = type;
|
||||
this.inventory = slotInventory;
|
||||
this.id = slotId;
|
||||
|
||||
SlotConfigPopupElement popupElement;
|
||||
|
||||
boolean inputEnabled = gui.builtScreenHandler.slots.stream()
|
||||
.filter(Objects::nonNull)
|
||||
.filter(slot -> slot.inventory == inventory)
|
||||
.filter(slot -> slot instanceof BaseSlot)
|
||||
.map(slot -> (BaseSlot) slot)
|
||||
.filter(baseSlot -> baseSlot.getIndex() == slotId)
|
||||
.allMatch(BaseSlot::canWorldBlockInsert);
|
||||
|
||||
|
||||
elements.add(popupElement = new SlotConfigPopupElement(this.id, x - 22, y - 22, this, inputEnabled));
|
||||
elements.add(new ButtonElement(x + 37, y - 25, Sprite.EXIT_BUTTON).addReleaseAction((element, gui1, provider, mouseX, mouseY) -> {
|
||||
SlotConfigGui.selectedSlot = -1;
|
||||
gui.closeSelectedTab();
|
||||
return true;
|
||||
}));
|
||||
|
||||
if (inputEnabled) {
|
||||
elements.add(new CheckBoxElement(Text.translatable("reborncore.gui.slotconfig.autoinput"), 0xFFFFFFFF, x - 26, y + 42, "input", slotId, Sprite.LIGHT_CHECK_BOX, gui.getMachine(),
|
||||
checkBoxElement -> checkBoxElement.machineBase.getSlotConfiguration().getSlotDetails(checkBoxElement.slotID).autoInput()).addPressAction((element, gui12, provider, mouseX, mouseY) -> {
|
||||
popupElement.updateCheckBox((CheckBoxElement) element, "input", gui12);
|
||||
return true;
|
||||
}));
|
||||
}
|
||||
|
||||
elements.add(new CheckBoxElement(Text.translatable("reborncore.gui.slotconfig.autooutput"), 0xFFFFFFFF, x - 26, y + 57, "output", slotId, Sprite.LIGHT_CHECK_BOX, gui.getMachine(),
|
||||
checkBoxElement -> checkBoxElement.machineBase.getSlotConfiguration().getSlotDetails(checkBoxElement.slotID).autoOutput()).addPressAction((element, gui13, provider, mouseX, mouseY) -> {
|
||||
popupElement.updateCheckBox((CheckBoxElement) element, "output", gui13);
|
||||
return true;
|
||||
}));
|
||||
|
||||
if (gui.getMachine() instanceof SlotConfiguration.SlotFilter slotFilter) {
|
||||
if (Arrays.stream(slotFilter.getInputSlots()).anyMatch(value -> value == slotId)) {
|
||||
elements.add(new CheckBoxElement(Text.translatable("reborncore.gui.slotconfig.filter_input"), 0xFFFFFFFF, x - 26, y + 72, "filter", slotId, Sprite.LIGHT_CHECK_BOX, gui.getMachine(),
|
||||
checkBoxElement -> checkBoxElement.machineBase.getSlotConfiguration().getSlotDetails(checkBoxElement.slotID).filter()).addPressAction((element, gui13, provider, mouseX, mouseY) -> {
|
||||
popupElement.updateCheckBox((CheckBoxElement) element, "filter", gui13);
|
||||
return true;
|
||||
}));
|
||||
filter = true;
|
||||
popupElement.filter = true;
|
||||
}
|
||||
}
|
||||
setWidth(85);
|
||||
setHeight(105 + (filter ? 15 : 0));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(MatrixStack matrixStack, GuiBase<?> gui) {
|
||||
super.draw(matrixStack, gui);
|
||||
ItemStack stack = inventory.getStack(id);
|
||||
int xPos = x + 1 + gui.getGuiLeft();
|
||||
int yPos = y + 1 + gui.getGuiTop();
|
||||
|
||||
RenderSystem.enableDepthTest();
|
||||
matrixStack.push();
|
||||
RenderSystem.enableBlend();
|
||||
RenderSystem.blendFunc(GlStateManager.SrcFactor.SRC_ALPHA, GlStateManager.DstFactor.ONE_MINUS_SRC_ALPHA);
|
||||
ItemRenderer renderItem = MinecraftClient.getInstance().getItemRenderer();
|
||||
renderItem.renderInGuiWithOverrides(stack, xPos, yPos);
|
||||
renderItem.renderGuiItemOverlay(gui.getTextRenderer(), stack, xPos, yPos, null);
|
||||
RenderSystem.disableDepthTest();
|
||||
matrixStack.pop();
|
||||
if (isHovering) {
|
||||
drawSprite(matrixStack, gui, type.getButtonHoverOverlay(), x, y);
|
||||
}
|
||||
elements.forEach(elementBase -> elementBase.draw(matrixStack, gui));
|
||||
}
|
||||
|
||||
public SlotType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,347 @@
|
|||
/*
|
||||
* This file is part of RebornCore, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2021 TeamReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package reborncore.client.gui.builder.slot.elements;
|
||||
|
||||
import com.mojang.blaze3d.platform.GlStateManager;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.render.item.ItemRenderer;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Identifier;
|
||||
import reborncore.client.RenderUtil;
|
||||
import reborncore.client.gui.builder.GuiBase;
|
||||
import reborncore.client.gui.guibuilder.GuiBuilder;
|
||||
import reborncore.common.blockentity.MachineBaseBlockEntity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ElementBase {
|
||||
|
||||
public int x;
|
||||
public int y;
|
||||
public boolean isHovering = false;
|
||||
public boolean isDragging = false;
|
||||
public boolean isPressing = false;
|
||||
public boolean isReleasing = false;
|
||||
public boolean startPressLast = false;
|
||||
public boolean isHoveringLast = false;
|
||||
public boolean isDraggingLast = false;
|
||||
public boolean isPressingLast = false;
|
||||
public boolean isReleasingLast = false;
|
||||
public List<ElementBase.Action> hoverActions = new ArrayList<>();
|
||||
public List<ElementBase.Action> dragActions = new ArrayList<>();
|
||||
public List<ElementBase.Action> startPressActions = new ArrayList<>();
|
||||
public List<ElementBase.Action> pressActions = new ArrayList<>();
|
||||
public List<ElementBase.Action> releaseActions = new ArrayList<>();
|
||||
public SpriteContainer container;
|
||||
public List<UpdateAction> updateActions = new ArrayList<>();
|
||||
public List<UpdateAction> buttonUpdate = new ArrayList<>();
|
||||
private int width;
|
||||
private int height;
|
||||
|
||||
public static final Identifier MECH_ELEMENTS = new Identifier("reborncore", "textures/gui/elements.png");
|
||||
|
||||
public ElementBase(int x, int y, SpriteContainer container) {
|
||||
this.container = container;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public ElementBase(int x, int y, ISprite... sprites) {
|
||||
this.container = new SpriteContainer();
|
||||
for (ISprite sprite : sprites) {
|
||||
container.addSprite(sprite);
|
||||
}
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public ElementBase(int x, int y, int width, int height) {
|
||||
this.container = new SpriteContainer();
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
public ElementBase(int x, int y, int width, int height, SpriteContainer container) {
|
||||
this.container = container;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
public ElementBase(int x, int y, int width, int height, ISprite... sprites) {
|
||||
this.container = new SpriteContainer();
|
||||
for (ISprite sprite : sprites) {
|
||||
container.addSprite(sprite);
|
||||
}
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
public SpriteContainer getSpriteContainer() {
|
||||
return container;
|
||||
}
|
||||
|
||||
public void adjustDimensions(MachineBaseBlockEntity provider) {
|
||||
if (container.offsetSprites != null) {
|
||||
for (OffsetSprite offsetSprite : container.offsetSprites) {
|
||||
if (offsetSprite.getSprite().getSprite(provider).width + offsetSprite.getOffsetX(provider) > this.width) {
|
||||
this.width = offsetSprite.getSprite().getSprite(provider).width + offsetSprite.getOffsetX(provider);
|
||||
}
|
||||
if (offsetSprite.getSprite().getSprite(provider).height + offsetSprite.getOffsetY(provider) > this.height) {
|
||||
this.height = offsetSprite.getSprite().getSprite(provider).height + offsetSprite.getOffsetY(provider);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void draw(MatrixStack matrixStack, GuiBase<?> gui) {
|
||||
for (OffsetSprite sprite : getSpriteContainer().offsetSprites) {
|
||||
drawSprite(matrixStack, gui, sprite.getSprite(), x + sprite.getOffsetX(gui.getMachine()), y + sprite.getOffsetY(gui.getMachine()));
|
||||
}
|
||||
}
|
||||
|
||||
public void renderUpdate(GuiBase<?> gui) {
|
||||
isHoveringLast = isHovering;
|
||||
isPressingLast = isPressing;
|
||||
isDraggingLast = isDragging;
|
||||
isReleasingLast = isReleasing;
|
||||
}
|
||||
|
||||
public void update(GuiBase<?> gui) {
|
||||
for (UpdateAction action : updateActions) {
|
||||
action.update(gui, this);
|
||||
}
|
||||
}
|
||||
|
||||
public ElementBase addUpdateAction(UpdateAction action) {
|
||||
updateActions.add(action);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ElementBase setWidth(int width) {
|
||||
this.width = width;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ElementBase setHeight(int height) {
|
||||
this.height = height;
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public ElementBase setX(int x) {
|
||||
this.x = x;
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
public ElementBase setY(int y) {
|
||||
this.y = y;
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getWidth(MachineBaseBlockEntity provider) {
|
||||
adjustDimensions(provider);
|
||||
return width;
|
||||
}
|
||||
|
||||
public int getHeight(MachineBaseBlockEntity provider) {
|
||||
adjustDimensions(provider);
|
||||
return height;
|
||||
}
|
||||
|
||||
public int getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
public int getHeight() {
|
||||
return height;
|
||||
}
|
||||
|
||||
public ElementBase addHoverAction(ElementBase.Action action) {
|
||||
this.hoverActions.add(action);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ElementBase addDragAction(ElementBase.Action action) {
|
||||
this.dragActions.add(action);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ElementBase addStartPressAction(ElementBase.Action action) {
|
||||
this.startPressActions.add(action);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ElementBase addPressAction(ElementBase.Action action) {
|
||||
this.pressActions.add(action);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ElementBase addReleaseAction(ElementBase.Action action) {
|
||||
this.releaseActions.add(action);
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean onHover(MachineBaseBlockEntity provider, GuiBase<?> gui, double mouseX, double mouseY) {
|
||||
for (ElementBase.Action action : hoverActions) {
|
||||
action.execute(this, gui, provider, mouseX, mouseY);
|
||||
}
|
||||
return !hoverActions.isEmpty();
|
||||
}
|
||||
|
||||
public boolean onDrag(MachineBaseBlockEntity provider, GuiBase<?> gui, double mouseX, double mouseY) {
|
||||
for (ElementBase.Action action : dragActions) {
|
||||
action.execute(this, gui, provider, mouseX, mouseY);
|
||||
}
|
||||
return !dragActions.isEmpty();
|
||||
}
|
||||
|
||||
public boolean onStartPress(MachineBaseBlockEntity provider, GuiBase<?> gui, double mouseX, double mouseY) {
|
||||
for (ElementBase.Action action : startPressActions) {
|
||||
action.execute(this, gui, provider, mouseX, mouseY);
|
||||
}
|
||||
return !startPressActions.isEmpty();
|
||||
}
|
||||
|
||||
public boolean onRelease(MachineBaseBlockEntity provider, GuiBase<?> gui, double mouseX, double mouseY) {
|
||||
for (ElementBase.Action action : releaseActions) {
|
||||
if (action.execute(this, gui, provider, mouseX, mouseY)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (isPressing) {
|
||||
for (ElementBase.Action action : pressActions) {
|
||||
action.execute(this, gui, provider, mouseX, mouseY);
|
||||
}
|
||||
}
|
||||
return !releaseActions.isEmpty() || !pressActions.isEmpty();
|
||||
}
|
||||
|
||||
public interface Action {
|
||||
boolean execute(ElementBase element, GuiBase<?> gui, MachineBaseBlockEntity provider, double mouseX, double mouseY);
|
||||
}
|
||||
|
||||
public interface UpdateAction {
|
||||
void update(GuiBase<?> gui, ElementBase element);
|
||||
}
|
||||
|
||||
public void drawRect(MatrixStack matrices, GuiBase<?> gui, int x, int y, int width, int height, int colour) {
|
||||
drawGradientRect(matrices, gui, x, y, width, height, colour, colour);
|
||||
}
|
||||
|
||||
/*
|
||||
Taken from Gui
|
||||
*/
|
||||
public void drawGradientRect(MatrixStack matrices, GuiBase<?> gui, int x, int y, int width, int height, int startColor, int endColor) {
|
||||
x = adjustX(gui, x);
|
||||
y = adjustY(gui, y);
|
||||
|
||||
int left = x;
|
||||
int top = y;
|
||||
int right = x + width;
|
||||
int bottom = y + height;
|
||||
|
||||
RenderUtil.drawGradientRect(matrices, 0, left, top, right, bottom, startColor, endColor);
|
||||
}
|
||||
|
||||
public int adjustX(GuiBase<?> gui, int x) {
|
||||
return gui.getGuiLeft() + x;
|
||||
}
|
||||
|
||||
public int adjustY(GuiBase<?> gui, int y) {
|
||||
return gui.getGuiTop() + y;
|
||||
}
|
||||
|
||||
public boolean isInRect(GuiBase<?> gui, int x, int y, int xSize, int ySize, double mouseX, double mouseY) {
|
||||
return gui.isPointInRect(x + gui.getGuiLeft(), y + gui.getGuiTop(), xSize, ySize, mouseX, mouseY);
|
||||
}
|
||||
|
||||
public void drawText(MatrixStack matrixStack, GuiBase<?> gui, Text text, int x, int y, int color) {
|
||||
x = adjustX(gui, x);
|
||||
y = adjustY(gui, y);
|
||||
gui.getTextRenderer().draw(matrixStack, text, x, y, color);
|
||||
}
|
||||
|
||||
public void setTextureSheet(Identifier textureLocation) {
|
||||
RenderSystem.setShaderTexture(0, textureLocation);
|
||||
}
|
||||
|
||||
public void drawSprite(MatrixStack matrixStack, GuiBase<?> gui, ISprite iSprite, int x, int y) {
|
||||
Sprite sprite = iSprite.getSprite(gui.getMachine());
|
||||
if (sprite != null) {
|
||||
if (sprite.hasTextureInfo()) {
|
||||
RenderSystem.setShaderColor(1F, 1F, 1F, 1F);
|
||||
setTextureSheet(sprite.textureLocation);
|
||||
gui.drawTexture(matrixStack, x + gui.getGuiLeft(), y + gui.getGuiTop(), sprite.x, sprite.y, sprite.width, sprite.height);
|
||||
}
|
||||
if (sprite.hasStack()) {
|
||||
matrixStack.push();
|
||||
RenderSystem.enableBlend();
|
||||
RenderSystem.blendFunc(GlStateManager.SrcFactor.SRC_ALPHA, GlStateManager.DstFactor.ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
ItemRenderer itemRenderer = MinecraftClient.getInstance().getItemRenderer();
|
||||
itemRenderer.renderInGuiWithOverrides(sprite.itemStack, x + gui.getGuiLeft(), y + gui.getGuiTop());
|
||||
|
||||
matrixStack.pop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int getScaledBurnTime(int scale, int burnTime, int totalBurnTime) {
|
||||
return (int) (((float) burnTime / (float) totalBurnTime) * scale);
|
||||
}
|
||||
|
||||
public int getPercentage(int MaxValue, int CurrentValue) {
|
||||
if (CurrentValue == 0) {
|
||||
return 0;
|
||||
}
|
||||
return (int) ((CurrentValue * 100.0f) / MaxValue);
|
||||
}
|
||||
|
||||
public void drawDefaultBackground(MatrixStack matrixStack, Screen gui, int x, int y, int width, int height) {
|
||||
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
RenderSystem.setShaderTexture(0, GuiBuilder.defaultTextureSheet);
|
||||
gui.drawTexture(matrixStack, x, y, 0, 0, width / 2, height / 2);
|
||||
gui.drawTexture(matrixStack, x + width / 2, y, 150 - width / 2, 0, width / 2, height / 2);
|
||||
gui.drawTexture(matrixStack, x, y + height / 2, 0, 150 - height / 2, width / 2, height / 2);
|
||||
gui.drawTexture(matrixStack, x + width / 2, y + height / 2, 150 - width / 2, 150 - height / 2, width / 2, height / 2);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,200 @@
|
|||
/*
|
||||
* This file is part of RebornCore, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2021 TeamReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package reborncore.client.gui.builder.slot.elements;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.render.OverlayTexture;
|
||||
import net.minecraft.client.render.RenderLayer;
|
||||
import net.minecraft.client.render.Tessellator;
|
||||
import net.minecraft.client.render.VertexConsumerProvider;
|
||||
import net.minecraft.client.render.block.BlockRenderManager;
|
||||
import net.minecraft.client.render.model.BakedModel;
|
||||
import net.minecraft.client.texture.SpriteAtlasTexture;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.util.math.Quaternion;
|
||||
import net.minecraft.util.math.Vec3f;
|
||||
import net.minecraft.world.World;
|
||||
import reborncore.RebornCore;
|
||||
import reborncore.client.gui.GuiUtil;
|
||||
import reborncore.client.gui.builder.GuiBase;
|
||||
import reborncore.common.blockentity.FluidConfiguration;
|
||||
import reborncore.common.blockentity.MachineBaseBlockEntity;
|
||||
import reborncore.common.network.IdentifiedPacket;
|
||||
import reborncore.common.network.NetworkManager;
|
||||
import reborncore.common.network.ServerBoundPackets;
|
||||
import reborncore.common.util.Color;
|
||||
import reborncore.common.util.MachineFacing;
|
||||
|
||||
public class FluidConfigPopupElement extends ElementBase {
|
||||
public boolean filter = false;
|
||||
|
||||
ConfigFluidElement fluidElement;
|
||||
double lastMouseX, lastMouseY;
|
||||
|
||||
public FluidConfigPopupElement(int x, int y, ConfigFluidElement fluidElement) {
|
||||
super(x, y, Sprite.SLOT_CONFIG_POPUP);
|
||||
this.fluidElement = fluidElement;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(MatrixStack matrixStack, GuiBase<?> gui) {
|
||||
drawDefaultBackground(matrixStack, gui, adjustX(gui, getX() - 8), adjustY(gui, getY() - 7), 84, 105 + (filter ? 15 : 0));
|
||||
super.draw(matrixStack, gui);
|
||||
|
||||
MachineBaseBlockEntity machine = ((MachineBaseBlockEntity) gui.be);
|
||||
World world = machine.getWorld();
|
||||
BlockPos pos = machine.getPos();
|
||||
BlockState state = world.getBlockState(pos);
|
||||
BlockState actualState = state.getBlock().getDefaultState();
|
||||
BlockRenderManager dispatcher = MinecraftClient.getInstance().getBlockRenderManager();
|
||||
BakedModel model = dispatcher.getModels().getModel(state.getBlock().getDefaultState());
|
||||
MinecraftClient.getInstance().getTextureManager().bindTexture(SpriteAtlasTexture.BLOCK_ATLAS_TEXTURE);
|
||||
drawState(gui, world, model, actualState, pos, dispatcher, 4, 23, Vec3f.POSITIVE_Y.getDegreesQuaternion(90F)); //left
|
||||
drawState(gui, world, model, actualState, pos, dispatcher, 23, 4, Vec3f.NEGATIVE_X.getDegreesQuaternion(90F)); //top
|
||||
drawState(gui, world, model, actualState, pos, dispatcher, 23, 23, null); //centre
|
||||
drawState(gui, world, model, actualState, pos, dispatcher, 23, 26, Vec3f.POSITIVE_X.getDegreesQuaternion(90F)); //bottom
|
||||
drawState(gui, world, model, actualState, pos, dispatcher, 42, 23, Vec3f.POSITIVE_Y.getDegreesQuaternion(90F)); //right
|
||||
drawState(gui, world, model, actualState, pos, dispatcher, 26, 42, Vec3f.POSITIVE_Y.getDegreesQuaternion(180F)); //back
|
||||
|
||||
drawSateColor(matrixStack, gui.getMachine(), MachineFacing.UP.getFacing(machine), 22, -1, gui);
|
||||
drawSateColor(matrixStack, gui.getMachine(), MachineFacing.FRONT.getFacing(machine), 22, 18, gui);
|
||||
drawSateColor(matrixStack, gui.getMachine(), MachineFacing.DOWN.getFacing(machine), 22, 37, gui);
|
||||
drawSateColor(matrixStack, gui.getMachine(), MachineFacing.RIGHT.getFacing(machine), 41, 18, gui);
|
||||
drawSateColor(matrixStack, gui.getMachine(), MachineFacing.BACK.getFacing(machine), 41, 37, gui);
|
||||
drawSateColor(matrixStack, gui.getMachine(), MachineFacing.LEFT.getFacing(machine), 3, 18, gui);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onRelease(MachineBaseBlockEntity provider, GuiBase<?> gui, double mouseX, double mouseY) {
|
||||
if (isInBox(23, 4, 16, 16, mouseX, mouseY, gui)) {
|
||||
cycleConfig(MachineFacing.UP.getFacing(provider), gui);
|
||||
} else if (isInBox(23, 23, 16, 16, mouseX, mouseY, gui)) {
|
||||
cycleConfig(MachineFacing.FRONT.getFacing(provider), gui);
|
||||
} else if (isInBox(42, 23, 16, 16, mouseX, mouseY, gui)) {
|
||||
cycleConfig(MachineFacing.RIGHT.getFacing(provider), gui);
|
||||
} else if (isInBox(4, 23, 16, 16, mouseX, mouseY, gui)) {
|
||||
cycleConfig(MachineFacing.LEFT.getFacing(provider), gui);
|
||||
} else if (isInBox(23, 42, 16, 16, mouseX, mouseY, gui)) {
|
||||
cycleConfig(MachineFacing.DOWN.getFacing(provider), gui);
|
||||
} else if (isInBox(42, 42, 16, 16, mouseX, mouseY, gui)) {
|
||||
cycleConfig(MachineFacing.BACK.getFacing(provider), gui);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void cycleConfig(Direction side, GuiBase<?> guiBase) {
|
||||
FluidConfiguration.FluidConfig config = guiBase.getMachine().fluidConfiguration.getSideDetail(side);
|
||||
|
||||
FluidConfiguration.ExtractConfig fluidIO = config.getIoConfig().getNext();
|
||||
FluidConfiguration.FluidConfig newConfig = new FluidConfiguration.FluidConfig(side, fluidIO);
|
||||
|
||||
IdentifiedPacket packetSave = ServerBoundPackets.createPacketFluidConfigSave(guiBase.be.getPos(), newConfig);
|
||||
NetworkManager.sendToServer(packetSave);
|
||||
}
|
||||
|
||||
public void updateCheckBox(CheckBoxElement checkBoxElement, String type, GuiBase<?> guiBase) {
|
||||
FluidConfiguration configHolder = guiBase.getMachine().fluidConfiguration;
|
||||
boolean input = configHolder.autoInput();
|
||||
boolean output = configHolder.autoOutput();
|
||||
if (type.equalsIgnoreCase("input")) {
|
||||
input = !configHolder.autoInput();
|
||||
}
|
||||
if (type.equalsIgnoreCase("output")) {
|
||||
output = !configHolder.autoOutput();
|
||||
}
|
||||
|
||||
IdentifiedPacket packetFluidIOSave = ServerBoundPackets.createPacketFluidIOSave(guiBase.be.getPos(), input, output);
|
||||
NetworkManager.sendToServer(packetFluidIOSave);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onHover(MachineBaseBlockEntity provider, GuiBase<?> gui, double mouseX, double mouseY) {
|
||||
lastMouseX = mouseX;
|
||||
lastMouseY = mouseY;
|
||||
return super.onHover(provider, gui, mouseX, mouseY);
|
||||
}
|
||||
|
||||
private void drawSateColor(MatrixStack matrices, MachineBaseBlockEntity machineBase, Direction side, int inx, int iny, GuiBase<?> gui) {
|
||||
iny += 4;
|
||||
int sx = inx + getX() + gui.getGuiLeft();
|
||||
int sy = iny + getY() + gui.getGuiTop();
|
||||
FluidConfiguration fluidConfiguration = machineBase.fluidConfiguration;
|
||||
if (fluidConfiguration == null) {
|
||||
RebornCore.LOGGER.debug("Hmm, this isn't supposed to happen");
|
||||
return;
|
||||
}
|
||||
FluidConfiguration.FluidConfig fluidConfig = fluidConfiguration.getSideDetail(side);
|
||||
Color color = switch (fluidConfig.getIoConfig()) {
|
||||
case NONE -> new Color(0, 0, 0, 0);
|
||||
case INPUT -> new Color(0, 0, 255, 128);
|
||||
case OUTPUT -> new Color(255, 69, 0, 128);
|
||||
case ALL -> new Color(52, 255, 30, 128);
|
||||
};
|
||||
RenderSystem.setShaderColor(1, 1, 1, 1);
|
||||
GuiUtil.drawGradientRect(matrices, sx, sy, 18, 18, color.getColor(), color.getColor());
|
||||
RenderSystem.setShaderColor(1, 1, 1, 1);
|
||||
}
|
||||
|
||||
private boolean isInBox(int rectX, int rectY, int rectWidth, int rectHeight, double pointX, double pointY, GuiBase<?> guiBase) {
|
||||
rectX += getX();
|
||||
rectY += getY();
|
||||
return isInRect(guiBase, rectX, rectY, rectWidth, rectHeight, pointX, pointY);
|
||||
//return (pointX - guiBase.getGuiLeft()) >= rectX - 1 && (pointX - guiBase.getGuiLeft()) < rectX + rectWidth + 1 && (pointY - guiBase.getGuiTop()) >= rectY - 1 && (pointY - guiBase.getGuiTop()) < rectY + rectHeight + 1;
|
||||
}
|
||||
|
||||
public void drawState(GuiBase<?> gui,
|
||||
World world,
|
||||
BakedModel model,
|
||||
BlockState actualState,
|
||||
BlockPos pos,
|
||||
BlockRenderManager dispatcher,
|
||||
int x,
|
||||
int y,
|
||||
Quaternion quaternion) {
|
||||
|
||||
MatrixStack matrixStack = new MatrixStack();
|
||||
matrixStack.push();
|
||||
matrixStack.translate(8 + gui.getGuiLeft() + this.x + x, 8 + gui.getGuiTop() + this.y + y, 512);
|
||||
matrixStack.scale(16F, 16F, 16F);
|
||||
matrixStack.translate(0.5F, 0.5F, 0.5F);
|
||||
matrixStack.scale(-1, -1, -1);
|
||||
|
||||
if (quaternion != null) {
|
||||
matrixStack.multiply(quaternion);
|
||||
}
|
||||
|
||||
VertexConsumerProvider.Immediate immediate = VertexConsumerProvider.immediate(Tessellator.getInstance().getBuffer());
|
||||
dispatcher.getModelRenderer().render(matrixStack.peek(), immediate.getBuffer(RenderLayer.getSolid()), actualState, model, 1F, 1F, 1F, OverlayTexture.getU(15F), OverlayTexture.DEFAULT_UV);
|
||||
immediate.draw();
|
||||
matrixStack.pop();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* This file is part of RebornCore, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2021 TeamReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package reborncore.client.gui.builder.slot.elements;
|
||||
|
||||
import reborncore.common.blockentity.MachineBaseBlockEntity;
|
||||
|
||||
public interface ISprite {
|
||||
Sprite getSprite(MachineBaseBlockEntity provider);
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
/*
|
||||
* This file is part of RebornCore, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2021 TeamReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package reborncore.client.gui.builder.slot.elements;
|
||||
|
||||
import reborncore.common.blockentity.MachineBaseBlockEntity;
|
||||
|
||||
public class OffsetSprite {
|
||||
public ISprite sprite;
|
||||
public int offsetX = 0;
|
||||
public int offsetY = 0;
|
||||
|
||||
public OffsetSprite(ISprite sprite, int offsetX, int offsetY) {
|
||||
this.sprite = sprite;
|
||||
this.offsetX = offsetX;
|
||||
this.offsetY = offsetY;
|
||||
}
|
||||
|
||||
public OffsetSprite(ISprite sprite) {
|
||||
this.sprite = sprite;
|
||||
}
|
||||
|
||||
public OffsetSprite(Sprite sprite, MachineBaseBlockEntity provider) {
|
||||
this.sprite = sprite;
|
||||
}
|
||||
|
||||
public ISprite getSprite() {
|
||||
return sprite;
|
||||
}
|
||||
|
||||
public int getOffsetX(MachineBaseBlockEntity provider) {
|
||||
return offsetX + sprite.getSprite(provider).offsetX;
|
||||
}
|
||||
|
||||
public OffsetSprite setOffsetX(int offsetX) {
|
||||
this.offsetX = offsetX;
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getOffsetY(MachineBaseBlockEntity provider) {
|
||||
return offsetY + sprite.getSprite(provider).offsetY;
|
||||
}
|
||||
|
||||
public OffsetSprite setOffsetY(int offsetY) {
|
||||
this.offsetY = offsetY;
|
||||
return this;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,209 @@
|
|||
/*
|
||||
* This file is part of RebornCore, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2021 TeamReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package reborncore.client.gui.builder.slot.elements;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.render.OverlayTexture;
|
||||
import net.minecraft.client.render.RenderLayer;
|
||||
import net.minecraft.client.render.Tessellator;
|
||||
import net.minecraft.client.render.VertexConsumerProvider;
|
||||
import net.minecraft.client.render.block.BlockRenderManager;
|
||||
import net.minecraft.client.render.model.BakedModel;
|
||||
import net.minecraft.client.texture.SpriteAtlasTexture;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.util.math.Quaternion;
|
||||
import net.minecraft.util.math.Vec3f;
|
||||
import net.minecraft.world.World;
|
||||
import reborncore.RebornCore;
|
||||
import reborncore.client.gui.GuiUtil;
|
||||
import reborncore.client.gui.builder.GuiBase;
|
||||
import reborncore.common.blockentity.MachineBaseBlockEntity;
|
||||
import reborncore.common.blockentity.SlotConfiguration;
|
||||
import reborncore.common.network.IdentifiedPacket;
|
||||
import reborncore.common.network.NetworkManager;
|
||||
import reborncore.common.network.ServerBoundPackets;
|
||||
import reborncore.common.util.Color;
|
||||
import reborncore.common.util.MachineFacing;
|
||||
|
||||
public class SlotConfigPopupElement extends ElementBase {
|
||||
int id;
|
||||
public boolean filter = false;
|
||||
|
||||
ConfigSlotElement slotElement;
|
||||
|
||||
boolean allowInput = true;
|
||||
|
||||
public SlotConfigPopupElement(int slotId, int x, int y, ConfigSlotElement slotElement, boolean allowInput) {
|
||||
super(x, y, Sprite.SLOT_CONFIG_POPUP);
|
||||
this.id = slotId;
|
||||
this.slotElement = slotElement;
|
||||
this.allowInput = allowInput;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(MatrixStack matrixStack, GuiBase<?> gui) {
|
||||
drawDefaultBackground(matrixStack, gui, adjustX(gui, getX() - 8), adjustY(gui, getY() - 7), 84, 105 + (filter ? 15 : 0));
|
||||
super.draw(matrixStack, gui);
|
||||
|
||||
MachineBaseBlockEntity machine = ((MachineBaseBlockEntity) gui.be);
|
||||
World world = machine.getWorld();
|
||||
BlockPos pos = machine.getPos();
|
||||
BlockState state = world.getBlockState(pos);
|
||||
BlockState actualState = state.getBlock().getDefaultState();
|
||||
BlockRenderManager dispatcher = MinecraftClient.getInstance().getBlockRenderManager();
|
||||
BakedModel model = dispatcher.getModels().getModel(state.getBlock().getDefaultState());
|
||||
MinecraftClient.getInstance().getTextureManager().bindTexture(SpriteAtlasTexture.BLOCK_ATLAS_TEXTURE);
|
||||
drawState(gui, world, model, actualState, pos, dispatcher, 4, 23, Vec3f.POSITIVE_Y.getDegreesQuaternion(90F)); //left
|
||||
drawState(gui, world, model, actualState, pos, dispatcher, 23, 4, Vec3f.NEGATIVE_X.getDegreesQuaternion(90F)); //top
|
||||
drawState(gui, world, model, actualState, pos, dispatcher, 23, 23, null); //centre
|
||||
drawState(gui, world, model, actualState, pos, dispatcher, 23, 26, Vec3f.POSITIVE_X.getDegreesQuaternion(90F)); //bottom
|
||||
drawState(gui, world, model, actualState, pos, dispatcher, 42, 23, Vec3f.POSITIVE_Y.getDegreesQuaternion(90F)); //right
|
||||
drawState(gui, world, model, actualState, pos, dispatcher, 26, 42, Vec3f.POSITIVE_Y.getDegreesQuaternion(180F)); //back
|
||||
|
||||
drawSlotSateColor(matrixStack, gui.getMachine(), MachineFacing.UP.getFacing(machine), id, 22, -1, gui);
|
||||
drawSlotSateColor(matrixStack, gui.getMachine(), MachineFacing.FRONT.getFacing(machine), id, 22, 18, gui);
|
||||
drawSlotSateColor(matrixStack, gui.getMachine(), MachineFacing.DOWN.getFacing(machine), id, 22, 37, gui);
|
||||
drawSlotSateColor(matrixStack, gui.getMachine(), MachineFacing.RIGHT.getFacing(machine), id, 41, 18, gui);
|
||||
drawSlotSateColor(matrixStack, gui.getMachine(), MachineFacing.BACK.getFacing(machine), id, 41, 37, gui);
|
||||
drawSlotSateColor(matrixStack, gui.getMachine(), MachineFacing.LEFT.getFacing(machine), id, 3, 18, gui);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onRelease(MachineBaseBlockEntity provider, GuiBase<?> gui, double mouseX, double mouseY) {
|
||||
if (isInBox(23, 4, 16, 16, mouseX, mouseY, gui)) {
|
||||
cycleSlotConfig(MachineFacing.UP.getFacing(provider), gui);
|
||||
} else if (isInBox(23, 23, 16, 16, mouseX, mouseY, gui)) {
|
||||
cycleSlotConfig(MachineFacing.FRONT.getFacing(provider), gui);
|
||||
} else if (isInBox(42, 23, 16, 16, mouseX, mouseY, gui)) {
|
||||
cycleSlotConfig(MachineFacing.RIGHT.getFacing(provider), gui);
|
||||
} else if (isInBox(4, 23, 16, 16, mouseX, mouseY, gui)) {
|
||||
cycleSlotConfig(MachineFacing.LEFT.getFacing(provider), gui);
|
||||
} else if (isInBox(23, 42, 16, 16, mouseX, mouseY, gui)) {
|
||||
cycleSlotConfig(MachineFacing.DOWN.getFacing(provider), gui);
|
||||
} else if (isInBox(42, 42, 16, 16, mouseX, mouseY, gui)) {
|
||||
cycleSlotConfig(MachineFacing.BACK.getFacing(provider), gui);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void cycleSlotConfig(Direction side, GuiBase<?> guiBase) {
|
||||
SlotConfiguration.SlotConfig currentSlot = guiBase.getMachine().getSlotConfiguration().getSlotDetails(id).getSideDetail(side);
|
||||
|
||||
// A bit of a mess, in the future have a way to remove config options from this list
|
||||
SlotConfiguration.ExtractConfig nextConfig = currentSlot.getSlotIO().getIoConfig().getNext();
|
||||
if (!allowInput && nextConfig == SlotConfiguration.ExtractConfig.INPUT) {
|
||||
nextConfig = SlotConfiguration.ExtractConfig.OUTPUT;
|
||||
}
|
||||
|
||||
SlotConfiguration.SlotIO slotIO = new SlotConfiguration.SlotIO(nextConfig);
|
||||
SlotConfiguration.SlotConfig newConfig = new SlotConfiguration.SlotConfig(side, slotIO, id);
|
||||
IdentifiedPacket packetSlotSave = ServerBoundPackets.createPacketSlotSave(guiBase.be.getPos(), newConfig);
|
||||
NetworkManager.sendToServer(packetSlotSave);
|
||||
}
|
||||
|
||||
public void updateCheckBox(CheckBoxElement checkBoxElement, String type, GuiBase<?> guiBase) {
|
||||
SlotConfiguration.SlotConfigHolder configHolder = guiBase.getMachine().getSlotConfiguration().getSlotDetails(id);
|
||||
boolean input = configHolder.autoInput();
|
||||
boolean output = configHolder.autoOutput();
|
||||
boolean filter = configHolder.filter();
|
||||
if (type.equalsIgnoreCase("input")) {
|
||||
input = !configHolder.autoInput();
|
||||
}
|
||||
if (type.equalsIgnoreCase("output")) {
|
||||
output = !configHolder.autoOutput();
|
||||
}
|
||||
if (type.equalsIgnoreCase("filter")) {
|
||||
filter = !configHolder.filter();
|
||||
}
|
||||
|
||||
IdentifiedPacket packetSlotSave = ServerBoundPackets.createPacketIOSave(guiBase.be.getPos(), id, input, output, filter);
|
||||
NetworkManager.sendToServer(packetSlotSave);
|
||||
}
|
||||
|
||||
private void drawSlotSateColor(MatrixStack matrices, MachineBaseBlockEntity machineBase, Direction side, int slotID, int inx, int iny, GuiBase<?> gui) {
|
||||
iny += 4;
|
||||
int sx = inx + getX() + gui.getGuiLeft();
|
||||
int sy = iny + getY() + gui.getGuiTop();
|
||||
SlotConfiguration.SlotConfigHolder slotConfigHolder = machineBase.getSlotConfiguration().getSlotDetails(slotID);
|
||||
if (slotConfigHolder == null) {
|
||||
RebornCore.LOGGER.debug("Hmm, this isn't supposed to happen");
|
||||
return;
|
||||
}
|
||||
SlotConfiguration.SlotConfig slotConfig = slotConfigHolder.getSideDetail(side);
|
||||
Color color = switch (slotConfig.getSlotIO().getIoConfig()) {
|
||||
case INPUT -> new Color(0, 0, 255, 128);
|
||||
case OUTPUT -> new Color(255, 69, 0, 128);
|
||||
default -> new Color(0, 0, 0, 0);
|
||||
};
|
||||
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
GuiUtil.drawGradientRect(matrices, sx, sy, 18, 18, color.getColor(), color.getColor());
|
||||
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
|
||||
}
|
||||
|
||||
private boolean isInBox(int rectX, int rectY, int rectWidth, int rectHeight, double pointX, double pointY, GuiBase<?> guiBase) {
|
||||
rectX += getX();
|
||||
rectY += getY();
|
||||
return isInRect(guiBase, rectX, rectY, rectWidth, rectHeight, pointX, pointY);
|
||||
//return (pointX - guiBase.getGuiLeft()) >= rectX - 1 && (pointX - guiBase.getGuiLeft()) < rectX + rectWidth + 1 && (pointY - guiBase.getGuiTop()) >= rectY - 1 && (pointY - guiBase.getGuiTop()) < rectY + rectHeight + 1;
|
||||
}
|
||||
|
||||
public void drawState(GuiBase<?> gui,
|
||||
World world,
|
||||
BakedModel model,
|
||||
BlockState actualState,
|
||||
BlockPos pos,
|
||||
BlockRenderManager dispatcher,
|
||||
int x,
|
||||
int y,
|
||||
Quaternion quaternion) {
|
||||
|
||||
MatrixStack matrixStack = new MatrixStack();
|
||||
matrixStack.push();
|
||||
matrixStack.translate(8 + gui.getGuiLeft() + this.x + x, 8 + gui.getGuiTop() + this.y + y, 512);
|
||||
matrixStack.scale(16F, 16F, 16F);
|
||||
matrixStack.translate(0.5F, 0.5F, 0.5F);
|
||||
matrixStack.scale(-1, -1, -1);
|
||||
|
||||
if (quaternion != null) {
|
||||
matrixStack.multiply(quaternion);
|
||||
}
|
||||
|
||||
VertexConsumerProvider.Immediate immediate = VertexConsumerProvider.immediate(Tessellator.getInstance().getBuffer());
|
||||
dispatcher.getModelRenderer().render(matrixStack.peek(), immediate.getBuffer(RenderLayer.getSolid()), actualState, model, 1F, 1F, 1F, OverlayTexture.getU(15F), OverlayTexture.DEFAULT_UV);
|
||||
immediate.draw();
|
||||
matrixStack.pop();
|
||||
}
|
||||
|
||||
public void drawState(GuiBase<?> gui, World world, BakedModel model, BlockState actualState, BlockPos pos, BlockRenderManager dispatcher, int x, int y) {
|
||||
drawState(gui, world, model, actualState, pos, dispatcher, x, y, null);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
/*
|
||||
* This file is part of RebornCore, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2021 TeamReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package reborncore.client.gui.builder.slot.elements;
|
||||
|
||||
import net.minecraft.inventory.Inventory;
|
||||
|
||||
public class SlotElement extends ElementBase {
|
||||
protected Inventory slotInventory;
|
||||
protected SlotType type;
|
||||
int slotId, slotX, slotY;
|
||||
|
||||
public SlotElement(Inventory slotInventory, int slotId, int slotX, int slotY, SlotType type, int x, int y) {
|
||||
super(x, y, type.getSprite());
|
||||
this.type = type;
|
||||
this.slotInventory = slotInventory;
|
||||
this.slotId = slotId;
|
||||
this.slotX = slotX;
|
||||
this.slotY = slotY;
|
||||
}
|
||||
|
||||
public SlotType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public Inventory getSlotInventory() {
|
||||
return slotInventory;
|
||||
}
|
||||
|
||||
public int getSlotId() {
|
||||
return slotId;
|
||||
}
|
||||
|
||||
public int getSlotX() {
|
||||
return slotX;
|
||||
}
|
||||
|
||||
public int getSlotY() {
|
||||
return slotY;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
/*
|
||||
* This file is part of RebornCore, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2021 TeamReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package reborncore.client.gui.builder.slot.elements;
|
||||
|
||||
public enum SlotType {
|
||||
NORMAL(1, 1, Sprite.SLOT_NORMAL, Sprite.BUTTON_SLOT_NORMAL, Sprite.BUTTON_HOVER_OVERLAY_SLOT_NORMAL);
|
||||
|
||||
int slotOffsetX;
|
||||
int slotOffsetY;
|
||||
Sprite sprite;
|
||||
Sprite buttonSprite;
|
||||
Sprite buttonHoverOverlay;
|
||||
|
||||
SlotType(int slotOffsetX, int slotOffsetY, Sprite sprite, Sprite buttonSprite, Sprite buttonHoverOverlay) {
|
||||
this.slotOffsetX = slotOffsetX;
|
||||
this.slotOffsetY = slotOffsetY;
|
||||
this.sprite = sprite;
|
||||
this.buttonSprite = buttonSprite;
|
||||
this.buttonHoverOverlay = buttonHoverOverlay;
|
||||
}
|
||||
|
||||
SlotType(int slotOffset, Sprite sprite) {
|
||||
this.slotOffsetX = slotOffset;
|
||||
this.slotOffsetY = slotOffset;
|
||||
this.sprite = sprite;
|
||||
}
|
||||
|
||||
public int getSlotOffsetX() {
|
||||
return slotOffsetX;
|
||||
}
|
||||
|
||||
public int getSlotOffsetY() {
|
||||
return slotOffsetY;
|
||||
}
|
||||
|
||||
public Sprite getSprite() {
|
||||
return sprite;
|
||||
}
|
||||
|
||||
public Sprite getButtonSprite() {
|
||||
return buttonSprite;
|
||||
}
|
||||
|
||||
public Sprite getButtonHoverOverlay() {
|
||||
return buttonHoverOverlay;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,122 @@
|
|||
/*
|
||||
* This file is part of RebornCore, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2021 TeamReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package reborncore.client.gui.builder.slot.elements;
|
||||
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.util.Identifier;
|
||||
import reborncore.common.blockentity.MachineBaseBlockEntity;
|
||||
|
||||
public class Sprite implements ISprite {
|
||||
public static final Sprite EMPTY = new Sprite(ElementBase.MECH_ELEMENTS, 0, 0, 0, 0);
|
||||
public static final Sprite SLOT_NORMAL = new Sprite(ElementBase.MECH_ELEMENTS, 0, 0, 18, 18);
|
||||
public static final Sprite CHARGE_SLOT_ICON = new Sprite(ElementBase.MECH_ELEMENTS, 18, 0, 18, 18);
|
||||
public static final Sprite DISCHARGE_SLOT_ICON = new Sprite(ElementBase.MECH_ELEMENTS, 36, 0, 18, 18);
|
||||
public static final Sprite ENERGY_BAR = new Sprite(ElementBase.MECH_ELEMENTS, 0, 18, 12, 40);
|
||||
public static final Sprite ENERGY_BAR_BACKGROUND = new Sprite(ElementBase.MECH_ELEMENTS, 12, 18, 14, 42);
|
||||
public static final Sprite TOP_ENERGY_BAR = new Sprite(ElementBase.MECH_ELEMENTS, 0, 215, 167, 2);
|
||||
public static final Sprite TOP_ENERGY_BAR_BACKGROUND = new Sprite(ElementBase.MECH_ELEMENTS, 0, 217, 169, 3);
|
||||
public static final Sprite LEFT_TAB = new Sprite(ElementBase.MECH_ELEMENTS, 0, 86, 23, 26);
|
||||
public static final Sprite LEFT_TAB_SELECTED = new Sprite(ElementBase.MECH_ELEMENTS, 0, 60, 29, 26);
|
||||
public static final Sprite CONFIGURE_ICON = new Sprite(ElementBase.MECH_ELEMENTS, 26, 18, 16, 16);
|
||||
public static final Sprite REDSTONE_DISABLED_ICON = new Sprite(new ItemStack(Items.GUNPOWDER));
|
||||
public static final Sprite REDSTONE_LOW_ICON = new Sprite(new ItemStack(Items.REDSTONE));
|
||||
public static final Sprite REDSTONE_HIGH_ICON = new Sprite(new ItemStack(Blocks.REDSTONE_TORCH));
|
||||
public static final Sprite UPGRADE_ICON = new Sprite(ElementBase.MECH_ELEMENTS, 26, 34, 16, 16);
|
||||
public static final Sprite ENERGY_ICON = new Sprite(ElementBase.MECH_ELEMENTS, 46, 19, 9, 13);
|
||||
public static final Sprite ENERGY_ICON_EMPTY = new Sprite(ElementBase.MECH_ELEMENTS, 62, 19, 9, 13);
|
||||
public static final Sprite JEI_ICON = new Sprite(ElementBase.MECH_ELEMENTS, 42, 34, 16, 16);
|
||||
public static final Sprite BUTTON_SLOT_NORMAL = new Sprite(ElementBase.MECH_ELEMENTS, 54, 0, 18, 18);
|
||||
public static final Sprite FAKE_SLOT = new Sprite(ElementBase.MECH_ELEMENTS, 72, 0, 18, 18);
|
||||
public static final Sprite BUTTON_HOVER_OVERLAY_SLOT_NORMAL = new Sprite(ElementBase.MECH_ELEMENTS, 90, 0, 18, 18);
|
||||
public static final Sprite SLOT_CONFIG_POPUP = new Sprite(ElementBase.MECH_ELEMENTS, 29, 60, 62, 62);
|
||||
public static final Sprite.Button EXIT_BUTTON = new Sprite.Button(new Sprite(ElementBase.MECH_ELEMENTS, 26, 122, 13, 13), new Sprite(ElementBase.MECH_ELEMENTS, 39, 122, 13, 13));
|
||||
public static final Sprite.CheckBox DARK_CHECK_BOX = new Sprite.CheckBox(new Sprite(ElementBase.MECH_ELEMENTS, 74, 18, 13, 13), new Sprite(ElementBase.MECH_ELEMENTS, 87, 18, 16, 13));
|
||||
public static final Sprite.CheckBox LIGHT_CHECK_BOX = new Sprite.CheckBox(new Sprite(ElementBase.MECH_ELEMENTS, 74, 31, 13, 13), new Sprite(ElementBase.MECH_ELEMENTS, 87, 31, 16, 13));
|
||||
|
||||
public final Identifier textureLocation;
|
||||
public final int x;
|
||||
public final int y;
|
||||
public final int width;
|
||||
public final int height;
|
||||
public int offsetX = 0;
|
||||
public int offsetY = 0;
|
||||
public ItemStack itemStack;
|
||||
|
||||
public Sprite(Identifier textureLocation, int x, int y, int width, int height) {
|
||||
this.textureLocation = textureLocation;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.itemStack = null;
|
||||
}
|
||||
|
||||
public Sprite(ItemStack stack) {
|
||||
this.textureLocation = null;
|
||||
this.x = -1;
|
||||
this.y = -1;
|
||||
this.width = -1;
|
||||
this.height = -1;
|
||||
this.itemStack = stack;
|
||||
}
|
||||
|
||||
public boolean hasStack() {
|
||||
return itemStack != null;
|
||||
}
|
||||
|
||||
public boolean hasTextureInfo() {
|
||||
return x >= 0 && y >= 0 && width >= 0 && height >= 0;
|
||||
}
|
||||
|
||||
public Sprite setOffsetX(int offsetX) {
|
||||
this.offsetX = offsetX;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Sprite setOffsetY(int offsetY) {
|
||||
this.offsetY = offsetY;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Sprite getSprite(MachineBaseBlockEntity provider) {
|
||||
return this;
|
||||
}
|
||||
|
||||
public record Button(Sprite normal,
|
||||
Sprite hovered) {
|
||||
}
|
||||
|
||||
public record ToggleButton(Sprite normal,
|
||||
Sprite hovered,
|
||||
Sprite pressed) {
|
||||
}
|
||||
|
||||
public record CheckBox(Sprite normal,
|
||||
Sprite ticked) {
|
||||
}
|
||||
}
|
|
@ -0,0 +1,78 @@
|
|||
/*
|
||||
* This file is part of RebornCore, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2021 TeamReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package reborncore.client.gui.builder.slot.elements;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SpriteContainer {
|
||||
public List<OffsetSprite> offsetSprites = new ArrayList<>();
|
||||
|
||||
public SpriteContainer setSprite(int index, OffsetSprite sprite) {
|
||||
offsetSprites.set(index, sprite);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SpriteContainer setSprite(int index, ISprite sprite, int offsetX, int offsetY) {
|
||||
if (sprite instanceof Sprite) {
|
||||
offsetSprites.set(index, new OffsetSprite(sprite).setOffsetX(((Sprite) sprite).offsetX + offsetX).setOffsetY(((Sprite) sprite).offsetY + offsetY));
|
||||
} else {
|
||||
offsetSprites.set(index, new OffsetSprite(sprite, offsetX, offsetY));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public SpriteContainer setSprite(int index, ISprite sprite) {
|
||||
if (sprite instanceof Sprite) {
|
||||
offsetSprites.set(index, new OffsetSprite(sprite).setOffsetX(((Sprite) sprite).offsetX).setOffsetY(((Sprite) sprite).offsetY));
|
||||
} else {
|
||||
offsetSprites.add(index, new OffsetSprite(sprite));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public SpriteContainer addSprite(OffsetSprite sprite) {
|
||||
offsetSprites.add(sprite);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SpriteContainer addSprite(ISprite sprite, int offsetX, int offsetY) {
|
||||
if (sprite instanceof Sprite) {
|
||||
offsetSprites.add(new OffsetSprite(sprite).setOffsetX(((Sprite) sprite).offsetX + offsetX).setOffsetY(((Sprite) sprite).offsetY + offsetY));
|
||||
} else {
|
||||
offsetSprites.add(new OffsetSprite(sprite, offsetX, offsetY));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public SpriteContainer addSprite(ISprite sprite) {
|
||||
if (sprite instanceof Sprite) {
|
||||
offsetSprites.add(new OffsetSprite(sprite).setOffsetX(((Sprite) sprite).offsetX).setOffsetY(((Sprite) sprite).offsetY));
|
||||
} else {
|
||||
offsetSprites.add(new OffsetSprite(sprite));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
* This file is part of RebornCore, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2021 TeamReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package reborncore.client.gui.builder.widget;
|
||||
|
||||
import net.minecraft.client.gui.widget.ButtonWidget;
|
||||
import net.minecraft.text.Text;
|
||||
import reborncore.common.misc.TriConsumer;
|
||||
|
||||
public class GuiButtonExtended extends ButtonWidget {
|
||||
|
||||
private TriConsumer<GuiButtonExtended, Double, Double> clickHandler;
|
||||
|
||||
public GuiButtonExtended(int x, int y, Text buttonText, ButtonWidget.PressAction pressAction) {
|
||||
super(x, y, 20, 200, buttonText, pressAction);
|
||||
}
|
||||
|
||||
public GuiButtonExtended(int x, int y, int widthIn, int heightIn, Text buttonText, ButtonWidget.PressAction pressAction) {
|
||||
super(x, y, widthIn, heightIn, buttonText, pressAction);
|
||||
}
|
||||
|
||||
public GuiButtonExtended clickHandler(TriConsumer<GuiButtonExtended, Double, Double> consumer) {
|
||||
clickHandler = consumer;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(double mouseX, double mouseY) {
|
||||
if (clickHandler != null) {
|
||||
clickHandler.accept(this, mouseX, mouseY);
|
||||
}
|
||||
super.onClick(mouseX, mouseY);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* This file is part of RebornCore, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2021 TeamReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package reborncore.client.gui.builder.widget;
|
||||
|
||||
import net.minecraft.client.gui.widget.ButtonWidget;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.text.Text;
|
||||
import reborncore.client.gui.builder.GuiBase;
|
||||
|
||||
/**
|
||||
* Created by Prospector
|
||||
*/
|
||||
public class GuiButtonHologram extends GuiButtonExtended {
|
||||
|
||||
GuiBase.Layer layer;
|
||||
GuiBase<?> gui;
|
||||
|
||||
public GuiButtonHologram(int x, int y, GuiBase<?> gui, GuiBase.Layer layer, ButtonWidget.PressAction pressAction) {
|
||||
super(x, y, 20, 12, Text.empty(), pressAction);
|
||||
this.layer = layer;
|
||||
this.gui = gui;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(MatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) {
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* This file is part of RebornCore, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2021 TeamReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package reborncore.client.gui.builder.widget;
|
||||
|
||||
import net.minecraft.client.gui.widget.ButtonWidget;
|
||||
import net.minecraft.text.Text;
|
||||
|
||||
public class GuiButtonSimple extends ButtonWidget {
|
||||
|
||||
/**
|
||||
* @deprecated Please use {@link ButtonWidget}
|
||||
*/
|
||||
@Deprecated
|
||||
public GuiButtonSimple(int x, int y, Text buttonText, ButtonWidget.PressAction pressAction) {
|
||||
super(x, y, 20, 200, buttonText, pressAction);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Please use {@link ButtonWidget}
|
||||
*/
|
||||
@Deprecated
|
||||
public GuiButtonSimple(int x, int y, int widthIn, int heightIn, Text buttonText, ButtonWidget.PressAction pressAction) {
|
||||
super(x, y, widthIn, heightIn, buttonText, pressAction);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
/*
|
||||
* This file is part of RebornCore, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2021 TeamReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package reborncore.client.gui.builder.widget;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import net.minecraft.client.gui.widget.ButtonWidget;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.text.Text;
|
||||
import reborncore.client.gui.builder.GuiBase;
|
||||
|
||||
/**
|
||||
* @author drcrazy
|
||||
*/
|
||||
public class GuiButtonUpDown extends GuiButtonExtended {
|
||||
|
||||
GuiBase<?> gui;
|
||||
UpDownButtonType type;
|
||||
|
||||
public GuiButtonUpDown(int x, int y, GuiBase<?> gui, ButtonWidget.PressAction pressAction, UpDownButtonType type) {
|
||||
super(x, y, 12, 12, Text.empty(), pressAction);
|
||||
this.gui = gui;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderButton(MatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) {
|
||||
if (gui.hideGuiElements()) return;
|
||||
RenderSystem.setShaderTexture(0, gui.builder.getResourceLocation());
|
||||
switch (type) {
|
||||
case FASTFORWARD:
|
||||
gui.drawTexture(matrixStack, x, y, 174, 74, 12, 12);
|
||||
break;
|
||||
case FORWARD:
|
||||
gui.drawTexture(matrixStack, x, y, 174, 86, 12, 12);
|
||||
break;
|
||||
case REWIND:
|
||||
gui.drawTexture(matrixStack, x, y, 174, 98, 12, 12);
|
||||
break;
|
||||
case FASTREWIND:
|
||||
gui.drawTexture(matrixStack, x, y, 174, 110, 12, 12);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public enum UpDownButtonType {
|
||||
FASTFORWARD,
|
||||
FORWARD,
|
||||
REWIND,
|
||||
FASTREWIND
|
||||
}
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
* This file is part of RebornCore, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2021 TeamReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package reborncore.client.gui.componets;
|
||||
|
||||
public class BaseTextures {
|
||||
//
|
||||
// private static final ResourceLocation baseTexture = new ResourceLocation("reborncore", "textures/gui/base.png");
|
||||
//
|
||||
// public GuiTexture background;
|
||||
// public GuiTexture slot;
|
||||
// public GuiTexture burnBase;
|
||||
// public GuiTexture burnOverlay;
|
||||
// public GuiTexture powerBase;
|
||||
// public GuiTexture powerOverlay;
|
||||
// public GuiTexture progressBase;
|
||||
// public GuiTexture progressOverlay;
|
||||
// public GuiTexture tank;
|
||||
// public GuiTexture tankBase;
|
||||
// public GuiTexture tankScale;
|
||||
// public GuiTexture powerBaseOld;
|
||||
// public GuiTexture powerOverlayOld;
|
||||
//
|
||||
// public BaseTextures()
|
||||
// {
|
||||
// background = new GuiTexture(baseTexture, 176, 166, 0, 0);
|
||||
// slot = new GuiTexture(baseTexture, 18, 18, 176, 31);
|
||||
// burnBase = new GuiTexture(baseTexture, 14, 14, 176, 0);
|
||||
// burnOverlay = new GuiTexture(baseTexture, 13, 13, 176, 50);
|
||||
// powerBase = new GuiTexture(baseTexture, 7, 13, 190, 0);
|
||||
// powerOverlay = new GuiTexture(baseTexture, 7, 13, 197, 0);
|
||||
// progressBase = new GuiTexture(baseTexture, 22, 15, 200, 14);
|
||||
// progressOverlay = new GuiTexture(baseTexture, 22, 16, 177, 14);
|
||||
// tank = new GuiTexture(baseTexture, 20, 55, 176, 63);
|
||||
// tankBase = new GuiTexture(baseTexture, 20, 55, 196, 63);
|
||||
// tankScale = new GuiTexture(baseTexture, 20, 55, 216, 63);
|
||||
// powerBaseOld = new GuiTexture(baseTexture, 32, 17, 224, 13);
|
||||
// powerOverlayOld = new GuiTexture(baseTexture, 32, 17, 224, 30);
|
||||
// }
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
/*
|
||||
* This file is part of RebornCore, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2021 TeamReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package reborncore.client.gui.componets;
|
||||
|
||||
import com.mojang.blaze3d.platform.GlStateManager;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.font.TextRenderer;
|
||||
import net.minecraft.client.gui.widget.ButtonWidget;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.text.Text;
|
||||
|
||||
public class GuiHiddenButton extends ButtonWidget {
|
||||
|
||||
public GuiHiddenButton(int xPosition, int yPosition, Text displayString) {
|
||||
super(xPosition, yPosition, 0, 0, displayString, var1 -> {
|
||||
});
|
||||
}
|
||||
|
||||
public GuiHiddenButton(int id, int xPosition, int yPosition, int width, int height, Text displayString) {
|
||||
super(xPosition, yPosition, width, height, displayString, var1 -> {
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(MatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) {
|
||||
if (this.visible) {
|
||||
TextRenderer textRenderer = MinecraftClient.getInstance().textRenderer;
|
||||
RenderSystem.setShaderTexture(0, WIDGETS_TEXTURE);
|
||||
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
this.hovered = mouseX >= this.x && mouseY >= this.y
|
||||
&& mouseX < this.x + this.width && mouseY < this.y + this.height;
|
||||
RenderSystem.enableBlend();
|
||||
RenderSystem.blendFuncSeparate(770, 771, 1, 0);
|
||||
RenderSystem.blendFunc(GlStateManager.SrcFactor.SRC_ALPHA, GlStateManager.DstFactor.ONE_MINUS_SRC_ALPHA);
|
||||
int l = 14737632;
|
||||
|
||||
if (!this.active) {
|
||||
l = 10526880;
|
||||
} else if (this.isHovered()) {
|
||||
l = 16777120;
|
||||
}
|
||||
|
||||
this.drawTextWithShadow(matrixStack, textRenderer, this.getMessage(), this.x + this.width / 2,
|
||||
this.y + (this.height - 8) / 2, l);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,831 @@
|
|||
/*
|
||||
* This file is part of RebornCore, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2021 TeamReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package reborncore.client.gui.guibuilder;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import net.fabricmc.fabric.api.transfer.v1.client.fluid.FluidVariantRendering;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.gui.DrawableHelper;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder;
|
||||
import net.minecraft.client.gui.widget.EntryListWidget;
|
||||
import net.minecraft.client.render.BufferBuilder;
|
||||
import net.minecraft.client.render.Tessellator;
|
||||
import net.minecraft.client.render.VertexFormat;
|
||||
import net.minecraft.client.render.VertexFormats;
|
||||
import net.minecraft.client.texture.Sprite;
|
||||
import net.minecraft.client.texture.SpriteAtlasTexture;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.fluid.Fluids;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Formatting;
|
||||
import net.minecraft.util.Identifier;
|
||||
import reborncore.api.IListInfoProvider;
|
||||
import reborncore.client.RenderUtil;
|
||||
import reborncore.client.gui.builder.GuiBase;
|
||||
import reborncore.client.gui.builder.slot.GuiTab;
|
||||
import reborncore.common.fluid.FluidUtils;
|
||||
import reborncore.common.fluid.FluidValue;
|
||||
import reborncore.common.fluid.container.FluidInstance;
|
||||
import reborncore.common.powerSystem.PowerSystem;
|
||||
import reborncore.common.powerSystem.PowerSystem.EnergySystem;
|
||||
import reborncore.common.util.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Created by Gigabit101 on 08/08/2016.
|
||||
*/
|
||||
public class GuiBuilder {
|
||||
public static final Identifier defaultTextureSheet = new Identifier("reborncore", "textures/gui/guielements.png");
|
||||
private static final Text SPACE_TEXT = Text.literal(" ");
|
||||
static Identifier resourceLocation;
|
||||
|
||||
public GuiBuilder() {
|
||||
GuiBuilder.resourceLocation = defaultTextureSheet;
|
||||
}
|
||||
|
||||
public GuiBuilder(Identifier resourceLocation) {
|
||||
GuiBuilder.resourceLocation = resourceLocation;
|
||||
}
|
||||
|
||||
public Identifier getResourceLocation() {
|
||||
return resourceLocation;
|
||||
}
|
||||
|
||||
public void drawDefaultBackground(MatrixStack matrixStack, Screen gui, int x, int y, int width, int height) {
|
||||
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
RenderSystem.setShaderTexture(0, resourceLocation);
|
||||
gui.drawTexture(matrixStack, x, y, 0, 0, width / 2, height / 2);
|
||||
gui.drawTexture(matrixStack, x + width / 2, y, 150 - width / 2, 0, width / 2, height / 2);
|
||||
gui.drawTexture(matrixStack, x, y + height / 2, 0, 150 - height / 2, width / 2, height / 2);
|
||||
gui.drawTexture(matrixStack, x + width / 2, y + height / 2, 150 - width / 2, 150 - height / 2, width / 2,
|
||||
height / 2);
|
||||
}
|
||||
|
||||
public void drawPlayerSlots(MatrixStack matrixStack, Screen gui, int posX, int posY, boolean center) {
|
||||
RenderSystem.setShaderTexture(0, resourceLocation);
|
||||
|
||||
if (center) {
|
||||
posX -= 81;
|
||||
}
|
||||
|
||||
for (int y = 0; y < 3; y++) {
|
||||
for (int x = 0; x < 9; x++) {
|
||||
gui.drawTexture(matrixStack, posX + x * 18, posY + y * 18, 150, 0, 18, 18);
|
||||
}
|
||||
}
|
||||
|
||||
for (int x = 0; x < 9; x++) {
|
||||
gui.drawTexture(matrixStack, posX + x * 18, posY + 58, 150, 0, 18, 18);
|
||||
}
|
||||
}
|
||||
|
||||
public void drawSlot(MatrixStack matrixStack, Screen gui, int posX, int posY) {
|
||||
RenderSystem.setShaderTexture(0, resourceLocation);
|
||||
gui.drawTexture(matrixStack, posX, posY, 150, 0, 18, 18);
|
||||
}
|
||||
|
||||
public void drawText(MatrixStack matrixStack, GuiBase<?> gui, Text text, int x, int y, int color) {
|
||||
gui.getTextRenderer().draw(matrixStack, text, x, y, color);
|
||||
}
|
||||
|
||||
public void drawProgressBar(MatrixStack matrixStack, GuiBase<?> gui, double progress, int x, int y) {
|
||||
RenderSystem.setShaderTexture(0, resourceLocation);
|
||||
gui.drawTexture(matrixStack, x, y, 150, 18, 22, 15);
|
||||
int j = (int) (progress);
|
||||
if (j > 0) {
|
||||
gui.drawTexture(matrixStack, x, y, 150, 34, j + 1, 15);
|
||||
}
|
||||
}
|
||||
|
||||
public void drawOutputSlot(MatrixStack matrixStack, GuiBase<?> gui, int x, int y) {
|
||||
RenderSystem.setShaderTexture(0, resourceLocation);
|
||||
gui.drawTexture(matrixStack, x, y, 174, 0, 26, 26);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws button with JEI icon in the given coords.
|
||||
*
|
||||
* @param gui {@link GuiBase} The GUI to draw on
|
||||
* @param x {@code int} Top left corner where to place button
|
||||
* @param y {@code int} Top left corner where to place button
|
||||
* @param layer {@link GuiBase.Layer} The layer to draw on
|
||||
*/
|
||||
public void drawJEIButton(MatrixStack matrixStack, GuiBase<?> gui, int x, int y, GuiBase.Layer layer) {
|
||||
if (gui.hideGuiElements()) return;
|
||||
if (FabricLoader.getInstance().isModLoaded("jei")) {
|
||||
if (layer == GuiBase.Layer.BACKGROUND) {
|
||||
x += gui.getGuiLeft();
|
||||
y += gui.getGuiTop();
|
||||
}
|
||||
RenderSystem.setShaderTexture(0, resourceLocation);
|
||||
gui.drawTexture(matrixStack, x, y, 202, 0, 12, 12);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws lock button in either locked or unlocked state
|
||||
*
|
||||
* @param gui {@link GuiBase} The GUI to draw on
|
||||
* @param x {@code int} Top left corner where to place button
|
||||
* @param y {@code int} Top left corner where to place button
|
||||
* @param mouseX {@code int} Mouse cursor position to check for tooltip
|
||||
* @param mouseY {@code int} Mouse cursor position to check for tooltip
|
||||
* @param layer {@link GuiBase.Layer} The layer to draw on
|
||||
* @param locked {@code boolean} Set to true if it is in locked state
|
||||
*/
|
||||
public void drawLockButton(MatrixStack matrixStack, GuiBase<?> gui, int x, int y, int mouseX, int mouseY, GuiBase.Layer layer, boolean locked) {
|
||||
if (gui.hideGuiElements()) return;
|
||||
if (layer == GuiBase.Layer.BACKGROUND) {
|
||||
x += gui.getGuiLeft();
|
||||
y += gui.getGuiTop();
|
||||
}
|
||||
RenderSystem.setShaderTexture(0, resourceLocation);
|
||||
gui.drawTexture(matrixStack, x, y, 174, 26 + (locked ? 12 : 0), 20, 12);
|
||||
if (gui.isPointInRect(x, y, 20, 12, mouseX, mouseY)) {
|
||||
List<Text> list = new ArrayList<>();
|
||||
if (locked) {
|
||||
list.add(Text.translatable("reborncore.gui.tooltip.unlock_items"));
|
||||
} else {
|
||||
list.add(Text.translatable("reborncore.gui.tooltip.lock_items"));
|
||||
}
|
||||
matrixStack.push();
|
||||
gui.renderTooltip(matrixStack, list, mouseX, mouseY);
|
||||
matrixStack.pop();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws hologram toggle button
|
||||
*
|
||||
* @param gui {@link GuiBase} The GUI to draw on
|
||||
* @param x {@code int} Top left corner where to place button
|
||||
* @param y {@code int} Top left corner where to place button
|
||||
* @param mouseX {@code int} Mouse cursor position to check for tooltip
|
||||
* @param mouseY {@code int} Mouse cursor position to check for tooltip
|
||||
* @param layer {@link GuiBase.Layer} The layer to draw on
|
||||
*/
|
||||
public void drawHologramButton(MatrixStack matrixStack, GuiBase<?> gui, int x, int y, int mouseX, int mouseY, GuiBase.Layer layer) {
|
||||
if (gui.isTabOpen()) return;
|
||||
if (layer == GuiBase.Layer.BACKGROUND) {
|
||||
x += gui.getGuiLeft();
|
||||
y += gui.getGuiTop();
|
||||
}
|
||||
RenderSystem.setShaderTexture(0, resourceLocation);
|
||||
if (gui.getMachine().renderMultiblock) {
|
||||
gui.drawTexture(matrixStack, x, y, 174, 62, 20, 12);
|
||||
} else {
|
||||
gui.drawTexture(matrixStack, x, y, 174, 50, 20, 12);
|
||||
}
|
||||
if (gui.isPointInRect(x, y, 20, 12, mouseX, mouseY)) {
|
||||
List<Text> list = new ArrayList<>();
|
||||
list.add(Text.translatable("reborncore.gui.tooltip.hologram"));
|
||||
matrixStack.push();
|
||||
if (layer == GuiBase.Layer.FOREGROUND) {
|
||||
mouseX -= gui.getGuiLeft();
|
||||
mouseY -= gui.getGuiTop();
|
||||
}
|
||||
gui.renderTooltip(matrixStack, list, mouseX, mouseY);
|
||||
matrixStack.pop();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws big horizontal bar for heat value
|
||||
*
|
||||
* @param gui {@link GuiBase} The GUI to draw on
|
||||
* @param x {@code int} Top left corner where to place bar
|
||||
* @param y {@code int} Top left corner where to place bar
|
||||
* @param value {@code int} Current heat value
|
||||
* @param max {@code int} Maximum heat value
|
||||
* @param layer {@link GuiBase.Layer} The layer to draw on
|
||||
*/
|
||||
public void drawBigHeatBar(MatrixStack matrixStack, GuiBase<?> gui, int x, int y, int value, int max, GuiBase.Layer layer) {
|
||||
if (gui.hideGuiElements()) return;
|
||||
if (layer == GuiBase.Layer.BACKGROUND) {
|
||||
x += gui.getGuiLeft();
|
||||
y += gui.getGuiTop();
|
||||
}
|
||||
RenderSystem.setShaderTexture(0, resourceLocation);
|
||||
gui.drawTexture(matrixStack, x, y, 26, 218, 114, 18);
|
||||
if (value != 0) {
|
||||
int j = (int) ((double) value / (double) max * 106);
|
||||
if (j < 0) {
|
||||
j = 0;
|
||||
}
|
||||
gui.drawTexture(matrixStack, x + 4, y + 4, 26, 246, j, 10);
|
||||
|
||||
Text text = Text.literal(String.valueOf(value))
|
||||
.append(Text.translatable("reborncore.gui.heat"));
|
||||
|
||||
gui.drawCentredText(matrixStack, text, y + 5, 0xFFFFFF, layer);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws big horizontal blue bar
|
||||
*
|
||||
* @param gui {@link GuiBase} The GUI to draw on
|
||||
* @param x {@code int} Top left corner where to place bar
|
||||
* @param y {@code int} Top left corner where to place bar
|
||||
* @param value {@code int} Current value
|
||||
* @param max {@code int} Maximum value
|
||||
* @param mouseX {@code int} Mouse cursor position to check for tooltip
|
||||
* @param mouseY {@code int} Mouse cursor position to check for tooltip
|
||||
* @param suffix {@link String} String to put on the bar and tooltip after percentage value
|
||||
* @param line2 {@link String} String to put into tooltip as a second line
|
||||
* @param format {@link String} Formatted value to put on the bar
|
||||
* @param layer {@link GuiBase.Layer} The layer to draw on
|
||||
*/
|
||||
public void drawBigBlueBar(MatrixStack matrixStack, GuiBase<?> gui, int x, int y, int value, int max, int mouseX, int mouseY, String suffix, Text line2, String format, GuiBase.Layer layer) {
|
||||
if (gui.hideGuiElements()) return;
|
||||
if (layer == GuiBase.Layer.BACKGROUND) {
|
||||
x += gui.getGuiLeft();
|
||||
y += gui.getGuiTop();
|
||||
}
|
||||
RenderSystem.setShaderTexture(0, resourceLocation);
|
||||
int j = (int) ((double) value / (double) max * 106);
|
||||
if (j < 0) {
|
||||
j = 0;
|
||||
}
|
||||
gui.drawTexture(matrixStack, x + 4, y + 4, 0, 236, j, 10);
|
||||
if (!suffix.equals("")) {
|
||||
suffix = " " + suffix;
|
||||
}
|
||||
gui.drawCentredText(matrixStack, Text.literal(format).append(suffix), y + 5, 0xFFFFFF, layer);
|
||||
if (gui.isPointInRect(x, y, 114, 18, mouseX, mouseY)) {
|
||||
int percentage = percentage(max, value);
|
||||
List<Text> list = new ArrayList<>();
|
||||
|
||||
list.add(
|
||||
Text.literal(String.valueOf(value))
|
||||
.formatted(Formatting.GOLD)
|
||||
.append("/")
|
||||
.append(String.valueOf(max))
|
||||
.append(suffix)
|
||||
);
|
||||
|
||||
list.add(
|
||||
Text.literal(String.valueOf(percentage))
|
||||
.formatted(StringUtils.getPercentageColour(percentage))
|
||||
.append("%")
|
||||
.append(
|
||||
Text.translatable("reborncore.gui.tooltip.dsu_fullness")
|
||||
.formatted(Formatting.GRAY)
|
||||
)
|
||||
);
|
||||
|
||||
list.add(line2);
|
||||
|
||||
if (value > max) {
|
||||
list.add(
|
||||
Text.literal("Yo this is storing more than it should be able to")
|
||||
.formatted(Formatting.GRAY)
|
||||
);
|
||||
list.add(
|
||||
Text.literal("prolly a bug")
|
||||
.formatted(Formatting.GRAY)
|
||||
);
|
||||
list.add(
|
||||
Text.literal("pls report and tell how tf you did this")
|
||||
.formatted(Formatting.GRAY)
|
||||
);
|
||||
}
|
||||
if (layer == GuiBase.Layer.FOREGROUND) {
|
||||
mouseX -= gui.getGuiLeft();
|
||||
mouseY -= gui.getGuiTop();
|
||||
}
|
||||
gui.renderTooltip(matrixStack, list, mouseX, mouseY);
|
||||
//RenderSystem.disableLighting();
|
||||
RenderSystem.setShaderColor(1, 1, 1, 1);
|
||||
}
|
||||
}
|
||||
|
||||
public void drawBigBlueBar(MatrixStack matrixStack, GuiBase<?> gui, int x, int y, int value, int max, int mouseX, int mouseY, String suffix, GuiBase.Layer layer) {
|
||||
drawBigBlueBar(matrixStack, gui, x, y, value, max, mouseX, mouseY, suffix, Text.empty(), Integer.toString(value), layer);
|
||||
|
||||
}
|
||||
|
||||
public void drawBigBlueBar(MatrixStack matrixStack, GuiBase<?> gui, int x, int y, int value, int max, int mouseX, int mouseY, GuiBase.Layer layer) {
|
||||
drawBigBlueBar(matrixStack, gui, x, y, value, max, mouseX, mouseY, "", Text.empty(), "", layer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shades GUI and draw gray bar on top of GUI
|
||||
*
|
||||
* @param gui {@link GuiBase} The GUI to draw on
|
||||
* @param layer {@link GuiBase.Layer} The layer to draw on
|
||||
*/
|
||||
public void drawMultiblockMissingBar(MatrixStack matrixStack, GuiBase<?> gui, GuiBase.Layer layer) {
|
||||
if (gui.hideGuiElements()) return;
|
||||
int x = 0;
|
||||
int y = 4;
|
||||
if (layer == GuiBase.Layer.BACKGROUND) {
|
||||
x += gui.getGuiLeft();
|
||||
y += gui.getGuiTop();
|
||||
}
|
||||
//RenderSystem.disableLighting();
|
||||
RenderSystem.enableDepthTest();
|
||||
RenderSystem.colorMask(true, true, true, false);
|
||||
RenderUtil.drawGradientRect(matrixStack, 0, x, y, x + 176, y + 20, 0x000000, 0xC0000000);
|
||||
RenderUtil.drawGradientRect(matrixStack, 0, x, y + 20, x + 176, y + 20 + 48, 0xC0000000, 0xC0000000);
|
||||
RenderUtil.drawGradientRect(matrixStack, 0, x, y + 68, x + 176, y + 70 + 20, 0xC0000000, 0x00000000);
|
||||
RenderSystem.colorMask(true, true, true, true);
|
||||
RenderSystem.disableDepthTest();
|
||||
gui.drawCentredText(matrixStack, Text.translatable("reborncore.gui.missingmultiblock"), 43, 0xFFFFFF, layer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws upgrade slots on the left side of machine GUI. Draws on the background
|
||||
* level.
|
||||
*
|
||||
* @param gui {@link GuiBase} The GUI to draw on
|
||||
* @param x {@code int} Top left corner where to place slots
|
||||
* @param y {@code int} Top left corner where to place slots
|
||||
*/
|
||||
public void drawUpgrades(MatrixStack matrixStack, GuiBase<?> gui, int x, int y) {
|
||||
RenderSystem.setShaderTexture(0, resourceLocation);
|
||||
gui.drawTexture(matrixStack, x, y, 217, 0, 24, 81);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws tab on the left side of machine GUI. Draws on the background level.
|
||||
*
|
||||
* @param gui {@link GuiBase} The GUI to draw on
|
||||
* @param x {@code int} Top left corner where to place tab
|
||||
* @param y {@code int} Top left corner where to place tab
|
||||
* @param stack {@link ItemStack} Item to show as tab icon
|
||||
*/
|
||||
public void drawSlotTab(MatrixStack matrixStack, GuiBase<?> gui, int x, int y, ItemStack stack) {
|
||||
RenderSystem.setShaderTexture(0, resourceLocation);
|
||||
gui.drawTexture(matrixStack, x, y, 217, 82, 24, 24);
|
||||
gui.getMinecraft().getItemRenderer().renderInGuiWithOverrides(stack, x + 5, y + 4);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Draws Slot Configuration tips instead of player inventory
|
||||
*
|
||||
* @param gui {@link GuiBase} The GUI to draw on
|
||||
* @param x {@code int} Top left corner where to place tips list
|
||||
* @param y {@code int} Top left corner where to place tips list
|
||||
* @param mouseX {@code int} Mouse cursor position
|
||||
* @param mouseY {@code int} Mouse cursor position
|
||||
*/
|
||||
public void drawSlotConfigTips(MatrixStack matrixStack, GuiBase<?> gui, int x, int y, int mouseX, int mouseY, GuiTab guiTab) {
|
||||
List<Text> tips = guiTab.getTips().stream()
|
||||
.map(Text::translatable)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
TipsListWidget explanation = new TipsListWidget(gui, gui.getScreenWidth() - 14, 54, y, y + 76, 9 + 2, tips);
|
||||
explanation.setLeftPos(x - 81);
|
||||
explanation.render(matrixStack, mouseX, mouseY, 1.0f);
|
||||
RenderSystem.setShaderColor(1, 1, 1, 1);
|
||||
}
|
||||
|
||||
|
||||
private static class TipsListWidget extends EntryListWidget<TipsListWidget.TipsListEntry> {
|
||||
|
||||
public TipsListWidget(GuiBase<?> gui, int width, int height, int top, int bottom, int entryHeight, List<Text> tips) {
|
||||
super(gui.getMinecraft(), width, height, top, bottom, entryHeight);
|
||||
for (Text tip : tips) {
|
||||
this.addEntry(new TipsListEntry(tip));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRowWidth() {
|
||||
return 162;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void renderBackground(MatrixStack matrixStack) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
|
||||
Tessellator tessellator = Tessellator.getInstance();
|
||||
BufferBuilder bufferBuilder = tessellator.getBuffer();
|
||||
RenderSystem.setShaderTexture(0, OPTIONS_BACKGROUND_TEXTURE);
|
||||
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
bufferBuilder.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_TEXTURE_COLOR);
|
||||
bufferBuilder.vertex(this.left, this.bottom, 0.0D).texture((float) this.left / 32.0F, (float) (this.bottom + (int) this.getScrollAmount()) / 32.0F).color(32, 32, 32, 255).next();
|
||||
bufferBuilder.vertex(this.right, this.bottom, 0.0D).texture((float) this.right / 32.0F, (float) (this.bottom + (int) this.getScrollAmount()) / 32.0F).color(32, 32, 32, 255).next();
|
||||
bufferBuilder.vertex(this.right, this.top, 0.0D).texture((float) this.right / 32.0F, (float) (this.top + (int) this.getScrollAmount()) / 32.0F).color(32, 32, 32, 255).next();
|
||||
bufferBuilder.vertex(this.left, this.top, 0.0D).texture((float) this.left / 32.0F, (float) (this.top + (int) this.getScrollAmount()) / 32.0F).color(32, 32, 32, 255).next();
|
||||
tessellator.draw();
|
||||
|
||||
super.renderList(matrices, this.getRowLeft(), this.top, mouseX, mouseY, delta);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendNarrations(NarrationMessageBuilder builder) {
|
||||
|
||||
}
|
||||
|
||||
private class TipsListEntry extends EntryListWidget.Entry<TipsListWidget.TipsListEntry> {
|
||||
private final Text tip;
|
||||
|
||||
public TipsListEntry(Text tip) {
|
||||
this.tip = tip;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(MatrixStack matrixStack, int index, int y, int x, int width, int height, int mouseX, int mouseY, boolean hovering, float delta) {
|
||||
MinecraftClient.getInstance().textRenderer.drawTrimmed(tip, x, y, width, 11184810);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: change to double
|
||||
|
||||
/**
|
||||
* Draws energy output value and icon
|
||||
*
|
||||
* @param gui {@link GuiBase} The GUI to draw on
|
||||
* @param x {@code int} Top left corner where to place energy output
|
||||
* @param y {@code int} Top left corner where to place energy output
|
||||
* @param maxOutput {@code int} Energy output value
|
||||
* @param layer {@link GuiBase.Layer} The layer to draw on
|
||||
*/
|
||||
public void drawEnergyOutput(MatrixStack matrixStack, GuiBase<?> gui, int x, int y, int maxOutput, GuiBase.Layer layer) {
|
||||
if (gui.hideGuiElements()) return;
|
||||
Text text = Text.literal(PowerSystem.getLocalizedPowerNoSuffix(maxOutput))
|
||||
.append(SPACE_TEXT)
|
||||
.append(PowerSystem.getDisplayPower().abbreviation)
|
||||
.append("\t");
|
||||
|
||||
int width = gui.getTextRenderer().getWidth(text);
|
||||
gui.drawText(matrixStack, text, x - width - 2, y + 5, 0, layer);
|
||||
if (layer == GuiBase.Layer.BACKGROUND) {
|
||||
x += gui.getGuiLeft();
|
||||
y += gui.getGuiTop();
|
||||
}
|
||||
RenderSystem.setShaderTexture(0, resourceLocation);
|
||||
gui.drawTexture(matrixStack, x, y, 150, 91, 16, 16);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws progress arrow in direction specified.
|
||||
*
|
||||
* @param gui {@link GuiBase} The GUI to draw on
|
||||
* @param progress {@code int} Current progress
|
||||
* @param maxProgress {@code int} Maximum progress
|
||||
* @param x {@code int} Top left corner where to place progress arrow
|
||||
* @param y {@code int} Top left corner where to place progress arrow
|
||||
* @param mouseX {@code int} Mouse cursor position to check for tooltip
|
||||
* @param mouseY {@code int} Mouse cursor position to check for tooltip
|
||||
* @param direction {@link ProgressDirection} Direction of the progress arrow
|
||||
* @param layer {@link GuiBase.Layer} The layer to draw on
|
||||
*/
|
||||
public void drawProgressBar(MatrixStack matrixStack, GuiBase<?> gui, int progress, int maxProgress, int x, int y, int mouseX, int mouseY, ProgressDirection direction, GuiBase.Layer layer) {
|
||||
if (gui.hideGuiElements()) return;
|
||||
if (layer == GuiBase.Layer.BACKGROUND) {
|
||||
x += gui.getGuiLeft();
|
||||
y += gui.getGuiTop();
|
||||
}
|
||||
|
||||
RenderSystem.setShaderTexture(0, resourceLocation);
|
||||
gui.drawTexture(matrixStack, x, y, direction.x, direction.y, direction.width, direction.height);
|
||||
int j = (int) ((double) progress / (double) maxProgress * 16);
|
||||
if (j < 0) {
|
||||
j = 0;
|
||||
}
|
||||
|
||||
switch (direction) {
|
||||
case RIGHT:
|
||||
gui.drawTexture(matrixStack, x, y, direction.xActive, direction.yActive, j, 10);
|
||||
break;
|
||||
case LEFT:
|
||||
gui.drawTexture(matrixStack, x + 16 - j, y, direction.xActive + 16 - j, direction.yActive, j, 10);
|
||||
break;
|
||||
case UP:
|
||||
gui.drawTexture(matrixStack, x, y + 16 - j, direction.xActive, direction.yActive + 16 - j, 10, j);
|
||||
break;
|
||||
case DOWN:
|
||||
gui.drawTexture(matrixStack, x, y, direction.xActive, direction.yActive, 10, j);
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
if (gui.isPointInRect(x, y, direction.width, direction.height, mouseX, mouseY)) {
|
||||
int percentage = percentage(maxProgress, progress);
|
||||
List<Text> list = new ArrayList<>();
|
||||
list.add(
|
||||
Text.literal(String.valueOf(percentage))
|
||||
.formatted(StringUtils.getPercentageColour(percentage))
|
||||
.append("%")
|
||||
);
|
||||
if (layer == GuiBase.Layer.FOREGROUND) {
|
||||
mouseX -= gui.getGuiLeft();
|
||||
mouseY -= gui.getGuiTop();
|
||||
}
|
||||
gui.renderTooltip(matrixStack, list, mouseX, mouseY);
|
||||
//RenderSystem.disableLighting();
|
||||
RenderSystem.setShaderColor(1, 1, 1, 1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws multi-energy bar
|
||||
*
|
||||
* @param gui {@link GuiBase} The GUI to draw on
|
||||
* @param x {@code int} Top left corner where to place energy bar
|
||||
* @param y {@code int} Top left corner where to place energy bar
|
||||
* @param energyStored {@code long} Current amount of energy
|
||||
* @param maxEnergyStored {@code long} Maximum amount of energy
|
||||
* @param mouseX {@code int} Mouse cursor position to check for tooltip
|
||||
* @param mouseY {@code int} Mouse cursor position to check for tooltip
|
||||
* @param buttonID {@code int} Button ID used to switch energy systems
|
||||
* @param layer {@link GuiBase.Layer} The layer to draw on
|
||||
*/
|
||||
public void drawMultiEnergyBar(MatrixStack matrixStack, GuiBase<?> gui, int x, int y, long energyStored, long maxEnergyStored, int mouseX,
|
||||
int mouseY, int buttonID, GuiBase.Layer layer) {
|
||||
if (gui.hideGuiElements()) return;
|
||||
if (layer == GuiBase.Layer.BACKGROUND) {
|
||||
x += gui.getGuiLeft();
|
||||
y += gui.getGuiTop();
|
||||
}
|
||||
|
||||
EnergySystem displayPower = PowerSystem.getDisplayPower();
|
||||
RenderSystem.setShaderTexture(0, resourceLocation);
|
||||
gui.drawTexture(matrixStack, x, y, displayPower.xBar - 15, displayPower.yBar - 1, 14, 50);
|
||||
int draw = (int) ((double) energyStored / (double) maxEnergyStored * (48));
|
||||
if (energyStored > maxEnergyStored) {
|
||||
draw = 48;
|
||||
}
|
||||
gui.drawTexture(matrixStack, x + 1, y + 49 - draw, displayPower.xBar, 48 + displayPower.yBar - draw, 12, draw);
|
||||
int percentage = percentage(maxEnergyStored, energyStored);
|
||||
if (gui.isPointInRect(x + 1, y + 1, 11, 48, mouseX, mouseY)) {
|
||||
List<Text> list = Lists.newArrayList();
|
||||
if (Screen.hasShiftDown()) {
|
||||
list.add(
|
||||
Text.literal(PowerSystem.getLocalizedPowerFullNoSuffix(energyStored))
|
||||
.formatted(Formatting.GOLD)
|
||||
.append("/")
|
||||
.append(PowerSystem.getLocalizedPowerFull(maxEnergyStored))
|
||||
);
|
||||
} else {
|
||||
list.add(
|
||||
Text.literal(PowerSystem.getLocalizedPowerNoSuffix(energyStored))
|
||||
.formatted(Formatting.GOLD)
|
||||
.append("/")
|
||||
.append(PowerSystem.getLocalizedPower(maxEnergyStored))
|
||||
);
|
||||
}
|
||||
list.add(
|
||||
StringUtils.getPercentageText(percentage)
|
||||
.append(SPACE_TEXT)
|
||||
.append(
|
||||
Text.translatable("reborncore.gui.tooltip.power_charged")
|
||||
.formatted(Formatting.GRAY)
|
||||
)
|
||||
);
|
||||
|
||||
if (gui.be instanceof IListInfoProvider) {
|
||||
if (Screen.hasShiftDown()) {
|
||||
((IListInfoProvider) gui.be).addInfo(list, true, true);
|
||||
} else {
|
||||
list.add(Text.empty());
|
||||
|
||||
list.add(
|
||||
Text.literal("Shift")
|
||||
.formatted(Formatting.BLUE)
|
||||
.append(SPACE_TEXT)
|
||||
.formatted(Formatting.GRAY)
|
||||
.append(Text.translatable("reborncore.gui.tooltip.power_moreinfo"))
|
||||
);
|
||||
}
|
||||
}
|
||||
if (layer == GuiBase.Layer.FOREGROUND) {
|
||||
mouseX -= gui.getGuiLeft();
|
||||
mouseY -= gui.getGuiTop();
|
||||
}
|
||||
gui.renderTooltip(matrixStack, list, mouseX, mouseY);
|
||||
//RenderSystem.disableLighting();
|
||||
RenderSystem.setShaderColor(1, 1, 1, 1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws tank and fluid inside it
|
||||
*
|
||||
* @param gui {@link GuiBase} The GUI to draw on
|
||||
* @param x {@code int} Top left corner of tank
|
||||
* @param y {@code int} Top left corner of tank
|
||||
* @param mouseX {@code int} Mouse cursor position to check for tooltip
|
||||
* @param mouseY {@code int} Mouse cursor position to check for tooltip
|
||||
* @param fluid {@link FluidInstance} to draw in tank
|
||||
* @param maxCapacity {@code int} Maximum tank capacity
|
||||
* @param isTankEmpty {@code boolean} True if tank is empty
|
||||
* @param layer {@link GuiBase.Layer} The layer to draw on
|
||||
*/
|
||||
public void drawTank(MatrixStack matrixStack, GuiBase<?> gui, int x, int y, int mouseX, int mouseY, FluidInstance fluid, FluidValue maxCapacity, boolean isTankEmpty, GuiBase.Layer layer) {
|
||||
if (gui.hideGuiElements()) return;
|
||||
if (layer == GuiBase.Layer.BACKGROUND) {
|
||||
x += gui.getGuiLeft();
|
||||
y += gui.getGuiTop();
|
||||
}
|
||||
|
||||
int percentage = 0;
|
||||
FluidValue amount = FluidValue.EMPTY;
|
||||
if (!isTankEmpty) {
|
||||
amount = fluid.getAmount();
|
||||
percentage = percentage(maxCapacity.getRawValue(), amount.getRawValue());
|
||||
}
|
||||
RenderSystem.setShaderTexture(0, resourceLocation);
|
||||
gui.drawTexture(matrixStack, x, y, 194, 26, 22, 56);
|
||||
if (!isTankEmpty) {
|
||||
drawFluid(matrixStack, gui, fluid, x + 4, y + 4, 14, 48, maxCapacity.getRawValue());
|
||||
}
|
||||
gui.drawTexture(matrixStack, x + 3, y + 3, 194, 82, 16, 50);
|
||||
|
||||
if (gui.isPointInRect(x, y, 22, 56, mouseX, mouseY)) {
|
||||
List<Text> list = new ArrayList<>();
|
||||
if (isTankEmpty) {
|
||||
list.add(Text.translatable("reborncore.gui.tooltip.tank_empty").formatted(Formatting.GOLD));
|
||||
} else {
|
||||
list.add(
|
||||
Text.literal(String.format("%s / %s", amount, maxCapacity))
|
||||
.formatted(Formatting.GOLD)
|
||||
.append(SPACE_TEXT)
|
||||
.append(FluidUtils.getFluidName(fluid))
|
||||
);
|
||||
}
|
||||
|
||||
list.add(
|
||||
StringUtils.getPercentageText(percentage)
|
||||
.formatted(Formatting.GRAY)
|
||||
.append(SPACE_TEXT)
|
||||
.append(Text.translatable("reborncore.gui.tooltip.tank_fullness"))
|
||||
);
|
||||
|
||||
if (layer == GuiBase.Layer.FOREGROUND) {
|
||||
mouseX -= gui.getGuiLeft();
|
||||
mouseY -= gui.getGuiTop();
|
||||
}
|
||||
gui.renderTooltip(matrixStack, list, mouseX, mouseY);
|
||||
//RenderSystem.disableLighting();
|
||||
RenderSystem.setShaderColor(1, 1, 1, 1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws fluid in tank
|
||||
*
|
||||
* @param gui {@link GuiBase} The GUI to draw on
|
||||
* @param fluid {@link FluidInstance} Fluid to draw
|
||||
* @param x {@code int} Top left corner of fluid
|
||||
* @param y {@code int} Top left corner of fluid
|
||||
* @param width {@code int} Width of fluid to draw
|
||||
* @param height {@code int} Height of fluid to draw
|
||||
* @param maxCapacity {@code int} Maximum capacity of tank
|
||||
*/
|
||||
public void drawFluid(MatrixStack matrixStack, GuiBase<?> gui, FluidInstance fluid, int x, int y, int width, int height, long maxCapacity) {
|
||||
if (fluid.getFluid() == Fluids.EMPTY) {
|
||||
return;
|
||||
}
|
||||
RenderSystem.setShaderTexture(0, SpriteAtlasTexture.BLOCK_ATLAS_TEXTURE);
|
||||
y += height;
|
||||
final Sprite sprite = FluidVariantRendering.getSprite(fluid.getVariant());
|
||||
int color = FluidVariantRendering.getColor(fluid.getVariant());
|
||||
|
||||
final int drawHeight = (int) (fluid.getAmount().getRawValue() / (maxCapacity * 1F) * height);
|
||||
final int iconHeight = sprite.getHeight();
|
||||
int offsetHeight = drawHeight;
|
||||
|
||||
RenderSystem.setShaderColor((color >> 16 & 255) / 255.0F, (float) (color >> 8 & 255) / 255.0F, (float) (color & 255) / 255.0F, 1F);
|
||||
|
||||
int iteration = 0;
|
||||
while (offsetHeight != 0) {
|
||||
final int curHeight = offsetHeight < iconHeight ? offsetHeight : iconHeight;
|
||||
|
||||
DrawableHelper.drawSprite(matrixStack, x, y - offsetHeight, 0, width, curHeight, sprite);
|
||||
offsetHeight -= curHeight;
|
||||
iteration++;
|
||||
if (iteration > 50) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
RenderSystem.setShaderColor(1F, 1F, 1F, 1F);
|
||||
|
||||
RenderSystem.setShaderTexture(0, resourceLocation);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws burning progress, similar to vanilla furnace
|
||||
*
|
||||
* @param gui {@link GuiBase} The GUI to draw on
|
||||
* @param progress {@code int} Current progress
|
||||
* @param maxProgress {@code int} Maximum progress
|
||||
* @param x {@code int} Top left corner where to place burn bar
|
||||
* @param y {@code int} Top left corner where to place burn bar
|
||||
* @param mouseX {@code int} Mouse cursor position to check for tooltip
|
||||
* @param mouseY {@code int} Mouse cursor position to check for tooltip
|
||||
* @param layer {@link GuiBase.Layer} The layer to draw on
|
||||
*/
|
||||
public void drawBurnBar(MatrixStack matrixStack, GuiBase<?> gui, int progress, int maxProgress, int x, int y, int mouseX, int mouseY, GuiBase.Layer layer) {
|
||||
if (gui.hideGuiElements()) return;
|
||||
if (layer == GuiBase.Layer.BACKGROUND) {
|
||||
x += gui.getGuiLeft();
|
||||
y += gui.getGuiTop();
|
||||
}
|
||||
RenderSystem.setShaderTexture(0, resourceLocation);
|
||||
gui.drawTexture(matrixStack, x, y, 150, 64, 13, 13);
|
||||
int j = 13 - (int) ((double) progress / (double) maxProgress * 13);
|
||||
if (j > 0) {
|
||||
gui.drawTexture(matrixStack, x, y + j, 150, 51 + j, 13, 13 - j);
|
||||
|
||||
}
|
||||
if (gui.isPointInRect(x, y, 12, 12, mouseX, mouseY)) {
|
||||
int percentage = percentage(maxProgress, progress);
|
||||
List<Text> list = new ArrayList<>();
|
||||
list.add(StringUtils.getPercentageText(percentage));
|
||||
if (layer == GuiBase.Layer.FOREGROUND) {
|
||||
mouseX -= gui.getGuiLeft();
|
||||
mouseY -= gui.getGuiTop();
|
||||
}
|
||||
gui.renderTooltip(matrixStack, list, mouseX, mouseY);
|
||||
//RenderSystem.disableLighting();
|
||||
RenderSystem.setShaderColor(1, 1, 1, 1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws bar containing output slots
|
||||
*
|
||||
* @param gui {@link GuiBase} The GUI to draw on
|
||||
* @param x {@code int} Top left corner where to place slots bar
|
||||
* @param y {@code int} Top left corner where to place slots bar
|
||||
* @param count {@code int} Number of output slots
|
||||
*/
|
||||
public void drawOutputSlotBar(MatrixStack matrixStack, GuiBase<?> gui, int x, int y, int count) {
|
||||
RenderSystem.setShaderTexture(0, resourceLocation);
|
||||
gui.drawTexture(matrixStack, x, y, 150, 122, 3, 26);
|
||||
x += 3;
|
||||
for (int i = 1; i <= count; i++) {
|
||||
gui.drawTexture(matrixStack, x, y, 150 + 3, 122, 20, 26);
|
||||
x += 20;
|
||||
}
|
||||
gui.drawTexture(matrixStack, x, y, 150 + 23, 122, 3, 26);
|
||||
}
|
||||
|
||||
protected int percentage(long MaxValue, long CurrentValue) {
|
||||
if (CurrentValue == 0) {
|
||||
return 0;
|
||||
}
|
||||
return (int) ((CurrentValue * 100.0f) / MaxValue);
|
||||
}
|
||||
|
||||
public enum ProgressDirection {
|
||||
RIGHT(58, 150, 74, 150, 16, 10),
|
||||
LEFT(74, 160, 58, 160, 16, 10),
|
||||
DOWN(78, 170, 88, 170, 10, 16),
|
||||
UP(58, 170, 68, 170, 10, 16);
|
||||
public int x;
|
||||
public int y;
|
||||
public int xActive;
|
||||
public int yActive;
|
||||
public int width;
|
||||
public int height;
|
||||
|
||||
ProgressDirection(int x, int y, int xActive, int yActive, int width, int height) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.xActive = xActive;
|
||||
this.yActive = yActive;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
* This file is part of RebornCore, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2021 TeamReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package reborncore.client.mixin;
|
||||
|
||||
import net.minecraft.client.render.VertexConsumerProvider;
|
||||
import net.minecraft.client.render.debug.DebugRenderer;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
import reborncore.client.ClientChunkManager;
|
||||
|
||||
@Mixin(DebugRenderer.class)
|
||||
public class MixinDebugRenderer {
|
||||
|
||||
@Inject(method = "render", at = @At("RETURN"))
|
||||
public void render(MatrixStack matrices, VertexConsumerProvider.Immediate vertexConsumers, double cameraX, double cameraY, double cameraZ, CallbackInfo info) {
|
||||
ClientChunkManager.render(matrices, vertexConsumers, cameraX, cameraY, cameraZ);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* This file is part of RebornCore, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2021 TeamReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package reborncore.client.mixin;
|
||||
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.network.AbstractClientPlayerEntity;
|
||||
import net.minecraft.client.render.GameRenderer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
import reborncore.api.items.ArmorFovHandler;
|
||||
|
||||
@Mixin(GameRenderer.class)
|
||||
public class MixinGameRenderer {
|
||||
|
||||
@Shadow
|
||||
@Final
|
||||
private MinecraftClient client;
|
||||
|
||||
@Redirect(method = "updateFovMultiplier", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/AbstractClientPlayerEntity;getFovMultiplier()F"))
|
||||
private float updateFovMultiplier(AbstractClientPlayerEntity playerEntity) {
|
||||
float playerSpeed = playerEntity.getFovMultiplier();
|
||||
for (ItemStack stack : playerEntity.getArmorItems()) {
|
||||
if (stack.getItem() instanceof ArmorFovHandler) {
|
||||
playerSpeed = ((ArmorFovHandler) stack.getItem()).changeFov(playerSpeed, stack, client.player);
|
||||
}
|
||||
}
|
||||
return playerSpeed;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
package reborncore.client.multiblock;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.FluidBlock;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.render.OverlayTexture;
|
||||
import net.minecraft.client.render.RenderLayers;
|
||||
import net.minecraft.client.render.VertexConsumer;
|
||||
import net.minecraft.client.render.VertexConsumerProvider;
|
||||
import net.minecraft.client.render.block.BlockRenderManager;
|
||||
import net.minecraft.client.render.model.json.ModelTransformation;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.fluid.FluidState;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.random.AbstractRandom;
|
||||
import net.minecraft.world.BlockRenderView;
|
||||
import net.minecraft.world.BlockView;
|
||||
import reborncore.common.blockentity.MultiblockWriter;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.function.BiPredicate;
|
||||
|
||||
/**
|
||||
* Renders a hologram
|
||||
*/
|
||||
@Environment(EnvType.CLIENT)
|
||||
public
|
||||
record HologramRenderer(BlockRenderView view, MatrixStack matrix, VertexConsumerProvider vertexConsumerProvider,
|
||||
float scale) implements MultiblockWriter {
|
||||
private static final BlockPos OUT_OF_WORLD_POS = new BlockPos(0, 260, 0); // Bad hack; disables lighting
|
||||
|
||||
@Override
|
||||
public MultiblockWriter add(int x, int y, int z, BiPredicate<BlockView, BlockPos> predicate, BlockState state) {
|
||||
final BlockRenderManager blockRenderManager = MinecraftClient.getInstance().getBlockRenderManager();
|
||||
matrix.push();
|
||||
matrix.translate(x, y, z);
|
||||
matrix.translate(0.5, 0.5, 0.5);
|
||||
matrix.scale(scale, scale, scale);
|
||||
|
||||
|
||||
if (state.getBlock() instanceof FluidBlock) {
|
||||
FluidState fluidState = ((FluidBlock) state.getBlock()).getFluidState(state);
|
||||
MinecraftClient.getInstance().getItemRenderer().renderItem(new ItemStack(fluidState.getFluid().getBucketItem()), ModelTransformation.Mode.FIXED, 15728880, OverlayTexture.DEFAULT_UV, matrix, vertexConsumerProvider, 0);
|
||||
} else {
|
||||
matrix.translate(-0.5, -0.5, -0.5);
|
||||
VertexConsumer consumer = vertexConsumerProvider.getBuffer(RenderLayers.getBlockLayer(state));
|
||||
blockRenderManager.renderBlock(state, OUT_OF_WORLD_POS, view, matrix, consumer, false, AbstractRandom.create());
|
||||
}
|
||||
|
||||
matrix.pop();
|
||||
return this;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
/*
|
||||
* This file is part of RebornCore, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2021 TeamReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This class was created by <Vazkii>. It's distributed as
|
||||
* part of the Botania Mod. Get the Source Code in GitHub:
|
||||
* https://github.com/Vazkii/Botania
|
||||
* <p>
|
||||
* Botania is Open Source and distributed under the
|
||||
* Botania License: http://botaniamod.net/license.php
|
||||
*/
|
||||
|
||||
package reborncore.client.multiblock;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
public class MultiblockComponent {
|
||||
|
||||
public BlockPos relPos;
|
||||
public final BlockState state;
|
||||
|
||||
public MultiblockComponent(BlockPos relPos, BlockState state) {
|
||||
this.relPos = relPos;
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public BlockPos getRelativePosition() {
|
||||
return relPos;
|
||||
}
|
||||
|
||||
public Block getBlock() {
|
||||
return state.getBlock();
|
||||
}
|
||||
|
||||
public BlockState getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
public MultiblockComponent copy() {
|
||||
return new MultiblockComponent(relPos, state);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* This file is part of RebornCore, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2021 TeamReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package reborncore.client.multiblock;
|
||||
|
||||
import net.minecraft.client.render.VertexConsumerProvider;
|
||||
import net.minecraft.client.render.block.entity.BlockEntityRenderer;
|
||||
import net.minecraft.client.render.block.entity.BlockEntityRendererFactory;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import reborncore.common.blockentity.MachineBaseBlockEntity;
|
||||
|
||||
public class MultiblockRenderer<T extends MachineBaseBlockEntity> implements BlockEntityRenderer<T> {
|
||||
|
||||
public MultiblockRenderer(BlockEntityRendererFactory.Context ctx) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(T blockEntity, float partialTicks, MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int light, int overlay) {
|
||||
if (blockEntity.renderMultiblock) {
|
||||
blockEntity.writeMultiblock(new HologramRenderer(blockEntity.getWorld(), matrixStack, vertexConsumerProvider, 0.4F).rotate(blockEntity.getFacing().getOpposite()));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"required": true,
|
||||
"package": "reborncore.client.mixin",
|
||||
"compatibilityLevel": "JAVA_17",
|
||||
"client": [
|
||||
"MixinGameRenderer",
|
||||
"MixinDebugRenderer"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue