Skip to content

Commit

Permalink
Add classes RayTrace, WorldSender, GameStructs, DebugTimer
Browse files Browse the repository at this point in the history
  • Loading branch information
OldSerpskiStalker committed Sep 18, 2024
1 parent b01568a commit afd9cd3
Show file tree
Hide file tree
Showing 6 changed files with 561 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package org.imesense.dynamicspawncontrol.debug;

import org.imesense.dynamicspawncontrol.technical.customlibrary.Log;

/**
*
*/
public final class Timer
{
/**
*
*/
private long startTime;

/**
*
* @param nameClass
*/
public Timer(final String nameClass)
{
Log.writeDataToLogFile(Log.TypeLog[0], nameClass);
}

/**
*
*/
public void start()
{
this.startTime = System.nanoTime();
}

/**
*
* @return
*/
public double stop()
{
long endTime = System.nanoTime();
return (endTime - this.startTime) / 1_000_000.0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,72 @@

import javax.annotation.Nonnull;

/**
*
* @param <T>
*/
public final class AttributeKey<T>
{
/**
*
*/
private final String name;

/**
*
*/
private final AttributeType<T> type;

/**
*
* @param type
* @param name
*/
public AttributeKey(@Nonnull AttributeType<T> type,
@Nonnull String name)
{
this.type = type;
this.name = name;
}

/**
*
* @param type
* @param code
* @return
* @param <T>
*/
@Nonnull
public static <T> AttributeKey<T> create(@Nonnull AttributeType<T> type,
@Nonnull String code)
{
return new AttributeKey<>(type, code);
}

/**
*
* @return
*/
@Nonnull
public AttributeType<T> getType()
{
return this.type;
}

/**
*
* @return
*/
@Nonnull
public String getName()
{
return this.name;
}

/**
*
* @return
*/
@Override
public String toString()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package org.imesense.dynamicspawncontrol.technical.customlibrary;

import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.Blocks;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;

/**
*
*/
public final class RayTrace
{
/**
*
* @param worldIn
* @param playerIn
* @param useLiquids
* @return
*/
public static RayTraceResult getMovingObjectPositionFromPlayer(World worldIn, EntityPlayer playerIn, boolean useLiquids)
{
float pitch = playerIn.rotationPitch;
float yaw = playerIn.rotationYaw;

Vec3d vec3 = getPlayerEyes(playerIn);

float f2 = MathHelper.cos(-yaw * 0.017453292F - (float)Math.PI);
float f3 = MathHelper.sin(-yaw * 0.017453292F - (float)Math.PI);
float f4 = -MathHelper.cos(-pitch * 0.017453292F);
float f5 = MathHelper.sin(-pitch * 0.017453292F);
float f6 = f3 * f4;
float f7 = f2 * f4;

double reach = 5.00;

if (playerIn instanceof net.minecraft.entity.player.EntityPlayerMP)
{
reach = ((EntityPlayerMP)playerIn).interactionManager.getBlockReachDistance();
}

Vec3d vec31 = vec3.addVector(f6 * reach, f5 * reach, f7 * reach);

return worldIn.rayTraceBlocks(vec3, vec31, useLiquids, !useLiquids, false);
}

/**
*
* @param playerIn
* @return
*/
private static Vec3d getPlayerEyes(EntityPlayer playerIn)
{
double x = playerIn.posX;
double y = playerIn.posY + playerIn.getEyeHeight();
double z = playerIn.posZ;

return new Vec3d(x, y, z);
}

/**
*
* @param world
* @param player
* @return
*/
public static boolean isPlayerStandingOnBlock(World world, EntityPlayer player)
{
double posX = player.posX;
double posY = player.posY;
double posZ = player.posZ;

double adjustedY = posY - 0.1;

BlockPos blockPosBelow = new BlockPos(posX, adjustedY, posZ);

IBlockState blockStateBelow = world.getBlockState(blockPosBelow);
Block blockBelow = blockStateBelow.getBlock();

return blockBelow != Blocks.AIR;
}

/**
*
* @param player
* @return
*/
public static BlockPos getBlockPosBelowPlayer(EntityPlayer player)
{
double posX = player.posX;
double posY = player.posY - 0.1;
double posZ = player.posZ;
return new BlockPos(posX, posY, posZ);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
package org.imesense.dynamicspawncontrol.technical.customlibrary;

import net.minecraft.command.CommandResultStats;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.world.World;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

/**
*
*/
public final class Sender implements ICommandSender
{
/**
*
*/
private final World world;

/**
*
*/
private final EntityPlayer player;

/**
*
* @param world
* @param player
*/
public Sender(World world, EntityPlayer player)
{
this.world = world;
this.player = player;
}

/**
*
* @return
*/
@Nonnull
@Override
public String getName()
{
return "Sender";
}

/**
*
* @return
*/
@Nonnull
@Override
public ITextComponent getDisplayName()
{
return new TextComponentString("ISender");
}

/**
*
* @param component
*/
@Override
public void sendMessage(ITextComponent component)
{
System.out.println(component.getFormattedText());
}

/**
*
* @param permLevel
* @param commandName
* @return
*/
@Override
public boolean canUseCommand(int permLevel, @Nonnull String commandName)
{
return true;
}

/**
*
* @return
*/
@Nonnull
@Override
public BlockPos getPosition()
{
return new BlockPos(0, 0, 0);
}

/**
*
* @return
*/
@Nonnull
@Override
public Vec3d getPositionVector()
{
return new Vec3d(0, 0, 0);
}

/**
*
* @return
*/
@Nonnull
@Override
public World getEntityWorld()
{
return this.world;
}

/**
*
* @return
*/
@Nullable
@Override
public Entity getCommandSenderEntity()
{
return this.player;
}

/**
*
* @return
*/
@Override
public boolean sendCommandFeedback()
{
return net.minecraft.command.ICommandSender.super.sendCommandFeedback();
}

/**
*
* @param type
* @param amount
*/
@Override
public void setCommandStat(@Nonnull final CommandResultStats.Type type, int amount)
{
}

/**
*
* @return
*/
@Nullable
@Override
public MinecraftServer getServer()
{
return this.world.getMinecraftServer();
}
}
Loading

0 comments on commit afd9cd3

Please sign in to comment.