Skip to content

Commit

Permalink
Merge pull request #9 from UselessBullets/1.7.7.x
Browse files Browse the repository at this point in the history
made colored items work
  • Loading branch information
mizuri-n authored Aug 16, 2024
2 parents 6f8313e + 9fd8331 commit 19f938d
Show file tree
Hide file tree
Showing 12 changed files with 273 additions and 85 deletions.
4 changes: 1 addition & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,7 @@ dependencies {
// If you do not need Halplibe you can comment this line out or delete this line
modImplementation "com.github.Turnip-Labs:bta-halplibe:${project.halplibe_version}"

modImplementation "BTA_Babric_PrismaticLibe:prismaticlibe:${project.prismatic_version}"

modImplementation "ModMenu:ModMenu:2.0.5"
modImplementation "ModMenu:ModMenu:2.0.6"

implementation "org.slf4j:slf4j-api:1.8.0-beta4"
implementation "org.apache.logging.log4j:log4j-slf4j18-impl:2.16.0"
Expand Down
6 changes: 2 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
org.gradle.jvmargs=-Xmx2G

# BTA
bta_version=7.2-pre1
bta_version=7.2_01

# Loader
loader_version=0.15.6-babric.6-bta

# HalpLibe
halplibe_version=4.0.6

prismatic_version=3.1.2-7.1
halplibe_version=4.1.3

# Mod
mod_version=1.0.7
Expand Down
29 changes: 17 additions & 12 deletions src/main/java/mizurin/shieldmod/ShieldAchievements.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,24 @@ public ShieldAchievements(){
achievementList.add(COLORS);
achievementList.add(INVINCIBLE);
}

@Override
public void getBackground(GuiAchievements guiAchievements, Random random, int iOffset, int jOffset, int blockX1, int blockY1, int blockX2, int blockY2) {
int l7 = 0;
while (l7 * 16 - blockY2 < 155) {
float f5 = 0.6f - (float)(blockY1 + l7) / 25.0f * 0.3f;
GL11.glColor4f(f5, f5, f5, 1.0f);
int i8 = 0;
while (i8 * 16 - blockX2 < 224) {
int k8 = Block.brickStone.getBlockTextureFromSideAndMetadata(Side.BOTTOM,0);
//guiAchievements.drawTexturedModalRect(iOffset + i8 * 16 - blockX2, jOffset + l7 * 16 - blockY2, k8 % Global.TEXTURE_ATLAS_WIDTH_TILES * TextureFX.tileWidthTerrain, k8 / Global.TEXTURE_ATLAS_WIDTH_TILES * TextureFX.tileWidthTerrain, 16, 16, TextureFX.tileWidthTerrain, 1.0f / (float)(Global.TEXTURE_ATLAS_WIDTH_TILES * TextureFX.tileWidthTerrain));
++i8;
}
++l7;
}

}
// @Override
// public void getBackground(GuiAchievements guiAchievements, Random random, int iOffset, int jOffset, int blockX1, int blockY1, int blockX2, int blockY2) {
// int l7 = 0;
// while (l7 * 16 - blockY2 < 155) {
// float f5 = 0.6f - (float)(blockY1 + l7) / 25.0f * 0.3f;
// GL11.glColor4f(f5, f5, f5, 1.0f);
// int i8 = 0;
// while (i8 * 16 - blockX2 < 224) {
// int k8 = Block.brickStone.getBlockTextureFromSideAndMetadata(Side.BOTTOM,0);
// //guiAchievements.drawTexturedModalRect(iOffset + i8 * 16 - blockX2, jOffset + l7 * 16 - blockY2, k8 % Global.TEXTURE_ATLAS_WIDTH_TILES * TextureFX.tileWidthTerrain, k8 / Global.TEXTURE_ATLAS_WIDTH_TILES * TextureFX.tileWidthTerrain, 16, 16, TextureFX.tileWidthTerrain, 1.0f / (float)(Global.TEXTURE_ATLAS_WIDTH_TILES * TextureFX.tileWidthTerrain));
// ++i8;
// }
// ++l7;
// }
// }
}
20 changes: 8 additions & 12 deletions src/main/java/mizurin/shieldmod/item/ArmorColored.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,16 @@
import net.minecraft.core.item.ItemArmor;
import net.minecraft.core.item.material.ArmorMaterial;
import net.minecraft.core.item.ItemStack;
import useless.prismaticlibe.ColoredArmorTexture;
import useless.prismaticlibe.ColoredTexture;
import useless.prismaticlibe.IColored;
import useless.prismaticlibe.IColoredArmor;

import java.awt.*;

public class ArmorColored extends ItemArmor implements IColored, IColoredArmor {
public class ArmorColored extends ItemArmor /*implements IColored, IColoredArmor*/ {
public static final String MOD_ID = ShieldMod.MOD_ID;
private final IconCoordinate[] armorColor = new IconCoordinate[]{
TextureRegistry.getTexture(MOD_ID + "item/armor/leather_helmet.png"),
TextureRegistry.getTexture(MOD_ID + "item/armor/leather_chestplate.png"),
TextureRegistry.getTexture(MOD_ID + "item/armor/leather_leggings.png"),
TextureRegistry.getTexture(MOD_ID + "item/armor/leather_boots.png")};
// private final IconCoordinate[] armorColor = new IconCoordinate[]{
// TextureRegistry.getTexture(MOD_ID + "item/armor/leather_helmet"),
// TextureRegistry.getTexture(MOD_ID + "item/armor/leather_chestplate"),
// TextureRegistry.getTexture(MOD_ID + "item/armor/leather_leggings"),
// TextureRegistry.getTexture(MOD_ID + "item/armor/leather_boots")};


public ArmorColored(String name, int id, ArmorMaterial material, int armorPiece) {
Expand All @@ -36,13 +32,13 @@ public Color getColor(ItemStack itemStack){
}
return new Color(255, 255,255);
}
@Override
/*@Override
public ColoredTexture[] getTextures(ItemStack itemStack) {
return new ColoredTexture[]{new ColoredTexture(armorColor[armorPiece], getColor(itemStack))};
}
public ColoredArmorTexture[] getArmorTextures(ItemStack itemStack) {
return new ColoredArmorTexture[]{new ColoredArmorTexture("leather", getColor(itemStack))};
}
}*/

}
133 changes: 133 additions & 0 deletions src/main/java/mizurin/shieldmod/item/ItemModelColored.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
package mizurin.shieldmod.item;

import net.minecraft.client.Minecraft;
import net.minecraft.client.render.EntityRenderDispatcher;
import net.minecraft.client.render.FontRenderer;
import net.minecraft.client.render.RenderEngine;
import net.minecraft.client.render.item.model.ItemModelStandard;
import net.minecraft.client.render.stitcher.IconCoordinate;
import net.minecraft.client.render.tessellator.Tessellator;
import net.minecraft.core.entity.Entity;
import net.minecraft.core.item.Item;
import net.minecraft.core.item.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.lwjgl.opengl.GL11;

import java.util.Random;
import java.util.function.Function;

public class ItemModelColored extends ItemModelStandard {
private int currentIndex;
private final ColoredTextureEntry[] textureEntries; // Specifically an array list to guarantee consecutive order when indexing
public ItemModelColored(Item item, ColoredTextureEntry[] textureEntries) {
super(item, null);
this.textureEntries = textureEntries;
}

@Override
public void renderItemInWorld(Tessellator tessellator, Entity entity, ItemStack itemStack, float brightness, float alpha, boolean worldTransform) {
currentIndex = 0;
for (int i = 0; i < textureEntries.length; i++) {
currentIndex = i;
super.renderItemInWorld(tessellator, entity, itemStack, brightness, alpha, worldTransform);
}
}

@Override
public void renderItemIntoGui(Tessellator tessellator, FontRenderer fontrenderer, RenderEngine renderengine, ItemStack itemStack, int x, int y, float brightness, float alpha) {
currentIndex = 0;
for (int i = 0; i < textureEntries.length; i++) {
currentIndex = i;
super.renderItemIntoGui(tessellator, fontrenderer, renderengine, itemStack, x, y, brightness, alpha);
}
}

@Override
public void renderAsItemEntity(Tessellator tessellator, @Nullable Entity entity, Random random, ItemStack itemstack, int renderCount, float yaw, float brightness, float partialTick) {
Minecraft mc = Minecraft.getMinecraft(this);
if (mc.fullbright || this.itemfullBright) {
brightness = 1.0F;
}

EntityRenderDispatcher renderDispatcher = EntityRenderDispatcher.instance;
GL11.glScalef(0.5F, 0.5F, 0.5F);
IconCoordinate tex = this.getIcon(entity, itemstack);
tex.parentAtlas.bindTexture();
int render;
float r;
float g;
float b;

if (mc.gameSettings.items3D.value) {
GL11.glPushMatrix();
GL11.glScaled(1.0, 1.0, 1.0);
GL11.glRotated(yaw, 0.0, 1.0, 0.0);
GL11.glTranslated(-0.5, 0.0, -0.05 * (double)(renderCount - 1));

for(render = 0; render < renderCount; ++render) {
GL11.glPushMatrix();
GL11.glTranslated(0.0, 0.0, 0.1 * (double)render);
for (int index = 0; index < textureEntries.length; index++) {
currentIndex = index;
ColoredTextureEntry e = textureEntries[index];
int color = e.colorProcessor.apply(itemstack);
r = (float)(color >> 16 & 255) / 255.0F;
g = (float)(color >> 8 & 255) / 255.0F;
b = (float)(color & 255) / 255.0F;
GL11.glColor4f(r * brightness, g * brightness, b * brightness, 1.0F);
this.renderItem(tessellator, renderDispatcher.itemRenderer, itemstack, entity, brightness, false);
}
currentIndex = 0;
GL11.glPopMatrix();
}

GL11.glPopMatrix();
} else {
for(render = 0; render < renderCount; ++render) {
GL11.glPushMatrix();
if (render > 0) {
float rOffX = (random.nextFloat() * 2.0F - 1.0F) * 0.3F;
float rOffY = (random.nextFloat() * 2.0F - 1.0F) * 0.3F;
float rOffZ = (random.nextFloat() * 2.0F - 1.0F) * 0.3F;
GL11.glTranslatef(rOffX, rOffY, rOffZ);
}

GL11.glRotatef(180.0F - renderDispatcher.viewLerpYaw, 0.0F, 1.0F, 0.0F);
for (int index = 0; index < textureEntries.length; index++) {
currentIndex = index;
ColoredTextureEntry e = textureEntries[index];
int color = e.colorProcessor.apply(itemstack);
r = (float)(color >> 16 & 255) / 255.0F;
g = (float)(color >> 8 & 255) / 255.0F;
b = (float)(color & 255) / 255.0F;
GL11.glColor4f(r * brightness, g * brightness, b * brightness, 1.0F);
this.renderFlat(tessellator, e.coordinate);
}
currentIndex = 0;
GL11.glPopMatrix();
}
}

}


@Override
public @NotNull IconCoordinate getIcon(@Nullable Entity entity, ItemStack itemStack) {
return textureEntries[currentIndex].coordinate;
}

@Override
public int getColor(ItemStack stack) {
return textureEntries[currentIndex].colorProcessor.apply(stack);
}

public static class ColoredTextureEntry {
public final IconCoordinate coordinate;
public final Function<ItemStack, Integer> colorProcessor;
public ColoredTextureEntry(IconCoordinate coordinate, Function<ItemStack, Integer> colorProcessor) {
this.coordinate = coordinate;
this.colorProcessor = colorProcessor;
}
}
}
25 changes: 21 additions & 4 deletions src/main/java/mizurin/shieldmod/item/ItemModelShield.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,33 @@
package mizurin.shieldmod.item;

import com.mojang.nbt.CompoundTag;
import net.minecraft.client.render.ItemRenderer;
import net.minecraft.client.render.item.model.ItemModelStandard;
import net.minecraft.client.render.stitcher.TextureRegistry;
import net.minecraft.core.entity.Entity;
import net.minecraft.core.item.Item;
import net.minecraft.core.item.ItemStack;
import org.lwjgl.opengl.GL11;

public class ItemModelShield extends ItemModelStandard {
public ItemModelShield(Item item, String namespace) {
super(item, namespace);
import java.util.ArrayList;

import static mizurin.shieldmod.ShieldMod.MOD_ID;

public class ItemModelShield extends ItemModelColored {
public ItemModelShield(Item item, ColoredTextureEntry[] textureEntries) {
super(item, textureEntries);
}

public static int shieldColor(ItemStack itemStack){
if (itemStack.getData().containsKey("dyed_color")){
CompoundTag colorTag = itemStack.getData().getCompound("dyed_color");
int red = colorTag.getShort("red");
int green = colorTag.getShort("green");
int blue = colorTag.getShort("blue");
return (0xFF << 24 | red << 16 | green << 8 | blue);
}
return 0xFFFFFFFF;
}

@Override
public void heldTransformThirdPerson(ItemRenderer renderer, Entity entity, ItemStack itemstack) {
if (itemstack.getData().getBoolean("active")) {
Expand Down
27 changes: 2 additions & 25 deletions src/main/java/mizurin/shieldmod/item/ShieldColored.java
Original file line number Diff line number Diff line change
@@ -1,38 +1,15 @@
package mizurin.shieldmod.item;

import com.mojang.nbt.CompoundTag;
import mizurin.shieldmod.ShieldMod;
import net.minecraft.client.render.stitcher.IconCoordinate;
import net.minecraft.client.render.stitcher.TextureRegistry;
import net.minecraft.core.entity.Entity;
import net.minecraft.core.world.World;
import net.minecraft.core.item.ItemStack;
import net.minecraft.core.item.material.ToolMaterial;
import useless.prismaticlibe.ColoredTexture;
import useless.prismaticlibe.IColored;
import java.awt.*;

public class ShieldColored extends ShieldItem implements IColored {
public static final String MOD_ID = ShieldMod.MOD_ID;
public static final IconCoordinate baseColor = TextureRegistry.getTexture(MOD_ID + "item/colored.png");
public static final IconCoordinate overlayShield = TextureRegistry.getTexture(MOD_ID + "item/outline.png");
public class ShieldColored extends ShieldItem {
public ShieldColored(String name, int id, ToolMaterial toolMaterial) {
super(name, id, toolMaterial);
}
public Color getColor(ItemStack itemStack){
if (itemStack.getData().containsKey("dyed_color")){
CompoundTag colorTag = itemStack.getData().getCompound("dyed_color");
int red = colorTag.getShort("red");
int green = colorTag.getShort("green");
int blue = colorTag.getShort("blue");
return new Color(red, green, blue);
}
return new Color(255, 255,255);
}
@Override
public ColoredTexture[] getTextures(ItemStack itemStack) {
return new ColoredTexture[]{new ColoredTexture(baseColor, getColor(itemStack)), new ColoredTexture(overlayShield, getColor(itemStack))};
}

@Override
public void inventoryTick(ItemStack itemstack, World world, Entity entity, int i, boolean flag) {
if(itemstack.getData().getBoolean("active")){
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/mizurin/shieldmod/item/ShieldItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,12 @@ public int getDamageVsEntity(Entity entity) {
}

@Override
public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer entityplayer) {
public ItemStack onUseItem(ItemStack itemstack, World world, EntityPlayer entityplayer) {
itemstack.getData().putBoolean("active", true);
itemstack.getData().putInt("ticks",ticksToAdd);
return itemstack;
}


@Override
public void inventoryTick(ItemStack itemstack, World world, Entity entity, int i, boolean flag) {
if(itemstack.getData().getBoolean("active")){
Expand Down
Loading

0 comments on commit 19f938d

Please sign in to comment.