-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add classes RayTrace, WorldSender, GameStructs, DebugTimer
- Loading branch information
1 parent
b01568a
commit afd9cd3
Showing
6 changed files
with
561 additions
and
0 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/debug/Timer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
...12.2/src/main/java/org/imesense/dynamicspawncontrol/technical/customlibrary/RayTrace.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
161 changes: 161 additions & 0 deletions
161
...1.12.2/src/main/java/org/imesense/dynamicspawncontrol/technical/customlibrary/Sender.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
Oops, something went wrong.