Skip to content

Commit

Permalink
Reforged: IReachEntity related stuff, version check and Reforged version
Browse files Browse the repository at this point in the history
  • Loading branch information
Kleadron authored and halotroop2288 committed Nov 5, 2023
1 parent cedd1c3 commit a0cebf4
Show file tree
Hide file tree
Showing 6 changed files with 210 additions and 27 deletions.
6 changes: 6 additions & 0 deletions forge_common/net/minecraft/src/forge/ForgeHooks.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ static void initTools() {
if(toolInit) return;
toolInit=true;

// This is wacky

MinecraftForge.setToolClass(Item.pickaxeWood,"pickaxe",0);
MinecraftForge.setToolClass(Item.pickaxeStone,"pickaxe",1);
MinecraftForge.setToolClass(Item.pickaxeSteel,"pickaxe",2);
Expand Down Expand Up @@ -137,6 +139,10 @@ static void initTools() {
// TODO: add other tool tables.
}

public static void touch() {
// touch :)
}

public static final int majorVersion=1;
public static final int minorVersion=0;
public static final int revisionVersion=6;
Expand Down
38 changes: 21 additions & 17 deletions forge_common/net/minecraft/src/forge/MinecraftForge.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import net.minecraft.src.Item;
import net.minecraft.src.ItemStack;
import net.minecraft.src.World;
import net.minecraft.src.reforged.ReforgedHooks;

import java.util.*;

Expand Down Expand Up @@ -171,6 +172,8 @@ public static void killMinecraft(String modname, String msg) {
throw new RuntimeException(modname+": "+msg);
}

public static boolean disableVersionCheckCrash = false;

/**
* Version checking. Ensures that a sufficiently recent version of Forge
* is installed. Will result in a fatal error if the major versions
Expand All @@ -179,6 +182,14 @@ public static void killMinecraft(String modname, String msg) {
*/
public static void versionDetect(String modname,
int major, int minor, int revision) {

if (disableVersionCheckCrash) {
// invoke static constructor for forgehooks
ReforgedHooks.touch();
System.out.println(modname + ": Forge version detect was called, but strict crashing is disabled. Expected version "+major+"."+minor+"."+revision);
return;
}

if(major!=ForgeHooks.majorVersion) {
killMinecraft(modname,"MinecraftForge Major Version Mismatch, expecting "+major+".x.x");
} else if(minor!=ForgeHooks.minorVersion) {
Expand All @@ -201,6 +212,14 @@ public static void versionDetect(String modname,
*/
public static void versionDetectStrict(String modname,
int major, int minor, int revision) {

if (disableVersionCheckCrash) {
// invoke static constructor for forgehooks
ReforgedHooks.touch();
System.out.println(modname + ": Forge version detect was called, but strict crashing is disabled. Expected version "+major+"."+minor+"."+revision);
return;
}

if(major!=ForgeHooks.majorVersion) {
killMinecraft(modname,"MinecraftForge Major Version Mismatch, expecting "+major+".x.x");
} else if(minor!=ForgeHooks.minorVersion) {
Expand All @@ -213,23 +232,8 @@ public static void versionDetectStrict(String modname,
killMinecraft(modname,"MinecraftForge Too Old, need at least "+major+"."+minor+"."+revision);
}
}



















// Ore Dictionary
// ------------------------------------------------------------
private static LinkedList<IOreHandler> oreHandlers = new LinkedList<IOreHandler>();
Expand Down
2 changes: 2 additions & 0 deletions forge_common/net/minecraft/src/reforged/IReachEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@

public interface IReachEntity
{
// If this item is applicable to a custom range
public abstract boolean reachEntityItemMatches(ItemStack itemstack);

// The maximum distance in meters/blocks
public abstract float getReachEntity(ItemStack itemstack);
}
86 changes: 76 additions & 10 deletions forge_common/net/minecraft/src/reforged/Reforged.java
Original file line number Diff line number Diff line change
@@ -1,32 +1,37 @@
/**
* This software is provided under the terms of the Minecraft Forge Public
* License v1.1.
*/
package net.minecraft.src.reforged;

import java.util.ArrayList;
import java.util.Iterator;

import net.minecraft.src.EntityPlayer;
import net.minecraft.src.ItemStack;
import net.minecraft.src.forge.MinecraftForge;

public class Reforged {

private static ArrayList<IReachEntity> reachesEntity = new ArrayList<IReachEntity>();
private static ArrayList<IReachEntity> reachesEntity = new ArrayList<IReachEntity>();

/* Entity Reach - reachAdd
* Registers an IReachEntity interface provider to the list to be used when
* reachGetEntityPlayer is called
*/
/* Entity Reach - reachAdd
* Registers an IReachEntity interface provider to the list to be used when
* reachGetEntityPlayer is called
*/
public static void reachAdd(IReachEntity ireachentity)
{
reachesEntity.add(ireachentity);
}

/* Entity Reach - reachGetEntityPlayer
* Returns the max reach distance provided by an interface provider
* added by reachAdd
*/
* Returns the max reach distance provided by an interface provider
* added by reachAdd
*/
public static float reachGetEntityPlayer(EntityPlayer player)
{
ItemStack itemstack = player.inventory.getCurrentItem();

for(Iterator<IReachEntity> iterator = reachesEntity.iterator(); iterator.hasNext();)
{
IReachEntity ireachentity = iterator.next();
Expand All @@ -35,7 +40,68 @@ public static float reachGetEntityPlayer(EntityPlayer player)
return ireachentity.getReachEntity(itemstack);
}
}

return 3F;
}

public static boolean disableVersionCheckCrash = false;

/**
* Version checking. Ensures that a sufficiently recent version of Reforged
* is installed. Will result in a fatal error if the major versions
* mismatch or if the version is too old. Will print a warning message if
* the minor versions don't match.
*/
public static void versionDetect(String modname,
int major, int minor, int revision) {

if (disableVersionCheckCrash) {
// invoke static constructor for reforgedhooks
ReforgedHooks.touch();
System.out.println(modname + ": Reforged version detect was called, but strict crashing is disabled. Expected version "+major+"."+minor+"."+revision);
return;
}

if(major!=ReforgedHooks.majorVersion) {
MinecraftForge.killMinecraft(modname,"Reforged Major Version Mismatch, expecting "+major+".x.x");
} else if(minor!=ReforgedHooks.minorVersion) {
if(minor>ReforgedHooks.minorVersion) {
MinecraftForge.killMinecraft(modname,"Reforged Too Old, need at least "+major+"."+minor+"."+revision);
} else {
System.out.println(modname + ": Reforged minor version mismatch, expecting "+major+"."+minor+".x, may lead to unexpected behavior");
}
} else if(revision>ReforgedHooks.revisionVersion) {
MinecraftForge.killMinecraft(modname,"Reforged Too Old, need at least "+major+"."+minor+"."+revision);
}
}

/**
* Strict version checking. Ensures that a sufficiently recent version of
* Reforged is installed. Will result in a fatal error if the major or minor
* versions mismatch or if the version is too old. Use this function for
* mods that use recent, new, or unstable APIs to prevent
* incompatibilities.
*/
public static void versionDetectStrict(String modname,
int major, int minor, int revision) {

if (disableVersionCheckCrash) {
// invoke static constructor for reforgedhooks
ReforgedHooks.touch();
System.out.println(modname + ": Reforged version detect was called, but strict crashing is disabled. Expected version "+major+"."+minor+"."+revision);
return;
}

if(major!=ReforgedHooks.majorVersion) {
MinecraftForge.killMinecraft(modname,"Reforged Major Version Mismatch, expecting "+major+".x.x");
} else if(minor!=ReforgedHooks.minorVersion) {
if(minor>ReforgedHooks.minorVersion) {
MinecraftForge.killMinecraft(modname,"Reforged Too Old, need at least "+major+"."+minor+"."+revision);
} else {
MinecraftForge.killMinecraft(modname,"Reforged minor version mismatch, expecting "+major+"."+minor+".x");
}
} else if(revision>ReforgedHooks.revisionVersion) {
MinecraftForge.killMinecraft(modname,"Reforged Too Old, need at least "+major+"."+minor+"."+revision);
}
}
}
19 changes: 19 additions & 0 deletions forge_common/net/minecraft/src/reforged/ReforgedHooks.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* This software is provided under the terms of the Minecraft Forge Public
* License v1.1.
*/
package net.minecraft.src.reforged;

public class ReforgedHooks {

public static void touch() {
// touch :)
}

public static final int majorVersion=1;
public static final int minorVersion=0;
public static final int revisionVersion=0;
static {
System.out.printf("Reforged V%d.%d.%d Initialized\n",majorVersion,minorVersion,revisionVersion);
}
}
86 changes: 86 additions & 0 deletions minecraft.patch
Original file line number Diff line number Diff line change
Expand Up @@ -1410,6 +1410,49 @@ diff -rN -r --strip-trailing-cr ../src_base/minecraft/net/minecraft/src/WorldRen
< {
< tessellator = Tessellator.instance;
< }
diff -rN -r --strip-trailing-cr ../src_base/minecraft/net/minecraft/src/mod_Reforged.java ../src_work/minecraft/net/minecraft/src/mod_Reforged.java
0a1,40
> /**
> * This software is provided under the terms of the Minecraft Forge Public
> * License v1.1.
> */
>
> package net.minecraft.src;
>
> import net.minecraft.src.forge.ForgeHooks;
> import net.minecraft.src.reforged.IReachEntity;
> import net.minecraft.src.reforged.Reforged;
> import net.minecraft.src.reforged.ReforgedHooks;
>
> public class mod_Reforged extends BaseModMp implements IReachEntity {
>
> final boolean testEnabled = false;
>
> public mod_Reforged() {
> if (testEnabled)
> Reforged.reachAdd(this);
> }
>
> @Override
> public String Version() {
> return String.format("[Forge %d.%d.%d, Reforged %d.%d.%d]",
> ForgeHooks.majorVersion, ForgeHooks.minorVersion, ForgeHooks.revisionVersion,
> ReforgedHooks.majorVersion, ReforgedHooks.minorVersion, ReforgedHooks.revisionVersion
> );
> }
>
> @Override
> public boolean reachEntityItemMatches(ItemStack itemstack) {
> return testEnabled;
> }
>
> @Override
> public float getReachEntity(ItemStack itemstack) {
> return 100f;
> }
>
> }
\ No newline at end of file
diff -rN -r --strip-trailing-cr ../src_base/minecraft_server/net/minecraft/server/MinecraftServ# ../src_work/minecraft_server/net/minecraft/server/MinecraftServ#
2c2,20
< *** 332,369 ****
Expand Down Expand Up @@ -2461,3 +2504,46 @@ diff -rN -r --strip-trailing-cr ../src_base/minecraft_server/net/minecraft/src/W
< protected int autosavePeriod;
---
> public int autosavePeriod;
diff -rN -r --strip-trailing-cr ../src_base/minecraft_server/net/minecraft/src/mod_Reforged.java ../src_work/minecraft_server/net/minecraft/src/mod_Reforged.java
0a1,40
> /**
> * This software is provided under the terms of the Minecraft Forge Public
> * License v1.1.
> */
>
> package net.minecraft.src;
>
> import net.minecraft.src.forge.ForgeHooks;
> import net.minecraft.src.reforged.IReachEntity;
> import net.minecraft.src.reforged.Reforged;
> import net.minecraft.src.reforged.ReforgedHooks;
>
> public class mod_Reforged extends BaseModMp implements IReachEntity {
>
> final boolean testEnabled = false;
>
> public mod_Reforged() {
> if (testEnabled)
> Reforged.reachAdd(this);
> }
>
> @Override
> public String Version() {
> return String.format("[Forge %d.%d.%d, Reforged %d.%d.%d]",
> ForgeHooks.majorVersion, ForgeHooks.minorVersion, ForgeHooks.revisionVersion,
> ReforgedHooks.majorVersion, ReforgedHooks.minorVersion, ReforgedHooks.revisionVersion
> );
> }
>
> @Override
> public boolean reachEntityItemMatches(ItemStack itemstack) {
> return testEnabled;
> }
>
> @Override
> public float getReachEntity(ItemStack itemstack) {
> return 100f;
> }
>
> }
\ No newline at end of file

0 comments on commit a0cebf4

Please sign in to comment.