diff --git a/gradle.properties b/gradle.properties index 8499ffb..dd0ebc3 100644 --- a/gradle.properties +++ b/gradle.properties @@ -11,6 +11,6 @@ halplibe_version=4.1.3 terrain_api_version=1.4.4-7.2-pre1 # Mod -mod_version=1.0.9 +mod_version=1.1.1 mod_group=Mizuri-n -mod_name=Better with Defense +mod_name=Rin's Fortress diff --git a/src/main/java/mizurin/shieldmod/IColorable.java b/src/main/java/mizurin/shieldmod/IColorable.java deleted file mode 100644 index ff03b05..0000000 --- a/src/main/java/mizurin/shieldmod/IColorable.java +++ /dev/null @@ -1,4 +0,0 @@ -package mizurin.shieldmod; - -public interface IColorable { -} diff --git a/src/main/java/mizurin/shieldmod/IShieldZombie.java b/src/main/java/mizurin/shieldmod/IShieldZombie.java deleted file mode 100644 index 6ecb82d..0000000 --- a/src/main/java/mizurin/shieldmod/IShieldZombie.java +++ /dev/null @@ -1,6 +0,0 @@ -package mizurin.shieldmod; - -public interface IShieldZombie { - boolean better_with_defense$isShieldZombie(); - boolean better_with_defense$isSnowJack(); -} diff --git a/src/main/java/mizurin/shieldmod/ShieldAchievements.java b/src/main/java/mizurin/shieldmod/ShieldAchievements.java deleted file mode 100644 index 38ae259..0000000 --- a/src/main/java/mizurin/shieldmod/ShieldAchievements.java +++ /dev/null @@ -1,52 +0,0 @@ -package mizurin.shieldmod; -import mizurin.shieldmod.item.Shields; -import net.minecraft.core.achievement.Achievement; -import net.minecraft.core.achievement.AchievementList; -import net.minecraft.core.block.Block; -import net.minecraft.core.item.ItemDye; -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, Shields.woodenShield, null); - public static final Achievement BLOCK = new Achievement(AchievementList.achievementList.size() + 1, "shieldmod.block", 2, 0, Block.brickStone, SHIELD_GOT); - public static final Achievement MODERN_AGE = new Achievement(AchievementList.achievementList.size() + 1, "shieldmod.modern.age", 4, -1, Shields.steelShield, BLOCK); - public static final Achievement FLY_HIGH = new Achievement(AchievementList.achievementList.size() + 1, "shieldmod.fly.high", 3, 2, Block.wool, BLOCK); - public static final Achievement GOLD_RETAL = new Achievement(AchievementList.achievementList.size() + 1, "shieldmod.gold.retal", 1, 2, Shields.goldShield, BLOCK); - public static final Achievement COLORS = new Achievement(AchievementList.achievementList.size() + 1, "shieldmod.colorful.world", 5, 2, ItemDye.dye, FLY_HIGH); - - public static final Achievement INVINCIBLE = new Achievement(AchievementList.achievementList.size() + 1, "shieldmod.undying.shield", 6, -1, Block.bedrock, MODERN_AGE); - - public ShieldAchievements(){ - super("Better with defense", "achievements.page.defense"); - achievementList.add(SHIELD_GOT); - achievementList.add(BLOCK); - achievementList.add(MODERN_AGE); - achievementList.add(FLY_HIGH); - achievementList.add(GOLD_RETAL); - 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) { - - } -// @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; -// } -// } -} diff --git a/src/main/java/mizurin/shieldmod/ShieldMod.java b/src/main/java/mizurin/shieldmod/ShieldMod.java index 447ca79..1c3f0f5 100644 --- a/src/main/java/mizurin/shieldmod/ShieldMod.java +++ b/src/main/java/mizurin/shieldmod/ShieldMod.java @@ -1,29 +1,31 @@ package mizurin.shieldmod; +import com.mojang.nbt.CompoundTag; import mizurin.shieldmod.entities.*; +import mizurin.shieldmod.item.ArmorColored; import net.fabricmc.api.ModInitializer; import net.minecraft.client.render.colorizer.Colorizers; -import net.minecraft.client.render.entity.ArmoredZombieRenderer; import net.minecraft.client.render.entity.SnowballRenderer; -import net.minecraft.client.render.model.ModelZombie; +import net.minecraft.core.block.Block; import net.minecraft.core.crafting.LookupFuelFurnace; -import net.minecraft.core.entity.SpawnListEntry; +import net.minecraft.core.data.registry.recipe.SearchQuery; +import net.minecraft.core.data.registry.recipe.entry.RecipeEntryCraftingDynamic; import net.minecraft.core.enums.ArtType; -import net.minecraft.core.enums.EnumCreatureType; import net.minecraft.core.item.Item; +import net.minecraft.core.item.ItemDye; +import net.minecraft.core.item.ItemStack; import net.minecraft.core.net.entity.NetEntityHandler; -import net.minecraft.core.net.entity.entries.ArrowNetEntry; -import net.minecraft.core.world.biome.Biomes; +import net.minecraft.core.player.inventory.InventoryCrafting; +import net.minecraft.core.util.helper.Color; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import turniplabs.halplibe.helper.AchievementHelper; import turniplabs.halplibe.helper.EntityHelper; import turniplabs.halplibe.util.ClientStartEntrypoint; import turniplabs.halplibe.util.ConfigHandler; import turniplabs.halplibe.util.GameStartEntrypoint; import mizurin.shieldmod.item.Shields; -import java.util.Properties; +import java.util.*; public class ShieldMod implements ModInitializer, GameStartEntrypoint, ClientStartEntrypoint{ public static final String MOD_ID = "shieldmod"; @@ -32,22 +34,25 @@ public class ShieldMod implements ModInitializer, GameStartEntrypoint, ClientSta public static int itemID; public static int entityID; + public static boolean hurtSound; public static ArtType paintingSeal; public static ArtType paintingRice; static { Properties prop = new Properties(); prop.setProperty("starting_item_id", "21000"); prop.setProperty("starting_entity_id", "100"); + prop.setProperty("enable_hit_sounds", "false"); ConfigHandler config = new ConfigHandler(ShieldMod.MOD_ID, prop); itemID = config.getInt("starting_item_id"); entityID = config.getInt("starting_entity_id"); + hurtSound = config.getBoolean("enable_hit_sounds"); config.updateConfig(); } @Override public void onInitialize() { - LOGGER.info("Better with Defense has been initialized!"); + LOGGER.info("Rin's Fortress has been initialized."); new Shields().initializeItems(); Colorizers.registerColorizers(); } @@ -59,19 +64,18 @@ public void beforeGameStart() { EntityHelper.createEntity(EntityShield.class, entityID, "ammoShield", () -> new SnowballRenderer(Shields.ammotearShield)); EntityHelper.createEntity(EntityPB.class, ++entityID, "poisonBottle", () -> new SnowballRenderer(Shields.poisonBottle)); EntityHelper.createEntity(EntityRock.class, ++entityID, "pebbleShield", () -> new SnowballRenderer(Item.ammoPebble)); - //AchievementPage SHIELDACHIEVEMENTS; - //SHIELDACHIEVEMENTS = new ShieldAchievements(); - AchievementHelper.addPage(new ShieldAchievements()); + EntityHelper.createEntity(EntityFire.class, ++entityID, "entityFire", () -> new SnowballRenderer(Block.fire.asItem())); NetEntityHandler.registerNetworkEntry(new NetShieldEntry(), 8000); NetEntityHandler.registerNetworkEntry(new NetPotionEntry(), 8001); + NetEntityHandler.registerNetworkEntry(new NetFireEntry(), 8002); } @Override public void afterGameStart() { LookupFuelFurnace.instance.addFuelEntry(Shields.woodenShield.id, 600); new recipes().initializeRecipe(); - LOGGER.info("BWD initialized"); + LOGGER.info("RF initialized"); } @Override @@ -81,4 +85,7 @@ public void beforeClientStart() { @Override public void afterClientStart() { } + + + } diff --git a/src/main/java/mizurin/shieldmod/armorRecipeColor.java b/src/main/java/mizurin/shieldmod/armorRecipeColor.java deleted file mode 100644 index aaa452e..0000000 --- a/src/main/java/mizurin/shieldmod/armorRecipeColor.java +++ /dev/null @@ -1,142 +0,0 @@ -package mizurin.shieldmod; - -import com.mojang.nbt.CompoundTag; -import mizurin.shieldmod.item.ArmorColored; -import net.minecraft.core.data.registry.recipe.SearchQuery; -import net.minecraft.core.data.registry.recipe.entry.RecipeEntryCraftingDynamic; -import net.minecraft.core.item.Item; -import net.minecraft.core.item.ItemDye; -import net.minecraft.core.item.ItemStack; -import net.minecraft.core.player.inventory.InventoryCrafting; -import net.minecraft.core.util.helper.Color; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -//Special thanks to UselessBullets for being extremely awesome https://github.com/UselessBullets/Lunacy/tree/7.1 -public class armorRecipeColor extends RecipeEntryCraftingDynamic { - public static HashMap> dyeMap = new HashMap<>(); - private static final Map vanillaDye; - static { - vanillaDye = new HashMap<>(); - ItemDye.field_31002_bk[7] = 13027014; - ItemDye.field_31002_bk[15] = 16777215; - for (int color = 0; color < 16; color++) { - vanillaDye.put(color, new Color().setARGB(ItemDye.field_31002_bk[color])); - } - dyeMap.put(Item.dye, vanillaDye); - } - @Override - public ItemStack getCraftingResult(InventoryCrafting inventorycrafting) { - ItemStack armorStack = null; - List dyeStacks = new ArrayList<>(); - for (int x = 0; x < 3; ++x) { - for (int y = 0; y < 3; ++y) { - ItemStack stack = inventorycrafting.getItemStackAt(x, y); - if (stack == null) continue; - if (stack.getItem() instanceof ArmorColored) { - armorStack = stack; - } else if (dyeMap.containsKey(stack.getItem())) { - dyeStacks.add(stack); - } - } - } - if (armorStack != null && !dyeStacks.isEmpty()) { - ItemStack outStack = armorStack.copy(); - int r = -1; - int g = -1; - int b = -1; - int count = 0; - if (outStack.getData().containsKey("dyed_color")){ - CompoundTag armorColorTag = outStack.getData().getCompound("dyed_color"); - r = armorColorTag.getShort("red"); - g = armorColorTag.getShort("green"); - b = armorColorTag.getShort("blue"); - count += 1; - } - - for (ItemStack dyeStack : dyeStacks){ - Color color = dyeMap.getOrDefault(dyeStack.getItem(), vanillaDye).getOrDefault(dyeStack.getMetadata(), vanillaDye.get(0)); - if (r == -1 || g == -1 || b == -1){ - r = (int) (color.getRed() * 0.85f); - g = (int) (color.getGreen() * 0.85f); - b = (int) (color.getBlue() * 0.85f); - } else { - r += color.getRed(); - g += color.getGreen(); - b += color.getBlue(); - } - count += 1; - } - - if (count > 0){ - r /= count; - g /= count; - b /= count; - CompoundTag colorTag = new CompoundTag(); - colorTag.putShort("red", (short) r); - colorTag.putShort("green", (short) g); - colorTag.putShort("blue", (short) b); - outStack.getData().putCompound("dyed_color", colorTag); - } - - outStack.stackSize = 1; - return outStack; - } - return null; - } - - @Override - public int getRecipeSize() { - return 9; - } - - @Override - public boolean matches(InventoryCrafting crafting) { - ItemStack armorStack = null; - ItemStack dyeStack = null; - for (int x = 0; x < 3; ++x) { - for (int y = 0; y < 3; ++y) { - ItemStack stack = crafting.getItemStackAt(x, y); - if (stack == null) continue; - if (stack.getItem() instanceof ArmorColored) { - if (armorStack != null) { - return false; - } - armorStack = stack; - continue; - } - if (dyeMap.containsKey(stack.getItem())) { - dyeStack = stack; - continue; - } - return false; - } - } - return armorStack != null && dyeStack != null; - } - - @Override - public boolean matchesQuery(SearchQuery query) { - return false; - } - - @Override - public ItemStack[] onCraftResult(InventoryCrafting crafting) { - ItemStack[] returnStack = new ItemStack[9]; - for (int x = 0; x < 3; ++x) { - for (int y = 0; y < 3; ++y) { - ItemStack stack = crafting.getItemStackAt(x, y); - if (stack == null) continue; - --stack.stackSize; - if (stack.stackSize > 0) continue; - crafting.setSlotContentsAt(x, y, null); - } - } - - return returnStack; - } - -} diff --git a/src/main/java/mizurin/shieldmod/entities/EntityFire.java b/src/main/java/mizurin/shieldmod/entities/EntityFire.java new file mode 100644 index 0000000..74745bf --- /dev/null +++ b/src/main/java/mizurin/shieldmod/entities/EntityFire.java @@ -0,0 +1,72 @@ +package mizurin.shieldmod.entities; +import net.minecraft.core.HitResult; +import net.minecraft.core.entity.EntityLiving; +import net.minecraft.core.entity.player.EntityPlayer; +import net.minecraft.core.entity.projectile.EntityProjectile; +import net.minecraft.core.item.Item; +import net.minecraft.core.util.helper.DamageType; +import net.minecraft.core.util.phys.Vec3d; +import net.minecraft.core.world.World; + +public class EntityFire extends EntityProjectile { + public EntityFire(World world, EntityLiving entityliving){ + super(world, entityliving); + this.modelItem = Item.ammoFireball; + } + public EntityFire(World world, double d, double d1, double d2){ + super(world, d, d1, d2); + this.modelItem = Item.ammoFireball; + } + + public void init() { + this.damage = 6; + this.defaultGravity = 0.003F; + this.defaultProjectileSpeed = 0.15F; + } + + public void onHit(HitResult hitResult) { + if (hitResult.hitType == HitResult.HitType.ENTITY && hitResult.entity != this.owner) { + hitResult.entity.hurt(this.owner, this.damage, DamageType.FIRE); + + hitResult.entity.xd *= .33; + hitResult.entity.yd = 0.0; + hitResult.entity.zd *= .33; + + hitResult.entity.remainingFireTicks = 300; + if (hitResult.entity instanceof EntityPlayer){ + remove(); + } + } + + } + + @Override + protected void checkOnWater(boolean addVelocity) { + if (this.checkAndHandleWater(addVelocity)) { + this.remove(); + } + } + + @Override + public void tick() { + super.tick(); + + this.xd *= 7.5; + this.yd *= 7.5; + this.zd *= 7.5; + + if(this.tickCount > 8){ + this.remove(); + } + if(this.tickCount > 1) { + world.spawnParticle("flame", this.x, this.y, this.z, this.random.nextFloat()*.1, this.random.nextFloat()*.1, this.random.nextFloat()*.1, 0); + } + } + @Override + public HitResult getHitResult() { + Vec3d currentPos = Vec3d.createVector(this.x, this.y, this.z); + Vec3d nextPos = Vec3d.createVector(this.x + this.xd, this.y + this.yd - 0.25, this.z + this.zd); + HitResult hit = this.world.checkBlockCollisionBetweenPoints(currentPos, nextPos, false, true); + return hit; + } +} diff --git a/src/main/java/mizurin/shieldmod/entities/EntityPB.java b/src/main/java/mizurin/shieldmod/entities/EntityPB.java index 93f4e37..5449d76 100644 --- a/src/main/java/mizurin/shieldmod/entities/EntityPB.java +++ b/src/main/java/mizurin/shieldmod/entities/EntityPB.java @@ -1,17 +1,16 @@ package mizurin.shieldmod.entities; -import mizurin.shieldmod.item.IDazed; +import mizurin.shieldmod.interfaces.IDazed; import mizurin.shieldmod.item.Shields; import net.minecraft.core.HitResult; import net.minecraft.core.entity.EntityLiving; import net.minecraft.core.entity.projectile.EntityProjectile; -import net.minecraft.core.entity.projectile.EntitySnowball; import net.minecraft.core.item.Item; -import net.minecraft.core.item.ItemDye; import net.minecraft.core.util.helper.DamageType; import net.minecraft.core.util.phys.Vec3d; import net.minecraft.core.world.World; +//Entity Poison Bottle public class EntityPB extends EntityProjectile { public EntityPB(World world, EntityLiving entityliving) { super(world, entityliving); @@ -36,11 +35,13 @@ public void init() { public void onHit(HitResult hitResult) { if (hitResult.entity != null) { hitResult.entity.hurt(this.owner, this.damage, DamageType.COMBAT); - ((IDazed) hitResult.entity).better_with_defense$dazedHurt(); + ((IDazed) hitResult.entity).shieldmod$dazedHurt(); + //Applies my custom status effect from the IDazed interface. } if (this.modelItem != null) { for(int j = 0; j < 8; ++j) { this.world.spawnParticle("item", this.x, this.y, this.z, 0.0, 0.0, 0.0, Item.dye.id); + //This does a loop to spawn particles on impact. } } super.onHit(hitResult); @@ -51,6 +52,7 @@ public HitResult getHitResult() { Vec3d currentPos = Vec3d.createVector(this.x, this.y, this.z); Vec3d nextPos = Vec3d.createVector(this.x + this.xd, this.y + this.yd - 0.25, this.z + this.zd); HitResult hit = this.world.checkBlockCollisionBetweenPoints(currentPos, nextPos, false, true); + //I redid the getHitResult so that it can pass through non-solid blocks. (flag1: true). return hit; } } diff --git a/src/main/java/mizurin/shieldmod/entities/EntityRock.java b/src/main/java/mizurin/shieldmod/entities/EntityRock.java index 30afb1b..ab1105c 100644 --- a/src/main/java/mizurin/shieldmod/entities/EntityRock.java +++ b/src/main/java/mizurin/shieldmod/entities/EntityRock.java @@ -7,6 +7,7 @@ import net.minecraft.core.util.helper.DamageType; import net.minecraft.core.world.World; +//This is just the pebble used for the stone shield to prevent infinite pebbles, give impact particles, and to increase the base damage. public class EntityRock extends EntityPebble { public EntityRock(World world, EntityLiving entityliving) { super(world, entityliving); diff --git a/src/main/java/mizurin/shieldmod/entities/EntityShield.java b/src/main/java/mizurin/shieldmod/entities/EntityShield.java index 1b1601f..2267af6 100644 --- a/src/main/java/mizurin/shieldmod/entities/EntityShield.java +++ b/src/main/java/mizurin/shieldmod/entities/EntityShield.java @@ -1,13 +1,12 @@ package mizurin.shieldmod.entities; -import mizurin.shieldmod.IThrownItem; +import mizurin.shieldmod.interfaces.IThrownItem; import mizurin.shieldmod.item.Shields; 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.entity.projectile.EntityProjectile; import net.minecraft.core.item.Item; import net.minecraft.core.item.ItemStack; import net.minecraft.core.player.inventory.InventoryPlayer; @@ -21,7 +20,7 @@ import java.util.List; public class EntityShield extends EntityPebble { - private int fuse = 4; + private int bounce = 4; //Amount of bounces allowed. I set a limit as a failsafe as the entity can get stuck inside blocks and or fences. public EntityShield(World world) { super(world); this.modelItem = Shields.ammotearShield; @@ -44,6 +43,7 @@ public void init() { this.defaultGravity = 0.03F; this.defaultProjectileSpeed = 0.99F; } + //storeOrDropItem is a failsafe if the player's inventory is full. if not directly put the shield into the inventory. public void storeOrDropItem(EntityPlayer player, ItemStack stack){ if(stack == null || stack.stackSize <= 0){ return; @@ -56,7 +56,7 @@ public void storeOrDropItem(EntityPlayer player, ItemStack stack){ } public void tick () { this.baseTick(); - ++this.ticksInAir; + ++this.ticksInAir; //Used for damage calc float velocity; if (this.xRotO == 0.0F && this.yRotO == 0.0F) { velocity = MathHelper.sqrt_double(this.xd * this.xd + this.zd * this.zd); @@ -70,6 +70,7 @@ public void tick () { HitResult hit = this.world.checkBlockCollisionBetweenPoints(currentPos, nextPos, false, true); float otherAxisScale; float deceleration; + //This section is used to invert the velocity of the entity after it hits a tile. inverting it basically turns it around. if (hit != null && hit.hitType == HitResult.HitType.TILE) { float bounceAxisScale = 0.4F; otherAxisScale = 0.6F; @@ -100,12 +101,13 @@ public void tick () { this.xd *= (double) otherAxisScale; this.yd *= (double) otherAxisScale; } - --this.fuse; + --this.bounce; } List collidingEntities = this.world.getEntitiesWithinAABBExcludingEntity(this, this.bb.getOffsetBoundingBox(this.xd, this.yd, this.zd).expand(0.5, 0.5, 0.5)); - if ((collidingEntities == null || collidingEntities.size() <= 0) && this.fuse > 0 || collidingEntities != null && collidingEntities.size() == 1 && collidingEntities.get(0) == this.owner && this.tickCount < 4) { + if ((collidingEntities == null || collidingEntities.size() <= 0) && this.bounce > 0 || collidingEntities != null && collidingEntities.size() == 1 && collidingEntities.get(0) == this.owner && this.tickCount < 4) { + //This grabs a list of entities inside the bounding box this.x += this.xd; this.y += this.yd; this.z += this.zd; @@ -147,8 +149,10 @@ public void tick () { this.setPos(this.x, this.y, this.z); if (velocity == 0) { this.remove(); + //failsafe to prevent the entity from not removing itself if (this.owner != null) { storeOrDropItem((EntityPlayer) owner, ((IThrownItem) owner).getThrownItem()); + //returns the item to the player who threw it. } } } else { @@ -156,6 +160,7 @@ public void tick () { for (int j = 0; j < 8; ++j) { this.world.spawnParticle("item", this.x, this.y, this.z, 0.0, 0.0, 0.0, Item.ammoSnowball.id); this.world.spawnParticle("item", this.x, this.y, this.z, 0.0, 0.0, 0.0, this.modelItem.id); + //spawns particles on impact. } } damage = ticksInAir /3 + 3; @@ -164,17 +169,19 @@ public void tick () { } if(collidingEntities != null && collidingEntities.size() == 1) { if (collidingEntities.get(0) != null) { - collidingEntities.get(0).hurt(this, this.damage, DamageType.COMBAT); + collidingEntities.get(0).hurt((EntityPlayer)owner, this.damage, DamageType.COMBAT); } + //this is used to hurt the entities hit directly with the entity through the bounding box. } this.remove(); if (this.owner != null) { storeOrDropItem((EntityPlayer) owner, ((IThrownItem) owner).getThrownItem()); + //returns item to the player who threw it. } } } - + //this is all leftover code for the original throwing mechanic. will be added to a config in the future. public void onHit(HitResult hitResult) { damage = ticksInAir /3 + 3; if (damage > 14){ diff --git a/src/main/java/mizurin/shieldmod/entities/NetFireEntry.java b/src/main/java/mizurin/shieldmod/entities/NetFireEntry.java new file mode 100644 index 0000000..4c027eb --- /dev/null +++ b/src/main/java/mizurin/shieldmod/entities/NetFireEntry.java @@ -0,0 +1,59 @@ +package mizurin.shieldmod.entities; + +import net.minecraft.core.entity.Entity; +import net.minecraft.core.entity.EntityLiving; +import net.minecraft.core.net.entity.ITrackedEntry; +import net.minecraft.core.net.entity.IVehicleEntry; +import net.minecraft.core.net.packet.Packet23VehicleSpawn; +import net.minecraft.core.world.World; +import net.minecraft.server.entity.EntityTracker; +import net.minecraft.server.entity.EntityTrackerEntry; +import org.jetbrains.annotations.NotNull; + +//This is used to render custom entities on servers +//Entity Fire. +public class NetFireEntry + implements IVehicleEntry, + ITrackedEntry { + @Override + @NotNull + public Class getAppliedClass() { + return EntityFire.class; + } + + @Override + public int getTrackingDistance() { + return 1; + } + + @Override + public int getPacketDelay() { + return 20; + } + + @Override + public boolean sendMotionUpdates() { + return false; + } + + @Override + public void onEntityTracked(EntityTracker tracker, EntityTrackerEntry trackerEntry, EntityFire trackedObject) { + } + + @Override + public Entity getEntity(World world, double x, double y, double z, int metadata, boolean hasVelocity, double xd, double yd, double zd, Entity owner) { + if (owner instanceof EntityLiving) { + return new EntityFire(world, (EntityLiving) owner); + } else { + return new EntityFire(world, x, y, z); + } + } + + @Override + public Packet23VehicleSpawn getSpawnPacket(EntityTrackerEntry tracker, EntityFire trackedObject) { + System.out.println("FIRE"); + EntityLiving entityliving = trackedObject.owner; + return new Packet23VehicleSpawn(trackedObject, 0, entityliving == null ? -1 : entityliving.id, trackedObject.xd, trackedObject.yd, trackedObject.zd); + } +} + diff --git a/src/main/java/mizurin/shieldmod/entities/NetPotionEntry.java b/src/main/java/mizurin/shieldmod/entities/NetPotionEntry.java index 27a6418..edad88f 100644 --- a/src/main/java/mizurin/shieldmod/entities/NetPotionEntry.java +++ b/src/main/java/mizurin/shieldmod/entities/NetPotionEntry.java @@ -10,6 +10,8 @@ import net.minecraft.server.entity.EntityTrackerEntry; import org.jetbrains.annotations.NotNull; +//This is used to render custom entities on servers +//Entity Poison Bottle. public class NetPotionEntry implements IVehicleEntry, ITrackedEntry { diff --git a/src/main/java/mizurin/shieldmod/entities/NetShieldEntry.java b/src/main/java/mizurin/shieldmod/entities/NetShieldEntry.java index 8735219..64da131 100644 --- a/src/main/java/mizurin/shieldmod/entities/NetShieldEntry.java +++ b/src/main/java/mizurin/shieldmod/entities/NetShieldEntry.java @@ -10,6 +10,8 @@ import net.minecraft.server.entity.EntityTrackerEntry; import org.jetbrains.annotations.NotNull; +//This is used to render custom entities on servers +//Entity Thrown Shield. public class NetShieldEntry implements IVehicleEntry, ITrackedEntry { diff --git a/src/main/java/mizurin/shieldmod/interfaces/IColorable.java b/src/main/java/mizurin/shieldmod/interfaces/IColorable.java new file mode 100644 index 0000000..b89b78f --- /dev/null +++ b/src/main/java/mizurin/shieldmod/interfaces/IColorable.java @@ -0,0 +1,4 @@ +package mizurin.shieldmod.interfaces; + +public interface IColorable { +} diff --git a/src/main/java/mizurin/shieldmod/IColoredArmor.java b/src/main/java/mizurin/shieldmod/interfaces/IColoredArmor.java similarity index 61% rename from src/main/java/mizurin/shieldmod/IColoredArmor.java rename to src/main/java/mizurin/shieldmod/interfaces/IColoredArmor.java index 30b7377..e97d7ad 100644 --- a/src/main/java/mizurin/shieldmod/IColoredArmor.java +++ b/src/main/java/mizurin/shieldmod/interfaces/IColoredArmor.java @@ -1,9 +1,8 @@ -package mizurin.shieldmod; +package mizurin.shieldmod.interfaces; +import mizurin.shieldmod.ColoredArmorTexture; import net.minecraft.core.item.ItemStack; -import java.awt.*; - public interface IColoredArmor { ColoredArmorTexture[] getArmorTextures(ItemStack stack); } diff --git a/src/main/java/mizurin/shieldmod/interfaces/IDazed.java b/src/main/java/mizurin/shieldmod/interfaces/IDazed.java new file mode 100644 index 0000000..9012c87 --- /dev/null +++ b/src/main/java/mizurin/shieldmod/interfaces/IDazed.java @@ -0,0 +1,5 @@ +package mizurin.shieldmod.interfaces; + +public interface IDazed { + public void shieldmod$dazedHurt(); +} diff --git a/src/main/java/mizurin/shieldmod/interfaces/IShieldZombie.java b/src/main/java/mizurin/shieldmod/interfaces/IShieldZombie.java new file mode 100644 index 0000000..41476a6 --- /dev/null +++ b/src/main/java/mizurin/shieldmod/interfaces/IShieldZombie.java @@ -0,0 +1,6 @@ +package mizurin.shieldmod.interfaces; + +public interface IShieldZombie { + boolean shieldmod$isShieldZombie(); + boolean shieldmod$isSnowJack(); +} diff --git a/src/main/java/mizurin/shieldmod/IThrownItem.java b/src/main/java/mizurin/shieldmod/interfaces/IThrownItem.java similarity index 71% rename from src/main/java/mizurin/shieldmod/IThrownItem.java rename to src/main/java/mizurin/shieldmod/interfaces/IThrownItem.java index 24c4cf3..5c2390d 100644 --- a/src/main/java/mizurin/shieldmod/IThrownItem.java +++ b/src/main/java/mizurin/shieldmod/interfaces/IThrownItem.java @@ -1,6 +1,5 @@ -package mizurin.shieldmod; +package mizurin.shieldmod.interfaces; -import net.minecraft.core.item.Item; import net.minecraft.core.item.ItemStack; public interface IThrownItem { diff --git a/src/main/java/mizurin/shieldmod/interfaces/ParryInterface.java b/src/main/java/mizurin/shieldmod/interfaces/ParryInterface.java new file mode 100644 index 0000000..fea951b --- /dev/null +++ b/src/main/java/mizurin/shieldmod/interfaces/ParryInterface.java @@ -0,0 +1,18 @@ +package mizurin.shieldmod.interfaces; + +public interface ParryInterface { + public int shieldmod$getParryTicks(); + public void shieldmod$Parry(int parryTicks); + + public int shieldmod$getBlockTicks(); + public void shieldmod$Block(int blockTicks); + + public boolean shieldmod$getIsBlock(); + public void shieldmod$setIsBlock(boolean bool); + + public int shieldmod$getCounterTicks(); + public void shieldmod$Counter(int counterTicks); + + public int shieldmod$getFireTicks(); + public void shieldmod$Fire(int fireTicks); +} diff --git a/src/main/java/mizurin/shieldmod/item/ArmorColored.java b/src/main/java/mizurin/shieldmod/item/ArmorColored.java index b0cea22..3380180 100644 --- a/src/main/java/mizurin/shieldmod/item/ArmorColored.java +++ b/src/main/java/mizurin/shieldmod/item/ArmorColored.java @@ -2,8 +2,8 @@ import com.mojang.nbt.CompoundTag; import mizurin.shieldmod.ColoredArmorTexture; -import mizurin.shieldmod.IColorable; -import mizurin.shieldmod.IColoredArmor; +import mizurin.shieldmod.interfaces.IColorable; +import mizurin.shieldmod.interfaces.IColoredArmor; import mizurin.shieldmod.ShieldMod; import net.minecraft.core.item.ItemArmor; import net.minecraft.core.item.material.ArmorMaterial; diff --git a/src/main/java/mizurin/shieldmod/item/IDazed.java b/src/main/java/mizurin/shieldmod/item/IDazed.java deleted file mode 100644 index 88d02ec..0000000 --- a/src/main/java/mizurin/shieldmod/item/IDazed.java +++ /dev/null @@ -1,5 +0,0 @@ -package mizurin.shieldmod.item; - -public interface IDazed { - public void better_with_defense$dazedHurt(); -} diff --git a/src/main/java/mizurin/shieldmod/item/ItemModelShield.java b/src/main/java/mizurin/shieldmod/item/ItemModelShield.java index eba70a2..3711f23 100644 --- a/src/main/java/mizurin/shieldmod/item/ItemModelShield.java +++ b/src/main/java/mizurin/shieldmod/item/ItemModelShield.java @@ -1,8 +1,11 @@ package mizurin.shieldmod.item; import com.mojang.nbt.CompoundTag; +import mizurin.shieldmod.interfaces.ParryInterface; import net.minecraft.client.render.ItemRenderer; import net.minecraft.core.entity.Entity; +import net.minecraft.core.entity.monster.EntityMonster; +import net.minecraft.core.entity.player.EntityPlayer; import net.minecraft.core.item.Item; import net.minecraft.core.item.ItemStack; import org.lwjgl.opengl.GL11; @@ -13,6 +16,7 @@ public ItemModelShield(Item item, ColoredTextureEntry[] textureEntries) { super(item, textureEntries); } + //This determines the shield color when rendering. public static int shieldColor(ItemStack itemStack){ if (itemStack.getData().containsKey("dyed_color")){ CompoundTag colorTag = itemStack.getData().getCompound("dyed_color"); @@ -26,17 +30,33 @@ public static int shieldColor(ItemStack itemStack){ @Override public void heldTransformThirdPerson(ItemRenderer renderer, Entity entity, ItemStack itemstack) { - if (itemstack.getData().getBoolean("active")) { - final float scale2 = 0.625F; - GL11.glTranslatef(0.25F, -0.1875F, -0.1875F); - GL11.glScalef(scale2, scale2, scale2); - GL11.glRotatef(175, 0.0F, 0.0F, 1.0F); - GL11.glRotatef(145F, 0.0F, 1.0F, 0.0F); - GL11.glRotatef(30F, 1.0F, 0.0F, 0.0F); - GL11.glRotatef(-25F, 0.0F, 1.0F, 0.0F); - GL11.glRotatef(10F, 0.0F, 0.0F, 1.0F); - GL11.glTranslatef(0.10F, -0.80075F, 0.375F); - } else { + //The "active" data renders the shield when it is blocking. + if (entity instanceof EntityPlayer) { + if (((ParryInterface) entity).shieldmod$getIsBlock()) { + final float scale2 = 0.625F; + GL11.glTranslatef(0.25F, -0.1875F, -0.1875F); + GL11.glScalef(scale2, scale2, scale2); + GL11.glRotatef(175, 0.0F, 0.0F, 1.0F); + GL11.glRotatef(145F, 0.0F, 1.0F, 0.0F); + GL11.glRotatef(30F, 1.0F, 0.0F, 0.0F); + GL11.glRotatef(-25F, 0.0F, 1.0F, 0.0F); + GL11.glRotatef(10F, 0.0F, 0.0F, 1.0F); + GL11.glTranslatef(0.10F, -0.80075F, 0.375F); + } else { + //Renders the shield when not blocking. + //Doing this blind was hell. + final float scale = 0.625F; + GL11.glTranslatef(-0.25F, -0.1875F, -0.1F); + GL11.glScalef(scale, scale, scale); + GL11.glRotatef(35F, 0.0F, 1.0F, 0.0F); //y value + GL11.glRotatef(-5F, 1.0F, 0.0F, 0.0F); //x value + GL11.glRotatef(40F, 0.0F, 0.0F, 1.0F); //z value + GL11.glRotatef(-25F, 0.0F, 0.0F, 1.0F); //z value + GL11.glRotatef(30F, 1.0F, 0.0F, 0.0F); //x value + GL11.glTranslatef(0.31F, -0.20075F, -0.3F); + } + } + if(entity instanceof EntityMonster){ final float scale = 0.625F; GL11.glTranslatef(-0.25F, -0.1875F, -0.1F); GL11.glScalef(scale, scale, scale); @@ -51,14 +71,16 @@ public void heldTransformThirdPerson(ItemRenderer renderer, Entity entity, ItemS @Override public void heldTransformFirstPerson(ItemRenderer renderer, Entity entity, ItemStack itemStack) { - if (itemStack.getData().getBoolean("active")) { - GL11.glRotatef(77, 0.0F, 1.0F, 0.0F); - GL11.glRotatef(24, 0.0F, 0.0F, 1.0F); - GL11.glRotatef(10, 1.0F, 0.0F, 0.0F); - GL11.glTranslatef(0.3F, -0.2F, -0.7F); + //Renders the blocking state in first person. + if (((ParryInterface) entity).shieldmod$getIsBlock()) { + GL11.glRotatef(77, 0.0F, 1.0F, 0.0F); + GL11.glRotatef(24, 0.0F, 0.0F, 1.0F); + GL11.glRotatef(10, 1.0F, 0.0F, 0.0F); + GL11.glTranslatef(0.3F, -0.2F, -0.7F); - } else { + } else { + //Renders the idle state in first person. final float scale3 = 0.625F; GL11.glRotatef(74, 0.0F, 1.0F, 0.0F); GL11.glRotatef(23, 0.0F, 0.0F, 1.0F); diff --git a/src/main/java/mizurin/shieldmod/item/ItemPB.java b/src/main/java/mizurin/shieldmod/item/ItemPB.java index 8c962bd..fd68eb2 100644 --- a/src/main/java/mizurin/shieldmod/item/ItemPB.java +++ b/src/main/java/mizurin/shieldmod/item/ItemPB.java @@ -6,6 +6,7 @@ import net.minecraft.core.item.ItemStack; import net.minecraft.core.world.World; +//ItemPB is short for Item Poison Bottle. public class ItemPB extends Item { public ItemPB(String name, int id) { super(name, id); @@ -17,6 +18,7 @@ public ItemStack onUseItem(ItemStack itemstack, World world, EntityPlayer entity if (!world.isClientSide) { world.entityJoinedWorld(new EntityPB(world, entityplayer)); } + //For any devs looking at my code. This if statement (!world.isClientSide) is used for server compatibility, please use it when spawning items. return itemstack; } diff --git a/src/main/java/mizurin/shieldmod/item/LightShield.java b/src/main/java/mizurin/shieldmod/item/LightShield.java deleted file mode 100644 index 731cb89..0000000 --- a/src/main/java/mizurin/shieldmod/item/LightShield.java +++ /dev/null @@ -1,25 +0,0 @@ -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); - } - } - } -} diff --git a/src/main/java/mizurin/shieldmod/item/ParryInterface.java b/src/main/java/mizurin/shieldmod/item/ParryInterface.java deleted file mode 100644 index f411b53..0000000 --- a/src/main/java/mizurin/shieldmod/item/ParryInterface.java +++ /dev/null @@ -1,7 +0,0 @@ -package mizurin.shieldmod.item; -import net.minecraft.core.entity.Entity; - -public interface ParryInterface { - int shieldmod$getParryTicks(); - void shieldmod$Parry(int parryTicks); -} diff --git a/src/main/java/mizurin/shieldmod/item/ParryShield.java b/src/main/java/mizurin/shieldmod/item/ParryShield.java index df124e7..fe7d521 100644 --- a/src/main/java/mizurin/shieldmod/item/ParryShield.java +++ b/src/main/java/mizurin/shieldmod/item/ParryShield.java @@ -1,22 +1,12 @@ package mizurin.shieldmod.item; -import mizurin.shieldmod.entities.EntityPB; -import mizurin.shieldmod.entities.EntityShield; -import net.minecraft.core.entity.monster.EntityMonster; +import mizurin.shieldmod.interfaces.ParryInterface; import net.minecraft.core.entity.player.EntityPlayer; import net.minecraft.core.item.ItemStack; import net.minecraft.core.item.material.ToolMaterial; -import net.minecraft.core.util.phys.AABB; import net.minecraft.core.world.World; -import net.minecraft.core.entity.Entity; -import net.minecraft.core.entity.projectile.*; -import net.minecraft.core.util.helper.DamageType; - -import java.util.List; public class ParryShield extends ThrowShield { - public int parryDelay = 0; - public EntityPlayer player; public ParryShield(String name, int id, ToolMaterial toolMaterial) { super(name, id, toolMaterial); @@ -24,143 +14,19 @@ public ParryShield(String name, int id, ToolMaterial toolMaterial) { @Override public ItemStack onUseItem(ItemStack itemstack, World world, EntityPlayer entityPlayer) { - itemstack.getData().putBoolean("active", true); - itemstack.getData().putInt("ticks", ticksToAdd); + ((ParryInterface)entityPlayer).shieldmod$setIsBlock(true); + ((ParryInterface)entityPlayer).shieldmod$Block(5); onBlock(itemstack, world, entityPlayer); return itemstack; } + //onBlock function is used so players can sneak right click as an action instead of assigning a new key. @Override public void onBlock(ItemStack itemstack, World world, EntityPlayer entityplayer) { - if (entityplayer.isSneaking()){ - if (this.parryDelay == 0) { - this.parryDelay = 20; - } - - this.player = entityplayer; - - } - } - - public void parryHitbox(World world, EntityPlayer player) { - double bound = 1.75; - AABB aabb1 = new AABB( - player.x - bound, - player.y + player.getHeadHeight() - bound, - player.z - bound, - player.x + bound, - player.y + player.getHeadHeight() + bound, - player.z + bound - ); - List projectileList = player.world.getEntitiesWithinAABB(EntityProjectile.class, aabb1 ); - for (Entity entity : projectileList) { - world.spawnParticle("largesmoke", entity.x, entity.y, entity.z, 0.0, 0.0, 0.0, 0); - - if(entity instanceof EntityArrow) { - double oldArrowX = entity.x; - double oldArrowY = entity.y; - double oldArrowZ = entity.z; - - if (!((EntityArrow) entity).isGrounded()) { - entity.remove(); - EntityArrow newArrow = new EntityArrow(world, player, true, ((EntityArrow) entity).getArrowType()); - if (!world.isClientSide) { - world.entityJoinedWorld(newArrow); - newArrow.setPos(oldArrowX, oldArrowY, oldArrowZ); - world.playSoundAtEntity(player, player, "mob.ghast.fireball", 0.66f, 1.0f); - } - } - } - - if(entity instanceof EntityFireball) { - entity.hurt(player, 1, DamageType.COMBAT); - world.playSoundAtEntity(player, player, "mob.ghast.fireball", 0.66f, 1.0f); - } - - if(entity instanceof EntityCannonball) { - - double oldCBX = entity.x; - double oldCBY = entity.y; - double oldCBZ = entity.z; - - entity.remove(); - EntityCannonball newCB = new EntityCannonball(world, player); - if (!world.isClientSide) { - world.entityJoinedWorld(newCB); - newCB.setPos(oldCBX, oldCBY, oldCBZ); - double pushX = player.getLookAngle().xCoord; - double pushY = player.getLookAngle().yCoord; - double pushZ = player.getLookAngle().zCoord; - newCB.push(pushX * 1.2, pushY * 1.2, pushZ * 1.2); - world.playSoundAtEntity(player, player, "mob.ghast.fireball", 0.66f, 1.0f); - } - } - if(entity instanceof EntitySnowball){ - double oldSBX = entity.x; - double oldSBY = entity.y; - double oldSBZ = entity.z; - - entity.remove(); - EntitySnowball newSB = new EntitySnowball(world, player); - if (!world.isClientSide) { - world.entityJoinedWorld(newSB); - world.playSoundAtEntity(player, player, "mob.ghast.fireball", 0.66f, 1.0f); - } - } - if(entity instanceof EntityShield){ - double oldSBX = entity.x; - double oldSBY = entity.y; - double oldSBZ = entity.z; - - entity.remove(); - EntityShield newTS = new EntityShield(world, player); - if (!world.isClientSide) { - world.entityJoinedWorld(newTS); - world.playSoundAtEntity(player, player, "mob.ghast.fireball", 0.66f, 1.0f); - } - } - if(entity instanceof EntityPB){ - double oldSBX = entity.x; - double oldSBY = entity.y; - double oldSBZ = entity.z; - - entity.remove(); - EntityPB newPS = new EntityPB(world, player); - if (!world.isClientSide) { - world.entityJoinedWorld(newPS); - world.playSoundAtEntity(player, player, "mob.ghast.fireball", 0.66f, 1.0f); - } - } - - } - - player.swingItem(); - world.playSoundAtEntity(player, player, "mob.ghast.fireball", 0.3f, 1.0f); -} - @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) { - itemstack.getData().putInt("ticks", ticks - 1); - } else { - itemstack.getData().putBoolean("active", false); - } - } - if (this.parryDelay > 0) { - this.parryDelay--; - } - - if (this.parryDelay >= 10 && this.parryDelay <= 16) { - ((ParryInterface) player).shieldmod$Parry(1); - } + if (entityplayer.isSneaking()) { + ((ParryInterface) entityplayer).shieldmod$Parry(20); - if (parryDelay == 18) { - this.parryHitbox(world, this.player); } } diff --git a/src/main/java/mizurin/shieldmod/item/ShieldColored.java b/src/main/java/mizurin/shieldmod/item/ShieldColored.java index 159108b..637f6f1 100644 --- a/src/main/java/mizurin/shieldmod/item/ShieldColored.java +++ b/src/main/java/mizurin/shieldmod/item/ShieldColored.java @@ -1,29 +1,12 @@ package mizurin.shieldmod.item; -import mizurin.shieldmod.IColorable; -import net.minecraft.core.entity.Entity; -import net.minecraft.core.world.World; -import net.minecraft.core.item.ItemStack; +import mizurin.shieldmod.interfaces.IColorable; import net.minecraft.core.item.material.ToolMaterial; +//Colored Shield, same as Light Shield for movement speed but implements IColorable. public class ShieldColored extends ShieldItem implements IColorable { public ShieldColored(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); - } - } - } - } diff --git a/src/main/java/mizurin/shieldmod/item/ShieldItem.java b/src/main/java/mizurin/shieldmod/item/ShieldItem.java index f21f086..751ba46 100644 --- a/src/main/java/mizurin/shieldmod/item/ShieldItem.java +++ b/src/main/java/mizurin/shieldmod/item/ShieldItem.java @@ -1,18 +1,18 @@ package mizurin.shieldmod.item; +import mizurin.shieldmod.interfaces.IDazed; +import mizurin.shieldmod.interfaces.ParryInterface; import net.minecraft.core.entity.Entity; import net.minecraft.core.entity.EntityLiving; import net.minecraft.core.entity.player.EntityPlayer; import net.minecraft.core.item.ItemStack; import net.minecraft.core.item.material.ToolMaterial; import net.minecraft.core.item.tool.ItemToolSword; -import net.minecraft.core.util.helper.DamageType; import net.minecraft.core.world.World; public class ShieldItem extends ItemToolSword { public ToolMaterial tool; public int weaponDamage; - private static final int ticksToAdd = 5; public ShieldItem(String name, int id, ToolMaterial toolMaterial){ @@ -25,6 +25,7 @@ public ShieldItem(String name, int id, ToolMaterial toolMaterial){ } + //Applies a knockback effect for all shields, bonus knockback to Leather Shields, and sets hitEntities on fire when hit by a Steel Shield. @Override public boolean hitEntity(ItemStack itemstack, EntityLiving target, EntityLiving player) { if(itemstack.getItem() == Shields.leatherShield){ @@ -33,11 +34,8 @@ public boolean hitEntity(ItemStack itemstack, EntityLiving target, EntityLiving } else { target.knockBack(player, 3, player.x - target.x, player.z - target.z); } - if(itemstack.getItem() == Shields.steelShield){ - target.fireHurt(); - } if(itemstack.getItem() == Shields.goldShield){ - ((IDazed)target).better_with_defense$dazedHurt(); + ((IDazed)target).shieldmod$dazedHurt(); target.push((target.x - player.x)/20, 0, (target.z - player.z)/20); } itemstack.damageItem(1, player); @@ -49,26 +47,15 @@ public int getDamageVsEntity(Entity entity) { } + //Activates ticks that determine if the player is blocking. @Override public ItemStack onUseItem(ItemStack itemstack, World world, EntityPlayer entityplayer) { - itemstack.getData().putBoolean("active", true); - itemstack.getData().putInt("ticks",ticksToAdd); + //Set to true then add the ticks to the data. + ((ParryInterface)entityplayer).shieldmod$setIsBlock(true); + ((ParryInterface)entityplayer).shieldmod$Block(5); + return itemstack; } - @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) { - itemstack.getData().putInt("ticks", ticks - 1); - } else { - itemstack.getData().putBoolean("active", false); - } - } - } } diff --git a/src/main/java/mizurin/shieldmod/item/ShieldMaterials.java b/src/main/java/mizurin/shieldmod/item/ShieldMaterials.java index 6ac584c..c7cce47 100644 --- a/src/main/java/mizurin/shieldmod/item/ShieldMaterials.java +++ b/src/main/java/mizurin/shieldmod/item/ShieldMaterials.java @@ -11,6 +11,7 @@ public ToolMaterial setGuard(float guard){ this.guard = guard; return this; } + //ToolMaterials for shields. Haste efficiency is overridden for the shield's block percent. ex: 0.85 is a 15% damage reduction. public static final ToolMaterial TOOL_LEATHER = new ToolMaterial().setDurability(64).setDamage(-2).setEfficiency(2.0f, 0.85f); public static final ToolMaterial TOOL_WOOD = new ToolMaterial().setDurability(96).setDamage(-1).setEfficiency(2.0f, 0.80f); public static final ToolMaterial TOOL_STONE = new ToolMaterial().setDurability(128).setDamage(0).setEfficiency(2.0f, 0.70f); diff --git a/src/main/java/mizurin/shieldmod/item/Shields.java b/src/main/java/mizurin/shieldmod/item/Shields.java index 94011fd..6ac7410 100644 --- a/src/main/java/mizurin/shieldmod/item/Shields.java +++ b/src/main/java/mizurin/shieldmod/item/Shields.java @@ -1,12 +1,12 @@ package mizurin.shieldmod.item; -import net.minecraft.client.render.item.model.ItemModelStandard; import net.minecraft.client.render.stitcher.TextureRegistry; import net.minecraft.core.item.Item; +import net.minecraft.core.item.ItemArmor; import net.minecraft.core.item.ItemSoup; import net.minecraft.core.item.tag.ItemTags; -import net.minecraft.core.util.helper.DamageType; import org.slf4j.LoggerFactory; +import turniplabs.halplibe.helper.ArmorHelper; import turniplabs.halplibe.helper.ItemBuilder; import mizurin.shieldmod.ShieldMod; import org.slf4j.Logger; @@ -33,10 +33,15 @@ public class Shields { public static Item armorLeatherLeg; public static Item armorLeatherBoot; public static Item poisonBottle; + public static Item rockyHelmet; + public static Item regenAmulet; + public static ArmorMaterial rockyArmor = ArmorHelper.createArmorMaterial(MOD_ID, "armor_stone", 256, 30f, 30f, 30f, 30f); + public static ArmorMaterial heartAmulet = ArmorHelper.createArmorMaterial(MOD_ID, "armor_stone", 384, 5f, 5f, 5f, 5f); @SuppressWarnings("unchecked") + //Initialize items at main. public void initializeItems(){ woodenShield = new ItemBuilder(MOD_ID) .setStackSize(1) @@ -44,9 +49,10 @@ public void initializeItems(){ { new ItemModelColored.ColoredTextureEntry(TextureRegistry.getTexture("shieldmod:item/wooden_shield"), (s) -> -1) }).setFull3D()) - .build(new LightShield("wooden.shield", ++itemID, ShieldMaterials.TOOL_WOOD)) + .build(new ShieldItem("wooden.shield", ++itemID, ShieldMaterials.TOOL_WOOD)) .withTags(ItemTags.PREVENT_CREATIVE_MINING); + stoneShield = new ItemBuilder(MOD_ID) .setStackSize(1) .setItemModel(item -> new ItemModelShield(item, new ItemModelColored.ColoredTextureEntry[] @@ -56,6 +62,7 @@ public void initializeItems(){ .build(new ShieldItem("stone.shield", ++itemID, ShieldMaterials.TOOL_STONE)) .withTags(ItemTags.PREVENT_CREATIVE_MINING); + ironShield = new ItemBuilder(MOD_ID) .setStackSize(1) .setItemModel(item -> new ItemModelShield(item, new ItemModelColored.ColoredTextureEntry[] @@ -65,6 +72,7 @@ public void initializeItems(){ .build(new ShieldItem("iron.shield", ++itemID, ShieldMaterials.TOOL_IRON)) .withTags(ItemTags.PREVENT_CREATIVE_MINING); + goldShield = new ItemBuilder(MOD_ID) .setStackSize(1) .setItemModel(item -> new ItemModelShield(item, new ItemModelColored.ColoredTextureEntry[] @@ -74,6 +82,7 @@ public void initializeItems(){ .build(new ParryShield("gold.shield", ++itemID, ShieldMaterials.TOOL_GOLD)) .withTags(ItemTags.PREVENT_CREATIVE_MINING); + diamondShield = new ItemBuilder(MOD_ID) .setStackSize(1) .setItemModel(item -> new ItemModelShield(item, new ItemModelColored.ColoredTextureEntry[] @@ -83,15 +92,17 @@ public void initializeItems(){ .build(new TreasureShield("diamond.shield", ++itemID, ShieldMaterials.TOOL_DIAMOND)) .withTags(ItemTags.PREVENT_CREATIVE_MINING); + steelShield = new ItemBuilder(MOD_ID) .setStackSize(1) .setItemModel(item -> new ItemModelShield(item, new ItemModelColored.ColoredTextureEntry[] { new ItemModelColored.ColoredTextureEntry(TextureRegistry.getTexture("shieldmod:item/steel_shield"), (s) -> -1) }).setFull3D()) - .build(new ShieldItem("steel.shield", ++itemID, ShieldMaterials.TOOL_STEEL)) + .build(new SteelShield("steel.shield", ++itemID, ShieldMaterials.TOOL_STEEL)) .withTags(ItemTags.PREVENT_CREATIVE_MINING); + leatherShield = new ItemBuilder(MOD_ID) .setStackSize(1) .setItemModel(item -> new ItemModelShield(item, new ItemModelColored.ColoredTextureEntry[] @@ -102,6 +113,7 @@ public void initializeItems(){ .build(new ShieldColored("leather.shield", ++itemID, ShieldMaterials.TOOL_LEATHER)) .withTags(ItemTags.PREVENT_CREATIVE_MINING); + tearShield = new ItemBuilder(MOD_ID) .setItemModel(item -> new ItemModelShield(item, new ItemModelColored.ColoredTextureEntry[] { @@ -120,34 +132,50 @@ public void initializeItems(){ .build(new Item("tear.shield.ammo", ++itemID)) .withTags(ItemTags.NOT_IN_CREATIVE_MENU); + pumpkinStew = new ItemBuilder(MOD_ID) .setIcon("shieldmod:item/pumpkin_stew") .build(new ItemSoup("food.stew.pumpkin", ++itemID, 16, 30)); + armorLeatherHelmet = new ItemBuilder(MOD_ID).setItemModel(item -> new ItemModelColored(item, new ItemModelColored.ColoredTextureEntry[] { new ItemModelColored.ColoredTextureEntry(TextureRegistry.getTexture(MOD_ID + ":item/leather_helmet"), ItemModelShield::shieldColor) })) .build(new ArmorColored("armor.helmet.leather", 16426, ArmorMaterial.LEATHER, 0)); + armorLeatherChest = new ItemBuilder(MOD_ID).setItemModel(item -> new ItemModelColored(item, new ItemModelColored.ColoredTextureEntry[] { new ItemModelColored.ColoredTextureEntry(TextureRegistry.getTexture(MOD_ID + ":item/leather_chestplate"), ItemModelShield::shieldColor) })) .build(new ArmorColored("armor.chestplate.leather", 16427, ArmorMaterial.LEATHER, 1)); + armorLeatherLeg = new ItemBuilder(MOD_ID).setItemModel(item -> new ItemModelColored(item, new ItemModelColored.ColoredTextureEntry[] { new ItemModelColored.ColoredTextureEntry(TextureRegistry.getTexture(MOD_ID + ":item/leather_leggings"), ItemModelShield::shieldColor) })) .build(new ArmorColored("armor.leggings.leather", 16428, ArmorMaterial.LEATHER, 2)); + armorLeatherBoot = new ItemBuilder(MOD_ID).setItemModel(item -> new ItemModelColored(item, new ItemModelColored.ColoredTextureEntry[] { new ItemModelColored.ColoredTextureEntry(TextureRegistry.getTexture(MOD_ID + ":item/leather_boots"), ItemModelShield::shieldColor) })) .build(new ArmorColored("armor.boots.leather", 16429, ArmorMaterial.LEATHER, 3)); + poisonBottle = new ItemBuilder(MOD_ID).setStackSize(16).setIcon(String.format("%s:item/poison_bottle",MOD_ID)).build(new ItemPB("poison.bottle", ++itemID)); + + + rockyHelmet = new ItemBuilder(MOD_ID) + .setIcon("shieldmod:item/rocky_helmet") + .build(new ItemArmor("helmet.rock", ++itemID, rockyArmor, 0)); + + + regenAmulet = new ItemBuilder(MOD_ID) + .setIcon("shieldmod:item/regen_amulet") + .build(new ItemArmor("amulet.heart", ++itemID, heartAmulet, 1)); } } diff --git a/src/main/java/mizurin/shieldmod/item/SteelShield.java b/src/main/java/mizurin/shieldmod/item/SteelShield.java new file mode 100644 index 0000000..b6057dc --- /dev/null +++ b/src/main/java/mizurin/shieldmod/item/SteelShield.java @@ -0,0 +1,45 @@ +package mizurin.shieldmod.item; + +import mizurin.shieldmod.entities.EntityFire; +import mizurin.shieldmod.interfaces.ParryInterface; +import net.minecraft.core.entity.player.EntityPlayer; +import net.minecraft.core.item.Item; +import net.minecraft.core.item.ItemStack; +import net.minecraft.core.item.material.ToolMaterial; +import net.minecraft.core.util.phys.Vec3d; +import net.minecraft.core.world.World; + + + +public class SteelShield extends ThrowShield{ + public SteelShield(String name, int id, ToolMaterial toolMaterial) { + super(name, id, toolMaterial); + } + + //currently working on fire. + @Override + public void onBlock(ItemStack itemstack, World world, EntityPlayer entityplayer) { + if (entityplayer.isSneaking() && ((ParryInterface)entityplayer).shieldmod$getFireTicks() == 0){ + if(entityplayer.inventory.consumeInventoryItem(Item.flint.id)){ + itemstack.damageItem(4, entityplayer); + for (int i = 4; i != 0; i--) { + Vec3d plylook = entityplayer.getLookAngle(); + EntityFire flame = new EntityFire(world, entityplayer); + if (!world.isClientSide) { + world.entityJoinedWorld(flame); + + flame.setHeading(flame.xd, flame.yd, flame.zd, .55f, 10); + double newX = flame.x + plylook.xCoord * .5; + double newY = flame.y + plylook.yCoord * .5; + double newZ = flame.z + plylook.zCoord * .5; + } + } + world.playSoundAtEntity(entityplayer, entityplayer, "fire.ignite", 3.6F, 1.5F); + + ((ParryInterface)entityplayer).shieldmod$Fire(10); + + } + } + + } +} diff --git a/src/main/java/mizurin/shieldmod/item/ThrowShield.java b/src/main/java/mizurin/shieldmod/item/ThrowShield.java index c7d0f76..ce74d1c 100644 --- a/src/main/java/mizurin/shieldmod/item/ThrowShield.java +++ b/src/main/java/mizurin/shieldmod/item/ThrowShield.java @@ -1,14 +1,14 @@ package mizurin.shieldmod.item; -import mizurin.shieldmod.IThrownItem; +import mizurin.shieldmod.interfaces.IThrownItem; import mizurin.shieldmod.entities.EntityShield; +import mizurin.shieldmod.interfaces.ParryInterface; 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) { @@ -21,23 +21,26 @@ public ThrowShield(String name, int id, ToolMaterial toolMaterial) { } @Override public ItemStack onUseItem(ItemStack itemstack, World world, EntityPlayer entityplayer) { - itemstack.getData().putBoolean("active", true); - itemstack.getData().putInt("ticks", ticksToAdd); + ((ParryInterface)entityplayer).shieldmod$setIsBlock(true); + ((ParryInterface)entityplayer).shieldmod$Block(5); onBlock(itemstack, world, entityplayer); return itemstack; } - + //onBlock used so the player can shift right click to throw the shield. public void onBlock(ItemStack itemstack, World world, EntityPlayer entityplayer){ if (entityplayer.isSneaking()){ ((IThrownItem)entityplayer).setThrownItem(itemstack); + //Sets the shield to the player's thrown item. entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem,null); + //Sets the shield to null to hide it and act as a cooldown. world.playSoundAtEntity(null, entityplayer, "mob.ghast.fireball", 0.3F, 1.0F / (itemRand.nextFloat() * 0.4F + 0.8F)); if (!world.isClientSide) { + //For any devs looking at my code. This if statement is used for server compatibility, please use it when spawning items. world.entityJoinedWorld(new EntityShield(world, entityplayer)); itemstack.damageItem(4, entityplayer); - itemstack.getData().putBoolean("active", false); } + ((ParryInterface)entityplayer).shieldmod$setIsBlock(false); } } diff --git a/src/main/java/mizurin/shieldmod/item/TreasureShield.java b/src/main/java/mizurin/shieldmod/item/TreasureShield.java index 484b7dd..214167a 100644 --- a/src/main/java/mizurin/shieldmod/item/TreasureShield.java +++ b/src/main/java/mizurin/shieldmod/item/TreasureShield.java @@ -1,12 +1,12 @@ package mizurin.shieldmod.item; -import net.minecraft.core.entity.Entity; +import mizurin.shieldmod.interfaces.ParryInterface; import net.minecraft.core.entity.EntityLiving; import net.minecraft.core.item.ItemStack; import net.minecraft.core.item.material.ToolMaterial; import net.minecraft.core.util.helper.DamageType; -import net.minecraft.core.world.World; +//For the Diamond Shield. public class TreasureShield extends ShieldItem{ public TreasureShield(String name, int id, ToolMaterial toolMaterial) { super(name, id, toolMaterial); @@ -15,35 +15,17 @@ public TreasureShield(String name, int id, ToolMaterial toolMaterial) { this.tool = toolMaterial; this.weaponDamage = 4 + toolMaterial.getDamage(); } - @Override - public void inventoryTick(ItemStack itemstack, World world, Entity entity, int i, boolean flag) { - if(itemstack.getData().getBoolean("active")){ - entity.xd *= 0.20D; - entity.zd *= 0.20D; - int ticks = itemstack.getData().getInteger("ticks"); - - if (ticks > 0){ - itemstack.getData().putInt("ticks", ticks - 1); - } else { - itemstack.getData().putBoolean("active", false); - } - } - int ticksB = itemstack.getData().getInteger("ticksB"); - - if (ticksB > 0){ - itemstack.getData().putInt("ticksB", ticksB - 1); - } - } + //If the ticks(Blocked) are active, then the player has bonus damage and knockback for the shield. @Override public boolean hitEntity(ItemStack itemstack, EntityLiving target, EntityLiving player) { - int ticksB = itemstack.getData().getInteger("ticksB"); - if(ticksB > 0){ + if(((ParryInterface)player).shieldmod$getCounterTicks() > 0){ target.knockBack(player, 1, (player.x - target.x), (player.z - target.z )); target.push((target.x - player.x)/7, 1, (target.z - player.z)/7); target.push(target.xd, target.yd, target.zd); target.hurt(player, 14, DamageType.COMBAT); - itemstack.getData().putInt("ticksB", 0); + ((ParryInterface)player).shieldmod$Counter(0); + //After hitting an entity, set the ticksB to 0, ending the countdown immediately. } if(itemstack.getItem() == Shields.leatherShield){ diff --git a/src/main/java/mizurin/shieldmod/mixins/BipedRendererMixin.java b/src/main/java/mizurin/shieldmod/mixins/BipedRendererMixin.java index c2cb239..378d03a 100644 --- a/src/main/java/mizurin/shieldmod/mixins/BipedRendererMixin.java +++ b/src/main/java/mizurin/shieldmod/mixins/BipedRendererMixin.java @@ -1,8 +1,6 @@ package mizurin.shieldmod.mixins; -import mizurin.shieldmod.IShieldZombie; -import net.minecraft.client.Minecraft; -import net.minecraft.client.render.LightmapHelper; +import mizurin.shieldmod.interfaces.IShieldZombie; import net.minecraft.client.render.block.model.BlockModel; import net.minecraft.client.render.block.model.BlockModelDispatcher; import net.minecraft.client.render.entity.LivingRenderer; @@ -10,7 +8,6 @@ import net.minecraft.client.render.item.model.ItemModelDispatcher; import net.minecraft.client.render.model.ModelBiped; import net.minecraft.client.render.tessellator.Tessellator; -import net.minecraft.core.Global; import net.minecraft.core.block.Block; import net.minecraft.core.entity.EntityLiving; import net.minecraft.core.item.ItemStack; @@ -21,6 +18,7 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +//Mixin to render carved pumpkins on snowmen. @Mixin(value = MobRenderer.class, remap = false) public class BipedRendererMixin extends LivingRenderer { @@ -33,7 +31,7 @@ public BipedRendererMixin(ModelBiped model, float shadowSize) { @Inject(method = "renderEquippedItems", at = @At("HEAD")) public void inject(T entity, float f, CallbackInfo ci){ - if (entity instanceof IShieldZombie && ((IShieldZombie)entity).better_with_defense$isSnowJack()) { + if (entity instanceof IShieldZombie && ((IShieldZombie)entity).shieldmod$isSnowJack()) { ItemStack itemstack = Block.pumpkinCarvedIdle.getDefaultStack(); if (itemstack != null && itemstack.getItem().id < Block.blocksList.length) { diff --git a/src/main/java/mizurin/shieldmod/mixins/BlockFarmlandMixin.java b/src/main/java/mizurin/shieldmod/mixins/BlockFarmlandMixin.java index d94d40f..e9fd91a 100644 --- a/src/main/java/mizurin/shieldmod/mixins/BlockFarmlandMixin.java +++ b/src/main/java/mizurin/shieldmod/mixins/BlockFarmlandMixin.java @@ -9,6 +9,7 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Redirect; +//Mixin to prevent crop trampling from the custom leather boots. @Mixin(value = BlockFarmland.class, remap = false) public class BlockFarmlandMixin { @Redirect(method = "onEntityWalking(Lnet/minecraft/core/world/World;IIILnet/minecraft/core/entity/Entity;)V", diff --git a/src/main/java/mizurin/shieldmod/mixins/DazedMixin.java b/src/main/java/mizurin/shieldmod/mixins/DazedMixin.java index 194b853..9184422 100644 --- a/src/main/java/mizurin/shieldmod/mixins/DazedMixin.java +++ b/src/main/java/mizurin/shieldmod/mixins/DazedMixin.java @@ -1,6 +1,6 @@ package mizurin.shieldmod.mixins; -import mizurin.shieldmod.item.IDazed; +import mizurin.shieldmod.interfaces.IDazed; import net.minecraft.core.entity.Entity; import net.minecraft.core.util.helper.DamageType; import org.spongepowered.asm.mixin.Mixin; @@ -29,6 +29,7 @@ public boolean hurt(Entity attacker, int damage, DamageType type) { @Unique public int remainingDazedTicks; + //Mirrors the fire status effect but cannot be put out and slows the entity. @Inject(method = "Lnet/minecraft/core/entity/Entity;baseTick()V", at = @At("HEAD")) public void inject(CallbackInfo callbackInfo) { if (this.remainingDazedTicks > 0) { @@ -42,10 +43,13 @@ public void inject(CallbackInfo callbackInfo) { --this.remainingDazedTicks; --this.remainingDazedTicks; --this.remainingDazedTicks; + //the ticks are put in a way to deal small damage and slow while also being offset by fire status + //having it mimic the fire status countdown causes them to overlap and only deal damage once due to invulnerability frames. } + } @Override - public void better_with_defense$dazedHurt(){ + public void shieldmod$dazedHurt(){ this.hurt((Entity) null, 1, DamageType.COMBAT); this.remainingDazedTicks = 300; } diff --git a/src/main/java/mizurin/shieldmod/mixins/EntityLivingMixin.java b/src/main/java/mizurin/shieldmod/mixins/EntityLivingMixin.java new file mode 100644 index 0000000..f4fefd9 --- /dev/null +++ b/src/main/java/mizurin/shieldmod/mixins/EntityLivingMixin.java @@ -0,0 +1,52 @@ +package mizurin.shieldmod.mixins; + +import mizurin.shieldmod.item.Shields; +import net.minecraft.core.entity.Entity; +import net.minecraft.core.entity.EntityLiving; +import net.minecraft.core.entity.player.EntityPlayer; +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.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +import static mizurin.shieldmod.ShieldMod.hurtSound; + +@Mixin(value = EntityLiving.class, remap = false) +public class EntityLivingMixin { + @Inject( + method = "onDeath(Lnet/minecraft/core/entity/Entity;)V", + at = @At(value = "TAIL")) + public void healthSteal(Entity entityKilledBy, CallbackInfo ci) { + + if(entityKilledBy instanceof EntityPlayer){ + ItemStack helmet_item = ((EntityPlayer)entityKilledBy).inventory.armorItemInSlot(2); + boolean AR = false; + if ((helmet_item != null && helmet_item.getItem().equals(Shields.regenAmulet))){ + AR = true; + } + if (AR) { + ((EntityPlayer) entityKilledBy).heal(1); + for (int j = 0; j < 8; ++j) { + entityKilledBy.world.spawnParticle("largesmoke", entityKilledBy.x, entityKilledBy.y, entityKilledBy.z, 0.0, 0.0, 0.0, 0); + + } + } + } + } + + //needs fixing. + @Inject(method = "getHurtSound()Ljava/lang/String;", at = @At(value = "HEAD"), cancellable = true) + public void insertHurt(CallbackInfoReturnable cir){ + if(hurtSound) { + cir.setReturnValue("damage.hurtflesh"); + } + } + @Inject(method = "getDeathSound()Ljava/lang/String;", at = @At(value = "HEAD"), cancellable = true) + public void insertHurtDeath(CallbackInfoReturnable cir){ + if(hurtSound) { + cir.setReturnValue("damage.hurtflesh"); + } + } +} diff --git a/src/main/java/mizurin/shieldmod/mixins/EntitySnowManMixin.java b/src/main/java/mizurin/shieldmod/mixins/EntitySnowManMixin.java index 0c6effe..aa1c1e1 100644 --- a/src/main/java/mizurin/shieldmod/mixins/EntitySnowManMixin.java +++ b/src/main/java/mizurin/shieldmod/mixins/EntitySnowManMixin.java @@ -1,7 +1,7 @@ package mizurin.shieldmod.mixins; import com.mojang.nbt.CompoundTag; -import mizurin.shieldmod.IShieldZombie; +import mizurin.shieldmod.interfaces.IShieldZombie; import net.minecraft.core.block.Block; import net.minecraft.core.entity.Entity; import net.minecraft.core.entity.monster.*; @@ -26,14 +26,16 @@ protected void init() { entityData.define(22, (byte)0); } + //Right click to put a carved pumpkin on the snowman's head @Override public boolean interact(EntityPlayer entityplayer) { if (super.interact(entityplayer)) { return true; } else { ItemStack itemstack = entityplayer.inventory.getCurrentItem(); - if (itemstack != null && itemstack.getItem() == Block.pumpkinCarvedIdle.asItem() && !better_with_defense$isSnowJack()) { + if (itemstack != null && itemstack.getItem() == Block.pumpkinCarvedIdle.asItem() && !shieldmod$isSnowJack()) { setTarget(null); + //Snowman stops targeting player. entityData.set(22, (byte) 1); itemstack.consumeItem(entityplayer); @@ -46,7 +48,9 @@ public boolean interact(EntityPlayer entityplayer) { @Override protected Entity findPlayerToAttack() { - if (better_with_defense$isSnowJack()) { + if (shieldmod$isSnowJack()) { + //creates a bounding box and grabs a list of monsters to attack. + //doing just monsters causes the snowman to attack itself, I also want to exclude creepers from being attacked. List nearbyMon = this.world.getEntitiesWithinAABB(EntityZombie.class, AABB.getBoundingBoxFromPool(this.x, this.y, this.z, this.x + 1.0, this.y + 1.0, this.z + 1.0).expand(16.0, 4.0, 16.0)); nearbyMon.addAll(this.world.getEntitiesWithinAABB(EntitySkeleton.class, AABB.getBoundingBoxFromPool(this.x, this.y, this.z, this.x + 1.0, this.y + 1.0, this.z + 1.0).expand(16.0, 4.0, 16.0))); nearbyMon.addAll(this.world.getEntitiesWithinAABB(EntitySpider.class, AABB.getBoundingBoxFromPool(this.x, this.y, this.z, this.x + 1.0, this.y + 1.0, this.z + 1.0).expand(16.0, 4.0, 16.0))); @@ -55,6 +59,7 @@ protected Entity findPlayerToAttack() { super.setTarget((Entity) nearbyMon.get(this.world.rand.nextInt(nearbyMon.size()))); } } else { + //else statement for regular snowmen without carved pumpkins. EntityPlayer entityplayer = this.world.getClosestPlayerToEntity(this, 16.0); return entityplayer != null && this.canEntityBeSeen(entityplayer) && entityplayer.getGamemode().areMobsHostile() ? entityplayer : null; } @@ -63,12 +68,12 @@ protected Entity findPlayerToAttack() { @Override - public boolean better_with_defense$isShieldZombie() { + public boolean shieldmod$isShieldZombie() { return false; } @Override - public boolean better_with_defense$isSnowJack() { + public boolean shieldmod$isSnowJack() { return entityData.getByte(22) == 1; } @@ -76,16 +81,16 @@ protected Entity findPlayerToAttack() { @Override public void addAdditionalSaveData(CompoundTag tag) { super.addAdditionalSaveData(tag); - tag.putByte("better_with_defense$isSnowJack", better_with_defense$isSnowJack() ? (byte) 1 : (byte)0); + tag.putByte("shieldmod$isSnowJack", shieldmod$isSnowJack() ? (byte) 1 : (byte)0); } @Override public void readAdditionalSaveData(CompoundTag tag) { super.readAdditionalSaveData(tag); - entityData.set(22, tag.getByte("better_with_defense$isSnowJack")); + entityData.set(22, tag.getByte("shieldmod$isSnowJack")); } @Override public boolean canDespawn() { - if (better_with_defense$isSnowJack()) { + if (shieldmod$isSnowJack()) { return false; } else { return true; diff --git a/src/main/java/mizurin/shieldmod/mixins/EntityZombieArmoredMixin.java b/src/main/java/mizurin/shieldmod/mixins/EntityZombieArmoredMixin.java index ee26f1d..d0625f8 100644 --- a/src/main/java/mizurin/shieldmod/mixins/EntityZombieArmoredMixin.java +++ b/src/main/java/mizurin/shieldmod/mixins/EntityZombieArmoredMixin.java @@ -1,7 +1,7 @@ package mizurin.shieldmod.mixins; import com.mojang.nbt.CompoundTag; -import mizurin.shieldmod.IShieldZombie; +import mizurin.shieldmod.interfaces.IShieldZombie; import mizurin.shieldmod.item.Shields; import net.minecraft.core.WeightedRandomLootObject; import net.minecraft.core.entity.Entity; @@ -32,32 +32,36 @@ public EntityZombieArmoredMixin(World world) { public void init(CallbackInfo ci){ entityData.define(21, (byte)0); } + @Override public void spawnInit(){ super.spawnInit(); if ((random.nextInt(5) == 0)){ + //chance of spawning setHealthRaw(80); attackStrength = 6; this.mobDrops.add(new WeightedRandomLootObject(Item.ingotIron.getDefaultStack(), 1, 2)); + //guaranteed drop of 1-2 iron as a reward for killing the shielded zombie. entityData.set(21, (byte)1); + //if it spawns, set the data true. } } @Override - public boolean better_with_defense$isShieldZombie() { + public boolean shieldmod$isShieldZombie() { return entityData.getByte(21) == 1; } @Override - public boolean better_with_defense$isSnowJack() { + public boolean shieldmod$isSnowJack() { return false; } - + //Used to give the zombie a shield. @Inject(method = "getHeldItem()Lnet/minecraft/core/item/ItemStack;", at = @At("HEAD"), cancellable = true) private void sword(CallbackInfoReturnable cir){ - if (better_with_defense$isShieldZombie()){ + if (shieldmod$isShieldZombie()){ cir.setReturnValue(new ItemStack(Shields.ironShield)); } } @@ -65,24 +69,27 @@ private void sword(CallbackInfoReturnable cir){ @Override public void addAdditionalSaveData(CompoundTag tag) { super.addAdditionalSaveData(tag); - tag.putByte("better_with_defense$isShieldZombie", better_with_defense$isShieldZombie() ? (byte) 1 : (byte)0); + tag.putByte("shieldmod$isShieldZombie", shieldmod$isShieldZombie() ? (byte) 1 : (byte)0); } @Override public void readAdditionalSaveData(CompoundTag tag) { super.readAdditionalSaveData(tag); - entityData.set(21, tag.getByte("better_with_defense$isShieldZombie")); + entityData.set(21, tag.getByte("shieldmod$isShieldZombie")); } + @Override protected void attackEntity(Entity entity, float distance) { - if (better_with_defense$isShieldZombie()) { + if (shieldmod$isShieldZombie()) { + //really fun knockback that sends the entity in an arc when hit if (this.attackTime <= 0 && distance < 2.0F && entity.bb.maxY > this.bb.minY && entity.bb.minY < this.bb.maxY) { this.attackTime = 20; entity.hurt(this, this.attackStrength, DamageType.COMBAT); entity.push(entity.xd, entity.yd, entity.zd); } } else { + //else statement for normal zombie attack pattern. if (this.attackTime <= 0 && distance < 2.0F && entity.bb.maxY > this.bb.minY && entity.bb.minY < this.bb.maxY) { this.attackTime = 20; entity.hurt(this, this.attackStrength, DamageType.COMBAT); diff --git a/src/main/java/mizurin/shieldmod/mixins/FieldMixin.java b/src/main/java/mizurin/shieldmod/mixins/FieldMixin.java index e361b18..1153326 100644 --- a/src/main/java/mizurin/shieldmod/mixins/FieldMixin.java +++ b/src/main/java/mizurin/shieldmod/mixins/FieldMixin.java @@ -1,6 +1,6 @@ package mizurin.shieldmod.mixins; import com.mojang.nbt.CompoundTag; -import mizurin.shieldmod.IThrownItem; +import mizurin.shieldmod.interfaces.IThrownItem; import net.minecraft.core.entity.player.EntityPlayer; import net.minecraft.core.item.ItemStack; import net.minecraft.core.player.inventory.InventoryPlayer; @@ -12,6 +12,7 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +//Mixin for the throwable shield. @Mixin(value = EntityPlayer.class, remap = false) public abstract class FieldMixin implements IThrownItem { @Shadow @@ -35,11 +36,13 @@ public void storeOrDropItem(EntityPlayer player, ItemStack stack){ } } + //Sets the thrown item to save for later. @Override public ItemStack setThrownItem(ItemStack itemStack) { this.thrownItem = itemStack; return itemStack; } + //adds save data for when the player quits after throwing the shield @Inject(method = "addAdditionalSaveData(Lcom/mojang/nbt/CompoundTag;)V", at = @At("TAIL")) private void addData(CompoundTag tag, CallbackInfo ci){ ItemStack thrownItem = getThrownItem(); @@ -47,9 +50,11 @@ private void addData(CompoundTag tag, CallbackInfo ci){ tag.putCompound("item", thrownItem.writeToNBT(new CompoundTag())); } } + //reads the save data after the player rejoins the world after throwing the shield @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); + //gives the player their thrown item back. good failsafe so they do not lose the item. } } diff --git a/src/main/java/mizurin/shieldmod/mixins/KnockBackMixin.java b/src/main/java/mizurin/shieldmod/mixins/KnockBackMixin.java index b7951b2..a0c4044 100644 --- a/src/main/java/mizurin/shieldmod/mixins/KnockBackMixin.java +++ b/src/main/java/mizurin/shieldmod/mixins/KnockBackMixin.java @@ -1,11 +1,11 @@ package mizurin.shieldmod.mixins; +import mizurin.shieldmod.interfaces.ParryInterface; import mizurin.shieldmod.item.ShieldItem; import mizurin.shieldmod.item.ShieldMaterials; 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.EntityArrow; import net.minecraft.core.item.ItemStack; import net.minecraft.core.util.helper.DamageType; import net.minecraft.core.util.helper.MathHelper; @@ -15,6 +15,7 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +//Mixin for knockback when blocking. @Mixin(value = EntityLiving.class, remap = false) @@ -35,12 +36,17 @@ public void injectKnockBack(Entity entity, int i, double d, double d1, CallbackI if (stack != null) { if (stack.getItem() instanceof ShieldItem) { + //checks if the player is holding a shield. ShieldItem shield = ((ShieldItem) stack.getItem()); - if (stack.getData().getBoolean("active") && shield.tool == ShieldMaterials.TOOL_IRON) { + if (((ParryInterface)((EntityPlayer)(Object)this)).shieldmod$getIsBlock() && shield.tool == ShieldMaterials.TOOL_IRON) { + //checks if the player is blocking and holding an iron shield + // cancels early and ignores knockback. ci.cancel(); } - if (stack.getData().getBoolean("active") && shield.tool != ShieldMaterials.TOOL_IRON){ + if (((ParryInterface)((EntityPlayer)(Object)this)).shieldmod$getIsBlock() && shield.tool != ShieldMaterials.TOOL_IRON){ + //checks if the player is blocking and not holding an iron shield. + //removed the jump to the y value when being hit. float f = MathHelper.sqrt_double(d * d + d1 * d1); float f1 = 0.9F; ((EntityPlayer)(Object)this).xd /= 2.0; diff --git a/src/main/java/mizurin/shieldmod/mixins/LivingRendererMixin.java b/src/main/java/mizurin/shieldmod/mixins/LivingRendererMixin.java index 7febd53..960ed90 100644 --- a/src/main/java/mizurin/shieldmod/mixins/LivingRendererMixin.java +++ b/src/main/java/mizurin/shieldmod/mixins/LivingRendererMixin.java @@ -2,7 +2,7 @@ import com.llamalad7.mixinextras.sugar.Local; import mizurin.shieldmod.ColoredArmorTexture; -import mizurin.shieldmod.IColoredArmor; +import mizurin.shieldmod.interfaces.IColoredArmor; import mizurin.shieldmod.ShieldMod; import net.minecraft.client.render.entity.LivingRenderer; import net.minecraft.client.render.model.ModelBase; @@ -18,6 +18,7 @@ import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +//Mixin for colored armor renderer @Mixin(value = LivingRenderer.class, remap = false) public abstract class LivingRendererMixin { @Shadow protected abstract boolean shouldRenderPass(T entity, int renderPass, float partialTick); diff --git a/src/main/java/mizurin/shieldmod/mixins/PaintingMixin.java b/src/main/java/mizurin/shieldmod/mixins/PaintingMixin.java index f191887..3886bbf 100644 --- a/src/main/java/mizurin/shieldmod/mixins/PaintingMixin.java +++ b/src/main/java/mizurin/shieldmod/mixins/PaintingMixin.java @@ -14,6 +14,7 @@ import static net.minecraft.client.render.stitcher.TextureRegistry.artAtlas; +//Mixin for reloading painting textures. @Mixin(TextureRegistry.class) public abstract class PaintingMixin { @Shadow diff --git a/src/main/java/mizurin/shieldmod/mixins/PlayerRendererMixin.java b/src/main/java/mizurin/shieldmod/mixins/PlayerRendererMixin.java index 662988a..687eda6 100644 --- a/src/main/java/mizurin/shieldmod/mixins/PlayerRendererMixin.java +++ b/src/main/java/mizurin/shieldmod/mixins/PlayerRendererMixin.java @@ -1,7 +1,7 @@ package mizurin.shieldmod.mixins; import mizurin.shieldmod.ColoredArmorTexture; -import mizurin.shieldmod.IColoredArmor; +import mizurin.shieldmod.interfaces.IColoredArmor; import mizurin.shieldmod.ShieldMod; import net.minecraft.client.Minecraft; import net.minecraft.client.render.entity.PlayerRenderer; diff --git a/src/main/java/mizurin/shieldmod/mixins/ShieldMixin.java b/src/main/java/mizurin/shieldmod/mixins/ShieldMixin.java index 03e837e..9517729 100644 --- a/src/main/java/mizurin/shieldmod/mixins/ShieldMixin.java +++ b/src/main/java/mizurin/shieldmod/mixins/ShieldMixin.java @@ -2,29 +2,31 @@ import mizurin.shieldmod.entities.EntityPB; import mizurin.shieldmod.entities.EntityRock; -import mizurin.shieldmod.item.ParryInterface; +import mizurin.shieldmod.entities.EntityShield; +import mizurin.shieldmod.interfaces.ParryInterface; import mizurin.shieldmod.item.ShieldItem; import mizurin.shieldmod.item.ShieldMaterials; -import net.minecraft.core.achievement.stat.Stat; +import mizurin.shieldmod.item.Shields; 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; -import net.minecraft.core.entity.projectile.EntityPebble; +import net.minecraft.core.entity.projectile.*; import net.minecraft.core.item.ItemStack; import net.minecraft.core.player.gamemode.Gamemode; import net.minecraft.core.player.inventory.InventoryPlayer; import net.minecraft.core.util.helper.DamageType; +import net.minecraft.core.util.phys.AABB; import net.minecraft.core.world.World; -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; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import java.util.List; // mixin to EntityPlayer, do not remap(forgot what remap does) @@ -51,29 +53,171 @@ public ShieldMixin(World world) { @Shadow public abstract ItemStack getHeldItem(); - @Shadow - public abstract void addStat(Stat statbase, int i); - - @Shadow - public abstract void triggerAchievement(Stat statbase); + @Unique + public EntityLiving thisObject = (EntityLiving) (Object) this; @Shadow - private ChunkCoordinates playerSpawnCoordinate; + public abstract int getMaxHealth(); @Unique private int parryTicks; + @Unique + private int blockTicks; + + @Unique + private int counterTicks; + + @Unique + private int fireTicks; + + @Unique + private boolean isBlock; + @Override - public void shieldmod$Parry(int parryTicks){ + public void shieldmod$Parry(int parryTicks) { this.parryTicks = parryTicks; } + @Override - public int shieldmod$getParryTicks(){ + public int shieldmod$getParryTicks() { return parryTicks; } + @Override + public int shieldmod$getBlockTicks() { + return blockTicks; + } + + @Override + public void shieldmod$Block(int blockTicks) { + this.blockTicks = blockTicks; + } + + @Override + public boolean shieldmod$getIsBlock() { + return isBlock; + } + @Override + public void shieldmod$setIsBlock(boolean bool) { + this.isBlock = bool; + } + @Override + public int shieldmod$getCounterTicks(){ + return counterTicks; + } + @Override + public void shieldmod$Counter(int counterTicks){ + this.counterTicks = counterTicks; + } + @Override + public int shieldmod$getFireTicks(){ + return fireTicks; + } + @Override + public void shieldmod$Fire(int fireTicks){ + this.fireTicks = fireTicks; + } + //programmer note. I want to die after this lmao. + + @Unique + public void parryHitbox(World world, EntityPlayer player) { + + double bound = 1.75; + AABB aabb1 = new AABB( + player.x - bound, + player.y + player.getHeadHeight() - bound, + player.z - bound, + player.x + bound, + player.y + player.getHeadHeight() + bound, + player.z + bound + ); + + + List projectileList = player.world.getEntitiesWithinAABB(EntityProjectile.class, aabb1); + for (Entity entity : projectileList) { + world.spawnParticle("largesmoke", entity.x, entity.y, entity.z, 0.0, 0.0, 0.0, 0); + if (entity instanceof EntityArrow) { + if (((EntityArrow) entity).isGrounded()) { + return; + } + } + + if (entity instanceof EntityArrow) { + + if (!((EntityArrow) entity).isGrounded()) { + entity.remove(); + EntityArrow newArrow = new EntityArrow(world, player, false, ((EntityArrow) entity).getArrowType()); + newArrow.damage += 3; + if (!world.isClientSide) { + //For any devs looking at my code. This if statement (!world.isClientSide) is used for server compatibility, please use it when spawning items. + //In this case, failure to do so can cause the player to parry their own clientside projectiles that do not disappear. + world.entityJoinedWorld(newArrow); + world.playSoundAtEntity(player, player, "mob.ghast.fireball", 0.66f, 1.0f); + } + } + } + + if (entity instanceof EntityFireball) { + entity.hurt(player, 1, DamageType.COMBAT); + world.playSoundAtEntity(player, player, "mob.ghast.fireball", 0.66f, 1.0f); + } + + if (entity instanceof EntityCannonball) { + + double oldCBX = entity.x; + double oldCBY = entity.y; + double oldCBZ = entity.z; + + entity.remove(); + EntityCannonball newCB = new EntityCannonball(world, player); + if (!world.isClientSide) { + world.entityJoinedWorld(newCB); + newCB.setPos(oldCBX, oldCBY, oldCBZ); + double pushX = player.getLookAngle().xCoord; + double pushY = player.getLookAngle().yCoord; + double pushZ = player.getLookAngle().zCoord; + newCB.push(pushX * 1.2, pushY * 1.2, pushZ * 1.2); + world.playSoundAtEntity(player, player, "mob.ghast.fireball", 0.66f, 1.0f); + } + } + if (entity instanceof EntitySnowball) { + + entity.remove(); + EntitySnowball newSB = new EntitySnowball(world, player); + newSB.damage +=1; + if (!world.isClientSide) { + world.entityJoinedWorld(newSB); + world.playSoundAtEntity(player, player, "mob.ghast.fireball", 0.66f, 1.0f); + } + } + if (entity instanceof EntityShield) { + + entity.remove(); + EntityShield newTS = new EntityShield(world, player); + newTS.damage += 2; + if (!world.isClientSide) { + world.entityJoinedWorld(newTS); + world.playSoundAtEntity(player, player, "mob.ghast.fireball", 0.66f, 1.0f); + } + } + if (entity instanceof EntityPB) { + + entity.remove(); + EntityPB newPS = new EntityPB(world, player); + newPS.damage +=1; + if (!world.isClientSide) { + world.entityJoinedWorld(newPS); + world.playSoundAtEntity(player, player, "mob.ghast.fireball", 0.66f, 1.0f); + } + } + + } + player.swingItem(); + world.playSoundAtEntity(player, player, "mob.ghast.fireball", 0.3f, 1.0f); + } // inject at the top(HEAD) of hurt(), allow us to call return(cancel/set return value) @Inject(method = "hurt", at = @At("HEAD"), cancellable = true) @@ -93,6 +237,16 @@ public void injectHurt(Entity attacker, int damage, DamageType type, CallbackInf } // check if we are holding the shield item. ItemStack stack = inventory.mainInventory[inventory.currentItem]; + //check if we are wearing the helmet. + ItemStack helmet_item = this.inventory.armorItemInSlot(3); + if(attacker != null) { //need this or you will get a null pointer. + if (!this.gamemode.isPlayerInvulnerable()) { + if ((helmet_item != null && helmet_item.getItem().equals(Shields.rockyHelmet)) && attacker != this) { + attacker.hurt(attacker, 2, DamageType.COMBAT); + } + } + } + if (stack != null) { if (stack.getItem() instanceof ShieldItem) { @@ -102,10 +256,13 @@ 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){ + if(shield.tool == ShieldMaterials.TOOL_TEAR && getHealth() <= getMaxHealth() * 0.3){ damage = Math.round(damage * 0.5f); } - if (stack.getData().getBoolean("active")) { + //tear shield provides a damage resistance when the player is low health. it can stack with blocking too. + if (shieldmod$getIsBlock()) { + //checks if the player is blocking to apply the damage resistance. + int newDamage = Math.round(damage * (shield.tool.getEfficiency(true))); double _dx = attacker.x - this.x; @@ -117,25 +274,25 @@ public void injectHurt(Entity attacker, int damage, DamageType type, CallbackInf if (shield.tool == ShieldMaterials.TOOL_LEATHER && attacker != this){ attacker.push(_dx * 1.2 ,0.75,_dz * 1.2); - //addStat(ShieldAchievements.FLY_HIGH, 1); + //applies funny knockback to attack when hit. } if (shield.tool == ShieldMaterials.TOOL_STONE && attacker != this){ - attacker.hurt(this, 4, DamageType.FALL); - attacker.heartsFlashTime = 0; + if ((helmet_item != null && helmet_item.getItem().equals(Shields.rockyHelmet))) { + attacker.hurt(attacker, 5, DamageType.FALL); + } else { + attacker.hurt(this, 3, DamageType.FALL); + } if (!world.isClientSide) { world.entityJoinedWorld(new EntityRock(world, this)); } + //stone shield works similarly to the rocky helmet, but it also spawns a pebble. } if (shield.tool == ShieldMaterials.TOOL_DIAMOND){ - stack.getData().putInt("ticksB", 20); + shieldmod$Counter(20); + //adds the ticks(Blocked) when hit. } super.hurt(attacker, newDamage, type); - //addStat(ShieldAchievements.BLOCK, 1); - - //if( damage > 20 && isAlive()){ - //addStat(ShieldAchievements.INVINCIBLE, 1); - //} world.playSoundAtEntity(attacker, @@ -169,5 +326,71 @@ public void injectHurt(Entity attacker, int damage, DamageType type, CallbackInf } } } + @Unique + private int tickCounter = 0; + + @Unique + private int parryDelay = 0; + @Inject( + method = "Lnet/minecraft/core/entity/player/EntityPlayer;onLivingUpdate()V", + at = @At(value = "HEAD") + ) + public void tickMixin(CallbackInfo ci){ + ItemStack stack = inventory.mainInventory[inventory.currentItem]; + if (stack != null) { + if (stack.getItem() instanceof ShieldItem) { + + ShieldItem shield = ((ShieldItem) stack.getItem()); + if (isBlock && (shield.tool == ShieldMaterials.TOOL_LEATHER || shield.tool == ShieldMaterials.TOOL_WOOD)) { + this.xd *= 0.65D; + this.zd *= 0.65D; + } + else if (isBlock && shield.tool == ShieldMaterials.TOOL_DIAMOND){ + this.xd *= 0.20D; + this.zd *= 0.20D; + } + else if (isBlock){ + this.xd *= 0.4D; + this.zd *= 0.4D; + } + + if (blockTicks > 0) { + blockTicks--; + } else { + shieldmod$setIsBlock(false); + } + if(this.fireTicks > 0) { + this.fireTicks--; + } + if(this.counterTicks > 0) { + this.counterTicks--; + } + + } + } + ItemStack helmet_item = this.inventory.armorItemInSlot(2); + if ((helmet_item != null && helmet_item.getItem().equals(Shields.regenAmulet))) { + ++this.tickCounter; + if (this.tickCounter >= 600) { + this.tickCounter = 0; + this.heal(1); + } + + } + if(this.parryTicks != 0) { + this.parryTicks--; + } + if(parryDelay > 0){ + parryDelay--; + } + + if(this.parryTicks == 18 && thisObject instanceof EntityPlayer && parryDelay == 0){ + parryHitbox(thisObject.world, (EntityPlayer)thisObject); + parryDelay = 30; + } + + + } + } diff --git a/src/main/java/mizurin/shieldmod/mixins/WorldFeatureLabyrinthMixin.java b/src/main/java/mizurin/shieldmod/mixins/WorldFeatureLabyrinthMixin.java index 20c38b8..f848477 100644 --- a/src/main/java/mizurin/shieldmod/mixins/WorldFeatureLabyrinthMixin.java +++ b/src/main/java/mizurin/shieldmod/mixins/WorldFeatureLabyrinthMixin.java @@ -2,19 +2,25 @@ import mizurin.shieldmod.item.Shields; import net.minecraft.core.item.ItemStack; +import net.minecraft.core.world.World; import net.minecraft.core.world.generate.feature.WorldFeatureLabyrinth; 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.CallbackInfoReturnable; import java.util.Random; +//Mixin to add different treasure items to biomes based off temperature. @Mixin(value = WorldFeatureLabyrinth.class, remap = false) public class WorldFeatureLabyrinthMixin { @Shadow - private boolean isCold; + boolean isCold; + + @Unique + private boolean isHot; @Inject(method = "pickCheckLootItem(Ljava/util/Random;)Lnet/minecraft/core/item/ItemStack;", at = @At(value = "FIELD", target = "Lnet/minecraft/core/world/generate/feature/WorldFeatureLabyrinth;treasureGenerated:Z", ordinal = 1, shift = At.Shift.AFTER), cancellable = true) @@ -22,5 +28,16 @@ private void addTreasure(Random random, CallbackInfoReturnable cir) { if (isCold && random.nextInt(2) == 0) { cir.setReturnValue(new ItemStack(Shields.tearShield)); } + if(isHot && random.nextInt(2)== 0){ + cir.setReturnValue(new ItemStack(Shields.rockyHelmet)); + } + if(!isHot && !isCold && random.nextInt(2)== 0){ + cir.setReturnValue(new ItemStack(Shields.regenAmulet)); + } + } + @Inject(method = "generate(Lnet/minecraft/core/world/World;Ljava/util/Random;III)Z", at = @At(value = "FIELD", target = "net/minecraft/core/world/generate/feature/WorldFeatureLabyrinth.slabBlock : I", ordinal = 0)) + private void addBiome(World world, Random random, int x, int y, int z, CallbackInfoReturnable cir){ + this.isHot = true; } } + diff --git a/src/main/java/mizurin/shieldmod/mixins/WorldMixin.java b/src/main/java/mizurin/shieldmod/mixins/WorldMixin.java new file mode 100644 index 0000000..f46c46a --- /dev/null +++ b/src/main/java/mizurin/shieldmod/mixins/WorldMixin.java @@ -0,0 +1,71 @@ +package mizurin.shieldmod.mixins; +import mizurin.shieldmod.item.Shields; +import net.minecraft.core.entity.player.EntityPlayer; +import net.minecraft.core.item.ItemStack; +import net.minecraft.core.world.World; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Overwrite; +import org.spongepowered.asm.mixin.Unique; + +//please god help me. +@Mixin(value = World.class, remap = false) +public class WorldMixin { + + @Unique + World thisObject = (World)(Object)this; + + /** + * @author + * @reason + */ + @Overwrite + public EntityPlayer getClosestPlayer(double x, double y, double z, double radius) { + double closestDistance = Double.POSITIVE_INFINITY; + EntityPlayer entityplayer = null; + if (radius < 0.0) { + for (EntityPlayer entityPlayer1 : thisObject.players) { + double currentDistance = entityPlayer1.distanceToSqr(x, y, z); + if (!(currentDistance < closestDistance)) continue; + closestDistance = currentDistance; + entityplayer = entityPlayer1; + } + } else { + double armorTotal = 16; + double rSquared = radius * radius; + for (EntityPlayer entityPlayer1 : thisObject.players) { + double currentDistance = entityPlayer1.distanceToSqr(x, y, z); + if (!(currentDistance < rSquared) || !(currentDistance < closestDistance)) continue; + closestDistance = currentDistance; + + boolean plyInvis = false; + + ItemStack bootSlot = entityPlayer1.inventory.armorItemInSlot(0); //1 + ItemStack leggingsSlot = entityPlayer1.inventory.armorItemInSlot(1); //2 + ItemStack chestplateSlot = entityPlayer1.inventory.armorItemInSlot(2); //4 + ItemStack helmetSlot = entityPlayer1.inventory.armorItemInSlot(3); //1 + + + if (helmetSlot != null && helmetSlot.itemID == Shields.armorLeatherHelmet.id){ + armorTotal -= 1; + plyInvis = true; + } if (chestplateSlot != null && chestplateSlot.itemID == Shields.armorLeatherChest.id) { + armorTotal -= 4; + plyInvis = true; + } if (leggingsSlot != null && leggingsSlot.itemID == Shields.armorLeatherLeg.id) { + armorTotal -= 2; + plyInvis = true; + } if (bootSlot != null && bootSlot.itemID == Shields.armorLeatherBoot.id){ + armorTotal -= 1; + plyInvis = true; + } + double rThirdSquared = (radius * armorTotal/16) * (radius * armorTotal/16); + + if(plyInvis & currentDistance < rThirdSquared || !plyInvis){ + entityplayer = entityPlayer1; + } + } + } + + return entityplayer; + } +} diff --git a/src/main/java/mizurin/shieldmod/mixins/achievement/dyeMixin.java b/src/main/java/mizurin/shieldmod/mixins/achievement/dyeMixin.java deleted file mode 100644 index cfd143f..0000000 --- a/src/main/java/mizurin/shieldmod/mixins/achievement/dyeMixin.java +++ /dev/null @@ -1,48 +0,0 @@ -/*package mizurin.shieldmod.mixins.achievement; - -import mizurin.shieldmod.ShieldAchievements; -import mizurin.shieldmod.item.Shields; -import net.minecraft.core.entity.player.EntityPlayer; -import net.minecraft.core.item.Item; -import net.minecraft.core.item.ItemStack; -import net.minecraft.core.player.inventory.slot.SlotCrafting; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(value = SlotCrafting.class, remap = false) -public class dyeMixin { - - @Shadow - private EntityPlayer thePlayer; - - @Inject(method = "onPickupFromSlot", at = @At("TAIL")) - private void injectPickup(ItemStack itemStack, CallbackInfo ci){ - Item item = itemStack.getItem(); - if(item.id == Shields.woodenShield.id){ - thePlayer.triggerAchievement(ShieldAchievements.SHIELD_GOT); - } - if(item.id == Shields.steelShield.id){ - thePlayer.addStat(ShieldAchievements.MODERN_AGE, 1); - } - if(item.id == Shields.armorLeatherHelmet.id && itemStack.getData().containsKey("dyed_color")){ - thePlayer.addStat(ShieldAchievements.COLORS, 1); - } - if(item.id == Shields.armorLeatherChest.id && itemStack.getData().containsKey("dyed_color")){ - thePlayer.addStat(ShieldAchievements.COLORS, 1); - } - if(item.id == Shields.armorLeatherLeg.id && itemStack.getData().containsKey("dyed_color")){ - thePlayer.addStat(ShieldAchievements.COLORS, 1); - } - if(item.id == Shields.armorLeatherBoot.id && itemStack.getData().containsKey("dyed_color")){ - thePlayer.addStat(ShieldAchievements.COLORS, 1); - } - if(item.id == Shields.leatherShield.id && itemStack.getData().containsKey("dyed_color")){ - thePlayer.addStat(ShieldAchievements.COLORS, 1); - } - - } -} -*/ diff --git a/src/main/java/mizurin/shieldmod/recipeColor.java b/src/main/java/mizurin/shieldmod/recipeColor.java index 40a9e77..773d2da 100644 --- a/src/main/java/mizurin/shieldmod/recipeColor.java +++ b/src/main/java/mizurin/shieldmod/recipeColor.java @@ -1,6 +1,7 @@ package mizurin.shieldmod; import com.mojang.nbt.CompoundTag; +import mizurin.shieldmod.interfaces.IColorable; import net.minecraft.core.data.registry.recipe.SearchQuery; import net.minecraft.core.data.registry.recipe.entry.RecipeEntryCraftingDynamic; import net.minecraft.core.item.Item; @@ -17,6 +18,7 @@ import java.util.Map; //Special thanks to UselessBullets for being extremely awesome https://github.com/UselessBullets/Lunacy/tree/7.1 +//Mixin for custom recipe colors. public class recipeColor extends RecipeEntryCraftingDynamic { public static boolean nonamedyesOn = ModVersionHelper.isModPresent("nonamedyes"); @@ -32,6 +34,7 @@ public class recipeColor extends RecipeEntryCraftingDynamic { vanillaDye.put(color, new Color().setARGB(ItemDye.field_31002_bk[color])); } if (nonamedyesOn){ + //checks if nonamedyes is enabled, then adds them to the hasmap. nonameDye.put(0, new Color().setARGB(11540279)); //crimson nonameDye.put(1, new Color().setARGB(6627104)); //maroon nonameDye.put(2, new Color().setARGB(10005149)); //ash.gray diff --git a/src/main/java/mizurin/shieldmod/recipes.java b/src/main/java/mizurin/shieldmod/recipes.java index 385eaaa..b02f1a4 100644 --- a/src/main/java/mizurin/shieldmod/recipes.java +++ b/src/main/java/mizurin/shieldmod/recipes.java @@ -1,7 +1,5 @@ package mizurin.shieldmod; -import goocraft4evr.nonamedyes.NoNameDyes; -import goocraft4evr.nonamedyes.crafting.RecipeBuilderBleacher; import net.minecraft.core.block.Block; import net.minecraft.core.data.registry.Registries; import net.minecraft.core.data.registry.recipe.RecipeNamespace; @@ -21,6 +19,7 @@ public class recipes implements RecipeEntrypoint { public static final String MOD_ID = ShieldMod.MOD_ID; public static final RecipeGroup> WORKBENCH = new RecipeGroup<>(new RecipeSymbol(new ItemStack(Block.workbench))); + //initNamespaces for recipes in servers. @Override public void initNamespaces() { RecipeNamespace BETTERWITHDEFENSE = new RecipeNamespace(); @@ -93,6 +92,10 @@ public void onRecipesReady() { WORKBENCH.register("tearstoneShield", new RecipeEntryRepairable(Shields.tearShield, Item.ingotIron)); + + WORKBENCH.register("amuletRegenChest", new RecipeEntryRepairable(Shields.regenAmulet, Item.dustRedstone)); + + WORKBENCH.register("rockyHelmetHat", new RecipeEntryRepairable(Shields.rockyHelmet, Block.cobbleStone.asItem())); } public void initializeRecipe(){ Registries.RECIPE_TYPES.register("colored/shield", recipeColor.class); diff --git a/src/main/resources/assets/shieldmod/textures/armor/armor_stone_1.png b/src/main/resources/assets/shieldmod/textures/armor/armor_stone_1.png new file mode 100644 index 0000000..91afc42 Binary files /dev/null and b/src/main/resources/assets/shieldmod/textures/armor/armor_stone_1.png differ diff --git a/src/main/resources/assets/shieldmod/textures/armor/armor_stone_1.png~ b/src/main/resources/assets/shieldmod/textures/armor/armor_stone_1.png~ new file mode 100644 index 0000000..d9b4f3b Binary files /dev/null and b/src/main/resources/assets/shieldmod/textures/armor/armor_stone_1.png~ differ diff --git a/src/main/resources/assets/shieldmod/textures/item/poison_bottle.png~ b/src/main/resources/assets/shieldmod/textures/item/poison_bottle.png~ deleted file mode 100644 index 462635b..0000000 Binary files a/src/main/resources/assets/shieldmod/textures/item/poison_bottle.png~ and /dev/null differ diff --git a/src/main/resources/assets/shieldmod/textures/item/purple_fire.png b/src/main/resources/assets/shieldmod/textures/item/purple_fire.png new file mode 100644 index 0000000..76d6e01 Binary files /dev/null and b/src/main/resources/assets/shieldmod/textures/item/purple_fire.png differ diff --git a/src/main/resources/assets/shieldmod/textures/item/regen_amulet.png b/src/main/resources/assets/shieldmod/textures/item/regen_amulet.png new file mode 100644 index 0000000..fe78654 Binary files /dev/null and b/src/main/resources/assets/shieldmod/textures/item/regen_amulet.png differ diff --git a/src/main/resources/assets/shieldmod/textures/item/regen_amulet.png~ b/src/main/resources/assets/shieldmod/textures/item/regen_amulet.png~ new file mode 100644 index 0000000..978243f Binary files /dev/null and b/src/main/resources/assets/shieldmod/textures/item/regen_amulet.png~ differ diff --git a/src/main/resources/assets/shieldmod/textures/item/rocky_helmet.png b/src/main/resources/assets/shieldmod/textures/item/rocky_helmet.png new file mode 100644 index 0000000..7e1e67d Binary files /dev/null and b/src/main/resources/assets/shieldmod/textures/item/rocky_helmet.png differ diff --git a/src/main/resources/assets/shieldmod/textures/item/snow_pebble.png b/src/main/resources/assets/shieldmod/textures/item/snow_pebble.png deleted file mode 100644 index 4dd6759..0000000 Binary files a/src/main/resources/assets/shieldmod/textures/item/snow_pebble.png and /dev/null differ diff --git a/src/main/resources/assets/shieldmod/textures/item/snow_pebble.png~ b/src/main/resources/assets/shieldmod/textures/item/snow_pebble.png~ deleted file mode 100644 index f45ef67..0000000 Binary files a/src/main/resources/assets/shieldmod/textures/item/snow_pebble.png~ and /dev/null differ diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 2e365d8..a844e5b 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -3,7 +3,7 @@ "id": "shieldmod", "version": "${version}", - "name": "Better with defense", + "name": "Rin's Fortress", "description": "This mod aims to add more options of defense to BTA!", "authors": [ "Mizuri-n" diff --git a/src/main/resources/icon.png b/src/main/resources/icon.png index f08c7fb..1ba4c7b 100644 Binary files a/src/main/resources/icon.png and b/src/main/resources/icon.png differ diff --git a/src/main/resources/lang/shieldmod/en_US.lang b/src/main/resources/lang/shieldmod/en_US.lang index dc4b4f0..de74167 100644 --- a/src/main/resources/lang/shieldmod/en_US.lang +++ b/src/main/resources/lang/shieldmod/en_US.lang @@ -11,16 +11,17 @@ item.shieldmod.gold.shield.desc=Send projectiles back to monsters with this gold item.shieldmod.diamond.shield.name=Diamond Shield item.shieldmod.diamond.shield.desc=A rare and pretty shield. item.shieldmod.steel.shield.name=Steel Shield -item.shieldmod.steel.shield.desc=Set monsters ablaze with this steel shield! - +item.shieldmod.steel.shield.desc=A comically large steel fire striker item.shieldmod.tear.shield.name=Tearstone Shield item.shieldmod.tear.shield.desc=A throwable frozen shield that boosts defense when close to death. - item.shieldmod.food.stew.pumpkin.name=Pumpkin Stew item.shieldmod.food.stew.pumpkin.desc=Hearty... tasty! - item.shieldmod.poison.bottle.name=Alchemist's Poison item.shieldmod.poison.bottle.desc=Full of a velvet gloom... +item.shieldmod.helmet.rock.name=Rocky Helmet +item.shieldmod.helmet.rock.desc=A crumbling helmet. +item.shieldmod.amulet.heart.name=Amulet of restoration +item.shieldmod.amulet.heart.desc=An amulet that is warm to the touch and fills you with vigor. item.shieldmod.armor.helmet.leather.name=Leather Cap @@ -33,21 +34,3 @@ item.shieldmod.armor.boots.leather.name=Leather Boots item.shieldmod.armor.boots.leather.desc=A pair of boots made from a cow's hide. - -achievements.page.defense.desc=BWD achievements WIP -achievement.shieldmod.block=Block Blocked -achievement.shieldmod.block.desc=Block an attack -achievement.shieldmod.shield.got=Time to Defend! -achievement.shieldmod.shield.got.desc=Use planks and a log to make a shield -achievement.shieldmod.modern.age=The Modern Age -achievement.shieldmod.modern.age.desc=Obtain a Steel Shield -achievement.shieldmod.fly.high=Fly High -achievement.shieldmod.fly.high.desc=Knock an attacker into the air! -achievement.shieldmod.gold.retal=Golden Retaliation -achievement.shieldmod.gold.retal.desc=Send damage back to an attacker -achievement.shieldmod.colorful.world=Colorful World -achievement.shieldmod.colorful.world.desc=Obtain a dyed shield or armor - -achievement.shieldmod.undying.shield=Invincible! -achievement.shieldmod.undying.shield.desc=Survive a Lethal blow - diff --git a/src/main/resources/shieldmod.mixins.json b/src/main/resources/shieldmod.mixins.json index 7964b86..4716009 100644 --- a/src/main/resources/shieldmod.mixins.json +++ b/src/main/resources/shieldmod.mixins.json @@ -4,18 +4,22 @@ "package": "mizurin.shieldmod.mixins", "compatibilityLevel": "JAVA_8", "mixins": [ - "BipedRendererMixin", "BlockFarmlandMixin", "DazedMixin", + "EntityLivingMixin", "EntitySnowManMixin", "EntityZombieArmoredMixin", "FieldMixin", "KnockBackMixin", + "ShieldMixin", + "WorldFeatureLabyrinthMixin", + "WorldMixin" + ], + "client": [ + "BipedRendererMixin", "LivingRendererMixin", "PaintingMixin", - "PlayerRendererMixin", - "ShieldMixin", - "WorldFeatureLabyrinthMixin" + "PlayerRendererMixin" ], "injectors": { "defaultRequire": 1