diff --git a/build.gradle b/build.gradle index 59a49f2..2bf04d9 100644 --- a/build.gradle +++ b/build.gradle @@ -11,7 +11,7 @@ apply plugin: 'net.minecraftforge.gradle.forge' //Only edit below this line, the above code adds and enables the necessary things for Forge to be setup. -version = "1.1.0" +version = "1.1.1" group = "shnupbups.tinkersaether" // http://maven.apache.org/guides/mini/guide-naming-conventions.html archivesBaseName = "tinkersaether" diff --git a/src/main/java/shnupbups/tinkersaether/TinkersAether.java b/src/main/java/shnupbups/tinkersaether/TinkersAether.java index 54a12a9..8feb2e1 100644 --- a/src/main/java/shnupbups/tinkersaether/TinkersAether.java +++ b/src/main/java/shnupbups/tinkersaether/TinkersAether.java @@ -10,14 +10,19 @@ import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.common.network.NetworkRegistry; +import net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper; import net.minecraftforge.fml.common.registry.EntityEntry; import net.minecraftforge.fml.common.registry.EntityRegistry; +import net.minecraftforge.fml.relauncher.Side; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import shnupbups.tinkersaether.config.TAConfig; import shnupbups.tinkersaether.entities.EntityDart; import shnupbups.tinkersaether.misc.MiscUtils; import shnupbups.tinkersaether.modules.ModuleBase; +import shnupbups.tinkersaether.network.HandlerExtendedAttack; +import shnupbups.tinkersaether.network.MessageExtendedAttack; import shnupbups.tinkersaether.proxy.CommonProxy; import slimeknights.tconstruct.library.materials.BowMaterialStats; import slimeknights.tconstruct.tools.TinkerMaterials; @@ -26,7 +31,7 @@ public class TinkersAether { public static final String modid = "tinkersaether"; public static final String name = "MoreTiC"; - public static final String version = "1.1.0"; + public static final String version = "1.1.1"; @Mod.Instance(modid) public static TinkersAether instance; @@ -34,6 +39,8 @@ public class TinkersAether { @SidedProxy(serverSide = "shnupbups.tinkersaether.proxy.CommonProxy", clientSide = "shnupbups.tinkersaether.proxy.ClientProxy") public static CommonProxy proxy; + public static SimpleNetworkWrapper network = NetworkRegistry.INSTANCE.newSimpleChannel(modid+"network"); + public static final Logger logger = LogManager.getLogger(modid); public static BowMaterialStats plzNo = new BowMaterialStats(0.2f, 0.4f, -1f); @@ -45,16 +52,19 @@ public TinkersAether() { @Mod.EventHandler public void preInit(FMLPreInitializationEvent event) { - ModuleBase.aether.preInit(); + ModuleBase.base.preInit(); } @Mod.EventHandler public void init(FMLInitializationEvent event) { + int packet = 0; + network.registerMessage(HandlerExtendedAttack.class,MessageExtendedAttack.class, packet++, Side.SERVER); + if(TAConfig.darts) { proxy.initToolGuis(); } - ModuleBase.aether.init(); + ModuleBase.base.init(); if(TAConfig.skyroot) { MiscUtils.displace(TinkerMaterials.wood.getIdentifier()); // Skyroot needs priority @@ -63,7 +73,7 @@ public void init(FMLInitializationEvent event) { @Mod.EventHandler public void postInit(FMLPostInitializationEvent event) { - + ModuleBase.base.postInit(); } @SubscribeEvent diff --git a/src/main/java/shnupbups/tinkersaether/modules/ModuleBase.java b/src/main/java/shnupbups/tinkersaether/modules/ModuleBase.java index 0c7d0cb..14cb1d8 100644 --- a/src/main/java/shnupbups/tinkersaether/modules/ModuleBase.java +++ b/src/main/java/shnupbups/tinkersaether/modules/ModuleBase.java @@ -1,6 +1,5 @@ package shnupbups.tinkersaether.modules; -import com.legacy.aether.items.ItemsAether; import net.minecraft.block.Block; import net.minecraft.item.Item; import net.minecraft.item.ItemBlock; @@ -31,7 +30,7 @@ @Mod.EventBusSubscriber(modid = TinkersAether.modid) public class ModuleBase { - public static ModuleBase aether = new ModuleBase(); + public static ModuleBase base = new ModuleBase(); public ModuleBase() { MinecraftForge.EVENT_BUS.register(this); @@ -178,21 +177,15 @@ public void init() { TinkersAether.logger.info("Base Module - OreDict Registered"); + TinkersAether.logger.info("Base Module - End Init"); + } + + public void postInit() { if(TAConfig.gravitite) { TinkerRegistry.registerMelting("blockEnchantedGravitite", gravitite.getFluid(), Material.VALUE_Ingot); TinkerRegistry.registerBasinCasting(new CastingRecipe(MiscUtils.stackFromOreDict("blockEnchantedGravitite"), gravitite.getFluid(), Material.VALUE_Ingot, 180)); + TinkersAether.logger.info("Base Module - Gravitite Stuffs Registered"); } - - if(TAConfig.valkyrie) { - TinkerRegistry.registerMelting(ItemsAether.valkyrie_boots, valkyrie.getFluid(), Material.VALUE_Ingot*4); - TinkerRegistry.registerMelting(ItemsAether.valkyrie_chestplate, valkyrie.getFluid(), Material.VALUE_Ingot*8); - TinkerRegistry.registerMelting(ItemsAether.valkyrie_helmet, valkyrie.getFluid(), Material.VALUE_Ingot*5); - TinkerRegistry.registerMelting(ItemsAether.valkyrie_leggings, valkyrie.getFluid(), Material.VALUE_Ingot*7); - } - - TinkersAether.logger.info("Base Module - Gravitite Stuffs Registered"); - - TinkersAether.logger.info("Base Module - End Init"); } @SubscribeEvent diff --git a/src/main/java/shnupbups/tinkersaether/network/HandlerExtendedAttack.java b/src/main/java/shnupbups/tinkersaether/network/HandlerExtendedAttack.java new file mode 100644 index 0000000..5804a5a --- /dev/null +++ b/src/main/java/shnupbups/tinkersaether/network/HandlerExtendedAttack.java @@ -0,0 +1,32 @@ +package shnupbups.tinkersaether.network; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fml.common.network.simpleimpl.IMessage; +import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; +import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; +import shnupbups.tinkersaether.traits.Reach; +import slimeknights.tconstruct.library.tools.TinkerToolCore; +import slimeknights.tconstruct.library.utils.ToolHelper; + +public class HandlerExtendedAttack implements IMessageHandler { + @Override + public IMessage onMessage(MessageExtendedAttack message, MessageContext ctx) { + EntityPlayerMP player = ctx.getServerHandler().player; + player.getServer().addScheduledTask( new Runnable() { + @Override + public void run() { + Entity entity = player.getEntityWorld().getEntityByID(message.getEntityId()); + ItemStack stack = player.getHeldItemMainhand(); + if(stack.isEmpty() || !(stack.getItem() instanceof TinkerToolCore)) { + return; + } + if(ToolHelper.getTraits(stack).contains(Reach.reach)) { + player.attackTargetEntityWithCurrentItem(entity); + } + } + }); + return null; + } +} diff --git a/src/main/java/shnupbups/tinkersaether/network/MessageExtendedAttack.java b/src/main/java/shnupbups/tinkersaether/network/MessageExtendedAttack.java new file mode 100644 index 0000000..4682a24 --- /dev/null +++ b/src/main/java/shnupbups/tinkersaether/network/MessageExtendedAttack.java @@ -0,0 +1,32 @@ +package shnupbups.tinkersaether.network; + +import io.netty.buffer.ByteBuf; +import net.minecraftforge.fml.common.network.ByteBufUtils; +import net.minecraftforge.fml.common.network.simpleimpl.IMessage; + +public class MessageExtendedAttack implements IMessage { + + private int entity; + + public MessageExtendedAttack() { + + } + + public MessageExtendedAttack(int entity) { + this.entity=entity; + } + + @Override + public void fromBytes(ByteBuf buf) { + entity = ByteBufUtils.readVarInt(buf, 4); + } + + @Override + public void toBytes(ByteBuf buf) { + ByteBufUtils.writeVarInt(buf, entity, 4); + } + + public int getEntityId() { + return entity; + } +} diff --git a/src/main/java/shnupbups/tinkersaether/traits/Reach.java b/src/main/java/shnupbups/tinkersaether/traits/Reach.java index cc619f9..59524a0 100644 --- a/src/main/java/shnupbups/tinkersaether/traits/Reach.java +++ b/src/main/java/shnupbups/tinkersaether/traits/Reach.java @@ -1,13 +1,20 @@ package shnupbups.tinkersaether.traits; +import net.minecraft.entity.Entity; import net.minecraft.entity.ai.attributes.AttributeModifier; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; +import net.minecraft.util.math.AxisAlignedBB; +import net.minecraft.util.math.Vec3d; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.entity.living.LivingEvent; +import net.minecraftforge.event.entity.player.PlayerInteractEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import shnupbups.tinkersaether.TinkersAether; +import shnupbups.tinkersaether.network.MessageExtendedAttack; import slimeknights.tconstruct.library.traits.AbstractTrait; +import java.util.List; import java.util.UUID; public class Reach extends AbstractTrait { @@ -32,4 +39,43 @@ public void onPlayerUpdate(LivingEvent.LivingUpdateEvent event) { } } } + + @SubscribeEvent + public void onMouseClick(PlayerInteractEvent.LeftClickEmpty event) { + EntityPlayer player = event.getEntityPlayer(); + ItemStack stack = player.getHeldItemMainhand(); + if(isToolWithTrait(stack)) { + Vec3d playerVision = player.getLookVec(); + AxisAlignedBB reachDistance = player.getEntityBoundingBox().grow(10.0D); + List locatedEntities = player.world.getEntitiesWithinAABB(Entity.class, reachDistance); + Entity found = null; + double foundLen = 0.0D; + for (Object o : locatedEntities) { + if (o == player) { + continue; + } + Entity ent = (Entity) o; + if (!ent.canBeCollidedWith()) { + continue; + } + Vec3d vec = new Vec3d(ent.posX - player.posX, ent.getEntityBoundingBox().minY + ent.height / 2f - player.posY - player.getEyeHeight(), ent.posZ - player.posZ); + double len = vec.lengthVector(); + if (len > 10.0F) { + continue; + } + vec = vec.normalize(); + double dot = playerVision.dotProduct(vec); + if (dot < 1.0 - 0.125 / len || !player.canEntityBeSeen(ent)) { + continue; + } + if (foundLen == 0.0 || len < foundLen) { + found = ent; + foundLen = len; + } + } + if (found != null && player.getRidingEntity() != found) { + TinkersAether.network.sendToServer(new MessageExtendedAttack(found.getEntityId())); + } + } + } } diff --git a/src/main/resources/mcmod.info b/src/main/resources/mcmod.info index d44d9c9..0b1560a 100644 --- a/src/main/resources/mcmod.info +++ b/src/main/resources/mcmod.info @@ -3,7 +3,7 @@ "modid": "tinkersaether", "name": "Tinker's Aether", "description": "Adds Aether materials and stuff to Tinker's Construct.", - "version": "1.1.0", + "version": "1.1.1", "mcversion": "${mcversion}", "url": "", "updateUrl": "",