Mana blaster bursts now spawn off the correct hand, closes #2609 (also fixes color handler making a new entity every render tick)

This commit is contained in:
Vincent Lee committed 2018-04-22 15:38:43 -05:00
1 parent 7d48d1ffb9
commit c3adac1c04
4 files changed
+19 -11

No files matched your search

@@ -11,11 +11,13 @@ import net.minecraft.item.EnumDyeColor;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumHand;
import net.minecraftforge.fml.relauncher.ReflectionHelper;
import net.minecraftforge.registries.IRegistryDelegate;
import vazkii.botania.api.BotaniaAPI;
import vazkii.botania.api.brew.Brew;
import vazkii.botania.api.brew.IBrewItem;
import vazkii.botania.api.mana.BurstProperties;
import vazkii.botania.api.state.BotaniaStateProps;
import vazkii.botania.api.state.enums.PoolVariant;
import vazkii.botania.api.state.enums.SpreaderVariant;
@@ -142,8 +144,8 @@ public final class ColorHandler {
return Minecraft.getMinecraft().getItemColors().colorMultiplier(lens, t);
if(t == 2) {
EntityManaBurst burst = ((ItemManaGun) s.getItem()).getBurst(Minecraft.getMinecraft().player, s, false);
Color color = new Color(burst == null ? 0x20FF20 : burst.getColor());
BurstProperties props = ((ItemManaGun) s.getItem()).getBurstProps(Minecraft.getMinecraft().player, s, false, EnumHand.MAIN_HAND);
Color color = new Color(props.color);
float mul = (float) (Math.sin((double) ClientTickHandler.ticksInGame / 5) * 0.15F);
int c = (int) (255 * mul);
@@ -37,6 +37,7 @@ import net.minecraft.network.datasync.DataParameter;
import net.minecraft.network.datasync.DataSerializers;
import net.minecraft.network.datasync.EntityDataManager;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumHand;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
@@ -140,15 +141,15 @@ public class EntityManaBurst extends EntityThrowable implements IManaBurst, ILig
setMotion(mx, my, mz);
}
public EntityManaBurst(EntityPlayer player) {
public EntityManaBurst(EntityPlayer player, EnumHand hand) {
this(player.world);
setBurstSourceCoords(new BlockPos(0, -1, 0));
setLocationAndAngles(player.posX, player.posY + player.getEyeHeight(), player.posZ, player.rotationYaw + 180, -player.rotationPitch);
posX -= MathHelper.cos((rotationYaw + 180) / 180.0F * (float) Math.PI) * 0.16F;
posX -= (hand == EnumHand.OFF_HAND ? -1 : 1) * MathHelper.cos((rotationYaw + 180) / 180.0F * (float) Math.PI) * 0.16F;
posY -= 0.10000000149011612D;
posZ -= MathHelper.sin((rotationYaw + 180) / 180.0F * (float) Math.PI) * 0.16F;
posZ -= (hand == EnumHand.OFF_HAND ? -1 : 1) * MathHelper.sin((rotationYaw + 180) / 180.0F * (float) Math.PI) * 0.16F;
setPosition(posX, posY, posZ);
float f = 0.4F;
@@ -84,7 +84,7 @@ public class ItemManaGun extends ItemMod implements IManaUsingItem {
stack.setItemDamage(effCd);
return ActionResult.newResult(EnumActionResult.SUCCESS, stack);
} else if(stack.getItemDamage() == 0) {
EntityManaBurst burst = getBurst(player, stack, true);
EntityManaBurst burst = getBurst(player, stack, true, hand);
if(burst != null && ManaItemHandler.requestManaExact(stack, player, burst.getMana(), true)) {
if(!world.isRemote) {
world.playSound(null, player.posX, player.posY, player.posZ, ModSounds.manaBlaster, SoundCategory.PLAYERS, 0.6F, 1);
@@ -134,9 +134,8 @@ public class ItemManaGun extends ItemMod implements IManaUsingItem {
return getLens(itemStack);
}
public EntityManaBurst getBurst(EntityPlayer player, ItemStack stack, boolean request) {
EntityManaBurst burst = new EntityManaBurst(player);
@Nonnull
public BurstProperties getBurstProps(EntityPlayer player, ItemStack stack, boolean request, EnumHand hand) {
int maxMana = 120;
int color = 0x20FF20;
int ticksBeforeManaLoss = 60;
@@ -148,9 +147,14 @@ public class ItemManaGun extends ItemMod implements IManaUsingItem {
ItemStack lens = getLens(stack);
if(!lens.isEmpty())
((ILens) lens.getItem()).apply(lens, props);
return props;
}
public EntityManaBurst getBurst(EntityPlayer player, ItemStack stack, boolean request, EnumHand hand) {
EntityManaBurst burst = new EntityManaBurst(player, hand);
BurstProperties props = getBurstProps(player, stack, request, hand);
burst.setSourceLens(lens);
burst.setSourceLens(getLens(stack));
if(!request || ManaItemHandler.requestManaExact(stack, player, props.maxMana, false)) {
burst.setColor(props.color);
burst.setMana(props.maxMana);
@@ -15,6 +15,7 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntityThrowable;
import net.minecraft.item.ItemStack;
import net.minecraft.util.DamageSource;
import net.minecraft.util.EnumHand;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.RayTraceResult;
@@ -83,7 +84,7 @@ public class ItemTerraSword extends ItemManasteelSword implements ILensEffect {
}
public EntityManaBurst getBurst(EntityPlayer player, ItemStack stack) {
EntityManaBurst burst = new EntityManaBurst(player);
EntityManaBurst burst = new EntityManaBurst(player, EnumHand.MAIN_HAND);
float motionModifier = 7F;