generated from Turnip-Labs/bta-example-mod
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Rin
committed
Jun 10, 2024
1 parent
60d15f8
commit 7879957
Showing
23 changed files
with
300 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
org.gradle.jvmargs=-Xmx2G | ||
|
||
# BTA | ||
bta_version=7.1 | ||
bta_version=7.1_01 | ||
|
||
# Loader | ||
loader_version=0.15.6-babric.5-bta | ||
|
||
# HalpLibe | ||
halplibe_version=3.5.2 | ||
halplibe_version=3.5.4 | ||
|
||
prismatic_version=3.1.2-7.1 | ||
|
||
# Mod | ||
mod_version=1.1.4 | ||
mod_version=1.0.6 | ||
mod_group=Mizuri-n | ||
mod_name=Better with Defense |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package mizurin.shieldmod; | ||
|
||
import net.minecraft.core.item.Item; | ||
import net.minecraft.core.item.ItemStack; | ||
|
||
public interface IThrownItem { | ||
public ItemStack getThrownItem(); | ||
public ItemStack setThrownItem(ItemStack itemStack); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package mizurin.shieldmod.item; | ||
|
||
import mizurin.shieldmod.IThrownItem; | ||
import net.minecraft.core.HitResult; | ||
import net.minecraft.core.entity.Entity; | ||
import net.minecraft.core.entity.EntityLiving; | ||
import net.minecraft.core.entity.player.EntityPlayer; | ||
import net.minecraft.core.entity.projectile.EntityPebble; | ||
import net.minecraft.core.item.Item; | ||
import net.minecraft.core.item.ItemStack; | ||
import net.minecraft.core.player.inventory.InventoryPlayer; | ||
import net.minecraft.core.util.helper.DamageType; | ||
import net.minecraft.core.world.World; | ||
|
||
public class EntityShield extends EntityPebble { | ||
public EntityShield(World world) { | ||
super(world); | ||
this.modelItem = Item.ammoSnowball; | ||
this.setSize(0.9F, 0.9F); | ||
} | ||
|
||
public EntityShield(World world, EntityLiving entityliving) { | ||
super(world, entityliving); | ||
this.modelItem = Item.ammoSnowball; | ||
} | ||
|
||
public EntityShield(World world, double d, double d1, double d2) { | ||
super(world, d, d1, d2); | ||
this.modelItem = Item.ammoSnowball; | ||
} | ||
|
||
public void init() { | ||
super.init(); | ||
this.damage = 0; | ||
} | ||
public void storeOrDropItem(EntityPlayer player, ItemStack stack){ | ||
if(stack == null || stack.stackSize <= 0){ | ||
return; | ||
} | ||
InventoryPlayer inventory = player.inventory; | ||
inventory.insertItem(stack, false); | ||
if (stack.stackSize > 0){ | ||
player.dropPlayerItem(stack); | ||
} | ||
} | ||
|
||
|
||
public void onHit(HitResult hitResult) { | ||
damage = ticksInAir /3 + 3; | ||
if (damage > 14){ | ||
damage = 14; | ||
} | ||
if (hitResult.entity != null) { | ||
hitResult.entity.hurt(this.owner, this.damage, DamageType.COMBAT); | ||
//hitResult.entity.push(this.xd * 0.2, 0, this.zd * 0.2); | ||
} | ||
if (!this.world.isClientSide) { | ||
this.world.playSoundAtEntity((Entity) null, this, "mob.ghast.fireball", 1.0F, 1.2F / (this.random.nextFloat() * 0.2F + 0.9F)); | ||
} | ||
if (this.modelItem != null) { | ||
for(int j = 0; j < 8; ++j) { | ||
this.world.spawnParticle("item", this.x, this.y, this.z, (double)this.modelItem.id, 0.0, 0.0); | ||
} | ||
} | ||
this.remove(); | ||
storeOrDropItem((EntityPlayer) owner, ((IThrownItem)owner).getThrownItem()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package mizurin.shieldmod.item; | ||
import net.minecraft.core.entity.Entity; | ||
import net.minecraft.core.item.ItemStack; | ||
import net.minecraft.core.item.material.ToolMaterial; | ||
import net.minecraft.core.world.World; | ||
|
||
public class LightShield extends ShieldItem{ | ||
public LightShield(String name, int id, ToolMaterial toolMaterial) { | ||
super(name, id, toolMaterial); | ||
} | ||
@Override | ||
public void inventoryTick(ItemStack itemstack, World world, Entity entity, int i, boolean flag) { | ||
if(itemstack.getData().getBoolean("active")){ | ||
entity.xd *= 0.65D; | ||
entity.zd *= 0.65D; | ||
int ticks = itemstack.getData().getInteger("ticks"); | ||
|
||
if (ticks > 0){ | ||
itemstack.getData().putInt("ticks", ticks - 1); | ||
} else { | ||
itemstack.getData().putBoolean("active", false); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package mizurin.shieldmod.item; | ||
|
||
import mizurin.shieldmod.IThrownItem; | ||
import net.minecraft.core.entity.player.EntityPlayer; | ||
import net.minecraft.core.item.ItemStack; | ||
import net.minecraft.core.item.material.ToolMaterial; | ||
import net.minecraft.core.world.World; | ||
|
||
public class ThrowShield extends ShieldItem{ | ||
int ticksToAdd = 5; | ||
|
||
|
||
public ThrowShield(String name, int id, ToolMaterial toolMaterial) { | ||
super(name, id, toolMaterial); | ||
maxStackSize = 1; | ||
setMaxDamage(toolMaterial.getDurability()); | ||
this.tool = toolMaterial; | ||
this.weaponDamage = 4 + toolMaterial.getDamage(); | ||
|
||
} | ||
@Override | ||
public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer entityplayer) { | ||
itemstack.getData().putBoolean("active", true); | ||
itemstack.getData().putInt("ticks", ticksToAdd); | ||
onBlock(itemstack, world, entityplayer); | ||
|
||
return itemstack; | ||
} | ||
|
||
public void onBlock(ItemStack itemstack, World world, EntityPlayer entityplayer){ | ||
if (entityplayer.isSneaking()){ | ||
((IThrownItem)entityplayer).setThrownItem(itemstack); | ||
entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem,null); | ||
world.playSoundAtEntity(null, entityplayer, "mob.ghast.fireball", 0.3F, 1.0F / (itemRand.nextFloat() * 0.4F + 0.8F)); | ||
if (!world.isClientSide) { | ||
world.entityJoinedWorld(new EntityShield(world, entityplayer)); | ||
itemstack.damageItem(4, entityplayer); | ||
itemstack.getData().putBoolean("active", false); | ||
} | ||
} | ||
} | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/mizurin/shieldmod/mixins/BlockFarmlandMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package mizurin.shieldmod.mixins; | ||
|
||
|
||
import mizurin.shieldmod.item.Shields; | ||
import net.minecraft.core.block.BlockFarmland; | ||
import net.minecraft.core.item.Item; | ||
import net.minecraft.core.item.ItemStack; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Redirect; | ||
|
||
@Mixin(value = BlockFarmland.class, remap = false) | ||
public class BlockFarmlandMixin { | ||
@Redirect(method = "onEntityWalking(Lnet/minecraft/core/world/World;IIILnet/minecraft/core/entity/Entity;)V", | ||
at = @At(value = "INVOKE",target = "Lnet/minecraft/core/item/ItemStack;getItem()Lnet/minecraft/core/item/Item;")) | ||
public Item addCustomBoots(ItemStack instance){ | ||
Item item = instance.getItem(); | ||
if (item == Shields.armorLeatherBoot){ | ||
return Item.armorBootsLeather; | ||
} | ||
return item; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package mizurin.shieldmod.mixins; | ||
import com.mojang.nbt.CompoundTag; | ||
import mizurin.shieldmod.IThrownItem; | ||
import net.minecraft.core.entity.player.EntityPlayer; | ||
import net.minecraft.core.item.ItemStack; | ||
import net.minecraft.core.player.inventory.InventoryPlayer; | ||
import net.minecraft.core.world.chunk.ChunkCoordinates; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.Unique; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
@Mixin(value = EntityPlayer.class, remap = false) | ||
public abstract class FieldMixin implements IThrownItem { | ||
@Shadow | ||
public abstract ChunkCoordinates getLastDeathCoordinate(); | ||
|
||
@Unique | ||
private ItemStack thrownItem; | ||
|
||
@Override | ||
public ItemStack getThrownItem() { | ||
return thrownItem; | ||
} | ||
public void storeOrDropItem(EntityPlayer player, ItemStack stack){ | ||
if(stack == null || stack.stackSize <= 0){ | ||
return; | ||
} | ||
InventoryPlayer inventory = player.inventory; | ||
inventory.insertItem(stack, false); | ||
if (stack.stackSize > 0){ | ||
player.dropPlayerItem(stack); | ||
} | ||
} | ||
|
||
@Override | ||
public ItemStack setThrownItem(ItemStack itemStack) { | ||
this.thrownItem = itemStack; | ||
return itemStack; | ||
} | ||
@Inject(method = "addAdditionalSaveData(Lcom/mojang/nbt/CompoundTag;)V", at = @At("TAIL")) | ||
private void addData(CompoundTag tag, CallbackInfo ci){ | ||
ItemStack thrownItem = getThrownItem(); | ||
if(thrownItem != null) { | ||
tag.putCompound("item", thrownItem.writeToNBT(new CompoundTag())); | ||
} | ||
} | ||
@Inject(method = "readAdditionalSaveData(Lcom/mojang/nbt/CompoundTag;)V", at = @At("TAIL")) | ||
private void loadData(CompoundTag tag, CallbackInfo ci){ | ||
this.thrownItem = ItemStack.readItemStackFromNbt(tag.getCompound("item")); | ||
storeOrDropItem((EntityPlayer)(Object)this, this.thrownItem); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.