-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
104 changed files
with
3,466 additions
and
581 deletions.
There are no files selected for viewing
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
File renamed without changes.
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
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,5 @@ | ||
package huige233.transcend.api; | ||
|
||
public enum BossType { | ||
TRANSCEND,NORMAL_BOSS; | ||
} |
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,74 @@ | ||
package huige233.transcend.api; | ||
|
||
|
||
import net.minecraftforge.fml.common.gameevent.TickEvent; | ||
|
||
import java.util.EnumSet; | ||
import java.util.Iterator; | ||
import java.util.LinkedList; | ||
|
||
public class ClientScheduler implements ITickHandler { | ||
private static long clientTick = 0; | ||
private static final Object lock = new Object(); | ||
|
||
private boolean inTick = false; | ||
private LinkedList<Tuple<Runnable, Counter>> queue = new LinkedList<>(); | ||
private LinkedList<Tuple<Runnable, Integer>> waiting = new LinkedList<>(); | ||
|
||
@Override | ||
public void tick(TickEvent.Type type, Object... context) { | ||
clientTick++; | ||
|
||
inTick = true; | ||
synchronized (lock) { | ||
inTick = true; | ||
Iterator<Tuple<Runnable, Counter>> iterator = queue.iterator(); | ||
while (iterator.hasNext()) { | ||
Tuple<Runnable, Counter> r = iterator.next(); | ||
r.value.decrement(); | ||
if(r.value.value <= 0) { | ||
r.key.run(); | ||
iterator.remove(); | ||
} | ||
} | ||
inTick = false; | ||
for (Tuple<Runnable, Integer> wait : waiting) { | ||
queue.addLast(new Tuple<>(wait.key, new Counter(wait.value))); | ||
} | ||
} | ||
waiting.clear(); | ||
} | ||
|
||
public static long getClientTick() { | ||
return clientTick; | ||
} | ||
|
||
public static long getIndependentClientTick() { | ||
return System.currentTimeMillis() / 50; | ||
} | ||
|
||
@Override | ||
public EnumSet<TickEvent.Type> getHandledTypes() { | ||
return EnumSet.of(TickEvent.Type.CLIENT); | ||
} | ||
|
||
@Override | ||
public boolean canFire(TickEvent.Phase phase) { | ||
return phase == TickEvent.Phase.END; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "Client Scheduler"; | ||
} | ||
|
||
public void addRunnable(Runnable r, int tickDelay) { | ||
synchronized (lock) { | ||
if(inTick) { | ||
waiting.addLast(new Tuple<>(r, tickDelay)); | ||
} else { | ||
queue.addLast(new Tuple<>(r, new Counter(tickDelay))); | ||
} | ||
} | ||
} | ||
} |
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,17 @@ | ||
package huige233.transcend.api; | ||
|
||
public class Counter { | ||
public int value; | ||
|
||
public Counter(int value) { | ||
this.value = value; | ||
} | ||
|
||
public void decrement() { | ||
value--; | ||
} | ||
|
||
public void increment() { | ||
value++; | ||
} | ||
} |
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,29 @@ | ||
package huige233.transcend.api; | ||
|
||
public interface IColorEffect { | ||
public boolean canRemove(); | ||
|
||
public boolean isRemoved(); | ||
|
||
public void flagAsRemoved(); | ||
|
||
public void clearRemoveFlag(); | ||
|
||
public RenderTarget getRenderTarget(); | ||
|
||
public void render(float pTicks); | ||
|
||
public void tick(); | ||
default public int getLayer() { | ||
return 0; | ||
} | ||
|
||
public static enum RenderTarget { | ||
|
||
OVERLAY_TEXT, | ||
RENDERLOOP | ||
|
||
} | ||
|
||
public static interface PreventRemoval {} | ||
} |
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,22 @@ | ||
package huige233.transcend.api; | ||
|
||
import net.minecraftforge.fml.common.gameevent.TickEvent; | ||
|
||
import java.util.EnumSet; | ||
|
||
public interface ITickHandler { | ||
public void tick(TickEvent.Type type, Object... context); | ||
|
||
/** | ||
* WORLD, context: world | ||
* SERVER, context: | ||
* CLIENT, context: | ||
* RENDER, context: pTicks | ||
* PLAYER, context: player, side | ||
*/ | ||
public EnumSet<TickEvent.Type> getHandledTypes(); | ||
|
||
public boolean canFire(TickEvent.Phase phase); | ||
|
||
public String getName(); | ||
} |
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,10 @@ | ||
package huige233.transcend.api; | ||
|
||
import java.util.UUID; | ||
|
||
public interface ITrBoss { | ||
public UUID getBoosInfoUuid(); | ||
public default BossType getBossType(){ | ||
return BossType.NORMAL_BOSS; | ||
} | ||
} |
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,80 @@ | ||
package huige233.transcend.api; | ||
|
||
|
||
import huige233.transcend.event.ClientInitEvent; | ||
import net.minecraftforge.common.MinecraftForge; | ||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; | ||
import net.minecraftforge.fml.common.gameevent.TickEvent; | ||
|
||
import java.util.HashMap; | ||
import java.util.LinkedList; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class TickManager { | ||
private static boolean firedFirstTick = false; | ||
private static final TickManager instance = new TickManager(); | ||
|
||
private Map<TickEvent.Type, List<ITickHandler>> registeredTickHandlers = new HashMap<>(); | ||
|
||
private TickManager() { | ||
for (TickEvent.Type type : TickEvent.Type.values()) { | ||
registeredTickHandlers.put(type, new LinkedList<>()); | ||
} | ||
} | ||
|
||
public static TickManager getInstance() { | ||
return instance; | ||
} | ||
|
||
public void register(ITickHandler handler) { | ||
for (TickEvent.Type type : handler.getHandledTypes()) { | ||
registeredTickHandlers.get(type).add(handler); | ||
} | ||
} | ||
|
||
@SubscribeEvent | ||
public void worldTick(TickEvent.WorldTickEvent event) { | ||
TickEvent.Phase ph = event.phase; | ||
for (ITickHandler handler : registeredTickHandlers.get(TickEvent.Type.WORLD)) { | ||
if(handler.canFire(ph)) handler.tick(TickEvent.Type.WORLD, event.world); | ||
} | ||
} | ||
|
||
@SubscribeEvent | ||
public void serverTick(TickEvent.ServerTickEvent event) { | ||
TickEvent.Phase ph = event.phase; | ||
for (ITickHandler handler : registeredTickHandlers.get(TickEvent.Type.SERVER)) { | ||
if(handler.canFire(ph)) handler.tick(TickEvent.Type.SERVER); | ||
} | ||
} | ||
|
||
@SubscribeEvent | ||
public void clientTick(TickEvent.ClientTickEvent event) { | ||
TickEvent.Phase ph = event.phase; | ||
for (ITickHandler handler : registeredTickHandlers.get(TickEvent.Type.CLIENT)) { | ||
if(handler.canFire(ph)) handler.tick(TickEvent.Type.CLIENT); | ||
} | ||
|
||
if(!firedFirstTick) { | ||
firedFirstTick = true; | ||
MinecraftForge.EVENT_BUS.post(new ClientInitEvent()); | ||
} | ||
} | ||
|
||
@SubscribeEvent | ||
public void renderTick(TickEvent.RenderTickEvent event) { | ||
TickEvent.Phase ph = event.phase; | ||
for (ITickHandler handler : registeredTickHandlers.get(TickEvent.Type.RENDER)) { | ||
if(handler.canFire(ph)) handler.tick(TickEvent.Type.RENDER, event.renderTickTime); | ||
} | ||
} | ||
|
||
@SubscribeEvent | ||
public void playerTick(TickEvent.PlayerTickEvent event) { | ||
TickEvent.Phase ph = event.phase; | ||
for (ITickHandler handler : registeredTickHandlers.get(TickEvent.Type.PLAYER)) { | ||
if(handler.canFire(ph)) handler.tick(TickEvent.Type.PLAYER, event.player, event.side); | ||
} | ||
} | ||
} |
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,44 @@ | ||
package huige233.transcend.api; | ||
|
||
public class Tuple<K, V> { | ||
|
||
public final K key; | ||
public final V value; | ||
|
||
public Tuple(K key, V value) { | ||
this.key = key; | ||
this.value = value; | ||
} | ||
|
||
public K getKey() { | ||
return key; | ||
} | ||
|
||
public V getValue() { | ||
return value; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
|
||
hellfirepvp.astralsorcery.common.util.data.Tuple tuple = (hellfirepvp.astralsorcery.common.util.data.Tuple) o; | ||
return (key == null ? tuple.key == null : key.equals(tuple.key)) && (value == null ? tuple.value == null : value.equals(tuple.value)); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
int result = key == null ? 0 : key.hashCode(); | ||
result = 31 * result + (value == null ? 0 : value.hashCode()); | ||
return result; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Tuple{" + | ||
"key=" + key + | ||
", value=" + value + | ||
'}'; | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
src/main/java/huige233/transcend/asm/transformers/ChatAllowedCharactersTransformer.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,50 @@ | ||
package huige233.transcend.asm.transformers; | ||
|
||
import org.objectweb.asm.*; | ||
import org.objectweb.asm.tree.AbstractInsnNode; | ||
import org.objectweb.asm.tree.ClassNode; | ||
import org.objectweb.asm.tree.LabelNode; | ||
import org.objectweb.asm.tree.MethodNode; | ||
|
||
import java.util.Arrays; | ||
import java.util.Map; | ||
|
||
public class ChatAllowedCharactersTransformer implements ITransformer { | ||
|
||
@Override | ||
public String targetClass() { | ||
return "net.minecraft.util.ChatAllowedCharacters"; | ||
} | ||
|
||
@Override | ||
public ClassNode transform(ClassNode cn) { | ||
|
||
for (MethodNode method : cn.methods) { | ||
String name = method.name; | ||
String desc = method.desc; | ||
if (name.equals("a") && desc.equals("(C)Z") || name.equals("isAllowedCharacter")) { | ||
Arrays.stream(method.instructions.toArray()) | ||
.filter(abstractInsnNode -> abstractInsnNode.getOpcode() == Opcodes.SIPUSH) | ||
.findFirst().ifPresent(abstractInsnNode -> { | ||
method.instructions.set(abstractInsnNode, new AbstractInsnNode(abstractInsnNode.getOpcode()) { | ||
@Override | ||
public int getType() { | ||
return abstractInsnNode.getType(); | ||
} | ||
|
||
@Override | ||
public void accept(MethodVisitor cv) { | ||
cv.visitIntInsn(Opcodes.SIPUSH, 127); | ||
} | ||
|
||
@Override | ||
public AbstractInsnNode clone(Map<LabelNode, LabelNode> labels) { | ||
return abstractInsnNode.clone(labels); | ||
} | ||
}); | ||
}); | ||
} | ||
} | ||
return cn; | ||
} | ||
} |
Oops, something went wrong.