Checks if placeBlock is allowed. Fixed stutter on line rendering. Added toggle for creative/survival mode.
This commit is contained in:
@@ -3,7 +3,9 @@ package nl.requios.effortlessbuilding;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
@@ -59,31 +61,27 @@ public class Array {
|
||||
if (event.getWorld().isBlockLoaded(pos, true)) {
|
||||
if (itemStack.isEmpty()) break;
|
||||
|
||||
//Check if held block = placed block (otherwise its a bag or wand)
|
||||
if (!event.getPlayer().isCreative() && Block.getBlockFromItem(itemStack.getItem()) == event.getPlacedBlock().getBlock()) {
|
||||
itemStack.shrink(1);
|
||||
}
|
||||
IBlockState blockState = event.getPlacedBlock();
|
||||
|
||||
//Randomizer bag synergy
|
||||
IBlockState blockState = bagInventory == null ? event.getPlacedBlock() :
|
||||
getBlockStateFromRandomizerBag(bagInventory, event.getWorld(), event.getPlayer(), event.getPos());
|
||||
if (bagInventory != null) {
|
||||
itemStack = ItemRandomizerBag.pickRandomStack(bagInventory);
|
||||
if (itemStack.isEmpty()) continue;
|
||||
blockState = getBlockStateFromRandomizerBag(bagInventory, event.getWorld(), event.getPlayer(), event.getPos(), itemStack);
|
||||
if (blockState == null) continue;
|
||||
}
|
||||
|
||||
//TODO check if can place (ItemBlock) and if can break replaced
|
||||
|
||||
//Drop existing block
|
||||
SurvivalHelper.dropBlock(event.getWorld(), pos, event.getPlayer());
|
||||
|
||||
event.getWorld().setBlockState(pos, blockState);
|
||||
SurvivalHelper.placeBlock(event.getWorld(), event.getPlayer(), pos, blockState, itemStack, EnumFacing.NORTH, true, false);
|
||||
}
|
||||
}
|
||||
//EffortlessBuilding.log(event.getPlayer(), String.valueOf(event.getPlayer().getHeldItem(event.getHand()).getCount()));
|
||||
}
|
||||
|
||||
private static IBlockState getBlockStateFromRandomizerBag(IItemHandler bagInventory, World world, EntityPlayer player, BlockPos pos) {
|
||||
int randomSlot = ItemRandomizerBag.pickRandomSlot(bagInventory);
|
||||
ItemStack stack = bagInventory.getStackInSlot(randomSlot);
|
||||
private static IBlockState getBlockStateFromRandomizerBag(IItemHandler bagInventory, World world, EntityPlayer player, BlockPos pos, ItemStack itemStack) {
|
||||
//TODO get facing from getPlacedAgainst and getPlacedBlock
|
||||
return Block.getBlockFromItem(stack.getItem()).getStateForPlacement(world, pos, EnumFacing.NORTH, 0, 0, 0, stack.getMetadata(), player, EnumHand.MAIN_HAND);
|
||||
return Block.getBlockFromItem(itemStack.getItem()).getStateForPlacement(world, pos, EnumFacing.NORTH, 0, 0, 0, itemStack.getMetadata(), player, EnumHand.MAIN_HAND);
|
||||
}
|
||||
|
||||
//Called from EventHandler
|
||||
|
||||
@@ -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.1.3";
|
||||
public static final String VERSION = "0.2";
|
||||
|
||||
@Mod.Instance(EffortlessBuilding.MODID)
|
||||
public static EffortlessBuilding instance;
|
||||
|
||||
@@ -79,6 +79,8 @@ public class Mirror {
|
||||
oldBlockPos.getZ() + 0.5 < m.position.z - m.radius || oldBlockPos.getZ() + 0.5 > m.position.z + m.radius)
|
||||
return;
|
||||
|
||||
ItemStack itemStack = event.getPlayer().getHeldItem(event.getHand());
|
||||
|
||||
//Randomizer bag synergy
|
||||
IItemHandler bagInventory = null;
|
||||
if (event.getPlayer().getHeldItem(event.getHand()).getItem() == EffortlessBuilding.ITEM_RANDOMIZER_BAG) {
|
||||
@@ -86,91 +88,91 @@ public class Mirror {
|
||||
}
|
||||
|
||||
if (m.mirrorX) {
|
||||
placeMirrorX(event.getWorld(), event.getPlayer(), m, event.getPos(), event.getPlacedBlock(), bagInventory);
|
||||
placeMirrorX(event.getWorld(), event.getPlayer(), m, event.getPos(), event.getPlacedBlock(), bagInventory, itemStack);
|
||||
}
|
||||
|
||||
if (m.mirrorY) {
|
||||
placeMirrorY(event.getWorld(), event.getPlayer(), m, oldBlockPos, event.getPlacedBlock(), bagInventory);
|
||||
placeMirrorY(event.getWorld(), event.getPlayer(), m, oldBlockPos, event.getPlacedBlock(), bagInventory, itemStack);
|
||||
}
|
||||
|
||||
if (m.mirrorZ) {
|
||||
placeMirrorZ(event.getWorld(), event.getPlayer(), m, oldBlockPos, event.getPlacedBlock(), bagInventory);
|
||||
placeMirrorZ(event.getWorld(), event.getPlayer(), m, oldBlockPos, event.getPlacedBlock(), bagInventory, itemStack);
|
||||
}
|
||||
}
|
||||
|
||||
private static IBlockState getBlockStateFromRandomizerBag(IItemHandler bagInventory, World world, EntityPlayer player, BlockPos pos) {
|
||||
int randomSlot = ItemRandomizerBag.pickRandomSlot(bagInventory);
|
||||
ItemStack stack = bagInventory.getStackInSlot(randomSlot);
|
||||
//TODO get facing from getPlacedAgainst and getPlacedBlock
|
||||
return Block.getBlockFromItem(stack.getItem()).getStateForPlacement(world, pos, EnumFacing.NORTH, 0, 0, 0, stack.getMetadata(), player, EnumHand.MAIN_HAND);
|
||||
}
|
||||
|
||||
private static void placeMirrorX(World world, EntityPlayer player, MirrorSettings m, BlockPos oldBlockPos, IBlockState oldBlockState, IItemHandler bagInventory) {
|
||||
private static void placeMirrorX(World world, EntityPlayer player, MirrorSettings m, BlockPos oldBlockPos, IBlockState oldBlockState, IItemHandler bagInventory, ItemStack itemStack) {
|
||||
//find mirror position
|
||||
double x = m.position.x + (m.position.x - oldBlockPos.getX() - 0.5);
|
||||
BlockPos newBlockPos = new BlockPos(x, oldBlockPos.getY(), oldBlockPos.getZ());
|
||||
|
||||
//Randomizer bag synergy
|
||||
if (bagInventory != null)
|
||||
oldBlockState = getBlockStateFromRandomizerBag(bagInventory, world, player, oldBlockPos);
|
||||
if (bagInventory != null) {
|
||||
itemStack = ItemRandomizerBag.pickRandomStack(bagInventory);
|
||||
if (itemStack.isEmpty()) return;
|
||||
oldBlockState = getBlockStateFromRandomizerBag(bagInventory, world, player, oldBlockPos, itemStack);
|
||||
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);
|
||||
placeBlock(world, player, newBlockPos, newBlockState, itemStack);
|
||||
}
|
||||
if (m.mirrorY) placeMirrorY(world, player, m, newBlockPos, newBlockState, bagInventory);
|
||||
if (m.mirrorZ) placeMirrorZ(world, player, m, newBlockPos, newBlockState, bagInventory);
|
||||
if (m.mirrorY) placeMirrorY(world, player, m, newBlockPos, newBlockState, bagInventory, itemStack);
|
||||
if (m.mirrorZ) placeMirrorZ(world, player, m, newBlockPos, newBlockState, bagInventory, itemStack);
|
||||
}
|
||||
|
||||
private static void placeMirrorY(World world, EntityPlayer player, MirrorSettings m, BlockPos oldBlockPos, IBlockState oldBlockState, IItemHandler bagInventory) {
|
||||
private static void placeMirrorY(World world, EntityPlayer player, MirrorSettings m, BlockPos oldBlockPos, IBlockState oldBlockState, IItemHandler bagInventory, ItemStack itemStack) {
|
||||
//find mirror position
|
||||
double y = m.position.y + (m.position.y - oldBlockPos.getY() - 0.5);
|
||||
BlockPos newBlockPos = new BlockPos(oldBlockPos.getX(), y, oldBlockPos.getZ());
|
||||
|
||||
//Randomizer bag synergy
|
||||
if (bagInventory != null)
|
||||
oldBlockState = getBlockStateFromRandomizerBag(bagInventory, world, player, oldBlockPos);
|
||||
if (bagInventory != null) {
|
||||
itemStack = ItemRandomizerBag.pickRandomStack(bagInventory);
|
||||
if (itemStack.isEmpty()) return;
|
||||
oldBlockState = getBlockStateFromRandomizerBag(bagInventory, world, player, oldBlockPos, itemStack);
|
||||
if (oldBlockState == null) return;
|
||||
}
|
||||
|
||||
IBlockState newBlockState = getVerticalMirror(oldBlockState);
|
||||
//place block
|
||||
if (world.isBlockLoaded(newBlockPos, true)) {
|
||||
placeBlock(world, player, newBlockPos, newBlockState);
|
||||
placeBlock(world, player, newBlockPos, newBlockState, itemStack);
|
||||
}
|
||||
if (m.mirrorZ) placeMirrorZ(world, player, m, newBlockPos, newBlockState, bagInventory);
|
||||
if (m.mirrorZ) placeMirrorZ(world, player, m, newBlockPos, newBlockState, bagInventory, itemStack);
|
||||
}
|
||||
|
||||
private static void placeMirrorZ(World world, EntityPlayer player, MirrorSettings m, BlockPos oldBlockPos, IBlockState oldBlockState, IItemHandler bagInventory) {
|
||||
private static void placeMirrorZ(World world, EntityPlayer player, MirrorSettings m, BlockPos oldBlockPos, IBlockState oldBlockState, IItemHandler bagInventory, ItemStack itemStack) {
|
||||
//find mirror position
|
||||
double z = m.position.z + (m.position.z - oldBlockPos.getZ() - 0.5);
|
||||
BlockPos newBlockPos = new BlockPos(oldBlockPos.getX(), oldBlockPos.getY(), z);
|
||||
|
||||
//Randomizer bag synergy
|
||||
if (bagInventory != null)
|
||||
oldBlockState = getBlockStateFromRandomizerBag(bagInventory, world, player, oldBlockPos);
|
||||
if (bagInventory != null) {
|
||||
itemStack = ItemRandomizerBag.pickRandomStack(bagInventory);
|
||||
if (itemStack.isEmpty()) return;
|
||||
oldBlockState = getBlockStateFromRandomizerBag(bagInventory, world, player, oldBlockPos, itemStack);
|
||||
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);
|
||||
placeBlock(world, player, newBlockPos, newBlockState, itemStack);
|
||||
}
|
||||
}
|
||||
|
||||
private static void placeBlock(World world, EntityPlayer player, BlockPos newBlockPos, IBlockState newBlockState) {
|
||||
//Check itemstack
|
||||
ItemStack itemStack = player.getHeldItem(player.swingingHand); //TODO check hand
|
||||
if (itemStack.isEmpty()) return;
|
||||
private static IBlockState getBlockStateFromRandomizerBag(IItemHandler bagInventory, World world, EntityPlayer player, BlockPos pos, ItemStack itemStack) {
|
||||
//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);
|
||||
}
|
||||
|
||||
private static void placeBlock(World world, EntityPlayer player, BlockPos newBlockPos, IBlockState newBlockState, ItemStack itemStack) {
|
||||
//TODO check if can place
|
||||
//TODO check if can break
|
||||
|
||||
SurvivalHelper.dropBlock(world, newBlockPos, player);
|
||||
world.setBlockState(newBlockPos, newBlockState);
|
||||
|
||||
//Check if held block = placed block (otherwise its a bag or wand)
|
||||
if (!player.isCreative() && Block.getBlockFromItem(itemStack.getItem()) == newBlockState.getBlock()) {
|
||||
itemStack.shrink(1);
|
||||
}
|
||||
SurvivalHelper.placeBlock(world, player, newBlockPos, newBlockState, itemStack, EnumFacing.NORTH, true, false);
|
||||
|
||||
//Array synergy
|
||||
BlockSnapshot blockSnapshot = new BlockSnapshot(world, newBlockPos, newBlockState);
|
||||
@@ -304,7 +306,11 @@ public class Mirror {
|
||||
|
||||
if (m == null || !m.enabled || (!m.mirrorX && !m.mirrorY && !m.mirrorZ)) return;
|
||||
|
||||
Vec3d playerPos = new Vec3d(player.posX, player.posY, player.posZ);
|
||||
double playerX = player.prevPosX + (player.posX - player.prevPosX) * event.getPartialTicks();
|
||||
double playerY = player.prevPosY + (player.posY - player.prevPosY) * event.getPartialTicks();
|
||||
double playerZ = player.prevPosZ + (player.posZ - player.prevPosZ) * event.getPartialTicks();
|
||||
|
||||
Vec3d playerPos = new Vec3d(playerX, playerY, playerZ);
|
||||
Vec3d pos = m.position.add(epsilon);
|
||||
int radius = m.radius;
|
||||
|
||||
@@ -345,6 +351,7 @@ public class Mirror {
|
||||
|
||||
GL11.glEnable(GL11.GL_BLEND);
|
||||
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
GL11.glTranslated(-playerPos.x, -playerPos.y, -playerPos.z);
|
||||
|
||||
GL11.glColor4d(c.getRed(), c.getGreen(), c.getBlue(), planeAlpha);
|
||||
|
||||
@@ -58,14 +58,15 @@ public class QuickReplace {
|
||||
|
||||
IBlockState blockState = blockStates.get(player.getUniqueID());
|
||||
|
||||
SurvivalHelper.dropBlock(player.world, placedAgainstBlockPos, player);
|
||||
player.world.setBlockState(placedAgainstBlockPos, blockState);
|
||||
|
||||
//Shrink itemstack with 1
|
||||
ItemStack itemStack = player.getHeldItem(player.swingingHand); //TODO check hand
|
||||
if (!player.isCreative() && Block.getBlockFromItem(itemStack.getItem()) == blockState.getBlock()) {
|
||||
itemStack.shrink(1);
|
||||
}
|
||||
//SurvivalHelper.dropBlock(player.world, placedAgainstBlockPos, player);
|
||||
//player.world.setBlockState(placedAgainstBlockPos, blockState);
|
||||
SurvivalHelper.placeBlock(player.world, player, placedAgainstBlockPos, blockState, itemStack, message.getSideHit(), true, false);
|
||||
|
||||
// //Shrink itemstack with 1
|
||||
// if (!player.isCreative() && Block.getBlockFromItem(itemStack.getItem()) == blockState.getBlock()) {
|
||||
// itemStack.shrink(1);
|
||||
// }
|
||||
|
||||
//Mirror and Array synergy
|
||||
BlockSnapshot blockSnapshot = new BlockSnapshot(player.world, placedAgainstBlockPos, blockState);
|
||||
|
||||
@@ -1,17 +1,64 @@
|
||||
package nl.requios.effortlessbuilding;
|
||||
|
||||
import net.minecraft.advancements.CriteriaTriggers;
|
||||
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.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
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.World;
|
||||
import net.minecraftforge.items.ItemHandlerHelper;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
|
||||
public class SurvivalHelper {
|
||||
|
||||
//From ItemBlock#onItemUse
|
||||
public static boolean placeBlock(World world, EntityPlayer player, BlockPos pos, IBlockState blockState, ItemStack itemstack, EnumFacing facing, boolean skipCollisionCheck, boolean playSound) {
|
||||
Block block = ((ItemBlock) itemstack.getItem()).getBlock();
|
||||
if (!itemstack.isEmpty() && canPlayerEdit(player, world, pos, itemstack) && mayPlace(world, block, pos, skipCollisionCheck, facing.getOpposite(), player))
|
||||
{
|
||||
//Drop existing block
|
||||
dropBlock(world, pos, player);
|
||||
|
||||
//From ItemBlock#placeBlockAt
|
||||
if (!world.setBlockState(pos, blockState, 11)) return false;
|
||||
|
||||
IBlockState state = world.getBlockState(pos);
|
||||
if (state.getBlock() == block)
|
||||
{
|
||||
((ItemBlock) itemstack.getItem()).setTileEntityNBT(world, player, pos, itemstack);
|
||||
block.onBlockPlacedBy(world, pos, state, player, itemstack);
|
||||
|
||||
// if (player instanceof EntityPlayerMP)
|
||||
// CriteriaTriggers.PLACED_BLOCK.trigger((EntityPlayerMP)player, pos, itemstack);
|
||||
}
|
||||
|
||||
if (playSound) {
|
||||
SoundType soundtype = state.getBlock().getSoundType(state, world, pos, player);
|
||||
world.playSound(null, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F);
|
||||
}
|
||||
|
||||
if (!player.isCreative() && Block.getBlockFromItem(itemstack.getItem()) == block) {
|
||||
itemstack.shrink(1);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean canBreak(){
|
||||
return true;
|
||||
}
|
||||
@@ -32,4 +79,41 @@ public class SurvivalHelper {
|
||||
ItemHandlerHelper.giveItemToPlayer(player, drop);
|
||||
}
|
||||
}
|
||||
|
||||
//From EntityPlayer#canPlayerEdit
|
||||
private static boolean canPlayerEdit(EntityPlayer player, World world, BlockPos pos, ItemStack stack)
|
||||
{
|
||||
if (player.capabilities.allowEdit)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Block block = world.getBlockState(pos).getBlock();
|
||||
return stack.canPlaceOn(block) || stack.canEditBlocks();
|
||||
}
|
||||
}
|
||||
|
||||
//From World#mayPlace
|
||||
private static boolean mayPlace(World world, Block blockIn, BlockPos pos, boolean skipCollisionCheck, EnumFacing sidePlacedOn, @Nullable Entity placer)
|
||||
{
|
||||
IBlockState iblockstate1 = world.getBlockState(pos);
|
||||
AxisAlignedBB axisalignedbb = skipCollisionCheck ? null : blockIn.getDefaultState().getCollisionBoundingBox(world, pos);
|
||||
|
||||
if (axisalignedbb != Block.NULL_AABB && !world.checkNoEntityCollision(axisalignedbb.offset(pos), placer))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (iblockstate1.getMaterial() == Material.CIRCUITS && blockIn == Blocks.ANVIL)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
//TODO check config for allow to replace
|
||||
return true;
|
||||
//TODO fix check canPlaceBlockOnSide
|
||||
//return /*iblockstate1.getBlock().isReplaceable(world, pos) &&*/ blockIn.canPlaceBlockOnSide(world, pos, sidePlacedOn);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ 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;
|
||||
@@ -23,6 +24,7 @@ import net.minecraftforge.items.IItemHandler;
|
||||
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 javax.annotation.Nullable;
|
||||
@@ -40,7 +42,7 @@ public class ItemRandomizerBag extends Item {
|
||||
this.setUnlocalizedName(this.getRegistryName().toString());
|
||||
|
||||
this.maxStackSize = 1;
|
||||
this.setCreativeTab(CreativeTabs.DECORATIONS);
|
||||
this.setCreativeTab(CreativeTabs.TOOLS);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -59,11 +61,7 @@ public class ItemRandomizerBag extends Item {
|
||||
if (bagInventory == null)
|
||||
return EnumActionResult.FAIL;
|
||||
|
||||
int randomSlot = pickRandomSlot(bagInventory);
|
||||
if (randomSlot < 0 || randomSlot > bagInventory.getSlots()) return EnumActionResult.FAIL;
|
||||
|
||||
ItemStack toPlace = bagInventory.getStackInSlot(randomSlot);
|
||||
|
||||
ItemStack toPlace = pickRandomStack(bagInventory);
|
||||
if (toPlace.isEmpty()) return EnumActionResult.FAIL;
|
||||
|
||||
//Previously: use onItemUse to place block (no synergy)
|
||||
@@ -74,15 +72,21 @@ public class ItemRandomizerBag extends Item {
|
||||
pos = pos.offset(facing);
|
||||
}
|
||||
|
||||
// if (!player.isCreative()) {
|
||||
// toPlace.shrink(1);
|
||||
// }
|
||||
|
||||
IBlockState blockState = Block.getBlockFromItem(toPlace.getItem()).getStateForPlacement(world, pos, facing,
|
||||
hitX, hitY, hitZ, toPlace.getMetadata(), player, hand);
|
||||
world.setBlockState(pos, blockState);
|
||||
//world.setBlockState(pos, blockState);
|
||||
SurvivalHelper.placeBlock(world, player, pos, blockState, toPlace, facing, false, true);
|
||||
|
||||
//Synergy
|
||||
BlockSnapshot blockSnapshot = new BlockSnapshot(player.world, pos, blockState);
|
||||
BlockEvent.PlaceEvent placeEvent = new BlockEvent.PlaceEvent(blockSnapshot, blockState, player, hand);
|
||||
Mirror.onBlockPlaced(placeEvent);
|
||||
Array.onBlockPlaced(placeEvent);
|
||||
//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;
|
||||
}
|
||||
@@ -102,11 +106,7 @@ public class ItemRandomizerBag extends Item {
|
||||
if (bagInventory == null)
|
||||
return new ActionResult<>(EnumActionResult.FAIL, player.getHeldItem(hand));
|
||||
|
||||
int randomSlot = pickRandomSlot(bagInventory);
|
||||
if (randomSlot < 0 || randomSlot > bagInventory.getSlots())
|
||||
return new ActionResult<>(EnumActionResult.FAIL, player.getHeldItem(hand));
|
||||
|
||||
ItemStack toUse = bagInventory.getStackInSlot(randomSlot);
|
||||
ItemStack toUse = pickRandomStack(bagInventory);
|
||||
if (toUse.isEmpty()) return new ActionResult<>(EnumActionResult.FAIL, player.getHeldItem(hand));
|
||||
|
||||
return toUse.useItemRightClick(world, player, hand);
|
||||
@@ -131,7 +131,7 @@ public class ItemRandomizerBag extends Item {
|
||||
* @param bagInventory
|
||||
* @return
|
||||
*/
|
||||
public static int pickRandomSlot(IItemHandler bagInventory) {
|
||||
public static ItemStack pickRandomStack(IItemHandler bagInventory) {
|
||||
//Find how many stacks are non-empty, and save them in a list
|
||||
int nonempty = 0;
|
||||
List<ItemStack> nonEmptyStacks = new ArrayList<>(INV_SIZE);
|
||||
@@ -148,12 +148,16 @@ public class ItemRandomizerBag extends Item {
|
||||
if (nonEmptyStacks.size() != originalSlots.size())
|
||||
throw new Error("NonEmptyStacks and OriginalSlots not same size");
|
||||
|
||||
if (nonempty == 0) return -1;
|
||||
if (nonempty == 0) return ItemStack.EMPTY;
|
||||
|
||||
//Pick random slot
|
||||
int randomSlot = rand.nextInt(nonempty);
|
||||
if (randomSlot < 0 || randomSlot > bagInventory.getSlots()) return ItemStack.EMPTY;
|
||||
|
||||
return originalSlots.get(randomSlot);
|
||||
int originalSlot = originalSlots.get(randomSlot);
|
||||
if (originalSlot < 0 || originalSlot > bagInventory.getSlots()) return ItemStack.EMPTY;
|
||||
|
||||
return bagInventory.getStackInSlot(originalSlot);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -172,4 +176,9 @@ public class ItemRandomizerBag extends Item {
|
||||
tooltip.add(TextFormatting.BLUE + "Rightclick" + TextFormatting.GRAY + " to place a random block");
|
||||
tooltip.add(TextFormatting.BLUE + "Sneak + rightclick" + TextFormatting.GRAY + " to open inventory");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUnlocalizedName() {
|
||||
return super.getUnlocalizedName();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package nl.requios.effortlessbuilding.proxy;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.SoundType;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.entity.EntityPlayerSP;
|
||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||
@@ -41,11 +42,12 @@ public class ClientProxy implements IProxy {
|
||||
@Override
|
||||
public void init(FMLInitializationEvent event) {
|
||||
// register key bindings
|
||||
keyBindings = new KeyBinding[2];
|
||||
keyBindings = new KeyBinding[3];
|
||||
|
||||
// instantiate the key bindings
|
||||
keyBindings[0] = new KeyBinding("key.hud.desc", Keyboard.KEY_ADD, "key.effortlessbuilding.category");
|
||||
keyBindings[1] = new KeyBinding("key.replace.desc", Keyboard.KEY_SUBTRACT, "key.effortlessbuilding.category");
|
||||
keyBindings[2] = new KeyBinding("key.creative.desc", Keyboard.KEY_F4, "key.effortlessbuilding.category");
|
||||
|
||||
// register all the key bindings
|
||||
for (int i = 0; i < keyBindings.length; ++i) {
|
||||
@@ -105,6 +107,13 @@ public class ClientProxy implements IProxy {
|
||||
EffortlessBuilding.log(player, "Set "+ TextFormatting.GOLD + "Quick Replace " + TextFormatting.RESET + (buildSettings.doQuickReplace() ? "on" : "off"));
|
||||
EffortlessBuilding.packetHandler.sendToServer(new BuildSettingsMessage(buildSettings));
|
||||
}
|
||||
if (keyBindings[2].isPressed()) {
|
||||
if (player.isCreative()) {
|
||||
player.sendChatMessage("/gamemode 0");
|
||||
} else {
|
||||
player.sendChatMessage("/gamemode 1");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
key.effortlessbuilding.category=Effortless Building
|
||||
key.hud.desc=Open Settings
|
||||
key.replace.desc=Switch Replace Mode
|
||||
key.replace.desc=Toggle QuickReplace
|
||||
key.creative.desc=Toggle Creative/Survival
|
||||
|
||||
item.effortlessbuilding:randomizer_bag.name=Randomizer Bag
|
||||
Reference in New Issue
Block a user