Make arcane lock work on both halves of a double chest at once
This commit is contained in:
@@ -47,28 +47,39 @@ public class ArcaneLock extends SpellRay {
|
|||||||
protected boolean onBlockHit(World world, BlockPos pos, EnumFacing side, Vec3d hit, EntityLivingBase caster, Vec3d origin, int ticksInUse, SpellModifiers modifiers){
|
protected boolean onBlockHit(World world, BlockPos pos, EnumFacing side, Vec3d hit, EntityLivingBase caster, Vec3d origin, int ticksInUse, SpellModifiers modifiers){
|
||||||
|
|
||||||
if(caster instanceof EntityPlayer){
|
if(caster instanceof EntityPlayer){
|
||||||
|
|
||||||
TileEntity tileentity = world.getTileEntity(pos);
|
|
||||||
|
|
||||||
if(tileentity != null){
|
if(toggleLock(world, pos, (EntityPlayer)caster)){
|
||||||
|
BlockPos otherHalf = WizardryUtilities.getConnectedChest(world, pos);
|
||||||
if(tileentity.getTileData().hasUniqueId(NBT_KEY)){
|
if(otherHalf != null) toggleLock(world, otherHalf, (EntityPlayer)caster);
|
||||||
// Unlocking
|
return true;
|
||||||
if(world.getPlayerEntityByUUID(tileentity.getTileData().getUniqueId(NBT_KEY)) == caster){
|
|
||||||
NBTExtras.removeUniqueId(tileentity.getTileData(), NBT_KEY);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
// Locking
|
|
||||||
tileentity.getTileData().setUniqueId(NBT_KEY, caster.getUniqueID());
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean toggleLock(World world, BlockPos pos, EntityPlayer player){
|
||||||
|
|
||||||
|
TileEntity tileentity = world.getTileEntity(pos);
|
||||||
|
|
||||||
|
if(tileentity != null){
|
||||||
|
|
||||||
|
if(tileentity.getTileData().hasUniqueId(NBT_KEY)){
|
||||||
|
// Unlocking
|
||||||
|
if(world.getPlayerEntityByUUID(tileentity.getTileData().getUniqueId(NBT_KEY)) == player){
|
||||||
|
NBTExtras.removeUniqueId(tileentity.getTileData(), NBT_KEY);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
// Locking
|
||||||
|
tileentity.getTileData().setUniqueId(NBT_KEY, player.getUniqueID());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean onMiss(World world, EntityLivingBase caster, Vec3d origin, Vec3d direction, int ticksInUse, SpellModifiers modifiers){
|
protected boolean onMiss(World world, EntityLivingBase caster, Vec3d origin, Vec3d direction, int ticksInUse, SpellModifiers modifiers){
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import electroblob.wizardry.item.ISpellCastingItem;
|
|||||||
import electroblob.wizardry.spell.Spell;
|
import electroblob.wizardry.spell.Spell;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.BlockCactus;
|
import net.minecraft.block.BlockCactus;
|
||||||
|
import net.minecraft.block.BlockChest;
|
||||||
import net.minecraft.block.BlockLog;
|
import net.minecraft.block.BlockLog;
|
||||||
import net.minecraft.block.properties.IProperty;
|
import net.minecraft.block.properties.IProperty;
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
@@ -39,7 +40,6 @@ import javax.annotation.Nullable;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.function.BiPredicate;
|
import java.util.function.BiPredicate;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <i>"Where do you put random but useful bits and pieces? {@code WizardryUtilities} of course - the 'stuff that doesn't
|
* <i>"Where do you put random but useful bits and pieces? {@code WizardryUtilities} of course - the 'stuff that doesn't
|
||||||
@@ -307,6 +307,29 @@ public final class WizardryUtilities {
|
|||||||
|| Settings.containsMetaBlock(Wizardry.settings.treeBlocks, world.getBlockState(pos));
|
|| Settings.containsMetaBlock(Wizardry.settings.treeBlocks, world.getBlockState(pos));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Given the position of one half of a double chest, returns the position of the other half of that double chest.
|
||||||
|
* @param world The world in which the chest is located
|
||||||
|
* @param pos The position of one half of the double chest
|
||||||
|
* @return The position of the other half of the double chest, or null if the given position is not part of a
|
||||||
|
* double chest.
|
||||||
|
*/
|
||||||
|
public static BlockPos getConnectedChest(World world, BlockPos pos){
|
||||||
|
|
||||||
|
Block block = world.getBlockState(pos).getBlock();
|
||||||
|
|
||||||
|
if(block instanceof BlockChest){
|
||||||
|
for(EnumFacing enumfacing : EnumFacing.Plane.HORIZONTAL){
|
||||||
|
BlockPos pos1 = pos.offset(enumfacing);
|
||||||
|
if(world.getBlockState(pos1).getBlock() == block){
|
||||||
|
return pos1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds the nearest floor level in the given direction from the given position,
|
* Finds the nearest floor level in the given direction from the given position,
|
||||||
* within the range specified. This is a shorthand for
|
* within the range specified. This is a shorthand for
|
||||||
|
|||||||
Reference in New Issue
Block a user