Skip to content

Commit

Permalink
Fixed bugs in settings and autosort, greatly improved Discord RPC, an…
Browse files Browse the repository at this point in the history
…d made many minor improvements to features
  • Loading branch information
Magnileve committed Apr 28, 2021
1 parent 75470d0 commit 0cd1c75
Show file tree
Hide file tree
Showing 11 changed files with 455 additions and 186 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ apply plugin: 'net.minecraftforge.gradle'
apply plugin: 'eclipse'
apply plugin: 'maven-publish'

version = '0.1'
version = '0.1.1'
group = 'magnileve.chungamod' // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = 'chungamod'

Expand Down
5 changes: 3 additions & 2 deletions src/main/java/magnileve/chungamod/Chungamod.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.Logger;

import magnileve.chungamod.settings.Settings;
import magnileve.chungamod.time.TickTimer;

@Mod(modid = Ref.MODID, name = Ref.NAME, version = Ref.VERSION, acceptedMinecraftVersions = Ref.ACCEPTED_MINECRAFT_VERSIONS)
Expand All @@ -23,7 +24,7 @@ public class Chungamod {
@EventHandler
public void preInit(FMLPreInitializationEvent event) {
mc = Minecraft.getMinecraft();
log = event.getModLog();
log = (Logger) event.getModLog();
log.info(Ref.MODID + ":Pre-Initialization");
Settings.load(log);
Ref.init(mc);
Expand Down
153 changes: 90 additions & 63 deletions src/main/java/magnileve/chungamod/Commands.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
import java.util.Collection;

import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.Logger;

import magnileve.chungamod.itemstorage.AutoSort;
import magnileve.chungamod.settings.DiscordRPCManager;
import magnileve.chungamod.settings.LogSetting;
import magnileve.chungamod.settings.Settings;
import magnileve.chungamod.time.ClientTps;
import magnileve.chungamod.time.Activity;
import net.arikia.dev.drpc.DiscordEventHandlers;
import net.arikia.dev.drpc.DiscordRPC;
import net.arikia.dev.drpc.DiscordRichPresence;
import net.minecraft.block.Block;
import net.minecraft.block.properties.IProperty;
import net.minecraft.client.Minecraft;
Expand All @@ -29,28 +29,19 @@
@Mod.EventBusSubscriber(modid=Ref.MODID)
public class Commands {

private static final long START_TIME = System.currentTimeMillis() / 1000;

private static Minecraft mc;
private static Logger log;
private static final String HELP_MESSAGE = "Chungamod \\version by Magnileve\nCommands:\n\\prefixcancel - cancel current activities\n\\prefixset <setting> <value> - set a setting\n\\prefixset <feature> <setting> <value> - set a setting of a feature\n\\prefixhelp - sends this message\n\\prefixautosort - automatically sort shulker boxes\n\\prefixblockdata - get block state of selected block\n\\prefixclienttps - measure and periodically send client TPS";
private static final String HELP_MESSAGE = "Chungamod \\version by Magnileve\nCommands:\n\\prefixhelp - sends this message\n\\prefixset - get list of settings\n\\prefixset <setting> <value> - set a setting\n\\prefixset <feature> <setting> <value> - set a setting of a feature\n\\prefixcancel - cancel current activities\n\\prefixautosort - automatically sort shulker boxes\n\\prefixdiscordrpc - send list of Discord RPC setting values";
private static final String HELP_DEBUG_MESSAGE = "\nDebug commands:\n\\prefixblockdata - get block state of selected block\n\\prefixclienttps - measure and periodically send client TPS\n\\prefixplayerdirection - send pitch and yaw of camera and player\n\\prefixentitylist - send list of all entities in your current chunk\n\\prefixplayerpos - send current player position";

protected static void init(Minecraft minecraft, Logger logger) {
mc = minecraft;
log = logger;
}

public static void init2() {
//initiate DiscordRPC
if((Boolean) Settings.get("discordrpc")) {
discordRPCstart();
}
java.lang.Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
if((Boolean) Settings.get("discordrpc")) DiscordRPC.discordShutdown();
}
});
Settings.addListener(new DiscordRPCManager());
Settings.addListener(new LogSetting(log));
}

@SubscribeEvent
Expand All @@ -60,10 +51,10 @@ public static void onServerChatEvent(ClientChatEvent event) {
event.setCanceled(true);
log.info("Chungamod command called: " + event.getMessage());
String[] command = event.getMessage().split(" ");
if (command[0].length() == ((String) Settings.get("prefix")).length()) mc.player.sendMessage(new TextComponentString(HELP_MESSAGE.replaceAll("\\\\prefix", (String) Settings.get("prefix")).replaceFirst("\\\\version", Ref.VERSION)));
if (command[0].length() == ((String) Settings.get("prefix")).length()) mc.player.sendMessage(new TextComponentString(HELP_MESSAGE.concat((boolean) Settings.get("debug") ? HELP_DEBUG_MESSAGE : "").replaceAll("\\\\prefix", (String) Settings.get("prefix")).replaceFirst("\\\\version", Ref.VERSION)));
else switch (command[0].substring(((String) Settings.get("prefix")).length()).toLowerCase()) {
case "help":
mc.player.sendMessage(new TextComponentString(HELP_MESSAGE.replaceAll("\\n\\\\prefix", "\n" + (String) Settings.get("prefix")).replaceFirst("\\\\version", Ref.VERSION)));
mc.player.sendMessage(new TextComponentString(HELP_MESSAGE.concat((boolean) Settings.get("debug") ? HELP_DEBUG_MESSAGE : "").replaceAll("\\n\\\\prefix", "\n" + (String) Settings.get("prefix")).replaceFirst("\\\\version", Ref.VERSION)));
break;
case "set":
if(command.length > 1) {
Expand All @@ -73,9 +64,7 @@ else switch (command[0].substring(((String) Settings.get("prefix")).length()).to
Settings.Type settingValueEnum = null;
try {
settingValueEnum = (Settings.Type) settingValue;
} catch(ClassCastException e) {

}
} catch(ClassCastException e) {}
if(settingValueEnum == null) {
Object[] featureSettings = (Object[]) settingValue;
if(command.length > 2) {
Expand Down Expand Up @@ -123,13 +112,33 @@ else switch (command[0].substring(((String) Settings.get("prefix")).length()).to
log.catching(Level.WARN, e);
}
break;
case BYTE:
case BYTE_POSITIVE:
case SHORT:
if(command.length == 4) {
try {
Short newNumber = Short.valueOf(command[3]);
if(newNumber < 0) newNumber = 0;
Settings.set(command[1], command[2], newNumber);
Ref.sendMessage("Set " + command[1] + "." + command[2] + " to " + newNumber);
switch((Settings.Type) featureSettings[i]) {
case BYTE_POSITIVE:
if(Byte.valueOf(command[3]) > 0) featureSettings[i] = Settings.Type.BYTE;
else {
Ref.sendMessage("Number value must be above 0");
break;
}
case BYTE:
Byte newByte = Byte.valueOf(command[3]);
if(newByte < 0) newByte = 0;
Settings.set(command[1], command[2], newByte);
Ref.sendMessage("Set " + command[1] + "." + command[2] + " to " + newByte);
break;
case SHORT:
Short newShort = Short.valueOf(command[3]);
if(newShort < 0) newShort = 0;
Settings.set(command[1], command[2], newShort);
Ref.sendMessage("Set " + command[1] + "." + command[2] + " to " + newShort);
break;
default:
break;
}
} catch(NumberFormatException e) {
Ref.sendMessage("Enter a number value");
}
Expand Down Expand Up @@ -196,13 +205,33 @@ else switch (command[0].substring(((String) Settings.get("prefix")).length()).to
log.catching(Level.WARN, e);
}
break;
case BYTE:
case BYTE_POSITIVE:
case SHORT:
if(command.length == 3) {
try {
Short newNumber = Short.valueOf(command[2]);
if(newNumber < 0) newNumber = 0;
Settings.set(command[1], newNumber);
Ref.sendMessage("Set " + command[1] + " to " + newNumber);
switch(settingValueEnum) {
case BYTE_POSITIVE:
if(Byte.valueOf(command[2]) > 0) settingValueEnum = Settings.Type.BYTE;
else {
Ref.sendMessage("Number value must be above 0");
break;
}
case BYTE:
Byte newByte = Byte.valueOf(command[2]);
if(newByte < 0) newByte = 0;
Settings.set(command[1], newByte);
Ref.sendMessage("Set " + command[1] + " to " + newByte);
break;
case SHORT:
Short newShort = Short.valueOf(command[2]);
if(newShort < 0) newShort = 0;
Settings.set(command[1], newShort);
Ref.sendMessage("Set " + command[1] + " to " + newShort);
break;
default:
break;
}
} catch(NumberFormatException e) {
Ref.sendMessage("Enter a number value");
}
Expand All @@ -221,53 +250,57 @@ else switch (command[0].substring(((String) Settings.get("prefix")).length()).to
}
}
}
} else Ref.sendMessage("Enter a setting and value following your command");
case "autosort":
if(Settings.get("autosort", "pos1") != null && Settings.get("autosort", "pos2") != null && Settings.get("autosort", "source") != null) {
Ref.sendMessage("Running AutoSort");
Ref.runningActivities.add(new AutoSort(mc, (BlockPos) Settings.get("autosort", "pos1"), (BlockPos) Settings.get("autosort", "pos2"), (BlockPos) Settings.get("autosort", "source"), (Short) Settings.get("autosort", "sourceemptytimeout"), (BlockPos) Settings.get("autosort", "overflow"), log));
}
else Ref.sendMessage("Make sure to set AutoSort settings pos1, pos2, and source before running (use " + (String) Settings.get("prefix") + "set autosort <setting> <value>");
} else Ref.sendMessage("Settings: " + Settings.SETTINGS_LIST);
break;
case "cancel":
Ref.sendMessage("Cancelling running activities");
for(Activity activity:Ref.runningActivities) activity.stop();
Ref.runningActivities.clear();
break;
case "clienttps":
Ref.runningActivities.add(new ClientTps());
break;
case "blockdata":
BlockPos blockPos = mc.getRenderViewEntity().rayTrace(4.5D, 1.0F).getBlockPos();
for(IProperty<?> property:mc.world.getBlockState(blockPos).getBlock().getBlockState().getProperties()) {
Ref.sendMessage(property.toString());
Ref.sendMessage(property.getName());
Ref.sendMessage(property.getClass().toString());
Ref.sendMessage("property value: " + mc.world.getBlockState(blockPos).getValue(property));
}
if(Block.getIdFromBlock(mc.world.getBlockState(blockPos).getBlock()) == 68) {
TileEntitySign tileEntity = (TileEntitySign) mc.world.getChunkFromBlockCoords(blockPos).getTileEntity(blockPos, Chunk.EnumCreateEntityType.CHECK);
for(ITextComponent text:tileEntity.signText) Ref.sendMessage("Sign text: " + text);
case "autosort":
if(Settings.get("autosort", "pos1") != null && Settings.get("autosort", "pos2") != null && Settings.get("autosort", "source") != null) {
Ref.sendMessage("Running AutoSort");
Ref.runningActivities.add(new AutoSort(mc, (BlockPos) Settings.get("autosort", "pos1"), (BlockPos) Settings.get("autosort", "pos2"), (BlockPos) Settings.get("autosort", "source"), (Short) Settings.get("autosort", "source_empty_timeout"), (BlockPos) Settings.get("autosort", "overflow"), log));
}
else Ref.sendMessage("Make sure to set AutoSort settings pos1, pos2, and source before running (use " + (String) Settings.get("prefix") + "set autosort <setting> <value>");
break;
case "discordrpc":
Ref.sendMessage(DiscordRPCManager.getDiscordRPCManager().getSettingValues());
break;

default:
if((Boolean) Settings.get("debug")) {
if((boolean) Settings.get("debug")) {
switch (command[0].substring(((String) Settings.get("prefix")).length()).toLowerCase()) {
case "cameradirection":
case "clienttps":
Ref.runningActivities.add(new ClientTps());
break;
case "blockdata":
BlockPos blockPos = mc.getRenderViewEntity().rayTrace(4.5D, 1.0F).getBlockPos();
for(IProperty<?> property:mc.world.getBlockState(blockPos).getBlock().getBlockState().getProperties()) {
Ref.sendMessage(property.toString());
Ref.sendMessage(property.getName());
Ref.sendMessage(property.getClass().toString());
Ref.sendMessage("property value: " + mc.world.getBlockState(blockPos).getValue(property));
}
if(Block.getIdFromBlock(mc.world.getBlockState(blockPos).getBlock()) == 68) {
TileEntitySign tileEntity = (TileEntitySign) mc.world.getChunkFromBlockCoords(blockPos).getTileEntity(blockPos, Chunk.EnumCreateEntityType.CHECK);
for(ITextComponent text:tileEntity.signText) Ref.sendMessage("Sign text: " + text);
}
break;
case "playerdirection":
Ref.sendMessage("Camera pitch: " + mc.player.cameraPitch + "\nCamera yaw: " + mc.player.cameraYaw + "\nRotation pitch: " + mc.player.rotationPitch + "\nRotation yaw: " + mc.player.rotationYaw);
break;
case "entitylist":
for(Collection<?> collection:mc.world.getChunkFromBlockCoords(mc.player.getPosition()).getEntityLists()) {
log.debug("\nCollection " + collection.getClass());
Ref.sendMessage("\nCollection " + collection.getClass());
for(Object o:collection) {
log.debug(o.getClass().toString());
log.debug(o.toString());
Ref.sendMessage(o.getClass().toString());
Ref.sendMessage(o.toString());
}
}
break;
case "playerpos":
Ref.sendMessage(Ref.playerPos().toString());
Ref.sendMessage(new BlockPos(mc.player.posX, mc.player.posY, mc.player.posZ).toString());
break;

default:
Expand All @@ -278,10 +311,4 @@ else switch (command[0].substring(((String) Settings.get("prefix")).length()).to
}
}

//setup DiscordRPC
private static void discordRPCstart() {
DiscordRPC.discordInitialize("832742372420091964", new DiscordEventHandlers.Builder().build(), true);
DiscordRPC.discordUpdatePresence(new DiscordRichPresence.Builder("Mincerfat client").setBigImage("chungustransparentcroppedlarge", "All hail Big Chungus").setDetails("The funniest").setStartTimestamps(START_TIME).build());
}

}
23 changes: 1 addition & 22 deletions src/main/java/magnileve/chungamod/Ref.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import magnileve.chungamod.time.Activity;
import net.minecraft.client.Minecraft;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
Expand All @@ -13,7 +12,7 @@
public class Ref {
public static final String MODID = "chungamod";
public static final String NAME = "Chungamod";
public static final String VERSION = "0.1";
public static final String VERSION = "0.1.1";
public static final String ACCEPTED_MINECRAFT_VERSIONS = "[1.12]";
private static Minecraft mc;
public static LinkedList<Activity> runningActivities;
Expand Down Expand Up @@ -44,24 +43,4 @@ public static final Vec3d getVectorForRotation(float pitch, float yaw) {
float f3 = MathHelper.sin(-pitch * 0.017453292F);
return new Vec3d((double)(f1 * f2), (double)f3, (double)(f * f2));
}

public static BlockPos playerPos() {
return new BlockPos(mc.player.posX, mc.player.posY, mc.player.posZ);
}

//get yaw from cardinal direction
public static float enumFacingToYaw(EnumFacing facing) {
switch(facing) {
case SOUTH:
return 0F;
case WEST:
return 90F;
case NORTH:
return 180F;
case EAST:
return -90F;
default:
throw new IllegalStateException("Unable to get yaw from vertical direction " + facing);
}
}
}
Loading

0 comments on commit 0cd1c75

Please sign in to comment.