Skip to content

Commit

Permalink
almost finished
Browse files Browse the repository at this point in the history
  • Loading branch information
mizuri-n committed Mar 17, 2024
1 parent 7e5ea6f commit bdfec4d
Show file tree
Hide file tree
Showing 7 changed files with 153 additions and 38 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ halplibe_version=3.4.14

# Mod
mod_version=1.0.0
mod_group=turniplabs
mod_name=examplemod
mod_group=Mizuri-n
mod_name=Shield mod
48 changes: 24 additions & 24 deletions src/main/java/turniplabs/shieldmod/ShieldMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ public class ShieldMod implements ModInitializer, RecipeEntrypoint {
public static final String MOD_ID = "shield_mod";
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);

public static final Item woodenShield = ItemHelper.createItem(MOD_ID, new ShieldItem("wooden.shield", 17000, ShieldMaterials.TOOL_WOOD),"wooden_shield.png");
public static final Item stoneShield = ItemHelper.createItem(MOD_ID, new ShieldItem("stone.shield", 17001, ShieldMaterials.TOOL_STONE), "stone_shield.png");
public static final Item ironShield = ItemHelper.createItem(MOD_ID, new ShieldItem("iron.shield", 17002, ShieldMaterials.TOOL_IRON), "iron_shield.png");
public static final Item goldShield = ItemHelper.createItem(MOD_ID, new ShieldItem("gold.shield", 17003, ShieldMaterials.TOOL_GOLD), "gold_shield.png");
public static final Item diamondShield = ItemHelper.createItem(MOD_ID, new ShieldItem("diamond.shield", 17004, ShieldMaterials.TOOL_DIAMOND), "diamond_shield.png");
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");
public static final Item steelShield = ItemHelper.createItem(MOD_ID, new ShieldItem("steel.shield", 17005, ShieldMaterials.TOOL_STEEL), "steel_shield.png").withTags(ItemTags.preventCreativeMining);



Expand All @@ -37,39 +37,39 @@ public void onInitialize() {
@Override
public void onRecipesReady() {
RecipeBuilder.Shaped(MOD_ID)
.setShape("PLP","PPP"," P ")
.addInput('P', Block.planksOak)
.addInput('L',Block.logOak)
.setShape(" P ","PLP"," P ")
.addInput('P', "minecraft:planks")
.addInput('L',"minecraft:logs")
.create("woodenShield", woodenShield.getDefaultStack());

RecipeBuilder.Shaped(MOD_ID)
.setShape("PLP","PPP"," P ")
.addInput('P', Block.planksOak)
.addInput('L',Block.stone)
.setShape(" P ","PLP"," P ")
.addInput('P', Block.cobbleStone)
.addInput('L',"minecraft:planks")
.create("stoneShield", stoneShield.getDefaultStack());

RecipeBuilder.Shaped(MOD_ID)
.setShape("PLP","PPP"," P ")
.addInput('P', Block.planksOak)
.addInput('L',Block.blockIron)
.setShape(" P ","PLP"," P ")
.addInput('P', Item.ingotIron)
.addInput('L',"minecraft:planks")
.create("ironShield", ironShield.getDefaultStack());

RecipeBuilder.Shaped(MOD_ID)
.setShape("PLP","PPP"," P ")
.addInput('P', Block.planksOak)
.addInput('L',Block.blockGold)
.setShape(" P ","PLP"," P ")
.addInput('P', Item.ingotGold)
.addInput('L',"minecraft:planks")
.create("goldShield", goldShield.getDefaultStack());

RecipeBuilder.Shaped(MOD_ID)
.setShape("PLP","PPP"," P ")
.addInput('P', Block.planksOak)
.addInput('L',Block.blockDiamond)
.setShape(" P ","PLP"," P ")
.addInput('P', Item.diamond)
.addInput('L',"minecraft:planks")
.create("diamondShield", diamondShield.getDefaultStack());

RecipeBuilder.Shaped(MOD_ID)
.setShape("PLP","PPP"," P ")
.addInput('P', Block.planksOak)
.addInput('L',Block.blockSteel)
.setShape(" P ","PLP"," P ")
.addInput('P', Item.ingotSteel)
.addInput('L',"minecraft:planks")
.create("woodenShield", steelShield.getDefaultStack());


Expand Down
16 changes: 14 additions & 2 deletions src/main/java/turniplabs/shieldmod/item/ShieldItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@
import net.minecraft.core.util.helper.MathHelper;
import java.util.Random;
import net.minecraft.core.util.helper.DamageType;
import turniplabs.shieldmod.ShieldMod;

import javax.tools.Tool;

public class ShieldItem extends ItemToolSword {
public ToolMaterial tool;
public int weaponDamage;
private static final int ticksToAdd = 5;


Expand All @@ -27,18 +29,26 @@ public ShieldItem(String name, int id, ToolMaterial toolMaterial){
maxStackSize = 1;
setMaxDamage(toolMaterial.getDurability());
this.tool = toolMaterial;
this.weaponDamage = 4 + toolMaterial.getDamage();


}
@Override
public boolean hitEntity(ItemStack itemstack, EntityLiving target, EntityLiving player) {
//target.health -= (int) 1.5;
target.knockBack(player, 3, player.x - target.x, player.z - target.z);
if(itemstack.getItem() == ShieldMod.goldShield){
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;
}
public int getDamageVsEntity(Entity entity) {
return this.weaponDamage;
}

@Override
public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer entityplayer) {
Expand All @@ -50,6 +60,8 @@ public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer
@Override
public void inventoryTick(ItemStack itemstack, World world, Entity entity, int i, boolean flag) {
if(itemstack.getData().getBoolean("active")){
entity.xd *= 0.4D;
entity.zd *= 0.4D;
int ticks = itemstack.getData().getInteger("ticks");

if (ticks > 0){
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/turniplabs/shieldmod/item/ShieldMaterials.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ public ToolMaterial setGuard(float guard){
return this;
}
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(-1).setEfficiency(2.0f, 0.75f);
public static final ToolMaterial TOOL_IRON = new ToolMaterial().setDurability(256).setDamage(0).setEfficiency(2.0f, 0.60f);
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(0).setEfficiency(2.0f, 0.40f).setSilkTouch(true);
public static final ToolMaterial TOOL_DIAMOND = new ToolMaterial().setDurability(1536).setDamage(1).setEfficiency(2.0f, 0.40f);
public static final ToolMaterial TOOL_STEEL = new ToolMaterial().setDurability(4608).setDamage(0).setEfficiency(2.0f, 0.60f);
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);

@Override
public ToolMaterial setEfficiency(float efficiency, float guard) {
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/turniplabs/shieldmod/mixins/ShieldMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ public void injectHurt(Entity attacker, int damage, DamageType type, CallbackInf
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(1, 1, 1);
//}
if (shield.tool == ShieldMaterials.TOOL_WOOD){
attacker.push(0,1,0);
}
super.hurt(attacker, newDamage, type);
world.playSoundAtEntity(
attacker, ("mob.ghast.fireball"),
Expand Down
103 changes: 103 additions & 0 deletions src/main/resources/assets/shield_mod/item/stone_shield.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
{
"credit": "Made with Blockbench",
"textures": {
"0": "stone_shield",
"particle": "stone_shield"
},
"elements": [
{
"from": [1, 0, 4],
"to": [15, 1, 12],
"faces": {
"north": {"uv": [1, 4, 15, 5], "texture": "#0"},
"east": {"uv": [4, 14, 12, 15], "texture": "#0"},
"south": {"uv": [1, 11, 15, 12], "texture": "#0"},
"west": {"uv": [4, 1, 12, 2], "texture": "#0"},
"up": {"uv": [4, 1, 12, 15], "rotation": 90, "texture": "#0"},
"down": {"uv": [4, 1, 12, 15], "rotation": 90, "texture": "#0"}
}
},
{
"from": [4, 0, 1],
"to": [12, 1, 2],
"faces": {
"north": {"uv": [14, 4, 15, 12], "rotation": 90, "texture": "#0"},
"east": {"uv": [13, 12, 14, 13], "texture": "#0"},
"south": {"uv": [0, 0, 8, 1], "texture": "#missing"},
"west": {"uv": [13, 3, 14, 4], "texture": "#0"},
"up": {"uv": [1, 4, 2, 12], "texture": "#0"},
"down": {"uv": [14, 4, 15, 12], "rotation": 90, "texture": "#0"}
}
},
{
"from": [2, 0, 2],
"to": [14, 1, 4],
"faces": {
"north": {"uv": [2, 2, 14, 3], "texture": "#0"},
"east": {"uv": [4, 14, 6, 15], "texture": "#0"},
"south": {"uv": [2, 12, 14, 13], "texture": "#0"},
"west": {"uv": [5, 1, 7, 2], "texture": "#0"},
"up": {"uv": [2, 2, 4, 14], "rotation": 90, "texture": "#0"},
"down": {"uv": [12, 2, 14, 14], "rotation": 90, "texture": "#0"}
}
},
{
"from": [2, 0, 12],
"to": [14, 1, 14],
"faces": {
"north": {"uv": [0, 0, 12, 1], "texture": "#missing"},
"east": {"uv": [2, 13, 4, 14], "texture": "#0"},
"south": {"uv": [2, 12, 14, 13], "texture": "#0"},
"west": {"uv": [4, 1, 6, 2], "texture": "#0"},
"up": {"uv": [12, 2, 14, 14], "rotation": 90, "texture": "#0"},
"down": {"uv": [2, 2, 4, 14], "rotation": 90, "texture": "#0"}
}
},
{
"from": [4, 0, 14],
"to": [12, 1, 15],
"faces": {
"north": {"uv": [0, 0, 8, 1], "texture": "#missing"},
"east": {"uv": [2, 12, 3, 13], "texture": "#0"},
"south": {"uv": [1, 4, 2, 12], "rotation": 90, "texture": "#0"},
"west": {"uv": [2, 2, 3, 3], "texture": "#0"},
"up": {"uv": [14, 4, 15, 12], "rotation": 90, "texture": "#0"},
"down": {"uv": [14, 4, 15, 12], "rotation": 90, "texture": "#0"}
}
}
],
"display": {
"thirdperson_righthand": {
"rotation": [0, 0, -91],
"translation": [9, -2, 2.75],
"scale": [0.9, 0.9, 0.9]
},
"thirdperson_lefthand": {
"rotation": [0, 0, 91],
"translation": [-4, -2, 2.75],
"scale": [0.9, 0.9, 0.9]
},
"firstperson_righthand": {
"rotation": [-1, 87, 90],
"translation": [1.75, -0.5, 5.25],
"scale": [0.9, 0.9, 0.9]
},
"firstperson_lefthand": {
"rotation": [-1, 87, 90],
"translation": [0.75, -0.5, 5.25],
"scale": [0.9, 0.9, 0.9]
},
"gui": {
"rotation": [90, 90, 0],
"translation": [0.25, 0, 0]
}
},
"groups": [
{
"name": "group",
"origin": [0, 0, 0],
"color": 0,
"children": [0, 1, 2, 3, 4]
}
]
}
6 changes: 3 additions & 3 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
"id": "shieldmod",
"version": "${version}",

"name": "Shield Mod",
"description": "shield test",
"name": "Better with defense",
"description": "A simple mod adding shields",
"authors": [
"Mizuri-n"
],
"contact": {
"homepage": "",
"homepage": "https://github.com/mizuri-n/Better-with-defense",
"sources": ""
},

Expand Down

0 comments on commit bdfec4d

Please sign in to comment.