SCAREX
Members-
Posts
28 -
Joined
-
Last visited
Everything posted by SCAREX
-
Your instance annotation should have the modid inside, not the name
-
You can download all the mods you want using gradle : just use the dev version (de-obfuscated) or add the code chicken core (/code chicken lib) in your dev workspace to play with obfuscated mods without de-deobfuscating the mod, I've made a tutorial for this here : http://www.minecraftforgefrance.fr/showthread.php?tid=2689 (in french sorry) There is 3 types of jars : the obfuscated (the one used to play), the de-obfuscated (to use in your dev environment), the source (uncompiled files). the API seems to be only the files to use to make your classpath happy
-
Correction : it seems to work, before I tested it no particles appeared. EDIT : no particles appeared because I was using world.spawnParticle.
-
Before I used if (this.worldObj.isRemote) but no particles appeared. I think it's because the particles are entities, and entities need to be spawned from the server.
-
Recently I had to create a smoke grenade. In order to do this, I used particles but the problem was that the player could deactivate them in the options so I used another way to do it. All were fine during a time but after my game crashes with different crash reports : My class : (EntityGrenade.class) public void performAction(MovingObjectPosition mop) { switch (this.metadata) { case 1: if (this.fuse > 0) { for (int i = 0; i < 4; i++) { Minecraft mc = Minecraft.getMinecraft(); if (mc.renderViewEntity != null && mc.effectRenderer != null) { float multi = 1.6F; double x = this.posX + this.rand.nextGaussian() * multi; double y = this.posY + ((this.rand.nextDouble() - 0.2D) * 3) * multi; double z = this.posZ + this.rand.nextGaussian() * multi; double d = mc.renderViewEntity.posX - x; double d1 = mc.renderViewEntity.posY - y; double d2 = mc.renderViewEntity.posZ - z; if (d * d + d1 * d1 + d2 * d2 <= 1024.0D) mc.effectRenderer.addEffect(new EntitySmokeFX(this.worldObj, x, y, z, 0.0D, 0.0D, 0.0D, 2.0F)); // Particles are created here } } if (this.fuse >= 20) this.setDead(); } break; default: if (!this.worldObj.isRemote && this.fuse >= 40 || (mop != null && mop.entityHit != null)) { this.setDead(); this.worldObj.createExplosion(this, this.posX, this.posY + 1.0D, this.posZ, 3.4F, this.worldObj.getGameRules().getGameRuleBooleanValue("mobGriefing")); } break; } } The crash report is not always the same : the entity type change every time. Once it was an EntityItem and another time a particle. But the NPE is in these loops : List list = this.worldObj.getCollidingBoundingBoxes(this, this.boundingBox.addCoord(p_70091_1_, p_70091_3_, p_70091_5_)); for (int i = 0; i < list.size(); ++i) { p_70091_3_ = ((AxisAlignedBB)list.get(i)).calculateYOffset(this.boundingBox, p_70091_3_); // here (Entity.class:692) } this.boundingBox.offset(0.0D, p_70091_3_, 0.0D); if (!this.field_70135_K && d7 != p_70091_3_) { p_70091_5_ = 0.0D; p_70091_3_ = 0.0D; p_70091_1_ = 0.0D; } boolean flag1 = this.onGround || d7 != p_70091_3_ && d7 < 0.0D; int j; for (j = 0; j < list.size(); ++j) { p_70091_1_ = ((AxisAlignedBB)list.get(j)).calculateXOffset(this.boundingBox, p_70091_1_); // Or here (Entity.class:709) } this.boundingBox.offset(p_70091_1_, 0.0D, 0.0D); if (!this.field_70135_K && d6 != p_70091_1_) { p_70091_5_ = 0.0D; p_70091_3_ = 0.0D; p_70091_1_ = 0.0D; } for (j = 0; j < list.size(); ++j) { p_70091_5_ = ((AxisAlignedBB)list.get(j)).calculateZOffset(this.boundingBox, p_70091_5_); // Or here (Entity.class:723) } The only thing that can cause a NPE is the method "calculateYOffset" / "calculateXOffset" / "calculateZOffset". But when I see the code when the list comes from : public List getCollidingBoundingBoxes(Entity p_72945_1_, AxisAlignedBB p_72945_2_) { this.collidingBoundingBoxes.clear(); int i = MathHelper.floor_double(p_72945_2_.minX); int j = MathHelper.floor_double(p_72945_2_.maxX + 1.0D); int k = MathHelper.floor_double(p_72945_2_.minY); int l = MathHelper.floor_double(p_72945_2_.maxY + 1.0D); int i1 = MathHelper.floor_double(p_72945_2_.minZ); int j1 = MathHelper.floor_double(p_72945_2_.maxZ + 1.0D); for (int k1 = i; k1 < j; ++k1) { for (int l1 = i1; l1 < j1; ++l1) { if (this.blockExists(k1, 64, l1)) { for (int i2 = k - 1; i2 < l; ++i2) { Block block; if (k1 >= -30000000 && k1 < 30000000 && l1 >= -30000000 && l1 < 30000000) { block = this.getBlock(k1, i2, l1); } else { block = Blocks.stone; } block.addCollisionBoxesToList(this, k1, i2, l1, p_72945_2_, this.collidingBoundingBoxes, p_72945_1_); } } } } double d0 = 0.25D; List list = this.getEntitiesWithinAABBExcludingEntity(p_72945_1_, p_72945_2_.expand(d0, d0, d0)); for (int j2 = 0; j2 < list.size(); ++j2) { AxisAlignedBB axisalignedbb1 = ((Entity)list.get(j2)).getBoundingBox(); if (axisalignedbb1 != null && axisalignedbb1.intersectsWith(p_72945_2_)) // NullPointerCheck with "axisalignedbb1 != null" { this.collidingBoundingBoxes.add(axisalignedbb1); } axisalignedbb1 = p_72945_1_.getCollisionBox((Entity)list.get(j2)); if (axisalignedbb1 != null && axisalignedbb1.intersectsWith(p_72945_2_)) // Same here { this.collidingBoundingBoxes.add(axisalignedbb1); } } return this.collidingBoundingBoxes; } So it can't be the source of the crash. If you know why, tell me, it's been 4 days since I'm looking for an answer but it seems impossible for me. Forge version : tested in 1.7.10-10.13.4.1448 and 1.7.10-10.13.4.1481.
-
[1.7.10] Entity mountable not working (problem with synchronization)
SCAREX replied to SCAREX's topic in Modder Support
I can get it to work by implementing IEntityAdditionalSpawnData, but it takes a bit of time to update the y offset : After a bit of time : -
[1.7.10] Entity mountable not working (problem with synchronization)
SCAREX replied to SCAREX's topic in Modder Support
Now, I can sit on thee block but the mounted Y offset is correct only for the server : package fr.scarex.hilium.block; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.world.World; import fr.scarex.hilium.Hilium; import fr.scarex.hilium.entity.EntitySit; import fr.scarex.hilium.tileentity.TileEntitySit; /** * @author SCAREX * */ public class BlockSit extends Block { protected BlockSit(Material material) { super(material); } @Override public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) { if (this.canSit(world, x, y, z, player, side, hitX, hitY, hitZ)) { EntitySit entity = new EntitySit(world, x + 0.5D, y + 0.5D, z + 0.5D, this.getOffsetY(world, x, y, z)); world.spawnEntityInWorld(entity); entity.interactFirst(player); return true; } return false; } public boolean canSit(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) { return true; } public double getOffsetY(World world, int x, int y, int z) { return 0.5D; } } package fr.scarex.hilium.block; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.EntityLivingBase; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.MathHelper; import net.minecraft.world.World; import cpw.mods.fml.common.registry.GameRegistry; import fr.scarex.hilium.Hilium; import fr.scarex.hilium.client.ClientProxy; import fr.scarex.hilium.tileentity.TileEntitySit; import fr.scarex.hilium.tileentity.TileEntityUseless; /** * @author SCAREX * */ public class BlockToilet extends BlockSit { public static final String NAME = "toilet"; protected BlockToilet() { super(Material.glass); this.setHardness(0.5F); this.setResistance(5.0F); this.setStepSound(this.soundTypeGlass); this.setCreativeTab(CreativeTabs.tabDecorations); this.setBlockName(Hilium.MODID + "_" + NAME); this.setBlockTextureName(Hilium.MODID + ":" + NAME); this.register(); } private void register() { GameRegistry.registerBlock(this, NAME); GameRegistry.registerTileEntity(TileEntitySit.class, Hilium.MODID + ":" + NAME); } @Override public boolean renderAsNormalBlock() { return false; } @Override public int getRenderType() { return ClientProxy.RENDER_ID; } @Override public boolean isOpaqueCube() { return false; } @Override public boolean hasTileEntity(int metadata) { return true; } @Override public TileEntity createTileEntity(World world, int metadata) { return new TileEntitySit(); } @Override public void setBlockBoundsForItemRender() { this.setBlockBounds(0.05F, 0.0F, 0.05F, 0.95F, 0.88F, 0.95F); } @Override public void registerBlockIcons(IIconRegister register) { this.blockIcon = register.registerIcon("glass"); } @Override public boolean canPlaceBlockAt(World world, int x, int y, int z) { return super.canPlaceBlockAt(world, x, y, z) && World.doesBlockHaveSolidTopSurface(world, x, y - 1, z); } @Override public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entity, ItemStack stack) { int direction = MathHelper.floor_double((double) (entity.rotationYaw * 4.0F / 360.0F) + 2.5D) & 3; world.setBlockMetadataWithNotify(x, y, z, direction == 3 ? 0 : direction + 1, 2); } @Override public double getOffsetY(World world, int x, int y, int z) { return 0.3D; } } package fr.scarex.hilium.entity; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.MathHelper; import net.minecraft.world.World; import fr.scarex.hilium.Hilium; import fr.scarex.hilium.block.BlockSit; /** * @author SCAREX * */ public class EntitySit extends Entity { protected double offsetY; public EntitySit(World world) { super(world); this.noClip = true; this.preventEntitySpawning = true; this.setSize(0.0F, 0.0F); this.offsetY = 0.0F; } public EntitySit(World world, double x, double y, double z, double offsetY) { this(world); this.setPosition(x, y, z); this.offsetY = offsetY; } @Override protected void entityInit() {} @Override protected void readEntityFromNBT(NBTTagCompound comp) {} @Override protected void writeEntityToNBT(NBTTagCompound comp) {} @Override public void onEntityUpdate() { if (this.riddenByEntity == null || this.riddenByEntity.isDead) this.setDead(); super.onEntityUpdate(); } @Override public boolean interactFirst(EntityPlayer p) { if (this.riddenByEntity != null) return true; if (!this.worldObj.isRemote) p.mountEntity(this); return true; } @Override public double getMountedYOffset() { return this.offsetY; } } -
[1.7.10] Entity mountable not working (problem with synchronization)
SCAREX replied to SCAREX's topic in Modder Support
I found out that the method onBlockAdded is fired only on the server, And when I spawn the entity, the client doesn't know that the entity is actually there : I will put the spawn of the mob in another method to see if there is a difference. -
The name of the event is InitGuiEvent, but you can also use the postInitializationEvent
-
Minecraft.getMinecraft().thePlayer.getGameProfile()
-
You can replace the block with GameRegistry.addSubstitute (or something like that).
-
The break event gives you all the parameters you need to get the block metadata, new ItemStack(evt.block, 1, evt.blockMetadata)
-
Attack animation not working [1.7.10]
SCAREX replied to BoonieQuafter-CrAfTeR's topic in Modder Support
File corruption with techne example : LegR = new ModelRenderer(this, 46, 0); LegR.addBox(0F, 0F, 0F, 4, 16, 4); // The variables names should begin with a lower case letter LegR.setRotationPoint(1F, 8F, -2F); LegR.setTextureSize(64, 64); LegR.mirror = true; // Miror texture should be after the initialization setRotation(LegR, 0F, 0F, 0F); The reason that your animation doesn't work is because your event is fired once, but the method setLivingAnimation is fired every render tick. -
[SOLVED][1.8] Crash when placing underwater plant
SCAREX replied to JimiIT92's topic in Modder Support
You are using a liquid material : super(Material.water); try with a correct Material. -
I tested what you said, and I confirm : this is a bug. Another thing I found is that when you shift click, the event is fired 4 times but a simple click fires it 2 times (client and server I suppose).
-
There events fired after game initialization, but why do you need their UUID ? And why do you want to see if the players is logged in ?
-
[SOLVED][1.8] Crash when placing underwater plant
SCAREX replied to JimiIT92's topic in Modder Support
Can you give us the crash report ? -
I don't understand what you mean, the ItemSmeltedEvent is fired when the Item has been smelt, where do you see a shift-click ?
-
Blocks.theBlockYouWant.getDefaultState()
-
Attack animation not working [1.7.10]
SCAREX replied to BoonieQuafter-CrAfTeR's topic in Modder Support
You are using a corrupted model from techne, that's not your fault but techne creates corrupted files, you can correct your file here : http://scarex.fr/model_corrector.php. For the animation, I found this : /** * Used for easily adding entity-dependent animations. The second and third float params here are the same second * and third as in the setRotationAngles method. */ public void setLivingAnimations(EntityLivingBase p_78086_1_, float p_78086_2_, float p_78086_3_, float p_78086_4_) { EntityIronGolem entityirongolem = (EntityIronGolem)p_78086_1_; int i = entityirongolem.getAttackTimer(); if (i > 0) { this.ironGolemRightArm.rotateAngleX = -2.0F + 1.5F * this.func_78172_a((float)i - p_78086_4_, 10.0F); this.ironGolemLeftArm.rotateAngleX = -2.0F + 1.5F * this.func_78172_a((float)i - p_78086_4_, 10.0F); } else { int j = entityirongolem.getHoldRoseTick(); if (j > 0) { this.ironGolemRightArm.rotateAngleX = -0.8F + 0.025F * this.func_78172_a((float)j, 70.0F); this.ironGolemLeftArm.rotateAngleX = 0.0F; } else { this.ironGolemRightArm.rotateAngleX = (-0.2F + 1.5F * this.func_78172_a(p_78086_2_, 13.0F)) * p_78086_3_; this.ironGolemLeftArm.rotateAngleX = (-0.2F - 1.5F * this.func_78172_a(p_78086_2_, 13.0F)) * p_78086_3_; } } } Class : net.minecraft.client.model.ModelIronGolem -
Recently, I had to create a new block for sitting but I had problem with synchronization : the player was correctly placed for the server but not for the client (I'm playing in single player). I posted this problem on the MinecraftForgeFrance forum but no one could find an answer to my problem (http://www.minecraftforgefrance.fr/showthread.php?tid=2225). My classes : package fr.scarex.hilium.block; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.world.World; import fr.scarex.hilium.entity.EntitySit; import fr.scarex.hilium.tileentity.TileEntitySit; /** * @author SCAREX * */ public class BlockSit extends Block { protected BlockSit(Material material) { super(material); } @Override public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) { if (this.canSit(world, x, y, z, player, side, hitX, hitY, hitZ)) { Entity entity = world.getEntityByID(((TileEntitySit) world.getTileEntity(x, y, z)).getEntityId()); if (entity != null) ((EntitySit) entity).interactFirst(player); return true; } return false; } public boolean canSit(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) { return true; } @Override public void onBlockAdded(World world, int x, int y, int z) { EntitySit e = new EntitySit(world, x + 0.5D, y + 0.5D, z + 0.5D, this.getOffsetY(world, x, y, z)); world.spawnEntityInWorld(e); ((TileEntitySit) world.getTileEntity(x, y, z)).setEntityId(e.getEntityId()); } public float getOffsetY(World world, int x, int y, int z) { return 0.5F; } } package fr.scarex.hilium.tileentity; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.NetworkManager; import net.minecraft.network.Packet; import net.minecraft.network.play.server.S35PacketUpdateTileEntity; import net.minecraft.tileentity.TileEntity; /** * @author SCAREX * */ public class TileEntitySit extends TileEntity { protected int entityId; public int getEntityId() { return this.entityId; } public void setEntityId(int id) { this.entityId = id; } @Override public void readFromNBT(NBTTagCompound comp) { super.readFromNBT(comp); this.entityId = comp.getInteger("entityId"); } @Override public void writeToNBT(NBTTagCompound comp) { super.writeToNBT(comp); comp.setInteger("entityId", this.entityId); } @Override public Packet getDescriptionPacket() { NBTTagCompound comp = new NBTTagCompound(); this.writeToNBT(comp); return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, 0, comp); } @Override public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) { this.readFromNBT(pkt.func_148857_g()); } } package fr.scarex.hilium.entity; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.MathHelper; import net.minecraft.world.World; import fr.scarex.hilium.Hilium; import fr.scarex.hilium.block.BlockSit; /** * @author SCAREX * */ public class EntitySit extends Entity { protected float offsetY; public EntitySit(World world) { super(world); this.noClip = true; this.preventEntitySpawning = true; this.setSize(0.0F, 0.0F); this.offsetY = 0.0F; } public EntitySit(World world, double x, double y, double z, float offsetY) { this(world); this.setPosition(x, y, z); this.offsetY = offsetY; } @Override protected void entityInit() {} @Override protected void readEntityFromNBT(NBTTagCompound comp) {} @Override protected void writeEntityToNBT(NBTTagCompound comp) {} @Override public void onUpdate() { super.onUpdate(); if (!(this.worldObj.getBlock(MathHelper.floor_double(this.posX), MathHelper.floor_double(this.posY), MathHelper.floor_double(this.posZ)) instanceof BlockSit)) this.kill(); } @Override public boolean interactFirst(EntityPlayer p) { if (this.riddenByEntity != null) return true; if (!this.worldObj.isRemote) p.mountEntity(this); return true; } @Override public double getMountedYOffset() { return this.offsetY; } } When I click the block the first time, it works, but after the game show the message "Press shift to dismount" but I can move around, and when I throw an Item on the floor, it is threw beside the block, which indicates that this is a problem with synchronization.
-
Problem solved, it was just eclipse doing strange things : The debug mode was telling me that the problem was from Gson but the problem was from a pattern in my class (I found it when I launch the game in run mode instead of debug mode)
-
The gson is in my buildpath : http://puu.sh/hv727/bb86fe2872.png
-
Recently I've been using Gson but in the last days I had problems with Gson, so I have deleted my last modifications but nothing could correct this problem. (I'm using MinecraftForge 1.8-11.14.1.1397) Stacktrace : Thread [updater Thread] (Suspended (exception NoClassDefFoundError)) Gson.fromJson(JsonReader, Type) line: 820 Gson.fromJson(Reader, Type) line: 768 Gson.fromJson(String, Type) line: 717 Gson.fromJson(String, Class<T>) line: 689 Updater$1.run() line: 114 My code : package fr.scarex.updater; import java.io.InputStream; import java.lang.reflect.Method; import java.lang.reflect.Type; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.Proxy; import java.net.URL; import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; import java.util.Iterator; import java.util.List; import java.util.Map.Entry; import java.util.TreeMap; import java.util.regex.Matcher; import java.util.regex.Pattern; import net.minecraft.client.Minecraft; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.common.Loader; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.ModContainer; import net.minecraftforge.fml.common.event.FMLInitializationEvent; import org.apache.commons.io.Charsets; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.ArrayUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonArray; import com.google.gson.JsonDeserializationContext; import com.google.gson.JsonDeserializer; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParseException; import fr.scarex.updater.exception.VersionFormatException; import fr.scarex.updater.handler.UpdaterHandler; /** * @author SCAREX */ @Mod(modid = Updater.MODID, name = Updater.NAME, version = Updater.VERSION, clientSideOnly = true) public class Updater { public static final String MODID = "supdater"; public static final String NAME = "Updater"; public static final String VERSION = "0.1.0-SNAPSHOT"; public static final Logger logger = LogManager.getLogger("Updater"); public static Gson gson; public static Version mcversion; @Mod.EventHandler public void init(FMLInitializationEvent event) { GsonBuilder builder = new GsonBuilder(); builder.registerTypeAdapter(Version.class, new VersionDeserializer()); builder.registerTypeAdapter(ModVersions.class, new ModVersionsDeserializer()); gson = builder.create(); MinecraftForge.EVENT_BUS.register(new UpdaterHandler()); doUpdate(); } public static ArrayList<ModVersions> modsList = new ArrayList<Updater.ModVersions>(); public String getVersionFileURL() { return "http://scarex.on.vg/Updater/versions.json"; } public String getUpdaterVersion() { return Updater.VERSION; } public static void doUpdate() { Thread t = new Thread("Updater Thread") { @Override public void run() { try { mcversion = Version.parseMcVersion(); } catch (VersionFormatException e1) { e1.printStackTrace(); } modsList.clear(); for (ModContainer mod : Loader.instance().getModList()) { if (mod.getMod() != null) { Class<?> clazz = mod.getMod().getClass(); if (!clazz.getCanonicalName().startsWith("net.minecraft")) { try { String rawVersion; Version currentVersion; try { Method versionMethod = clazz.getDeclaredMethod("getUpdaterVersion"); rawVersion = (String) versionMethod.invoke(mod.getMod()); currentVersion = Version.parseVersion(rawVersion); } catch (Exception e) { rawVersion = mod.getVersion(); currentVersion = Version.parseVersion(rawVersion); } String stringUrl = (String) clazz.getDeclaredMethod("getVersionFileURL").invoke(mod.getMod()); URL versionFile = new URL(stringUrl); InputStream is = null; try { HttpURLConnection con = (HttpURLConnection) versionFile.openConnection(Proxy.NO_PROXY); con.setConnectTimeout(15000); con.setReadTimeout(15000); is = con.getInputStream(); ModVersions modV = gson.fromJson(IOUtils.toString(is, Charsets.UTF_, ModVersions.class); modV.setModContainer(mod); modV.setVersionFileLink(stringUrl); modV.setCurrentVersion(currentVersion); modsList.add(modV); } catch (Exception e) { logger.warn("Couldn't get version file with given url : " + versionFile, e); } IOUtils.closeQuietly(is); } catch (Exception e) { logger.warn("Couldn't retrieve mod's informations from mod " + mod.getName() + "(" + clazz.getCanonicalName() + ")", e); } } } } } }; t.start(); } public static class ModVersions { public static final Comparator<String> comparator = new Comparator<String>() { @Override public int compare(String s, String s1) { try { return Version.parseVersion(s).isNewerOrEqualWithSameIndex(mcversion, 1) ? (Version.parseVersion(s1).isNewerOrEqualWithSameIndex(mcversion, 1) ? s.compareTo(s1) : 1) : -1; } catch (VersionFormatException e) { e.printStackTrace(); } return 0; } }; public static final Pattern PARAMETERS_FINDER = Pattern.compile("{{(.+)}}"); private ModContainer modContainer; private String versionFileLink; private String downloadLink; private TreeMap<String, Version[]> versions; private Version currentVersion; public ModVersions(ModContainer modC, String modid, String versionFile, String dlink, TreeMap<String, Version[]> versions, Version currentV) { this.modContainer = modC; this.versionFileLink = versionFile; this.downloadLink = dlink; this.versions = versions; this.currentVersion = currentV; } public ModVersions(String dlink, TreeMap<String, Version[]> versions) { this.downloadLink = dlink; this.versions = versions; } public Version getLatestVersionForUser(byte usertype, boolean acceptSnapshots) { Entry<String, Version[]> entry = this.versions.lastEntry(); if ((entry.getKey().substring(0, 3)).equalsIgnoreCase(Minecraft.getMinecraft().getVersion().substring(0, 3))) { Version[] versions = entry.getValue(); Version version = versions[0]; for (int i = 0; i < versions.length; i++) { if (versions[i].isNewerThanOrEqual(version) && versions[i].getUserType() == usertype && (versions[i].isSnapshot() && acceptSnapshots)) version = versions[i]; } return version; } return null; } public URL getDownloadLinkForVersion(Version v, String mcversion) { String beginning = this.versionFileLink.replaceFirst("/(*)$", ""); String middle = this.downloadLink != null ? this.downloadLink : ""; String end = v.getDownloadLink() != null ? v.getDownloadLink() : ""; logger.info(beginning + " | " + middle + " | " + end); String fullURL = ""; if (v.getDownloadLink().startsWith("http://") || v.getDownloadLink().startsWith("https://")) { fullURL = v.getDownloadLink(); } else { if (middle.startsWith("http://") || middle.startsWith("https://")) fullURL = middle + end; else fullURL = beginning + middle + end; } StringBuffer sb = new StringBuffer(fullURL); Matcher m = PARAMETERS_FINDER.matcher(fullURL); while (m.find()) { if ("name".equalsIgnoreCase(m.group(1))) m.appendReplacement(sb, v.getName()); else if ("version".equalsIgnoreCase(m.group(1))) m.appendReplacement(sb, v.getVersionString()); else if ("user-type".equalsIgnoreCase(m.group(1))) m.appendReplacement(sb, "" + v.getUserType()); else if ("importance".equalsIgnoreCase(m.group(1))) m.appendReplacement(sb, "" + v.getImportance()); else if ("mc-version".equalsIgnoreCase(m.group(1))) m.appendReplacement(sb, mcversion); } m.appendTail(sb); logger.info(sb.toString()); URL url = null; try { url = new URL(sb.toString()); } catch (MalformedURLException e) { logger.warn(e); } return url; } public ModContainer getModContainer() { return this.modContainer; } public void setModContainer(ModContainer modC) { this.modContainer = modC; } public String getVersionFileLink() { return versionFileLink; } public void setVersionFileLink(String versionFileLink) { this.versionFileLink = versionFileLink; } public Version getCurrentVersion() { return currentVersion; } public void setCurrentVersion(Version currentVersion) { this.currentVersion = currentVersion; } public TreeMap<String, Version[]> getVersions() { return versions; } public void setVersions(TreeMap<String, Version[]> versions) { this.versions = versions; } @Override public String toString() { return "ModVersions [modContainer=" + modContainer + ", versionFileLink=" + versionFileLink + ", downloadLink=" + downloadLink + "]"; } public String getMapAsString() { Iterator ite = versions.entrySet().iterator(); String output = ""; while (ite.hasNext()) { Entry<String, Version[]> entry = (Entry<String, Updater.Version[]>) ite.next(); output += "[Mc-version=" + entry.getKey() + ", versions=" + Arrays.toString(entry.getValue()) + "]\n"; } return output; } } public static class Version implements Comparable<Version> { private static final Pattern pattern = Pattern.compile("(?i)(\\d+)((?:\\.\\d+)*)([a-zA-Z])?(-snapshot)?"); private static final Pattern patternMC = Pattern.compile("(?i)(\\d+)((?:\\.\\d+)*)([a-z- ]*)"); private String name; private String changes; private String downloadLink; private String versionString; private int[] releases; private char releaseChar; private boolean snapshot; private byte userType; private byte importance; public Version(String versionS, char releaseChar, boolean snapshot, int ... releases) { this.versionString = versionS; this.releaseChar = releaseChar; this.snapshot = snapshot; this.releases = releases; } public boolean isNewerThanOrEqual(Version v) { if (v.getLength() > this.getLength()) return false; else if (v.getLength() < this.getLength()) return true; for (int i = 0; i < this.getLength(); i++) { if (v.getIndex(i) > this.getIndex(i)) return false; else if (v.getIndex(i) < this.getIndex(i)) return true; } if (v.getReleaseChar() < this.getReleaseChar()) return true; return true; } public boolean isNewerOrEqualWithSameIndex(Version v, int index) { for (int i = 0; i <= index; i++) { if (v.getIndex(i) != this.getIndex(i)) return false; } for (int i = index + 1; i < Math.min(this.getLength(), v.getLength()); i++) { if (this.getIndex(i) < v.getIndex(i)) return false; } return true; } @Override public int compareTo(Version v) { return this.isNewerThanOrEqual(v) ? -1 : 1; } public static Version parseVersion(String version) throws VersionFormatException { Matcher m = pattern.matcher(version); if (m.matches()) { List<Integer> list = new ArrayList<Integer>(); list.add(new Integer(m.group(1))); String[] array = m.group(2).split("\\."); for (int i = 1; i < array.length; i++) { list.add(Integer.parseInt(array[i])); } char c = m.group(3) != null && m.group(3).length() == 1 && Character.isAlphabetic(m.group(3).charAt(0)) ? m.group(3).charAt(0) : 'a'; boolean snapshot = "-snapshot".equalsIgnoreCase(m.group(4)) ? true : false; return new Version(version, c, snapshot, ArrayUtils.toPrimitive(list.toArray(new Integer[0]))); } else { throw new VersionFormatException(version); } } public static Version parseMcVersion() throws VersionFormatException { Matcher m = patternMC.matcher(Minecraft.getMinecraft().getVersion()); if (m.matches()) { List<Integer> list = new ArrayList<Integer>(); list.add(new Integer(m.group(1))); String[] array = m.group(2).split("\\."); for (int i = 1; i < array.length; i++) { list.add(Integer.parseInt(array[i])); } return new Version(Minecraft.getMinecraft().getVersion(), 'a', false, ArrayUtils.toPrimitive(list.toArray(new Integer[0]))); } else { throw new VersionFormatException(Minecraft.getMinecraft().getVersion()); } } public int getIndex(int i) { return this.releases[i]; } public int getLength() { return this.releases.length; } public String getName() { return name; } public void setName(String name) { this.name = name; } public char getReleaseChar() { return releaseChar; } public void setReleaseChar(char releaseChar) { this.releaseChar = releaseChar; } public boolean isSnapshot() { return snapshot; } public void setSnapshot(boolean snapshot) { this.snapshot = snapshot; } public byte getUserType() { return userType; } public void setUserType(byte userType) { this.userType = userType; } public String getChanges() { return changes; } public void setChanges(String changes) { this.changes = changes; } public String getDownloadLink() { return downloadLink; } public void setDownloadLink(String downloadLink) { this.downloadLink = downloadLink; } public byte getImportance() { return importance; } public void setImportance(byte importance) { this.importance = importance; } public String getVersionString() { return versionString; } public void setVersionString(String versionString) { this.versionString = versionString; } @Override public String toString() { return "Version [name=" + name + ", releases=" + Arrays.toString(releases) + ", releaseChar=" + releaseChar + ", snapshot=" + snapshot + ", userType=" + userType + "]"; } public String toName() { String output = ""; for (int i = 0; i < releases.length - 1; i++) { output += releases[i] + "."; } return output + releases[releases.length - 1] + (releaseChar == 'a' ? "" : releaseChar) + (snapshot ? "-snapshot" : ""); } } public static class VersionDeserializer implements JsonDeserializer<Version> { @Override public Version deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext ctx) throws JsonParseException { JsonObject obj = json.getAsJsonObject(); Version version = null; try { version = Version.parseVersion(obj.get("version").getAsString()); } catch (VersionFormatException e) { throw new JsonParseException("version couldn't be deserialized"); } String name = obj.has("name") ? obj.get("name").getAsString() : ""; version.setName(name); byte usertype = obj.has("user-type") ? obj.get("user-type").getAsByte() : 0; version.setUserType(usertype); String changes = obj.has("changes") ? obj.get("changes").getAsString() : ""; version.setChanges(changes); byte imp = obj.has("importance") ? obj.get("importance").getAsByte() : 0; version.setImportance(imp); String dl = obj.has("download-link") ? obj.get("download-link").getAsString() : ""; version.setDownloadLink(dl); return version; } } public static class ModVersionsDeserializer implements JsonDeserializer<ModVersions> { @Override public ModVersions deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext ctx) throws JsonParseException { JsonObject obj = json.getAsJsonObject(); TreeMap<String, Version[]> map = new TreeMap<String, Version[]>(ModVersions.comparator); String dlink = obj.has("download-link") ? obj.get("download-link").getAsString() : ""; JsonObject mcvobj = obj.get("mc-versions").getAsJsonObject(); Iterator ite = mcvobj.entrySet().iterator(); while (ite.hasNext()) { Entry<String, JsonElement> entry = (Entry<String, JsonElement>) ite.next(); JsonArray jarray = entry.getValue().getAsJsonArray(); Version[] versions = new Version[jarray.size()]; Iterator ite1 = jarray.iterator(); int i = 0; while (ite1.hasNext()) { JsonObject vobj = (JsonObject) ite1.next(); versions[i] = ctx.<Version> deserialize(vobj, Version.class); i++; } Arrays.sort(versions); map.put(entry.getKey(), versions); } return new ModVersions(dlink, map); } } } I searched on Google and MinecraftForgeFrance but no one could help me.
-
It could be great if there were an option in the server.properties file to disable some anti-cheats checks, example : (the code is from NetHandlerPlayServer.class) if(*boolean*) //*boolean* is the boolean from the server.properties file if (!this.hasMoved) { return; } double d11 = d8 - this.playerEntity.posX; double d12 = d9 - this.playerEntity.posY; double d13 = d10 - this.playerEntity.posZ; //BUGFIX: min -> max, grabs the highest distance double d14 = Math.max(Math.abs(d11), Math.abs(this.playerEntity.motionX)); double d15 = Math.max(Math.abs(d12), Math.abs(this.playerEntity.motionY)); double d16 = Math.max(Math.abs(d13), Math.abs(this.playerEntity.motionZ)); double d17 = d14 * d14 + d15 * d15 + d16 * d16; if (d17 > 100.0D && (!this.serverController.isSinglePlayer() || !this.serverController.getServerOwner().equals(this.playerEntity.getName()))) { logger.warn(this.playerEntity.getName() + " moved too quickly! " + d11 + "," + d12 + "," + d13 + " (" + d14 + ", " + d15 + ", " + d16 + ")"); this.setPlayerLocation(this.lastPosX, this.lastPosY, this.lastPosZ, this.playerEntity.rotationYaw, this.playerEntity.rotationPitch); return; } } Because currently my server has a lot of "[Player] move to quickly..." but this check is useless because it will be a friends-only server. (sorry if my english is bad)