Skip to content

Commit

Permalink
7.1_01
Browse files Browse the repository at this point in the history
  • Loading branch information
Rin committed Jun 10, 2024
1 parent 60d15f8 commit 7879957
Show file tree
Hide file tree
Showing 23 changed files with 300 additions and 11 deletions.
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
org.gradle.jvmargs=-Xmx2G

# BTA
bta_version=7.1
bta_version=7.1_01

# Loader
loader_version=0.15.6-babric.5-bta

# HalpLibe
halplibe_version=3.5.2
halplibe_version=3.5.4

prismatic_version=3.1.2-7.1

# Mod
mod_version=1.1.4
mod_version=1.0.6
mod_group=Mizuri-n
mod_name=Better with Defense
9 changes: 9 additions & 0 deletions src/main/java/mizurin/shieldmod/IThrownItem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package mizurin.shieldmod;

import net.minecraft.core.item.Item;
import net.minecraft.core.item.ItemStack;

public interface IThrownItem {
public ItemStack getThrownItem();
public ItemStack setThrownItem(ItemStack itemStack);
}
6 changes: 6 additions & 0 deletions src/main/java/mizurin/shieldmod/ShieldMod.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package mizurin.shieldmod;

import mizurin.shieldmod.item.EntityShield;
import net.fabricmc.api.ModInitializer;
import net.minecraft.client.render.entity.SnowballRenderer;
import net.minecraft.core.crafting.LookupFuelFurnace;
import net.minecraft.core.data.registry.Registries;
import net.minecraft.core.entity.projectile.EntitySnowball;
import net.minecraft.core.item.Item;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import turniplabs.halplibe.helper.AchievementHelper;
import turniplabs.halplibe.helper.EntityHelper;
import turniplabs.halplibe.util.ConfigHandler;
import turniplabs.halplibe.util.GameStartEntrypoint;
import mizurin.shieldmod.item.Shields;
Expand Down Expand Up @@ -39,6 +44,7 @@ public void beforeGameStart() {
//AchievementPage SHIELDACHIEVEMENTS;
//SHIELDACHIEVEMENTS = new ShieldAchievements();
AchievementHelper.addPage(new ShieldAchievements());
EntityHelper.Client.assignEntityRenderer(EntityShield.class, new SnowballRenderer(Shields.ammotearShield.getIconFromDamage(0)));

}

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

import mizurin.shieldmod.IThrownItem;
import net.minecraft.core.HitResult;
import net.minecraft.core.entity.Entity;
import net.minecraft.core.entity.EntityLiving;
import net.minecraft.core.entity.player.EntityPlayer;
import net.minecraft.core.entity.projectile.EntityPebble;
import net.minecraft.core.item.Item;
import net.minecraft.core.item.ItemStack;
import net.minecraft.core.player.inventory.InventoryPlayer;
import net.minecraft.core.util.helper.DamageType;
import net.minecraft.core.world.World;

public class EntityShield extends EntityPebble {
public EntityShield(World world) {
super(world);
this.modelItem = Item.ammoSnowball;
this.setSize(0.9F, 0.9F);
}

public EntityShield(World world, EntityLiving entityliving) {
super(world, entityliving);
this.modelItem = Item.ammoSnowball;
}

public EntityShield(World world, double d, double d1, double d2) {
super(world, d, d1, d2);
this.modelItem = Item.ammoSnowball;
}

public void init() {
super.init();
this.damage = 0;
}
public void storeOrDropItem(EntityPlayer player, ItemStack stack){
if(stack == null || stack.stackSize <= 0){
return;
}
InventoryPlayer inventory = player.inventory;
inventory.insertItem(stack, false);
if (stack.stackSize > 0){
player.dropPlayerItem(stack);
}
}


public void onHit(HitResult hitResult) {
damage = ticksInAir /3 + 3;
if (damage > 14){
damage = 14;
}
if (hitResult.entity != null) {
hitResult.entity.hurt(this.owner, this.damage, DamageType.COMBAT);
//hitResult.entity.push(this.xd * 0.2, 0, this.zd * 0.2);
}
if (!this.world.isClientSide) {
this.world.playSoundAtEntity((Entity) null, this, "mob.ghast.fireball", 1.0F, 1.2F / (this.random.nextFloat() * 0.2F + 0.9F));
}
if (this.modelItem != null) {
for(int j = 0; j < 8; ++j) {
this.world.spawnParticle("item", this.x, this.y, this.z, (double)this.modelItem.id, 0.0, 0.0);
}
}
this.remove();
storeOrDropItem((EntityPlayer) owner, ((IThrownItem)owner).getThrownItem());
}
}
25 changes: 25 additions & 0 deletions src/main/java/mizurin/shieldmod/item/LightShield.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package mizurin.shieldmod.item;
import net.minecraft.core.entity.Entity;
import net.minecraft.core.item.ItemStack;
import net.minecraft.core.item.material.ToolMaterial;
import net.minecraft.core.world.World;

public class LightShield extends ShieldItem{
public LightShield(String name, int id, ToolMaterial toolMaterial) {
super(name, id, toolMaterial);
}
@Override
public void inventoryTick(ItemStack itemstack, World world, Entity entity, int i, boolean flag) {
if(itemstack.getData().getBoolean("active")){
entity.xd *= 0.65D;
entity.zd *= 0.65D;
int ticks = itemstack.getData().getInteger("ticks");

if (ticks > 0){
itemstack.getData().putInt("ticks", ticks - 1);
} else {
itemstack.getData().putBoolean("active", false);
}
}
}
}
16 changes: 16 additions & 0 deletions src/main/java/mizurin/shieldmod/item/ShieldColored.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.mojang.nbt.CompoundTag;
import mizurin.shieldmod.ShieldMod;
import net.minecraft.core.entity.Entity;
import net.minecraft.core.world.World;
import turniplabs.halplibe.helper.TextureHelper;
import net.minecraft.core.item.ItemStack;
import net.minecraft.core.item.material.ToolMaterial;
Expand Down Expand Up @@ -30,5 +32,19 @@ public Color getColor(ItemStack itemStack){
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")){
entity.xd *= 0.65D;
entity.zd *= 0.65D;
int ticks = itemstack.getData().getInteger("ticks");

if (ticks > 0){
itemstack.getData().putInt("ticks", ticks - 1);
} else {
itemstack.getData().putBoolean("active", false);
}
}
}

}
1 change: 1 addition & 0 deletions src/main/java/mizurin/shieldmod/item/ShieldItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public ShieldItem(String name, int id, ToolMaterial toolMaterial){


}

@Override
public boolean hitEntity(ItemStack itemstack, EntityLiving target, EntityLiving player) {
if(itemstack.getItem() == Shields.leatherShield){
Expand Down
1 change: 1 addition & 0 deletions src/main/java/mizurin/shieldmod/item/ShieldMaterials.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public ToolMaterial setGuard(float guard){
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);
public static final ToolMaterial TOOL_TEAR = new ToolMaterial().setDurability(512).setDamage(1).setEfficiency(2.0F, 0.60F);

@Override
public ToolMaterial setEfficiency(float efficiency, float guard) {
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/mizurin/shieldmod/item/Shields.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,20 @@
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 woodenShield = ItemHelper.createItem(MOD_ID, new ShieldItem("wooden.shield", ++itemID, ShieldMaterials.TOOL_WOOD),"wooden_shield.png").withTags(ItemTags.preventCreativeMining);
public static final Item woodenShield = ItemHelper.createItem(MOD_ID, new LightShield("wooden.shield", ++itemID, ShieldMaterials.TOOL_WOOD),"wooden_shield.png").withTags(ItemTags.preventCreativeMining);
public static final Item stoneShield = ItemHelper.createItem(MOD_ID, new ShieldItem("stone.shield", ++itemID, ShieldMaterials.TOOL_STONE), "stone_shield.png").withTags(ItemTags.preventCreativeMining);
public static final Item ironShield = ItemHelper.createItem(MOD_ID, new ShieldItem("iron.shield", ++itemID, ShieldMaterials.TOOL_IRON), "iron_shield.png").withTags(ItemTags.preventCreativeMining);
public static final Item goldShield = ItemHelper.createItem(MOD_ID, new ShieldItem("gold.shield", ++itemID, ShieldMaterials.TOOL_GOLD), "gold_shield.png").withTags(ItemTags.preventCreativeMining);
public static final Item diamondShield = ItemHelper.createItem(MOD_ID, new ShieldItem("diamond.shield", ++itemID, ShieldMaterials.TOOL_DIAMOND), "diamond_shield.png").withTags(ItemTags.preventCreativeMining);
public static final Item steelShield = ItemHelper.createItem(MOD_ID, new ShieldItem("steel.shield", ++itemID, ShieldMaterials.TOOL_STEEL), "steel_shield.png").withTags(ItemTags.preventCreativeMining);
public static final Item leatherShield = ItemHelper.createItem(MOD_ID, new ShieldColored("leather.shield", ++itemID, ShieldMaterials.TOOL_LEATHER), "wooden_shield.png").withTags(ItemTags.preventCreativeMining);
public static final Item tearShield = ItemHelper.createItem(MOD_ID, new ThrowShield("tear.shield", ++itemID, ShieldMaterials.TOOL_TEAR), "tearstone_shield.png").withTags(ItemTags.preventCreativeMining);
public static final Item ammotearShield = ItemHelper.createItem(MOD_ID, new Item("tear.shield.ammo", ++itemID), "ammotearstone_shield.png").setNotInCreativeMenu();

public static final Item armorLeatherHelmet = ItemHelper.createItem(MOD_ID, new ArmorColored("Leather Cap", 16426,ArmorMaterial.LEATHER , 0 ), "armor.helmet.leather");
public static final Item armorLeatherChest = ItemHelper.createItem(MOD_ID, new ArmorColored("Leather Tunic", 16427,ArmorMaterial.LEATHER , 1 ), "armor.chestplate.leather");
public static final Item armorLeatherLeg = ItemHelper.createItem(MOD_ID, new ArmorColored("Leather Pants", 16428,ArmorMaterial.LEATHER , 2 ), "armor.leggings.leather");
public static final Item armorLeatherBoot = ItemHelper.createItem(MOD_ID, new ArmorColored("Leather Boots", 16429,ArmorMaterial.LEATHER , 3 ), "armor.boots.leather");


public void initializeItems(){}
}
43 changes: 43 additions & 0 deletions src/main/java/mizurin/shieldmod/item/ThrowShield.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package mizurin.shieldmod.item;

import mizurin.shieldmod.IThrownItem;
import net.minecraft.core.entity.player.EntityPlayer;
import net.minecraft.core.item.ItemStack;
import net.minecraft.core.item.material.ToolMaterial;
import net.minecraft.core.world.World;

public class ThrowShield extends ShieldItem{
int ticksToAdd = 5;


public ThrowShield(String name, int id, ToolMaterial toolMaterial) {
super(name, id, toolMaterial);
maxStackSize = 1;
setMaxDamage(toolMaterial.getDurability());
this.tool = toolMaterial;
this.weaponDamage = 4 + toolMaterial.getDamage();

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

return itemstack;
}

public void onBlock(ItemStack itemstack, World world, EntityPlayer entityplayer){
if (entityplayer.isSneaking()){
((IThrownItem)entityplayer).setThrownItem(itemstack);
entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem,null);
world.playSoundAtEntity(null, entityplayer, "mob.ghast.fireball", 0.3F, 1.0F / (itemRand.nextFloat() * 0.4F + 0.8F));
if (!world.isClientSide) {
world.entityJoinedWorld(new EntityShield(world, entityplayer));
itemstack.damageItem(4, entityplayer);
itemstack.getData().putBoolean("active", false);
}
}
}

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


import mizurin.shieldmod.item.Shields;
import net.minecraft.core.block.BlockFarmland;
import net.minecraft.core.item.Item;
import net.minecraft.core.item.ItemStack;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

@Mixin(value = BlockFarmland.class, remap = false)
public class BlockFarmlandMixin {
@Redirect(method = "onEntityWalking(Lnet/minecraft/core/world/World;IIILnet/minecraft/core/entity/Entity;)V",
at = @At(value = "INVOKE",target = "Lnet/minecraft/core/item/ItemStack;getItem()Lnet/minecraft/core/item/Item;"))
public Item addCustomBoots(ItemStack instance){
Item item = instance.getItem();
if (item == Shields.armorLeatherBoot){
return Item.armorBootsLeather;
}
return item;
}
}

55 changes: 55 additions & 0 deletions src/main/java/mizurin/shieldmod/mixins/FieldMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package mizurin.shieldmod.mixins;
import com.mojang.nbt.CompoundTag;
import mizurin.shieldmod.IThrownItem;
import net.minecraft.core.entity.player.EntityPlayer;
import net.minecraft.core.item.ItemStack;
import net.minecraft.core.player.inventory.InventoryPlayer;
import net.minecraft.core.world.chunk.ChunkCoordinates;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(value = EntityPlayer.class, remap = false)
public abstract class FieldMixin implements IThrownItem {
@Shadow
public abstract ChunkCoordinates getLastDeathCoordinate();

@Unique
private ItemStack thrownItem;

@Override
public ItemStack getThrownItem() {
return thrownItem;
}
public void storeOrDropItem(EntityPlayer player, ItemStack stack){
if(stack == null || stack.stackSize <= 0){
return;
}
InventoryPlayer inventory = player.inventory;
inventory.insertItem(stack, false);
if (stack.stackSize > 0){
player.dropPlayerItem(stack);
}
}

@Override
public ItemStack setThrownItem(ItemStack itemStack) {
this.thrownItem = itemStack;
return itemStack;
}
@Inject(method = "addAdditionalSaveData(Lcom/mojang/nbt/CompoundTag;)V", at = @At("TAIL"))
private void addData(CompoundTag tag, CallbackInfo ci){
ItemStack thrownItem = getThrownItem();
if(thrownItem != null) {
tag.putCompound("item", thrownItem.writeToNBT(new CompoundTag()));
}
}
@Inject(method = "readAdditionalSaveData(Lcom/mojang/nbt/CompoundTag;)V", at = @At("TAIL"))
private void loadData(CompoundTag tag, CallbackInfo ci){
this.thrownItem = ItemStack.readItemStackFromNbt(tag.getCompound("item"));
storeOrDropItem((EntityPlayer)(Object)this, this.thrownItem);
}
}
4 changes: 1 addition & 3 deletions src/main/java/mizurin/shieldmod/mixins/ItemMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public ItemMixin(ModelBase model, float shadowSize) {
@Shadow
private ModelBiped modelBipedMain;

@Inject(method = "renderSpecials", at = @At("HEAD"), cancellable = true)
@Inject(method = "renderSpecials", at = @At(value = "INVOKE", target = "Lnet/minecraft/core/player/inventory/InventoryPlayer;getCurrentItem()Lnet/minecraft/core/item/ItemStack;"), cancellable = true)
public void injectRenderer(EntityPlayer entity, float f, CallbackInfo ci) {
ItemStack itemstack = entity.inventory.getCurrentItem();

Expand Down Expand Up @@ -64,8 +64,6 @@ public void injectRenderer(EntityPlayer entity, float f, CallbackInfo ci) {
GL11.glPopMatrix();
ci.cancel();
}


}
}

Expand Down
8 changes: 7 additions & 1 deletion src/main/java/mizurin/shieldmod/mixins/ShieldMixin.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package mizurin.shieldmod.mixins;

import mizurin.shieldmod.item.Shields;
import net.minecraft.core.achievement.stat.Stat;
import net.minecraft.core.entity.Entity;
import net.minecraft.core.entity.EntityLiving;
import net.minecraft.core.entity.monster.EntityMonster;
import net.minecraft.core.entity.player.EntityPlayer;
import net.minecraft.core.entity.projectile.EntityArrow;
Expand All @@ -26,7 +28,7 @@

// extend Entity so we get access to entity methods and fields.
// abstract so we don't have to implement interfaces, constructor is not used but required.
public abstract class ShieldMixin extends Entity {
public abstract class ShieldMixin extends EntityLiving {
public ShieldMixin(World world) {
super(world);
}
Expand All @@ -41,6 +43,7 @@ public ShieldMixin(World world) {
@Shadow
public Gamemode gamemode;


@Shadow
public abstract ItemStack getHeldItem();

Expand Down Expand Up @@ -79,6 +82,9 @@ public void injectHurt(Entity attacker, int damage, DamageType type, CallbackInf
World world = attacker.world;

if (!this.gamemode.isPlayerInvulnerable()) {
if(shield.tool == ShieldMaterials.TOOL_TEAR && getHealth() <= 6){
damage = Math.round(damage * 0.5f);
}
if (stack.getData().getBoolean("active")) {
int newDamage = Math.round(damage * (shield.tool.getEfficiency(true)));

Expand Down
Loading

0 comments on commit 7879957

Please sign in to comment.