Forge 1.16.5 get attack damage of an item - minecraft-forge

I am trying to get the attack damage of the item in the players offhand. So far I have this mc.player.inventory.offhand.get(0) in my world ticking event (mc is the instance of minecraft). But the item does not seem to have any attack damage attribute. Is there some other way to get it?

I had the same problem, and It took me a while to figure this out. Here's my solution.
Note: I'm using fabric, but this should still work in a similar way with forge.
ItemStack handItem = minecraftClient.player.getMainHandStack();
// get the damage of the item in the players main hand (does not include player base damage)
String itemDamageStr = handItem.getAttributeModifiers(EquipmentSlot.MAINHAND).get(EntityAttributes.GENERIC_ATTACK_DAMAGE).toString().replaceFirst(".*?amount=([0-9]+\\.[0-9]+).*", "$1");
Double itemDamage = 0.0;
if(itemDamageStr.matches("[0-9]+\\.[0-9]+")){
itemDamage = Double.parseDouble(itemDamageStr);
}
// get the players damage
Double playerDamage = minecraftClient.player.getAttributes().getValue(EntityAttributes.GENERIC_ATTACK_DAMAGE);
float totalDamage = (float) (itemDamage + playerDamage);
Also, just in case someone finds this helpful, when I was trying to get the player to damage an entity, I had to grab the entity from the server world in order to do anything to it from the client.
ServerWorld serverWorld = minecraftClient.getServer().getWorld(minecraftClient.world.getRegistryKey());
Entity entity = minecraftClient.targetedEntity;
Entity serverEntity = serverWorld.getEntity(entity.getUuid());

Related

Alternative to moveWithCollision

I've been making a (potentially massive) multiplayer video game in javascript, nodejs and babylonjs...
It's been a few months that a code is causing me problems in front:
it's currently a simple first person shooter with waves of monsters in player versus player.
The code I'm having trouble with is gravity.
players and monsters can therefore fall or climb, and those from more or less high, of course, the ground is not smooth.
for the moment I calculate the gravity in front only (the server does not receive "y"): I would like not to change that.
The monsters, which can be numerous, are also impacted by gravity only in front.
I searched, went through the babylonjs api and I can't find a viable alternative to "moveWithCollisions"
if (gamers[id][0] == false) {
var before = scene.getMeshByName(gamers[id][1]).gravity.y;
var after = scene.getMeshByName(gamers[id][1]).gravity.y;
for (var a = 0; a < Math.abs(4); a++) {
if (Math.round(after) == Math.round(before)) {
before = scene.getMeshByName(gamers[id][1]).position.y+scene.getMeshByName(gamers[id][1]).gravity.y;
scene.getMeshByName(gamers[id][1]).moveWithCollisions(scene.getMeshByName(gamers[id][1]).gravity);
after = scene.getMeshByName(gamers[id][1]).position.y;
} else {
a = 5;
gamers[id][0] = true;
}
}
when the character receives a move gamers[id][0] becomes false again
I really need a lighter command:
With 100 players and 1000 monsters you will understand that there is no chance that this code will work?
Hence my question, not having the strength to create this command myself, is there a real alternative to the "moveWithCollision" command?
I take you to consider my question, I have been looking for several weeks without finding anything better...
thanks in advance

Determining what direction to face over a network with an omnidirectional camera

I have a rather difficult problem. I am making a topdown 2D game. And I have decided to make an omnidirectional character control like realm of the mad god (Video shows at second 16 what that means). I have it all working fine and have managed to work out almost all the kinks of this sort of camera but one thing remains.
(if you dont know what effect im looking create you can see and example hee at 16 seconds mark: https://youtu.be/N2q6aXkvIiI?t=12s)
When the Camera of the the main client gets rotated more that 180 degrees Left becomes right and right becomes left and my messages to the server about flipping the given character when he is supposed to get inverted. I somewhat fixed this by making an if statement that sends an opposite flip request when your world is completely flipped.
However up and down also become a factor as they dont send requests to flip the character.
What im trying to get to is that I have overcomplicted this script I beleive when trying to get the correct messages accross all clients.
I am wondering if anyone has a logical solution to making sure all chracters on the network are always facing the correct direction at all times.
I am using socket.io and Node.js for speaking to the server.
Any input would be appeciated.
TL;DR
How would you go about making realm of the mad gods camera rotation style when all clients need to know what way everyone is facing. (see video 0:16)
thanks.
I have somewhat fixed this problem with a bit of a rewrite of my logic and managed to make all the magic happen on the client and keep the server out of it entirely. I do not know if what I have done is super effecient as I am rather new to coding.
The logic is that I have created a circle collider2D that represents the players field of view. so things slightly outside the camera view are included. Any collision with an object tagged "otherPlayer" will add them to a list.
I then iterate through the list, if its not empty, and I determine if the object is moving away or coming towards me. (thank you to HigherScriptingAuthority for part of the code for this :: https://forum.unity3d.com/threads/left-right-test-function.31420/).
once I know that, all I have to do is grab the transform of that object and flip it accordingly. Boom it now rotates the object or player correctly no matter what rotation the main client is in.
Hope this makes sense and it helps someone:
private float lastDist = 0;
public float dirNum;
void CheckArea()
{
if (listOfPlayers.Count != 0)
{
foreach(var otherPlayer in listOfPlayers)
{
float distance = (transform.position - otherPlayer.transform.position).magnitude;
if (distance < lastDist)
{
Vector3 heading = otherPlayer.transform.position - transform.position;
dirNum = AngleDir(transform.forward, heading, transform.up);
var objectDirection = AngleDir(transform.forward, heading, transform.up);
if (objectDirection > 0)
{
var nav = otherPlayer.GetComponent<Navigator>();
nav.Left();
}
if (objectDirection < 0)
{
var nav = otherPlayer.GetComponent<Navigator>();
nav.Right();
}
}
if (distance > lastDist)
{
Vector3 heading = otherPlayer.transform.position - transform.position;
dirNum = AngleDir(transform.forward, heading, transform.up);
var objectDirection = AngleDir(transform.forward, heading, transform.up);
if (objectDirection > 0)
{
var nav = otherPlayer.GetComponent<Navigator>();
nav.Right();
}
if (objectDirection < 0)
{
var nav = otherPlayer.GetComponent<Navigator>();
nav.Left();
}
}
lastDist = distance;
}
}
}

Import TransferOrder lines (InventTransferLine)

I am trying to import a transfer order line with this code from Transfer Orders Import:
InventDim inventDim;
InventTransferLine inventTransferLine;
#define.ShipDate("1/1/2016")
#define.ReceiveDate("1/1/2016")
//Order line
inventDim.clear();
inventDim.InventSiteId = "GENERAL";
inventDim.InventLocationId = "103";
inventTransferLine.clear();
inventTransferLine.initValue();
inventTransferLine.ItemId = "A01103472";
inventTransferLine.InventDimId = InventDim::findOrCreate(inventDim).inventDimId;
inventTransferLine.QtyTransfer = 2;
inventTransferLine.initFromInventTableModule(InventTableModule::find(inventTransferLine.ItemId,ModuleInventPurchSales::Invent));
inventTransferLine.QtyRemainReceive = inventTransferLine.QtyTransfer;
inventTransferLine.QtyRemainShip = inventTransferLine.QtyTransfer;
inventTransferLine.ShipDate = str2Date(#ShipDate, 213);
inventTransferLine.ReceiveDate = str2Date(#ReceiveDate, 213);
inventTransferLine.initFromInventTransferTable(inventTransferTable, false);
inventTransferLine.LineNum = InventTransferLine::lastLineNum(inventTransferLine.TransferId) + 1.0;
if (inventTransferLine.validateWrite())
{
inventTransferLine.insert();
}
else
throw error("Order line");
Is this the correct or the preferred way to do it?
What's the use of inventDim here? I am transferring this product from warehouse A to warehouse B and those are specified in the selected header, meaning the InventTransferTable record.
And i am not sure about these two lines:
1. inventTransferLine.QtyRemainReceive = inventTransferLine.QtyTransfer;
2. inventTransferLine.QtyRemainShip = inventTransferLine.QtyTransfer;
RemainReceive from where? i can't figure out what are they referring to.
You are more or less good to go.
You seems to have copied what others have done, which is good.
There are other ways to it, one using AxInventTransferTable and ...Line classes, another using the TransferOrderCreateService service. None will give you much competitive advantage, if working from within AX.
The InventDim (see white paper) contains the inventory, storage, and tracking dimensions of the item. You will need to set more fields if the item requires it as specified on the item and product.
Product dimensions. Item dimensions, color, size and configuration.
Storage dimensions. These are Site, Warehouse, Location, and Pallet.
Tracking dimensions. These are Batch number and Serial number.
A shipment is a two-step thing. First you ship the item from the source site/warehouse. Later you receive the item at the target site/warehouse.
The QtyRemainShipand QtyRemainReceive fields represents the quantity remaining for each step.

AX 2009: Adjusting User Group Length

We're looking into refining our User Groups in Dynamics AX 2009 into more precise and fine-tuned groupings due to the wide range of variability between specific people within the same department. With this plan, it wouldn't be uncommon for majority of our users to fall user 5+ user groups.
Part of this would involve us expanding the default length of the User Group ID from 10 to 40 (as per Best Practice for naming conventions) since 10 characters don't give us enough room to adequately name each group as we would like (again, based on Best Practice Naming Conventions).
We have found that the main information seems to be obtained from the UserGroupInfo table, but that table isn't present under the Data Dictionary (it's under the System Documentation, so unavailable to be changed that way by my understanding). We've also found the UserGroupName EDT, but that is already set at 40 characters. The form itself doesn't seem to restricting the length of the field either. We've discussed changing the field on the SQL directly, but again my understanding is that if we do a full synchronization it would overwrite this change.
Where can we go to change this particular setting, or is it possible to change?
The size of the user group id is defined as as system extended data type (here \System Documentation\Types\userGroupId) and you cannot change any of the properties including the size 10 length.
You should live with that, don't try to fake the system using direct SQL changes. Even if you did that, AX would still believe that length is 10.
You could change the SysUserInfo form to show the group name only. The groupId might as well be assigned by a number sequence in your context.
I wrote a job to change the string size via X++ and it works for EDTs, but it can't seem to find the "userGroupId". From the general feel of AX I get, I'd be willing to guess that they just have it in a different location, but maybe not. I wonder if this could be tweaked to work:
static void Job9(Args _args)
{
#AOT
TreeNode treeNode;
Struct propertiesExt;
Map mapNewPropertyValues;
void setTreeNodePropertyExt(
Struct _propertiesExt,
Map _newProperties
)
{
Counter propertiesCount;
Array propertyInfoArray;
Struct propertyInfo;
str propertyValue;
int i;
;
_newProperties.insert('IsDefault', '0');
propertiesCount = _propertiesExt.value('Entries');
propertyInfoArray = _propertiesExt.value('PropertyInfo');
for (i = 1; i <= propertiesCount; i++)
{
propertyInfo = propertyInfoArray.value(i);
if (_newProperties.exists(propertyInfo.value('Name')))
{
propertyValue = _newProperties.lookup(propertyInfo.value('Name'));
propertyInfo.value('Value', propertyValue);
}
}
}
;
treeNode = TreeNode::findNode(#ExtendedDataTypesPath);
// This doesn't seem to be able to find the system type
//treeNode = treeNode.AOTfindChild('userGroupId');
treeNode = treeNode.AOTfindChild('AccountCategory');
propertiesExt = treeNode.AOTgetPropertiesExt();
mapNewPropertyValues = new Map(Types::String, Types::String);
mapNewPropertyValues.insert('StringSize', '30');
setTreeNodePropertyExt(propertiesExt, mapNewPropertyValues);
treeNode.AOTsetPropertiesExt(propertiesExt);
treeNode.AOTsave();
info("Done");
}

2D Game colision response

So I am writing a game, but I have come to the part where i need to do some collision response, and I have been stumped. I have an algorithm that finds the objects collision angle, and collision depth meaning how much the two objects over lap. I understand what i want to do and that is to find a perpendicular vector to the collision angle and push back the object that is colliding by it's collision depth, but I just can't seem to write it correctly.
Here is the code I'm working with for the time being.
var collision:Object = collisions[i];
var angle:Number = collision.angle;
var overlap:Number = collision.overlapping.length;
trace(overlap);
trace(angle);
var moveX = Math.cos(angle) * overlap;
var moveY = Math.sin(angle) * overlap;
obj2.x -= moveX;
obj2.y += moveY;
basically I just want the object that is colliding with the wall to stop when it hits it.
any help would be greatly appreciated.
I worked on elastic collision with flash as3 once.I tried to fix overlap a lot of.But i could'nt solved it completely.They did not overlapping normally but if you forced enought, they overlapping.
if you want look at my work, i uploaded my codes.You can download and look at my code.
And if you solve this problem completely, please tell me solution.
swf(with friction, it's more problem) : http://nafiz.in/collision/carpisma.swf
swf(without friction, it's little problem than first.) : http://nafiz.in/collision/carpisma_surtunmesiz.swf
q : add a ball at mouse location.
w, a,s,d : controll #1 ball.
Click with mouse without relase and move mouse and relase. You selected balls.
When you press space, selected balls will go mouse location.
Cods : http://nafiz.in/collision/collision.rar
i hope you solve.
So after a few hours of tweaking the code, I came up with the solution that works well. here is my new code:
public function Colisions(obj1,obj2) {
var collisions:Array=MyCollision.checkCollisions();
for (var i = 0; i < collisions.length; i++) {
var collision:Object=collisions[i];
var angle:Number=collision.angle;
var overlap:Number=collision.overlapping.length;
// finds the amount in x and y coordinates to move the ball back, and it devides overlap by 20 so that the ball does not jump as much.
var moveX=Math.cos(angle)*(overlap/20);
var moveY=Math.sin(angle)*(overlap/20);
// sets the ball to it's original location before the colision.
obj2.x=obj2.x-moveX;
obj2.y=obj2.y-moveY;
}
}
just as a side note I am using CDK which stands for the collision detection toolkit as the algorithm that finds the collisions and the info associated with the collisions.

Resources