model rework

This commit is contained in:
2023-08-19 22:24:52 +02:00
parent ce887a8e6d
commit b041599cf5
37 changed files with 844 additions and 193 deletions

View File

@@ -1,13 +0,0 @@
{
"block.trading_station.powered_trading_station": "uoıʇɐʇS buıpɐɹ⟘ pǝɹǝʍoԀ",
"block.trading_station.trading_station": "uoıʇɐʇS buıpɐɹ⟘",
"config.jade.plugin_trading_station.trading_station_data": "ɐʇɐp uoıʇɐʇS buıpɐɹ⟘",
"itemGroup.trading_station": "uoıʇɐʇS buıpɐɹ⟘",
"trading_station.powered_trading_station.block.display": "uoıʇɐʇS buıpɐɹ⟘ pǝɹǝʍoԀ",
"trading_station.select_target.button": "ʇǝbɹɐʇ ʇɔǝןǝS",
"trading_station.select_target.clear": "ɹɐǝןƆ",
"trading_station.select_target.title": "ʇǝbɹɐʇ ʇndʇno uɐ ʇɔǝןǝS",
"trading_station.tooltip.progress": "%d%% :ssǝɹboɹԀ",
"trading_station.trading.recipe": "ǝdıɔǝɹ buıpɐɹ⟘",
"trading_station.trading_station.block.display": "uoıʇɐʇS buıpɐɹ⟘"
}

View File

@@ -1,13 +0,0 @@
{
"block.trading_station.powered_trading_station": "Powered Trading Station",
"block.trading_station.trading_station": "Trading Station",
"config.jade.plugin_trading_station.trading_station_data": "Trading Station data",
"itemGroup.trading_station": "Trading Station",
"trading_station.powered_trading_station.block.display": "Powered Trading Station",
"trading_station.select_target.button": "Select target",
"trading_station.select_target.clear": "Clear",
"trading_station.select_target.title": "Select an output target",
"trading_station.tooltip.progress": "Progress: %d%%",
"trading_station.trading.recipe": "Trading recipe",
"trading_station.trading_station.block.display": "Trading Station"
}

View File

@@ -0,0 +1,4 @@
package com.oierbravo.trading_station.compat.jei;
public class TradingRecipeHandler {
}

View File

@@ -0,0 +1,2 @@
package com.oierbravo.trading_station.compat.kubejs;public class BiomeConditionComponent {
}

View File

@@ -0,0 +1,50 @@
package com.oierbravo.trading_station.compat.kubejs;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.oierbravo.trading_station.content.trading_recipe.BiomeCondition;
import dev.latvian.mods.kubejs.recipe.RecipeJS;
import dev.latvian.mods.kubejs.recipe.component.ComponentRole;
import dev.latvian.mods.kubejs.recipe.component.RecipeComponent;
import dev.latvian.mods.rhino.NativeObject;
import net.minecraft.world.level.biome.Biome;
public class ExclusiveToConditionComponent implements RecipeComponent<BiomeCondition> {
public static final RecipeComponent<BiomeCondition> BIOME_CONDITION= new ExclusiveToConditionComponent();
public ComponentRole role() {
return ComponentRole.OTHER;
}
@Override
public Class<?> componentClass() {
return BiomeCondition.class;
}
@Override
public JsonElement write(RecipeJS recipe, BiomeCondition value) {
return value.toJson();
}
private BiomeCondition fromNativeObject(NativeObject nativeObject ){
if(nativeObject.containsKey("tag"))
return BiomeCondition.fromString("#" + nativeObject.get("tag"));
return BiomeCondition.fromString(nativeObject.get("name").toString());
}
@Override
public BiomeCondition read(RecipeJS recipe, Object from) {
if (from instanceof BiomeCondition bc) {
return bc;
} else if (from instanceof Biome b) {
return BiomeCondition.fromBiome(b);
} else if (from instanceof JsonObject je) {
return BiomeCondition.fromJson(je);
} else if(from instanceof NativeObject no){
return fromNativeObject(no);
} else {
return BiomeCondition.fromString(String.valueOf(from));
}
}
}

View File

@@ -0,0 +1,197 @@
package com.oierbravo.trading_station.content.trading_recipe;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonSyntaxException;
import net.minecraft.core.Registry;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.TagKey;
import net.minecraft.util.GsonHelper;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.biome.Biome;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.IForgeRegistry;
import javax.annotation.Nullable;
import java.util.List;
import java.util.Objects;
public class BiomeCondition {
public static final BiomeCondition EMPTY = new BiomeCondition();
protected Biome biome;
public static BiomeCondition fromTag(TagKey<Biome> tag) {
BiomeTagCondition condition = new BiomeTagCondition();
condition.tag = tag;
return condition;
}
public static BiomeCondition fromBiome(Biome biome) {
BiomeCondition condition = new BiomeCondition();
condition.biome = biome;
return condition;
}
public static BiomeCondition fromString(String biome) {
if(Objects.equals(biome, "Any")){
return BiomeCondition.EMPTY;
}
if(biome.startsWith("#")){
var tagManager = ForgeRegistries.BIOMES.tags();
var tagKey = tagManager.createTagKey(new ResourceLocation(biome.replace("#","")));
var tag = tagManager.getTag(tagKey);
BiomeTagCondition tagCondition = new BiomeTagCondition();
tagCondition.tag = tagKey;
return tagCondition;
}
BiomeCondition condition = new BiomeCondition();
ResourceLocation id = new ResourceLocation(biome);
condition.biome = ForgeRegistries.BIOMES.getValue(id);
return condition;
}
protected void readInternal(FriendlyByteBuf buffer){
biome = buffer.readRegistryId();
};
protected void writeInternal(FriendlyByteBuf buffer){
buffer.writeRegistryId(ForgeRegistries.BIOMES, biome);
};
protected void readInternal(JsonObject json){
ResourceLocation id = new ResourceLocation(GsonHelper.getAsString(json, "name"));
biome = ForgeRegistries.BIOMES.getValue(id);
if (biome == null)
throw new JsonSyntaxException("Unknown biome '" + id + "'");
};
protected void writeInternal(JsonObject json){
json.addProperty("name", getKeyOrThrow(biome)
.toString());
};
public static <V> ResourceLocation getKeyOrThrow(IForgeRegistry<V> registry, V value) {
ResourceLocation key = registry.getKey(value);
if (key == null) {
throw new IllegalArgumentException("Could not get key for value " + value + "!");
}
return key;
}
public static ResourceLocation getKeyOrThrow(Biome value) {
ResourceLocation key = ForgeRegistries.BIOMES.getKey(value);
if (key == null) {
throw new IllegalArgumentException("Could not get key for value " + value + "!");
}
return key;
}
public boolean test(Biome b, LevelAccessor pLevel) {
if (b == null)
throw new IllegalArgumentException("Biome cannot be null");
return testInternal(b, pLevel);
}
protected boolean testInternal(Biome b, LevelAccessor pLevel){
if(biome == null)
return false;
if (biome.toString() != b.toString())
return false;
return true;
};
public void write(FriendlyByteBuf buffer) {
buffer.writeBoolean(this instanceof BiomeTagCondition);
writeInternal(buffer);
}
public static BiomeCondition read(FriendlyByteBuf buffer) {
boolean isTagBiome = buffer.readBoolean();
BiomeCondition biome = isTagBiome ? new BiomeTagCondition() : new BiomeCondition();
biome.readInternal(buffer);
return biome;
}
public JsonObject serialize() {
JsonObject json = new JsonObject();
writeInternal(json);
return json;
}
public static boolean isBiomeCondition(@Nullable JsonElement je) {
if (je == null || je.isJsonNull())
return false;
if (!je.isJsonObject())
return false;
JsonObject json = je.getAsJsonObject();
if (json.has("tag"))
return true;
else if (json.has("name"))
return true;
return false;
}
public static BiomeCondition deserialize(@Nullable JsonElement je) {
if (!isBiomeCondition(je))
throw new JsonSyntaxException("Invalid biome condition: " + Objects.toString(je));
JsonObject json = je.getAsJsonObject();
BiomeCondition condition = json.has("tag") ? new BiomeTagCondition() : new BiomeCondition();
condition.readInternal(json);
return condition;
}
public String toString(){
return toStringInternal();
}
protected String toStringInternal(){
if(biome == null)
return "Any";
return ForgeRegistries.BIOMES.getKey(biome).toString();
}
public static class BiomeTagCondition extends BiomeCondition {
protected TagKey<Biome> tag;
protected List<Biome> matchingBiomes;
@Override
protected boolean testInternal(Biome b, LevelAccessor pLevel) {
Registry<Biome> biomeRegistry = pLevel.registryAccess().registryOrThrow(ForgeRegistries.BIOMES.getRegistryKey());
ResourceKey<Biome> key = biomeRegistry.getResourceKey(b).get();
boolean result = biomeRegistry.getOrCreateTag(tag).contains(biomeRegistry.getOrCreateHolderOrThrow(key));
return biomeRegistry.getOrCreateTag(tag).contains(biomeRegistry.getOrCreateHolderOrThrow(key));
}
@Override
protected void readInternal(FriendlyByteBuf buffer) {
ResourceLocation resourceLocation = buffer.readResourceLocation();
tag = TagKey.create(Registry.BIOME_REGISTRY, resourceLocation);
}
@Override
protected void writeInternal(FriendlyByteBuf buffer) {
buffer.writeResourceLocation(tag.location());
}
@Override
protected void readInternal(JsonObject json) {
ResourceLocation resourceLocation = new ResourceLocation(GsonHelper.getAsString(json, "tag"));
tag = TagKey.create(Registry.BIOME_REGISTRY, resourceLocation);
}
@Override
protected void writeInternal(JsonObject json) {
json.addProperty("tag", tag.location()
.toString());
}
@Override
protected String toStringInternal(){
return "#" + tag.location().toString();
}
}
}

View File

@@ -0,0 +1,4 @@
package com.oierbravo.trading_station.content.trading_recipe;
public class ExclusiveToCondition {
}

View File

@@ -0,0 +1,4 @@
package com.oierbravo.trading_station.foundation.gui;
public class Coords2D {
}

View File

@@ -0,0 +1,57 @@
package com.oierbravo.trading_station.foundation.gui;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.narration.NarrationElementOutput;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
/**
* Copyright: Direwolf20
* Source: https://github.com/Direwolf20-MC/LaserIO
* License: MIT
*/
public class IconButton extends Button {
private ResourceLocation texture;
public IconButton(int x, int y, int width, int height, ResourceLocation texture, OnPress onPress) {
super(x, y, width, height, Component.empty(), onPress);
this.texture = texture;
}
public IconButton(int x, int y, int width, int height, ResourceLocation texture, OnPress onPress, OnTooltip onTooltip) {
super(x, y, width, height, Component.empty(), onPress, onTooltip);
this.texture = texture;
}
@Override
public void render(PoseStack stack, int mouseX, int mouseY, float partialTicks) {
RenderSystem.setShader(GameRenderer::getPositionTexShader);
RenderSystem.setShaderColor(1f, 1f, 1f, 1f);
RenderSystem.setShaderTexture(0, texture);
blit(stack, this.x, this.y, 0, 0, width, height, width, height);
}
@Override
public void renderToolTip(PoseStack stack, int x, int y) {
super.renderToolTip(stack, x, y);
}
@Override
public void onClick(double p_onClick_1_, double p_onClick_3_) {
super.onClick(p_onClick_1_, p_onClick_3_);
}
@Override
public boolean mouseClicked(double x, double y, int button) {
return super.mouseClicked(x, y, button);
}
@Override
public void updateNarration(NarrationElementOutput p_169152_) {
}
}

View File

@@ -0,0 +1,80 @@
package com.oierbravo.trading_station.foundation.gui;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.narration.NarrationElementOutput;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
/**
* Copyright: Direwolf20
* Source: https://github.com/Direwolf20-MC/LaserIO
* License: MIT
*/
public class ToggleButton extends Button {
private ResourceLocation[] textures;
private int texturePosition;
public ToggleButton(int x, int y, int width, int height, ResourceLocation[] textures, int texturePosition, OnPress onPress) {
super(x, y, width, height, Component.empty(), onPress);
this.textures = textures;
setTexturePosition(texturePosition);
}
public ToggleButton(int x, int y, int width, int height, ResourceLocation[] textures, int texturePosition, OnPress onPress, OnTooltip onTooltip) {
super(x, y, width, height, Component.empty(), onPress, onTooltip);
this.textures = textures;
setTexturePosition(texturePosition);
}
@Override
public void render(PoseStack stack, int mouseX, int mouseY, float partialTicks) {
//fill(stack, this.x, this.y, this.x + this.width, this.y + this.height, 0xFFa8a8a8);
RenderSystem.setShader(GameRenderer::getPositionTexShader);
RenderSystem.setShaderColor(1f, 1f, 1f, 1f);
RenderSystem.setShaderTexture(0, textures[texturePosition]);
blit(stack, this.x, this.y, 0, 0, width, height, width, height);
}
@Override
public void renderToolTip(PoseStack stack, int x, int y) {
super.renderToolTip(stack, x, y);
}
@Override
public void onClick(double p_onClick_1_, double p_onClick_3_) {
super.onClick(p_onClick_1_, p_onClick_3_);
}
@Override
public boolean mouseClicked(double x, double y, int button) {
return super.mouseClicked(x, y, button);
}
@Override
public void updateNarration(NarrationElementOutput p_169152_) {
}
public int getTexturePosition() {
return texturePosition;
}
public void setTexturePosition(int texturePosition) {
if (texturePosition > textures.length)
this.texturePosition = textures.length;
else
this.texturePosition = texturePosition;
}
public void nextTexturePosition() {
if (texturePosition == textures.length)
texturePosition = 0;
else
texturePosition++;
}
}

View File

@@ -0,0 +1,172 @@
package com.oierbravo.trading_station.foundation.render;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.platform.Lighting;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.*;
import net.minecraft.client.Minecraft;
import net.minecraft.client.color.item.ItemColors;
import net.minecraft.client.gui.Font;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.client.renderer.BlockEntityWithoutLevelRenderer;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.block.model.ItemTransforms;
import net.minecraft.client.renderer.entity.ItemRenderer;
import net.minecraft.client.renderer.texture.OverlayTexture;
import net.minecraft.client.renderer.texture.TextureAtlas;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.client.resources.model.BakedModel;
import net.minecraft.client.resources.model.ModelManager;
import net.minecraft.util.Mth;
import net.minecraft.world.item.ItemStack;
import javax.annotation.Nullable;
/** This class is used to make the numbers on items in the FilterCountContainer smaller when greater than 100 **/
public class LaserIOItemRenderer extends ItemRenderer {
public LaserIOItemRenderer(TextureManager textureManager, ModelManager modelManager, ItemColors itemColors, BlockEntityWithoutLevelRenderer blockEntityWithoutLevelRenderer) {
super(textureManager, modelManager, itemColors, blockEntityWithoutLevelRenderer);
}
private void fillRect(BufferBuilder p_115153_, int p_115154_, int p_115155_, int p_115156_, int p_115157_, int p_115158_, int p_115159_, int p_115160_, int p_115161_) {
RenderSystem.setShader(GameRenderer::getPositionColorShader);
p_115153_.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR);
p_115153_.vertex((double) (p_115154_ + 0), (double) (p_115155_ + 0), 0.0D).color(p_115158_, p_115159_, p_115160_, p_115161_).endVertex();
p_115153_.vertex((double) (p_115154_ + 0), (double) (p_115155_ + p_115157_), 0.0D).color(p_115158_, p_115159_, p_115160_, p_115161_).endVertex();
p_115153_.vertex((double) (p_115154_ + p_115156_), (double) (p_115155_ + p_115157_), 0.0D).color(p_115158_, p_115159_, p_115160_, p_115161_).endVertex();
p_115153_.vertex((double) (p_115154_ + p_115156_), (double) (p_115155_ + 0), 0.0D).color(p_115158_, p_115159_, p_115160_, p_115161_).endVertex();
//p_115153_.end();
BufferUploader.drawWithShader(p_115153_.end());
}
@Override
public void renderGuiItemDecorations(Font font, ItemStack itemstack, int x, int y, @Nullable String altText) {
if (!itemstack.isEmpty()) {
PoseStack posestack = new PoseStack();
if (itemstack.getCount() != 1 || altText != null) {
String textToDraw = altText == null ? String.valueOf(itemstack.getCount()) : altText;
posestack.translate(0.0D, 0.0D, (double) (this.blitOffset + 200.0F));
MultiBufferSource.BufferSource multibuffersource$buffersource = MultiBufferSource.immediate(Tesselator.getInstance().getBuilder());
if (itemstack.getCount() > 99) {
posestack.pushPose();
posestack.translate(x, y, 300);
posestack.scale(0.65f, 0.65f, 0.65f);
font.drawInBatch(textToDraw, (float) (17 - font.width(textToDraw) * 0.65f), (float) (17), 16777215, true, posestack.last().pose(), multibuffersource$buffersource, false, 0, 15728880);
posestack.popPose();
} else {
font.drawInBatch(textToDraw, (float) (x + 19 - 2 - font.width(textToDraw)), (float) (y + 6 + 3), 16777215, true, posestack.last().pose(), multibuffersource$buffersource, false, 0, 15728880);
}
multibuffersource$buffersource.endBatch();
}
if (itemstack.isBarVisible()) {
RenderSystem.disableDepthTest();
RenderSystem.disableTexture();
RenderSystem.disableBlend();
Tesselator tesselator = Tesselator.getInstance();
BufferBuilder bufferbuilder = tesselator.getBuilder();
int i = itemstack.getBarWidth();
int j = itemstack.getBarColor();
this.fillRect(bufferbuilder, x + 2, y + 13, 13, 2, 0, 0, 0, 255);
this.fillRect(bufferbuilder, x + 2, y + 13, i, 1, j >> 16 & 255, j >> 8 & 255, j & 255, 255);
RenderSystem.enableBlend();
RenderSystem.enableTexture();
RenderSystem.enableDepthTest();
}
LocalPlayer localplayer = Minecraft.getInstance().player;
float f = localplayer == null ? 0.0F : localplayer.getCooldowns().getCooldownPercent(itemstack.getItem(), Minecraft.getInstance().getFrameTime());
if (f > 0.0F) {
RenderSystem.disableDepthTest();
RenderSystem.disableTexture();
RenderSystem.enableBlend();
RenderSystem.defaultBlendFunc();
Tesselator tesselator1 = Tesselator.getInstance();
BufferBuilder bufferbuilder1 = tesselator1.getBuilder();
this.fillRect(bufferbuilder1, x, y + Mth.floor(16.0F * (1.0F - f)), 16, Mth.ceil(16.0F * f), 255, 255, 255, 127);
RenderSystem.enableTexture();
RenderSystem.enableDepthTest();
}
}
}
public void renderGuiItemDecorations(Font font, ItemStack itemstack, int x, int y, @Nullable String altText, float scale) {
if (!itemstack.isEmpty()) {
PoseStack posestack = new PoseStack();
if (itemstack.getCount() != 1 || altText != null) {
String textToDraw = altText == null ? String.valueOf(itemstack.getCount()) : altText;
posestack.translate(0.0D, 0.0D, (double) (this.blitOffset + 600.0F));
MultiBufferSource.BufferSource multibuffersource$buffersource = MultiBufferSource.immediate(Tesselator.getInstance().getBuilder());
posestack.pushPose();
posestack.translate(0, y, 300);
posestack.scale(scale, scale, scale);
font.drawInBatch(textToDraw, (float) (x + 13 - font.width(textToDraw) * scale) / scale, (float) (17), 16777215, true, posestack.last().pose(), multibuffersource$buffersource, false, 0, 15728880);
posestack.popPose();
multibuffersource$buffersource.endBatch();
}
if (itemstack.isBarVisible()) {
RenderSystem.disableDepthTest();
RenderSystem.disableTexture();
RenderSystem.disableBlend();
Tesselator tesselator = Tesselator.getInstance();
BufferBuilder bufferbuilder = tesselator.getBuilder();
int i = itemstack.getBarWidth();
int j = itemstack.getBarColor();
this.fillRect(bufferbuilder, x + 2, y + 13, 13, 2, 0, 0, 0, 255);
this.fillRect(bufferbuilder, x + (int) (2 / scale), y + 13, (int) (i * scale), 1, j >> 16 & 255, j >> 8 & 255, j & 255, 255);
RenderSystem.enableBlend();
RenderSystem.enableTexture();
RenderSystem.enableDepthTest();
}
LocalPlayer localplayer = Minecraft.getInstance().player;
float f = localplayer == null ? 0.0F : localplayer.getCooldowns().getCooldownPercent(itemstack.getItem(), Minecraft.getInstance().getFrameTime());
if (f > 0.0F) {
RenderSystem.disableDepthTest();
RenderSystem.disableTexture();
RenderSystem.enableBlend();
RenderSystem.defaultBlendFunc();
Tesselator tesselator1 = Tesselator.getInstance();
BufferBuilder bufferbuilder1 = tesselator1.getBuilder();
this.fillRect(bufferbuilder1, x, y + Mth.floor(16.0F * (1.0F - f)), 16, Mth.ceil(16.0F * f), 255, 255, 255, 127);
RenderSystem.enableTexture();
RenderSystem.enableDepthTest();
}
}
}
public void renderGuiItem(float scale, ItemStack p_115128_, int p_115129_, int p_115130_, BakedModel p_115131_) {
Minecraft.getInstance().getTextureManager().getTexture(TextureAtlas.LOCATION_BLOCKS).setFilter(false, false);
RenderSystem.setShaderTexture(0, TextureAtlas.LOCATION_BLOCKS);
RenderSystem.enableBlend();
RenderSystem.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA);
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
PoseStack posestack = RenderSystem.getModelViewStack();
posestack.pushPose();
posestack.translate((double) p_115129_, (double) p_115130_, (double) (500.0F + this.blitOffset));
posestack.translate(8.0D, 8.0D, 0.0D);
posestack.scale(1.0F, -1.0F, 1.0F);
posestack.scale(scale, scale, scale);
RenderSystem.applyModelViewMatrix();
PoseStack posestack1 = new PoseStack();
MultiBufferSource.BufferSource multibuffersource$buffersource = Minecraft.getInstance().renderBuffers().bufferSource();
boolean flag = !p_115131_.usesBlockLight();
if (flag) {
Lighting.setupForFlatItems();
}
this.render(p_115128_, ItemTransforms.TransformType.GUI, false, posestack1, multibuffersource$buffersource, 15728880, OverlayTexture.NO_OVERLAY, p_115131_);
multibuffersource$buffersource.endBatch();
RenderSystem.enableDepthTest();
if (flag) {
Lighting.setupFor3DItems();
}
posestack.popPose();
RenderSystem.applyModelViewMatrix();
}
}

View File

@@ -1,148 +0,0 @@
package com.oierbravo.trading_station.foundation.render;
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
import com.mojang.blaze3d.vertex.VertexFormat;
import com.oierbravo.trading_station.TradingStation;
import net.minecraft.client.renderer.RenderStateShard;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.ShaderInstance;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.resources.ResourceManager;
import net.minecraft.world.inventory.InventoryMenu;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.client.event.RegisterShadersEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
import java.io.IOException;
// TODO 1.17: use custom shaders instead of vanilla ones
public class RenderTypes extends RenderStateShard {
public static final ShaderStateShard GLOWING_SHADER = new ShaderStateShard(() -> Shaders.glowingShader);
public static RenderType getOutlineTranslucent(ResourceLocation texture, boolean cull) {
return RenderType.create(createLayerName("outline_translucent" + (cull ? "_cull" : "")),
DefaultVertexFormat.NEW_ENTITY, VertexFormat.Mode.QUADS, 256, false, true, RenderType.CompositeState.builder()
.setShaderState(cull ? RENDERTYPE_ENTITY_TRANSLUCENT_CULL_SHADER : RENDERTYPE_ENTITY_TRANSLUCENT_SHADER)
.setTextureState(new TextureStateShard(texture, false, false))
.setTransparencyState(TRANSLUCENT_TRANSPARENCY)
.setCullState(cull ? CULL : NO_CULL)
.setLightmapState(LIGHTMAP)
.setOverlayState(OVERLAY)
.setWriteMaskState(COLOR_WRITE)
.createCompositeState(false));
}
public static RenderType getGlowingSolid(ResourceLocation texture) {
return RenderType.create(createLayerName("glowing_solid"), DefaultVertexFormat.NEW_ENTITY, VertexFormat.Mode.QUADS, 256,
true, false, RenderType.CompositeState.builder()
.setShaderState(GLOWING_SHADER)
.setTextureState(new TextureStateShard(texture, false, false))
.setCullState(CULL)
.setLightmapState(LIGHTMAP)
.setOverlayState(OVERLAY)
.createCompositeState(true));
}
private static final RenderType GLOWING_SOLID_DEFAULT = getGlowingSolid(InventoryMenu.BLOCK_ATLAS);
public static RenderType getGlowingSolid() {
return GLOWING_SOLID_DEFAULT;
}
public static RenderType getGlowingTranslucent(ResourceLocation texture) {
return RenderType.create(createLayerName("glowing_translucent"), DefaultVertexFormat.NEW_ENTITY, VertexFormat.Mode.QUADS,
256, true, true, RenderType.CompositeState.builder()
.setShaderState(GLOWING_SHADER)
.setTextureState(new TextureStateShard(texture, false, false))
.setTransparencyState(TRANSLUCENT_TRANSPARENCY)
.setLightmapState(LIGHTMAP)
.setOverlayState(OVERLAY)
.createCompositeState(true));
}
private static final RenderType ADDITIVE = RenderType.create(createLayerName("additive"), DefaultVertexFormat.BLOCK,
VertexFormat.Mode.QUADS, 256, true, true, RenderType.CompositeState.builder()
.setShaderState(BLOCK_SHADER)
.setTextureState(new TextureStateShard(InventoryMenu.BLOCK_ATLAS, false, false))
.setTransparencyState(ADDITIVE_TRANSPARENCY)
.setCullState(NO_CULL)
.setLightmapState(LIGHTMAP)
.setOverlayState(OVERLAY)
.createCompositeState(true));
public static RenderType getAdditive() {
return ADDITIVE;
}
private static final RenderType GLOWING_TRANSLUCENT_DEFAULT = getGlowingTranslucent(InventoryMenu.BLOCK_ATLAS);
public static RenderType getGlowingTranslucent() {
return GLOWING_TRANSLUCENT_DEFAULT;
}
private static final RenderType ITEM_PARTIAL_SOLID =
RenderType.create(createLayerName("item_partial_solid"), DefaultVertexFormat.NEW_ENTITY, VertexFormat.Mode.QUADS, 256, true,
false, RenderType.CompositeState.builder()
.setShaderState(RENDERTYPE_ENTITY_SOLID_SHADER)
.setTextureState(BLOCK_SHEET)
.setCullState(CULL)
.setLightmapState(LIGHTMAP)
.setOverlayState(OVERLAY)
.createCompositeState(true));
public static RenderType getItemPartialSolid() {
return ITEM_PARTIAL_SOLID;
}
private static final RenderType ITEM_PARTIAL_TRANSLUCENT = RenderType.create(createLayerName("item_partial_translucent"),
DefaultVertexFormat.NEW_ENTITY, VertexFormat.Mode.QUADS, 256, true, true, RenderType.CompositeState.builder()
.setShaderState(RENDERTYPE_ENTITY_TRANSLUCENT_CULL_SHADER)
.setTextureState(BLOCK_SHEET)
.setTransparencyState(TRANSLUCENT_TRANSPARENCY)
.setLightmapState(LIGHTMAP)
.setOverlayState(OVERLAY)
.createCompositeState(true));
public static RenderType getItemPartialTranslucent() {
return ITEM_PARTIAL_TRANSLUCENT;
}
private static final RenderType FLUID = RenderType.create(createLayerName("fluid"),
DefaultVertexFormat.NEW_ENTITY, VertexFormat.Mode.QUADS, 256, false, true, RenderType.CompositeState.builder()
.setShaderState(RENDERTYPE_ENTITY_TRANSLUCENT_CULL_SHADER)
.setTextureState(BLOCK_SHEET_MIPPED)
.setTransparencyState(TRANSLUCENT_TRANSPARENCY)
.setLightmapState(LIGHTMAP)
.setOverlayState(OVERLAY)
.createCompositeState(true));
public static RenderType getFluid() {
return FLUID;
}
private static String createLayerName(String name) {
return TradingStation.MODID + ":" + name;
}
// Mmm gimme those protected fields
private RenderTypes() {
super(null, null, null);
}
@EventBusSubscriber(value = Dist.CLIENT, bus = EventBusSubscriber.Bus.MOD)
private static class Shaders {
private static ShaderInstance glowingShader;
/*@SubscribeEvent
public static void onRegisterShaders(RegisterShadersEvent event) throws IOException {
ResourceManager resourceManager = event.getResourceManager();
event.registerShader(new ShaderInstance(resourceManager, TradingStation.asResource("glowing_shader"), DefaultVertexFormat.NEW_ENTITY), shader -> glowingShader = shader);
}*/
}
}

View File

@@ -0,0 +1,79 @@
package com.oierbravo.trading_station.foundation.util;
import com.mojang.math.Vector3f;
import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.network.chat.Style;
import java.util.ArrayList;
import java.util.List;
/**
* Copyright: Direwolf20
* Source: https://github.com/Direwolf20-MC/LaserIO
* License: MIT
*/
public class MiscTools {
public static boolean inBounds(int x, int y, int w, int h, double ox, double oy) {
return ox >= x && ox <= x + w && oy >= y && oy <= y + h;
}
public static Vector3f findOffset(Direction direction, int slot, Vector3f[] offsets) {
Vector3f offsetVector = offsets[slot].copy();
switch (direction) {
case UP -> {
offsetVector.transform(Vector3f.XP.rotationDegrees(-270));
offsetVector.add(0, 1, 0);
}
case DOWN -> {
offsetVector.transform(Vector3f.XP.rotationDegrees(-90));
offsetVector.add(0, 0, 1);
//reverse = false;
}
//case NORTH -> offsetVector;
case EAST -> {
offsetVector.transform(Vector3f.YP.rotationDegrees(-90));
offsetVector.add(1, 0, 0);
}
case SOUTH -> {
offsetVector.transform(Vector3f.YP.rotationDegrees(-180));
offsetVector.add(1, 0, 1);
}
case WEST -> {
offsetVector.transform(Vector3f.YP.rotationDegrees(-270));
offsetVector.add(0, 0, 1);
}
}
return offsetVector;
}
public static ListTag stringListToNBT(List<String> list) {
ListTag nbtList = new ListTag();
for (String string : list) {
CompoundTag tag = new CompoundTag();
tag.putString("list", string);
nbtList.add(tag);
}
return nbtList;
}
public static List<String> NBTToStringList(ListTag nbtList) {
List<String> list = new ArrayList<>();
for (int i = 0; i < nbtList.size(); i++) {
CompoundTag tag = nbtList.getCompound(i);
list.add(tag.getString("list"));
}
return list;
}
public static MutableComponent tooltipMaker(String string, int color) {
Style style = Style.EMPTY;
style = style.withColor(color);
MutableComponent current = Component.translatable(string);
current.setStyle(style);
return current;
}
}

View File

@@ -0,0 +1,55 @@
package com.oierbravo.trading_station.network.packets;
import com.oierbravo.trading_station.content.trading_station.ITradingStationBlockEntity;
import net.minecraft.core.BlockPos;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.network.NetworkEvent;
import java.util.function.Supplier;
public class RedstoneModeSyncC2SPacket {
private final byte mode;
private final BlockPos pos;
public RedstoneModeSyncC2SPacket(byte mode, BlockPos pos) {
this.mode = mode;
this.pos = pos;
}
public RedstoneModeSyncC2SPacket(FriendlyByteBuf buf) {
this.mode = buf.readByte();
this.pos = buf.readBlockPos();
}
public void toBytes(FriendlyByteBuf buf) {
buf.writeByte(mode);
buf.writeBlockPos(pos);
}
public static void handle(RedstoneModeSyncC2SPacket message, Supplier<NetworkEvent.Context> supplier) {
NetworkEvent.Context context = supplier.get();
context.enqueueWork(() -> {
ServerPlayer sender = context.getSender();
if (sender == null)
return;
AbstractContainerMenu container = sender.containerMenu;
if (container == null)
return;
if(sender.getLevel().getBlockEntity(message.pos) instanceof ITradingStationBlockEntity blockEntity) {
blockEntity.setRedstoneMode(message.mode);
blockEntity.setChanged();
}
});
context.setPacketHandled(true);
}
}

View File

@@ -2,6 +2,8 @@
"credit": "Made with Blockbench",
"parent": "trading_station:block/trading_station",
"textures": {
"3": "trading_station:block/powered_trading_station"
"base": "trading_station:block/powered_trading_station",
"back": "trading_station:block/powered_trading_station_base",
"particle": "trading_station:block/powered_trading_station_base"
}
}

View File

@@ -0,0 +1,7 @@
{
"credit": "Made with Blockbench",
"parent": "trading_station:block/powered_trading_station",
"textures": {
"base": "trading_station:block/powered_trading_station_lit"
}
}

View File

@@ -2,6 +2,6 @@
"credit": "Made with Blockbench",
"parent": "trading_station:block/powered_trading_station",
"textures": {
"3": "trading_station:block/powered_trading_station_powered"
"base": "trading_station:block/powered_trading_station_powered"
}
}

View File

@@ -0,0 +1,7 @@
{
"credit": "Made with Blockbench",
"parent": "trading_station:block/powered_trading_station",
"textures": {
"base": "trading_station:block/powered_trading_station_powered_lit"
}
}

View File

@@ -3,31 +3,122 @@
"parent": "minecraft/block",
"render_type": "minecraft:translucent",
"textures": {
"3": "trading_station:block/trading_station"
"base": "trading_station:block/trading_station",
"particle": "trading_station:block/trading_station_back",
"back": "trading_station:block/trading_station_back"
},
"elements": [
{
"from": [0, 0, 0],
"to": [16, 16, 17],
"name": "base",
"from": [1, 2, 2],
"to": [15, 14, 15],
"faces": {
"north": {"uv": [0, 0, 8, 8], "texture": "#3"},
"east": {"uv": [0, 8, 8, 16], "texture": "#3"},
"south": {"uv": [0, 8, 8, 16], "texture": "#3"},
"west": {"uv": [0, 8, 8, 16], "texture": "#3"},
"up": {"uv": [8, 0, 16, 8], "texture": "#3"},
"down": {"uv": [8, 8, 16, 16], "texture": "#3"}
"north": {"uv": [0, 1, 8, 7], "texture": "#base"},
"east": {"uv": [0.5, 9, 7.5, 15], "texture": "#base"},
"south": {"uv": [1, 2, 15, 14], "texture": "#back"},
"west": {"uv": [0.5, 9, 7.5, 15], "texture": "#base"},
"up": {"uv": [8, 0.5, 16, 8], "texture": "#base"},
"down": {"uv": [8, 8, 16, 16], "texture": "#base"}
}
},
{
"name": "greenLamp",
"from": [3, 16, 4],
"to": [13, 18, 13],
"to": [13, 18, 12],
"faces": {
"north": {"uv": [9.5, 5, 14.5, 6], "texture": "#3"},
"east": {"uv": [9.5, 5, 14.5, 6], "texture": "#3"},
"south": {"uv": [9.5, 5, 14.5, 6], "texture": "#3"},
"west": {"uv": [9.5, 5, 14.5, 6], "texture": "#3"},
"up": {"uv": [9.5, 2, 14.5, 6], "texture": "#3"},
"down": {"uv": [0, 0, 0, 0], "texture": "#3"}
"north": {"uv": [9.5, 5, 14.5, 6], "texture": "#base"},
"east": {"uv": [9.5, 5, 14.5, 6], "texture": "#base"},
"south": {"uv": [9.5, 5, 14.5, 6], "texture": "#base"},
"west": {"uv": [9.5, 5, 14.5, 6], "texture": "#base"},
"up": {"uv": [9.5, 2, 14.5, 6], "texture": "#base"},
"down": {"uv": [0, 0, 0, 0], "texture": "#base"}
}
},
{
"name": "redLamp",
"from": [4, 3, 0],
"to": [12, 5, 2],
"faces": {
"north": {"uv": [2, 5.5, 6, 6.5], "texture": "#base"},
"east": {"uv": [2, 5.5, 3, 6.5], "texture": "#base"},
"south": {"uv": [2, 5.5, 6, 6.5], "texture": "#base"},
"west": {"uv": [2, 5.5, 3, 6.5], "texture": "#base"},
"up": {"uv": [2, 5.5, 6, 6.5], "texture": "#base"},
"down": {"uv": [2, 5.5, 6, 6.5], "texture": "#base"}
}
},
{
"name": "bottom",
"from": [0, 0, 0],
"to": [16, 2, 16],
"faces": {
"north": {"uv": [0, 7, 8, 8], "texture": "#base"},
"east": {"uv": [0, 15, 8, 16], "texture": "#base"},
"south": {"uv": [0, 15, 8, 16], "texture": "#base"},
"west": {"uv": [0, 15, 8, 16], "texture": "#base"},
"up": {"uv": [8, 8, 16, 16], "texture": "#base"},
"down": {"uv": [8, 8, 16, 16], "texture": "#base"}
}
},
{
"name": "top",
"from": [0, 14, 0],
"to": [16, 16, 16],
"faces": {
"north": {"uv": [0, 0, 8, 1], "texture": "#base"},
"east": {"uv": [0, 0, 8, 1], "texture": "#base"},
"south": {"uv": [0, 0, 8, 1], "texture": "#base"},
"west": {"uv": [0.5, 0, 8, 1], "texture": "#base"},
"up": {"uv": [8, 0, 16, 8], "texture": "#base"},
"down": {"uv": [8, 0, 16, 8], "texture": "#base"}
}
},
{
"name": "frontFrame",
"from": [1, 2, 1],
"to": [4, 14, 2],
"faces": {
"north": {"uv": [6, 1, 8, 7], "texture": "#base"},
"east": {"uv": [6, 1, 6.5, 7], "texture": "#base"},
"west": {"uv": [7.5, 1, 8, 7], "texture": "#base"},
"up": {"uv": [6, 1, 8, 7], "texture": "#base"},
"down": {"uv": [0, 0, 3, 1], "texture": "#base"}
}
},
{
"name": "frontFrame",
"from": [12, 2, 1],
"to": [15, 14, 2],
"faces": {
"north": {"uv": [0, 1, 2, 7], "texture": "#base"},
"east": {"uv": [0, 1, 0.5, 7], "texture": "#base"},
"west": {"uv": [1.5, 1, 2, 7], "texture": "#base"},
"up": {"uv": [0, 0, 3, 1], "texture": "#base"},
"down": {"uv": [0, 0, 3, 1], "texture": "#base"}
}
},
{
"name": "frontFrame",
"from": [4, 11, 1],
"to": [12, 14, 2],
"faces": {
"north": {"uv": [2, 1, 6, 2.5], "texture": "#base"},
"east": {"uv": [2, 1, 2.5, 2.5], "texture": "#base"},
"west": {"uv": [2, 1, 2.5, 2.5], "texture": "#base"},
"up": {"uv": [0, 0, 8, 1], "texture": "#base"},
"down": {"uv": [2, 2, 6, 2.5], "texture": "#base"}
}
},
{
"name": "frontFrame",
"from": [4, 2, 1],
"to": [12, 3, 2],
"faces": {
"north": {"uv": [2, 6.5, 6, 7], "texture": "#base"},
"east": {"uv": [2, 6.5, 2.5, 7], "texture": "#base"},
"west": {"uv": [2, 6.5, 2.5, 7], "texture": "#base"},
"up": {"uv": [2, 6.5, 6, 7], "texture": "#base"},
"down": {"uv": [0, 0, 8, 1], "texture": "#base"}
}
}
],

View File

@@ -0,0 +1,7 @@
{
"credit": "Made with Blockbench",
"parent": "trading_station:block/trading_station",
"textures": {
"base": "trading_station:block/trading_station_lit"
}
}

View File

@@ -2,6 +2,6 @@
"credit": "Made with Blockbench",
"parent": "trading_station:block/trading_station",
"textures": {
"3": "trading_station:block/trading_station_powered"
"base": "trading_station:block/trading_station_powered"
}
}

View File

@@ -0,0 +1,7 @@
{
"credit": "Made with Blockbench",
"parent": "trading_station:block/trading_station",
"textures": {
"base": "trading_station:block/trading_station_powered_lit"
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 860 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 222 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 916 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 916 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 967 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 857 B

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 286 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 999 B

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB