v1.6.0
This commit is contained in:
1 parent
ebf7da6dd0
commit
e9d4665059
18 files changed
+58
-73
No files matched your search
@@ -3,6 +3,7 @@ package com.lzxnone.terraria.client.event;
|
|||||||
import com.lzxnone.terraria.LzxnoneTerraria;
|
import com.lzxnone.terraria.LzxnoneTerraria;
|
||||||
import com.lzxnone.terraria.item.ModItemTags;
|
import com.lzxnone.terraria.item.ModItemTags;
|
||||||
import com.lzxnone.terraria.item.weapon.RangedWeapon;
|
import com.lzxnone.terraria.item.weapon.RangedWeapon;
|
||||||
|
import net.minecraft.client.gui.Font;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.gui.GuiGraphics;
|
import net.minecraft.client.gui.GuiGraphics;
|
||||||
import net.minecraft.world.entity.HumanoidArm;
|
import net.minecraft.world.entity.HumanoidArm;
|
||||||
@@ -49,7 +50,7 @@ public class RangedWeaponGuiHandler {
|
|||||||
for(int i = 0; i < 9; i++) {
|
for(int i = 0; i < 9; i++) {
|
||||||
ItemStack stack = player.getInventory().items.get(i);
|
ItemStack stack = player.getInventory().items.get(i);
|
||||||
int slotX = centerX - 90 + i * 20 + 2;
|
int slotX = centerX - 90 + i * 20 + 2;
|
||||||
renderSelectedAmmoIcon(guiGraphics, stack, slotX, hotbarY);
|
renderSelectedAmmoIcon(guiGraphics, stack, slotX, hotbarY, player);
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemStack offhandStack = player.getOffhandItem();
|
ItemStack offhandStack = player.getOffhandItem();
|
||||||
@@ -57,7 +58,7 @@ public class RangedWeaponGuiHandler {
|
|||||||
int offhandX = player.getMainArm().getOpposite() == HumanoidArm.LEFT
|
int offhandX = player.getMainArm().getOpposite() == HumanoidArm.LEFT
|
||||||
? centerX - 91 - 26
|
? centerX - 91 - 26
|
||||||
: centerX + 91 + 10;
|
: centerX + 91 + 10;
|
||||||
renderSelectedAmmoIcon(guiGraphics, offhandStack, offhandX, hotbarY);
|
renderSelectedAmmoIcon(guiGraphics, offhandStack, offhandX, hotbarY, player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,7 +71,11 @@ public class RangedWeaponGuiHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void renderSelectedAmmoIcon(GuiGraphics guiGraphics, ItemStack weaponStack, int slotX, int slotY) {
|
private static void renderSelectedAmmoIcon(GuiGraphics guiGraphics, ItemStack weaponStack, int slotX, int slotY) {
|
||||||
if(!(weaponStack.getItem() instanceof RangedWeapon)) return;
|
renderSelectedAmmoIcon(guiGraphics, weaponStack, slotX, slotY, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void renderSelectedAmmoIcon(GuiGraphics guiGraphics, ItemStack weaponStack, int slotX, int slotY, Player player) {
|
||||||
|
if(!(weaponStack.getItem() instanceof RangedWeapon rangedWeapon)) return;
|
||||||
|
|
||||||
ItemStack ammoStack = RangedWeapon.getAmmoStack(weaponStack);
|
ItemStack ammoStack = RangedWeapon.getAmmoStack(weaponStack);
|
||||||
if(ammoStack.isEmpty()) return;
|
if(ammoStack.isEmpty()) return;
|
||||||
@@ -83,5 +88,27 @@ public class RangedWeaponGuiHandler {
|
|||||||
guiGraphics.pose().scale(0.25F, 0.25F, 1.0F);
|
guiGraphics.pose().scale(0.25F, 0.25F, 1.0F);
|
||||||
guiGraphics.renderItem(ammoStack, 0, 0);
|
guiGraphics.renderItem(ammoStack, 0, 0);
|
||||||
guiGraphics.pose().popPose();
|
guiGraphics.pose().popPose();
|
||||||
|
|
||||||
|
if(player != null) {
|
||||||
|
renderAmmoCount(guiGraphics, rangedWeapon, weaponStack, player, x, y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void renderAmmoCount(GuiGraphics guiGraphics, RangedWeapon rangedWeapon,
|
||||||
|
ItemStack weaponStack, Player player, int iconX, int iconY) {
|
||||||
|
int count = rangedWeapon.getAmmoCount(weaponStack, player);
|
||||||
|
String text = Integer.toString(count);
|
||||||
|
Minecraft minecraft = Minecraft.getInstance();
|
||||||
|
Font font = minecraft.font;
|
||||||
|
float scale = 0.75F;
|
||||||
|
int textWidth = font.width(text);
|
||||||
|
float textX = (iconX - 2) / scale - textWidth;
|
||||||
|
float textY = (iconY - 3) / scale;
|
||||||
|
|
||||||
|
guiGraphics.pose().pushPose();
|
||||||
|
guiGraphics.pose().translate(0.0F, 0.0F, 300.0F);
|
||||||
|
guiGraphics.pose().scale(scale, scale, 1.0F);
|
||||||
|
guiGraphics.drawString(font, text, (int) textX, (int) textY, 0xFFFFFF, true);
|
||||||
|
guiGraphics.pose().popPose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -56,8 +56,8 @@ public class AcidVenomEffect extends MobEffect {
|
|||||||
|
|
||||||
public static final DustParticleOptions PARTICLE = new DustParticleOptions(
|
public static final DustParticleOptions PARTICLE = new DustParticleOptions(
|
||||||
0.075f, 0.5f, 40, false, new Vector3f[]{
|
0.075f, 0.5f, 40, false, new Vector3f[]{
|
||||||
new Vector3f(0.0F, 0.0F, 0.0F),
|
new Vector3f(0.12F, 0.0F, 0.18F),
|
||||||
new Vector3f(0.06F, 0.06F, 0.06F)
|
new Vector3f(0.45F, 0.05F, 0.65F)
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -1,54 +0,0 @@
|
|||||||
package com.lzxnone.terraria.item.ammo;
|
|
||||||
|
|
||||||
import com.lzxnone.terraria.entity.summon.IStaticSummonBehavior;
|
|
||||||
import com.lzxnone.terraria.entity.summon.StaticSummon;
|
|
||||||
import com.lzxnone.terraria.utils.CollisionUtil;
|
|
||||||
import com.lzxnone.terraria.utils.DamageUtil;
|
|
||||||
import com.lzxnone.terraria.utils.FilterUtil;
|
|
||||||
import net.minecraft.nbt.CompoundTag;
|
|
||||||
import net.minecraft.world.entity.Entity;
|
|
||||||
import net.minecraft.world.item.ItemStack;
|
|
||||||
import net.minecraft.world.phys.AABB;
|
|
||||||
import net.minecraft.world.phys.BlockHitResult;
|
|
||||||
import net.minecraft.world.phys.HitResult;
|
|
||||||
import net.minecraft.world.phys.Vec3;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public abstract class BasicBulletAmmo extends BulletAmmo {
|
|
||||||
public static IStaticSummonBehavior createSummonBehavior(float baseDamage, double speed) {
|
|
||||||
return new IStaticSummonBehavior() {
|
|
||||||
@Override
|
|
||||||
public void tick(StaticSummon summon) {
|
|
||||||
this.checkBeforeTick(summon);
|
|
||||||
Vec3 motion = summon.getLookAngle().normalize().scale(speed);
|
|
||||||
summon.setDeltaMovement(motion);
|
|
||||||
|
|
||||||
AABB hitBox = new AABB(summon.position(), summon.position().add(motion)).inflate(0.25);
|
|
||||||
List<Entity> targets = summon.level().getEntitiesOfClass(
|
|
||||||
Entity.class,
|
|
||||||
hitBox,
|
|
||||||
FilterUtil.createTargetFilter(summon, summon.getOwner())
|
|
||||||
);
|
|
||||||
if(!targets.isEmpty()) {
|
|
||||||
CompoundTag customData = summon.getEntityData().get(StaticSummon.CUSTOM_DATA);
|
|
||||||
float damage = customData.contains("damage") ? customData.getFloat("damage") : 0;
|
|
||||||
float knockbackScale = customData.contains("knockbackScale") ? customData.getFloat("knockbackScale") : 1.0f;
|
|
||||||
int invulnerableTime = customData.contains("invulnerableTime") ? customData.getInt("invulnerableTime") : 20;
|
|
||||||
|
|
||||||
ItemStack sourceStack = summon.getEntityData().get(StaticSummon.STACK_SOURCE);
|
|
||||||
Entity target = targets.getFirst();
|
|
||||||
if(DamageUtil.rangedAttack(summon, target, sourceStack, baseDamage + damage, knockbackScale)) {
|
|
||||||
target.invulnerableTime = invulnerableTime;
|
|
||||||
this.onDied(summon);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
BlockHitResult blockHitResult = CollisionUtil.checkBlockHit(summon, summon.position().add(motion));
|
|
||||||
if(blockHitResult.getType() != HitResult.Type.MISS) {
|
|
||||||
this.onDied(summon);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -3,7 +3,7 @@ package com.lzxnone.terraria.item.ammo;
|
|||||||
import net.minecraft.world.item.Item;
|
import net.minecraft.world.item.Item;
|
||||||
|
|
||||||
public class BulletAmmo extends Item {
|
public class BulletAmmo extends Item {
|
||||||
public static final int MAX_STACK_SIZE = 9999;
|
public static final int MAX_STACK_SIZE = 99;
|
||||||
|
|
||||||
public BulletAmmo() {
|
public BulletAmmo() {
|
||||||
super(new Item.Properties().stacksTo(MAX_STACK_SIZE));
|
super(new Item.Properties().stacksTo(MAX_STACK_SIZE));
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ import org.joml.Vector3f;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class ChlorophyteBullet extends BasicBulletAmmo {
|
public class ChlorophyteBullet extends BulletAmmo {
|
||||||
public static final String ID = "chlorophyte_bullet";
|
public static final String ID = "chlorophyte_bullet";
|
||||||
public static final float BASE_DAMAGE_DEFAULT = 1.5f;
|
public static final float BASE_DAMAGE_DEFAULT = 1.5f;
|
||||||
public static final double SPEED_DEFAULT = 3.0D;
|
public static final double SPEED_DEFAULT = 3.0D;
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ import org.joml.Vector3f;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class CrystalBullet extends BasicBulletAmmo {
|
public class CrystalBullet extends BulletAmmo {
|
||||||
public static final String ID = "crystal_bullet";
|
public static final String ID = "crystal_bullet";
|
||||||
public static final float BASE_DAMAGE_DEFAULT = 1.2f;
|
public static final float BASE_DAMAGE_DEFAULT = 1.2f;
|
||||||
public static final double SPEED_DEFAULT = 3.0D;
|
public static final double SPEED_DEFAULT = 3.0D;
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ import net.minecraft.world.phys.Vec3;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class CursedBullet extends BasicBulletAmmo {
|
public class CursedBullet extends BulletAmmo {
|
||||||
public static final String ID = "cursed_bullet";
|
public static final String ID = "cursed_bullet";
|
||||||
public static final float BASE_DAMAGE_DEFAULT = 2.0f;
|
public static final float BASE_DAMAGE_DEFAULT = 2.0f;
|
||||||
public static final double SPEED_DEFAULT = 3.0D;
|
public static final double SPEED_DEFAULT = 3.0D;
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ import org.joml.Vector3f;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class ExplodingBullet extends BasicBulletAmmo {
|
public class ExplodingBullet extends BulletAmmo {
|
||||||
public static final String ID = "exploding_bullet";
|
public static final String ID = "exploding_bullet";
|
||||||
public static final float BASE_DAMAGE_DEFAULT = 1.5f;
|
public static final float BASE_DAMAGE_DEFAULT = 1.5f;
|
||||||
public static final double SPEED_DEFAULT = 3.0D;
|
public static final double SPEED_DEFAULT = 3.0D;
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ import net.minecraft.world.phys.Vec3;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class GoldenBullet extends BasicBulletAmmo {
|
public class GoldenBullet extends BulletAmmo {
|
||||||
private static final String CONFIG_TRANSLATION_PREFIX = "lzxnoneterraria.configuration.";
|
private static final String CONFIG_TRANSLATION_PREFIX = "lzxnoneterraria.configuration.";
|
||||||
|
|
||||||
public static final String BASE_DAMAGE_PATH = "ammo.golden_bullet.base_damage";
|
public static final String BASE_DAMAGE_PATH = "ammo.golden_bullet.base_damage";
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ import net.minecraft.world.phys.Vec3;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class HighVelocityBullet extends BasicBulletAmmo {
|
public class HighVelocityBullet extends BulletAmmo {
|
||||||
public static final String ID = "high_velocity_bullet";
|
public static final String ID = "high_velocity_bullet";
|
||||||
public static final float BASE_DAMAGE_DEFAULT = 1.5f;
|
public static final float BASE_DAMAGE_DEFAULT = 1.5f;
|
||||||
public static final double SPEED_DEFAULT = 4.0D;
|
public static final double SPEED_DEFAULT = 4.0D;
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ import net.minecraft.world.phys.Vec3;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class IchorBullet extends BasicBulletAmmo {
|
public class IchorBullet extends BulletAmmo {
|
||||||
public static final String ID = "ichor_bullet";
|
public static final String ID = "ichor_bullet";
|
||||||
public static final float BASE_DAMAGE_DEFAULT = 2.25f;
|
public static final float BASE_DAMAGE_DEFAULT = 2.25f;
|
||||||
public static final double SPEED_DEFAULT = 3.0D;
|
public static final double SPEED_DEFAULT = 3.0D;
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ import net.minecraft.world.phys.Vec3;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class LuminiteBullet extends BasicBulletAmmo {
|
public class LuminiteBullet extends BulletAmmo {
|
||||||
public static final String ID = "luminite_bullet";
|
public static final String ID = "luminite_bullet";
|
||||||
public static final float BASE_DAMAGE_DEFAULT = 3.0f;
|
public static final float BASE_DAMAGE_DEFAULT = 3.0f;
|
||||||
public static final double SPEED_DEFAULT = 3.5D;
|
public static final double SPEED_DEFAULT = 3.5D;
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ import net.minecraft.world.phys.Vec3;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class NanoBullet extends BasicBulletAmmo {
|
public class NanoBullet extends BulletAmmo {
|
||||||
public static final String ID = "nano_bullet";
|
public static final String ID = "nano_bullet";
|
||||||
public static final float BASE_DAMAGE_DEFAULT = 2.5f;
|
public static final float BASE_DAMAGE_DEFAULT = 2.5f;
|
||||||
public static final double SPEED_DEFAULT = 3.0D;
|
public static final double SPEED_DEFAULT = 3.0D;
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ import net.minecraft.world.phys.Vec3;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class PartyBullet extends BasicBulletAmmo {
|
public class PartyBullet extends BulletAmmo {
|
||||||
public static final String ID = "party_bullet";
|
public static final String ID = "party_bullet";
|
||||||
public static final float BASE_DAMAGE_DEFAULT = 1.5f;
|
public static final float BASE_DAMAGE_DEFAULT = 1.5f;
|
||||||
public static final double SPEED_DEFAULT = 3.0D;
|
public static final double SPEED_DEFAULT = 3.0D;
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ import net.minecraft.world.phys.Vec3;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class SilverBullet extends BasicBulletAmmo {
|
public class SilverBullet extends BulletAmmo {
|
||||||
private static final String CONFIG_TRANSLATION_PREFIX = "lzxnoneterraria.configuration.";
|
private static final String CONFIG_TRANSLATION_PREFIX = "lzxnoneterraria.configuration.";
|
||||||
|
|
||||||
public static final String BASE_DAMAGE_PATH = "ammo.silver_bullet.base_damage";
|
public static final String BASE_DAMAGE_PATH = "ammo.silver_bullet.base_damage";
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ import net.minecraft.world.phys.Vec3;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class TungstenBullet extends BasicBulletAmmo {
|
public class TungstenBullet extends BulletAmmo {
|
||||||
private static final String CONFIG_TRANSLATION_PREFIX = "lzxnoneterraria.configuration.";
|
private static final String CONFIG_TRANSLATION_PREFIX = "lzxnoneterraria.configuration.";
|
||||||
|
|
||||||
public static final String BASE_DAMAGE_PATH = "ammo.tungsten_bullet.base_damage";
|
public static final String BASE_DAMAGE_PATH = "ammo.tungsten_bullet.base_damage";
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ import net.minecraft.world.phys.Vec3;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class VenomBullet extends BasicBulletAmmo {
|
public class VenomBullet extends BulletAmmo {
|
||||||
public static final String ID = "venom_bullet";
|
public static final String ID = "venom_bullet";
|
||||||
public static final float BASE_DAMAGE_DEFAULT = 2.5f;
|
public static final float BASE_DAMAGE_DEFAULT = 2.5f;
|
||||||
public static final double SPEED_DEFAULT = 3.0D;
|
public static final double SPEED_DEFAULT = 3.0D;
|
||||||
|
|||||||
@@ -82,6 +82,18 @@ public class RangedWeapon extends Weapon {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getAmmoCount(ItemStack weaponStack, Player player) {
|
||||||
|
ItemStack ammoStack = getAmmoStack(weaponStack);
|
||||||
|
if(ammoStack.isEmpty() || !canUseAmmo(weaponStack, ammoStack)) return 0;
|
||||||
|
|
||||||
|
Item ammoItem = ammoStack.getItem();
|
||||||
|
int count = 0;
|
||||||
|
for(ItemStack inventoryStack : player.getInventory().items) {
|
||||||
|
if(inventoryStack.is(ammoItem)) count += inventoryStack.getCount();
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean consumeAmmo(ItemStack weaponStack, Player player, int amount) {
|
public boolean consumeAmmo(ItemStack weaponStack, Player player, int amount) {
|
||||||
if(amount <= 0 || player.hasInfiniteMaterials()) return true;
|
if(amount <= 0 || player.hasInfiniteMaterials()) return true;
|
||||||
if(shouldSkipAmmoConsume(weaponStack, player)) return true;
|
if(shouldSkipAmmoConsume(weaponStack, player)) return true;
|
||||||
|
|||||||
Reference in new issue
Block a user