Skip to content

Commit

Permalink
wip 2
Browse files Browse the repository at this point in the history
  • Loading branch information
Rin committed Aug 31, 2024
1 parent 19f938d commit e5be845
Show file tree
Hide file tree
Showing 10 changed files with 102 additions and 20 deletions.
11 changes: 9 additions & 2 deletions src/main/java/mizurin/shieldmod/ShieldMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@

import mizurin.shieldmod.item.EntityShield;
import net.fabricmc.api.ModInitializer;
import net.minecraft.client.render.entity.ArmoredZombieRenderer;
import net.minecraft.client.render.entity.EntityRenderer;
import net.minecraft.client.render.entity.PaintingRenderer;
import net.minecraft.client.render.entity.SnowballRenderer;
import net.minecraft.client.render.model.ModelZombie;
import net.minecraft.client.render.stitcher.TextureRegistry;
import net.minecraft.core.crafting.LookupFuelFurnace;
import net.minecraft.core.data.registry.Registries;
import net.minecraft.core.entity.projectile.EntitySnowball;
import net.minecraft.core.enums.ArtType;
import net.minecraft.core.item.Item;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -21,12 +26,13 @@
import java.util.Properties;
import java.util.function.Supplier;

public class ShieldMod implements ModInitializer, GameStartEntrypoint, ClientStartEntrypoint {
public class ShieldMod implements ModInitializer, GameStartEntrypoint, ClientStartEntrypoint{
public static final String MOD_ID = "shieldmod";
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);

public static int itemID;
public static int entityID;
public static ArtType paintingSeal;
static {
Properties prop = new Properties();
prop.setProperty("starting_item_id", "17000");
Expand All @@ -38,7 +44,6 @@ public class ShieldMod implements ModInitializer, GameStartEntrypoint, ClientSta
}



@Override
public void onInitialize() {
LOGGER.info("Better with Defense has been initialized!");
Expand All @@ -61,7 +66,9 @@ public void afterGameStart() {

@Override
public void beforeClientStart() {
paintingSeal = new ArtType("paintingSeal", "The Orb", "Rin", "shieldmod:art/seal", 32, 32);
EntityHelper.createEntity(EntityShield.class, entityID, "ammoShield", () -> new SnowballRenderer(Shields.ammotearShield));
EntityHelper.createEntity(ShieldZombie.class, ++entityID, "ShieldZombie", () -> new ArmoredZombieRenderer(new ModelZombie(), 0.1F));
}

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

import mizurin.shieldmod.item.Shields;
import net.minecraft.core.entity.Entity;
import net.minecraft.core.entity.EntityLiving;
import net.minecraft.core.entity.monster.EntityArmoredZombie;
import net.minecraft.core.item.ItemStack;
import net.minecraft.core.util.helper.DamageType;
import net.minecraft.core.world.World;

public class ShieldZombie extends EntityArmoredZombie {
public ShieldZombie(World world) {
super(world);
this.attackStrength += 1;
}

@Override
public int getMaxHealth() {
return 80;
}

@Override
public ItemStack getHeldItem() {
return new ItemStack(Shields.ironShield);
}

@Override
protected void attackEntity(Entity entity, float distance) {
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);
}
}
}
6 changes: 4 additions & 2 deletions src/main/java/mizurin/shieldmod/item/EntityShield.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,12 @@ public void onHit(HitResult hitResult) {
}
if (this.modelItem != null) {
for(int j = 0; j < 8; ++j) {
this.world.spawnParticle("item", this.x, this.y, this.z, (double)this.modelItem.id, 0.0, 0.0, 0);
this.world.spawnParticle("item", this.x, this.y, this.z, 0.0, 0.0, 0.0, this.modelItem.id);
}
}
this.remove();
storeOrDropItem((EntityPlayer) owner, ((IThrownItem)owner).getThrownItem());
if (this.owner != null) {
storeOrDropItem((EntityPlayer) owner, ((IThrownItem) owner).getThrownItem());
}
}
}
22 changes: 20 additions & 2 deletions src/main/java/mizurin/shieldmod/item/ItemModelShield.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static int shieldColor(ItemStack itemStack){
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.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);
Expand All @@ -42,7 +42,7 @@ public void heldTransformThirdPerson(ItemRenderer renderer, Entity entity, ItemS
GL11.glTranslatef(0.10F, -0.80075F, 0.375F);
} else {
final float scale = 0.625F;
GL11.glTranslatef(-0.25F, 0.1875F, 0);
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
Expand All @@ -52,4 +52,22 @@ public void heldTransformThirdPerson(ItemRenderer renderer, Entity entity, ItemS
GL11.glTranslatef(0.31F, -0.20075F, -0.3F);
}
}

@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);


} else {
final float scale3 = 0.625F;
GL11.glRotatef(74, 0.0F, 1.0F, 0.0F);
GL11.glRotatef(23, 0.0F, 0.0F, 1.0F);
GL11.glRotatef(10, 1.0F, 0.0F, 0.0F);
GL11.glTranslatef(0.0F, -0.3F, -0.5F);
}
}
}
4 changes: 4 additions & 0 deletions src/main/java/mizurin/shieldmod/item/Shields.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package mizurin.shieldmod.item;

import net.minecraft.client.render.stitcher.TextureRegistry;
import net.minecraft.core.enums.ArtType;
import net.minecraft.core.item.Item;
import net.minecraft.core.item.ItemPainting;
import net.minecraft.core.item.tag.ItemTags;
import org.slf4j.LoggerFactory;
import turniplabs.halplibe.helper.ItemBuilder;
Expand Down Expand Up @@ -31,6 +33,7 @@ public class Shields {
public static Item armorLeatherBoot;



@SuppressWarnings("unchecked")
public void initializeItems(){
woodenShield = new ItemBuilder(MOD_ID)
Expand Down Expand Up @@ -118,5 +121,6 @@ public void initializeItems(){
armorLeatherChest = new ItemBuilder(MOD_ID).build(new ArmorColored("armor.chestplate.leather", 16427, ArmorMaterial.LEATHER, 1));
armorLeatherLeg = new ItemBuilder(MOD_ID).build(new ArmorColored("armor.leggings.leather", 16428, ArmorMaterial.LEATHER, 2));
armorLeatherBoot = new ItemBuilder(MOD_ID).build(new ArmorColored("armor.boots.leather", 16429, ArmorMaterial.LEATHER, 3));

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

public class PaintingMixin {
}
15 changes: 14 additions & 1 deletion src/main/java/mizurin/shieldmod/mixins/ShieldMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@
import net.minecraft.core.achievement.stat.Stat;
import net.minecraft.core.entity.Entity;
import net.minecraft.core.entity.EntityLiving;
import net.minecraft.core.entity.EntityTNT;
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.EntityCannonball;
import net.minecraft.core.entity.projectile.EntityProjectile;
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.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.injection.At;
Expand Down Expand Up @@ -52,6 +56,9 @@ public ShieldMixin(World world) {
@Shadow
public abstract void triggerAchievement(Stat statbase);

@Shadow
private ChunkCoordinates playerSpawnCoordinate;

// inject at the top(HEAD) of hurt(), allow us to call return(cancel/set return value)
@Inject(method = "hurt", at = @At("HEAD"), cancellable = true)
public void injectHurt(Entity attacker, int damage, DamageType type, CallbackInfoReturnable<Boolean> ci) {
Expand Down Expand Up @@ -86,8 +93,14 @@ public void injectHurt(Entity attacker, int damage, DamageType type, CallbackInf
if (stack.getData().getBoolean("active")) {
int newDamage = Math.round(damage * (shield.tool.getEfficiency(true)));

double _dx = attacker.x - this.x;
double _dz = attacker.z - this.z;
double length = Math.hypot(_dx, _dz);
_dx /= length;
_dz /= length;

if (shield.tool == ShieldMaterials.TOOL_LEATHER){
attacker.push(0 ,1,0);
attacker.push(_dx * 1.2 ,0.75,_dz * 1.2);
//addStat(ShieldAchievements.FLY_HIGH, 1);
}
if(shield.tool == ShieldMaterials.TOOL_GOLD){
Expand Down
24 changes: 12 additions & 12 deletions src/main/java/mizurin/shieldmod/mixins/ZombieShieldMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
import mizurin.shieldmod.item.Shields;
import net.minecraft.core.entity.monster.EntityArmoredZombie;
import net.minecraft.core.item.ItemStack;
import net.minecraft.core.world.SpawnerMobs;
import net.minecraft.core.world.World;
import org.spongepowered.asm.mixin.Final;
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;
Expand All @@ -13,20 +16,17 @@

import java.util.Random;

@Mixin(value = EntityArmoredZombie.class, remap = false)
/*@Mixin(value = SpawnerMobs.class, remap = false)
public class ZombieShieldMixin {
@Unique
public boolean isHoldingShield;
@Shadow
@Final
private static Class<?>[] nightSpawnEntities;
@Inject(method = "<init>(Lnet/minecraft/core/world/World;)V", at = @At(value = "INVOKE", target = "Ljava/util/Random;nextInt(I)I",shift = At.Shift.BEFORE))
private void injectZombie(World world, CallbackInfo ci){
Random rand = new Random();
this.isHoldingShield = rand.nextInt(5) == 0;
@Inject(method = "Lnet/minecraft/core/world/SpawnerMobs;<init>()V", at = @At(value = "HEAD"))
private static void injectEntity(CallbackInfo callbackInfo){
nightSpawnEntities
}
@Inject(method = "getHeldItem()Lnet/minecraft/core/item/ItemStack;", at =@At("HEAD"), cancellable = true)
private void injectShield(CallbackInfoReturnable<ItemStack> cir){
cir.setReturnValue(this.isHoldingShield ? new ItemStack(Shields.ironShield, 1) : null);
}
}
} */
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion src/main/resources/shieldmod.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"FieldMixin",
"ShieldMixin",
"WorldFeatureLabyrinthMixin",
"ZombieShieldMixin"
],
"injectors": {
"defaultRequire": 1
Expand Down

0 comments on commit e5be845

Please sign in to comment.