Fixed rare crash on ladders.

Added config file with reach, increased mining time and block outline settings.
Mirror size has been renamed to reach.
Mirror and array abide by the new reach settings.
Added reach counter to array UI (reach = count * max offset).
If reach is 0 (as can be set in config), the UI will be disabled.
Added the ability to show the white block outline on the block you place, in addition to blocks placed by mirror/array.
Added the ability to disable increased mining time and to change its percentage in the config.
This commit is contained in:
Christian Knaapen
2018-12-01 18:33:21 +01:00
parent 3891cc349f
commit 1933832c58
15 changed files with 240 additions and 63 deletions

View File

@@ -11,7 +11,7 @@ apply plugin: 'net.minecraftforge.gradle.forge'
//Only edit below this line, the above code adds and enables the necessary things for Forge to be setup.
version = "0.3.4"
version = "0.3.5"
group = "nl.requios.effortlessbuilding" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = "effortlessbuilding"

View File

@@ -12,11 +12,10 @@ import net.minecraft.world.World;
import net.minecraftforge.event.entity.player.PlayerEvent;
import net.minecraftforge.event.world.BlockEvent;
import net.minecraftforge.items.IItemHandler;
import nl.requios.effortlessbuilding.helper.SurvivalHelper;
import nl.requios.effortlessbuilding.item.ItemRandomizerBag;
public class Array {
//TODO config file
public static final int MAX_COUNT = 100;
public static class ArraySettings{
public boolean enabled = false;
@@ -31,6 +30,16 @@ public class Array {
this.offset = offset;
this.count = count;
}
public int getReach() {
//find largest offset
int x = Math.abs(offset.getX());
int y = Math.abs(offset.getY());
int z = Math.abs(offset.getZ());
int largestOffset = Math.max(Math.max(x, y), z);
return largestOffset * count;
}
}
//Called from EventHandler

View File

@@ -0,0 +1,54 @@
package nl.requios.effortlessbuilding;
import net.minecraftforge.common.config.Config;
import static net.minecraftforge.common.config.Config.*;
@Config(modid = EffortlessBuilding.MODID, name = "EffortlessBuilding", type = Type.INSTANCE, category = "")
public class BuildConfig {
public static Reach reach = new Reach();
public static SurvivalBalancers survivalBalancers = new SurvivalBalancers();
public static Visuals visuals = new Visuals();
public static class Reach {
@Comment({"Reach: how far away the player can place blocks using mirror/array etc.",
"Maximum reach in creative"})
public int maxReachCreative = 200;
@Comment({"Maximum reach in survival without upgrades",
"Reach upgrades are craftable consumables that permanently increase reach.",
"Set to 0 to disable Effortless Building until the player has consumed a reach upgrade."})
public int maxReachLevel0 = 10;
@Comment("Maximum reach in survival with one upgrade")
public int maxReachLevel1 = 20;
@Comment("Maximum reach in survival with two upgrades")
public int maxReachLevel2 = 50;
@Comment("Maximum reach in survival with three upgrades")
public int maxReachLevel3 = 200;
}
public static class SurvivalBalancers {
@Comment({"Increases the time to mine a block when breaking multiple at once.",
"Mining time depends on how many blocks, what type of blocks, and the percentage below.",
"Example: breaking 1 dirt + 1 obsidian takes the time of breaking 1 dirt + 1 obsidian."})
public boolean increasedMiningTime = true;
@Comment({"How much the mining time of each additional block counts towards an increased mining time.",
"A percentage between 0% and 100%, where 0% is the same as disabling it,",
"and 100% takes as much time as breaking each block individually.",
"The block in front of you always counts as 100%."})
@RangeInt(min = 0, max = 100)
public int miningTimePercentage = 50;
}
public static class Visuals {
@Comment({"Shows a white block outline for the block you manually place,",
"in addition to blocks placed by the mirror or array."})
public boolean showOutlineOnCurrentBlock = false;
}
}

View File

@@ -2,6 +2,7 @@ package nl.requios.effortlessbuilding;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.util.text.TextFormatting;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.PlayerEvent;
@@ -26,7 +27,7 @@ public class BuildSettingsManager {
public static void setBuildSettings(EntityPlayer player, BuildSettings buildSettings) {
if (player == null) {
EffortlessBuilding.log("cannot set buildsettings, player is null");
EffortlessBuilding.log("Cannot set buildsettings, player is null");
return;
}
if (player.hasCapability(BuildModifierCapability.buildModifier, null)) {
@@ -37,20 +38,74 @@ public class BuildSettingsManager {
}
}
public static String sanitize(BuildSettings buildSettings, EntityPlayer player) {
int maxReach = getMaxReach(player);
String error = "";
//Mirror settings
Mirror.MirrorSettings m = buildSettings.getMirrorSettings();
if (m.radius < 1) {
m.radius = 1;
error += "Mirror size is too small. Size has been reset to 1. ";
}
if (m.getReach() > maxReach) {
m.radius = maxReach / 2;
error += "Mirror exceeds your maximum reach. Reach has been reset to max. ";
}
//Array settings
Array.ArraySettings a = buildSettings.getArraySettings();
if (a.count < 0) {
a.count = 0;
error += "Array count cannot be negative. Count has been reset to 0. ";
}
if (a.getReach() > maxReach) {
a.count = 0;
error += "Array exceeds your maximum reach. Count has been reset to 0. ";
}
//Other
if (buildSettings.reachUpgrade < 0) {
buildSettings.reachUpgrade = 0;
}
if (buildSettings.reachUpgrade > 3) {
buildSettings.reachUpgrade = 3;
}
return error;
}
public static int getMaxReach(EntityPlayer player) {
if (player.isCreative()) return BuildConfig.reach.maxReachCreative;
//Check buildsettings for reachUpgrade
int reachUpgrade = getBuildSettings(player).getReachUpgrade();
switch (reachUpgrade) {
case 0: return BuildConfig.reach.maxReachLevel0;
case 1: return BuildConfig.reach.maxReachLevel1;
case 2: return BuildConfig.reach.maxReachLevel2;
case 3: return BuildConfig.reach.maxReachLevel3;
}
return BuildConfig.reach.maxReachLevel0;
}
public static class BuildSettings {
private Mirror.MirrorSettings mirrorSettings;
private Array.ArraySettings arraySettings;
private boolean quickReplace = false;
private int reachUpgrade = 0;
public BuildSettings() {
mirrorSettings = new Mirror.MirrorSettings();
arraySettings = new Array.ArraySettings();
}
public BuildSettings(Mirror.MirrorSettings mirrorSettings, Array.ArraySettings arraySettings, boolean quickReplace) {
public BuildSettings(Mirror.MirrorSettings mirrorSettings, Array.ArraySettings arraySettings, boolean quickReplace, int reachUpgrade) {
this.mirrorSettings = mirrorSettings;
this.arraySettings = arraySettings;
this.quickReplace = quickReplace;
this.reachUpgrade = reachUpgrade;
}
public Mirror.MirrorSettings getMirrorSettings() {
@@ -76,6 +131,14 @@ public class BuildSettingsManager {
public void setQuickReplace(boolean quickReplace) {
this.quickReplace = quickReplace;
}
public int getReachUpgrade() {
return reachUpgrade;
}
public void setReachUpgrade(int reachUpgrade) {
this.reachUpgrade = reachUpgrade;
}
}
@SubscribeEvent

View File

@@ -5,6 +5,8 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.util.text.TextComponentString;
import net.minecraftforge.common.capabilities.CapabilityManager;
import net.minecraftforge.common.config.Config;
import net.minecraftforge.common.config.ConfigManager;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.SidedProxy;
@@ -29,7 +31,7 @@ public class EffortlessBuilding
{
public static final String MODID = "effortlessbuilding";
public static final String NAME = "Effortless Building";
public static final String VERSION = "0.3.4";
public static final String VERSION = "0.3.5";
@Mod.Instance(EffortlessBuilding.MODID)
public static EffortlessBuilding instance;
@@ -77,6 +79,7 @@ public class EffortlessBuilding
// Register network handlers
public void init(FMLInitializationEvent event)
{
ConfigManager.sync(MODID, Config.Type.INSTANCE);
NetworkRegistry.INSTANCE.registerGuiHandler(EffortlessBuilding.instance, new RandomizerBagGuiHandler());
proxy.init(event);
}

View File

@@ -14,11 +14,14 @@ import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.common.config.Config;
import net.minecraftforge.common.config.ConfigManager;
import net.minecraftforge.event.AttachCapabilitiesEvent;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.event.entity.player.PlayerEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.event.world.BlockEvent;
import net.minecraftforge.fml.client.event.ConfigChangedEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;
@@ -54,6 +57,15 @@ public class EventHandler
}
}
@SubscribeEvent
public void onConfigChangedEvent(ConfigChangedEvent.OnConfigChangedEvent event)
{
if (event.getModID().equals(EffortlessBuilding.MODID))
{
ConfigManager.sync(EffortlessBuilding.MODID, Config.Type.INSTANCE);
}
}
@SubscribeEvent
public static void onServerTick(TickEvent.ServerTickEvent event) {
if (placedBlock) {
@@ -85,7 +97,9 @@ public class EventHandler
@SubscribeEvent
public static void breakSpeed(PlayerEvent.BreakSpeed event) {
//TODO disable with config
//Disable if config says so
if (!BuildConfig.survivalBalancers.increasedMiningTime) return;
EntityPlayer player = event.getEntityPlayer();
World world = player.world;
BlockPos pos = event.getPos();
@@ -97,8 +111,8 @@ public class EventHandler
totalBlockHardness += Mirror.getTotalBlockHardness(world, player, pos);
totalBlockHardness += Array.getTotalBlockHardness(world, player, pos);
//TODO get percentage from config
float percentage = 0.5f;
//Grabbing percentage from config
float percentage = (float) BuildConfig.survivalBalancers.miningTimePercentage / 100;
totalBlockHardness *= percentage;
totalBlockHardness += originalBlockHardness;

View File

@@ -13,13 +13,11 @@ import net.minecraft.world.World;
import net.minecraftforge.common.util.BlockSnapshot;
import net.minecraftforge.event.world.BlockEvent;
import net.minecraftforge.items.IItemHandler;
import nl.requios.effortlessbuilding.helper.SurvivalHelper;
import nl.requios.effortlessbuilding.item.ItemRandomizerBag;
public class Mirror {
//TODO config file
public static final int MAX_RADIUS = 200;
public static class MirrorSettings {
public boolean enabled = false;
public Vec3d position = new Vec3d(0.5, 64.5, 0.5);
@@ -40,6 +38,10 @@ public class Mirror {
this.drawLines = drawLines;
this.drawPlanes = drawPlanes;
}
public int getReach() {
return radius * 2;
}
}
//Called from EventHandler

View File

@@ -8,6 +8,7 @@ import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.common.util.BlockSnapshot;
import net.minecraftforge.event.world.BlockEvent;
import nl.requios.effortlessbuilding.helper.SurvivalHelper;
import nl.requios.effortlessbuilding.network.QuickReplaceMessage;
import java.util.Dictionary;

View File

@@ -49,6 +49,7 @@ public class BuildModifierCapability {
public NBTBase writeNBT(Capability<IBuildModifier> capability, IBuildModifier instance, EnumFacing side) {
NBTTagCompound compound = new NBTTagCompound();
BuildSettings buildSettings = instance.getBuildModifierData();
if (buildSettings == null) buildSettings = new BuildSettings();
//MIRROR
Mirror.MirrorSettings m = buildSettings.getMirrorSettings();
@@ -71,6 +72,8 @@ public class BuildModifierCapability {
compound.setInteger("arrayOffsetZ", a.offset.getZ());
compound.setInteger("arrayCount", a.count);
compound.setInteger("reachUpgrade", buildSettings.getReachUpgrade());
//compound.setBoolean("quickReplace", buildSettings.doQuickReplace()); dont save quickreplace
return compound;
}
@@ -96,9 +99,11 @@ public class BuildModifierCapability {
int arrayCount = compound.getInteger("arrayCount");
Array.ArraySettings arraySettings = new Array.ArraySettings(arrayEnabled, arrayOffset, arrayCount);
int reachUpgrade = compound.getInteger("reachUpgrade");
//boolean quickReplace = compound.getBoolean("quickReplace"); //dont load quickreplace
BuildSettings buildSettings = new BuildSettings(mirrorSettings, arraySettings, false);
BuildSettings buildSettings = new BuildSettings(mirrorSettings, arraySettings, false, reachUpgrade);
instance.setBuildModifierData(buildSettings);
}
}

View File

@@ -1,11 +1,11 @@
package nl.requios.effortlessbuilding.gui;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.text.TextFormatting;
import net.minecraftforge.fml.client.config.GuiCheckBox;
import nl.requios.effortlessbuilding.Array;
import nl.requios.effortlessbuilding.BuildSettingsManager;
@@ -59,17 +59,17 @@ public class SettingsGui extends GuiScreen {
y = top + 18;
textMirrorPosX = new GuiNumberField(id++, id++, id++, fontRenderer, buttonList, left + 58, y, 62, 18);
textMirrorPosX.setNumber(0);
textMirrorPosX.setTooltip(Arrays.asList("The position of the mirror.", "For odd numbered builds add 0.5."));
textMirrorPosX.setTooltip(Arrays.asList("The position of the mirror.", TextFormatting.GRAY + "For odd numbered builds add 0.5."));
mirrorNumberFieldList.add(textMirrorPosX);
textMirrorPosY = new GuiNumberField(id++, id++, id++, fontRenderer, buttonList, left + 138, y, 62, 18);
textMirrorPosY.setNumber(64);
textMirrorPosY.setTooltip(Arrays.asList("The position of the mirror.", "For odd numbered builds add 0.5."));
textMirrorPosY.setTooltip(Arrays.asList("The position of the mirror.", TextFormatting.GRAY + "For odd numbered builds add 0.5."));
mirrorNumberFieldList.add(textMirrorPosY);
textMirrorPosZ = new GuiNumberField(id++, id++, id++, fontRenderer, buttonList, left + 218, y, 62, 18);
textMirrorPosZ.setNumber(0);
textMirrorPosZ.setTooltip(Arrays.asList("The position of the mirror.", "For odd numbered builds add 0.5."));
textMirrorPosZ.setTooltip(Arrays.asList("The position of the mirror.", TextFormatting.GRAY + "For odd numbered builds add 0.5."));
mirrorNumberFieldList.add(textMirrorPosZ);
y = top + 50;
@@ -85,7 +85,10 @@ public class SettingsGui extends GuiScreen {
y = top + 47;
textMirrorRadius = new GuiNumberField(id++, id++, id++, fontRenderer, buttonList, left + 218, y, 62, 18);
textMirrorRadius.setNumber(50);
textMirrorRadius.setTooltip("How far the mirror reaches in any direction.");
//TODO change to diameter (remove /2)
textMirrorRadius.setTooltip(Arrays.asList("How far the mirror reaches in any direction.",
TextFormatting.GRAY + "Max: " + TextFormatting.GOLD + BuildSettingsManager.getMaxReach(mc.player) / 2,
TextFormatting.GRAY + "Upgradeable in survival with reach upgrades."));
mirrorNumberFieldList.add(textMirrorRadius);
y = top + 72;
@@ -206,7 +209,7 @@ public class SettingsGui extends GuiScreen {
y = top + 52;
fontRenderer.drawString("Direction", left + offset, y, 0xFFFFFF, true);
fontRenderer.drawString("Size", left + 190, y, 0xFFFFFF, true);
fontRenderer.drawString("Reach", left + 176 + offset, y, 0xFFFFFF, true);
mirrorButtonList.forEach(button -> button.drawButton(this.mc, mouseX, mouseY, partialTicks));
mirrorIconButtonList.forEach(button -> button.drawButton(this.mc, mouseX, mouseY, partialTicks));
@@ -229,6 +232,12 @@ public class SettingsGui extends GuiScreen {
y = top + 150 + 5;
fontRenderer.drawString("Count", left + offset, y, 0xFFFFFF, true);
int currentReach = Math.max(-1, getArrayReach());
int maxReach = BuildSettingsManager.getMaxReach(mc.player);
TextFormatting reachColor = isCurrentReachValid(currentReach, maxReach) ? TextFormatting.GRAY : TextFormatting.RED;
String reachText = "Reach: " + reachColor + currentReach + TextFormatting.GRAY + "/" + TextFormatting.GRAY + maxReach;
fontRenderer.drawString(reachText, left + 176 + offset, y, 0xFFFFFF, true);
arrayNumberFieldList.forEach(numberField -> numberField.drawNumberField(this.mc, mouseX, mouseY, partialTicks));
} else {
fontRenderer.drawString("Array disabled", left + offset, y, 0x999999, true);
@@ -255,7 +264,7 @@ public class SettingsGui extends GuiScreen {
numberField.keyTyped(typedChar, keyCode);
}
if (keyCode == ClientProxy.keyBindings[0].getKeyCode()) {
Minecraft.getMinecraft().player.closeScreen();
mc.player.closeScreen();
}
}
@@ -339,8 +348,7 @@ public class SettingsGui extends GuiScreen {
try {
mirrorPos = new Vec3d(textMirrorPosX.getNumber(), textMirrorPosY.getNumber(), textMirrorPosZ.getNumber());
} catch (NumberFormatException | NullPointerException ex) {
EffortlessBuilding.log(Minecraft.getMinecraft().player, "Mirror position not valid.", true);
EffortlessBuilding.log("Mirror position not valid. Resetting to default.");
EffortlessBuilding.log(mc.player, "Mirror position not valid.");
}
boolean mirrorX = buttonMirrorX.isChecked();
@@ -349,13 +357,10 @@ public class SettingsGui extends GuiScreen {
int mirrorRadius = 50;
try {
mirrorRadius = Math.min((int) textMirrorRadius.getNumber(), Mirror.MAX_RADIUS);
mirrorRadius = (int) textMirrorRadius.getNumber();
} catch (NumberFormatException | NullPointerException ex) {
EffortlessBuilding.log(Minecraft.getMinecraft().player, "Mirror radius not valid.", true);
EffortlessBuilding.log("Mirror radius not valid. Resetting to default.");
EffortlessBuilding.log(mc.player, "Mirror radius not valid.");
}
mirrorRadius = Math.max(1, mirrorRadius);
mirrorRadius = Math.min(Mirror.MAX_RADIUS, mirrorRadius);
Mirror.MirrorSettings m = new Mirror.MirrorSettings(mirrorEnabled, mirrorPos, mirrorX, mirrorY, mirrorZ, mirrorRadius, drawLines, drawPlanes);
@@ -365,19 +370,15 @@ public class SettingsGui extends GuiScreen {
try {
arrayOffset = new BlockPos(textArrayOffsetX.getNumber(), textArrayOffsetY.getNumber(), textArrayOffsetZ.getNumber());
} catch (NumberFormatException | NullPointerException ex) {
EffortlessBuilding.log(Minecraft.getMinecraft().player, "Array offset not valid.", true);
EffortlessBuilding.log("Array offset not valid. Resetting to default.");
EffortlessBuilding.log(mc.player, "Array offset not valid.");
}
int arrayCount = 5;
try {
arrayCount = (int) textArrayCount.getNumber();
} catch (NumberFormatException | NullPointerException ex) {
EffortlessBuilding.log(Minecraft.getMinecraft().player, "Array count not valid.", true);
EffortlessBuilding.log("Array count not valid. Resetting to default.");
EffortlessBuilding.log(mc.player, "Array count not valid.");
}
arrayCount = Math.max(1, arrayCount);
arrayCount = Math.min(Array.MAX_COUNT, arrayCount);
Array.ArraySettings a = new Array.ArraySettings(arrayEnabled, arrayOffset, arrayCount);
@@ -385,9 +386,32 @@ public class SettingsGui extends GuiScreen {
if (buildSettings == null) buildSettings = new BuildSettingsManager.BuildSettings();
buildSettings.setMirrorSettings(m);
buildSettings.setArraySettings(a);
//Sanitize
String error = BuildSettingsManager.sanitize(buildSettings, mc.player);
if (!error.isEmpty()) EffortlessBuilding.log(mc.player, error);
BuildSettingsManager.setBuildSettings(mc.player, buildSettings);
//Send to server
EffortlessBuilding.packetHandler.sendToServer(new BuildSettingsMessage(buildSettings));
}
private int getArrayReach() {
try
{
//find largest offset
double x = Math.abs(textArrayOffsetX.getNumber());
double y = Math.abs(textArrayOffsetY.getNumber());
double z = Math.abs(textArrayOffsetZ.getNumber());
double largestOffset = Math.max(Math.max(x, y), z);
return (int) (largestOffset * textArrayCount.getNumber());
} catch (NumberFormatException | NullPointerException ex) {
return -1;
}
}
private boolean isCurrentReachValid(int currentReach, int maxReach) {
return currentReach <= maxReach && currentReach > -1;
}
}

View File

@@ -1,4 +1,4 @@
package nl.requios.effortlessbuilding;
package nl.requios.effortlessbuilding.helper;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.BufferBuilder;
@@ -13,6 +13,7 @@ import net.minecraftforge.client.event.RenderWorldLastEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.relauncher.Side;
import nl.requios.effortlessbuilding.*;
import org.lwjgl.opengl.GL11;
import org.lwjgl.util.Color;
@@ -116,7 +117,8 @@ public class RenderHelper {
//Render block outlines
RayTraceResult objectMouseOver = Minecraft.getMinecraft().objectMouseOver;
if (objectMouseOver.typeOfHit == RayTraceResult.Type.BLOCK)
//Checking for null is necessary! Even in vanilla when looking down ladders it is occasionally null (instead of Type MISS)
if (objectMouseOver != null && objectMouseOver.typeOfHit == RayTraceResult.Type.BLOCK)
{
BlockPos blockPos = objectMouseOver.getBlockPos();
@@ -136,8 +138,8 @@ public class RenderHelper {
}
}
//TODO render current block outline based on config
if (buildSettings.doQuickReplace()) {
//Render current block outline based on config, or when QuickReplace is enabled
if (buildSettings.doQuickReplace() || BuildConfig.visuals.showOutlineOnCurrentBlock) {
RenderHelper.renderBlockOutline(blockPos);
}

View File

@@ -1,4 +1,4 @@
package nl.requios.effortlessbuilding;
package nl.requios.effortlessbuilding.helper;
import net.minecraft.block.Block;
import net.minecraft.block.SoundType;
@@ -20,6 +20,7 @@ import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.ItemHandlerHelper;
import nl.requios.effortlessbuilding.EffortlessBuilding;
import nl.requios.effortlessbuilding.item.ItemRandomizerBag;
import javax.annotation.Nonnull;

View File

@@ -6,7 +6,6 @@ import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ActionResult;
@@ -17,16 +16,11 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.world.World;
import net.minecraftforge.common.capabilities.ICapabilityProvider;
import net.minecraftforge.common.util.BlockSnapshot;
import net.minecraftforge.event.world.BlockEvent;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.ItemStackHandler;
import nl.requios.effortlessbuilding.Array;
import nl.requios.effortlessbuilding.EffortlessBuilding;
import nl.requios.effortlessbuilding.Mirror;
import nl.requios.effortlessbuilding.SurvivalHelper;
import nl.requios.effortlessbuilding.capability.ItemHandlerCapabilityProvider;
import nl.requios.effortlessbuilding.helper.SurvivalHelper;
import javax.annotation.Nullable;
import java.util.ArrayList;

View File

@@ -1,9 +1,7 @@
package nl.requios.effortlessbuilding.network;
import io.netty.buffer.ByteBuf;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.util.IThreadListener;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
@@ -51,6 +49,8 @@ public class BuildSettingsMessage implements IMessage {
buf.writeInt(a.count);
buf.writeBoolean(buildSettings.doQuickReplace());
buf.writeInt(buildSettings.getReachUpgrade());
}
@Override
@@ -73,7 +73,10 @@ public class BuildSettingsMessage implements IMessage {
Array.ArraySettings a = new Array.ArraySettings(arrayEnabled, arrayOffset, arrayCount);
boolean quickReplace = buf.readBoolean();
buildSettings = new BuildSettings(m, a, quickReplace);
int reachUpgrade = buf.readInt();
buildSettings = new BuildSettings(m, a, quickReplace, reachUpgrade);
}
// The params of the IMessageHandler are <REQ, REPLY>
@@ -88,15 +91,9 @@ public class BuildSettingsMessage implements IMessage {
EntityPlayer player = EffortlessBuilding.proxy.getPlayerEntityFromContext(ctx);
// The value that was sent
BuildSettings buildSettings = message.buildSettings;
Mirror.MirrorSettings m = buildSettings.getMirrorSettings();
Array.ArraySettings a = buildSettings.getArraySettings();
// Sanitize
m.radius = Math.min(m.radius, Mirror.MAX_RADIUS);
m.radius = Math.max(1, m.radius);
a.count = Math.min(a.count, Array.MAX_COUNT);
a.count = Math.max(0, a.count);
BuildSettingsManager.sanitize(buildSettings, player);
// Execute the action on the main server thread by adding it as a scheduled task
IThreadListener threadListener = EffortlessBuilding.proxy.getThreadListenerFromContext(ctx);

View File

@@ -88,25 +88,32 @@ public class ClientProxy implements IProxy {
@SubscribeEvent(priority = EventPriority.NORMAL, receiveCanceled = true)
public static void onKeyPress(InputEvent.KeyInputEvent event) {
// check each enumerated key binding type for pressed and take appropriate action
EntityPlayerSP player = Minecraft.getMinecraft().player;
//Remember to send packet to server if necessary
//Show HUD
if (keyBindings[0].isPressed()) {
// do stuff for this key binding here
// remember you may need to send packet to server
if (Minecraft.getMinecraft().currentScreen == null) {
Minecraft.getMinecraft().displayGuiScreen(new SettingsGui());
//Disabled if max reach is 0, might be set in the config that way.
if (BuildSettingsManager.getMaxReach(player) == 0) {
EffortlessBuilding.log(player, "Effortless Building is disabled until your reach has increased. Increase your reach with craftable reach upgrades.");
} else {
player.closeScreen();
if (Minecraft.getMinecraft().currentScreen == null) {
Minecraft.getMinecraft().displayGuiScreen(new SettingsGui());
} else {
player.closeScreen();
}
}
}
//QuickReplace toggle
if (keyBindings[1].isPressed()) {
// do stuff for this key binding here
// remember you may need to send packet to server
BuildSettingsManager.BuildSettings buildSettings = BuildSettingsManager.getBuildSettings(player);
buildSettings.setQuickReplace(!buildSettings.doQuickReplace());
EffortlessBuilding.log(player, "Set "+ TextFormatting.GOLD + "Quick Replace " + TextFormatting.RESET + (buildSettings.doQuickReplace() ? "on" : "off"));
EffortlessBuilding.packetHandler.sendToServer(new BuildSettingsMessage(buildSettings));
}
//Creative/survival mode toggle
if (keyBindings[2].isPressed()) {
if (player.isCreative()) {
player.sendChatMessage("/gamemode 0");
@@ -121,6 +128,7 @@ public class ClientProxy implements IProxy {
if (event.phase != TickEvent.Phase.START) return;
RayTraceResult objectMouseOver = Minecraft.getMinecraft().objectMouseOver;
//Checking for null is necessary! Even in vanilla when looking down ladders it is occasionally null (instead of Type MISS)
if (objectMouseOver == null) return;
if (currentLookAt == null) {