mirror of
https://github.com/eaglerforge/EaglerForgeInjector
synced 2025-07-23 14:11:16 -09:00
make guns work
This commit is contained in:
parent
0dd5ed09bf
commit
a0241562df
@ -13,26 +13,30 @@
|
|||||||
itemSuper(this); //Use super function to get block properties on this class.
|
itemSuper(this); //Use super function to get block properties on this class.
|
||||||
this.$setCreativeTab(creativeMiscTab);
|
this.$setCreativeTab(creativeMiscTab);
|
||||||
}
|
}
|
||||||
function entityraycast(player, world, range){
|
function entityRayCast(player, world, range){
|
||||||
var eyePosition = player.getPositionEyes(1.0);
|
var eyePosition = player.getPositionEyes(0.0);
|
||||||
var lookVector = player.getLook(1.0);
|
var lookVector = player.getLook(0.0);
|
||||||
var targetPosition = eyePosition.addVector(lookVector.xCoord * range, lookVector.yCoord * range, lookVector.zCoord * range);
|
var targetPosition = eyePosition.addVector(lookVector.xCoord * range, lookVector.yCoord * range, lookVector.zCoord * range);
|
||||||
var entities = world.getEntitiesWithinAABBExcludingEntity(
|
var entities = world.getEntitiesWithinAABBExcludingEntity(
|
||||||
player,
|
player.getRef(),
|
||||||
player.getEntityBoundingBox().expand(range, range, range)
|
player.getEntityBoundingBox().expand(range, range, range).getRef()
|
||||||
);
|
).getCorrective().array;
|
||||||
var closestEntity = null;
|
var closestEntity = null;
|
||||||
var closestDistance = range;
|
var closestDistance = range;
|
||||||
|
|
||||||
// Iterate through all entities to find the one the player is looking at
|
// Iterate through all entities to find the one the player is looking at
|
||||||
for (var i = 0; i < entities.length; i++) {
|
for (var i = 0; i < entities.length; i++) {
|
||||||
|
if (!entities[i]) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
var entity = entities[i];
|
var entity = entities[i];
|
||||||
|
|
||||||
// Check if the entity's bounding box intersects with the player's ray
|
// Check if the entity's bounding box intersects with the player's ray
|
||||||
var entityBB = entity.getEntityBoundingBox().expand(0.3, 0.3, 0.3);
|
var entityBB = entity.getEntityBoundingBox().expand(0.3, 0.3, 0.3);
|
||||||
var intercept = entityBB.calculateIntercept(eyePosition, targetPosition);
|
var intercept = entityBB.calculateIntercept(eyePosition.getRef(), targetPosition.getRef());
|
||||||
|
|
||||||
if (intercept != null) {
|
if (intercept != null) {
|
||||||
var distance = eyePosition.distanceTo(intercept.hitVec);
|
var distance = eyePosition.distanceTo(intercept.hitVec.getRef());
|
||||||
if (distance < closestDistance) {
|
if (distance < closestDistance) {
|
||||||
closestDistance = distance;
|
closestDistance = distance;
|
||||||
closestEntity = entity;
|
closestEntity = entity;
|
||||||
@ -40,7 +44,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var rayTraceResult = closestEntity
|
var rayTraceResult = closestEntity;
|
||||||
if (rayTraceResult != null){
|
if (rayTraceResult != null){
|
||||||
return rayTraceResult;
|
return rayTraceResult;
|
||||||
} else{
|
} else{
|
||||||
@ -51,12 +55,10 @@
|
|||||||
nmi_ItemPistol.prototype.$onItemRightClick = function ($itemstack, $world, $player) {
|
nmi_ItemPistol.prototype.$onItemRightClick = function ($itemstack, $world, $player) {
|
||||||
var world = ModAPI.util.wrap($world);
|
var world = ModAPI.util.wrap($world);
|
||||||
var entityplayer = ModAPI.util.wrap($player);
|
var entityplayer = ModAPI.util.wrap($player);
|
||||||
var shotentity = entityraycast(entityplayer, world, 10.0)
|
var shotentity = entityRayCast(entityplayer, world, 12.0)
|
||||||
if (shotentity != null){
|
if (shotentity != null){
|
||||||
var entityName = shotentity.getName();
|
shotentity.heal(-10);
|
||||||
entityplayer.sendMessage(ModAPI.reflect.getClassById("net.minecraft.util.ChatComponentText").constructors[0](ModAPI.util.str(entityName)))
|
world.playSoundAtEntity(entityplayer.getRef(), ModAPI.util.str("tile.piston.out"), 1.0, 1.8);
|
||||||
console.log(entityName)
|
|
||||||
world.playSoundAtEntity(entityplayer, "tile.piston.out", 1.0, 1.8);
|
|
||||||
}
|
}
|
||||||
return $itemstack;
|
return $itemstack;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user