Skip to content

Commit

Permalink
Added tempat command to get the target temperature for a block locati…
Browse files Browse the repository at this point in the history
…on in a world. Added optional argument to hide the print output of setseason and tempat commands. Configured thermometer to display its location's temperature when placed in an item frame.
  • Loading branch information
TimTinkers committed Jul 8, 2017
1 parent e73d509 commit 55845cf
Show file tree
Hide file tree
Showing 15 changed files with 897 additions and 607 deletions.
13 changes: 9 additions & 4 deletions src/main/java/toughasnails/api/season/IDecayableCrop.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,15 @@
******************************************************************************/
package toughasnails.api.season;

/**
* A marker interface which should be implemented by crops which decay
* in the winter in the absence of proper heating.
/**
* A marker interface which should be implemented by crops which decay in the
* winter in the absence of proper heating.
*
* Please note that due to how Java bytecode works, you must explicitly
* implement this interface if your class overrides updateTick.
*/
public interface IDecayableCrop {

}
// Crop will only decay in winter if this returns true
boolean shouldDecay();
}
17 changes: 12 additions & 5 deletions src/main/java/toughasnails/api/season/IHibernatingCrop.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,17 @@
******************************************************************************/
package toughasnails.api.season;

/**
* A marker interface which should be implemented by crops which stop growing
* in the winter in the absence of proper heating.
/**
* An interface which should be implemented by crops which become inactive in
* the winter in the absence of proper heating.
*
* Crops using this interface should make sure they use Forge's crop growth
* events and appropriately cancel the crop growth when the event result is set
* to DENY. (See net.minecraftforge.event.BlockEvent$CropGrowEvent or
* alternatively net.minecraftforge.common.ForgeHooks.onCropsGrowPre)
*/
public interface IHibernatingCrop {

}

// Crop will only hibernate in winter if this returns true
boolean shouldHibernate();
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import net.minecraft.world.World;
import toughasnails.api.TANCapabilities;
import toughasnails.api.stat.capability.ITemperature;
import toughasnails.api.stat.capability.IThirst;

public class TemperatureHelper
{
Expand Down
55 changes: 31 additions & 24 deletions src/main/java/toughasnails/asm/transformer/PamCropTransformer.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,35 @@
import toughasnails.asm.transformer.AbstractCropTransformer.WinterBehavior;

// Pam's Harvestcraft compatibility
public class PamCropTransformer extends AbstractCropTransformer
{
private static final String[] VALID_HASHES_CROP = new String[] { "03263774b5cda6bfeccc1622fd344710" };
private static final String[] VALID_HASHES_FRUIT = new String[] { "da4a453d0bcd36b8db130e372865cb24" };
private static final String[] VALID_HASHES_FRUIT_LOG = new String[] { "ce0043f49abbe83982be20cbf4989bb3" };

@Override
public byte[] transform(String name, String transformedName, byte[] basicClass)
{
if (transformedName.equals("com.pam.harvestcraft.blocks.growables.BlockPamCrop"))
{
return transformCrop(basicClass, !transformedName.equals(name), "BlockPamCrop", VALID_HASHES_CROP, WinterBehavior.DECAY);
}
if (transformedName.equals("com.pam.harvestcraft.blocks.growables.BlockPamFruit"))
{
return transformCrop(basicClass, !transformedName.equals(name), "BlockPamFruit", VALID_HASHES_FRUIT, WinterBehavior.HIBERNATE);
}
if (transformedName.equals("com.pam.harvestcraft.blocks.growables.BlockPamFruitLog"))
{
return transformCrop(basicClass, !transformedName.equals(name), "BlockPamFruitLog", VALID_HASHES_FRUIT_LOG, WinterBehavior.HIBERNATE);
}

return basicClass;
}
public class PamCropTransformer extends AbstractCropTransformer {
private static final String[] VALID_HASHES_CROP = new String[] {
"03263774b5cda6bfeccc1622fd344710" };
private static final String[] VALID_HASHES_FRUIT = new String[] {
"da4a453d0bcd36b8db130e372865cb24" };
private static final String[] VALID_HASHES_FRUIT_LOG = new String[] {
"ce0043f49abbe83982be20cbf4989bb3" };

@Override
public byte[] transform(String name, String transformedName,
byte[] basicClass) {
if (transformedName
.equals("com.pam.harvestcraft.blocks.growables.BlockPamCrop")) {
return transformCrop(basicClass, !transformedName.equals(name),
"BlockPamCrop", VALID_HASHES_CROP, WinterBehavior.DECAY);
}
if (transformedName.equals(
"com.pam.harvestcraft.blocks.growables.BlockPamFruit")) {
return transformCrop(basicClass, !transformedName.equals(name),
"BlockPamFruit", VALID_HASHES_FRUIT,
WinterBehavior.HIBERNATE);
}
if (transformedName.equals(
"com.pam.harvestcraft.blocks.growables.BlockPamFruitLog")) {
return transformCrop(basicClass, !transformedName.equals(name),
"BlockPamFruitLog", VALID_HASHES_FRUIT_LOG,
WinterBehavior.HIBERNATE);
}

return basicClass;
}
}
107 changes: 104 additions & 3 deletions src/main/java/toughasnails/command/TANCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import net.minecraft.command.CommandBase;
import net.minecraft.command.CommandException;
import net.minecraft.command.CommandResultStats;
import net.minecraft.command.ICommandSender;
import net.minecraft.command.WrongUsageException;
import net.minecraft.entity.player.EntityPlayerMP;
Expand All @@ -29,6 +30,12 @@
import toughasnails.season.SeasonTime;
import toughasnails.temperature.TemperatureDebugger;
import toughasnails.temperature.TemperatureHandler;
import toughasnails.temperature.modifier.AltitudeModifier;
import toughasnails.temperature.modifier.BiomeModifier;
import toughasnails.temperature.modifier.ObjectProximityModifier;
import toughasnails.temperature.modifier.SeasonModifier;
import toughasnails.temperature.modifier.TimeModifier;
import toughasnails.temperature.modifier.WeatherModifier;
import toughasnails.thirst.ThirstHandler;

public class TANCommand extends CommandBase {
Expand Down Expand Up @@ -59,10 +66,16 @@ public void execute(MinecraftServer server, ICommandSender sender,
throw new WrongUsageException("commands.toughasnails.usage");
} else if ("tempinfo".equals(args[0])) {
displayTemperatureInfo(sender, args);
} else if ("tempat".equals(args[0])) {
if (args.length < 5 || args.length > 6) {
throw new WrongUsageException("commands.toughasnails.usage");
} else {
retrieveTemperatureAt(sender, args);
}
} else if ("settemp".equals(args[0])) {
setTemperature(sender, args);
} else if ("setseason".equals(args[0])) {
if (args.length != 3) {
if (args.length < 3 || args.length > 4) {
throw new WrongUsageException("commands.toughasnails.usage");
} else {
setSeason(sender, args);
Expand Down Expand Up @@ -97,6 +110,87 @@ private void displayTemperatureInfo(ICommandSender sender, String[] args)
}
}

// tan tempat <world> <x> <y> <z>
private void retrieveTemperatureAt(ICommandSender sender, String[] args)
throws CommandException {
int dimensionID = 0;
int x = 0;
int y = 0;
int z = 0;
boolean printOutput = true;
try {
dimensionID = Integer.parseInt(args[1]);
x = Integer.parseInt(args[2]);
y = Integer.parseInt(args[3]);
z = Integer.parseInt(args[4]);
if (args.length >= 6) {
printOutput = Boolean.parseBoolean(args[5]);
}
} catch (NumberFormatException e) {
throw new WrongUsageException("commands.toughasnails.usage");
}

if (SyncedConfig.getBooleanValue(GameplayOption.ENABLE_TEMPERATURE)) {
World world = null;
WorldServer[] worldServers = FMLCommonHandler.instance()
.getMinecraftServerInstance().worldServers;
WorldServer candidate = FMLCommonHandler.instance()
.getMinecraftServerInstance()
.worldServerForDimension(dimensionID);
if (candidate == null) {
throw new WrongUsageException("commands.toughasnails.usage");
}

for (int i = 0; i < worldServers.length; i++) {
WorldServer target = worldServers[i];
if (candidate.equals(target)) {
world = target;
break;
}
}

if (world == null) {
throw new WrongUsageException("commands.toughasnails.usage");
}
final TemperatureDebugger debugger = new TemperatureDebugger();
AltitudeModifier altitudeModifier = new AltitudeModifier(debugger);
BiomeModifier biomeModifier = new BiomeModifier(debugger);
ObjectProximityModifier objectProximityModifier = new ObjectProximityModifier(
debugger);
WeatherModifier weatherModifier = new WeatherModifier(debugger);
TimeModifier timeModifier = new TimeModifier(debugger);
SeasonModifier seasonModifier = new SeasonModifier(debugger);

BlockPos position = new BlockPos(x, y, z);
Temperature baseTemperature = new Temperature(
TemperatureHandler.TEMPERATURE_SCALE_MIDPOINT);
Temperature targetTemperature = biomeModifier.modifyTarget(world,
position, baseTemperature);
targetTemperature = altitudeModifier.modifyTarget(world, position,
targetTemperature);
targetTemperature = objectProximityModifier.modifyTarget(world,
position, targetTemperature);
targetTemperature = weatherModifier.modifyTarget(world, position,
targetTemperature);
targetTemperature = timeModifier.modifyTarget(world, position,
targetTemperature);
targetTemperature = seasonModifier.modifyTarget(world, position,
targetTemperature);

int finalTemperature = targetTemperature.getRawValue();
if (printOutput) {
sender.addChatMessage(new TextComponentTranslation(
"commands.toughasnails.tempat.success", dimensionID, x,
y, z, finalTemperature));
}
sender.setCommandStat(CommandResultStats.Type.QUERY_RESULT,
finalTemperature);
} else {
sender.addChatMessage(new TextComponentTranslation(
"commands.toughasnails.tempat.disabled"));
}
}

private void setTemperature(ICommandSender sender, String[] args)
throws CommandException {
EntityPlayerMP player = getCommandSenderAsPlayer(sender);
Expand Down Expand Up @@ -126,8 +220,12 @@ private void setTemperature(ICommandSender sender, String[] args)
private void setSeason(ICommandSender sender, String[] args)
throws CommandException {
int dimensionID = 0;
boolean printOutput = true;
try {
dimensionID = Integer.parseInt(args[2]);
if (args.length >= 4) {
printOutput = Boolean.parseBoolean(args[3]);
}
} catch (NumberFormatException e) {
throw new WrongUsageException("commands.toughasnails.usage");
}
Expand Down Expand Up @@ -172,8 +270,11 @@ private void setSeason(ICommandSender sender, String[] args)
* SeasonTime.SUB_SEASON_DURATION * newSeason.ordinal();
seasonData.markDirty();
SeasonHandler.sendSeasonUpdate(world);
sender.addChatMessage(new TextComponentTranslation(
"commands.toughasnails.setseason.success", args[1]));
if (printOutput) {
sender.addChatMessage(new TextComponentTranslation(
"commands.toughasnails.setseason.success",
args[1]));
}
} else {
sender.addChatMessage(new TextComponentTranslation(
"commands.toughasnails.setseason.fail", args[1]));
Expand Down
Loading

0 comments on commit 55845cf

Please sign in to comment.