Skip to content

Commit

Permalink
New animation for Crossbow + Broke it -.-
Browse files Browse the repository at this point in the history
  • Loading branch information
ThexXTURBOXx committed Apr 16, 2016
1 parent d4b53d4 commit a6699fc
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 45 deletions.
19 changes: 8 additions & 11 deletions java/org/silvercatcher/reforged/api/AReloadable.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@ public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPl

byte loadState = compound.getByte(CompoundTags.AMMUNITION);

if(loadState == empty && worldIn.isRemote) {
if(playerIn.inventory.consumeInventoryItem(getAmmo())) {
if(loadState == empty) {
if(playerIn.capabilities.isCreativeMode || playerIn.inventory.consumeInventoryItem(getAmmo())) {

loadState = loading;
compound.setInteger(CompoundTags.RELOAD, playerIn.ticksExisted + getReloadTotal());
if(compound.getByte(CompoundTags.AMMUNITION) == empty) compound.setInteger(CompoundTags.STARTED, playerIn.ticksExisted + getReloadTotal());
if(compound.getByte(CompoundTags.AMMUNITION) == empty && worldIn.isRemote) compound.setInteger(CompoundTags.STARTED, playerIn.ticksExisted + getReloadTotal());
} else {

worldIn.playSoundAtEntity(playerIn, "item.fireCharge.use", 1.0f, 0.7f);
Expand All @@ -110,15 +110,12 @@ public void onPlayerStoppedUsing(ItemStack stack, World worldIn, EntityPlayer pl

worldIn.playSoundAtEntity(playerIn, "ambient.weather.thunder", 1f, 1f);

if(!worldIn.isRemote) {

shoot(worldIn, playerIn, stack);
if(!playerIn.capabilities.isCreativeMode && (stack.getItem().isDamageable() && stack.attemptDamageItem(5, itemRand))) {
playerIn.renderBrokenItemStack(stack);
playerIn.destroyCurrentEquippedItem();
}

shoot(worldIn, playerIn, stack);
if(!playerIn.capabilities.isCreativeMode && stack.getItem().isDamageable() && stack.attemptDamageItem(5, itemRand)) {
playerIn.renderBrokenItemStack(stack);
playerIn.destroyCurrentEquippedItem();
}

compound.setByte(CompoundTags.AMMUNITION, empty);
compound.setInteger(CompoundTags.RELOAD, -1);
compound.setInteger(CompoundTags.STARTED, -1);
Expand Down
48 changes: 23 additions & 25 deletions java/org/silvercatcher/reforged/items/weapons/ItemCrossbow.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.silvercatcher.reforged.items.weapons;

import java.util.List;
import java.util.Random;

import org.silvercatcher.reforged.ReforgedMod;
import org.silvercatcher.reforged.api.CompoundTags;
Expand All @@ -12,10 +13,10 @@
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntityArrow;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.EnumAction;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBow;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
Expand All @@ -25,8 +26,6 @@

public class ItemCrossbow extends ItemBow implements ItemExtension {

private Item ammo = ReforgedAdditions.CROSSBOW;

public ItemCrossbow() {
setMaxStackSize(1);
setMaxDamage(100);
Expand Down Expand Up @@ -84,8 +83,7 @@ public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPl
byte loadState = compound.getByte(CompoundTags.AMMUNITION);

if(loadState == empty && worldIn.isRemote) {
if(playerIn.inventory.consumeInventoryItem(ammo)) {

if(playerIn.capabilities.isCreativeMode || playerIn.inventory.consumeInventoryItem(ReforgedAdditions.CROSSBOW_BOLT)) {
loadState = loading;
compound.setInteger(CompoundTags.RELOAD, playerIn.ticksExisted + getReloadTotal());
if(compound.getByte(CompoundTags.AMMUNITION) == empty) compound.setInteger(CompoundTags.STARTED, playerIn.ticksExisted + getReloadTotal());
Expand All @@ -104,38 +102,35 @@ public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPl

@Override
public void onPlayerStoppedUsing(ItemStack stack, World worldIn, EntityPlayer playerIn, int timeLeft) {

NBTTagCompound compound = giveCompound(stack);

byte loadState = compound.getByte(CompoundTags.AMMUNITION);

if(loadState == loaded) {
if(worldIn.isRemote) {

worldIn.playSoundAtEntity(playerIn, "reforged:crossbow_shoot", 1f, 1f);

if(!worldIn.isRemote) {
NBTTagCompound compound = giveCompound(stack);

byte loadState = compound.getByte(CompoundTags.AMMUNITION);
if(loadState == loaded) {

worldIn.playSoundAtEntity(playerIn, "reforged:crossbow_shoot", 1f, 1f);
shoot(worldIn, playerIn, stack);
if(!playerIn.capabilities.isCreativeMode && (stack.getItem().isDamageable() && stack.attemptDamageItem(5, itemRand))) {
playerIn.renderBrokenItemStack(stack);
playerIn.destroyCurrentEquippedItem();
}
}
compound.setByte(CompoundTags.AMMUNITION, empty);
compound.setInteger(CompoundTags.RELOAD, -1);
compound.setInteger(CompoundTags.STARTED, -1);
compound.setByte(CompoundTags.AMMUNITION, empty);
compound.setInteger(CompoundTags.RELOAD, -1);
compound.setInteger(CompoundTags.STARTED, -1);
}
}
}

public void shoot(World worldIn, EntityLivingBase playerIn, ItemStack stack) {

EntityArrow a = new EntityArrow(worldIn, playerIn, 2.1F);
a.canBePickedUp = new Random().nextInt(2);
worldIn.spawnEntityInWorld(a);
}

@Override
public ItemStack onItemUseFinish(ItemStack stack, World worldIn, EntityPlayer playerIn) {

byte loadState = giveCompound(stack).getByte(CompoundTags.AMMUNITION);

if(loadState == loading) {
loadState = loaded;
}
Expand Down Expand Up @@ -170,14 +165,17 @@ public Multimap getAttributeModifiers(ItemStack stack) {
@Override
public ModelResourceLocation getModel(ItemStack stack, EntityPlayer player, int useRemaining) {
ModelResourceLocation mrl = new ModelResourceLocation(ReforgedMod.ID + ":crossbow", "inventory");
if(stack.getItem() == this && player.getItemInUse() != null && getLoadState(stack) != empty) {
if(stack.getItem() == this && player.getItemInUse() != null) {
if(getLoadState(stack) == loading) {
int left = getReloadLeft(stack, player);
System.out.println("left: " + left);
if(left > 0) {
if(left > 10) {
mrl = new ModelResourceLocation(ReforgedMod.ID + ":crossbow_1", "inventory");
} else {
} else if(left > 0) {
mrl = new ModelResourceLocation(ReforgedMod.ID + ":crossbow_2", "inventory");
} else if(left > -10) {
mrl = new ModelResourceLocation(ReforgedMod.ID + ":crossbow_4", "inventory");
} else {
mrl = new ModelResourceLocation(ReforgedMod.ID + ":crossbow_5", "inventory");
}
} else if(getLoadState(stack) == loaded) {
mrl = new ModelResourceLocation(ReforgedMod.ID + ":crossbow_3", "inventory");
Expand Down
15 changes: 7 additions & 8 deletions java/org/silvercatcher/reforged/proxy/ClientProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ protected void registerItemRenderers() {
String inventory = "inventory";

if(GlobalValues.CROSSBOW) {
ModelBakery.addVariantName(ReforgedAdditions.CROSSBOW, new String[] {ReforgedMod.ID + ":crossbow",
ReforgedMod.ID + ":crossbow_1", ReforgedMod.ID + ":crossbow_2", ReforgedMod.ID + ":crossbow_3"});
ModelBakery.addVariantName(ReforgedAdditions.CROSSBOW, new String[] {ReforgedMod.ID + ":crossbow",
ReforgedMod.ID + ":crossbow_1", ReforgedMod.ID + ":crossbow_2", ReforgedMod.ID + ":crossbow_3",
ReforgedMod.ID + ":crossbow_4", ReforgedMod.ID + ":crossbow_5"});
}

for(Item item : ReforgedRegistry.registrationList) {
Expand All @@ -80,12 +81,10 @@ protected void registerItemRenderers() {
}

if(GlobalValues.CROSSBOW) {
mesher.register(ReforgedAdditions.CROSSBOW, 1, new ModelResourceLocation(ReforgedMod.ID + ":"
+ "crossbow_1"));
mesher.register(ReforgedAdditions.CROSSBOW, 2, new ModelResourceLocation(ReforgedMod.ID + ":"
+ "crossbow_2"));
mesher.register(ReforgedAdditions.CROSSBOW, 3, new ModelResourceLocation(ReforgedMod.ID + ":"
+ "crossbow_3"));
for(int i = 1; i <= 5; i++) {
mesher.register(ReforgedAdditions.CROSSBOW, i, new ModelResourceLocation(ReforgedMod.ID + ":"
+ "crossbow_" + i));
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion resources/assets/reforged/models/item/crossbow_3.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"parent": "reforged:item/crossbow",
"textures": {
"layer0": "reforged:items/crossbow_1"
"layer0": "reforged:items/crossbow_4"
}
}
6 changes: 6 additions & 0 deletions resources/assets/reforged/models/item/crossbow_4.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "reforged:item/crossbow_1",
"textures": {
"layer0": "reforged:items/crossbow_2"
}
}
6 changes: 6 additions & 0 deletions resources/assets/reforged/models/item/crossbow_5.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "reforged:item/crossbow_1",
"textures": {
"layer0": "reforged:items/crossbow_3"
}
}

0 comments on commit a6699fc

Please sign in to comment.