Skip to content

Commit

Permalink
Some code modi
Browse files Browse the repository at this point in the history
  • Loading branch information
Mgazul committed Mar 16, 2023
1 parent cc9652e commit 7368e4f
Show file tree
Hide file tree
Showing 26 changed files with 84 additions and 158 deletions.
2 changes: 2 additions & 0 deletions src/main/java/cn/academy/AcademyCraft.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ private static void preInit(FMLPreInitializationEvent event) {
log.info("Starting AcademyCraft");
log.info("Copyright (c) Lambda Innovation, 2013-2018");
log.info("https://ac.li-dev.cn/");
log.info("Copyright (c) MohistMC, 2023-2023");
log.info("https://www.mohistmc.cn");
recipes = new RecipeRegistry();

config = new Configuration(event.getSuggestedConfigurationFile());
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/cn/academy/ability/CategoryManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public Category getCategory(String name) {

private void bake() {
_baked = true;
catList.sort(Comparator.comparing(it -> it.getName()));
catList.sort(Comparator.comparing(Category::getName));
for (int idx = 0; idx < catList.size(); ++idx) {
catList.get(idx).catID = idx;
}
Expand Down
8 changes: 1 addition & 7 deletions src/main/java/cn/academy/ability/context/ClientRuntime.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,7 @@ public void tick() {

// Remove dead keys
{
Iterator<Entry<Integer, KeyState>> iter = keyStates.entrySet().iterator();
while (iter.hasNext()) {
Entry<Integer, KeyState> ent = iter.next();
if (!ent.getValue().realState && !delegates.containsKey(ent.getKey())) {
iter.remove();
}
}
keyStates.entrySet().removeIf(ent -> !ent.getValue().realState && !delegates.containsKey(ent.getKey()));
}

// Update override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ private void s_tick()
ctx.addSkillExp(1e-6f);

// Find the entities that are 'colliding' with the shield.
List<Entity> candidates = WorldUtils.getEntities(player, 3, basicSelector.and(t -> isEntityReachable(t)).and(EntitySelectors.exclude(player)));
List<Entity> candidates = WorldUtils.getEntities(player, 3, basicSelector.and(this::isEntityReachable).and(EntitySelectors.exclude(player)));
for (Entity e : candidates) {
if (e.hurtResistantTime <= 0 && ctx.consume(getAbsorbOverload(), getAbsorbConsumption()))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public ShiftTeleport()
@SideOnly(Side.CLIENT)
public void activate(ClientRuntime rt, int keyID)
{
activateSingleKey2(rt, keyID, p -> new STContext(p));
activateSingleKey2(rt, keyID, STContext::new);
}

@Override
Expand Down Expand Up @@ -218,15 +218,10 @@ List<Entity> getTargetsInLine()
Vec3d v0= new Vec3d(player.posX, player.posY, player.posZ);
Vec3d v1 = new Vec3d(dest[0] + .5, dest[1] + .5, dest[2] + .5);
AxisAlignedBB area = WorldUtils.minimumBounds(v0, v1);
Predicate<Entity> pred = EntitySelectors.living().and(EntitySelectors.exclude(player)).and(new Predicate<Entity>() {

@Override
public boolean test(Entity entity){
double hw = entity.width / 2;
return VecUtils.checkLineBox(new Vec3d(entity.posX - hw, entity.posY, entity.posZ - hw),
new Vec3d(entity.posX + hw, entity.posY + entity.height, entity.posZ + hw), v0, v1) != null;
}

Predicate<Entity> pred = EntitySelectors.living().and(EntitySelectors.exclude(player)).and(entity -> {
double hw = entity.width / 2;
return VecUtils.checkLineBox(new Vec3d(entity.posX - hw, entity.posY, entity.posZ - hw),
new Vec3d(entity.posX + hw, entity.posY + entity.height, entity.posZ + hw), v0, v1) != null;
});
return WorldUtils.getEntities(player.world, area, pred);
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/cn/academy/client/auxgui/KeyHintUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ private void addDrawing() {
});

int availIdx = 0;
for (int i = 0; i < groups.size(); ++i) {
Collection<DelegateNode> nodes = map.get(groups.get(i));
for (String group : groups) {
Collection<DelegateNode> nodes = map.get(group);
if (!nodes.isEmpty()) {
final double x = -200 - availIdx * 200;
double y = 0;
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/cn/academy/client/auxgui/PresetEditUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -351,10 +351,8 @@ private class TransitPage extends Page {
public TransitPage(int _id) {
super(_id);

listen(FrameEvent.class, (w, e) ->
{
DrawTexture.get(w).color.setAlpha(alpha);
});
listen(FrameEvent.class, (w, e) ->
DrawTexture.get(w).color.setAlpha(alpha));
}

@Override
Expand Down
32 changes: 11 additions & 21 deletions src/main/java/cn/academy/client/auxgui/TerminalUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -264,35 +264,25 @@ private void initGui() {
createTime = GameTimer.getTime();

root.getWidget("arrow_up").listen(FrameEvent.class,
(w, e) -> {
w.getComponent(DrawTexture.class).enabled = scroll > 0;
});
(w, e) -> w.getComponent(DrawTexture.class).enabled = scroll > 0);

root.getWidget("arrow_up").listen(FrameEvent.class,
(w, e) -> {
w.getComponent(DrawTexture.class).enabled = scroll > 0;
});
(w, e) -> w.getComponent(DrawTexture.class).enabled = scroll > 0);

root.getWidget("arrow_down").listen(FrameEvent.class,
(w, e) -> {
w.getComponent(DrawTexture.class).enabled = scroll < getMaxScroll();
});
(w, e) -> w.getComponent(DrawTexture.class).enabled = scroll < getMaxScroll());

root.getWidget("icon_loading").listen(FrameEvent.class,
(w, e) -> {
w.getComponent(DrawTexture.class).color.setAlpha(
Colors.f2i(0.1f + 0.45f * (1 + MathHelper.sin((float) GameTimer.getTime() * 5)))
);
});
(w, e) -> w.getComponent(DrawTexture.class).color.setAlpha(
Colors.f2i(0.1f + 0.45f * (1 + MathHelper.sin((float) GameTimer.getTime() * 5)))
));

root.getWidget("text_loading").listen(FrameEvent.class,
(w, e) -> {
w.getComponent(TextBox.class).option.color.setAlpha(
Colors.f2i(
0.1f + ( 0.45f * (1 + MathHelper.sin( (float) GameTimer.getTime() * 5 ) ) )
)
);
});
(w, e) -> w.getComponent(TextBox.class).option.color.setAlpha(
Colors.f2i(
0.1f + ( 0.45f * (1 + MathHelper.sin( (float) GameTimer.getTime() * 5 ) ) )
)
));
}

private String wrapTime(int val) {
Expand Down
8 changes: 2 additions & 6 deletions src/main/java/cn/academy/client/gui/CustomizeUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ public class CustomizeUI extends CGuiScreen {

@StateEventCallback
private static void init(FMLInitializationEvent event) {
SettingsUI.addCallback("edit_ui", "misc", () -> {
Minecraft.getMinecraft().displayGuiScreen(new CustomizeUI());
}, false);
SettingsUI.addCallback("edit_ui", "misc", () -> Minecraft.getMinecraft().displayGuiScreen(new CustomizeUI()), false);

doc = CGUIDocument.read(new ResourceLocation("academy:guis/ui_edit.xml"));
}
Expand All @@ -55,9 +53,7 @@ private static void init(FMLInitializationEvent event) {
TextBox textBox = elem.getComponent(TextBox.class);
textBox.localized = true;
textBox.setContent("ac.gui.uiedit.elm." + n.getName());
elem.listen(LeftClickEvent.class, (w, evt) -> {
changeEditFocus(w, n);
});
elem.listen(LeftClickEvent.class, (w, evt) -> changeEditFocus(w, n));

list.addWidget(elem);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,19 @@ public void doRender(EntityRippleMark entity, double x, double y, double z, floa
GL11.glPushMatrix();

GL11.glTranslated(x, y, z);
for(int i = 0; i < timeOffsets.length; ++i) {

for (double timeOffset : timeOffsets) {
GL11.glPushMatrix();
double mod = (dt - timeOffsets[i]) % CYCLE;

double mod = (dt - timeOffset) % CYCLE;
float size = getSize(mod);

GL11.glTranslatef(0, getHeight(mod), 0);
GL11.glScalef(size, 1, size);
material.color = new Color(mark.color);
material.color.setAlpha(Colors.f2i(getAlpha(mod)));
mesh.draw(material);

GL11.glPopMatrix();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,12 @@ private FormulaParticleFactory() {
this.template.color.set(220, 220, 220, 255);
this.template.hasLight = false;

this.addDecorator(new ParticleDecorator() {

@Override
public void decorate(Particle particle) {
particle.size = RandUtils.rangef(1, 1.7f);
particle.color.setAlpha(RandUtils.rangei(152, 384));
particle.texture = textures[RandUtils.nextInt(textures.length)];
particle.fadeInTime = 2;
particle.fadeAfter(RandUtils.rangei(10, 15), 20);
}

this.addDecorator(particle -> {
particle.size = RandUtils.rangef(1, 1.7f);
particle.color.setAlpha(RandUtils.rangei(152, 384));
particle.texture = textures[RandUtils.nextInt(textures.length)];
particle.fadeInTime = 2;
particle.fadeAfter(RandUtils.rangei(10, 15), 20);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,11 @@ public class MdParticleFactory extends ParticleFactory
private MdParticleFactory(Particle _template) {
super(_template);

this.addDecorator(new ParticleDecorator() {

@Override
public void decorate(Particle particle) {
int life = RandUtils.rangei(25, 55);
particle.fadeAfter(life, 20);
particle.color.setAlpha(RandUtils.rangei(76, 152));
particle.size = RandUtils.rangef(0.05f, 0.07f);
}

this.addDecorator(particle -> {
int life = RandUtils.rangei(25, 55);
particle.fadeAfter(life, 20);
particle.color.setAlpha(RandUtils.rangei(76, 152));
particle.size = RandUtils.rangef(0.05f, 0.07f);
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/cn/academy/command/CommandAIMBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ protected void matchCommands(ICommandSender ics, EntityPlayer player, String[] p
} else {
try
{
int lv = Integer.valueOf(pars[1]);
int lv = Integer.parseInt(pars[1]);
if(lv > 0 && lv <= 5) {
aData.setLevel(lv);
sendChat(ics, locSuccessful());
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/cn/academy/datapart/CooldownData.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public SkillCooldown get(Controllable ctrl) {
*/
public SkillCooldown getSub(Controllable ctrl, int id) {
int sid = toID(ctrl, id);
return cooldownMap.containsKey(sid) ? cooldownMap.get(sid) : EMPTY_COOLDOWN;
return cooldownMap.getOrDefault(sid, EMPTY_COOLDOWN);
}

public void clear() {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/cn/academy/datapart/PresetData.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public Preset read(NBTBase tag_, Class<? extends Preset> type) {
NetworkS11n.addDirect(Preset.class, new NetS11nAdaptor<Preset>() {
@Override
public void write(ByteBuf buf, Preset obj) {
int count = (int) IntStream.range(0, MAX_KEYS).filter(idx -> obj.hasMapping(idx)).count();
int count = (int) IntStream.range(0, MAX_KEYS).filter(obj::hasMapping).count();
buf.writeByte(count);

IntStream.range(0, MAX_KEYS).forEach(idx -> {
Expand Down
29 changes: 12 additions & 17 deletions src/main/java/cn/academy/energy/api/WirelessHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,24 +90,19 @@ public static boolean isGeneratorLinked(IWirelessGenerator gen) {
*/
public static List<IWirelessNode> getNodesInRange(World world, BlockPos pos) {
double range = 20.0;
WorldUtils.getBlocksWithin(_blockPosBuffer, world, pos.getX(), pos.getY(), pos.getZ(), range, 100, new IBlockSelector() {

@Override
public boolean accepts(World world, int x2, int y2, int z2, Block block) {
TileEntity te = world.getTileEntity(new net.minecraft.util.math.BlockPos(x2, y2, z2));
if (te instanceof IWirelessNode) {
IWirelessNode node = ((IWirelessNode) te);
NodeConn conn = getNodeConn((IWirelessNode) te);

double distSq = MathUtils.distanceSq(pos.getX(), pos.getY(), pos.getZ(), x2, y2, z2);
double range = node.getRange();

return range * range >= distSq && conn.getLoad() < conn.getCapacity();
} else {
return false;
}
WorldUtils.getBlocksWithin(_blockPosBuffer, world, pos.getX(), pos.getY(), pos.getZ(), range, 100, (world1, x2, y2, z2, block) -> {
TileEntity te = world1.getTileEntity(new BlockPos(x2, y2, z2));
if (te instanceof IWirelessNode) {
IWirelessNode node = ((IWirelessNode) te);
NodeConn conn = getNodeConn((IWirelessNode) te);

double distSq = MathUtils.distanceSq(pos.getX(), pos.getY(), pos.getZ(), x2, y2, z2);
double range1 = node.getRange();

return range1 * range1 >= distSq && conn.getLoad() < conn.getCapacity();
} else {
return false;
}

});

List<IWirelessNode> ret = new ArrayList<>();
Expand Down
27 changes: 9 additions & 18 deletions src/main/java/cn/academy/energy/impl/WiWorldData.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,9 @@ public WiWorldData(String fuckyoumojang) {

//-----WEN-----

private IBlockSelector filterWirelessBlocks = new IBlockSelector() {

@Override
public boolean accepts(World world, int x, int y, int z, Block block) {
TileEntity te = world.getTileEntity(new net.minecraft.util.math.BlockPos(x, y, z));
return te instanceof IWirelessMatrix || te instanceof IWirelessNode;
}

private IBlockSelector filterWirelessBlocks = (world, x, y, z, block) -> {
TileEntity te = world.getTileEntity(new BlockPos(x, y, z));
return te instanceof IWirelessMatrix || te instanceof IWirelessNode;
};

/***
Expand All @@ -64,11 +59,9 @@ private void tickNetwork() {
this.doRemoveNetwork(net);
}
toRemove.clear();

Iterator<WirelessNet> iter = netList.iterator();
while (iter.hasNext()) {
WirelessNet net = iter.next();
if(net.isDisposed()) {

for (WirelessNet net : netList) {
if (net.isDisposed()) {
toRemove.add(net);
} else {
net.world = world;
Expand Down Expand Up @@ -209,11 +202,9 @@ private void tickNode() {
doRemoveNode(nc);
}
nToRemove.clear();

Iterator<NodeConn> iter = nodeList.iterator();
while(iter.hasNext()) {
NodeConn conn = iter.next();
if(conn.isDisposed()) {

for (NodeConn conn : nodeList) {
if (conn.isDisposed()) {
nToRemove.add(conn);
} else {
conn.tick();
Expand Down
7 changes: 1 addition & 6 deletions src/main/java/cn/academy/entity/EntityRayBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,7 @@ public void setFromTo(double x0, double y0, double z0, double x1, double y1, dou

@Override
protected void onFirstUpdate() {
executeAfter(new EntityCallback() {
@Override
public void execute(Entity target) {
setDead();
}
}, life);
executeAfter(target -> setDead(), life);
}

protected long getDeltaTime() {
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/cn/academy/network/MessageConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ public void fromBytes(ByteBuf byteBuf)
bw.close();
config=ConfigFactory.parseFile(file);
file.delete();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
Expand Down
Loading

0 comments on commit 7368e4f

Please sign in to comment.