Mining speed is decreased based on blocks mined (extra blocks count for 50%, which will be configurable).
Tool durability is checked after each block break (no more breaking 5 blocks with 1 durability). Fortune is taken into account. Outlines now change to blocks that will be broken when holding tools. Added indication QuickReplace is on: outline of current block will be white. Fixed opening Randomizer Bag in offhand. Fixed placing blocks with Randomizer Bag in offhand. Fixed mirror block outline showing up outside range. Fixed outline of QuickReplace not being under replaceables like tall grass.
This commit is contained in:
@@ -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.3"
|
||||
version = "0.3.4"
|
||||
group = "nl.requios.effortlessbuilding" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
|
||||
archivesBaseName = "effortlessbuilding"
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3i;
|
||||
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.item.ItemRandomizerBag;
|
||||
@@ -45,15 +46,15 @@ public class Array {
|
||||
BlockPos pos = event.getPos();
|
||||
Vec3i offset = new Vec3i(a.offset.getX(), a.offset.getY(), a.offset.getZ());
|
||||
|
||||
//Randomizer bag synergy
|
||||
IItemHandler bagInventory = null;
|
||||
if (event.getPlayer().getHeldItemMainhand().getItem() instanceof ItemRandomizerBag) {
|
||||
bagInventory = ItemRandomizerBag.getBagInventory(event.getPlayer().getHeldItemMainhand());
|
||||
}
|
||||
|
||||
//Get itemstack
|
||||
ItemStack itemStack = event.getPlayer().getHeldItem(event.getHand());
|
||||
|
||||
//Randomizer bag synergy
|
||||
IItemHandler bagInventory = null;
|
||||
if (!itemStack.isEmpty() && itemStack.getItem() instanceof ItemRandomizerBag) {
|
||||
bagInventory = ItemRandomizerBag.getBagInventory(itemStack);
|
||||
}
|
||||
|
||||
for (int i = 0; i < a.count; i++) {
|
||||
pos = pos.add(offset);
|
||||
if (event.getWorld().isBlockLoaded(pos, true)) {
|
||||
@@ -65,7 +66,7 @@ public class Array {
|
||||
if (bagInventory != null) {
|
||||
itemStack = ItemRandomizerBag.pickRandomStack(bagInventory);
|
||||
if (itemStack.isEmpty()) continue;
|
||||
blockState = getBlockStateFromRandomizerBag(bagInventory, event.getWorld(), event.getPlayer(), event.getPos(), itemStack);
|
||||
blockState = getBlockStateFromRandomizerBag(bagInventory, event.getWorld(), event.getPlayer(), event.getPos(), itemStack, event.getHand());
|
||||
if (blockState == null) continue;
|
||||
}
|
||||
|
||||
@@ -78,16 +79,16 @@ public class Array {
|
||||
return true;
|
||||
}
|
||||
|
||||
private static IBlockState getBlockStateFromRandomizerBag(IItemHandler bagInventory, World world, EntityPlayer player, BlockPos pos, ItemStack itemStack) {
|
||||
private static IBlockState getBlockStateFromRandomizerBag(IItemHandler bagInventory, World world, EntityPlayer player, BlockPos pos, ItemStack itemStack, EnumHand hand) {
|
||||
//TODO get facing from getPlacedAgainst and getPlacedBlock
|
||||
return Block.getBlockFromItem(itemStack.getItem()).getStateForPlacement(world, pos, EnumFacing.NORTH, 0, 0, 0, itemStack.getMetadata(), player, EnumHand.MAIN_HAND);
|
||||
return Block.getBlockFromItem(itemStack.getItem()).getStateForPlacement(world, pos, EnumFacing.NORTH, 0, 0, 0, itemStack.getMetadata(), player, hand);
|
||||
}
|
||||
|
||||
//Called from EventHandler
|
||||
public static void onBlockBroken(BlockEvent.BreakEvent event) {
|
||||
if (event.getWorld().isRemote) return;
|
||||
|
||||
//find arraysettings for the player that placed the block
|
||||
//find arraysettings for the player that broke the block
|
||||
ArraySettings a = BuildSettingsManager.getBuildSettings(event.getPlayer()).getArraySettings();
|
||||
if (a == null || !a.enabled) return;
|
||||
|
||||
@@ -101,4 +102,23 @@ public class Array {
|
||||
}
|
||||
}
|
||||
|
||||
//Called from EventHandler
|
||||
public static float getTotalBlockHardness(World world, EntityPlayer player, BlockPos pos) {
|
||||
float hardness = 0;
|
||||
|
||||
//find arraysettings for the player that broke the block
|
||||
ArraySettings a = BuildSettingsManager.getBuildSettings(player).getArraySettings();
|
||||
if (a == null || !a.enabled) return 0;
|
||||
|
||||
if (a.offset.getX() == 0 && a.offset.getY() == 0 && a.offset.getZ() == 0) return 0;
|
||||
|
||||
Vec3i offset = new Vec3i(a.offset.getX(), a.offset.getY(), a.offset.getZ());
|
||||
for (int i = 0; i < a.count; i++) {
|
||||
pos = pos.add(offset);
|
||||
if (SurvivalHelper.canBreak(world, player, pos))
|
||||
hardness += world.getBlockState(pos).getBlockHardness(world, pos);
|
||||
}
|
||||
return hardness;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ public class EffortlessBuilding
|
||||
{
|
||||
public static final String MODID = "effortlessbuilding";
|
||||
public static final String NAME = "Effortless Building";
|
||||
public static final String VERSION = "0.3.3";
|
||||
public static final String VERSION = "0.3.4";
|
||||
|
||||
@Mod.Instance(EffortlessBuilding.MODID)
|
||||
public static EffortlessBuilding instance;
|
||||
|
||||
@@ -11,8 +11,12 @@ import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.ForgeHooks;
|
||||
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.common.Mod;
|
||||
@@ -79,4 +83,29 @@ public class EventHandler
|
||||
Array.onBlockBroken(event);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void breakSpeed(PlayerEvent.BreakSpeed event) {
|
||||
//TODO disable with config
|
||||
EntityPlayer player = event.getEntityPlayer();
|
||||
World world = player.world;
|
||||
BlockPos pos = event.getPos();
|
||||
|
||||
//EffortlessBuilding.log(player, String.valueOf(event.getNewSpeed()));
|
||||
|
||||
float originalBlockHardness = event.getState().getBlockHardness(world, pos);
|
||||
float totalBlockHardness = 0;
|
||||
totalBlockHardness += Mirror.getTotalBlockHardness(world, player, pos);
|
||||
totalBlockHardness += Array.getTotalBlockHardness(world, player, pos);
|
||||
|
||||
//TODO get percentage from config
|
||||
float percentage = 0.5f;
|
||||
totalBlockHardness *= percentage;
|
||||
totalBlockHardness += originalBlockHardness;
|
||||
|
||||
float newSpeed = event.getOriginalSpeed() / totalBlockHardness * originalBlockHardness;
|
||||
if (Float.isNaN(newSpeed) || newSpeed == 0f) newSpeed = 1f;
|
||||
event.setNewSpeed(newSpeed);
|
||||
|
||||
//EffortlessBuilding.log(player, String.valueOf(event.getNewSpeed()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.util.math.Vec3i;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.BlockSnapshot;
|
||||
import net.minecraftforge.event.world.BlockEvent;
|
||||
@@ -59,30 +60,32 @@ public class Mirror {
|
||||
oldBlockPos.getZ() + 0.5 < m.position.z - m.radius || oldBlockPos.getZ() + 0.5 > m.position.z + m.radius)
|
||||
return false;
|
||||
|
||||
//Get itemstack
|
||||
ItemStack itemStack = event.getPlayer().getHeldItem(event.getHand());
|
||||
|
||||
//Randomizer bag synergy
|
||||
IItemHandler bagInventory = null;
|
||||
if (event.getPlayer().getHeldItem(event.getHand()).getItem() == EffortlessBuilding.ITEM_RANDOMIZER_BAG) {
|
||||
bagInventory = ItemRandomizerBag.getBagInventory(event.getPlayer().getHeldItem(EnumHand.MAIN_HAND));
|
||||
if (!itemStack.isEmpty() && itemStack.getItem() instanceof ItemRandomizerBag) {
|
||||
bagInventory = ItemRandomizerBag.getBagInventory(itemStack);
|
||||
}
|
||||
|
||||
if (m.mirrorX) {
|
||||
placeMirrorX(event.getWorld(), event.getPlayer(), m, event.getPos(), event.getPlacedBlock(), bagInventory, itemStack);
|
||||
placeMirrorX(event.getWorld(), event.getPlayer(), m, event.getPos(), event.getPlacedBlock(), bagInventory, itemStack, event.getHand());
|
||||
}
|
||||
|
||||
if (m.mirrorY) {
|
||||
placeMirrorY(event.getWorld(), event.getPlayer(), m, oldBlockPos, event.getPlacedBlock(), bagInventory, itemStack);
|
||||
placeMirrorY(event.getWorld(), event.getPlayer(), m, oldBlockPos, event.getPlacedBlock(), bagInventory, itemStack, event.getHand());
|
||||
}
|
||||
|
||||
if (m.mirrorZ) {
|
||||
placeMirrorZ(event.getWorld(), event.getPlayer(), m, oldBlockPos, event.getPlacedBlock(), bagInventory, itemStack);
|
||||
placeMirrorZ(event.getWorld(), event.getPlayer(), m, oldBlockPos, event.getPlacedBlock(), bagInventory, itemStack, event.getHand());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static void placeMirrorX(World world, EntityPlayer player, MirrorSettings m, BlockPos oldBlockPos, IBlockState oldBlockState, IItemHandler bagInventory, ItemStack itemStack) {
|
||||
private static void placeMirrorX(World world, EntityPlayer player, MirrorSettings m, BlockPos oldBlockPos, IBlockState oldBlockState,
|
||||
IItemHandler bagInventory, ItemStack itemStack, EnumHand hand) {
|
||||
//find mirror position
|
||||
double x = m.position.x + (m.position.x - oldBlockPos.getX() - 0.5);
|
||||
BlockPos newBlockPos = new BlockPos(x, oldBlockPos.getY(), oldBlockPos.getZ());
|
||||
@@ -91,20 +94,21 @@ public class Mirror {
|
||||
if (bagInventory != null) {
|
||||
itemStack = ItemRandomizerBag.pickRandomStack(bagInventory);
|
||||
if (itemStack.isEmpty()) return;
|
||||
oldBlockState = getBlockStateFromRandomizerBag(bagInventory, world, player, oldBlockPos, itemStack);
|
||||
oldBlockState = getBlockStateFromRandomizerBag(bagInventory, world, player, oldBlockPos, itemStack, hand);
|
||||
if (oldBlockState == null) return;
|
||||
}
|
||||
|
||||
IBlockState newBlockState = oldBlockState.withMirror(net.minecraft.util.Mirror.FRONT_BACK);
|
||||
//place block
|
||||
if (world.isBlockLoaded(newBlockPos, true)) {
|
||||
placeBlock(world, player, newBlockPos, newBlockState, itemStack);
|
||||
placeBlock(world, player, newBlockPos, newBlockState, itemStack, hand);
|
||||
}
|
||||
if (m.mirrorY) placeMirrorY(world, player, m, newBlockPos, newBlockState, bagInventory, itemStack);
|
||||
if (m.mirrorZ) placeMirrorZ(world, player, m, newBlockPos, newBlockState, bagInventory, itemStack);
|
||||
if (m.mirrorY) placeMirrorY(world, player, m, newBlockPos, newBlockState, bagInventory, itemStack, hand);
|
||||
if (m.mirrorZ) placeMirrorZ(world, player, m, newBlockPos, newBlockState, bagInventory, itemStack, hand);
|
||||
}
|
||||
|
||||
private static void placeMirrorY(World world, EntityPlayer player, MirrorSettings m, BlockPos oldBlockPos, IBlockState oldBlockState, IItemHandler bagInventory, ItemStack itemStack) {
|
||||
private static void placeMirrorY(World world, EntityPlayer player, MirrorSettings m, BlockPos oldBlockPos, IBlockState oldBlockState,
|
||||
IItemHandler bagInventory, ItemStack itemStack, EnumHand hand) {
|
||||
//find mirror position
|
||||
double y = m.position.y + (m.position.y - oldBlockPos.getY() - 0.5);
|
||||
BlockPos newBlockPos = new BlockPos(oldBlockPos.getX(), y, oldBlockPos.getZ());
|
||||
@@ -113,19 +117,20 @@ public class Mirror {
|
||||
if (bagInventory != null) {
|
||||
itemStack = ItemRandomizerBag.pickRandomStack(bagInventory);
|
||||
if (itemStack.isEmpty()) return;
|
||||
oldBlockState = getBlockStateFromRandomizerBag(bagInventory, world, player, oldBlockPos, itemStack);
|
||||
oldBlockState = getBlockStateFromRandomizerBag(bagInventory, world, player, oldBlockPos, itemStack, hand);
|
||||
if (oldBlockState == null) return;
|
||||
}
|
||||
|
||||
IBlockState newBlockState = getVerticalMirror(oldBlockState);
|
||||
//place block
|
||||
if (world.isBlockLoaded(newBlockPos, true)) {
|
||||
placeBlock(world, player, newBlockPos, newBlockState, itemStack);
|
||||
placeBlock(world, player, newBlockPos, newBlockState, itemStack, hand);
|
||||
}
|
||||
if (m.mirrorZ) placeMirrorZ(world, player, m, newBlockPos, newBlockState, bagInventory, itemStack);
|
||||
if (m.mirrorZ) placeMirrorZ(world, player, m, newBlockPos, newBlockState, bagInventory, itemStack, hand);
|
||||
}
|
||||
|
||||
private static void placeMirrorZ(World world, EntityPlayer player, MirrorSettings m, BlockPos oldBlockPos, IBlockState oldBlockState, IItemHandler bagInventory, ItemStack itemStack) {
|
||||
private static void placeMirrorZ(World world, EntityPlayer player, MirrorSettings m, BlockPos oldBlockPos, IBlockState oldBlockState,
|
||||
IItemHandler bagInventory, ItemStack itemStack, EnumHand hand) {
|
||||
//find mirror position
|
||||
double z = m.position.z + (m.position.z - oldBlockPos.getZ() - 0.5);
|
||||
BlockPos newBlockPos = new BlockPos(oldBlockPos.getX(), oldBlockPos.getY(), z);
|
||||
@@ -134,23 +139,23 @@ public class Mirror {
|
||||
if (bagInventory != null) {
|
||||
itemStack = ItemRandomizerBag.pickRandomStack(bagInventory);
|
||||
if (itemStack.isEmpty()) return;
|
||||
oldBlockState = getBlockStateFromRandomizerBag(bagInventory, world, player, oldBlockPos, itemStack);
|
||||
oldBlockState = getBlockStateFromRandomizerBag(bagInventory, world, player, oldBlockPos, itemStack, hand);
|
||||
if (oldBlockState == null) return;
|
||||
}
|
||||
|
||||
IBlockState newBlockState = oldBlockState.withMirror(net.minecraft.util.Mirror.LEFT_RIGHT);
|
||||
//place block
|
||||
if (world.isBlockLoaded(newBlockPos, true)) {
|
||||
placeBlock(world, player, newBlockPos, newBlockState, itemStack);
|
||||
placeBlock(world, player, newBlockPos, newBlockState, itemStack, hand);
|
||||
}
|
||||
}
|
||||
|
||||
private static IBlockState getBlockStateFromRandomizerBag(IItemHandler bagInventory, World world, EntityPlayer player, BlockPos pos, ItemStack itemStack) {
|
||||
private static IBlockState getBlockStateFromRandomizerBag(IItemHandler bagInventory, World world, EntityPlayer player, BlockPos pos, ItemStack itemStack, EnumHand hand) {
|
||||
//TODO get facing from getPlacedAgainst and getPlacedBlock
|
||||
return Block.getBlockFromItem(itemStack.getItem()).getStateForPlacement(world, pos, EnumFacing.NORTH, 0, 0, 0, itemStack.getMetadata(), player, EnumHand.MAIN_HAND);
|
||||
return Block.getBlockFromItem(itemStack.getItem()).getStateForPlacement(world, pos, EnumFacing.NORTH, 0, 0, 0, itemStack.getMetadata(), player, hand);
|
||||
}
|
||||
|
||||
private static void placeBlock(World world, EntityPlayer player, BlockPos newBlockPos, IBlockState newBlockState, ItemStack itemStack) {
|
||||
private static void placeBlock(World world, EntityPlayer player, BlockPos newBlockPos, IBlockState newBlockState, ItemStack itemStack, EnumHand hand) {
|
||||
//TODO check if can place
|
||||
//TODO check if can break
|
||||
|
||||
@@ -158,7 +163,7 @@ public class Mirror {
|
||||
|
||||
//Array synergy
|
||||
BlockSnapshot blockSnapshot = new BlockSnapshot(world, newBlockPos, newBlockState);
|
||||
BlockEvent.PlaceEvent placeEvent = new BlockEvent.PlaceEvent(blockSnapshot, newBlockState, player, EnumHand.MAIN_HAND);
|
||||
BlockEvent.PlaceEvent placeEvent = new BlockEvent.PlaceEvent(blockSnapshot, newBlockState, player, hand);
|
||||
Array.onBlockPlaced(placeEvent);
|
||||
}
|
||||
|
||||
@@ -271,4 +276,78 @@ public class Mirror {
|
||||
Array.onBlockBroken(breakEvent);
|
||||
}
|
||||
|
||||
|
||||
//Called from EventHandler
|
||||
public static float getTotalBlockHardness(World world, EntityPlayer player, BlockPos oldBlockPos) {
|
||||
float hardness = 0;
|
||||
|
||||
//find mirrorsettings for the player that broke the block
|
||||
MirrorSettings m = BuildSettingsManager.getBuildSettings(player).getMirrorSettings();
|
||||
if (m == null) return 0;
|
||||
|
||||
if (!m.enabled || (!m.mirrorX && !m.mirrorY && !m.mirrorZ)) return 0;
|
||||
|
||||
//if within mirror distance, break mirror block
|
||||
if (oldBlockPos.getX() + 0.5 < m.position.x - m.radius || oldBlockPos.getX() + 0.5 > m.position.x + m.radius ||
|
||||
oldBlockPos.getY() + 0.5 < m.position.y - m.radius || oldBlockPos.getY() + 0.5 > m.position.y + m.radius ||
|
||||
oldBlockPos.getZ() + 0.5 < m.position.z - m.radius || oldBlockPos.getZ() + 0.5 > m.position.z + m.radius)
|
||||
return 0;
|
||||
|
||||
if (m.mirrorX) {
|
||||
hardness += getHardnessX(world, player, m, oldBlockPos);
|
||||
}
|
||||
|
||||
if (m.mirrorY) {
|
||||
hardness += getHardnessY(world, player, m, oldBlockPos);
|
||||
}
|
||||
|
||||
if (m.mirrorZ) {
|
||||
hardness += getHardnessZ(world, player, m, oldBlockPos);
|
||||
}
|
||||
return hardness;
|
||||
}
|
||||
|
||||
private static float getHardnessX(World world, EntityPlayer player, MirrorSettings m, BlockPos oldBlockPos) {
|
||||
float hardness = 0;
|
||||
|
||||
//find mirror position
|
||||
double x = m.position.x + (m.position.x - oldBlockPos.getX() - 0.5);
|
||||
BlockPos newBlockPos = new BlockPos(x, oldBlockPos.getY(), oldBlockPos.getZ());
|
||||
|
||||
if (SurvivalHelper.canBreak(world, player, newBlockPos))
|
||||
hardness += world.getBlockState(newBlockPos).getBlockHardness(world, newBlockPos);
|
||||
|
||||
if (m.mirrorY) hardness += getHardnessY(world, player, m, newBlockPos);
|
||||
if (m.mirrorZ) hardness += getHardnessZ(world, player, m, newBlockPos);
|
||||
|
||||
return hardness;
|
||||
}
|
||||
|
||||
private static float getHardnessY(World world, EntityPlayer player, MirrorSettings m, BlockPos oldBlockPos) {
|
||||
float hardness = 0;
|
||||
|
||||
//find mirror position
|
||||
double y = m.position.y + (m.position.y - oldBlockPos.getY() - 0.5);
|
||||
BlockPos newBlockPos = new BlockPos(oldBlockPos.getX(), y, oldBlockPos.getZ());
|
||||
|
||||
if (SurvivalHelper.canBreak(world, player, newBlockPos))
|
||||
hardness += world.getBlockState(newBlockPos).getBlockHardness(world, newBlockPos);
|
||||
|
||||
if (m.mirrorZ) hardness += getHardnessZ(world, player, m, newBlockPos);
|
||||
|
||||
return hardness;
|
||||
}
|
||||
|
||||
private static float getHardnessZ(World world, EntityPlayer player, MirrorSettings m, BlockPos oldBlockPos) {
|
||||
float hardness = 0;
|
||||
|
||||
//find mirror position
|
||||
double z = m.position.z + (m.position.z - oldBlockPos.getZ() - 0.5);
|
||||
BlockPos newBlockPos = new BlockPos(oldBlockPos.getX(), oldBlockPos.getY(), z);
|
||||
|
||||
if (SurvivalHelper.canBreak(world, player, newBlockPos))
|
||||
hardness += world.getBlockState(newBlockPos).getBlockHardness(world, newBlockPos);
|
||||
|
||||
return hardness;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ public class QuickReplace {
|
||||
|
||||
private static Dictionary<UUID, IBlockState> blockStates = new Hashtable<>();
|
||||
private static Dictionary<UUID, ItemStack> itemStacks = new Hashtable<>();
|
||||
private static Dictionary<UUID, EnumHand> hands = new Hashtable<>();
|
||||
|
||||
public static boolean onBlockPlaced(BlockEvent.PlaceEvent event) {
|
||||
if (event.getWorld().isRemote) return true;
|
||||
@@ -35,6 +36,7 @@ public class QuickReplace {
|
||||
|
||||
blockStates.put(event.getPlayer().getUniqueID(), event.getPlacedBlock());
|
||||
itemStacks.put(event.getPlayer().getUniqueID(), event.getPlayer().getHeldItem(event.getHand()));
|
||||
hands.put(event.getPlayer().getUniqueID(), event.getHand());
|
||||
|
||||
//RayTraceResult result = event.getWorld().rayTraceBlocks(event.getPlayer().getPositionEyes(1f), event.getPlayer().getLookVec());
|
||||
EffortlessBuilding.packetHandler.sendTo(new QuickReplaceMessage(), (EntityPlayerMP) event.getPlayer());
|
||||
@@ -57,13 +59,14 @@ public class QuickReplace {
|
||||
|
||||
IBlockState blockState = blockStates.get(player.getUniqueID());
|
||||
ItemStack itemStack = itemStacks.get(player.getUniqueID());
|
||||
EnumHand hand = hands.get(player.getUniqueID());
|
||||
|
||||
SurvivalHelper.placeBlock(player.world, player, placedAgainstBlockPos, blockState, itemStack, message.getSideHit(), true, false);
|
||||
|
||||
//Mirror and Array synergy
|
||||
blockState = player.world.getBlockState(placedAgainstBlockPos);
|
||||
BlockSnapshot blockSnapshot = new BlockSnapshot(player.world, placedAgainstBlockPos, blockState);
|
||||
BlockEvent.PlaceEvent placeEvent = new BlockEvent.PlaceEvent(blockSnapshot, blockState, player, EnumHand.MAIN_HAND);
|
||||
BlockEvent.PlaceEvent placeEvent = new BlockEvent.PlaceEvent(blockSnapshot, blockState, player, hand);
|
||||
Mirror.onBlockPlaced(placeEvent);
|
||||
Array.onBlockPlaced(placeEvent);
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@ import net.minecraft.client.renderer.RenderGlobal;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.ItemTool;
|
||||
import net.minecraft.util.math.*;
|
||||
import net.minecraftforge.client.event.RenderWorldLastEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
@@ -110,30 +112,48 @@ public class RenderHelper {
|
||||
drawMirrorLines(m);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//Render block outlines
|
||||
RayTraceResult objectMouseOver = Minecraft.getMinecraft().objectMouseOver;
|
||||
if (objectMouseOver.typeOfHit == RayTraceResult.Type.BLOCK)
|
||||
{
|
||||
BlockPos blockPos = objectMouseOver.getBlockPos();
|
||||
if (!buildSettings.doQuickReplace()) blockPos = blockPos.offset(objectMouseOver.sideHit);
|
||||
|
||||
//RenderHelper.renderBlockOutline(blockPos);
|
||||
//Check if tool (or none) in hand
|
||||
ItemStack mainhand = player.getHeldItemMainhand();
|
||||
//ItemStack offhand = player.getHeldItemOffhand();
|
||||
//boolean noneInHand = mainhand.isEmpty() && (offhand.isEmpty() || offhand.getItem() instanceof ItemTool);
|
||||
boolean toolInHand = !mainhand.isEmpty() && mainhand.getItem() instanceof ItemTool;
|
||||
if (!buildSettings.doQuickReplace() && !toolInHand) {
|
||||
blockPos = blockPos.offset(objectMouseOver.sideHit);
|
||||
}
|
||||
|
||||
if (buildSettings.doQuickReplace() && !toolInHand) {
|
||||
//Get under tall grass and other replaceable blocks
|
||||
if (player.world.getBlockState(blockPos).getBlock().isReplaceable(player.world, blockPos)) {
|
||||
blockPos = blockPos.down();
|
||||
}
|
||||
}
|
||||
|
||||
//TODO render current block outline based on config
|
||||
if (buildSettings.doQuickReplace()) {
|
||||
RenderHelper.renderBlockOutline(blockPos);
|
||||
}
|
||||
|
||||
//Mirror
|
||||
if (m != null && m.enabled && (m.mirrorX || m.mirrorY || m.mirrorZ) &&
|
||||
!(blockPos.getX() + 0.5 < m.position.x - m.radius) && !(blockPos.getX() + 0.5 > m.position.x + m.radius) &&
|
||||
!(blockPos.getY() + 0.5 < m.position.y - m.radius) && !(blockPos.getY() + 0.5 > m.position.y + m.radius) &&
|
||||
!(blockPos.getZ() + 0.5 < m.position.z - m.radius) && !(blockPos.getZ() + 0.5 > m.position.z + m.radius))
|
||||
{
|
||||
if (m.mirrorX) drawMirrorBlockOutlineX(buildSettings, blockPos);
|
||||
if (m.mirrorY) drawMirrorBlockOutlineY(buildSettings, blockPos);
|
||||
if (m.mirrorZ) drawMirrorBlockOutlineZ(buildSettings, blockPos);
|
||||
}
|
||||
}
|
||||
|
||||
//Array
|
||||
if (a != null && a.enabled && (a.offset.getX() != 0 || a.offset.getY() != 0 || a.offset.getZ() != 0))
|
||||
{
|
||||
//Render block outlines
|
||||
RayTraceResult objectMouseOver = Minecraft.getMinecraft().objectMouseOver;
|
||||
if (objectMouseOver.typeOfHit == RayTraceResult.Type.BLOCK)
|
||||
{
|
||||
BlockPos blockPos = objectMouseOver.getBlockPos();
|
||||
if (!buildSettings.doQuickReplace()) blockPos = blockPos.offset(objectMouseOver.sideHit);
|
||||
|
||||
if (a != null && a.enabled && (a.offset.getX() != 0 || a.offset.getY() != 0 || a.offset.getZ() != 0)) {
|
||||
drawArrayBlockOutlines(a, blockPos);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,9 +4,11 @@ import net.minecraft.block.Block;
|
||||
import net.minecraft.block.SoundType;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.enchantment.EnchantmentHelper;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.Enchantments;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -14,11 +16,13 @@ import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.SoundCategory;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import net.minecraftforge.items.ItemHandlerHelper;
|
||||
import nl.requios.effortlessbuilding.item.ItemRandomizerBag;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
|
||||
@@ -39,7 +43,7 @@ public class SurvivalHelper {
|
||||
|
||||
//Check if itemstack is correct
|
||||
if (!(itemstack.getItem() instanceof ItemBlock) || Block.getBlockFromItem(itemstack.getItem()) != blockState.getBlock()) {
|
||||
EffortlessBuilding.log(player, "Cannot replace block", true);
|
||||
EffortlessBuilding.log(player, "Cannot (re)place block", true);
|
||||
EffortlessBuilding.log("SurvivalHelper#placeBlock: itemstack " + itemstack.toString() + " does not match blockstate " + blockState.toString());
|
||||
return false;
|
||||
}
|
||||
@@ -106,9 +110,36 @@ public class SurvivalHelper {
|
||||
if (player.isCreative()) return true;
|
||||
|
||||
IBlockState blockState = world.getBlockState(pos);
|
||||
if (blockState.getBlock().canHarvestBlock(world, pos, player)) return true;
|
||||
return canHarvestBlock(blockState.getBlock(), player, world, pos);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//From ForgeHooks#canHarvestBlock
|
||||
public static boolean canHarvestBlock(@Nonnull Block block, @Nonnull EntityPlayer player, @Nonnull IBlockAccess world, @Nonnull BlockPos pos)
|
||||
{
|
||||
IBlockState state = world.getBlockState(pos);
|
||||
state = state.getBlock().getActualState(state, world, pos);
|
||||
if (state.getMaterial().isToolNotRequired())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
ItemStack stack = player.getHeldItemMainhand();
|
||||
String tool = block.getHarvestTool(state);
|
||||
if (stack.isEmpty() || tool == null)
|
||||
{
|
||||
return player.canHarvestBlock(state);
|
||||
}
|
||||
|
||||
if (stack.getItemDamage() >= stack.getMaxDamage()) return false;
|
||||
|
||||
int toolLevel = stack.getItem().getHarvestLevel(stack, tool, player, state);
|
||||
if (toolLevel < 0)
|
||||
{
|
||||
return player.canHarvestBlock(state);
|
||||
}
|
||||
|
||||
return toolLevel >= block.getHarvestLevel(state);
|
||||
}
|
||||
|
||||
//Can be harvested with hand? (or in creative)
|
||||
@@ -128,7 +159,8 @@ public class SurvivalHelper {
|
||||
|
||||
IBlockState blockState = world.getBlockState(pos);
|
||||
|
||||
List<ItemStack> drops = blockState.getBlock().getDrops(world, pos, blockState, 0);
|
||||
int fortune = EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, player.getHeldItemMainhand());
|
||||
List<ItemStack> drops = blockState.getBlock().getDrops(world, pos, blockState, fortune);
|
||||
for (ItemStack drop : drops)
|
||||
{
|
||||
ItemHandlerHelper.giveItemToPlayer(player, drop);
|
||||
|
||||
@@ -7,6 +7,7 @@ import net.minecraftforge.fml.common.network.IGuiHandler;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import net.minecraftforge.items.CapabilityItemHandler;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import nl.requios.effortlessbuilding.EffortlessBuilding;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
@@ -17,8 +18,10 @@ public class RandomizerBagGuiHandler implements IGuiHandler {
|
||||
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
|
||||
if (ID == EffortlessBuilding.RANDOMIZER_BAG_GUI) {
|
||||
// Use the player's held item to create the container
|
||||
return new RandomizerBagContainer(player.inventory,
|
||||
player.getHeldItem(EnumHand.MAIN_HAND).getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null));
|
||||
IItemHandler capability = player.getHeldItemMainhand().hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null) ?
|
||||
player.getHeldItemMainhand().getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null) :
|
||||
player.getHeldItemOffhand().getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
|
||||
return new RandomizerBagContainer(player.inventory, capability);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -29,8 +32,10 @@ public class RandomizerBagGuiHandler implements IGuiHandler {
|
||||
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
|
||||
if (ID == EffortlessBuilding.RANDOMIZER_BAG_GUI) {
|
||||
// Use the player's held item to create the client-side gui container
|
||||
return new RandomizerBagGuiContainer(player.inventory,
|
||||
player.getHeldItem(EnumHand.MAIN_HAND).getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null));
|
||||
IItemHandler capability = player.getHeldItemMainhand().hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null) ?
|
||||
player.getHeldItemMainhand().getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null) :
|
||||
player.getHeldItemOffhand().getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
|
||||
return new RandomizerBagGuiContainer(player.inventory, capability);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -2,9 +2,7 @@ package nl.requios.effortlessbuilding.gui;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiButtonImage;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.gui.GuiTextField;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
@@ -15,7 +13,6 @@ import nl.requios.effortlessbuilding.EffortlessBuilding;
|
||||
import nl.requios.effortlessbuilding.Mirror;
|
||||
import nl.requios.effortlessbuilding.network.BuildSettingsMessage;
|
||||
import nl.requios.effortlessbuilding.proxy.ClientProxy;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
import org.lwjgl.input.Mouse;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -90,25 +90,25 @@ public class ItemRandomizerBag extends Item {
|
||||
|
||||
@Override
|
||||
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
|
||||
ItemStack bag = player.getHeldItem(hand);
|
||||
|
||||
if (player.isSneaking()) {
|
||||
if (world.isRemote) return new ActionResult<>(EnumActionResult.SUCCESS, player.getHeldItem(hand));
|
||||
if (world.isRemote) return new ActionResult<>(EnumActionResult.SUCCESS, bag);
|
||||
//Open inventory
|
||||
player.openGui(EffortlessBuilding.instance, EffortlessBuilding.RANDOMIZER_BAG_GUI, world, 0, 0, 0);
|
||||
} else {
|
||||
//Use item
|
||||
//Get bag inventory
|
||||
ItemStack bag = player.getHeldItem(hand);
|
||||
IItemHandler bagInventory = getBagInventory(bag);
|
||||
if (bagInventory == null)
|
||||
return new ActionResult<>(EnumActionResult.FAIL, player.getHeldItem(hand));
|
||||
return new ActionResult<>(EnumActionResult.FAIL, bag);
|
||||
|
||||
ItemStack toUse = pickRandomStack(bagInventory);
|
||||
if (toUse.isEmpty()) return new ActionResult<>(EnumActionResult.FAIL, player.getHeldItem(hand));
|
||||
if (toUse.isEmpty()) return new ActionResult<>(EnumActionResult.FAIL, bag);
|
||||
|
||||
return toUse.useItemRightClick(world, player, hand);
|
||||
}
|
||||
return new ActionResult<>(EnumActionResult.PASS, player.getHeldItem(hand));
|
||||
return new ActionResult<>(EnumActionResult.PASS, bag);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user