package com.yolp900.itsjustacharm.common.events; import com.yolp900.itsjustacharm.api.IJCConstants; import com.yolp900.itsjustacharm.common.avchievemetns.ModAchievements; import com.yolp900.itsjustacharm.common.blocks.ModBlocks; import com.yolp900.itsjustacharm.util.NBTHelper; import com.yolp900.itsjustacharm.common.network.*; import com.yolp900.itsjustacharm.reference.LibParticles; import com.yolp900.itsjustacharm.reference.LibSounds; import com.yolp900.itsjustacharm.reference.LibTexts; import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.item.ItemStack; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraftforge.event.entity.player.PlayerInteractEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import java.util.Random; public class EventConstructionTableConstruction { private static Random rand = new Random(); @SubscribeEvent public void onConstructionTableConstruction(PlayerInteractEvent.RightClickBlock event) { EntityPlayer player = event.getEntityPlayer(); ItemStack heldItem = event.getItemStack(); World world = event.getWorld(); BlockPos pos = event.getPos(); Block block = world.getBlockState(pos).getBlock(); Block blockN = world.getBlockState(pos.north()).getBlock(); Block blockS = world.getBlockState(pos.south()).getBlock(); Block blockW = world.getBlockState(pos.west()).getBlock(); Block blockE = world.getBlockState(pos.east()).getBlock(); if (!world.isRemote && block == Blocks.CRAFTING_TABLE && blockN == Blocks.COBBLESTONE && blockS == Blocks.COBBLESTONE && blockW == Blocks.COBBLESTONE && blockE == Blocks.COBBLESTONE && heldItem != null && heldItem.getItem() == Items.STICK && player.isSneaking()) { player.addStat(ModAchievements.ConstructionTableConstruction.getAchievement()); world.setBlockToAir(pos.north()); world.setBlockToAir(pos.south()); world.setBlockToAir(pos.west()); world.setBlockToAir(pos.east()); world.setBlockState(pos, ModBlocks.ConstructionTable.getDefaultState()); double x = pos.getX() + 0.5; double y = pos.getY() + 0.5; double z = pos.getZ() + 0.5; int num = rand.nextInt(64) + 64; for (int i = 0; i < num; i++) { NetworkHandler.sendToAllAround(new MessageParticle(LibParticles.ConstructionTableConstruction, x, y, z, -1 + rand.nextDouble() * 2, -1 + rand.nextDouble() * 2, -1 + rand.nextDouble() * 2), player.dimension, x, y, z, 16); } NetworkHandler.sendToAllAround(new MessageSound(LibSounds.ConstructionTableConstruction, x, y, z, 1, 1), player.dimension, x, y, z, 16); if (NBTHelper.getInt(player, IJCConstants.NBT.PlayerProgression.KEY) == IJCConstants.NBT.PlayerProgression.NONE.getID()) { NetworkHandler.sendTo(new MessageChatMessage(LibTexts.ChatMessages.JourneyBegun), (EntityPlayerMP)player); NBTHelper.setInt(player, IJCConstants.NBT.PlayerProgression.KEY, IJCConstants.NBT.PlayerProgression.FIRST_STEPS.getID()); } } } }