From b699454975385c6f395dd1b124cb3a811f86102e Mon Sep 17 00:00:00 2001 From: huige <61108540+huige233@users.noreply.github.com> Date: Sun, 4 Sep 2022 22:14:26 +0800 Subject: [PATCH] An epic enhancement --- .../transcend/compat/tinkers/TiCConfig.java | 4 +- .../transcend/items/armor/ArmorBase.java | 35 ++++++-- .../transcend/items/tools/ToolPickaxe.java | 9 +- .../transcend/items/tools/ToolSword.java | 83 ++++++++++++------- .../huige233/transcend/proxy/CommonProxy.java | 4 +- .../huige233/transcend/util/SwordUtil.java | 68 +++++++++++++++ .../assets/transcend/lang/en_US.lang | 2 +- .../assets/transcend/lang/zh_CN.lang | 2 +- 8 files changed, 164 insertions(+), 43 deletions(-) create mode 100644 src/main/java/huige233/transcend/util/SwordUtil.java diff --git a/src/main/java/huige233/transcend/compat/tinkers/TiCConfig.java b/src/main/java/huige233/transcend/compat/tinkers/TiCConfig.java index aff6c18..729c1c8 100644 --- a/src/main/java/huige233/transcend/compat/tinkers/TiCConfig.java +++ b/src/main/java/huige233/transcend/compat/tinkers/TiCConfig.java @@ -29,7 +29,7 @@ public class TiCConfig { public static final AbstractTrait flawlesstrait = new TraitFlawless(); public static final AbstractTrait transcendtratt = new TraitTranscend(); public static final List materials = Lists.newArrayList(); - public static Material flawless = mat("flawless", 0xfffff); + public static Material flawless = mat("flawless", 0x777777); public static final Material transcend = mat("transcend",0x9e9e9e9); private static Material mat(String name, int color) { if (TinkerRegistry.getMaterial(name) == TinkerRegistry.getMaterial("unknown")){ @@ -109,7 +109,7 @@ public void postInit(FMLPostInitializationEvent event) { @SideOnly(Side.CLIENT) static void registerMaterialRendering() { - flawless.setRenderInfo(new MaterialRenderInfo.Metal(0xffffff, 0.5f, 0.5f, 0.2f)); + flawless.setRenderInfo(new MaterialRenderInfo.Metal(0x777777, 0.5f, 0.5f, 0.2f)); transcend.setRenderInfo(new MaterialRenderInfo.Metal(0x9e9e9e, 0.5f, 0.5f, 0.2f)); } } diff --git a/src/main/java/huige233/transcend/items/armor/ArmorBase.java b/src/main/java/huige233/transcend/items/armor/ArmorBase.java index 08a8d0c..42e08ec 100644 --- a/src/main/java/huige233/transcend/items/armor/ArmorBase.java +++ b/src/main/java/huige233/transcend/items/armor/ArmorBase.java @@ -24,9 +24,12 @@ import net.minecraft.item.Item; import net.minecraft.item.ItemArmor; import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.potion.PotionEffect; +import net.minecraft.util.EnumHand; import net.minecraft.util.NonNullList; import net.minecraft.world.World; +import net.minecraftforge.client.event.RenderPlayerEvent; import net.minecraftforge.event.entity.living.LivingAttackEvent; import net.minecraftforge.event.entity.living.LivingDeathEvent; import net.minecraftforge.event.entity.living.LivingHurtEvent; @@ -140,16 +143,36 @@ public void onArmorTick(@NotNull World world, @NotNull EntityPlayer player, @Not if(player.isBurning()) { player.extinguish(); } - } else if (ArmorUtils.fullEquipped(player)) { - if(!player.world.isRemote) { - Multimap attributes = HashMultimap.create(); - if(attributes.isEmpty()) return; - player.setEntityInvulnerable(true); - player.setHealth(player.getMaxHealth()); + } + if (ArmorUtils.fullEquipped(player)) { + player.setEntityInvulnerable(true); + player.setHealth(player.getMaxHealth()); + if(player.getHeldItemMainhand().getItem()==ModItems.TRANSCEND_SWORD){ + if(!ItemNBTHelper.getBoolean(player.getHeldItem(EnumHand.MAIN_HAND),"Invul",false)){ + ItemNBTHelper.setBoolean(player.getHeldItem(EnumHand.MAIN_HAND),"Invul",true); + } + } + } else if(!ArmorUtils.fullEquipped(player)) { + if (player.getHeldItem(EnumHand.MAIN_HAND).getItem() == ModItems.TRANSCEND_SWORD) { + if (ItemNBTHelper.getBoolean(player.getHeldItem(EnumHand.MAIN_HAND), "Invul", false)) { + NonNullList armor = player.inventory.armorInventory; + armor.set(3, new ItemStack(ModItems.FLAWLESS_HELMET)); + armor.set(2, new ItemStack(ModItems.FLAWLESS_CHESTPLATE)); + armor.set(1, new ItemStack(ModItems.FLAWLESS_LEGGINGS)); + armor.set(0, new ItemStack(ModItems.FLAWLESS_BOOTS)); + } } } } + @SubscribeEvent + public void onPlayerRender(RenderPlayerEvent.Pre event){ + EntityPlayer player = event.getEntityPlayer(); + if(ArmorUtils.fullEquipped(player)){ + event.setCanceled(true); + } + } + @Override public Multimap getAttributeModifiers(EntityEquipmentSlot slot, ItemStack stack) { Multimap attrib = super.getAttributeModifiers(slot, stack); diff --git a/src/main/java/huige233/transcend/items/tools/ToolPickaxe.java b/src/main/java/huige233/transcend/items/tools/ToolPickaxe.java index ffa7caa..ccd9c2a 100644 --- a/src/main/java/huige233/transcend/items/tools/ToolPickaxe.java +++ b/src/main/java/huige233/transcend/items/tools/ToolPickaxe.java @@ -9,8 +9,6 @@ import huige233.transcend.util.ArmorUtils; import huige233.transcend.util.IHasModel; import huige233.transcend.util.Reference; -import morph.avaritia.handler.AvaritiaEventHandler; -import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.enchantment.EnchantmentHelper; @@ -26,7 +24,6 @@ import net.minecraft.item.Item; import net.minecraft.item.ItemPickaxe; import net.minecraft.item.ItemStack; -import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ActionResult; import net.minecraft.util.EnumActionResult; import net.minecraft.util.EnumHand; @@ -35,6 +32,9 @@ import net.minecraft.util.text.translation.I18n; import net.minecraft.world.World; import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.common.gameevent.TickEvent.ClientTickEvent; +import net.minecraftforge.fml.common.gameevent.TickEvent.Phase; import java.util.Random; import java.util.UUID; @@ -49,6 +49,8 @@ public ToolPickaxe(String name, CreativeTabs tab, ToolMaterial material) { ModItems.ITEMS.add(this); } + private int tick = 0; + @Override public void registerModels() { Main.proxy.registerItemRenderer(this, 0, "inventory"); @@ -68,6 +70,7 @@ public ActionResult onItemRightClick(World world, EntityPlayer player return new ActionResult(EnumActionResult.PASS, stack); } + @Override public boolean onBlockStartBreak(ItemStack stack, BlockPos pos, EntityPlayer player) { World world = player.world; diff --git a/src/main/java/huige233/transcend/items/tools/ToolSword.java b/src/main/java/huige233/transcend/items/tools/ToolSword.java index 740774e..892e5e9 100644 --- a/src/main/java/huige233/transcend/items/tools/ToolSword.java +++ b/src/main/java/huige233/transcend/items/tools/ToolSword.java @@ -7,6 +7,7 @@ import huige233.transcend.items.fireimmune; import huige233.transcend.lib.TranscendDamageSources; import huige233.transcend.util.*; +import net.minecraft.client.Minecraft; import net.minecraft.client.util.ITooltipFlag; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.Entity; @@ -19,26 +20,23 @@ import net.minecraft.item.ItemStack; import net.minecraft.item.ItemSword; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ActionResult; import net.minecraft.util.EntityDamageSource; import net.minecraft.util.EnumHand; import net.minecraft.util.NonNullList; +import net.minecraft.util.text.TextComponentTranslation; import net.minecraft.util.text.TextFormatting; import net.minecraft.util.text.translation.I18n; import net.minecraft.world.World; -import net.minecraftforge.event.entity.living.LivingSetAttackTargetEvent; import net.minecraftforge.event.entity.player.ItemTooltipEvent; import net.minecraftforge.fml.common.Loader; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Optional; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.common.gameevent.TickEvent.ClientTickEvent; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; import org.jetbrains.annotations.NotNull; -import vazkii.botania.api.mana.ICreativeManaProvider; -import vazkii.botania.api.mana.IManaItem; -import vazkii.botania.api.mana.IManaTooltipDisplay; import java.util.List; import java.util.UUID; @@ -66,11 +64,13 @@ public ToolSword(String name, CreativeTabs tab, ToolMaterial material) { } public void getSubItems(@NotNull CreativeTabs tab, @NotNull NonNullList stack) { - if(tab == Main.TranscendTab && Loader.isModLoaded("botania")) { - ItemStack create = new ItemStack(ModItems.TRANSCEND_SWORD); - setMana(create, MAX_MANA); - setStackCreative(create); - stack.add(create); + if(tab == Main.TranscendTab){ + if(Loader.isModLoaded("botania")) { + ItemStack create = new ItemStack(ModItems.TRANSCEND_SWORD); + setMana(create, MAX_MANA); + setStackCreative(create); + stack.add(create); + } } } @@ -85,6 +85,20 @@ public boolean hasEffect(@NotNull ItemStack par1ItemStack) { return false; } + @SubscribeEvent + public void onClientTick(ClientTickEvent event){ + EntityPlayer player = Minecraft.getMinecraft().player; + if(ArmorUtils.fullEquipped(player)){ + if(player.isDead){ + player.isDead=false; + } + if(!player.world.playerEntities.contains(player)){ + player.world.playerEntities.add(player); + player.world.onEntityAdded(player); + } + } + } + public boolean hitEntity(@NotNull ItemStack stack, @NotNull EntityLivingBase target, EntityLivingBase player) { if (!player.world.isRemote) { if (target instanceof EntityPlayer) { @@ -119,45 +133,58 @@ public boolean hitEntity(@NotNull ItemStack stack, @NotNull EntityLivingBase tar @Override public boolean onLeftClickEntity(@NotNull ItemStack stack, @NotNull EntityPlayer player, Entity entity) { if(!entity.world.isRemote) { - if(ItemNBTHelper.getBoolean(stack, "Destruction", false)) { - entity.setEntityInvulnerable(false); - entity.onKillCommand(); - entity.isDead = true; - entity.hurtResistantTime=0;; - } if(entity instanceof EntityPlayer) { EntityPlayer t = (EntityPlayer) entity; - if(t.capabilities.isCreativeMode && !t.isDead && !ArmorUtils.fullEquipped(t)) { + if(!ArmorUtils.fullEquipped(t)) { + t.clearActivePotions(); t.inventory.dropAllItems(); t.attackEntityFrom((new TranscendDamageSources(player)).setDamageAllowedInCreativeMode().setDamageBypassesArmor().setDamageIsAbsolute(), Float.MAX_VALUE); t.setHealth(0); t.onDeath(new EntityDamageSource("transcend", player)); - return true; + } else { + EntityLivingBase en = (EntityLivingBase) entity; + en.setHealth(0.0f); + en.clearActivePotions(); + en.attackEntityFrom((new TranscendDamageSources(player)).setDamageAllowedInCreativeMode().setDamageBypassesArmor().setDamageIsAbsolute(), Float.MAX_VALUE); + en.onDeath(new EntityDamageSource("transcend",player)); } } + if(ItemNBTHelper.getBoolean(stack, "Destruction", false)) { + if(entity instanceof EntityPlayer){ + SwordUtil.killPlayer((EntityPlayer) entity,player); + } else if (entity instanceof EntityLivingBase) { + SwordUtil.killEntityLiving((EntityLivingBase) entity,player); + } else{ + SwordUtil.killEntity(entity); + } + entity.onKillCommand(); + } } return false; } + + @Override public @NotNull ActionResult onItemRightClick(@NotNull World world, EntityPlayer player, @NotNull EnumHand hand) { ItemStack stack = player.getHeldItem(hand); - if(player.isSneaking()) { - NBTTagCompound tags = stack.getTagCompound(); - boolean destruction = ItemNBTHelper.getBoolean(stack,"Destruction",false); - if(tags == null) { - ItemNBTHelper.setBoolean(stack,"Destruction",false); - stack.setStackDisplayName(TextFormatting.RED + stack.getDisplayName()); - } else { - if(!destruction) { - ItemNBTHelper.setBoolean(stack,"Destruction",true); + if(!world.isRemote) { + if (!player.isSneaking()) { + boolean destruction = ItemNBTHelper.getBoolean(stack, "Destruction", false); + if (!destruction) { + ItemNBTHelper.setBoolean(stack, "Destruction", true); stack.setStackDisplayName(TextFormatting.RED + I18n.translateToLocal("item.transcend.sword.destruction.name")); player.swingArm(hand); } else { - ItemNBTHelper.setBoolean(stack,"Destruction",false); + ItemNBTHelper.setBoolean(stack, "Destruction", false); stack.setStackDisplayName(TextFormatting.RED + I18n.translateToLocal("item.transcend_sword.name")); player.swingArm(hand); } + } else if (player.isSneaking()) { + if (ItemNBTHelper.getBoolean(stack, "Destruction", false)) { + int count = SwordUtil.killRangeEntity(world, player); + player.sendMessage(new TextComponentTranslation("transcend.sword.ranger_kill", 50, count)); + } } } return super.onItemRightClick(world, player, hand); diff --git a/src/main/java/huige233/transcend/proxy/CommonProxy.java b/src/main/java/huige233/transcend/proxy/CommonProxy.java index 86e4150..523f5c5 100644 --- a/src/main/java/huige233/transcend/proxy/CommonProxy.java +++ b/src/main/java/huige233/transcend/proxy/CommonProxy.java @@ -19,9 +19,9 @@ public void registerItemRenderer( Item item, int meta, String id ) public void preInit( FMLPreInitializationEvent event ) { if(Loader.isModLoaded("tconstruct")){ - TiCConfig.setup(); - } + TiCConfig.setup(); } + } public void init( FMLInitializationEvent event ) diff --git a/src/main/java/huige233/transcend/util/SwordUtil.java b/src/main/java/huige233/transcend/util/SwordUtil.java new file mode 100644 index 0000000..625c458 --- /dev/null +++ b/src/main/java/huige233/transcend/util/SwordUtil.java @@ -0,0 +1,68 @@ +package huige233.transcend.util; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityCreature; +import net.minecraft.entity.EntityLiving; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.item.EntityArmorStand; +import net.minecraft.entity.monster.EntityMob; +import net.minecraft.entity.passive.EntityAmbientCreature; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.InventoryEnderChest; +import net.minecraft.item.ItemStack; +import net.minecraft.util.DamageSource; +import net.minecraft.util.EntityDamageSource; +import net.minecraft.util.EnumHand; +import net.minecraft.util.math.AxisAlignedBB; +import net.minecraft.world.World; + +import java.util.List; + +public class SwordUtil { + public static void killPlayer(EntityPlayer player, EntityLivingBase source){ + ItemStack stack = source.getHeldItem(EnumHand.MAIN_HAND); + player.inventory.clearMatchingItems(null,-1,-1,null); + InventoryEnderChest ec = player.getInventoryEnderChest(); + for(int i = 0;i < ec.getSizeInventory();i++){ + ec.removeStackFromSlot(i); + } + player.inventory.dropAllItems(); + DamageSource ds = source == null ? new DamageSource("infinity") :new EntityDamageSource("infinity",source); + DamageSource ds1 = source == null ? new DamageSource("transcend") :new EntityDamageSource("transcend",source); + player.getCombatTracker().trackDamage(ds,Float.MIN_VALUE,Float.MAX_VALUE); + player.getCombatTracker().trackDamage(ds1,Float.MIN_VALUE,Float.MAX_VALUE); + player.setHealth(0.0f); + player.onDeath(ds); + player.isDead=true; + } + public static void killEntityLiving(EntityLivingBase entity,EntityLivingBase source){ + if(!(entity.world.isRemote || entity.isDead || entity.getHealth()==0.0f)){ + entity.setEntityInvulnerable(false); + DamageSource ds = source == null ? new DamageSource("infinity") :new EntityDamageSource("infinity",source); + DamageSource ds1 = source == null ? new DamageSource("transcend") :new EntityDamageSource("transcend",source); + entity.getCombatTracker().trackDamage(ds,Float.MAX_VALUE,Float.MAX_VALUE); + entity.getCombatTracker().trackDamage(ds1,Float.MIN_VALUE,Float.MAX_VALUE); + entity.setHealth(0.0f); + entity.isDead=true; + } + } + public static void killEntity(Entity entity){ + entity.setDead(); + } + public static int killRangeEntity(World world,EntityLivingBase entity){ + int range = 50; + List list = world.getEntitiesWithinAABB(EntityLivingBase.class,new AxisAlignedBB(entity.posX - range, entity.posY - range, entity.posZ - range, entity.posX + range, entity.posY + range, entity.posZ + range)); + list.removeIf(en -> en instanceof EntityPlayer || en instanceof EntityArmorStand || en instanceof EntityAmbientCreature || (en instanceof EntityCreature && !(en instanceof EntityMob))); + list.remove(entity); + for(Entity en : list) { + if(en instanceof EntityPlayer){ + killPlayer((EntityPlayer) en,entity); + }else if(en instanceof EntityLivingBase){ + killEntityLiving((EntityLivingBase) en,entity); + } else { + killEntity((Entity) en); + } + } + return list.size(); + } +} diff --git a/src/main/resources/assets/transcend/lang/en_US.lang b/src/main/resources/assets/transcend/lang/en_US.lang index 6f80b80..315d0f4 100644 --- a/src/main/resources/assets/transcend/lang/en_US.lang +++ b/src/main/resources/assets/transcend/lang/en_US.lang @@ -44,7 +44,7 @@ tooltip.warp_sword1.desc=Should need Thaumcraft can use it tooltip.warp_sword2.desc=Warp Power has been unsealed tooltip.invulnerable=This tool can modify entity invincible attribute, hit entity will be invincible/uninvincible tooltip.TimeStop=This tool can Stop the entity time,hit entity will be stop/unstop it time - +transcend.sword.ranger_kill=Dealt a critical blow to %2$d creatures in %1$d blocks message.bedrock_ore_failed= "You failed to break the bedrock" death.attack.transcend=%s A power beyond all things will wipe you out diff --git a/src/main/resources/assets/transcend/lang/zh_CN.lang b/src/main/resources/assets/transcend/lang/zh_CN.lang index d0e7846..77953ef 100644 --- a/src/main/resources/assets/transcend/lang/zh_CN.lang +++ b/src/main/resources/assets/transcend/lang/zh_CN.lang @@ -45,7 +45,7 @@ tooltip.warp_sword2.desc=扭曲的力量已经解封 tooltip.invulnerable=本工具可以修改实体的无敌属性,被击中的实体将会无敌/取消无敌 tooltip.TimeStop=This tool can Stop the entity time,hit entity will be stop/unstop it time message.bedrock_ore_failed="挖掘基岩矿石失败" - +transcend.sword.ranger_kill=对%1$d方块内的%2$d个生物造成了致命打击 death.attack.transcend=%s被超越万物的力量粉碎 tip.transcend=Infinity container.cast_machine=基岩冶炼厂