Skip to content

Commit

Permalink
large update
Browse files Browse the repository at this point in the history
  • Loading branch information
mizuri-n committed Mar 31, 2024
1 parent ac36835 commit ae098b0
Show file tree
Hide file tree
Showing 15 changed files with 314 additions and 19 deletions.
10 changes: 10 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ repositories {
name = 'Fabric'
url = 'https://maven.fabricmc.net/'
}
ivy {
url = "https://github.com/UselessSolutions"
patternLayout {
artifact "[organisation]/releases/download/v[revision]/[module]-[revision].jar"
m2compatible = true
}
metadataSources { artifact() }
}
ivy {
url = "https://github.com/Better-than-Adventure"
patternLayout {
Expand Down Expand Up @@ -85,6 +93,8 @@ 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.4"

implementation "org.slf4j:slf4j-api:1.8.0-beta4"
Expand Down
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ loader_version=0.14.19-babric.3-bta
# HalpLibe
halplibe_version=3.5.1

prismatic_version=3.0.3-7.1

# Mod
mod_version=1.0.2
mod_group=Mizuri-n
Expand Down
45 changes: 45 additions & 0 deletions src/main/java/mizurin/shieldmod/ShieldAchievements.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package mizurin.shieldmod;
import net.minecraft.client.render.TextureFX;
import net.minecraft.core.Global;
import net.minecraft.core.achievement.Achievement;
import net.minecraft.core.achievement.AchievementList;
import net.minecraft.core.achievement.stat.Stat;
import net.minecraft.core.block.Block;
import net.minecraft.core.util.helper.Side;
import org.lwjgl.opengl.GL11;
import turniplabs.halplibe.util.achievements.AchievementPage;
import turniplabs.halplibe.util.achievements.GuiAchievements;

import java.util.Random;

public class ShieldAchievements extends AchievementPage {
public static final Achievement SHIELD_GOT = new Achievement(AchievementList.achievementList.size() + 1, "shieldmod.shield.got", 0, 0, Block.cobbleStone, null);
public static final Achievement BLOCK = new Achievement(AchievementList.achievementList.size() + 1, "shieldmod.block", 2, 1, Block.brickStone, SHIELD_GOT);
public static final Achievement MODERN_AGE = new Achievement(AchievementList.achievementList.size() + 1, "shieldmod.modern.age", 2, 0, Block.blockSteel, SHIELD_GOT);
public static final Achievement FLY_HIGH = new Achievement(AchievementList.achievementList.size() + 1, "shieldmod.fly.high", 2, 2, Block.wool, BLOCK);
public static final Achievement GOLD_RETAL = new Achievement(AchievementList.achievementList.size() + 1, "shieldmod.gold.retal", 3, 2, Block.blockGold, BLOCK);
public ShieldAchievements(){
super("Better with defense", "achievements.page.defense");
((Stat) BLOCK).registerStat();
achievementList.add(SHIELD_GOT);
achievementList.add(BLOCK);
achievementList.add(MODERN_AGE);
achievementList.add(FLY_HIGH);
achievementList.add(GOLD_RETAL);
}
@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.cobbleStone.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;
}
}
}
5 changes: 5 additions & 0 deletions src/main/java/mizurin/shieldmod/ShieldMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
import net.minecraft.core.crafting.LookupFuelFurnace;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import turniplabs.halplibe.helper.AchievementHelper;
import turniplabs.halplibe.util.GameStartEntrypoint;
import mizurin.shieldmod.item.Shields;
import turniplabs.halplibe.util.achievements.AchievementPage;

public class ShieldMod implements ModInitializer, GameStartEntrypoint {
public static final String MOD_ID = "shieldmod";
Expand All @@ -21,6 +23,9 @@ public void onInitialize() {
@Override
public void beforeGameStart() {
new Shields().initializeItems();
AchievementPage SHIELDACHIEVEMENTS;
SHIELDACHIEVEMENTS = new ShieldAchievements();
AchievementHelper.addPage(SHIELDACHIEVEMENTS);

}

Expand Down
33 changes: 33 additions & 0 deletions src/main/java/mizurin/shieldmod/item/ShieldColored.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package mizurin.shieldmod.item;

import com.mojang.nbt.CompoundTag;
import mizurin.shieldmod.ShieldMod;
import turniplabs.halplibe.helper.TextureHelper;
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 int[] baseColor = TextureHelper.getOrCreateItemTexture(ShieldMod.MOD_ID, "colored.png");
public static final int[] overlayShield = TextureHelper.getOrCreateItemTexture(ShieldMod.MOD_ID, "outline.png");
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))};
}
}
13 changes: 11 additions & 2 deletions src/main/java/mizurin/shieldmod/item/ShieldItem.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package mizurin.shieldmod.item;

import mizurin.shieldmod.ShieldAchievements;
import net.minecraft.client.Minecraft;
import net.minecraft.core.entity.Entity;
import net.minecraft.core.entity.EntityLiving;
import net.minecraft.core.entity.player.EntityPlayer;
Expand All @@ -25,13 +27,12 @@ public ShieldItem(String name, int id, ToolMaterial toolMaterial){
}
@Override
public boolean hitEntity(ItemStack itemstack, EntityLiving target, EntityLiving player) {
if(itemstack.getItem() == Shields.goldShield){
if(itemstack.getItem() == Shields.leatherShield){
target.knockBack(player, 1, (player.x - target.x), (player.z - target.z ));
target.push((target.x - player.x)/7, 0, (target.z - player.z)/7);
} else {
target.knockBack(player, 3, player.x - target.x, player.z - target.z);
}
// Decrease durability
itemstack.damageItem(1, player);

return true;
Expand Down Expand Up @@ -60,6 +61,14 @@ public void inventoryTick(ItemStack itemstack, World world, Entity entity, int i
itemstack.getData().putBoolean("active", false);
}
}
if (itemstack != null && itemstack.getItem() instanceof ShieldItem) {
EntityPlayer thePlayer = Minecraft.getMinecraft(this).thePlayer;
thePlayer.triggerAchievement(ShieldAchievements.SHIELD_GOT);
ShieldItem shield = ((ShieldItem) itemstack.getItem());
if(shield.tool == ShieldMaterials.TOOL_STEEL){
thePlayer.triggerAchievement(ShieldAchievements.MODERN_AGE);
}
}
}
}

3 changes: 2 additions & 1 deletion src/main/java/mizurin/shieldmod/item/ShieldMaterials.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ public ToolMaterial setGuard(float guard){
this.guard = guard;
return this;
}
public static final ToolMaterial TOOL_LEATHER = new ToolMaterial().setDurability(96).setDamage(-2).setEfficiency(2.0f, 0.85f);
public static final ToolMaterial TOOL_WOOD = new ToolMaterial().setDurability(64).setDamage(-1).setEfficiency(2.0f, 0.85f);
public static final ToolMaterial TOOL_STONE = new ToolMaterial().setDurability(128).setDamage(0).setEfficiency(2.0f, 0.75f);
public static final ToolMaterial TOOL_IRON = new ToolMaterial().setDurability(256).setDamage(1).setEfficiency(2.0f, 0.60f);
public static final ToolMaterial TOOL_GOLD = new ToolMaterial().setDurability(64).setDamage(-1).setEfficiency(2.0f, 0.40f).setSilkTouch(true);
public static final ToolMaterial TOOL_GOLD = new ToolMaterial().setDurability(96).setDamage(-1).setEfficiency(2.0f, 0.50f).setSilkTouch(true);
public static final ToolMaterial TOOL_DIAMOND = new ToolMaterial().setDurability(1536).setDamage(3).setEfficiency(2.0f, 0.40f);
public static final ToolMaterial TOOL_STEEL = new ToolMaterial().setDurability(4608).setDamage(2).setEfficiency(2.0f, 0.60f);

Expand Down
8 changes: 1 addition & 7 deletions src/main/java/mizurin/shieldmod/item/Shields.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,13 @@
public class Shields {
public static final String MOD_ID = ShieldMod.MOD_ID;
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
public static final Item leatherShield = ItemHelper.createItem(MOD_ID, new ShieldColored("leather.shield", 17006, ShieldMaterials.TOOL_LEATHER), "wooden_shield.png").withTags(ItemTags.preventCreativeMining);
public static final Item woodenShield = ItemHelper.createItem(MOD_ID, new ShieldItem("wooden.shield", 17000, ShieldMaterials.TOOL_WOOD),"wooden_shield.png").withTags(ItemTags.preventCreativeMining);
public static final Item stoneShield = ItemHelper.createItem(MOD_ID, new ShieldItem("stone.shield", 17001, ShieldMaterials.TOOL_STONE), "stone_shield.png").withTags(ItemTags.preventCreativeMining);
public static final Item ironShield = ItemHelper.createItem(MOD_ID, new ShieldItem("iron.shield", 17002, ShieldMaterials.TOOL_IRON), "iron_shield.png").withTags(ItemTags.preventCreativeMining);
public static final Item goldShield = ItemHelper.createItem(MOD_ID, new ShieldItem("gold.shield", 17003, ShieldMaterials.TOOL_GOLD), "gold_shield.png").withTags(ItemTags.preventCreativeMining);
public static final Item diamondShield = ItemHelper.createItem(MOD_ID, new ShieldItem("diamond.shield", 17004, ShieldMaterials.TOOL_DIAMOND), "diamond_shield.png").withTags(ItemTags.preventCreativeMining);
public static final Item steelShield = ItemHelper.createItem(MOD_ID, new ShieldItem("steel.shield", 17005, ShieldMaterials.TOOL_STEEL), "steel_shield.png").withTags(ItemTags.preventCreativeMining);


//woodenShield = ItemHelper.createItem(MOD_ID, new ShieldItem("wooden.shield", 17000, ShieldMaterials.TOOL_WOOD),"wooden_shield.png").withTags(ItemTags.preventCreativeMining);
//stoneShield = ItemHelper.createItem(MOD_ID, new ShieldItem("stone.shield", 17001, ShieldMaterials.TOOL_STONE), "stone_shield.png").withTags(ItemTags.preventCreativeMining);
//ironShield = ItemHelper.createItem(MOD_ID, new ShieldItem("iron.shield", 17002, ShieldMaterials.TOOL_IRON), "iron_shield.png").withTags(ItemTags.preventCreativeMining);
//goldShield = ItemHelper.createItem(MOD_ID, new ShieldItem("gold.shield", 17003, ShieldMaterials.TOOL_GOLD), "gold_shield.png").withTags(ItemTags.preventCreativeMining);
//diamondShield = ItemHelper.createItem(MOD_ID, new ShieldItem("diamond.shield", 17004, ShieldMaterials.TOOL_DIAMOND), "diamond_shield.png").withTags(ItemTags.preventCreativeMining);
//steelShield = ItemHelper.createItem(MOD_ID, new ShieldItem("steel.shield", 17005, ShieldMaterials.TOOL_STEEL), "steel_shield.png").withTags(ItemTags.preventCreativeMining);
public void initializeItems(){}
}
4 changes: 4 additions & 0 deletions src/main/java/mizurin/shieldmod/mixins/ItemMixin.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package mizurin.shieldmod.mixins;
import mizurin.shieldmod.ShieldAchievements;
import mizurin.shieldmod.item.ShieldItem;
import net.minecraft.client.Minecraft;
import net.minecraft.client.render.entity.LivingRenderer;
import net.minecraft.client.render.entity.PlayerRenderer;
import net.minecraft.client.render.model.ModelBase;
Expand Down Expand Up @@ -27,6 +29,8 @@ public void injectRenderer(EntityPlayer entity, float f, CallbackInfo ci) {
ItemStack itemstack = entity.inventory.getCurrentItem();

if (itemstack != null && itemstack.getItem() instanceof ShieldItem) {
EntityPlayer thePlayer = Minecraft.getMinecraft(this).thePlayer;
thePlayer.triggerAchievement(ShieldAchievements.SHIELD_GOT);
if (itemstack.getData().getBoolean("active")) {
GL11.glPushMatrix();
modelBipedMain.bipedRightArm.postRender(0.0625F);
Expand Down
32 changes: 29 additions & 3 deletions src/main/java/mizurin/shieldmod/mixins/ShieldMixin.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package mizurin.shieldmod.mixins;

import net.minecraft.client.Minecraft;
import net.minecraft.core.entity.Entity;
import net.minecraft.core.entity.monster.EntityMonster;
import net.minecraft.core.entity.player.EntityPlayer;
import net.minecraft.core.entity.projectile.EntityArrow;
import net.minecraft.core.item.ItemStack;
import net.minecraft.core.player.gamemode.Gamemode;
import net.minecraft.core.util.helper.DamageType;
Expand All @@ -14,6 +17,7 @@
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import mizurin.shieldmod.item.ShieldItem;
import mizurin.shieldmod.item.ShieldMaterials;
import mizurin.shieldmod.ShieldAchievements;


// mixin to EntityPlayer, do not remap(forgot what remap does)
Expand Down Expand Up @@ -44,23 +48,45 @@ public ShieldMixin(World world) {
// inject at the top(HEAD) of hurt(), allow us to call return(cancel/set return value)
@Inject(method = "hurt", at = @At("HEAD"), cancellable = true)
public void injectHurt(Entity attacker, int damage, DamageType type, CallbackInfoReturnable<Boolean> ci) {
if (attacker instanceof EntityMonster || attacker instanceof EntityArrow) {
if (this.world.difficultySetting == 0) {
damage = 0;
}

if (this.world.difficultySetting == 1) {
damage = damage / 3 + 1;
}

if (this.world.difficultySetting == 3) {
damage = damage * 3 / 2;
}
}

// check if we are holding the shield item.
EntityPlayer thePlayer = Minecraft.getMinecraft(this).thePlayer;
ItemStack stack = inventory.mainInventory[inventory.currentItem];
if (stack != null) {
if (stack.getItem() instanceof ShieldItem) {

ShieldItem shield = ((ShieldItem) stack.getItem());
{
if (attacker != null) {
World world = attacker.world;

int newDamage = Math.round(damage * (shield.tool.getEfficiency(true)));
if (!this.gamemode.isPlayerInvulnerable()) {
if (stack.getData().getBoolean("active")) {
if (shield.tool == ShieldMaterials.TOOL_WOOD){
attacker.push(0,1,0);
int newDamage = Math.round(damage * (shield.tool.getEfficiency(true)));
if (shield.tool == ShieldMaterials.TOOL_LEATHER){
attacker.push(0 ,1,0);
thePlayer.triggerAchievement(ShieldAchievements.FLY_HIGH);
}
if(shield.tool == ShieldMaterials.TOOL_GOLD){
attacker.hurt(attacker, newDamage, type);
thePlayer.triggerAchievement(ShieldAchievements.GOLD_RETAL);
}
super.hurt(attacker, newDamage, type);
thePlayer.triggerAchievement(ShieldAchievements.BLOCK);

world.playSoundAtEntity(attacker,
attacker, ("mob.ghast.fireball"),
1.0F,
Expand Down
Loading

0 comments on commit ae098b0

Please sign in to comment.