diff --git a/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/debug/Timer.java b/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/debug/Timer.java new file mode 100644 index 0000000..ac317c6 --- /dev/null +++ b/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/debug/Timer.java @@ -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; + } +} diff --git a/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/technical/attributefactory/AttributeKey.java b/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/technical/attributefactory/AttributeKey.java index 81bfb62..eb5c529 100644 --- a/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/technical/attributefactory/AttributeKey.java +++ b/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/technical/attributefactory/AttributeKey.java @@ -2,12 +2,27 @@ import javax.annotation.Nonnull; +/** + * + * @param + */ public final class AttributeKey { + /** + * + */ private final String name; + /** + * + */ private final AttributeType type; + /** + * + * @param type + * @param name + */ public AttributeKey(@Nonnull AttributeType type, @Nonnull String name) { @@ -15,6 +30,13 @@ public AttributeKey(@Nonnull AttributeType type, this.name = name; } + /** + * + * @param type + * @param code + * @return + * @param + */ @Nonnull public static AttributeKey create(@Nonnull AttributeType type, @Nonnull String code) @@ -22,18 +44,30 @@ public static AttributeKey create(@Nonnull AttributeType type, return new AttributeKey<>(type, code); } + /** + * + * @return + */ @Nonnull public AttributeType getType() { return this.type; } + /** + * + * @return + */ @Nonnull public String getName() { return this.name; } + /** + * + * @return + */ @Override public String toString() { diff --git a/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/technical/customlibrary/RayTrace.java b/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/technical/customlibrary/RayTrace.java new file mode 100644 index 0000000..6dbea85 --- /dev/null +++ b/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/technical/customlibrary/RayTrace.java @@ -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); + } +} diff --git a/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/technical/customlibrary/Sender.java b/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/technical/customlibrary/Sender.java new file mode 100644 index 0000000..ccd7d93 --- /dev/null +++ b/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/technical/customlibrary/Sender.java @@ -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(); + } +} diff --git a/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/technical/gamestructures/StructureEntry.java b/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/technical/gamestructures/StructureEntry.java new file mode 100644 index 0000000..4d65704 --- /dev/null +++ b/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/technical/gamestructures/StructureEntry.java @@ -0,0 +1,113 @@ +package org.imesense.dynamicspawncontrol.technical.gamestructures; + +import javax.annotation.Nonnull; + +/** + * + */ +public class StructureEntry +{ + /** + * + */ + private final int dimension; + + /** + * + */ + private final long chunkPos; + + /** + * + */ + private final String structure; + + /** + * + * @param structure + * @param dimension + * @param chunkPos + */ + public StructureEntry(@Nonnull String structure, int dimension, long chunkPos) + { + this.structure = structure; + this.dimension = dimension; + this.chunkPos = chunkPos; + } + + /** + * + * @return + */ + @Nonnull + public String getStructure() + { + return structure; + } + + /** + * + * @return + */ + public int getDimension() + { + return dimension; + } + + /** + * + * @return + */ + public long getChunkPos() + { + return chunkPos; + } + + /** + * + * @param object + * @return + */ + @Override + public boolean equals(Object object) + { + if (this == object) + { + return true; + } + + if (object == null || getClass() != object.getClass()) + { + return false; + } + + StructureEntry that = (StructureEntry) object; + + if (this.dimension != that.dimension) + { + return false; + } + + if (this.chunkPos != that.chunkPos) + { + return false; + } + + return this.structure.equals(that.structure); + } + + /** + * + * @return + */ + @Override + public int hashCode() + { + int result = this.structure.hashCode(); + + result = 31 * result + this.dimension; + result = 31 * result + (int) (this.chunkPos ^ (this.chunkPos >>> 32)); + + return result; + } +} diff --git a/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/technical/gamestructures/Structures.java b/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/technical/gamestructures/Structures.java new file mode 100644 index 0000000..2d089c0 --- /dev/null +++ b/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/technical/gamestructures/Structures.java @@ -0,0 +1,112 @@ +package org.imesense.dynamicspawncontrol.technical.gamestructures; + +import net.minecraft.nbt.NBTBase; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.ChunkPos; +import net.minecraft.world.World; +import net.minecraft.world.gen.structure.MapGenStructureData; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +/** + * + */ +public class Structures +{ + /** + * + */ + public static final Structures StructuresCache = new Structures(); + + /** + * + */ + private final Map structuresCacheHashMap = new HashMap<>(); + + /** + * + */ + public void clean() + { + structuresCacheHashMap.clear(); + } + + /** + * + * @param world + * @param structure + * @param blockPos + * @return + */ + public boolean isInStructure(World world, String structure, BlockPos blockPos) + { + int dimension = world.provider.getDimension(); + ChunkPos objectChunkPos = new ChunkPos(blockPos); + long longChunkPos = ChunkPos.asLong(objectChunkPos.x, objectChunkPos.z); + StructureEntry entry = new StructureEntry(structure, dimension, longChunkPos); + + if (structuresCacheHashMap.containsKey(entry)) + { + return structuresCacheHashMap.get(entry); + } + + MapGenStructureData data = (MapGenStructureData) world.getPerWorldStorage().getOrLoadData(MapGenStructureData.class, structure); + + if (data == null) + { + return false; + } + + Set longs = parseStructureData(data); + + for (Long _long : longs) + { + structuresCacheHashMap.put(new StructureEntry(structure, dimension, _long), true); + } + + if (structuresCacheHashMap.containsKey(entry)) + { + return true; + } + else + { + structuresCacheHashMap.put(entry, false); + return false; + } + } + + /** + * + * @param data + * @return + */ + private static Set parseStructureData(MapGenStructureData data) + { + Set chunks = new HashSet<>(); + NBTTagCompound nbttagcompound = data.getTagCompound(); + + for (String _getStringNBT : nbttagcompound.getKeySet()) + { + NBTBase nbtbase = nbttagcompound.getTag(_getStringNBT); + + if (nbtbase.getId() == 10) + { + NBTTagCompound _nbtBase = (NBTTagCompound) nbtbase; + + if (_nbtBase.hasKey("ChunkX") && _nbtBase.hasKey("ChunkZ")) + { + int i = _nbtBase.getInteger("ChunkX"); + int j = _nbtBase.getInteger("ChunkZ"); + + chunks.add(ChunkPos.asLong(i, j)); + } + } + } + + return chunks; + } +}