3 Commits

Author SHA1 Message Date
Christian Knaapen
346fc6d533 Fixed mouse clicks in Modifier Settings sometimes being in the wrong place.
Fixed typing in multiple text fields at once.
2019-02-28 18:25:39 +01:00
Christian Knaapen
6678405c75 Settings are saved across dimensions (including reach upgrades, issue #12).
Fixed silk touch, shearing leaves, dropping bed etc. (issue #15)
Items dont drop directly to inventory anymore because of above fix, might be re-added later.
Can no longer place blocks in entities (including the player).
Added support for changing config ingame.
Added preliminary ArchitectureCraft compatibility (places right type, not rotation yet).
Updated forge.
2019-02-14 14:57:28 +01:00
Christian Knaapen
d07751a01f Fixed issue #8 Craft when activating the menu.
Fixed being able to mine bedrock. Whoops.
Fixed grass and flowers instabreaking other blocks.
2019-01-11 03:01:04 +01:00
15 changed files with 148 additions and 87 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. //Only edit below this line, the above code adds and enables the necessary things for Forge to be setup.
version = "1.0" version = "1.0.3"
group = "nl.requios.effortlessbuilding" // http://maven.apache.org/guides/mini/guide-naming-conventions.html group = "nl.requios.effortlessbuilding" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = "effortlessbuilding" archivesBaseName = "effortlessbuilding"
@@ -21,7 +21,7 @@ compileJava {
} }
minecraft { minecraft {
version = "1.12.2-14.23.4.2705" version = "1.12.2-14.23.5.2768"
runDir = "run" runDir = "run"
// the mappings can be changed at any time, and must be in the following format. // the mappings can be changed at any time, and must be in the following format.
@@ -29,7 +29,7 @@ minecraft {
// stable_# stables are built at the discretion of the MCP team. // stable_# stables are built at the discretion of the MCP team.
// Use non-default mappings at your own risk. they may not always work. // Use non-default mappings at your own risk. they may not always work.
// simply re-run your setup task after changing the mappings to update your workspace. // simply re-run your setup task after changing the mappings to update your workspace.
mappings = "snapshot_20171003" mappings = "stable_39"
// makeObfSourceJar = false // an Srg named sources jar is made by default. uncomment this to disable. // makeObfSourceJar = false // an Srg named sources jar is made by default. uncomment this to disable.
} }

View File

@@ -74,7 +74,7 @@ public class BuildModifiers {
if (world.isBlockLoaded(blockPos, true)) { if (world.isBlockLoaded(blockPos, true)) {
//check itemstack empty //check itemstack empty
if (itemStack.isEmpty()) continue; if (itemStack.isEmpty()) continue;
SurvivalHelper.placeBlock(world, player, blockPos, blockState, itemStack, EnumFacing.UP, true, false); SurvivalHelper.placeBlock(world, player, blockPos, blockState, itemStack, EnumFacing.UP, hitVec, false, false);
} }
} }
} }
@@ -101,18 +101,27 @@ public class BuildModifiers {
} }
public static void onBlockBroken(BlockEvent.BreakEvent event) { public static void onBlockBroken(BlockEvent.BreakEvent event) {
if (event.getWorld().isRemote) return; World world = event.getWorld();
BlockPos pos = event.getPos();
if (world.isRemote) return;
BuildSettingsManager.BuildSettings buildSettings = BuildSettingsManager.getBuildSettings(event.getPlayer()); BuildSettingsManager.BuildSettings buildSettings = BuildSettingsManager.getBuildSettings(event.getPlayer());
//Only use own break event if anything is enabled //Only use own break event if anything is enabled
if (isEnabled(buildSettings, event.getPos())) { if (isEnabled(buildSettings, pos)) {
//get coordinates //get coordinates
List<BlockPos> coordinates = findCoordinates(event.getPlayer(), event.getPos()); List<BlockPos> coordinates = findCoordinates(event.getPlayer(), pos);
//If the player is going to instabreak grass or a plant, only break other instabreaking things
boolean onlyInstaBreaking = world.getBlockState(pos).getBlockHardness(
world, pos) == 0f;
//break all those blocks //break all those blocks
for (BlockPos coordinate : coordinates) { for (BlockPos coordinate : coordinates) {
if (event.getWorld().isBlockLoaded(coordinate, false)) { if (world.isBlockLoaded(coordinate, false)) {
SurvivalHelper.breakBlock(event.getWorld(), event.getPlayer(), coordinate); if (!onlyInstaBreaking || world.getBlockState(coordinate).getBlockHardness(world, coordinate) == 0f) {
SurvivalHelper.breakBlock(world, event.getPlayer(), coordinate);
}
} }
} }
} }

View File

@@ -104,6 +104,7 @@ public class BuildSettingsManager {
public BuildSettings() { public BuildSettings() {
mirrorSettings = new Mirror.MirrorSettings(); mirrorSettings = new Mirror.MirrorSettings();
arraySettings = new Array.ArraySettings(); arraySettings = new Array.ArraySettings();
radialMirrorSettings = new RadialMirror.RadialMirrorSettings();
} }
public BuildSettings(Mirror.MirrorSettings mirrorSettings, Array.ArraySettings arraySettings, public BuildSettings(Mirror.MirrorSettings mirrorSettings, Array.ArraySettings arraySettings,
@@ -116,26 +117,32 @@ public class BuildSettingsManager {
} }
public Mirror.MirrorSettings getMirrorSettings() { public Mirror.MirrorSettings getMirrorSettings() {
return mirrorSettings; if (this.mirrorSettings == null) this.mirrorSettings = new Mirror.MirrorSettings();
return this.mirrorSettings;
} }
public void setMirrorSettings(Mirror.MirrorSettings mirrorSettings) { public void setMirrorSettings(Mirror.MirrorSettings mirrorSettings) {
if (mirrorSettings == null) return;
this.mirrorSettings = mirrorSettings; this.mirrorSettings = mirrorSettings;
} }
public Array.ArraySettings getArraySettings() { public Array.ArraySettings getArraySettings() {
return arraySettings; if (this.arraySettings == null) this.arraySettings = new Array.ArraySettings();
return this.arraySettings;
} }
public void setArraySettings(Array.ArraySettings arraySettings) { public void setArraySettings(Array.ArraySettings arraySettings) {
if (arraySettings == null) return;
this.arraySettings = arraySettings; this.arraySettings = arraySettings;
} }
public RadialMirror.RadialMirrorSettings getRadialMirrorSettings() { public RadialMirror.RadialMirrorSettings getRadialMirrorSettings() {
return radialMirrorSettings; if (this.radialMirrorSettings == null) this.radialMirrorSettings = new RadialMirror.RadialMirrorSettings();
return this.radialMirrorSettings;
} }
public void setRadialMirrorSettings(RadialMirror.RadialMirrorSettings radialMirrorSettings) { public void setRadialMirrorSettings(RadialMirror.RadialMirrorSettings radialMirrorSettings) {
if (radialMirrorSettings == null) return;
this.radialMirrorSettings = radialMirrorSettings; this.radialMirrorSettings = radialMirrorSettings;
} }
@@ -168,6 +175,12 @@ public class BuildSettingsManager {
handleNewPlayer(player); handleNewPlayer(player);
} }
@SubscribeEvent
public static void onPlayerChangedDimension(PlayerEvent.PlayerChangedDimensionEvent event) {
EntityPlayer player = event.player;
handleNewPlayer(player);
}
private static void handleNewPlayer(EntityPlayer player){ private static void handleNewPlayer(EntityPlayer player){
if (getBuildSettings(player) == null) { if (getBuildSettings(player) == null) {
setBuildSettings(player, new BuildSettings()); setBuildSettings(player, new BuildSettings());

View File

@@ -36,7 +36,7 @@ public class EffortlessBuilding
{ {
public static final String MODID = "effortlessbuilding"; public static final String MODID = "effortlessbuilding";
public static final String NAME = "Effortless Building"; public static final String NAME = "Effortless Building";
public static final String VERSION = "1.0"; public static final String VERSION = "1.0.3";
@Mod.Instance(EffortlessBuilding.MODID) @Mod.Instance(EffortlessBuilding.MODID)
public static EffortlessBuilding instance; public static EffortlessBuilding instance;

View File

@@ -52,7 +52,7 @@ public class EventHandler
} }
@SubscribeEvent @SubscribeEvent
public void onConfigChangedEvent(ConfigChangedEvent.OnConfigChangedEvent event) public static void onConfigChangedEvent(ConfigChangedEvent.OnConfigChangedEvent event)
{ {
if (event.getModID().equals(EffortlessBuilding.MODID)) if (event.getModID().equals(EffortlessBuilding.MODID))
{ {
@@ -88,6 +88,7 @@ public class EventHandler
//EffortlessBuilding.log(player, String.valueOf(event.getNewSpeed())); //EffortlessBuilding.log(player, String.valueOf(event.getNewSpeed()));
float originalBlockHardness = event.getState().getBlockHardness(world, pos); float originalBlockHardness = event.getState().getBlockHardness(world, pos);
if (originalBlockHardness < 0) return; //Dont break bedrock
float totalBlockHardness = 0; float totalBlockHardness = 0;
//get coordinates //get coordinates
List<BlockPos> coordinates = BuildModifiers.findCoordinates(player, pos); List<BlockPos> coordinates = BuildModifiers.findCoordinates(player, pos);

View File

@@ -139,7 +139,7 @@ public class ArraySettingsGui extends GuiCollapsibleScrollEntry {
@Override @Override
public boolean mousePressed(int slotIndex, int mouseX, int mouseY, int mouseEvent, int relativeX, int relativeY) { public boolean mousePressed(int slotIndex, int mouseX, int mouseY, int mouseEvent, int relativeX, int relativeY) {
super.mousePressed(slotIndex, mouseX, mouseY, mouseEvent, relativeX, relativeY); super.mousePressed(slotIndex, mouseX, mouseY, mouseEvent, relativeX, relativeY);
arrayNumberFieldList.forEach(numberField -> numberField.mouseClicked(mouseX, mouseY, mouseEvent)); arrayNumberFieldList.forEach(numberField -> numberField.mouseClicked(mouseX, mouseY, mouseEvent));
boolean insideArrayEnabledLabel = mouseX >= left && mouseX < right && relativeY >= -2 && relativeY < 12; boolean insideArrayEnabledLabel = mouseX >= left && mouseX < right && relativeY >= -2 && relativeY < 12;

View File

@@ -73,22 +73,24 @@ public class GuiScrollPane extends GuiListExtended {
int insideLeft = this.left + this.width / 2 - this.getListWidth() / 2 + 2; int insideLeft = this.left + this.width / 2 - this.getListWidth() / 2 + 2;
int insideTop = this.top + 4 - (int)this.amountScrolled; int insideTop = this.top + 4 - (int)this.amountScrolled;
if (this.hasListHeader) if (this.hasListHeader) {
{
this.drawListHeader(insideLeft, insideTop, tessellator); this.drawListHeader(insideLeft, insideTop, tessellator);
} }
//All entries //All entries
this.drawSelectionBox(insideLeft, insideTop, mouseXIn, mouseYIn, partialTicks); this.drawSelectionBox(insideLeft, insideTop, mouseXIn, mouseYIn, partialTicks);
GlStateManager.disableDepth(); GlStateManager.disableDepth();
//Dirt overlays on top and bottom //Dirt overlays on top and bottom
// this.overlayBackground(0, this.top, 255, 255); // this.overlayBackground(0, this.top, 255, 255);
// this.overlayBackground(this.bottom, this.height, 255, 255); // this.overlayBackground(this.bottom, this.height, 255, 255);
GlStateManager.enableBlend(); GlStateManager.enableBlend();
GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ZERO, GlStateManager.DestFactor.ONE); GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ZERO, GlStateManager.DestFactor.ONE);
GlStateManager.disableAlpha(); GlStateManager.disableAlpha();
GlStateManager.shadeModel(7425); GlStateManager.shadeModel(7425);
GlStateManager.disableTexture2D(); GlStateManager.disableTexture2D();
// //top fade // //top fade
// bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR); // bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
// bufferbuilder.pos((double)this.left, (double)(this.top + 5), 0.0D).tex(0.0D, 1.0D).color(100, 100, 100, 0).endVertex(); // bufferbuilder.pos((double)this.left, (double)(this.top + 5), 0.0D).tex(0.0D, 1.0D).color(100, 100, 100, 0).endVertex();
@@ -96,6 +98,7 @@ public class GuiScrollPane extends GuiListExtended {
// bufferbuilder.pos((double)this.right, (double)this.top, 0.0D).tex(1.0D, 0.0D).color(100, 100, 100, 100).endVertex(); // bufferbuilder.pos((double)this.right, (double)this.top, 0.0D).tex(1.0D, 0.0D).color(100, 100, 100, 100).endVertex();
// bufferbuilder.pos((double)this.left, (double)this.top, 0.0D).tex(0.0D, 0.0D).color(100, 100, 100, 100).endVertex(); // bufferbuilder.pos((double)this.left, (double)this.top, 0.0D).tex(0.0D, 0.0D).color(100, 100, 100, 100).endVertex();
// tessellator.draw(); // tessellator.draw();
// //top line // //top line
// bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR); // bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
// bufferbuilder.pos((double)this.left, (double)this.top, 0.0D).tex(0.0D, 1.0D).color(20, 20, 20, 255).endVertex(); // bufferbuilder.pos((double)this.left, (double)this.top, 0.0D).tex(0.0D, 1.0D).color(20, 20, 20, 255).endVertex();
@@ -103,6 +106,7 @@ public class GuiScrollPane extends GuiListExtended {
// bufferbuilder.pos((double)this.right, (double)(this.top - 1), 0.0D).tex(1.0D, 0.0D).color(20, 20, 20, 255).endVertex(); // bufferbuilder.pos((double)this.right, (double)(this.top - 1), 0.0D).tex(1.0D, 0.0D).color(20, 20, 20, 255).endVertex();
// bufferbuilder.pos((double)this.left, (double)(this.top - 1), 0.0D).tex(0.0D, 0.0D).color(20, 20, 20, 255).endVertex(); // bufferbuilder.pos((double)this.left, (double)(this.top - 1), 0.0D).tex(0.0D, 0.0D).color(20, 20, 20, 255).endVertex();
// tessellator.draw(); // tessellator.draw();
// //bottom fade // //bottom fade
// bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR); // bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
// bufferbuilder.pos((double)this.left, (double)this.bottom, 0.0D).tex(0.0D, 1.0D).color(10, 10, 10, 100).endVertex(); // bufferbuilder.pos((double)this.left, (double)this.bottom, 0.0D).tex(0.0D, 1.0D).color(10, 10, 10, 100).endVertex();
@@ -110,6 +114,7 @@ public class GuiScrollPane extends GuiListExtended {
// bufferbuilder.pos((double)this.right, (double)(this.bottom - 5), 0.0D).tex(1.0D, 0.0D).color(10, 10, 10, 0).endVertex(); // bufferbuilder.pos((double)this.right, (double)(this.bottom - 5), 0.0D).tex(1.0D, 0.0D).color(10, 10, 10, 0).endVertex();
// bufferbuilder.pos((double)this.left, (double)(this.bottom - 5), 0.0D).tex(0.0D, 0.0D).color(10, 10, 10, 0).endVertex(); // bufferbuilder.pos((double)this.left, (double)(this.bottom - 5), 0.0D).tex(0.0D, 0.0D).color(10, 10, 10, 0).endVertex();
// tessellator.draw(); // tessellator.draw();
// //bottom line // //bottom line
// bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR); // bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
// bufferbuilder.pos((double)this.left, (double)(this.bottom + 1), 0.0D).tex(0.0D, 1.0D).color(20, 20, 20, 255).endVertex(); // bufferbuilder.pos((double)this.left, (double)(this.bottom + 1), 0.0D).tex(0.0D, 1.0D).color(20, 20, 20, 255).endVertex();
@@ -137,12 +142,14 @@ public class GuiScrollPane extends GuiListExtended {
bufferbuilder.pos((double)scrollBarRight, (double)this.top, 0.0D).tex(1.0D, 0.0D).color(0, 0, 0, 255).endVertex(); bufferbuilder.pos((double)scrollBarRight, (double)this.top, 0.0D).tex(1.0D, 0.0D).color(0, 0, 0, 255).endVertex();
bufferbuilder.pos((double)scrollBarLeft, (double)this.top, 0.0D).tex(0.0D, 0.0D).color(0, 0, 0, 255).endVertex(); bufferbuilder.pos((double)scrollBarLeft, (double)this.top, 0.0D).tex(0.0D, 0.0D).color(0, 0, 0, 255).endVertex();
tessellator.draw(); tessellator.draw();
bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR); bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
bufferbuilder.pos((double)scrollBarLeft, (double)(l1 + k1), 0.0D).tex(0.0D, 1.0D).color(128, 128, 128, 255).endVertex(); bufferbuilder.pos((double)scrollBarLeft, (double)(l1 + k1), 0.0D).tex(0.0D, 1.0D).color(128, 128, 128, 255).endVertex();
bufferbuilder.pos((double)scrollBarRight, (double)(l1 + k1), 0.0D).tex(1.0D, 1.0D).color(128, 128, 128, 255).endVertex(); bufferbuilder.pos((double)scrollBarRight, (double)(l1 + k1), 0.0D).tex(1.0D, 1.0D).color(128, 128, 128, 255).endVertex();
bufferbuilder.pos((double)scrollBarRight, (double)l1, 0.0D).tex(1.0D, 0.0D).color(128, 128, 128, 255).endVertex(); bufferbuilder.pos((double)scrollBarRight, (double)l1, 0.0D).tex(1.0D, 0.0D).color(128, 128, 128, 255).endVertex();
bufferbuilder.pos((double)scrollBarLeft, (double)l1, 0.0D).tex(0.0D, 0.0D).color(128, 128, 128, 255).endVertex(); bufferbuilder.pos((double)scrollBarLeft, (double)l1, 0.0D).tex(0.0D, 0.0D).color(128, 128, 128, 255).endVertex();
tessellator.draw(); tessellator.draw();
bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR); bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
bufferbuilder.pos((double)scrollBarLeft, (double)(l1 + k1 - 1), 0.0D).tex(0.0D, 1.0D).color(192, 192, 192, 255).endVertex(); bufferbuilder.pos((double)scrollBarLeft, (double)(l1 + k1 - 1), 0.0D).tex(0.0D, 1.0D).color(192, 192, 192, 255).endVertex();
bufferbuilder.pos((double)(scrollBarRight - 1), (double)(l1 + k1 - 1), 0.0D).tex(1.0D, 1.0D).color(192, 192, 192, 255).endVertex(); bufferbuilder.pos((double)(scrollBarRight - 1), (double)(l1 + k1 - 1), 0.0D).tex(1.0D, 1.0D).color(192, 192, 192, 255).endVertex();
@@ -184,8 +191,7 @@ public class GuiScrollPane extends GuiListExtended {
public int getSlotIndexFromScreenCoords(int posX, int posY) { public int getSlotIndexFromScreenCoords(int posX, int posY) {
int left = this.left + (this.width - this.getListWidth()) / 2; int left = this.left + (this.width - this.getListWidth()) / 2;
int right = this.left + (this.width + this.getListWidth()) / 2; int right = this.left + (this.width + this.getListWidth()) / 2;
int relativeMouseY = posY - this.top - this.headerPadding + (int)this.amountScrolled - 4; //click height in content dimensions int relativeMouseY = getRelativeMouseY(mouseY, 0);
//int slotIndex = relativeMouseY / this.slotHeight;
//Iterate over every entry until relativeMouseY falls within its height //Iterate over every entry until relativeMouseY falls within its height
for (int i = 0; i < listEntries.size(); i++) { for (int i = 0; i < listEntries.size(); i++) {
@@ -201,25 +207,33 @@ public class GuiScrollPane extends GuiListExtended {
@Override @Override
public boolean mouseClicked(int mouseX, int mouseY, int mouseEvent) public boolean mouseClicked(int mouseX, int mouseY, int mouseEvent)
{ {
if (this.isMouseYWithinSlotBounds(mouseY)) int selectedSlot = this.getSlotIndexFromScreenCoords(mouseX, mouseY);
{ int relativeX = getRelativeMouseX(mouseX);
int i = this.getSlotIndexFromScreenCoords(mouseX, mouseY);
if (i >= 0) //Always pass through mouseclicked, to be able to unfocus textfields
{ for (int i = 0; i < this.listEntries.size(); i++) {
int j = this.left + this.width / 2 - this.getListWidth() / 2 + 2; int relativeY = getRelativeMouseY(mouseY, i);
int k = this.top + 4 - this.getAmountScrolled() + getContentHeight(i) + this.headerPadding; this.getListEntry(i).mousePressed(selectedSlot, mouseX, mouseY, mouseEvent, relativeX, relativeY);
int relativeX = mouseX - j;
int relativeY = mouseY - k;
if (this.getListEntry(i).mousePressed(i, mouseX, mouseY, mouseEvent, relativeX, relativeY))
{
this.setEnabled(false);
return true;
}
}
} }
// if (this.isMouseYWithinSlotBounds(mouseY))
// {
// int i = this.getSlotIndexFromScreenCoords(mouseX, mouseY);
//
// if (i >= 0)
// {
// int relativeX = getRelativeMouseX(mouseX);
// int relativeY = getRelativeMouseY(mouseY, i);
//
// if (this.getListEntry(i).mousePressed(i, mouseX, mouseY, mouseEvent, relativeX, relativeY))
// {
// this.setEnabled(false);
// return true;
// }
// }
// }
return false; return false;
} }
@@ -228,10 +242,8 @@ public class GuiScrollPane extends GuiListExtended {
{ {
for (int i = 0; i < this.getSize(); ++i) for (int i = 0; i < this.getSize(); ++i)
{ {
int j = this.left + this.width / 2 - this.getListWidth() / 2 + 2; int relativeX = getRelativeMouseX(mouseX);
int k = this.top + 4 - this.getAmountScrolled() + getContentHeight(i) + this.headerPadding; int relativeY = getRelativeMouseY(mouseY, i);
int relativeX = x - j;
int relativeY = y - k;
this.getListEntry(i).mouseReleased(i, x, y, mouseEvent, relativeX, relativeY); this.getListEntry(i).mouseReleased(i, x, y, mouseEvent, relativeX, relativeY);
} }
@@ -246,9 +258,8 @@ public class GuiScrollPane extends GuiListExtended {
this.mouseY <= this.bottom) { this.mouseY <= this.bottom) {
int i = this.left + (this.width - this.getListWidth()) / 2; int i = this.left + (this.width - this.getListWidth()) / 2;
int j = this.left + (this.width + this.getListWidth()) / 2; int j = this.left + (this.width + this.getListWidth()) / 2;
int relativeMouseY = this.mouseY - this.top - this.headerPadding + (int) this.amountScrolled -
4; //click height in content dimensions
int slotIndex = getSlotIndexFromScreenCoords(this.mouseX, this.mouseY); int slotIndex = getSlotIndexFromScreenCoords(this.mouseX, this.mouseY);
int relativeMouseY = getRelativeMouseY(mouseY, slotIndex);
if (slotIndex > -1) { if (slotIndex > -1) {
this.elementClicked(slotIndex, false, this.mouseX, this.mouseY); this.elementClicked(slotIndex, false, this.mouseX, this.mouseY);
@@ -265,9 +276,8 @@ public class GuiScrollPane extends GuiListExtended {
if (this.mouseY >= this.top && this.mouseY <= this.bottom) { if (this.mouseY >= this.top && this.mouseY <= this.bottom) {
int i2 = this.left + (this.width - this.getListWidth()) / 2; int i2 = this.left + (this.width - this.getListWidth()) / 2;
int j2 = this.left + (this.width + this.getListWidth()) / 2; int j2 = this.left + (this.width + this.getListWidth()) / 2;
int relativeMouseY = this.mouseY - this.top - this.headerPadding + (int) this.amountScrolled -
4; //click height in content dimensions
int slotIndex = getSlotIndexFromScreenCoords(this.mouseX, this.mouseY); int slotIndex = getSlotIndexFromScreenCoords(this.mouseX, this.mouseY);
int relativeMouseY = getRelativeMouseY(mouseY, slotIndex);
if (slotIndex > -1) { if (slotIndex > -1) {
boolean flag = slotIndex == this.selectedElement && boolean flag = slotIndex == this.selectedElement &&
@@ -383,6 +393,26 @@ public class GuiScrollPane extends GuiListExtended {
} }
} }
private int getRelativeMouseX(int mouseX) {
int j = this.left + this.width / 2 - this.getListWidth() / 2 + 2;
return mouseX - j;
}
private int getRelativeMouseY(int mouseY, int contentIndex) {
int k = this.top + 4 - this.getAmountScrolled() + getContentHeight(contentIndex) + this.headerPadding;
int relativeMouseY = mouseY - k;
//Content might be centered, adjust relative mouse y accordingly
int contentHeight = getContentHeight();
int insideHeight = this.bottom - this.top - 4;
if (contentHeight < insideHeight) {
//it fits, so we can center it vertically
relativeMouseY -= (insideHeight - contentHeight) / 2;
}
return relativeMouseY;
}
//PASSTHROUGHS //PASSTHROUGHS
public int initGui(int id, List<GuiButton> buttonList) { public int initGui(int id, List<GuiButton> buttonList) {
for (IScrollEntry entry : this.listEntries) { for (IScrollEntry entry : this.listEntries) {

View File

@@ -232,7 +232,7 @@ public class RenderHelper implements IWorldEventListener {
ItemStack itemstack = itemStacks.get(i); ItemStack itemstack = itemStacks.get(i);
//Check if can place //Check if can place
if (!itemstack.isEmpty() && SurvivalHelper.canPlayerEdit(player, player.world, blockPos, itemstack) && if (!itemstack.isEmpty() && SurvivalHelper.canPlayerEdit(player, player.world, blockPos, itemstack) &&
SurvivalHelper.mayPlace(player.world, Block.getBlockFromItem(itemstack.getItem()), blockState, blockPos, true, EnumFacing.UP, player) && SurvivalHelper.mayPlace(player.world, Block.getBlockFromItem(itemstack.getItem()), blockState, blockPos, false, EnumFacing.UP, player) &&
SurvivalHelper.canReplace(player.world, player, blockPos)) { SurvivalHelper.canReplace(player.world, player, blockPos)) {
renderBlockPreview(dispatcher, blockPos, blockState); renderBlockPreview(dispatcher, blockPos, blockState);
} }

View File

@@ -13,10 +13,12 @@ import net.minecraft.init.Enchantments;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.stats.StatList;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
import net.minecraft.util.SoundCategory; import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.IBlockAccess; import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.IItemHandler;
@@ -34,7 +36,7 @@ public class SurvivalHelper {
//Used for all placing of blocks in this mod. //Used for all placing of blocks in this mod.
//Checks if area is loaded, if player has the right permissions, if existing block can be replaced (drops it if so) and consumes an item from the stack. //Checks if area is loaded, if player has the right permissions, if existing block can be replaced (drops it if so) and consumes an item from the stack.
//Based on ItemBlock#onItemUse //Based on ItemBlock#onItemUse
public static boolean placeBlock(World world, EntityPlayer player, BlockPos pos, IBlockState blockState, ItemStack itemstack, EnumFacing facing, boolean skipCollisionCheck, boolean playSound) { public static boolean placeBlock(World world, EntityPlayer player, BlockPos pos, IBlockState blockState, ItemStack itemstack, EnumFacing facing, Vec3d hitVec, boolean skipCollisionCheck, boolean playSound) {
if (!world.isBlockLoaded(pos, true)) return false; if (!world.isBlockLoaded(pos, true)) return false;
//Randomizer bag synergy //Randomizer bag synergy
@@ -55,24 +57,26 @@ public class SurvivalHelper {
if (!itemstack.isEmpty() && canPlayerEdit(player, world, pos, itemstack) && if (!itemstack.isEmpty() && canPlayerEdit(player, world, pos, itemstack) &&
mayPlace(world, block, blockState, pos, skipCollisionCheck, facing.getOpposite(), player) && mayPlace(world, block, blockState, pos, skipCollisionCheck, facing.getOpposite(), player) &&
canReplace(world, player, pos)) canReplace(world, player, pos)) {
{
//Drop existing block //Drop existing block
//TODO check if can replace
dropBlock(world, player, pos); dropBlock(world, player, pos);
boolean placed = ((ItemBlock) itemstack.getItem()).placeBlockAt(itemstack, player, world, pos, facing, (float) hitVec.x, (float) hitVec.y, (float) hitVec.z, blockState);
if (!placed) return false;
//From ItemBlock#placeBlockAt //From ItemBlock#placeBlockAt
if (!world.setBlockState(pos, blockState, 11)) return false; // if (!world.setBlockState(pos, blockState, 11)) return false;
//
IBlockState state = world.getBlockState(pos); IBlockState state = world.getBlockState(pos);
if (state.getBlock() == block) // if (state.getBlock() == block)
{ // {
((ItemBlock) itemstack.getItem()).setTileEntityNBT(world, player, pos, itemstack); // ((ItemBlock) itemstack.getItem()).setTileEntityNBT(world, player, pos, itemstack);
block.onBlockPlacedBy(world, pos, state, player, itemstack); // block.onBlockPlacedBy(world, pos, state, player, itemstack);
//
// if (player instanceof EntityPlayerMP) //// if (player instanceof EntityPlayerMP)
// CriteriaTriggers.PLACED_BLOCK.trigger((EntityPlayerMP)player, pos, itemstack); //// CriteriaTriggers.PLACED_BLOCK.trigger((EntityPlayerMP)player, pos, itemstack);
} // }
if (playSound) { if (playSound) {
SoundType soundtype = state.getBlock().getSoundType(state, world, pos, player); SoundType soundtype = state.getBlock().getSoundType(state, world, pos, player);
@@ -123,6 +127,12 @@ public class SurvivalHelper {
{ {
IBlockState state = world.getBlockState(pos); IBlockState state = world.getBlockState(pos);
state = state.getBlock().getActualState(state, world, pos); state = state.getBlock().getActualState(state, world, pos);
//Dont break bedrock
if (state.getBlockHardness((World) world, pos) < 0) {
return false;
}
if (state.getMaterial().isToolNotRequired()) if (state.getMaterial().isToolNotRequired())
{ {
return true; return true;
@@ -162,13 +172,16 @@ public class SurvivalHelper {
if (player.isCreative()) return; if (player.isCreative()) return;
IBlockState blockState = world.getBlockState(pos); IBlockState blockState = world.getBlockState(pos);
Block block = blockState.getBlock();
int fortune = EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, player.getHeldItemMainhand()); block.harvestBlock(world, player, pos, blockState, world.getTileEntity(pos), player.getHeldItemMainhand());
List<ItemStack> drops = blockState.getBlock().getDrops(world, pos, blockState, fortune);
for (ItemStack drop : drops) // int fortune = EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, player.getHeldItemMainhand());
{ // List<ItemStack> drops = blockState.getBlock().getDrops(world, pos, blockState, fortune);
ItemHandlerHelper.giveItemToPlayer(player, drop); // for (ItemStack drop : drops)
} // {
// ItemHandlerHelper.giveItemToPlayer(player, drop);
// }
} }
//From EntityPlayer#canPlayerEdit //From EntityPlayer#canPlayerEdit
@@ -191,9 +204,9 @@ public class SurvivalHelper {
public static boolean mayPlace(World world, Block blockIn, IBlockState newBlockState, BlockPos pos, boolean skipCollisionCheck, EnumFacing sidePlacedOn, @Nullable Entity placer) public static boolean mayPlace(World world, Block blockIn, IBlockState newBlockState, BlockPos pos, boolean skipCollisionCheck, EnumFacing sidePlacedOn, @Nullable Entity placer)
{ {
IBlockState iblockstate1 = world.getBlockState(pos); IBlockState iblockstate1 = world.getBlockState(pos);
AxisAlignedBB axisalignedbb = skipCollisionCheck ? null : blockIn.getDefaultState().getCollisionBoundingBox(world, pos); AxisAlignedBB axisalignedbb = skipCollisionCheck ? Block.NULL_AABB : blockIn.getDefaultState().getCollisionBoundingBox(world, pos);
if (axisalignedbb != Block.NULL_AABB && !world.checkNoEntityCollision(axisalignedbb.offset(pos), placer)) if (axisalignedbb != Block.NULL_AABB && !world.checkNoEntityCollision(axisalignedbb.offset(pos)))
{ {
return false; return false;
} }

View File

@@ -13,6 +13,7 @@ import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand; import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.text.TextFormatting; import net.minecraft.util.text.TextFormatting;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.capabilities.ICapabilityProvider; import net.minecraftforge.common.capabilities.ICapabilityProvider;
@@ -36,7 +37,7 @@ public class ItemRandomizerBag extends Item {
public ItemRandomizerBag() { public ItemRandomizerBag() {
this.setRegistryName(EffortlessBuilding.MODID, "randomizer_bag"); this.setRegistryName(EffortlessBuilding.MODID, "randomizer_bag");
this.setUnlocalizedName(this.getRegistryName().toString()); this.setTranslationKey(this.getRegistryName().toString());
this.maxStackSize = 1; this.maxStackSize = 1;
this.setCreativeTab(CreativeTabs.TOOLS); this.setCreativeTab(CreativeTabs.TOOLS);
@@ -72,14 +73,8 @@ public class ItemRandomizerBag extends Item {
IBlockState blockState = Block.getBlockFromItem(toPlace.getItem()).getStateForPlacement(world, pos, facing, IBlockState blockState = Block.getBlockFromItem(toPlace.getItem()).getStateForPlacement(world, pos, facing,
hitX, hitY, hitZ, toPlace.getMetadata(), player, hand); hitX, hitY, hitZ, toPlace.getMetadata(), player, hand);
SurvivalHelper.placeBlock(world, player, pos, blockState, toPlace, facing, false, true); SurvivalHelper.placeBlock(world, player, pos, blockState, toPlace, facing, new Vec3d(hitX, hitY, hitZ), false, true);
//Synergy
//Works without calling
// BlockSnapshot blockSnapshot = new BlockSnapshot(player.world, pos, blockState);
// BlockEvent.PlaceEvent placeEvent = new BlockEvent.PlaceEvent(blockSnapshot, blockState, player, hand);
// Mirror.onBlockPlaced(placeEvent);
// Array.onBlockPlaced(placeEvent);
} }
return EnumActionResult.SUCCESS; return EnumActionResult.SUCCESS;
} }
@@ -181,8 +176,8 @@ public class ItemRandomizerBag extends Item {
} }
@Override @Override
public String getUnlocalizedName() { public String getTranslationKey() {
return super.getUnlocalizedName(); return super.getTranslationKey();
} }
public static void resetRandomness() { public static void resetRandomness() {

View File

@@ -21,7 +21,7 @@ public class ItemReachUpgrade1 extends Item {
public ItemReachUpgrade1() { public ItemReachUpgrade1() {
this.setRegistryName(EffortlessBuilding.MODID, "reach_upgrade1"); this.setRegistryName(EffortlessBuilding.MODID, "reach_upgrade1");
this.setUnlocalizedName(this.getRegistryName().toString()); this.setTranslationKey(this.getRegistryName().toString());
this.maxStackSize = 1; this.maxStackSize = 1;
this.setCreativeTab(CreativeTabs.TOOLS); this.setCreativeTab(CreativeTabs.TOOLS);
@@ -67,7 +67,7 @@ public class ItemReachUpgrade1 extends Item {
} }
@Override @Override
public String getUnlocalizedName() { public String getTranslationKey() {
return super.getUnlocalizedName(); return super.getTranslationKey();
} }
} }

View File

@@ -20,7 +20,7 @@ public class ItemReachUpgrade2 extends Item {
public ItemReachUpgrade2() { public ItemReachUpgrade2() {
this.setRegistryName(EffortlessBuilding.MODID, "reach_upgrade2"); this.setRegistryName(EffortlessBuilding.MODID, "reach_upgrade2");
this.setUnlocalizedName(this.getRegistryName().toString()); this.setTranslationKey(this.getRegistryName().toString());
this.maxStackSize = 1; this.maxStackSize = 1;
this.setCreativeTab(CreativeTabs.TOOLS); this.setCreativeTab(CreativeTabs.TOOLS);
@@ -65,7 +65,7 @@ public class ItemReachUpgrade2 extends Item {
} }
@Override @Override
public String getUnlocalizedName() { public String getTranslationKey() {
return super.getUnlocalizedName(); return super.getTranslationKey();
} }
} }

View File

@@ -20,7 +20,7 @@ public class ItemReachUpgrade3 extends Item {
public ItemReachUpgrade3() { public ItemReachUpgrade3() {
this.setRegistryName(EffortlessBuilding.MODID, "reach_upgrade3"); this.setRegistryName(EffortlessBuilding.MODID, "reach_upgrade3");
this.setUnlocalizedName(this.getRegistryName().toString()); this.setTranslationKey(this.getRegistryName().toString());
this.maxStackSize = 1; this.maxStackSize = 1;
this.setCreativeTab(CreativeTabs.TOOLS); this.setCreativeTab(CreativeTabs.TOOLS);
@@ -68,7 +68,7 @@ public class ItemReachUpgrade3 extends Item {
} }
@Override @Override
public String getUnlocalizedName() { public String getTranslationKey() {
return super.getUnlocalizedName(); return super.getTranslationKey();
} }
} }

View File

@@ -65,7 +65,7 @@ public class BlockBrokenMessage implements IMessage {
public void fromBytes(ByteBuf buf) { public void fromBytes(ByteBuf buf) {
blockHit = buf.readBoolean(); blockHit = buf.readBoolean();
blockPos = new BlockPos(buf.readInt(), buf.readInt(), buf.readInt()); blockPos = new BlockPos(buf.readInt(), buf.readInt(), buf.readInt());
sideHit = EnumFacing.getFront(buf.readInt()); sideHit = EnumFacing.byIndex(buf.readInt());
hitVec = new Vec3d(buf.readDouble(), buf.readDouble(), buf.readDouble()); hitVec = new Vec3d(buf.readDouble(), buf.readDouble(), buf.readDouble());
} }

View File

@@ -66,7 +66,7 @@ public class BlockPlacedMessage implements IMessage {
public void fromBytes(ByteBuf buf) { public void fromBytes(ByteBuf buf) {
blockHit = buf.readBoolean(); blockHit = buf.readBoolean();
blockPos = new BlockPos(buf.readInt(), buf.readInt(), buf.readInt()); blockPos = new BlockPos(buf.readInt(), buf.readInt(), buf.readInt());
sideHit = EnumFacing.getFront(buf.readInt()); sideHit = EnumFacing.byIndex(buf.readInt());
hitVec = new Vec3d(buf.readDouble(), buf.readDouble(), buf.readDouble()); hitVec = new Vec3d(buf.readDouble(), buf.readDouble(), buf.readDouble());
} }