Search in sources :

Example 1 with TileEntityRuneBase

use of lumien.randomthings.tileentity.TileEntityRuneBase in project Random-Things by lumien231.

the class BlockRuneBase method onBlockClicked.

@Override
public void onBlockClicked(World worldIn, BlockPos pos, EntityPlayer playerIn) {
    if (!worldIn.isRemote) {
        Vec3d start = playerIn.getPositionEyes(0);
        RayTraceResult result = worldIn.rayTraceBlocks(start, start.add(playerIn.getLookVec().scale(6)), false, true, false);
        if (result != null && result.typeOfHit == RayTraceResult.Type.BLOCK) {
            BlockPos hitPos = result.getBlockPos();
            if (hitPos.equals(pos)) {
                Vec3d hitVec = result.hitVec.subtract(new Vec3d(pos));
                TileEntityRuneBase te = (TileEntityRuneBase) worldIn.getTileEntity(pos);
                int[][] runeData = te.getRuneData();
                int x = (int) Math.floor(hitVec.x * 4);
                int y = (int) Math.floor(hitVec.z * 4);
                if (runeData[x][y] != -1) {
                    EntityItem entityitem = new EntityItem(worldIn, pos.getX() + hitVec.x, pos.getY() + 0.1, pos.getZ() + hitVec.z, new ItemStack(ModItems.runeDust, 1, runeData[x][y]));
                    entityitem.setNoPickupDelay();
                    worldIn.spawnEntity(entityitem);
                    runeData[x][y] = -1;
                    te.syncTE();
                    worldIn.playSound(null, pos, SoundEvents.BLOCK_STONE_BREAK, SoundCategory.BLOCKS, 1F, 0.8F);
                    boolean empty = true;
                    for (x = 0; x < runeData.length; x++) {
                        for (y = 0; y < runeData[0].length; y++) {
                            int rune = runeData[x][y];
                            if (rune != -1) {
                                empty = false;
                                break;
                            }
                        }
                        if (!empty) {
                            break;
                        }
                    }
                    if (empty) {
                        worldIn.setBlockToAir(pos);
                    }
                }
            }
        }
    }
    super.onBlockClicked(worldIn, pos, playerIn);
}
Also used : RayTraceResult(net.minecraft.util.math.RayTraceResult) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) Vec3d(net.minecraft.util.math.Vec3d) TileEntityRuneBase(lumien.randomthings.tileentity.TileEntityRuneBase) EntityItem(net.minecraft.entity.item.EntityItem)

Example 2 with TileEntityRuneBase

use of lumien.randomthings.tileentity.TileEntityRuneBase in project Random-Things by lumien231.

the class BlockRuneBase method breakBlock.

@Override
public void breakBlock(World worldIn, BlockPos pos, IBlockState state) {
    TileEntity te = worldIn.getTileEntity(pos);
    if (te instanceof TileEntityRuneBase) {
        TileEntityRuneBase runeTE = (TileEntityRuneBase) te;
        int[][] runeData = runeTE.getRuneData();
        for (int x = 0; x < runeData.length; x++) {
            for (int y = 0; y < runeData[0].length; y++) {
                int rune = runeData[x][y];
                if (rune != -1) {
                    ItemStack dustStack = new ItemStack(ModItems.runeDust, 1, rune);
                    EntityItem entityitem = new EntityItem(worldIn, (double) pos.getX() + x / 4F, pos.getY() + 0.1, (double) pos.getZ() + y / 4F, dustStack);
                    entityitem.setNoPickupDelay();
                    worldIn.spawnEntity(entityitem);
                }
            }
        }
    }
    super.breakBlock(worldIn, pos, state);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ItemStack(net.minecraft.item.ItemStack) TileEntityRuneBase(lumien.randomthings.tileentity.TileEntityRuneBase) EntityItem(net.minecraft.entity.item.EntityItem)

Example 3 with TileEntityRuneBase

use of lumien.randomthings.tileentity.TileEntityRuneBase in project Random-Things by lumien231.

the class BlockRuneBase method getExtendedState.

@Override
public IBlockState getExtendedState(IBlockState state, IBlockAccess worldIn, BlockPos pos) {
    TileEntityRuneBase te = (TileEntityRuneBase) worldIn.getTileEntity(pos);
    IExtendedBlockState actualState = (IExtendedBlockState) state;
    if (te != null) {
        boolean[] connectionData = new boolean[16];
        int[][] runeData = te.getRuneData();
        for (EnumFacing facing : EnumFacing.HORIZONTALS) {
            BlockPos mod = pos.offset(facing);
            TileEntity otherTE = worldIn.getTileEntity(mod);
            if (otherTE instanceof TileEntityRuneBase) {
                TileEntityRuneBase otherRune = (TileEntityRuneBase) otherTE;
                int[][] otherRuneData = otherRune.getRuneData();
                for (int i = 0; i < 4; i++) {
                    if (facing == EnumFacing.NORTH) {
                        connectionData[i] = runeData[i][0] == otherRuneData[i][3];
                    } else if (facing == EnumFacing.EAST) {
                        connectionData[i + 4] = runeData[3][i] == otherRuneData[0][i];
                    } else if (facing == EnumFacing.SOUTH) {
                        connectionData[i + 8] = runeData[i][3] == otherRuneData[i][0];
                    } else if (facing == EnumFacing.WEST) {
                        connectionData[i + 12] = runeData[0][i] == otherRuneData[3][i];
                    }
                }
            }
        }
        return actualState.withProperty(RUNE_DATA, runeData).withProperty(CONNECTION_DATA, connectionData);
    } else {
        return actualState.withProperty(RUNE_DATA, new int[4][4]);
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IExtendedBlockState(net.minecraftforge.common.property.IExtendedBlockState) EnumFacing(net.minecraft.util.EnumFacing) BlockPos(net.minecraft.util.math.BlockPos) TileEntityRuneBase(lumien.randomthings.tileentity.TileEntityRuneBase)

Example 4 with TileEntityRuneBase

use of lumien.randomthings.tileentity.TileEntityRuneBase in project Random-Things by lumien231.

the class RTEventHandler method playerInteract.

@SubscribeEvent
public void playerInteract(PlayerInteractEvent event) {
    if (event instanceof RightClickBlock) {
        ItemStack equipped = event.getEntityPlayer().getHeldItem(event.getHand());
        if (!equipped.isEmpty() && equipped.getItem() instanceof ItemSpade) {
            RightClickBlock rcEvent = (RightClickBlock) event;
            IBlockState targetState = event.getWorld().getBlockState(event.getPos());
            if (targetState.getBlock() == Blocks.SLIME_BLOCK) {
                event.getEntityPlayer().swingArm(event.getHand());
                if (!event.getWorld().isRemote) {
                    if (!event.getWorld().isRemote) {
                        event.getWorld().setBlockState(event.getPos(), ModBlocks.compressedSlimeBlock.getDefaultState());
                        event.getWorld().playSound(null, event.getPos().getX(), event.getPos().getY(), event.getPos().getZ(), Blocks.SLIME_BLOCK.getSoundType().getPlaceSound(), SoundCategory.PLAYERS, 1, 0.8f);
                        equipped.damageItem(1, event.getEntityPlayer());
                    }
                }
            } else if (targetState.getBlock() == ModBlocks.compressedSlimeBlock) {
                int currentCompression = targetState.getValue(BlockCompressedSlimeBlock.COMPRESSION);
                event.getEntityPlayer().swingArm(event.getHand());
                if (!event.getWorld().isRemote) {
                    if (currentCompression < 2) {
                        rcEvent.getWorld().setBlockState(rcEvent.getPos(), targetState.withProperty(BlockCompressedSlimeBlock.COMPRESSION, currentCompression + 1));
                        event.getWorld().playSound(null, event.getPos().getX(), event.getPos().getY(), event.getPos().getZ(), Blocks.SLIME_BLOCK.getSoundType().getPlaceSound(), SoundCategory.PLAYERS, 1, 0.8f - ((currentCompression + 1) * 0.2f));
                        equipped.damageItem(1, event.getEntityPlayer());
                    }
                }
            }
        }
        if (!event.getWorld().isRemote && !equipped.isEmpty() && equipped.getItem() == Items.PAPER) {
            RightClickBlock rcEvent = (RightClickBlock) event;
            IBlockState targetState = event.getWorld().getBlockState(event.getPos());
            if (targetState.getBlock() == ModBlocks.runeBase) {
                TileEntityRuneBase te = (TileEntityRuneBase) event.getWorld().getTileEntity(rcEvent.getPos());
                int[][] runeData = te.getRuneData();
                int[] savedData = new int[16];
                int counter = 0;
                for (int y = 0; y < runeData[0].length; y++) {
                    for (int x = 0; x < runeData.length; x++) {
                        savedData[counter] = runeData[x][y];
                        counter++;
                    }
                }
                ItemStack patternStack = new ItemStack(ModItems.runePattern);
                patternStack.setTagCompound(new NBTTagCompound());
                patternStack.getTagCompound().setIntArray("runeData", savedData);
                ((RightClickBlock) event).setUseItem(Result.ALLOW);
                if (equipped.getCount() == 1) {
                    int slot;
                    if (event.getHand() == EnumHand.MAIN_HAND) {
                        slot = event.getEntityPlayer().inventory.currentItem;
                    } else {
                        slot = 40;
                    }
                    event.getEntityPlayer().inventory.setInventorySlotContents(slot, patternStack);
                } else {
                    equipped.shrink(1);
                    event.getEntityPlayer().inventory.addItemStackToInventory(patternStack);
                }
            }
        }
        if (!event.getWorld().isRemote && event.getHand() == EnumHand.MAIN_HAND) {
            for (EnumFacing facing : EnumFacing.values()) {
                BlockPos pos = event.getPos().offset(facing);
                IBlockState state = event.getWorld().getBlockState(pos);
                if (state.getBlock() == ModBlocks.contactButton) {
                    if (state.getValue(BlockContactButton.FACING).getOpposite() == facing) {
                        ((BlockContactButton) state.getBlock()).activate(event.getWorld(), event.getPos().offset(facing), facing.getOpposite());
                        break;
                    }
                } else if (state.getBlock() == ModBlocks.contactLever) {
                    if (state.getValue(BlockContactLever.FACING).getOpposite() == facing) {
                        ((BlockContactLever) state.getBlock()).activate(event.getWorld(), event.getPos().offset(facing), facing.getOpposite());
                        break;
                    }
                }
            }
        }
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) ItemSpade(net.minecraft.item.ItemSpade) EnumFacing(net.minecraft.util.EnumFacing) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) BlockContactButton(lumien.randomthings.block.BlockContactButton) BlockPos(net.minecraft.util.math.BlockPos) RightClickBlock(net.minecraftforge.event.entity.player.PlayerInteractEvent.RightClickBlock) ItemStack(net.minecraft.item.ItemStack) TileEntityRuneBase(lumien.randomthings.tileentity.TileEntityRuneBase) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 5 with TileEntityRuneBase

use of lumien.randomthings.tileentity.TileEntityRuneBase in project Random-Things by lumien231.

the class ItemRuneDust method onItemUse.

@Override
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    if (!worldIn.isRemote && facing == EnumFacing.UP) {
        ItemStack me = player.getHeldItem(hand);
        IBlockState targetState = worldIn.getBlockState(pos);
        TileEntityRuneBase te = null;
        if (targetState.getBlock() == ModBlocks.runeBase) {
            te = (TileEntityRuneBase) worldIn.getTileEntity(pos);
        } else {
            if (targetState.isSideSolid(worldIn, pos, EnumFacing.UP)) {
                BlockPos replacePos = pos.offset(facing);
                IBlockState toReplace = worldIn.getBlockState(replacePos);
                if (toReplace.getBlock().isAir(toReplace, worldIn, replacePos) || toReplace.getBlock().isReplaceable(worldIn, replacePos)) {
                    worldIn.setBlockState(replacePos, ModBlocks.runeBase.getDefaultState());
                    te = (TileEntityRuneBase) worldIn.getTileEntity(replacePos);
                }
            }
        }
        if (te != null) {
            int[][] runeData = te.getRuneData();
            int x = (int) Math.floor(hitX * 4);
            int y = (int) Math.floor(hitZ * 4);
            if (runeData[x][y] == -1) {
                runeData[x][y] = me.getItemDamage();
                te.syncTE();
                if (!player.capabilities.isCreativeMode) {
                    me.shrink(1);
                }
                return EnumActionResult.SUCCESS;
            }
        }
    }
    return super.onItemUse(player, worldIn, pos, hand, facing, hitX, hitY, hitZ);
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) TileEntityRuneBase(lumien.randomthings.tileentity.TileEntityRuneBase)

Aggregations

TileEntityRuneBase (lumien.randomthings.tileentity.TileEntityRuneBase)6 ItemStack (net.minecraft.item.ItemStack)5 BlockPos (net.minecraft.util.math.BlockPos)4 IBlockState (net.minecraft.block.state.IBlockState)3 EntityItem (net.minecraft.entity.item.EntityItem)2 TileEntity (net.minecraft.tileentity.TileEntity)2 EnumFacing (net.minecraft.util.EnumFacing)2 BlockContactButton (lumien.randomthings.block.BlockContactButton)1 ItemSpade (net.minecraft.item.ItemSpade)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 RayTraceResult (net.minecraft.util.math.RayTraceResult)1 Vec3d (net.minecraft.util.math.Vec3d)1 IExtendedBlockState (net.minecraftforge.common.property.IExtendedBlockState)1 RightClickBlock (net.minecraftforge.event.entity.player.PlayerInteractEvent.RightClickBlock)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1