diff --git a/gradle.properties b/gradle.properties index d772120..a91b3f6 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,22 +5,23 @@ cleanroom_version=15.24.0.3029 # Mod Information # HIGHLY RECOMMEND complying with SemVer for mod_version: https://semver.org/ mod_version=1.0.0 -root_package=com.example -mod_id=modid +root_package=com.somebody.idlframewok +mod_id=idlframewok mod_name=Mod Name # Mod Metadata (Optional) mod_description= -mod_url= +mod_url=https://www.mcmod.cn/class/2421.html mod_update_json= # Delimit authors with commas -mod_authors= -mod_credits= +mod_authors=somebody +mod_credits=Idealland - they provided this framework. mod_logo_path= # Mapping Properties -mapping_channel= stable -mapping_version= 39-1.12 +mapping_channel= snapshot +mapping_version= 20171003 + # If any properties changes below this line, refresh gradle again to ensure everything is working correctly. diff --git a/src/main/java/com/somebody/idlframewok/IdlFramework.java b/src/main/java/com/somebody/idlframewok/IdlFramework.java new file mode 100644 index 0000000..b824ae8 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/IdlFramework.java @@ -0,0 +1,150 @@ +package com.somebody.idlframewok; + +import com.somebody.idlframewok.gui.ModGuiElementLoader; +import com.somebody.idlframewok.init.ModConfig; +import com.somebody.idlframewok.init.ModRecipes; +import com.somebody.idlframewok.init.ModSpawn; +import com.somebody.idlframewok.init.RegistryHandler; +import com.somebody.idlframewok.keys.KeyboardManager; +import com.somebody.idlframewok.meta.MetaUtil; +import com.somebody.idlframewok.network.NetworkHandler; +import com.somebody.idlframewok.proxy.ProxyBase; +import com.somebody.idlframewok.util.CommonDef; +import com.somebody.idlframewok.util.Reference; +import net.minecraftforge.fml.common.Loader; +import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.common.Mod.EventHandler; +import net.minecraftforge.fml.common.SidedProxy; +import net.minecraftforge.fml.common.event.FMLInitializationEvent; +import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; +import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; +import net.minecraftforge.fml.common.event.FMLServerStartingEvent; +import org.apache.logging.log4j.Logger; + +//To let the player be a traveling god who plays yin-yang magic. + +@Mod(modid = IdlFramework.MODID, name = IdlFramework.NAME, version = IdlFramework.VERSION)//dependencies = "required-after:Forge@[14.23.5.2705,)" +public class IdlFramework { + public static final String MODID = "untitled"; + public static final String NAME = "IdlFramework"; + public static final String VERSION = "0.1.101"; + + public static Logger logger; + + public static final boolean SHOW_WARN = true; + + @Mod.Instance + public static IdlFramework instance; + + @SidedProxy(clientSide = Reference.CLIENT_PROXY_CLASS, serverSide = Reference.SERVER_PROXY_CLASS) + public static ProxyBase proxy; + + @EventHandler + public void preInit(FMLPreInitializationEvent event) { + logger = event.getModLog(); + + if (MODID.equals("untitled")) + { + logger.error("Please change your mod id in the main class."); + + } + + if (Reference.CLIENT_PROXY_CLASS.indexOf("somebody.idlframewok.proxy.ClientProxy") > 0) + { + logger.warn("Have you changed your package name to author and modname?"); + + } + + RegistryHandler.preInitRegistries(event); + + } + + @EventHandler + public static void Init(FMLInitializationEvent event) { + ModRecipes.Init(); + RegisterTileEntity(); + RegistryHandler.initRegistries(event); + new ModGuiElementLoader(); + if (!proxy.isServer()) + { + KeyboardManager.init(); + } + NetworkHandler.init(); + + LogWarning("%s has finished its initializations", MODID); + + } + + @EventHandler + public void postInit(FMLPostInitializationEvent event) { + // Moved Spawning registry to last since forge doesn't auto-generate sub + // "M' biomes until late + if (ModConfig.SPAWN_CONF.SPAWN) { + ModSpawn.registerSpawnList(); + } + + MetaUtil.isIDLLoaded = Loader.isModLoaded("idealland"); + MetaUtil.isIRRLoaded = Loader.isModLoaded("itemrender"); + MetaUtil.isLoaded_TiC = Loader.isModLoaded("tconstruct"); + MetaUtil.isLoaded_Slashblade = Loader.isModLoaded("flammpfeil.slashblade"); + MetaUtil.isLoaded_Botania = Loader.isModLoaded("botania"); + MetaUtil.isLoaded_DWeapon = Loader.isModLoaded("dweapon"); + MetaUtil.isLoaded_AOA3 = Loader.isModLoaded(CommonDef.MOD_NAME_AOA3); + MetaUtil.isLoaded_GC = Loader.isModLoaded("galacticraftcore"); + MetaUtil.isLoaded_Taoism = Loader.isModLoaded("taoism"); + MetaUtil.isLoaded_GOG = Loader.isModLoaded(CommonDef.MOD_NAME_GOG); + + TrashTalking(); + + RegistryHandler.postInitReg(); + } + + @EventHandler + public static void serverInit(FMLServerStartingEvent event) { + RegistryHandler.serverRegistries(event); + } + + + private void TrashTalking() { + if (MetaUtil.isIDLLoaded) + { + IdlFramework.Log("[Idealland Framework] Bow to Idealland."); + } + else { + IdlFramework.Log("[Idealland Framework] Made with Idealland Framework."); + } + } + + private static void RegisterTileEntity() { +// GameRegistry.registerTileEntity(TileEntityDeBoomOrb.class, new ResourceLocation(MODID, "deboom_orb_basic")); + + //GameRegistry.registerTileEntity(TileEntityBuilderFarm.class, new ResourceLocation(MODID, "builder_farm_basic")); + //GameRegistry.registerTileEntity(TileEntityBuilderOne.class, new ResourceLocation(MODID, "builder.builder_one")); + } + + public static void LogWarning(String str, Object... args) { + if (SHOW_WARN) { + logger.warn(String.format(str, args)); + } + } + + public static void LogWarning(String str) { + if (SHOW_WARN) { + logger.warn(str); + } + } + + public static void Log(String str) { +// if (ModConfig.GeneralConf.LOG_ON) +// { + logger.info(str); +// } + } + + public static void Log(String str, Object... args) { +// if (ModConfig.GeneralConf.LOG_ON) +// { + logger.info(String.format(str, args)); +// } + } +} \ No newline at end of file diff --git a/src/main/java/com/somebody/idlframewok/TODO.txt b/src/main/java/com/somebody/idlframewok/TODO.txt new file mode 100644 index 0000000..f930f04 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/TODO.txt @@ -0,0 +1,15 @@ +plans: +buff: +[shield A]: absorbs damage. for each damage absorbed, -1s. +[shield B]: (Darker Protection) absorbs damage, revenges attacker, try create explosion +[Explosion Proof] +[Arrow Proof]* only arrows, or other bullets +[melee proof] +[nullified/phased]deal and receive no melee damage + +[void touch]all damage is void damage. + +[Berserk]Damage dealt and receive is increaed by Lv * 10% +--crtical +[Crit% Up/Down] +[Crit% Dmg Up/Down] \ No newline at end of file diff --git a/src/main/java/com/somebody/idlframewok/blocks/BlockBase.java b/src/main/java/com/somebody/idlframewok/blocks/BlockBase.java new file mode 100644 index 0000000..b6491a6 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/blocks/BlockBase.java @@ -0,0 +1,49 @@ +package com.somebody.idlframewok.blocks; + +import java.util.Random; + +import com.somebody.idlframewok.IdlFramework; +import com.somebody.idlframewok.init.ModCreativeTab; +import com.somebody.idlframewok.item.ModItems; +import com.somebody.idlframewok.util.IHasModel; +import net.minecraft.block.Block; +import net.minecraft.block.material.Material; +import net.minecraft.block.state.IBlockState; +import net.minecraft.item.Item; +import net.minecraft.item.ItemBlock; + +public class BlockBase extends Block implements IHasModel +{ + public BlockBase(String name, Material material) + { + super(material); + setUnlocalizedName(name); + setRegistryName(name); + setCreativeTab(ModCreativeTab.IDL_MISC);; + + ModBlocks.BLOCKS.add(this); + ModItems.ITEMS.add(new ItemBlock(this).setRegistryName(this.getRegistryName())); + + setHardness(5.0F); + //setResistance(1000.0F); + //setHarvestLevel("pickaxe", 1); + //setLightLevel(1f); + setLightOpacity(1); + } + + @Override + public Item getItemDropped(IBlockState state, Random rand, int fortune) + { + return super.getItemDropped(state, rand, fortune); + } + + @Override + public int quantityDropped(Random rand) { + return super.quantityDropped(rand); + } + + @Override + public void registerModels() { + IdlFramework.proxy.registerItemRenderer(Item.getItemFromBlock(this), 0, "inventory"); + } +} diff --git a/src/main/java/com/somebody/idlframewok/blocks/BlockTeleporter.java b/src/main/java/com/somebody/idlframewok/blocks/BlockTeleporter.java new file mode 100644 index 0000000..cb8b127 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/blocks/BlockTeleporter.java @@ -0,0 +1,26 @@ +package com.somebody.idlframewok.blocks; + +import net.minecraft.block.material.Material; +import net.minecraft.block.state.IBlockState; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.EnumHand; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; + +public class BlockTeleporter extends BlockBase { + public BlockTeleporter(String name, Material material) { + super(name, material); + } + + @Override + public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { + if (!worldIn.isRemote) { +// Teleport.teleportToDim(playerIn, ModConfig.DEBUG_CONF.DIM_ONE_ID, playerIn.getPosition().getX(), +// playerIn.posY + 5, playerIn.posZ); + return true; + } + + return false; + } +} diff --git a/src/main/java/com/somebody/idlframewok/blocks/Furnitures/BlockExtractionDoorTest.java b/src/main/java/com/somebody/idlframewok/blocks/Furnitures/BlockExtractionDoorTest.java new file mode 100644 index 0000000..95bbc64 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/blocks/Furnitures/BlockExtractionDoorTest.java @@ -0,0 +1,514 @@ +package com.somebody.idlframewok.blocks.Furnitures; + +import java.util.Random; +import javax.annotation.Nullable; + +import com.somebody.idlframewok.blocks.BlockBase; +import com.somebody.idlframewok.init.ModCreativeTab; +import net.minecraft.block.Block; +import net.minecraft.block.SoundType; +import net.minecraft.block.material.Material; +import net.minecraft.block.properties.PropertyBool; +import net.minecraft.block.properties.PropertyEnum; +import net.minecraft.block.state.BlockStateContainer; +import net.minecraft.block.state.IBlockState; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.SoundEvents; +import net.minecraft.item.Item; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.EnumHand; +import net.minecraft.util.IStringSerializable; +import net.minecraft.util.Mirror; +import net.minecraft.util.Rotation; +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; + +public class BlockExtractionDoorTest extends BlockBase { + public BlockExtractionDoorTest(String name, Material material) + { + super(name, material); + setSoundType(SoundType.STONE); + setHardness(5.0F); + setResistance(35.0F); + setLightOpacity(1); + + this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, BlockExtractionDoorTest.EnumOrientation.NORTH).withProperty(POWERED, Boolean.valueOf(false))); + this.setCreativeTab(ModCreativeTab.IDL_MISC); + } + + public static final PropertyEnum FACING = PropertyEnum.create("facing", BlockExtractionDoorTest.EnumOrientation.class); + public static final PropertyBool POWERED = PropertyBool.create("powered"); + protected static final AxisAlignedBB LEVER_NORTH_AABB = new AxisAlignedBB(0D,0D,0D,1D,1D,1D); + protected static final AxisAlignedBB LEVER_SOUTH_AABB = new AxisAlignedBB(0D,0D,0D,1D,1D,1D); + protected static final AxisAlignedBB LEVER_WEST_AABB = new AxisAlignedBB(0D,0D,0D,1D,1D,1D); + protected static final AxisAlignedBB LEVER_EAST_AABB = new AxisAlignedBB(0D,0D,0D,1D,1D,1D); + protected static final AxisAlignedBB LEVER_UP_AABB = new AxisAlignedBB(0D,0D,0D,1D,1D,1D); + protected static final AxisAlignedBB LEVER_DOWN_AABB = new AxisAlignedBB(0D,0D,0D,1D,1D,1D); + + protected static final AxisAlignedBB OPENED_LEVER_NORTH_AABB = new AxisAlignedBB(0D,0D,0D,1D,1D,1D); + protected static final AxisAlignedBB OPENED_LEVER_SOUTH_AABB = new AxisAlignedBB(0D,0D,0D,1D,1D,1D); + protected static final AxisAlignedBB OPENED_LEVER_WEST_AABB = new AxisAlignedBB(0D,0D,0D,1D,1D,1D); + protected static final AxisAlignedBB OPENED_LEVER_EAST_AABB = new AxisAlignedBB(0D,0D,0D,1D,1D,1D); + protected static final AxisAlignedBB OPENED_LEVER_UP_AABB = new AxisAlignedBB(0D,0D,0D,1D,1D,1D); + protected static final AxisAlignedBB OPENED_LEVER_DOWN_AABB = new AxisAlignedBB(0D,0D,0D,1D,1D,1D); + + + @Deprecated + @Nullable + public AxisAlignedBB getCollisionBoundingBox(IBlockState blockState, IBlockAccess worldIn, BlockPos pos) + { + if (blockState.getValue(POWERED)) { + return null; + } + else + { + return blockState.getBoundingBox(worldIn, pos); + } + } + + /** + * Used to determine ambient occlusion and culling when rebuilding chunks for render + */ + public boolean isOpaqueCube(IBlockState state) + { + return !state.getValue(POWERED); + } + + public boolean isFullCube(IBlockState state) + { + return !state.getValue(POWERED); + } + + public boolean causesSuffocation(IBlockState state) + { + return false; + } + + /** + * Check whether this Block can be placed at pos, while aiming at the specified side of an adjacent block + */ + public boolean canPlaceBlockOnSide(World worldIn, BlockPos pos, EnumFacing side) + { + return canAttachTo(worldIn, pos, side); + } + + /** + * Checks if this block can be placed exactly at the given position. + */ + public boolean canPlaceBlockAt(World worldIn, BlockPos pos) + { + for (EnumFacing enumfacing : EnumFacing.values()) + { + if (canAttachTo(worldIn, pos, enumfacing)) + { + return true; + } + } + + return false; + } + + protected static boolean canAttachTo(World worldIn, BlockPos p_181090_1_, EnumFacing p_181090_2_) + { + return true; + } + + /** + * Called by ItemBlocks just before a block is actually set in the world, to allow for adjustments to the + * IBlockstate + */ + public IBlockState getStateForPlacement(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer) + { + IBlockState iblockstate = this.getDefaultState().withProperty(POWERED, Boolean.valueOf(false)); + + if (canAttachTo(worldIn, pos, facing)) + { + return iblockstate.withProperty(FACING, BlockExtractionDoorTest.EnumOrientation.forFacings(facing, placer.getHorizontalFacing())); + } + else + { + for (EnumFacing enumfacing : EnumFacing.Plane.HORIZONTAL) + { + if (enumfacing != facing && canAttachTo(worldIn, pos, enumfacing)) + { + return iblockstate.withProperty(FACING, BlockExtractionDoorTest.EnumOrientation.forFacings(enumfacing, placer.getHorizontalFacing())); + } + } + + if (worldIn.getBlockState(pos.down()).isTopSolid()) + { + return iblockstate.withProperty(FACING, BlockExtractionDoorTest.EnumOrientation.forFacings(EnumFacing.UP, placer.getHorizontalFacing())); + } + else + { + return iblockstate; + } + } + } + + /** + * Called when a neighboring block was changed and marks that this state should perform any checks during a neighbor + * change. Cases may include when redstone power is updated, cactus blocks popping off due to a neighboring solid + * block, etc. + */ + public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos) + { + if (this.checkCanSurvive(worldIn, pos, state) && !canAttachTo(worldIn, pos, state.getValue(FACING).getFacing())) + { + this.dropBlockAsItem(worldIn, pos, state, 0); + worldIn.setBlockToAir(pos); + } + } + + private boolean checkCanSurvive(World worldIn, BlockPos pos, IBlockState state) + { + if (this.canPlaceBlockAt(worldIn, pos)) + { + return true; + } + else + { + this.dropBlockAsItem(worldIn, pos, state, 0); + worldIn.setBlockToAir(pos); + return false; + } + } + + public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) + { + switch (state.getValue(FACING)) + { + case EAST: + default: + return LEVER_EAST_AABB; + case WEST: + return LEVER_WEST_AABB; + case SOUTH: + return LEVER_SOUTH_AABB; + case NORTH: + return LEVER_NORTH_AABB; + case UP_Z: + case UP_X: + return LEVER_UP_AABB; + case DOWN_X: + case DOWN_Z: + return LEVER_DOWN_AABB; + } + } + + /** + * Called when the block is right clicked by a player. + */ + public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) + { + if (worldIn.isRemote) + { + return true; + } + else + { + Toggle(worldIn, state, pos); + float f = state.getValue(POWERED) ? 0.6F : 0.5F; + worldIn.playSound(null, pos, SoundEvents.BLOCK_LEVER_CLICK, SoundCategory.BLOCKS, 0.3F, f); + + OnNotifySync(worldIn, pos.add(1,0,0), !state.getValue(POWERED)); + OnNotifySync(worldIn, pos.add(-1,0,0), !state.getValue(POWERED)); + OnNotifySync(worldIn, pos.add(0,1,0), !state.getValue(POWERED)); + OnNotifySync(worldIn, pos.add(0,-1,0), !state.getValue(POWERED)); + OnNotifySync(worldIn, pos.add(0,0,1), !state.getValue(POWERED)); + OnNotifySync(worldIn, pos.add(0,0,-1), !state.getValue(POWERED)); + return true; + } + } + + public void Toggle(World worldIn, IBlockState state,BlockPos pos) + { + state = state.cycleProperty(POWERED); + worldIn.setBlockState(pos, state, 3); + worldIn.notifyNeighborsOfStateChange(pos, this, false); + EnumFacing enumfacing = state.getValue(FACING).getFacing(); + worldIn.notifyNeighborsOfStateChange(pos.offset(enumfacing.getOpposite()), this, false); + } + + public static void OnNotifySync(World world, BlockPos pos, boolean toOpen) { + IBlockState block = world.getBlockState(pos); + + if (block.getBlock() instanceof BlockExtractionDoorTest) { + BlockExtractionDoorTest door = (BlockExtractionDoorTest)(block.getBlock()); + if (isOpened(block) != toOpen){ + door.Toggle(world, block, pos); + OnNotifySync(world, pos.add(1,0,0), !block.getValue(POWERED)); + OnNotifySync(world, pos.add(-1,0,0), !block.getValue(POWERED)); + OnNotifySync(world, pos.add(0,1,0), !block.getValue(POWERED)); + OnNotifySync(world, pos.add(0,-1,0), !block.getValue(POWERED)); + OnNotifySync(world, pos.add(0,0,1), !block.getValue(POWERED)); + OnNotifySync(world, pos.add(0,0,-1), !block.getValue(POWERED)); + } + } + } + + /** + * Called serverside after this block is replaced with another in Chunk, but before the Tile Entity is updated + */ + public void breakBlock(World worldIn, BlockPos pos, IBlockState state) + { + if (state.getValue(POWERED).booleanValue()) + { + worldIn.notifyNeighborsOfStateChange(pos, this, false); + EnumFacing enumfacing = state.getValue(FACING).getFacing(); + worldIn.notifyNeighborsOfStateChange(pos.offset(enumfacing.getOpposite()), this, false); + } + + super.breakBlock(worldIn, pos, state); + } + + /** + * Get the Item that this Block should drop when harvested. + */ + public Item getItemDropped(IBlockState state, Random rand, int fortune) + { + return Item.getItemFromBlock(this); + } + + /** + * Can this block provide power. Only wire currently seems to have this change based on its state. + */ + public boolean canProvidePower(IBlockState state) + { + return true; + } + + /** + * Convert the given metadata into a BlockState for this Block + */ + public IBlockState getStateFromMeta(int meta) + { + return this.getDefaultState().withProperty(FACING, BlockExtractionDoorTest.EnumOrientation.byMetadata(meta & 7)).withProperty(POWERED, Boolean.valueOf((meta & 8) > 0)); + } + + /** + * Convert the BlockState into the correct metadata value + */ + public int getMetaFromState(IBlockState state) + { + int i = 0; + i = i | state.getValue(FACING).getMetadata(); + + if (state.getValue(POWERED)) + { + i |= 8; + } + + return i; + } + + /** + * Returns the blockstate with the given rotation from the passed blockstate. If inapplicable, returns the passed + * blockstate. + */ + public IBlockState withRotation(IBlockState state, Rotation rot) + { + switch (rot) + { + case CLOCKWISE_180: + + switch (state.getValue(FACING)) + { + case EAST: + return state.withProperty(FACING, BlockExtractionDoorTest.EnumOrientation.WEST); + case WEST: + return state.withProperty(FACING, BlockExtractionDoorTest.EnumOrientation.EAST); + case SOUTH: + return state.withProperty(FACING, BlockExtractionDoorTest.EnumOrientation.NORTH); + case NORTH: + return state.withProperty(FACING, BlockExtractionDoorTest.EnumOrientation.SOUTH); + default: + return state; + } + + case COUNTERCLOCKWISE_90: + + switch (state.getValue(FACING)) + { + case EAST: + return state.withProperty(FACING, BlockExtractionDoorTest.EnumOrientation.NORTH); + case WEST: + return state.withProperty(FACING, BlockExtractionDoorTest.EnumOrientation.SOUTH); + case SOUTH: + return state.withProperty(FACING, BlockExtractionDoorTest.EnumOrientation.EAST); + case NORTH: + return state.withProperty(FACING, BlockExtractionDoorTest.EnumOrientation.WEST); + case UP_Z: + return state.withProperty(FACING, BlockExtractionDoorTest.EnumOrientation.UP_X); + case UP_X: + return state.withProperty(FACING, BlockExtractionDoorTest.EnumOrientation.UP_Z); + case DOWN_X: + return state.withProperty(FACING, BlockExtractionDoorTest.EnumOrientation.DOWN_Z); + case DOWN_Z: + return state.withProperty(FACING, BlockExtractionDoorTest.EnumOrientation.DOWN_X); + } + + case CLOCKWISE_90: + + switch (state.getValue(FACING)) + { + case EAST: + return state.withProperty(FACING, BlockExtractionDoorTest.EnumOrientation.SOUTH); + case WEST: + return state.withProperty(FACING, BlockExtractionDoorTest.EnumOrientation.NORTH); + case SOUTH: + return state.withProperty(FACING, BlockExtractionDoorTest.EnumOrientation.WEST); + case NORTH: + return state.withProperty(FACING, BlockExtractionDoorTest.EnumOrientation.EAST); + case UP_Z: + return state.withProperty(FACING, BlockExtractionDoorTest.EnumOrientation.UP_X); + case UP_X: + return state.withProperty(FACING, BlockExtractionDoorTest.EnumOrientation.UP_Z); + case DOWN_X: + return state.withProperty(FACING, BlockExtractionDoorTest.EnumOrientation.DOWN_Z); + case DOWN_Z: + return state.withProperty(FACING, BlockExtractionDoorTest.EnumOrientation.DOWN_X); + } + + default: + return state; + } + } + + /** + * Returns the blockstate with the given mirror of the passed blockstate. If inapplicable, returns the passed + * blockstate. + */ + public IBlockState withMirror(IBlockState state, Mirror mirrorIn) + { + return state.withRotation(mirrorIn.toRotation(state.getValue(FACING).getFacing())); + } + + protected BlockStateContainer createBlockState() + { + return new BlockStateContainer(this, FACING, POWERED); + } + + public boolean isPassable(IBlockAccess worldIn, BlockPos pos) + { + return isOpened(worldIn, pos); + } + + public static boolean isOpened(IBlockAccess worldIn, BlockPos pos) + { + return worldIn.getBlockState(pos).getValue(POWERED); + } + + public static boolean isOpened(IBlockState state) + { + return state.getValue(POWERED); + } + + public enum EnumOrientation implements IStringSerializable + { + DOWN_X(0, "down_x", EnumFacing.DOWN), + EAST(1, "east", EnumFacing.EAST), + WEST(2, "west", EnumFacing.WEST), + SOUTH(3, "south", EnumFacing.SOUTH), + NORTH(4, "north", EnumFacing.NORTH), + UP_Z(5, "up_z", EnumFacing.UP), + UP_X(6, "up_x", EnumFacing.UP), + DOWN_Z(7, "down_z", EnumFacing.DOWN); + + private static final BlockExtractionDoorTest.EnumOrientation[] META_LOOKUP = new BlockExtractionDoorTest.EnumOrientation[values().length]; + private final int meta; + private final String name; + private final EnumFacing facing; + + EnumOrientation(int meta, String name, EnumFacing facing) + { + this.meta = meta; + this.name = name; + this.facing = facing; + } + + public int getMetadata() + { + return this.meta; + } + + public EnumFacing getFacing() + { + return this.facing; + } + + public String toString() + { + return this.name; + } + + public static BlockExtractionDoorTest.EnumOrientation byMetadata(int meta) + { + if (meta < 0 || meta >= META_LOOKUP.length) + { + meta = 0; + } + + return META_LOOKUP[meta]; + } + + public static BlockExtractionDoorTest.EnumOrientation forFacings(EnumFacing clickedSide, EnumFacing entityFacing) + { + switch (clickedSide) + { + case DOWN: + + switch (entityFacing.getAxis()) + { + case X: + return DOWN_X; + case Z: + return DOWN_Z; + default: + throw new IllegalArgumentException("Invalid entityFacing " + entityFacing + " for facing " + clickedSide); + } + + case UP: + + switch (entityFacing.getAxis()) + { + case X: + return UP_X; + case Z: + return UP_Z; + default: + throw new IllegalArgumentException("Invalid entityFacing " + entityFacing + " for facing " + clickedSide); + } + + case NORTH: + return NORTH; + case SOUTH: + return SOUTH; + case WEST: + return WEST; + case EAST: + return EAST; + default: + throw new IllegalArgumentException("Invalid facing: " + clickedSide); + } + } + + public String getName() + { + return this.name; + } + + static + { + for (BlockExtractionDoorTest.EnumOrientation blocklever$enumorientation : values()) + { + META_LOOKUP[blocklever$enumorientation.getMetadata()] = blocklever$enumorientation; + } + } + } + +} diff --git a/src/main/java/com/somebody/idlframewok/blocks/ModBlocks.java b/src/main/java/com/somebody/idlframewok/blocks/ModBlocks.java new file mode 100644 index 0000000..7e52fb2 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/blocks/ModBlocks.java @@ -0,0 +1,20 @@ +package com.somebody.idlframewok.blocks; + +import java.util.ArrayList; +import java.util.List; + +import net.minecraft.block.Block; + +public class ModBlocks { + public static final List BLOCKS = new ArrayList(); + + /* + * To add a block, put a line here, + * -Create a json at assets.eo.blockstates + * -Create a json at assets.eo.models.block + * -Create a json at assets.eo.models.item + * -Add corresponding texture png + */ + + //public static final Block GRID_BLOCK_1 = new BlockBase("test", Material.CLAY).setCreativeTab(ModCreativeTab.IDL_MISC).setHardness(15f); +} diff --git a/src/main/java/com/somebody/idlframewok/blocks/blockBasic/BlockDeboomOrb.java b/src/main/java/com/somebody/idlframewok/blocks/blockBasic/BlockDeboomOrb.java new file mode 100644 index 0000000..180ce33 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/blocks/blockBasic/BlockDeboomOrb.java @@ -0,0 +1,56 @@ +package com.somebody.idlframewok.blocks.blockBasic; + +import java.util.Random; + +import com.somebody.idlframewok.blocks.BlockBase; +import com.somebody.idlframewok.blocks.tileEntity.orbs.TileEntityDeBoomOrb; +import com.somebody.idlframewok.init.ModCreativeTab; +import net.minecraft.block.ITileEntityProvider; +import net.minecraft.block.SoundType; +import net.minecraft.block.material.Material; +import net.minecraft.block.state.IBlockState; +import net.minecraft.item.Item; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; + +public class BlockDeboomOrb extends BlockBase implements ITileEntityProvider { + + public static final int NULLIFY_DISTANCE = 7; + + public BlockDeboomOrb(String name, Material material) { + super(name, material); + this.hasTileEntity = true; + setSoundType(SoundType.METAL); + setHardness(5.0F); + setResistance(1500.0F); + setHarvestLevel("pickaxe", 3); + setLightOpacity(1); + setCreativeTab(ModCreativeTab.IDL_MISC); + } + + //optional + @Override + public Item getItemDropped(IBlockState state, Random rand, int fortune) + { + return super.getItemDropped(state, rand, fortune); + } + + @Override + public int quantityDropped(Random rand) { +// int max = 4; +// int min = 1; +// return rand.nextInt(max) + min; + + return super.quantityDropped(rand); + } + + /** + * Returns a new instance of a block's tile entity class. Called on placing the block. + */ + public TileEntity createNewTileEntity(World worldIn, int meta) + { + return new TileEntityDeBoomOrb(); + } + + +} diff --git a/src/main/java/com/somebody/idlframewok/blocks/blockBasic/BlockGeneralOrb.java b/src/main/java/com/somebody/idlframewok/blocks/blockBasic/BlockGeneralOrb.java new file mode 100644 index 0000000..26f885b --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/blocks/blockBasic/BlockGeneralOrb.java @@ -0,0 +1,64 @@ +package com.somebody.idlframewok.blocks.blockBasic; + +import java.util.Random; + +import com.somebody.idlframewok.blocks.BlockBase; +import com.somebody.idlframewok.init.ModCreativeTab; +import net.minecraft.block.ITileEntityProvider; +import net.minecraft.block.SoundType; +import net.minecraft.block.material.Material; +import net.minecraft.block.state.IBlockState; +import net.minecraft.item.Item; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; + +public class BlockGeneralOrb extends BlockBase implements ITileEntityProvider { + + public Class tileEntity; + + public BlockGeneralOrb(String name, Material material, Class classEntity) { + super(name, material); + this.hasTileEntity = true; + this.tileEntity = classEntity; + setSoundType(SoundType.METAL); + setHardness(5.0F); + setResistance(1500.0F); + setHarvestLevel("pickaxe", 3); + setLightOpacity(1); + setCreativeTab(ModCreativeTab.IDL_MISC); + } + + //optional + @Override + public Item getItemDropped(IBlockState state, Random rand, int fortune) + { + return super.getItemDropped(state, rand, fortune); + } + + @Override + public int quantityDropped(Random rand) { +// int max = 4; +// int min = 1; +// return rand.nextInt(max) + min; + + return super.quantityDropped(rand); + } + + /** + * Returns a new instance of a block's tile entity class. Called on placing the block. + */ + public TileEntity createNewTileEntity(World worldIn, int meta) + { + try { + return tileEntity.newInstance(); + } catch (InstantiationException e) { + e.printStackTrace(); + return null; + } catch (IllegalAccessException e) { + e.printStackTrace(); + return null; + } + } + + +} diff --git a/src/main/java/com/somebody/idlframewok/blocks/blockBasic/BlockNullifyOrb.java b/src/main/java/com/somebody/idlframewok/blocks/blockBasic/BlockNullifyOrb.java new file mode 100644 index 0000000..68866d1 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/blocks/blockBasic/BlockNullifyOrb.java @@ -0,0 +1,64 @@ +package com.somebody.idlframewok.blocks.blockBasic; + +import java.util.Random; + +import com.somebody.idlframewok.blocks.BlockBase; +import com.somebody.idlframewok.blocks.tileEntity.orbs.TileEntityNullifyOrb; +import com.somebody.idlframewok.blocks.tileEntity.orbs.TileEntityNullifyOrbMor; +import com.somebody.idlframewok.init.ModCreativeTab; +import net.minecraft.block.ITileEntityProvider; +import net.minecraft.block.SoundType; +import net.minecraft.block.material.Material; +import net.minecraft.block.state.IBlockState; +import net.minecraft.item.Item; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; + +public class BlockNullifyOrb extends BlockBase implements ITileEntityProvider { + + public boolean isMoroonProof = false; + public BlockNullifyOrb(String name, Material material) { + super(name, material); + this.hasTileEntity = true; + setSoundType(SoundType.METAL); + setHardness(5.0F); + setResistance(15.0F); + setHarvestLevel("pickaxe", 3); + setLightOpacity(1); + setCreativeTab(ModCreativeTab.IDL_MISC); + } + + public BlockNullifyOrb setAdvanced(boolean val) + { + isMoroonProof = val; + return this; + } + + + //optional + @Override + public Item getItemDropped(IBlockState state, Random rand, int fortune) + { + return super.getItemDropped(state, rand, fortune); + } + + @Override + public int quantityDropped(Random rand) { + return super.quantityDropped(rand); + } + + /** + * Returns a new instance of a block's tile entity class. Called on placing the block. + */ + public TileEntity createNewTileEntity(World worldIn, int meta) + { + if (isMoroonProof) + { + return new TileEntityNullifyOrbMor(); + }else { + return new TileEntityNullifyOrb(); + } + } + + +} diff --git a/src/main/java/com/somebody/idlframewok/blocks/blockBasic/DivineOre.java b/src/main/java/com/somebody/idlframewok/blocks/blockBasic/DivineOre.java new file mode 100644 index 0000000..a4abb98 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/blocks/blockBasic/DivineOre.java @@ -0,0 +1,40 @@ +package com.somebody.idlframewok.blocks.blockBasic; + +import java.util.Random; + +import com.somebody.idlframewok.blocks.BlockBase; +import net.minecraft.block.SoundType; +import net.minecraft.block.material.Material; +import net.minecraft.block.state.IBlockState; +import net.minecraft.item.Item; + +public class DivineOre extends BlockBase { + + public DivineOre(String name, Material material) { + super(name, material); + + setSoundType(SoundType.METAL); + setHardness(5.0F); + setResistance(15.0F); + setHarvestLevel("pickaxe", 3); + setLightLevel(1f); + setLightOpacity(1); + + } + + //optional + @Override + public Item getItemDropped(IBlockState state, Random rand, int fortune) + { + return super.getItemDropped(state, rand, fortune); + } + + @Override + public int quantityDropped(Random rand) { +// int max = 4; +// int min = 1; +// return rand.nextInt(max) + min; + + return super.quantityDropped(rand); + } +} diff --git a/src/main/java/com/somebody/idlframewok/blocks/blockBasic/IdeallandLight.java b/src/main/java/com/somebody/idlframewok/blocks/blockBasic/IdeallandLight.java new file mode 100644 index 0000000..a8cc3da --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/blocks/blockBasic/IdeallandLight.java @@ -0,0 +1,41 @@ +package com.somebody.idlframewok.blocks.blockBasic; + +import java.util.Random; + +import com.somebody.idlframewok.blocks.BlockBase; +import com.somebody.idlframewok.init.ModCreativeTab; +import net.minecraft.block.SoundType; +import net.minecraft.block.material.Material; +import net.minecraft.block.state.IBlockState; +import net.minecraft.item.Item; + +public class IdeallandLight extends BlockBase { + + public IdeallandLight(String name, Material material) { + super(name, material); + + setSoundType(SoundType.METAL); + setHardness(5.0F); + setResistance(1000.0F); + setHarvestLevel("pickaxe", 1); + setLightLevel(1f); + setLightOpacity(1); + setCreativeTab(ModCreativeTab.IDL_MISC); + } + + //optional + @Override + public Item getItemDropped(IBlockState state, Random rand, int fortune) + { + return super.getItemDropped(state, rand, fortune); + } + + @Override + public int quantityDropped(Random rand) { +// int max = 4; +// int min = 1; +// return rand.nextInt(max) + min; + + return super.quantityDropped(rand); + } +} diff --git a/src/main/java/com/somebody/idlframewok/blocks/blockBasic/ModBlockGlassBase.java b/src/main/java/com/somebody/idlframewok/blocks/blockBasic/ModBlockGlassBase.java new file mode 100644 index 0000000..5e66432 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/blocks/blockBasic/ModBlockGlassBase.java @@ -0,0 +1,61 @@ +package com.somebody.idlframewok.blocks.blockBasic; + +import com.somebody.idlframewok.blocks.BlockBase; +import net.minecraft.block.Block; +import net.minecraft.block.material.Material; +import net.minecraft.block.state.IBlockState; +import net.minecraft.util.BlockRenderLayer; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.IBlockAccess; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +public class ModBlockGlassBase extends BlockBase { + public ModBlockGlassBase(String name, Material material) { + super(name, material); + } + + @SideOnly(Side.CLIENT) + public BlockRenderLayer getBlockLayer() + { + return BlockRenderLayer.TRANSLUCENT; + } + + public boolean isFullCube(IBlockState state) + { + return false; + } + + protected boolean canSilkHarvest() + { + return true; + } + + /** + * Used to determine ambient occlusion and culling when rebuilding chunks for render + */ + public boolean isOpaqueCube(IBlockState state) + { + return false; + } + + @SideOnly(Side.CLIENT) + public boolean shouldSideBeRendered(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side) + { + IBlockState iblockstate = blockAccess.getBlockState(pos.offset(side)); + Block block = iblockstate.getBlock(); + + if (blockState != iblockstate) + { + return true; + } + + if (block == this) + { + return false; + } + + return super.shouldSideBeRendered(blockState, blockAccess, pos, side); + } +} diff --git a/src/main/java/com/somebody/idlframewok/blocks/blockBasic/PureOre.java b/src/main/java/com/somebody/idlframewok/blocks/blockBasic/PureOre.java new file mode 100644 index 0000000..8e8b64c --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/blocks/blockBasic/PureOre.java @@ -0,0 +1,33 @@ +package com.somebody.idlframewok.blocks.blockBasic; + +import java.util.Random; + +import com.somebody.idlframewok.blocks.BlockBase; +import net.minecraft.block.SoundType; +import net.minecraft.block.material.Material; +import net.minecraft.block.state.IBlockState; +import net.minecraft.item.Item; + +public class PureOre extends BlockBase { + + public PureOre(String name, Material material) { + super(name, material); + + setSoundType(SoundType.METAL); + setHardness(15.0F); + setResistance(15.0F); + setHarvestLevel("pickaxe", 1); + } + + //optional + @Override + public Item getItemDropped(IBlockState state, Random rand, int fortune) + { + return super.getItemDropped(state, rand, fortune); + } + + @Override + public int quantityDropped(Random rand) { + return super.quantityDropped(rand); + } +} diff --git a/src/main/java/com/somebody/idlframewok/blocks/blockMisc/BlockArtifactHead.java b/src/main/java/com/somebody/idlframewok/blocks/blockMisc/BlockArtifactHead.java new file mode 100644 index 0000000..3cd9cdc --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/blocks/blockMisc/BlockArtifactHead.java @@ -0,0 +1,237 @@ +package com.somebody.idlframewok.blocks.blockMisc; + +import javax.annotation.Nullable; + +import com.google.common.base.Predicate; +import net.minecraft.advancements.CriteriaTriggers; +import net.minecraft.block.BlockHorizontal; +import net.minecraft.block.material.MapColor; +import net.minecraft.block.material.Material; +import net.minecraft.block.properties.IProperty; +import net.minecraft.block.state.BlockStateContainer; +import net.minecraft.block.state.BlockWorldState; +import net.minecraft.block.state.IBlockState; +import net.minecraft.block.state.pattern.BlockMaterialMatcher; +import net.minecraft.block.state.pattern.BlockPattern; +import net.minecraft.block.state.pattern.BlockStateMatcher; +import net.minecraft.block.state.pattern.FactoryBlockPattern; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.monster.EntityIronGolem; +import net.minecraft.entity.monster.EntitySnowman; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.init.Blocks; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.EnumParticleTypes; +import net.minecraft.util.Mirror; +import net.minecraft.util.Rotation; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; + +public class BlockArtifactHead extends BlockHorizontal +{ + private BlockPattern snowmanBasePattern; + private BlockPattern snowmanPattern; + private BlockPattern golemBasePattern; + private BlockPattern golemPattern; + private static final Predicate IS_PUMPKIN = new Predicate() + { + public boolean apply(@Nullable IBlockState p_apply_1_) + { + return p_apply_1_ != null && (p_apply_1_.getBlock() == Blocks.PUMPKIN || p_apply_1_.getBlock() == Blocks.LIT_PUMPKIN); + } + }; + + protected BlockArtifactHead() + { + super(Material.GOURD, MapColor.ADOBE); + this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH)); + this.setTickRandomly(true); + this.setCreativeTab(CreativeTabs.BUILDING_BLOCKS); + } + + /** + * Called after the block is set in the Chunk data, but before the Tile Entity is set + */ + public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state) + { + super.onBlockAdded(worldIn, pos, state); + this.trySpawnGolem(worldIn, pos); + } + + public boolean canDispenserPlace(World worldIn, BlockPos pos) + { + return this.getSnowmanBasePattern().match(worldIn, pos) != null || this.getGolemBasePattern().match(worldIn, pos) != null; + } + + private void trySpawnGolem(World worldIn, BlockPos pos) + { + BlockPattern.PatternHelper blockpattern$patternhelper = this.getSnowmanPattern().match(worldIn, pos); + + if (blockpattern$patternhelper != null) + { + for (int i = 0; i < this.getSnowmanPattern().getThumbLength(); ++i) + { + BlockWorldState blockworldstate = blockpattern$patternhelper.translateOffset(0, i, 0); + worldIn.setBlockState(blockworldstate.getPos(), Blocks.AIR.getDefaultState(), 2); + } + + EntitySnowman entitysnowman = new EntitySnowman(worldIn); + BlockPos blockpos1 = blockpattern$patternhelper.translateOffset(0, 2, 0).getPos(); + entitysnowman.setLocationAndAngles((double)blockpos1.getX() + 0.5D, (double)blockpos1.getY() + 0.05D, (double)blockpos1.getZ() + 0.5D, 0.0F, 0.0F); + worldIn.spawnEntity(entitysnowman); + + for (EntityPlayerMP entityplayermp : worldIn.getEntitiesWithinAABB(EntityPlayerMP.class, entitysnowman.getEntityBoundingBox().grow(5.0D))) + { + CriteriaTriggers.SUMMONED_ENTITY.trigger(entityplayermp, entitysnowman); + } + + for (int l = 0; l < 120; ++l) + { + worldIn.spawnParticle(EnumParticleTypes.SNOW_SHOVEL, (double)blockpos1.getX() + worldIn.rand.nextDouble(), (double)blockpos1.getY() + worldIn.rand.nextDouble() * 2.5D, (double)blockpos1.getZ() + worldIn.rand.nextDouble(), 0.0D, 0.0D, 0.0D); + } + + for (int i1 = 0; i1 < this.getSnowmanPattern().getThumbLength(); ++i1) + { + BlockWorldState blockworldstate2 = blockpattern$patternhelper.translateOffset(0, i1, 0); + worldIn.notifyNeighborsRespectDebug(blockworldstate2.getPos(), Blocks.AIR, false); + } + } + else + { + blockpattern$patternhelper = this.getGolemPattern().match(worldIn, pos); + + if (blockpattern$patternhelper != null) + { + for (int j = 0; j < this.getGolemPattern().getPalmLength(); ++j) + { + for (int k = 0; k < this.getGolemPattern().getThumbLength(); ++k) + { + worldIn.setBlockState(blockpattern$patternhelper.translateOffset(j, k, 0).getPos(), Blocks.AIR.getDefaultState(), 2); + } + } + + BlockPos blockpos = blockpattern$patternhelper.translateOffset(1, 2, 0).getPos(); + EntityIronGolem entityirongolem = new EntityIronGolem(worldIn); + entityirongolem.setPlayerCreated(true); + entityirongolem.setLocationAndAngles((double)blockpos.getX() + 0.5D, (double)blockpos.getY() + 0.05D, (double)blockpos.getZ() + 0.5D, 0.0F, 0.0F); + worldIn.spawnEntity(entityirongolem); + + for (EntityPlayerMP entityplayermp1 : worldIn.getEntitiesWithinAABB(EntityPlayerMP.class, entityirongolem.getEntityBoundingBox().grow(5.0D))) + { + CriteriaTriggers.SUMMONED_ENTITY.trigger(entityplayermp1, entityirongolem); + } + + for (int j1 = 0; j1 < 120; ++j1) + { + worldIn.spawnParticle(EnumParticleTypes.SNOWBALL, (double)blockpos.getX() + worldIn.rand.nextDouble(), (double)blockpos.getY() + worldIn.rand.nextDouble() * 3.9D, (double)blockpos.getZ() + worldIn.rand.nextDouble(), 0.0D, 0.0D, 0.0D); + } + + for (int k1 = 0; k1 < this.getGolemPattern().getPalmLength(); ++k1) + { + for (int l1 = 0; l1 < this.getGolemPattern().getThumbLength(); ++l1) + { + BlockWorldState blockworldstate1 = blockpattern$patternhelper.translateOffset(k1, l1, 0); + worldIn.notifyNeighborsRespectDebug(blockworldstate1.getPos(), Blocks.AIR, false); + } + } + } + } + } + + /** + * Checks if this block can be placed exactly at the given position. + */ + public boolean canPlaceBlockAt(World worldIn, BlockPos pos) + { + return worldIn.getBlockState(pos).getBlock().isReplaceable(worldIn, pos) && worldIn.isSideSolid(pos.down(), EnumFacing.UP); + } + + /** + * Returns the blockstate with the given rotation from the passed blockstate. If inapplicable, returns the passed + * blockstate. + */ + public IBlockState withRotation(IBlockState state, Rotation rot) + { + return state.withProperty(FACING, rot.rotate((EnumFacing)state.getValue(FACING))); + } + + /** + * Returns the blockstate with the given mirror of the passed blockstate. If inapplicable, returns the passed + * blockstate. + */ + public IBlockState withMirror(IBlockState state, Mirror mirrorIn) + { + return state.withRotation(mirrorIn.toRotation((EnumFacing)state.getValue(FACING))); + } + + /** + * Called by ItemBlocks just before a block is actually set in the world, to allow for adjustments to the + * IBlockstate + */ + public IBlockState getStateForPlacement(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer) + { + return this.getDefaultState().withProperty(FACING, placer.getHorizontalFacing().getOpposite()); + } + + /** + * Convert the given metadata into a BlockState for this Block + */ + public IBlockState getStateFromMeta(int meta) + { + return this.getDefaultState().withProperty(FACING, EnumFacing.getHorizontal(meta)); + } + + /** + * Convert the BlockState into the correct metadata value + */ + public int getMetaFromState(IBlockState state) + { + return ((EnumFacing)state.getValue(FACING)).getHorizontalIndex(); + } + + protected BlockStateContainer createBlockState() + { + return new BlockStateContainer(this, new IProperty[] {FACING}); + } + + protected BlockPattern getSnowmanBasePattern() + { + if (this.snowmanBasePattern == null) + { + this.snowmanBasePattern = FactoryBlockPattern.start().aisle(" ", "#", "#").where('#', BlockWorldState.hasState(BlockStateMatcher.forBlock(Blocks.SNOW))).build(); + } + + return this.snowmanBasePattern; + } + + protected BlockPattern getSnowmanPattern() + { + if (this.snowmanPattern == null) + { + this.snowmanPattern = FactoryBlockPattern.start().aisle("^", "#", "#").where('^', BlockWorldState.hasState(IS_PUMPKIN)).where('#', BlockWorldState.hasState(BlockStateMatcher.forBlock(Blocks.SNOW))).build(); + } + + return this.snowmanPattern; + } + + protected BlockPattern getGolemBasePattern() + { + if (this.golemBasePattern == null) + { + this.golemBasePattern = FactoryBlockPattern.start().aisle("~ ~", "###", "~#~").where('#', BlockWorldState.hasState(BlockStateMatcher.forBlock(Blocks.IRON_BLOCK))).where('~', BlockWorldState.hasState(BlockMaterialMatcher.forMaterial(Material.AIR))).build(); + } + + return this.golemBasePattern; + } + + protected BlockPattern getGolemPattern() + { + if (this.golemPattern == null) + { + this.golemPattern = FactoryBlockPattern.start().aisle("~^~", "###", "~#~").where('^', BlockWorldState.hasState(IS_PUMPKIN)).where('#', BlockWorldState.hasState(BlockStateMatcher.forBlock(Blocks.IRON_BLOCK))).where('~', BlockWorldState.hasState(BlockMaterialMatcher.forMaterial(Material.AIR))).build(); + } + + return this.golemPattern; + } +} \ No newline at end of file diff --git a/src/main/java/com/somebody/idlframewok/blocks/blockMoroon/BlockMoroonBase.java b/src/main/java/com/somebody/idlframewok/blocks/blockMoroon/BlockMoroonBase.java new file mode 100644 index 0000000..4c60bd8 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/blocks/blockMoroon/BlockMoroonBase.java @@ -0,0 +1,11 @@ +package com.somebody.idlframewok.blocks.blockMoroon; + +import com.somebody.idlframewok.blocks.BlockBase; +import net.minecraft.block.material.Material; + +public class BlockMoroonBase extends BlockBase { + public BlockMoroonBase(String name, Material material) { + super(name, material); + setResistance(1.0F); + } +} diff --git a/src/main/java/com/somebody/idlframewok/blocks/builder/BlockBuilderBase.java b/src/main/java/com/somebody/idlframewok/blocks/builder/BlockBuilderBase.java new file mode 100644 index 0000000..60faba9 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/blocks/builder/BlockBuilderBase.java @@ -0,0 +1,42 @@ +package com.somebody.idlframewok.blocks.builder; + +import com.somebody.idlframewok.IdlFramework; +import com.somebody.idlframewok.blocks.BlockBase; +import com.somebody.idlframewok.blocks.tileEntity.builder.TileEntityBuilderBase; +import com.somebody.idlframewok.init.ModCreativeTab; +import net.minecraft.block.ITileEntityProvider; +import net.minecraft.block.SoundType; +import net.minecraft.block.material.Material; +import net.minecraft.world.World; + +public class BlockBuilderBase extends BlockBase implements ITileEntityProvider { + + Class tileEntity; + + public BlockBuilderBase(String name, Material material, Class tileEntity) { + super(name, material); + this.tileEntity = tileEntity; + setCreativeTab(ModCreativeTab.IDL_MISC); + setSoundType(SoundType.METAL); + setHardness(5.0F); + setResistance(15.0F); + setHarvestLevel("pickaxe", 3); + setLightOpacity(1); + } + + /** + * Returns a new instance of a block's tile entity class. Called on placing the block. + */ + public TileEntityBuilderBase createNewTileEntity(World worldIn, int meta) { + TileEntityBuilderBase t = null; + try { + t = tileEntity.newInstance(); + } catch (InstantiationException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + IdlFramework.Log("Instantiate failed"); + } + return t; + } +} diff --git a/src/main/java/com/somebody/idlframewok/blocks/builder/BlockBuilderOne.java b/src/main/java/com/somebody/idlframewok/blocks/builder/BlockBuilderOne.java new file mode 100644 index 0000000..9409ab3 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/blocks/builder/BlockBuilderOne.java @@ -0,0 +1,32 @@ +package com.somebody.idlframewok.blocks.builder; + +import com.somebody.idlframewok.blocks.BlockBase; +import com.somebody.idlframewok.blocks.tileEntity.builder.TileEntityBuilderOne; +import com.somebody.idlframewok.init.ModCreativeTab; +import net.minecraft.block.ITileEntityProvider; +import net.minecraft.block.SoundType; +import net.minecraft.block.material.Material; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; + +public class BlockBuilderOne extends BlockBase implements ITileEntityProvider { + + public BlockBuilderOne(String name, Material material) { + super(name, material); + setCreativeTab(ModCreativeTab.IDL_MISC); + setSoundType(SoundType.METAL); + setHardness(5.0F); + setResistance(15.0F); + setHarvestLevel("pickaxe", 3); + setLightOpacity(1); + } + + /** + * Returns a new instance of a block's tile entity class. Called on placing the block. + */ + public TileEntity createNewTileEntity(World worldIn, int meta) { + TileEntityBuilderOne t = new TileEntityBuilderOne(); + t.buildRatePerTick = 1f; + return t; + } +} diff --git a/src/main/java/com/somebody/idlframewok/blocks/tileEntity/builder/TileEntityBuilderBase.java b/src/main/java/com/somebody/idlframewok/blocks/tileEntity/builder/TileEntityBuilderBase.java new file mode 100644 index 0000000..f814647 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/blocks/tileEntity/builder/TileEntityBuilderBase.java @@ -0,0 +1,208 @@ +package com.somebody.idlframewok.blocks.tileEntity.builder; + +import java.util.Vector; + +import com.somebody.idlframewok.blocks.tileEntity.builder.builderAction.BuilderActionBase; +import com.somebody.idlframewok.blocks.tileEntity.builder.builderAction.BuilderActionBlock; +import com.somebody.idlframewok.blocks.tileEntity.builder.builderAction.BuilderActionBlockSafe; +import com.somebody.idlframewok.util.CommonDef; +import com.somebody.idlframewok.util.NBTStrDef.IDLNBTDef; +import net.minecraft.block.state.IBlockState; +import net.minecraft.init.Blocks; +import net.minecraft.init.SoundEvents; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.ITickable; +import net.minecraft.util.SoundCategory; +import net.minecraft.util.SoundEvent; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.MathHelper; + +public class TileEntityBuilderBase extends TileEntity implements ITickable { + private SoundEvent onLoadSound = SoundEvents.BLOCK_NOTE_CHIME; + + protected SoundEvent buildSound = SoundEvents.BLOCK_NOTE_CHIME; + protected SoundEvent finishSound = SoundEvents.BLOCK_NOTE_XYLOPHONE; + protected SoundEvent failSound = SoundEvents.BLOCK_LEVER_CLICK; + + protected Vector list; + + protected int reserved_first_tasks_count = 0;//some has to be done before anything else, like clearing + + @Override + public void onLoad() + { + super.onLoad(); + Init(); + } + + void Init() + { + InitTaskQueue(); + } + + public void PlaySound(SoundEvent ev) + { + world.playSound(null, this.pos, ev, SoundCategory.BLOCKS, 0.3F, 1f); + } + + + public void CreateParticles() + { +// if (world.isRemote && isReady) +// { +// Random random = new Random(); +// Vec3d myPos = GetPosInFloat(); +// float range = 2f; +// float x = (random.nextFloat() - 0.5f) * range; +// float y = (random.nextFloat() - 0.5f) * range; +// float z = (random.nextFloat() - 0.5f) * range; +// float vFactor = -1f; +// +// world.spawnParticle(particleType, myPos.x + x, myPos.y + y, myPos.z + z, x * vFactor, y * vFactor, z * vFactor); +// } + } + + //building + + public float buildRatePerTick = 1f; + public float curBuildCounter = - CommonDef.TICK_PER_SECOND * 3; + + private int curBuildActionIndex = 0; + private boolean finished = false; + + public void readFromNBT(NBTTagCompound compound) { + super.readFromNBT(compound); + this.curBuildActionIndex = compound.getInteger(IDLNBTDef.CUR_TASK_INDEX); + this.buildRatePerTick = compound.getFloat(IDLNBTDef.BUILD_SPEED); + if (list == null){ + InitTaskQueue(); + } + + if (curBuildActionIndex >= list.size()) { + finished = true; + return; + } + } + + public NBTTagCompound getUpdateTag() + { + return this.writeToNBT(new NBTTagCompound()); + } + + public NBTTagCompound writeToNBT(NBTTagCompound compound) + { + super.writeToNBT(compound); + compound.setInteger(IDLNBTDef.CUR_TASK_INDEX, this.curBuildActionIndex); + compound.setFloat(IDLNBTDef.BUILD_SPEED, this.buildRatePerTick); + return compound; + } + + protected void OnFinished(){ + world.setBlockState(pos, Blocks.AIR.getDefaultState()); + invalidate(); + } + + @Override + public void update() { + if (finished || world.isRemote) { + return; + } + + curBuildCounter += buildRatePerTick; + while (curBuildCounter > 1){ + curBuildCounter -= 1; + + BuilderActionBase action = list.get(curBuildActionIndex); + if (action != null){ + boolean success = action.Execute(world, this.pos); + if (success) { + curBuildActionIndex++; + if (curBuildActionIndex >= list.size()) { + finished = true; + PlaySound(finishSound); + OnFinished(); + return; + } + + if (world.getTotalWorldTime() % CommonDef.TICK_PER_SECOND == 0) { + PlaySound(buildSound); + } + } + else { + if (world.getTotalWorldTime() % CommonDef.TICK_PER_SECOND == 0) { + PlaySound(failSound); + } + return; + } + } + } + } + + public float GetProgress() { + return MathHelper.clamp(curBuildActionIndex / list.size(), 0f, 1f) ; + } + + public void InitTaskQueue(){ +// int radius = 10; +// list = new Vector(); +// for (int x = -radius; x <= radius; x++) +// for (int z = -radius; z <= radius; z++) { +// list.add(new BuilderActionBlock(ModBlocks.CONSTRUCTION_SITE, x,-1,z)); +// } + } + + //some helper + public void AddTaskFillWithBlockCentered(BlockPos origin, int rangeX, int rangeY, int rangeZ, IBlockState newState) { + AddTaskFillWithBlockCentered(origin, rangeX, rangeY, rangeZ, newState, true); + } + + public void AddTaskFillWithBlockCentered(BlockPos origin, int rangeX, int rangeY, int rangeZ, IBlockState newState, boolean isSafe) { + for(int x = -rangeX; + x <=rangeX;x++) { + for (int y = -rangeY; y <= rangeY; y++) { + for (int z = -rangeZ; z <= rangeZ; z++) { + AddTaskBuild(origin.add(x, y, z), newState, isSafe); + } + } + } + } + + public void AddTaskBuildWallWithBlockCentered(BlockPos origin, int rangeX, int height, int rangeZ, IBlockState newState) { + AddTaskBuildWallWithBlockCentered(origin, rangeX, height, rangeZ, newState, true); + } + + public void AddTaskBuildWallWithBlockCentered(BlockPos origin, int rangeX, int height, int rangeZ, IBlockState newState, boolean isSafe) { + for(int x = -rangeX; + x <=rangeX;x++) { + for (int y = 0; y < height; y++) { + for (int z = -rangeZ; z <= rangeZ; z++) { + AddTaskBuild(origin.add(x, y, z), newState, isSafe); + } + } + } + } + + public void AddTaskBuild(BlockPos pos, IBlockState newState) { + AddTaskBuild(pos, newState, true); + } + + public void AddTaskBuild(BlockPos pos, IBlockState newState, boolean isSafe){ + if (isSafe) { + if (newState.getBlock() == Blocks.AIR) { + list.add(reserved_first_tasks_count, new BuilderActionBlock(newState, pos)); + reserved_first_tasks_count++; + }else { + list.add(reserved_first_tasks_count, new BuilderActionBlock(Blocks.BRICK_BLOCK, pos)); + list.add(new BuilderActionBlockSafe(newState, pos)); + } + } else { + list.add(new BuilderActionBlock(newState, pos)); + } + } + +// static +// { +// registerSpawnList("idlframewok:builder.builder_one", TileEntityBuilderBase.class); +// } +} diff --git a/src/main/java/com/somebody/idlframewok/blocks/tileEntity/builder/TileEntityBuilderOne.java b/src/main/java/com/somebody/idlframewok/blocks/tileEntity/builder/TileEntityBuilderOne.java new file mode 100644 index 0000000..d90a588 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/blocks/tileEntity/builder/TileEntityBuilderOne.java @@ -0,0 +1,24 @@ +package com.somebody.idlframewok.blocks.tileEntity.builder; + +import java.util.Vector; + +import com.somebody.idlframewok.blocks.tileEntity.builder.builderAction.BuilderActionBase; +import com.somebody.idlframewok.blocks.tileEntity.builder.builderAction.BuilderActionBlock; +import net.minecraft.init.Blocks; + +public class TileEntityBuilderOne extends TileEntityBuilderBase { + + public void InitTaskQueue(){ + int radius = 10; + list = new Vector(); + for (int x = -radius; x <= radius; x++) + for (int z = -radius; z <= radius; z++) { + list.add(new BuilderActionBlock(Blocks.BRICK_BLOCK, x,-1,z)); + } + } + + static + { + register("idlframewok:builder.builder_one", TileEntityBuilderOne.class); + } +} diff --git a/src/main/java/com/somebody/idlframewok/blocks/tileEntity/builder/builderAction/BuilderActionBase.java b/src/main/java/com/somebody/idlframewok/blocks/tileEntity/builder/builderAction/BuilderActionBase.java new file mode 100644 index 0000000..1b6abcb --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/blocks/tileEntity/builder/builderAction/BuilderActionBase.java @@ -0,0 +1,37 @@ +package com.somebody.idlframewok.blocks.tileEntity.builder.builderAction; + +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Vec3d; +import net.minecraft.world.World; + +public class BuilderActionBase { + + Vec3d relativePos; + public boolean complete = false; + + BuilderActionBase(float x, float y, float z){ + SetRelativePos(x,y,z); + } + + BuilderActionBase(BlockPos blockPos){ + SetRelativePos(blockPos.getX(),blockPos.getY(),blockPos.getZ()); + } + + public boolean IsComplete(){ + return complete; + } + + public boolean Execute(World world, BlockPos ori_pos){ + complete = true; + return true; + } + + public void SetRelativePos(float x, float y, float z){ + relativePos = new Vec3d(x,y,z); + } + + public Vec3d getRelativePos() + { + return relativePos; + } +} diff --git a/src/main/java/com/somebody/idlframewok/blocks/tileEntity/builder/builderAction/BuilderActionBlock.java b/src/main/java/com/somebody/idlframewok/blocks/tileEntity/builder/builderAction/BuilderActionBlock.java new file mode 100644 index 0000000..a001433 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/blocks/tileEntity/builder/builderAction/BuilderActionBlock.java @@ -0,0 +1,73 @@ +package com.somebody.idlframewok.blocks.tileEntity.builder.builderAction; + +import java.util.List; + +import com.somebody.idlframewok.IdlFramework; +import net.minecraft.block.Block; +import net.minecraft.block.state.IBlockState; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.util.math.AxisAlignedBB; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Vec3d; +import net.minecraft.world.World; + +public class BuilderActionBlock extends BuilderActionBase { + + private Block block; + protected IBlockState blockState; + + public BuilderActionBlock(Block _block, int x, int y, int z){ + super((float) x,(float) y,(float) z); + block = _block; + blockState = _block.getDefaultState(); + } + + public BuilderActionBlock(IBlockState _block_state, int x, int y, int z){ + super((float) x,(float) y,(float) z); + block = _block_state.getBlock(); + blockState = _block_state; + } + + public BuilderActionBlock(Block _block, BlockPos blockPos){ + super(blockPos); + block = _block; + blockState = _block.getDefaultState(); + } + + public BuilderActionBlock(IBlockState _block_state, BlockPos blockPos){ + super(blockPos); + block = _block_state.getBlock(); + blockState = _block_state; + } + + @Override + public boolean Execute(World world, BlockPos ori_pos){ + if (relativePos.lengthSquared() < 1) { + IdlFramework.LogWarning("Trying to build a block at self-pos."); + return true; + } + + BlockPos pos = ori_pos.add(relativePos.x, relativePos.y, relativePos.z); + if (!world.isBlockLoaded(pos)) { + return false; + } + float range = 0.5f; + Vec3d posInFloat = new Vec3d(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5); + AxisAlignedBB aabb = new AxisAlignedBB(posInFloat.x - range, posInFloat.y - range, posInFloat.z - range, posInFloat.x + range, posInFloat.y + range, posInFloat.z + range); + List entities = world.getEntitiesWithinAABB(EntityLivingBase.class, aabb); + if (entities.size() > 0) { + //building stuck because of entity + return false; + } + + if (!world.isRemote) { + //should drop the original blocks + //dig time should be considered + if (world.getBlockState(pos) != blockState) { + world.setBlockState(pos, blockState); + } + } + return super.Execute(world, ori_pos); + } +} diff --git a/src/main/java/com/somebody/idlframewok/blocks/tileEntity/builder/builderAction/BuilderActionBlockBrutal.java b/src/main/java/com/somebody/idlframewok/blocks/tileEntity/builder/builderAction/BuilderActionBlockBrutal.java new file mode 100644 index 0000000..4970db4 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/blocks/tileEntity/builder/builderAction/BuilderActionBlockBrutal.java @@ -0,0 +1,68 @@ +package com.somebody.idlframewok.blocks.tileEntity.builder.builderAction; + +import net.minecraft.block.Block; +import net.minecraft.block.state.IBlockState; +import net.minecraft.init.Blocks; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; + +public class BuilderActionBlockBrutal extends BuilderActionBase { + + private Block block; + protected IBlockState blockState; + + public BuilderActionBlockBrutal(Block _block, int x, int y, int z){ + super((float) x,(float) y,(float) z); + block = _block; + blockState = _block.getDefaultState(); + } + + public BuilderActionBlockBrutal(IBlockState _block_state, int x, int y, int z){ + super((float) x,(float) y,(float) z); + block = _block_state.getBlock(); + blockState = _block_state; + } + + public BuilderActionBlockBrutal(Block _block, BlockPos blockPos){ + super(blockPos); + block = _block; + blockState = _block.getDefaultState(); + } + + public BuilderActionBlockBrutal(IBlockState _block_state, BlockPos blockPos){ + super(blockPos); + block = _block_state.getBlock(); + blockState = _block_state; + } + + @Override + public boolean Execute(World world, BlockPos ori_pos){ +// if (relativePos.lengthSquared() < 1) { +// //IdlFramework.LogWarning("Trying to build a block at self-pos."); +// //return true; +// } + + BlockPos pos = ori_pos.add(relativePos.x, relativePos.y, relativePos.z); + if (!world.isBlockLoaded(pos)) { + return false; + } + float range = 0.5f; +// Vec3d posInFloat = new Vec3d(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5); +// AxisAlignedBB aabb = new AxisAlignedBB(posInFloat.x - range, posInFloat.y - range, posInFloat.z - range, posInFloat.x + range, posInFloat.y + range, posInFloat.z + range); +// List entities = world.getEntitiesWithinAABB(EntityLivingBase.class, aabb); +// if (entities.size() > 0) { +// //building stuck because of entity +// return false; +// } + + if (!world.isRemote) { + //should drop the original blocks + //dig time should be considered + IBlockState original = world.getBlockState(pos); + if (original != blockState && original != Blocks.BEDROCK.getDefaultState()) { + world.setBlockState(pos, blockState); + } + } + return super.Execute(world, ori_pos); + } +} diff --git a/src/main/java/com/somebody/idlframewok/blocks/tileEntity/builder/builderAction/BuilderActionBlockSafe.java b/src/main/java/com/somebody/idlframewok/blocks/tileEntity/builder/builderAction/BuilderActionBlockSafe.java new file mode 100644 index 0000000..3622d8c --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/blocks/tileEntity/builder/builderAction/BuilderActionBlockSafe.java @@ -0,0 +1,69 @@ +package com.somebody.idlframewok.blocks.tileEntity.builder.builderAction; + +import java.util.List; + +import net.minecraft.block.Block; +import net.minecraft.block.state.IBlockState; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.init.Blocks; +import net.minecraft.util.math.AxisAlignedBB; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Vec3d; +import net.minecraft.world.World; + +public class BuilderActionBlockSafe extends BuilderActionBlock { + + public static Block block_req = Blocks.BRICK_BLOCK; + + public BuilderActionBlockSafe(Block _block, Block _req , int x, int y, int z) { + super(_block, x, y, z); + block_req = _req; + } + + public BuilderActionBlockSafe(Block _block, int x, int y, int z) { + super(_block, x, y, z); + } + + public BuilderActionBlockSafe(Block _block, BlockPos blockPos) { + super(_block, blockPos); + } + + public BuilderActionBlockSafe(IBlockState _block_state, int x, int y, int z) { + super(_block_state, x, y, z); + } + + public BuilderActionBlockSafe(IBlockState _block_state, BlockPos blockPos) { + super(_block_state, blockPos); + } + + @Override + public boolean Execute(World world, BlockPos ori_pos){ + if (relativePos.lengthSquared() < 1) { + //IdlFramework.LogWarning("Trying to build a block at self-pos."); + return true; + } + + BlockPos pos = ori_pos.add(relativePos.x, relativePos.y, relativePos.z); + if (!world.isBlockLoaded(pos)) { + return false; + } + + if (!world.isRemote) { + if (world.getBlockState(pos).getBlock() == block_req) { + return super.Execute(world, ori_pos); + } else { + float range = 0.5f; + Vec3d posInFloat = new Vec3d(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5); + AxisAlignedBB aabb = new AxisAlignedBB(posInFloat.x - range, posInFloat.y - range, posInFloat.z - range, posInFloat.x + range, posInFloat.y + range, posInFloat.z + range); + List entities = world.getEntitiesWithinAABB(EntityLivingBase.class, aabb); + if (entities.size() > 0) { + //building stuck because of entity + return false; + } + world.setBlockState(pos, block_req.getDefaultState()); + } + } + return false; + } +} diff --git a/src/main/java/com/somebody/idlframewok/blocks/tileEntity/builder/builderAction/BuilderActionSummonEntity.java b/src/main/java/com/somebody/idlframewok/blocks/tileEntity/builder/builderAction/BuilderActionSummonEntity.java new file mode 100644 index 0000000..9b9820d --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/blocks/tileEntity/builder/builderAction/BuilderActionSummonEntity.java @@ -0,0 +1,55 @@ +package com.somebody.idlframewok.blocks.tileEntity.builder.builderAction; + +import java.lang.reflect.InvocationTargetException; + +import com.somebody.idlframewok.IdlFramework; +import net.minecraft.entity.Entity; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Vec3d; +import net.minecraft.world.World; + +public class BuilderActionSummonEntity extends BuilderActionBase { + + Vec3d relative_pos; + public boolean complete = false; + + protected Class toSummon; + +// BuilderActionSummonEntity(float x, float y, float z){ +// SetRelativePos(x,y,z); +// } +// +// BuilderActionSummonEntity(BlockPos blockPos){ +// SetRelativePos(blockPos.getX(),blockPos.getY(),blockPos.getZ()); +// } + + public BuilderActionSummonEntity(BlockPos blockPos, Class toSummon){ + super(blockPos); + SetRelativePos(blockPos.getX(),blockPos.getY(),blockPos.getZ()); + this.toSummon = toSummon; + } + + public boolean Execute(World world, BlockPos ori_pos){ + if (world.isRemote) + { + return true; + } + + try { + Entity summoned = toSummon.getConstructor(World.class).newInstance(world); + summoned.setPosition(ori_pos.getX() + relative_pos.x + 0.5f, + ori_pos.getY() + relative_pos.y + 0.5f, + ori_pos.getZ() + relative_pos.z + 0.5f); + world.spawnEntity(summoned); + + } catch (NoSuchMethodException | InvocationTargetException | InstantiationException | IllegalAccessException e) { + e.printStackTrace(); + IdlFramework.LogWarning("A building process failed to summon creature"); + } + return super.Execute(world, ori_pos); + } + + public void SetRelativePos(float x, float y, float z){ + relative_pos = new Vec3d(x,y,z); + } +} diff --git a/src/main/java/com/somebody/idlframewok/blocks/tileEntity/orbs/TileEntityDeArrowOrb.java b/src/main/java/com/somebody/idlframewok/blocks/tileEntity/orbs/TileEntityDeArrowOrb.java new file mode 100644 index 0000000..e8eeecd --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/blocks/tileEntity/orbs/TileEntityDeArrowOrb.java @@ -0,0 +1,90 @@ +package com.somebody.idlframewok.blocks.tileEntity.orbs; + +import java.util.List; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.IProjectile; +import net.minecraft.entity.item.EntityTNTPrimed; +import net.minecraft.entity.projectile.EntityArrow; +import net.minecraft.entity.projectile.EntityFireball; +import net.minecraft.entity.projectile.EntityShulkerBullet; +import net.minecraft.init.Blocks; +import net.minecraft.init.Items; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ITickable; + +//"Tonation Orb" de-detonation orb +public class TileEntityDeArrowOrb extends TileEntityOrbBase implements ITickable { + + @Override + public void update() { + super.update(); + disarmProjectiles(); + } + + private void disarmProjectiles() + { + if (world.isRemote) { + return; + } + + List entities = world.getEntitiesWithinAABB(Entity.class, + aabb); + for (Entity entity : entities) { + HandleProjectile(entity); + } + } + + private void HandleProjectile(Entity projectile) + { + if (projectile.isDead) + { + return; + } + + if (projectile instanceof IProjectile || + projectile instanceof EntityFireball || + projectile instanceof EntityShulkerBullet) { + ItemStack result = GetCorrespondingStack(projectile); + if (result != null) { + projectile.entityDropItem(result, 0.1F); + + } + projectile.setDead(); + } + } + + //Tried to get the arrow from the entity. + //there is an implemented method, but it's protected. + //The only way I can think of to support light arrow and tipped arrows are rewriting them from nbt. + private ItemStack GetArrowStack(EntityArrow arrow) { + return new ItemStack(Items.ARROW); + } + + private ItemStack GetCorrespondingStack(Entity projectile) + { + if (projectile instanceof IProjectile) { + if (projectile instanceof EntityArrow) { + EntityArrow arrow = (EntityArrow) projectile; + if (arrow.pickupStatus == EntityArrow.PickupStatus.ALLOWED) + { + return GetArrowStack(arrow); + } + else { + return null; + } + } + } else if (projectile instanceof EntityFireball) + { + return new ItemStack(Items.FIRE_CHARGE); + }else if (projectile instanceof EntityTNTPrimed) { + return new ItemStack(Blocks.TNT.getItemDropped(Blocks.TNT.getDefaultState(), null, 0)); + } + return ItemStack.EMPTY; + } + + static + { + register("idlframewok:de_arrow_orb", TileEntityDeArrowOrb.class); + } +} diff --git a/src/main/java/com/somebody/idlframewok/blocks/tileEntity/orbs/TileEntityDeBoomOrb.java b/src/main/java/com/somebody/idlframewok/blocks/tileEntity/orbs/TileEntityDeBoomOrb.java new file mode 100644 index 0000000..58e56c8 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/blocks/tileEntity/orbs/TileEntityDeBoomOrb.java @@ -0,0 +1,30 @@ +package com.somebody.idlframewok.blocks.tileEntity.orbs; + +import com.somebody.idlframewok.IdlFramework; +import net.minecraft.util.ITickable; +import net.minecraft.util.math.Vec3d; +import net.minecraftforge.event.world.ExplosionEvent; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; + +//"Tonation Orb" de-detonation orb +public class TileEntityDeBoomOrb extends TileEntityOrbBase implements ITickable { + + @SubscribeEvent + public void onExplode(ExplosionEvent.Start event) { + Vec3d pos = event.getExplosion().getPosition(); + //IdlFramework.Log(String.format("onExplode:(%s,%s,%s)", pos.x, pos.y, pos.z)); + //can use some optimization here. each orb will make it worse. + + if (!event.isCanceled() && aabb.contains(pos)) + { + event.setCanceled(true); + PlaySoundHere(); + IdlFramework.Log("Stopped an explosion"); + } + } + + static + { + register("idlframewok:deboom_orb_basic", TileEntityDeBoomOrb.class); + } +} diff --git a/src/main/java/com/somebody/idlframewok/blocks/tileEntity/orbs/TileEntityEarthMender.java b/src/main/java/com/somebody/idlframewok/blocks/tileEntity/orbs/TileEntityEarthMender.java new file mode 100644 index 0000000..de9c47f --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/blocks/tileEntity/orbs/TileEntityEarthMender.java @@ -0,0 +1,112 @@ +package com.somebody.idlframewok.blocks.tileEntity.orbs; + +import net.minecraft.block.state.IBlockState; +import net.minecraft.init.Blocks; +import net.minecraft.util.ITickable; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; + +public class TileEntityEarthMender extends TileEntityOrbBase implements ITickable { + + int depth = 4; + int range = 5;//0 is self. this is radius + + @Override + public void update() { + super.update(); + + World worldIn = this.world; + if (worldIn.isRemote) { + return; + } + if (worldIn.getTotalWorldTime() % 3L == 0L) + { + IBlockState block = Blocks.DIRT.getDefaultState(); + + int diameter = 2 * range + 1; + int zFactor = diameter; + int slowDownFactor = 5; + + long worldTime = worldIn.getTotalWorldTime() / slowDownFactor; + + int dx = (int) (worldTime % diameter) - range; + int dz = (int) (worldTime / zFactor % (diameter)) - range; + + BlockPos targetPos = pos.add(dx, -depth, dz); + + boolean isDownEmpty = IsBlockPosEmpty(worldIn, targetPos.down()); + boolean isCenterEmpty = IsBlockPosEmpty(worldIn, targetPos); + + for(int y = 1; y <= depth; y++) + { + boolean[] nearbyOccupied = new boolean[4]; + nearbyOccupied[0] = !IsBlockPosEmpty(worldIn, targetPos.east()); + nearbyOccupied[1] = !IsBlockPosEmpty(worldIn, targetPos.south()); + nearbyOccupied[2] = !IsBlockPosEmpty(worldIn, targetPos.west()); + nearbyOccupied[3] = !IsBlockPosEmpty(worldIn, targetPos.north()); + + boolean putDown = false; + + if (!isDownEmpty && isCenterEmpty) + { + //check the four directions + for (int i = 0; i <= 3; i++) + { + if (nearbyOccupied[i] && nearbyOccupied[(i + 1)%4]) + { + // At first I want to make the block imitate a nearby block + //but soon I found this will allow players to get ores indefinitely. + worldIn.setBlockState(targetPos, Blocks.DIRT.getDefaultState()); + putDown = true; + break; + } + } + } + + targetPos = targetPos.up(); + isDownEmpty = isCenterEmpty && !putDown ; + isCenterEmpty = IsBlockPosEmpty(worldIn, targetPos); + } + } + } + + private boolean IsBlockStateEmpty(World worldIn, IBlockState blockState) { + boolean result = blockState.getBlock() == Blocks.AIR; + return result; + } + + private boolean IsBlockPosEmpty(World worldIn, BlockPos targetPos) { + IBlockState block = worldIn.getBlockState(targetPos); + boolean result = (block.getBlock() == Blocks.AIR) || + (block.getBlock().isReplaceable(worldIn, targetPos)); + //&& block.isOpaqueCube(); + return result; + } + +// @Override +// public boolean receiveClientEvent(int event, int param) { +// return true; +// } + +// //No Use +// @SubscribeEvent +// public void onSpawn(LivingSpawnEvent.CheckSpawn event) { +// IdlFramework.Log("Spawning:"+event.getEntityLiving().getName()); +// int range = NULLIFY_DISTANCE; +// if(event.getResult() != Event.Result.ALLOW && event.getEntityLiving() instanceof IMob) { +// AxisAlignedBB aabb = new AxisAlignedBB(event.getX() - NULLIFY_DISTANCE, event.getY() - NULLIFY_DISTANCE, event.getZ() - NULLIFY_DISTANCE, event.getX() + NULLIFY_DISTANCE, event.getY() + NULLIFY_DISTANCE, event.getZ() + NULLIFY_DISTANCE); +// if (aabb.contains(new Vec3d(this.pos.getX(), this.pos.getY(), this.pos.getZ()))) +// { +// event.setResult(Event.Result.DENY); +// IdlFramework.Log("Stopped spawning:"+event.getEntityLiving().getName()); +// return; +// } +// } +// } + + static + { + register("idlframewok:earth_mender_basic", TileEntityEarthMender.class); + } + +} diff --git a/src/main/java/com/somebody/idlframewok/blocks/tileEntity/orbs/TileEntityNullifyOrb.java b/src/main/java/com/somebody/idlframewok/blocks/tileEntity/orbs/TileEntityNullifyOrb.java new file mode 100644 index 0000000..1707101 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/blocks/tileEntity/orbs/TileEntityNullifyOrb.java @@ -0,0 +1,44 @@ +package com.somebody.idlframewok.blocks.tileEntity.orbs; + +import com.somebody.idlframewok.IdlFramework; +import net.minecraft.entity.monster.IMob; +import net.minecraft.init.Blocks; +import net.minecraft.util.ITickable; +import net.minecraft.util.math.Vec3d; +import net.minecraftforge.event.entity.living.LivingSpawnEvent; +import net.minecraftforge.fml.common.eventhandler.Event; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; + +public class TileEntityNullifyOrb extends TileEntityOrbBase implements ITickable { + + @SubscribeEvent + public void onSpawn(LivingSpawnEvent.CheckSpawn event) { + if (world.isRemote) + { + return; + } + + if (aabb == null) + { + world.setBlockState(pos, Blocks.AIR.getDefaultState()); + IdlFramework.LogWarning("A Nullify Orb @%s is not working correctly. Removing it.", pos); + invalidate(); + return; + } + + if(event.getResult() != Event.Result.DENY && event.getEntityLiving() instanceof IMob) { + if (aabb.contains(new Vec3d(event.getX(), event.getY(), event.getZ()))) + { + event.setResult(Event.Result.DENY); + //IdlFramework.Log("Stopped spawning:"+event.getEntityLiving().getName()); + return; + } + } + } + + static + { + register("idlframewok:nullify_orb_basic", TileEntityNullifyOrb.class); + } + +} diff --git a/src/main/java/com/somebody/idlframewok/blocks/tileEntity/orbs/TileEntityNullifyOrbMor.java b/src/main/java/com/somebody/idlframewok/blocks/tileEntity/orbs/TileEntityNullifyOrbMor.java new file mode 100644 index 0000000..fee5bd2 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/blocks/tileEntity/orbs/TileEntityNullifyOrbMor.java @@ -0,0 +1,40 @@ +package com.somebody.idlframewok.blocks.tileEntity.orbs; + +import com.somebody.idlframewok.util.EntityUtil; +import net.minecraft.entity.monster.IMob; +import net.minecraft.util.ITickable; +import net.minecraft.util.math.Vec3d; +import net.minecraftforge.event.entity.living.LivingSpawnEvent; +import net.minecraftforge.fml.common.eventhandler.Event; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; + +public class TileEntityNullifyOrbMor extends TileEntityNullifyOrb implements ITickable { + + protected int range = 15; + + void Init() + { + super.Init(); + SetRange(range); + } + + @SubscribeEvent + public void onSpawn(LivingSpawnEvent.CheckSpawn event) { + if(event.getResult() != Event.Result.DENY && + (event.getEntityLiving() instanceof IMob || EntityUtil.isMoroonTeam(event.getEntityLiving())) + ) { + if (aabb.contains(new Vec3d(event.getX(), event.getY(), event.getZ()))) + { + event.setResult(Event.Result.DENY); + //IdlFramework.Log("Stopped spawning:"+event.getEntityLiving().getName()); + return; + } + } + } + + static + { + register("idlframewok:nullify_orb_mor", TileEntityNullifyOrbMor.class); + } + +} diff --git a/src/main/java/com/somebody/idlframewok/blocks/tileEntity/orbs/TileEntityOrbBase.java b/src/main/java/com/somebody/idlframewok/blocks/tileEntity/orbs/TileEntityOrbBase.java new file mode 100644 index 0000000..efbd9ff --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/blocks/tileEntity/orbs/TileEntityOrbBase.java @@ -0,0 +1,148 @@ +package com.somebody.idlframewok.blocks.tileEntity.orbs; + +import java.util.Random; + +import net.minecraft.init.SoundEvents; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.EnumParticleTypes; +import net.minecraft.util.ITickable; +import net.minecraft.util.SoundCategory; +import net.minecraft.util.SoundEvent; +import net.minecraft.util.math.AxisAlignedBB; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Vec3d; +import net.minecraftforge.common.MinecraftForge; + +public class TileEntityOrbBase extends TileEntity implements ITickable { + + public AxisAlignedBB aabb; + private int range = 7; + public boolean isReady = false; + public SoundEvent onLoadSound = SoundEvents.BLOCK_NOTE_CHIME; + public EnumParticleTypes particleType = EnumParticleTypes.CRIT_MAGIC; + + public void SetRange(int newRange){ + range = newRange; + Vec3d posInFloat = GetPosInFloat(); + //IdlFramework.Log(String.format("SetRange:(%s,%s,%s) +- %s", posInFloat.x, posInFloat.y, posInFloat.z, newRange)); + aabb = new AxisAlignedBB(posInFloat.x - range, posInFloat.y - range, posInFloat.z - range, posInFloat.x + range, posInFloat.y + range, posInFloat.z + range); + + } + + public int getRange() + { + return range; + } + + public void onLoad() + { + Init(); + } + + @Override + public void invalidate() { + MinecraftForge.EVENT_BUS.unregister(this); + super.invalidate(); + } + + public Vec3d GetPosInFloat() + { + BlockPos myPos = this.pos; + Vec3d posInFloat = new Vec3d(myPos.getX() + 0.5, myPos.getY() + 0.5, myPos.getZ() + 0.5); + return posInFloat; + } + + void Init() + { + MinecraftForge.EVENT_BUS.register(this); + isReady = true; + SetRange(range); + if (!world.isRemote) + { + //Init Success + PlaySoundHere(); + } + } + + public void PlaySoundHere() + { + world.playSound(null, this.pos, onLoadSound, SoundCategory.BLOCKS, 0.3F, 1f); + } + + public void CreateParticles() + { + if (world.isRemote && isReady) + { + Random random = new Random(); + Vec3d myPos = GetPosInFloat(); + float range = 2f; + float x = (random.nextFloat() - 0.5f) * range; + float y = (random.nextFloat() - 0.5f) * range; + float z = (random.nextFloat() - 0.5f) * range; + float vFactor = -1f; + + world.spawnParticle(particleType, myPos.x + x, myPos.y + y, myPos.z + z, x * vFactor, y * vFactor, z * vFactor); + } + } + + @Override + public void update() { + //create particles + + CreateParticles(); + } + + //failed attempt +// @SubscribeEvent +// public void onWorldRenderLast(RenderWorldLastEvent event) { +// GlStateManager.pushMatrix(); +// GL11.glPushAttrib(GL11.GL_LIGHTING_BIT); +// GlStateManager.disableDepth(); +// GlStateManager.disableTexture2D(); +// GlStateManager.enableBlend(); +// +// //Minecraft.getMinecraft().getRenderManager().setRenderPosition(pos.getX(), pos.getY(), pos.getZ()); +// +// //Add drawing here +// int color = Color.HSBtoRGB(0F, 0.6F, 1F); +// Vec3d posInFloat = GetPosInFloat(); +// +// GlStateManager.scale(1F, 1F, 1F); +// +// GlStateManager.glLineWidth(1f); +// +// //draw a cube +// //for () +// DrawLine(posInFloat.x - range, posInFloat.y, posInFloat.z - range, +// posInFloat.x + range, posInFloat.y, posInFloat.z + range); +// +// DrawLine(posInFloat.x - range, posInFloat.y, posInFloat.z - range, +// posInFloat.x + range, posInFloat.y, posInFloat.z - range); +// +// DrawLine(posInFloat.x - range, posInFloat.y, posInFloat.z - range, +// posInFloat.x - range, posInFloat.y, posInFloat.z + range); +// +// DrawLine(posInFloat.x - range, posInFloat.y, posInFloat.z - range, +// posInFloat.x - range, posInFloat.y, posInFloat.z - range); +// +// DrawLine(posInFloat.x + range, posInFloat.y, posInFloat.z + range, +// posInFloat.x + range, posInFloat.y, posInFloat.z - range); +// +// DrawLine(posInFloat.x + range, posInFloat.y, posInFloat.z - range, +// posInFloat.x - range, posInFloat.y, posInFloat.z + range); +// +// GlStateManager.enableDepth(); +// GlStateManager.enableTexture2D(); +// GlStateManager.disableBlend(); +// GL11.glPopAttrib(); +// GlStateManager.popMatrix(); +// } +// +// public static void DrawLine(double x1, double y1, double z1, double x2, double y2, double z2){ +// Tessellator tessellator = Tessellator.getInstance(); +// tessellator.getBuffer().begin(GL11.GL_LINES, DefaultVertexFormats.POSITION); +// tessellator.getBuffer().pos(x1, y1, z1).endVertex(); +// tessellator.getBuffer().pos(x2, y2, z2).endVertex(); +// tessellator.draw(); +// } +} diff --git a/src/main/java/com/somebody/idlframewok/command/CommandDimTeleport.java b/src/main/java/com/somebody/idlframewok/command/CommandDimTeleport.java new file mode 100644 index 0000000..7458349 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/command/CommandDimTeleport.java @@ -0,0 +1,73 @@ +package com.somebody.idlframewok.command; + +import java.util.List; + +import com.google.common.collect.Lists; +import com.somebody.idlframewok.IdlFramework; +import com.somebody.idlframewok.util.CommonFunctions; +import com.somebody.idlframewok.util.Teleport; +import net.minecraft.command.CommandBase; +import net.minecraft.command.CommandException; +import net.minecraft.command.ICommandSender; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.server.MinecraftServer; +import net.minecraft.util.text.TextFormatting; + +public class CommandDimTeleport extends CommandBase { + + private final List aliases = Lists.newArrayList(IdlFramework.MODID, "tp", "tpdim", "tpdimension", "chuansong"); + + @Override + public String getName() { + return "tpdimension"; + } + + @Override + public String getUsage(ICommandSender sender) { + return "tpdimension "; + } + + @Override + public List getAliases() { + return aliases; + } + + + @Override + public boolean checkPermission(MinecraftServer server, ICommandSender sender) { + return true; + } + + @Override + public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException { + if (args.length < 1) { + return; + } + + String s = args[0]; + int dimensionID; + + try{ + dimensionID = Integer.parseInt(s); + }catch (NumberFormatException e) + { + if (sender instanceof EntityPlayerMP) + { + CommonFunctions.SendMsgToPlayerStyled((EntityPlayerMP) sender, "idlframewok.msg.dim_id_invalid", TextFormatting.RED, s); + } + return; + } + + if (sender instanceof EntityPlayer) + { + try{ + Teleport.teleportToDim((EntityPlayer) sender, dimensionID, ((EntityPlayer) sender).posX, ((EntityPlayer) sender).posY, ((EntityPlayer) sender).posZ); + } + catch (IllegalArgumentException e) + { + CommonFunctions.SendMsgToPlayerStyled((EntityPlayerMP) sender, "idlframewok.msg.dim_id_invalid", TextFormatting.RED, s); + } + } + } +} diff --git a/src/main/java/com/somebody/idlframewok/command/ModCommands.java b/src/main/java/com/somebody/idlframewok/command/ModCommands.java new file mode 100644 index 0000000..6a17c9b --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/command/ModCommands.java @@ -0,0 +1,4 @@ +package com.somebody.idlframewok.command; + +public class ModCommands { +} diff --git a/src/main/java/com/somebody/idlframewok/enchantments/ModEnchantmentBase.java b/src/main/java/com/somebody/idlframewok/enchantments/ModEnchantmentBase.java new file mode 100644 index 0000000..0858950 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/enchantments/ModEnchantmentBase.java @@ -0,0 +1,288 @@ +package com.somebody.idlframewok.enchantments; + +import com.somebody.idlframewok.IdlFramework; +import net.minecraft.enchantment.Enchantment; +import net.minecraft.enchantment.EnchantmentHelper; +import net.minecraft.enchantment.EnumEnchantmentType; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.inventory.EntityEquipmentSlot; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.item.ItemSword; +import net.minecraft.item.ItemTool; +import net.minecraft.util.DamageSource; + +public class ModEnchantmentBase extends Enchantment { + private boolean isTreasure = false; + + private int maxLevel = 1; + + private float base_val = 0f; + private float per_level = 0f; + + private float rarityBaseMultiplier = 1f; + private float rarityDeltaMultiplier = 1f; + + private Enchantment[] conflicts = new Enchantment[]{}; + + private boolean isHidden = false; + + private boolean isCurseEnch = false; + + //make this accessible + protected final EntityEquipmentSlot[] applicableEquipmentTypesOpen; + + //failed attempt to inter-mod compatible + //private Enchantment shareConflicts = null; + + //values get set +// public void setSimulateConflictForVanilla(Enchantment ench) +// {//doesn't work since canApplyTogether is protected +// shareConflicts = ench; +// } + + public ModEnchantmentBase setHidden(boolean val) + { + isHidden = val; + return this; + } + + public ModEnchantmentBase setMaxLevel(int maxLevel) + { + this.maxLevel = maxLevel; + return this; + } + + public ModEnchantmentBase setAsTreasure() + { + this.isTreasure = true; + return this; + } + public ModEnchantmentBase setAsCurse() + { + this.isCurseEnch = true; + return this; + } + + public ModEnchantmentBase setConflicts(Enchantment[] conflicts) + { + this.conflicts = conflicts; + return this; + } + + public ModEnchantmentBase setRarityModifier(float baseFactor, float deltaFactor) + { + this.rarityBaseMultiplier = baseFactor; + this.rarityDeltaMultiplier = deltaFactor; + return this; + } + + public ModEnchantmentBase setValue(float base_val, float per_level) + { + this.base_val = base_val; + this.per_level = per_level; + return this; + } + + @Override + public boolean isCurse() { + return isCurseEnch; + } + + public float getValue(int level) + { + if (level <= 0) + { + return 0; + } + return base_val + (level - 1) * per_level; + } + + public float getValue(EntityLivingBase creature) + { + return getValue(getLevelOnCreature(creature)); + } + + public int getLevelOnCreature(EntityLivingBase creature) + { + if (creature == null) + { + return 0; + } + return EnchantmentHelper.getMaxEnchantmentLevel(this, creature); + } + + public boolean appliedOnCreature(EntityLivingBase creature) + { + if (creature == null) + { + return false; + } + return EnchantmentHelper.getMaxEnchantmentLevel(this, creature) > 0; + } + + //Constructors + public ModEnchantmentBase(String name, Rarity rarityIn, EnumEnchantmentType typeIn, EntityEquipmentSlot[] slots) + { + super(rarityIn, typeIn, slots); + setRegistryName(IdlFramework.MODID, name); + setName(name); + ModEnchantmentInit.ENCHANTMENT_LIST.add(this); + applicableEquipmentTypesOpen = slots; + //note this slots arguments. Only enchantments in those slots will be counted! + + //additional enchantments: (modified level + 1) / 50, after applying, + //modified level /= 2. This don't change the list, but only changes the chance of going on. + + //rarity: +// COMMON(10), +// UNCOMMON(5), +// RARE(2), +// VERY_RARE(1); + } + + // // Generate a random number between 1 and 1+(enchantability/2), with a triangular distribution +// int rand_enchantability = 1 + randomInt(enchantability / 4 + 1) + randomInt(enchantability / 4 + 1); +// +// // Choose the enchantment level +// int k = chosen_enchantment_level + rand_enchantability; +// +// // A random bonus, between .85 and 1.15 +// float rand_bonus_percent = 1 + (randomFloat() + randomFloat() - 1) * 0.15; +// +// // Finally, we calculate the level +// int final_level = round(k * rand_bonus_percent); +//if ( final_level < 1 ) final_level = 1 + + // max: (30 + MaterialEnchantability/2) * 1.15 = 34.5 + 0.575 * ench + //diamond: + + //B = 1~30, depending on slots and bookshelves + //L = B + R1 + R2 + 1 + //R = randomInteger(0, E / 4) + //L *= 1 + random(-0.15,0.15) + @Override + public int getMinEnchantability(int enchantmentLevel) { + return (int) (super.getMinEnchantability(enchantmentLevel) * rarityBaseMultiplier); + } + + @Override + public int getMaxEnchantability(int enchantmentLevel) { + return (int) (getMinEnchantability(enchantmentLevel) * rarityBaseMultiplier + 50 * rarityDeltaMultiplier); + } + + @Override + public int getMaxLevel() { + return maxLevel; + } + + @Override + public int getMinLevel() { + return super.getMinLevel(); + } + + @Override + protected boolean canApplyTogether(Enchantment ench) { + for (Enchantment iter: + conflicts) { + if (ench == iter) + { + return false; + } + } + + return super.canApplyTogether(ench); + } + +// @Override +// public boolean isCompatibleWith(Enchantment en) +// { +// //this won't work +// } + + //Normally you won't care for this + @Override + public boolean canApplyAtEnchantingTable(ItemStack stack) { + //special requirement: tool or sword + if (applicableEquipmentTypesOpen == ModEnchantmentInit.mainHand) + { + Item itemType = stack.getItem(); + if (!(itemType instanceof ItemSword) && !(itemType instanceof ItemTool)) { + return false; + } + } + return !isHidden && super.canApplyAtEnchantingTable(stack); + } + + //if it's treasure, it can NOT be applied at enchant table + //villager will sell it for double price + public boolean isTreasureEnchantment() + { + return this.isTreasure; + } + + // @Override +// public float calcDamageByCreature(int level, EnumCreatureAttribute creatureType) { +// return super.calcDamageByCreature(level, creatureType); +// } + + //other shorthands + public int getEnchantmentLevel(ItemStack stack) { + return EnchantmentHelper.getEnchantmentLevel(this, stack); + } + + /** + * Called whenever a mob is damaged with an item that has this enchantment on it. + */ + public void onEntityDamaged(EntityLivingBase user, Entity target, int level) + { + } + + /** + * Whenever an entity that has this enchantment on one of its associated items is damaged this method will be + * called. + */ + public void onUserHurt(EntityLivingBase user, Entity attacker, int level) + { + } + + /** + * Calculates the damage protection of the enchantment based on level and damage source passed. + */ + public int calcModifierDamage(int level, DamageSource source) + { + //Note that this can't judge the victim's attributes as it does not contain the ref of that living base. + //it returns an int, but at last it calculates as a float. + //1 = 8% Damage. 10 = 80% (max reduction) + //note it's not Enchantment.calcDamageByCreature(int level, EnumCreatureAttribute creatureType) + + return super.calcModifierDamage(level, source); + + //EnchantmentProtection: +// if (source.canHarmInCreative()) +// { +// return 0; +// } +// else if (this.protectionType == EnchantmentProtection.Type.ALL) +// { +// return level; +// } +// else if (this.protectionType == EnchantmentProtection.Type.FIRE && source.isFireDamage()) +// { +// return level * 2; +// } +// else if (this.protectionType == EnchantmentProtection.Type.FALL && source == DamageSource.FALL) +// { +// return level * 3; +// } +// else if (this.protectionType == EnchantmentProtection.Type.EXPLOSION && source.isExplosion()) +// { +// return level * 2; +// } +// else +// { +// return this.protectionType == EnchantmentProtection.Type.PROJECTILE && source.isProjectile() ? level * 2 : 0; +// } + } +} diff --git a/src/main/java/com/somebody/idlframewok/enchantments/ModEnchantmentInit.java b/src/main/java/com/somebody/idlframewok/enchantments/ModEnchantmentInit.java new file mode 100644 index 0000000..19799fb --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/enchantments/ModEnchantmentInit.java @@ -0,0 +1,119 @@ +package com.somebody.idlframewok.enchantments; + +import java.util.ArrayList; +import java.util.List; + +import com.somebody.idlframewok.IdlFramework; +import com.somebody.idlframewok.util.CommonDef; +import net.minecraft.enchantment.Enchantment; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.init.Enchantments; +import net.minecraft.inventory.EntityEquipmentSlot; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.registry.RegistryNamespaced; +import net.minecraft.world.World; +import net.minecraftforge.event.entity.living.LivingEvent; +import net.minecraftforge.event.entity.living.LivingHurtEvent; +import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; + +@Mod.EventBusSubscriber(modid = IdlFramework.MODID) +public class ModEnchantmentInit { + + public static final EntityEquipmentSlot[] armorSlots = new EntityEquipmentSlot[] {EntityEquipmentSlot.HEAD, EntityEquipmentSlot.CHEST, EntityEquipmentSlot.LEGS, EntityEquipmentSlot.FEET}; + public static final EntityEquipmentSlot[] allSlots = EntityEquipmentSlot.values(); + public static final EntityEquipmentSlot[] handSlots = new EntityEquipmentSlot[] {EntityEquipmentSlot.MAINHAND, EntityEquipmentSlot.OFFHAND}; + public static final EntityEquipmentSlot[] mainHand = new EntityEquipmentSlot[] {EntityEquipmentSlot.MAINHAND}; + + public static final RegistryNamespaced REGISTRY = net.minecraftforge.registries.GameData.getWrapper(Enchantment.class); + public static final List ENCHANTMENT_LIST = new ArrayList(); + + //Example Enchant +// public static final ModEnchantmentBase ANTI_VANILLA = new ModEnchantmentBase("idlframewok.anti_vanilla", Enchantment.Rarity.UNCOMMON, EnumEnchantmentType.WEAPON, mainHand) +// .setMaxLevel(10).setValue(0.3f, 0.3f); + + //Conflict groups + public static final Enchantment[] WEAPON_DAMAGE_CONFLICT_GROUP = new Enchantment[] + { + Enchantments.SHARPNESS, + Enchantments.SMITE, + Enchantments.BANE_OF_ARTHROPODS, + //ANTI_VANILLA, + }; + + + public static void BeforeRegister() + { + //ANTI_AOA.setHidden(!MetaUtil.isLoaded_AOA3); + + ApplyConflictGroup(WEAPON_DAMAGE_CONFLICT_GROUP); + } + + private static void ApplyConflictGroup(Enchantment[] group) + { + for (Enchantment ench: + group + ) { + //is my enchants + if (ench instanceof ModEnchantmentBase) + { + ((ModEnchantmentBase) ench).setConflicts(group); + } + } + } + + + @SubscribeEvent + public static void onCreatureHurt(LivingHurtEvent evt) { + World world = evt.getEntity().getEntityWorld(); + EntityLivingBase hurtOne = evt.getEntityLiving(); + + if (evt.isCanceled() || world.isRemote) + { + return; + } + + float dmgModifier = 1f; + + Entity trueSource = evt.getSource().getTrueSource(); + if (trueSource instanceof EntityLivingBase) { + + EntityLivingBase attacker = (EntityLivingBase) trueSource; + + } + + evt.setAmount(evt.getAmount() * dmgModifier); + } + + @SubscribeEvent + public static void onLivingUpdateEvent(LivingEvent.LivingUpdateEvent event) + { + EntityLivingBase livingBase = event.getEntityLiving(); + + for (EntityEquipmentSlot slot: + EntityEquipmentSlot.values()) { + checkItemForTicking(livingBase, slot); + } + } + + public static void checkItemForTicking(EntityLivingBase living, EntityEquipmentSlot slot) + { + World world = living.world; + + ItemStack stack = living.getItemStackFromSlot(slot); + if (!stack.isEmpty()) + { + if (world.getWorldTime() % CommonDef.TICK_PER_SECOND == 0) + { + + } + } + } + + void OnJump(LivingEvent.LivingJumpEvent event) + { + + } +} diff --git a/src/main/java/com/somebody/idlframewok/enchantments/ModEnchantmentProtection.java b/src/main/java/com/somebody/idlframewok/enchantments/ModEnchantmentProtection.java new file mode 100644 index 0000000..52c49a4 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/enchantments/ModEnchantmentProtection.java @@ -0,0 +1,16 @@ +package com.somebody.idlframewok.enchantments; + +import net.minecraft.enchantment.EnumEnchantmentType; +import net.minecraft.inventory.EntityEquipmentSlot; + +public class ModEnchantmentProtection extends ModEnchantmentBase { + public ModEnchantmentProtection(String name, Rarity rarityIn, EnumEnchantmentType typeIn, EntityEquipmentSlot[] slots) { + super(name, rarityIn, typeIn, slots); + } + + //damage *= this + @Override + public float getValue(int level) { + return 1f / (1 + (float)level / 2f); + } +} diff --git a/src/main/java/com/somebody/idlframewok/entity/BuildingCore.java b/src/main/java/com/somebody/idlframewok/entity/BuildingCore.java new file mode 100644 index 0000000..0a4eee2 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/entity/BuildingCore.java @@ -0,0 +1,179 @@ +package com.somebody.idlframewok.entity; + +import java.util.Vector; + +import com.somebody.idlframewok.blocks.tileEntity.builder.builderAction.BuilderActionBase; +import com.somebody.idlframewok.blocks.tileEntity.builder.builderAction.BuilderActionBlock; +import com.somebody.idlframewok.blocks.tileEntity.builder.builderAction.BuilderActionBlockBrutal; +import com.somebody.idlframewok.blocks.tileEntity.builder.builderAction.BuilderActionBlockSafe; +import com.somebody.idlframewok.blocks.tileEntity.builder.builderAction.BuilderActionSummonEntity; +import com.somebody.idlframewok.util.CommonDef; +import com.somebody.idlframewok.util.NBTStrDef.IDLNBTDef; +import net.minecraft.block.state.IBlockState; +import net.minecraft.entity.Entity; +import net.minecraft.init.Blocks; +import net.minecraft.init.SoundEvents; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.MathHelper; +import net.minecraft.world.World; + +public class BuildingCore { + + private World world; + protected Vector list; + + protected int reserved_first_tasks_count = 0;//some has to be done before anything else, like clearing + + public float buildRatePerTick = 60f; + public float curBuildCounter = - CommonDef.TICK_PER_SECOND * 3f * buildRatePerTick; + + private int curBuildActionIndex = 0; + private boolean finished = false; + + private BuildingCore() { + } + + public void ResetTasks() + { + reserved_first_tasks_count = 0; + list.clear(); + } + + public void setSpeed(float buildSpeed) + { + buildRatePerTick = buildSpeed; + curBuildCounter = - CommonDef.TICK_PER_SECOND * 3f * buildRatePerTick; + } + + public BuildingCore(World world) { + this.world = world; + list = new Vector<>(); + } + + public void AddTaskSummon(BlockPos pos, Class creature) + { + list.add(new BuilderActionSummonEntity(pos, creature)); + } + + public void AddTaskBuild(BlockPos pos, IBlockState newState) { + AddTaskBuild(pos, newState, false); + } + + public void AddTaskBuild(BlockPos pos, IBlockState newState, boolean isSafe){ + if (isSafe) { + if (newState.getBlock() == Blocks.AIR) { + list.add(reserved_first_tasks_count, new BuilderActionBlock(newState, pos)); + reserved_first_tasks_count++; + }else { + list.add(reserved_first_tasks_count, new BuilderActionBlock(Blocks.BRICK_BLOCK, pos)); + list.add(new BuilderActionBlockSafe(newState, pos)); + } + } else { + list.add(new BuilderActionBlockBrutal(newState, pos)); + } + } + + public void readFromNBT(NBTTagCompound compound) { + //super.readFromNBT(compound); + this.curBuildActionIndex = compound.getInteger(IDLNBTDef.CUR_TASK_INDEX); + this.buildRatePerTick = compound.getFloat(IDLNBTDef.BUILD_SPEED); + + if (curBuildActionIndex >= list.size()) { + finished = true; + } + } + +// public NBTTagCompound getUpdateTag() +// { +// return this.writeToNBT(new NBTTagCompound()); +// } + + public NBTTagCompound writeToNBT(NBTTagCompound compound) + { + //super.writeToNBT(compound); + compound.setInteger(IDLNBTDef.CUR_TASK_INDEX, this.curBuildActionIndex); + compound.setFloat(IDLNBTDef.BUILD_SPEED, this.buildRatePerTick); + return compound; + } + + public BuilderActionBase getCurAction() + { + if (curBuildActionIndex >= list.size()) + { + return list.get(list.size() - 1); + } + else { + return list.get(curBuildActionIndex); + } + } + + public void update(BlockPos basePos) { + boolean remote = world.isRemote; + + if (finished || remote) { + return; + } + + curBuildCounter += buildRatePerTick; + while (curBuildCounter > 1){ + curBuildCounter--; + + BuilderActionBase action = list.get(curBuildActionIndex); + if (action != null){ + boolean success = action.Execute(world, basePos); + if (success) { + curBuildActionIndex++; + if (curBuildActionIndex >= list.size()) { + finished = true; + OnFinished(basePos); + return; + } + } + else { + return; + } + } + } + } + + public float GetProgress() { + return MathHelper.clamp((float) curBuildActionIndex / list.size(), 0f, 1f) ; + } + + public void OnFinished(BlockPos basePos) + { + world.playSound(basePos.getX(), basePos.getY(), basePos.getZ(), SoundEvents.BLOCK_PISTON_EXTEND, null, 1f, 1f, true); + } + + //some helper + public void AddTaskFillWithBlockCentered(BlockPos origin, int rangeX, int rangeY, int rangeZ, IBlockState newState) { + AddTaskFillWithBlockCentered(origin, rangeX, rangeY, rangeZ, newState, false); + } + + public void AddTaskFillWithBlockCentered(BlockPos origin, int rangeX, int rangeY, int rangeZ, IBlockState newState, boolean isSafe) { + for(int x = -rangeX; + x <=rangeX;x++) { + for (int y = -rangeY; y <= rangeY; y++) { + for (int z = -rangeZ; z <= rangeZ; z++) { + AddTaskBuild(origin.add(x, y, z), newState, isSafe); + } + } + } + } + + public void AddTaskBuildWallWithBlockCentered(BlockPos origin, int rangeX, int height, int rangeZ, IBlockState newState) { + AddTaskBuildWallWithBlockCentered(origin, rangeX, height, rangeZ, newState, false); + } + + public void AddTaskBuildWallWithBlockCentered(BlockPos origin, int rangeX, int height, int rangeZ, IBlockState newState, boolean isSafe) { + for(int x = -rangeX; + x <=rangeX;x++) { + for (int y = height - 1; y >= 0; y--) { + for (int z = -rangeZ; z <= rangeZ; z++) { + AddTaskBuild(origin.add(x, y, z), newState, isSafe); + } + } + } + } +} diff --git a/src/main/java/com/somebody/idlframewok/entity/ModEntityInit.java b/src/main/java/com/somebody/idlframewok/entity/ModEntityInit.java new file mode 100644 index 0000000..ef28941 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/entity/ModEntityInit.java @@ -0,0 +1,51 @@ +package com.somebody.idlframewok.entity; + +import com.somebody.idlframewok.IdlFramework; +import com.somebody.idlframewok.util.Reference; +import net.minecraft.entity.Entity; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.datafix.DataFixer; +import net.minecraftforge.fml.common.registry.EntityRegistry; + +public class ModEntityInit { + private static int ENTITY_NEXT_ID = 1; + public static void registerEntities() + { + //Examples +// registerEntity("moroon_orbital_beacon", EntityMoroonBombBeacon.class); +// registerEntity("moroon_tainter", EntityMoroonTainter.class,0xff00ff, 0x000033); +// registerEntity("idealland_whitetower_core", EntityIDLWhiteTowerCore.class, ENTITY_NEXT_ID, 128, 0xeeee00, 0xffffff); + + //the bullet + //registerEntity("bullet", EntityIdlProjectile.class); + + //Assign Dungeons + //DungeonHooks.addDungeonMob(EntityList.getKey(EntityMoroonTainter.class), STANDARD_DUNGEON_MOB_RARITY); + + DataFixer datafixer = new DataFixer(1343); + } + + private static void registerEntity(String name, Class entity) + { + registerEntity(name, entity, ENTITY_NEXT_ID, 50, 0xff00ff, 0x000000); + } + + private static void registerEntity(String name, Class entity, int color1, int color2) + { + registerEntity(name, entity, ENTITY_NEXT_ID, 50, color1, color2); + } + + private static void registerEntity(String name, Class entity, int id, int range, int color1, int color2){ + EntityRegistry.registerModEntity(new ResourceLocation(Reference.MOD_ID + ":" + name), + entity, + name, + id, + IdlFramework.instance, + range, + 1, + true, + color1, color2 + ); + ENTITY_NEXT_ID++; + } +} diff --git a/src/main/java/com/somebody/idlframewok/entity/RenderHandler.java b/src/main/java/com/somebody/idlframewok/entity/RenderHandler.java new file mode 100644 index 0000000..1d96f15 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/entity/RenderHandler.java @@ -0,0 +1,19 @@ +package com.somebody.idlframewok.entity; + +import com.somebody.idlframewok.IdlFramework; +import com.somebody.idlframewok.entity.creatures.moroon.EntityMoroonUnitBase; +import com.somebody.idlframewok.entity.creatures.render.RenderBullet; +import com.somebody.idlframewok.entity.creatures.render.RenderMoroonHumanoid; +import com.somebody.idlframewok.entity.projectiles.EntityIdlProjectile; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.fml.client.registry.RenderingRegistry; + +public class RenderHandler { + + public static void registerEntityRenders() { + RenderingRegistry.registerEntityRenderingHandler(EntityMoroonUnitBase.class, RenderMoroonHumanoid::new); + + RenderingRegistry.registerEntityRenderingHandler(EntityIdlProjectile.class, renderManager -> new RenderBullet<>(renderManager, new ResourceLocation(IdlFramework.MODID, + "textures/entity/projectiles/bullet_norm.png"))); + } +} diff --git a/src/main/java/com/somebody/idlframewok/entity/creatures/EntityModUnit.java b/src/main/java/com/somebody/idlframewok/entity/creatures/EntityModUnit.java new file mode 100644 index 0000000..2662feb --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/entity/creatures/EntityModUnit.java @@ -0,0 +1,473 @@ +package com.somebody.idlframewok.entity.creatures; + +import java.util.UUID; +import javax.annotation.Nullable; + +import com.google.common.base.Predicate; +import com.somebody.idlframewok.blocks.blockMoroon.BlockMoroonBase; +import com.somebody.idlframewok.util.CommonDef; +import com.somebody.idlframewok.util.EntityUtil; +import com.somebody.idlframewok.util.NBTStrDef.IDLNBTDef; +import net.minecraft.block.material.EnumPushReaction; +import net.minecraft.block.state.IBlockState; +import net.minecraft.enchantment.EnchantmentHelper; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityCreature; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.IEntityLivingData; +import net.minecraft.entity.SharedMonsterAttributes; +import net.minecraft.entity.ai.EntityAINearestAttackableTarget; +import net.minecraft.entity.ai.attributes.AttributeModifier; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.network.datasync.DataParameter; +import net.minecraft.network.datasync.DataSerializers; +import net.minecraft.network.datasync.EntityDataManager; +import net.minecraft.util.DamageSource; +import net.minecraft.util.SoundEvent; +import net.minecraft.util.math.AxisAlignedBB; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.MathHelper; +import net.minecraft.world.DifficultyInstance; +import net.minecraft.world.EnumDifficulty; +import net.minecraft.world.EnumSkyBlock; +import net.minecraft.world.World; + +public class EntityModUnit extends EntityCreature { + + private int level = 1; + + public boolean is_pinned_on_ground = false; + public boolean is_mechanic = false; + public boolean is_god = false; + public boolean is_building = false; + public boolean is_cubix = false; + + public boolean spawn_without_darkness = false; + public boolean spawn_without_moroon_ground = false; + + public boolean isMoroon = false; + public boolean isIdealland = false; + protected boolean applyLevelBoost = false; + + public boolean dontDespawn = false; + + public float MP = 0; + public float MPMax = 0; + public float MPRegen = 1 / CommonDef.TICK_PER_SECOND; + + protected static final DataParameter SWINGING_ARMS = EntityDataManager.createKey(EntityModUnit.class, DataSerializers.BOOLEAN); + + public EntityModUnit(World worldIn) { + super(worldIn); + //this.entityCollisionReduction = 0.9f;//not much use for fixed ones + } + + public EntityModUnit setBuilding() + { + is_mechanic = true; + is_building = true; + is_pinned_on_ground = true; + dontDespawn = true; + return this; + } + + + protected void entityInit() + { + this.dataManager.register(SWINGING_ARMS, Boolean.FALSE); + + super.entityInit(); + } + + @Override + public void writeEntityToNBT(NBTTagCompound compound) { + super.writeEntityToNBT(compound); + compound.setInteger(IDLNBTDef.LEVEL, level); + } + + @Override + public void readEntityFromNBT(NBTTagCompound compound) { + super.readEntityFromNBT(compound); + level = compound.getInteger(IDLNBTDef.LEVEL); + } + + public void setLevel(int newLevel) + { + if (newLevel > 0) + { + level = newLevel; + ApplyLevelModifier(); + } + } + + public int getLevel() + { + return level; + } + + protected int maxEasyLevel = 3; + protected int maxNormLevel = 5; + protected int maxHardLevel = 10; + + public int getMaxLevel() { + return 10; + } + + public int getRank() + { + int level = getLevel(); + if (level>=maxHardLevel) + { + return 4; + } + else if (level>=maxNormLevel) + { + return 3; + } + else if (level>=maxEasyLevel) + { + return 2; + } + return 1; + } + + public void ApplyGeneralLevelBoost(DifficultyInstance difficulty, @Nullable IEntityLivingData livingdata) + { + //with localDiff / 10 chance to lv up recursively + int level = getLevel(); + int maxLv = getMaxLevel(); + float localDifficulty = difficulty.getAdditionalDifficulty(); + while (level < maxLv && ((getRNG().nextFloat()* 10f) <= localDifficulty)) + { + level++; + } + setLevel(level); + } + + @Override + public void onUpdate() { + super.onUpdate(); + + if (EntityUtil.getAttitude(EntityUtil.Faction.PLAYER, this) == EntityUtil.ATTITUDE.HATE) + { + if (!this.world.isRemote && this.world.getDifficulty() == EnumDifficulty.PEACEFUL) + { + this.setDead(); + } + } + + if (is_pinned_on_ground) + { + motionX = 0; + motionZ = 0; + } + + if (MP < MPMax) + { + MP += MPRegen; + if (MP > MPMax) + { + MP = MPMax; + } + } + } + + public boolean trySpendMana(float val) + { + if (val <= MP) + { + MP -= val; + return true; + } + return false; + } + + protected void applyEntityAttributes() + { + super.applyEntityAttributes(); + this.getAttributeMap().registerAttribute(SharedMonsterAttributes.ATTACK_DAMAGE); + } + + //KB:1.0 = total defend + public void setAttr(double sight, double speed, double attack, double armor, double hp) + { + //float modifier = getLevelModifier(); + float modifier = 1f; + this.getEntityAttribute(SharedMonsterAttributes.FOLLOW_RANGE).setBaseValue(sight * modifier); + this.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).setBaseValue(speed * modifier); + this.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).setBaseValue(attack * modifier); + this.getEntityAttribute(SharedMonsterAttributes.ARMOR).setBaseValue(armor * modifier); + this.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(hp * modifier); + if (is_pinned_on_ground) + { + this.getEntityAttribute(SharedMonsterAttributes.KNOCKBACK_RESISTANCE).setBaseValue(2.0f); + } + } + + protected static final UUID LEVEL_BONUS_UUID = UUID.fromString("CEE0E5FE-3E5C-4515-AD0C-66483EAC7B9B"); + + public void ApplyLevelModifier() + { + AttributeModifier LEVEL_BONUS_MODIFIER = (new AttributeModifier(LEVEL_BONUS_UUID, "level bonus", getLevelModifier(), 1)); + + //prevent crashing + if (this.getEntityAttribute(SharedMonsterAttributes.ARMOR).hasModifier(LEVEL_BONUS_MODIFIER)) { + this.getEntityAttribute(SharedMonsterAttributes.ARMOR).removeModifier(LEVEL_BONUS_UUID); + this.getEntityAttribute(SharedMonsterAttributes.FOLLOW_RANGE).removeModifier(LEVEL_BONUS_UUID); + this.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).removeModifier(LEVEL_BONUS_UUID); + this.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).removeModifier(LEVEL_BONUS_UUID); + this.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).removeModifier(LEVEL_BONUS_UUID); + } + + this.getEntityAttribute(SharedMonsterAttributes.ARMOR).applyModifier(LEVEL_BONUS_MODIFIER); + this.getEntityAttribute(SharedMonsterAttributes.FOLLOW_RANGE).applyModifier(LEVEL_BONUS_MODIFIER); + this.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).applyModifier(LEVEL_BONUS_MODIFIER); + this.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).applyModifier(LEVEL_BONUS_MODIFIER); + this.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).applyModifier(LEVEL_BONUS_MODIFIER); + this.setHealth(this.getMaxHealth()); + } + + public float getLevelModifier() + { + return (level - 1f) * 0.2f; + } + + //Simulate EntityMob, use enchantments, knockback, etc. + //this is attacking other + public boolean attackEntityAsMob(Entity target) + { + float f = (float)this.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).getAttributeValue(); + int i = 0; + + if (target instanceof EntityLivingBase) + { + f += EnchantmentHelper.getModifierForCreature(this.getHeldItemMainhand(), ((EntityLivingBase)target).getCreatureAttribute()); + i += EnchantmentHelper.getKnockbackModifier(this); + } + + boolean flag = target.attackEntityFrom(DamageSource.causeMobDamage(this), f); + + if (flag) + { + if (i > 0) + { + ((EntityLivingBase)target).knockBack(this, (float)i * 0.5F, (double) MathHelper.sin(this.rotationYaw * 0.017453292F), (double)(-MathHelper.cos(this.rotationYaw * 0.017453292F))); + this.motionX *= 0.6D; + this.motionZ *= 0.6D; + } + + int j = EnchantmentHelper.getFireAspectModifier(this); + + if (j > 0) + { + target.setFire(j * 4); + } + + if (target instanceof EntityPlayer) + { + EntityPlayer entityplayer = (EntityPlayer)target; + ItemStack itemstack = this.getHeldItemMainhand(); + ItemStack itemstack1 = entityplayer.isHandActive() ? entityplayer.getActiveItemStack() : ItemStack.EMPTY; + + if (!itemstack.isEmpty() && !itemstack1.isEmpty() && itemstack.getItem().canDisableShield(itemstack, itemstack1, entityplayer, this) && itemstack1.getItem().isShield(itemstack1, entityplayer)) + { + float f1 = 0.25F + (float)EnchantmentHelper.getEfficiencyModifier(this) * 0.05F; + + if (this.rand.nextFloat() < f1) + { + entityplayer.getCooldownTracker().setCooldown(itemstack1.getItem(), 100); + this.world.setEntityState(entityplayer, (byte)30); + } + } + } + + this.applyEnchantments(this, target); + } + + return flag; + } + + + + public EnumPushReaction getPushReaction() + { + if (is_pinned_on_ground) + { + return EnumPushReaction.IGNORE; + } + else { + return EnumPushReaction.NORMAL; + } + } + /** + * Called only once on an entity when first time spawned, via egg, mob spawner, natural spawning etc, but not called + * when entity is reloaded from nbt. Mainly used for initializing attributes and inventory + */ + @Nullable + public IEntityLivingData onInitialSpawn(DifficultyInstance difficulty, @Nullable IEntityLivingData livingdata) + { + livingdata = super.onInitialSpawn(difficulty, livingdata); + return livingdata; + } + + @Override + public void addVelocity(double x, double y, double z) { + if (is_pinned_on_ground) { + super.addVelocity(0, y, 0); + } else { + super.addVelocity(x, y, z); + } + } + + //being knocked by others + @Override + public void knockBack(Entity source, float strength, double xRatio, double zRatio) { + if (!is_pinned_on_ground) { + super.knockBack(source, strength, xRatio, zRatio); + } + } + + //sound + @Override + protected SoundEvent getAmbientSound() { + return super.getAmbientSound(); + } + + @Override + protected SoundEvent getHurtSound(DamageSource damageSourceIn) { + return super.getHurtSound(damageSourceIn); + } + + @Override + protected SoundEvent getDeathSound() { + return super.getDeathSound(); + } + + + //Spawn------------------------------------------------------ + + public boolean getCanSpawnHere() + { + IBlockState iblockstate = this.world.getBlockState((new BlockPos(this)).down()); + + return iblockstate.canEntitySpawn(this) + && this.getBlockPathWeight(new BlockPos(this.posX, this.getEntityBoundingBox().minY, this.posZ)) >= 0.0F + && (spawn_without_darkness || isValidLightLevel()) + && (spawn_without_moroon_ground || iblockstate.getBlock() instanceof BlockMoroonBase); + } + + /** + * Checks to make sure the light is not too bright where the mob is spawning + */ + protected boolean isValidLightLevel() + { + BlockPos blockpos = new BlockPos(this.posX, this.getEntityBoundingBox().minY, this.posZ); + + if (this.world.getLightFor(EnumSkyBlock.SKY, blockpos) > this.rand.nextInt(32)) + { + return false; + } + else + { + int i = this.world.getLightFromNeighbors(blockpos); + + if (this.world.isThundering()) + { + int j = this.world.getSkylightSubtracted(); + this.world.setSkylightSubtracted(10); + i = this.world.getLightFromNeighbors(blockpos); + this.world.setSkylightSubtracted(j); + } + + return i <= this.rand.nextInt(8); + } + } + +// /** +// * Get this Entity's EnumCreatureAttribute +// */ +// public EnumCreatureAttribute getCreatureAttribute() +// { +// return EnumCreatureAttribute.UNDEAD; +// } + +// @Nullable +// protected ResourceLocation getLootTable() +// { +// return ModLootList.EMPTY; +// } + + //AI.................................. + public class ModAIAttackNearest extends EntityAINearestAttackableTarget + { + public ModAIAttackNearest(EntityCreature creature, Class classTarget, boolean checkSight) { + super(creature, classTarget, checkSight); + } + + public ModAIAttackNearest(EntityCreature creature, Class classTarget, boolean checkSight, boolean onlyNearby) { + super(creature, classTarget, checkSight, onlyNearby); + } + + public ModAIAttackNearest(EntityCreature creature, Class classTarget, int chance, boolean checkSight, boolean onlyNearby, @Nullable Predicate targetSelector) { + super(creature, classTarget, chance, checkSight, onlyNearby, targetSelector); + } + + protected AxisAlignedBB getTargetableArea(double targetDistance) + { + return this.taskOwner.getEntityBoundingBox().grow(targetDistance, targetDistance, targetDistance); + } + } + + public class ModAIAttackNearestAntiAir extends EntityAINearestAttackableTarget + { + public ModAIAttackNearestAntiAir(EntityCreature creature, Class classTarget, boolean checkSight) { + super(creature, classTarget, checkSight); + } + + public ModAIAttackNearestAntiAir(EntityCreature creature, Class classTarget, boolean checkSight, boolean onlyNearby) { + super(creature, classTarget, checkSight, onlyNearby); + } + + public ModAIAttackNearestAntiAir(EntityCreature creature, Class classTarget, int chance, boolean checkSight, boolean onlyNearby, @Nullable Predicate targetSelector) { + super(creature, classTarget, chance, checkSight, onlyNearby, targetSelector); + } + + protected AxisAlignedBB getTargetableArea(double targetDistance) + { + return this.taskOwner.getEntityBoundingBox().grow(targetDistance, 255, targetDistance); + } + } + + @Override + public boolean attackEntityFrom(DamageSource source, float amount) { + if (is_building){ + if (source == DamageSource.IN_WALL) { + return false; + } + + if (source.isExplosion() || source.isFireDamage()) + { + amount *= 2; + } + + if (source.isProjectile()) + { + amount *= 0.5f; + } + } + + return super.attackEntityFrom(source, amount); + } + + @Override + public boolean isNoDespawnRequired() { + return dontDespawn; + } + + protected boolean canDespawn() + { + return !dontDespawn; + } +} diff --git a/src/main/java/com/somebody/idlframewok/entity/creatures/ai/BulletMode.java b/src/main/java/com/somebody/idlframewok/entity/creatures/ai/BulletMode.java new file mode 100644 index 0000000..c5d649d --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/entity/creatures/ai/BulletMode.java @@ -0,0 +1,7 @@ +package com.somebody.idlframewok.entity.creatures.ai; + +//Imitate TF +public enum BulletMode{ + SmallFireball, + BigFireball +} diff --git a/src/main/java/com/somebody/idlframewok/entity/creatures/ai/EntityAIAttackRangedSniper.java b/src/main/java/com/somebody/idlframewok/entity/creatures/ai/EntityAIAttackRangedSniper.java new file mode 100644 index 0000000..7ea259e --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/entity/creatures/ai/EntityAIAttackRangedSniper.java @@ -0,0 +1,14 @@ +package com.somebody.idlframewok.entity.creatures.ai; + +import net.minecraft.entity.IRangedAttackMob; +import net.minecraft.entity.ai.EntityAIAttackRanged; + +public class EntityAIAttackRangedSniper extends EntityAIAttackRanged { + public EntityAIAttackRangedSniper(IRangedAttackMob attacker, double movespeed, int maxAttackTime, float maxAttackDistanceIn) { + super(attacker, movespeed, maxAttackTime, maxAttackDistanceIn); + } + + public EntityAIAttackRangedSniper(IRangedAttackMob attacker, double movespeed, int p_i1650_4_, int maxAttackTime, float maxAttackDistanceIn) { + super(attacker, movespeed, p_i1650_4_, maxAttackTime, maxAttackDistanceIn); + } +} diff --git a/src/main/java/com/somebody/idlframewok/entity/creatures/ai/EntityAIBulletAttack.java b/src/main/java/com/somebody/idlframewok/entity/creatures/ai/EntityAIBulletAttack.java new file mode 100644 index 0000000..dfcaec4 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/entity/creatures/ai/EntityAIBulletAttack.java @@ -0,0 +1,161 @@ +package com.somebody.idlframewok.entity.creatures.ai; + +import net.minecraft.entity.EntityLiving; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.ai.EntityAIBase; +import net.minecraft.entity.projectile.EntityFireball; +import net.minecraft.entity.projectile.EntityLargeFireball; +import net.minecraft.entity.projectile.EntitySmallFireball; +import net.minecraft.util.EnumHand; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Vec3d; +import net.minecraft.world.World; + +public class EntityAIBulletAttack extends EntityAIBase +{ + public RangedAttackArguments attackArguments = new RangedAttackArguments(); + public static float hostRadius = 0.5f; + private World worldObj; + /** The entity the AI instance has been applied to */ + private EntityLiving entityHost; + private EntityLivingBase attackTarget; + private float sqRange = 100f; + /** + * A decrementing tick that spawns a ranged attack once this value reaches 0. It is then set back to the + * maxRangedAttackTime. + */ + private int rangedAttackTime = 0; + private int ticksLookingAtTarget = 0; + + public EntityAIBulletAttack(EntityLiving par1EntityLiving, RangedAttackArguments args){ + this.attackArguments = args; + sqRange = args.range * args.range; + this.entityHost = par1EntityLiving; + this.worldObj = par1EntityLiving.world; + this.setMutexBits(3); + } + + /** + * Returns whether the EntityAIBase should begin execution. + */ + @Override + public boolean shouldExecute() + { + EntityLivingBase var1 = this.entityHost.getAttackTarget(); + + if (var1 == null || this.entityHost.getRNG().nextFloat() > attackArguments.attack_chance) + { + return false; + } + else + { + this.attackTarget = var1; + return true; + } + } + + /** + * Returns whether an in-progress EntityAIBase should continue executing + */ + @Override + public boolean shouldContinueExecuting() + { +// if (attackArguments.isTurret) { +// return this.shouldExecute(); +// } else { + return this.shouldExecute() || !this.entityHost.getNavigator().noPath(); +// } + } + + /** + * Resets the task + */ + @Override + public void resetTask() + { + this.attackTarget = null; + } + + /** + * Updates the task + */ + @Override + public void updateTask() + { + double maxRange = sqRange; + double targetDistance = this.entityHost.getDistanceSq(this.attackTarget.posX, this.attackTarget.posY, this.attackTarget.posZ); + boolean canSee = this.entityHost.getEntitySenses().canSee(this.attackTarget); + + if (canSee) + { + ++this.ticksLookingAtTarget; + } + else + { +// IdlFramework.LogWarning("cant see"); + this.ticksLookingAtTarget = 0; + } + +// IdlFramework.Log(String.format("Looking ticks = %d", ticksLookingAtTarget )); +// IdlFramework.Log(String.format("dist = %.2f/%.2f", targetDistance, maxRange)); + if (targetDistance <= maxRange && this.ticksLookingAtTarget >= 20) + { + this.entityHost.getNavigator().clearPath(); + } + else + { + this.entityHost.getNavigator().tryMoveToEntityLiving(this.attackTarget, attackArguments.bullet_speed); +// if (!attackArguments.isTurret) { +// this.entityHost.getNavigator().tryMoveToEntityLiving(this.attackTarget, attackArguments.bullet_speed); +// } +// else if (this.ticksLookingAtTarget >= 100) { +// resetTask(); +// return; +// } + } + + this.entityHost.getLookHelper().setLookPositionWithEntity(this.attackTarget, 30.0F, 30.0F); + this.rangedAttackTime = Math.max(this.rangedAttackTime - 1, 0); + + if (this.rangedAttackTime <= 0) + { + if (targetDistance <= maxRange && canSee) + { + this.doRangedAttack(); + this.rangedAttackTime = attackArguments.cool_down; + } + } + } + + /** + * Performs a ranged attack according to the AI's rangedAttackID. + */ + protected void doRangedAttack() + { + double d1 = hostRadius; + Vec3d vec3d = this.entityHost.getLook(1.0F); + double d2 = attackTarget.posX - (this.entityHost.posX + vec3d.x * d1); + double d3 = attackTarget.getEntityBoundingBox().minY + (double)(attackTarget.height / 2.0F) - (0.5D + this.entityHost.posY + (double)(this.entityHost.height / 2.0F)); + double d4 = attackTarget.posZ - (this.entityHost.posZ + vec3d.z * d1); + worldObj.playEvent(null, 1016, new BlockPos(this.entityHost), 0); + + //this swing is not working for turrets, reason unknown. + //will probably work on other things. + this.entityHost.swingArm(EnumHand.MAIN_HAND); + this.entityHost.swingArm(EnumHand.OFF_HAND); + this.entityHost.limbSwingAmount = 1.5f; + + EntityFireball entityBullet; + if (attackArguments.attack_mode == BulletMode.SmallFireball) { + entityBullet = new EntitySmallFireball(worldObj, this.entityHost, d2, d3, d4); + } else { + entityBullet = new EntityLargeFireball(worldObj, this.entityHost, d2, d3, d4); + ((EntityLargeFireball)entityBullet).explosionPower = (int)attackArguments.power; + } + + entityBullet.posX = this.entityHost.posX + vec3d.x * d1; + entityBullet.posY = this.entityHost.posY + (double)(this.entityHost.height / 2.0F); + entityBullet.posZ = this.entityHost.posZ + vec3d.z * d1; + worldObj.spawnEntity(entityBullet); + } +} diff --git a/src/main/java/com/somebody/idlframewok/entity/creatures/ai/EntityAIStrafeRangedAttack.java b/src/main/java/com/somebody/idlframewok/entity/creatures/ai/EntityAIStrafeRangedAttack.java new file mode 100644 index 0000000..823afc3 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/entity/creatures/ai/EntityAIStrafeRangedAttack.java @@ -0,0 +1,197 @@ +package com.somebody.idlframewok.entity.creatures.ai; + +import com.somebody.idlframewok.util.CommonDef; +import com.somebody.idlframewok.util.CommonFunctions; +import net.minecraft.entity.EntityLiving; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.IRangedAttackMob; +import net.minecraft.entity.ai.EntityAIBase; +import net.minecraft.inventory.EntityEquipmentSlot; +import net.minecraft.util.EnumHand; + +public class EntityAIStrafeRangedAttack extends EntityAIBase +{ + private final T entity; + private final double moveSpeedAmp; + private int attackCooldown; + private final float maxAttackDistanceSq; + private int attackTime = -1; + private int seeTime; + private boolean strafingClockwise; + private boolean strafingBackwards; + private int strafingTime = -1; + float targetLostThreshold = 3f; + + float aimingCooldownTimeMin = 0.3f; + float aimingCooldownTimeDelta = 0.7f; + + int curAimingCooldownThreshold = 0; + void randomAimingCooldown() + { + curAimingCooldownThreshold = (int) (CommonDef.TICK_PER_SECOND *( aimingCooldownTimeMin + this.entity.getRNG().nextFloat() * aimingCooldownTimeDelta)); + } + + public EntityAIStrafeRangedAttack(T self, double moveSpeedAmp, int attackCd, float maxAttackDistance) + { + this.entity = self; + this.moveSpeedAmp = moveSpeedAmp; + this.attackCooldown = attackCd; + this.maxAttackDistanceSq = maxAttackDistance * maxAttackDistance; + this.setMutexBits(3); + } + + //This is the time between two attacking-aiming sequence + public void setAttackCooldown(int attackCooldown) + { + this.attackCooldown = attackCooldown; + } + + //aiming can be interruppted by sight lost + public void setAimingCooldown(float minVal, float range) + { + aimingCooldownTimeMin = minVal; + aimingCooldownTimeDelta = range; + } + + /** + * Returns whether the EntityAIBase should begin execution. + */ + public boolean shouldExecute() + { + return this.entity.getAttackTarget() != null && this.isRangedWeaponInMainhand(); + } + + protected boolean isRangedWeaponInMainhand() + { + return CommonFunctions.isItemRangedWeapon(this.entity.getItemStackFromSlot(EntityEquipmentSlot.MAINHAND)); + } + + /** + * Returns whether an in-progress EntityAIBase should continue executing + */ + public boolean shouldContinueExecuting() + { + return (this.shouldExecute() || !this.entity.getNavigator().noPath()) && this.isRangedWeaponInMainhand(); + } + + /** + * Execute a one shot task or start executing a continuous task + */ + public void startExecuting() + { + super.startExecuting(); + this.entity.setSwingingArms(true); + } + + /** + * Reset the task's internal state. Called when this task is interrupted by another one + */ + public void resetTask() + { + super.resetTask(); + this.entity.setSwingingArms(false); + this.seeTime = 0; + this.attackTime = -1; + this.entity.resetActiveHand(); + } + + /** + * Keep ticking a continuous task that has already been started + */ + public void updateTask() + { + EntityLivingBase entitylivingbase = this.entity.getAttackTarget(); + + if (entitylivingbase != null) + { + double d0 = this.entity.getDistanceSq(entitylivingbase.posX, entitylivingbase.getEntityBoundingBox().minY, entitylivingbase.posZ); + boolean canSee = this.entity.getEntitySenses().canSee(entitylivingbase); + boolean flag1 = this.seeTime > 0; + + if (canSee != flag1) + { + this.seeTime = 0; + } + + if (canSee) + { + ++this.seeTime; + } + else + { + --this.seeTime; + } + + if (d0 <= (double)this.maxAttackDistanceSq && this.seeTime >= CommonDef.TICK_PER_SECOND) + { + this.entity.getNavigator().clearPath(); + ++this.strafingTime; + } + else + { + this.entity.getNavigator().tryMoveToEntityLiving(entitylivingbase, this.moveSpeedAmp); + this.strafingTime = -1; + } + + if (this.strafingTime >= CommonDef.TICK_PER_SECOND) + { + if ((double)this.entity.getRNG().nextFloat() < 0.3D) + { + this.strafingClockwise = !this.strafingClockwise; + } + + if ((double)this.entity.getRNG().nextFloat() < 0.3D) + { + this.strafingBackwards = !this.strafingBackwards; + } + + this.strafingTime = 0; + } + + if (this.strafingTime > -1) + { + if (d0 > (double)(this.maxAttackDistanceSq * 0.75F)) + { + this.strafingBackwards = false; + } + else if (d0 < (double)(this.maxAttackDistanceSq * 0.25F)) + { + this.strafingBackwards = true; + } + + this.entity.getMoveHelper().strafe(this.strafingBackwards ? -0.5F : 0.5F, this.strafingClockwise ? 0.5F : -0.5F); + this.entity.faceEntity(entitylivingbase, 30.0F, 30.0F); + } + else + { + this.entity.getLookHelper().setLookPositionWithEntity(entitylivingbase, 30.0F, 30.0F); + } + + //IdlFramework.Log("isHandActive = %s, uuid=%s", this.entity.isHandActive(), this.entity.getUniqueID()); + if (this.entity.isHandActive()) + { + if (!canSee && this.seeTime < -targetLostThreshold * CommonDef.TICK_PER_SECOND) + { + this.entity.resetActiveHand(); + } + else if (canSee) + { + int aimingTicks = this.entity.getItemInUseMaxCount(); + + if (aimingTicks >= curAimingCooldownThreshold) + { + this.entity.resetActiveHand(); + this.entity.attackEntityWithRangedAttack(entitylivingbase, (float) d0); + this.attackTime = this.attackCooldown; + + randomAimingCooldown(); + } + } + } + else if (--this.attackTime <= 0 && this.seeTime >= -targetLostThreshold * CommonDef.TICK_PER_SECOND) + { + this.entity.setActiveHand(EnumHand.MAIN_HAND); + } + } + } +} \ No newline at end of file diff --git a/src/main/java/com/somebody/idlframewok/entity/creatures/ai/EntityAITurretAttack.java b/src/main/java/com/somebody/idlframewok/entity/creatures/ai/EntityAITurretAttack.java new file mode 100644 index 0000000..814d806 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/entity/creatures/ai/EntityAITurretAttack.java @@ -0,0 +1,126 @@ +package com.somebody.idlframewok.entity.creatures.ai; + +import com.somebody.idlframewok.entity.projectiles.EntityIdlProjectile; +import com.somebody.idlframewok.entity.projectiles.ProjectileArgs; +import com.somebody.idlframewok.util.EntityUtil; +import net.minecraft.entity.EntityLiving; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.SharedMonsterAttributes; +import net.minecraft.entity.ai.EntityAIBase; +import net.minecraft.entity.ai.attributes.IAttributeInstance; +import net.minecraft.util.math.MathHelper; +import net.minecraft.world.EnumDifficulty; + +public class EntityAITurretAttack extends EntityAIBase { + + protected final EntityLiving self; + protected int curCoolDown; + protected float rangeSquare = 400f; + float errorModifier; + float bulletAccel = 0.1f; + + public int coolDownMin = 20;//ticks + public int coolDownDelta = 20;//ticks + + public EntityAITurretAttack(EntityLiving self, float errorModifier) + { + this.self = self; + this.errorModifier = errorModifier; + } + + public EntityAITurretAttack(EntityLiving self, float errorModifier, int coolDownMin, int coolDownDelta) { + this.self = self; + this.errorModifier = errorModifier; + this.coolDownMin = coolDownMin; + this.coolDownDelta = coolDownDelta; + } + + /** + * Returns whether the EntityAIBase should begin execution. + */ + @Override + public boolean shouldExecute() { + EntityLivingBase entitylivingbase = self.getAttackTarget(); + return entitylivingbase != null && entitylivingbase.isEntityAlive(); + } + + /** + * Execute a one shot task or start executing a continuous task + */ + public void startExecuting() + { + this.curCoolDown = coolDownMin; + } + + /** + * Reset the task's internal state. Called when this task is interrupted by another one + */ + public void resetTask() + { + + } + + /** + * Keep ticking a continuous task that has already been started + */ + public void updateTask() + { + if (self.world.getDifficulty() != EnumDifficulty.PEACEFUL) + { + --this.curCoolDown; + EntityLivingBase attackTarget = self.getAttackTarget(); + + if (attackTarget != null) + { + double d0 = self.getDistanceSq(attackTarget); + self.getLookHelper().setLookPosition(attackTarget.posX, + attackTarget.posY + (double)attackTarget.getEyeHeight(), + attackTarget.posZ, + (float)self.getHorizontalFaceSpeed(), + (float)self.getVerticalFaceSpeed()); + + rangeSquare = (float) (EntityUtil.getSight(self) * EntityUtil.getSight(self)); + + if (d0 < rangeSquare) + { + if (this.curCoolDown <= 0) + { + IAttributeInstance attribute = self.getEntityAttribute(SharedMonsterAttributes.ATTACK_SPEED); + double speedFactor = ((attribute == null) || (attribute.getAttributeValue() == 0)) ? 1 : attribute.getBaseValue() / attribute.getAttributeValue(); + + this.curCoolDown = (int) ((coolDownMin + self.getRNG().nextInt(coolDownDelta)) * speedFactor); + onAttackTriggered(attackTarget); + + } + } + else + { + self.setAttackTarget(null); + } + } + super.updateTask(); + } + } + + public void onAttackTriggered(EntityLivingBase target) + { + double d0 = self.getDistanceSq(target); + double d1 = target.posX - self.posX; + double d2 = target.getEntityBoundingBox().minY + (double)(target.height / 2.0F) - (self.posY + (double)(self.height / 2.0F)); + double d3 = target.posZ - self.posZ; + + float dist = MathHelper.sqrt(MathHelper.sqrt(d0)); + float estimateHitTime = MathHelper.sqrt(2 * bulletAccel * dist); + + //float halfDist = MathHelper.sqrt(MathHelper.sqrt(d0)) * 0.5F; + + EntityIdlProjectile entityIdlProjectile = new EntityIdlProjectile(self.world, new ProjectileArgs((float) EntityUtil.getAttack(self)), self, + d1 + self.getRNG().nextGaussian() * (double)errorModifier + estimateHitTime * target.motionX, + d2 + self.getRNG().nextGaussian() * (double)errorModifier + estimateHitTime * target.motionY, + d3 + self.getRNG().nextGaussian() * (double)errorModifier + estimateHitTime * target.motionZ, + bulletAccel); + + //entityIdlProjectile.posY += self.posY + (double)(self.height / 2.0F); + self.world.spawnEntity(entityIdlProjectile); + } +} diff --git a/src/main/java/com/somebody/idlframewok/entity/creatures/ai/RangedAttackArguments.java b/src/main/java/com/somebody/idlframewok/entity/creatures/ai/RangedAttackArguments.java new file mode 100644 index 0000000..ccf8299 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/entity/creatures/ai/RangedAttackArguments.java @@ -0,0 +1,11 @@ +package com.somebody.idlframewok.entity.creatures.ai; + +public class RangedAttackArguments { + public float range = 100f; + public int cool_down = 20;//ticks + public float power = 1f; + public float bullet_speed = 2f; + public float attack_chance = 1f; + public BulletMode attack_mode = BulletMode.SmallFireball; + public boolean isTurret = false; +} diff --git a/src/main/java/com/somebody/idlframewok/entity/creatures/buildings/EntityIdlBuildingBase.java b/src/main/java/com/somebody/idlframewok/entity/creatures/buildings/EntityIdlBuildingBase.java new file mode 100644 index 0000000..01477ec --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/entity/creatures/buildings/EntityIdlBuildingBase.java @@ -0,0 +1,96 @@ +package com.somebody.idlframewok.entity.creatures.buildings; + +import javax.annotation.Nullable; + +import com.somebody.idlframewok.blocks.tileEntity.builder.builderAction.BuilderActionBase; +import com.somebody.idlframewok.entity.BuildingCore; +import com.somebody.idlframewok.entity.creatures.EntityModUnit; +import net.minecraft.block.state.IBlockState; +import net.minecraft.entity.IEntityLivingData; +import net.minecraft.entity.SharedMonsterAttributes; +import net.minecraft.init.Blocks; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.DamageSource; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Vec3d; +import net.minecraft.world.DifficultyInstance; +import net.minecraft.world.World; + +public class EntityIdlBuildingBase extends EntityModUnit { + BuildingCore buildingCore; + protected boolean suicide_after_finish = true; + public EntityIdlBuildingBase(World worldIn) { + super(worldIn); + + buildingCore = new BuildingCore(worldIn); + InitTaskQueue(); + setAttr(1, 0, 0, 8, 10); + this.getEntityAttribute(SharedMonsterAttributes.KNOCKBACK_RESISTANCE).setBaseValue(1.0); + setBuilding(); + } + + @Nullable + @Override + public IEntityLivingData onInitialSpawn(DifficultyInstance difficulty, @Nullable IEntityLivingData livingdata) { + + + return super.onInitialSpawn(difficulty, livingdata); + } + + public Vec3d getCurBuildingVector() + { + BuilderActionBase action = buildingCore.getCurAction(); + if (action == null) + { + return Vec3d.ZERO; + }else { + Vec3d result = action.getRelativePos(); + return result==null ? Vec3d.ZERO : result; + } + } + + void InitTaskQueue() + { + AddTaskBuild(getPosition().add(0,-1,0), Blocks.BRICK_BLOCK.getDefaultState()); + //AddTaskBuildWallWithBlockCentered(origin.add(-floorReach,2,0), 0, windowHeight, 1, windowMaterial); + } + + public void AddTaskBuild(BlockPos pos, IBlockState newState) { + buildingCore.AddTaskBuild(pos, newState, true); + } + + public void AddTaskBuild(BlockPos pos, IBlockState newState, boolean isSafe) { + buildingCore.AddTaskBuild(pos, newState, isSafe); + } + + @Override + public void onUpdate() { + super.onUpdate(); + buildingCore.update(this.getPosition()); + + if (!world.isRemote && suicide_after_finish && buildingCore.GetProgress() >= 1f) + { + attackEntityFrom(DamageSource.OUT_OF_WORLD, getMaxHealth() * 100f); + } + } + + @Override + public void readFromNBT(NBTTagCompound compound) { + super.readFromNBT(compound); + buildingCore.readFromNBT(compound); + } + + @Override + public NBTTagCompound writeToNBT(NBTTagCompound compound) { + NBTTagCompound result = super.writeToNBT(compound); + result = buildingCore.writeToNBT(result); + return result; + } + + @Override + protected boolean canDespawn() { + return false; + } + + +} diff --git a/src/main/java/com/somebody/idlframewok/entity/creatures/buildings/EntityIdlBuildingRoom.java b/src/main/java/com/somebody/idlframewok/entity/creatures/buildings/EntityIdlBuildingRoom.java new file mode 100644 index 0000000..900061a --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/entity/creatures/buildings/EntityIdlBuildingRoom.java @@ -0,0 +1,52 @@ +package com.somebody.idlframewok.entity.creatures.buildings; + +import com.somebody.idlframewok.IdlFramework; +import com.somebody.idlframewok.util.CommonDef; +import net.minecraft.block.state.IBlockState; +import net.minecraft.init.Blocks; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; + +public class EntityIdlBuildingRoom extends EntityIdlBuildingBase { + + private int size = 3; + + public EntityIdlBuildingRoom(World worldIn) { + super(worldIn); + setAttr(1, 0, 0, 8, 5); + size = 3;//ModConfig.DEBUG_CONF.ROOM_SIZE; + buildingCore.ResetTasks(); + InitTaskQueue(); + buildingCore.setSpeed(40f / CommonDef.TICK_PER_SECOND); + IdlFramework.LogWarning("Summon. Size = " + size); + } + + void InitTaskQueue() + { + BlockPos origin = new BlockPos(0,0,0); + + if (buildingCore == null) + { + IdlFramework.LogWarning("Core is null"); + } + + int bottomRange = size; + int wallHeight = 2 * size + 1; + + IdlFramework.LogWarning("Size = " + size); + + IBlockState blockState = Blocks.IRON_BLOCK.getDefaultState(); + + //floor + buildingCore.AddTaskBuildWallWithBlockCentered(origin.add(0, -1, 0), bottomRange, 1, bottomRange, blockState); + + //ceiling + buildingCore.AddTaskBuildWallWithBlockCentered(origin.add(0, wallHeight, 0), bottomRange, 1, bottomRange, blockState); + + //surrounding + buildingCore.AddTaskBuildWallWithBlockCentered(origin.add(0, 0, bottomRange + 1), bottomRange + 1, wallHeight, 0, blockState); + buildingCore.AddTaskBuildWallWithBlockCentered(origin.add(0, 0, -bottomRange - 1), bottomRange + 1, wallHeight, 0, blockState); + buildingCore.AddTaskBuildWallWithBlockCentered(origin.add(bottomRange + 1, 0, 0), 0, wallHeight, bottomRange, blockState); + buildingCore.AddTaskBuildWallWithBlockCentered(origin.add(-bottomRange - 1, 0, 0), 0, wallHeight, bottomRange, blockState); + } +} diff --git a/src/main/java/com/somebody/idlframewok/entity/creatures/ideallandTeam/EntityIdeallandUnitBase.java b/src/main/java/com/somebody/idlframewok/entity/creatures/ideallandTeam/EntityIdeallandUnitBase.java new file mode 100644 index 0000000..ece708a --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/entity/creatures/ideallandTeam/EntityIdeallandUnitBase.java @@ -0,0 +1,72 @@ +package com.somebody.idlframewok.entity.creatures.ideallandTeam; + +import javax.annotation.Nullable; + +import com.somebody.idlframewok.entity.creatures.EntityModUnit; +import net.minecraft.entity.IEntityLivingData; +import net.minecraft.pathfinding.PathNavigateGround; +import net.minecraft.world.DifficultyInstance; +import net.minecraft.world.World; + +public class EntityIdeallandUnitBase extends EntityModUnit { + public EntityIdeallandUnitBase(World worldIn) { + super(worldIn); + setCanPickUpLoot(false);//prevent pick up player things. keep until gui done + isMoroon = false; + isIdealland = true; + dontDespawn = true; + } + + public int getRank() + { + int level = getLevel(); + if (level>=maxHardLevel) + { + return 4; + } + else if (level>=maxNormLevel) + { + return 3; + } + else if (level>=maxEasyLevel) + { + return 2; + } + return 1; + } + + public void ApplyGeneralLevelBoost(DifficultyInstance difficulty, @Nullable IEntityLivingData livingdata) + { + //with localDiff / 10 chance to lv up recursively + int level = getLevel(); + int maxLv = getMaxLevel(); + float localDifficulty = difficulty.getAdditionalDifficulty(); + while (level < maxLv && ((getRNG().nextFloat()* 10f) <= localDifficulty)) + { + level++; + } + setLevel(level); + } + +// @Nullable +// @Override +// public IEntityLivingData onInitialSpawn(DifficultyInstance difficulty, @Nullable IEntityLivingData livingdata) { +// livingdata = super.onInitialSpawn(difficulty, livingdata); +// ApplyGeneralLevelBoost(difficulty, livingdata); +// return super.onInitialSpawn(difficulty, livingdata); +// } + + protected void applyGeneralAI() + { + +// this.targetTasks.addTask(3, new EntityAINearestAttackableTarget(this, EntityLiving.class, 10, false, true, new Predicate() +// { +// public boolean apply(@Nullable EntityLiving p_apply_1_) +// { +// return p_apply_1_ != null && IMob.VISIBLE_MOB_SELECTOR.apply(p_apply_1_) && !(p_apply_1_ instanceof EntityCreeper); +// } +// })); + + ((PathNavigateGround)this.getNavigator()).setEnterDoors(true); + } +} diff --git a/src/main/java/com/somebody/idlframewok/entity/creatures/misc/EntityEternalZombie.java b/src/main/java/com/somebody/idlframewok/entity/creatures/misc/EntityEternalZombie.java new file mode 100644 index 0000000..170fcfa --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/entity/creatures/misc/EntityEternalZombie.java @@ -0,0 +1,35 @@ +package com.somebody.idlframewok.entity.creatures.misc; + +import net.minecraft.entity.SharedMonsterAttributes; +import net.minecraft.entity.monster.EntityZombie; +import net.minecraft.init.Items; +import net.minecraft.inventory.EntityEquipmentSlot; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; + +public class EntityEternalZombie extends EntityZombie { + + public EntityEternalZombie(World worldIn) { + super(worldIn); + setItemStackToSlot(EntityEquipmentSlot.HEAD, new ItemStack(Items.DIAMOND_HELMET)); + setItemStackToSlot(EntityEquipmentSlot.CHEST, new ItemStack(Items.DIAMOND_CHESTPLATE)); + setItemStackToSlot(EntityEquipmentSlot.LEGS, new ItemStack(Items.DIAMOND_LEGGINGS)); + setItemStackToSlot(EntityEquipmentSlot.FEET, new ItemStack(Items.DIAMOND_BOOTS)); + + setItemStackToSlot(EntityEquipmentSlot.MAINHAND, new ItemStack(Items.DIAMOND_SWORD)); + } + + protected void applyEntityAttributes() + { + super.applyEntityAttributes(); + this.getEntityAttribute(SharedMonsterAttributes.FOLLOW_RANGE).setBaseValue(35.0D); + this.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).setBaseValue(0.23000000417232513D); + this.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).setBaseValue(3.0D); + this.getEntityAttribute(SharedMonsterAttributes.ARMOR).setBaseValue(2.0D); + } + + protected boolean shouldBurnInDay() + { + return false; + } +} diff --git a/src/main/java/com/somebody/idlframewok/entity/creatures/misc/EntityHiredSkeleton.java b/src/main/java/com/somebody/idlframewok/entity/creatures/misc/EntityHiredSkeleton.java new file mode 100644 index 0000000..afec696 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/entity/creatures/misc/EntityHiredSkeleton.java @@ -0,0 +1,49 @@ +package com.somebody.idlframewok.entity.creatures.misc; + +import net.minecraft.entity.SharedMonsterAttributes; +import net.minecraft.entity.monster.EntitySkeleton; +import net.minecraft.init.Items; +import net.minecraft.inventory.EntityEquipmentSlot; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; + +public class EntityHiredSkeleton extends EntitySkeleton { + + boolean canDespawnNatural = true; + + public void SetDespawnable(boolean val) + { + canDespawnNatural = val; + } + + public EntityHiredSkeleton(World worldIn) { + super(worldIn); + setItemStackToSlot(EntityEquipmentSlot.HEAD, new ItemStack(Items.LEATHER_HELMET)); + setItemStackToSlot(EntityEquipmentSlot.CHEST, new ItemStack(Items.LEATHER_CHESTPLATE)); + setItemStackToSlot(EntityEquipmentSlot.LEGS, new ItemStack(Items.LEATHER_LEGGINGS)); + setItemStackToSlot(EntityEquipmentSlot.FEET, new ItemStack(Items.LEATHER_BOOTS)); + + setItemStackToSlot(EntityEquipmentSlot.MAINHAND, new ItemStack(Items.BOW)); + } + + protected void applyEntityAttributes() + { + super.applyEntityAttributes(); + this.getEntityAttribute(SharedMonsterAttributes.FOLLOW_RANGE).setBaseValue(35.0D); + } + + @Override + public void onEntityUpdate() { + super.onEntityUpdate(); + //IdlFramework.Log(getPositionVector() + " " + getUniqueID().toString()); + } + + protected boolean shouldBurnInDay() + { + return false; + } + protected boolean canDespawn() + { + return canDespawnNatural; + } +} diff --git a/src/main/java/com/somebody/idlframewok/entity/creatures/misc/EntityTurretPrototype.java b/src/main/java/com/somebody/idlframewok/entity/creatures/misc/EntityTurretPrototype.java new file mode 100644 index 0000000..0544d56 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/entity/creatures/misc/EntityTurretPrototype.java @@ -0,0 +1,205 @@ +package com.somebody.idlframewok.entity.creatures.misc; + +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.SharedMonsterAttributes; +import net.minecraft.entity.ai.EntityAIBase; +import net.minecraft.entity.ai.EntityAIFindEntityNearestPlayer; +import net.minecraft.entity.ai.EntityAILookIdle; +import net.minecraft.entity.ai.EntityAIWatchClosest; +import net.minecraft.entity.monster.EntityGhast; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.projectile.EntityLargeFireball; +import net.minecraft.util.DamageSource; +import net.minecraft.util.SoundEvent; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.MathHelper; +import net.minecraft.util.math.Vec3d; +import net.minecraft.world.World; + +public class EntityTurretPrototype extends EntityGhast { + public EntityTurretPrototype(World worldIn) { + super(worldIn); + this.setSize(0.9F,1F); + } + + @Override + protected void initEntityAI() { + //super.initEntityAI(); + //this.tasks.addTask(7, new EntityTurretPrototype.AILookAround(this)); + this.tasks.addTask(7, new EntityTurretPrototype.AIFireballAttack(this)); + this.tasks.addTask(6, new EntityAIWatchClosest(this, EntityPlayer.class, 6.0F)); + this.tasks.addTask(7, new EntityAILookIdle(this)); + + this.targetTasks.addTask(1, new EntityAIFindEntityNearestPlayer(this)); + //this.targetTasks.addTask(1, new EntityAIFindEntityNearestPlayer(this)); + //this.targetTasks.addTask(1, new EntityAIHurtByTarget(this, false)); + //this.targetTasks.addTask(2, new EntityAINearestAttackableTarget(this, EntityPlayer.class, true)); + //this.targetTasks.addTask(3, new EntityAINearestAttackableTarget(this, EntityCow.class, true)); + } + + @Override + protected void applyEntityAttributes() { + super.applyEntityAttributes(); + this.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(40.0D); + this.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).setBaseValue(0D); + this.getEntityAttribute(SharedMonsterAttributes.KNOCKBACK_RESISTANCE).setBaseValue(1.0D); + } + + @Override + public float getEyeHeight() { + return 0.5F; + } + + @Override + protected SoundEvent getAmbientSound() { + return super.getAmbientSound(); + } + + @Override + protected SoundEvent getHurtSound(DamageSource damageSourceIn) { + return super.getHurtSound(damageSourceIn); + } + + @Override + protected SoundEvent getDeathSound() { + return super.getDeathSound(); + } + + //attacking + /** The explosion radius of spawned fireballs. */ + private int explosionStrength = 1; + public int getFireballStrength() + { + return this.explosionStrength; + } + +// private static final DataParameter ATTACKING = EntityDataManager.createKey(EntityTurretPrototype.class, DataSerializers.BOOLEAN); + +// public void setAttacking(boolean attacking) +// { +// this.dataManager.set(ATTACKING, attacking); +// } + + //AI + public static class AIFireballAttack extends EntityAIBase + { + private final EntityTurretPrototype parentEntity; + public int attackTimer; + + public AIFireballAttack(EntityTurretPrototype ghast) + { + this.parentEntity = ghast; + } + + /** + * Returns whether the EntityAIBase should begin execution. + */ + public boolean shouldExecute() + { + return this.parentEntity.getAttackTarget() != null; + } + + /** + * Execute a one shot task or start executing a continuous task + */ + public void startExecuting() + { + this.attackTimer = 0; + } + + /** + * Reset the task's internal state. Called when this task is interrupted by another one + */ + public void resetTask() + { + this.parentEntity.setAttacking(false); + } + + /** + * Keep ticking a continuous task that has already been started + */ + public void updateTask() + { + EntityLivingBase entitylivingbase = this.parentEntity.getAttackTarget(); + double d0 = 64.0D; + + if (entitylivingbase.getDistanceSq(this.parentEntity) < 4096.0D && this.parentEntity.canEntityBeSeen(entitylivingbase)) + { + World world = this.parentEntity.world; + ++this.attackTimer; + + if (this.attackTimer == 10) + { + world.playEvent((EntityPlayer)null, 1015, new BlockPos(this.parentEntity), 0); + } + + if (this.attackTimer == 20) + { + double d1 = 4.0D; + Vec3d vec3d = this.parentEntity.getLook(1.0F); + double d2 = entitylivingbase.posX - (this.parentEntity.posX + vec3d.x * 4.0D); + double d3 = entitylivingbase.getEntityBoundingBox().minY + (double)(entitylivingbase.height / 2.0F) - (0.5D + this.parentEntity.posY + (double)(this.parentEntity.height / 2.0F)); + double d4 = entitylivingbase.posZ - (this.parentEntity.posZ + vec3d.z * 4.0D); + world.playEvent((EntityPlayer)null, 1016, new BlockPos(this.parentEntity), 0); + EntityLargeFireball entitylargefireball = new EntityLargeFireball(world, this.parentEntity, d2, d3, d4); + entitylargefireball.explosionPower = this.parentEntity.getFireballStrength(); + entitylargefireball.posX = this.parentEntity.posX + vec3d.x * 4.0D; + entitylargefireball.posY = this.parentEntity.posY + (double)(this.parentEntity.height / 2.0F) + 0.5D; + entitylargefireball.posZ = this.parentEntity.posZ + vec3d.z * 4.0D; + world.spawnEntity(entitylargefireball); + this.attackTimer = -40; + } + } + else if (this.attackTimer > 0) + { + --this.attackTimer; + } + + this.parentEntity.setAttacking(this.attackTimer > 10); + } + } + + public static class AILookAround extends EntityAIBase + { + private final EntityTurretPrototype parentEntity; + + public AILookAround(EntityTurretPrototype ghast) + { + this.parentEntity = ghast; + this.setMutexBits(2); + } + + /** + * Returns whether the EntityAIBase should begin execution. + */ + public boolean shouldExecute() + { + return true; + } + + /** + * Keep ticking a continuous task that has already been started + */ + public void updateTask() + { + if (this.parentEntity.getAttackTarget() == null) + { + this.parentEntity.rotationYaw = -((float) MathHelper.atan2(this.parentEntity.motionX, this.parentEntity.motionZ)) * (180F / (float)Math.PI); + this.parentEntity.renderYawOffset = this.parentEntity.rotationYaw; + } + else + { + EntityLivingBase entitylivingbase = this.parentEntity.getAttackTarget(); + double d0 = 64.0D; + + if (entitylivingbase.getDistanceSq(this.parentEntity) < 4096.0D) + { + double d1 = entitylivingbase.posX - this.parentEntity.posX; + double d2 = entitylivingbase.posZ - this.parentEntity.posZ; + this.parentEntity.rotationYaw = -((float)MathHelper.atan2(d1, d2)) * (180F / (float)Math.PI); + this.parentEntity.renderYawOffset = this.parentEntity.rotationYaw; + } + } + } + } +} diff --git a/src/main/java/com/somebody/idlframewok/entity/creatures/misc/EntityTurretPrototype2.java b/src/main/java/com/somebody/idlframewok/entity/creatures/misc/EntityTurretPrototype2.java new file mode 100644 index 0000000..383b46c --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/entity/creatures/misc/EntityTurretPrototype2.java @@ -0,0 +1,63 @@ +package com.somebody.idlframewok.entity.creatures.misc; + +import com.somebody.idlframewok.entity.creatures.EntityModUnit; +import com.somebody.idlframewok.entity.creatures.ai.BulletMode; +import com.somebody.idlframewok.entity.creatures.ai.EntityAIBulletAttack; +import com.somebody.idlframewok.entity.creatures.ai.RangedAttackArguments; +import net.minecraft.entity.SharedMonsterAttributes; +import net.minecraft.entity.ai.EntityAIHurtByTarget; +import net.minecraft.entity.ai.EntityAILookIdle; +import net.minecraft.entity.ai.EntityAINearestAttackableTarget; +import net.minecraft.entity.ai.EntityAIWatchClosest; +import net.minecraft.entity.monster.EntityIronGolem; +import net.minecraft.entity.passive.EntityCow; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.world.World; + +public class EntityTurretPrototype2 extends EntityModUnit { +//public class EntityTurretPrototype2 extends EntityMob implements IRangedAttackMob { + + public static float lookRange = 10f; + public static boolean fixed_on_ground = true; + + + public EntityTurretPrototype2(World worldIn) { + super(worldIn); + setSize(0.9F,1F); + entityCollisionReduction = 0.9f;//not much use for fixed ones + is_mechanic = true; + } + + @Override + public float getEyeHeight() { + return 0.5F; + } + + @Override + protected void initEntityAI() { + this.tasks.addTask(6, new EntityAIWatchClosest(this, EntityPlayer.class, lookRange)); + this.tasks.addTask(6, new EntityAILookIdle(this)); + + RangedAttackArguments args = new RangedAttackArguments(); + args.attack_mode = BulletMode.SmallFireball; + args.range = (float) this.getEntityAttribute(SharedMonsterAttributes.FOLLOW_RANGE).getBaseValue(); + args.isTurret = true; + + this.tasks.addTask(5, new EntityAIBulletAttack(this, args)); + + this.targetTasks.addTask(1, new EntityAIHurtByTarget(this, false, new Class[0])); + this.targetTasks.addTask(2, new EntityAINearestAttackableTarget(this, EntityPlayer.class, true)); + this.targetTasks.addTask(3, new EntityAINearestAttackableTarget(this, EntityIronGolem.class, true)); + this.targetTasks.addTask(4, new EntityAINearestAttackableTarget(this, EntityCow.class, true)); + + } + + @Override + protected void applyEntityAttributes() { + super.applyEntityAttributes(); + this.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(40.0D); + this.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).setBaseValue(0D); + this.getEntityAttribute(SharedMonsterAttributes.KNOCKBACK_RESISTANCE).setBaseValue(1.0D); + this.getEntityAttribute(SharedMonsterAttributes.FOLLOW_RANGE).setBaseValue(32.0D); + } +} diff --git a/src/main/java/com/somebody/idlframewok/entity/creatures/model/ModelCentaur.java b/src/main/java/com/somebody/idlframewok/entity/creatures/model/ModelCentaur.java new file mode 100644 index 0000000..09ecb65 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/entity/creatures/model/ModelCentaur.java @@ -0,0 +1,114 @@ +package com.somebody.idlframewok.entity.creatures.model; + +import net.minecraft.client.model.ModelBase; +import net.minecraft.client.model.ModelRenderer; +import net.minecraft.entity.Entity; +import net.minecraft.util.math.MathHelper; + +/** + * ModelCow - Either Mojang or a mod author + * Created using Tabula 7.1.0 + */ +public class ModelCentaur extends ModelBase { + public ModelRenderer cow_body; + public ModelRenderer cow_belly; + public ModelRenderer cow_leg_2_L; + public ModelRenderer cow_leg_1_L; + public ModelRenderer cow_leg_2_R; + public ModelRenderer cow_leg_1_R; + public ModelRenderer VillagerHead; + public ModelRenderer VillagerRHand; + public ModelRenderer VillagerLHand; + public ModelRenderer VillagerCenterHand; + public ModelRenderer VillagerChest; + public ModelRenderer VillagerCoat; + public ModelRenderer VillagerNose; + + public ModelCentaur() { + this.textureWidth = 64; + this.textureHeight = 32; + this.VillagerLHand = new ModelRenderer(this, 44, 22); + this.VillagerLHand.setRotationPoint(0.20000000000000004F, -12.0F, -5.799999999999996F); + this.VillagerLHand.addBox(4.0F, -2.0F, -2.0F, 4, 8, 4, 0.0F); + this.setRotateAngle(VillagerLHand, -0.7499679795819634F, 0.0F, 0.0F); + this.VillagerCoat = new ModelRenderer(this, 0, 38); + this.VillagerCoat.setRotationPoint(0.20000000000000004F, -15.0F, -4.799999999999999F); + this.VillagerCoat.addBox(-4.0F, 0.0F, -3.0F, 8, 18, 6, 0.5F); + this.VillagerNose = new ModelRenderer(this, 24, 0); + this.VillagerNose.setRotationPoint(0.0F, -2.0F, 0.0F); + this.VillagerNose.addBox(-1.0F, -1.0F, -6.0F, 2, 4, 2, 0.0F); + this.VillagerRHand = new ModelRenderer(this, 44, 22); + this.VillagerRHand.setRotationPoint(0.20000000000000004F, -12.0F, -5.799999999999996F); + this.VillagerRHand.addBox(-8.0F, -2.0F, -2.0F, 4, 8, 4, 0.0F); + this.setRotateAngle(VillagerRHand, -0.7499679795819634F, 0.0F, 0.0F); + this.cow_belly = new ModelRenderer(this, 52, 0); + this.cow_belly.setRotationPoint(0.0F, 5.0F, 2.0F); + this.cow_belly.addBox(-2.0F, 2.0F, -8.0F, 4, 6, 1, 0.0F); + this.setRotateAngle(cow_belly, 1.5707963267948966F, 0.0F, 0.0F); + this.VillagerCenterHand = new ModelRenderer(this, 40, 38); + this.VillagerCenterHand.setRotationPoint(0.20000000000000004F, -12.0F, -5.799999999999996F); + this.VillagerCenterHand.addBox(-4.0F, 2.0F, -2.0F, 8, 4, 4, 0.0F); + this.setRotateAngle(VillagerCenterHand, -0.7499679795819634F, 0.0F, 0.0F); + this.VillagerHead = new ModelRenderer(this, 0, 0); + this.VillagerHead.setRotationPoint(0.20000000000000004F, -15.0F, -4.799999999999999F); + this.VillagerHead.addBox(-4.0F, -10.0F, -4.0F, 8, 10, 8, 0.0F); + this.cow_body = new ModelRenderer(this, 18, 4); + this.cow_body.setRotationPoint(0.0F, 5.0F, 2.0F); + this.cow_body.addBox(-6.0F, -10.0F, -7.0F, 12, 18, 10, 0.0F); + this.setRotateAngle(cow_body, 1.5707963267948966F, 0.0F, 0.0F); + this.cow_leg_2_L = new ModelRenderer(this, 0, 16); + this.cow_leg_2_L.setRotationPoint(4.0F, 12.0F, 7.0F); + this.cow_leg_2_L.addBox(-2.0F, 0.0F, -2.0F, 4, 12, 4, 0.0F); + this.VillagerChest = new ModelRenderer(this, 16, 20); + this.VillagerChest.setRotationPoint(0.20000000000000004F, -15.0F, -4.799999999999999F); + this.VillagerChest.addBox(-4.0F, 0.0F, -3.0F, 8, 12, 6, 0.0F); + this.cow_leg_1_L = new ModelRenderer(this, 0, 16); + this.cow_leg_1_L.setRotationPoint(4.0F, 12.0F, -6.0F); + this.cow_leg_1_L.addBox(-2.0F, 0.0F, -2.0F, 4, 12, 4, 0.0F); + this.cow_leg_2_R = new ModelRenderer(this, 0, 16); + this.cow_leg_2_R.setRotationPoint(-4.0F, 12.0F, 7.0F); + this.cow_leg_2_R.addBox(-2.0F, 0.0F, -2.0F, 4, 12, 4, 0.0F); + this.cow_leg_1_R = new ModelRenderer(this, 0, 16); + this.cow_leg_1_R.setRotationPoint(-4.0F, 12.0F, -6.0F); + this.cow_leg_1_R.addBox(-2.0F, 0.0F, -2.0F, 4, 12, 4, 0.0F); + this.VillagerHead.addChild(this.VillagerNose); + } + + @Override + public void render(Entity entity, float f, float f1, float f2, float f3, float f4, float f5) { + this.VillagerLHand.render(f5); + this.VillagerCoat.render(f5); + this.VillagerRHand.render(f5); + this.cow_belly.render(f5); + this.VillagerCenterHand.render(f5); + this.VillagerHead.render(f5); + this.cow_body.render(f5); + this.cow_leg_2_L.render(f5); + this.VillagerChest.render(f5); + this.cow_leg_1_L.render(f5); + this.cow_leg_2_R.render(f5); + this.cow_leg_1_R.render(f5); + } + + /** + * This is a helper function from Tabula to set the rotation of model parts + */ + public void setRotateAngle(ModelRenderer modelRenderer, float x, float y, float z) { + modelRenderer.rotateAngleX = x; + modelRenderer.rotateAngleY = y; + modelRenderer.rotateAngleZ = z; + } + + @Override + public void setRotationAngles(float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch, float scaleFactor, Entity entityIn) { + this.cow_leg_1_L.rotateAngleX = MathHelper.cos(limbSwing * 0.6662F) * 1.4F * limbSwingAmount; + this.cow_leg_2_L.rotateAngleX = MathHelper.cos(limbSwing * 0.6662F) * 1.4F * limbSwingAmount; + + this.cow_leg_1_R.rotateAngleX = - MathHelper.cos(limbSwing * 0.6662F) * 1.4F * limbSwingAmount; + this.cow_leg_2_R.rotateAngleX = - MathHelper.cos(limbSwing * 0.6662F) * 1.4F * limbSwingAmount; + + this.VillagerHead.rotateAngleY = netHeadYaw * 0.017453292F; + this.VillagerHead.rotateAngleX = headPitch * 0.017453292F; + //super.setRotationAngles(limbSwing, limbSwingAmount, ageInTicks, netHeadYaw, headPitch, scaleFactor, entityIn); + } +} diff --git a/src/main/java/com/somebody/idlframewok/entity/creatures/model/ModelIDLConstruction.java b/src/main/java/com/somebody/idlframewok/entity/creatures/model/ModelIDLConstruction.java new file mode 100644 index 0000000..c0d40d7 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/entity/creatures/model/ModelIDLConstruction.java @@ -0,0 +1,162 @@ +package com.somebody.idlframewok.entity.creatures.model; + +import com.somebody.idlframewok.entity.creatures.buildings.EntityIdlBuildingBase; +import com.somebody.idlframewok.util.CommonDef; +import net.minecraft.client.model.ModelBase; +import net.minecraft.client.model.ModelRenderer; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.entity.Entity; +import net.minecraft.util.math.Vec3d; + +/** + * ModelIDLConstruction - TaoismDeepLake + * Created using Tabula 7.1.0 + */ +public class ModelIDLConstruction extends ModelBase { + public ModelRenderer Pillar; + public ModelRenderer Floor; + public ModelRenderer Target; + public ModelRenderer CornerBoard; + public ModelRenderer CornerBoard_1; + public ModelRenderer CornerBoard_2; + public ModelRenderer CornerBoard_3; + + public ModelIDLConstruction() { + this.textureWidth = 64; + this.textureHeight = 64; + this.Pillar = new ModelRenderer(this, 0, 0); + this.Pillar.setRotationPoint(0.0F, 24.0F, 0.0F); + this.Pillar.addBox(-2.0F, -4.0F, -2.0F, 4, 4, 4, 0.0F); + this.CornerBoard = new ModelRenderer(this, 44, 0); + this.CornerBoard.setRotationPoint(8.0F, 23.5F, -8.0F); + this.CornerBoard.addBox(0.0F, 0.0F, -1.0F, 4, 1, 2, 0.0F); + this.setRotateAngle(CornerBoard, 0.0F, 0.7853981633974483F, 0.0F); + this.Target = new ModelRenderer(this, 32, 0); + this.Target.setRotationPoint(0.0F, 0.0F, 0.0F); + this.Target.addBox(-2.0F, -2.0F, -2.0F, 4, 4, 4, 0.0F); + this.CornerBoard_2 = new ModelRenderer(this, 46, 6); + this.CornerBoard_2.setRotationPoint(-8.0F, 23.5F, 8.0F); + this.CornerBoard_2.addBox(0.0F, 0.0F, -1.0F, 4, 1, 2, 0.0F); + this.setRotateAngle(CornerBoard_2, 0.0F, -2.356194490192345F, 0.0F); + this.Floor = new ModelRenderer(this, 8, 0); + this.Floor.setRotationPoint(0.0F, 23.5F, 0.0F); + this.Floor.addBox(-4.0F, 0.0F, -4.0F, 8, 1, 8, 0.0F); + this.CornerBoard_1 = new ModelRenderer(this, 48, 3); + this.CornerBoard_1.setRotationPoint(8.0F, 23.5F, 8.0F); + this.CornerBoard_1.addBox(0.0F, 0.0F, -1.0F, 4, 1, 2, 0.0F); + this.setRotateAngle(CornerBoard_1, 0.0F, -0.7853981633974483F, 0.0F); + this.CornerBoard_3 = new ModelRenderer(this, 0, 9); + this.CornerBoard_3.setRotationPoint(-8.0F, 23.5F, -8.0F); + this.CornerBoard_3.addBox(0.0F, 0.0F, -1.0F, 4, 1, 2, 0.0F); + this.setRotateAngle(CornerBoard_3, 0.0F, 2.356194490192345F, 0.0F); + } + + @Override + public void render(Entity entity, float f, float f1, float f2, float f3, float f4, float f5) { + GlStateManager.pushMatrix(); + GlStateManager.translate(this.Pillar.offsetX, this.Pillar.offsetY, this.Pillar.offsetZ); + GlStateManager.translate(this.Pillar.rotationPointX * f5, this.Pillar.rotationPointY * f5, this.Pillar.rotationPointZ * f5); + GlStateManager.scale(1.0D, 4.0D, 1.0D); + GlStateManager.translate(-this.Pillar.offsetX, -this.Pillar.offsetY, -this.Pillar.offsetZ); + GlStateManager.translate(-this.Pillar.rotationPointX * f5, -this.Pillar.rotationPointY * f5, -this.Pillar.rotationPointZ * f5); + this.Pillar.render(f5); + GlStateManager.popMatrix(); + GlStateManager.pushMatrix(); + GlStateManager.translate(this.CornerBoard.offsetX, this.CornerBoard.offsetY, this.CornerBoard.offsetZ); + GlStateManager.translate(this.CornerBoard.rotationPointX * f5, this.CornerBoard.rotationPointY * f5, this.CornerBoard.rotationPointZ * f5); + GlStateManager.scale(4.0D, 1.0D, 4.0D); + GlStateManager.translate(-this.CornerBoard.offsetX, -this.CornerBoard.offsetY, -this.CornerBoard.offsetZ); + GlStateManager.translate(-this.CornerBoard.rotationPointX * f5, -this.CornerBoard.rotationPointY * f5, -this.CornerBoard.rotationPointZ * f5); + this.CornerBoard.render(f5); + GlStateManager.popMatrix(); + GlStateManager.pushMatrix(); + GlStateManager.translate(this.Target.offsetX, this.Target.offsetY, this.Target.offsetZ); + GlStateManager.translate(this.Target.rotationPointX * f5, this.Target.rotationPointY * f5, this.Target.rotationPointZ * f5); + GlStateManager.scale(5.0D, 5.0D, 5.0D); + GlStateManager.translate(-this.Target.offsetX, -this.Target.offsetY, -this.Target.offsetZ); + GlStateManager.translate(-this.Target.rotationPointX * f5, -this.Target.rotationPointY * f5, -this.Target.rotationPointZ * f5); + this.Target.render(f5); + GlStateManager.popMatrix(); + GlStateManager.pushMatrix(); + GlStateManager.translate(this.CornerBoard_2.offsetX, this.CornerBoard_2.offsetY, this.CornerBoard_2.offsetZ); + GlStateManager.translate(this.CornerBoard_2.rotationPointX * f5, this.CornerBoard_2.rotationPointY * f5, this.CornerBoard_2.rotationPointZ * f5); + GlStateManager.scale(4.0D, 1.0D, 4.0D); + GlStateManager.translate(-this.CornerBoard_2.offsetX, -this.CornerBoard_2.offsetY, -this.CornerBoard_2.offsetZ); + GlStateManager.translate(-this.CornerBoard_2.rotationPointX * f5, -this.CornerBoard_2.rotationPointY * f5, -this.CornerBoard_2.rotationPointZ * f5); + this.CornerBoard_2.render(f5); + GlStateManager.popMatrix(); + GlStateManager.pushMatrix(); + GlStateManager.translate(this.Floor.offsetX, this.Floor.offsetY, this.Floor.offsetZ); + GlStateManager.translate(this.Floor.rotationPointX * f5, this.Floor.rotationPointY * f5, this.Floor.rotationPointZ * f5); + GlStateManager.scale(2.5D, 1.0D, 2.5D); + GlStateManager.translate(-this.Floor.offsetX, -this.Floor.offsetY, -this.Floor.offsetZ); + GlStateManager.translate(-this.Floor.rotationPointX * f5, -this.Floor.rotationPointY * f5, -this.Floor.rotationPointZ * f5); + this.Floor.render(f5); + GlStateManager.popMatrix(); + GlStateManager.pushMatrix(); + GlStateManager.translate(this.CornerBoard_1.offsetX, this.CornerBoard_1.offsetY, this.CornerBoard_1.offsetZ); + GlStateManager.translate(this.CornerBoard_1.rotationPointX * f5, this.CornerBoard_1.rotationPointY * f5, this.CornerBoard_1.rotationPointZ * f5); + GlStateManager.scale(4.0D, 1.0D, 4.0D); + GlStateManager.translate(-this.CornerBoard_1.offsetX, -this.CornerBoard_1.offsetY, -this.CornerBoard_1.offsetZ); + GlStateManager.translate(-this.CornerBoard_1.rotationPointX * f5, -this.CornerBoard_1.rotationPointY * f5, -this.CornerBoard_1.rotationPointZ * f5); + this.CornerBoard_1.render(f5); + GlStateManager.popMatrix(); + GlStateManager.pushMatrix(); + GlStateManager.translate(this.CornerBoard_3.offsetX, this.CornerBoard_3.offsetY, this.CornerBoard_3.offsetZ); + GlStateManager.translate(this.CornerBoard_3.rotationPointX * f5, this.CornerBoard_3.rotationPointY * f5, this.CornerBoard_3.rotationPointZ * f5); + GlStateManager.scale(4.0D, 1.0D, 4.0D); + GlStateManager.translate(-this.CornerBoard_3.offsetX, -this.CornerBoard_3.offsetY, -this.CornerBoard_3.offsetZ); + GlStateManager.translate(-this.CornerBoard_3.rotationPointX * f5, -this.CornerBoard_3.rotationPointY * f5, -this.CornerBoard_3.rotationPointZ * f5); + this.CornerBoard_3.render(f5); + GlStateManager.popMatrix(); + } + + /** + * This is a helper function from Tabula to set the rotation of model parts + */ + public void setRotateAngle(ModelRenderer modelRenderer, float x, float y, float z) { + modelRenderer.rotateAngleX = x; + modelRenderer.rotateAngleY = y; + modelRenderer.rotateAngleZ = z; + } + + int timeToReady = CommonDef.TICK_PER_SECOND; + float maxAngle = 3.14159f/2f; + + @Override + public void setRotationAngles(float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch, float scaleFactor, Entity entityIn) { + this.Target.rotateAngleY = ageInTicks * 5f; + if (entityIn instanceof EntityIdlBuildingBase) + { + EntityIdlBuildingBase buildingBase = (EntityIdlBuildingBase) entityIn; + Vec3d vec = buildingBase.getCurBuildingVector().rotateYaw(entityIn.rotationYaw); + float offset = 0f; + this.Target.offsetX = (float) (vec.x + offset); + this.Target.offsetY = (float) (-vec.y + offset); + this.Target.offsetZ = (float) (vec.z + offset); + +// if (ageInTicks <= timeToReady) { +// CornerBoard.rotateAngleZ = -maxAngle * (ageInTicks / timeToReady); +// CornerBoard_1.rotateAngleZ = maxAngle * (ageInTicks / timeToReady); +// CornerBoard_2.rotateAngleZ = -maxAngle * (ageInTicks / timeToReady); +// CornerBoard_3.rotateAngleZ = maxAngle * (ageInTicks / timeToReady); +// +// CornerBoard.rotateAngleX = -maxAngle * (ageInTicks / timeToReady); +// CornerBoard_1.rotateAngleX = maxAngle * (ageInTicks / timeToReady); +// CornerBoard_2.rotateAngleX = -maxAngle * (ageInTicks / timeToReady); +// CornerBoard_3.rotateAngleX = maxAngle * (ageInTicks / timeToReady); +// } +// else { +// CornerBoard.rotateAngleZ = maxAngle; +// CornerBoard_1.rotateAngleZ = maxAngle; +// CornerBoard_2.rotateAngleZ = maxAngle; +// CornerBoard_3.rotateAngleZ = maxAngle; +// CornerBoard.rotateAngleX = maxAngle; +// CornerBoard_1.rotateAngleX = maxAngle; +// CornerBoard_2.rotateAngleX = maxAngle; +// CornerBoard_3.rotateAngleX = maxAngle; +// } + } + //this.Target.offsetX = + } +} diff --git a/src/main/java/com/somebody/idlframewok/entity/creatures/model/ModelMoroonBeacon.java b/src/main/java/com/somebody/idlframewok/entity/creatures/model/ModelMoroonBeacon.java new file mode 100644 index 0000000..d2cec6e --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/entity/creatures/model/ModelMoroonBeacon.java @@ -0,0 +1,88 @@ +package com.somebody.idlframewok.entity.creatures.model; + +import net.minecraft.client.model.ModelBase; +import net.minecraft.client.model.ModelRenderer; +import net.minecraft.entity.Entity; + +/** + * MoroonBeacon - TaoismDeeplake + * Created using Tabula 7.1.0 + */ +public class ModelMoroonBeacon extends ModelBase { + public ModelRenderer CenterPillar; + public ModelRenderer BuildBase; + public ModelRenderer RotationBase; + public ModelRenderer RotationBase_1; + public ModelRenderer SidePillar; + public ModelRenderer SidePillar_1; + public ModelRenderer SidePillar_2; + public ModelRenderer SidePillar_3; + public ModelRenderer SidePillar_4; + public ModelRenderer SidePillar_5; + + public ModelMoroonBeacon() { + this.textureWidth = 64; + this.textureHeight = 32; + this.SidePillar = new ModelRenderer(this, 0, 0); + this.SidePillar.setRotationPoint(0.0F, 0.0F, -8.0F); + this.SidePillar.addBox(-1.0F, 1.0F, -1.0F, 2, 8, 2, 0.0F); + this.SidePillar_5 = new ModelRenderer(this, 0, 0); + this.SidePillar_5.setRotationPoint(0.0F, 8.0F, 0.0F); + this.SidePillar_5.addBox(-1.0F, -1.0F, -7.0F, 2, 2, 14, 0.0F); + this.SidePillar_1 = new ModelRenderer(this, 0, 0); + this.SidePillar_1.setRotationPoint(0.0F, 0.0F, 8.0F); + this.SidePillar_1.addBox(-1.0F, 1.0F, -1.0F, 2, 8, 2, 0.0F); + this.RotationBase_1 = new ModelRenderer(this, 0, 0); + this.RotationBase_1.setRotationPoint(0.0F, 0.0F, 0.0F); + this.RotationBase_1.addBox(0.0F, 0.0F, 0.0F, 0, 0, 0, 0.0F); + this.SidePillar_3 = new ModelRenderer(this, 0, 0); + this.SidePillar_3.setRotationPoint(0.0F, 0.0F, -8.0F); + this.SidePillar_3.addBox(-1.0F, 1.0F, -1.0F, 2, 8, 2, 0.0F); + this.RotationBase = new ModelRenderer(this, 0, 0); + this.RotationBase.setRotationPoint(0.0F, 9.0F, 0.0F); + this.RotationBase.addBox(0.0F, 0.0F, 0.0F, 0, 0, 0, 0.0F); + this.SidePillar_2 = new ModelRenderer(this, 0, 0); + this.SidePillar_2.setRotationPoint(0.0F, 8.0F, 0.0F); + this.SidePillar_2.addBox(-1.0F, -1.0F, -7.0F, 2, 2, 14, 0.0F); + this.SidePillar_4 = new ModelRenderer(this, 0, 0); + this.SidePillar_4.setRotationPoint(0.0F, 0.0F, 8.0F); + this.SidePillar_4.addBox(-1.0F, 1.0F, -1.0F, 2, 8, 2, 0.0F); + this.CenterPillar = new ModelRenderer(this, 0, 0); + this.CenterPillar.setRotationPoint(0.0F, 0.0F, 0.0F); + this.CenterPillar.addBox(-2.0F, -8.0F, -2.0F, 4, 32, 4, 0.0F); + this.BuildBase = new ModelRenderer(this, 0, 0); + this.BuildBase.setRotationPoint(0.0F, 24.0F, 0.0F); + this.BuildBase.addBox(-4.0F, -0.5F, -4.0F, 8, 1, 8, 0.0F); + this.RotationBase.addChild(this.SidePillar); + this.RotationBase_1.addChild(this.SidePillar_5); + this.RotationBase.addChild(this.SidePillar_1); + this.RotationBase_1.addChild(this.SidePillar_3); + this.RotationBase.addChild(this.SidePillar_2); + this.RotationBase_1.addChild(this.SidePillar_4); + } + + @Override + public void render(Entity entity, float f, float f1, float f2, float f3, float f4, float f5) { + this.RotationBase_1.render(f5); + this.RotationBase.render(f5); + this.CenterPillar.render(f5); + this.BuildBase.render(f5); + } + + + @Override + public void setRotationAngles(float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch, float scaleFactor, Entity entityIn) { + + this.RotationBase.rotateAngleY = (float) (Math.sin(ageInTicks * 0.017453292F) * 5f); + this.RotationBase_1.rotateAngleY = ageInTicks * 0.017453292F * -10.1f; + } + + /** + * This is a helper function from Tabula to set the rotation of model parts + */ + public void setRotationAngles(ModelRenderer modelRenderer, float x, float y, float z) { + modelRenderer.rotateAngleX = x; + modelRenderer.rotateAngleY = y; + modelRenderer.rotateAngleZ = z; + } +} diff --git a/src/main/java/com/somebody/idlframewok/entity/creatures/model/ModelTurretPrototype.java b/src/main/java/com/somebody/idlframewok/entity/creatures/model/ModelTurretPrototype.java new file mode 100644 index 0000000..32ad691 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/entity/creatures/model/ModelTurretPrototype.java @@ -0,0 +1,72 @@ +package com.somebody.idlframewok.entity.creatures.model; + +import net.minecraft.client.model.ModelBase; +import net.minecraft.client.model.ModelRenderer; +import net.minecraft.entity.Entity; +import net.minecraft.util.math.MathHelper; + +/** + * TurrentPrototype - TaoismDeepLake + * Created using Tabula 7.1.0 + */ +public class ModelTurretPrototype extends ModelBase { + public ModelRenderer BaseHead; + public ModelRenderer BaseRoot; + public ModelRenderer BarrelLookBase; + public ModelRenderer BodyL; + public ModelRenderer HeadR; + public ModelRenderer Barrel; + + public ModelTurretPrototype() { + this.textureWidth = 128; + this.textureHeight = 64; + this.Barrel = new ModelRenderer(this, 10, 17); + this.Barrel.mirror = true; + this.Barrel.setRotationPoint(0.0F, 0.0F, 0.0F); + this.Barrel.addBox(-1.0F, -1.0F, 0.0F, 2, 2, 32, 0.0F); + this.BarrelLookBase = new ModelRenderer(this, 45, 0); + this.BarrelLookBase.setRotationPoint(0.0F, 0.0F, 0.0F); + this.BarrelLookBase.addBox(-4.0F, -2.0F, -2.0F, 8, 4, 4, 0.0F); + this.HeadR = new ModelRenderer(this, 0, 17); + this.HeadR.setRotationPoint(0.0F, 0.0F, 0.0F); + this.HeadR.addBox(3.0F, -8.0F, -8.0F, 5, 16, 16, 0.0F); + this.BaseHead = new ModelRenderer(this, 0, 0); + this.BaseHead.setRotationPoint(0.0F, 16.0F, 0.0F); + this.BaseHead.addBox(-1.0F, 0.0F, -1.0F, 2, 2, 2, 0.0F); + this.BodyL = new ModelRenderer(this, 60, 0); + this.BodyL.setRotationPoint(0.0F, 0.0F, 0.0F); + this.BodyL.addBox(-8.0F, -8.0F, -8.0F, 5, 16, 16, 0.0F); + this.BaseRoot = new ModelRenderer(this, 0, 0); + this.BaseRoot.setRotationPoint(0.0F, 16.0F, 0.0F); + this.BaseRoot.addBox(-2.0F, 0.0F, -2.0F, 4, 10, 4, 0.0F); + this.BarrelLookBase.addChild(this.Barrel); + this.BaseHead.addChild(this.BarrelLookBase); + this.BaseHead.addChild(this.HeadR); + this.BaseHead.addChild(this.BodyL); + } + + @Override + public void render(Entity entityIn, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch, float scale) { + this.setRotationAngles(limbSwing, limbSwingAmount, ageInTicks, netHeadYaw, headPitch, scale, entityIn); + this.BaseHead.render(scale); + this.BaseRoot.render(scale); +// this.BaseHead.renderWithRotation(scale); +// this.BaseRoot.renderWithRotation(scale); + } + + /** + * This is a helper function from Tabula to set the rotation of model parts + */ + public void setRotateAngle(ModelRenderer modelRenderer, float x, float y, float z) { + modelRenderer.rotateAngleX = x; + modelRenderer.rotateAngleY = y; + modelRenderer.rotateAngleZ = z; + } + + @Override + public void setRotationAngles(float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch, float scaleFactor, Entity entityIn) { + this.BarrelLookBase.offsetZ = MathHelper.cos(limbSwing * 0.6662F) * 0.5F * limbSwingAmount; + this.BaseHead.rotateAngleY = netHeadYaw * 0.017453292F; + this.BarrelLookBase.rotateAngleX = 3.14F + headPitch * 0.017453292F; + } +} diff --git a/src/main/java/com/somebody/idlframewok/entity/creatures/moroon/EntityMorBlindingAssassin.java b/src/main/java/com/somebody/idlframewok/entity/creatures/moroon/EntityMorBlindingAssassin.java new file mode 100644 index 0000000..61aeb17 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/entity/creatures/moroon/EntityMorBlindingAssassin.java @@ -0,0 +1,173 @@ +package com.somebody.idlframewok.entity.creatures.moroon; + +import com.somebody.idlframewok.util.CommonDef; +import com.somebody.idlframewok.util.EntityUtil; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.SharedMonsterAttributes; +import net.minecraft.entity.ai.EntityAIAttackMelee; +import net.minecraft.entity.ai.EntityAIHurtByTarget; +import net.minecraft.entity.ai.EntityAILookIdle; +import net.minecraft.entity.ai.EntityAIMoveThroughVillage; +import net.minecraft.entity.ai.EntityAIMoveTowardsRestriction; +import net.minecraft.entity.ai.EntityAISwimming; +import net.minecraft.entity.ai.EntityAIWanderAvoidWater; +import net.minecraft.entity.ai.EntityAIWatchClosest; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Items; +import net.minecraft.init.MobEffects; +import net.minecraft.init.SoundEvents; +import net.minecraft.inventory.EntityEquipmentSlot; +import net.minecraft.item.ItemStack; +import net.minecraft.potion.PotionEffect; +import net.minecraft.util.math.Vec3d; +import net.minecraft.world.World; +import net.minecraftforge.common.MinecraftForge; + +public class EntityMorBlindingAssassin extends EntityMoroonUnitBase { + int stealthNeedTick = CommonDef.TICK_PER_SECOND * 10; + int stealthCounter = 0; + //A creatures that teleports whenever its hit + public EntityMorBlindingAssassin(World worldIn) { + super(worldIn); + spawn_without_darkness = false; + spawn_without_moroon_ground = false; + + inflictBerserkBuff =false; + + experienceValue = 30; + //MinecraftForge.EVENT_BUS.register(this); + setItemStackToSlot(EntityEquipmentSlot.OFFHAND, new ItemStack(Items.FLINT_AND_STEEL)); + } + + protected void initEntityAI() + { + this.tasks.addTask(0, new EntityAISwimming(this)); + this.tasks.addTask(2, new EntityAIAttackMelee(this, 1.0D, false)); + //this.tasks.addTask(3, new EntityAIAvoidEntity(this, EntityMoroonBombBeacon.class, 8.0F, 0.6D, 0.6D)); + this.tasks.addTask(5, new EntityAIMoveTowardsRestriction(this, 1.0D)); + this.tasks.addTask(6, new EntityAIMoveThroughVillage(this, 1.0D, false)); + this.tasks.addTask(7, new EntityAIWanderAvoidWater(this, 1.0D)); + this.tasks.addTask(8, new EntityAIWatchClosest(this, EntityPlayer.class, 8.0F)); + this.tasks.addTask(8, new EntityAILookIdle(this)); + this.applyEntityAI(); + } + + protected void applyEntityAI() + { + //wont move through village + this.targetTasks.addTask(1, new EntityAIHurtByTarget(this, true, new Class[] {EntityMoroonUnitBase.class})); + applyGeneralAI(); + } + + protected void applyEntityAttributes() + { + super.applyEntityAttributes(); + + setAttr(64, 0.4, 7, 2, 16); + } + + @Override + public void onUpdate() { + super.onUpdate(); + //IdlFramework.Log("Tick"); + if (!this.world.isRemote) + { + if (stealthCounter >= stealthNeedTick || this.world.isRainingAt(getPosition())) + { + if (world.getWorldTime() % CommonDef.TICK_PER_SECOND == 3) { + addPotionEffect(new PotionEffect(MobEffects.INVISIBILITY, CommonDef.TICK_PER_SECOND * 2, 0)); + + } + stealthCounter++; + } + } + } + +// @SubscribeEvent +// public void onHit(LivingHurtEvent evt) +// { +// Entity attacker = evt.getSource().getTrueSource(); +// if (attacker == this) +// { +// +// +// } +// } + + @Override + public boolean attackEntityAsMob(Entity entityIn) { + boolean result = super.attackEntityAsMob(entityIn); + stealthCounter = 0; + EntityUtil.TryRemoveGivenBuff(this, MobEffects.INVISIBILITY); + if (result) + { + if (entityIn instanceof EntityLivingBase) + { + EntityLivingBase target = (EntityLivingBase) entityIn; + target.addPotionEffect(new PotionEffect(MobEffects.BLINDNESS, + (int) (CommonDef.TICK_PER_SECOND * this.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).getAttributeValue()), + 0)); + fiveRandomTeleport(); + } + } + + return result; + } + + private void fiveRandomTeleport() + { + int trial = 5; + while(trial > 0) + { + if (teleportRandomly()) + { + break; + } + trial--; + } + } + + /** + * Teleport the enderman to a random nearby position + */ + protected boolean teleportRandomly() + { + double d0 = this.posX + (this.rand.nextDouble() - 0.5D) * 64.0D; + double d1 = this.posY + (double)(this.rand.nextInt(64) - 32); + double d2 = this.posZ + (this.rand.nextDouble() - 0.5D) * 64.0D; + return this.teleportTo(d0, d1, d2); + } + + /** + * Teleport the enderman to another entity + */ + protected boolean teleportToEntity(Entity p_70816_1_) + { + Vec3d vec3d = new Vec3d(this.posX - p_70816_1_.posX, this.getEntityBoundingBox().minY + (double)(this.height / 2.0F) - p_70816_1_.posY + (double)p_70816_1_.getEyeHeight(), this.posZ - p_70816_1_.posZ); + vec3d = vec3d.normalize(); + double d0 = 16.0D; + double d1 = this.posX + (this.rand.nextDouble() - 0.5D) * 8.0D - vec3d.x * 16.0D; + double d2 = this.posY + (double)(this.rand.nextInt(16) - 8) - vec3d.y * 16.0D; + double d3 = this.posZ + (this.rand.nextDouble() - 0.5D) * 8.0D - vec3d.z * 16.0D; + return this.teleportTo(d1, d2, d3); + } + + /** + * Teleport the enderman + */ + private boolean teleportTo(double x, double y, double z) + { + net.minecraftforge.event.entity.living.EnderTeleportEvent event = new net.minecraftforge.event.entity.living.EnderTeleportEvent(this, x, y, z, 0); + if (MinecraftForge.EVENT_BUS.post(event)) return false; + boolean flag = this.attemptTeleport(event.getTargetX(), event.getTargetY(), event.getTargetZ()); + + if (flag) + { + this.world.playSound((EntityPlayer)null, this.prevPosX, this.prevPosY, this.prevPosZ, SoundEvents.ENTITY_ENDERMEN_TELEPORT, this.getSoundCategory(), 1.0F, 1.0F); + this.playSound(SoundEvents.ENTITY_ENDERMEN_TELEPORT, 1.0F, 1.0F); + } + + return flag; + } +} diff --git a/src/main/java/com/somebody/idlframewok/entity/creatures/moroon/EntityMoroonFlickFighter.java b/src/main/java/com/somebody/idlframewok/entity/creatures/moroon/EntityMoroonFlickFighter.java new file mode 100644 index 0000000..35f7826 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/entity/creatures/moroon/EntityMoroonFlickFighter.java @@ -0,0 +1,161 @@ +package com.somebody.idlframewok.entity.creatures.moroon; + +import com.somebody.idlframewok.util.CommonDef; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.ai.EntityAIAttackMelee; +import net.minecraft.entity.ai.EntityAIHurtByTarget; +import net.minecraft.entity.ai.EntityAILookIdle; +import net.minecraft.entity.ai.EntityAIMoveThroughVillage; +import net.minecraft.entity.ai.EntityAIMoveTowardsRestriction; +import net.minecraft.entity.ai.EntityAISwimming; +import net.minecraft.entity.ai.EntityAIWanderAvoidWater; +import net.minecraft.entity.ai.EntityAIWatchClosest; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Items; +import net.minecraft.init.SoundEvents; +import net.minecraft.inventory.EntityEquipmentSlot; +import net.minecraft.item.ItemStack; +import net.minecraft.util.DamageSource; +import net.minecraft.util.math.Vec3d; +import net.minecraft.world.World; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.event.entity.living.LivingHurtEvent; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; + +public class EntityMoroonFlickFighter extends EntityMoroonUnitBase { + //A creatures that teleports whenever its hit + public EntityMoroonFlickFighter(World worldIn) { + super(worldIn); + spawn_without_darkness = true; + spawn_without_moroon_ground = false; + MinecraftForge.EVENT_BUS.register(this); + experienceValue = 15; + setItemStackToSlot(EntityEquipmentSlot.OFFHAND, new ItemStack(Items.ENDER_PEARL)); + } + + @Override + protected void dropLoot(boolean wasRecentlyHit, int lootingModifier, DamageSource source) { + super.dropLoot(wasRecentlyHit, lootingModifier, source); + + if (wasRecentlyHit) { +// if (getRNG().nextFloat() <= (1 + lootingModifier) * 0.3f +// ) { +// dropItem(ModItems.ITEM_ETHREAL_SWORD, rand.nextInt(1 + lootingModifier)); +// } + + dropItem(Items.ENDER_PEARL, rand.nextInt(1 + lootingModifier)); + } + } + + protected void initEntityAI() + { + this.tasks.addTask(0, new EntityAISwimming(this)); + this.tasks.addTask(2, new EntityAIAttackMelee(this, 1.0D, false)); + //this.tasks.addTask(3, new EntityAIAvoidEntity(this, EntityMoroonBombBeacon.class, 8.0F, 0.6D, 0.6D)); + this.tasks.addTask(5, new EntityAIMoveTowardsRestriction(this, 1.0D)); + this.tasks.addTask(6, new EntityAIMoveThroughVillage(this, 1.0D, false)); + this.tasks.addTask(7, new EntityAIWanderAvoidWater(this, 1.0D)); + this.tasks.addTask(8, new EntityAIWatchClosest(this, EntityPlayer.class, 8.0F)); + this.tasks.addTask(8, new EntityAILookIdle(this)); + this.applyEntityAI(); + } + + protected void applyEntityAI() + { + this.targetTasks.addTask(1, new EntityAIHurtByTarget(this, true, new Class[] {EntityMoroonUnitBase.class})); + applyGeneralAI(); + } + + protected void applyEntityAttributes() + { + super.applyEntityAttributes(); + + setAttr(32, 0.4, 6.0, 2, 16); + } + + @Override + public void onUpdate() { + super.onUpdate(); + //IdlFramework.Log("Tick"); + if (!this.world.isRemote) + { + if (world.getWorldTime() % CommonDef.TICK_PER_SECOND == 0) { + + } + } + } + + @SubscribeEvent + public void onHurt(LivingHurtEvent evt) + { + if (evt.getEntity() == this) + { + Entity attacker = evt.getSource().getTrueSource(); + if (attacker instanceof EntityLivingBase) + { + this.setAttackTarget((EntityLivingBase) attacker); + fiveRandomTeleport(); + } + else { + fiveRandomTeleport(); + } + } + } + + private void fiveRandomTeleport() + { + int trial = 5; + while(trial > 0) + { + if (teleportRandomly()) + { + break; + } + trial--; + } + } + + /** + * Teleport the enderman to a random nearby position + */ + protected boolean teleportRandomly() + { + double d0 = this.posX + (this.rand.nextDouble() - 0.5D) * 64.0D; + double d1 = this.posY + (double)(this.rand.nextInt(64) - 32); + double d2 = this.posZ + (this.rand.nextDouble() - 0.5D) * 64.0D; + return this.teleportTo(d0, d1, d2); + } + + /** + * Teleport the enderman to another entity + */ + protected boolean teleportToEntity(Entity p_70816_1_) + { + Vec3d vec3d = new Vec3d(this.posX - p_70816_1_.posX, this.getEntityBoundingBox().minY + (double)(this.height / 2.0F) - p_70816_1_.posY + (double)p_70816_1_.getEyeHeight(), this.posZ - p_70816_1_.posZ); + vec3d = vec3d.normalize(); + double d0 = 16.0D; + double d1 = this.posX + (this.rand.nextDouble() - 0.5D) * 8.0D - vec3d.x * 16.0D; + double d2 = this.posY + (double)(this.rand.nextInt(16) - 8) - vec3d.y * 16.0D; + double d3 = this.posZ + (this.rand.nextDouble() - 0.5D) * 8.0D - vec3d.z * 16.0D; + return this.teleportTo(d1, d2, d3); + } + + /** + * Teleport the enderman + */ + private boolean teleportTo(double x, double y, double z) + { + net.minecraftforge.event.entity.living.EnderTeleportEvent event = new net.minecraftforge.event.entity.living.EnderTeleportEvent(this, x, y, z, 0); + if (net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(event)) return false; + boolean flag = this.attemptTeleport(event.getTargetX(), event.getTargetY(), event.getTargetZ()); + + if (flag) + { + this.world.playSound((EntityPlayer)null, this.prevPosX, this.prevPosY, this.prevPosZ, SoundEvents.ENTITY_ENDERMEN_TELEPORT, this.getSoundCategory(), 1.0F, 1.0F); + this.playSound(SoundEvents.ENTITY_ENDERMEN_TELEPORT, 1.0F, 1.0F); + } + + return flag; + } +} diff --git a/src/main/java/com/somebody/idlframewok/entity/creatures/moroon/EntityMoroonGhostArcher.java b/src/main/java/com/somebody/idlframewok/entity/creatures/moroon/EntityMoroonGhostArcher.java new file mode 100644 index 0000000..97ebb17 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/entity/creatures/moroon/EntityMoroonGhostArcher.java @@ -0,0 +1,209 @@ +package com.somebody.idlframewok.entity.creatures.moroon; + +import com.somebody.idlframewok.util.CommonDef; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.IRangedAttackMob; +import net.minecraft.entity.SharedMonsterAttributes; +import net.minecraft.entity.ai.EntityAIAttackRanged; +import net.minecraft.entity.ai.EntityAIHurtByTarget; +import net.minecraft.entity.ai.EntityAILookIdle; +import net.minecraft.entity.ai.EntityAISwimming; +import net.minecraft.entity.ai.EntityAIWatchClosest; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.projectile.EntityArrow; +import net.minecraft.entity.projectile.EntityTippedArrow; +import net.minecraft.init.Items; +import net.minecraft.init.SoundEvents; +import net.minecraft.inventory.EntityEquipmentSlot; +import net.minecraft.item.ItemStack; +import net.minecraft.network.datasync.DataParameter; +import net.minecraft.network.datasync.DataSerializers; +import net.minecraft.network.datasync.EntityDataManager; +import net.minecraft.util.DamageSource; +import net.minecraft.util.math.MathHelper; +import net.minecraft.world.World; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +public class EntityMoroonGhostArcher extends EntityMoroonUnitBase implements IRangedAttackMob { + private int stationaryCounter = 0; + private int stationaryToInvisible = CommonDef.TICK_PER_SECOND * 5; + + //A creatures that does ranged attack and becomes invisible + public EntityMoroonGhostArcher(World worldIn) { + super(worldIn); + spawn_without_darkness = true; + spawn_without_moroon_ground = false; + MinecraftForge.EVENT_BUS.register(this); + experienceValue = 15; + setItemStackToSlot(EntityEquipmentSlot.MAINHAND, new ItemStack(Items.BOW)); + //setItemStackToSlot(EntityEquipmentSlot.HEAD, new ItemStack(ModItems.helmetSniper)); + setSneaking(true); + inflictBerserkBuff = false; + } + + public void updateAITasks() + { + setSneaking(true); + } + + @Override + protected void dropLoot(boolean wasRecentlyHit, int lootingModifier, DamageSource source) { + super.dropLoot(wasRecentlyHit, lootingModifier, source); + + if (wasRecentlyHit) { + //if (lootingModifier >= rand.nextInt(10)) +// { +// dropItem(ModItems.skill_hate_detect_sniper, 1); +// } +// +// if (lootingModifier >= rand.nextInt(10)) +// { +// dropItem(ModItems.helmetSniper, 1); +// } + + //dropItem(ModItems.skillFireBall, rand.nextInt(1 + lootingModifier)); + } + } + + protected void initEntityAI() + { + this.tasks.addTask(0, new EntityAISwimming(this)); + this.tasks.addTask(1, new EntityAIAttackRanged(this, 0.3f, CommonDef.TICK_PER_SECOND * 2, 32.0F)); + //this.tasks.addTask(2, new EntityAIAttackMelee(this, 1.0D, false)); + //this.tasks.addTask(3, new EntityAIAvoidEntity(this, EntityMoroonBombBeacon.class, 16.0F, 0.6D, 1D)); +// this.tasks.addTask(5, new EntityAIMoveTowardsRestriction(this, 1.0D)); +// this.tasks.addTask(6, new EntityAIMoveThroughVillage(this, 1.0D, false)); +// this.tasks.addTask(7, new EntityAIWanderAvoidWater(this, 1.0D)); + this.tasks.addTask(8, new EntityAIWatchClosest(this, EntityPlayer.class, 8.0F)); + this.tasks.addTask(8, new EntityAILookIdle(this)); + this.applyEntityAI(); + } + + protected void applyEntityAI() + { + this.targetTasks.addTask(1, new EntityAIHurtByTarget(this, true, EntityMoroonUnitBase.class)); + applyGeneralAI(); + } + + protected void applyEntityAttributes() + { + super.applyEntityAttributes(); + setAttr(32, 0.3, 20, 2, 20); + } + + @Override + public void onUpdate() { + super.onUpdate(); + if (!this.world.isRemote) + { + //if (this.getMoveHelper().isUpdating()) { + //double d0 = this.getMoveHelper().getSpeed(); + + // if ((getAttackTarget() != null) || (this.getActivePotionEffect(ModPotions.INTERFERENCE) != null)) +// { +// stationaryCounter=0; +// if (this.getActivePotionEffect(MobEffects.INVISIBILITY) != null) +// { +// EntityUtil.TryRemoveGivenBuff(this, MobEffects.INVISIBILITY); +// } +// +// }else { +// stationaryCounter++; +// if (stationaryCounter > stationaryToInvisible) { +// stationaryCounter = stationaryToInvisible; +// if (world.getWorldTime() % TICK_PER_SECOND == 0) { +// addPotionEffect(new PotionEffect(MobEffects.INVISIBILITY, TICK_PER_SECOND * 2, 0)); +// } +// } +// } + //} + } + } + + /** + * sets this entity's combat AI. + */ +// public void setCombatTask() +// { +// if (this.world != null && !this.world.isRemote) +// { +// this.tasks.removeTask(this.aiAttackOnCollide); +// this.tasks.removeTask(this.aiArrowAttack); +// ItemStack itemstack = this.getHeldItemMainhand(); +// +// if (itemstack.getItem() == Items.BOW) +// { +// int i = 20; +// +// if (this.world.getDifficulty() != EnumDifficulty.HARD) +// { +// i = 40; +// } +// +// this.aiArrowAttack.setAttackCooldown(i); +// this.tasks.addTask(4, this.aiArrowAttack); +// } +// else +// { +// this.tasks.addTask(4, this.aiAttackOnCollide); +// } +// } +// } + +// @SubscribeEvent +// public void onHurt(LivingHurtEvent evt) +// { +// if (evt.getEntity() == this) +// { +// Entity attacker = evt.getSource().getTrueSource(); +// if (attacker instanceof EntityLivingBase) +// { +// this.setAttackTarget((EntityLivingBase) attacker); +// } +// else { +// +// } +// } +// } + + protected EntityArrow getArrow(float p_190726_1_) + { + EntityTippedArrow entitytippedarrow = new EntityTippedArrow(this.world, this); + entitytippedarrow.setEnchantmentEffectsFromEntity(this, p_190726_1_); + return entitytippedarrow; + } + + @Override + public void attackEntityWithRangedAttack(EntityLivingBase target, float distanceFactor) { + //EntityMoroonBullet entityArrow = new EntityMoroonBullet(world, new ProjectileArgs((float) this.getEntityAttribute(ATTACK_DAMAGE).getAttributeValue())); + EntityArrow entityArrow = getArrow(distanceFactor); + double d0 = target.posY + (double)target.getEyeHeight() - 1.100000023841858D; + double d1 = target.posX - this.posX; + double d2 = d0 - entityArrow.posY; + double d3 = target.posZ - this.posZ; + float f = MathHelper.sqrt(d1 * d1 + d3 * d3) * 0.1F; + entityArrow.shoot(d1, d2 + (double)f, d3, 2F, (float)(f + 7 - this.world.getDifficulty().getDifficultyId() * 2)); + double damage = this.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).getAttributeValue(); + if (target.isSneaking()) + { + damage /= 5f; + } + entityArrow.setDamage(damage); + this.playSound(SoundEvents.ENTITY_SKELETON_SHOOT, 1.0F, 1.0F / (this.getRNG().nextFloat() * 0.4F + 0.8F)); + this.world.spawnEntity(entityArrow); + } + + private static final DataParameter SWINGING_ARMS = EntityDataManager.createKey(EntityMoroonGhostArcher.class, DataSerializers.BOOLEAN); + @SideOnly(Side.CLIENT) + public boolean isSwingingArms() + { + return ((Boolean)this.dataManager.get(SWINGING_ARMS)).booleanValue(); + } + + @Override + public void setSwingingArms(boolean swingingArms) { + this.dataManager.set(SWINGING_ARMS, Boolean.valueOf(swingingArms)); + } +} diff --git a/src/main/java/com/somebody/idlframewok/entity/creatures/moroon/EntityMoroonMindMage.java b/src/main/java/com/somebody/idlframewok/entity/creatures/moroon/EntityMoroonMindMage.java new file mode 100644 index 0000000..f8a9e27 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/entity/creatures/moroon/EntityMoroonMindMage.java @@ -0,0 +1,284 @@ +package com.somebody.idlframewok.entity.creatures.moroon; + +import java.util.List; + +import com.somebody.idlframewok.util.EntityUtil; +import com.somebody.idlframewok.util.IDLGeneral; +import net.minecraft.entity.EntityLiving; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.IRangedAttackMob; +import net.minecraft.entity.SharedMonsterAttributes; +import net.minecraft.entity.ai.EntityAIHurtByTarget; +import net.minecraft.entity.ai.EntityAILookIdle; +import net.minecraft.entity.ai.EntityAIMoveThroughVillage; +import net.minecraft.entity.ai.EntityAIMoveTowardsRestriction; +import net.minecraft.entity.ai.EntityAIPanic; +import net.minecraft.entity.ai.EntityAISwimming; +import net.minecraft.entity.ai.EntityAIWanderAvoidWater; +import net.minecraft.entity.ai.EntityAIWatchClosest; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.init.MobEffects; +import net.minecraft.inventory.EntityEquipmentSlot; +import net.minecraft.item.ItemStack; +import net.minecraft.pathfinding.Path; +import net.minecraft.util.DamageSource; +import net.minecraft.world.World; + +public class EntityMoroonMindMage extends EntityMoroonUnitBase implements IRangedAttackMob { + + public EntityMoroonMindMage(World worldIn) { + super(worldIn); + setItemStackToSlot(EntityEquipmentSlot.OFFHAND, new ItemStack(Blocks.LIT_PUMPKIN)); + } + + protected void initEntityAI() + { + this.tasks.addTask(0, new EntityAISwimming(this)); + this.tasks.addTask(1, new EntityAIPanic(this, 1.4D)); + //this.tasks.addTask(2, new EntityAIAttackRanged((IRangedAttackMob) this, 1.0D, 60, 10.0F)); + // this.tasks.addTask(3, new EntityAIAvoidEntity(this, EntityMoroonBombBeacon.class, 16.0F, 0.6D, 1.0D)); + this.tasks.addTask(5, new EntityAIMoveTowardsRestriction(this, 1.0D)); + this.tasks.addTask(7, new EntityAIWanderAvoidWater(this, 1.0D)); + this.tasks.addTask(8, new EntityAIWatchClosest(this, EntityPlayer.class, 8.0F)); + this.tasks.addTask(8, new EntityAILookIdle(this)); + this.applyEntityAI(); + } + + protected void applyEntityAI() + { + this.tasks.addTask(6, new EntityAIMoveThroughVillage(this, 1.0D, false)); + this.targetTasks.addTask(1, new EntityAIHurtByTarget(this, true, new Class[] {EntityMoroonUnitBase.class})); + applyGeneralAI(); + } + + @Override + protected void dropLoot(boolean wasRecentlyHit, int lootingModifier, DamageSource source) { + super.dropLoot(wasRecentlyHit, lootingModifier, source); +// if (rand.nextFloat() < 0.1f * getLevel()) +// { +// dropItem(ModItems.ITEM_HELM_SANITY, 1 + rand.nextInt(2 + lootingModifier)); +// } +// +// if (rand.nextFloat() < 0.01f * getLevel() * (1+lootingModifier)) +// { +// dropItem(ModItems.ITEM_EL_PSY_CONGROO, 1); +// } + } + + protected void applyEntityAttributes() + { + super.applyEntityAttributes(); + setAttr(32.0D, 0.33000000417232513D, 3.0D, 0.0D, 14.0D); + } + + @Override + public void onUpdate() { + super.onUpdate(); + //IdlFramework.Log("Tick"); + if (!this.world.isRemote) + { + //if (world.getWorldTime() % TICK_PER_SECOND == 1 && getActivePotionEffect(ModPotions.INTERFERENCE) == null) + { + float range = (float) getEntityAttribute(SharedMonsterAttributes.FOLLOW_RANGE).getAttributeValue(); + + if (getRank() > 1) + { + //strong mind mages resists mind magic, won't attack allies + if (EntityUtil.getAttitude(this, getAttackTarget()) == EntityUtil.ATTITUDE.FRIEND) + { + setAttackTarget(null); + } + } + + List entities = world.getEntitiesWithinAABB(EntityLivingBase.class, + IDLGeneral.ServerAABB(getPositionEyes(0f), range)); + + for (EntityLivingBase living: + entities + ) { + if (living == this) + continue; + + if (living instanceof EntityPlayer) + { + //ignore creative players + if (((EntityPlayer)living).capabilities.isCreativeMode) + { + continue; + } + } + + EntityUtil.ATTITUDE attitude = EntityUtil.getAttitude(this, living); + if (attitude == EntityUtil.ATTITUDE.FRIEND) { + ApplyMindControlToFriend(living); + } + else if (attitude == EntityUtil.ATTITUDE.HATE || living == getAttackTarget()) + { + ApplyMindControlToEnemy(living); + } + else if (living instanceof EntityLiving) + { + EntityLivingBase theirTarget = ((EntityLiving) living).getAttackTarget(); + if (EntityUtil.getAttitude(this, theirTarget) == EntityUtil.ATTITUDE.FRIEND) + { + ApplyMindControlToEnemy(living); + } + } + } + } + } + else { + //remote + } + } + + public float getSeconds() + { + return getLevel(); + } + + public int getBuffLevel() + { + return getRank() - 1; + } + + + public void ApplyMindControlToEnemy(EntityLivingBase livingBase) + { +// if (livingBase.getItemStackFromSlot(EntityEquipmentSlot.HEAD).getItem() instanceof ItemHelmSanity) +// { +// return; +// } + + if (getAttackTarget() == null) + { + Path path = getNavigator().getPathToEntityLiving(livingBase); + if (path != null) + { + setAttackTarget(livingBase); + } + else { + getLookHelper().setLookPosition(livingBase.posX, livingBase.posY, livingBase.posZ, 0.1f, 0.1f); + } + } + + int rank = getRank(); + + EntityUtil.TryRemoveGivenBuff(livingBase, MobEffects.INVISIBILITY); + EntityUtil.TryRemoveGivenBuff(livingBase, MobEffects.NIGHT_VISION); + + //EntityUtil.ApplyBuff(livingBase, ModPotions.CRIT_CHANCE_MINUS, getBuffLevel(), getSeconds()); + EntityUtil.ApplyBuff(livingBase, MobEffects.GLOWING, 0, getLevel()); + if (rank >= 2) + { + EntityUtil.ApplyBuff(livingBase, MobEffects.NAUSEA, getBuffLevel(), getSeconds()); + EntityUtil.ApplyBuff(livingBase, MobEffects.WEAKNESS, getBuffLevel(), getSeconds()); + if (rank >= 3) + { + EntityUtil.ApplyBuff(livingBase, MobEffects.BLINDNESS,0, getSeconds()); + EntityUtil.ApplyBuff(livingBase, MobEffects.SLOWNESS, getBuffLevel(), getSeconds()); + } + } + + TryChangeTargetToEnemy(livingBase); + } + + public void ApplyMindControlToFriend(EntityLivingBase livingBase) + { +// if (livingBase.getItemStackFromSlot(EntityEquipmentSlot.HEAD).getItem() instanceof ItemHelmSanity) +// { +// return; +// } + + int level = getLevel(); + int rank = getRank(); + + EntityUtil.ApplyBuff(livingBase, MobEffects.INVISIBILITY, getBuffLevel(), getSeconds()); + EntityUtil.TryRemoveGivenBuff(livingBase, MobEffects.GLOWING); + EntityUtil.TryRemoveGivenBuff(livingBase, MobEffects.BLINDNESS); + EntityUtil.TryRemoveGivenBuff(livingBase, MobEffects.NAUSEA); + + if (rank >= 2) + { + //EntityUtil.ApplyBuff(livingBase, ModPotions.CRIT_CHANCE_PLUS, getBuffLevel(), getSeconds()); + if (rank >= 3) + { + EntityUtil.ApplyBuff(livingBase, MobEffects.HASTE, getBuffLevel(), getSeconds()); + } + } + + TryChangeTargetToEnemy(livingBase); + } + + public void TryChangeTargetToEnemy(EntityLivingBase livingBase) + { + if (livingBase instanceof EntityLiving) + { + //change their targets + EntityLiving entityLiving = (EntityLiving) livingBase; + EntityLivingBase theirTarget = ((EntityLiving) livingBase).getAttackTarget(); + if (EntityUtil.getAttitude(this, theirTarget) != EntityUtil.ATTITUDE.HATE) + { + //try to make them attack only if the path ready + EntityLivingBase myTarget = getAttackTarget(); + if (myTarget != null) + { + Path path = entityLiving.getNavigator().getPathToEntityLiving(myTarget); + if (path != null) + { + setAttackTarget(myTarget); + } + else { + // target not available for mind-control subject, just cancel their current friendly fire + //and warn them of the target. Note this will weaken the disruption to enemy, too. + getLookHelper().setLookPosition(livingBase.posX, livingBase.posY, livingBase.posZ, 0.1f, 0.1f); + setAttackTarget(null); + } + } + else { + setAttackTarget(null); + } + } + } + } + + /** + * Attack the specified entity using a ranged attack. + */ + public void attackEntityWithRangedAttack(EntityLivingBase target, float distanceFactor) + { +// if (getRank() <= 2) +// { +// return; +// } +// +// double d0 = target.posY + (double)target.getEyeHeight() - 1.100000023841858D; +// double d1 = target.posX + target.motionX - this.posX; +// double d2 = d0 - this.posY; +// double d3 = target.posZ + target.motionZ - this.posZ; +// float f = MathHelper.sqrt(d1 * d1 + d3 * d3); +// PotionType potiontype = PotionTypes.HARMING; +// +// if (f >= 8.0F && !target.isPotionActive(MobEffects.SLOWNESS)) +// { +// potiontype = PotionTypes.SLOWNESS; +// } +// else if (f <= 3.0F && !target.isPotionActive(MobEffects.WEAKNESS) && this.rand.nextFloat() < 0.25F) +// { +// potiontype = PotionTypes.WEAKNESS; +// } +// +// EntityPotion entitypotion = new EntityPotion(this.world, this, PotionUtils.addPotionToItemStack(new ItemStack(Items.SPLASH_POTION), potiontype)); +// entitypotion.rotationPitch -= -20.0F; +// entitypotion.shoot(d1, d2 + (double)(f * 0.2F), d3, 0.75F, 8.0F); +// this.world.playSound((EntityPlayer)null, this.posX, this.posY, this.posZ, SoundEvents.ENTITY_WITCH_THROW, this.getSoundCategory(), 1.0F, 0.8F + this.rand.nextFloat() * 0.4F); +// this.world.spawnEntity(entitypotion); + + } + + @Override + public void setSwingingArms(boolean swingingArms) { + + } +} diff --git a/src/main/java/com/somebody/idlframewok/entity/creatures/moroon/EntityMoroonStandardInfantry.java b/src/main/java/com/somebody/idlframewok/entity/creatures/moroon/EntityMoroonStandardInfantry.java new file mode 100644 index 0000000..635fe26 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/entity/creatures/moroon/EntityMoroonStandardInfantry.java @@ -0,0 +1,184 @@ +package com.somebody.idlframewok.entity.creatures.moroon; + +import javax.annotation.Nullable; + +import com.somebody.idlframewok.entity.creatures.ai.EntityAIStrafeRangedAttack; +import com.somebody.idlframewok.util.CommonFunctions; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.IEntityLivingData; +import net.minecraft.entity.IRangedAttackMob; +import net.minecraft.entity.ai.EntityAIAttackMelee; +import net.minecraft.entity.ai.EntityAIAvoidEntity; +import net.minecraft.entity.ai.EntityAIHurtByTarget; +import net.minecraft.entity.ai.EntityAILookIdle; +import net.minecraft.entity.ai.EntityAIMoveThroughVillage; +import net.minecraft.entity.ai.EntityAIMoveTowardsRestriction; +import net.minecraft.entity.ai.EntityAISwimming; +import net.minecraft.entity.ai.EntityAIWanderAvoidWater; +import net.minecraft.entity.ai.EntityAIWatchClosest; +import net.minecraft.entity.item.EntityTNTPrimed; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.EntityEquipmentSlot; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.DamageSource; +import net.minecraft.util.math.MathHelper; +import net.minecraft.world.DifficultyInstance; +import net.minecraft.world.EnumDifficulty; +import net.minecraft.world.World; + +public class EntityMoroonStandardInfantry extends EntityMoroonUnitBase implements IRangedAttackMob { + private float bulletAccel = 0.1f; + private float errorModifier = 0.2f; + + public EntityMoroonStandardInfantry(World worldIn) { + super(worldIn); + this.setCombatTask(); + autoArmor = true; + } + + @Override + protected void dropLoot(boolean wasRecentlyHit, int lootingModifier, DamageSource source) { + super.dropLoot(wasRecentlyHit, lootingModifier, source); + + if (wasRecentlyHit) { + if (getRNG().nextFloat() < 0.1f * (1 + lootingModifier)) + { + //dropItem (ModItems.MOROON_RIFLE, 1); + } + } + } + + protected void applyEntityAttributes() + { + super.applyEntityAttributes(); + setAttr(32.0D, 0.33000000417232513D, 8.0D, 5.0D, 20.0D); + } + + @Override + public void readEntityFromNBT(NBTTagCompound compound) { + super.readEntityFromNBT(compound); + this.setCombatTask(); + } + + protected final EntityAIStrafeRangedAttack aiArrowAttack = new EntityAIStrafeRangedAttack<>(this, 1.0D, 5, 16.0F); + protected final EntityAIAttackMelee aiAttackOnCollide = new EntityAIAttackMelee(this, 1.2D, false) + { + /** + * Reset the task's internal state. Called when this task is interrupted by another one + */ + public void resetTask() + { + super.resetTask(); + EntityMoroonStandardInfantry.this.setSwingingArms(false); + } + /** + * Execute a one shot task or start executing a continuous task + */ + public void startExecuting() + { + super.startExecuting(); + EntityMoroonStandardInfantry.this.setSwingingArms(true); + } + }; + + protected void initEntityAI() + { + this.tasks.addTask(0, new EntityAISwimming(this)); + // this.tasks.addTask(2, new EntityAIAttackMelee(this, 1.0D, false)); + //this.tasks.addTask(3, new EntityAIAvoidEntity(this, EntityMoroonBombBeacon.class, 8.0F, 0.6D, 0.6D)); + this.tasks.addTask(3, new EntityAIAvoidEntity(this, EntityTNTPrimed.class, 8.0F, 0.6D, 0.6D)); + this.tasks.addTask(5, new EntityAIMoveTowardsRestriction(this, 1.0D)); + this.tasks.addTask(7, new EntityAIWanderAvoidWater(this, 1.0D)); + this.tasks.addTask(8, new EntityAIWatchClosest(this, EntityPlayer.class, 8.0F)); + this.tasks.addTask(8, new EntityAILookIdle(this)); + this.applyEntityAI(); + } + + protected void applyEntityAI() + { + this.tasks.addTask(6, new EntityAIMoveThroughVillage(this, 0.5D, false)); + this.targetTasks.addTask(1, new EntityAIHurtByTarget(this, true, new Class[] {EntityMoroonTainter.class})); + applyGeneralAI(); + } + + @Nullable + @Override + public IEntityLivingData onInitialSpawn(DifficultyInstance difficulty, @Nullable IEntityLivingData livingdata) { + this.setEquipmentBasedOnDifficulty(difficulty); + this.setEnchantmentBasedOnDifficulty(difficulty); + this.setCombatTask(); + return super.onInitialSpawn(difficulty, livingdata); + } + + protected void setEquipmentBasedOnDifficulty(DifficultyInstance difficulty) + { + super.setEquipmentBasedOnDifficulty(difficulty); + //this.setItemStackToSlot(EntityEquipmentSlot.MAINHAND, new ItemStack(ModItems.MOROON_RIFLE)); + } + + public void setItemStackToSlot(EntityEquipmentSlot slotIn, ItemStack stack) + { + super.setItemStackToSlot(slotIn, stack); + + if (!this.world.isRemote && slotIn == EntityEquipmentSlot.MAINHAND) + { + this.setCombatTask(); + } + } + + /** + * sets this entity's combat AI. + */ + public void setCombatTask() + { + if (this.world != null && !this.world.isRemote) + { + this.tasks.removeTask(this.aiAttackOnCollide); + this.tasks.removeTask(this.aiArrowAttack); + ItemStack itemstack = this.getHeldItemMainhand(); + + if (CommonFunctions.isItemRangedWeapon(itemstack)) + { + int i = 20; + + if (this.world.getDifficulty() != EnumDifficulty.HARD) + { + i = 40; + } + + this.aiArrowAttack.setAttackCooldown(i); + this.tasks.addTask(4, this.aiArrowAttack); + } + else + { + this.tasks.addTask(4, this.aiAttackOnCollide); + } + } + } + + @Override + public void attackEntityWithRangedAttack(EntityLivingBase target, float distanceFactor) { + double d0 = this.getDistanceSq(target); + double d1 = target.posX - this.posX; + double d2 = target.getEntityBoundingBox().minY + (double)(target.height / 2.0F) - (this.posY + (double)(this.height / 2.0F)); + double d3 = target.posZ - this.posZ; + + float dist = MathHelper.sqrt(MathHelper.sqrt(d0)); + float estimateHitTime = MathHelper.sqrt(2 * bulletAccel * dist); + +// EntityMoroonBullet entityIdlProjectile = new EntityMoroonBullet(this.world, new ProjectileArgs((float) EntityUtil.getAttack(this)), this, +// d1 + this.getRNG().nextGaussian() * (double)errorModifier + estimateHitTime * target.motionX, +// d2 + this.getRNG().nextGaussian() * (double)errorModifier + estimateHitTime * target.motionY, +// d3 + this.getRNG().nextGaussian() * (double)errorModifier + estimateHitTime * target.motionZ, +// bulletAccel); +// +// playSound(SoundEvents.BLOCK_PISTON_EXTEND, 1f, 2f); +// world.spawnEntity(entityIdlProjectile); + } + + @Override + public void setSwingingArms(boolean swingingArms) { + this.dataManager.set(SWINGING_ARMS, swingingArms); + } +} diff --git a/src/main/java/com/somebody/idlframewok/entity/creatures/moroon/EntityMoroonTainter.java b/src/main/java/com/somebody/idlframewok/entity/creatures/moroon/EntityMoroonTainter.java new file mode 100644 index 0000000..8514778 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/entity/creatures/moroon/EntityMoroonTainter.java @@ -0,0 +1,100 @@ +package com.somebody.idlframewok.entity.creatures.moroon; + +import net.minecraft.block.material.Material; +import net.minecraft.block.state.IBlockState; +import net.minecraft.entity.ai.EntityAIAttackMelee; +import net.minecraft.entity.ai.EntityAIHurtByTarget; +import net.minecraft.entity.ai.EntityAILookIdle; +import net.minecraft.entity.ai.EntityAIMoveThroughVillage; +import net.minecraft.entity.ai.EntityAIMoveTowardsRestriction; +import net.minecraft.entity.ai.EntityAISwimming; +import net.minecraft.entity.ai.EntityAIWanderAvoidWater; +import net.minecraft.entity.ai.EntityAIWatchClosest; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.inventory.EntityEquipmentSlot; +import net.minecraft.item.ItemStack; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.MathHelper; +import net.minecraft.world.World; + +public class EntityMoroonTainter extends EntityMoroonUnitBase { + + public float taintChance = 0.03f;//per tick + + public EntityMoroonTainter(World worldIn) { + super(worldIn); + setItemStackToSlot(EntityEquipmentSlot.OFFHAND, new ItemStack(Blocks.PUMPKIN)); + spawn_without_moroon_ground = true; + } + + protected void initEntityAI() + { + this.tasks.addTask(0, new EntityAISwimming(this)); + this.tasks.addTask(2, new EntityAIAttackMelee(this, 1.0D, false)); + this.tasks.addTask(5, new EntityAIMoveTowardsRestriction(this, 1.0D)); + this.tasks.addTask(7, new EntityAIWanderAvoidWater(this, 1.0D)); + this.tasks.addTask(8, new EntityAIWatchClosest(this, EntityPlayer.class, 8.0F)); + this.tasks.addTask(8, new EntityAILookIdle(this)); + this.applyEntityAI(); + } + + protected void applyEntityAI() + { + this.tasks.addTask(6, new EntityAIMoveThroughVillage(this, 1.0D, false)); + this.targetTasks.addTask(1, new EntityAIHurtByTarget(this, true, new Class[] {EntityMoroonTainter.class})); + applyGeneralAI(); + } + + protected void applyEntityAttributes() + { + super.applyEntityAttributes(); + setAttr(35.0D, 0.33000000417232513D, 3.0D, 0.0D, 14.0D); + } + + @Override + public void onUpdate() { + super.onUpdate(); + //IdlFramework.Log("Tick"); + if (!this.world.isRemote) + { + int i = MathHelper.floor(this.posX); + int j = MathHelper.floor(this.posY); + int k = MathHelper.floor(this.posZ); + + if (!net.minecraftforge.event.ForgeEventFactory.getMobGriefingEvent(this.world, this)) + { + return; + } + //Creates MoronBase block under foot + for (int l = 0; l < 4; ++l) + { + i = MathHelper.floor(this.posX + (double)((float)(l % 2 * 2 - 1) * 0.25F)); + j = MathHelper.floor(this.posY) - 1; + k = MathHelper.floor(this.posZ + (double)((float)(l / 2 % 2 * 2 - 1) * 0.25F)); + BlockPos blockpos = new BlockPos(i, j, k); + + if (rand.nextFloat() < taintChance * (2 - getHealth() / getMaxHealth()) && + legalTransformBlockstate(this.world.getBlockState(blockpos))) + { + this.world.setBlockState(blockpos, Blocks.PUMPKIN.getDefaultState()); + } + } + } + } + + public boolean legalTransformBlockstate(IBlockState state) + { + return state.getMaterial() != Material.AIR && state.getBlock() != Blocks.MOB_SPAWNER; + } + + public void onLivingUpdate() + { + super.onLivingUpdate(); + } + + public boolean getCanSpawnHere() + { + return super.getCanSpawnHere(); + } +} diff --git a/src/main/java/com/somebody/idlframewok/entity/creatures/moroon/EntityMoroonTideMaker.java b/src/main/java/com/somebody/idlframewok/entity/creatures/moroon/EntityMoroonTideMaker.java new file mode 100644 index 0000000..b6bd6a6 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/entity/creatures/moroon/EntityMoroonTideMaker.java @@ -0,0 +1,116 @@ +package com.somebody.idlframewok.entity.creatures.moroon; + +import com.somebody.idlframewok.util.Reference; +import net.minecraft.block.material.Material; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.ai.EntityAIAttackMelee; +import net.minecraft.entity.ai.EntityAIHurtByTarget; +import net.minecraft.entity.ai.EntityAILookIdle; +import net.minecraft.entity.ai.EntityAIMoveThroughVillage; +import net.minecraft.entity.ai.EntityAIMoveTowardsRestriction; +import net.minecraft.entity.ai.EntityAISwimming; +import net.minecraft.entity.ai.EntityAIWanderAvoidWater; +import net.minecraft.entity.ai.EntityAIWatchClosest; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.init.Items; +import net.minecraft.inventory.EntityEquipmentSlot; +import net.minecraft.item.ItemStack; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.MathHelper; +import net.minecraft.world.World; +import net.minecraftforge.event.entity.living.LivingDeathEvent; +import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; + +@Mod.EventBusSubscriber(modid = Reference.MOD_ID) +public class EntityMoroonTideMaker extends EntityMoroonUnitBase { + + public EntityMoroonTideMaker(World worldIn) { + super(worldIn); + experienceValue = 10; + setItemStackToSlot(EntityEquipmentSlot.OFFHAND, new ItemStack(Items.WATER_BUCKET)); + } + + protected void applyEntityAttributes() + { + super.applyEntityAttributes(); + + setAttr(16.0D, 0.5D, 5.0D, 0.0D, 64.0D); + } + + protected void initEntityAI() + { + this.tasks.addTask(0, new EntityAISwimming(this)); + + //this.tasks.addTask(1, new EntityAIAvoidEntity(this, EntityGolem.class, 8.0F, 0.6D, 0.6D)); + + this.tasks.addTask(2, new EntityAIAttackMelee(this, 1.0D, false)); + //this.tasks.addTask(3, new EntityAIAvoidEntity(this, EntityMoroonBombBeacon.class, 8.0F, 0.6D, 0.6D)); + this.tasks.addTask(5, new EntityAIMoveTowardsRestriction(this, 1.0D)); + this.tasks.addTask(7, new EntityAIWanderAvoidWater(this, 1.0D)); + this.tasks.addTask(8, new EntityAIWatchClosest(this, EntityPlayer.class, 8.0F)); + this.tasks.addTask(8, new EntityAILookIdle(this)); + this.applyEntityAI(); + } + + protected void applyEntityAI() + { + this.tasks.addTask(6, new EntityAIMoveThroughVillage(this, 1.0D, false)); + this.targetTasks.addTask(1, new EntityAIHurtByTarget(this, true, new Class[0])); + applyGeneralAI(); + } + + //wont be affected by water flow + @Override + public boolean isPushedByWater() { + return false; + } + + @SubscribeEvent + public static void onCreatureDied(final LivingDeathEvent ev) { + World world = ev.getEntityLiving().world; + EntityLivingBase diedOne = ev.getEntityLiving(); + } + + + + @Override + public void onUpdate() { + super.onUpdate(); + //IdlFramework.Log("Tick"); + if (!this.world.isRemote) + { + int i = MathHelper.floor(this.posX); + int j = MathHelper.floor(this.posY); + int k = MathHelper.floor(this.posZ); + + if (!net.minecraftforge.event.ForgeEventFactory.getMobGriefingEvent(this.world, this)) + { + return; + } + //Creates water alongside + for (int l = 0; l < 4; ++l) + { + i = MathHelper.floor(this.posX + (double)((float)(l % 2 * 2 - 1) * 0.25F)); + j = MathHelper.floor(this.posY); + k = MathHelper.floor(this.posZ + (double)((float)(l / 2 % 2 * 2 - 1) * 0.25F)); + BlockPos blockpos = new BlockPos(i, j, k); + + if ((this.world.getBlockState(blockpos).getMaterial() == Material.AIR || + this.world.getBlockState(blockpos).getBlock() == Blocks.FLOWING_WATER) + && + this.world.getBlockState(blockpos.add(0, -1 ,0)).getMaterial() != Material.AIR) + { + this.world.setBlockState(blockpos, Blocks.WATER.getDefaultState()); + } + } + } + } + + public void onLivingUpdate() + { + super.onLivingUpdate(); + + } +} diff --git a/src/main/java/com/somebody/idlframewok/entity/creatures/moroon/EntityMoroonUnitBase.java b/src/main/java/com/somebody/idlframewok/entity/creatures/moroon/EntityMoroonUnitBase.java new file mode 100644 index 0000000..6cf3181 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/entity/creatures/moroon/EntityMoroonUnitBase.java @@ -0,0 +1,183 @@ +package com.somebody.idlframewok.entity.creatures.moroon; + +import javax.annotation.Nullable; + +import com.somebody.idlframewok.entity.creatures.EntityModUnit; +import com.somebody.idlframewok.entity.creatures.ideallandTeam.EntityIdeallandUnitBase; +import net.minecraft.entity.IEntityLivingData; +import net.minecraft.entity.ai.EntityAINearestAttackableTarget; +import net.minecraft.entity.monster.EntityZombie; +import net.minecraft.entity.passive.EntityVillager; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.SoundEvents; +import net.minecraft.pathfinding.PathNavigateGround; +import net.minecraft.util.DamageSource; +import net.minecraft.util.SoundEvent; +import net.minecraft.world.DifficultyInstance; +import net.minecraft.world.EnumDifficulty; +import net.minecraft.world.World; + +public class EntityMoroonUnitBase extends EntityModUnit { + + int berserkGazeLv = 0; + protected boolean inflictBerserkBuff = true; + protected boolean autoArmor = false; + +// protected float[] inventoryHandsDropChances = new float[2]; +// /** Chances for armor dropping when this entity dies. */ +// protected float[] inventoryArmorDropChances = new float[4]; + + + + // (Base + Op0) × (1 + SUM(Op1)) × PRODUCT(1+Op2) + //Note that ops are 1 + + //https://minecraft-zh.gamepedia.com/%E5%B1%9E%E6%80%A7 + public EntityMoroonUnitBase(World worldIn) { + super(worldIn); + setCanPickUpLoot(true); + spawn_without_darkness = false; + spawn_without_moroon_ground = false; + experienceValue = 10; + isMoroon = true; + isIdealland = false; + applyLevelBoost = true; + } + + public int getMaxLevel() { + switch (world.getDifficulty()) + { + case PEACEFUL: + return 1; + case EASY: + return 3; + case NORMAL: + return 5; + case HARD: + return maxHardLevel; + } + return 1; + } + + public int getRank() + { + int level = getLevel(); + if (level>=maxHardLevel) + { + return 4; + } + else if (level>=maxNormLevel) + { + return 3; + } + else if (level>=maxEasyLevel) + { + return 2; + } + return 1; + } + + public void ApplyGeneralLevelBoost(DifficultyInstance difficulty, @Nullable IEntityLivingData livingdata) + { + //with localDiff / 10 chance to lv up recursively + int level = getLevel(); + int maxLv = getMaxLevel(); + float localDifficulty = difficulty.getAdditionalDifficulty(); + while (level < maxLv && ((getRNG().nextFloat()* 10f) <= localDifficulty)) + { + level++; + } + setLevel(level); + } + + @Nullable + @Override + public IEntityLivingData onInitialSpawn(DifficultyInstance difficulty, @Nullable IEntityLivingData livingdata) { + livingdata = super.onInitialSpawn(difficulty, livingdata); + ApplyGeneralLevelBoost(difficulty, livingdata); + + if (autoArmor) + { + this.setEquipmentBasedOnDifficulty(difficulty); + this.setEnchantmentBasedOnDifficulty(difficulty); + } + + return super.onInitialSpawn(difficulty, livingdata); + } + + protected void applyGeneralAI() + { + + + this.targetTasks.addTask(2, new EntityAINearestAttackableTarget(this, EntityPlayer.class, true)); + this.targetTasks.addTask(3, new EntityAINearestAttackableTarget(this, EntityIdeallandUnitBase.class, true)); + this.targetTasks.addTask(3, new EntityAINearestAttackableTarget(this, EntityZombie.class, false)); + this.targetTasks.addTask(3, new EntityAINearestAttackableTarget(this, EntityVillager.class, false)); + + ((PathNavigateGround)this.getNavigator()).setEnterDoors(true); + } + + @Override + public void onUpdate() { + super.onUpdate(); +// EntityLivingBase target = getAttackTarget(); +// if (inflictBerserkBuff && target != null && berserkGazeLv >= 0 && (world.getWorldTime() % TICK_PER_SECOND == 7) ) +// { +// target.addPotionEffect(new PotionEffect(ModPotions.BERSERK, TICK_PER_SECOND + 1, berserkGazeLv)); +// } + } + + /** + * Checks if the entity's current position is a valid location to spawn this entity. + */ + public boolean getCanSpawnHere() + { + return this.world.getDifficulty() != EnumDifficulty.PEACEFUL && super.getCanSpawnHere(); + } + + public boolean isPreventingPlayerRest(EntityPlayer playerIn) + { + return true; + } + + @Override + protected void dropLoot(boolean wasRecentlyHit, int lootingModifier, DamageSource source) { + super.dropLoot(wasRecentlyHit, lootingModifier, source); + //IdlFramework.Log("dropLoot Called"); +// dropItem(ModItems.MOR_FRAG, 2 + rand.nextInt(2 + lootingModifier)); +// if (rand.nextFloat() < 0.01f * getLevel()) +// { +// dropItem(ModItems.RANDOM_SKILL, 1); +// } +// +// if (rand.nextFloat() < 0.1f * getLevel()) +// { +// dropItem(ModItems.itemNanoMender_16, 1 + rand.nextInt(2 + lootingModifier)); +// } +// +// if (rand.nextFloat() < 0.1f * getLevel()) +// { +// dropItem(ModItems.itemNanoMender_16, 1 + rand.nextInt(2 + lootingModifier)); +// } +// +// if (rand.nextFloat() < 0.2f * getLevel()) +// { +// dropItem(ModItems.FIGHT_BREAD, 1 + rand.nextInt(2 + lootingModifier)); +// } +// +// if (rand.nextFloat() < ModConfig.GeneralConf.SKILL_RATE * getLevel()) +// { +// dropItem(ModItems.itemNanoMender_128, 1); +// } + + } + + @Override + protected SoundEvent getHurtSound(DamageSource damageSourceIn) { + return SoundEvents.ENTITY_PLAYER_HURT; + } + + // @Override +// protected SoundEvent getAmbientSound() { +// return ModSoundHandler.SOUND_1; +// } +} diff --git a/src/main/java/com/somebody/idlframewok/entity/creatures/moroon/EntityMoroonVampire.java b/src/main/java/com/somebody/idlframewok/entity/creatures/moroon/EntityMoroonVampire.java new file mode 100644 index 0000000..835124d --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/entity/creatures/moroon/EntityMoroonVampire.java @@ -0,0 +1,202 @@ +package com.somebody.idlframewok.entity.creatures.moroon; + +import java.util.List; + +import com.somebody.idlframewok.entity.creatures.ideallandTeam.EntityIdeallandUnitBase; +import com.somebody.idlframewok.util.IDLGeneral; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.ai.EntityAIAttackMelee; +import net.minecraft.entity.ai.EntityAILookIdle; +import net.minecraft.entity.ai.EntityAIMoveThroughVillage; +import net.minecraft.entity.ai.EntityAIMoveTowardsRestriction; +import net.minecraft.entity.ai.EntityAINearestAttackableTarget; +import net.minecraft.entity.ai.EntityAISwimming; +import net.minecraft.entity.ai.EntityAIWanderAvoidWater; +import net.minecraft.entity.ai.EntityAIWatchClosest; +import net.minecraft.entity.monster.EntityZombie; +import net.minecraft.entity.passive.EntityBat; +import net.minecraft.entity.passive.EntityCow; +import net.minecraft.entity.passive.EntitySheep; +import net.minecraft.entity.passive.EntityVillager; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Items; +import net.minecraft.init.MobEffects; +import net.minecraft.init.SoundEvents; +import net.minecraft.inventory.EntityEquipmentSlot; +import net.minecraft.item.ItemStack; +import net.minecraft.pathfinding.PathNavigateGround; +import net.minecraft.potion.PotionEffect; +import net.minecraft.util.DamageSource; +import net.minecraft.world.World; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.event.entity.living.LivingDeathEvent; +import net.minecraftforge.fml.common.eventhandler.EventPriority; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; + +import static com.somebody.idlframewok.util.CommonDef.TICK_PER_SECOND; + +public class EntityMoroonVampire extends EntityMoroonUnitBase { + //Summons bats + //Attacking summons bats + //Consume bats to revive + //Become bats when killed (can be used for other vampires) + int summonBatCount = 4; + float summonReqMP = 60f; + + + float reviveConsumeRange = 16; + int reviveConsumeCount = 2; + + + @Override + public boolean isEntityUndead() { + return true; + } + + public EntityMoroonVampire(World worldIn) { + super(worldIn); + + spawn_without_darkness = false; + spawn_without_moroon_ground = true; + MinecraftForge.EVENT_BUS.register(this); + experienceValue = 40; + + MPMax = 100f; + MP = MPMax; + + setItemStackToSlot(EntityEquipmentSlot.OFFHAND, new ItemStack(Items.MUTTON)); + } + + @Override + protected void dropLoot(boolean wasRecentlyHit, int lootingModifier, DamageSource source) { + super.dropLoot(wasRecentlyHit, lootingModifier, source); + +// if (wasRecentlyHit) { +// dropItem(ModItems.skillAttack1, rand.nextInt(1 + lootingModifier)); +// } + } + + protected void initEntityAI() + { + this.tasks.addTask(0, new EntityAISwimming(this)); + this.tasks.addTask(2, new EntityAIAttackMelee(this, 1.0D, false)); + //this.tasks.addTask(3, new EntityAIAvoidEntity(this, EntityMoroonBombBeacon.class, 8.0F, 0.6D, 1d)); + this.tasks.addTask(5, new EntityAIMoveTowardsRestriction(this, 1.0D)); + this.tasks.addTask(6, new EntityAIMoveThroughVillage(this, 1.0D, false)); + this.tasks.addTask(7, new EntityAIWanderAvoidWater(this, 1.0D)); + this.tasks.addTask(8, new EntityAIWatchClosest(this, EntityPlayer.class, 8.0F)); + this.tasks.addTask(8, new EntityAILookIdle(this)); + this.applyEntityAI(); + } + + protected void applyEntityAI() + { + //this.targetTasks.addTask(1, new EntityAIHurtByTarget(this, true, new Class[] {EntityMoroonVampire.class})); + this.targetTasks.addTask(2, new EntityAINearestAttackableTarget(this, EntityPlayer.class, false)); + this.targetTasks.addTask(3, new EntityAINearestAttackableTarget(this, EntityIdeallandUnitBase.class, false)); + this.targetTasks.addTask(3, new EntityAINearestAttackableTarget(this, EntityZombie.class, false)); + this.targetTasks.addTask(3, new EntityAINearestAttackableTarget(this, EntityVillager.class, false)); + + ((PathNavigateGround)this.getNavigator()).setEnterDoors(true); + this.targetTasks.addTask(4, new EntityAINearestAttackableTarget(this, EntitySheep.class, false)); + this.targetTasks.addTask(4, new EntityAINearestAttackableTarget(this, EntityCow.class, false)); + } + + protected void applyEntityAttributes() + { + super.applyEntityAttributes(); + + setAttr(32, 0.4, 6.0, 2, 24); + } + + @Override + public void onUpdate() { + super.onUpdate(); + //IdlFramework.Log("Tick"); + if (!this.world.isRemote) + { + if (world.getWorldTime() % TICK_PER_SECOND == 0) { + if (getAttackTarget() != null && trySpendMana(summonReqMP)) + { + float angle = getRNG().nextFloat() * 6.28f; + for (int i = 1; i <= summonBatCount; i++) + { + EntityBat bat = new EntityBat(world); + angle += 6.28f / summonBatCount; + bat.setPosition(posX + Math.cos(angle), posY, posZ + Math.sin(angle)); + bat.spawnExplosionParticle(); + world.spawnEntity(bat); + } + setHealth(0.8f * getHealth()); + + } + } + } + } + + public boolean attackEntityAsMob(Entity target) { + boolean result = super.attackEntityAsMob(target); + if (result) + { + this.addPotionEffect(new PotionEffect(MobEffects.STRENGTH, 3*TICK_PER_SECOND, 0)); + heal(1f); + } + return result; + } + + @SubscribeEvent(priority = EventPriority.LOW) + public void OnDeath(LivingDeathEvent ev) + { + if (!world.isRemote) + { + EntityLivingBase diedOne = ev.getEntityLiving(); + if (diedOne == this) + { + List entities = world.getEntitiesWithinAABB(EntityBat.class, + IDLGeneral.ServerAABB(getPositionEyes(0f), reviveConsumeRange)); + + if (entities.size() >= reviveConsumeCount) + { + ev.setCanceled(true); + for (int i = 0; i < reviveConsumeCount; i++) + { + EntityBat entityBat = entities.get(i); + this.heal(entityBat.getHealth() / 2); + entityBat.setDead(); + this.spawnRunningParticles(); + this.playSound(SoundEvents.ENTITY_WITCH_AMBIENT, 1f, 1f); + } + } + else { + float angle = getRNG().nextFloat() * 6.28f; + for (int i = 1; i <= summonBatCount; i++) + { + EntityBat bat = new EntityBat(world); + angle += 6.28f / summonBatCount; + bat.setPosition(posX + Math.cos(angle), posY, posZ + Math.sin(angle)); + bat.spawnExplosionParticle(); + world.spawnEntity(bat); + } + } + } + + DamageSource source = ev.getSource(); + if (source != null) + { + Entity killer = source.getTrueSource(); + if (killer == this) + { + EntityBat bat = new EntityBat(world); + bat.setPosition(diedOne.posX , diedOne.posY, diedOne.posZ); + bat.spawnExplosionParticle(); + world.spawnEntity(bat); + heal(diedOne.getMaxHealth() / 10f); + } + } + } + + } + + +} diff --git a/src/main/java/com/somebody/idlframewok/entity/creatures/render/RenderBullet.java b/src/main/java/com/somebody/idlframewok/entity/creatures/render/RenderBullet.java new file mode 100644 index 0000000..4b9cec9 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/entity/creatures/render/RenderBullet.java @@ -0,0 +1,67 @@ +package com.somebody.idlframewok.entity.creatures.render; + +import javax.annotation.Nullable; + +import com.somebody.idlframewok.entity.projectiles.EntityIdlProjectile; +import net.minecraft.client.renderer.BufferBuilder; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.entity.Render; +import net.minecraft.client.renderer.entity.RenderManager; +import net.minecraft.client.renderer.vertex.DefaultVertexFormats; +import net.minecraft.util.ResourceLocation; + +public class RenderBullet extends Render { + + private final ResourceLocation texture; + + public RenderBullet(final RenderManager manager, final ResourceLocation textureResource) { + super(manager); + texture = textureResource; + } + + public void doRender(T entity, double x, double y, double z, float entityYaw, float partialTicks) + { + GlStateManager.pushMatrix(); + bindEntityTexture(entity); + GlStateManager.translate((float)x, (float)y,(float)z); + GlStateManager.enableRescaleNormal(); + GlStateManager.scale(0.5f, 0.5f, 0.5f); + + Tessellator tess = Tessellator.getInstance(); + BufferBuilder buffer = tess.getBuffer(); + + GlStateManager.rotate(180.0F - this.renderManager.playerViewY, 0.0F, 1.0F, 0.0F); + GlStateManager.rotate(-this.renderManager.playerViewX, 1.0F, 0.0F, 0.0F); + + if (renderOutlines) { + GlStateManager.enableColorMaterial(); + GlStateManager.enableOutlineMode(getTeamColor(entity)); + } + + buffer.begin(7, DefaultVertexFormats.POSITION_TEX_NORMAL); + buffer.pos(-0.5D, -0.25D, 0.0D).tex(0.0D, 1.0D).normal(0.0F, 1.0F, 0.0F).endVertex(); + buffer.pos(0.5D, -0.25D, 0.0D).tex(1.0D, 1.0D).normal(0.0F, 1.0F, 0.0F).endVertex(); + buffer.pos(0.5D, 0.75D, 0.0D).tex(1.0D, 0.0D).normal(0.0F, 1.0F, 0.0F).endVertex(); + buffer.pos(-0.5D, 0.75D, 0.0D).tex(0.0D, 0.0D).normal(0.0F, 1.0F, 0.0F).endVertex(); + tess.draw(); + + if (renderOutlines) { + GlStateManager.disableOutlineMode(); + GlStateManager.disableColorMaterial(); + } + + GlStateManager.disableRescaleNormal(); + GlStateManager.popMatrix(); + } + + /** + * Returns the location of an entity's texture. Doesn't seem to be called unless you call Render.bindEntityTexture. + */ + @Nullable + @Override + protected ResourceLocation getEntityTexture(EntityIdlProjectile entity) + { + return texture; + } +} diff --git a/src/main/java/com/somebody/idlframewok/entity/creatures/render/RenderConstruction.java b/src/main/java/com/somebody/idlframewok/entity/creatures/render/RenderConstruction.java new file mode 100644 index 0000000..23a32c3 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/entity/creatures/render/RenderConstruction.java @@ -0,0 +1,29 @@ +package com.somebody.idlframewok.entity.creatures.render; + +import javax.annotation.Nullable; + +import com.somebody.idlframewok.entity.creatures.EntityModUnit; +import com.somebody.idlframewok.entity.creatures.model.ModelIDLConstruction; +import com.somebody.idlframewok.util.Reference; +import net.minecraft.client.renderer.entity.RenderLiving; +import net.minecraft.client.renderer.entity.RenderManager; +import net.minecraft.util.ResourceLocation; + +public class RenderConstruction extends RenderLiving { + public static final ResourceLocation TEXTURES = new ResourceLocation(Reference.MOD_ID + ":textures/entity/idl_construction.png"); + public RenderConstruction(RenderManager manager){ + super(manager, new ModelIDLConstruction(), 0.5F); + } + + @Nullable + @Override + protected ResourceLocation getEntityTexture(EntityModUnit entity) { + return TEXTURES; + } + + @Override + protected void applyRotations(EntityModUnit entityLiving, float p_77043_2_, float rotationYaw, float partialTicks) { + super.applyRotations(entityLiving, p_77043_2_, rotationYaw, partialTicks); + + } +} diff --git a/src/main/java/com/somebody/idlframewok/entity/creatures/render/RenderModUnit.java b/src/main/java/com/somebody/idlframewok/entity/creatures/render/RenderModUnit.java new file mode 100644 index 0000000..53c54f4 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/entity/creatures/render/RenderModUnit.java @@ -0,0 +1,42 @@ +package com.somebody.idlframewok.entity.creatures.render; + +import com.somebody.idlframewok.entity.creatures.EntityModUnit; +import net.minecraft.client.model.ModelBiped; +import net.minecraft.client.model.ModelZombie; +import net.minecraft.client.renderer.entity.RenderBiped; +import net.minecraft.client.renderer.entity.RenderManager; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +@SideOnly(Side.CLIENT) +public class RenderModUnit extends RenderBiped { + private static final ResourceLocation DEFAULT_RES_LOC = new ResourceLocation("textures/entity/steve.png"); + + public RenderModUnit(RenderManager renderManagerIn) + { + super(renderManagerIn, new ModelZombie(), 0.5F); + } + + + public RenderModUnit(RenderManager renderManagerIn, ModelBiped modelBipedIn, float shadowSize) { + super(renderManagerIn, modelBipedIn, shadowSize); +// LayerBipedArmor layerbipedarmor = new LayerBipedArmor(this) +// { +// protected void initArmor() +// { +// this.modelLeggings = new ModelZombie(0.5F, true); +// this.modelArmor = new ModelZombie(1.0F, true); +// } +// }; +// this.addLayer(layerbipedarmor); + } + + /** + * Returns the location of an entity's texture. Doesn't seem to be called unless you call Render.bindEntityTexture. + */ + protected ResourceLocation getEntityTexture(EntityModUnit entity) + { + return DEFAULT_RES_LOC; + } +} diff --git a/src/main/java/com/somebody/idlframewok/entity/creatures/render/RenderMoroonHumanoid.java b/src/main/java/com/somebody/idlframewok/entity/creatures/render/RenderMoroonHumanoid.java new file mode 100644 index 0000000..a39c38e --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/entity/creatures/render/RenderMoroonHumanoid.java @@ -0,0 +1,52 @@ +package com.somebody.idlframewok.entity.creatures.render; + +import com.somebody.idlframewok.entity.creatures.EntityModUnit; +import com.somebody.idlframewok.util.Reference; +import net.minecraft.client.model.ModelBiped; +import net.minecraft.client.model.ModelPlayer; +import net.minecraft.client.renderer.entity.RenderBiped; +import net.minecraft.client.renderer.entity.RenderManager; +import net.minecraft.client.renderer.entity.layers.LayerBipedArmor; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +@SideOnly(Side.CLIENT) +public class RenderMoroonHumanoid extends RenderBiped { + private static final ResourceLocation DEFAULT_RES_LOC = new ResourceLocation(Reference.MOD_ID + ":textures/entity/moroon_humanoid.png"); + + public RenderMoroonHumanoid(RenderManager renderManagerIn) + { + super(renderManagerIn, new ModelPlayer(1f, false), 0.5F); + this.addLayer(new LayerBipedArmor(this)); + //this.addLayer(new LayerHeldItem(this)); + //this.addLayer(new LayerArrow(this)); +// this.addLayer(new LayerDeadmau5Head(this)); +// this.addLayer(new LayerCape(this)); +// this.addLayer(new LayerCustomHead(this.getMainModel().bipedHead)); + //this.addLayer(new LayerElytra(this)); + //this.addLayer(new LayerEntityOnShoulder(renderManager)); + } + + + public RenderMoroonHumanoid(RenderManager renderManagerIn, ModelBiped modelBipedIn, float shadowSize) { + super(renderManagerIn, modelBipedIn, shadowSize); +// LayerBipedArmor layerbipedarmor = new LayerBipedArmor(this) +// { +// protected void initArmor() +// { +// this.modelLeggings = new ModelZombie(0.5F, true); +// this.modelArmor = new ModelZombie(1.0F, true); +// } +// }; +// this.addLayer(layerbipedarmor); + } + + /** + * Returns the location of an entity's texture. Doesn't seem to be called unless you call Render.bindEntityTexture. + */ + protected ResourceLocation getEntityTexture(EntityModUnit entity) + { + return DEFAULT_RES_LOC; + } +} diff --git a/src/main/java/com/somebody/idlframewok/entity/creatures/render/RenderTurret.java b/src/main/java/com/somebody/idlframewok/entity/creatures/render/RenderTurret.java new file mode 100644 index 0000000..f4eba98 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/entity/creatures/render/RenderTurret.java @@ -0,0 +1,29 @@ +package com.somebody.idlframewok.entity.creatures.render; + +import javax.annotation.Nullable; + +import com.somebody.idlframewok.entity.creatures.EntityModUnit; +import com.somebody.idlframewok.entity.creatures.model.ModelTurretPrototype; +import com.somebody.idlframewok.util.Reference; +import net.minecraft.client.renderer.entity.RenderLiving; +import net.minecraft.client.renderer.entity.RenderManager; +import net.minecraft.util.ResourceLocation; + +public class RenderTurret extends RenderLiving { + public static final ResourceLocation TEXTURES = new ResourceLocation(Reference.MOD_ID + ":textures/entity/turret_one.png"); + public RenderTurret(RenderManager manager){ + super(manager, new ModelTurretPrototype(), 0.5F); + } + + @Nullable + @Override + protected ResourceLocation getEntityTexture(EntityModUnit entity) { + return TEXTURES; + } + + @Override + protected void applyRotations(EntityModUnit entityLiving, float p_77043_2_, float rotationYaw, float partialTicks) { + super.applyRotations(entityLiving, p_77043_2_, rotationYaw, partialTicks); + + } +} diff --git a/src/main/java/com/somebody/idlframewok/entity/creatures/render/RenderTurret2.java b/src/main/java/com/somebody/idlframewok/entity/creatures/render/RenderTurret2.java new file mode 100644 index 0000000..7f5061e --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/entity/creatures/render/RenderTurret2.java @@ -0,0 +1,28 @@ +package com.somebody.idlframewok.entity.creatures.render; + +import javax.annotation.Nullable; + +import com.somebody.idlframewok.entity.creatures.misc.EntityTurretPrototype2; +import com.somebody.idlframewok.entity.creatures.model.ModelTurretPrototype; +import com.somebody.idlframewok.util.Reference; +import net.minecraft.client.renderer.entity.RenderLiving; +import net.minecraft.client.renderer.entity.RenderManager; +import net.minecraft.util.ResourceLocation; + +public class RenderTurret2 extends RenderLiving { + public static final ResourceLocation TEXTURES = new ResourceLocation(Reference.MOD_ID + ":textures/entity/turret_one.png"); + public RenderTurret2(RenderManager manager){ + super(manager, new ModelTurretPrototype(), 0.5F); + } + + @Nullable + @Override + protected ResourceLocation getEntityTexture(EntityTurretPrototype2 entity) { + return TEXTURES; + } + + @Override + protected void applyRotations(EntityTurretPrototype2 entityLiving, float p_77043_2_, float rotationYaw, float partialTicks) { + super.applyRotations(entityLiving, p_77043_2_, rotationYaw, partialTicks); + } +} diff --git a/src/main/java/com/somebody/idlframewok/entity/projectiles/EntityIdlProjectile.java b/src/main/java/com/somebody/idlframewok/entity/projectiles/EntityIdlProjectile.java new file mode 100644 index 0000000..9f3a9f6 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/entity/projectiles/EntityIdlProjectile.java @@ -0,0 +1,354 @@ +package com.somebody.idlframewok.entity.projectiles; + +import java.util.Random; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.IProjectile; +import net.minecraft.entity.projectile.ProjectileHelper; +import net.minecraft.init.SoundEvents; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.util.DamageSource; +import net.minecraft.util.EnumParticleTypes; +import net.minecraft.util.SoundCategory; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.MathHelper; +import net.minecraft.util.math.RayTraceResult; +import net.minecraft.util.math.Vec3d; +import net.minecraft.world.World; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +//modified from fireballs +public class EntityIdlProjectile extends Entity implements IProjectile { + public EntityLivingBase shootingEntity; + private int ticksAlive; + protected int ticksInAir; + public double accelerationX; + public double accelerationY; + public double accelerationZ; + public ProjectileArgs args; + boolean hitToDeflect = false; + + public float acceleration = 0.1f; + + protected EntityIdlProjectile(World worldIn) + { + super(worldIn); + args = new ProjectileArgs(1f); + } + + @Override + protected void entityInit() { + + } + + protected EntityIdlProjectile(World worldIn, ProjectileArgs args) { + super(worldIn); + this.args = args; + //IdlFramework.Log("bullet created %s, args = %s", getUniqueID(), this.args); + } + + /** + * Checks if the entity is in range to render. + */ + @SideOnly(Side.CLIENT) + public boolean isInRangeToRenderDist(double distance) + { + double d0 = this.getEntityBoundingBox().getAverageEdgeLength() * 4.0D; + + if (Double.isNaN(d0)) + { + d0 = 4.0D; + } + + d0 = d0 * 64.0D; + return distance < d0 * d0; + } + +// public EntityIdlProjectile(World worldIn, ProjectileArgs args, double x, double y, double z, double accelX, double accelY, double accelZ) +// { +// this(worldIn, args); +// this.setSize(0.3125F, 0.3125F); +// this.setLocationAndAngles(x, y, z, this.rotationYaw, this.rotationPitch); +// this.setPosition(x, y, z); +// double d0 = (double) MathHelper.sqrt(accelX * accelX + accelY * accelY + accelZ * accelZ); +// this.accelerationX = accelX / d0 * 0.1D; +// this.accelerationY = accelY / d0 * 0.1D; +// this.accelerationZ = accelZ / d0 * 0.1D; +// } + + public EntityIdlProjectile(World worldIn, ProjectileArgs args, EntityLivingBase shooter, double accelX, double accelY, double accelZ, float acceleration) + { + this(worldIn, args); + this.shootingEntity = shooter; + this.setSize(0.3125F, 0.3125F); + + Vec3d shooterFacing = shooter.getLook(0f); + + this.setLocationAndAngles(shooter.posX + shooterFacing.x, + shooter.posY + shooter.getEyeHeight() + shooterFacing.y, + shooter.posZ + shooterFacing.z, + shooter.rotationYaw, shooter.rotationPitch); + this.setPosition(this.posX, this.posY, this.posZ); + this.motionX = 0.0D; + this.motionY = 0.0D; + this.motionZ = 0.0D; + //accelX = accelX + this.rand.nextGaussian() * 0.4D; + //accelY = accelY + this.rand.nextGaussian() * 0.4D; + //accelZ = accelZ + this.rand.nextGaussian() * 0.4D; + double accelLength = (double)MathHelper.sqrt(accelX * accelX + accelY * accelY + accelZ * accelZ); + this.accelerationX = accelX / accelLength * acceleration; + this.accelerationY = accelY / accelLength * acceleration; + this.accelerationZ = accelZ / accelLength * acceleration; + } + + public EntityIdlProjectile(World worldIn, ProjectileArgs args, EntityLivingBase shooter, double accelX, double accelY, double accelZ) + { + this(worldIn, args, shooter, accelX, accelY, accelZ, 0.1f); + } + + /** + * Called to update the entity's position/logic. + */ + public void onUpdate() + { + //IdlFramework.Log("Bullet pos update:%s", getPositionEyes(0)); + + if (this.world.isRemote || (this.shootingEntity == null || !this.shootingEntity.isDead) && this.world.isBlockLoaded(new BlockPos(this))) + { + super.onUpdate(); + + if (this.isFireballFiery()) + { + this.setFire(1); + } + + ++this.ticksInAir; + RayTraceResult raytraceresult = ProjectileHelper.forwardsRaycast(this, true, this.ticksInAir >= 25, this.shootingEntity); + + if (raytraceresult != null && !net.minecraftforge.event.ForgeEventFactory.onProjectileImpact(this, raytraceresult)) + { + this.onImpact(raytraceresult); + } + + this.posX += this.motionX; + this.posY += this.motionY; + this.posZ += this.motionZ; + ProjectileHelper.rotateTowardsMovement(this, 0.2F); + float f = 0.99f; + + if (this.isInWater()) + { + for (int i = 0; i < 4; ++i) + { + float f1 = 0.25F; + this.world.spawnParticle(EnumParticleTypes.WATER_BUBBLE, this.posX - this.motionX * 0.25D, this.posY - this.motionY * 0.25D, this.posZ - this.motionZ * 0.25D, this.motionX, this.motionY, this.motionZ); + } + + f = 0.8F; + } + + this.motionX += this.accelerationX; + this.motionY += this.accelerationY; + this.motionZ += this.accelerationZ; + this.motionX *= (double)f; + this.motionY *= (double)f; + this.motionZ *= (double)f; + //this.world.spawnParticle(this.getParticleType(), this.posX, this.posY + 0.5D, this.posZ, 0.0D, 0.0D, 0.0D); + this.setPosition(this.posX, this.posY, this.posZ); + } + else + { + this.setDead(); + } + } + + protected boolean isFireballFiery() + { + if (args == null) + { + //IdlFramework.LogWarning("Args not found for bullet"); + return false; + } + return args.burning; + } + +// protected EnumParticleTypes getParticleType() +// { +// return EnumParticleTypes.SMOKE_NORMAL; +// } + + /** + * Called when this EntityIdlProjectile hits a block or entity. + */ + protected void onImpact(RayTraceResult result) + { + //IdlFramework.Log("bullet impact %s", getUniqueID()); + if (!this.world.isRemote) + { + if (result.entityHit != null) + { + result.entityHit.attackEntityFrom(DamageSource.causeIndirectDamage(this, this.shootingEntity).setProjectile(), args.damage); + this.applyEnchantments(this.shootingEntity, result.entityHit); + } + + boolean flag = net.minecraftforge.event.ForgeEventFactory.getMobGriefingEvent(this.world, this.shootingEntity); + if (args.explosion_power > 0) { + this.world.newExplosion(null, posX, posY, posZ, args.explosion_power, flag, flag); + } + world.playSound(posX, posY, posZ, SoundEvents.BLOCK_LAVA_EXTINGUISH, + SoundCategory.NEUTRAL, 1f, 1f, false); + + this.setDead(); + } + else { + world.spawnParticle(EnumParticleTypes.CLOUD, posX, posY, posZ, motionX, motionY, motionZ); + if (result.entityHit == null) + { + Random random = new Random(); + float vx = (float) (motionX * 0.3f); + float vy = (float) (motionY * 0.3f); + float vz = (float) (motionZ * 0.3f); + + world.spawnParticle(EnumParticleTypes.FLAME, posX, posY, posZ, vx * random.nextFloat(), vy * random.nextFloat(), vz * random.nextFloat()); + world.spawnParticle(EnumParticleTypes.FLAME, posX, posY, posZ, -vx * random.nextFloat(), -vy * random.nextFloat(), -vz * random.nextFloat()); + world.spawnParticle(EnumParticleTypes.FLAME, posX, posY, posZ, -vx * random.nextFloat(), -vy * random.nextFloat(), -vz * random.nextFloat()); + } + } + } + + /** + * (abstract) Protected helper method to write subclass entity data to NBT. + */ + public void writeEntityToNBT(NBTTagCompound compound) + { + compound.setTag("direction", this.newDoubleNBTList(this.motionX, this.motionY, this.motionZ)); + compound.setTag("power", this.newDoubleNBTList(this.accelerationX, this.accelerationY, this.accelerationZ)); + compound.setInteger("life", this.ticksAlive); + + this.args.writeEntityToNBT(compound); + } + + /** + * (abstract) Protected helper method to read subclass entity data from NBT. + */ + public void readEntityFromNBT(NBTTagCompound compound) + { + if (compound.hasKey("power", 9)) + { + NBTTagList nbttaglist = compound.getTagList("power", 6); + + if (nbttaglist.tagCount() == 3) + { + this.accelerationX = nbttaglist.getDoubleAt(0); + this.accelerationY = nbttaglist.getDoubleAt(1); + this.accelerationZ = nbttaglist.getDoubleAt(2); + } + } + + this.ticksAlive = compound.getInteger("life"); + + if (compound.hasKey("direction", 9) && compound.getTagList("direction", 6).tagCount() == 3) + { + NBTTagList nbttaglist1 = compound.getTagList("direction", 6); + this.motionX = nbttaglist1.getDoubleAt(0); + this.motionY = nbttaglist1.getDoubleAt(1); + this.motionZ = nbttaglist1.getDoubleAt(2); + } + else + { + this.setDead(); + } + + if (this.args == null) + { + this.args = new ProjectileArgs(1f); + } + this.args.readEntityFromNBT(compound); + } + + /** + * Returns true if other Entities should be prevented from moving through this Entity. + */ + public boolean canBeCollidedWith() + { + return true; + } + + public float getCollisionBorderSize() + { + return 1.0F; + } + + /** + * Called when the entity is attacked. + */ + public boolean attackEntityFrom(DamageSource source, float amount) + { + if (this.isEntityInvulnerable(source) || !hitToDeflect) + { + return false; + } + else + { + this.markVelocityChanged(); + + if (source.getTrueSource() != null) + { + Vec3d vec3d = source.getTrueSource().getLookVec(); + + this.motionX = vec3d.x; + this.motionY = vec3d.y; + this.motionZ = vec3d.z; + this.accelerationX = this.motionX * 0.1D; + this.accelerationY = this.motionY * 0.1D; + this.accelerationZ = this.motionZ * 0.1D; + + if (source.getTrueSource() instanceof EntityLivingBase) + { + this.shootingEntity = (EntityLivingBase)source.getTrueSource(); + } + + return true; + } + else + { + return false; + } + } + } + + @SideOnly(Side.CLIENT) + public int getBrightnessForRender() + { + return 15728880; + } + + /** + * Similar to setArrowHeading, it's point the throwable entity to a x, y, z direction. + */ + public void shoot(double x, double y, double z, float velocity, float inaccuracy) + { + float f = MathHelper.sqrt(x * x + y * y + z * z); + x = x / (double)f; + y = y / (double)f; + z = z / (double)f; + x = x + this.rand.nextGaussian() * 0.007499999832361937D * (double)inaccuracy; + y = y + this.rand.nextGaussian() * 0.007499999832361937D * (double)inaccuracy; + z = z + this.rand.nextGaussian() * 0.007499999832361937D * (double)inaccuracy; + x = x * (double)velocity; + y = y * (double)velocity; + z = z * (double)velocity; + this.motionX = x; + this.motionY = y; + this.motionZ = z; + float f1 = MathHelper.sqrt(x * x + z * z); + this.rotationYaw = (float)(MathHelper.atan2(x, z) * (180D / Math.PI)); + this.rotationPitch = (float)(MathHelper.atan2(y, (double)f1) * (180D / Math.PI)); + this.prevRotationYaw = this.rotationYaw; + this.prevRotationPitch = this.rotationPitch; + //this.ticksInGround = 0; + } +} diff --git a/src/main/java/com/somebody/idlframewok/entity/projectiles/ProjectileArgs.java b/src/main/java/com/somebody/idlframewok/entity/projectiles/ProjectileArgs.java new file mode 100644 index 0000000..18bf332 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/entity/projectiles/ProjectileArgs.java @@ -0,0 +1,38 @@ +package com.somebody.idlframewok.entity.projectiles; + +import net.minecraft.nbt.NBTTagCompound; + +public class ProjectileArgs { + public float damage = 1f; + public float explosion_power = 0f; + public float speed = 1f; + public boolean burning = false; + + public ProjectileArgs(float damage, float explosion_power, float speed, boolean burning) { + this.damage = damage; + this.explosion_power = explosion_power; + this.speed = speed; + this.burning = burning; + } + + public ProjectileArgs(float damage) { + this.damage = damage; + } + + public void writeEntityToNBT(NBTTagCompound compound) + { + compound.setFloat("damage", damage); + compound.setFloat("explosion_power", explosion_power); + compound.setBoolean("burning", this.burning); + compound.setFloat("explosion_power", this.explosion_power); + } + + public void readEntityFromNBT(NBTTagCompound compound) + { + this.damage = compound.getFloat("damage"); + this.explosion_power = compound.getFloat("explosion_power"); + this.burning = compound.getBoolean("burning"); + this.explosion_power = compound.getFloat("explosion_power"); + + } +} diff --git a/src/main/java/com/somebody/idlframewok/events/ModStarterEvents.java b/src/main/java/com/somebody/idlframewok/events/ModStarterEvents.java new file mode 100644 index 0000000..693d888 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/events/ModStarterEvents.java @@ -0,0 +1,31 @@ +package com.somebody.idlframewok.events; + +import com.somebody.idlframewok.util.IDLNBT; +import com.somebody.idlframewok.util.NBTStrDef.IDLNBTDef; +import com.somebody.idlframewok.util.Reference; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.common.gameevent.PlayerEvent; + +@Mod.EventBusSubscriber(modid = Reference.MOD_ID) +public class ModStarterEvents { + @SubscribeEvent + public static void onPlayerLoggedIn(PlayerEvent.PlayerLoggedInEvent event) { + EntityPlayer player = event.player; + //IdlFramework.Log(getPlyrIdlTagSafe(player).toString()); + int lastStarterVer = IDLNBT.getPlayerIdeallandIntSafe(player, IDLNBTDef.STARTER_KIT_VERSION_TAG); + if(lastStarterVer < IDLNBTDef.CUR_STARTER_KIT_VERSION) { +// IDLNBT.setPlayerIdeallandTagSafe(player, STARTER_KIT_VERSION_TAG, CUR_STARTER_KIT_VERSION); +// +// ItemStack scry = new ItemStack(Items.QUARTZ); +// player.addItemStackToInventory(scry); +// +// if (player instanceof EntityPlayerMP) { +// CommonFunctions.SendMsgToPlayerStyled((EntityPlayerMP)player, "idlframework.msg.starter_kit_given", TextFormatting.AQUA); +// } +// IdlFramework.Log(String.format("Given starter items to player %s, ver %d", player.getDisplayNameString(), CUR_STARTER_KIT_VERSION)); + } + } + +} diff --git a/src/main/java/com/somebody/idlframewok/gui/ModGuiElementLoader.java b/src/main/java/com/somebody/idlframewok/gui/ModGuiElementLoader.java new file mode 100644 index 0000000..4983104 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/gui/ModGuiElementLoader.java @@ -0,0 +1,48 @@ +package com.somebody.idlframewok.gui; + +import javax.annotation.Nullable; + +import com.somebody.idlframewok.IdlFramework; +import com.somebody.idlframewok.gui.expOne.ContainerDemo; +import com.somebody.idlframewok.gui.expOne.GuiContainerDemo; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.world.World; +import net.minecraftforge.fml.common.network.IGuiHandler; +import net.minecraftforge.fml.common.network.NetworkRegistry; + +//todo +//https://fmltutor.ustc-zzzz.net/3.4.3-GUI%E7%95%8C%E9%9D%A2%E4%B8%AD%E7%9A%84%E4%BA%A4%E4%BA%92.html +public class ModGuiElementLoader implements IGuiHandler { + + public static final int GUI_DEMO = 1; + public static final int GUI_RESEARCH = 2; + + public ModGuiElementLoader() + { + NetworkRegistry.INSTANCE.registerGuiHandler(IdlFramework.instance, this); + } + + @Nullable + @Override + public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { + switch (ID) + { + case GUI_DEMO: + return new ContainerDemo(player); + default: + return null; + } + } + + @Nullable + @Override + public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { + switch (ID) + { + case GUI_DEMO: + return new GuiContainerDemo(new ContainerDemo(player)); + default: + return null; + } + } +} diff --git a/src/main/java/com/somebody/idlframewok/gui/expOne/ContainerDemo.java b/src/main/java/com/somebody/idlframewok/gui/expOne/ContainerDemo.java new file mode 100644 index 0000000..f43b5a0 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/gui/expOne/ContainerDemo.java @@ -0,0 +1,193 @@ +package com.somebody.idlframewok.gui.expOne; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Items; +import net.minecraft.inventory.Container; +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; +import net.minecraftforge.items.ItemStackHandler; +import net.minecraftforge.items.SlotItemHandler; + +//https://fmltutor.ustc-zzzz.net/3.4.2-GUI%E7%95%8C%E9%9D%A2%E7%9A%84%E4%B8%AA%E6%80%A7%E5%8C%96%E4%B8%8E%E7%89%A9%E5%93%81%E6%A7%BD%E7%9A%84%E6%B7%BB%E5%8A%A0.html +public class ContainerDemo extends Container { + private ItemStackHandler items = new ItemStackHandler(4); + + protected Slot goldSlot; + protected Slot diamondSlot; + protected Slot emeraldSlot; + protected Slot ironSlot; + + public ContainerDemo(EntityPlayer player) + { + super(); + + this.addSlotToContainer(this.goldSlot = new SlotItemHandler(items, 0, 38 + 0 * 32, 20) + { + @Override + public boolean isItemValid(ItemStack stack) + { + return stack != null && stack.getItem() == Items.GOLD_INGOT && super.isItemValid(stack); + } + + @Override + public int getItemStackLimit(ItemStack stack) + { + return 16; + } + }); + + //2nd + this.addSlotToContainer(this.diamondSlot = new SlotItemHandler(items, 1, 38 + 1 * 32, 20) + { + { + this.putStack(new ItemStack(Items.DIAMOND, 64)); + } + + @Override + public boolean canTakeStack(EntityPlayer playerIn) + { + return false; + } + }); + + //3rd + this.addSlotToContainer(this.emeraldSlot = new SlotItemHandler(items, 2, 38 + 2 * 32, 20) + { + @Override + public boolean isItemValid(ItemStack stack) + { + return stack != null && stack.getItem() == Items.EMERALD && super.isItemValid(stack); + } + + @Override + public void onSlotChanged() + { + ItemStack stack = this.getStack(); + int amount = stack.isEmpty() ? 64 : 64 - stack.getCount(); + ContainerDemo.this.diamondSlot.putStack(amount == 0 ? ItemStack.EMPTY : new ItemStack(Items.DIAMOND, amount)); + super.onSlotChanged(); + } + }); + + //4th + this.addSlotToContainer(this.ironSlot = new SlotItemHandler(items, 3, 38 + 3 * 32, 20) + { + { + this.putStack(new ItemStack(Items.IRON_INGOT, 64)); + } + + @Override + public boolean canTakeStack(EntityPlayer playerIn) + { + return false; + } + }); + + for (int i = 0; i < 3; ++i) + { + for (int j = 0; j < 9; ++j) + { + this.addSlotToContainer(new Slot(player.inventory, j + i * 9 + 9, 8 + j * 18, 51 + i * 18)); + } + } + + for (int i = 0; i < 9; ++i) + { + this.addSlotToContainer(new Slot(player.inventory, i, 8 + i * 18, 109)); + } + + + } + + public Slot getIronSlot() + { + return this.ironSlot; + } + + @Override + public boolean canInteractWith(EntityPlayer playerIn) { + return true; + //return playerIn.getHeldItemOffhand().getItem() == ModItems.DEBUG_ITEM_3; + } + + @Override + public void onContainerClosed(EntityPlayer playerIn) + { + //if the gui does not connects a tile entity, this must be manually rewritten + super.onContainerClosed(playerIn); + + if (playerIn.isServerWorld()) + { + ItemStack goldStack = this.goldSlot.getStack(); + if (goldStack != ItemStack.EMPTY) + { + playerIn.addItemStackToInventory(goldStack); + this.goldSlot.putStack(ItemStack.EMPTY); + } + ItemStack emeraldStack = this.emeraldSlot.getStack(); + if (emeraldStack != ItemStack.EMPTY) + { + playerIn.addItemStackToInventory(emeraldStack); + this.emeraldSlot.putStack(ItemStack.EMPTY); + } + } + } + + @Override + public ItemStack transferStackInSlot(EntityPlayer playerIn, int index) + { + Slot slot = inventorySlots.get(index); + + if (slot == null || !slot.getHasStack()) + { + return null; + } + + ItemStack newStack = slot.getStack(), oldStack = newStack.copy(); + + //--------------------- + boolean isMerged = false; + + if (index == 0 || index == 2) + { + isMerged = mergeItemStack(newStack, 4, 40, true); + } + else if (index >= 4 && index < 31) + { + isMerged = !goldSlot.getHasStack() && newStack.getCount() <= 16 && mergeItemStack(newStack, 0, 1, false) + || !emeraldSlot.getHasStack() && mergeItemStack(newStack, 2, 3, false) + || mergeItemStack(newStack, 31, 40, false); + } + else if (index >= 31 && index < 40) + { + isMerged = !goldSlot.getHasStack() && newStack.getCount() <= 16 && mergeItemStack(newStack, 0, 1, false) + || !emeraldSlot.getHasStack() && mergeItemStack(newStack, 2, 3, false) + || mergeItemStack(newStack, 4, 31, false); + } + + if (!isMerged) + { + return ItemStack.EMPTY; + } + + //--------------------- + + if (!isMerged) + { + return ItemStack.EMPTY; + } + + if (newStack.getCount() == 0) + { + slot.putStack(ItemStack.EMPTY); + } + else + { + slot.onSlotChanged(); + } + + slot.onTake(playerIn, newStack); + + return oldStack; + } +} diff --git a/src/main/java/com/somebody/idlframewok/gui/expOne/GuiContainerDemo.java b/src/main/java/com/somebody/idlframewok/gui/expOne/GuiContainerDemo.java new file mode 100644 index 0000000..d2fd987 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/gui/expOne/GuiContainerDemo.java @@ -0,0 +1,134 @@ +package com.somebody.idlframewok.gui.expOne; + +import java.io.IOException; + +import com.somebody.idlframewok.IdlFramework; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.resources.I18n; +import net.minecraft.init.Items; +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +@SideOnly(Side.CLIENT) +public class GuiContainerDemo extends GuiContainer { + private static final String TEXTURE_PATH = IdlFramework.MODID + ":" + "textures/gui/container/gui_demo.png"; + private static final ResourceLocation TEXTURE = new ResourceLocation(TEXTURE_PATH); + + private static final int BUTTON_UP = 0; + private static final int BUTTON_DOWN = 1; + + private Slot ironSlot; + + @Override + protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) { + GlStateManager.color(1.0F, 1.0F, 1.0F); + + this.mc.getTextureManager().bindTexture(TEXTURE); + int offsetX = (this.width - this.xSize) / 2, offsetY = (this.height - this.ySize) / 2; + + this.drawTexturedModalRect(offsetX, offsetY, 0, 0, this.xSize, this.ySize); + } + + public GuiContainerDemo(ContainerDemo inventorySlotsIn) + { + super(inventorySlotsIn); + this.xSize = 176; + this.ySize = 133; + this.ironSlot = inventorySlotsIn.getIronSlot(); + } + + @Override + protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) + { + this.drawVerticalLine(30, 19, 36, 0xFF000000); + this.drawHorizontalLine(8, 167, 43, 0xFF000000); + + String title = I18n.format("container.fmltutor.demo"); + this.fontRenderer.drawString(title, (this.xSize - this.fontRenderer.getStringWidth(title)) / 2, 6, 0x404040); + + ItemStack item = new ItemStack(Items.QUARTZ); + this.itemRender.renderItemAndEffectIntoGUI(item, 8, 20); + } + + @Override + protected void actionPerformed(GuiButton button) throws IOException + { + ItemStack stack = this.ironSlot.getStack(); + int amount = stack == ItemStack.EMPTY ? 0 : stack.getCount(); + + switch (button.id) + { + case BUTTON_DOWN: + amount = (amount + 64) % 65; + break; + case BUTTON_UP: + amount = (amount + 1) % 65; + break; + default: + super.actionPerformed(button); + return; + } + + this.ironSlot.putStack(amount == 0 ? ItemStack.EMPTY : new ItemStack(Items.IRON_INGOT, amount)); + } + + @Override + public void initGui() + { + super.initGui(); + int offsetX = (this.width - this.xSize) / 2, offsetY = (this.height - this.ySize) / 2; + this.buttonList.add(new GuiButton(BUTTON_UP, offsetX + 153, offsetY + 17, 15, 10, "") + { + @Override + public void drawButton(Minecraft mc, int mouseX, int mouseY, float partialTicks) + { + if (this.visible) + { + GlStateManager.color(1.0F, 1.0F, 1.0F); + + mc.getTextureManager().bindTexture(TEXTURE); + int x = mouseX - this.x, y = mouseY - this.y; + + if (x >= 0 && y >= 0 && x < this.width && y < this.height) + { + this.drawTexturedModalRect(this.x, this.y, 1, 146, this.width, this.height); + } + else + { + this.drawTexturedModalRect(this.x, this.y, 1, 134, this.width, this.height); + } + } + } + }); + this.buttonList.add(new GuiButton(BUTTON_DOWN, offsetX + 153, offsetY + 29, 15, 10, "") + { + @Override + public void drawButton(Minecraft mc, int mouseX, int mouseY, float partialTicks) + { + if (this.visible) + { + GlStateManager.color(1.0F, 1.0F, 1.0F); + + mc.getTextureManager().bindTexture(TEXTURE); + int x = mouseX - this.x, y = mouseY - this.y; + + if (x >= 0 && y >= 0 && x < this.width && y < this.height) + { + this.drawTexturedModalRect(this.x, this.y, 20, 146, this.width, this.height); + } + else + { + this.drawTexturedModalRect(this.x, this.y, 20, 134, this.width, this.height); + } + } + } + }); + } +} + diff --git a/src/main/java/com/somebody/idlframewok/init/InitBiome.java b/src/main/java/com/somebody/idlframewok/init/InitBiome.java new file mode 100644 index 0000000..8ed778e --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/init/InitBiome.java @@ -0,0 +1,29 @@ +package com.somebody.idlframewok.init; + +import com.somebody.idlframewok.IdlFramework; +import net.minecraft.world.biome.Biome; +import net.minecraftforge.common.BiomeDictionary; +import net.minecraftforge.common.BiomeDictionary.Type; +import net.minecraftforge.common.BiomeManager; +import net.minecraftforge.common.BiomeManager.BiomeEntry; +import net.minecraftforge.fml.common.registry.ForgeRegistries; + +public class InitBiome { + //public static final Biome BIOME_ONE = new BiomeOne(); + public static void registerBiomes() + { + //initBiome(BIOME_ONE, "biome_one", BiomeManager.BiomeType.WARM, Type.HILLS, Type.DENSE); + } + + public static Biome initBiome(Biome biome, String name, BiomeManager.BiomeType biomeType, Type... type) + { + biome.setRegistryName(name); + ForgeRegistries.BIOMES.register(biome); + IdlFramework.LogWarning("Biome registered:%s", name); + BiomeDictionary.addTypes(biome, type); + BiomeManager.addBiome(biomeType, new BiomeEntry(biome, 10)); + BiomeManager.addSpawnBiome(biome); + return biome; + } + +} diff --git a/src/main/java/com/somebody/idlframewok/init/InitDimension.java b/src/main/java/com/somebody/idlframewok/init/InitDimension.java new file mode 100644 index 0000000..bd677ff --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/init/InitDimension.java @@ -0,0 +1,10 @@ +package com.somebody.idlframewok.init; + +public class InitDimension { + //public static final DimensionType DIM_ONE = DimensionType.register("Dim_one", "_testdim", ModConfig.DEBUG_CONF.DIM_ONE_ID, DimensionOne.class, false); + + public static void registerDimensions() + { + //DimensionManager.registerDimension(ModConfig.DEBUG_CONF.DIM_ONE_ID, DIM_ONE); + } +} diff --git a/src/main/java/com/somebody/idlframewok/init/ModAchivements.java b/src/main/java/com/somebody/idlframewok/init/ModAchivements.java new file mode 100644 index 0000000..990ee80 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/init/ModAchivements.java @@ -0,0 +1,7 @@ +package com.somebody.idlframewok.init; + +public class ModAchivements { + + //Todo: achivements + +} diff --git a/src/main/java/com/somebody/idlframewok/init/ModAnvilEvents.java b/src/main/java/com/somebody/idlframewok/init/ModAnvilEvents.java new file mode 100644 index 0000000..45fb98a --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/init/ModAnvilEvents.java @@ -0,0 +1,64 @@ +package com.somebody.idlframewok.init; + +import com.somebody.idlframewok.util.Reference; +import net.minecraftforge.event.AnvilUpdateEvent; +import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; + +@Mod.EventBusSubscriber(modid = Reference.MOD_ID) +public class ModAnvilEvents { +// @Cancelable +// public class AnvilUpdateEvent extends Event +// { +// @Nonnull +// private final ItemStack left; // The left side of the input +// @Nonnull +// private final ItemStack right; // The right side of the input +// private final String name; // The name to set the item, if the user specified one. +// @Nonnull +// private ItemStack output; // Set this to set the output stack +// private int cost; // The base cost, set this to change it if output != null +// private int materialCost; // The number of items from the right slot to be consumed during the repair. Leave as 0 to consume the entire stack. +// +// public AnvilUpdateEvent(@Nonnull ItemStack left, @Nonnull ItemStack right, String name, int cost) +// { +// this.left = left; +// this.right = right; +// this.output = ItemStack.EMPTY; +// this.name = name; +// this.setCost(cost); +// this.setMaterialCost(0); +// } +// +// @Nonnull +// public ItemStack getLeft() { return left; } +// @Nonnull +// public ItemStack getRight() { return right; } +// public String getName() { return name; } +// @Nonnull +// public ItemStack getOutput() { return output; } +// public void setOutput(@Nonnull ItemStack output) { this.output = output; } +// public int getCost() { return cost; } +// public void setCost(int cost) { this.cost = cost; } +// public int getMaterialCost() { return materialCost; } +// public void setMaterialCost(int materialCost) { this.materialCost = materialCost; } +// } + + @SubscribeEvent + public static void checkEdictCraft(AnvilUpdateEvent event) + { +// if (event.getLeft() != ItemStack.EMPTY && event.getRight() != ItemStack.EMPTY ) { +// ItemStack left = event.getLeft(); +// ItemStack right = event.getRight(); +// +// if (left.getItem() == Items.PAPER && right.getItem() == Item.getItemFromBlock(Blocks.GOLD_BLOCK)) +// { +// event.setMaterialCost(1); +// event.setCost(30); +// +// ItemStack result = new ItemStack(ModItems.RANDOM_EDICT); +// event.setOutput(result); +// } +// } + } +} diff --git a/src/main/java/com/somebody/idlframewok/init/ModConfig.java b/src/main/java/com/somebody/idlframewok/init/ModConfig.java new file mode 100644 index 0000000..92c6b6a --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/init/ModConfig.java @@ -0,0 +1,59 @@ +package com.somebody.idlframewok.init; + +import com.somebody.idlframewok.util.Reference; +import net.minecraftforge.common.config.Config; +import net.minecraftforge.common.config.ConfigManager; +import net.minecraftforge.fml.client.event.ConfigChangedEvent; +import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; + +@Config(modid = Reference.MOD_ID, category = "") +public class ModConfig { + @Mod.EventBusSubscriber(modid = Reference.MOD_ID) + private static class EventHandler { + + private EventHandler() { + } + + @SubscribeEvent + public static void onConfigChanged(final ConfigChangedEvent.OnConfigChangedEvent event) { + if (event.getModID().equals(Reference.MOD_ID)) { + ConfigManager.sync(Reference.MOD_ID, Config.Type.INSTANCE); + } + } + } + + @Config.LangKey("configgui.idlframewok.category.Menu0.GeneralConf") + @Config.Comment("IdlFramework general config.") + public static final GeneralConf GeneralConf = new GeneralConf(); + + public static class GeneralConf { +// @Config.LangKey("idlframewok.conf.general.welcome") +// @Config.Comment("The text shown when a player logs in. Can be a key or a string.") +// public String WELCOME_MSG = "idlframewok.msg.welcome"; + } + + @Config.LangKey("configgui.idlframewok.category.Menu0.DebugConf") + @Config.Comment("Config for developers") + public static final DebugConf DEBUG_CONF = new DebugConf(); + + public static class DebugConf { + + } + + @Config.LangKey("configgui.idlframewok.category.Menu0.SpawnConf") + @Config.Comment("Spawning") + public static final SpawnConf SPAWN_CONF = new SpawnConf(); + + public static class SpawnConf { + @Config.LangKey("conf.spawn.enabled") + @Config.Comment("Spawn mod creatures") + @Config.RequiresMcRestart + public boolean SPAWN = true; + +// @Config.LangKey("entity.moroon_tainter.name") +// @Config.Comment("Spawn Moroon Tainter") +// @Config.RequiresMcRestart +// public int SPAWN_TAINTER = 100; + } +} diff --git a/src/main/java/com/somebody/idlframewok/init/ModCreativeTab.java b/src/main/java/com/somebody/idlframewok/init/ModCreativeTab.java new file mode 100644 index 0000000..da14f2e --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/init/ModCreativeTab.java @@ -0,0 +1,18 @@ +package com.somebody.idlframewok.init; + +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.init.Items; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +public class ModCreativeTab { + public static final CreativeTabs IDL_MISC = new CreativeTabs(CreativeTabs.getNextID(), "ideallandMiscTab") + { + @SideOnly(Side.CLIENT) + public ItemStack getTabIconItem() + { + return new ItemStack(Items.QUARTZ); + } + }; +} diff --git a/src/main/java/com/somebody/idlframewok/init/ModLootList.java b/src/main/java/com/somebody/idlframewok/init/ModLootList.java new file mode 100644 index 0000000..4f0ea77 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/init/ModLootList.java @@ -0,0 +1,61 @@ +package com.somebody.idlframewok.init; + +import java.io.File; +import java.util.Collections; +import java.util.Set; + +import com.google.common.collect.Sets; +import com.somebody.idlframewok.util.Reference; +import net.minecraft.util.ResourceLocation; +import net.minecraft.world.storage.loot.LootTable; +import net.minecraft.world.storage.loot.LootTableManager; + +public class ModLootList { + + private static final Set LOOT_TABLES = Sets.newHashSet(); + private static final Set READ_ONLY_LOOT_TABLES = Collections.unmodifiableSet(LOOT_TABLES); + public static final ResourceLocation EMPTY = register("empty"); + //public static final ResourceLocation M_O_B = register("entities/mor_orbital_beacon"); + + + private static ResourceLocation register(String id) + { + return register(new ResourceLocation(Reference.MOD_ID, "loot_table/" + id)); + } + + public static ResourceLocation register(ResourceLocation id) + { + if (LOOT_TABLES.add(id)) + { + return id; + } + else + { + throw new IllegalArgumentException(id + " is already a registered modded loot table"); + } + } + + /** + * An unmodifiable set is returned + */ + public static Set getAll() + { + return READ_ONLY_LOOT_TABLES; + } + + public static boolean test() + { + LootTableManager loottablemanager = new LootTableManager((File)null); + + for (ResourceLocation resourcelocation : READ_ONLY_LOOT_TABLES) + { + if (loottablemanager.getLootTableFromLocation(resourcelocation) == LootTable.EMPTY_LOOT_TABLE) + { + return false; + } + } + + return true; + } + +} diff --git a/src/main/java/com/somebody/idlframewok/init/ModRecipes.java b/src/main/java/com/somebody/idlframewok/init/ModRecipes.java new file mode 100644 index 0000000..02fdbc1 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/init/ModRecipes.java @@ -0,0 +1,28 @@ +package com.somebody.idlframewok.init; + +import com.somebody.idlframewok.util.Reference; +import net.minecraft.item.crafting.IRecipe; +import net.minecraftforge.event.RegistryEvent; +import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.registries.IForgeRegistry; + +@Mod.EventBusSubscriber(modid = Reference.MOD_ID) +public class ModRecipes { + + + public static void Init() { + //Only smelting recipes +// GameRegistry.addSmelting(ModItems.PURE_INGOT, +// new ItemStack(ModItems.WEAPON_PEARL), +// 0.1f); + + } + + @SubscribeEvent + public static void registerRecipes(RegistryEvent.Register evt) { + IForgeRegistry r = evt.getRegistry(); + //Example + //r.register(new GobletFill().setRegistryName(new ResourceLocation(Reference.MOD_ID, "goblet_fill"))); + } +} diff --git a/src/main/java/com/somebody/idlframewok/init/ModSpawn.java b/src/main/java/com/somebody/idlframewok/init/ModSpawn.java new file mode 100644 index 0000000..a4ca6e3 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/init/ModSpawn.java @@ -0,0 +1,103 @@ +package com.somebody.idlframewok.init; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +import net.minecraft.entity.EntityLiving; +import net.minecraft.entity.EnumCreatureType; +import net.minecraft.world.biome.Biome; +import net.minecraftforge.common.BiomeDictionary; +import net.minecraftforge.common.BiomeDictionary.Type; + +public class ModSpawn { + + /** + * Register Mobs based on Biome sub Types + */ + public static void registerSpawnList() { + Map> biomeMap = buildBiomeListByType(); + + addNormalSpawn(biomeMap); + addHumidSpawn(biomeMap); + addOpenGroundSpawn(biomeMap); + } + + //Mob + public static void add(Biome biome, int weight, Class entityclassIn, int groupCountMin, int groupCountMax) { + if (weight > 0) { + biome.getSpawnableList(EnumCreatureType.MONSTER).add(new Biome.SpawnListEntry(entityclassIn, weight, groupCountMin, groupCountMax)); + } + } + + public static void add_friendly(Biome biome, int weight, Class entityclassIn, int groupCountMin, int groupCountMax) { + if (weight > 0) { + biome.getSpawnableList(EnumCreatureType.CREATURE).add(new Biome.SpawnListEntry(entityclassIn, weight, groupCountMin, groupCountMax)); + } + } + + private static Map> buildBiomeListByType() { + Map> biomesAndTypes = new HashMap<>(); + + for (Biome biome : Biome.REGISTRY) { + Set types = BiomeDictionary.getTypes(biome); + for (BiomeDictionary.Type type : types) { + if (!biomesAndTypes.containsKey(type)) { + biomesAndTypes.put(type, new HashSet<>()); + } + + biomesAndTypes.get(type).add(biome); + } + } + + return biomesAndTypes; + } + + private static void addNormalSpawn(Map> biomeMap) { + for (Biome biome : Biome.REGISTRY) { + //Example Spawn + //add(biome, ModConfig.SPAWN_CONF.SPAWN_TAINTER, EntityMoroonTainter.class, 1, 4); + } + } + + private static void addOpenGroundSpawn(Map> biomeMap) { + for (Biome biome : Biome.REGISTRY) { + //if (!BiomeDictionary.hasType(biome, Type.DENSE)) + // add(biome, ModConfig.SPAWN_CONF.SPAWN_SKELETON_TOWER, EntitySpawnTower.class, 1, 1); + } + } + + private static void addHumidSpawn(Map> biomeMap) { + for (Biome biome : Biome.REGISTRY) { + if (BiomeDictionary.hasType(biome, Type.WET) || (BiomeDictionary.hasType(biome, Type.WATER))) + { + //add(biome, ModConfig.SPAWN_CONF.SPAWN_TIDE_MAKER, EntityMoroonTideMaker.class, 1, 1); + } + } + } + + private static void addNetherSPAWN(Map> biomeMap) { + /* + * NETHER + */ +// for (Biome biome : biomeMap.get(Type.NETHER)) { +// add(10, EntityMoroonTainter.class, 1, 4, biome); +// } + } + + /** + * Bridge Method for simpler spawning registry + * + * @param weight Spawn rate + * @param entityclassIn Entity + * @param groupCountMin Minimum amount (always 1) + * @param groupCountMax Maximum amount (depreciated due to chunk limits) + * @param biome Biome + */ + public static void add(int weight, Class entityclassIn, int groupCountMin, int groupCountMax, Biome biome) { + if (weight > 0) { + biome.getSpawnableList(EnumCreatureType.MONSTER).add(new Biome.SpawnListEntry(entityclassIn, weight, groupCountMin, groupCountMax)); + } + } +} diff --git a/src/main/java/com/somebody/idlframewok/init/RegistryHandler.java b/src/main/java/com/somebody/idlframewok/init/RegistryHandler.java new file mode 100644 index 0000000..6910db3 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/init/RegistryHandler.java @@ -0,0 +1,95 @@ +package com.somebody.idlframewok.init; + +import com.somebody.idlframewok.blocks.ModBlocks; +import com.somebody.idlframewok.enchantments.ModEnchantmentInit; +import com.somebody.idlframewok.entity.ModEntityInit; +import com.somebody.idlframewok.entity.RenderHandler; +import com.somebody.idlframewok.item.ModItems; +import com.somebody.idlframewok.util.IHasModel; +import com.somebody.idlframewok.util.ModSoundHandler; +import net.minecraft.block.Block; +import net.minecraft.enchantment.Enchantment; +import net.minecraft.item.Item; +import net.minecraftforge.client.event.ModelRegistryEvent; +import net.minecraftforge.event.RegistryEvent; +import net.minecraftforge.fml.common.Mod.EventBusSubscriber; +import net.minecraftforge.fml.common.event.FMLInitializationEvent; +import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; +import net.minecraftforge.fml.common.event.FMLServerStartingEvent; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +@EventBusSubscriber +public class RegistryHandler { + @SubscribeEvent + public static void onItemRegister(RegistryEvent.Register event) + { + event.getRegistry().registerAll(ModItems.ITEMS.toArray(new Item[0])); + } + + @SubscribeEvent + public static void onBlockRegister(RegistryEvent.Register event) { + event.getRegistry().registerAll(ModBlocks.BLOCKS.toArray(new Block[0])); + } + + @SubscribeEvent + public static void onEnchantmentRegister(RegistryEvent.Register event) + { + ModEnchantmentInit.BeforeRegister(); + event.getRegistry().registerAll(ModEnchantmentInit.ENCHANTMENT_LIST.toArray(new Enchantment[0])); + +// for (Enchantment enchantment : Enchantment.REGISTRY) { +// IdlFramework.Log("registered enchantments: %s", enchantment.getName()); +// } + } + + @SideOnly(Side.CLIENT) + @SubscribeEvent + public static void onModelRegister(ModelRegistryEvent event) + { + for(Item item : ModItems.ITEMS) + { + if (item instanceof IHasModel) + { + ((IHasModel)item).registerModels(); + } + } + + for(Block block : ModBlocks.BLOCKS) + { + if (block instanceof IHasModel) + { + ((IHasModel)block).registerModels(); + } + } + + RenderHandler.registerEntityRenders(); + } + + public static void preInitRegistries(FMLPreInitializationEvent event) + { + //GameRegistry.registerWorldGenerator(new ModWorldGenOld(), 100); + //GameRegistry.registerWorldGenerator(new ModWorldGenNew(), 120); + + InitBiome.registerBiomes(); + InitDimension.registerDimensions(); + + ModEntityInit.registerEntities(); + } + + public static void postInitReg() + { + //WorldType TYPE_ONE = new WorldTypeOne(); + } + + public static void initRegistries(FMLInitializationEvent event) + { + ModSoundHandler.soundRegister(); + } + + public static void serverRegistries(FMLServerStartingEvent event) + { + //event.registerServerCommand(new CommandDimTeleport()); + } +} diff --git a/src/main/java/com/somebody/idlframewok/item/IGuaEnhance.java b/src/main/java/com/somebody/idlframewok/item/IGuaEnhance.java new file mode 100644 index 0000000..e1c62b7 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/item/IGuaEnhance.java @@ -0,0 +1,7 @@ +package com.somebody.idlframewok.item; + +public interface IGuaEnhance { + //Some item accepts not every gua + public boolean acceptGuaIndex(int index); + +} diff --git a/src/main/java/com/somebody/idlframewok/item/ItemAdaptingBase.java b/src/main/java/com/somebody/idlframewok/item/ItemAdaptingBase.java new file mode 100644 index 0000000..9a8ac5b --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/item/ItemAdaptingBase.java @@ -0,0 +1,119 @@ +package com.somebody.idlframewok.item; + +import com.somebody.idlframewok.util.CommonDef; +import net.minecraft.enchantment.Enchantment; +import net.minecraft.enchantment.EnchantmentHelper; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Enchantments; +import net.minecraft.item.EnumAction; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumHand; +import net.minecraft.world.World; + +public class ItemAdaptingBase extends ItemBase { + public ItemAdaptingBase(String name) { + super(name); + } + + public float base_power = 6f; + public float base_range = 3f; + public float base_cd = 10f; + + public float getPower(ItemStack stack) + { + float result = base_power; + int powerEnchant = EnchantmentHelper.getEnchantmentLevel(Enchantments.POWER, stack); + + if (powerEnchant > 0) + { + result += powerEnchant ; + } + return result; + } + + public float getRange(ItemStack stack) + { + float result = base_power; + int powerEnchant = EnchantmentHelper.getEnchantmentLevel(Enchantments.POWER, stack); + + if (powerEnchant > 0) + { + result += powerEnchant ; + } + return result; + } + + + public int getCoolDownTicks(ItemStack stack) + { + return (int) (base_cd * CommonDef.TICK_PER_SECOND); + } + + @Override + public int getMaxDamage(ItemStack stack) { + return 256; + } + + /** + * How long it takes to use or consume an item + */ + public int getMaxItemUseDuration(ItemStack stack) + { + return 72000; + } + + /** + * returns the action that specifies what animation to play when the items is being used + */ + public EnumAction getItemUseAction(ItemStack stack) + { + return EnumAction.BOW; + } + + @Override + public boolean canApplyAtEnchantingTable(ItemStack stack, Enchantment enchantment) { + if (enchantment == Enchantments.PUNCH || enchantment == Enchantments.INFINITY) + { + return false; + } + + if (enchantment == Enchantments.POWER || enchantment == Enchantments.UNBREAKING) + { + return true; + } + + return super.canApplyAtEnchantingTable(stack, enchantment); + } + + /** + * Called when the player stops using an Item (stops holding the right mouse button). + */ + public void onPlayerStoppedUsing(ItemStack stack, World worldIn, EntityLivingBase entityLiving, int timeLeft) + { + if (!useable) + { + return; + } + + onCreatureStoppedUsing(stack, worldIn, entityLiving, timeLeft); + entityLiving.swingArm(entityLiving.getHeldItemMainhand() == stack ? EnumHand.MAIN_HAND : EnumHand.OFF_HAND); + + if (!worldIn.isRemote) + { + if (entityLiving instanceof EntityPlayer) + { + EntityPlayer entityplayer = (EntityPlayer)entityLiving; + { + entityplayer.getCooldownTracker().setCooldown(this, getCoolDownTicks(stack)); + } + } + } + } + + + public void onCreatureStoppedUsing(ItemStack stack, World worldIn, EntityLivingBase entityLiving, int timeLeft) + { + + } +} diff --git a/src/main/java/com/somebody/idlframewok/item/ItemArmorBase.java b/src/main/java/com/somebody/idlframewok/item/ItemArmorBase.java new file mode 100644 index 0000000..2ef7a6a --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/item/ItemArmorBase.java @@ -0,0 +1,215 @@ +package com.somebody.idlframewok.item; + +import java.util.List; +import java.util.UUID; +import javax.annotation.Nullable; + +import com.google.common.collect.HashMultimap; +import com.google.common.collect.Multimap; +import com.somebody.idlframewok.IdlFramework; +import com.somebody.idlframewok.init.ModCreativeTab; +import com.somebody.idlframewok.util.CommonFunctions; +import com.somebody.idlframewok.util.IDLSkillNBT; +import com.somebody.idlframewok.util.IHasModel; +import com.somebody.idlframewok.util.NBTStrDef.IDLNBTDef; +import com.somebody.idlframewok.util.NBTStrDef.IDLNBTUtil; +import net.minecraft.client.resources.I18n; +import net.minecraft.client.util.ITooltipFlag; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.ai.attributes.AttributeModifier; +import net.minecraft.inventory.EntityEquipmentSlot; +import net.minecraft.item.EnumRarity; +import net.minecraft.item.ItemArmor; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +//try to sync with ItemBase +public class ItemArmorBase extends ItemArmor implements IHasModel { + private boolean overrideRarity = false; + private EnumRarity enumRarity = EnumRarity.COMMON; + protected boolean showGuaSocketDesc = false; + protected boolean shiftToShowDesc = false; + protected boolean use_flavor = false; + protected boolean useable = false; + protected boolean logNBT = false; + + protected boolean ignoreVanillaSystem = false; + + protected static final UUID[] ARMOR_MODIFIERS_OVERRIDE = new UUID[] {UUID.fromString("845DB27C-C624-495F-8C9F-6020A9A58B6B"), UUID.fromString("D8499B04-0E66-4726-AB29-64469D734E0D"), UUID.fromString("9F3D476D-C118-4544-8365-64846904B48E"), UUID.fromString("2AD3F246-FEE1-4E67-B886-69FD380BB150")}; + private String texturePath; + public ItemArmorBase(String name, ArmorMaterial materialIn, int renderIndexIn, EntityEquipmentSlot equipmentSlotIn) { + super(materialIn, renderIndexIn, equipmentSlotIn); + setUnlocalizedName(name); + setRegistryName(name); + setCreativeTab(ModCreativeTab.IDL_MISC); + + ModItems.ITEMS.add(this); + + InitItem(); + } + + public void InitItem() + { + + } + + public ItemArmorBase setRarity(EnumRarity enumRarity) + { + overrideRarity = true; + this.enumRarity = enumRarity; + return this; + } + + public EnumRarity getRarity(ItemStack stack) + { + if (overrideRarity) + { + return enumRarity; + }else { + return super.getRarity(stack); + } + } + + public String GetStringForThisByKey(String key) + { + return CommonFunctions.GetStringLocalTranslated(getUnlocalizedName() + key); + } + + public String GetBasicDesc() + { + return CommonFunctions.GetStringLocalTranslated(getUnlocalizedName() + IDLNBTDef.DESC_COMMON); + } + +// @Override +// public void onUsingTick(ItemStack stack, EntityLivingBase living, int count) { +// //Particle; +// super.onUsingTick(stack, living, count); +// //IdlFramework.LogWarning(String.format("base onUsingTick %s",count)); +// +// if (living.world.isRemote) +// { +// clientUseTick(stack, living, getMaxItemUseDuration(stack) - count); +// } +// else +// { +// serverUseTick(stack, living, getMaxItemUseDuration(stack) - count); +// } +// } +// +// public void clientUseTick(ItemStack stack, EntityLivingBase living, int count) +// { +// +// } +// +// public void serverUseTick(ItemStack stack, EntityLivingBase living, int count) +// { +// +// } + + /** + * Called by RenderBiped and RenderPlayer to determine the armor texture that + * should be use for the currently equipped item. + * This will only be called on instances of ItemArmor. + * + * Returning null from this function will use the default value. + * + * @param stack ItemStack for the equipped armor + * @param entity The entity wearing the armor + * @param slot The slot the armor is in + * @param type The subtype, can be null or "overlay" + * @return Path of texture to bind, or null to use default + */ + @Nullable + public String getArmorTexture(ItemStack stack, Entity entity, EntityEquipmentSlot slot, String type) + { + return null; + } + + + @Override + public void registerModels() + { + IdlFramework.proxy.registerItemRenderer(this, 0, "inventory"); + } + + + @SideOnly(Side.CLIENT) + @Override + public void addInformation(ItemStack stack, World world, List tooltip, ITooltipFlag flag) { + + IDLSkillNBT.addInformation(stack,world,tooltip,flag,shiftToShowDesc, showGuaSocketDesc, use_flavor, + getMainDesc(stack,world,tooltip,flag)); + + if (logNBT) + { + tooltip.add(IDLNBTUtil.getNBT(stack).toString()); + } + } + + @SideOnly(Side.CLIENT) + public String descGetKey(ItemStack stack, World world, boolean showFlavor) + { + return showFlavor ? (stack.getUnlocalizedName() + IDLNBTDef.FLAVOR_KEY) + : (stack.getUnlocalizedName() + IDLNBTDef.DESC_COMMON); + } + + @SideOnly(Side.CLIENT) + public String getMainDesc(ItemStack stack, World world, List tooltip, ITooltipFlag flag) + { + if (CommonFunctions.isShiftPressed() || !shiftToShowDesc) + { + String key = descGetKey(stack,world,false); + if (I18n.hasKey(key)) + { + return I18n.format(key); + } + else + { + return ""; + } + } + + if (!CommonFunctions.isShiftPressed() && use_flavor) + { + String key = descGetKey(stack,world,true); + if (I18n.hasKey(key)) + { + return I18n.format(key); + } + else + { + return ""; + } + } + return ""; + } + + //virtual + public void onUpdateWearing(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) { + + } + + @Override + public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) { + super.onUpdate(stack, worldIn, entityIn, itemSlot, isSelected); + + EntityLivingBase living = (EntityLivingBase) entityIn; + if (living.getItemStackFromSlot(armorType) == stack) + { + onUpdateWearing(stack, worldIn, entityIn, itemSlot, isSelected); + } + } + + public Multimap getAttributeModifiers(EntityEquipmentSlot equipmentSlot, ItemStack stack) + { + if (ignoreVanillaSystem) + { + return HashMultimap.create(); + }else { + return super.getAttributeModifiers(equipmentSlot, stack); + } + } +} diff --git a/src/main/java/com/somebody/idlframewok/item/ItemArmorLivingMetalBase.java b/src/main/java/com/somebody/idlframewok/item/ItemArmorLivingMetalBase.java new file mode 100644 index 0000000..e6ef417 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/item/ItemArmorLivingMetalBase.java @@ -0,0 +1,121 @@ +package com.somebody.idlframewok.item; + +import com.google.common.collect.Multimap; +import com.somebody.idlframewok.util.CommonDef; +import com.somebody.idlframewok.util.CommonFunctions; +import com.somebody.idlframewok.util.IHasModel; +import com.somebody.idlframewok.util.NBTStrDef.IDLNBTDef; +import com.somebody.idlframewok.util.NBTStrDef.IDLNBTUtil; +import com.somebody.idlframewok.util.Reference; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.SharedMonsterAttributes; +import net.minecraft.entity.ai.attributes.AttributeModifier; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.inventory.EntityEquipmentSlot; +import net.minecraft.item.ItemStack; +import net.minecraft.util.FoodStats; +import net.minecraft.world.World; +import net.minecraftforge.event.entity.living.LivingHealEvent; +import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.common.eventhandler.EventPriority; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; + +//try to sync with ItemBase +@Mod.EventBusSubscriber(modid = Reference.MOD_ID) +public class ItemArmorLivingMetalBase extends ItemArmorBase implements IHasModel { + + public ItemArmorLivingMetalBase(String name, ArmorMaterial materialIn, int renderIndexIn, EntityEquipmentSlot equipmentSlotIn) { + super(name, materialIn, renderIndexIn, equipmentSlotIn); + ignoreVanillaSystem = false; + } + + public int getRepairAmount(ItemStack stack, Entity entityIn) + { + return 1; + } + + public double getHealthPlus(ItemStack stack) + { + return 1; + } + + @Override + public void onUpdateWearing(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) { + super.onUpdateWearing(stack, worldIn, entityIn, itemSlot, isSelected); + EntityPlayer player = (EntityPlayer) entityIn; + + if (worldIn.getWorldTime() % CommonDef.TICK_PER_SECOND == 0) + { + boolean flagRule = player.world.getGameRules().getBoolean("naturalRegeneration"); + FoodStats stats = player.getFoodStats(); + if (flagRule && stats.getFoodLevel() >= 20) + { + // && stats.getSaturationLevel() > 0.0F && + if (player.getHealth() >= player.getMaxHealth()) + { + CommonFunctions.RepairItem(stack, getRepairAmount(stack, entityIn)); + } + } + } + + if (!worldIn.isRemote) + { + if (((float)stack.getItemDamage() / stack.getMaxDamage()) >= 0.9f) + { + if (worldIn.getWorldTime() % CommonDef.TICK_PER_SECOND == 0 && !IDLNBTUtil.GetBoolean(stack, IDLNBTDef.BIOMETAL_WARNED, false)) { + IDLNBTUtil.SetBoolean(stack, IDLNBTDef.BIOMETAL_WARNED, true); + CommonFunctions.SendMsgToPlayer((EntityPlayerMP) player, "idlframewok.msg.low_dura", stack.getDisplayName()); + } + } + else { + IDLNBTUtil.SetBoolean(stack, IDLNBTDef.BIOMETAL_WARNED, false); + } + } + + } + + public Multimap getAttributeModifiers(EntityEquipmentSlot equipmentSlot, ItemStack stack) + { + Multimap multimap = super.getAttributeModifiers(equipmentSlot, stack); + + if (equipmentSlot == this.armorType) + { + //multimap.put(SharedMonsterAttributes.ARMOR.getName(), new AttributeModifier(ARMOR_MODIFIERS_OVERRIDE[equipmentSlot.getIndex()], "Armor modifier", (double)this.damageReduceAmount, 0)); + //multimap.put(SharedMonsterAttributes.ARMOR_TOUGHNESS.getName(), new AttributeModifier(ARMOR_MODIFIERS_OVERRIDE[equipmentSlot.getIndex()], "Armor toughness", (double)this.toughness, 0)); + multimap.put(SharedMonsterAttributes.MAX_HEALTH.getName(), new AttributeModifier(ARMOR_MODIFIERS_OVERRIDE[equipmentSlot.getIndex()],"Health modifier", getHealthPlus(stack), 0)); + //multimap.put(SharedMonsterAttributes.LUCK.getName(), new AttributeModifier(ARMOR_MODIFIERS_OVERRIDE[equipmentSlot.getIndex()], "Luck", (double)1f, 0)); + } + + return multimap; + } + + @SubscribeEvent(priority = EventPriority.LOWEST) + public static void OnWearerHeal(LivingHealEvent event) + { + if (event.isCanceled()) + { + return; + } + + EntityLivingBase livingBase = event.getEntityLiving(); + for (EntityEquipmentSlot slot: + EntityEquipmentSlot.values()){ + ItemStack stack = livingBase.getItemStackFromSlot(slot); + if (stack.getItem() instanceof ItemArmorLivingMetalBase) + { + CommonFunctions.RepairItem(stack,Math.round(event.getAmount())); + } + } + } + +// @SideOnly(Side.CLIENT) +// @Override +// public void addInformation(ItemStack stack, World world, List tooltip, ITooltipFlag flag) { +// super.addInformation(stack, world, tooltip, flag); +// +// //tooltip.add(I18n.format("idlframewok.gua_enhance_total.desc", IDLSkillNBT.GetGuaEnhanceTotal(stack))); +// tooltip.add(IDLNBTUtil.getNBT(stack).toString()); +// } +} diff --git a/src/main/java/com/somebody/idlframewok/item/ItemAxeBase.java b/src/main/java/com/somebody/idlframewok/item/ItemAxeBase.java new file mode 100644 index 0000000..e6a2cd3 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/item/ItemAxeBase.java @@ -0,0 +1,170 @@ +package com.somebody.idlframewok.item; + +import java.util.List; + +import com.somebody.idlframewok.IdlFramework; +import com.somebody.idlframewok.init.ModCreativeTab; +import com.somebody.idlframewok.util.CommonFunctions; +import com.somebody.idlframewok.util.IDLSkillNBT; +import com.somebody.idlframewok.util.IHasModel; +import com.somebody.idlframewok.util.NBTStrDef.IDLNBTDef; +import com.somebody.idlframewok.util.NBTStrDef.IDLNBTUtil; +import net.minecraft.client.resources.I18n; +import net.minecraft.client.util.ITooltipFlag; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.item.EnumRarity; +import net.minecraft.item.ItemAxe; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +public class ItemAxeBase extends ItemAxe implements IHasModel { + private boolean overrideRarity = false; + private EnumRarity enumRarity = EnumRarity.COMMON; + protected boolean showGuaSocketDesc = false; + protected boolean shiftToShowDesc = false; + protected boolean use_flavor = false; + protected boolean useable = false; + private boolean isRangedWeapon = false; + protected boolean logNBT = false; + protected boolean glitters = false; + + //for accessing the private value + protected ToolMaterial toolMaterial; + + public ItemAxeBase(String name, ToolMaterial material) + { + super(material, 8.0F, -2.8F); + setUnlocalizedName(name); + setRegistryName(name); + setCreativeTab(ModCreativeTab.IDL_MISC); + toolMaterial = material; + ModItems.ITEMS.add(this); + + InitItem(); + } + + public ItemAxeBase setRarity(EnumRarity enumRarity) + { + overrideRarity = true; + this.enumRarity = enumRarity; + return this; + } + + public EnumRarity getRarity(ItemStack stack) + { + if (overrideRarity) + { + return enumRarity; + }else { + return super.getRarity(stack); + } + } + + public void InitItem() + { + if (this instanceof IGuaEnhance) + { + showGuaSocketDesc = true; + } + } + + public String GetStringForThisByKey(String key) + { + return CommonFunctions.GetStringLocalTranslated(getUnlocalizedName() + key); + } + + public String GetBasicDesc() + { + return CommonFunctions.GetStringLocalTranslated(getUnlocalizedName() + IDLNBTDef.DESC_COMMON); + } + + @Override + public void onUsingTick(ItemStack stack, EntityLivingBase living, int count) { + //Particle; + super.onUsingTick(stack, living, count); + //Idealland.LogWarning(String.format("base onUsingTick %s",count)); + + if (living.world.isRemote) + { + clientUseTick(stack, living, getMaxItemUseDuration(stack) - count); + } + else + { + serverUseTick(stack, living, getMaxItemUseDuration(stack) - count); + } + } + + public void clientUseTick(ItemStack stack, EntityLivingBase living, int count) + { + + } + + public void serverUseTick(ItemStack stack, EntityLivingBase living, int count) + { + + } + + @Override + public void registerModels() + { + IdlFramework.proxy.registerItemRenderer(this, 0, "inventory"); + } + @SideOnly(Side.CLIENT) + @Override + public void addInformation(ItemStack stack, World world, List tooltip, ITooltipFlag flag) { + + IDLSkillNBT.addInformation(stack,world,tooltip,flag,shiftToShowDesc, showGuaSocketDesc, use_flavor, + getMainDesc(stack,world,tooltip,flag)); + + if (logNBT) + { + tooltip.add(IDLNBTUtil.getNBT(stack).toString()); + } + } + + @SideOnly(Side.CLIENT) + public String descGetKey(ItemStack stack, World world, boolean showFlavor) + { + return showFlavor ? (stack.getUnlocalizedName() + IDLNBTDef.FLAVOR_KEY) + : (stack.getUnlocalizedName() + IDLNBTDef.DESC_COMMON); + } + + @SideOnly(Side.CLIENT) + public String getMainDesc(ItemStack stack, World world, List tooltip, ITooltipFlag flag) + { + if (CommonFunctions.isShiftPressed() || !shiftToShowDesc) + { + String key = descGetKey(stack,world,false); + if (I18n.hasKey(key)) + { + return I18n.format(key); + } + else + { + return ""; + } + } + + if (!CommonFunctions.isShiftPressed() && use_flavor) + { + String key = descGetKey(stack,world,true); + if (I18n.hasKey(key)) + { + return I18n.format(key); + } + else + { + return ""; + } + } + return ""; + } + + //for accessing private values + protected float getBaseAttackDamage() + { + return 3.0F + toolMaterial.getAttackDamage(); + } +} diff --git a/src/main/java/com/somebody/idlframewok/item/ItemBase.java b/src/main/java/com/somebody/idlframewok/item/ItemBase.java new file mode 100644 index 0000000..345c51b --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/item/ItemBase.java @@ -0,0 +1,230 @@ +package com.somebody.idlframewok.item; + +import java.util.List; +import java.util.UUID; +import javax.annotation.Nonnull; + +import com.somebody.idlframewok.IdlFramework; +import com.somebody.idlframewok.init.ModCreativeTab; +import com.somebody.idlframewok.util.CommonFunctions; +import com.somebody.idlframewok.util.IDLSkillNBT; +import com.somebody.idlframewok.util.IHasModel; +import com.somebody.idlframewok.util.NBTStrDef.IDLNBTDef; +import com.somebody.idlframewok.util.NBTStrDef.IDLNBTUtil; +import net.minecraft.client.resources.I18n; +import net.minecraft.client.util.ITooltipFlag; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.EnumRarity; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ActionResult; +import net.minecraft.util.EnumActionResult; +import net.minecraft.util.EnumHand; +import net.minecraft.world.World; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +public class ItemBase extends Item implements IHasModel { + private boolean overrideRarity = false; + private EnumRarity enumRarity = EnumRarity.COMMON; + protected boolean showGuaSocketDesc = false; + protected boolean shiftToShowDesc = false; + protected boolean use_flavor = false; + protected boolean useable = false; + private boolean isRangedWeapon = false; + protected boolean logNBT = false; + protected boolean glitters = false; + + protected static final UUID OFF_HAND_MODIFIER = UUID.fromString("9271eeea-5f74-4e12-97b6-7cf3c60ef7a0"); + protected static final UUID MAIN_HAND_MODIFIER = UUID.fromString("7d766720-0695-46c6-b320-44529f3da63f"); + + protected static final UUID POWER_UP_MODIFIER = UUID.fromString("dc8a0a25-24c4-43a9-bfc3-e31e431f4ebf"); + protected static final UUID POWER_UP_MODIFIER_PERCENT = UUID.fromString("9236a0fe-8f9b-4ede-80a3-05386216d06f"); + + public ItemBase(String name) + { + setUnlocalizedName(name); + setRegistryName(name); + setCreativeTab(ModCreativeTab.IDL_MISC); + + ModItems.ITEMS.add(this); + + InitItem(); + } + + protected ItemBase setGlitter() + { + glitters = true; + return this; + } + + @SideOnly(Side.CLIENT) + public boolean hasEffect(ItemStack stack) + { + return stack.isItemEnchanted() || glitters; + } + + + public ItemBase setRangedWeapon() + { + isRangedWeapon = true; + return this; + } + + public ItemBase setRarity(EnumRarity enumRarity) + { + overrideRarity = true; + this.enumRarity = enumRarity; + return this; + } + + public EnumRarity getRarity(ItemStack stack) + { + if (overrideRarity) + { + return enumRarity; + }else { + return super.getRarity(stack); + } + } + + public void InitItem() + { + if (this instanceof IGuaEnhance) + { + showGuaSocketDesc = true; + } + } + + public boolean isRangedWeaponItem() + { + return isRangedWeapon; + } + + public String GetStringForThisByKey(String key) + { + return CommonFunctions.GetStringLocalTranslated(getUnlocalizedName() + key); + } + + public String GetBasicDesc() + { + return CommonFunctions.GetStringLocalTranslated(getUnlocalizedName() + IDLNBTDef.DESC_COMMON); + } + + @Override + public void onUsingTick(ItemStack stack, EntityLivingBase living, int count) { + //Particle; + super.onUsingTick(stack, living, count); + //IdlFramework.LogWarning(String.format("base onUsingTick %s",count)); + + if (living.world.isRemote) + { + clientUseTick(stack, living, getMaxItemUseDuration(stack) - count); + } + else + { + serverUseTick(stack, living, getMaxItemUseDuration(stack) - count); + } + } + + @Nonnull + @Override + public ActionResult onItemRightClick(World world, EntityPlayer player, @Nonnull EnumHand hand) { + if (useable) + { + player.setActiveHand(hand); + ItemStack stack = player.getHeldItem(hand); + boolean result = onUseSimple(player, stack); + if (result) + { + return ActionResult.newResult(EnumActionResult.SUCCESS, stack); + } + else { + return ActionResult.newResult(EnumActionResult.FAIL, stack); + } + } + else { + return super.onItemRightClick(world, player, hand); + } + } + + public boolean onUseSimple(EntityPlayer player, ItemStack stack) + { + return true; + } + + public void clientUseTick(ItemStack stack, EntityLivingBase living, int count) + { + + } + + public void serverUseTick(ItemStack stack, EntityLivingBase living, int count) + { + + } + + @Override + public void registerModels() + { + IdlFramework.proxy.registerItemRenderer(this, 0, "inventory"); + } + + + @SideOnly(Side.CLIENT) + @Override + public void addInformation(ItemStack stack, World world, List tooltip, ITooltipFlag flag) { + + IDLSkillNBT.addInformation(stack,world,tooltip,flag,shiftToShowDesc, showGuaSocketDesc, use_flavor, + getMainDesc(stack,world,tooltip,flag)); + + if (logNBT) + { + tooltip.add(IDLNBTUtil.getNBT(stack).toString()); + } + } + + @SideOnly(Side.CLIENT) + public String descGetKey(ItemStack stack, World world, boolean showFlavor) + { + return showFlavor ? (stack.getUnlocalizedName() + IDLNBTDef.FLAVOR_KEY) + : (stack.getUnlocalizedName() + IDLNBTDef.DESC_COMMON); + } + + @SideOnly(Side.CLIENT) + public String getMainDesc(ItemStack stack, World world, List tooltip, ITooltipFlag flag) + { + if (CommonFunctions.isShiftPressed() || !shiftToShowDesc) + { + String key = descGetKey(stack,world,false); + if (I18n.hasKey(key)) + { + return I18n.format(key); + } + else + { + return ""; + } + } + + if (!CommonFunctions.isShiftPressed() && use_flavor) + { + String key = descGetKey(stack,world,true); + if (I18n.hasKey(key)) + { + return I18n.format(key); + } + else + { + return ""; + } + } + return ""; + } + + public void onMouseFire(EntityPlayer player) + { + + } + +} diff --git a/src/main/java/com/somebody/idlframewok/item/ItemDebug.java b/src/main/java/com/somebody/idlframewok/item/ItemDebug.java new file mode 100644 index 0000000..c81ab0d --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/item/ItemDebug.java @@ -0,0 +1,136 @@ +package com.somebody.idlframewok.item; + +import java.util.List; + +import com.somebody.idlframewok.IdlFramework; +import com.somebody.idlframewok.entity.projectiles.EntityIdlProjectile; +import com.somebody.idlframewok.entity.projectiles.ProjectileArgs; +import com.somebody.idlframewok.gui.ModGuiElementLoader; +import com.somebody.idlframewok.util.NBTStrDef.IDLNBTUtil; +import net.minecraft.client.util.ITooltipFlag; +import net.minecraft.enchantment.Enchantment; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Items; +import net.minecraft.init.SoundEvents; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ActionResult; +import net.minecraft.util.EnumHand; +import net.minecraft.util.SoundCategory; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +public class ItemDebug extends ItemBase{ + int index = 0; + public ItemDebug SetIndex(int index){ + this.index = index; + return this; + } + public ItemDebug(String name) { + super(name); + } + + @SideOnly(Side.CLIENT) + @Override + public void addInformation(ItemStack stack, World world, List tooltip, ITooltipFlag flag) { + super.addInformation(stack, world, tooltip, flag); + + //tooltip.add(I18n.format("idlframewok.gua_enhance_total.desc", IDLSkillNBT.GetGuaEnhanceTotal(stack))); + tooltip.add(IDLNBTUtil.getNBT(stack).toString()); + } + +// public boolean isEnchantable(ItemStack stack) +// { +// return true; +// } +// +// @Override +// public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) { +// super.onUpdate(stack, worldIn, entityIn, itemSlot, isSelected); +// if (stack.isItemEnchantable()) +// { +// stack.addEnchantment(ModEnchantmentInit.fireBurn, 0); +// } +// } + + + void TestEnchant(World worldIn, EntityPlayer playerIn, EnumHand handIn) + { + int p_185291_0_ = 30; + ItemStack testItemStack = playerIn.getHeldItemOffhand(); + boolean allowTreasure = false; + Item item = testItemStack.getItem(); + boolean flag = item == Items.BOOK; + + for (Enchantment enchantment : Enchantment.REGISTRY) + { + boolean judge1 = !enchantment.isTreasureEnchantment() || allowTreasure; + boolean judge2 = enchantment.canApplyAtEnchantingTable(testItemStack); + boolean judge3 = flag && enchantment.isAllowedOnBooks(); + + IdlFramework.Log("[%s]Lv %d to %d, canApplyAtEnchantingTable = %s, judgement[%s,%s,%s]", + enchantment.getName(), + enchantment.getMinLevel(), + enchantment.getMaxLevel(), + enchantment.canApplyAtEnchantingTable(testItemStack), + judge1, judge2, judge3 + ); + if (judge1 && judge2 || judge3) + { + for (int i = enchantment.getMaxLevel(); i >= enchantment.getMinLevel() ; --i) + { + IdlFramework.Log("[%s] Lv.%d available range = %d to %d", enchantment.getName(), i, + enchantment.getMinEnchantability(i), enchantment.getMaxEnchantability(i)); + if (p_185291_0_ >= enchantment.getMinEnchantability(i) && p_185291_0_ <= enchantment.getMaxEnchantability(i)) + { + IdlFramework.Log("[%s] successfully elected", enchantment.getName()); + break; + } + } + } + } + } + + @Override + public ActionResult onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) { + + playerIn.swingArm(handIn); + + ItemStack stack = playerIn.getHeldItem(handIn); + + if (index == 2 && !worldIn.isRemote) { + EntityIdlProjectile bullet = new EntityIdlProjectile(worldIn, new ProjectileArgs(4f), playerIn, 0, 0.05, 0); + worldIn.spawnEntity(bullet); + IdlFramework.Log("bullet pos = %s", bullet.getPosition()); + worldIn.playSound(playerIn, playerIn.getPosition(), SoundEvents.ENTITY_PLAYER_LEVELUP, SoundCategory.PLAYERS, 1f, 1f); + //return + } + + if (!worldIn.isRemote) + { + //playerIn.getHeldItemOffhand().getItem() == ModItems.DEBUG_ITEM_3; + if (index == 3) + { + BlockPos pos = playerIn.getPosition(); + playerIn.openGui(IdlFramework.instance, ModGuiElementLoader.GUI_RESEARCH, worldIn, pos.getX(), pos.getY(), pos.getZ()); + } + //else + + //todo: optimize + //playerIn.openGui(IdlFramework.instance, ModGuiElementLoader.GUI_DEMO, worldIn, pos.getX(), pos.getY(), pos.getZ()); + +// for (int i = 1; i <= 1000; i++) +// { +// IDLNBTUtil.SetString(stack, "TEST", IDLNBTUtil.GetString(stack, "TEST", "") + "a"); +// } + } + //IdlFramework.Log("NBT len = %d", IDLNBTUtil.GetString(stack, "TEST", "").length()); + + //IDLSkillNBT.SetGuaEnhanceFree(playerIn.getHeldItem(handIn), 2); + return super.onItemRightClick(worldIn, playerIn, handIn); + } + + +} diff --git a/src/main/java/com/somebody/idlframewok/item/ItemHoeBase.java b/src/main/java/com/somebody/idlframewok/item/ItemHoeBase.java new file mode 100644 index 0000000..8795b81 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/item/ItemHoeBase.java @@ -0,0 +1,170 @@ +package com.somebody.idlframewok.item; + +import java.util.List; + +import com.somebody.idlframewok.IdlFramework; +import com.somebody.idlframewok.init.ModCreativeTab; +import com.somebody.idlframewok.util.CommonFunctions; +import com.somebody.idlframewok.util.IDLSkillNBT; +import com.somebody.idlframewok.util.IHasModel; +import com.somebody.idlframewok.util.NBTStrDef.IDLNBTDef; +import com.somebody.idlframewok.util.NBTStrDef.IDLNBTUtil; +import net.minecraft.client.resources.I18n; +import net.minecraft.client.util.ITooltipFlag; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.item.EnumRarity; +import net.minecraft.item.ItemHoe; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +public class ItemHoeBase extends ItemHoe implements IHasModel { + private boolean overrideRarity = false; + private EnumRarity enumRarity = EnumRarity.COMMON; + protected boolean showGuaSocketDesc = false; + protected boolean shiftToShowDesc = false; + protected boolean use_flavor = false; + protected boolean useable = false; + private boolean isRangedWeapon = false; + protected boolean logNBT = false; + protected boolean glitters = false; + + //for accessing the private value + protected ToolMaterial toolMaterial; + + public ItemHoeBase(String name, ToolMaterial material) + { + super(material); + setUnlocalizedName(name); + setRegistryName(name); + setCreativeTab(ModCreativeTab.IDL_MISC); + toolMaterial = material; + ModItems.ITEMS.add(this); + + InitItem(); + } + + public ItemHoeBase setRarity(EnumRarity enumRarity) + { + overrideRarity = true; + this.enumRarity = enumRarity; + return this; + } + + public EnumRarity getRarity(ItemStack stack) + { + if (overrideRarity) + { + return enumRarity; + }else { + return super.getRarity(stack); + } + } + + public void InitItem() + { + if (this instanceof IGuaEnhance) + { + showGuaSocketDesc = true; + } + } + + public String GetStringForThisByKey(String key) + { + return CommonFunctions.GetStringLocalTranslated(getUnlocalizedName() + key); + } + + public String GetBasicDesc() + { + return CommonFunctions.GetStringLocalTranslated(getUnlocalizedName() + IDLNBTDef.DESC_COMMON); + } + + @Override + public void onUsingTick(ItemStack stack, EntityLivingBase living, int count) { + //Particle; + super.onUsingTick(stack, living, count); + //Idealland.LogWarning(String.format("base onUsingTick %s",count)); + + if (living.world.isRemote) + { + clientUseTick(stack, living, getMaxItemUseDuration(stack) - count); + } + else + { + serverUseTick(stack, living, getMaxItemUseDuration(stack) - count); + } + } + + public void clientUseTick(ItemStack stack, EntityLivingBase living, int count) + { + + } + + public void serverUseTick(ItemStack stack, EntityLivingBase living, int count) + { + + } + + @Override + public void registerModels() + { + IdlFramework.proxy.registerItemRenderer(this, 0, "inventory"); + } + @SideOnly(Side.CLIENT) + @Override + public void addInformation(ItemStack stack, World world, List tooltip, ITooltipFlag flag) { + + IDLSkillNBT.addInformation(stack,world,tooltip,flag,shiftToShowDesc, showGuaSocketDesc, use_flavor, + getMainDesc(stack,world,tooltip,flag)); + + if (logNBT) + { + tooltip.add(IDLNBTUtil.getNBT(stack).toString()); + } + } + + @SideOnly(Side.CLIENT) + public String descGetKey(ItemStack stack, World world, boolean showFlavor) + { + return showFlavor ? (stack.getUnlocalizedName() + IDLNBTDef.FLAVOR_KEY) + : (stack.getUnlocalizedName() + IDLNBTDef.DESC_COMMON); + } + + @SideOnly(Side.CLIENT) + public String getMainDesc(ItemStack stack, World world, List tooltip, ITooltipFlag flag) + { + if (CommonFunctions.isShiftPressed() || !shiftToShowDesc) + { + String key = descGetKey(stack,world,false); + if (I18n.hasKey(key)) + { + return I18n.format(key); + } + else + { + return ""; + } + } + + if (!CommonFunctions.isShiftPressed() && use_flavor) + { + String key = descGetKey(stack,world,true); + if (I18n.hasKey(key)) + { + return I18n.format(key); + } + else + { + return ""; + } + } + return ""; + } + + //for accessing private values + protected float getBaseAttackDamage() + { + return 3.0F + toolMaterial.getAttackDamage(); + } +} diff --git a/src/main/java/com/somebody/idlframewok/item/ItemPickaxeBase.java b/src/main/java/com/somebody/idlframewok/item/ItemPickaxeBase.java new file mode 100644 index 0000000..a99df2d --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/item/ItemPickaxeBase.java @@ -0,0 +1,170 @@ +package com.somebody.idlframewok.item; + +import java.util.List; + +import com.somebody.idlframewok.IdlFramework; +import com.somebody.idlframewok.init.ModCreativeTab; +import com.somebody.idlframewok.util.CommonFunctions; +import com.somebody.idlframewok.util.IDLSkillNBT; +import com.somebody.idlframewok.util.IHasModel; +import com.somebody.idlframewok.util.NBTStrDef.IDLNBTDef; +import com.somebody.idlframewok.util.NBTStrDef.IDLNBTUtil; +import net.minecraft.client.resources.I18n; +import net.minecraft.client.util.ITooltipFlag; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.item.EnumRarity; +import net.minecraft.item.ItemPickaxe; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +public class ItemPickaxeBase extends ItemPickaxe implements IHasModel { + private boolean overrideRarity = false; + private EnumRarity enumRarity = EnumRarity.COMMON; + protected boolean showGuaSocketDesc = false; + protected boolean shiftToShowDesc = false; + protected boolean use_flavor = false; + protected boolean useable = false; + private boolean isRangedWeapon = false; + protected boolean logNBT = false; + protected boolean glitters = false; + + //for accessing the private value + protected ToolMaterial toolMaterial; + + public ItemPickaxeBase(String name, ToolMaterial material) + { + super(material); + setUnlocalizedName(name); + setRegistryName(name); + setCreativeTab(ModCreativeTab.IDL_MISC); + toolMaterial = material; + ModItems.ITEMS.add(this); + + InitItem(); + } + + public ItemPickaxeBase setRarity(EnumRarity enumRarity) + { + overrideRarity = true; + this.enumRarity = enumRarity; + return this; + } + + public EnumRarity getRarity(ItemStack stack) + { + if (overrideRarity) + { + return enumRarity; + }else { + return super.getRarity(stack); + } + } + + public void InitItem() + { + if (this instanceof IGuaEnhance) + { + showGuaSocketDesc = true; + } + } + + public String GetStringForThisByKey(String key) + { + return CommonFunctions.GetStringLocalTranslated(getUnlocalizedName() + key); + } + + public String GetBasicDesc() + { + return CommonFunctions.GetStringLocalTranslated(getUnlocalizedName() + IDLNBTDef.DESC_COMMON); + } + + @Override + public void onUsingTick(ItemStack stack, EntityLivingBase living, int count) { + //Particle; + super.onUsingTick(stack, living, count); + //Idealland.LogWarning(String.format("base onUsingTick %s",count)); + + if (living.world.isRemote) + { + clientUseTick(stack, living, getMaxItemUseDuration(stack) - count); + } + else + { + serverUseTick(stack, living, getMaxItemUseDuration(stack) - count); + } + } + + public void clientUseTick(ItemStack stack, EntityLivingBase living, int count) + { + + } + + public void serverUseTick(ItemStack stack, EntityLivingBase living, int count) + { + + } + + @Override + public void registerModels() + { + IdlFramework.proxy.registerItemRenderer(this, 0, "inventory"); + } + @SideOnly(Side.CLIENT) + @Override + public void addInformation(ItemStack stack, World world, List tooltip, ITooltipFlag flag) { + + IDLSkillNBT.addInformation(stack,world,tooltip,flag,shiftToShowDesc, showGuaSocketDesc, use_flavor, + getMainDesc(stack,world,tooltip,flag)); + + if (logNBT) + { + tooltip.add(IDLNBTUtil.getNBT(stack).toString()); + } + } + + @SideOnly(Side.CLIENT) + public String descGetKey(ItemStack stack, World world, boolean showFlavor) + { + return showFlavor ? (stack.getUnlocalizedName() + IDLNBTDef.FLAVOR_KEY) + : (stack.getUnlocalizedName() + IDLNBTDef.DESC_COMMON); + } + + @SideOnly(Side.CLIENT) + public String getMainDesc(ItemStack stack, World world, List tooltip, ITooltipFlag flag) + { + if (CommonFunctions.isShiftPressed() || !shiftToShowDesc) + { + String key = descGetKey(stack,world,false); + if (I18n.hasKey(key)) + { + return I18n.format(key); + } + else + { + return ""; + } + } + + if (!CommonFunctions.isShiftPressed() && use_flavor) + { + String key = descGetKey(stack,world,true); + if (I18n.hasKey(key)) + { + return I18n.format(key); + } + else + { + return ""; + } + } + return ""; + } + + //for accessing private values + protected float getBaseAttackDamage() + { + return 3.0F + toolMaterial.getAttackDamage(); + } +} diff --git a/src/main/java/com/somebody/idlframewok/item/ItemSpadeBase.java b/src/main/java/com/somebody/idlframewok/item/ItemSpadeBase.java new file mode 100644 index 0000000..d7a7735 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/item/ItemSpadeBase.java @@ -0,0 +1,170 @@ +package com.somebody.idlframewok.item; + +import java.util.List; + +import com.somebody.idlframewok.IdlFramework; +import com.somebody.idlframewok.init.ModCreativeTab; +import com.somebody.idlframewok.util.CommonFunctions; +import com.somebody.idlframewok.util.IDLSkillNBT; +import com.somebody.idlframewok.util.IHasModel; +import com.somebody.idlframewok.util.NBTStrDef.IDLNBTDef; +import com.somebody.idlframewok.util.NBTStrDef.IDLNBTUtil; +import net.minecraft.client.resources.I18n; +import net.minecraft.client.util.ITooltipFlag; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.item.EnumRarity; +import net.minecraft.item.ItemSpade; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +public class ItemSpadeBase extends ItemSpade implements IHasModel { + private boolean overrideRarity = false; + private EnumRarity enumRarity = EnumRarity.COMMON; + protected boolean showGuaSocketDesc = false; + protected boolean shiftToShowDesc = false; + protected boolean use_flavor = false; + protected boolean useable = false; + private boolean isRangedWeapon = false; + protected boolean logNBT = false; + protected boolean glitters = false; + + //for accessing the private value + protected ToolMaterial toolMaterial; + + public ItemSpadeBase(String name, ToolMaterial material) + { + super(material); + setUnlocalizedName(name); + setRegistryName(name); + setCreativeTab(ModCreativeTab.IDL_MISC); + toolMaterial = material; + ModItems.ITEMS.add(this); + + InitItem(); + } + + public ItemSpadeBase setRarity(EnumRarity enumRarity) + { + overrideRarity = true; + this.enumRarity = enumRarity; + return this; + } + + public EnumRarity getRarity(ItemStack stack) + { + if (overrideRarity) + { + return enumRarity; + }else { + return super.getRarity(stack); + } + } + + public void InitItem() + { + if (this instanceof IGuaEnhance) + { + showGuaSocketDesc = true; + } + } + + public String GetStringForThisByKey(String key) + { + return CommonFunctions.GetStringLocalTranslated(getUnlocalizedName() + key); + } + + public String GetBasicDesc() + { + return CommonFunctions.GetStringLocalTranslated(getUnlocalizedName() + IDLNBTDef.DESC_COMMON); + } + + @Override + public void onUsingTick(ItemStack stack, EntityLivingBase living, int count) { + //Particle; + super.onUsingTick(stack, living, count); + //Idealland.LogWarning(String.format("base onUsingTick %s",count)); + + if (living.world.isRemote) + { + clientUseTick(stack, living, getMaxItemUseDuration(stack) - count); + } + else + { + serverUseTick(stack, living, getMaxItemUseDuration(stack) - count); + } + } + + public void clientUseTick(ItemStack stack, EntityLivingBase living, int count) + { + + } + + public void serverUseTick(ItemStack stack, EntityLivingBase living, int count) + { + + } + + @Override + public void registerModels() + { + IdlFramework.proxy.registerItemRenderer(this, 0, "inventory"); + } + @SideOnly(Side.CLIENT) + @Override + public void addInformation(ItemStack stack, World world, List tooltip, ITooltipFlag flag) { + + IDLSkillNBT.addInformation(stack,world,tooltip,flag,shiftToShowDesc, showGuaSocketDesc, use_flavor, + getMainDesc(stack,world,tooltip,flag)); + + if (logNBT) + { + tooltip.add(IDLNBTUtil.getNBT(stack).toString()); + } + } + + @SideOnly(Side.CLIENT) + public String descGetKey(ItemStack stack, World world, boolean showFlavor) + { + return showFlavor ? (stack.getUnlocalizedName() + IDLNBTDef.FLAVOR_KEY) + : (stack.getUnlocalizedName() + IDLNBTDef.DESC_COMMON); + } + + @SideOnly(Side.CLIENT) + public String getMainDesc(ItemStack stack, World world, List tooltip, ITooltipFlag flag) + { + if (CommonFunctions.isShiftPressed() || !shiftToShowDesc) + { + String key = descGetKey(stack,world,false); + if (I18n.hasKey(key)) + { + return I18n.format(key); + } + else + { + return ""; + } + } + + if (!CommonFunctions.isShiftPressed() && use_flavor) + { + String key = descGetKey(stack,world,true); + if (I18n.hasKey(key)) + { + return I18n.format(key); + } + else + { + return ""; + } + } + return ""; + } + + //for accessing private values + protected float getBaseAttackDamage() + { + return 3.0F + toolMaterial.getAttackDamage(); + } +} diff --git a/src/main/java/com/somebody/idlframewok/item/ItemSwordBase.java b/src/main/java/com/somebody/idlframewok/item/ItemSwordBase.java new file mode 100644 index 0000000..a38876d --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/item/ItemSwordBase.java @@ -0,0 +1,172 @@ +package com.somebody.idlframewok.item; + +import java.util.List; + +import com.somebody.idlframewok.IdlFramework; +import com.somebody.idlframewok.init.ModCreativeTab; +import com.somebody.idlframewok.util.CommonFunctions; +import com.somebody.idlframewok.util.IDLSkillNBT; +import com.somebody.idlframewok.util.IHasModel; +import com.somebody.idlframewok.util.NBTStrDef.IDLNBTDef; +import com.somebody.idlframewok.util.NBTStrDef.IDLNBTUtil; +import net.minecraft.client.resources.I18n; +import net.minecraft.client.util.ITooltipFlag; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.item.EnumRarity; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.item.ItemSword; +import net.minecraft.world.World; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +public class ItemSwordBase extends ItemSword implements IHasModel { + private boolean overrideRarity = false; + private EnumRarity enumRarity = EnumRarity.COMMON; + protected boolean showGuaSocketDesc = false; + protected boolean shiftToShowDesc = false; + protected boolean use_flavor = false; + protected boolean useable = false; + private boolean isRangedWeapon = false; + protected boolean logNBT = false; + protected boolean glitters = false; + + //for accessing the private value + protected Item.ToolMaterial toolMaterial; + + public ItemSwordBase(String name, Item.ToolMaterial material) + { + super(material); + setUnlocalizedName(name); + setRegistryName(name); + setCreativeTab(ModCreativeTab.IDL_MISC); + toolMaterial = material; + ModItems.ITEMS.add(this); + + InitItem(); + } + + public ItemSwordBase setRarity(EnumRarity enumRarity) + { + overrideRarity = true; + this.enumRarity = enumRarity; + return this; + } + + public EnumRarity getRarity(ItemStack stack) + { + if (overrideRarity) + { + return enumRarity; + }else { + return super.getRarity(stack); + } + } + + public void InitItem() + { + if (this instanceof IGuaEnhance) + { + showGuaSocketDesc = true; + } + } + + public String GetStringForThisByKey(String key) + { + return CommonFunctions.GetStringLocalTranslated(getUnlocalizedName() + key); + } + + public String GetBasicDesc() + { + return CommonFunctions.GetStringLocalTranslated(getUnlocalizedName() + IDLNBTDef.DESC_COMMON); + } + + @Override + public void onUsingTick(ItemStack stack, EntityLivingBase living, int count) { + //Particle; + super.onUsingTick(stack, living, count); + //IdlFramework.LogWarning(String.format("base onUsingTick %s",count)); + + if (living.world.isRemote) + { + clientUseTick(stack, living, getMaxItemUseDuration(stack) - count); + } + else + { + serverUseTick(stack, living, getMaxItemUseDuration(stack) - count); + } + } + + public void clientUseTick(ItemStack stack, EntityLivingBase living, int count) + { + + } + + public void serverUseTick(ItemStack stack, EntityLivingBase living, int count) + { + + } + + @Override + public void registerModels() + { + IdlFramework.proxy.registerItemRenderer(this, 0, "inventory"); + } + + @SideOnly(Side.CLIENT) + @Override + public void addInformation(ItemStack stack, World world, List tooltip, ITooltipFlag flag) { + + IDLSkillNBT.addInformation(stack,world,tooltip,flag,shiftToShowDesc, showGuaSocketDesc, use_flavor, + getMainDesc(stack,world,tooltip,flag)); + + if (logNBT) + { + tooltip.add(IDLNBTUtil.getNBT(stack).toString()); + } + } + + @SideOnly(Side.CLIENT) + public String descGetKey(ItemStack stack, World world, boolean showFlavor) + { + return showFlavor ? (stack.getUnlocalizedName() + IDLNBTDef.FLAVOR_KEY) + : (stack.getUnlocalizedName() + IDLNBTDef.DESC_COMMON); + } + + @SideOnly(Side.CLIENT) + public String getMainDesc(ItemStack stack, World world, List tooltip, ITooltipFlag flag) + { + if (CommonFunctions.isShiftPressed() || !shiftToShowDesc) + { + String key = descGetKey(stack,world,false); + if (I18n.hasKey(key)) + { + return I18n.format(key); + } + else + { + return ""; + } + } + + if (!CommonFunctions.isShiftPressed() && use_flavor) + { + String key = descGetKey(stack,world,true); + if (I18n.hasKey(key)) + { + return I18n.format(key); + } + else + { + return ""; + } + } + return ""; + } + + //for accessing private values + protected float getBaseAttackDamage() + { + return 3.0F + toolMaterial.getAttackDamage(); + } +} diff --git a/src/main/java/com/somebody/idlframewok/item/ModItems.java b/src/main/java/com/somebody/idlframewok/item/ModItems.java new file mode 100644 index 0000000..d3f80e6 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/item/ModItems.java @@ -0,0 +1,74 @@ +package com.somebody.idlframewok.item; + +import java.util.ArrayList; +import java.util.List; + +import net.minecraft.item.Item; + +public class ModItems { + + public static final List ITEMS = new ArrayList(); + + //Basic + //public static final Item PAPER_BLOOD = new ItemBase("paper_blood"); + + + /* + WOOD(0, 59, 2.0F, 0.0F, 15), + STONE(1, 131, 4.0F, 1.0F, 5), + IRON(2, 250, 6.0F, 2.0F, 14), + DIAMOND(3, 1561, 8.0F, 3.0F, 10), + GOLD(0, 32, 12.0F, 0.0F, 22); + + harvestLevel, maxUses, efficiency, damage, enchantability + */ + + //Tool Material +// public static final Item BLOOD_IRON_INGOT = new ItemBase("blood_iron_ingot"); +// +// public static final Item.ToolMaterial TOOL_MATERIAL_BLOOD = +// EnumHelper.addToolMaterial("material_blood", 3, 512, 3.0F, 4F, 20).setRepairItem(new ItemStack( ModItems.BLOOD_IRON_INGOT)); +// +// public static final ItemKinshipSword KINSHIP_SWORD = new ItemKinshipSword("kinship_sword", TOOL_MATERIAL_BLOOD); + + //Armor +// LEATHER("leather", 5, new int[]{1, 2, 3, 1}, 15, SoundEvents.ITEM_ARMOR_EQUIP_LEATHER, 0.0F), +// CHAIN("chainmail", 15, new int[]{1, 4, 5, 2}, 12, SoundEvents.ITEM_ARMOR_EQUIP_CHAIN, 0.0F), +// IRON("iron", 15, new int[]{2, 5, 6, 2}, 9, SoundEvents.ITEM_ARMOR_EQUIP_IRON, 0.0F), +// GOLD("gold", 7, new int[]{1, 3, 5, 2}, 25, SoundEvents.ITEM_ARMOR_EQUIP_GOLD, 0.0F), +// DIAMOND("diamond", 33, new int[]{3, 6, 8, 3}, 10, SoundEvents.ITEM_ARMOR_EQUIP_DIAMOND, 2.0F); + //Note that if you want to set a mod thing as repair material, define them before the material, otherwise it will be empty. + +// public static final ItemArmor.ArmorMaterial moroonArmorMaterial = EnumHelper.addArmorMaterial( +// "idlframewok:armor_moroon", "idlframewok:armor_moroon", 80, new int[] {3, 6, 8, 3}, 2, SoundEvents.ITEM_ARMOR_EQUIP_GOLD, 2) +// .setRepairItem(new ItemStack(Items.QUARTZ)); +// + + //Food +// static PotionEffect eff = new PotionEffect(MobEffects.LEVITATION, TICK_PER_SECOND * 60, 0); +// public static final ItemFoodBase FIGHT_BREAD = (ItemFoodBase) new ItemFoodBase("war_bread", 10, 10, false). +// setPotionEffect(eff, 1.0f). +// setAlwaysEdible(); +// public static final ItemFoodBase MEMORY_BREAD = new ItemFoodBase("memory_bread", 3, 0.6f, false).SetXP(10); + + + + + + //Armor +// public static final ItemHelmSniper helmetSniper = (ItemHelmSniper) new ItemHelmSniper("helmet_sniper", moroonArmorMaterialSniper, 1, EntityEquipmentSlot.HEAD); +// +// public static final ItemArmorBase[] MOR_GENERAL_ARMOR = +// { new ItemArmorBase("mor_armor_1", moroonArmorMaterial, 1, EntityEquipmentSlot.HEAD) +// ,new ItemArmorBase("mor_armor_2", moroonArmorMaterial, 1, EntityEquipmentSlot.CHEST) +// ,new ItemArmorBase("mor_armor_3", moroonArmorMaterial, 1, EntityEquipmentSlot.LEGS) +// ,new ItemArmorBase("mor_armor_4", moroonArmorMaterial, 1, EntityEquipmentSlot.FEET) +// }; + + //public static final ItemSkillDecodeItem skillDecodeItem = (ItemSkillDecodeItem) new ItemSkillDecodeItem("skill_decode_item").setRarity(EnumRarity.RARE); + + //Package Example +// public static final ItemPackage RANDOM_SKILL = (ItemPackage) new ItemPackage("random_skill", new Item[]{ +// Items.BLAZE_ROD, Items.PAPER +// }).setMaxStackSize(1); +} diff --git a/src/main/java/com/somebody/idlframewok/item/armorMaterials/ModArmorMaterial.java b/src/main/java/com/somebody/idlframewok/item/armorMaterials/ModArmorMaterial.java new file mode 100644 index 0000000..5f89891 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/item/armorMaterials/ModArmorMaterial.java @@ -0,0 +1,7 @@ +//package com.somebody.idlframewok.item.armorMaterials; +// +//import net.minecraft.item.ItemArmor; +//import net.minecraft.item.ItemArmor.ArmorMaterial; +// +//public class ModArmorMaterial extends ArmorMaterial { +//} diff --git a/src/main/java/com/somebody/idlframewok/item/consumables/ItemConsumableBase.java b/src/main/java/com/somebody/idlframewok/item/consumables/ItemConsumableBase.java new file mode 100644 index 0000000..0347afb --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/item/consumables/ItemConsumableBase.java @@ -0,0 +1,42 @@ +package com.somebody.idlframewok.item.consumables; + +import com.somebody.idlframewok.init.ModCreativeTab; +import com.somebody.idlframewok.item.ItemBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ActionResult; +import net.minecraft.util.EnumActionResult; +import net.minecraft.util.EnumHand; +import net.minecraft.world.World; + +public class ItemConsumableBase extends ItemBase { + boolean consumeSelf = true; + boolean consumeOther = false; + public ItemConsumableBase(String name) { + super(name); + setCreativeTab(ModCreativeTab.IDL_MISC); + } + + /** + * Called when the equipped item is right clicked. + */ + public ActionResult onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) + { + ItemStack itemstack = playerIn.getHeldItem(handIn); + itemstack.shrink(1); + return new ActionResult(EnumActionResult.SUCCESS, itemstack); +// EntityEquipmentSlot entityequipmentslot = EntityLiving.getSlotForItemStack(itemstack); +// ItemStack itemstack1 = playerIn.getItemStackFromSlot(entityequipmentslot); +// +// if (itemstack1.isEmpty()) +// { +// playerIn.setItemStackToSlot(entityequipmentslot, itemstack.copy()); +// itemstack.setCount(0); +// return new ActionResult(EnumActionResult.SUCCESS, itemstack); +// } +// else +// { +// return new ActionResult(EnumActionResult.FAIL, itemstack); +// } + } +} diff --git a/src/main/java/com/somebody/idlframewok/item/consumables/ItemFightBread.java b/src/main/java/com/somebody/idlframewok/item/consumables/ItemFightBread.java new file mode 100644 index 0000000..81ae84f --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/item/consumables/ItemFightBread.java @@ -0,0 +1,10 @@ +package com.somebody.idlframewok.item.consumables; + +import com.somebody.idlframewok.init.ModCreativeTab; + +public class ItemFightBread extends ItemConsumableBase { + public ItemFightBread(String name) { + super(name); + setCreativeTab(ModCreativeTab.IDL_MISC); + } +} diff --git a/src/main/java/com/somebody/idlframewok/item/consumables/ItemLevelUpBadge.java b/src/main/java/com/somebody/idlframewok/item/consumables/ItemLevelUpBadge.java new file mode 100644 index 0000000..3f48e88 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/item/consumables/ItemLevelUpBadge.java @@ -0,0 +1,35 @@ +package com.somebody.idlframewok.item.consumables; + +import com.somebody.idlframewok.entity.creatures.EntityModUnit; +import com.somebody.idlframewok.item.ItemBase; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.SoundEvents; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumHand; + +public class ItemLevelUpBadge extends ItemBase { + public ItemLevelUpBadge(String name) { + super(name); + } + + @Override + public boolean itemInteractionForEntity(ItemStack stack, EntityPlayer playerIn, EntityLivingBase target, EnumHand handIn) { + if (target instanceof EntityModUnit) + { + EntityModUnit legalTarget = (EntityModUnit) target; + int level = legalTarget.getLevel(); + int lvMax = legalTarget.getMaxLevel(); + if (level < lvMax) + { + legalTarget.setLevel(level+1); + } + + playerIn.swingArm(handIn); + target.playSound(SoundEvents.ENTITY_PLAYER_LEVELUP, 1f, 1f); + stack.shrink(1); + return true; + } + return false; + } +} diff --git a/src/main/java/com/somebody/idlframewok/item/consumables/ItemPowerUpModular.java b/src/main/java/com/somebody/idlframewok/item/consumables/ItemPowerUpModular.java new file mode 100644 index 0000000..8e4ffd0 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/item/consumables/ItemPowerUpModular.java @@ -0,0 +1,87 @@ +package com.somebody.idlframewok.item.consumables; + +import java.util.List; + +import com.somebody.idlframewok.entity.creatures.EntityModUnit; +import com.somebody.idlframewok.item.ItemBase; +import com.somebody.idlframewok.util.CommonFunctions; +import com.somebody.idlframewok.util.EntityUtil; +import com.somebody.idlframewok.util.NBTStrDef.IDLNBTUtil; +import net.minecraft.client.resources.I18n; +import net.minecraft.client.util.ITooltipFlag; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.SharedMonsterAttributes; +import net.minecraft.entity.ai.attributes.IAttribute; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.SoundEvents; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumHand; +import net.minecraft.world.World; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +import static com.somebody.idlframewok.util.NBTStrDef.IDLNBTDef.MARK_TOTAL_COUNT; + +public class ItemPowerUpModular extends ItemBase { + private IAttribute attrType; + private float amountFixed; + + public ItemPowerUpModular(String name, IAttribute attrType, float amountFixed) { + super(name); + this.attrType = attrType; + this.amountFixed = amountFixed; + } + + @Override + public boolean itemInteractionForEntity(ItemStack stack, EntityPlayer playerIn, EntityLivingBase target, EnumHand handIn) { + if (target instanceof EntityModUnit) + { + EntityModUnit legalTarget = (EntityModUnit) target; + if (legalTarget.is_mechanic) + { + int requireLv = (IDLNBTUtil.GetInt(target, MARK_TOTAL_COUNT, 0)); + if (requireLv > playerIn.experienceLevel) + { + CommonFunctions.SafeSendMsgToPlayer(playerIn, "idlframewok.msg.upgrade_module.req_lv", String.valueOf(requireLv)); + return false; + } + + if (!playerIn.world.isRemote) + { + double valueBefore = EntityUtil.getAttr(legalTarget, attrType); + boolean success = EntityUtil.boostAttr(legalTarget, attrType, amountFixed, POWER_UP_MODIFIER); + if (success) + { + double valueAfter = EntityUtil.getAttr(legalTarget, attrType); + CommonFunctions.SafeSendMsgToPlayer(playerIn, "idlframewok.msg.upgrade_module.ok", valueBefore, valueAfter); + playerIn.swingArm(handIn); + target.playSound(SoundEvents.ENTITY_PLAYER_LEVELUP, 1f, 1f); + stack.shrink(1); + IDLNBTUtil.SetInt(target,MARK_TOTAL_COUNT, requireLv + 1); + if (attrType == SharedMonsterAttributes.MAX_HEALTH) + { + target.heal(amountFixed); + } + } + else { + return false; + } + } + return true; + } + } + return false; + } + + @SideOnly(Side.CLIENT) + public String getMainDesc(ItemStack stack, World world, List tooltip, ITooltipFlag flag) + { + String key = stack.getUnlocalizedName() + ".desc"; + if (I18n.hasKey(key)) + { + String mainDesc = I18n.format(key, amountFixed); + return mainDesc; + } + return ""; + } +} diff --git a/src/main/java/com/somebody/idlframewok/item/consumables/ItemPowerUpModularPercent.java b/src/main/java/com/somebody/idlframewok/item/consumables/ItemPowerUpModularPercent.java new file mode 100644 index 0000000..bcc022c --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/item/consumables/ItemPowerUpModularPercent.java @@ -0,0 +1,87 @@ +package com.somebody.idlframewok.item.consumables; + +import java.util.List; + +import com.somebody.idlframewok.entity.creatures.EntityModUnit; +import com.somebody.idlframewok.item.ItemBase; +import com.somebody.idlframewok.util.CommonFunctions; +import com.somebody.idlframewok.util.EntityUtil; +import com.somebody.idlframewok.util.NBTStrDef.IDLNBTUtil; +import net.minecraft.client.resources.I18n; +import net.minecraft.client.util.ITooltipFlag; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.SharedMonsterAttributes; +import net.minecraft.entity.ai.attributes.IAttribute; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.SoundEvents; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumHand; +import net.minecraft.world.World; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +import static com.somebody.idlframewok.util.NBTStrDef.IDLNBTDef.MARK_TOTAL_COUNT; + +public class ItemPowerUpModularPercent extends ItemBase { + private IAttribute attrType; + private float amountRatio; + + public ItemPowerUpModularPercent(String name, IAttribute attrType, float amountRatio) { + super(name); + this.attrType = attrType; + this.amountRatio = amountRatio; + } + + @Override + public boolean itemInteractionForEntity(ItemStack stack, EntityPlayer playerIn, EntityLivingBase target, EnumHand handIn) { + if (target instanceof EntityModUnit) + { + EntityModUnit legalTarget = (EntityModUnit) target; + if (legalTarget.is_mechanic) + { + int requireLv = (IDLNBTUtil.GetInt(target, MARK_TOTAL_COUNT, 0)); + if (requireLv > playerIn.experienceLevel) + { + CommonFunctions.SafeSendMsgToPlayer(playerIn, "idlframewok.msg.upgrade_module.req_lv", requireLv); + return false; + } + + if (!playerIn.world.isRemote) + { + double valueBefore = EntityUtil.getAttr(legalTarget, attrType); + boolean success = EntityUtil.boostAttrRatio(legalTarget, attrType, amountRatio, POWER_UP_MODIFIER_PERCENT); + if (success) + { + double valueAfter = EntityUtil.getAttr(legalTarget, attrType); + CommonFunctions.SafeSendMsgToPlayer(playerIn, "idlframewok.msg.upgrade_module.ok", valueBefore, valueAfter); + playerIn.swingArm(handIn); + target.playSound(SoundEvents.ENTITY_PLAYER_LEVELUP, 1f, 1f); + stack.shrink(1); + IDLNBTUtil.SetInt(target,MARK_TOTAL_COUNT, requireLv + 1); + if (attrType == SharedMonsterAttributes.MAX_HEALTH) + { + target.heal((float) (valueAfter - valueBefore)); + } + } + else { + return false; + } + } + return true; + } + } + return false; + } + + @SideOnly(Side.CLIENT) + public String getMainDesc(ItemStack stack, World world, List tooltip, ITooltipFlag flag) + { + String key = stack.getUnlocalizedName() + ".desc"; + if (I18n.hasKey(key)) + { + String mainDesc = I18n.format(key, amountRatio * 100); + return mainDesc; + } + return ""; + } +} diff --git a/src/main/java/com/somebody/idlframewok/item/consumables/ItemRainCall.java b/src/main/java/com/somebody/idlframewok/item/consumables/ItemRainCall.java new file mode 100644 index 0000000..7c8aa35 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/item/consumables/ItemRainCall.java @@ -0,0 +1,39 @@ +package com.somebody.idlframewok.item.consumables; + +import com.somebody.idlframewok.util.CommonFunctions; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ActionResult; +import net.minecraft.util.EnumActionResult; +import net.minecraft.util.EnumHand; +import net.minecraft.world.World; +import net.minecraft.world.biome.Biome; + +public class ItemRainCall extends ItemConsumableBase { + public ItemRainCall(String name) { + super(name); + } + + /** + * Called when the equipped item is right clicked. + */ + public ActionResult onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) + { + ItemStack stack = playerIn.getHeldItem(handIn); + Biome biome = worldIn.getBiome(playerIn.getPosition()); + + if (biome.canRain() && !worldIn.isRaining()) + { + worldIn.setRainStrength(100f); + return super.onItemRightClick(worldIn, playerIn, handIn); + } + else { + if (playerIn instanceof EntityPlayerMP) + { + CommonFunctions.SendMsgToPlayer((EntityPlayerMP) playerIn, "idlframewok.msg.cannot_rain"); + } + return new ActionResult(EnumActionResult.FAIL,stack); + } + } +} diff --git a/src/main/java/com/somebody/idlframewok/item/consumables/autoConsume/ItemAutoConsumeBase.java b/src/main/java/com/somebody/idlframewok/item/consumables/autoConsume/ItemAutoConsumeBase.java new file mode 100644 index 0000000..29baf52 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/item/consumables/autoConsume/ItemAutoConsumeBase.java @@ -0,0 +1,27 @@ +package com.somebody.idlframewok.item.consumables.autoConsume; + +import com.somebody.idlframewok.item.consumables.ItemConsumableBase; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; + +public class ItemAutoConsumeBase extends ItemConsumableBase { + public ItemAutoConsumeBase(String name) { + super(name); + } + + public void OnConsume(ItemStack stack, World worldIn, EntityLivingBase entityIn, int itemSlot, boolean isSelected) + { + //do something + } + + @Override + public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) { + super.onUpdate(stack, worldIn, entityIn, itemSlot, isSelected); + + OnConsume(stack, worldIn, (EntityLivingBase) entityIn, itemSlot, isSelected); + + stack.shrink(1); + } +} diff --git a/src/main/java/com/somebody/idlframewok/item/consumables/autoConsume/ItemAutoConsumeHeal.java b/src/main/java/com/somebody/idlframewok/item/consumables/autoConsume/ItemAutoConsumeHeal.java new file mode 100644 index 0000000..9d47e72 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/item/consumables/autoConsume/ItemAutoConsumeHeal.java @@ -0,0 +1,18 @@ +package com.somebody.idlframewok.item.consumables.autoConsume; + +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; + +public class ItemAutoConsumeHeal extends ItemAutoConsumeBase { + float healAmount = 2f; + public ItemAutoConsumeHeal(String name) { + super(name); + } + + @Override + public void OnConsume(ItemStack stack, World worldIn, EntityLivingBase entityIn, int itemSlot, boolean isSelected) { + super.OnConsume(stack, worldIn, entityIn, itemSlot, isSelected); + entityIn.heal(healAmount); + } +} diff --git a/src/main/java/com/somebody/idlframewok/item/food/ItemFoodBase.java b/src/main/java/com/somebody/idlframewok/item/food/ItemFoodBase.java new file mode 100644 index 0000000..ebedab1 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/item/food/ItemFoodBase.java @@ -0,0 +1,156 @@ +package com.somebody.idlframewok.item.food; + +import java.util.List; + +import com.somebody.idlframewok.IdlFramework; +import com.somebody.idlframewok.init.ModCreativeTab; +import com.somebody.idlframewok.item.ModItems; +import com.somebody.idlframewok.util.CommonFunctions; +import com.somebody.idlframewok.util.IDLSkillNBT; +import com.somebody.idlframewok.util.IHasModel; +import com.somebody.idlframewok.util.NBTStrDef.IDLNBTDef; +import com.somebody.idlframewok.util.NBTStrDef.IDLNBTUtil; +import net.minecraft.client.resources.I18n; +import net.minecraft.client.util.ITooltipFlag; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.EnumRarity; +import net.minecraft.item.ItemFood; +import net.minecraft.item.ItemStack; +import net.minecraft.potion.Potion; +import net.minecraft.world.World; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +public class ItemFoodBase extends ItemFood implements IHasModel { + + private boolean overrideRarity = false; + private EnumRarity enumRarity = EnumRarity.COMMON; + protected boolean showGuaSocketDesc = false; + protected boolean shiftToShowDesc = false; + protected boolean use_flavor = false; + protected boolean useable = false; + protected boolean logNBT = false; + + //for creating variants + protected int value_main = 1; + public ItemFoodBase setValue(int amount) + { + this.value_main = amount; + return this; + } + + public ItemFoodBase setRarity(EnumRarity enumRarity) + { + overrideRarity = true; + this.enumRarity = enumRarity; + return this; + } + + public EnumRarity getRarity(ItemStack stack) + { + if (overrideRarity) + { + return enumRarity; + }else { + return super.getRarity(stack); + } + } + + public int addXP = 0; + + Potion potion; + int level; + int duration; + + public ItemFoodBase SetXP(int addXP) + { + this.addXP = addXP; + return this; + } + + + @Override + public void registerModels() + { + IdlFramework.proxy.registerItemRenderer(this, 0, "inventory"); + } + + public ItemFoodBase(String name, int amount, float saturation, boolean isWolfFood) { + super(amount, saturation, isWolfFood); + setUnlocalizedName(name); + setRegistryName(name); + setCreativeTab(ModCreativeTab.IDL_MISC); + + ModItems.ITEMS.add(this); + + InitItem(); + } + + protected void onFoodEaten(ItemStack stack, World worldIn, EntityPlayer player) + { + //IdlFramework.Log("%s:on Food Eaten", getUnlocalizedName()); + super.onFoodEaten(stack, worldIn, player); + if (addXP > 0) + { + player.addExperience(addXP); + } + } + + public void InitItem() + { + + } + + + @SideOnly(Side.CLIENT) + @Override + public void addInformation(ItemStack stack, World world, List tooltip, ITooltipFlag flag) { + + IDLSkillNBT.addInformation(stack,world,tooltip,flag,shiftToShowDesc, showGuaSocketDesc, use_flavor, + getMainDesc(stack,world,tooltip,flag)); + + if (logNBT) + { + tooltip.add(IDLNBTUtil.getNBT(stack).toString()); + } + } + + @SideOnly(Side.CLIENT) + public String descGetKey(ItemStack stack, World world, boolean showFlavor) + { + return showFlavor ? (stack.getUnlocalizedName() + IDLNBTDef.FLAVOR_KEY) + : (stack.getUnlocalizedName() + IDLNBTDef.DESC_COMMON); + } + + @SideOnly(Side.CLIENT) + public String getMainDesc(ItemStack stack, World world, List tooltip, ITooltipFlag flag) + { + if (CommonFunctions.isShiftPressed() || !shiftToShowDesc) + { + String key = descGetKey(stack,world,false); + if (I18n.hasKey(key)) + { + return I18n.format(key); + } + else + { + return ""; + } + } + + if (!CommonFunctions.isShiftPressed() && use_flavor) + { + String key = descGetKey(stack,world,true); + if (I18n.hasKey(key)) + { + return I18n.format(key); + } + else + { + return ""; + } + } + + return ""; + } +} diff --git a/src/main/java/com/somebody/idlframewok/item/goblet/ItemDigGoblet.java b/src/main/java/com/somebody/idlframewok/item/goblet/ItemDigGoblet.java new file mode 100644 index 0000000..0c847a8 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/item/goblet/ItemDigGoblet.java @@ -0,0 +1,93 @@ +package com.somebody.idlframewok.item.goblet; + +import java.util.List; + +import com.google.common.primitives.Ints; +import com.somebody.idlframewok.util.NBTStrDef.IDLNBTUtil; +import net.minecraft.block.Block; +import net.minecraft.client.resources.I18n; +import net.minecraft.client.util.ITooltipFlag; +import net.minecraft.entity.Entity; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.ResourceLocation; +import net.minecraft.world.World; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +import static com.somebody.idlframewok.util.NBTStrDef.IDLNBTDef.ASSIGNED_BLOCK_NAME; + +public class ItemDigGoblet extends ItemGobletBase { + public ItemDigGoblet(String name) { + super(name); + } + + private void Test() + { + //Entity entity = AnvilChunkLoader.readWorldEntityPos(nbttagcompound, world, d0, d1, d2, false); + } + + public String GetStoredBlockName(ItemStack stack) + { + NBTTagCompound compound = stack.getTagCompound(); + return compound == null ? "" : compound.getString(ASSIGNED_BLOCK_NAME); + } + + public void SetStoredBlockName(ItemStack stack, Block block) + { + ResourceLocation resourceLocation = block.getRegistryName(); + IDLNBTUtil.SetString(stack, ASSIGNED_BLOCK_NAME, resourceLocation==null ? "" : block.getRegistryName().toString()); + } + + @Override + public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) { + super.onUpdate(stack, worldIn, entityIn, itemSlot, isSelected); + + if (isSelected && !worldIn.isRemote) + { + int level = GetLevelFromEXP(GetCacheEXP(stack)); + + String storedName = GetStoredBlockName(stack); + boolean hasSPBlock = !storedName.isEmpty(); + + if (level > 0) + { + int maxRange = 5; + int maxHeight = 3; + + int rangeXZ = Ints.min(maxRange, level); + int rangeY = Ints.min(maxHeight, level); + + for (int x = -rangeXZ; x <= rangeXZ; x++) + { + for (int z = -rangeXZ; z <= rangeXZ; z++) + { + for (int y = 0; y <= rangeY; y++) + { + Block block = worldIn.getBlockState(entityIn.getPosition().add(x, y, z)).getBlock(); + ResourceLocation loc = block.getRegistryName(); + if (block == Blocks.STONE + || (hasSPBlock && loc != null && loc.toString().equals(storedName))) + { + worldIn.setBlockState(entityIn.getPosition().add(x, y, z), Blocks.AIR.getDefaultState()); + } + } + } + } + } + } + } + + //Desc + @SideOnly(Side.CLIENT) + @Override + public void addInformation(ItemStack stack, World world, List tooltip, ITooltipFlag flag) { + String mainDesc = I18n.format(stack.getUnlocalizedName() + ".desc"); + tooltip.add(mainDesc); + + String blockDesc = I18n.format( stack.getUnlocalizedName() + ".desc2", GetStoredBlockName(stack)); + tooltip.add(blockDesc); + addInformationLast(stack, world, tooltip, flag); + } +} diff --git a/src/main/java/com/somebody/idlframewok/item/goblet/ItemFlameGoblet.java b/src/main/java/com/somebody/idlframewok/item/goblet/ItemFlameGoblet.java new file mode 100644 index 0000000..0313c17 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/item/goblet/ItemFlameGoblet.java @@ -0,0 +1,60 @@ +package com.somebody.idlframewok.item.goblet; + +import java.util.List; + +import com.somebody.idlframewok.util.IDLGeneral; +import net.minecraft.client.resources.I18n; +import net.minecraft.client.util.ITooltipFlag; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLiving; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.MobEffects; +import net.minecraft.item.ItemStack; +import net.minecraft.potion.PotionEffect; +import net.minecraft.util.math.Vec3d; +import net.minecraft.world.World; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +import static com.somebody.idlframewok.util.CommonDef.TICK_PER_SECOND; +import static net.minecraft.util.DamageSource.causePlayerDamage; + +public class ItemFlameGoblet extends ItemGobletBase { + public ItemFlameGoblet(String name) { + super(name); + } + + @Override + public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) { + super.onUpdate(stack, worldIn, entityIn, itemSlot, isSelected); + + if (isSelected && !worldIn.isRemote) + { + int level = GetLevelFromEXP(GetCacheEXP(stack)); + + if (level > 0 && worldIn.getWorldTime() % TICK_PER_SECOND == 0) + { + EntityPlayer playerIn = (EntityPlayer) entityIn; + Vec3d basePos = playerIn.getPositionVector(); + List entities = worldIn.getEntitiesWithinAABB(EntityLiving.class, IDLGeneral.ServerAABB(basePos.addVector(-level, -level, -level), basePos.addVector(level, level, level))); + for (EntityLiving living: entities + ) { + living.attackEntityFrom(causePlayerDamage(playerIn).setFireDamage().setMagicDamage(), level); + living.setFire(level); + } + + playerIn.addPotionEffect(new PotionEffect(MobEffects.FIRE_RESISTANCE, TICK_PER_SECOND, 0)); + playerIn.setFire(level); + } + } + } + + //Desc + @SideOnly(Side.CLIENT) + @Override + public void addInformation(ItemStack stack, World world, List tooltip, ITooltipFlag flag) { + String mainDesc = I18n.format(stack.getUnlocalizedName() + ".desc", GetLevelFromEXP(GetCacheEXP(stack))); + tooltip.add(mainDesc); + addInformationLast(stack, world, tooltip, flag); + } +} diff --git a/src/main/java/com/somebody/idlframewok/item/goblet/ItemGobletBase.java b/src/main/java/com/somebody/idlframewok/item/goblet/ItemGobletBase.java new file mode 100644 index 0000000..ae75583 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/item/goblet/ItemGobletBase.java @@ -0,0 +1,147 @@ +package com.somebody.idlframewok.item.goblet; + +import java.util.List; + +import com.somebody.idlframewok.item.ItemBase; +import com.somebody.idlframewok.util.CommonDef; +import com.somebody.idlframewok.util.IDLNBT; +import com.somebody.idlframewok.util.NBTStrDef.IDLNBTDef; +import com.somebody.idlframewok.util.NBTStrDef.IDLNBTUtil; +import net.minecraft.client.resources.I18n; +import net.minecraft.client.util.ITooltipFlag; +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.world.World; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +public class ItemGobletBase extends ItemBase { + + public float cool_down = 1f; + public float cool_down_reduce_per_lv = 0f; + + public ItemGobletBase(String name) { + super(name); + } + + public void SetPayingEXP(ItemStack stack, int val) + { + IDLNBTUtil.SetInt(stack, IDLNBTDef.P2W_PAYING_EXP, val); + } + + public int GetPayingEXP(ItemStack stack) + { + return IDLNBTUtil.GetInt(stack, IDLNBTDef.P2W_PAYING_EXP); + } + + public void SetCacheEXP(ItemStack stack, int val) + { + IDLNBTUtil.SetInt(stack, IDLNBTDef.P2W_CACHE_EXP, val); + } + + public static int GetCacheEXP(ItemStack stack) + { + return IDLNBTUtil.GetInt(stack, IDLNBTDef.P2W_CACHE_EXP); + } + + public static int GetP2WExpForPlayer(EntityPlayer player) + { + NBTTagCompound playerData = player.getEntityData(); + NBTTagCompound data = IDLNBT.getTagSafe(playerData, EntityPlayer.PERSISTED_NBT_TAG); + + return data.getInteger(IDLNBTDef.P2W_EXP); + } + + public static void SetP2WExpForPlayer(EntityPlayer player, int val) + { + NBTTagCompound playerData = player.getEntityData(); + NBTTagCompound data = IDLNBT.getTagSafe(playerData, EntityPlayer.PERSISTED_NBT_TAG); + + data.setInteger(IDLNBTDef.P2W_EXP, val); + playerData.setTag(EntityPlayer.PERSISTED_NBT_TAG, data); + } + + public static int GetLevelFromEXP(int xp) + { + return (int)Math.log(xp+1); + } + + public static int GetExpForLevelFromEXP(int xp) + { + return (int)Math.pow(Math.exp(1), (int)Math.log(xp+1)+1); + } + public static int GetLevelFromItemStack(ItemStack stack) + { + return GetCacheEXP(stack); + } + + public static void activateCoolDown(EntityPlayer player, ItemStack stack) + { + Item item = stack.getItem(); + if (item instanceof ItemGobletBase) + { + player.getCooldownTracker().setCooldown(stack.getItem(), ((ItemGobletBase) item).GetMaxTick(stack)); + } + } + + private int GetMaxTick(ItemStack stack) { + return (int) (getCoolDown(stack) * CommonDef.TICK_PER_SECOND); + } + + public float getCoolDown(ItemStack stack) { + float result = -(GetLevelFromItemStack(stack) - 1) * cool_down_reduce_per_lv + cool_down; + return result > 0.1f ? result : 0.1f; } + + + @Override + public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) { + super.onUpdate(stack, worldIn, entityIn, itemSlot, isSelected); + if (!worldIn.isRemote) + { + EntityPlayer player = (EntityPlayer) entityIn; + int playerXP = GetP2WExpForPlayer((EntityPlayer) entityIn); + int payingXP = GetPayingEXP(stack); + if (payingXP > 0) + { + //first, crafting charges the goblet + //when the player holds the goblet, the player absorbs the experience. + //todo; make the player drink from it to get the experience + playerXP += payingXP; + SetP2WExpForPlayer(player, playerXP); + SetPayingEXP(stack, 0); + } + + int lastCache = GetCacheEXP(stack); + if (lastCache != playerXP) + { + SetCacheEXP(stack, playerXP); + //stack.writeToNBT() + } + //IdlFramework.Log(playerXP + " " + getUnlocalizedName(stack)); + } + } + + @SideOnly(Side.CLIENT) + public void addInformationLast(ItemStack stack, World world, List tooltip, ITooltipFlag flag) { + int val = GetPayingEXP(stack); + if (val > 0) + tooltip.add(I18n.format("item.p2w_goblet.contain.desc", val)); + + val = GetCacheEXP(stack); + + if (GetCacheEXP(stack) > 0) + tooltip.add(I18n.format("item.p2w_goblet.player.desc", GetLevelFromEXP(val), val, GetExpForLevelFromEXP(val))); + } + + //Desc + @SideOnly(Side.CLIENT) + @Override + public void addInformation(ItemStack stack, World world, List tooltip, ITooltipFlag flag) { + String mainDesc = I18n.format(stack.getUnlocalizedName() + ".desc"); + tooltip.add(mainDesc); + addInformationLast(stack, world, tooltip, flag); + } +} diff --git a/src/main/java/com/somebody/idlframewok/item/goblet/ItemHealGoblet.java b/src/main/java/com/somebody/idlframewok/item/goblet/ItemHealGoblet.java new file mode 100644 index 0000000..0da3833 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/item/goblet/ItemHealGoblet.java @@ -0,0 +1,59 @@ +package com.somebody.idlframewok.item.goblet; + +import java.util.List; + +import com.somebody.idlframewok.util.CommonDef; +import net.minecraft.client.resources.I18n; +import net.minecraft.client.util.ITooltipFlag; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.SoundEvents; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumHand; +import net.minecraft.world.World; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +public class ItemHealGoblet extends ItemGobletBase { + public ItemHealGoblet(String name) { + super(name); + } + + @Override + public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) { + super.onUpdate(stack, worldIn, entityIn, itemSlot, isSelected); + + if (isSelected && !worldIn.isRemote) + { + int level = GetLevelFromEXP(GetCacheEXP(stack)); + + if (level > 0) + { + if (entityIn instanceof EntityLivingBase) + { + ((EntityLivingBase) entityIn).heal((float)level / CommonDef.TICK_PER_SECOND); + } + } + } + } + + @Override + public boolean itemInteractionForEntity(ItemStack stack, EntityPlayer playerIn, EntityLivingBase target, EnumHand handIn) { + target.heal(GetLevelFromEXP(GetCacheEXP(stack))); + + playerIn.swingArm(handIn); + activateCoolDown(playerIn, stack); + target.playSound(SoundEvents.ITEM_BOTTLE_FILL, 1f, 1f); + return true; + } + + //Desc + @SideOnly(Side.CLIENT) + @Override + public void addInformation(ItemStack stack, World world, List tooltip, ITooltipFlag flag) { + String mainDesc = I18n.format(stack.getUnlocalizedName() + ".desc", GetLevelFromEXP(GetCacheEXP(stack))); + tooltip.add(mainDesc); + addInformationLast(stack, world, tooltip, flag); + } +} diff --git a/src/main/java/com/somebody/idlframewok/item/goblet/ItemKnockBackGoblet.java b/src/main/java/com/somebody/idlframewok/item/goblet/ItemKnockBackGoblet.java new file mode 100644 index 0000000..ff87305 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/item/goblet/ItemKnockBackGoblet.java @@ -0,0 +1,81 @@ +package com.somebody.idlframewok.item.goblet; + +import java.util.List; + +import com.somebody.idlframewok.util.CommonDef; +import com.somebody.idlframewok.util.IDLGeneral; +import com.somebody.idlframewok.util.Reference; +import net.minecraft.client.resources.I18n; +import net.minecraft.client.util.ITooltipFlag; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLiving; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.MobEffects; +import net.minecraft.init.SoundEvents; +import net.minecraft.item.ItemStack; +import net.minecraft.potion.PotionEffect; +import net.minecraft.util.EnumHand; +import net.minecraft.util.math.Vec3d; +import net.minecraft.world.World; +import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +@Mod.EventBusSubscriber(modid = Reference.MOD_ID) +public class ItemKnockBackGoblet extends ItemGobletBase { + public ItemKnockBackGoblet(String name) { + super(name); + } + + public int getBuffLevel(int level) + { + int result = level / 3; + return result > 4 ? 4 : result; + } + + @Override + public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) { + super.onUpdate(stack, worldIn, entityIn, itemSlot, isSelected); + + if (isSelected && !worldIn.isRemote) + { + int level = GetLevelFromEXP(GetCacheEXP(stack)); + + if (level > 0 && worldIn.getWorldTime() % (CommonDef.TICK_PER_SECOND << 1) == 0) + { + EntityPlayer playerIn = (EntityPlayer) entityIn; + Vec3d basePos = playerIn.getPositionVector(); + List entities = worldIn.getEntitiesWithinAABB(EntityLiving.class, IDLGeneral.ServerAABB(basePos.addVector(-level, -level, -level), basePos.addVector(level, level, level))); + for (EntityLiving living: entities + ) { + living.knockBack(playerIn, level * 0.1f + 0.5f, (playerIn.posX - living.posX), (playerIn.posZ - living.posZ)); + } + + playerIn.addPotionEffect(new PotionEffect(MobEffects.SPEED, CommonDef.TICK_PER_SECOND, getBuffLevel(level))); + if (playerIn.isSneaking()) + { + playerIn.addPotionEffect(new PotionEffect(MobEffects.JUMP_BOOST, CommonDef.TICK_PER_SECOND, getBuffLevel(level))); + } + } + } + } + + @Override + public boolean itemInteractionForEntity(ItemStack stack, EntityPlayer playerIn, EntityLivingBase target, EnumHand handIn) { + int level = GetLevelFromEXP(GetCacheEXP(stack)); + target.addPotionEffect(new PotionEffect(MobEffects.SPEED, CommonDef.TICK_PER_SECOND * level, getBuffLevel(level))); + activateCoolDown(playerIn, stack); + target.playSound(SoundEvents.ITEM_BOTTLE_FILL, 1f, 1f); + return true; + } + + //Desc + @SideOnly(Side.CLIENT) + @Override + public void addInformation(ItemStack stack, World world, List tooltip, ITooltipFlag flag) { + String mainDesc = I18n.format(stack.getUnlocalizedName() + ".desc", GetLevelFromEXP(GetCacheEXP(stack))); + tooltip.add(mainDesc); + addInformationLast(stack, world, tooltip, flag); + } +} diff --git a/src/main/java/com/somebody/idlframewok/item/goblet/ItemP2WGoblet.java b/src/main/java/com/somebody/idlframewok/item/goblet/ItemP2WGoblet.java new file mode 100644 index 0000000..543301c --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/item/goblet/ItemP2WGoblet.java @@ -0,0 +1,9 @@ +package com.somebody.idlframewok.item.goblet; + +public class ItemP2WGoblet extends ItemGobletBase { + public ItemP2WGoblet(String name) { + super(name); + } + + +} diff --git a/src/main/java/com/somebody/idlframewok/item/goblet/ItemWaterGoblet.java b/src/main/java/com/somebody/idlframewok/item/goblet/ItemWaterGoblet.java new file mode 100644 index 0000000..2a5dbf7 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/item/goblet/ItemWaterGoblet.java @@ -0,0 +1,54 @@ +package com.somebody.idlframewok.item.goblet; + +import java.util.List; + +import com.somebody.idlframewok.util.CommonDef; +import net.minecraft.client.resources.I18n; +import net.minecraft.client.util.ITooltipFlag; +import net.minecraft.entity.Entity; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +public class ItemWaterGoblet extends ItemGobletBase { + public ItemWaterGoblet(String name) { + super(name); + } + + @Override + public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) { + super.onUpdate(stack, worldIn, entityIn, itemSlot, isSelected); + + //todo : produce water, gives breathing and night vision buff in water; acquire those abilities one by one + + if (isSelected && !worldIn.isRemote) + { + int level = GetLevelFromEXP(GetCacheEXP(stack)); + + if (level > 0 && worldIn.getWorldTime() % CommonDef.TICK_PER_SECOND == 0) + { +// EntityPlayer playerIn = (EntityPlayer) entityIn; +// Vec3d basePos = playerIn.getPositionVector(); +// List entities = worldIn.getEntitiesWithinAABB(EntityLiving.class, IDLGeneral.ServerAABB(basePos.addVector(-level, -level, -level), basePos.addVector(level, level, level))); +// for (EntityLiving living: entities +// ) { +// living.attackEntityFrom(causePlayerDamage(playerIn).setFireDamage().setMagicDamage(), level); +// living.setFire(level * TICK_PER_SECOND); +// } +// +// playerIn.addPotionEffect(new PotionEffect(MobEffects.FIRE_RESISTANCE, TICK_PER_SECOND, 0)); +// playerIn.setFire(level * TICK_PER_SECOND); + } + } + } + + //Desc + @SideOnly(Side.CLIENT) + @Override + public void addInformation(ItemStack stack, World world, List tooltip, ITooltipFlag flag) { + String mainDesc = I18n.format(stack.getUnlocalizedName() + ".desc", GetLevelFromEXP(GetCacheEXP(stack))); + tooltip.add(mainDesc); + addInformationLast(stack, world, tooltip, flag); + } +} diff --git a/src/main/java/com/somebody/idlframewok/item/misc/ItemAttrMeasure.java b/src/main/java/com/somebody/idlframewok/item/misc/ItemAttrMeasure.java new file mode 100644 index 0000000..a167d58 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/item/misc/ItemAttrMeasure.java @@ -0,0 +1,36 @@ +package com.somebody.idlframewok.item.misc; + +import com.somebody.idlframewok.item.ItemBase; +import com.somebody.idlframewok.util.EntityUtil; +import com.somebody.idlframewok.util.NBTStrDef.IDLNBTDef; +import com.somebody.idlframewok.util.NBTStrDef.IDLNBTUtil; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.SharedMonsterAttributes; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumHand; + +public class ItemAttrMeasure extends ItemBase { + public ItemAttrMeasure(String name) { + super(name); + useable = true; + + } + + @Override + public boolean itemInteractionForEntity(ItemStack stack, EntityPlayer playerIn, EntityLivingBase target, EnumHand hand) { + + IDLNBTUtil.SetDouble(stack, IDLNBTDef.MARK_ATK, EntityUtil.getAttr(target, SharedMonsterAttributes.ATTACK_DAMAGE)); + IDLNBTUtil.SetDouble(stack, IDLNBTDef.MARK_HP, EntityUtil.getAttr(target, SharedMonsterAttributes.MAX_HEALTH)); + IDLNBTUtil.SetDouble(stack, IDLNBTDef.MARK_DEF, EntityUtil.getAttr(target, SharedMonsterAttributes.ARMOR)); + IDLNBTUtil.SetDouble(stack, IDLNBTDef.MARK_ARMOR_T, EntityUtil.getAttr(target, SharedMonsterAttributes.ARMOR_TOUGHNESS)); + IDLNBTUtil.SetDouble(stack, IDLNBTDef.MARK_RANGE, EntityUtil.getAttr(target, SharedMonsterAttributes.FOLLOW_RANGE)); + IDLNBTUtil.SetDouble(stack, IDLNBTDef.MARK_KB_R, EntityUtil.getAttr(target, SharedMonsterAttributes.KNOCKBACK_RESISTANCE)); + IDLNBTUtil.SetDouble(stack, IDLNBTDef.MARK_SPEED, EntityUtil.getAttr(target, SharedMonsterAttributes.MOVEMENT_SPEED)); + IDLNBTUtil.SetDouble(stack, IDLNBTDef.MARK_ATK_SPEED, EntityUtil.getAttr(target, SharedMonsterAttributes.ATTACK_SPEED)); + + return true; + } + + +} diff --git a/src/main/java/com/somebody/idlframewok/item/misc/ItemBasicBinary.java b/src/main/java/com/somebody/idlframewok/item/misc/ItemBasicBinary.java new file mode 100644 index 0000000..8e565b0 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/item/misc/ItemBasicBinary.java @@ -0,0 +1,24 @@ +package com.somebody.idlframewok.item.misc; + +import com.somebody.idlframewok.item.ItemBase; + +public class ItemBasicBinary extends ItemBase { + + public int getValue() { + return value; + } + + public ItemBasicBinary setValue(int value) { + this.value = value; + return this; + } + + int value = 0;//0 = yin, 1 = yang + + public ItemBasicBinary(String name) { + super(name); + } + + + +} diff --git a/src/main/java/com/somebody/idlframewok/item/misc/ItemBasicGua.java b/src/main/java/com/somebody/idlframewok/item/misc/ItemBasicGua.java new file mode 100644 index 0000000..3bb190d --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/item/misc/ItemBasicGua.java @@ -0,0 +1,24 @@ +package com.somebody.idlframewok.item.misc; + +import com.somebody.idlframewok.item.ItemBase; + +public class ItemBasicGua extends ItemBase { + + public int getGua() { + return gua; + } + + public ItemBasicGua setGua(int gua) { + this.gua = gua; + return this; + } + + int gua = 0; + + public ItemBasicGua(String name) { + super(name); + } + + + +} diff --git a/src/main/java/com/somebody/idlframewok/item/misc/ItemKinshipSword.java b/src/main/java/com/somebody/idlframewok/item/misc/ItemKinshipSword.java new file mode 100644 index 0000000..4f3999d --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/item/misc/ItemKinshipSword.java @@ -0,0 +1,221 @@ +package com.somebody.idlframewok.item.misc; + +import java.util.List; + +import com.google.common.collect.Multimap; +import com.somebody.idlframewok.item.IGuaEnhance; +import com.somebody.idlframewok.item.ItemSwordBase; +import com.somebody.idlframewok.util.CommonDef; +import com.somebody.idlframewok.util.IDLGeneral; +import com.somebody.idlframewok.util.IDLSkillNBT; +import com.somebody.idlframewok.util.Reference; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.SharedMonsterAttributes; +import net.minecraft.entity.ai.attributes.AttributeModifier; +import net.minecraft.entity.effect.EntityLightningBolt; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.MobEffects; +import net.minecraft.inventory.EntityEquipmentSlot; +import net.minecraft.item.ItemStack; +import net.minecraft.potion.PotionEffect; +import net.minecraft.util.DamageSource; +import net.minecraft.util.EnumHand; +import net.minecraft.util.math.Vec3d; +import net.minecraft.world.World; +import net.minecraftforge.fml.common.Mod; + +@Mod.EventBusSubscriber(modid = Reference.MOD_ID) +public class ItemKinshipSword extends ItemSwordBase implements IGuaEnhance { + + public ItemKinshipSword(String name, ToolMaterial material) { + super(name, material); + shiftToShowDesc = true; + } + +// @SubscribeEvent +// public static void onCreatureHurt(LivingHurtEvent evt) { +// if (evt.isCanceled()) +// { +// return; +// } +// +// World world = evt.getEntity().getEntityWorld(); +// if (!world.isRemote) { +// EntityLivingBase hurtOne = evt.getEntityLiving(); +// Entity trueSource = evt.getSource().getTrueSource(); +// +// if (hurtOne instanceof EntityPlayer && !(evt.getSource().getTrueSource() instanceof EntityPlayer)) { +// EntityPlayer player = (EntityPlayer) hurtOne; +// ItemStack stack = AttemptPlayerHand(player, EnumHand.MAIN_HAND); +// if (stack == ItemStack.EMPTY) { +// stack = AttemptPlayerHand(player, EnumHand.OFF_HAND); +// } +// if (stack != ItemStack.EMPTY) { +// ItemSkillCalmWalk skillThunderFall = ((ItemSkillCalmWalk) stack.getItem()); +// +// if (!player.world.isRemote) { +// //int level = skillThunderFall.getLevel(stack); +// evt.setCanceled(true); +// } +// } +// } +// +// if (trueSource instanceof EntityPlayer) { +// ItemStack stack = AttemptPlayerHand((EntityPlayer) trueSource, EnumHand.MAIN_HAND); +// if (stack == ItemStack.EMPTY) { +// stack = AttemptPlayerHand((EntityPlayer) trueSource, EnumHand.OFF_HAND); +// } +// if (stack != ItemStack.EMPTY) { +// evt.setCanceled(true); +// } +// } +// } +// } + + + public float getSplashDamage(ItemStack stack, EntityLivingBase target, EntityLivingBase attacker) + { + return (float)attacker.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).getAttributeValue(); + } + + public boolean hitEntity(ItemStack stack, EntityLivingBase target, EntityLivingBase attacker) + { + stack.damageItem(1, attacker); + World worldIn = attacker.getEntityWorld(); + + if (!worldIn.isRemote) + { + float base_range = 16f + IDLSkillNBT.GetGuaEnhance(stack, 7); + + Vec3d basePos = attacker.getPositionVector(); + List entities = worldIn.getEntitiesWithinAABB(target.getClass(), IDLGeneral.ServerAABB(basePos.addVector(-base_range, -base_range, -base_range), basePos.addVector(base_range, base_range, base_range))); + + for (EntityLivingBase living: entities + ) { + if (living != target) + { + //damage is only dealt once + OnHitBasic(stack, attacker, living, EnumHand.MAIN_HAND); + OnHitExtra(stack, attacker, living, EnumHand.MAIN_HAND); + } + else { + OnHitExtra(stack, attacker, living, EnumHand.MAIN_HAND); + } + + } + } + + return true; + } + //gua enhance + float windModifier = 0.1f; + //6 wind + public float getKBPower(ItemStack stack) + { + return 0.4f + windModifier * IDLSkillNBT.GetGuaEnhance(stack, 6); + } + + public void OnHitBasic(ItemStack stack, EntityLivingBase playerIn, EntityLivingBase target, EnumHand handIn) + { + if (!playerIn.world.isRemote) { + float dmg = getSplashDamage(stack, target, playerIn) / 2f + getExtraDamage(stack, target.isWet()); + + target.attackEntityFrom(DamageSource.causePlayerDamage((EntityPlayer) playerIn), dmg); + } + } + + float getExtraDamage(ItemStack stack, boolean targetWet) + { + int fire = IDLSkillNBT.GetGuaEnhance(stack, 5); + int thunder = IDLSkillNBT.GetGuaEnhance(stack, 1); + return fire + (targetWet ? thunder * 2 : thunder); + } + + public void OnHitExtra(ItemStack stack, EntityLivingBase playerIn, EntityLivingBase target, EnumHand handIn) + { + int mountain = IDLSkillNBT.GetGuaEnhance(stack, 4); + int water = IDLSkillNBT.GetGuaEnhance(stack, 2); + int lake = IDLSkillNBT.GetGuaEnhance(stack, 3); + int fire = IDLSkillNBT.GetGuaEnhance(stack, 5); + int thunder = IDLSkillNBT.GetGuaEnhance(stack, 1); + + if (mountain > 0) + { + target.addPotionEffect(new PotionEffect(MobEffects.SLOWNESS, CommonDef.TICK_PER_SECOND * mountain * 2, mountain / 4)); + } + + if (water > 0) + { + target.addPotionEffect(new PotionEffect(MobEffects.WEAKNESS, CommonDef.TICK_PER_SECOND * water * 2, water / 4)); + target.extinguish(); + } + + if (lake > 0) + { + target.heal(lake); + playerIn.heal(lake); + } + + //wind + target.knockBack(playerIn, getKBPower(stack), (playerIn.posX - target.posX), (playerIn.posZ - target.posZ)); + + //fire + target.setFire(fire); + + //thunder + if (thunder >= 8) + { + playerIn.world.addWeatherEffect(new EntityLightningBolt(playerIn.world, target.posX, target.posY, target.posZ, false)); + } + + } + + @Override + public boolean acceptGuaIndex(int index) { + return index != 0; + } + + class BuffTuple + { + public int tick; + public int power; + + public BuffTuple(int power, int tick) { + this.tick = tick; + this.power = power; + } + } + +// public com.somebody.idlframewok.item.skills.martial.BuffTuple GetWaterBuff(ItemStack stack) +// { +// int water = GetGuaEnhance(stack, 2); +// return new com.somebody.idlframewok.item.skills.martial.BuffTuple(water / 4, TICK_PER_SECOND * water * 2); +// } +// +// public com.somebody.idlframewok.item.skills.martial.BuffTuple GetMountainBuff(ItemStack stack) +// { +// int gua = GetGuaEnhance(stack, 4); +// return new com.somebody.idlframewok.item.skills.martial.BuffTuple(gua / 4, TICK_PER_SECOND * gua * 2); +// } +// +// public DamageSource GetDamageSource(ItemStack stack, EntityLivingBase playerIn, EntityLivingBase target, EnumHand handIn) +// { +// return new EntityDamageSource("race", playerIn); +// } + + /** + * Gets a map of item attribute modifiers, used by ItemSword to increase hit damage. + */ + public Multimap getAttributeModifiers(EntityEquipmentSlot slot, ItemStack stack) + { + Multimap multimap = super.getItemAttributeModifiers(slot); + + if (slot == EntityEquipmentSlot.MAINHAND) + { + multimap.put(SharedMonsterAttributes.ATTACK_DAMAGE.getName(), new AttributeModifier(ATTACK_DAMAGE_MODIFIER, "Weapon modifier", getBaseAttackDamage() + IDLSkillNBT.GetGuaEnhance(stack, 7), 0)); + multimap.put(SharedMonsterAttributes.ATTACK_SPEED.getName(), new AttributeModifier(ATTACK_SPEED_MODIFIER, "Weapon modifier", -2.4000000953674316D, 0)); + } + + return multimap; + } +} diff --git a/src/main/java/com/somebody/idlframewok/item/misc/ItemNanoMender.java b/src/main/java/com/somebody/idlframewok/item/misc/ItemNanoMender.java new file mode 100644 index 0000000..2813269 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/item/misc/ItemNanoMender.java @@ -0,0 +1,42 @@ +package com.somebody.idlframewok.item.misc; + +import com.somebody.idlframewok.item.ItemBase; +import com.somebody.idlframewok.util.CommonFunctions; +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.EntityEquipmentSlot; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; + +public class ItemNanoMender extends ItemBase { + public ItemNanoMender(String name, int maxDmg) { + super(name); + setMaxDamage(maxDmg); + } + + @Override + public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) { + super.onUpdate(stack, worldIn, entityIn, itemSlot, isSelected); + + if (!worldIn.isRemote) + { + EntityPlayer playerIn = (EntityPlayer) entityIn; + for (EntityEquipmentSlot slot: + EntityEquipmentSlot.values()) { + + ItemStack itemstack1 = playerIn.getItemStackFromSlot(slot); + if (!itemstack1.isEmpty() && itemstack1.isItemDamaged() && !(itemstack1.getItem() instanceof ItemNanoMender)) { + //Fix Dura + CommonFunctions.RepairItem(itemstack1, 1); + stack.damageItem(1, playerIn); + break; + } + } + } + } + +// public EnumRarity getRarity(ItemStack stack) +// { +// return stack.isItemEnchanted() ? EnumRarity.RARE : EnumRarity.COMMON; +// } +} diff --git a/src/main/java/com/somebody/idlframewok/item/misc/ItemPackage.java b/src/main/java/com/somebody/idlframewok/item/misc/ItemPackage.java new file mode 100644 index 0000000..a41ee6b --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/item/misc/ItemPackage.java @@ -0,0 +1,57 @@ +package com.somebody.idlframewok.item.misc; + +import javax.annotation.Nonnull; + +import com.somebody.idlframewok.item.ItemBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.SoundEvents; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ActionResult; +import net.minecraft.util.EnumActionResult; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.EnumHand; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; + +public class ItemPackage extends ItemBase { + public Item[] validItems = new Item[]{}; + int pick = 1; + + public ItemPackage(String name, Item[] validItems) { + super(name); + this.validItems = validItems; + } + + public ItemPackage(String name, Item[] validItems, int pick) { + super(name); + this.validItems = validItems; + this.pick = pick; + } + + @Nonnull + @Override + public ActionResult onItemRightClick(World world, EntityPlayer player, @Nonnull EnumHand hand) { + player.setActiveHand(hand); + ItemStack stack = player.getHeldItem(hand); + + if (!world.isRemote) { + + player.addItemStackToInventory(new ItemStack(validItems[player.getRNG().nextInt(validItems.length)])); + player.playSound(SoundEvents.ENTITY_PLAYER_LEVELUP, 1f, 1f); + player.addExperience(10); + + // Must do shrink AFTER addItemStackToInventory, + //or it would make the addItemStackToInventory fail if the new thing were to be in the new place. + // Try do this when helding one sealed weapon in slot 1, and something else in slot 2. + stack.shrink(1); + } + + return ActionResult.newResult(EnumActionResult.SUCCESS, stack); + } + + public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) + { + return EnumActionResult.PASS; + } +} diff --git a/src/main/java/com/somebody/idlframewok/item/misc/ItemSpaceAnchor.java b/src/main/java/com/somebody/idlframewok/item/misc/ItemSpaceAnchor.java new file mode 100644 index 0000000..2b9ac9b --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/item/misc/ItemSpaceAnchor.java @@ -0,0 +1,120 @@ +package com.somebody.idlframewok.item.misc; + +import java.util.List; +import javax.annotation.Nonnull; + +import com.somebody.idlframewok.item.ItemBase; +import com.somebody.idlframewok.util.CommonFunctions; +import com.somebody.idlframewok.util.EntityUtil; +import com.somebody.idlframewok.util.NBTStrDef.IDLNBTDef; +import com.somebody.idlframewok.util.NBTStrDef.IDLNBTUtil; +import net.minecraft.client.util.ITooltipFlag; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.EnumAction; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumParticleTypes; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +public class ItemSpaceAnchor extends ItemBase { + public int chargeTickDefault = 20; + + public ItemSpaceAnchor(String name) { + super(name); + useable = true; + } + + + public int chargeNeedTick(ItemStack stack) + { + return chargeTickDefault; + } + + /** + * How long it takes to use or consume an item + */ + @Override + public int getMaxItemUseDuration(ItemStack stack) + { + return 200; + } + + //Animation + @Nonnull + @Override + public EnumAction getItemUseAction(ItemStack stack) { + + return EnumAction.BOW; + + } + + @Override + public void clientUseTick(ItemStack stack, EntityLivingBase living, int count) { +// //Particle; + //DWeapons.LogWarning(String.format("onUsingTick %s",count)); + + if (count >= chargeNeedTick(stack)) { + CreateParticle(stack, living); + } + } + + private void CreateParticle(ItemStack stack, EntityLivingBase living) { + EntityUtil.SpawnParticleAround(living, EnumParticleTypes.PORTAL, 10); + } + + /** + * Called when the player stops using an Item (stops holding the right mouse button). + */ + @Override + public void onPlayerStoppedUsing(ItemStack stack, World world, EntityLivingBase living, int time) { + //change mode + if (!world.isRemote) { + if (getMaxItemUseDuration(stack) - time >= chargeNeedTick(stack)) + { + if (IDLNBTUtil.GetBoolean(stack, IDLNBTDef.ANCHOR_READY, false)) + { + BlockPos pos = IDLNBTUtil.getMarkedPos(stack); + if (living.attemptTeleport(pos.getX(), pos.getY(), pos.getZ())) + { + stack.shrink(1); + } + else { + CommonFunctions.SafeSendMsgToPlayer((EntityPlayer) living, "idlframewok.msg.teleport.fail"); + } + } + else { + IDLNBTUtil.markPosToStack(stack, living.getPosition()); + } + + //DWeapons.LogWarning("Weapon mode is:" + GetWeaponMode(stack)); + } + } + } + + @SideOnly(Side.CLIENT) + @Override + public void addInformation(ItemStack stack, World world, List tooltip, ITooltipFlag flag) { + super.addInformation(stack, world, tooltip, flag); + + //tooltip.add(I18n.format("idlframewok.gua_enhance_total.desc", IDLSkillNBT.GetGuaEnhanceTotal(stack))); + tooltip.add(IDLNBTUtil.getNBT(stack).toString()); + } +// @Override +// public ItemStack onItemUseFinish(ItemStack stack, World worldIn, EntityLivingBase entityLiving) { +// return super.onItemUseFinish(stack, worldIn, entityLiving); +// } +// +// @Override +// public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { +// +// return super.onItemUse(player, worldIn, pos, hand, facing, hitX, hitY, hitZ); +// } +// +// @Override +// public ActionResult onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) { +// return super.onItemRightClick(worldIn, playerIn, handIn); +// } +} diff --git a/src/main/java/com/somebody/idlframewok/item/misc/ItemSummon.java b/src/main/java/com/somebody/idlframewok/item/misc/ItemSummon.java new file mode 100644 index 0000000..da6a777 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/item/misc/ItemSummon.java @@ -0,0 +1,71 @@ +package com.somebody.idlframewok.item.misc; + +import com.somebody.idlframewok.IdlFramework; +import com.somebody.idlframewok.item.ItemBase; +import com.somebody.idlframewok.util.Reference; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityList; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ActionResult; +import net.minecraft.util.EnumActionResult; +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; + +public class ItemSummon extends ItemBase { + + ResourceLocation entityLocation; + + protected boolean doWarn = true; + + public ItemSummon(String name) { + super(name); + } + + public ItemSummon setEntity(String id) + { + useable = true; + this.entityLocation = new ResourceLocation(Reference.MOD_ID,id); + + //this.entityLocation = new ResourceLocation(layer); + return this; + } + + + @Override + public EnumActionResult onItemUse(EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand handIn, EnumFacing facing, float hitX, float hitY, float hitZ) { + ItemStack stack = playerIn.getHeldItem(handIn); + + if (!worldIn.isRemote) + { + stack.shrink(1); + Entity entity = EntityList.createEntityByIDFromName(entityLocation, worldIn); + if (entity instanceof EntityLivingBase) + { + EntityLivingBase entityLivingBase = (EntityLivingBase) entity; + entityLivingBase.setPosition(pos.getX() + 0.5f,pos.getY() + 1f,pos.getZ() + 0.5f); + IdlFramework.Log("Spawned: %s @ %s", entityLivingBase.getName(), entityLivingBase.getPosition()); + worldIn.spawnEntity(entityLivingBase); +// if (entityLivingBase instanceof EntityLiving) +// { +// ((EntityLiving)entityLivingBase).spawnExplosionParticle(); +// } + } + else { + if (doWarn) + IdlFramework.LogWarning("Trying to summon a non-living entity"); + } + } + + return super.onItemUse(playerIn, worldIn, pos, handIn, facing, hitX, hitY, hitZ); + } + + @Override + public ActionResult onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) { + return new ActionResult<>(EnumActionResult.FAIL, playerIn.getHeldItem(handIn)); + } +} diff --git a/src/main/java/com/somebody/idlframewok/item/misc/ItemSummonEternal.java b/src/main/java/com/somebody/idlframewok/item/misc/ItemSummonEternal.java new file mode 100644 index 0000000..a82f69e --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/item/misc/ItemSummonEternal.java @@ -0,0 +1,42 @@ +package com.somebody.idlframewok.item.misc; + +import com.somebody.idlframewok.entity.creatures.misc.EntityEternalZombie; +import com.somebody.idlframewok.item.ItemBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.SoundEvents; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ActionResult; +import net.minecraft.util.EnumActionResult; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.EnumHand; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; + +public class ItemSummonEternal extends ItemBase { + + public ItemSummonEternal(String name) { + super(name); + } + + @Override + public EnumActionResult onItemUse(EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand handIn, EnumFacing facing, float hitX, float hitY, float hitZ) { + ItemStack stack = playerIn.getHeldItem(handIn); + + if (!worldIn.isRemote) + { + stack.shrink(1); + EntityEternalZombie zombie = new EntityEternalZombie(worldIn); + zombie.setPosition(pos.getX(),pos.getY()+1,pos.getZ()); + worldIn.spawnEntity(zombie); + }else { + playerIn.playSound(SoundEvents.ENTITY_FIREWORK_LARGE_BLAST, 1f, 1f); + } + + return super.onItemUse(playerIn, worldIn, pos, handIn, facing, hitX, hitY, hitZ); + } + + @Override + public ActionResult onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) { + return new ActionResult<>(EnumActionResult.FAIL, playerIn.getHeldItem(handIn)); + } +} diff --git a/src/main/java/com/somebody/idlframewok/item/misc/ItemYiJianMei.java b/src/main/java/com/somebody/idlframewok/item/misc/ItemYiJianMei.java new file mode 100644 index 0000000..06f6c48 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/item/misc/ItemYiJianMei.java @@ -0,0 +1,29 @@ +package com.somebody.idlframewok.item.misc; + +import java.util.Random; + +import com.somebody.idlframewok.item.ItemBase; +import com.somebody.idlframewok.util.EntityUtil; +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumParticleTypes; +import net.minecraft.util.math.Vec3d; +import net.minecraft.world.World; + +public class ItemYiJianMei extends ItemBase { + public ItemYiJianMei(String name) { + super(name); + } + + @Override + public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) { + super.onUpdate(stack, worldIn, entityIn, itemSlot, isSelected); + if (worldIn.isRemote && entityIn instanceof EntityPlayer) + { + Random random = ((EntityPlayer) entityIn).getRNG(); + Vec3d pos = EntityUtil.GetRandomAroundPos(entityIn.getPositionEyes(0f), 1f, random).addVector(0, random.nextFloat(), 0); + worldIn.spawnParticle(EnumParticleTypes.SNOW_SHOVEL, pos.x, pos.y, pos.z, 0,0, random.nextFloat());//from the north + } + } +} diff --git a/src/main/java/com/somebody/idlframewok/item/misc/armor/ItemArmorUnderfootGeta.java b/src/main/java/com/somebody/idlframewok/item/misc/armor/ItemArmorUnderfootGeta.java new file mode 100644 index 0000000..69f2ea4 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/item/misc/armor/ItemArmorUnderfootGeta.java @@ -0,0 +1,140 @@ +package com.somebody.idlframewok.item.misc.armor; + +import java.util.Collection; +import java.util.List; + +import com.google.common.collect.HashMultimap; +import com.google.common.collect.Multimap; +import com.somebody.idlframewok.item.IGuaEnhance; +import com.somebody.idlframewok.item.ItemArmorBase; +import com.somebody.idlframewok.util.CommonDef; +import com.somebody.idlframewok.util.IDLSkillNBT; +import com.somebody.idlframewok.util.Reference; +import net.minecraft.client.resources.I18n; +import net.minecraft.client.util.ITooltipFlag; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.SharedMonsterAttributes; +import net.minecraft.entity.ai.attributes.AttributeModifier; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.EntityEquipmentSlot; +import net.minecraft.item.ItemStack; +import net.minecraft.potion.PotionEffect; +import net.minecraft.world.World; +import net.minecraftforge.event.entity.living.LivingHurtEvent; +import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.common.eventhandler.EventPriority; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +@Mod.EventBusSubscriber(modid = Reference.MOD_ID) +public class ItemArmorUnderfootGeta extends ItemArmorBase implements IGuaEnhance { + public ItemArmorUnderfootGeta(String name, ArmorMaterial materialIn, int renderIndexIn, EntityEquipmentSlot equipmentSlotIn) { + super(name, materialIn, renderIndexIn, equipmentSlotIn); + showGuaSocketDesc = true; + ignoreVanillaSystem = true; + } + + static final int maxEnhance = 5; + + @Override + public void onUpdateWearing(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) { + super.onUpdateWearing(stack, worldIn, entityIn, itemSlot, isSelected); + + if (!worldIn.isRemote) + { + EntityLivingBase livingBase = (EntityLivingBase) entityIn; + + if (livingBase instanceof EntityPlayer) + { + if (((EntityPlayer) livingBase).capabilities.isCreativeMode) + { + //quite annoying in creative + return; + } + } + + if (worldIn.getWorldTime() % (maxEnhance - IDLSkillNBT.GetGuaEnhance(stack, CommonDef.G_EARTH)) == 0) + { + Collection activePotionEffects = livingBase.getActivePotionEffects(); + for (int i = 0; i < activePotionEffects.size(); i++) { + PotionEffect buff = (PotionEffect)activePotionEffects.toArray()[i]; + if (buff.getPotion().isBadEffect()){ + livingBase.removePotionEffect(buff.getPotion()); + break; + } + } + + for (int i = 0; i < activePotionEffects.size(); i++) { + PotionEffect buff = (PotionEffect)activePotionEffects.toArray()[i]; + if (!buff.getPotion().isBadEffect()){ + livingBase.removePotionEffect(buff.getPotion()); + break; + } + } + } + } + } + + static float fireRatioBase = 1.5f; + static float fireRatioPerEnhance = 0.5f; + public static float GetDamageMultiplierFire(ItemStack stack) + { + return IDLSkillNBT.GetGuaEnhance(stack, CommonDef.G_EARTH) * fireRatioPerEnhance + fireRatioBase; + } + + public static float GetDebuffPeriod(ItemStack stack) + { + return Math.max(1f - (float)IDLSkillNBT.GetGuaEnhance(stack, CommonDef.G_EARTH) / (float)maxEnhance, 1f/ CommonDef.TICK_PER_SECOND); + } + + @SubscribeEvent(priority = EventPriority.HIGH) + public static void onCreatureHurt(LivingHurtEvent evt) { + if (evt.isCanceled() || !evt.getSource().isFireDamage()) { + return; + } + + EntityLivingBase hurtOne = evt.getEntityLiving(); + ItemStack onFoot = hurtOne.getItemStackFromSlot(EntityEquipmentSlot.FEET); + if (onFoot.getItem() instanceof ItemArmorUnderfootGeta) + { + float amplifier = ItemArmorUnderfootGeta.GetDamageMultiplierFire(onFoot); + evt.setAmount(evt.getAmount() * amplifier); + } + } + + @Override + public boolean acceptGuaIndex(int index) { + return index == 0; + } + + @SideOnly(Side.CLIENT) + public String getMainDesc(ItemStack stack, World world, List tooltip, ITooltipFlag flag) + { + String key = getUnlocalizedName() + ".desc"; + if (I18n.hasKey(key)) + { + float fireAmplify = GetDamageMultiplierFire(stack); + float buffTime = GetDebuffPeriod(stack); + + return I18n.format(key, buffTime, fireAmplify); + } + return ""; + } + + public Multimap getAttributeModifiers(EntityEquipmentSlot equipmentSlot, ItemStack stack) + { + Multimap multimap = HashMultimap.create(); + + if (equipmentSlot == this.armorType) + { + multimap.put(SharedMonsterAttributes.ARMOR.getName(), new AttributeModifier(ARMOR_MODIFIERS_OVERRIDE[equipmentSlot.getIndex()], "Armor modifier", (double)this.damageReduceAmount, 0)); + multimap.put(SharedMonsterAttributes.ARMOR_TOUGHNESS.getName(), new AttributeModifier(ARMOR_MODIFIERS_OVERRIDE[equipmentSlot.getIndex()], "Armor toughness", (double)this.toughness, 0)); + multimap.put(SharedMonsterAttributes.MAX_HEALTH.getName(), new AttributeModifier(ARMOR_MODIFIERS_OVERRIDE[equipmentSlot.getIndex()],"Health modifier", (double)2f + IDLSkillNBT.GetGuaEnhance(stack, 0), 0)); + multimap.put(SharedMonsterAttributes.LUCK.getName(), new AttributeModifier(ARMOR_MODIFIERS_OVERRIDE[equipmentSlot.getIndex()], "Luck", (double)1f, 0)); + } + + return multimap; + } +} diff --git a/src/main/java/com/somebody/idlframewok/item/misc/armor/ItemArmorXieGeta.java b/src/main/java/com/somebody/idlframewok/item/misc/armor/ItemArmorXieGeta.java new file mode 100644 index 0000000..dff7420 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/item/misc/armor/ItemArmorXieGeta.java @@ -0,0 +1,186 @@ +package com.somebody.idlframewok.item.misc.armor; + +import java.util.List; + +import com.somebody.idlframewok.item.IGuaEnhance; +import com.somebody.idlframewok.item.ItemArmorBase; +import com.somebody.idlframewok.util.CommonDef; +import com.somebody.idlframewok.util.IDLSkillNBT; +import com.somebody.idlframewok.util.NBTStrDef.IDLNBTDef; +import com.somebody.idlframewok.util.NBTStrDef.IDLNBTUtil; +import com.somebody.idlframewok.util.Reference; +import net.minecraft.client.resources.I18n; +import net.minecraft.client.util.ITooltipFlag; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.MobEffects; +import net.minecraft.init.SoundEvents; +import net.minecraft.inventory.EntityEquipmentSlot; +import net.minecraft.item.ItemStack; +import net.minecraft.potion.PotionEffect; +import net.minecraft.util.DamageSource; +import net.minecraft.util.EnumActionResult; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.EnumHand; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.minecraftforge.event.entity.living.LivingHurtEvent; +import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.common.eventhandler.EventPriority; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +@Mod.EventBusSubscriber(modid = Reference.MOD_ID) +public class ItemArmorXieGeta extends ItemArmorBase implements IGuaEnhance { + + static final int UP_HILL = 0; + static final int FLAT_WALK = 1; + static final int DOWN_HILL = 2; + static final int MAX_MODE = 2; + + public ItemArmorXieGeta(String name, ArmorMaterial materialIn, int renderIndexIn, EntityEquipmentSlot equipmentSlotIn) { + super(name, materialIn, renderIndexIn, equipmentSlotIn); + showGuaSocketDesc = true; + ignoreVanillaSystem = true; + } + + @Override + public void onUpdateWearing(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) { + super.onUpdateWearing(stack, worldIn, entityIn, itemSlot, isSelected); + + if (!worldIn.isRemote) + { + EntityLivingBase living = (EntityLivingBase) entityIn; + + int buffPower = getBuffPower(stack); + switch ((IDLNBTUtil.GetInt(stack, IDLNBTDef.MODE))) + { + case UP_HILL: + living.addPotionEffect(new PotionEffect(MobEffects.JUMP_BOOST, CommonDef.TICK_PER_SECOND, buffPower)); + break; + case FLAT_WALK: + living.addPotionEffect(new PotionEffect(MobEffects.SPEED, CommonDef.TICK_PER_SECOND, buffPower)); + break; + default: + living.addPotionEffect(new PotionEffect(MobEffects.SLOWNESS, CommonDef.TICK_PER_SECOND, 0)); + break; + } + } + } + + public int getBuffPower(ItemStack stack) + { + return IDLSkillNBT.GetGuaEnhance(stack, CommonDef.G_EARTH) / 3; + } + + static float basicReduction = 2f; + public static float GetDamageReductionFall(ItemStack stack) + { + if (IDLNBTUtil.GetInt(stack, IDLNBTDef.MODE) != DOWN_HILL) + { + return 0; + } + else { + return IDLSkillNBT.GetGuaEnhance(stack, CommonDef.G_EARTH) + basicReduction; + } + } + + @SubscribeEvent(priority = EventPriority.HIGH) + public static void onCreatureHurt(LivingHurtEvent evt) { + if (evt.isCanceled() || evt.getSource() != DamageSource.FALL) { + //IdlFramework.Log("Xie Geta wrong type"); + return; + } + + EntityLivingBase hurtOne = evt.getEntityLiving(); + ItemStack onFoot = hurtOne.getItemStackFromSlot(EntityEquipmentSlot.FEET); + if (onFoot.getItem() instanceof ItemArmorXieGeta) + { + float reduction = ItemArmorXieGeta.GetDamageReductionFall(onFoot); + //IdlFramework.Log("Xie Geta dmg reduction:%s", reduction); + if (evt.getAmount() <= reduction) + { + evt.setCanceled(true); + } + else { + evt.setAmount(evt.getAmount() - reduction); + } + } + } + + @Override + public EnumActionResult onItemUse(EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand handIn, EnumFacing facing, float hitX, float hitY, float hitZ) { + + ItemStack stack = playerIn.getHeldItem(handIn); + int mode = IDLNBTUtil.GetInt(stack, IDLNBTDef.MODE); + if (!worldIn.isRemote) + { + if (mode == MAX_MODE) + { + IDLNBTUtil.SetInt(stack, IDLNBTDef.MODE, 0); + } + else + { + IDLNBTUtil.SetInt(stack, IDLNBTDef.MODE, mode + 1); + } + } + else { + switch (mode) + { + case UP_HILL: + playerIn.playSound(SoundEvents.BLOCK_WOOD_BREAK, 1f, 1f); + break; + + case FLAT_WALK: + playerIn.playSound(SoundEvents.BLOCK_WOOD_BUTTON_CLICK_OFF, 1f, 1f); + break; + + case DOWN_HILL: + playerIn.playSound(SoundEvents.BLOCK_WOOD_BUTTON_CLICK_ON, 1f, 1f); + break; + + default: + break; + } + + } + + return super.onItemUse(playerIn, worldIn, pos, handIn, facing, hitX, hitY, hitZ); + } + + @Override + public boolean acceptGuaIndex(int index) { + return index == 0 || index == 7; + } + + @SideOnly(Side.CLIENT) + public String getMainDesc(ItemStack stack, World world, List tooltip, ITooltipFlag flag) + { + String key = getNameKey(stack, world, tooltip, flag); + if (I18n.hasKey(key)) + { + float reduction = ItemArmorXieGeta.GetDamageReductionFall(stack); + int buffPower = getBuffPower(stack); + + int mode = IDLNBTUtil.GetInt(stack, IDLNBTDef.MODE); + if (mode == DOWN_HILL) + { + return I18n.format(key, reduction); + }else + { + return I18n.format(key, buffPower + 1); + } + + } + return ""; + } + + @SideOnly(Side.CLIENT) + public String getNameKey(ItemStack stack, World world, List tooltip, ITooltipFlag flag) + { + int mode = IDLNBTUtil.GetInt(stack, IDLNBTDef.MODE); + return stack.getUnlocalizedName() + ".desc." + String.valueOf(mode); + } +} diff --git a/src/main/java/com/somebody/idlframewok/item/potions/PotionBase.java b/src/main/java/com/somebody/idlframewok/item/potions/PotionBase.java new file mode 100644 index 0000000..69f5199 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/item/potions/PotionBase.java @@ -0,0 +1,25 @@ +package com.somebody.idlframewok.item.potions; + +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.potion.Potion; + +public class PotionBase extends Potion { + + //todo: add a registerSpawnList for this + + public PotionBase(String name, boolean badEffect, int color, int iconIndex) { + super(badEffect, color); + setRegistryName(name); + setPotionName("idlframewok.potion." + name); + } + + public boolean hasEffect(EntityLivingBase entity) { + return hasEffect(entity, this); + } + + public boolean hasEffect(EntityLivingBase entity, Potion potion) { + return entity.getActivePotionEffect(potion) != null; + } + + +} diff --git a/src/main/java/com/somebody/idlframewok/item/skills/ItemCreatureRadar.java b/src/main/java/com/somebody/idlframewok/item/skills/ItemCreatureRadar.java new file mode 100644 index 0000000..d2cefff --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/item/skills/ItemCreatureRadar.java @@ -0,0 +1,172 @@ +package com.somebody.idlframewok.item.skills; + +import java.util.List; + +import com.somebody.idlframewok.IdlFramework; +import com.somebody.idlframewok.util.CommonFunctions; +import com.somebody.idlframewok.util.IDLGeneral; +import com.somebody.idlframewok.util.NBTStrDef.IDLNBTDef; +import com.somebody.idlframewok.util.NBTStrDef.IDLNBTUtil; +import net.minecraft.client.resources.I18n; +import net.minecraft.client.util.ITooltipFlag; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityList; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.init.SoundEvents; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.EnumHand; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.SoundEvent; +import net.minecraft.util.math.Vec3d; +import net.minecraft.util.text.TextFormatting; +import net.minecraft.world.World; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +public class ItemCreatureRadar extends ItemSkillBase { + + private String msgKey = "idlframewok.msg.radar_nearbycreatures"; + private SoundEvent alarm = SoundEvents.BLOCK_NOTE_BELL; + +// public ItemCreatureRadar(String name, Class targetCategory, String msgKey, SoundEvent alarm) { +// this(name); +// this.msgKey = msgKey; +// this.alarm = alarm; +// } + + @Override + public boolean itemInteractionForEntity(ItemStack stack, EntityPlayer playerIn, EntityLivingBase target, EnumHand handIn) { + + World world = playerIn.world; + if (!world.isRemote) { + ItemStack cloneResult = target.getPickedResult(null); + if (!cloneResult.isEmpty()) + { + ResourceLocation name = EntityList.getKey(target); + if (name != null && EntityList.ENTITY_EGGS.containsKey(name)) + { + //SetString(stack, "creature_id", name.toString()); + NBTTagCompound tagCompound = IDLNBTUtil.getNBT(stack); + tagCompound.setString("creature_id", name.toString()); + + //stack.writeToNBT(tagCompound); + //net.minecraft.item.ItemMonsterPlacer.applyEntityIdToItemStack(stack, name); + CommonFunctions.SafeSendMsgToPlayer(playerIn, getUnlocalizedName() + ".msg.success"); + IdlFramework.LogWarning(IDLNBTUtil.getNBT(stack).toString()); + activateCoolDown(playerIn, stack); + } + + return true; + } + } + + return false; + } + + public ItemCreatureRadar(String name) { + super(name); + showCDDesc = false; + showDamageDesc = false; + showRangeDesc = true; +// this.addPropertyOverride(new ResourceLocation(STATE), new IItemPropertyGetter() +// { +// @SideOnly(Side.CLIENT) +// public float apply(ItemStack stack, @Nullable World worldIn, @Nullable EntityLivingBase entityIn) +// { +// if (entityIn == null)//when not in hand, world is null. +// { +// return 1.0F;//set to 0 will cause no updating when not in hand. dunno why +// } +// else +// { +//// if (worldIn == null) +//// { +//// worldIn = entityIn.world; +//// } +//// int state = GetInt(stack, STATE); +// //IdlFramework.Log("State = " + state); +// return (float)GetInt(stack, STATE); +// } +// } +// }); + } + + public Class getCreatureFromStack(ItemStack stack) + { + NBTTagCompound nbttagcompound = IDLNBTUtil.getNBT(stack); + //NBTTagCompound nbttagcompound1 = nbttagcompound.getCompoundTag("EntityTag"); + + + if (nbttagcompound.hasKey("creature_id", 8)) + { + net.minecraftforge.fml.common.registry.EntityEntry entry = net.minecraftforge.fml.common.registry.ForgeRegistries.ENTITIES.getValue(new ResourceLocation( nbttagcompound.getString("creature_id"))); + if (entry != null) + { + return entry.getEntityClass(); + } + } + + return EntityPlayer.class; +// ResourceLocation resourcelocation = new ResourceLocation(nbt.getString("layer")); +// Entity entity = EntityList.createEntityByIDFromName(resourcelocation, worldIn); + + } + + + @Override + public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) { + super.onUpdate(stack, worldIn, entityIn, itemSlot, isSelected); + + if (!worldIn.isRemote) + { + int detection = 0; + float XZRangeRadius = getRange(stack); + float YRangeRadius = getRange(stack); + + Vec3d pos = entityIn.getPositionEyes(1.0F); + + IdlFramework.Log("update:", IDLNBTUtil.getNBT(stack).toString()); + + Class s = getCreatureFromStack(stack); + if (s == null) + { + s = EntityPlayer.class; + } + + List entities = worldIn.getEntitiesWithinAABB(EntityLivingBase.class, + IDLGeneral.ServerAABB(pos.addVector(-XZRangeRadius, -YRangeRadius, -XZRangeRadius), pos.addVector(XZRangeRadius, YRangeRadius, XZRangeRadius))); + for (EntityLivingBase entity : entities) + { + //IdlFramework.Log(String.format("[Active]Nearby %s -> %s" , entity.getName() ,entity.getAttackTarget())); + if (entity.getClass() == s && entity != entityIn) + { + detection++; + //IdlFramework.Log("[Active]Detected!"); + } + } + + IDLNBTUtil.SetInt(stack, IDLNBTDef.STATE, detection); + int detectionPre = IDLNBTUtil.GetInt(stack, IDLNBTDef.STATE); + if (detectionPre != detection)//optimize + { + IdlFramework.LogWarning("Changed to " + detection); + IDLNBTUtil.SetInt(stack, IDLNBTDef.STATE, detection); + CommonFunctions.SendMsgToPlayerStyled((EntityPlayerMP) entityIn, msgKey, TextFormatting.YELLOW, detection); + //worldIn.playSound(); + //entityIn.playSound(alarm, 0.7f, detection * 0.1f); + } + } + } + + @SideOnly(Side.CLIENT) + @Override + public void addInformation(ItemStack stack, World world, List tooltip, ITooltipFlag flag) { + super.addInformation(stack, world, tooltip, flag); + String mainDesc = I18n.format(stack.getUnlocalizedName() + ".extra", getCreatureFromStack(stack).getName() ); + tooltip.add(mainDesc); + } + +} diff --git a/src/main/java/com/somebody/idlframewok/item/skills/ItemHateDetector.java b/src/main/java/com/somebody/idlframewok/item/skills/ItemHateDetector.java new file mode 100644 index 0000000..68b6f49 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/item/skills/ItemHateDetector.java @@ -0,0 +1,103 @@ +package com.somebody.idlframewok.item.skills; + +import java.util.List; +import javax.annotation.Nullable; + +import com.somebody.idlframewok.util.CommonFunctions; +import com.somebody.idlframewok.util.IDLGeneral; +import com.somebody.idlframewok.util.NBTStrDef.IDLNBTDef; +import com.somebody.idlframewok.util.NBTStrDef.IDLNBTUtil; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLiving; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.init.SoundEvents; +import net.minecraft.item.IItemPropertyGetter; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.SoundEvent; +import net.minecraft.util.math.Vec3d; +import net.minecraft.util.text.TextFormatting; +import net.minecraft.world.World; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +public class ItemHateDetector extends ItemSkillBase { + + private Class targetCategory = EntityLiving.class; + private String msgKey = "idlframewok.msg.being_targeted"; + private SoundEvent alarm = SoundEvents.BLOCK_NOTE_BELL; + + public ItemHateDetector(String name, Class targetCategory, String msgKey, SoundEvent alarm) { + this(name); + this.targetCategory = targetCategory; + this.msgKey = msgKey; + this.alarm = alarm; + } + + public ItemHateDetector(String name) { + super(name); + showCDDesc = false; + showDamageDesc = false; + showRangeDesc = true; + this.addPropertyOverride(new ResourceLocation(IDLNBTDef.STATE), new IItemPropertyGetter() + { + @SideOnly(Side.CLIENT) + public float apply(ItemStack stack, @Nullable World worldIn, @Nullable EntityLivingBase entityIn) + { + if (entityIn == null)//when not in hand, world is null. + { + return 1.0F;//set to 0 will cause no updating when not in hand. dunno why + } + else + { +// if (worldIn == null) +// { +// worldIn = entityIn.world; +// } +// int state = GetInt(stack, STATE); + //IdlFramework.Log("State = " + state); + return (float) IDLNBTUtil.GetInt(stack, IDLNBTDef.STATE); + } + } + }); + } + + @Override + public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) { + super.onUpdate(stack, worldIn, entityIn, itemSlot, isSelected); + + if (!worldIn.isRemote) + { + int detection = 0; + float XZRangeRadius = getRange(stack); + float YRangeRadius = getRange(stack); + + Vec3d pos = entityIn.getPositionEyes(1.0F); + + List entities = worldIn.getEntitiesWithinAABB(targetCategory, + IDLGeneral.ServerAABB(pos.addVector(-XZRangeRadius, -YRangeRadius, -XZRangeRadius), pos.addVector(XZRangeRadius, YRangeRadius, XZRangeRadius))); + for (EntityLiving entity : entities) + { + //IdlFramework.Log(String.format("[Active]Nearby %s -> %s" , entity.getName() ,entity.getAttackTarget())); + if (entity.getAttackTarget() == entityIn) + { + detection++; + //IdlFramework.Log("[Active]Detected!"); + } + } + + int detectionPre = IDLNBTUtil.GetInt(stack, IDLNBTDef.STATE); + if (detectionPre != detection)//optimize + { + IDLNBTUtil.SetInt(stack, IDLNBTDef.STATE, detection); + if (detectionPre == 0) + { + CommonFunctions.SendMsgToPlayerStyled((EntityPlayerMP) entityIn, msgKey, TextFormatting.YELLOW); + } + //worldIn.playSound(); + //entityIn.playSound(alarm, 0.7f, detection * 0.1f); + } + } + } +} diff --git a/src/main/java/com/somebody/idlframewok/item/skills/ItemMirrorWork.java b/src/main/java/com/somebody/idlframewok/item/skills/ItemMirrorWork.java new file mode 100644 index 0000000..793529b --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/item/skills/ItemMirrorWork.java @@ -0,0 +1,38 @@ +package com.somebody.idlframewok.item.skills; + +import com.somebody.idlframewok.util.CommonDef; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.EnumRarity; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ActionResult; +import net.minecraft.util.EnumActionResult; +import net.minecraft.util.EnumHand; +import net.minecraft.world.World; + +public class ItemMirrorWork extends ItemSkillBase { + + public ItemMirrorWork(String name) { + super(name); + maxLevel = 10; + setCD(3600, 300); + showDamageDesc = false; + } + + @Override + public ActionResult onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) { + ItemStack stack = playerIn.getHeldItem(handIn); + + if (!worldIn.isRemote && handIn == EnumHand.MAIN_HAND) + { + playerIn.setFire(5 * CommonDef.TICK_PER_SECOND); + playerIn.addItemStackToInventory(playerIn.getHeldItemOffhand().copy()); + activateCoolDown(playerIn, stack); + } + return new ActionResult<>(EnumActionResult.SUCCESS, playerIn.getHeldItem(handIn)); + } + + @Override + public EnumRarity getRarity(ItemStack stack) { + return EnumRarity.EPIC; + } +} diff --git a/src/main/java/com/somebody/idlframewok/item/skills/ItemSkillAquireItems.java b/src/main/java/com/somebody/idlframewok/item/skills/ItemSkillAquireItems.java new file mode 100644 index 0000000..428cbd1 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/item/skills/ItemSkillAquireItems.java @@ -0,0 +1,36 @@ +package com.somebody.idlframewok.item.skills; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Items; +import net.minecraft.init.SoundEvents; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ActionResult; +import net.minecraft.util.EnumActionResult; +import net.minecraft.util.EnumHand; +import net.minecraft.world.World; + +public class ItemSkillAquireItems extends ItemSkillBase { + public Item[] validItems = new Item[]{Items.PAPER}; + + public ItemSkillAquireItems(String name, Item[] validItems) { + super(name); + maxLevel = 1; + showDamageDesc = false; + this.validItems = validItems; + } + + @Override + public ActionResult onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) { + ItemStack stack = playerIn.getHeldItem(handIn); + + if (!worldIn.isRemote) + { + playerIn.addItemStackToInventory(new ItemStack(validItems[validItems.length])); + playerIn.playSound(SoundEvents.BLOCK_NOTE_HARP, 1f, 3f); + activateCoolDown(playerIn, stack); + } + return new ActionResult<>(EnumActionResult.SUCCESS, playerIn.getHeldItem(handIn)); + + } +} diff --git a/src/main/java/com/somebody/idlframewok/item/skills/ItemSkillAttackBoost.java b/src/main/java/com/somebody/idlframewok/item/skills/ItemSkillAttackBoost.java new file mode 100644 index 0000000..f00b936 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/item/skills/ItemSkillAttackBoost.java @@ -0,0 +1,54 @@ +package com.somebody.idlframewok.item.skills; + +import java.util.List; + +import com.somebody.idlframewok.util.CommonDef; +import com.somebody.idlframewok.util.EntityUtil; +import com.somebody.idlframewok.util.IDLGeneral; +import com.somebody.idlframewok.util.IDLSkillNBT; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.MobEffects; +import net.minecraft.init.SoundEvents; +import net.minecraft.item.ItemStack; +import net.minecraft.potion.PotionEffect; +import net.minecraft.util.ActionResult; +import net.minecraft.util.EnumActionResult; +import net.minecraft.util.EnumHand; +import net.minecraft.util.math.Vec3d; +import net.minecraft.world.World; + +public class ItemSkillAttackBoost extends ItemSkillBase { + public ItemSkillAttackBoost(String name) { + super(name); + cool_down = 50f; + maxLevel = 4; + } + + @Override + public ActionResult onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) { + ItemStack stack = playerIn.getHeldItem(handIn); + if (isStackReady(playerIn, stack)) + { + if (!worldIn.isRemote) + { + Vec3d basePos = playerIn.getPositionVector(); + List entities = worldIn.getEntitiesWithinAABB(EntityLivingBase.class, IDLGeneral.ServerAABB(basePos.addVector(-base_range, -base_range, -base_range), basePos.addVector(base_range, base_range, base_range))); + for (EntityLivingBase living: entities + ) { + if (EntityUtil.getAttitude(playerIn, living) == EntityUtil.ATTITUDE.FRIEND) + { + living.addPotionEffect(new PotionEffect(MobEffects.STRENGTH, 3* CommonDef.TICK_PER_TURN, IDLSkillNBT.getLevel(stack) - 1)); + } + } + playerIn.swingArm(handIn); + playerIn.playSound(SoundEvents.ENTITY_VILLAGER_YES, 1f, 1f); + activateCoolDown(playerIn, stack); + } + + return new ActionResult<>(EnumActionResult.SUCCESS, playerIn.getHeldItem(handIn)); + } + + return new ActionResult<>(EnumActionResult.FAIL, playerIn.getHeldItem(handIn)); + } +} diff --git a/src/main/java/com/somebody/idlframewok/item/skills/ItemSkillBase.java b/src/main/java/com/somebody/idlframewok/item/skills/ItemSkillBase.java new file mode 100644 index 0000000..932ede6 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/item/skills/ItemSkillBase.java @@ -0,0 +1,344 @@ +package com.somebody.idlframewok.item.skills; + +import java.util.List; + +import com.somebody.idlframewok.IdlFramework; +import com.somebody.idlframewok.init.ModCreativeTab; +import com.somebody.idlframewok.item.ItemBase; +import com.somebody.idlframewok.util.CommonDef; +import com.somebody.idlframewok.util.CommonFunctions; +import com.somebody.idlframewok.util.IDLSkillNBT; +import com.somebody.idlframewok.util.MessageDef; +import net.minecraft.client.resources.I18n; +import net.minecraft.client.util.ITooltipFlag; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.item.EnumRarity; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ActionResult; +import net.minecraft.util.EnumActionResult; +import net.minecraft.util.EnumHand; +import net.minecraft.util.text.TextFormatting; +import net.minecraft.world.World; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +enum SKILL_MSG_TYPE +{ + SUCCESS, + CD, +} + + +public class ItemSkillBase extends ItemBase { + public boolean isMartial = false; + + public float cool_down = 1f; + public float cool_down_reduce_per_lv = 0.2f; + + public float base_range = 5f; + public float range_per_level = 0f; + + public float basic_val = 0f; + public float val_per_level = 0f; + + public float dura_val = 0f; + public float dura_per_level = 0f; + + public float level_modifier = 0f; + + public int maxLevel = 5; + + public int gua_index = CommonDef.G_SKY; + + public boolean showCDDesc = true; + public boolean showDamageDesc = true; + public boolean showRangeDesc = false; + public boolean showDuraDesc = false; + + //for arknights + public boolean offHandCast = false; + public boolean mainHandCast = false; + public boolean cannotMouseCast = false; + + protected int maxDialogues = 0; + + protected int GetMaxTick(ItemStack stack) { + return (int) (getCoolDown(stack) * CommonDef.TICK_PER_SECOND); + } + + public ItemSkillBase(String name) { + super(name); + setMaxStackSize(1); + setNoRepair(); + setCreativeTab(ModCreativeTab.IDL_MISC); + } + + @Override + public EnumRarity getRarity(ItemStack stack) { + return super.getRarity(stack); + } + + public ItemSkillBase setMaxLevel(int maxLevel) + { + this.maxLevel = maxLevel; + return this; + } + + public ItemSkillBase setVal(float val, float val_per_level) + { + basic_val = val; + this.val_per_level = val_per_level; + return this; + } + + public ItemSkillBase setCD(float val, float val_per_level) + { + cool_down = val; + this.cool_down_reduce_per_lv = val_per_level; + return this; + } + + public ItemSkillBase setDura(float val, float val_per_level) + { + dura_val = val; + this.dura_per_level = val_per_level; + return this; + } + + public ItemSkillBase setRange(float val, float val_per_level) + { + base_range = val; + this.range_per_level = val_per_level; + return this; + } + + public float getRange(ItemStack stack) + { + return (IDLSkillNBT.getLevel(stack) - 1) * range_per_level + base_range; + } + + public float getDura(ItemStack stack) + { + return (IDLSkillNBT.getLevel(stack) - 1) * dura_per_level + dura_val; + } + public float getVal(ItemStack stack) + { + return (IDLSkillNBT.getLevel(stack) - 1) * val_per_level + basic_val; + } + public float getCoolDown(ItemStack stack) { + float result = -(IDLSkillNBT.getLevel(stack) - 1) * cool_down_reduce_per_lv + cool_down; + return result > 0.1f ? result : 0.1f; } + + //leveling------------------------------------- + + public int GetLevelMax(ItemStack stack) + { + if (!(stack.getItem() instanceof ItemSkillBase)) { + return 0; + } + return maxLevel; + } + + public void SendDefaultMsg(EntityPlayer player, ItemStack stack, SKILL_MSG_TYPE msg_type) + { + switch (msg_type) + { + case CD: + CommonFunctions.SendMsgToPlayer((EntityPlayerMP)player, stack.getUnlocalizedName()+ IDLSkillNBT.IN_CD_DESC_KEY); + case SUCCESS: + CommonFunctions.SendMsgToPlayer((EntityPlayerMP)player, stack.getUnlocalizedName()+ IDLSkillNBT.SUCCESS_DESC_KEY); + default: + break; + } + } + + public static void activateCoolDown(EntityPlayer player, ItemStack stack) + { + Item item = stack.getItem(); + if (item instanceof ItemSkillBase) + { + player.getCooldownTracker().setCooldown(stack.getItem(), ((ItemSkillBase) item).GetMaxTick(stack)); + } + } + + public static void notifyCoolingDown(EntityPlayerMP player) + { + CommonFunctions.SendMsgToPlayer(player, "idlframewok.skill.msg.cool_down"); + } + + public static boolean isStackReady(EntityPlayer player, ItemStack stack) + { + return !player.getCooldownTracker().hasCooldown(stack.getItem()); + //return stack.getItemDamage() == 0; + } + + //-------------------------- + + @Override + public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) { + super.onUpdate(stack, worldIn, entityIn, itemSlot, isSelected); + //stack.setItemDamage(stack.getItemDamage() - 1); + } + + + @Override + public ActionResult onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) { + if (cannotMouseCast) + { + return new ActionResult<>(EnumActionResult.PASS, playerIn.getHeldItem(handIn)); + } + + ItemStack stack = playerIn.getHeldItem(handIn); + if (isStackReady(playerIn, stack)) + { + if (canCast(worldIn, playerIn, handIn)) + { + tryCast(worldIn, playerIn, handIn); + activateCoolDown(playerIn, stack); + return new ActionResult<>(EnumActionResult.SUCCESS, playerIn.getHeldItem(handIn)); + } + else { + return new ActionResult<>(EnumActionResult.FAIL, playerIn.getHeldItem(handIn)); + + } + } + + return new ActionResult<>(EnumActionResult.FAIL, playerIn.getHeldItem(handIn)); + } + + public boolean canCast(World worldIn, EntityLivingBase livingBase, EnumHand handIn) + { + if (livingBase instanceof EntityPlayer) + { + isStackReady((EntityPlayer) livingBase, livingBase.getHeldItem(handIn)); + } + return true; + } + + public boolean tryCast(World worldIn, EntityLivingBase livingBase, EnumHand handIn) + { + if (livingBase instanceof EntityPlayer) + { + activateCoolDown((EntityPlayer) livingBase, livingBase.getHeldItem(handIn)); + } + return true; + } + + public boolean onKeyboardCast(EntityLivingBase caster, ItemStack stack, EnumHand hand) + { + World world = caster.world; + boolean casterIsPlayer = caster instanceof EntityPlayer; + if (!casterIsPlayer || isStackReady((EntityPlayer) caster, stack)) { + if (canCast(world, caster, hand)) { + if (hand == EnumHand.MAIN_HAND) { + if (mainHandCast) { + return tryCast(caster.world, caster, hand); + } else { + if (casterIsPlayer) + { + CommonFunctions.SafeSendMsgToPlayer(TextFormatting.RED, (EntityPlayer) caster, MessageDef.NOT_CASTABLE_MAINHAND); + } + else { + IdlFramework.LogWarning("Trying to do invalid cast from a creature: %s", caster.getName()); + } + } + } else if (hand == EnumHand.OFF_HAND) + if (offHandCast) { + return tryCast(caster.world, caster, hand); + }else { + if (casterIsPlayer) + { + CommonFunctions.SafeSendMsgToPlayer(TextFormatting.RED, (EntityPlayer) caster, MessageDef.NOT_CASTABLE_OFFHAND); + } + else { + IdlFramework.LogWarning("Trying to do invalid cast from a creature: %s", caster.getName()); + } + } + } + } + else { + EntityPlayer player = (EntityPlayer) caster; + CommonFunctions.SafeSendMsgToPlayer(TextFormatting.YELLOW, player, MessageDef.IN_COOLDOWN); + } + + return false; + } + + /** + * Returns true if the item can be used on the given entity, e.g. shears on sheep. + */ + public boolean itemInteractionForEntity(ItemStack stack, EntityPlayer playerIn, EntityLivingBase target, EnumHand hand) { + return false; + } + + //Desc + @SideOnly(Side.CLIENT) + @Override + public void addInformation(ItemStack stack, World world, List tooltip, ITooltipFlag flag) { + super.addInformation(stack, world, tooltip, flag); + boolean shiftPressed = !shiftToShowDesc || CommonFunctions.isShiftPressed(); + if (shiftPressed) + { + if (showCDDesc) + tooltip.add(I18n.format("idlframewok.skill.shared.cool_down_desc", getCoolDown(stack))); + if (showDamageDesc && getVal(stack) > 0) + tooltip.add(I18n.format("idlframewok.skill.shared.power_desc", getVal(stack))); + if (showRangeDesc) + tooltip.add(I18n.format("idlframewok.skill.shared.range_desc", getRange(stack))); + if (showDuraDesc) + tooltip.add(GetDuraDescString(getDura(stack))); + + if (maxLevel != 1) + { + tooltip.add(I18n.format("idlframewok.skill.shared.level_desc", IDLSkillNBT.getLevel(stack), maxLevel)); + } + } + } + + @SideOnly(Side.CLIENT) + public String getItemStackDisplayName(ItemStack stack) + { + if (maxLevel == 1) + { + return super.getItemStackDisplayName(stack); + } + +// String strMain =""; +//// if (IsNameHidden(stack)) +//// { +//// strMain = I18n.format(getUnlocalizedName(stack) + IDLNBTDef.TOOLTIP_HIDDEN); +//// +//// } +//// else +// { +// strMain = super.getItemStackDisplayName(stack); +// } + + String strMain = super.getItemStackDisplayName(stack); + int lv = IDLSkillNBT.getLevel(stack); + String strMaxLv = lv == maxLevel ? I18n.format("idlframewok.skill.shared.lv_max") : ""; + + return I18n.format("idlframewok.skill.shared.name_format_with_lv",strMain, IDLSkillNBT.getLevel(stack), strMaxLv); + } + + public String GetDuraDescString(float val) + { + return I18n.format("idlframewok.skill.shared.duration_desc", val); + } + + public void trySayDialogue(EntityLivingBase livingBase, ItemStack stack) + { + if (maxDialogues > 0) + { + int index = livingBase.getRNG().nextInt(maxDialogues); + if (livingBase instanceof EntityPlayer) + { + CommonFunctions.SafeSendMsgToPlayer((EntityPlayer) livingBase, MessageDef.getSkillCastKey(stack, index)); + } + } + } +} diff --git a/src/main/java/com/somebody/idlframewok/item/skills/ItemSkillBlessedArmor.java b/src/main/java/com/somebody/idlframewok/item/skills/ItemSkillBlessedArmor.java new file mode 100644 index 0000000..4efb090 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/item/skills/ItemSkillBlessedArmor.java @@ -0,0 +1,87 @@ +package com.somebody.idlframewok.item.skills; + +import com.somebody.idlframewok.util.Reference; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.SoundEvents; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ActionResult; +import net.minecraft.util.DamageSource; +import net.minecraft.util.EnumActionResult; +import net.minecraft.util.EnumHand; +import net.minecraft.util.SoundCategory; +import net.minecraft.world.World; +import net.minecraftforge.event.entity.living.LivingDamageEvent; +import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; + +@Mod.EventBusSubscriber(modid = Reference.MOD_ID) +public class ItemSkillBlessedArmor extends ItemSkillBase { + private float KBPower = 1f; + + @Override + public boolean isEnchantable(ItemStack stack) { + return true; + } + + public boolean isBookEnchantable(ItemStack stack, ItemStack book) + { + return true; + } + + public ItemSkillBlessedArmor(String name) { + super(name); + basic_val = 3f; + showDamageDesc = false; + } + + @SubscribeEvent + public static void onCreatureDamaged(LivingDamageEvent evt) { + World world = evt.getEntity().getEntityWorld(); + EntityLivingBase hurtOne = evt.getEntityLiving(); + if (evt.getSource() == DamageSource.FALL && hurtOne instanceof EntityPlayer) + { + EntityPlayer player = (EntityPlayer)hurtOne; + ItemStack stack = AttemptPlayerHand(player, EnumHand.MAIN_HAND); + if (stack == ItemStack.EMPTY) + { + stack = AttemptPlayerHand(player, EnumHand.OFF_HAND); + } + if (stack != ItemStack.EMPTY) + { + ItemSkillBlessedArmor skillThunderFall = ((ItemSkillBlessedArmor)stack.getItem()); + + evt.setAmount(0); + world.playSound(player, player.getPosition(), SoundEvents.BLOCK_NOTE_HARP, SoundCategory.PLAYERS, 1f, 3f); + } + } + } + + public static ItemStack AttemptPlayerHand(EntityPlayer player, EnumHand hand) + { + ItemStack stack = player.getHeldItem(hand); + if (stack.getItem() instanceof ItemSkillBlessedArmor && isStackReady(player, stack)){ + activateCoolDown(player, stack); + return stack; + } + return ItemStack.EMPTY; + } + + @Override + public ActionResult onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) { +// ItemStack stack = playerIn.getHeldItem(handIn); +// if (isStackReady(stack )) +// { +// Vec3d basePos = playerIn.getPositionVector(); +// List entities = worldIn.getEntitiesWithinAABB(EntityLiving.class, IDLGeneral.ServerAABB(basePos.addVector(-base_range, -base_range, -base_range), basePos.addVector(base_range, base_range, base_range))); +// for (EntityLiving living: entities +// ) { +// living.setAttackTarget(playerIn); +// } +// playerIn.swingArm(handIn); +// activateCoolDown(stack); +// return new ActionResult<>(EnumActionResult.SUCCESS, playerIn.getHeldItem(handIn)); +// } + return new ActionResult<>(EnumActionResult.PASS, playerIn.getHeldItem(handIn)); + } +} diff --git a/src/main/java/com/somebody/idlframewok/item/skills/ItemSkillBulletStrike.java b/src/main/java/com/somebody/idlframewok/item/skills/ItemSkillBulletStrike.java new file mode 100644 index 0000000..1b3f2f8 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/item/skills/ItemSkillBulletStrike.java @@ -0,0 +1,53 @@ +package com.somebody.idlframewok.item.skills; + +import com.somebody.idlframewok.entity.projectiles.EntityIdlProjectile; +import com.somebody.idlframewok.entity.projectiles.ProjectileArgs; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.SoundEvents; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ActionResult; +import net.minecraft.util.EnumActionResult; +import net.minecraft.util.EnumHand; +import net.minecraft.util.math.Vec3d; +import net.minecraft.world.World; + +public class ItemSkillBulletStrike extends ItemSkillBase { + public ItemSkillBulletStrike(String name) { + super(name); + } + + @Override + public ActionResult onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) { + ItemStack stack = playerIn.getHeldItem(handIn); + if (isStackReady(playerIn, stack)) + { + if (!worldIn.isRemote) + { + doRangedAttack(playerIn); + playerIn.swingArm(handIn); + activateCoolDown(playerIn, stack); + }else { + playerIn.playSound(SoundEvents.ENTITY_FIREWORK_LARGE_BLAST, 1f, 1f); + } + + return new ActionResult<>(EnumActionResult.SUCCESS, playerIn.getHeldItem(handIn)); + } + + return new ActionResult<>(EnumActionResult.FAIL, playerIn.getHeldItem(handIn)); + } + + protected void doRangedAttack(EntityPlayer caster) + { + World worldObj = caster.world; + + double d1 = caster.getCollisionBorderSize(); + Vec3d vec3d = caster.getLookVec().scale(100); + + EntityIdlProjectile entityBullet = new EntityIdlProjectile(worldObj, new ProjectileArgs(4f), caster, vec3d.x, vec3d.y, vec3d.z, 0.1f); + + entityBullet.posX = caster.getPositionEyes(0f).x + vec3d.x * d1; + entityBullet.posY = caster.getPositionEyes(0f).y + vec3d.y * d1; + entityBullet.posZ = caster.getPositionEyes(0f).z + vec3d.z * d1; + worldObj.spawnEntity(entityBullet); + } +} diff --git a/src/main/java/com/somebody/idlframewok/item/skills/ItemSkillCloneBlock.java b/src/main/java/com/somebody/idlframewok/item/skills/ItemSkillCloneBlock.java new file mode 100644 index 0000000..e3cf7b4 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/item/skills/ItemSkillCloneBlock.java @@ -0,0 +1,56 @@ +package com.somebody.idlframewok.item.skills; + +import net.minecraft.block.state.IBlockState; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.EnumRarity; +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; +import net.minecraft.world.World; + +public class ItemSkillCloneBlock extends ItemSkillBase { + + public ItemSkillCloneBlock(String name) { + super(name); + maxLevel = 12; + setCD(300, 20); + showDamageDesc = false; + } + + /** + * Called when a Block is right-clicked with this Item + */ + @Override + public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { + ItemStack stack = player.getHeldItem(hand); + + if (isStackReady(player, stack)) { + World world = player.world; + if (!world.isRemote) { + IBlockState state = world.getBlockState(pos); + + if (state.getBlock().isAir(state, world, pos)) + { + return EnumActionResult.FAIL; + } +// if (isCreative && GuiScreen.isCtrlKeyDown() && state.getBlock().hasTileEntity(state)) +// te = world.getTileEntity(pos); + ItemStack cloneResult = state.getBlock().getPickBlock(state, null, world, pos, player); + if (!cloneResult.isEmpty()) + { + player.addItemStackToInventory(cloneResult); + activateCoolDown(player, stack); + return EnumActionResult.SUCCESS; + } + } + } + return EnumActionResult.FAIL; + } + + @Override + public EnumRarity getRarity(ItemStack stack) { + return EnumRarity.EPIC; + } +} diff --git a/src/main/java/com/somebody/idlframewok/item/skills/ItemSkillCloneEgg.java b/src/main/java/com/somebody/idlframewok/item/skills/ItemSkillCloneEgg.java new file mode 100644 index 0000000..1692ee6 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/item/skills/ItemSkillCloneEgg.java @@ -0,0 +1,41 @@ +package com.somebody.idlframewok.item.skills; + +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.EnumRarity; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumHand; +import net.minecraft.world.World; + +public class ItemSkillCloneEgg extends ItemSkillBase { + + public ItemSkillCloneEgg(String name) { + super(name); + maxLevel = 12; + setCD(60, 5); + showDamageDesc = false; + } + + + @Override + public boolean itemInteractionForEntity(ItemStack stack, EntityPlayer playerIn, EntityLivingBase target, EnumHand handIn) { + if (isStackReady(playerIn, stack)) { + World world = playerIn.world; + if (!world.isRemote) { + ItemStack cloneResult = target.getPickedResult(null); + if (!cloneResult.isEmpty()) + { + playerIn.addItemStackToInventory(cloneResult); + activateCoolDown(playerIn, stack); + return true; + } + } + } + return false; + } + + @Override + public EnumRarity getRarity(ItemStack stack) { + return EnumRarity.EPIC; + } +} diff --git a/src/main/java/com/somebody/idlframewok/item/skills/ItemSkillDecodeItem.java b/src/main/java/com/somebody/idlframewok/item/skills/ItemSkillDecodeItem.java new file mode 100644 index 0000000..029b431 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/item/skills/ItemSkillDecodeItem.java @@ -0,0 +1,55 @@ +package com.somebody.idlframewok.item.skills; + +import java.util.List; + +import net.minecraft.client.resources.I18n; +import net.minecraft.client.util.ITooltipFlag; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.EnumRarity; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ActionResult; +import net.minecraft.util.EnumActionResult; +import net.minecraft.util.EnumHand; +import net.minecraft.world.World; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +public class ItemSkillDecodeItem extends ItemSkillBase { + + public ItemSkillDecodeItem(String name) { + super(name); + maxLevel = 10; + setCD(12, 1); + setVal(1, 0.1f); + showDamageDesc = false; + } + + @Override + public ActionResult onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) { + ItemStack stack = playerIn.getHeldItem(handIn); + + if (!worldIn.isRemote && handIn == EnumHand.MAIN_HAND) + { + //playerIn.setFire(5); + int count = playerIn.getHeldItemOffhand().getCount(); + float xp = (float)count * getVal(stack); + playerIn.addExperience((int) xp); + playerIn.setHeldItem(EnumHand.OFF_HAND, ItemStack.EMPTY); + activateCoolDown(playerIn, stack); + } + return new ActionResult<>(EnumActionResult.SUCCESS, playerIn.getHeldItem(handIn)); + } + + @Override + public EnumRarity getRarity(ItemStack stack) { + return EnumRarity.RARE; + } + + @SideOnly(Side.CLIENT) + @Override + public void addInformation(ItemStack stack, World world, List tooltip, ITooltipFlag flag) { + super.addInformation(stack, world, tooltip, flag); + String mainDesc = I18n.format(stack.getUnlocalizedName() + ".desc.extra", getVal(stack)); + tooltip.add(mainDesc); + } +} diff --git a/src/main/java/com/somebody/idlframewok/item/skills/ItemSkillExperienceDamageAbsorption.java b/src/main/java/com/somebody/idlframewok/item/skills/ItemSkillExperienceDamageAbsorption.java new file mode 100644 index 0000000..e169d5d --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/item/skills/ItemSkillExperienceDamageAbsorption.java @@ -0,0 +1,102 @@ +package com.somebody.idlframewok.item.skills; + +import java.util.List; + +import com.somebody.idlframewok.util.Reference; +import net.minecraft.client.resources.I18n; +import net.minecraft.client.util.ITooltipFlag; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ActionResult; +import net.minecraft.util.EnumActionResult; +import net.minecraft.util.EnumHand; +import net.minecraft.world.World; +import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +@Mod.EventBusSubscriber(modid = Reference.MOD_ID) +public class ItemSkillExperienceDamageAbsorption extends ItemSkillBase { + + public ItemSkillExperienceDamageAbsorption(String name) { + super(name); + setCD(0.1f, 0); + setVal(2f, -0.5f);//how many xp point 1 damage would cost; + maxLevel = 4; + } + +// @SubscribeEvent +// public static void onCreatureDamaged(LivingDamageEvent evt) { +// if (evt.isCanceled()) +// { +// return; +// } +// +// World world = evt.getEntity().getEntityWorld(); +// EntityLivingBase hurtOne = evt.getEntityLiving(); +// //CrowFlight.Log(String.format("DMG:%s=%f",evt.getEntityLiving(), evt.getAmount())); +// if (hurtOne instanceof EntityPlayer) +// { +// EntityPlayer player = (EntityPlayer)hurtOne; +// ItemStack stack = AttemptPlayerHand(player, EnumHand.MAIN_HAND); +// if (stack == ItemStack.EMPTY) +// { +// stack = AttemptPlayerHand(player, EnumHand.OFF_HAND); +// } +// if (stack != ItemStack.EMPTY) +// { +// ItemSkillExperienceDamageAbsorption skill = ((ItemSkillExperienceDamageAbsorption)stack.getItem()); +// +// float amount = evt.getAmount(); +// float multiplier = skill.getVal(stack); +// int xpCost = (int) (amount * multiplier); +// +// //if (!player.world.isRemote) { +// if (CommonFunctions.TryConsumePlayerXP(player, xpCost)) +// { +// player.playSound(SoundEvents.BLOCK_GLASS_BREAK, 1f, 1f); +// evt.setAmount(0); +// } +// //} +// } +// } +// } + + + public static ItemStack AttemptPlayerHand(EntityPlayer player, EnumHand hand) + { + ItemStack stack = player.getHeldItem(hand); + if (stack.getItem() instanceof ItemSkillExperienceDamageAbsorption && isStackReady(player, stack)){ + activateCoolDown(player, stack); + return stack; + } + return ItemStack.EMPTY; + } + + @Override + public ActionResult onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) { +// ItemStack stack = playerIn.getHeldItem(handIn); +// if (isStackReady(stack )) +// { +// Vec3d basePos = playerIn.getPositionVector(); +// List entities = worldIn.getEntitiesWithinAABB(EntityLiving.class, IDLGeneral.ServerAABB(basePos.addVector(-base_range, -base_range, -base_range), basePos.addVector(base_range, base_range, base_range))); +// for (EntityLiving living: entities +// ) { +// living.setAttackTarget(playerIn); +// } +// playerIn.swingArm(handIn); +// activateCoolDown(stack); +// return new ActionResult<>(EnumActionResult.SUCCESS, playerIn.getHeldItem(handIn)); +// } + return new ActionResult<>(EnumActionResult.PASS, playerIn.getHeldItem(handIn)); + } + + //Desc + @SideOnly(Side.CLIENT) + @Override + public void addInformation(ItemStack stack, World world, List tooltip, ITooltipFlag flag) { + String mainDesc = I18n.format(stack.getUnlocalizedName() + ".desc", getVal(stack)); + tooltip.add(mainDesc); + tooltip.add(I18n.format("idlframewok.skill.shared.cool_down_desc", getCoolDown(stack))); + } +} diff --git a/src/main/java/com/somebody/idlframewok/item/skills/ItemSkillExperiencePrideShield.java b/src/main/java/com/somebody/idlframewok/item/skills/ItemSkillExperiencePrideShield.java new file mode 100644 index 0000000..6f99143 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/item/skills/ItemSkillExperiencePrideShield.java @@ -0,0 +1,92 @@ +package com.somebody.idlframewok.item.skills; + +import com.somebody.idlframewok.util.Reference; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.SoundEvents; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ActionResult; +import net.minecraft.util.EnumActionResult; +import net.minecraft.util.EnumHand; +import net.minecraft.world.World; +import net.minecraftforge.event.entity.living.LivingDamageEvent; +import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.common.eventhandler.EventPriority; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; + +@Mod.EventBusSubscriber(modid = Reference.MOD_ID) +public class ItemSkillExperiencePrideShield extends ItemSkillBase { + + public ItemSkillExperiencePrideShield(String name) { + super(name); + setCD(0.1f, 0); + maxLevel = 1; + showCDDesc = false; + //setVal(2f, -0.5f);//how many xp point 1 damage would cost; + } + + @SubscribeEvent(priority = EventPriority.HIGHEST) + public static void onCreatureDamaged(LivingDamageEvent evt) { + if (evt.isCanceled()) + { + return; + } + EntityLivingBase hurtOne = evt.getEntityLiving(); + //CrowFlight.Log(String.format("DMG:%s=%f",evt.getEntityLiving(), evt.getAmount())); + if (hurtOne instanceof EntityPlayer) + { + EntityPlayer player = (EntityPlayer)hurtOne; + ItemStack stack = AttemptPlayerHand(player, EnumHand.MAIN_HAND); + if (stack == ItemStack.EMPTY) + { + stack = AttemptPlayerHand(player, EnumHand.OFF_HAND); + } + if (stack != ItemStack.EMPTY) + { + ItemSkillExperiencePrideShield skill = ((ItemSkillExperiencePrideShield)stack.getItem()); + + float amount = evt.getAmount(); + if (!player.world.isRemote) { + if (player.experienceLevel >= amount) + { + player.playSound(SoundEvents.BLOCK_GLASS_BREAK, 1f, 1f); + evt.setCanceled(true); + } + else { + evt.setAmount(amount * 2); + //player.experienceLevel -= 1; + } + } + } + } + } + + + public static ItemStack AttemptPlayerHand(EntityPlayer player, EnumHand hand) + { + ItemStack stack = player.getHeldItem(hand); + if (stack.getItem() instanceof ItemSkillExperiencePrideShield && isStackReady(player, stack)){ + activateCoolDown(player, stack); + return stack; + } + return ItemStack.EMPTY; + } + + @Override + public ActionResult onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) { +// ItemStack stack = playerIn.getHeldItem(handIn); +// if (isStackReady(stack )) +// { +// Vec3d basePos = playerIn.getPositionVector(); +// List entities = worldIn.getEntitiesWithinAABB(EntityLiving.class, IDLGeneral.ServerAABB(basePos.addVector(-base_range, -base_range, -base_range), basePos.addVector(base_range, base_range, base_range))); +// for (EntityLiving living: entities +// ) { +// living.setAttackTarget(playerIn); +// } +// playerIn.swingArm(handIn); +// activateCoolDown(stack); +// return new ActionResult<>(EnumActionResult.SUCCESS, playerIn.getHeldItem(handIn)); +// } + return new ActionResult<>(EnumActionResult.PASS, playerIn.getHeldItem(handIn)); + } +} diff --git a/src/main/java/com/somebody/idlframewok/item/skills/ItemSkillExperienceStrike.java b/src/main/java/com/somebody/idlframewok/item/skills/ItemSkillExperienceStrike.java new file mode 100644 index 0000000..c494579 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/item/skills/ItemSkillExperienceStrike.java @@ -0,0 +1,37 @@ +package com.somebody.idlframewok.item.skills; + +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.SoundEvents; +import net.minecraft.item.ItemStack; +import net.minecraft.util.DamageSource; +import net.minecraft.util.EnumHand; +import net.minecraft.world.World; + +public class ItemSkillExperienceStrike extends ItemSkillBase { + public ItemSkillExperienceStrike(String name) { + super(name); + setCD(2f,0.5f); + maxLevel = 3; + showDamageDesc = false; + showCDDesc = true; + } + + @Override + public boolean itemInteractionForEntity(ItemStack stack, EntityPlayer playerIn, EntityLivingBase target, EnumHand handIn) { + World world = playerIn.world; + if (!world.isRemote) + { + DamageSource damageSource = DamageSource.causePlayerDamage(playerIn).setMagicDamage(); + if (target.getHealth() < playerIn.experienceLevel) + { + damageSource.setDamageBypassesArmor(); + } + target.attackEntityFrom(damageSource, playerIn.experienceLevel); + } + playerIn.swingArm(handIn); + activateCoolDown(playerIn, stack); + target.playSound(SoundEvents.ENTITY_BLAZE_SHOOT, 1f, 1f); + return true; + } +} diff --git a/src/main/java/com/somebody/idlframewok/item/skills/ItemSkillFireBall.java b/src/main/java/com/somebody/idlframewok/item/skills/ItemSkillFireBall.java new file mode 100644 index 0000000..3cb2db8 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/item/skills/ItemSkillFireBall.java @@ -0,0 +1,69 @@ +package com.somebody.idlframewok.item.skills; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.projectile.EntityFireball; +import net.minecraft.entity.projectile.EntityLargeFireball; +import net.minecraft.entity.projectile.EntitySmallFireball; +import net.minecraft.init.SoundEvents; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ActionResult; +import net.minecraft.util.EnumActionResult; +import net.minecraft.util.EnumHand; +import net.minecraft.util.math.Vec3d; +import net.minecraft.world.World; + +public class ItemSkillFireBall extends ItemSkillBase { + public float KBPower = 1f; + public boolean useSmall = true; + public ItemSkillFireBall(String name) { + super(name); + } + + public ItemSkillFireBall setIsSmallFireBall(boolean val) + { + useSmall = val; + return this; + } + + @Override + public ActionResult onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) { + ItemStack stack = playerIn.getHeldItem(handIn); + if (isStackReady(playerIn, stack)) + { + if (!worldIn.isRemote) + { + doRangedAttack(playerIn); + playerIn.swingArm(handIn); + activateCoolDown(playerIn, stack); + }else { + playerIn.playSound(SoundEvents.ENTITY_FIREWORK_LARGE_BLAST, 1f, 1f); + } + + return new ActionResult<>(EnumActionResult.SUCCESS, playerIn.getHeldItem(handIn)); + } + + return new ActionResult<>(EnumActionResult.FAIL, playerIn.getHeldItem(handIn)); + } + + protected void doRangedAttack(EntityPlayer caster) + { + World worldObj = caster.world; + ItemStack stack = caster.getHeldItemMainhand(); + + double d1 = caster.getCollisionBorderSize(); + Vec3d vec3d = caster.getLookVec().scale(10); + + EntityFireball entityBullet; + if (useSmall) { + entityBullet = new EntitySmallFireball(worldObj, caster, vec3d.x, vec3d.y, vec3d.z); + } else { + entityBullet = new EntityLargeFireball(worldObj, caster,vec3d.x, vec3d.y, vec3d.z); + ((EntityLargeFireball)entityBullet).explosionPower = (int)getVal(stack); + } + + entityBullet.posX = caster.getPositionEyes(0f).x + vec3d.x * d1; + entityBullet.posY = caster.getPositionEyes(0f).y + vec3d.y * d1; + entityBullet.posZ = caster.getPositionEyes(0f).z + vec3d.z * d1; + worldObj.spawnEntity(entityBullet); + } +} diff --git a/src/main/java/com/somebody/idlframewok/item/skills/ItemSkillFireBlast.java b/src/main/java/com/somebody/idlframewok/item/skills/ItemSkillFireBlast.java new file mode 100644 index 0000000..0c40ab6 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/item/skills/ItemSkillFireBlast.java @@ -0,0 +1,65 @@ +package com.somebody.idlframewok.item.skills; + +import java.util.List; + +import com.somebody.idlframewok.util.IDLGeneral; +import net.minecraft.entity.EntityLiving; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.SoundEvents; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ActionResult; +import net.minecraft.util.DamageSource; +import net.minecraft.util.EnumActionResult; +import net.minecraft.util.EnumHand; +import net.minecraft.util.EnumParticleTypes; +import net.minecraft.util.math.Vec3d; +import net.minecraft.world.World; + +public class ItemSkillFireBlast extends ItemSkillBase { + public float KBPower = 0.01f; + public ItemSkillFireBlast(String name) { + super(name); + } + + @Override + public ActionResult onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) { + ItemStack stack = playerIn.getHeldItem(handIn); + if (isStackReady(playerIn, stack))//mostly always ready + { + //IdlFramework.Log("Trigg'd:" + worldIn.getWorldTime()); + if (!worldIn.isRemote) + { + ItemSkillFireBlast skillThunderFall = ((ItemSkillFireBlast)stack.getItem()); + + Vec3d basePos = playerIn.getPositionVector(); + List entities = worldIn.getEntitiesWithinAABB(EntityLiving.class, IDLGeneral.ServerAABB(basePos.addVector(-base_range, -base_range, -base_range), basePos.addVector(base_range, base_range, base_range))); + for (EntityLiving living: entities + ) { + living.attackEntityFrom(DamageSource.causePlayerDamage(playerIn).setFireDamage().setMagicDamage(), getVal(stack)); + //make sure it's not 0 0 ratio, or the target vanishes + living.knockBack(playerIn, skillThunderFall.KBPower, (playerIn.posX - living.posX), (playerIn.posZ - living.posZ)); + living.setFire((int)getVal(stack)); + } + playerIn.swingArm(handIn); + activateCoolDown(playerIn, stack); + }else { + playerIn.world.spawnParticle(EnumParticleTypes.EXPLOSION_HUGE, playerIn.posX, playerIn.posY, playerIn.posZ, 1.0D, 0.0D, 0.0D); + playerIn.playSound(SoundEvents.ENTITY_FIREWORK_LARGE_BLAST, 1f, 1f); + } + return new ActionResult<>(EnumActionResult.SUCCESS, playerIn.getHeldItem(handIn)); + } +// else { +// //wont run here in cool down. +// if (playerIn instanceof EntityPlayerMP) +// { +// notifyCoolingDown((EntityPlayerMP)playerIn); +// IdlFramework.Log("notified"); +// } +// else { +// IdlFramework.Log("wrong type"); +// } +// return new ActionResult<>(EnumActionResult.FAIL, playerIn.getHeldItem(handIn)); +// } + return new ActionResult<>(EnumActionResult.FAIL, playerIn.getHeldItem(handIn)); + } +} diff --git a/src/main/java/com/somebody/idlframewok/item/skills/ItemSkillGambit.java b/src/main/java/com/somebody/idlframewok/item/skills/ItemSkillGambit.java new file mode 100644 index 0000000..54cc555 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/item/skills/ItemSkillGambit.java @@ -0,0 +1,47 @@ +package com.somebody.idlframewok.item.skills; + +import java.util.Random; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.SoundEvents; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ActionResult; +import net.minecraft.util.EnumActionResult; +import net.minecraft.util.EnumHand; +import net.minecraft.util.SoundCategory; +import net.minecraft.world.World; + +public class ItemSkillGambit extends ItemSkillBase { + + public ItemSkillGambit(String name) { + super(name); + maxLevel = 1; + setCD(1,0); + showDamageDesc = false; + } + + @Override + public ActionResult onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) { + ItemStack stack = playerIn.getHeldItem(handIn); + + if (!worldIn.isRemote && handIn == EnumHand.MAIN_HAND) + { + Random rand = playerIn.getRNG(); + if (playerIn.getRNG().nextBoolean()) + { + playerIn.setHeldItem(EnumHand.OFF_HAND, ItemStack.EMPTY); + worldIn.playSound(playerIn, playerIn.getPosition(), SoundEvents.BLOCK_GLASS_BREAK, SoundCategory.PLAYERS, 1f, 3f); + } + else { + playerIn.addItemStackToInventory(playerIn.getHeldItemOffhand().copy()); + worldIn.playSound(playerIn, playerIn.getPosition(), SoundEvents.BLOCK_PISTON_CONTRACT, SoundCategory.PLAYERS, 1f, 3f); +// worldIn.spawnParticle(EnumParticleTypes.FIREWORKS_SPARK, playerIn.posX, playerIn.posY - 0.3D, playerIn.posZ, +// rand.nextGaussian() * 0.05D, -playerIn.motionY * 0.5D, rand.nextGaussian() * 0.05D); + } + + + activateCoolDown(playerIn, stack); + } + return new ActionResult<>(EnumActionResult.SUCCESS, playerIn.getHeldItem(handIn)); + } +} diff --git a/src/main/java/com/somebody/idlframewok/item/skills/ItemSkillModListStrike.java b/src/main/java/com/somebody/idlframewok/item/skills/ItemSkillModListStrike.java new file mode 100644 index 0000000..bd14a14 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/item/skills/ItemSkillModListStrike.java @@ -0,0 +1,55 @@ +package com.somebody.idlframewok.item.skills; + +import java.util.List; + +import com.somebody.idlframewok.meta.MetaUtil; +import net.minecraft.client.resources.I18n; +import net.minecraft.client.util.ITooltipFlag; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.SoundEvents; +import net.minecraft.item.ItemStack; +import net.minecraft.util.DamageSource; +import net.minecraft.util.EnumHand; +import net.minecraft.world.World; +import net.minecraftforge.fml.common.Loader; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +public class ItemSkillModListStrike extends ItemSkillBase { + public ItemSkillModListStrike(String name) { + super(name); + setCD(1f,0f); + showDamageDesc = false; + showCDDesc = true; + } + + @Override + public boolean itemInteractionForEntity(ItemStack stack, EntityPlayer playerIn, EntityLivingBase target, EnumHand handIn) { + World world = playerIn.world; + if (!world.isRemote) + { + DamageSource damageSource = DamageSource.causePlayerDamage(playerIn).setMagicDamage(); + + damageSource.setDamageBypassesArmor(); + + target.attackEntityFrom(damageSource, MetaUtil.GetModCount()); + } + playerIn.swingArm(handIn); + activateCoolDown(playerIn, stack); + target.playSound(SoundEvents.ENTITY_BLAZE_SHOOT, 1f, 1f); + return true; + } + + @SideOnly(Side.CLIENT) + public String getMainDesc(ItemStack stack, World world, List tooltip, ITooltipFlag flag) + { + String key = stack.getUnlocalizedName() + ".desc"; + if (I18n.hasKey(key)) + { + String mainDesc = I18n.format(key, Loader.instance().getActiveModList().size()); + return mainDesc; + } + return ""; + } +} diff --git a/src/main/java/com/somebody/idlframewok/item/skills/ItemSkillRepairArmor.java b/src/main/java/com/somebody/idlframewok/item/skills/ItemSkillRepairArmor.java new file mode 100644 index 0000000..06580be --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/item/skills/ItemSkillRepairArmor.java @@ -0,0 +1,86 @@ +package com.somebody.idlframewok.item.skills; + +import com.somebody.idlframewok.util.CommonFunctions; +import net.minecraft.enchantment.Enchantment; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.SoundEvents; +import net.minecraft.inventory.EntityEquipmentSlot; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.util.ActionResult; +import net.minecraft.util.EnumActionResult; +import net.minecraft.util.EnumHand; +import net.minecraft.util.SoundCategory; +import net.minecraft.world.World; + +public class ItemSkillRepairArmor extends ItemSkillBase { + public ItemSkillRepairArmor(String name) { + super(name); + } + + @Override + public boolean isEnchantable(ItemStack stack) { + return true; + } + + public boolean isBookEnchantable(ItemStack stack, ItemStack book) + { + return true; + } + + + public ActionResult onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) + { + ItemStack heldItem = playerIn.getHeldItem(handIn); + NBTTagList nbttaglist = heldItem.getEnchantmentTagList(); + + boolean used = false; + for (EntityEquipmentSlot slot: + EntityEquipmentSlot.values()){ + + if (slot == EntityEquipmentSlot.MAINHAND || slot == EntityEquipmentSlot.OFFHAND) + { + continue;//only repairs armor + } + + ItemStack itemstack1 = playerIn.getItemStackFromSlot(slot); + + //fix and enchant existing armor + if (!itemstack1.isEmpty()) + { + if (!playerIn.world.isRemote) + { + //Fix Dura + CommonFunctions.RepairItem(itemstack1, (int) getVal(heldItem)); + + //Copy Enchantment + for (int j = 0; j < nbttaglist.tagCount(); ++j) + { + NBTTagCompound nbttagcompound = nbttaglist.getCompoundTagAt(j); + int k = nbttagcompound.getShort("layer"); + int l = nbttagcompound.getShort("lvl"); + Enchantment enchantment = Enchantment.getEnchantmentByID(k); + + if (enchantment != null) + { + itemstack1.addEnchantment(enchantment, l); + } + } + } + used = true; + } + } + + if (used) + { + activateCoolDown(playerIn, heldItem); + worldIn.playSound(playerIn, playerIn.getPosition(), SoundEvents.BLOCK_NOTE_HARP, SoundCategory.PLAYERS, 1f, 3f); + return new ActionResult(EnumActionResult.SUCCESS, heldItem); + } + else + { + return new ActionResult(EnumActionResult.FAIL, heldItem); + } + } +} diff --git a/src/main/java/com/somebody/idlframewok/item/skills/ItemSkillSacrifce2020.java b/src/main/java/com/somebody/idlframewok/item/skills/ItemSkillSacrifce2020.java new file mode 100644 index 0000000..ef2e008 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/item/skills/ItemSkillSacrifce2020.java @@ -0,0 +1,58 @@ +package com.somebody.idlframewok.item.skills; + +import java.util.List; + +import com.somebody.idlframewok.util.CommonDef; +import com.somebody.idlframewok.util.EntityUtil; +import com.somebody.idlframewok.util.IDLGeneral; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.MobEffects; +import net.minecraft.item.ItemStack; +import net.minecraft.potion.PotionEffect; +import net.minecraft.util.ActionResult; +import net.minecraft.util.EnumActionResult; +import net.minecraft.util.EnumHand; +import net.minecraft.util.math.Vec3d; +import net.minecraft.world.World; + +public class ItemSkillSacrifce2020 extends ItemSkillBase { + public ItemSkillSacrifce2020(String name) { + super(name); + cool_down = 50f; + maxLevel = 1; + showDamageDesc = false; + + setRange(32, 32); + } + + @Override + public ActionResult onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) { + ItemStack stack = playerIn.getHeldItem(handIn); + if (isStackReady(playerIn, stack)) + { + if (!worldIn.isRemote) + { + Vec3d basePos = playerIn.getPositionVector(); + float range = getRange(stack); + List entities = worldIn.getEntitiesWithinAABB(EntityPlayer.class, IDLGeneral.ServerAABB(basePos.addVector(-range, -range, -range), basePos.addVector(range, range, range))); + for (EntityPlayer living: entities + ) { + if (living != playerIn) + { + EntityUtil.TryRemoveDebuff(living); + living.addPotionEffect(new PotionEffect(MobEffects.REGENERATION, CommonDef.TICK_PER_SECOND * 5, 0)); + living.heal(living.getMaxHealth()); + } + } + + playerIn.addPotionEffect(new PotionEffect(MobEffects.POISON, CommonDef.TICK_PER_SECOND * 60, 0)); + playerIn.setHealth(1f); + activateCoolDown(playerIn, stack); + } + + return new ActionResult<>(EnumActionResult.SUCCESS, playerIn.getHeldItem(handIn)); + } + + return new ActionResult<>(EnumActionResult.FAIL, playerIn.getHeldItem(handIn)); + } +} diff --git a/src/main/java/com/somebody/idlframewok/item/skills/ItemSkillSheepTransform.java b/src/main/java/com/somebody/idlframewok/item/skills/ItemSkillSheepTransform.java new file mode 100644 index 0000000..6740673 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/item/skills/ItemSkillSheepTransform.java @@ -0,0 +1,52 @@ +package com.somebody.idlframewok.item.skills; + +import com.somebody.idlframewok.util.CommonFunctions; +import net.minecraft.entity.EntityLiving; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.passive.EntitySheep; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.SoundEvents; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumHand; +import net.minecraft.util.EnumParticleTypes; +import net.minecraft.util.SoundCategory; +import net.minecraft.world.World; + +public class ItemSkillSheepTransform extends ItemSkillBase { + public ItemSkillSheepTransform(String name) { + super(name); + setCD(30f, 5f); + showDamageDesc = false; + } + + @Override + public boolean itemInteractionForEntity(ItemStack stack, EntityPlayer playerIn, EntityLivingBase target, EnumHand handIn) { + if (isStackReady(playerIn, stack)) + { + World world = playerIn.world; + if (!world.isRemote) + { + if ((target instanceof EntityLiving)) + { + EntitySheep elk = new EntitySheep(world); + elk.setPosition(target.posX,target.posY,target.posZ); + + CommonFunctions.CopyNormalAttr(target, elk); + + target.setDead(); + + world.spawnEntity(elk); + world.spawnParticle(EnumParticleTypes.MOB_APPEARANCE, target.posX, target.posY, target.posZ, 0,0,0); + world.playSound(null, target.getPosition(), SoundEvents.ENTITY_WITCH_AMBIENT, SoundCategory.PLAYERS,1f,1f); + //TryGrantAchv(playerIn, AchvDef.ELK_TRANSFORM); + } + } + playerIn.swingArm(handIn); + activateCoolDown(playerIn, stack); + target.playSound(SoundEvents.ENTITY_SHEEP_AMBIENT, 1f, 1f); + return true; + } + + return false; + } +} diff --git a/src/main/java/com/somebody/idlframewok/item/skills/ItemSkillTauntNearby.java b/src/main/java/com/somebody/idlframewok/item/skills/ItemSkillTauntNearby.java new file mode 100644 index 0000000..9638c3a --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/item/skills/ItemSkillTauntNearby.java @@ -0,0 +1,44 @@ +package com.somebody.idlframewok.item.skills; + +import java.util.List; + +import com.somebody.idlframewok.util.IDLGeneral; +import net.minecraft.entity.EntityLiving; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.SoundEvents; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ActionResult; +import net.minecraft.util.EnumActionResult; +import net.minecraft.util.EnumHand; +import net.minecraft.util.SoundCategory; +import net.minecraft.util.math.Vec3d; +import net.minecraft.world.World; + +public class ItemSkillTauntNearby extends ItemSkillBase { + public ItemSkillTauntNearby(String name) { + super(name); + showRangeDesc = true; + showCDDesc = false; + showDamageDesc = false; + } + + @Override + public ActionResult onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) { + ItemStack stack = playerIn.getHeldItem(handIn); + if (isStackReady(playerIn, stack)) + { + Vec3d basePos = playerIn.getPositionVector(); + List entities = worldIn.getEntitiesWithinAABB(EntityLiving.class, IDLGeneral.ServerAABB(basePos.addVector(-base_range, -base_range, -base_range), basePos.addVector(base_range, base_range, base_range))); + for (EntityLiving living: entities + ) { + living.setAttackTarget(playerIn); + } + worldIn.playSound(playerIn, playerIn.getPosition(), SoundEvents.BLOCK_NOTE_HARP, SoundCategory.PLAYERS, 1f, 3f); + playerIn.swingArm(handIn); + activateCoolDown(playerIn, stack); + return new ActionResult<>(EnumActionResult.SUCCESS, playerIn.getHeldItem(handIn)); + } + + return new ActionResult<>(EnumActionResult.FAIL, playerIn.getHeldItem(handIn)); + } +} diff --git a/src/main/java/com/somebody/idlframewok/item/skills/ItemSkillTauntNearbyToGiven.java b/src/main/java/com/somebody/idlframewok/item/skills/ItemSkillTauntNearbyToGiven.java new file mode 100644 index 0000000..4c659dc --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/item/skills/ItemSkillTauntNearbyToGiven.java @@ -0,0 +1,44 @@ +package com.somebody.idlframewok.item.skills; + +import java.util.List; + +import com.somebody.idlframewok.util.IDLGeneral; +import net.minecraft.entity.EntityLiving; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.SoundEvents; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumHand; +import net.minecraft.util.math.Vec3d; + +public class ItemSkillTauntNearbyToGiven extends ItemSkillBase { + public ItemSkillTauntNearbyToGiven(String name) { + super(name); + cool_down = 50f; + base_range = 10f; + range_per_level = 10f; + } + + @Override + public boolean itemInteractionForEntity(ItemStack stack, EntityPlayer playerIn, EntityLivingBase target, EnumHand handIn) { + if (isStackReady(playerIn, stack)) + { + Vec3d basePos = playerIn.getPositionVector(); + List entities = playerIn.world.getEntitiesWithinAABB(EntityLiving.class, IDLGeneral.ServerAABB(basePos.addVector(-getRange(stack), -getRange(stack), -getRange(stack)), + basePos.addVector(getRange(stack), getRange(stack), getRange(stack)))); + for (EntityLiving living: entities + ) { + if (living != target) + { + living.setAttackTarget(target); + } + } + playerIn.swingArm(handIn); + activateCoolDown(playerIn, stack); + target.playSound(SoundEvents.ENTITY_POLAR_BEAR_WARNING, 1f, 1f); + return true; + } + + return false; + } +} diff --git a/src/main/java/com/somebody/idlframewok/item/skills/ItemSkillThunderFall.java b/src/main/java/com/somebody/idlframewok/item/skills/ItemSkillThunderFall.java new file mode 100644 index 0000000..e5f4705 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/item/skills/ItemSkillThunderFall.java @@ -0,0 +1,100 @@ +package com.somebody.idlframewok.item.skills; + +import java.util.List; + +import com.somebody.idlframewok.util.IDLGeneral; +import com.somebody.idlframewok.util.Reference; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.SoundEvents; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ActionResult; +import net.minecraft.util.DamageSource; +import net.minecraft.util.EnumActionResult; +import net.minecraft.util.EnumHand; +import net.minecraft.util.math.Vec3d; +import net.minecraft.world.World; +import net.minecraftforge.event.entity.living.LivingDamageEvent; +import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; + +@Mod.EventBusSubscriber(modid = Reference.MOD_ID) +public class ItemSkillThunderFall extends ItemSkillBase { + private float KBPower = 1f; + + public ItemSkillThunderFall(String name) { + super(name); + maxLevel = 1; + basic_val = 3f; + showCDDesc = true; + } + + @SubscribeEvent + public static void onCreatureDamaged(LivingDamageEvent evt) { + World world = evt.getEntity().getEntityWorld(); + EntityLivingBase hurtOne = evt.getEntityLiving(); + //CrowFlight.Log(String.format("DMG:%s=%f",evt.getEntityLiving(), evt.getAmount())); + if (evt.getSource() == DamageSource.FALL && hurtOne instanceof EntityPlayer) + { + //IdlFramework.Log("player Falling"); + EntityPlayer player = (EntityPlayer)hurtOne; + ItemStack stack = AttemptPlayerHand(player, EnumHand.MAIN_HAND); + if (stack == ItemStack.EMPTY) + { + stack = AttemptPlayerHand(player, EnumHand.OFF_HAND); + } + if (stack != ItemStack.EMPTY) + { + ItemSkillThunderFall skillThunderFall = ((ItemSkillThunderFall)stack.getItem()); + + float amount = evt.getAmount(); + float multiplier = skillThunderFall.getVal(stack); + float range = skillThunderFall.getRange(stack); + + if (!player.world.isRemote) { + Vec3d mypos = player.getPositionEyes(0f); + player.playSound(SoundEvents.ENTITY_LIGHTNING_IMPACT, 1f, 1f); + //Damage nearby entities + List list = player.world.getEntitiesWithinAABB(EntityLivingBase.class, IDLGeneral.ServerAABB(mypos.addVector(-range, -range - hurtOne.getEyeHeight(), -range), mypos.addVector(range, range, range))); + for (EntityLivingBase creature : list) { + if (creature != hurtOne) { + if (creature.attackEntityFrom(DamageSource.ANVIL, multiplier * amount)) { + creature.knockBack(player, skillThunderFall.KBPower, (player.posX - creature.posX), (player.posZ - creature.posZ)); + } + } + } + } + + evt.setAmount(0); + } + } + } + + public static ItemStack AttemptPlayerHand(EntityPlayer player, EnumHand hand) + { + ItemStack stack = player.getHeldItem(hand); + if (stack.getItem() instanceof ItemSkillThunderFall && isStackReady(player, stack)){ + activateCoolDown(player, stack); + return stack; + } + return ItemStack.EMPTY; + } + + @Override + public ActionResult onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) { +// ItemStack stack = playerIn.getHeldItem(handIn); +// if (isStackReady(stack )) +// { +// Vec3d basePos = playerIn.getPositionVector(); +// List entities = worldIn.getEntitiesWithinAABB(EntityLiving.class, IDLGeneral.ServerAABB(basePos.addVector(-base_range, -base_range, -base_range), basePos.addVector(base_range, base_range, base_range))); +// for (EntityLiving living: entities +// ) { +// living.setAttackTarget(playerIn); +// } +// playerIn.swingArm(handIn); +// activateCoolDown(stack); +// return new ActionResult<>(EnumActionResult.SUCCESS, playerIn.getHeldItem(handIn)); +// } + return new ActionResult<>(EnumActionResult.PASS, playerIn.getHeldItem(handIn)); + } +} diff --git a/src/main/java/com/somebody/idlframewok/item/skills/ItemSkillTimeCutFixed.java b/src/main/java/com/somebody/idlframewok/item/skills/ItemSkillTimeCutFixed.java new file mode 100644 index 0000000..2c10a66 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/item/skills/ItemSkillTimeCutFixed.java @@ -0,0 +1,61 @@ +package com.somebody.idlframewok.item.skills; + +import java.util.List; + +import net.minecraft.client.resources.I18n; +import net.minecraft.client.util.ITooltipFlag; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Items; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ActionResult; +import net.minecraft.util.EnumActionResult; +import net.minecraft.util.EnumHand; +import net.minecraft.world.World; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +public class ItemSkillTimeCutFixed extends ItemSkillBase { + + public ItemSkillTimeCutFixed(String name) { + super(name); + maxLevel = 5; + setCD(20,0); + setVal(1f, 0.5f); + showDamageDesc = false; + } + + @Override + public ActionResult onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) { + ItemStack stack = playerIn.getHeldItem(handIn); + + if (!worldIn.isRemote && handIn == EnumHand.MAIN_HAND) + { + Item itemToSet = playerIn.getHeldItemOffhand().getItem(); + + float cut = getVal(stack); + if (itemToSet != Items.AIR && playerIn.getCooldownTracker().getCooldown(itemToSet, 0f) > 0) + { + float cd = playerIn.getCooldownTracker().getCooldown(itemToSet, 0f); + playerIn.getCooldownTracker().setCooldown(itemToSet, (int) (cd - cut)); + activateCoolDown(playerIn, stack); + return new ActionResult<>(EnumActionResult.SUCCESS, playerIn.getHeldItem(handIn)); + } + + } + return new ActionResult<>(EnumActionResult.FAIL, playerIn.getHeldItem(handIn)); + } + + @SideOnly(Side.CLIENT) + public String getMainDesc(ItemStack stack, World world, List tooltip, ITooltipFlag flag) + { + String key = stack.getUnlocalizedName() + ".desc"; + if (I18n.hasKey(key)) + { + String mainDesc = I18n.format(key, getVal(stack)); + return mainDesc; + } + return ""; + } +} + diff --git a/src/main/java/com/somebody/idlframewok/item/skills/ItemSkillTimeCutPercent.java b/src/main/java/com/somebody/idlframewok/item/skills/ItemSkillTimeCutPercent.java new file mode 100644 index 0000000..32aa202 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/item/skills/ItemSkillTimeCutPercent.java @@ -0,0 +1,60 @@ +package com.somebody.idlframewok.item.skills; + +import java.util.List; + +import net.minecraft.client.resources.I18n; +import net.minecraft.client.util.ITooltipFlag; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Items; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ActionResult; +import net.minecraft.util.EnumActionResult; +import net.minecraft.util.EnumHand; +import net.minecraft.world.World; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +public class ItemSkillTimeCutPercent extends ItemSkillBase { + + public ItemSkillTimeCutPercent(String name) { + super(name); + maxLevel = 9; + setCD(20,0); + setVal(0.9f, -0.1f); + showDamageDesc = false; + } + + @Override + public ActionResult onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) { + ItemStack stack = playerIn.getHeldItem(handIn); + + if (!worldIn.isRemote && handIn == EnumHand.MAIN_HAND) + { + Item itemToSet = playerIn.getHeldItemOffhand().getItem(); + + float factor = getVal(stack); + if (itemToSet != Items.AIR && playerIn.getCooldownTracker().getCooldown(itemToSet, 0f) > 0) + { + float cd = playerIn.getCooldownTracker().getCooldown(itemToSet, 0f); + playerIn.getCooldownTracker().setCooldown(itemToSet, (int) (cd * factor)); + activateCoolDown(playerIn, stack); + return new ActionResult<>(EnumActionResult.SUCCESS, playerIn.getHeldItem(handIn)); + } + + } + return new ActionResult<>(EnumActionResult.FAIL, playerIn.getHeldItem(handIn)); + } + + @SideOnly(Side.CLIENT) + public String getMainDesc(ItemStack stack, World world, List tooltip, ITooltipFlag flag) + { + String key = stack.getUnlocalizedName() + ".desc"; + if (I18n.hasKey(key)) + { + String mainDesc = I18n.format(key, 100f - getVal(stack) * 100f); + return mainDesc; + } + return ""; + } +} diff --git a/src/main/java/com/somebody/idlframewok/item/skills/ItemSkillVanquishWeak.java b/src/main/java/com/somebody/idlframewok/item/skills/ItemSkillVanquishWeak.java new file mode 100644 index 0000000..5da2cc1 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/item/skills/ItemSkillVanquishWeak.java @@ -0,0 +1,34 @@ +package com.somebody.idlframewok.item.skills; + +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.SoundEvents; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumHand; + +public class ItemSkillVanquishWeak extends ItemSkillBase { + public ItemSkillVanquishWeak(String name) { + super(name); + cool_down = 5f; + setVal(15,5f); + setCD(1f, 0.1f); + maxLevel = 25565; + } + + @Override + public boolean itemInteractionForEntity(ItemStack stack, EntityPlayer playerIn, EntityLivingBase target, EnumHand handIn) { + if (target.getHealth() < getVal(stack)) + { + playerIn.swingArm(handIn); + activateCoolDown(playerIn, stack); + target.playSound(SoundEvents.ENTITY_POLAR_BEAR_WARNING, 1f, 1f); + target.setDead(); + return true; + } + else { + return false; + } + + + } +} diff --git a/src/main/java/com/somebody/idlframewok/item/skills/ItemSkillWindWalk.java b/src/main/java/com/somebody/idlframewok/item/skills/ItemSkillWindWalk.java new file mode 100644 index 0000000..ddee1b0 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/item/skills/ItemSkillWindWalk.java @@ -0,0 +1,51 @@ +package com.somebody.idlframewok.item.skills; + +import java.util.List; + +import com.somebody.idlframewok.util.CommonDef; +import com.somebody.idlframewok.util.IDLSkillNBT; +import net.minecraft.client.util.ITooltipFlag; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.MobEffects; +import net.minecraft.init.SoundEvents; +import net.minecraft.item.ItemStack; +import net.minecraft.potion.PotionEffect; +import net.minecraft.util.ActionResult; +import net.minecraft.util.EnumActionResult; +import net.minecraft.util.EnumHand; +import net.minecraft.world.World; + +public class ItemSkillWindWalk extends ItemSkillBase { + public ItemSkillWindWalk(String name) { + super(name); + cool_down = 50f; + maxLevel = 4; + showDamageDesc = false; + setVal(20,5); + } + + @Override + public ActionResult onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) { + ItemStack stack = playerIn.getHeldItem(handIn); + if (isStackReady(playerIn, stack)) + { + if (!worldIn.isRemote) + { + playerIn.addPotionEffect(new PotionEffect(MobEffects.SPEED, (int)(getVal(stack) * CommonDef.TICK_PER_SECOND), IDLSkillNBT.getLevel(stack) - 1)); + playerIn.playSound(SoundEvents.BLOCK_NOTE_HARP, 1f, 3f); + activateCoolDown(playerIn, stack); + } + + return new ActionResult<>(EnumActionResult.SUCCESS, playerIn.getHeldItem(handIn)); + } + + return new ActionResult<>(EnumActionResult.FAIL, playerIn.getHeldItem(handIn)); + } + + + @Override + public void addInformation(ItemStack stack, World world, List tooltip, ITooltipFlag flag) { + super.addInformation(stack, world, tooltip, flag); + tooltip.add(GetDuraDescString(getVal(stack))); + } +} diff --git a/src/main/java/com/somebody/idlframewok/item/skills/arknights/ItemArknightsSkillBase.java b/src/main/java/com/somebody/idlframewok/item/skills/arknights/ItemArknightsSkillBase.java new file mode 100644 index 0000000..ae524cb --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/item/skills/arknights/ItemArknightsSkillBase.java @@ -0,0 +1,238 @@ +package com.somebody.idlframewok.item.skills.arknights; + +import com.somebody.idlframewok.IdlFramework; +import com.somebody.idlframewok.item.skills.ItemSkillBase; +import com.somebody.idlframewok.util.CommonDef; +import com.somebody.idlframewok.util.CommonFunctions; +import com.somebody.idlframewok.util.IDLSkillNBT; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumHand; +import net.minecraft.world.World; +import net.minecraftforge.event.entity.living.LivingDeathEvent; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.common.gameevent.PlayerEvent; + +public class ItemArknightsSkillBase extends ItemSkillBase { + + protected int[] dura = {10}; + //int[] cd = {90}; + protected int[] initPower = {0}; + + protected int[] max_charge = {5}; + + boolean isAutoCharge = true; + + public ItemArknightsSkillBase(String name) { + super(name); + CommonFunctions.addToEventBus(this); + } + + @Override + public int getMaxDamage(ItemStack stack) { + return 100; + } + + public float getInitPower(ItemStack stack) + { + int level = IDLSkillNBT.getLevel(stack) - 1; + + if (level < 0){ + return initPower[0]; + } + else if(level >= initPower.length) + { + return initPower[initPower.length - 1]; + } + + return initPower[level]; + } + + public float getDurationMax(ItemStack stack) + { + int level = IDLSkillNBT.getLevel(stack) - 1; + + if (level < 0){ + return dura[0]; + } + else if(level >= dura.length) + { + return dura[dura.length - 1]; + } + + return dura[level]; + } + + public float getChargeMax(ItemStack stack) + { + int level = IDLSkillNBT.getLevel(stack) - 1; + + if (level < 0){ + return max_charge[0]; + } + else if(level >= max_charge.length) + { + return max_charge[max_charge.length - 1]; + } + + return max_charge[level]; + } + + @Override + public float getCoolDown(ItemStack stack) { + return getChargeMax(stack); + } + + @Override + public float getDura(ItemStack stack) { + return getDurationMax(stack); + } + + public void upkeep(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) + { + if (worldIn.isRemote || worldIn.getWorldTime() % CommonDef.TICK_PER_SECOND != 0) + { + return; + } + + if (entityIn instanceof EntityPlayer) + { + boolean casting = IDLSkillNBT.IsCasting(stack); + EntityPlayer player = (EntityPlayer) entityIn; + player.getCooldownTracker().setCooldown(stack.getItem(), casting ? 3600 : 0); + if (casting) + { + float dura = IDLSkillNBT.GetDura(stack); + if (worldIn.getWorldTime() % CommonDef.TICK_PER_SECOND == 0) + { + dura -= 1f; + } + + if (dura <= 0) + { + dura = 0; + IDLSkillNBT.SetCasting(stack, false); + activateCoolDownArknights(stack); + IdlFramework.Log("%s casting complete.", entityIn); + } + + IDLSkillNBT.SetDura(stack, dura); + } + else { + if (isAutoCharge) + { + float charge = IDLSkillNBT.GetCharge(stack); + float curMaxCharge = getChargeMax(stack); + + if (charge >= curMaxCharge) + { + if (charge > curMaxCharge) + { + charge = curMaxCharge; + IDLSkillNBT.SetCharge(stack, curMaxCharge); + } + } + else { + charge += 1f; + IDLSkillNBT.SetCharge(stack, charge); + } + } + } + + if (casting) + { + stack.setItemDamage((int) ((1 - IDLSkillNBT.GetDura(stack) / getDurationMax(stack)) * getMaxDamage(stack))); + }else { + stack.setItemDamage((int) ((1 - IDLSkillNBT.GetCharge(stack) / getChargeMax(stack)) * getMaxDamage(stack))); + } + } + } + + public void activateCoolDownArknights(ItemStack stack) + { + Item item = stack.getItem(); + if (item instanceof ItemSkillBase) + { + IDLSkillNBT.SetCasting(stack, false); + IDLSkillNBT.SetCharge(stack, 0); + } + } + + @Override + public boolean canCast(World worldIn, EntityLivingBase livingBase, EnumHand handIn) { + ItemStack stack = livingBase.getHeldItem(handIn); + + boolean casting = IDLSkillNBT.IsCasting(stack); + if (casting) + { + return false; + } + + float charge = IDLSkillNBT.GetCharge(stack); + float curMaxCharge = getChargeMax(stack); + + if (charge >= curMaxCharge) + { + return super.canCast(worldIn, livingBase, handIn); + } + else { + return false; + } + } + + @Override + public boolean tryCast(World worldIn, EntityLivingBase livingBase, EnumHand handIn) { + + ItemStack stack = livingBase.getHeldItem(handIn); + IDLSkillNBT.SetCasting(stack, true); + IDLSkillNBT.SetCharge(stack, 0); + IDLSkillNBT.SetDura(stack, getDurationMax(stack)); + trySayDialogue(livingBase, stack); + + return true; + } + + @Override + public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) { + super.onUpdate(stack, worldIn, entityIn, itemSlot, isSelected); + upkeep(stack, worldIn, entityIn, itemSlot, isSelected); + } + + public void tryToInitializeCharge(EntityPlayer player) + { + for (int i = 0; i < player.inventory.getSizeInventory(); ++i) { + ItemStack itemstack = player.inventory.getStackInSlot(i); + { + if (itemstack.getItem() == this) + { + if (!IDLSkillNBT.IsCasting(itemstack)) + { + float power = getInitPower(itemstack); + IDLSkillNBT.SetCharge(itemstack, power); + } + } + } + } + } + + @SubscribeEvent + public void onLogIn(PlayerEvent.PlayerLoggedInEvent event) + { + if (!event.player.world.isRemote) + tryToInitializeCharge(event.player); + } + + @SubscribeEvent + public void onDeath(LivingDeathEvent event) + { + if (event.getEntityLiving() instanceof EntityPlayer) + { + EntityPlayer player = (EntityPlayer) event.getEntityLiving(); + if (!player.world.isRemote) + tryToInitializeCharge(player); + } + } +} diff --git a/src/main/java/com/somebody/idlframewok/item/skills/arknights/ItemSkillTrueSL.java b/src/main/java/com/somebody/idlframewok/item/skills/arknights/ItemSkillTrueSL.java new file mode 100644 index 0000000..9bb697f --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/item/skills/arknights/ItemSkillTrueSL.java @@ -0,0 +1,164 @@ +package com.somebody.idlframewok.item.skills.arknights; + +import java.util.List; +import java.util.UUID; + +import com.google.common.collect.HashMultimap; +import com.google.common.collect.Multimap; +import com.somebody.idlframewok.IdlFramework; +import com.somebody.idlframewok.util.CommonDef; +import com.somebody.idlframewok.util.CommonFunctions; +import com.somebody.idlframewok.util.EntityUtil; +import com.somebody.idlframewok.util.IDLGeneral; +import com.somebody.idlframewok.util.IDLSkillNBT; +import net.minecraft.client.resources.I18n; +import net.minecraft.client.util.ITooltipFlag; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.SharedMonsterAttributes; +import net.minecraft.entity.ai.attributes.AttributeModifier; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.EntityEquipmentSlot; +import net.minecraft.item.ItemStack; +import net.minecraft.util.DamageSource; +import net.minecraft.util.EnumParticleTypes; +import net.minecraft.util.math.Vec3d; +import net.minecraft.world.World; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +public class ItemSkillTrueSL extends ItemArknightsSkillBase { + + private UUID uuid = UUID.fromString("a7d91a0a-3922-4467-a114-f476ca4daf3e"); + private float range = 3.5f * CommonDef.METER_PER_BLOCK; + + private double defReduce = -0.7; + double[] atkPlus = {1.1, 1.15, 1.2, 1.25, 1.3, 1.35, 1.4, 1.6, 1.8, 2.0}; + + private int[] atkCount = {3,3,3,4,4,4,5,5,5,6}; + + public ItemSkillTrueSL(String name) { + super(name); + setRange(range,0); + offHandCast = true; + cannotMouseCast = true; + maxDialogues = 4; + maxLevel = 10; + + dura = new int[]{20, 21, 22, 23, 24, 25, 26, 27, 28, 30}; + max_charge = new int[]{90}; + //max_charge = new int[]{3}; + initPower = new int[]{50, 50, 50, 55, 55, 55, 60, 65, 70, 75}; + showDuraDesc = true; + CommonFunctions.addToEventBus(this); + } + + + + @Override + public int getMaxDamage(ItemStack stack) { + return 100; + } + + public Multimap getAttributeModifiers(EntityEquipmentSlot equipmentSlot, ItemStack stack) + { + Multimap multimap = HashMultimap.create(); + boolean isOn = IDLSkillNBT.IsCasting(stack); + + if (isOn && equipmentSlot == EntityEquipmentSlot.OFFHAND) + { + int level = IDLSkillNBT.getLevel(stack) - 1; + //in arknights, the modifier is type 1, but it makes no sense for players. + multimap.put(SharedMonsterAttributes.ATTACK_DAMAGE.getName(), new AttributeModifier(uuid, "Truesilver Slash Modifier", atkPlus[level], 2)); + multimap.put(SharedMonsterAttributes.ARMOR.getName(), new AttributeModifier(uuid, "Truesilver Slash Modifier", defReduce, 2)); + } + + return multimap; + } + + @Override + public void onMouseFire(EntityPlayer player) { + ItemStack stack = player.getHeldItemOffhand(); + if (stack.getItem() == this) + { + if (IDLSkillNBT.IsCasting(stack) && player.getCooledAttackStrength(0f) >= 0.99f) + { + playerSlash(player, IDLSkillNBT.getLevel(stack) - 1); + } + } + } + + public void playerSlash(EntityPlayer player, int level) + { + World world = player.world; + if (world.isRemote) + { + float scaleFactor = 2f; + + //create particle + Vec3d forward = player.getForward().scale(scaleFactor); + + double fx = forward.x; + double fy = forward.y; + double fz = forward.z; + + Vec3d right = forward.crossProduct(new Vec3d(0,1,0)).normalize().scale(scaleFactor); + + double rx = right.x; + double ry = right.y; + double rz = right.z; + + int max = 3; + for (int z = 0; z <= max; z++) + { + for (int x = - (max - z); x <= max - z; x++) + { + world.spawnParticle(EnumParticleTypes.SWEEP_ATTACK, + player.posX + fx * z + rx * x, + player.posY + player.getEyeHeight() + fy * z + ry * x, + player.posZ + fz * z + rz * x, + player.getForward().x, + player.getForward().y, + player.getForward().z); + } + } + + }else { + int targetLeft = atkCount[level]; + + Vec3d basePos = player.getPositionVector(); + List entities = world.getEntitiesWithinAABB(EntityLivingBase.class, IDLGeneral.ServerAABB(basePos.addVector(-base_range, -base_range, -base_range), basePos.addVector(base_range, base_range, base_range))); + for (EntityLivingBase living: entities + ) { + if (EntityUtil.getAttitude(player, living) == EntityUtil.ATTITUDE.HATE) + { + boolean isForwad = player.getForward().dotProduct(living.getPositionVector().subtract(player.getPositionVector())) >= 0; + if (isForwad) + { + living.attackEntityFrom(DamageSource.causePlayerDamage(player), (float) EntityUtil.getAttack(player)); + targetLeft--; + if (targetLeft <= 0) + { + break; + } + } + else { + IdlFramework.Log("%s is not in front"); + } + } + } + } + } + + @SideOnly(Side.CLIENT) + public String getMainDesc(ItemStack stack, World world, List tooltip, ITooltipFlag flag) + { + String key = stack.getUnlocalizedName() + ".desc"; + if (I18n.hasKey(key)) + { + int level = IDLSkillNBT.getLevel(stack) - 1; + String mainDesc = I18n.format(key, (int)(defReduce * 100f) , (int)(atkPlus[level] * 100f), atkCount[level]); + return mainDesc; + } + return ""; + } +} diff --git a/src/main/java/com/somebody/idlframewok/item/skills/arrowrain/ItemSkillArrowRainBase.java b/src/main/java/com/somebody/idlframewok/item/skills/arrowrain/ItemSkillArrowRainBase.java new file mode 100644 index 0000000..114e19a --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/item/skills/arrowrain/ItemSkillArrowRainBase.java @@ -0,0 +1,75 @@ +package com.somebody.idlframewok.item.skills.arrowrain; + +import com.somebody.idlframewok.item.skills.ItemSkillBase; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.SharedMonsterAttributes; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.projectile.EntityArrow; +import net.minecraft.entity.projectile.EntityTippedArrow; +import net.minecraft.init.SoundEvents; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ActionResult; +import net.minecraft.util.EnumActionResult; +import net.minecraft.util.EnumHand; +import net.minecraft.util.math.MathHelper; +import net.minecraft.world.World; + +public class ItemSkillArrowRainBase extends ItemSkillBase { + public float KBPower = 1f; + public boolean useSmall = true; + public ItemSkillArrowRainBase(String name) { + super(name); + } + + public ItemSkillArrowRainBase setIsSmallFireBall(boolean val) + { + useSmall = val; + return this; + } + + @Override + public ActionResult onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) { + ItemStack stack = playerIn.getHeldItem(handIn); + if (isStackReady(playerIn, stack)) + { + if (!worldIn.isRemote) + { + //doRangedAttack(playerIn); + playerIn.swingArm(handIn); + activateCoolDown(playerIn, stack); + }else { + playerIn.playSound(SoundEvents.ENTITY_FIREWORK_LARGE_BLAST, 1f, 1f); + } + + return new ActionResult<>(EnumActionResult.SUCCESS, playerIn.getHeldItem(handIn)); + } + + return new ActionResult<>(EnumActionResult.FAIL, playerIn.getHeldItem(handIn)); + } + + protected EntityArrow getArrow(float p_190726_1_, EntityLivingBase shooter) + { + EntityTippedArrow entitytippedarrow = new EntityTippedArrow(shooter.world, shooter); + entitytippedarrow.setEnchantmentEffectsFromEntity(shooter, p_190726_1_); + return entitytippedarrow; + } + + public void attackEntityWithRangedAttack(EntityLivingBase target, float distanceFactor, EntityLivingBase shooter) { + //EntityMoroonBullet entityArrow = new EntityMoroonBullet(world, new ProjectileArgs((float) this.getEntityAttribute(ATTACK_DAMAGE).getAttributeValue())); + EntityArrow entityArrow = getArrow(distanceFactor, shooter); + double d0 = target.posY + (double)target.getEyeHeight() - 1.100000023841858D; + double d1 = target.posX - shooter.posX; + double d2 = d0 - entityArrow.posY; + double d3 = target.posZ - shooter.posZ; + float f = MathHelper.sqrt(d1 * d1 + d3 * d3) * 0.2F; + entityArrow.shoot(d1, d2 + (double)f, d3, 1.6F, 12.0F); + double damage = shooter.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).getAttributeValue(); + if (target.isSneaking()) + { + damage /= 5f; + } + entityArrow.setDamage(shooter.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).getAttributeValue()); + shooter.playSound(SoundEvents.ENTITY_SKELETON_SHOOT, 1.0F, 1.0F / (shooter.getRNG().nextFloat() * 0.4F + 0.8F)); + shooter.world.spawnEntity(entityArrow); + } +} diff --git a/src/main/java/com/somebody/idlframewok/item/skills/martial/BuffTuple.java b/src/main/java/com/somebody/idlframewok/item/skills/martial/BuffTuple.java new file mode 100644 index 0000000..122249e --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/item/skills/martial/BuffTuple.java @@ -0,0 +1,12 @@ +package com.somebody.idlframewok.item.skills.martial; + +public class BuffTuple +{ + public int tick; + public int power; + + public BuffTuple(int power, int tick) { + this.tick = tick; + this.power = power; + } +} diff --git a/src/main/java/com/somebody/idlframewok/item/skills/martial/ItemSkillGuaPalm.java b/src/main/java/com/somebody/idlframewok/item/skills/martial/ItemSkillGuaPalm.java new file mode 100644 index 0000000..b645349 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/item/skills/martial/ItemSkillGuaPalm.java @@ -0,0 +1,211 @@ +package com.somebody.idlframewok.item.skills.martial; + +import java.util.List; + +import com.somebody.idlframewok.item.IGuaEnhance; +import com.somebody.idlframewok.item.skills.ItemSkillBase; +import com.somebody.idlframewok.util.CommonDef; +import com.somebody.idlframewok.util.IDLSkillNBT; +import com.somebody.idlframewok.util.Reference; +import net.minecraft.client.resources.I18n; +import net.minecraft.client.util.ITooltipFlag; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.effect.EntityLightningBolt; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.MobEffects; +import net.minecraft.item.ItemStack; +import net.minecraft.potion.PotionEffect; +import net.minecraft.util.DamageSource; +import net.minecraft.util.EntityDamageSource; +import net.minecraft.util.EnumHand; +import net.minecraft.world.World; +import net.minecraftforge.event.entity.living.LivingHurtEvent; +import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +@Mod.EventBusSubscriber(modid = Reference.MOD_ID) +public class ItemSkillGuaPalm extends ItemSkillMartialAttack implements IGuaEnhance { + public float earthModifier = 0.02f; + + public ItemSkillGuaPalm(String name) { + super(name); + maxLevel = 1; + setCD(2f,0); + showGuaSocketDesc = true; + shiftToShowDesc = true; + } + + @Override + public boolean itemInteractionForEntity(ItemStack stack, EntityPlayer playerIn, EntityLivingBase target, EnumHand handIn) { + if (isStackReady(playerIn, stack)) + { + OnHit(stack, playerIn, target, handIn); + if (!playerIn.world.isRemote) + { + activateCoolDown(playerIn, stack); + } + return true; + } + return false; + } + + public DamageSource GetDamageSource(ItemStack stack, EntityPlayer playerIn, EntityLivingBase target, EnumHand handIn) + { + return new EntityDamageSource("martial", playerIn); + } + + @Override + public float getVal(ItemStack stack) { + return super.getVal(stack) + IDLSkillNBT.GetGuaEnhance(stack,5) + IDLSkillNBT.GetGuaEnhance(stack,1); + } + + //Gua + //Sky 7 + public float getCoolDown(ItemStack stack) { + float skyModifier = 0.1f; + float result = cool_down - IDLSkillNBT.GetGuaEnhance(stack, 7) * skyModifier; + return result > 0.1f ? result : 0.1f; + } + + //Earth 0 + @SubscribeEvent + public static void onCreatureHurt(LivingHurtEvent evt) { + + if (evt.isCanceled()) + { + return; + } + + World world = evt.getEntity().getEntityWorld(); + if (!world.isRemote) { + EntityLivingBase hurtOne = evt.getEntityLiving(); + + if (hurtOne instanceof EntityPlayer) { + EntityPlayer player = (EntityPlayer) hurtOne; + ItemStack stack = player.getHeldItemMainhand(); + if (stack.getItem() instanceof ItemSkillGuaPalm) + { + ItemSkillGuaPalm palm = (ItemSkillGuaPalm) stack.getItem(); + float dmg = evt.getAmount(); + //IdlFramework.Log("Damage reduct: %f -> %f", dmg, (1f - GetGuaEnhance(stack,0) * palm.earthModifier) * dmg); + evt.setAmount((1f - IDLSkillNBT.GetGuaEnhance(stack,0) * palm.earthModifier) * dmg); + } + } + } + } + + float windModifier = 0.1f; + //6 wind + public float getKBPower(ItemStack stack) + { + return 0.4f + windModifier * IDLSkillNBT.GetGuaEnhance(stack, 6); + } + + public void OnHitBasic(ItemStack stack, EntityPlayer playerIn, EntityLivingBase target, EnumHand handIn) + { + if (!playerIn.world.isRemote) { + float dmg = 0; + int fire = IDLSkillNBT.GetGuaEnhance(stack, 5); + int thunder = IDLSkillNBT.GetGuaEnhance(stack, 1); + dmg = fire + (target.isWet() ? thunder * 2 : thunder); + + if (target.attackEntityFrom(GetDamageSource(stack, playerIn, target, handIn), dmg)) + { + //wind + target.knockBack(playerIn, getKBPower(stack), (playerIn.posX - target.posX), (playerIn.posZ - target.posZ)); + + //fire + target.setFire(fire); + + //thunder + if (thunder >= 8) + { + playerIn.world.addWeatherEffect(new EntityLightningBolt(playerIn.world, target.posX, target.posY, target.posZ, false)); + } + + playerIn.swingArm(handIn); + if (interrupts) { + if (target instanceof EntityPlayer) + { + EntityPlayer player = (EntityPlayer) target; + ItemStack inHand = player.getHeldItemMainhand(); + if (inHand.getItem() != null && inHand.getItem() instanceof ItemSkillBase) + { + ItemSkillBase.activateCoolDown(player, inHand); + } + } + } + } + + } + } + + public void OnHitExtra(ItemStack stack, EntityPlayer playerIn, EntityLivingBase target, EnumHand handIn) + { + int mountain = IDLSkillNBT.GetGuaEnhance(stack, 4); + int water = IDLSkillNBT.GetGuaEnhance(stack, 2); + int lake = IDLSkillNBT.GetGuaEnhance(stack, 3); + + if (mountain > 0) + { + target.addPotionEffect(new PotionEffect(MobEffects.SLOWNESS, CommonDef.TICK_PER_SECOND * mountain * 2, mountain / 4)); + } + + if (water > 0) + { + target.addPotionEffect(new PotionEffect(MobEffects.WEAKNESS, CommonDef.TICK_PER_SECOND * water * 2, water / 4)); + target.extinguish(); + } + + if (lake > 0) + { + target.heal(lake); + playerIn.heal(lake); + } + } + + @Override + public boolean acceptGuaIndex(int index) { + return true; + } + + public BuffTuple GetWaterBuff(ItemStack stack) + { + int water = IDLSkillNBT.GetGuaEnhance(stack, 2); + return new BuffTuple(water / 4, CommonDef.TICK_PER_SECOND * water * 2); + } + + public BuffTuple GetMountainBuff(ItemStack stack) + { + int gua = IDLSkillNBT.GetGuaEnhance(stack, 4); + return new BuffTuple(gua / 4, CommonDef.TICK_PER_SECOND * gua * 2); + } + + @SideOnly(Side.CLIENT) + public String getMainDesc(ItemStack stack, World world, List tooltip, ITooltipFlag flag) + { + //todo:highlight while upgrading + String key = stack.getUnlocalizedName() + ".desc"; + if (I18n.hasKey(key)) + { + BuffTuple mountain = GetMountainBuff(stack); + BuffTuple water = GetWaterBuff(stack); + int fire = IDLSkillNBT.GetGuaEnhance(stack, 5); + + + return I18n.format(stack.getUnlocalizedName() + ".desc", + (IDLSkillNBT.GetGuaEnhance(stack, 0) * earthModifier * 100f), + IDLSkillNBT.GetGuaEnhance(stack, 1), + water.power + 1, (water.tick / CommonDef.TICK_PER_SECOND), + IDLSkillNBT.GetGuaEnhance(stack, 3), + mountain.power + 1, (mountain.tick / CommonDef.TICK_PER_SECOND), + fire, fire, + IDLSkillNBT.GetGuaEnhance(stack, 6) + //GetGuaEnhance(stack, 7) + ); + } + return ""; + } +} diff --git a/src/main/java/com/somebody/idlframewok/item/skills/martial/ItemSkillMartialAttack.java b/src/main/java/com/somebody/idlframewok/item/skills/martial/ItemSkillMartialAttack.java new file mode 100644 index 0000000..8fd4a28 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/item/skills/martial/ItemSkillMartialAttack.java @@ -0,0 +1,106 @@ +package com.somebody.idlframewok.item.skills.martial; + +import com.somebody.idlframewok.item.skills.ItemSkillBase; +import com.somebody.idlframewok.util.IDLSkillNBT; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.SoundEvents; +import net.minecraft.item.ItemStack; +import net.minecraft.util.DamageSource; +import net.minecraft.util.EntityDamageSource; +import net.minecraft.util.EnumHand; + +public class ItemSkillMartialAttack extends ItemSkillBase { + public float KBPowerBase = 0.1f; + public float KBPowerPerLevel = 0.1f; + + public boolean interrupts = true; + public boolean isSlam = false; + + public float getKBPower(ItemStack stack) + { + return (IDLSkillNBT.getLevel(stack) - 1) * KBPowerPerLevel + KBPowerBase; + } + + public ItemSkillMartialAttack setKB(float val, float val_per_level) + { + KBPowerBase = val; + this.KBPowerPerLevel = val_per_level; + return this; + } + + public ItemSkillMartialAttack setIsSlam(boolean slam) + { + this.isSlam = slam; + return this; + } + + + public ItemSkillMartialAttack(String name) { + super(name); + cool_down = 1f; + basic_val = 1f; + val_per_level = 1f; + isMartial = true; + } + + public void OnHit(ItemStack stack, EntityPlayer playerIn, EntityLivingBase target, EnumHand handIn) + { + OnHitBasic(stack, playerIn, target, handIn); + OnHitSound(stack, playerIn, target, handIn); + OnHitExtra(stack, playerIn, target, handIn); + } + + public void OnHitBasic(ItemStack stack, EntityPlayer playerIn, EntityLivingBase target, EnumHand handIn) + { + if (!playerIn.world.isRemote) { + target.attackEntityFrom(GetDamageSource(stack, playerIn, target, handIn), getVal(stack)); + target.knockBack(playerIn, getKBPower(stack), (playerIn.posX - target.posX), (playerIn.posZ - target.posZ)); + playerIn.swingArm(handIn); + if (interrupts) { + if (target instanceof EntityPlayer) + { + EntityPlayer player = (EntityPlayer) target; + ItemStack inHand = player.getHeldItemMainhand(); + if (inHand.getItem() != null && inHand.getItem() instanceof ItemSkillBase) + { + ItemSkillBase.activateCoolDown(player, inHand); + } + } + } + } + } + + public void OnHitSound(ItemStack stack, EntityPlayer playerIn, EntityLivingBase target, EnumHand handIn) + { + target.playSound(SoundEvents.BLOCK_PISTON_EXTEND, 1f, 1f); + } + + public void OnHitExtra(ItemStack stack, EntityPlayer playerIn, EntityLivingBase target, EnumHand handIn) + { + + } + + @Override + public boolean itemInteractionForEntity(ItemStack stack, EntityPlayer playerIn, EntityLivingBase target, EnumHand handIn) { + if (isStackReady(playerIn, stack)) + { + OnHit(stack, playerIn, target, handIn); + if (!playerIn.world.isRemote) + { + activateCoolDown(playerIn, stack); + } + return true; + } + return false; + } + + public DamageSource GetDamageSource(ItemStack stack, EntityPlayer playerIn, EntityLivingBase target, EnumHand handIn) + { + if (isSlam) + { + return new EntityDamageSource("slam", playerIn); + } + return new EntityDamageSource("martial", playerIn); + } +} diff --git a/src/main/java/com/somebody/idlframewok/item/weapon/ItemEtherealSword.java b/src/main/java/com/somebody/idlframewok/item/weapon/ItemEtherealSword.java new file mode 100644 index 0000000..866f580 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/item/weapon/ItemEtherealSword.java @@ -0,0 +1,67 @@ +package com.somebody.idlframewok.item.weapon; + +import com.google.common.collect.HashMultimap; +import com.google.common.collect.Multimap; +import com.somebody.idlframewok.item.ItemSwordBase; +import net.minecraft.enchantment.Enchantment; +import net.minecraft.entity.SharedMonsterAttributes; +import net.minecraft.entity.ai.attributes.AttributeModifier; +import net.minecraft.inventory.EntityEquipmentSlot; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; + +public class ItemEtherealSword extends ItemSwordBase { + public ItemEtherealSword(String name, ToolMaterial material) { + super(name, material); + } + + @Override + public int getMaxDamage(ItemStack stack) { + return getEnchantmentTotalLevel(stack) * getDurabilityPerEnch(stack) + 100; + } + + public int getDurabilityPerEnch(ItemStack stack) + { + return 100; + } + + public float getDamagePerEnch(ItemStack stack) + { + return 1f; + } + + int getEnchantmentTotalLevel(ItemStack stack) + { + int result = 0; + NBTTagList nbttaglist = stack.getEnchantmentTagList(); + + for (int j = 0; j < nbttaglist.tagCount(); ++j) + { + NBTTagCompound nbttagcompound = nbttaglist.getCompoundTagAt(j); + int enchID = nbttagcompound.getShort("layer");//enchant ID + int lvl = nbttagcompound.getShort("lvl"); + Enchantment enchantment = Enchantment.getEnchantmentByID(enchID); + + if (enchantment != null) + { + result += lvl; + } + } + return result; + } + + public Multimap getAttributeModifiers(EntityEquipmentSlot equipmentSlot, ItemStack stack) + { + Multimap multimap = HashMultimap.create(); + + if (equipmentSlot == EntityEquipmentSlot.MAINHAND) + { + multimap.put(SharedMonsterAttributes.ATTACK_DAMAGE.getName(), new AttributeModifier(ATTACK_DAMAGE_MODIFIER, "Weapon modifier", 1f + getEnchantmentTotalLevel(stack) * getDamagePerEnch(stack), 0)); + multimap.put(SharedMonsterAttributes.ATTACK_SPEED.getName(), new AttributeModifier(ATTACK_SPEED_MODIFIER, "Weapon modifier", -2.4000000953674316D, 0)); + } + + return multimap; + } + +} diff --git a/src/main/java/com/somebody/idlframewok/item/weapon/ItemHealingGun.java b/src/main/java/com/somebody/idlframewok/item/weapon/ItemHealingGun.java new file mode 100644 index 0000000..446a259 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/item/weapon/ItemHealingGun.java @@ -0,0 +1,92 @@ +package com.somebody.idlframewok.item.weapon; + +import java.util.List; + +import com.somebody.idlframewok.item.ItemAdaptingBase; +import com.somebody.idlframewok.util.EntityUtil; +import com.somebody.idlframewok.util.IDLGeneral; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.init.SoundEvents; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumParticleTypes; +import net.minecraft.util.math.Vec3d; +import net.minecraft.world.World; + +public class ItemHealingGun extends ItemAdaptingBase { + public ItemHealingGun(String name) { + super(name); + setRangedWeapon(); + useable = true; + + base_cd = 10f; + base_power = 6f; + base_range = 3f; + } + + @Override + public int getMaxDamage(ItemStack stack) { + return 512; + } + + public void onCreatureStoppedUsing(ItemStack stack, World worldIn, EntityLivingBase entityLiving, int timeLeft) + { + //IdlFramework.Log("onCreatureStoppedUsing"); + Vec3d basePos = entityLiving.getPositionVector(); + float range = getRange(stack); + List entities = worldIn.getEntitiesWithinAABB(EntityLivingBase.class, IDLGeneral.ServerAABB(basePos.addVector(-range, -range, -range), basePos.addVector(range, range, range))); + //IdlFramework.Log("found %d targets", entities.size()); + for (EntityLivingBase target: entities + ) { + if (EntityUtil.getAttitude(entityLiving, target) == EntityUtil.ATTITUDE.FRIEND) + { + if (worldIn.isRemote) + { + EntityUtil.SpawnParticleAround(target, EnumParticleTypes.VILLAGER_HAPPY, 10); + }else { + target.heal(getPower(stack)); + } + } + } + + if (worldIn.isRemote) + { + //IdlFramework.Log("spawn particle!"); + spawnParticles(EnumParticleTypes.VILLAGER_HAPPY, worldIn, entityLiving); + } + + entityLiving.playSound(SoundEvents.ENTITY_SPLASH_POTION_BREAK, 1f, 0.8f); + } + + void spawnParticles(EnumParticleTypes particleType, World worldIn, EntityLivingBase center) + { + int count = 60; + float speedMagnitude = 1000f; + float maxAngle = 6.282f; + float deltaAngle = maxAngle/count; + + for (float angle = 0f; angle < maxAngle; angle += deltaAngle) + { + // float radius = center.getRNG().nextFloat() * speedMagnitude; + //IdlFramework.Log("spawn particle at %s, %s, %s", center.posX, center.posY, center.posZ); + center.world.spawnParticle(particleType, center.posX+Math.cos(angle), + center.getPositionEyes(0f).y, + center.posZ+Math.sin(angle), + Math.cos(angle) * speedMagnitude,0,Math.sin(angle) * speedMagnitude); + } + + +// Vec3d velocityShoot = Vec3d.ZERO; +// Vec3d velocitySide = Vec3d.ZERO; +// +// float theta = 0f; +// float accel = 0f; +// +// while(true) +// { +// //update +// Vec3d speed = velocityShoot.scale(Math.cos(theta)).add(velocitySide.scale(Math.sin(theta))); +// theta += accel; +// } + } + +} diff --git a/src/main/java/com/somebody/idlframewok/item/weapon/ItemPistolBase.java b/src/main/java/com/somebody/idlframewok/item/weapon/ItemPistolBase.java new file mode 100644 index 0000000..794ef07 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/item/weapon/ItemPistolBase.java @@ -0,0 +1,89 @@ +package com.somebody.idlframewok.item.weapon; + +import com.somebody.idlframewok.entity.projectiles.EntityIdlProjectile; +import com.somebody.idlframewok.entity.projectiles.ProjectileArgs; +import com.somebody.idlframewok.item.ItemAdaptingBase; +import net.minecraft.enchantment.Enchantment; +import net.minecraft.enchantment.EnchantmentHelper; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.init.Enchantments; +import net.minecraft.item.EnumAction; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; + +public class ItemPistolBase extends ItemAdaptingBase { + public ItemPistolBase(String name) { + super(name); + setRangedWeapon(); + useable = true; + base_cd = 1f; + } + + @Override + public int getMaxDamage(ItemStack stack) { + return 256; + } + + /** + * How long it takes to use or consume an item + */ + public int getMaxItemUseDuration(ItemStack stack) + { + return 72000; + } + + /** + * returns the action that specifies what animation to play when the items is being used + */ + public EnumAction getItemUseAction(ItemStack stack) + { + return EnumAction.BOW; + } + + public EntityIdlProjectile getBullet(ItemStack stack, World worldIn, EntityLivingBase entityLiving, int timeLeft) { + return new EntityIdlProjectile(worldIn, new ProjectileArgs(5f), entityLiving, + entityLiving.getLookVec().x * 10, + entityLiving.getLookVec().y * 10, + entityLiving.getLookVec().z * 10); + } + + @Override + public boolean canApplyAtEnchantingTable(ItemStack stack, Enchantment enchantment) { + if (enchantment == Enchantments.PUNCH || enchantment == Enchantments.INFINITY) + { + return false; + } + + if (enchantment == Enchantments.POWER || enchantment == Enchantments.UNBREAKING) + { + return true; + } + + return super.canApplyAtEnchantingTable(stack, enchantment); + } + + /** + * Called when the player stops using an Item (stops holding the right mouse button). + */ + public void onCreatureStoppedUsing(ItemStack stack, World worldIn, EntityLivingBase entityLiving, int timeLeft) + { + if (!worldIn.isRemote) + { + EntityIdlProjectile bullet = getBullet(stack, worldIn, entityLiving, timeLeft); + + int powerEnchant = EnchantmentHelper.getEnchantmentLevel(Enchantments.POWER, stack); + + if (powerEnchant > 0) + { + bullet.args.damage += (double)powerEnchant * 0.5D + 0.5D; + } + + if (EnchantmentHelper.getEnchantmentLevel(Enchantments.FLAME, stack) > 0) + { + bullet.setFire(100); + } + + worldIn.spawnEntity(bullet); + } + } +} diff --git a/src/main/java/com/somebody/idlframewok/item/weapon/ItemSmashShield.java b/src/main/java/com/somebody/idlframewok/item/weapon/ItemSmashShield.java new file mode 100644 index 0000000..f6746f2 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/item/weapon/ItemSmashShield.java @@ -0,0 +1,115 @@ +package com.somebody.idlframewok.item.weapon; + +import javax.annotation.Nullable; + +import com.google.common.collect.HashMultimap; +import com.google.common.collect.Multimap; +import com.somebody.idlframewok.item.ItemAdaptingBase; +import net.minecraft.enchantment.Enchantment; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.SharedMonsterAttributes; +import net.minecraft.entity.ai.attributes.AttributeModifier; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Enchantments; +import net.minecraft.inventory.EntityEquipmentSlot; +import net.minecraft.item.EnumAction; +import net.minecraft.item.IItemPropertyGetter; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ActionResult; +import net.minecraft.util.EnumActionResult; +import net.minecraft.util.EnumHand; +import net.minecraft.util.ResourceLocation; +import net.minecraft.world.World; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +public class ItemSmashShield extends ItemAdaptingBase { + public ItemSmashShield(String name) { + super(name); + setRangedWeapon(); + useable = true; + this.addPropertyOverride(new ResourceLocation("blocking"), new IItemPropertyGetter() + { + @SideOnly(Side.CLIENT) + public float apply(ItemStack stack, @Nullable World worldIn, @Nullable EntityLivingBase entityIn) + { + return entityIn != null && entityIn.isHandActive() && entityIn.getActiveItemStack() == stack ? 1.0F : 0.0F; + } + }); + } + + public boolean isShield(ItemStack stack, @Nullable EntityLivingBase entity) + { + return true; + } + + /** + * returns the action that specifies what animation to play when the items is being used + */ + public EnumAction getItemUseAction(ItemStack stack) + { + return EnumAction.BLOCK; + } + + /** + * How long it takes to use or consume an item + */ + public int getMaxItemUseDuration(ItemStack stack) + { + return 72000; + } + + /** + * Called when the equipped item is right clicked. + */ + public ActionResult onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) + { + ItemStack itemstack = playerIn.getHeldItem(handIn); + playerIn.setActiveHand(handIn); + return new ActionResult<>(EnumActionResult.SUCCESS, itemstack); + } + + @Override + public void onPlayerStoppedUsing(ItemStack stack, World worldIn, EntityLivingBase entityLiving, int timeLeft) { + + } + + @Override + public int getMaxDamage(ItemStack stack) { + return 512; + } + + @Override + public boolean canApplyAtEnchantingTable(ItemStack stack, Enchantment enchantment) { + if (enchantment == Enchantments.PUNCH || enchantment == Enchantments.INFINITY) + { + return false; + } + + if (enchantment == Enchantments.POWER || enchantment == Enchantments.UNBREAKING) + { + return true; + } + + return super.canApplyAtEnchantingTable(stack, enchantment); + } + + public Multimap getAttributeModifiers(EntityEquipmentSlot equipmentSlot, ItemStack stack) + { + Multimap multimap = HashMultimap.create(); + + if (equipmentSlot == EntityEquipmentSlot.OFFHAND ) + { + multimap.put(SharedMonsterAttributes.ARMOR.getName(), new AttributeModifier(OFF_HAND_MODIFIER, "Weapon modifier", (double)getPower(stack), 0)); + } + + if (equipmentSlot == EntityEquipmentSlot.MAINHAND) + { + multimap.put(SharedMonsterAttributes.ARMOR.getName(), new AttributeModifier(MAIN_HAND_MODIFIER, "Weapon modifier", (double)getPower(stack), 0)); + multimap.put(SharedMonsterAttributes.ATTACK_DAMAGE.getName(), new AttributeModifier(MAIN_HAND_MODIFIER, "Weapon modifier", (double)getPower(stack) / 2f, 0)); + } + + return multimap; + } + +} diff --git a/src/main/java/com/somebody/idlframewok/keys/KeyboardManager.java b/src/main/java/com/somebody/idlframewok/keys/KeyboardManager.java new file mode 100644 index 0000000..cd77b51 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/keys/KeyboardManager.java @@ -0,0 +1,61 @@ +package com.somebody.idlframewok.keys; + +import com.somebody.idlframewok.IdlFramework; +import com.somebody.idlframewok.proxy.ClientProxy; +import net.minecraft.client.settings.KeyBinding; +import net.minecraftforge.fml.client.registry.ClientRegistry; +import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.common.gameevent.InputEvent; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +//@SideOnly(Side.CLIENT) +@Mod.EventBusSubscriber +public class KeyboardManager { + //ref: https://harbinger.covertdragon.team/chapter-18/keyboard.html + + public static void init() { + for (KeyBinding key: + ClientProxy.KEY_BINDINGS) { + ClientRegistry.registerKeyBinding(key); + } + IdlFramework.Log("Registered %d keys", ClientProxy.KEY_BINDINGS.size()); + } + + @SideOnly(Side.CLIENT) + @SubscribeEvent + public static void onKeyPressed(InputEvent.KeyInputEvent event) { +// if (ClientProxy.CAST_OFFHAND.isPressed() || ClientProxy.CAST_MAINHAND.isPressed()) { +// +// Minecraft mc = Minecraft.getMinecraft(); +// EntityPlayerSP player = mc.player; +// if(player == null) return; +// if(mc.isGamePaused()) return; +// if(!mc.inGameHasFocus) return; +// if(mc.currentScreen != null) return; +// +// EnumHand hand = ClientProxy.CAST_OFFHAND.isKeyDown() ? EnumHand.MAIN_HAND : EnumHand.OFF_HAND; +// IdlFramework.Log("pressed key cast :" + hand); +// +// ItemStack item = player.getHeldItem(hand); +// if(item.isEmpty()) +// { +// IdlFramework.LogWarning("Trying to cast an empty item"); +// } +// +// if(item.getItem() instanceof ItemSkillBase) +// { +// ItemSkillBase skill = (ItemSkillBase) item.getItem(); +// if (skill.canCast(player.world, player, hand)) +// { +// NetworkHandler.SendToServer(new PacketTest(hand.ordinal())); +// } +// +// } +// +// //mc.playerController.updateController(); +// // NetworkManager.channel.sendToServer(new C2SSpecialAction((byte) 1)); +// } + } +} diff --git a/src/main/java/com/somebody/idlframewok/keys/ModKeyBinding.java b/src/main/java/com/somebody/idlframewok/keys/ModKeyBinding.java new file mode 100644 index 0000000..b3856de --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/keys/ModKeyBinding.java @@ -0,0 +1,15 @@ +package com.somebody.idlframewok.keys; + +import com.somebody.idlframewok.IdlFramework; +import com.somebody.idlframewok.proxy.ClientProxy; +import net.minecraft.client.settings.KeyBinding; +import net.minecraftforge.client.settings.IKeyConflictContext; +import net.minecraftforge.client.settings.KeyModifier; + +//@SideOnly(Side.CLIENT) +public class ModKeyBinding extends KeyBinding { + public ModKeyBinding(String description, IKeyConflictContext keyConflictContext, KeyModifier keyModifier, int keyCode, String category) { + super(String.format("key.%s.%s", IdlFramework.MODID, description), keyConflictContext, keyModifier, keyCode, category); + ClientProxy.KEY_BINDINGS.add(this); + } +} diff --git a/src/main/java/com/somebody/idlframewok/meta/MetaUtil.java b/src/main/java/com/somebody/idlframewok/meta/MetaUtil.java new file mode 100644 index 0000000..a514f42 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/meta/MetaUtil.java @@ -0,0 +1,46 @@ +package com.somebody.idlframewok.meta; + +import net.minecraftforge.fml.common.Loader; + +public class MetaUtil { + public static boolean isIDLLoaded = false; + public static boolean isIRRLoaded = false; + public static boolean isLoaded_TiC = false; + public static boolean isLoaded_Slashblade = false; + public static boolean isLoaded_Botania = false; + public static boolean isLoaded_DWeapon = false; + public static boolean isLoaded_AOA3 = false; + public static boolean isLoaded_GC = false; + public static boolean isLoaded_Taoism = false; + public static boolean isLoaded_GOG = false; + + //extra difficulty + public static int HARD_AOA3 = 5; + public static int HARD_GOG = 4; + + //static int modListDifficulty = 0; + static int modListExtraDifficulty = 0; + + public static int getModListExtraDifficulty() { + return modListExtraDifficulty; + } + + public static void CalcModListDifficulty() + { + //modListDifficulty = CommonFunctions.GetModCount(); + if (isLoaded_AOA3) + { + modListExtraDifficulty+=HARD_AOA3; + } + + if(isLoaded_GOG) + { + modListExtraDifficulty+=HARD_GOG; + } + } + + public static int GetModCount() + { + return Loader.instance().getActiveModList().size(); + } +} diff --git a/src/main/java/com/somebody/idlframewok/network/NetworkHandler.java b/src/main/java/com/somebody/idlframewok/network/NetworkHandler.java new file mode 100644 index 0000000..45fad48 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/network/NetworkHandler.java @@ -0,0 +1,32 @@ +package com.somebody.idlframewok.network; + +import com.somebody.idlframewok.IdlFramework; +import com.somebody.idlframewok.network.protocols.PacketTest; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.fml.common.network.NetworkRegistry; +import net.minecraftforge.fml.common.network.simpleimpl.IMessage; +import net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper; +import net.minecraftforge.fml.relauncher.Side; + +public class NetworkHandler { + public static final ResourceLocation MSG_RESOURCE = new ResourceLocation(IdlFramework.MODID, "msg"); + + public static final SimpleNetworkWrapper channel = NetworkRegistry.INSTANCE.newSimpleChannel(IdlFramework.MODID); + + static int id = 0; + public static void init() + { + //C2S + channel.registerMessage(PacketTest.Handler.class, PacketTest.class, id++, Side.SERVER); + //just call SendToServer + + + //S2C + //PacketUtil.network.sendTo(new PacketRevenge(cap.isRevengeActive()), (EntityPlayerMP)e.player); + } + + public static void SendToServer(IMessage packet) + { + channel.sendToServer(packet); + } +} diff --git a/src/main/java/com/somebody/idlframewok/network/protocols/PacketTest.java b/src/main/java/com/somebody/idlframewok/network/protocols/PacketTest.java new file mode 100644 index 0000000..7b45f52 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/network/protocols/PacketTest.java @@ -0,0 +1,68 @@ +package com.somebody.idlframewok.network.protocols; + +import com.somebody.idlframewok.IdlFramework; +import com.somebody.idlframewok.item.skills.ItemSkillBase; +import io.netty.buffer.ByteBuf; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumHand; +import net.minecraftforge.fml.common.network.simpleimpl.IMessage; +import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; +import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; + +public class PacketTest implements IMessage { + + int testVal; + + public PacketTest() { + } + + + public PacketTest(int testVal) { + this.testVal = testVal; + } + + @Override + public void fromBytes(ByteBuf buf) { + + testVal = buf.readInt(); + } + + @Override + public void toBytes(ByteBuf buf) { + buf.writeInt(testVal); + // these methods may also be of use for your code: + // for Itemstacks - ByteBufUtils.writeItemStack() + // for NBT tags ByteBufUtils.writeTag(); + // for Strings: ByteBufUtils.writeUTF8String(); + + } + + public static class Handler implements IMessageHandler { + public IMessage onMessage(final PacketTest msg, final MessageContext ctx) { + EntityPlayerMP player = ctx.getServerHandler().player; + + player.getServerWorld().addScheduledTask(() -> { + IdlFramework.Log("Packet:%d", msg.testVal); + + EnumHand hand = EnumHand.values()[msg.testVal]; + + ItemStack item = player.getHeldItem(hand); + if(item.isEmpty()) + { + IdlFramework.LogWarning("Trying to cast an empty item"); + } + + if(item.getItem() instanceof ItemSkillBase) + { + ItemSkillBase skill = (ItemSkillBase) item.getItem(); + if (skill.canCast(player.world, player, hand)) + { + skill.tryCast(player.world, player, hand); + } + } + }); + return null; + } + } +} diff --git a/src/main/java/com/somebody/idlframewok/potion/EffectTuple.java b/src/main/java/com/somebody/idlframewok/potion/EffectTuple.java new file mode 100644 index 0000000..3fa635d --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/potion/EffectTuple.java @@ -0,0 +1,37 @@ +package com.somebody.idlframewok.potion; + +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.init.MobEffects; +import net.minecraft.potion.Potion; +import net.minecraft.potion.PotionEffect; + +public class EffectTuple +{ + public float chance = 0.1f; + public Potion potion = MobEffects.ABSORPTION; + public int length = 200; + + public EffectTuple(float chance, Potion potion) { + this(chance, potion, 200); + } + + public EffectTuple(float chance, Potion potion, int length) { + this.chance = chance; + this.potion = potion; + this.length = length; + } + + public void AttemptBuffWithLevel(EntityLivingBase livingBase, int level) + { + if (livingBase.getRNG().nextFloat() < chance) + { + ApplyBuffWithLevel(livingBase, level); + } + } + + public void ApplyBuffWithLevel(EntityLivingBase livingBase, int level) + { + livingBase.addPotionEffect(new PotionEffect(potion, length, level, false, false)); + } + +} diff --git a/src/main/java/com/somebody/idlframewok/potion/ModPotions.java b/src/main/java/com/somebody/idlframewok/potion/ModPotions.java new file mode 100644 index 0000000..86d92c2 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/potion/ModPotions.java @@ -0,0 +1,46 @@ +package com.somebody.idlframewok.potion; + +import java.util.ArrayList; +import java.util.List; +import javax.annotation.Nullable; + +import com.somebody.idlframewok.IdlFramework; +import com.somebody.idlframewok.util.Reference; +import net.minecraft.potion.Potion; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.event.RegistryEvent; +import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; + +@Mod.EventBusSubscriber(modid = Reference.MOD_ID) +public class ModPotions { + + public static final List INSTANCES = new ArrayList(); + +// public static final PotionDeadly DEADLY = new PotionDeadly(false, 0x333333, "deadly", 0); +// public static final PotionZenHeart ZEN_HEART = new PotionZenHeart(false, 0xcccc00, "zen_heart", 1); + + @Nullable + private static Potion getRegisteredMobEffect(String id) + { + Potion potion = Potion.REGISTRY.getObject(new ResourceLocation(id)); + + if (potion == null) + { + throw new IllegalStateException("Invalid MobEffect requested: " + id); + } + else + { + return potion; + } + } + + @SubscribeEvent + public static void registerPotions(RegistryEvent.Register evt) + { + //VIRUS_ONE.tuples.add(new EffectTuple(0.2f, MobEffects.NAUSEA, 100)); + + evt.getRegistry().registerAll(INSTANCES.toArray(new Potion[0])); + IdlFramework.LogWarning("registered %d potion", INSTANCES.size()); + } +} diff --git a/src/main/java/com/somebody/idlframewok/potion/PotionEventHandler.java b/src/main/java/com/somebody/idlframewok/potion/PotionEventHandler.java new file mode 100644 index 0000000..d46db6d --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/potion/PotionEventHandler.java @@ -0,0 +1,245 @@ +package com.somebody.idlframewok.potion; + +import java.util.Collection; + +import com.somebody.idlframewok.potion.buff.BasePotion; +import com.somebody.idlframewok.util.Reference; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.potion.PotionEffect; +import net.minecraft.world.World; +import net.minecraftforge.event.entity.living.LivingHurtEvent; +import net.minecraftforge.event.entity.living.LivingKnockBackEvent; +import net.minecraftforge.event.entity.player.CriticalHitEvent; +import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.common.eventhandler.Event; +import net.minecraftforge.fml.common.eventhandler.EventPriority; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; + +@Mod.EventBusSubscriber(modid = Reference.MOD_ID) +public class PotionEventHandler { + + @SubscribeEvent(priority = EventPriority.HIGHEST) + public static void onCreatureHurt(LivingHurtEvent evt) { + World world = evt.getEntity().getEntityWorld(); + EntityLivingBase hurtOne = evt.getEntityLiving(); + +// if (hurtOne.getActivePotionEffect(INVINCIBLE) != null) +// { +// evt.setCanceled(true); +// return; +// } + + //Base Damage Reduction + Collection activePotionEffects = hurtOne.getActivePotionEffects(); + for (int i = 0; i < activePotionEffects.size(); i++) { + PotionEffect buff = (PotionEffect)activePotionEffects.toArray()[i]; + if (buff.getPotion() instanceof BasePotion) + { + BasePotion modBuff = (BasePotion)buff.getPotion(); + if (!world.isRemote) + { + float reduceRatio = modBuff.getDamageReductionMultiplier(buff.getAmplifier()); + evt.setAmount((1 - reduceRatio) * evt.getAmount()); + } + } + } + + Entity trueSource = evt.getSource().getTrueSource(); + if (trueSource instanceof EntityLivingBase){ + EntityLivingBase sourceCreature = (EntityLivingBase)trueSource; +// if (sourceCreature.isEntityUndead()) +// { +// PotionEffect curBuff = hurtOne.getActivePotionEffect(ZEN_HEART); +// if (curBuff != null) { +// if (!world.isRemote) { +// evt.setCanceled(true); +// } +// } +// } + + //Apply damage multiplier + Collection activePotionEffectsAttacker = sourceCreature.getActivePotionEffects(); + for (int i = 0; i < activePotionEffectsAttacker.size(); i++) { + PotionEffect buff = (PotionEffect)activePotionEffectsAttacker.toArray()[i]; + if (buff.getPotion() instanceof BasePotion) + { + BasePotion modBuff = (BasePotion)buff.getPotion(); + if (!world.isRemote) + { + evt.setAmount((1 + modBuff.getAttackMultiplier(buff.getAmplifier())) * evt.getAmount()); + } + } + } + + //Critical Judgement + if (!(trueSource instanceof EntityPlayer)) {//Players have their own critical judgement system. Now we add the non-player system. + float critRate = 0.1f; + boolean isCritical = false; + + //Critical chance buff + activePotionEffects = ((EntityLivingBase) trueSource).getActivePotionEffects(); + for (int i = 0; i < activePotionEffects.size(); i++) { + PotionEffect buff = (PotionEffect) activePotionEffects.toArray()[i]; + if (buff.getPotion() instanceof BasePotion) { + BasePotion modBuff = (BasePotion) buff.getPotion(); + + critRate += modBuff.getCritRate(buff.getAmplifier()); + } + } + + if (critRate > 0 && ((EntityLivingBase) trueSource).getRNG().nextFloat() < critRate) { + isCritical = true; + } + + //Critical damage multiplier buff + if (isCritical) { + float critDmg = 1.5f;//vanilla + + activePotionEffects = ((EntityLivingBase) trueSource).getActivePotionEffects(); + for (int i = 0; i < activePotionEffects.size(); i++) { + PotionEffect buff = (PotionEffect) activePotionEffects.toArray()[i]; + if (buff.getPotion() instanceof BasePotion) { + BasePotion modBuff = (BasePotion) buff.getPotion(); + + critDmg += modBuff.getCritDmgModifier(buff.getAmplifier()); + } + } + + evt.setAmount((critDmg) * evt.getAmount()); + //IdlFramework.Log(String.format("%s:isCrit = %s, x%s =%s, ", trueSource.getName(), isCritical, critDmg, evt.getAmount())); + } + //IdlFramework.Log(String.format("%s:isCrit = %s, x1f =%s, ", trueSource.getName(), isCritical, evt.getAmount())); + } + } + + if (evt.isCanceled()) + { + return; + } + + //slime erosion +// if (trueSource instanceof EntitySlime) +// { +// if (!world.isRemote) +// { +// hurtOne.addPotionEffect(new PotionEffect(ModPotions.EROSION, (int)(TICK_PER_SECOND * (evt.getAmount() + 1f)), (int)(evt.getAmount() / 10))); +// } +// } + + //onHit effect + for (int i = 0; i < activePotionEffects.size(); i++) { + PotionEffect buff = (PotionEffect)activePotionEffects.toArray()[i]; + if (buff.getPotion() instanceof BasePotion) + { + BasePotion modBuff = (BasePotion)buff.getPotion(); + if (world.isRemote) + { + modBuff.playOnHitEffect(hurtOne, evt.getAmount()); + } + } + } + } + + @SubscribeEvent(priority = EventPriority.HIGHEST) + public static void onCreatureKB(LivingKnockBackEvent evt) { + World world = evt.getEntity().getEntityWorld(); + EntityLivingBase hurtOne = evt.getEntityLiving(); + if (!world.isRemote) { + //Handle virtue and undead + Entity trueSource = evt.getOriginalAttacker(); + if (trueSource instanceof EntityLivingBase){ + EntityLivingBase sourceCreature = (EntityLivingBase)trueSource; + if (sourceCreature.isEntityUndead()) + { +// PotionEffect curBuff = hurtOne.getActivePotionEffect(ZEN_HEART); +// if (curBuff != null) { +// PotionEffect sourceBuff = sourceCreature.getActivePotionEffect(ZEN_HEART); +// if (sourceBuff == null) {//prevent dead loop +// sourceCreature.knockBack(hurtOne, evt.getStrength(), -evt.getRatioX(), -evt.getRatioZ()); +// } +// evt.setCanceled(true); +// } + } + } + + //KB Reduction + if (evt.isCanceled()) + { + return; + } + + Collection activePotionEffects = hurtOne.getActivePotionEffects(); + for (int i = 0; i < activePotionEffects.size(); i++) { + PotionEffect buff = (PotionEffect)activePotionEffects.toArray()[i]; + if (buff.getPotion() instanceof BasePotion) + { + BasePotion modBuff = (BasePotion)buff.getPotion(); + + float reduceRatio = modBuff.getKBResistanceMultiplier(buff.getAmplifier()); + evt.setStrength((1 - reduceRatio) * evt.getStrength()); + } + } + } else { + + } + } + + @SubscribeEvent(priority = EventPriority.HIGHEST) + public static void onPlayerCriticalJudge(CriticalHitEvent evt) { +// public class CriticalHitEvent extends PlayerEvent { +// private float damageModifier; +// private final float oldDamageModifier; +// private final Entity target; +// private final boolean vanillaCritical; +// } + EntityPlayer player = evt.getEntityPlayer(); + float critRate = 0f; + + Collection activePotionEffects = player.getActivePotionEffects(); + for (int i = 0; i < activePotionEffects.size(); i++) { + PotionEffect buff = (PotionEffect)activePotionEffects.toArray()[i]; + if (buff.getPotion() instanceof BasePotion) + { + BasePotion modBuff = (BasePotion)buff.getPotion(); + + critRate += modBuff.getCritRate(buff.getAmplifier()); + } + } + + if (evt.isVanillaCritical()) + { + if (critRate < 0 && player.getRNG().nextFloat() < (1 + critRate)) + { + evt.setResult(Event.Result.DENY); + } + }else { + if (critRate > 0 && player.getRNG().nextFloat() < (critRate)) + { + evt.setResult(Event.Result.ALLOW); + } + } + + boolean isCrit = evt.getResult() == Event.Result.ALLOW || (evt.getResult() == Event.Result.DEFAULT && evt.isVanillaCritical()); + //is critical + if (isCrit) + { + float critDmg = 0f; + + activePotionEffects = player.getActivePotionEffects(); + for (int i = 0; i < activePotionEffects.size(); i++) { + PotionEffect buff = (PotionEffect)activePotionEffects.toArray()[i]; + if (buff.getPotion() instanceof BasePotion) + { + BasePotion modBuff = (BasePotion)buff.getPotion(); + + critDmg += modBuff.getCritDmgModifier(buff.getAmplifier()); + } + } + + float originalModifier = evt.getDamageModifier(); + evt.setDamageModifier(originalModifier + critDmg); + } + } +} diff --git a/src/main/java/com/somebody/idlframewok/potion/buff/BasePotion.java b/src/main/java/com/somebody/idlframewok/potion/buff/BasePotion.java new file mode 100644 index 0000000..10e05a9 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/potion/buff/BasePotion.java @@ -0,0 +1,173 @@ +package com.somebody.idlframewok.potion.buff; + +import javax.annotation.Nonnull; + +import net.minecraft.entity.EntityLivingBase; + +public class BasePotion extends BaseSimplePotion { +// private static final ResourceLocation resource = new ResourceLocation("idlframewok","textures/misc/potions.png"); +// private final int iconIndex; + + protected float damageReductionRatioBase = 0.0f; + protected float damageReductionRatioPerLevel = 0.0f; + + protected float attackIncreaseRatioBase = 0.0f; + protected float attackIncreaseRatioPerLevel = 0.0f; + + protected float knockbackResistanceRatio = 0f; + protected float knockbackResistanceRatioPerLevel = 0f; + + protected float hpRecoverPerTick = 0f; + protected float hpRecoverPerLevel = 0f; + + protected float critRateBase = 0f; + protected float critRatePerLevel = 0f; + + //default = 1.5x + protected float critDmgRatioBase = 0f; + protected float critDmgRatioPerLevel = 0f; + + protected float resistancePerLevel = 0f;//for any buff + + + //----------------------------------------- + public BasePotion setHPRevocer(float begin, float upgrade) + { + hpRecoverPerTick = begin; + hpRecoverPerLevel = upgrade; + return this; + } + + public BasePotion setKBResistance(float begin, float upgrade) + { + knockbackResistanceRatio = begin; + knockbackResistanceRatioPerLevel = upgrade; + return this; + } + + public BasePotion setAttackRatio(float begin, float upgrade) + { + attackIncreaseRatioBase = begin; + attackIncreaseRatioPerLevel = upgrade; + return this; + } + + public BasePotion setProtectionRatio(float begin, float upgrade) + { + damageReductionRatioBase = begin; + damageReductionRatioPerLevel = upgrade; + return this; + } + + public BasePotion setCritRateRatio(float begin, float upgrade) + { + critRateBase = begin; + critRatePerLevel = upgrade; + return this; + } + + public BasePotion setCritDamageRatio(float begin, float upgrade) + { + critDmgRatioBase = begin; + critDmgRatioPerLevel = upgrade; + return this; + } + //---------------------------------------- + + public BasePotion(boolean isBadEffectIn, int liquidColorIn, String name, int icon) { + super(isBadEffectIn, liquidColorIn, name, icon); + } +// public BasePotion(boolean isBadEffectIn, int liquidColorIn, String name, int icon) { +// super(isBadEffectIn, liquidColorIn); +// setRegistryName(new ResourceLocation(Reference.MOD_ID, name)); +// setPotionName("idlframewok.potion." + name); +// iconIndex = icon; +// } + + @Override + public boolean isReady(int duration, int amplifier) { + return true; + } + + @Override + public void performEffect(@Nonnull EntityLivingBase living, int amplified) { + if (living.getHealth() < living.getMaxHealth()) + { + living.heal(hpRecoverPerTick + amplified * hpRecoverPerLevel); + } + } + + public void playOnHitEffect(EntityLivingBase entityLivingBase, float damage) + { + + } + + //damage = (1-x)damage + public float getDamageReductionMultiplier(int level) + { + //cant deal negative damage + return Math.min(1f, damageReductionRatioBase + level * damageReductionRatioPerLevel); + } + + public float getHealPerTick(int level) + { + //can be negative + return hpRecoverPerTick + level * hpRecoverPerLevel; + } + + //damage = (1+x)damage + public float getAttackMultiplier(int level) + { + return Math.max(-1f, attackIncreaseRatioBase + level * attackIncreaseRatioPerLevel); + } + + //KB = (1+x)KB + public float getKBResistanceMultiplier(int level) + { + return Math.max(-1f, knockbackResistanceRatio + level * knockbackResistanceRatioPerLevel); + } + + public float getCritRate(int level) + { + //can be negative + return critRateBase + level * critRatePerLevel; + } + + //need to plus 1.5 + public float getCritDmgModifier(int level) + { + //can be negative + return critDmgRatioBase + level * critDmgRatioPerLevel; + } + +// @SideOnly(Side.CLIENT) +// private void render(int x, int y, float alpha) { +// Minecraft.getMinecraft().renderEngine.bindTexture(resource); +// Tessellator tessellator = Tessellator.getInstance(); +// BufferBuilder buf = tessellator.getBuffer(); +// buf.begin(7, DefaultVertexFormats.POSITION_TEX); +// GlStateManager.color(1, 1, 1, alpha); +// +// int textureX = iconIndex % 8 * 18; +// int textureY = 198 + iconIndex / 8 * 18; +// +// buf.pos(x, y + 18, 0).tex(textureX * 0.00390625, (textureY + 18) * 0.00390625).endVertex(); +// buf.pos(x + 18, y + 18, 0).tex((textureX + 18) * 0.00390625, (textureY + 18) * 0.00390625).endVertex(); +// buf.pos(x + 18, y, 0).tex((textureX + 18) * 0.00390625, textureY * 0.00390625).endVertex(); +// buf.pos(x, y, 0).tex(textureX * 0.00390625, textureY * 0.00390625).endVertex(); +// +// tessellator.draw(); +// } +// +// @Override +// @SideOnly(Side.CLIENT) +// public void renderInventoryEffect(int x, int y, PotionEffect effect, Minecraft mc) { +// render(x + 6, y + 7, 1); +// } +// +// @Override +// @SideOnly(Side.CLIENT) +// public void renderHUDEffect(int x, int y, PotionEffect effect, Minecraft mc, float alpha) { +// render(x + 3, y + 3, alpha); +// } +} diff --git a/src/main/java/com/somebody/idlframewok/potion/buff/BaseSimplePotion.java b/src/main/java/com/somebody/idlframewok/potion/buff/BaseSimplePotion.java new file mode 100644 index 0000000..af3eeac --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/potion/buff/BaseSimplePotion.java @@ -0,0 +1,62 @@ +package com.somebody.idlframewok.potion.buff; + +import com.somebody.idlframewok.util.Reference; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.BufferBuilder; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.vertex.DefaultVertexFormats; +import net.minecraft.potion.Potion; +import net.minecraft.potion.PotionEffect; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +public class BaseSimplePotion extends Potion { + protected static final ResourceLocation resource = new ResourceLocation("idlframewok","textures/misc/potions.png"); + protected final int iconIndex; + +// if (!this.world.isRemote) +// { +// layer.getPotion().applyAttributesModifiersToEntity(this, this.getAttributeMap(), layer.getAmplifier()); +// } + + + public BaseSimplePotion(boolean isBadEffectIn, int liquidColorIn, String name, int icon) { + super(isBadEffectIn, liquidColorIn); + setRegistryName(new ResourceLocation(Reference.MOD_ID, name)); + setPotionName("idlframewok.potion." + name); + iconIndex = icon; + } + + @SideOnly(Side.CLIENT) + protected void render(int x, int y, float alpha) { + Minecraft.getMinecraft().renderEngine.bindTexture(resource); + Tessellator tessellator = Tessellator.getInstance(); + BufferBuilder buf = tessellator.getBuffer(); + buf.begin(7, DefaultVertexFormats.POSITION_TEX); + GlStateManager.color(1, 1, 1, alpha); + + int textureX = iconIndex % 14 * 18; + int textureY = 198 - iconIndex / 14 * 18; + + buf.pos(x, y + 18, 0).tex(textureX * 0.00390625, (textureY + 18) * 0.00390625).endVertex(); + buf.pos(x + 18, y + 18, 0).tex((textureX + 18) * 0.00390625, (textureY + 18) * 0.00390625).endVertex(); + buf.pos(x + 18, y, 0).tex((textureX + 18) * 0.00390625, textureY * 0.00390625).endVertex(); + buf.pos(x, y, 0).tex(textureX * 0.00390625, textureY * 0.00390625).endVertex(); + + tessellator.draw(); + } + + @Override + @SideOnly(Side.CLIENT) + public void renderInventoryEffect(int x, int y, PotionEffect effect, Minecraft mc) { + render(x + 6, y + 7, 1); + } + + @Override + @SideOnly(Side.CLIENT) + public void renderHUDEffect(int x, int y, PotionEffect effect, Minecraft mc, float alpha) { + render(x + 3, y + 3, alpha); + } +} diff --git a/src/main/java/com/somebody/idlframewok/potion/buff/PotionBlastResist.java b/src/main/java/com/somebody/idlframewok/potion/buff/PotionBlastResist.java new file mode 100644 index 0000000..8b0003c --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/potion/buff/PotionBlastResist.java @@ -0,0 +1,48 @@ +package com.somebody.idlframewok.potion.buff; + +import java.util.Collection; + +import com.somebody.idlframewok.util.Reference; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.potion.PotionEffect; +import net.minecraft.world.World; +import net.minecraftforge.event.entity.living.LivingHurtEvent; +import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; + +@Mod.EventBusSubscriber(modid = Reference.MOD_ID) +public class PotionBlastResist extends BasePotion { + public PotionBlastResist(boolean isBadEffectIn, int liquidColorIn, String name, int icon) { + super(isBadEffectIn, liquidColorIn, name, icon); + knockbackResistanceRatio = 0.1f; + knockbackResistanceRatioPerLevel = 0.1f; + + resistancePerLevel = 0.25f; + } + + @SubscribeEvent + public static void onCreatureHurt(LivingHurtEvent evt) { + World world = evt.getEntity().getEntityWorld(); + EntityLivingBase hurtOne = evt.getEntityLiving(); + + if (evt.isCanceled() || !evt.getSource().isExplosion()) + { + return; + } + + //Explosion Damage Reduction + Collection activePotionEffects = hurtOne.getActivePotionEffects(); + for (int i = 0; i < activePotionEffects.size(); i++) { + PotionEffect buff = (PotionEffect)activePotionEffects.toArray()[i]; + if (buff.getPotion() instanceof PotionBlastResist) + { + PotionBlastResist modBuff = (PotionBlastResist)buff.getPotion(); + if (!world.isRemote) + { + float reduceRatio = modBuff.resistancePerLevel * (buff.getAmplifier()); + evt.setAmount(Math.max(1 - reduceRatio, 0f) * evt.getAmount()); + } + } + } + } +} diff --git a/src/main/java/com/somebody/idlframewok/potion/buff/PotionDeadly.java b/src/main/java/com/somebody/idlframewok/potion/buff/PotionDeadly.java new file mode 100644 index 0000000..2e5b4ee --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/potion/buff/PotionDeadly.java @@ -0,0 +1,18 @@ +package com.somebody.idlframewok.potion.buff; + +import javax.annotation.Nonnull; + +import net.minecraft.entity.EntityLivingBase; + +public class PotionDeadly extends BasePotion { + + + public PotionDeadly(boolean isBadEffectIn, int liquidColorIn, String name, int icon) { + super(isBadEffectIn, liquidColorIn, name, icon); + } + + @Override + public void performEffect(@Nonnull EntityLivingBase living, int amplified) { + //do nothing + } +} diff --git a/src/main/java/com/somebody/idlframewok/potion/buff/PotionErosion.java b/src/main/java/com/somebody/idlframewok/potion/buff/PotionErosion.java new file mode 100644 index 0000000..2713ba0 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/potion/buff/PotionErosion.java @@ -0,0 +1,34 @@ +package com.somebody.idlframewok.potion.buff; + +import javax.annotation.Nonnull; + +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.inventory.EntityEquipmentSlot; +import net.minecraft.item.ItemStack; + +public class PotionErosion extends BaseSimplePotion { + public PotionErosion(boolean isBadEffectIn, int liquidColorIn, String name, int icon) { + super(isBadEffectIn, liquidColorIn, name, icon); + } + + @Override + public boolean isReady(int duration, int amplifier) { + return duration % 20 == 0; + } + + @Override + public void performEffect(@Nonnull EntityLivingBase living, int amplified) { + amplified ++;//buff starts from lv 0 + for (EntityEquipmentSlot slot: + EntityEquipmentSlot.values()) { + DamageItemInSlot(slot, living, amplified); + } + } + + public void DamageItemInSlot(EntityEquipmentSlot slot, EntityLivingBase livingBase, int amount) + { + ItemStack stack = livingBase.getItemStackFromSlot(slot); + stack.damageItem(amount, livingBase); + } + +} diff --git a/src/main/java/com/somebody/idlframewok/potion/buff/PotionInsidiousDisease.java b/src/main/java/com/somebody/idlframewok/potion/buff/PotionInsidiousDisease.java new file mode 100644 index 0000000..2bcfa89 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/potion/buff/PotionInsidiousDisease.java @@ -0,0 +1,51 @@ +package com.somebody.idlframewok.potion.buff; + +import java.util.ArrayList; +import java.util.List; +import javax.annotation.Nonnull; + +import com.somebody.idlframewok.IdlFramework; +import com.somebody.idlframewok.potion.EffectTuple; +import net.minecraft.entity.EntityLivingBase; + +public class PotionInsidiousDisease extends BasePotion { + + int baseCounter = 50; + + public List tuples = new ArrayList<>(); + public void AddTuple(EffectTuple tuple) + { + tuples.add(tuple); + } + + public PotionInsidiousDisease(boolean isBadEffectIn, int liquidColorIn, String name, int icon) { + super(isBadEffectIn, liquidColorIn, name, icon); + + } + + @Override + public boolean isReady(int duration, int amplifier) { + int k = baseCounter >> amplifier; + + if (k > 0) + { + return duration % k == 0; + } + else + { + return true; + } + } + + @Override + public void performEffect(@Nonnull EntityLivingBase living, int amplified) { + IdlFramework.Log("Perform"); + for (EffectTuple t: + tuples + ) { + t.AttemptBuffWithLevel(living, amplified); + } + } + + +} diff --git a/src/main/java/com/somebody/idlframewok/potion/buff/PotionMagicResist.java b/src/main/java/com/somebody/idlframewok/potion/buff/PotionMagicResist.java new file mode 100644 index 0000000..81470c1 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/potion/buff/PotionMagicResist.java @@ -0,0 +1,46 @@ +package com.somebody.idlframewok.potion.buff; + +import java.util.Collection; + +import com.somebody.idlframewok.util.Reference; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.potion.PotionEffect; +import net.minecraft.world.World; +import net.minecraftforge.event.entity.living.LivingHurtEvent; +import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; + +@Mod.EventBusSubscriber(modid = Reference.MOD_ID) +public class PotionMagicResist extends BasePotion { + public PotionMagicResist(boolean isBadEffectIn, int liquidColorIn, String name, int icon) { + super(isBadEffectIn, liquidColorIn, name, icon); + + resistancePerLevel = 0.25f; + } + + @SubscribeEvent + public static void onCreatureHurt(LivingHurtEvent evt) { + World world = evt.getEntity().getEntityWorld(); + EntityLivingBase hurtOne = evt.getEntityLiving(); + + if (evt.isCanceled() || !evt.getSource().isMagicDamage()) + { + return; + } + + //Magic Damage Reduction + Collection activePotionEffects = hurtOne.getActivePotionEffects(); + for (int i = 0; i < activePotionEffects.size(); i++) { + PotionEffect buff = (PotionEffect)activePotionEffects.toArray()[i]; + if (buff.getPotion() instanceof PotionMagicResist) + { + PotionMagicResist modBuff = (PotionMagicResist)buff.getPotion(); + if (!world.isRemote) + { + float reduceRatio = modBuff.resistancePerLevel * (buff.getAmplifier()); + evt.setAmount(Math.max(1 - reduceRatio, 0f) * evt.getAmount()); + } + } + } + } +} diff --git a/src/main/java/com/somebody/idlframewok/potion/buff/PotionUndying.java b/src/main/java/com/somebody/idlframewok/potion/buff/PotionUndying.java new file mode 100644 index 0000000..4cfe135 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/potion/buff/PotionUndying.java @@ -0,0 +1,36 @@ +package com.somebody.idlframewok.potion.buff; + +import com.somebody.idlframewok.util.Reference; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.world.World; +import net.minecraftforge.event.entity.living.LivingDeathEvent; +import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.common.eventhandler.EventPriority; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; + +@Mod.EventBusSubscriber(modid = Reference.MOD_ID) +public class PotionUndying extends BasePotion { + public PotionUndying(boolean isBadEffectIn, int liquidColorIn, String name, int icon) { + super(isBadEffectIn, liquidColorIn, name, icon); + + resistancePerLevel = 0.25f; + } + + @SubscribeEvent(priority = EventPriority.LOWEST) + public static void onCreatureDeath(LivingDeathEvent evt) { + World world = evt.getEntity().getEntityWorld(); + EntityLivingBase hurtOne = evt.getEntityLiving(); + + if (evt.isCanceled()) + { + return; + } + +// PotionEffect effect = hurtOne.getActivePotionEffect(ModPotions.UNDYING); +// if (effect != null) +// { +// evt.setCanceled(true); +// hurtOne.setHealth(hurtOne.getMaxHealth() / (ModPotions.UNDYING.resistancePerLevel * (effect.getAmplifier() + 1))); +// } + } +} diff --git a/src/main/java/com/somebody/idlframewok/potion/buff/PotionZenHeart.java b/src/main/java/com/somebody/idlframewok/potion/buff/PotionZenHeart.java new file mode 100644 index 0000000..1de608b --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/potion/buff/PotionZenHeart.java @@ -0,0 +1,7 @@ +package com.somebody.idlframewok.potion.buff; + +public class PotionZenHeart extends BasePotion { + public PotionZenHeart(boolean isBadEffectIn, int liquidColorIn, String name, int icon) { + super(isBadEffectIn, liquidColorIn, name, icon); + } +} diff --git a/src/main/java/com/somebody/idlframewok/proxy/ClientProxy.java b/src/main/java/com/somebody/idlframewok/proxy/ClientProxy.java new file mode 100644 index 0000000..3815857 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/proxy/ClientProxy.java @@ -0,0 +1,25 @@ +package com.somebody.idlframewok.proxy; + +import java.util.ArrayList; +import java.util.List; + +import net.minecraft.client.renderer.block.model.ModelResourceLocation; +import net.minecraft.client.settings.KeyBinding; +import net.minecraft.item.Item; +import net.minecraftforge.client.model.ModelLoader; + +public class ClientProxy extends ProxyBase { + public static final List KEY_BINDINGS = new ArrayList(); + //public static final KeyBinding CAST_MAINHAND = new ModKeyBinding("activate_skill_mainhand", KeyConflictContext.IN_GAME, KeyModifier.NONE, Keyboard.KEY_R, "key.category.idlframewok"); + //public static final KeyBinding CAST_OFFHAND = new ModKeyBinding("activate_skill_offhand", KeyConflictContext.IN_GAME, KeyModifier.NONE, Keyboard.KEY_GRAVE, "key.category.idlframewok"); + + public boolean isServer() + { + return false; + } + + public void registerItemRenderer(Item item, int meta, String id) + { + ModelLoader.setCustomModelResourceLocation(item, meta, new ModelResourceLocation(item.getRegistryName(), id)); + } +} diff --git a/src/main/java/com/somebody/idlframewok/proxy/ProxyBase.java b/src/main/java/com/somebody/idlframewok/proxy/ProxyBase.java new file mode 100644 index 0000000..0d604b8 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/proxy/ProxyBase.java @@ -0,0 +1,14 @@ +package com.somebody.idlframewok.proxy; + +import net.minecraft.item.Item; + +public class ProxyBase { + public boolean isServer() + { + return false; + } + + public void registerItemRenderer(Item item, int meta, String id) { + //Ignored + } +} diff --git a/src/main/java/com/somebody/idlframewok/proxy/ServerProxy.java b/src/main/java/com/somebody/idlframewok/proxy/ServerProxy.java new file mode 100644 index 0000000..646ee1b --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/proxy/ServerProxy.java @@ -0,0 +1,8 @@ +package com.somebody.idlframewok.proxy; + +public class ServerProxy extends ProxyBase { + public boolean isServer() + { + return true; + } +} diff --git a/src/main/java/com/somebody/idlframewok/recipe/special/BasicGua8.java b/src/main/java/com/somebody/idlframewok/recipe/special/BasicGua8.java new file mode 100644 index 0000000..a39da91 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/recipe/special/BasicGua8.java @@ -0,0 +1,94 @@ +package com.somebody.idlframewok.recipe.special; + +import javax.annotation.Nonnull; + +import com.somebody.idlframewok.item.misc.ItemBasicBinary; +import net.minecraft.inventory.InventoryCrafting; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.item.crafting.IRecipe; +import net.minecraft.world.World; +import net.minecraftforge.registries.IForgeRegistryEntry; + +public class BasicGua8 extends IForgeRegistryEntry.Impl implements IRecipe { + + @Override + public boolean isDynamic() { + return true; + } + + @Override + public boolean matches(@Nonnull InventoryCrafting var1, @Nonnull World var2) { + //must place the first sign in first line + int width = var1.getWidth(); + int usedCol = -1; + for (int i = 0; i < width; i++) { + ItemStack stack = var1.getStackInSlot(i); + if(!stack.isEmpty()) { + Item itemType = stack.getItem(); + if (itemType instanceof ItemBasicBinary) { + usedCol = i; + break; + }else + { + return false; + } + } + } + + if (usedCol < 0) { + return false; + } + + int itemCount = 0; + for(int i = 0; i < var1.getSizeInventory(); i++) { + ItemStack stack = var1.getStackInSlot(i); + if(!stack.isEmpty()) { + itemCount++; + if (i % width != usedCol) { + return false;//wrong shape + } + else { + Item itemType = stack.getItem(); + if (!(itemType instanceof ItemBasicBinary)) { + return false; + } + } + } + } + + return itemCount == 3; + } + + @Nonnull + @Override + public ItemStack getCraftingResult(@Nonnull InventoryCrafting var1) { + int guaValue = 0; + for(int i = 0; i < var1.getSizeInventory(); i++) { + ItemStack stack = var1.getStackInSlot(i); + Item itemType = stack.getItem(); + if(!stack.isEmpty() && (itemType instanceof ItemBasicBinary)) { + guaValue <<= 1; + guaValue += ((ItemBasicBinary) itemType).getValue(); + } + } + +// if (guaValue >= 0 && guaValue <= ModItems.GUA.length) { +// return new ItemStack(ModItems.GUA[guaValue]); +// } + + return ItemStack.EMPTY; + } + + @Override + public boolean canFit(int width, int height) { + return height >= 3; + } + + @Nonnull + @Override + public ItemStack getRecipeOutput() { + return ItemStack.EMPTY; + } +} + diff --git a/src/main/java/com/somebody/idlframewok/recipe/special/GobletDigBlockAssign.java b/src/main/java/com/somebody/idlframewok/recipe/special/GobletDigBlockAssign.java new file mode 100644 index 0000000..0a2a764 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/recipe/special/GobletDigBlockAssign.java @@ -0,0 +1,104 @@ +package com.somebody.idlframewok.recipe.special; + +import javax.annotation.Nonnull; + +import com.somebody.idlframewok.item.goblet.ItemDigGoblet; +import net.minecraft.inventory.InventoryCrafting; +import net.minecraft.item.ItemBlock; +import net.minecraft.item.ItemStack; +import net.minecraft.item.crafting.IRecipe; +import net.minecraft.world.World; +import net.minecraftforge.registries.IForgeRegistryEntry; + +public class GobletDigBlockAssign extends IForgeRegistryEntry.Impl implements IRecipe { + @Override + public boolean isDynamic() { + return true; + } + + @Override + public boolean matches(@Nonnull InventoryCrafting var1, @Nonnull World var2) { + //before finding the weapon, we dont know whats the max pearl accepted + boolean foundGoblet = false; + boolean foundBlock = false; + + for(int i = 0; i < var1.getSizeInventory(); i++) { + ItemStack stack = var1.getStackInSlot(i); + if(!stack.isEmpty()) { + if(stack.getItem() instanceof ItemDigGoblet) + { + if (foundGoblet) { + //IdlFramework.Log("Found more than one goblet item"); + return false;//only one goblwt at a time + } + foundGoblet = true; + } + else if ((stack.getItem() instanceof ItemBlock) && !foundBlock) + {//found a block + foundBlock = true; + } + else + { + return false; //Found an other. + } + } + } + + return foundBlock && foundGoblet; + } + + @Nonnull + @Override + public ItemStack getCraftingResult(@Nonnull InventoryCrafting var1) { + ItemStack cup = ItemStack.EMPTY; + + boolean foundGoblet = false; + boolean foundBlock = false; + ItemBlock block = null; + + for(int i = 0; i < var1.getSizeInventory(); i++) { + ItemStack stack = var1.getStackInSlot(i); + if(!stack.isEmpty()) { + if(stack.getItem() instanceof ItemDigGoblet) + { + if (foundGoblet) { + //IdlFramework.Log("Found more than one goblet item"); + return ItemStack.EMPTY;//only one goblwt at a time + } + cup = stack; + foundGoblet = true; + } + else if ((stack.getItem() instanceof ItemBlock) && !foundBlock) + {//found a block + foundBlock = true; + block = (ItemBlock) stack.getItem(); + } + else + { + return ItemStack.EMPTY; //Found an other. + } + } + } + + ItemStack result = cup.copy(); + if (foundGoblet && foundBlock) + { + ItemDigGoblet goblet = (ItemDigGoblet) result.getItem(); + goblet.SetStoredBlockName(result, block.getBlock()); + } + + return result; + } + + @Override + public boolean canFit(int width, int height) { + return true; + } + + @Nonnull + @Override + public ItemStack getRecipeOutput() { + return ItemStack.EMPTY; + } +} + diff --git a/src/main/java/com/somebody/idlframewok/recipe/special/GobletFill.java b/src/main/java/com/somebody/idlframewok/recipe/special/GobletFill.java new file mode 100644 index 0000000..72e9cf6 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/recipe/special/GobletFill.java @@ -0,0 +1,102 @@ +package com.somebody.idlframewok.recipe.special; + +import javax.annotation.Nonnull; + +import com.somebody.idlframewok.item.goblet.ItemP2WGoblet; +import net.minecraft.init.Blocks; +import net.minecraft.init.Items; +import net.minecraft.inventory.InventoryCrafting; +import net.minecraft.item.ItemBlock; +import net.minecraft.item.ItemStack; +import net.minecraft.item.crafting.IRecipe; +import net.minecraft.world.World; +import net.minecraftforge.registries.IForgeRegistryEntry; + +public class GobletFill extends IForgeRegistryEntry.Impl implements IRecipe { + + @Override + public boolean isDynamic() { + return true; + } + + @Override + public boolean matches(@Nonnull InventoryCrafting var1, @Nonnull World var2) { + int foundGoldXP = 0; + boolean foundCup = false; + + for(int i = 0; i < var1.getSizeInventory(); i++) { + ItemStack stack = var1.getStackInSlot(i); + if(!stack.isEmpty()) { + if(stack.getItem() instanceof ItemP2WGoblet) + { + if (foundCup) { + return false;//only one sword at a time + } + foundCup = true; + } + else if (stack.getItem() == Items.GOLD_INGOT) + {//found a xp item + foundGoldXP++; + } + else if(stack.getItem().equals(ItemBlock.getItemFromBlock(Blocks.GOLD_BLOCK))) + { + foundGoldXP+=9; + } + else + { + return false; + } + } + } + return foundGoldXP > 0 && foundCup; + } + + @Nonnull + @Override + public ItemStack getCraftingResult(@Nonnull InventoryCrafting var1) { + int payingXP = 0; + + ItemStack sword = ItemStack.EMPTY; + + for(int i = 0; i < var1.getSizeInventory(); i++) { + ItemStack stack = var1.getStackInSlot(i); + if(!stack.isEmpty()) { + if(stack.getItem() instanceof ItemP2WGoblet) + { + sword = stack; + payingXP += ((ItemP2WGoblet)(sword.getItem())).GetPayingEXP(stack); + } + else if(stack.getItem() == Items.GOLD_INGOT) + { + payingXP++; + } + else if(stack.getItem().getUnlocalizedName().equals(ItemBlock.getItemFromBlock(Blocks.GOLD_BLOCK).getUnlocalizedName())) + { + payingXP+=9; + } + //IdlFramework.Log(stack.getItem().getUnlocalizedName() + " vs " + ItemBlock.getItemFromBlock(Blocks.GOLD_BLOCK).getUnlocalizedName()); + } + } + + if(sword.isEmpty() || payingXP == 0) { + return ItemStack.EMPTY; + } + + ItemStack swordResult = sword.copy(); + ((ItemP2WGoblet)(swordResult.getItem())).SetPayingEXP(swordResult, payingXP); + + return swordResult; + } + + @Override + public boolean canFit(int width, int height) { + return true; + } + + @Nonnull + @Override + public ItemStack getRecipeOutput() { + return ItemStack.EMPTY; + } +} + diff --git a/src/main/java/com/somebody/idlframewok/recipe/special/GuaEnhanceByCrafting.java b/src/main/java/com/somebody/idlframewok/recipe/special/GuaEnhanceByCrafting.java new file mode 100644 index 0000000..480b45a --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/recipe/special/GuaEnhanceByCrafting.java @@ -0,0 +1,122 @@ +package com.somebody.idlframewok.recipe.special; + +import javax.annotation.Nonnull; + +import com.somebody.idlframewok.item.IGuaEnhance; +import com.somebody.idlframewok.util.IDLGeneral; +import com.somebody.idlframewok.util.IDLSkillNBT; +import net.minecraft.inventory.InventoryCrafting; +import net.minecraft.item.ItemStack; +import net.minecraft.item.crafting.IRecipe; +import net.minecraft.world.World; +import net.minecraftforge.registries.IForgeRegistryEntry; + +public class GuaEnhanceByCrafting extends IForgeRegistryEntry.Impl implements IRecipe { + @Override + public boolean isDynamic() { + return true; + } + + @Override + public boolean matches(@Nonnull InventoryCrafting var1, @Nonnull World var2) { + boolean foundMainItem = false; + boolean foundSecond = false; + IGuaEnhance guaEnhance = null; + int guaIndex = -1; + //currently only one gua at a time + + for(int i = 0; i < var1.getSizeInventory(); i++) { + ItemStack stack = var1.getStackInSlot(i); + if(!stack.isEmpty()) { + if(stack.getItem() instanceof IGuaEnhance) + { + if (foundMainItem || (IDLSkillNBT.GetGuaEnhanceFree(stack) == 0)) { + return false; + } + foundMainItem = true; + guaEnhance = (IGuaEnhance) stack.getItem(); + } + else if (!foundSecond) + {//found a gua + int index = IDLGeneral.returnGuaIndex(stack); + if (index >= 0) + { + foundSecond = true; + guaIndex = index; + }else { + return false; + } + + } + else + { + return false; //Found an other. + } + } + } + + if (guaEnhance != null) + { + return foundSecond && guaEnhance.acceptGuaIndex(guaIndex); + } + else { + return false; + } + } + + @Nonnull + @Override + public ItemStack getCraftingResult(@Nonnull InventoryCrafting var1) { + //wont check gua index here. + ItemStack goaEnhanceable = ItemStack.EMPTY; + + boolean foundMain = false; + boolean foundSecond = false; + int guaIndex = -1; + + for(int i = 0; i < var1.getSizeInventory(); i++) { + ItemStack stack = var1.getStackInSlot(i); + if(!stack.isEmpty()) { + if(stack.getItem() instanceof IGuaEnhance) + { + if (foundMain) { + return ItemStack.EMPTY;//only one goblwt at a time + } + goaEnhanceable = stack; + foundMain = true; + } + else if (IDLGeneral.returnGuaIndex(stack) >= 0 && !foundSecond) + {//found a gua + foundSecond = true; + guaIndex = IDLGeneral.returnGuaIndex(stack); + } + else + { + return ItemStack.EMPTY; //Found an other. + } + } + } + + ItemStack result = goaEnhanceable.copy(); + if (foundMain && foundSecond) + { + int freeSockets = IDLSkillNBT.GetGuaEnhanceFree(goaEnhanceable); + IDLSkillNBT.AddGuaEnhance(result, guaIndex, 1); + IDLSkillNBT.SetGuaEnhanceFree(result, freeSockets - 1); + } + + return result; + } + + @Override + public boolean canFit(int width, int height) { + return true; + } + + @Nonnull + @Override + public ItemStack getRecipeOutput() { + return ItemStack.EMPTY; + } +} + diff --git a/src/main/java/com/somebody/idlframewok/recipe/special/SkillUpgrade.java b/src/main/java/com/somebody/idlframewok/recipe/special/SkillUpgrade.java new file mode 100644 index 0000000..2860435 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/recipe/special/SkillUpgrade.java @@ -0,0 +1,117 @@ +package com.somebody.idlframewok.recipe.special; + +import javax.annotation.Nonnull; + +import com.somebody.idlframewok.item.skills.ItemSkillBase; +import com.somebody.idlframewok.util.IDLSkillNBT; +import net.minecraft.inventory.InventoryCrafting; +import net.minecraft.item.ItemStack; +import net.minecraft.item.crafting.IRecipe; +import net.minecraft.world.World; +import net.minecraftforge.registries.IForgeRegistryEntry; + +public class SkillUpgrade extends IForgeRegistryEntry.Impl implements IRecipe { + + @Override + public boolean isDynamic() { + return true; + } + + @Override + public boolean matches(@Nonnull InventoryCrafting var1, @Nonnull World var2) { + ItemStack stack1 = ItemStack.EMPTY, stack2 = ItemStack.EMPTY; + int skillCount = 0; + int lv1 = 0, lv2 = 0; + + for(int i = 0; i < var1.getSizeInventory(); i++) { + ItemStack stack = var1.getStackInSlot(i); + if(!stack.isEmpty()) { + if(stack.getItem() instanceof ItemSkillBase) + { + skillCount++; + if (skillCount > 2) + { + return false; + } + + if (skillCount == 1) + { + stack1 = stack; + ItemSkillBase itemSkillBase = (ItemSkillBase)(stack.getItem()); + lv1 = IDLSkillNBT.getLevel(stack); + if (lv1 >= itemSkillBase.maxLevel) + { + return false; + } + } + else { + stack2 = stack; + lv2 = IDLSkillNBT.getLevel(stack); + } + } + else + { + //DWeapons.logger.warn("Find useless components:[{}], instanceof", stack.getItem().getUnlocalizedName()); + return false; //Found other. + } + } + } + + return skillCount == 2 && (stack1.getItem() == stack2.getItem()) && lv1 == lv2; + } + + @Nonnull + @Override + public ItemStack getCraftingResult(@Nonnull InventoryCrafting var1) { + ItemStack stack1 = ItemStack.EMPTY, stack2 = ItemStack.EMPTY; + ItemStack stackResult = ItemStack.EMPTY; + int skillCount = 0; + int lv1 = 0, lv2 = 0; + + for(int i = 0; i < var1.getSizeInventory(); i++) { + ItemStack stack = var1.getStackInSlot(i); + if(!stack.isEmpty()) { + if(stack.getItem() instanceof ItemSkillBase) + { + skillCount++; + if (skillCount > 2) + { + return stackResult; + } + + if (skillCount == 1) + { + ItemSkillBase itemSkillBase = (ItemSkillBase)(stack.getItem()); + stack1 = stack; + lv1 = IDLSkillNBT.getLevel(stack); + stackResult = stack1.copy(); + IDLSkillNBT.SetLevel(stackResult, lv1 + 1); + } + } + else + { + return stackResult; //Found other. + } + } + } + + if (skillCount == 2 && (stack1.getItem() == stack2.getItem())) + { + + } + + return stackResult; + } + + @Override + public boolean canFit(int width, int height) { + return true; + } + + @Nonnull + @Override + public ItemStack getRecipeOutput() { + return ItemStack.EMPTY; + } +} + diff --git a/src/main/java/com/somebody/idlframewok/util/AchvDef.java b/src/main/java/com/somebody/idlframewok/util/AchvDef.java new file mode 100644 index 0000000..949f284 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/util/AchvDef.java @@ -0,0 +1,9 @@ +package com.somebody.idlframewok.util; + +public class AchvDef { + public final static String ELK_TRANSFORM = "elk_transform"; + public final static String GetAchvName(String key) + { + return Reference.MOD_ID + ":" + key; + } +} diff --git a/src/main/java/com/somebody/idlframewok/util/CommonDef.java b/src/main/java/com/somebody/idlframewok/util/CommonDef.java new file mode 100644 index 0000000..e6b36ae --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/util/CommonDef.java @@ -0,0 +1,56 @@ +package com.somebody.idlframewok.util; + +import java.text.SimpleDateFormat; + +public class CommonDef { + public static final int STANDARD_DUNGEON_MOB_RARITY = 100; + + public static final int INT_AS_FLOAT = 10000; + + public static final int TICK_PER_SECOND = 20; + + //for fgo skills + public static final int SECOND_PER_TURN = 5; + //for arknight skills + public static final int METER_PER_BLOCK = 2; + + public static final int TICK_PER_TURN = SECOND_PER_TURN * TICK_PER_SECOND; + + public static final float DEG_TO_RAD = 0.017453292F; + public static final int CHUNK_SIZE = 16; + + public static int GUA_TYPES = 8; + + public static int G_EARTH = 0; + public static int G_THUNDER = 1; + public static int G_WATER = 2; + public static int G_MOUNTAIN = 4; + public static int G_LAKE = 3; + public static int G_FIRE = 5; + public static int G_WIND = 6; + public static int G_SKY = 7; + + public static int MAX_AIR = 300; + + public static String MOD_NAME_AOA3 = "aoa3"; + public static String MOD_NAME_GOG = "grimoreofgaia3"; + public static SimpleDateFormat formatDate = new SimpleDateFormat("yyyy-MM-dd"); + public static SimpleDateFormat formatTime = new SimpleDateFormat("HH:mm:ss"); + + /** + * Flag 1 will cause a block update. Flag 2 will send the change to clients. Flag 4 will prevent the block from + * being re-rendered, if this is a client world. Flag 8 will force any re-renders to run on the main thread instead + * of the worker pool, if this is a client world and flag 4 is clear. Flag 16 will prevent observers from seeing + * this change. Flags can be OR-ed + */ + public static class BlockFlags + { + public static int BLOCK_UPDATE = 1; + public static int TO_CLIENT = 2; + public static int CLIENT_DONT_RENDER = 4; + public static int FORCE_RENDER = 8; + public static int IGNORE_OB = 16; + } + + +} diff --git a/src/main/java/com/somebody/idlframewok/util/CommonFunctions.java b/src/main/java/com/somebody/idlframewok/util/CommonFunctions.java new file mode 100644 index 0000000..75aad97 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/util/CommonFunctions.java @@ -0,0 +1,342 @@ +package com.somebody.idlframewok.util; + +import java.util.Calendar; +import java.util.Random; + +import com.somebody.idlframewok.IdlFramework; +import com.somebody.idlframewok.item.ItemBase; +import net.minecraft.block.state.IBlockState; +import net.minecraft.client.resources.I18n; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.SharedMonsterAttributes; +import net.minecraft.entity.ai.attributes.IAttribute; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.item.Item; +import net.minecraft.item.ItemBow; +import net.minecraft.item.ItemStack; +import net.minecraft.server.MinecraftServer; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.tileentity.TileEntitySign; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.text.ITextComponent; +import net.minecraft.util.text.TextComponentString; +import net.minecraft.util.text.TextComponentTranslation; +import net.minecraft.util.text.TextFormatting; +import net.minecraft.world.World; +import net.minecraft.world.WorldServer; +import net.minecraft.world.biome.Biome; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.fml.common.FMLCommonHandler; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; +import org.lwjgl.input.Keyboard; + +public class CommonFunctions { + + public static double flunctate(double ori, double radius, Random random) + { + return ori + (random.nextFloat() * 2 - 1) * radius; + } + + public static boolean isSecondTick(World world) + { + return world.getWorldTime() % CommonDef.TICK_PER_SECOND == 0; + } + + public static void teleportToDimension(EntityPlayer player, int dimension, double x, double y, double z) + { + int oldDimension = player.getEntityWorld().provider.getDimension(); + EntityPlayerMP entityPlayerMP = (EntityPlayerMP) player; + MinecraftServer server = player.getEntityWorld().getMinecraftServer(); + WorldServer worldServer = server.getWorld(dimension); + player.addExperienceLevel(0); + + if (worldServer == null || worldServer.getMinecraftServer() == null) + { + throw new IllegalArgumentException("Dimension: "+dimension+" doesn't exist!"); + } + + //todo + //worldServer.getMinecraftServer().getPlayerList().transferPlayerToDimension(entityPlayerMP, dimension, new CustomTeleporter(worldServer, x, y, z)); + player.setPositionAndUpdate(x, y, z); + } + + public static float GetTemperatureHere(Entity creature) + { + BlockPos pos = creature.getPosition(); + World world = creature.getEntityWorld(); + Biome biome = world.getBiomeForCoordsBody(pos); + return biome.getTemperature(pos); + } + + public static float GetTemperatureHere(BlockPos pos, World world) + { + Biome biome = world.getBiomeForCoordsBody(pos); + return biome.getTemperature(pos); + } + + public static int SecondToTicks(int ticks) { + return ticks * CommonDef.TICK_PER_SECOND; + } + + public static int SecondToTicks(float ticks) { + return (int)(ticks * CommonDef.TICK_PER_SECOND); + } + + public static void TryGrantAchv(EntityPlayer player, String key) + { + String achvName = AchvDef.GetAchvName(key); + //todo + } + + public static void BroadCastByKey(String key, Object... args) { + FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerList().sendMessage(new TextComponentTranslation(key, args)); + } + + public static void SafeSendMsgToPlayer(EntityPlayer player, String key, Object... args) + { + //Please note that you can only put %s as arguments. If you put %d, it's not going to translate. + if (player instanceof EntityPlayerMP) + { + player.sendMessage((new TextComponentTranslation(key, args))); + } + } + + public static void SafeSendMsgToPlayer(TextFormatting style, EntityPlayer player, String key, Object... args) + { + //Please note that you can only put %s as arguments. If you put %d, it's not going to translate. + if (player instanceof EntityPlayerMP) + { + TextComponentTranslation textcomponenttranslation = new TextComponentTranslation(key, args); + textcomponenttranslation.getStyle().setColor(style); + player.sendMessage(textcomponenttranslation); + } + } + + public static void SendMsgToPlayer(EntityPlayerMP playerMP, String key) + { + playerMP.sendMessage(new TextComponentTranslation(key)); + } + + public static void SendMsgToPlayerStyled(EntityPlayerMP playerMP, String key, TextFormatting style, Object... args) + { + TextComponentTranslation textcomponenttranslation = new TextComponentTranslation(key, args); + textcomponenttranslation.getStyle().setColor(style); + playerMP.sendMessage(textcomponenttranslation); + } + + + public static void SendMsgToPlayer(EntityPlayerMP playerMP, String key, Object... args) + { + playerMP.sendMessage((new TextComponentTranslation(key, args))); + } + + @SideOnly(Side.CLIENT) + public static String GetStringLocalTranslated(String key) { + //return "WIP"; + return I18n.format(key); + + } + + public static void FillWithBlockCornered(World world, BlockPos origin, int lengthX, int lengthY, int lengthZ, IBlockState newState) { + BlockPos target; + for(int x = 0; + x < lengthX;x++) { + for (int y = 0; y < lengthY; y++) { + for (int z = 0; z < lengthZ; z++) { + target = origin.add(x, y, z); + //IBlockState targetBlock = world.getBlockState(target); + world.setBlockState(target, newState); + } + } + } + } + + public static void FillWithBlockCentered(World world, BlockPos origin, int rangeX, int rangeY, int rangeZ, IBlockState newState) { + BlockPos target; + for(int x = -rangeX; + x <=rangeX;x++) { + for (int y = -rangeY; y <= rangeY; y++) { + for (int z = -rangeZ; z <= rangeZ; z++) { + target = origin.add(x, y, z); + //IBlockState targetBlock = world.getBlockState(target); + world.setBlockState(target, newState); + } + } + } + } + + public static void BuildWallWithBlockCentered(World world, BlockPos origin, int rangeX, int height, int rangeZ, IBlockState newState) { + BlockPos target; + for(int x = -rangeX; + x <=rangeX;x++) { + for (int y = 0; y < height; y++) { + for (int z = -rangeZ; z <= rangeZ; z++) { + target = origin.add(x, y, z); + //IBlockState targetBlock = world.getBlockState(target); + world.setBlockState(target, newState); + } + } + } + } + + public static void LogPlayerAction(EntityLivingBase living, String action){ + IdlFramework.Log(String.format("%s(%s): %s",living.getName(), living.getUniqueID(), action)); + } + + public static boolean RepairItem(ItemStack stack, int amount) + { + if (!stack.isItemStackDamageable()) + { + return false; + } + else { + int newVal = stack.getItemDamage() - amount; + //if (newVal < 0) newVal = 0; + stack.setItemDamage(newVal); + return true; + } + } + + public static void CopyNormalAttr(EntityLivingBase ori, EntityLivingBase to) + { + CopyAttr(ori, to, SharedMonsterAttributes.FOLLOW_RANGE); + CopyAttr(ori, to, SharedMonsterAttributes.MAX_HEALTH); + CopyAttr(ori, to, SharedMonsterAttributes.MOVEMENT_SPEED); + } + + + public static void CopyAttr(EntityLivingBase ori, EntityLivingBase to, IAttribute attrType) + { + to.getEntityAttribute(SharedMonsterAttributes.FOLLOW_RANGE).setBaseValue(ori.getEntityAttribute(attrType).getAttributeValue()); + } + + public static int XPForLevel(int lv) + { + /** + * This method returns the cap amount of experience that the experience bar can hold. With each level, the + * experience cap on the player's experience bar is raised by 10. + */ + + if (lv >= 30) + { + return 112 + (lv - 30) * 9; + } + else + { + return lv >= 15 ? 37 + (lv - 15) * 5 : 7 + lv * 2; + } + + } + + + public static boolean TryConsumePlayerXP(EntityPlayer player, int XP) + { + //float curXP = player.experience; + float curLv = player.experienceLevel; + float costLeft = XP; + + int playerTotalXP = 0; + for (int i = 1; i <= curLv; i++) + { + playerTotalXP += XPForLevel(i); + } + playerTotalXP += player.experience; + + if (playerTotalXP < XP) + { + //not enough + return false; + } + + //todo not working here + while (costLeft > 0 && (player.experienceLevel > 0 || player.experience > 0)) + { + if (player.experience > costLeft) + { + player.experience -= costLeft; + costLeft = 0; + IdlFramework.Log("A"); + } + else { + costLeft -= player.experience; + IdlFramework.Log("B"); + if (player.experienceLevel > 0) + { + player.experienceLevel--; + player.experience = XPForLevel(player.experienceLevel); + IdlFramework.Log(String.format("player.experience = %d", XPForLevel(player.experienceLevel))); + } + } + } + IdlFramework.Log(String.format("Lv= %s, xp = %s", player.experienceLevel, player.experience)); + return true; + } + + public static boolean isItemRangedWeapon(ItemStack stack) + { + if (stack.isEmpty()) + { + return false; + } + + Item item = stack.getItem(); + if (item instanceof ItemBow) + { + return true; + } + + if (item instanceof ItemBase) + { + return ((ItemBase) item).isRangedWeaponItem(); + } + return false; + } + + public static void WriteGraveToSign(EntityPlayer player, World world, TileEntity tileEntity1) { + if (tileEntity1 instanceof TileEntitySign) + { + WriteGraveToSign(player.getDisplayName(), world, tileEntity1); + } + } + + private static void WriteGraveToSign(ITextComponent name, World world, TileEntity tileEntity1) { + if (tileEntity1 instanceof TileEntitySign) + { + ((TileEntitySign) tileEntity1).signText[0] = name; + ((TileEntitySign) tileEntity1).signText[1] = new TextComponentString("R.I.P."); + + Calendar calendar = world.getCurrentDate(); + ((TileEntitySign) tileEntity1).signText[2] = new TextComponentString( + CommonDef.formatDate.format(calendar.getTime()) + ); + + ((TileEntitySign) tileEntity1).signText[3] = new TextComponentString( + CommonDef.formatTime.format(calendar.getTime()) + ); + } + } + + @SideOnly(Side.CLIENT) + public static boolean isShiftPressed() + { + return Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT); + } + + public static void sendBasicMsg(ItemStack stack, EntityPlayer player, int index) + { + if (player.world.isRemote) + { + return; + } + + SendMsgToPlayer((EntityPlayerMP) player, String.format("%s.msg.%d", stack.getUnlocalizedName(), index)); + } + + public static void addToEventBus(Object target) + { + MinecraftForge.EVENT_BUS.register(target); + } +} diff --git a/src/main/java/com/somebody/idlframewok/util/EntityUtil.java b/src/main/java/com/somebody/idlframewok/util/EntityUtil.java new file mode 100644 index 0000000..fb395f8 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/util/EntityUtil.java @@ -0,0 +1,591 @@ +package com.somebody.idlframewok.util; + +import java.util.Collection; +import java.util.List; +import java.util.Random; +import java.util.UUID; +import javax.annotation.Nullable; + +import com.google.common.base.Predicate; +import com.somebody.idlframewok.IdlFramework; +import com.somebody.idlframewok.entity.creatures.EntityModUnit; +import com.somebody.idlframewok.meta.MetaUtil; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.SharedMonsterAttributes; +import net.minecraft.entity.ai.attributes.AttributeModifier; +import net.minecraft.entity.ai.attributes.IAttribute; +import net.minecraft.entity.ai.attributes.IAttributeInstance; +import net.minecraft.entity.monster.EntityZombie; +import net.minecraft.entity.monster.IMob; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.SoundEvents; +import net.minecraft.potion.Potion; +import net.minecraft.potion.PotionEffect; +import net.minecraft.util.EnumParticleTypes; +import net.minecraft.util.math.AxisAlignedBB; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Vec3d; +import net.minecraft.world.World; +import net.minecraft.world.biome.Biome; +import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.common.gameevent.TickEvent; +import net.minecraftforge.fml.common.registry.EntityRegistry; + +@Mod.EventBusSubscriber(modid = IdlFramework.MODID) +public class EntityUtil { + public static void simpleKnockBack(float power, EntityLivingBase source, EntityLivingBase target) + { + target.knockBack(source, power, (source.posX - target.posX), (source.posZ - target.posZ)); + } + + public static void TryRemoveDebuff(EntityLivingBase livingBase) + { + //washes away debuff + Collection activePotionEffects = livingBase.getActivePotionEffects(); + for (int i = 0; i < activePotionEffects.size(); i++) { + PotionEffect buff = (PotionEffect)activePotionEffects.toArray()[i]; + if (buff.getPotion().isBadEffect()){ + livingBase.removePotionEffect(buff.getPotion()); + } + } + } + + public static void TryRemoveGivenBuff(EntityLivingBase livingBase, Potion potion) + { + //washes away debuff + Collection activePotionEffects = livingBase.getActivePotionEffects(); + for (int i = 0; i < activePotionEffects.size(); i++) { + PotionEffect buff = (PotionEffect)activePotionEffects.toArray()[i]; + if (buff.getPotion() == potion){ + livingBase.removePotionEffect(buff.getPotion()); + return; + } + } + } + + public static boolean ApplyBuff(EntityLivingBase livingBase, Potion potion, int level, float seconds) + { + if (livingBase == null || potion == null) + { + IdlFramework.LogWarning("Trying to apply illegal potion"); + return false; + } + livingBase.addPotionEffect(new PotionEffect(potion, (int) (seconds * CommonDef.TICK_PER_SECOND) + 1, level)); + return true; + } + + public static String getModName(EntityLivingBase creature) + { + if (creature instanceof EntityPlayer || creature == null) + { + return "minecraft"; + } + EntityRegistry.EntityRegistration er = EntityRegistry.instance().lookupModSpawn(creature.getClass(), true); + if (er == null) + { + //Vanilla creatures don't have ER + return "minecraft"; + } + return er.getContainer().getModId(); + } + + //Player is not vanilla + public static boolean isVanillaResident(EntityLivingBase creature) + { + if (creature instanceof EntityPlayer || creature == null) + { + return false; + } + + EntityRegistry.EntityRegistration er = EntityRegistry.instance().lookupModSpawn(creature.getClass(), true); + if (er == null) + { + return true; + } + String modid = er.getContainer().getModId(); + return modid.equals("minecraft"); + } + + //Player is not otherWorld + public static boolean isOtherworldAggression(EntityLivingBase creature) + { + if (creature instanceof EntityPlayer || creature == null || isIdeallandTeam(creature)) + { + return false; + } + + EntityRegistry.EntityRegistration er = EntityRegistry.instance().lookupModSpawn(creature.getClass(), true); + if (er == null) + { + //Normally this will be enough. Vanilla creatures don't have ER + return false; + } + String modid = er.getContainer().getModId(); + //IdlFramework.Log("Atk ER.modid is %s, name is %s", modid, er.getRegistryName()); + + return !modid.equals("minecraft"); + } + + public static boolean isIdeallandTeam(EntityLivingBase creature) + { + return (creature instanceof EntityModUnit && ((EntityModUnit) creature).isIdealland); + } + + public static boolean isMoroonTeam(EntityLivingBase creature) + { + return (creature instanceof EntityModUnit && ((EntityModUnit) creature).isMoroon); + } + + public static boolean isMechanical(EntityLivingBase creature) + { + return (creature instanceof EntityModUnit && ((EntityModUnit) creature).is_mechanic); + } + + public static boolean isAOA3Creature(EntityLivingBase creature) + { + if (!MetaUtil.isLoaded_AOA3) + { + return false; + } + return getModName(creature).equals(CommonDef.MOD_NAME_AOA3); + } + + public static boolean isGOGCreature(EntityLivingBase creature) + { + if (!MetaUtil.isLoaded_GOG) + { + return false; + } + return getModName(creature).equals(CommonDef.MOD_NAME_AOA3); + } + + public static List getEntitiesWithinAABB(World world, Class clazz, AxisAlignedBB aabb, @Nullable Predicate filter) + { + return world.getEntitiesWithinAABB(clazz, aabb, filter); + } + + public static List getEntitiesWithinAABB(World world, Class clazz, Vec3d center, float range, @Nullable Predicate filter) + { + return world.getEntitiesWithinAABB(clazz, IDLGeneral.ServerAABB(center.addVector(-range, -range, -range), center.addVector(range, range, range)) , filter); + } + + public static Vec3d GetRandomAroundUnderfoot(EntityLivingBase entity, float radius) + { + float angle = entity.getRNG().nextFloat() * 6.282f; + return new Vec3d(entity.posX + Math.sin(angle), entity.posY, entity.posZ + Math.cos(angle)); + } + + public static Vec3d GetRandomAroundPos(Vec3d pos, float radius, Random rng) + { + float angle = rng.nextFloat() * 6.282f; + return new Vec3d(pos.x + Math.sin(angle), pos.y, pos.z + Math.cos(angle)); + } + + public static void SpawnParticleAround(EntityLivingBase entity, EnumParticleTypes particleTypes) + { + Vec3d pos = GetRandomAroundUnderfoot(entity,1f); + entity.world.spawnParticle(particleTypes, pos.x, pos.y, pos.z, 0,0,0); + } + + public static void SpawnParticleAround(EntityLivingBase entity, EnumParticleTypes particleTypes, int count) + { + for (int i = 0; i < count; i++) + { + SpawnParticleAround(entity, particleTypes); + } + } + + public static void createTeleportEffect(EntityLivingBase livingBase) + { + if (livingBase == null) + { + return; + } + + World worldIn = livingBase.world; + if (worldIn.isRemote) + { + Vec3d oriPos = livingBase.getPositionEyes(0); + Random random = livingBase.getRNG(); + AxisAlignedBB bb = livingBase.getRenderBoundingBox(); + double radiusX = bb.maxX - bb.minX; + double radiusY = bb.maxY - bb.minY; + double radiusZ = bb.maxZ - bb.minZ; + + for (int i = 0; i <= 10; i++) + { + worldIn.spawnParticle(EnumParticleTypes.PORTAL, + CommonFunctions.flunctate(oriPos.x, radiusX, random), + CommonFunctions.flunctate(oriPos.y, radiusY, random), + CommonFunctions.flunctate(oriPos.z, radiusZ, random), + random.nextFloat(), + random.nextFloat(), + random.nextFloat() + ); + } + + worldIn.playSound(oriPos.x, oriPos.y, oriPos.z, SoundEvents.ENTITY_ENDERMEN_TELEPORT, null, 1f, 1.3f, false); + } + } + + static float angle = 0f; + + @SubscribeEvent + static void onWorldTick(TickEvent.WorldTickEvent event) + { + if (event.type == TickEvent.Type.WORLD ) + { + angle += 1.0f;//ModConfig.DEBUG_CONF.HALO_OMEGA; + angle %= 6.282f; + } + } + + public static void spawnHaloParticleAround(EntityLivingBase entity, EnumParticleTypes particleTypes, float radius) + { + for (int i = 0; i < 10; i++) + { + float deltaOmega = 1.0f * i;//ModConfig.DEBUG_CONF.HALO_OMEGA; + Vec3d pos = new Vec3d(entity.posX + radius * Math.sin(angle + deltaOmega), entity.posY + 0.1f * entity.getRNG().nextFloat(), entity.posZ + radius * Math.cos(angle + deltaOmega)); + entity.world.spawnParticle(particleTypes, pos.x, pos.y, pos.z, 0,0,0); + } + } + + public static Faction faction(EntityLivingBase creature) + { + if (isMoroonTeam(creature)) + { + return Faction.MOROON; + } else if (isIdeallandTeam(creature)) + { + return Faction.IDEALLAND; + }else if (creature instanceof EntityZombie) + { + return Faction.MOB_VAN_ZOMBIE; + } + else if (creature instanceof IMob) + { + return Faction.MOB_VANILLA; + }else if (creature instanceof EntityPlayer) + { + return Faction.PLAYER; + }else + { + return Faction.CRITTER; + } + } + + public static ATTITUDE getAttitude(EntityLivingBase subject, EntityLivingBase object) + { + if (subject == null || object == null) + { + return ATTITUDE.IGNORE; + } + + if (subject.isOnSameTeam(object)) + { + return ATTITUDE.FRIEND; + } + return getAttitude(faction(subject), faction(object)); + } + + public static ATTITUDE getAttitude(Faction subject, EntityLivingBase object) + { + return getAttitude(subject, faction(object)); + } + + public static ATTITUDE getAttitude(Faction subject, Faction object) + { + if (subject == object) + { + return ATTITUDE.FRIEND; + } + + if (subject == Faction.CRITTER || object == Faction.CRITTER) + { + return ATTITUDE.IGNORE; + } + + switch (subject) + { + case PLAYER: + case IDEALLAND: + switch (object) + { + case IDEALLAND: + return ATTITUDE.FRIEND; + case MOB_VANILLA: + case MOB_VAN_ZOMBIE: + case MOROON: + return ATTITUDE.HATE; + default: + return ATTITUDE.IGNORE; + } + case MOB_VANILLA: + switch (object) + { + case IDEALLAND: + case PLAYER: + return ATTITUDE.HATE; + case MOB_VAN_ZOMBIE: + return ATTITUDE.FRIEND; + + default: + return ATTITUDE.IGNORE; + } + + case MOB_VAN_ZOMBIE: + switch (object) + { + case IDEALLAND: + case PLAYER: + return ATTITUDE.HATE; + + case MOB_VANILLA: + return ATTITUDE.FRIEND; + + default: + return ATTITUDE.IGNORE; + } + + case MOROON: + switch (object) + { + case IDEALLAND: + case MOB_VAN_ZOMBIE: + case PLAYER: + return ATTITUDE.HATE; + + default: + return ATTITUDE.IGNORE; + } + } + return ATTITUDE.IGNORE; + } + + public static Vec3d GetRandomAround(EntityLivingBase entity, float radius) + { + float angle = entity.getRNG().nextFloat() * 6.282f; + return new Vec3d(entity.posX + Math.sin(angle), entity.getEyeHeight() + entity.posY, entity.posZ + Math.cos(angle)); + } + + public static final Predicate InWater = new Predicate() + { + public boolean apply(@Nullable EntityLivingBase p_apply_1_) + { + return p_apply_1_ != null && p_apply_1_.isInWater(); + } + }; + + public static final Predicate FriendToIdl = new Predicate() + { + public boolean apply(@Nullable EntityLivingBase p_apply_1_) + { + return p_apply_1_ != null && (getAttitude(Faction.IDEALLAND, p_apply_1_)==ATTITUDE.FRIEND); + } + }; + + public static final Predicate HostileToIdl = new Predicate() + { + public boolean apply(@Nullable EntityLivingBase p_apply_1_) + { + return p_apply_1_ != null && (getAttitude(Faction.IDEALLAND, p_apply_1_)==ATTITUDE.HATE) && (p_apply_1_).attackable(); + } + }; + + public static final Predicate HostileToIdl_AIR = new Predicate() + { + public boolean apply(@Nullable EntityLivingBase p_apply_1_) + { + return p_apply_1_ != null && (getAttitude(Faction.IDEALLAND, p_apply_1_)==ATTITUDE.HATE) && (p_apply_1_).attackable() && !p_apply_1_.onGround; + } + }; + + public static final Predicate HostileToMor = new Predicate() + { + public boolean apply(@Nullable EntityLivingBase p_apply_1_) + { + return p_apply_1_ != null && (getAttitude(Faction.MOROON, p_apply_1_)==ATTITUDE.HATE) && (p_apply_1_).attackable(); + } + }; + + public static final Predicate IsVanilla = new Predicate() + { + public boolean apply(@Nullable EntityLivingBase p_apply_1_) + { + return p_apply_1_ != null && isVanillaResident((p_apply_1_)) && (p_apply_1_).attackable(); + } + }; + public static double getAttack(EntityLivingBase creature) + { + if (creature == null) + { + return 0; + } + + IAttributeInstance attribute = creature.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE); + if (attribute == null) + { + return 0; + } + return attribute.getAttributeValue(); + } + + public static double getSight(EntityLivingBase creature) + { + if (creature == null) + { + return 0; + } + + IAttributeInstance attribute = creature.getEntityAttribute(SharedMonsterAttributes.FOLLOW_RANGE); + return attribute.getAttributeValue(); + } + + public static double getAtkSpeed(EntityLivingBase creature) + { + if (creature == null) + { + return 0; + } + + IAttributeInstance attribute = creature.getEntityAttribute(SharedMonsterAttributes.ATTACK_SPEED); + return attribute.getAttributeValue(); + } + + public static double getAttr(EntityLivingBase creature, IAttribute attr) + { + if (creature == null) + { + return 0; + } + + IAttributeInstance attribute = creature.getEntityAttribute(attr); + if (attribute == null) + { + return 0; + } + return attribute.getAttributeValue(); + } + + public static double getAttrBase(EntityLivingBase creature, IAttribute attr) + { + if (creature == null) + { + return 0; + } + + IAttributeInstance attribute = creature.getEntityAttribute(attr); + if (attribute == null) + { + return 0; + } + return attribute.getBaseValue(); + } + + public static boolean boostAttr(EntityLivingBase creature, IAttribute attrType, float amountFixed, UUID uuid) + { + float val = amountFixed; + IAttributeInstance attribute = creature.getEntityAttribute(attrType); + + if (attribute == null) + { + //this happens on creatures with no attack. + //will surely happen. + creature.playSound(SoundEvents.BLOCK_DISPENSER_FAIL, 1f, 1f); + return false; + } + + double valueBefore = attribute.getAttributeValue(); + + AttributeModifier modifier = attribute.getModifier(uuid); + if (modifier != null) + { + //stack up + val += modifier.getAmount(); + attribute.removeModifier(modifier); + } + attribute.applyModifier(new AttributeModifier(uuid, "pwr up", val, 0)); + double valueAfter = attribute.getAttributeValue(); + + if (modifier == null) + { + modifier = attribute.getModifier(uuid); + } + + //IdlFramework.Log("Value:%s: %.2f->%.2f", modifier.getName(), valueBefore, valueAfter); + return true; + } + + public static boolean boostAttrRatio(EntityLivingBase creature, IAttribute attrType, float amountRatio, UUID uuid) + { + float val = amountRatio; + IAttributeInstance attribute = creature.getEntityAttribute(attrType); + + if (attribute == null) + { + //this happens on creatures with no attack. + //will surely happen. + creature.playSound(SoundEvents.BLOCK_DISPENSER_FAIL, 1f, 1f); + return false; + } + + double valueBefore = attribute.getAttributeValue(); + + AttributeModifier modifier = attribute.getModifier(uuid); + if (modifier != null) + { + //stack up + val += modifier.getAmount(); + attribute.removeModifier(modifier); + } + attribute.applyModifier(new AttributeModifier(uuid, "pwr up percent", val, 1)); + double valueAfter = attribute.getAttributeValue(); + + if (modifier == null) + { + modifier = attribute.getModifier(uuid); + } + + //IdlFramework.Log("Value:%s: %.2f->%.2f", modifier.getName(), valueBefore, valueAfter); + return true; + } + + public enum Faction{ + PLAYER, + IDEALLAND, + MOB_VANILLA, + MOB_VAN_ZOMBIE, + MOROON, + CRITTER, + } + + public enum ATTITUDE{ + HATE, + IGNORE, + FRIEND + } + + public static Biome getBiomeForEntity(Entity entity) + { + World world = entity.getEntityWorld(); + return world.getBiomeForCoordsBody(entity.getPosition()); + } + + public static boolean isSunlit(Entity entity) + { + float f = entity.getBrightness(); + return f > 0.5F && entity.world.canSeeSky(new BlockPos(entity.posX, entity.posY + (double)entity.getEyeHeight(), entity.posZ)); + } + + public static boolean isMoonlit(Entity entity) + { + int tickInDay = (int) (entity.getEntityWorld().getWorldTime() % 24000); + if (tickInDay > 167 && tickInDay < 11834) + { + return false; + } + return entity.world.canSeeSky(new BlockPos(entity.posX, entity.posY + (double)entity.getEyeHeight(), entity.posZ)); + } +} diff --git a/src/main/java/com/somebody/idlframewok/util/IDLGeneral.java b/src/main/java/com/somebody/idlframewok/util/IDLGeneral.java new file mode 100644 index 0000000..07481e8 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/util/IDLGeneral.java @@ -0,0 +1,47 @@ +package com.somebody.idlframewok.util; + +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.potion.Potion; +import net.minecraft.potion.PotionEffect; +import net.minecraft.util.math.AxisAlignedBB; +import net.minecraft.util.math.Vec3d; + +public class IDLGeneral { + //server side dont have this constructor. + public static AxisAlignedBB ServerAABB(Vec3d from, Vec3d to) + { + return new AxisAlignedBB(from.x, from.y, from.z, to.x, to.y, to.z); + } + + public static AxisAlignedBB ServerAABB(Vec3d origin, float range) + { + return new AxisAlignedBB(origin.x - range, origin.y - range, origin.z - range, + origin.x + range, origin.y + range, origin.z + range); + } + + public static boolean EntityHasBuff(EntityLivingBase livingBase, Potion buff) + { + return livingBase.getActivePotionEffect(buff) != null; + } + + public static int EntityBuffCounter(EntityLivingBase livingBase, Potion buff) + { + PotionEffect effect = livingBase.getActivePotionEffect(buff); + return effect == null ? -1 : effect.getDuration(); + } + + public static int returnGuaIndex(ItemStack stack) + { + Item item = stack.getItem(); +// for (int i = 0; i < GUA_TYPES; i++) +// { +// if (item == ModItems.GUA[i]) +// { +// return i; +// } +// } + return -1; + } +} diff --git a/src/main/java/com/somebody/idlframewok/util/IDLNBT.java b/src/main/java/com/somebody/idlframewok/util/IDLNBT.java new file mode 100644 index 0000000..d4d2df6 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/util/IDLNBT.java @@ -0,0 +1,164 @@ +package com.somebody.idlframewok.util; + +import com.somebody.idlframewok.util.NBTStrDef.IDLNBTDef; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.nbt.NBTTagCompound; + +public class IDLNBT { + public int pearlCount; + public boolean isEarth; + public boolean isSky; + + private final NBTTagCompound basic; + + public IDLNBT() + { + pearlCount = 0; + isEarth = false; + isSky = false; + + basic = new NBTTagCompound(); + } + + public IDLNBT(NBTTagCompound srcNBT) + { + readFromBasic(srcNBT); + basic = srcNBT; + } + + public void readFromBasic(NBTTagCompound tag) + { + if (tag != null) + { + pearlCount = tag.getInteger(IDLNBTDef.LEVEL_TAG); + isEarth = tag.getBoolean(IDLNBTDef.IS_EARTH); + isSky = tag.getBoolean(IDLNBTDef.IS_SKY); + } + } + + public void writeToBasic(NBTTagCompound tag) + { + if (tag == null) + { + tag = new NBTTagCompound(); + } + + tag.setInteger(IDLNBTDef.LEVEL_TAG, pearlCount); + tag.setBoolean(IDLNBTDef.IS_EARTH, isEarth); + tag.setBoolean(IDLNBTDef.IS_SKY, isSky); + } + + public NBTTagCompound getBasic() + { + NBTTagCompound tag = basic.copy(); + writeToBasic(tag); + + return tag; + } + + public void save() + { + writeToBasic(basic); + } + + //PlayerData + //--PERSISTED_NBT_TAG + // --IDEALLAND + // --KILL_COUNT,etc + + + public static NBTTagCompound getTagSafe(NBTTagCompound tag, String key) { + if(tag == null) { + return new NBTTagCompound(); + } + + return tag.getCompoundTag(key); + } + + public static NBTTagCompound getPlyrIdlTagSafe(EntityPlayer player) { + NBTTagCompound playerData = player.getEntityData(); + NBTTagCompound data = getTagSafe(playerData, EntityPlayer.PERSISTED_NBT_TAG); + NBTTagCompound idl_data = getTagSafe(data, IDLNBTDef.IDEALLAND); + + return idl_data; + } + + public static NBTTagCompound getPlayerIdeallandTagGroupSafe(EntityPlayer player, String key) { + return getPlyrIdlTagSafe(player).getCompoundTag(key); + } + + public static int[] getPlayerIdeallandIntArraySafe(EntityPlayer player, String key) { + return getPlyrIdlTagSafe(player).getIntArray(key); + } + + public static int getPlayerIdeallandIntSafe(EntityPlayer player, String key) { + return getPlyrIdlTagSafe(player).getInteger(key); + } + public static float getPlayerIdeallandFloatSafe(EntityPlayer player, String key) { + return getPlyrIdlTagSafe(player).getFloat(key); + } + public static double getPlayerIdeallandDoubleSafe(EntityPlayer player, String key) { + return getPlyrIdlTagSafe(player).getDouble(key); + } + public static boolean getPlayerIdeallandBoolSafe(EntityPlayer player, String key) { + return getPlyrIdlTagSafe(player).getBoolean(key); + } + public static String getPlayerIdeallandStrSafe(EntityPlayer player, String key) { + return getPlyrIdlTagSafe(player).getString(key); + } + + public static void setPlayerIdeallandTagSafe(EntityPlayer player, String key, int value) { + NBTTagCompound playerData = player.getEntityData(); + NBTTagCompound data = getTagSafe(playerData, EntityPlayer.PERSISTED_NBT_TAG); + NBTTagCompound idl_data = getPlyrIdlTagSafe(player); + + idl_data.setInteger(key, value); + + data.setTag(IDLNBTDef.IDEALLAND, idl_data); + playerData.setTag(EntityPlayer.PERSISTED_NBT_TAG, data); + } + + public static void setPlayerIdeallandTagSafe(EntityPlayer player, String key, int[] value) { + NBTTagCompound playerData = player.getEntityData(); + NBTTagCompound data = getTagSafe(playerData, EntityPlayer.PERSISTED_NBT_TAG); + NBTTagCompound idl_data = getPlyrIdlTagSafe(player); + + idl_data.setIntArray(key, value); + + data.setTag(IDLNBTDef.IDEALLAND, idl_data); + playerData.setTag(EntityPlayer.PERSISTED_NBT_TAG, data); + } + + public static void setPlayerIdeallandTagSafe(EntityPlayer player, String key, double value) { + NBTTagCompound playerData = player.getEntityData(); + NBTTagCompound data = getTagSafe(playerData, EntityPlayer.PERSISTED_NBT_TAG); + NBTTagCompound idl_data = getPlyrIdlTagSafe(player); + + idl_data.setDouble(key, value); + + data.setTag(IDLNBTDef.IDEALLAND, idl_data); + playerData.setTag(EntityPlayer.PERSISTED_NBT_TAG, data); + } + + public static void setPlayerIdeallandTagSafe(EntityPlayer player, String key, boolean value) { + NBTTagCompound playerData = player.getEntityData(); + NBTTagCompound data = getTagSafe(playerData, EntityPlayer.PERSISTED_NBT_TAG); + NBTTagCompound idl_data = getPlyrIdlTagSafe(player); + + idl_data.setBoolean(key, value); + + data.setTag(IDLNBTDef.IDEALLAND, idl_data); + playerData.setTag(EntityPlayer.PERSISTED_NBT_TAG, data); + } + + public static void setPlayerIdeallandTagSafe(EntityPlayer player, String key, String value) { + NBTTagCompound playerData = player.getEntityData(); + NBTTagCompound data = getTagSafe(playerData, EntityPlayer.PERSISTED_NBT_TAG); + NBTTagCompound idl_data = getPlyrIdlTagSafe(player); + + idl_data.setString(key, value); + + data.setTag(IDLNBTDef.IDEALLAND, idl_data); + playerData.setTag(EntityPlayer.PERSISTED_NBT_TAG, data); + } +} diff --git a/src/main/java/com/somebody/idlframewok/util/IDLSkillNBT.java b/src/main/java/com/somebody/idlframewok/util/IDLSkillNBT.java new file mode 100644 index 0000000..1dd29af --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/util/IDLSkillNBT.java @@ -0,0 +1,322 @@ +package com.somebody.idlframewok.util; + +import java.util.List; + +import com.somebody.idlframewok.item.IGuaEnhance; +import com.somebody.idlframewok.item.skills.ItemSkillBase; +import com.somebody.idlframewok.util.NBTStrDef.IDLNBTDef; +import com.somebody.idlframewok.util.NBTStrDef.IDLNBTUtil; +import net.minecraft.client.resources.I18n; +import net.minecraft.client.util.ITooltipFlag; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.text.TextFormatting; +import net.minecraft.world.World; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +public class IDLSkillNBT { + public static final String SUCCESS_DESC_KEY = ".on_sucess"; + public static final String IN_CD_DESC_KEY = ".on_cooldown"; + public int level; + public int range_boost = 0; + public int duration_boost = 0; + public int[] gua_boost = new int[8]; + +// private final NBTTagCompound basic; + +// public IDLSkillNBT() +// { +// level = 1; +// range_boost = 0; +// duration_boost = 0; +// +// basic = new NBTTagCompound(); +// } +// +// public IDLSkillNBT(NBTTagCompound srcNBT) +// { +// readFromBasic(srcNBT); +// basic = srcNBT; +// } +// +// public void readFromBasic(NBTTagCompound tag) +// { +// if (tag != null) +// { +// level = tag.getInteger(IDLNBTDef.LEVEL_TAG); +// range_boost = tag.getInteger(IDLNBTDef.RANGE_BOOST); +// duration_boost = tag.getInteger(IDLNBTDef.DURA_BOOST); +// } +// } + +// public void writeToBasic(NBTTagCompound tag) +// { +// if (tag == null) +// { +// tag = new NBTTagCompound(); +// } +// +// tag.setInteger(IDLNBTDef.LEVEL_TAG, level); +// tag.setInteger(IDLNBTDef.RANGE_BOOST, range_boost); +// tag.setInteger(IDLNBTDef.DURA_BOOST, duration_boost); +// } +// +// public NBTTagCompound getBasic() +// { +// NBTTagCompound tag = basic.copy(); +// writeToBasic(tag); +// +// return tag; +// } +// +// public void save() +// { +// writeToBasic(basic); +// } + //---------------------- + //Integer + public static void SetGuaEnhance(ItemStack stack, int guaIndex, int value) + { + NBTTagCompound ori = IDLNBTUtil.getNBT(stack); + + NBTTagCompound subset = new NBTTagCompound(); + subset.setInteger(IDLNBTDef.GUA_ENHANCE_8 + guaIndex, value); + + NBTTagCompound newTag = new NBTTagCompound(); + newTag.setTag(IDLNBTDef.GUA_ENHANCE, subset); + + ori.merge(newTag); +// if (!StackHasKey(stack, GUA_ENHANCE)) +// { +// getNBT(stack).setTag(GUA_ENHANCE, new NBTTagCompound()); +// }else { +// +// } +// +// NBTTagCompound guaEnhanceNBT = getNBT(stack).getCompoundTag(GUA_ENHANCE); +// +// guaEnhanceNBT.setInteger(GUA_ENHANCE_8 + guaIndex, value); + } + + public static void AddGuaEnhance(ItemStack stack, int guaIndex, int value) + { + SetGuaEnhance(stack, guaIndex, value + GetGuaEnhance(stack, guaIndex)); + } + + public static String GetGuaEnhanceString(ItemStack stack, int guaIndex) + { + Item stackItem = stack.getItem(); + if (stackItem instanceof IGuaEnhance) + { + IGuaEnhance guaEnhance = (IGuaEnhance) stackItem; + if (guaEnhance.acceptGuaIndex(guaIndex)) + { + return String.valueOf(GetGuaEnhance(stack, guaIndex, 0)); + } + else { + return I18n.format(IDLNBTDef.GUA_N_A_DESC); + } + } + else { + return ""; + } + + } + + public static int GetGuaEnhance(ItemStack stack, int guaIndex) + { + return GetGuaEnhance(stack, guaIndex, 0); + } + + public static int GetGuaEnhance(ItemStack stack, int guaIndex, int defaultVal) + { + if (IDLNBTUtil.StackHasKey(stack, IDLNBTDef.GUA_ENHANCE)) + { + NBTTagCompound nbt = IDLNBTUtil.getNBT(stack).getCompoundTag(IDLNBTDef.GUA_ENHANCE); + String str = String.valueOf(IDLNBTDef.GUA_ENHANCE_8 + guaIndex); + if (nbt.hasKey(str)) + { + return nbt.getInteger(str); + } + } + + return defaultVal; + } + + public static int GetGuaEnhanceTotal(ItemStack stack) + { + int result = 0; + if (IDLNBTUtil.StackHasKey(stack, IDLNBTDef.GUA_ENHANCE)) + { + NBTTagCompound nbt = IDLNBTUtil.getNBT(stack).getCompoundTag(IDLNBTDef.GUA_ENHANCE); + for (String key: nbt.getKeySet() + ) { + result += nbt.getInteger(key); + } + } + + return result; + } + + public static int GetGuaEnhanceFree(ItemStack stack) + { + return IDLNBTUtil.GetInt(stack, IDLNBTDef.GUA_FREE_SOCKET); + } + + public static void SetGuaEnhanceFree(ItemStack stack, int val) + { + IDLNBTUtil.SetInt(stack, IDLNBTDef.GUA_FREE_SOCKET, val); + } + + @SideOnly(Side.CLIENT) + public static void addInformation(ItemStack stack, World world, List tooltip, ITooltipFlag flag, + boolean shiftToShowDesc, boolean showGuaSocketDesc, boolean use_flavor, String mainDescOrFlavor) { + + boolean shiftPressed = !shiftToShowDesc || CommonFunctions.isShiftPressed(); + if (shiftPressed) + { + if (!mainDescOrFlavor.isEmpty()) + { + tooltip.add(mainDescOrFlavor); + } + + if (showGuaSocketDesc) + { + int guaTotal = IDLSkillNBT.GetGuaEnhanceTotal(stack); + tooltip.add(I18n.format(IDLNBTDef.GUA_TOTAL_SOCKET_DESC, IDLSkillNBT.GetGuaEnhanceTotal(stack))); + if (guaTotal > 0) + { + tooltip.add(I18n.format("idlframewok.gua_enhance_list.desc", GetGuaEnhanceString(stack, 0), + GetGuaEnhanceString(stack, 1), + GetGuaEnhanceString(stack, 2), + GetGuaEnhanceString(stack, 3), + GetGuaEnhanceString(stack, 4), + GetGuaEnhanceString(stack, 5), + GetGuaEnhanceString(stack, 6), + GetGuaEnhanceString(stack, 7))); + } + + int freeSockets = IDLSkillNBT.GetGuaEnhanceFree(stack); + if (freeSockets > 0) + { + tooltip.add(TextFormatting.AQUA + I18n.format(IDLNBTDef.GUA_FREE_SOCKET_DESC, freeSockets)); + } + else { + tooltip.add(TextFormatting.ITALIC + (TextFormatting.WHITE + I18n.format(IDLNBTDef.GUA_NO_FREE_SOCKET_DESC))); + } + } + } + else { + tooltip.add(TextFormatting.AQUA + I18n.format("idlframewok.shared.press_shift")); + if (use_flavor) + { + tooltip.add(TextFormatting.ITALIC + mainDescOrFlavor); + } + } + } + + public static int getLevel(ItemStack stack) + { + if (!(stack.getItem() instanceof ItemSkillBase)) { + return 0; + } + ItemSkillBase skillBase = (ItemSkillBase) stack.getItem(); + + int level = IDLNBTUtil.GetInt(stack, IDLNBTDef.LEVEL_TAG); + + if (level <= 0) + { + return 1; + } + + int lvMax = skillBase.GetLevelMax(stack); + + if (level > lvMax) + { + return lvMax; + } + + return level; + } + + public static void SetLevel(ItemStack stack, int count) + { + if (!(stack.getItem() instanceof ItemSkillBase)) { + return; + } + ItemSkillBase skillBase = (ItemSkillBase) stack.getItem(); + + if (count <= skillBase.GetLevelMax(stack)) { + IDLNBTUtil.SetInt(stack, IDLNBTDef.LEVEL_TAG, count); + } + } + + public static boolean IsCasting(ItemStack stack) + { + return IDLNBTUtil.GetBoolean(stack, IDLNBTDef.IS_CASTING); + } + + public static void SetCasting(ItemStack stack, boolean bool) + { + IDLNBTUtil.SetBoolean(stack, IDLNBTDef.IS_CASTING, bool); + } + + public static void SetDura(ItemStack stack, float count) + { + if (!(stack.getItem() instanceof ItemSkillBase)) { + return; + } + ItemSkillBase skillBase = (ItemSkillBase) stack.getItem(); + + IDLNBTUtil.SetInt(stack, IDLNBTDef.CUR_TIME_LEFT, (int) (count * CommonDef.INT_AS_FLOAT)); + } + + public static void SetCharge(ItemStack stack, float count) + { + if (!(stack.getItem() instanceof ItemSkillBase)) { + return; + } + ItemSkillBase skillBase = (ItemSkillBase) stack.getItem(); + + IDLNBTUtil.SetInt(stack, IDLNBTDef.CUR_CHARGE, (int) (count * CommonDef.INT_AS_FLOAT)); + } + + public static float GetCharge(ItemStack stack) + { + if (!(stack.getItem() instanceof ItemSkillBase)) { + return 0; + } + + int charge = IDLNBTUtil.GetInt(stack, IDLNBTDef.CUR_CHARGE); + + return (float)charge / CommonDef.INT_AS_FLOAT; + } + + public static float GetDura(ItemStack stack) + { + if (!(stack.getItem() instanceof ItemSkillBase)) { + return 0; + } + int dura = IDLNBTUtil.GetInt(stack, IDLNBTDef.CUR_TIME_LEFT); + + return (float)dura / CommonDef.INT_AS_FLOAT; + } + + public static void AddLevelByCount(ItemStack stack, int count) + { + if (!(stack.getItem() instanceof ItemSkillBase)) { + return; + } + ItemSkillBase skillBase = (ItemSkillBase) stack.getItem(); + int lvMax = skillBase.GetLevelMax(stack); + int anticipatedCount = count + getLevel(stack); + if (anticipatedCount <= lvMax ) { + IDLNBTUtil.SetInt(stack, IDLNBTDef.LEVEL_TAG, anticipatedCount); + } + else { + IDLNBTUtil.SetInt(stack, IDLNBTDef.LEVEL_TAG, lvMax); + } + } +} diff --git a/src/main/java/com/somebody/idlframewok/util/IHasModel.java b/src/main/java/com/somebody/idlframewok/util/IHasModel.java new file mode 100644 index 0000000..0577184 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/util/IHasModel.java @@ -0,0 +1,5 @@ +package com.somebody.idlframewok.util; + +public interface IHasModel { + public void registerModels(); +} diff --git a/src/main/java/com/somebody/idlframewok/util/MessageDef.java b/src/main/java/com/somebody/idlframewok/util/MessageDef.java new file mode 100644 index 0000000..1092500 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/util/MessageDef.java @@ -0,0 +1,17 @@ +package com.somebody.idlframewok.util; + +import net.minecraft.item.ItemStack; + +public class MessageDef { + //GENERAL: + public static final String OUT_OF_RANGE = "idlframewok.msg.out_of_range"; + public static final String IN_COOLDOWN = "idlframewok.skill.msg.cool_down"; + public static final String NOT_CASTABLE_MAINHAND = "idlframewok.skill.msg.not_castable_mainhand"; + public static final String NOT_CASTABLE_OFFHAND = "idlframewok.skill.msg.not_castable_offhand"; + + public static String getSkillCastKey(ItemStack stack, int index) + { + //remove"item." + return String.format("msg.%s.cast.%d", stack.getUnlocalizedName().substring(5), index); + } +} diff --git a/src/main/java/com/somebody/idlframewok/util/ModSoundHandler.java b/src/main/java/com/somebody/idlframewok/util/ModSoundHandler.java new file mode 100644 index 0000000..a121809 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/util/ModSoundHandler.java @@ -0,0 +1,25 @@ +package com.somebody.idlframewok.util; + +import java.util.ArrayList; +import java.util.List; + +import com.somebody.idlframewok.IdlFramework; +import com.somebody.idlframewok.util.sound.ModSoundEvent; +import net.minecraft.util.SoundEvent; +import net.minecraftforge.fml.common.registry.ForgeRegistries; + +public class ModSoundHandler { + //To add a sound, remember assets.idlframewok.sounds.json + public static final List SOUNDS = new ArrayList<>(); + +// public static SoundEvent SOUND_1 = new ModSoundEvent("entity.moroon.ambient"); +// public static SoundEvent SOUND_2 = new ModSoundEvent("entity.moroon.hurt"); + + public static void soundRegister() + { + IdlFramework.Log("Registering %s sounds.", SOUNDS.size()); + ForgeRegistries.SOUND_EVENTS.registerAll(ModSoundHandler.SOUNDS.toArray(new SoundEvent[0])); + IdlFramework.Log("Registered %s sounds.", SOUNDS.size()); + } + +} diff --git a/src/main/java/com/somebody/idlframewok/util/NBTStrDef/IDLNBTDef.java b/src/main/java/com/somebody/idlframewok/util/NBTStrDef/IDLNBTDef.java new file mode 100644 index 0000000..4101c22 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/util/NBTStrDef/IDLNBTDef.java @@ -0,0 +1,164 @@ +package com.somebody.idlframewok.util.NBTStrDef; + +import com.somebody.idlframewok.IdlFramework; + +public class IDLNBTDef { + //GENERAL: + public static final String IDEALLAND = "idealland_nbt"; + + //NBT + public static final String IS_EARTH = "is_earth"; + public static final String IS_SKY = "is_sky"; + + //UNO + public static final String CARD_SUIT = "card_suit"; + + //goblet + public static final String P2W_EXP = "p2w_experience"; + public static final String P2W_PAYING_EXP = "p2w_experience_paying"; + public static final String P2W_CACHE_EXP = "p2w_experience_cache"; + + //skill + public static final String LEVEL_TAG = "level"; + public static final String RANGE_BOOST = "range_boost"; + public static final String DURA_BOOST = "dura_boost"; + public static final String IS_IDENTIFIED = "identified"; + public static final String STATE = "state"; + public static final String STATE_2 = "state2"; + + public static final String IS_NAME_HIDDEN = "name_hidden"; + public static final String IS_MANUAL_READY = "manual_ready"; + public static final String OWNER = "owner"; + public static final String IS_HEIRLOOM = "heirloom_of"; + public static final String HATE = "hate"; + + //skill arknights + public static final String IS_CASTING = "is_casting"; + public static final String CUR_CHARGE = "cur_charge";//x100 + public static final String CUR_TIME_LEFT = "time_left";//x100,please note that two may be the same + + + public static final String EDICT_REPEATABLE = "is_repeatable"; + + //upgrading + public static final String DIFFICULTY = "difficulty"; + + //TOOLTIP + public static final String TOOLTIP_SKY = ".sky_desc"; + public static final String TOOLTIP_EARTH = ".earth_desc"; + public static final String TOOLTIP_NORMAL = ".normal_desc"; + public static final String TOOLTIP_SHARED = ".shared_desc"; + public static final String TOOLTIP_HIDDEN = ".hidden"; + public static final String TOOLTIP_DAMAGE = ".damage_desc"; + + public static final String NAME_OFF= "idlframewok.shared.off"; + public static final String NAME_ON= "idlframewok.shared.on"; + + public static final String TRUENAME_TO_REVEAL = ".true_name_reveal"; + public static final String MANUAL_PAGE_COUNT = ".manual_page_count"; + public static final String MANUAL_PAGE_KEY = ".manual_page_"; + public static final String MANUAL_AUTHOR = ".manual_author"; + public static final String MANUAL_TITLE = ".manual_title"; + + //player + public static final String STARTER_BOOK_GIVEN = "starter_book_given"; + + //goblet + public static final String ASSIGNED_BLOCK_NAME = "assigned_block"; + + //IDL + public static final String DESC_COMMON = ".desc"; + public static final String KILL_COUNT = "kill_count"; + public static final String KILL_COUNT_MOR = "kill_count_mor"; + public static final String MOR_INTEREST = "mor_interest"; + + public static final String CHARGE_VALUE = "charge_value"; + + public static final String BIOMETAL_WARNED = "biometal_warned"; + + public static final String MODE = "mode"; + + public static final String STARTER_KIT_VERSION_TAG = "last_starter_kit_" + IdlFramework.MODID; + public static final int CUR_STARTER_KIT_VERSION = 2; + + //edict + public static final String EDICT_START = ".on_start"; + public static final String EDICT_END= ".on_end"; + public static final String EDICT_FAIL = ".on_fail"; + + public static final String EDICT_COMMON_START = "edict.shared.start"; + public static final String EDICT_COMMON_END = "edict.shared.end"; + public static final String EDICT_COMMON_FAIL = "edict.shared.fail"; + + + public static final String EDICT_COMMON_REPEAT = "edict.shared.repeatable"; + + //Builder + public static final String CUR_TASK_INDEX = "cur_task_index"; + public static final String BUILD_SPEED = "build_speed"; + public static final String BUILD_ARG_1 = "build_arg_1"; + public static final String BUILD_ARG_2 = "build_arg_2"; + + //gua socket + public static final String GUA_NO_FREE_SOCKET_DESC = "idlframewok.gua_enhance_no_free.desc"; + public static final String GUA_FREE_SOCKET_DESC = "idlframewok.gua_enhance_free.desc"; + public static final String GUA_TOTAL_SOCKET_DESC = "idlframewok.gua_enhance_total.desc"; + public static final String GUA_N_A_DESC = "idlframewok.gua_not_applicable.desc"; + + public static final String GUA_FREE_SOCKET = "gua_free_socket"; + public static final String GUA_ENHANCE = "gua_enhance"; + public static final String GUA_ENHANCE_8 = "gua_e_8"; + public static final String GUA_ENHANCE_64 = "gua_e_64"; + + //anchor + public static final String ANCHOR_READY = "anchor_ready"; + public static final String ANCHOR_X = "anchor_x"; + public static final String ANCHOR_Y = "anchor_y"; + public static final String ANCHOR_Z = "anchor_z"; + + public static final String ANCHOR_READY_2 = "anchor_ready_2"; + public static final String ANCHOR_X_2 = "anchor_x_2"; + public static final String ANCHOR_Y_2 = "anchor_y_2"; + public static final String ANCHOR_Z_2 = "anchor_z_2"; + + public static final String BUILDING_CHARGE = "building_charge"; + + //research + public static final String PACK_CODE = "pack_code"; + public static final String LEARNING_ID = "learning_id"; + public static final String LEARNING_PROGRESS = "learning_progress"; + public static final String LEARNING_DONE = "learning_done"; + + //temperature + public static final String BASE_TEMPERATURE = "base_temperature"; + public static final String BASE_IS_SET = "base_is_set"; + + //level + public static final String LAST_LEVEL = "last_lv"; + + public static final String LEVEL = "lv_idl"; + + public static final String INIT_DONE = "init_done"; + + + //nonsense + public static final String KILL_COUNT_ITEM = "kill_count";//marked on items, not players + public static final String KILL_COUNT_DESC = "idlframewok.kill_count.desc"; + + public static final String MARKING_POS_A = "marking_pos_a"; + public static final String MARKING_POS_B = "marking_pos_b"; + + public static final String MARK_ATK = "mark.attackDamage"; + public static final String MARK_HP = "mark.maxHealth"; + public static final String MARK_DEF = "mark.armor"; + public static final String MARK_ARMOR_T = "mark.armorToughness"; + public static final String MARK_RANGE = "mark.followRange"; + public static final String MARK_KB_R = "mark.knockbackResistance"; + public static final String MARK_SPEED = "mark.movementSpeed"; + public static final String MARK_ATK_SPEED = "mark.attackSpeed"; + + public static final String MARK_TOTAL_COUNT = "mark.count"; + + + public static final String FLAVOR_KEY = ".flvr"; +} diff --git a/src/main/java/com/somebody/idlframewok/util/NBTStrDef/IDLNBTUtil.java b/src/main/java/com/somebody/idlframewok/util/NBTStrDef/IDLNBTUtil.java new file mode 100644 index 0000000..78cf636 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/util/NBTStrDef/IDLNBTUtil.java @@ -0,0 +1,558 @@ +package com.somebody.idlframewok.util.NBTStrDef; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import javax.annotation.Nullable; + +import com.somebody.idlframewok.IdlFramework; +import com.somebody.idlframewok.util.IDLNBT; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.math.BlockPos; + +import static com.somebody.idlframewok.util.NBTStrDef.IDLNBTDef.*; + +//on a server, strlen 65000 is ok, but 66000 will crash +public class IDLNBTUtil { + public static NBTTagCompound getNBT(ItemStack stack) + { + NBTTagCompound nbt = stack.getTagCompound(); + if (nbt == null) + { + nbt = new NBTTagCompound(); + stack.setTagCompound(nbt); + } + return nbt; + } + + //so it won't produce empty tags + public static NBTTagCompound getNBTReadOnly(ItemStack stack) { + NBTTagCompound nbt = stack.getTagCompound(); + if (nbt == null) { + return new NBTTagCompound(); + } + return nbt; + } + + public static NBTTagCompound getNBT(Entity entity) { + NBTTagCompound nbt = entity.getEntityData(); + return nbt; + } + + //allow null + public static NBTTagCompound getNBT(NBTTagCompound tag) { + if(tag == null) { + return new NBTTagCompound(); + } + + return tag; + } + + //writeEntityToNBT + //readEntityFromNBT + + @Nullable + public static boolean StackHasKey(ItemStack stack, String key) { + return !(stack.isEmpty() || !getNBTReadOnly(stack).hasKey(key)); + } + + //Boolean + public static boolean SetBoolean(ItemStack stack, String key, boolean value) + { + NBTTagCompound nbt = getNBT(stack); + nbt.setBoolean(key, value); + return true; + } + + public static boolean GetBoolean(ItemStack stack, String key, boolean defaultVal) + { + if (StackHasKey(stack, key)) + { + NBTTagCompound nbt = getNBTReadOnly(stack); + return nbt.getBoolean(key); + } + else + { + return defaultVal; + } + } + + public static boolean GetBoolean(ItemStack stack, String key) + { + if (StackHasKey(stack, key)) + { + NBTTagCompound nbt = getNBTReadOnly(stack); + return nbt.getBoolean(key); + } + else + { + return false; + } + } + //get with default val + public static boolean GetBooleanDF(ItemStack stack, String key, boolean defaultVal) + { + if (StackHasKey(stack, key)) + { + NBTTagCompound nbt = getNBTReadOnly(stack); + return nbt.getBoolean(key); + } + else + { + return defaultVal; + } + } + + //Double + public static boolean SetDouble(ItemStack stack, String key, double value) + { + NBTTagCompound nbt = getNBT(stack); + nbt.setDouble(key, value); + return true; + } + + public static double GetDouble(ItemStack stack, String key, double defaultVal) + { + if (StackHasKey(stack, key)) + { + NBTTagCompound nbt = getNBTReadOnly(stack); + return nbt.getDouble(key); + } + else + { + return defaultVal; + } + } + + //Integer + public static boolean SetLong(ItemStack stack, String key, long value) + { + NBTTagCompound nbt = getNBT(stack); + nbt.setLong(key, value); + return true; + } + + public static boolean SetState(ItemStack stack, int value) + { + return SetInt(stack, STATE, value); + } + public static boolean SetState2(ItemStack stack, int value) + { + return SetInt(stack, STATE_2, value); + } + + public static boolean SetInt(ItemStack stack, String key, int value) + { + NBTTagCompound nbt = getNBT(stack); + nbt.setInteger(key, value); + return true; + } + //Used for state on-off things. + public static boolean switchState(ItemStack stack) + { + NBTTagCompound nbt = getNBT(stack); + nbt.setInteger(STATE, nbt.getInteger(STATE) > 0 ? 0 : 1); + return true; + } + + public static boolean setIntOptimized(ItemStack stack, String key, int value) + { + NBTTagCompound nbt = getNBT(stack); + if (nbt.getInteger(key) != value) + { + nbt.setInteger(key, value); + } + return true; + } + public static boolean SetInt(Entity entity, String key, int value) + { + NBTTagCompound nbt = getNBT(entity); + nbt.setInteger(key, value); + return true; + } + + public static boolean setIntAuto(Entity entity, String key, int value) + { + if (entity instanceof EntityPlayer) + { + setPlayerIdeallandTagSafe((EntityPlayer) entity, key, value); + return true; + } + NBTTagCompound nbt = getNBT(entity); + nbt.setInteger(key, value); + return true; + } + + public static boolean addIntAuto(Entity entity, String key, int value) + { + int oldVal = GetIntAuto(entity, key, 0); + setIntAuto(entity, key, value + oldVal); + return true; + } + + public static boolean addInt(ItemStack stack, String key, int value) { + int oldVal = GetInt(stack, key, 0); + SetInt(stack, key, value + oldVal); + return true; + } + + public static int GetInt(Entity entity, String key, int defaultVal) + { + if (EntityHasKey(entity, key)) + { + NBTTagCompound nbt = getNBT(entity); + return nbt.getInteger(key); + } + else + { + return defaultVal; + } + } + + public static int GetIntAuto(Entity entity, String key, int defaultVal) + { + if (entity instanceof EntityPlayer) + { + return getPlayerIdeallandIntSafe((EntityPlayer) entity, key); + } + + if (EntityHasKey(entity, key)) + { + NBTTagCompound nbt = getNBT(entity); + return nbt.getInteger(key); + } + else + { + return defaultVal; + } + } + + public static int GetState(ItemStack stack) + { + return GetInt(stack, STATE); + } + + public static int GetState2(ItemStack stack) + { + return GetInt(stack, STATE_2); + } + + public static int GetInt(ItemStack stack, String key, int defaultVal) + { + if (StackHasKey(stack, key)) + { + NBTTagCompound nbt = getNBTReadOnly(stack); + return nbt.getInteger(key); + } + else + { + return defaultVal; + } + } + + public static long GetLong(ItemStack stack, String key, int defaultVal) + { + if (StackHasKey(stack, key)) + { + NBTTagCompound nbt = getNBTReadOnly(stack); + return nbt.getLong(key); + } + else + { + return defaultVal; + } + } + + + public static int GetInt(ItemStack stack, String key) + { + return GetInt(stack, key, 0); + } + + //String + public static String GetString(ItemStack stack, String key, String defaultVal) + { + if (StackHasKey(stack, key)) + { + NBTTagCompound nbt = getNBTReadOnly(stack); + return nbt.getString(key); + } + else + { + return defaultVal; + } + } + + public static boolean SetString(ItemStack stack, String key, String value) + { + NBTTagCompound nbt = getNBT(stack); + nbt.setString(key, value); + + return true; + } + + + //entity + @Nullable + public static boolean EntityHasKey(Entity entity, String key) + { + return getNBT(entity).hasKey(key); + } + + //Boolean + public static boolean GetBoolean(Entity entity, String key, boolean defaultVal) + { + if (EntityHasKey(entity, key)) + { + NBTTagCompound nbt = getNBT(entity); + return nbt.getBoolean(key); + } + else + { + return defaultVal; + } + } + + public static boolean SetBoolean(Entity stack, String key, boolean value) + { + NBTTagCompound nbt = getNBT(stack); + nbt.setBoolean(key, value); + return true; + } + + public static boolean SetString(Entity stack, String key, String value) + { + NBTTagCompound nbt = getNBT(stack); + nbt.setString(key, value); + return true; + } + + public static int[] GetIntArray(ItemStack stack, String key) + { + if (StackHasKey(stack, key)) + { + NBTTagCompound nbt = getNBTReadOnly(stack); + return nbt.getIntArray(key); + } + else + { + return new int[0]; + } + } + + public static int[] GetIntArray(EntityLivingBase stack, String key) + { + if (EntityHasKey(stack, key)) + { + NBTTagCompound nbt = getNBT(stack); + return nbt.getIntArray(key); + } + else + { + return new int[0]; + } + } + + public static void SetIntArray(ItemStack stack, String key, int[] array) + { + NBTTagCompound nbt = getNBT(stack); + nbt.setIntArray(key, array); + } + + public static void SetGuaEnhanceFree(ItemStack stack, int val) + { + SetInt(stack, IDLNBTDef.GUA_FREE_SOCKET, val); + } + + public static boolean GetIsLearned(EntityPlayer player, int skillID) + { + int[] learnt = IDLNBT.getPlayerIdeallandIntArraySafe(player, IDLNBTDef.STARTER_KIT_VERSION_TAG); + if (Arrays.binarySearch(learnt, skillID) >= 0) + { + return true; + } + return false; + } + + public static void SetIsLearned(EntityPlayer player, int skillID, boolean val) + { + int[] learnt = IDLNBT.getPlayerIdeallandIntArraySafe(player, IDLNBTDef.LEARNING_DONE); + int oldIndex = Arrays.binarySearch(learnt, skillID); + if (oldIndex >= 0) + { + if (val) + { + return; + }else { + //todo: remove it + + } + }else { + if (val) + { + ArrayList list = new ArrayList(); + for (int oldID: + learnt + ) { + list.add(oldID); + } + list.add(skillID); + Collections.sort(list); + + int[] newLearnt = list.stream().mapToInt(Integer::valueOf).toArray(); + IDLNBT.setPlayerIdeallandTagSafe(player, IDLNBTDef.LEARNING_DONE, newLearnt); + }else { + return; + } + } + } + //-------------------------------------------- + + + + public static BlockPos getMarkedPos(ItemStack stack) + { + NBTTagCompound NBT = IDLNBTUtil.getNBTReadOnly(stack); + return new BlockPos(NBT.getDouble(IDLNBTDef.ANCHOR_X), NBT.getDouble(IDLNBTDef.ANCHOR_Y), NBT.getDouble(IDLNBTDef.ANCHOR_Z)); + } + + public static BlockPos getMarkedPos2(ItemStack stack) + { + NBTTagCompound NBT = IDLNBTUtil.getNBTReadOnly(stack); + return new BlockPos(NBT.getDouble(IDLNBTDef.ANCHOR_X_2), NBT.getDouble(IDLNBTDef.ANCHOR_Y_2), NBT.getDouble(IDLNBTDef.ANCHOR_Z_2)); + } + + public static void markPosToStack(ItemStack stack, BlockPos pos) + { + IDLNBTUtil.SetBoolean(stack, IDLNBTDef.ANCHOR_READY, true); + IDLNBTUtil.SetDouble(stack, IDLNBTDef.ANCHOR_X, pos.getX()); + IDLNBTUtil.SetDouble(stack, IDLNBTDef.ANCHOR_Y, pos.getY()); + IDLNBTUtil.SetDouble(stack, IDLNBTDef.ANCHOR_Z, pos.getZ()); + } + + public static void markPosToStack2(ItemStack stack, BlockPos pos) + { + IDLNBTUtil.SetBoolean(stack, IDLNBTDef.ANCHOR_READY_2, true); + IDLNBTUtil.SetDouble(stack, IDLNBTDef.ANCHOR_X_2, pos.getX()); + IDLNBTUtil.SetDouble(stack, IDLNBTDef.ANCHOR_Y_2, pos.getY()); + IDLNBTUtil.SetDouble(stack, IDLNBTDef.ANCHOR_Z_2, pos.getZ()); + } + + public static NBTTagCompound getTagSafe(NBTTagCompound tag, String key) { + if (tag == null) { + return new NBTTagCompound(); + } + + return tag.getCompoundTag(key); + } + + public static NBTTagCompound getPlyrIdlTagSafe(EntityPlayer player) { + NBTTagCompound playerData = player.getEntityData(); + NBTTagCompound data = getTagSafe(playerData, EntityPlayer.PERSISTED_NBT_TAG); + NBTTagCompound idl_data = getTagSafe(data, IdlFramework.MODID); + + return idl_data; + } + + public static NBTTagCompound getPlayerIdeallandTagGroupSafe(EntityPlayer player, String key) { + return getPlyrIdlTagSafe(player).getCompoundTag(key); + } + + public static int[] getPlayerIdeallandIntArraySafe(EntityPlayer player, String key) { + return getPlyrIdlTagSafe(player).getIntArray(key); + } + + public static long getPlayerIdeallandLongSafe(EntityPlayer player, String key) { + return getPlyrIdlTagSafe(player).getLong(key); + } + + public static int getPlayerIdeallandIntSafe(EntityPlayer player, String key) { + return getPlyrIdlTagSafe(player).getInteger(key); + } + + public static float getPlayerIdeallandFloatSafe(EntityPlayer player, String key) { + return getPlyrIdlTagSafe(player).getFloat(key); + } + + public static double getPlayerIdeallandDoubleSafe(EntityPlayer player, String key) { + return getPlyrIdlTagSafe(player).getDouble(key); + } + + public static boolean getPlayerIdeallandBoolSafe(EntityPlayer player, String key) { + return getPlyrIdlTagSafe(player).getBoolean(key); + } + + public static String getPlayerIdeallandStrSafe(EntityPlayer player, String key) { + return getPlyrIdlTagSafe(player).getString(key); + } + + public static void setPlayerIdeallandTagSafe(EntityPlayer player, String key, int value) { + NBTTagCompound playerData = player.getEntityData(); + NBTTagCompound data = getTagSafe(playerData, EntityPlayer.PERSISTED_NBT_TAG); + NBTTagCompound idl_data = getPlyrIdlTagSafe(player); + + idl_data.setInteger(key, value); + + data.setTag(IDEALLAND, idl_data); + playerData.setTag(EntityPlayer.PERSISTED_NBT_TAG, data); + } + + public static void setPlayerIdeallandTagSafe(EntityPlayer player, String key, int[] value) { + NBTTagCompound playerData = player.getEntityData(); + NBTTagCompound data = getTagSafe(playerData, EntityPlayer.PERSISTED_NBT_TAG); + NBTTagCompound idl_data = getPlyrIdlTagSafe(player); + + idl_data.setIntArray(key, value); + + data.setTag(IDEALLAND, idl_data); + playerData.setTag(EntityPlayer.PERSISTED_NBT_TAG, data); + } + + public static void setPlayerIdeallandTagSafe(EntityPlayer player, String key, double value) { + NBTTagCompound playerData = player.getEntityData(); + NBTTagCompound data = getTagSafe(playerData, EntityPlayer.PERSISTED_NBT_TAG); + NBTTagCompound idl_data = getPlyrIdlTagSafe(player); + + idl_data.setDouble(key, value); + + data.setTag(IDEALLAND, idl_data); + playerData.setTag(EntityPlayer.PERSISTED_NBT_TAG, data); + } + + public static void setPlayerIdeallandTagSafe(EntityPlayer player, String key, long value) { + NBTTagCompound playerData = player.getEntityData(); + NBTTagCompound data = getTagSafe(playerData, EntityPlayer.PERSISTED_NBT_TAG); + NBTTagCompound idl_data = getPlyrIdlTagSafe(player); + + idl_data.setLong(key, value); + + data.setTag(IDEALLAND, idl_data); + playerData.setTag(EntityPlayer.PERSISTED_NBT_TAG, data); + } + + public static void setPlayerIdeallandTagSafe(EntityPlayer player, String key, boolean value) { + NBTTagCompound playerData = player.getEntityData(); + NBTTagCompound data = getTagSafe(playerData, EntityPlayer.PERSISTED_NBT_TAG); + NBTTagCompound idl_data = getPlyrIdlTagSafe(player); + + idl_data.setBoolean(key, value); + + data.setTag(IDEALLAND, idl_data); + playerData.setTag(EntityPlayer.PERSISTED_NBT_TAG, data); + } + + public static void setPlayerIdeallandTagSafe(EntityPlayer player, String key, String value) { + NBTTagCompound playerData = player.getEntityData(); + NBTTagCompound data = getTagSafe(playerData, EntityPlayer.PERSISTED_NBT_TAG); + NBTTagCompound idl_data = getPlyrIdlTagSafe(player); + + idl_data.setString(key, value); + + data.setTag(IDEALLAND, idl_data); + playerData.setTag(EntityPlayer.PERSISTED_NBT_TAG, data); + } +} diff --git a/src/main/java/com/somebody/idlframewok/util/PlayerUtil.java b/src/main/java/com/somebody/idlframewok/util/PlayerUtil.java new file mode 100644 index 0000000..ff9e1e0 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/util/PlayerUtil.java @@ -0,0 +1,80 @@ +package com.somebody.idlframewok.util; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; + +public class PlayerUtil { + public static int FindItemInIvtrGeneralized(EntityPlayer player, Class itemClass) + { + for (int i = 0; i < player.inventory.getSizeInventory(); ++i) { + ItemStack itemstack = player.inventory.getStackInSlot(i); + { + //itemClass.getClass(); + if (itemClass.isAssignableFrom(itemstack.getItem().getClass())) + { + return i; + } + } + } + return -1; + } + + public static ItemStack FindStackInIvtrGeneralized(EntityPlayer player, Class itemClass) + { + for (int i = 0; i < player.inventory.getSizeInventory(); ++i) { + ItemStack itemstack = player.inventory.getStackInSlot(i); + { + //itemClass.getClass(); + if (itemClass.isAssignableFrom(itemstack.getItem().getClass())) + { + return itemstack; + } + } + } + return ItemStack.EMPTY; + } + + public static int FindItemInIvtr(EntityPlayer player, Item item) + { + for (int i = 0; i < player.inventory.getSizeInventory(); ++i) { + ItemStack itemstack = player.inventory.getStackInSlot(i); + { + if (itemstack.getItem() == item) + { + return i; + } + } + } + return -1; + } + + public static ItemStack FindStackInIvtr(EntityPlayer player, Item item) + { + for (int i = 0; i < player.inventory.getSizeInventory(); ++i) { + ItemStack itemstack = player.inventory.getStackInSlot(i); + { + if (itemstack.getItem() == item) + { + return itemstack; + } + } + } + return ItemStack.EMPTY; + } + + public static boolean isCreative(EntityPlayer player) + { + return player.capabilities.isCreativeMode; + } + + public static boolean giveToPlayer(EntityPlayer player, ItemStack stack) + { + boolean result = player.addItemStackToInventory(stack); + if (!result) + { + player.dropItem(stack, false); + } + return result; + } +} diff --git a/src/main/java/com/somebody/idlframewok/util/Reference.java b/src/main/java/com/somebody/idlframewok/util/Reference.java new file mode 100644 index 0000000..493b288 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/util/Reference.java @@ -0,0 +1,10 @@ +package com.somebody.idlframewok.util; + +import com.somebody.idlframewok.IdlFramework; + +public class Reference { + public static final String MOD_ID = IdlFramework.MODID; + public static final String CLIENT_PROXY_CLASS = "com.somebody.idlframewok.proxy.ClientProxy"; + public static final String SERVER_PROXY_CLASS = "com.somebody.idlframewok.proxy.ServerProxy"; + +} diff --git a/src/main/java/com/somebody/idlframewok/util/StringUtil.java b/src/main/java/com/somebody/idlframewok/util/StringUtil.java new file mode 100644 index 0000000..f1ef5d2 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/util/StringUtil.java @@ -0,0 +1,10 @@ +package com.somebody.idlframewok.util; + +import net.minecraft.util.text.ITextComponent; +import net.minecraft.util.text.TextComponentTranslation; + +public class StringUtil { + public static ITextComponent getLocale(String key) { + return new TextComponentTranslation(key); + } +} diff --git a/src/main/java/com/somebody/idlframewok/util/Teleport.java b/src/main/java/com/somebody/idlframewok/util/Teleport.java new file mode 100644 index 0000000..d96a4ab --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/util/Teleport.java @@ -0,0 +1,52 @@ +package com.somebody.idlframewok.util; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.server.MinecraftServer; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.Teleporter; +import net.minecraft.world.WorldServer; + +public class Teleport extends Teleporter { + private final WorldServer worldServer; + private double x,y,z; + + public Teleport(WorldServer worldServer, double x, double y, double z) { + super(worldServer); + this.worldServer = worldServer; + this.x = x; + this.y = y; + this.z = z; + } + + @Override + public void placeInPortal(Entity entityIn, float rotationYaw) { + worldServer.getBlockState(new BlockPos(x,y,z)); + entityIn.setPosition(x,y,z); + entityIn.motionX = 0f; + entityIn.motionY = 0f; + entityIn.motionZ = 0f; + + } + + public static void teleportToDim(EntityPlayer player, int dimension, double x, double y, double z) + { + int oldDim = player.getEntityWorld().provider.getDimension(); + EntityPlayerMP entityPlayerMP = (EntityPlayerMP) player; + MinecraftServer server = player.getEntityWorld().getMinecraftServer(); + if (server == null) + { + throw new IllegalArgumentException("Player status incorrect"); + } + + WorldServer worldServerNew = server.getWorld(dimension); + if (worldServerNew == null) + { + throw new IllegalArgumentException(String.format("[IDL]Teleporting dimension: %d does not exist", dimension)); + } + + worldServerNew.getMinecraftServer().getPlayerList().transferPlayerToDimension(entityPlayerMP, dimension, new Teleport(worldServerNew, x,y,z)); + player.setPositionAndUpdate(x,y,z); + } +} diff --git a/src/main/java/com/somebody/idlframewok/util/sound/ModSoundEvent.java b/src/main/java/com/somebody/idlframewok/util/sound/ModSoundEvent.java new file mode 100644 index 0000000..6a35867 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/util/sound/ModSoundEvent.java @@ -0,0 +1,14 @@ +package com.somebody.idlframewok.util.sound; + +import com.somebody.idlframewok.util.ModSoundHandler; +import com.somebody.idlframewok.util.Reference; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.SoundEvent; + +public class ModSoundEvent extends SoundEvent { + public ModSoundEvent(String path) { + super(new ResourceLocation(Reference.MOD_ID, path)); + ModSoundHandler.SOUNDS.add(this); + setRegistryName(path); + } +} diff --git a/src/main/java/com/somebody/idlframewok/world/biome/BiomeForDimOne.java b/src/main/java/com/somebody/idlframewok/world/biome/BiomeForDimOne.java new file mode 100644 index 0000000..8ccb022 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/world/biome/BiomeForDimOne.java @@ -0,0 +1,43 @@ +package com.somebody.idlframewok.world.biome; + +import java.util.Random; + +import net.minecraft.init.Blocks; +import net.minecraft.world.biome.Biome; +import net.minecraft.world.gen.feature.WorldGenAbstractTree; +import net.minecraft.world.gen.feature.WorldGenBigTree; +import net.minecraft.world.gen.feature.WorldGenMinable; + +public class BiomeForDimOne extends Biome { + + protected static final WorldGenAbstractTree TREE = new WorldGenBigTree(false); + + public BiomeForDimOne() { + super(new BiomeProperties("biome_one").setBaseHeight(-1.5f).setHeightVariation(1.2f).setTemperature(0.5f).setWaterColor(0xff3333)); + + topBlock = Blocks.PUMPKIN.getDefaultState(); + fillerBlock = Blocks.GOLD_BLOCK.getDefaultState(); + + decorator.coalGen = new WorldGenMinable(Blocks.PLANKS.getDefaultState(), 10); + + decorator.treesPerChunk = 2; + + this.spawnableCreatureList.clear(); + this.spawnableCaveCreatureList.clear(); + this.spawnableMonsterList.clear(); + this.spawnableWaterCreatureList.clear(); + + // this.spawnableCreatureList.add(new SpawnListEntry(EntityGhast.class, 5, 1,2)); + } + + public BiomeForDimOne(BiomeProperties properties) { + super(properties); + } + + + @Override + public WorldGenAbstractTree getRandomTreeFeature(Random random) + { + return TREE; + } +} diff --git a/src/main/java/com/somebody/idlframewok/world/biome/BiomeOne.java b/src/main/java/com/somebody/idlframewok/world/biome/BiomeOne.java new file mode 100644 index 0000000..df81ad5 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/world/biome/BiomeOne.java @@ -0,0 +1,44 @@ +package com.somebody.idlframewok.world.biome; + +import java.util.Random; + +import net.minecraft.entity.monster.EntityGhast; +import net.minecraft.init.Blocks; +import net.minecraft.world.biome.Biome; +import net.minecraft.world.gen.feature.WorldGenAbstractTree; +import net.minecraft.world.gen.feature.WorldGenBigTree; +import net.minecraft.world.gen.feature.WorldGenMinable; + +public class BiomeOne extends Biome { + + protected static final WorldGenAbstractTree TREE = new WorldGenBigTree(false); + + public BiomeOne() { + super(new BiomeProperties("biome_one").setBaseHeight(-1.5f).setHeightVariation(1.2f).setTemperature(0.5f).setWaterColor(0xff3333)); + + topBlock = Blocks.BOOKSHELF.getDefaultState(); + fillerBlock = Blocks.BRICK_BLOCK.getDefaultState(); + + decorator.coalGen = new WorldGenMinable(Blocks.PLANKS.getDefaultState(), 10); + + decorator.treesPerChunk = 2; + + this.spawnableCreatureList.clear(); + this.spawnableCaveCreatureList.clear(); + this.spawnableMonsterList.clear(); + this.spawnableWaterCreatureList.clear(); + + this.spawnableCreatureList.add(new SpawnListEntry(EntityGhast.class, 5, 1,2)); + } + + public BiomeOne(BiomeProperties properties) { + super(properties); + } + + + @Override + public WorldGenAbstractTree getRandomTreeFeature(Random random) + { + return TREE; + } +} diff --git a/src/main/java/com/somebody/idlframewok/world/dimension/DimensionOne.java b/src/main/java/com/somebody/idlframewok/world/dimension/DimensionOne.java new file mode 100644 index 0000000..d667f02 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/world/dimension/DimensionOne.java @@ -0,0 +1,37 @@ +package com.somebody.idlframewok.world.dimension; + +import com.somebody.idlframewok.world.dimension.hexcube.ChunkGeneratorHexCube16; +import net.minecraft.world.DimensionType; +import net.minecraft.world.WorldProvider; +import net.minecraft.world.gen.IChunkGenerator; + +public class DimensionOne extends WorldProvider { + + public DimensionOne() { + //this.biomeProvider = new BiomeProviderSingle(InitBiome.BIOME_ONE); + hasSkyLight = false; + } + + @Override + public DimensionType getDimensionType() { + return DimensionType.NETHER; + //return InitDimension.DIM_ONE; + } + + @Override + public IChunkGenerator createChunkGenerator() { + return new ChunkGeneratorHexCube16( world, true, world.getSeed()); + } + + @Override + public boolean canRespawnHere() { + return false; + } + + @Override + public boolean isSurfaceWorld() { + return false; + } + + +} diff --git a/src/main/java/com/somebody/idlframewok/world/dimension/hexcube/ChunkGeneratorHexCube16.java b/src/main/java/com/somebody/idlframewok/world/dimension/hexcube/ChunkGeneratorHexCube16.java new file mode 100644 index 0000000..8c4c170 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/world/dimension/hexcube/ChunkGeneratorHexCube16.java @@ -0,0 +1,390 @@ +package com.somebody.idlframewok.world.dimension.hexcube; + +import java.util.List; +import java.util.Random; +import javax.annotation.Nullable; + +import com.somebody.idlframewok.util.CommonDef; +import com.somebody.idlframewok.world.dimension.hexcube.structure.GenCubeBase; +import com.somebody.idlframewok.world.dimension.hexcube.structure.GenCubeSoilRoom; +import com.somebody.idlframewok.world.dimension.hexcube.structure.GenCubeTorchRoom; +import com.somebody.idlframewok.world.dimension.hexcube.structure.GenCubeTreasure; +import com.somebody.idlframewok.world.dimension.hexcube.structure.GenCubeWoodRoom; +import net.minecraft.block.BlockColored; +import net.minecraft.block.state.IBlockState; +import net.minecraft.entity.EnumCreatureType; +import net.minecraft.init.Biomes; +import net.minecraft.init.Blocks; +import net.minecraft.item.EnumDyeColor; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.minecraft.world.biome.Biome; +import net.minecraft.world.chunk.Chunk; +import net.minecraft.world.chunk.ChunkPrimer; +import net.minecraft.world.gen.IChunkGenerator; + +public class ChunkGeneratorHexCube16 implements IChunkGenerator { + + private static final int heightLimit = 255; + //private static final int yNoGateLimit = 255; + + private final World world; + private final boolean generateStructures; + private final Random rand; + + + public ChunkGeneratorHexCube16(World world, boolean generate, long seed) { + this.world = world; + this.generateStructures = generate; + this.rand = new Random(seed); + world.setSeaLevel(63); + } + + private static final EnumDyeColor[] colorByDiff = + { + EnumDyeColor.WHITE,//0 + EnumDyeColor.LIME,//1 + EnumDyeColor.CYAN,//3 + EnumDyeColor.GRAY,//4 + EnumDyeColor.YELLOW,//5 + EnumDyeColor.PINK,//7 + EnumDyeColor.ORANGE,//6 + EnumDyeColor.RED,//8 + }; + + public IBlockState getWall(int x, int y, int z) + { + float difficulty = HexCubeHelper.getDifficulty(x,y,z); + + int diffInt = (int) difficulty; + if (diffInt <= colorByDiff.length) + { + EnumDyeColor color = getColorForPos(x, y, z); + + return Blocks.CONCRETE.getDefaultState().withProperty(BlockColored.COLOR, color); + } + + return Blocks.OBSIDIAN.getDefaultState(); + } + + EnumDyeColor getColorForPos(int x, int y, int z) + { + float difficulty = HexCubeHelper.getDifficulty(x,y,z); + + int diffInt = (int) difficulty; + + return colorByDiff[diffInt % colorByDiff.length]; + } + + + public IBlockState getWall() + { + return getWall(0,0,0); + } + + float getLightChance(int x, int y, int z) + { + return Math.max(1f - ((x+z)>>4) * 0.01f - (y>>4) * 0.1f, 0.01f); + } + + boolean chunkUsed(int x, int z) + { + return (x != 0 && z != 0); + } + + public void buildChunk(int x, int z, ChunkPrimer primer) { + + if (chunkUsed(x, z)) { + for (int y = 0; y < heightLimit; y+= CommonDef.CHUNK_SIZE) { + genCubeHalf(primer, x, y, z); + } + } + + if (this.generateStructures) + { + + } + + GenerateFloor(primer); + } + + private void GenerateFloor(ChunkPrimer primer) { + for (int dx = 0; dx < CommonDef.CHUNK_SIZE; dx++) + { + //for (int dy = 0; dy < CommonDef.CHUNK_SIZE; dy++) + { + for (int dz = 0; dz < CommonDef.CHUNK_SIZE; dz++) + { + //BlockPos curPos = new BlockPos(x+dx, y+dy, z+dz); + primer.setBlockState(dx, 0, dz, + Blocks.BEDROCK.getDefaultState()); +// primer.setBlockState(dx, heightLimit, dz, +// Blocks.BEDROCK.getDefaultState()); + + } + } + } + } + + void setSeedFor(int x, int y, int z) + { + rand.setSeed((long)x * 341873128712L + (long)z * 132897987541L + (long)y * 438951276L); + } + + public boolean hasLight(int x, int y, int z) + { + setSeedFor(x, y, z); + return rand.nextFloat() < getLightChance(x, y, z); + } + + void genCubeHalf(ChunkPrimer primer, int x, int y, int z) + { + setSeedFor(x, y, z); + boolean hasDoorX = rand.nextBoolean(); + boolean hasDoorY = y != 0 && rand.nextBoolean();//wont fall to void + boolean hasDoorZ = rand.nextBoolean(); + + //Make sure at least one door + if (!(hasDoorX || hasDoorY || hasDoorZ)) + { + if (rand.nextBoolean()) { + hasDoorX = true; + } else + { + hasDoorZ = true; + } + } + + boolean hasLight = hasLight(x, y, z); + + IBlockState wallState = getWall(x, y, z); + for (int dx = 0; dx < CommonDef.CHUNK_SIZE; dx++) + { + for (int dy = 0; dy < CommonDef.CHUNK_SIZE; dy++) + { + for (int dz = 0; dz < CommonDef.CHUNK_SIZE; dz++) + { + //BlockPos curPos = new BlockPos(x+dx, y+dy, z+dz); + + if (dx==0 || dy==0 || dz==0) + { + primer.setBlockState(dx, y+dy, dz, + wallState); + } + } + } + } + + genDoorAndLight(primer,x, y,z, hasDoorX, hasDoorY, hasDoorZ, hasLight); + +// BlockPos boxFace = new BlockPos(15,15,15); +// primer.setBlockState(2, 2, 2, +// Blocks.CHEST.correctFacing(world, boxFace, Blocks.CHEST.getDefaultState())); +// TileEntity tileentity1 = world.getTileEntity(blockpos2); +// +// if (tileentity1 instanceof TileEntityChest) +// { +// ((TileEntityChest)tileentity1).setLootTable(LootTableList.CHESTS_SIMPLE_DUNGEON, rand.nextLong()); +// } + + } + + private void genDoorAndLight(ChunkPrimer primer, int x, int y, int z, boolean hasDoorX, boolean hasDoorY, boolean hasDoorZ, boolean hasLight) { + int xL = 7; + int xR = 9; + + int y1 = 1; + int y2 = 3; + + EnumDyeColor color = getColorForPos(x, y, z); + + IBlockState doorStateXZ=Blocks.STAINED_GLASS_PANE.getDefaultState().withProperty(BlockColored.COLOR, color); + if (hasDoorX) + { + for (int dx = xL; dx<=xR; dx++) + { + for (int dy = y1; dy<=y2; dy++) + { + primer.setBlockState(dx, y+dy, 0, + doorStateXZ); + } + } + } + + if (hasDoorZ) + { + for (int dz = xL; dz<=xR; dz++) + { + for (int dy = y1; dy<=y2; dy++) + { + primer.setBlockState(0, y+dy, dz, + doorStateXZ); + } + } + } + + IBlockState doorStateY =Blocks.STAINED_GLASS.getDefaultState().withProperty(BlockColored.COLOR, color); + + if (hasDoorY) + { + for (int dz = xL; dz<=xR; dz++) + { + for (int dx = xL; dx<=xR; dx++) + { + primer.setBlockState(dx, y, dz, + doorStateY); + } + } + } + + if (hasLight) + { + int min = 1; + int max = CommonDef.CHUNK_SIZE -1; + primer.setBlockState(min, y+min, min, Blocks.LIT_REDSTONE_LAMP.getDefaultState()); + primer.setBlockState(min, y+min, max, Blocks.LIT_REDSTONE_LAMP.getDefaultState()); + primer.setBlockState(max, y+min, min, Blocks.LIT_REDSTONE_LAMP.getDefaultState()); + primer.setBlockState(max, y+min, max, Blocks.LIT_REDSTONE_LAMP.getDefaultState()); + primer.setBlockState(min, y+max, min, Blocks.LIT_REDSTONE_LAMP.getDefaultState()); + primer.setBlockState(min, y+max, max, Blocks.LIT_REDSTONE_LAMP.getDefaultState()); + primer.setBlockState(max, y+max, min, Blocks.LIT_REDSTONE_LAMP.getDefaultState()); + primer.setBlockState(max, y+max, max, Blocks.LIT_REDSTONE_LAMP.getDefaultState()); + } + } + + //infrastructure + + @Override + public Chunk generateChunk(int x, int z) { + this.rand.setSeed((long)x * 341873128712L + (long)z * 132897987541L); + ChunkPrimer chunkprimer = new ChunkPrimer(); + buildChunk(x,z,chunkprimer); + + Chunk chunk = new Chunk(this.world, chunkprimer, x, z); + byte[] abyte = chunk.getBiomeArray(); + + for (int i = 0; i < abyte.length; ++i) + { + abyte[i] = (byte)Biome.getIdForBiome(Biomes.EXTREME_HILLS); + //abyte[i] = (byte)Biome.getIdForBiome(InitBiome.BIOME_ONE); + } + + chunk.resetRelightChecks(); + return chunk; + } + + enum EnumRoomType{ + EMPTY, + TREASURE, + SOIL, + WOOD, + TORCH + } + + static GenCubeBase genCubeTreasure = new GenCubeTreasure(true); + static GenCubeBase genCubeSoil = new GenCubeSoilRoom(true); + static GenCubeBase genCubeWood = new GenCubeWoodRoom(true); + static GenCubeBase genCubeTorch = new GenCubeTorchRoom(true); + + EnumRoomType getRoomType(int x, int y, int z) + { + setSeedFor(x, y, z); + return EnumRoomType.values()[rand.nextInt(EnumRoomType.values().length)]; +// if (rand.nextFloat() < 0.05f) +// { +// return EnumRoomType.TREASURE; +// } +// +// if (rand.nextFloat() < 0.05f) +// { +// return EnumRoomType.SOIL; +// } + + //return EnumRoomType.EMPTY; + } + + + @Override + public void populate(int chunkX, int chunkZ) { + if (!chunkUsed(chunkX, chunkZ)) + { + return; + } + + net.minecraft.block.BlockFalling.fallInstantly = true; + int x = chunkX * 16; + int z = chunkZ * 16; + + net.minecraftforge.event.ForgeEventFactory.onChunkPopulate(true, this, this.world, this.rand, chunkX, chunkZ, false); + + for (int y = 0; y < heightLimit; y+= CommonDef.CHUNK_SIZE) { + + EnumRoomType type = getRoomType(x,y,z); + + setSeedFor(x, y, z); + boolean hasDoorX = rand.nextBoolean(); + boolean hasDoorY = y != 0 && rand.nextBoolean();//wont fall to void + boolean hasDoorZ = rand.nextBoolean(); + boolean hasLight = hasLight(x,y,z); + + GenCubeBase gen = null; + + switch (type) + { + case EMPTY: + break; + case TREASURE: + gen = genCubeTreasure; + break; + case SOIL: + gen = genCubeSoil; + break; + case WOOD: + gen = genCubeWood; + break; + case TORCH: + gen = genCubeTorch; + break; + default: + break; + } + + if (gen != null) + { + gen.setHasDoorXYZ(hasDoorX, hasDoorY, hasDoorZ); + gen.setHasLightXYZ(hasLight); + gen.generate(world, rand, new BlockPos(x, y, z)); + } + } + + net.minecraftforge.event.ForgeEventFactory.onChunkPopulate(false, this, this.world, this.rand, chunkX, chunkZ, false); + net.minecraft.block.BlockFalling.fallInstantly = false; + } + + @Override + public boolean generateStructures(Chunk chunkIn, int x, int z) { + return false; + } + + @Override + public List getPossibleCreatures(EnumCreatureType creatureType, BlockPos pos) { + Biome biome = this.world.getBiome(pos); + return biome.getSpawnableList(creatureType); + } + + @Nullable + @Override + public BlockPos getNearestStructurePos(World worldIn, String structureName, BlockPos position, boolean findUnexplored) { + return null; + } + + @Override + public void recreateStructures(Chunk chunkIn, int x, int z) { + + } + + @Override + public boolean isInsideStructure(World worldIn, String structureName, BlockPos pos) { + return false; + } +} diff --git a/src/main/java/com/somebody/idlframewok/world/dimension/hexcube/HexCubeHelper.java b/src/main/java/com/somebody/idlframewok/world/dimension/hexcube/HexCubeHelper.java new file mode 100644 index 0000000..dba973a --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/world/dimension/hexcube/HexCubeHelper.java @@ -0,0 +1,48 @@ +package com.somebody.idlframewok.world.dimension.hexcube; + +import com.somebody.idlframewok.util.CommonDef; +import net.minecraft.init.Blocks; +import net.minecraft.world.chunk.ChunkPrimer; + +public class HexCubeHelper { + + private static final float CHUNK_PER_DIFF = 4f; + + public static float getDifficulty(int chunkX, int y, int chunkZ) + { + if (chunkX < 0) + { + chunkX = -chunkX; + } + if (chunkZ < 0) + { + chunkZ = -chunkZ; + } + + return chunkX / CHUNK_PER_DIFF + chunkZ / CHUNK_PER_DIFF + (y >> 4) / CHUNK_PER_DIFF; + } + + public static void genGrass(ChunkPrimer primer, int x, int y, int z) + { + for (int dx = 1; dx < CommonDef.CHUNK_SIZE; dx++) + { + //for (int dy = 0; dy < CHUNK_SIZE; dy++) + //{ + for (int dz = 1; dz < CommonDef.CHUNK_SIZE; dz++) + { + //BlockPos curPos = new BlockPos(x+dx, y+dy, z+dz); + + int min = 6; + int max = 10; + + if ((dx > min && dx < max) || + (dz > min && dz < max)) + { + continue; + } + primer.setBlockState(x, 1, z, Blocks.GRASS.getDefaultState()); + } + //} + } + } +} diff --git a/src/main/java/com/somebody/idlframewok/world/dimension/hexcube/structure/GenCubeBase.java b/src/main/java/com/somebody/idlframewok/world/dimension/hexcube/structure/GenCubeBase.java new file mode 100644 index 0000000..074e753 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/world/dimension/hexcube/structure/GenCubeBase.java @@ -0,0 +1,58 @@ +package com.somebody.idlframewok.world.dimension.hexcube.structure; + +import java.util.Random; + +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.minecraft.world.gen.feature.WorldGenerator; + +public class GenCubeBase extends WorldGenerator { + + protected boolean hasDoorX; + protected boolean hasDoorY; + protected boolean hasDoorZ; + + protected boolean hasLight; + + protected int xSize, ySize, zSize; + + public void setSize(int sizeX, int sizeY, int sizeZ) { + this.xSize = sizeX; + this.ySize = sizeY; + this.zSize = sizeZ; + } + + public GenCubeBase(boolean notify) { + this(notify, 16, 16, 16); + } + + public GenCubeBase(boolean notify, int xSize, int ySize, int zSize) { + super(notify); + this.xSize = xSize; + this.ySize = ySize; + this.zSize = zSize; + } + + public GenCubeBase(boolean notify, int xSize, int ySize) { + this(notify, xSize, ySize, xSize); + } + + //reuse the object to reduce GC. + public void setHasDoorXYZ(boolean hasDoorX, boolean hasDoorY, boolean hasDoorZ) { + this.hasDoorX = hasDoorX; + this.hasDoorY = hasDoorY; + this.hasDoorZ = hasDoorZ; + } + + public void setHasLightXYZ(boolean hasLight) + { + this.hasLight = hasLight; + } + + @Override + public boolean generate(World worldIn, Random rand, BlockPos positionOrigin) { + return false; + } + + +} diff --git a/src/main/java/com/somebody/idlframewok/world/dimension/hexcube/structure/GenCubeSoilRoom.java b/src/main/java/com/somebody/idlframewok/world/dimension/hexcube/structure/GenCubeSoilRoom.java new file mode 100644 index 0000000..0638fc1 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/world/dimension/hexcube/structure/GenCubeSoilRoom.java @@ -0,0 +1,54 @@ +package com.somebody.idlframewok.world.dimension.hexcube.structure; + +import java.util.Random; + +import net.minecraft.init.Blocks; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; + +public class GenCubeSoilRoom extends GenCubeBase { + + public GenCubeSoilRoom(boolean notify) { + super(notify); + } + + public GenCubeSoilRoom(boolean notify, int xSize, int ySize, int zSize) { + super(notify, xSize, ySize, zSize); + } + + @Override + public boolean generate(World worldIn, Random rand, BlockPos positionOrigin) { + //positionOrigin is 0,0,0 of the room. the corner of walls + int min = 1; + int max = xSize - 1; + + int minZ = 1; + int maxZ = zSize - 1; + + int yMax = ySize - 1; + + //with chance the grass can grow + boolean isGrass = hasDoorX && !hasDoorY && hasDoorZ; + + for (int x = min; x <= max; x++) + { + for (int z = minZ; z <= maxZ; z++) + { + BlockPos pos = positionOrigin.add(x, 1, z); + if ((x > min && x < max) || (z > minZ && z < maxZ)) + { + if (worldIn.getBlockState(pos).getBlock() != Blocks.AIR) { + //if there is a light placed, keep it + continue; + } + } + + worldIn.setBlockState(pos, isGrass ? Blocks.GRASS.getDefaultState() : Blocks.DIRT.getDefaultState(), 2); + } + } + + return false; + } + + +} diff --git a/src/main/java/com/somebody/idlframewok/world/dimension/hexcube/structure/GenCubeTorchRoom.java b/src/main/java/com/somebody/idlframewok/world/dimension/hexcube/structure/GenCubeTorchRoom.java new file mode 100644 index 0000000..7adff51 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/world/dimension/hexcube/structure/GenCubeTorchRoom.java @@ -0,0 +1,57 @@ +package com.somebody.idlframewok.world.dimension.hexcube.structure; + +import java.util.Random; + +import net.minecraft.block.BlockTorch; +import net.minecraft.init.Blocks; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; + +public class GenCubeTorchRoom extends GenCubeBase { + public GenCubeTorchRoom(boolean notify) { + super(notify); + } + + public GenCubeTorchRoom(boolean notify, int xSize, int ySize, int zSize) { + super(notify, xSize, ySize, zSize); + } + + @Override + public boolean generate(World worldIn, Random rand, BlockPos positionOrigin) { + //positionOrigin is 0,0,0 of the room. the corner of walls + int minY = hasLight ? 2 : 1; + int min = 1; + int max = xSize - 1; + + int minZ = 1; + int maxZ = zSize - 1; + + int yMax = ySize - 1; + + //east +x + //south +z + for (int y = minY; y <= yMax; y++) + { + CreateLogAt(worldIn, positionOrigin.add(min, y, minZ), EnumFacing.SOUTH); + CreateLogAt(worldIn, positionOrigin.add(min, y, maxZ), EnumFacing.EAST); + CreateLogAt(worldIn, positionOrigin.add(max, y, maxZ), EnumFacing.NORTH); + CreateLogAt(worldIn, positionOrigin.add(max, y, minZ), EnumFacing.WEST); + } + + return false; + } + + void CreateLogAt(World worldIn, BlockPos pos, EnumFacing facing) + { + //todo: prevent torch from falling + if (worldIn.getBlockState(pos.offset(facing.getOpposite())).getBlock() == Blocks.AIR)//does this work? need check + { + this.setBlockAndNotifyAdequately(worldIn, pos, Blocks.TORCH.getDefaultState().withProperty(BlockTorch.FACING, facing)); + } + + + } + + +} diff --git a/src/main/java/com/somebody/idlframewok/world/dimension/hexcube/structure/GenCubeTreasure.java b/src/main/java/com/somebody/idlframewok/world/dimension/hexcube/structure/GenCubeTreasure.java new file mode 100644 index 0000000..9e8bc74 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/world/dimension/hexcube/structure/GenCubeTreasure.java @@ -0,0 +1,63 @@ +package com.somebody.idlframewok.world.dimension.hexcube.structure; + +import java.util.Random; + +import net.minecraft.init.Blocks; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.tileentity.TileEntityChest; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.minecraft.world.storage.loot.LootTableList; + +public class GenCubeTreasure extends GenCubeBase { + + public GenCubeTreasure(boolean notify) { + super(notify); + } + + public GenCubeTreasure(boolean notify, int xSize, int ySize, int zSize) { + super(notify, xSize, ySize, zSize); + } + + @Override + public boolean generate(World worldIn, Random rand, BlockPos positionOrigin) { + //positionOrigin is 0,0,0 of the room. the corner of walls + int sideA = 2; + int sideB = xSize - 2; + + int minZ = 2; + int maxZ = zSize - 2; + + int yMax = ySize - 1; + + BlockPos[] posList = { + positionOrigin.add(sideA,1, minZ), + positionOrigin.add(sideA,1, maxZ), + positionOrigin.add(sideB,1, minZ), + positionOrigin.add(sideB,1, maxZ) + }; + + float hasLootChance = 0.25f; + for (BlockPos chestPos: + posList) { + worldIn.setBlockState(chestPos, Blocks.CHEST.correctFacing(worldIn, positionOrigin.add(xSize>>1, 1, zSize >> 1), Blocks.CHEST.getDefaultState()), 2); + TileEntity tileEntity1 = worldIn.getTileEntity(chestPos); + + if (tileEntity1 instanceof TileEntityChest) + { + if (rand.nextFloat() < hasLootChance) + { + ((TileEntityChest)tileEntity1).setLootTable(LootTableList.CHESTS_SIMPLE_DUNGEON, rand.nextLong()); + } + else { + hasLootChance += 0.25f; + } + + } + } + + return false; + } + + +} diff --git a/src/main/java/com/somebody/idlframewok/world/dimension/hexcube/structure/GenCubeWoodRoom.java b/src/main/java/com/somebody/idlframewok/world/dimension/hexcube/structure/GenCubeWoodRoom.java new file mode 100644 index 0000000..8d87a57 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/world/dimension/hexcube/structure/GenCubeWoodRoom.java @@ -0,0 +1,49 @@ +package com.somebody.idlframewok.world.dimension.hexcube.structure; + +import java.util.Random; + +import net.minecraft.block.BlockLog; +import net.minecraft.init.Blocks; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; + +public class GenCubeWoodRoom extends GenCubeBase { + + public GenCubeWoodRoom(boolean notify) { + super(notify); + } + + public GenCubeWoodRoom(boolean notify, int xSize, int ySize, int zSize) { + super(notify, xSize, ySize, zSize); + } + + @Override + public boolean generate(World worldIn, Random rand, BlockPos positionOrigin) { + //positionOrigin is 0,0,0 of the room. the corner of walls + int minY = hasLight ? 2 : 1; + int min = 1; + int max = xSize - 1; + + int minZ = 1; + int maxZ = zSize - 1; + + int yMax = ySize - 1; + + for (int y = minY; y <= yMax; y++) + { + CreateLogAt(worldIn, positionOrigin.add(min, y, minZ)); + CreateLogAt(worldIn, positionOrigin.add(min, y, maxZ)); + CreateLogAt(worldIn, positionOrigin.add(max, y, minZ)); + CreateLogAt(worldIn, positionOrigin.add(max, y, maxZ)); + } + + return false; + } + + void CreateLogAt(World worldIn, BlockPos pos) + { + this.setBlockAndNotifyAdequately(worldIn, pos, Blocks.LOG.getDefaultState().withProperty(BlockLog.LOG_AXIS, BlockLog.EnumAxis.Y)); + } + + +} diff --git a/src/main/java/com/somebody/idlframewok/world/structure/ModGenStructure.java b/src/main/java/com/somebody/idlframewok/world/structure/ModGenStructure.java new file mode 100644 index 0000000..3cd88f5 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/world/structure/ModGenStructure.java @@ -0,0 +1,215 @@ +package com.somebody.idlframewok.world.structure; + +import java.util.List; +import java.util.Map; +import java.util.Random; + +import com.google.common.collect.Lists; +import it.unimi.dsi.fastutil.objects.ObjectIterator; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.ChunkPos; +import net.minecraft.util.math.MathHelper; +import net.minecraft.world.World; +import net.minecraft.world.biome.Biome; +import net.minecraft.world.gen.structure.MapGenStructure; +import net.minecraft.world.gen.structure.StructureComponent; +import net.minecraft.world.gen.structure.StructureStart; +import net.minecraft.world.gen.structure.StructureStrongholdPieces; + +public class ModGenStructure extends MapGenStructure +{ + public final List allowedBiomes; + /** is spawned false and set true once the defined BiomeGenBases were compared with the present ones */ + private boolean ranBiomeCheck; + private ChunkPos[] structureCoords; + private double distance; + private int spread; + + public ModGenStructure() + { + this.structureCoords = new ChunkPos[128]; + this.distance = 32.0D; + this.spread = 3; + this.allowedBiomes = Lists.newArrayList(); + + //this.allowedBiomes.add(InitBiome.BIOME_ONE); + } + + public ModGenStructure(Map p_i2068_1_) + { + this(); + + for (Map.Entry entry : p_i2068_1_.entrySet()) + { + if (((String)entry.getKey()).equals("distance")) + { + this.distance = MathHelper.getDouble(entry.getValue(), this.distance, 1.0D); + } + else if (((String)entry.getKey()).equals("count")) + { + this.structureCoords = new ChunkPos[MathHelper.getInt(entry.getValue(), this.structureCoords.length, 1)]; + } + else if (((String)entry.getKey()).equals("spread")) + { + this.spread = MathHelper.getInt(entry.getValue(), this.spread, 1); + } + } + } + + public String getStructureName() + { + return "TestStructure"; + } + + public BlockPos getNearestStructurePos(World worldIn, BlockPos pos, boolean findUnexplored) + { + if (!this.ranBiomeCheck) + { + this.generatePositions(); + this.ranBiomeCheck = true; + } + + BlockPos blockpos = null; + BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos(0, 0, 0); + double d0 = Double.MAX_VALUE; + + for (ChunkPos chunkpos : this.structureCoords) + { + blockpos$mutableblockpos.setPos((chunkpos.x << 4) + 8, 32, (chunkpos.z << 4) + 8); + double d1 = blockpos$mutableblockpos.distanceSq(pos); + + if (blockpos == null) + { + blockpos = new BlockPos(blockpos$mutableblockpos); + d0 = d1; + } + else if (d1 < d0) + { + blockpos = new BlockPos(blockpos$mutableblockpos); + d0 = d1; + } + } + + return blockpos; + } + + protected boolean canSpawnStructureAtCoords(int chunkX, int chunkZ) + { + if (!this.ranBiomeCheck) + { + this.generatePositions(); + this.ranBiomeCheck = true; + } + + for (ChunkPos chunkpos : this.structureCoords) + { + if (chunkX == chunkpos.x && chunkZ == chunkpos.z) + { + return true; + } + } + + return false; + } + + private void generatePositions() + { + this.initializeStructureData(this.world); + int i = 0; + ObjectIterator lvt_2_1_ = this.structureMap.values().iterator(); + + while (lvt_2_1_.hasNext()) + { + StructureStart structurestart = (StructureStart)lvt_2_1_.next(); + + if (i < this.structureCoords.length) + { + this.structureCoords[i++] = new ChunkPos(structurestart.getChunkPosX(), structurestart.getChunkPosZ()); + } + } + + Random random = new Random(); + random.setSeed(this.world.getSeed()); + double d1 = random.nextDouble() * Math.PI * 2.0D; + int j = 0; + int k = 0; + int l = this.structureMap.size(); + + if (l < this.structureCoords.length) + { + for (int i1 = 0; i1 < this.structureCoords.length; ++i1) + { + double d0 = 4.0D * this.distance + this.distance * (double)j * 6.0D + (random.nextDouble() - 0.5D) * this.distance * 2.5D; + int j1 = (int)Math.round(Math.cos(d1) * d0); + int k1 = (int)Math.round(Math.sin(d1) * d0); + BlockPos blockpos = this.world.getBiomeProvider().findBiomePosition((j1 << 4) + 8, (k1 << 4) + 8, 112, this.allowedBiomes, random); + + if (blockpos != null) + { + j1 = blockpos.getX() >> 4; + k1 = blockpos.getZ() >> 4; + } + + if (i1 >= l) + { + this.structureCoords[i1] = new ChunkPos(j1, k1); + } + + d1 += (Math.PI * 2D) / (double)this.spread; + ++k; + + if (k == this.spread) + { + ++j; + k = 0; + this.spread += 2 * this.spread / (j + 1); + this.spread = Math.min(this.spread, this.structureCoords.length - i1); + d1 += random.nextDouble() * Math.PI * 2.0D; + } + } + } + } + + protected StructureStart getStructureStart(int chunkX, int chunkZ) + { + ModGenStructure.Start ModGenStructure$start; + + for (ModGenStructure$start = new ModGenStructure.Start(this.world, this.rand, chunkX, chunkZ); + ModGenStructure$start.getComponents().isEmpty() || + ((StructureStrongholdPieces.Stairs2)ModGenStructure$start.getComponents().get(0)).strongholdPortalRoom == null; + ModGenStructure$start = new ModGenStructure.Start(this.world, this.rand, chunkX, chunkZ)) + { + ; + } + + return ModGenStructure$start; + } + + public static class Start extends StructureStart + { + public Start() + { + } + + public Start(World worldIn, Random random, int chunkX, int chunkZ) + { + super(chunkX, chunkZ); + StructureStrongholdPieces.prepareStructurePieces(); + StructureStrongholdPieces.Stairs2 structurestrongholdpieces$stairs2 = new StructureStrongholdPieces.Stairs2(0, random, (chunkX << 4) + 2, (chunkZ << 4) + 2); + this.components.add(structurestrongholdpieces$stairs2); + structurestrongholdpieces$stairs2.buildComponent(structurestrongholdpieces$stairs2, this.components, random); + List list = structurestrongholdpieces$stairs2.pendingChildren; + + while (!list.isEmpty()) + { + int i = random.nextInt(list.size()); + StructureComponent structurecomponent = list.remove(i); + structurecomponent.buildComponent(structurestrongholdpieces$stairs2, this.components, random); + } + + this.updateBoundingBox(); + this.markAvailableHeight(worldIn, random, 10); + } + } + +} diff --git a/src/main/java/com/somebody/idlframewok/world/structure/TestStructurePieces.java b/src/main/java/com/somebody/idlframewok/world/structure/TestStructurePieces.java new file mode 100644 index 0000000..f9b958d --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/world/structure/TestStructurePieces.java @@ -0,0 +1,989 @@ +package com.somebody.idlframewok.world.structure; + +import java.util.List; +import java.util.Random; +import javax.annotation.Nullable; + +import com.google.common.collect.Lists; +import net.minecraft.block.BlockPlanks; +import net.minecraft.block.BlockRail; +import net.minecraft.block.BlockRailBase; +import net.minecraft.block.BlockTorch; +import net.minecraft.block.material.Material; +import net.minecraft.block.state.IBlockState; +import net.minecraft.entity.EntityList; +import net.minecraft.entity.item.EntityMinecartChest; +import net.minecraft.entity.monster.EntityCaveSpider; +import net.minecraft.init.Blocks; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.tileentity.TileEntityMobSpawner; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.minecraft.world.gen.structure.MapGenMineshaft; +import net.minecraft.world.gen.structure.MapGenStructureIO; +import net.minecraft.world.gen.structure.StructureBoundingBox; +import net.minecraft.world.gen.structure.StructureComponent; +import net.minecraft.world.gen.structure.template.TemplateManager; +import net.minecraft.world.storage.loot.LootTableList; + +public class TestStructurePieces { + + //see StructureComponent + + public static void registerStructurePieces() + { + MapGenStructureIO.registerStructureComponent(TestStructurePieces.Corridor.class, "MSCorridor"); + MapGenStructureIO.registerStructureComponent(TestStructurePieces.Cross.class, "MSCrossing"); + MapGenStructureIO.registerStructureComponent(TestStructurePieces.Room.class, "MSRoom"); + MapGenStructureIO.registerStructureComponent(TestStructurePieces.Stairs.class, "MSStairs"); + } + + private static TestStructurePieces.Peice createRandomShaftPiece(List p_189940_0_, Random p_189940_1_, int p_189940_2_, int p_189940_3_, int p_189940_4_, @Nullable EnumFacing p_189940_5_, int p_189940_6_, MapGenMineshaft.Type p_189940_7_) + { + int i = p_189940_1_.nextInt(100); + + if (i >= 80) + { + StructureBoundingBox structureboundingbox = TestStructurePieces.Cross.findCrossing(p_189940_0_, p_189940_1_, p_189940_2_, p_189940_3_, p_189940_4_, p_189940_5_); + + if (structureboundingbox != null) + { + return new TestStructurePieces.Cross(p_189940_6_, p_189940_1_, structureboundingbox, p_189940_5_, p_189940_7_); + } + } + else if (i >= 70) + { + StructureBoundingBox structureboundingbox1 = TestStructurePieces.Stairs.findStairs(p_189940_0_, p_189940_1_, p_189940_2_, p_189940_3_, p_189940_4_, p_189940_5_); + + if (structureboundingbox1 != null) + { + return new TestStructurePieces.Stairs(p_189940_6_, p_189940_1_, structureboundingbox1, p_189940_5_, p_189940_7_); + } + } + else + { + StructureBoundingBox structureboundingbox2 = TestStructurePieces.Corridor.findCorridorSize(p_189940_0_, p_189940_1_, p_189940_2_, p_189940_3_, p_189940_4_, p_189940_5_); + + if (structureboundingbox2 != null) + { + return new TestStructurePieces.Corridor(p_189940_6_, p_189940_1_, structureboundingbox2, p_189940_5_, p_189940_7_); + } + } + + return null; + } + + private static TestStructurePieces.Peice generateAndAddPiece(StructureComponent p_189938_0_, List p_189938_1_, Random p_189938_2_, int p_189938_3_, int p_189938_4_, int p_189938_5_, EnumFacing p_189938_6_, int p_189938_7_) + { + if (p_189938_7_ > 8) + { + return null; + } + else if (Math.abs(p_189938_3_ - p_189938_0_.getBoundingBox().minX) <= 80 && Math.abs(p_189938_5_ - p_189938_0_.getBoundingBox().minZ) <= 80) + { + MapGenMineshaft.Type mapgenmineshaft$type = ((TestStructurePieces.Peice)p_189938_0_).mineShaftType; + TestStructurePieces.Peice TestStructurePieces$peice = createRandomShaftPiece(p_189938_1_, p_189938_2_, p_189938_3_, p_189938_4_, p_189938_5_, p_189938_6_, p_189938_7_ + 1, mapgenmineshaft$type); + + if (TestStructurePieces$peice != null) + { + p_189938_1_.add(TestStructurePieces$peice); + TestStructurePieces$peice.buildComponent(p_189938_0_, p_189938_1_, p_189938_2_); + } + + return TestStructurePieces$peice; + } + else + { + return null; + } + } + + public static class Corridor extends TestStructurePieces.Peice + { + private boolean hasRails; + private boolean hasSpiders; + private boolean spawnerPlaced; + /** A count of the different sections of this mine. The space between ceiling supports. */ + private int sectionCount; + + public Corridor() + { + } + + /** + * (abstract) Helper method to write subclass data to NBT + */ + protected void writeStructureToNBT(NBTTagCompound tagCompound) + { + super.writeStructureToNBT(tagCompound); + tagCompound.setBoolean("hr", this.hasRails); + tagCompound.setBoolean("sc", this.hasSpiders); + tagCompound.setBoolean("hps", this.spawnerPlaced); + tagCompound.setInteger("Num", this.sectionCount); + } + + /** + * (abstract) Helper method to read subclass data from NBT + */ + protected void readStructureFromNBT(NBTTagCompound tagCompound, TemplateManager p_143011_2_) + { + super.readStructureFromNBT(tagCompound, p_143011_2_); + this.hasRails = tagCompound.getBoolean("hr"); + this.hasSpiders = tagCompound.getBoolean("sc"); + this.spawnerPlaced = tagCompound.getBoolean("hps"); + this.sectionCount = tagCompound.getInteger("Num"); + } + + public Corridor(int p_i47140_1_, Random p_i47140_2_, StructureBoundingBox p_i47140_3_, EnumFacing p_i47140_4_, MapGenMineshaft.Type p_i47140_5_) + { + super(p_i47140_1_, p_i47140_5_); + this.setCoordBaseMode(p_i47140_4_); + this.boundingBox = p_i47140_3_; + this.hasRails = p_i47140_2_.nextInt(3) == 0; + this.hasSpiders = !this.hasRails && p_i47140_2_.nextInt(23) == 0; + + if (this.getCoordBaseMode().getAxis() == EnumFacing.Axis.Z) + { + this.sectionCount = p_i47140_3_.getZSize() / 5; + } + else + { + this.sectionCount = p_i47140_3_.getXSize() / 5; + } + } + + public static StructureBoundingBox findCorridorSize(List p_175814_0_, Random rand, int x, int y, int z, EnumFacing facing) + { + StructureBoundingBox structureboundingbox = new StructureBoundingBox(x, y, z, x, y + 2, z); + int i; + + for (i = rand.nextInt(3) + 2; i > 0; --i) + { + int j = i * 5; + + switch (facing) + { + case NORTH: + default: + structureboundingbox.maxX = x + 2; + structureboundingbox.minZ = z - (j - 1); + break; + case SOUTH: + structureboundingbox.maxX = x + 2; + structureboundingbox.maxZ = z + (j - 1); + break; + case WEST: + structureboundingbox.minX = x - (j - 1); + structureboundingbox.maxZ = z + 2; + break; + case EAST: + structureboundingbox.maxX = x + (j - 1); + structureboundingbox.maxZ = z + 2; + } + + if (StructureComponent.findIntersecting(p_175814_0_, structureboundingbox) == null) + { + break; + } + } + + return i > 0 ? structureboundingbox : null; + } + + /** + * Initiates construction of the Structure Component picked, at the current Location of StructGen + */ + public void buildComponent(StructureComponent componentIn, List listIn, Random rand) + { + int i = this.getComponentType(); + int j = rand.nextInt(4); + EnumFacing enumfacing = this.getCoordBaseMode(); + + if (enumfacing != null) + { + switch (enumfacing) + { + case NORTH: + default: + + if (j <= 1) + { + TestStructurePieces.generateAndAddPiece(componentIn, listIn, rand, this.boundingBox.minX, this.boundingBox.minY - 1 + rand.nextInt(3), this.boundingBox.minZ - 1, enumfacing, i); + } + else if (j == 2) + { + TestStructurePieces.generateAndAddPiece(componentIn, listIn, rand, this.boundingBox.minX - 1, this.boundingBox.minY - 1 + rand.nextInt(3), this.boundingBox.minZ, EnumFacing.WEST, i); + } + else + { + TestStructurePieces.generateAndAddPiece(componentIn, listIn, rand, this.boundingBox.maxX + 1, this.boundingBox.minY - 1 + rand.nextInt(3), this.boundingBox.minZ, EnumFacing.EAST, i); + } + + break; + case SOUTH: + + if (j <= 1) + { + TestStructurePieces.generateAndAddPiece(componentIn, listIn, rand, this.boundingBox.minX, this.boundingBox.minY - 1 + rand.nextInt(3), this.boundingBox.maxZ + 1, enumfacing, i); + } + else if (j == 2) + { + TestStructurePieces.generateAndAddPiece(componentIn, listIn, rand, this.boundingBox.minX - 1, this.boundingBox.minY - 1 + rand.nextInt(3), this.boundingBox.maxZ - 3, EnumFacing.WEST, i); + } + else + { + TestStructurePieces.generateAndAddPiece(componentIn, listIn, rand, this.boundingBox.maxX + 1, this.boundingBox.minY - 1 + rand.nextInt(3), this.boundingBox.maxZ - 3, EnumFacing.EAST, i); + } + + break; + case WEST: + + if (j <= 1) + { + TestStructurePieces.generateAndAddPiece(componentIn, listIn, rand, this.boundingBox.minX - 1, this.boundingBox.minY - 1 + rand.nextInt(3), this.boundingBox.minZ, enumfacing, i); + } + else if (j == 2) + { + TestStructurePieces.generateAndAddPiece(componentIn, listIn, rand, this.boundingBox.minX, this.boundingBox.minY - 1 + rand.nextInt(3), this.boundingBox.minZ - 1, EnumFacing.NORTH, i); + } + else + { + TestStructurePieces.generateAndAddPiece(componentIn, listIn, rand, this.boundingBox.minX, this.boundingBox.minY - 1 + rand.nextInt(3), this.boundingBox.maxZ + 1, EnumFacing.SOUTH, i); + } + + break; + case EAST: + + if (j <= 1) + { + TestStructurePieces.generateAndAddPiece(componentIn, listIn, rand, this.boundingBox.maxX + 1, this.boundingBox.minY - 1 + rand.nextInt(3), this.boundingBox.minZ, enumfacing, i); + } + else if (j == 2) + { + TestStructurePieces.generateAndAddPiece(componentIn, listIn, rand, this.boundingBox.maxX - 3, this.boundingBox.minY - 1 + rand.nextInt(3), this.boundingBox.minZ - 1, EnumFacing.NORTH, i); + } + else + { + TestStructurePieces.generateAndAddPiece(componentIn, listIn, rand, this.boundingBox.maxX - 3, this.boundingBox.minY - 1 + rand.nextInt(3), this.boundingBox.maxZ + 1, EnumFacing.SOUTH, i); + } + } + } + + if (i < 8) + { + if (enumfacing != EnumFacing.NORTH && enumfacing != EnumFacing.SOUTH) + { + for (int i1 = this.boundingBox.minX + 3; i1 + 3 <= this.boundingBox.maxX; i1 += 5) + { + int j1 = rand.nextInt(5); + + if (j1 == 0) + { + TestStructurePieces.generateAndAddPiece(componentIn, listIn, rand, i1, this.boundingBox.minY, this.boundingBox.minZ - 1, EnumFacing.NORTH, i + 1); + } + else if (j1 == 1) + { + TestStructurePieces.generateAndAddPiece(componentIn, listIn, rand, i1, this.boundingBox.minY, this.boundingBox.maxZ + 1, EnumFacing.SOUTH, i + 1); + } + } + } + else + { + for (int k = this.boundingBox.minZ + 3; k + 3 <= this.boundingBox.maxZ; k += 5) + { + int l = rand.nextInt(5); + + if (l == 0) + { + TestStructurePieces.generateAndAddPiece(componentIn, listIn, rand, this.boundingBox.minX - 1, this.boundingBox.minY, k, EnumFacing.WEST, i + 1); + } + else if (l == 1) + { + TestStructurePieces.generateAndAddPiece(componentIn, listIn, rand, this.boundingBox.maxX + 1, this.boundingBox.minY, k, EnumFacing.EAST, i + 1); + } + } + } + } + } + + /** + * Adds chest to the structure and sets its contents + */ + protected boolean generateChest(World worldIn, StructureBoundingBox structurebb, Random randomIn, int x, int y, int z, ResourceLocation loot) + { + BlockPos blockpos = new BlockPos(this.getXWithOffset(x, z), this.getYWithOffset(y), this.getZWithOffset(x, z)); + + if (structurebb.isVecInside(blockpos) && worldIn.getBlockState(blockpos).getMaterial() == Material.AIR && worldIn.getBlockState(blockpos.down()).getMaterial() != Material.AIR) + { + IBlockState iblockstate = Blocks.RAIL.getDefaultState().withProperty(BlockRail.SHAPE, randomIn.nextBoolean() ? BlockRailBase.EnumRailDirection.NORTH_SOUTH : BlockRailBase.EnumRailDirection.EAST_WEST); + this.setBlockState(worldIn, iblockstate, x, y, z, structurebb); + EntityMinecartChest entityminecartchest = new EntityMinecartChest(worldIn, (double)((float)blockpos.getX() + 0.5F), (double)((float)blockpos.getY() + 0.5F), (double)((float)blockpos.getZ() + 0.5F)); + entityminecartchest.setLootTable(loot, randomIn.nextLong()); + worldIn.spawnEntity(entityminecartchest); + return true; + } + else + { + return false; + } + } + + /** + * second Part of Structure generating, this for example places Spiderwebs, Mob Spawners, it closes + * Mineshafts at the end, it adds Fences... + */ + public boolean addComponentParts(World worldIn, Random randomIn, StructureBoundingBox structureBoundingBoxIn) + { + if (this.isLiquidInStructureBoundingBox(worldIn, structureBoundingBoxIn)) + { + return false; + } + else + { + int i = 0; + int j = 2; + int k = 0; + int l = 2; + int i1 = this.sectionCount * 5 - 1; + IBlockState iblockstate = this.getPlanksBlock(); + this.fillWithBlocks(worldIn, structureBoundingBoxIn, 0, 0, 0, 2, 1, i1, Blocks.AIR.getDefaultState(), Blocks.AIR.getDefaultState(), false); + this.generateMaybeBox(worldIn, structureBoundingBoxIn, randomIn, 0.8F, 0, 2, 0, 2, 2, i1, Blocks.AIR.getDefaultState(), Blocks.AIR.getDefaultState(), false, 0); + + if (this.hasSpiders) + { + this.generateMaybeBox(worldIn, structureBoundingBoxIn, randomIn, 0.6F, 0, 0, 0, 2, 1, i1, Blocks.WEB.getDefaultState(), Blocks.AIR.getDefaultState(), false, 8); + } + + for (int j1 = 0; j1 < this.sectionCount; ++j1) + { + int k1 = 2 + j1 * 5; + this.placeSupport(worldIn, structureBoundingBoxIn, 0, 0, k1, 2, 2, randomIn); + this.placeCobWeb(worldIn, structureBoundingBoxIn, randomIn, 0.1F, 0, 2, k1 - 1); + this.placeCobWeb(worldIn, structureBoundingBoxIn, randomIn, 0.1F, 2, 2, k1 - 1); + this.placeCobWeb(worldIn, structureBoundingBoxIn, randomIn, 0.1F, 0, 2, k1 + 1); + this.placeCobWeb(worldIn, structureBoundingBoxIn, randomIn, 0.1F, 2, 2, k1 + 1); + this.placeCobWeb(worldIn, structureBoundingBoxIn, randomIn, 0.05F, 0, 2, k1 - 2); + this.placeCobWeb(worldIn, structureBoundingBoxIn, randomIn, 0.05F, 2, 2, k1 - 2); + this.placeCobWeb(worldIn, structureBoundingBoxIn, randomIn, 0.05F, 0, 2, k1 + 2); + this.placeCobWeb(worldIn, structureBoundingBoxIn, randomIn, 0.05F, 2, 2, k1 + 2); + + if (randomIn.nextInt(100) == 0) + { + this.generateChest(worldIn, structureBoundingBoxIn, randomIn, 2, 0, k1 - 1, LootTableList.CHESTS_ABANDONED_MINESHAFT); + } + + if (randomIn.nextInt(100) == 0) + { + this.generateChest(worldIn, structureBoundingBoxIn, randomIn, 0, 0, k1 + 1, LootTableList.CHESTS_ABANDONED_MINESHAFT); + } + + if (this.hasSpiders && !this.spawnerPlaced) + { + int l1 = this.getYWithOffset(0); + int i2 = k1 - 1 + randomIn.nextInt(3); + int j2 = this.getXWithOffset(1, i2); + int k2 = this.getZWithOffset(1, i2); + BlockPos blockpos = new BlockPos(j2, l1, k2); + + if (structureBoundingBoxIn.isVecInside(blockpos) && this.getSkyBrightness(worldIn, 1, 0, i2, structureBoundingBoxIn) < 8) + { + this.spawnerPlaced = true; + worldIn.setBlockState(blockpos, Blocks.MOB_SPAWNER.getDefaultState(), 2); + TileEntity tileentity = worldIn.getTileEntity(blockpos); + + if (tileentity instanceof TileEntityMobSpawner) + { + ((TileEntityMobSpawner)tileentity).getSpawnerBaseLogic().setEntityId(EntityList.getKey(EntityCaveSpider.class)); + } + } + } + } + + for (int l2 = 0; l2 <= 2; ++l2) + { + for (int i3 = 0; i3 <= i1; ++i3) + { + int k3 = -1; + IBlockState iblockstate3 = this.getBlockStateFromPos(worldIn, l2, -1, i3, structureBoundingBoxIn); + + if (iblockstate3.getMaterial() == Material.AIR && this.getSkyBrightness(worldIn, l2, -1, i3, structureBoundingBoxIn) < 8) + { + int l3 = -1; + this.setBlockState(worldIn, iblockstate, l2, -1, i3, structureBoundingBoxIn); + } + } + } + + if (this.hasRails) + { + IBlockState iblockstate1 = Blocks.RAIL.getDefaultState().withProperty(BlockRail.SHAPE, BlockRailBase.EnumRailDirection.NORTH_SOUTH); + + for (int j3 = 0; j3 <= i1; ++j3) + { + IBlockState iblockstate2 = this.getBlockStateFromPos(worldIn, 1, -1, j3, structureBoundingBoxIn); + + if (iblockstate2.getMaterial() != Material.AIR && iblockstate2.isFullBlock()) + { + float f = this.getSkyBrightness(worldIn, 1, 0, j3, structureBoundingBoxIn) > 8 ? 0.9F : 0.7F; + this.randomlyPlaceBlock(worldIn, structureBoundingBoxIn, randomIn, f, 1, 0, j3, iblockstate1); + } + } + } + + return true; + } + } + + private void placeSupport(World p_189921_1_, StructureBoundingBox p_189921_2_, int p_189921_3_, int p_189921_4_, int p_189921_5_, int p_189921_6_, int p_189921_7_, Random p_189921_8_) + { + if (this.isSupportingBox(p_189921_1_, p_189921_2_, p_189921_3_, p_189921_7_, p_189921_6_, p_189921_5_)) + { + IBlockState iblockstate = this.getPlanksBlock(); + IBlockState iblockstate1 = this.getFenceBlock(); + IBlockState iblockstate2 = Blocks.AIR.getDefaultState(); + this.fillWithBlocks(p_189921_1_, p_189921_2_, p_189921_3_, p_189921_4_, p_189921_5_, p_189921_3_, p_189921_6_ - 1, p_189921_5_, iblockstate1, iblockstate2, false); + this.fillWithBlocks(p_189921_1_, p_189921_2_, p_189921_7_, p_189921_4_, p_189921_5_, p_189921_7_, p_189921_6_ - 1, p_189921_5_, iblockstate1, iblockstate2, false); + + if (p_189921_8_.nextInt(4) == 0) + { + this.fillWithBlocks(p_189921_1_, p_189921_2_, p_189921_3_, p_189921_6_, p_189921_5_, p_189921_3_, p_189921_6_, p_189921_5_, iblockstate, iblockstate2, false); + this.fillWithBlocks(p_189921_1_, p_189921_2_, p_189921_7_, p_189921_6_, p_189921_5_, p_189921_7_, p_189921_6_, p_189921_5_, iblockstate, iblockstate2, false); + } + else + { + this.fillWithBlocks(p_189921_1_, p_189921_2_, p_189921_3_, p_189921_6_, p_189921_5_, p_189921_7_, p_189921_6_, p_189921_5_, iblockstate, iblockstate2, false); + this.randomlyPlaceBlock(p_189921_1_, p_189921_2_, p_189921_8_, 0.05F, p_189921_3_ + 1, p_189921_6_, p_189921_5_ - 1, Blocks.TORCH.getDefaultState().withProperty(BlockTorch.FACING, EnumFacing.NORTH)); + this.randomlyPlaceBlock(p_189921_1_, p_189921_2_, p_189921_8_, 0.05F, p_189921_3_ + 1, p_189921_6_, p_189921_5_ + 1, Blocks.TORCH.getDefaultState().withProperty(BlockTorch.FACING, EnumFacing.SOUTH)); + } + } + } + + private void placeCobWeb(World p_189922_1_, StructureBoundingBox p_189922_2_, Random p_189922_3_, float p_189922_4_, int p_189922_5_, int p_189922_6_, int p_189922_7_) + { + if (this.getSkyBrightness(p_189922_1_, p_189922_5_, p_189922_6_, p_189922_7_, p_189922_2_) < 8) + { + this.randomlyPlaceBlock(p_189922_1_, p_189922_2_, p_189922_3_, p_189922_4_, p_189922_5_, p_189922_6_, p_189922_7_, Blocks.WEB.getDefaultState()); + } + } + } + + public static class Cross extends TestStructurePieces.Peice + { + private EnumFacing corridorDirection; + private boolean isMultipleFloors; + + public Cross() + { + } + + /** + * (abstract) Helper method to write subclass data to NBT + */ + protected void writeStructureToNBT(NBTTagCompound tagCompound) + { + super.writeStructureToNBT(tagCompound); + tagCompound.setBoolean("tf", this.isMultipleFloors); + tagCompound.setInteger("D", this.corridorDirection.getHorizontalIndex()); + } + + /** + * (abstract) Helper method to read subclass data from NBT + */ + protected void readStructureFromNBT(NBTTagCompound tagCompound, TemplateManager p_143011_2_) + { + super.readStructureFromNBT(tagCompound, p_143011_2_); + this.isMultipleFloors = tagCompound.getBoolean("tf"); + this.corridorDirection = EnumFacing.getHorizontal(tagCompound.getInteger("D")); + } + + public Cross(int p_i47139_1_, Random p_i47139_2_, StructureBoundingBox p_i47139_3_, @Nullable EnumFacing p_i47139_4_, MapGenMineshaft.Type p_i47139_5_) + { + super(p_i47139_1_, p_i47139_5_); + this.corridorDirection = p_i47139_4_; + this.boundingBox = p_i47139_3_; + this.isMultipleFloors = p_i47139_3_.getYSize() > 3; + } + + public static StructureBoundingBox findCrossing(List listIn, Random rand, int x, int y, int z, EnumFacing facing) + { + StructureBoundingBox structureboundingbox = new StructureBoundingBox(x, y, z, x, y + 2, z); + + if (rand.nextInt(4) == 0) + { + structureboundingbox.maxY += 4; + } + + switch (facing) + { + case NORTH: + default: + structureboundingbox.minX = x - 1; + structureboundingbox.maxX = x + 3; + structureboundingbox.minZ = z - 4; + break; + case SOUTH: + structureboundingbox.minX = x - 1; + structureboundingbox.maxX = x + 3; + structureboundingbox.maxZ = z + 3 + 1; + break; + case WEST: + structureboundingbox.minX = x - 4; + structureboundingbox.minZ = z - 1; + structureboundingbox.maxZ = z + 3; + break; + case EAST: + structureboundingbox.maxX = x + 3 + 1; + structureboundingbox.minZ = z - 1; + structureboundingbox.maxZ = z + 3; + } + + return StructureComponent.findIntersecting(listIn, structureboundingbox) != null ? null : structureboundingbox; + } + + /** + * Initiates construction of the Structure Component picked, at the current Location of StructGen + */ + public void buildComponent(StructureComponent componentIn, List listIn, Random rand) + { + int i = this.getComponentType(); + + switch (this.corridorDirection) + { + case NORTH: + default: + TestStructurePieces.generateAndAddPiece(componentIn, listIn, rand, this.boundingBox.minX + 1, this.boundingBox.minY, this.boundingBox.minZ - 1, EnumFacing.NORTH, i); + TestStructurePieces.generateAndAddPiece(componentIn, listIn, rand, this.boundingBox.minX - 1, this.boundingBox.minY, this.boundingBox.minZ + 1, EnumFacing.WEST, i); + TestStructurePieces.generateAndAddPiece(componentIn, listIn, rand, this.boundingBox.maxX + 1, this.boundingBox.minY, this.boundingBox.minZ + 1, EnumFacing.EAST, i); + break; + case SOUTH: + TestStructurePieces.generateAndAddPiece(componentIn, listIn, rand, this.boundingBox.minX + 1, this.boundingBox.minY, this.boundingBox.maxZ + 1, EnumFacing.SOUTH, i); + TestStructurePieces.generateAndAddPiece(componentIn, listIn, rand, this.boundingBox.minX - 1, this.boundingBox.minY, this.boundingBox.minZ + 1, EnumFacing.WEST, i); + TestStructurePieces.generateAndAddPiece(componentIn, listIn, rand, this.boundingBox.maxX + 1, this.boundingBox.minY, this.boundingBox.minZ + 1, EnumFacing.EAST, i); + break; + case WEST: + TestStructurePieces.generateAndAddPiece(componentIn, listIn, rand, this.boundingBox.minX + 1, this.boundingBox.minY, this.boundingBox.minZ - 1, EnumFacing.NORTH, i); + TestStructurePieces.generateAndAddPiece(componentIn, listIn, rand, this.boundingBox.minX + 1, this.boundingBox.minY, this.boundingBox.maxZ + 1, EnumFacing.SOUTH, i); + TestStructurePieces.generateAndAddPiece(componentIn, listIn, rand, this.boundingBox.minX - 1, this.boundingBox.minY, this.boundingBox.minZ + 1, EnumFacing.WEST, i); + break; + case EAST: + TestStructurePieces.generateAndAddPiece(componentIn, listIn, rand, this.boundingBox.minX + 1, this.boundingBox.minY, this.boundingBox.minZ - 1, EnumFacing.NORTH, i); + TestStructurePieces.generateAndAddPiece(componentIn, listIn, rand, this.boundingBox.minX + 1, this.boundingBox.minY, this.boundingBox.maxZ + 1, EnumFacing.SOUTH, i); + TestStructurePieces.generateAndAddPiece(componentIn, listIn, rand, this.boundingBox.maxX + 1, this.boundingBox.minY, this.boundingBox.minZ + 1, EnumFacing.EAST, i); + } + + if (this.isMultipleFloors) + { + if (rand.nextBoolean()) + { + TestStructurePieces.generateAndAddPiece(componentIn, listIn, rand, this.boundingBox.minX + 1, this.boundingBox.minY + 3 + 1, this.boundingBox.minZ - 1, EnumFacing.NORTH, i); + } + + if (rand.nextBoolean()) + { + TestStructurePieces.generateAndAddPiece(componentIn, listIn, rand, this.boundingBox.minX - 1, this.boundingBox.minY + 3 + 1, this.boundingBox.minZ + 1, EnumFacing.WEST, i); + } + + if (rand.nextBoolean()) + { + TestStructurePieces.generateAndAddPiece(componentIn, listIn, rand, this.boundingBox.maxX + 1, this.boundingBox.minY + 3 + 1, this.boundingBox.minZ + 1, EnumFacing.EAST, i); + } + + if (rand.nextBoolean()) + { + TestStructurePieces.generateAndAddPiece(componentIn, listIn, rand, this.boundingBox.minX + 1, this.boundingBox.minY + 3 + 1, this.boundingBox.maxZ + 1, EnumFacing.SOUTH, i); + } + } + } + + /** + * second Part of Structure generating, this for example places Spiderwebs, Mob Spawners, it closes + * Mineshafts at the end, it adds Fences... + */ + public boolean addComponentParts(World worldIn, Random randomIn, StructureBoundingBox structureBoundingBoxIn) + { + if (this.isLiquidInStructureBoundingBox(worldIn, structureBoundingBoxIn)) + { + return false; + } + else + { + IBlockState iblockstate = this.getPlanksBlock(); + + if (this.isMultipleFloors) + { + this.fillWithBlocks(worldIn, structureBoundingBoxIn, this.boundingBox.minX + 1, this.boundingBox.minY, this.boundingBox.minZ, this.boundingBox.maxX - 1, this.boundingBox.minY + 3 - 1, this.boundingBox.maxZ, Blocks.AIR.getDefaultState(), Blocks.AIR.getDefaultState(), false); + this.fillWithBlocks(worldIn, structureBoundingBoxIn, this.boundingBox.minX, this.boundingBox.minY, this.boundingBox.minZ + 1, this.boundingBox.maxX, this.boundingBox.minY + 3 - 1, this.boundingBox.maxZ - 1, Blocks.AIR.getDefaultState(), Blocks.AIR.getDefaultState(), false); + this.fillWithBlocks(worldIn, structureBoundingBoxIn, this.boundingBox.minX + 1, this.boundingBox.maxY - 2, this.boundingBox.minZ, this.boundingBox.maxX - 1, this.boundingBox.maxY, this.boundingBox.maxZ, Blocks.AIR.getDefaultState(), Blocks.AIR.getDefaultState(), false); + this.fillWithBlocks(worldIn, structureBoundingBoxIn, this.boundingBox.minX, this.boundingBox.maxY - 2, this.boundingBox.minZ + 1, this.boundingBox.maxX, this.boundingBox.maxY, this.boundingBox.maxZ - 1, Blocks.AIR.getDefaultState(), Blocks.AIR.getDefaultState(), false); + this.fillWithBlocks(worldIn, structureBoundingBoxIn, this.boundingBox.minX + 1, this.boundingBox.minY + 3, this.boundingBox.minZ + 1, this.boundingBox.maxX - 1, this.boundingBox.minY + 3, this.boundingBox.maxZ - 1, Blocks.AIR.getDefaultState(), Blocks.AIR.getDefaultState(), false); + } + else + { + this.fillWithBlocks(worldIn, structureBoundingBoxIn, this.boundingBox.minX + 1, this.boundingBox.minY, this.boundingBox.minZ, this.boundingBox.maxX - 1, this.boundingBox.maxY, this.boundingBox.maxZ, Blocks.AIR.getDefaultState(), Blocks.AIR.getDefaultState(), false); + this.fillWithBlocks(worldIn, structureBoundingBoxIn, this.boundingBox.minX, this.boundingBox.minY, this.boundingBox.minZ + 1, this.boundingBox.maxX, this.boundingBox.maxY, this.boundingBox.maxZ - 1, Blocks.AIR.getDefaultState(), Blocks.AIR.getDefaultState(), false); + } + + this.placeSupportPillar(worldIn, structureBoundingBoxIn, this.boundingBox.minX + 1, this.boundingBox.minY, this.boundingBox.minZ + 1, this.boundingBox.maxY); + this.placeSupportPillar(worldIn, structureBoundingBoxIn, this.boundingBox.minX + 1, this.boundingBox.minY, this.boundingBox.maxZ - 1, this.boundingBox.maxY); + this.placeSupportPillar(worldIn, structureBoundingBoxIn, this.boundingBox.maxX - 1, this.boundingBox.minY, this.boundingBox.minZ + 1, this.boundingBox.maxY); + this.placeSupportPillar(worldIn, structureBoundingBoxIn, this.boundingBox.maxX - 1, this.boundingBox.minY, this.boundingBox.maxZ - 1, this.boundingBox.maxY); + + for (int i = this.boundingBox.minX; i <= this.boundingBox.maxX; ++i) + { + for (int j = this.boundingBox.minZ; j <= this.boundingBox.maxZ; ++j) + { + if (this.getBlockStateFromPos(worldIn, i, this.boundingBox.minY - 1, j, structureBoundingBoxIn).getMaterial() == Material.AIR && this.getSkyBrightness(worldIn, i, this.boundingBox.minY - 1, j, structureBoundingBoxIn) < 8) + { + this.setBlockState(worldIn, iblockstate, i, this.boundingBox.minY - 1, j, structureBoundingBoxIn); + } + } + } + + return true; + } + } + + private void placeSupportPillar(World p_189923_1_, StructureBoundingBox p_189923_2_, int p_189923_3_, int p_189923_4_, int p_189923_5_, int p_189923_6_) + { + if (this.getBlockStateFromPos(p_189923_1_, p_189923_3_, p_189923_6_ + 1, p_189923_5_, p_189923_2_).getMaterial() != Material.AIR) + { + this.fillWithBlocks(p_189923_1_, p_189923_2_, p_189923_3_, p_189923_4_, p_189923_5_, p_189923_3_, p_189923_6_, p_189923_5_, this.getPlanksBlock(), Blocks.AIR.getDefaultState(), false); + } + } + } + + abstract static class Peice extends StructureComponent + { + protected MapGenMineshaft.Type mineShaftType; + + public Peice() + { + } + + public Peice(int p_i47138_1_, MapGenMineshaft.Type p_i47138_2_) + { + super(p_i47138_1_); + this.mineShaftType = p_i47138_2_; + } + + /** + * (abstract) Helper method to write subclass data to NBT + */ + protected void writeStructureToNBT(NBTTagCompound tagCompound) + { + tagCompound.setInteger("MST", this.mineShaftType.ordinal()); + } + + /** + * (abstract) Helper method to read subclass data from NBT + */ + protected void readStructureFromNBT(NBTTagCompound tagCompound, TemplateManager p_143011_2_) + { + this.mineShaftType = MapGenMineshaft.Type.byId(tagCompound.getInteger("MST")); + } + + protected IBlockState getPlanksBlock() + { + switch (this.mineShaftType) + { + case NORMAL: + default: + return Blocks.PLANKS.getDefaultState(); + case MESA: + return Blocks.PLANKS.getDefaultState().withProperty(BlockPlanks.VARIANT, BlockPlanks.EnumType.DARK_OAK); + } + } + + protected IBlockState getFenceBlock() + { + switch (this.mineShaftType) + { + case NORMAL: + default: + return Blocks.OAK_FENCE.getDefaultState(); + case MESA: + return Blocks.DARK_OAK_FENCE.getDefaultState(); + } + } + + protected boolean isSupportingBox(World p_189918_1_, StructureBoundingBox p_189918_2_, int p_189918_3_, int p_189918_4_, int p_189918_5_, int p_189918_6_) + { + for (int i = p_189918_3_; i <= p_189918_4_; ++i) + { + if (this.getBlockStateFromPos(p_189918_1_, i, p_189918_5_ + 1, p_189918_6_, p_189918_2_).getMaterial() == Material.AIR) + { + return false; + } + } + + return true; + } + } + + public static class Room extends TestStructurePieces.Peice + { + /** List of other Mineshaft components linked to this room. */ + private final List connectedRooms = Lists.newLinkedList(); + + public Room() + { + } + + public Room(int p_i47137_1_, Random p_i47137_2_, int p_i47137_3_, int p_i47137_4_, MapGenMineshaft.Type p_i47137_5_) + { + super(p_i47137_1_, p_i47137_5_); + this.mineShaftType = p_i47137_5_; + this.boundingBox = new StructureBoundingBox(p_i47137_3_, 50, p_i47137_4_, p_i47137_3_ + 7 + p_i47137_2_.nextInt(6), 54 + p_i47137_2_.nextInt(6), p_i47137_4_ + 7 + p_i47137_2_.nextInt(6)); + } + + /** + * Initiates construction of the Structure Component picked, at the current Location of StructGen + */ + public void buildComponent(StructureComponent componentIn, List listIn, Random rand) + { + int i = this.getComponentType(); + int j = this.boundingBox.getYSize() - 3 - 1; + + if (j <= 0) + { + j = 1; + } + + int k; + + for (k = 0; k < this.boundingBox.getXSize(); k = k + 4) + { + k = k + rand.nextInt(this.boundingBox.getXSize()); + + if (k + 3 > this.boundingBox.getXSize()) + { + break; + } + + TestStructurePieces.Peice TestStructurePieces$peice = TestStructurePieces.generateAndAddPiece(componentIn, listIn, rand, this.boundingBox.minX + k, this.boundingBox.minY + rand.nextInt(j) + 1, this.boundingBox.minZ - 1, EnumFacing.NORTH, i); + + if (TestStructurePieces$peice != null) + { + StructureBoundingBox structureboundingbox = TestStructurePieces$peice.getBoundingBox(); + this.connectedRooms.add(new StructureBoundingBox(structureboundingbox.minX, structureboundingbox.minY, this.boundingBox.minZ, structureboundingbox.maxX, structureboundingbox.maxY, this.boundingBox.minZ + 1)); + } + } + + for (k = 0; k < this.boundingBox.getXSize(); k = k + 4) + { + k = k + rand.nextInt(this.boundingBox.getXSize()); + + if (k + 3 > this.boundingBox.getXSize()) + { + break; + } + + TestStructurePieces.Peice TestStructurePieces$peice1 = TestStructurePieces.generateAndAddPiece(componentIn, listIn, rand, this.boundingBox.minX + k, this.boundingBox.minY + rand.nextInt(j) + 1, this.boundingBox.maxZ + 1, EnumFacing.SOUTH, i); + + if (TestStructurePieces$peice1 != null) + { + StructureBoundingBox structureboundingbox1 = TestStructurePieces$peice1.getBoundingBox(); + this.connectedRooms.add(new StructureBoundingBox(structureboundingbox1.minX, structureboundingbox1.minY, this.boundingBox.maxZ - 1, structureboundingbox1.maxX, structureboundingbox1.maxY, this.boundingBox.maxZ)); + } + } + + for (k = 0; k < this.boundingBox.getZSize(); k = k + 4) + { + k = k + rand.nextInt(this.boundingBox.getZSize()); + + if (k + 3 > this.boundingBox.getZSize()) + { + break; + } + + TestStructurePieces.Peice TestStructurePieces$peice2 = TestStructurePieces.generateAndAddPiece(componentIn, listIn, rand, this.boundingBox.minX - 1, this.boundingBox.minY + rand.nextInt(j) + 1, this.boundingBox.minZ + k, EnumFacing.WEST, i); + + if (TestStructurePieces$peice2 != null) + { + StructureBoundingBox structureboundingbox2 = TestStructurePieces$peice2.getBoundingBox(); + this.connectedRooms.add(new StructureBoundingBox(this.boundingBox.minX, structureboundingbox2.minY, structureboundingbox2.minZ, this.boundingBox.minX + 1, structureboundingbox2.maxY, structureboundingbox2.maxZ)); + } + } + + for (k = 0; k < this.boundingBox.getZSize(); k = k + 4) + { + k = k + rand.nextInt(this.boundingBox.getZSize()); + + if (k + 3 > this.boundingBox.getZSize()) + { + break; + } + + StructureComponent structurecomponent = TestStructurePieces.generateAndAddPiece(componentIn, listIn, rand, this.boundingBox.maxX + 1, this.boundingBox.minY + rand.nextInt(j) + 1, this.boundingBox.minZ + k, EnumFacing.EAST, i); + + if (structurecomponent != null) + { + StructureBoundingBox structureboundingbox3 = structurecomponent.getBoundingBox(); + this.connectedRooms.add(new StructureBoundingBox(this.boundingBox.maxX - 1, structureboundingbox3.minY, structureboundingbox3.minZ, this.boundingBox.maxX, structureboundingbox3.maxY, structureboundingbox3.maxZ)); + } + } + } + + /** + * second Part of Structure generating, this for example places Spiderwebs, Mob Spawners, it closes + * Mineshafts at the end, it adds Fences... + */ + public boolean addComponentParts(World worldIn, Random randomIn, StructureBoundingBox structureBoundingBoxIn) + { + if (this.isLiquidInStructureBoundingBox(worldIn, structureBoundingBoxIn)) + { + return false; + } + else + { + this.fillWithBlocks(worldIn, structureBoundingBoxIn, this.boundingBox.minX, this.boundingBox.minY, this.boundingBox.minZ, this.boundingBox.maxX, this.boundingBox.minY, this.boundingBox.maxZ, Blocks.DIRT.getDefaultState(), Blocks.AIR.getDefaultState(), true); + this.fillWithBlocks(worldIn, structureBoundingBoxIn, this.boundingBox.minX, this.boundingBox.minY + 1, this.boundingBox.minZ, this.boundingBox.maxX, Math.min(this.boundingBox.minY + 3, this.boundingBox.maxY), this.boundingBox.maxZ, Blocks.AIR.getDefaultState(), Blocks.AIR.getDefaultState(), false); + + for (StructureBoundingBox structureboundingbox : this.connectedRooms) + { + this.fillWithBlocks(worldIn, structureBoundingBoxIn, structureboundingbox.minX, structureboundingbox.maxY - 2, structureboundingbox.minZ, structureboundingbox.maxX, structureboundingbox.maxY, structureboundingbox.maxZ, Blocks.AIR.getDefaultState(), Blocks.AIR.getDefaultState(), false); + } + + this.randomlyRareFillWithBlocks(worldIn, structureBoundingBoxIn, this.boundingBox.minX, this.boundingBox.minY + 4, this.boundingBox.minZ, this.boundingBox.maxX, this.boundingBox.maxY, this.boundingBox.maxZ, Blocks.AIR.getDefaultState(), false); + return true; + } + } + + public void offset(int x, int y, int z) + { + super.offset(x, y, z); + + for (StructureBoundingBox structureboundingbox : this.connectedRooms) + { + structureboundingbox.offset(x, y, z); + } + } + + /** + * (abstract) Helper method to write subclass data to NBT + */ + protected void writeStructureToNBT(NBTTagCompound tagCompound) + { + super.writeStructureToNBT(tagCompound); + NBTTagList nbttaglist = new NBTTagList(); + + for (StructureBoundingBox structureboundingbox : this.connectedRooms) + { + nbttaglist.appendTag(structureboundingbox.toNBTTagIntArray()); + } + + tagCompound.setTag("Entrances", nbttaglist); + } + + /** + * (abstract) Helper method to read subclass data from NBT + */ + protected void readStructureFromNBT(NBTTagCompound tagCompound, TemplateManager p_143011_2_) + { + super.readStructureFromNBT(tagCompound, p_143011_2_); + NBTTagList nbttaglist = tagCompound.getTagList("Entrances", 11); + + for (int i = 0; i < nbttaglist.tagCount(); ++i) + { + this.connectedRooms.add(new StructureBoundingBox(nbttaglist.getIntArrayAt(i))); + } + } + } + + public static class Stairs extends TestStructurePieces.Peice + { + public Stairs() + { + } + + public Stairs(int p_i47136_1_, Random p_i47136_2_, StructureBoundingBox p_i47136_3_, EnumFacing p_i47136_4_, MapGenMineshaft.Type p_i47136_5_) + { + super(p_i47136_1_, p_i47136_5_); + this.setCoordBaseMode(p_i47136_4_); + this.boundingBox = p_i47136_3_; + } + + public static StructureBoundingBox findStairs(List listIn, Random rand, int x, int y, int z, EnumFacing facing) + { + StructureBoundingBox structureboundingbox = new StructureBoundingBox(x, y - 5, z, x, y + 2, z); + + switch (facing) + { + case NORTH: + default: + structureboundingbox.maxX = x + 2; + structureboundingbox.minZ = z - 8; + break; + case SOUTH: + structureboundingbox.maxX = x + 2; + structureboundingbox.maxZ = z + 8; + break; + case WEST: + structureboundingbox.minX = x - 8; + structureboundingbox.maxZ = z + 2; + break; + case EAST: + structureboundingbox.maxX = x + 8; + structureboundingbox.maxZ = z + 2; + } + + return StructureComponent.findIntersecting(listIn, structureboundingbox) != null ? null : structureboundingbox; + } + + /** + * Initiates construction of the Structure Component picked, at the current Location of StructGen + */ + public void buildComponent(StructureComponent componentIn, List listIn, Random rand) + { + int i = this.getComponentType(); + EnumFacing enumfacing = this.getCoordBaseMode(); + + if (enumfacing != null) + { + switch (enumfacing) + { + case NORTH: + default: + TestStructurePieces.generateAndAddPiece(componentIn, listIn, rand, this.boundingBox.minX, this.boundingBox.minY, this.boundingBox.minZ - 1, EnumFacing.NORTH, i); + break; + case SOUTH: + TestStructurePieces.generateAndAddPiece(componentIn, listIn, rand, this.boundingBox.minX, this.boundingBox.minY, this.boundingBox.maxZ + 1, EnumFacing.SOUTH, i); + break; + case WEST: + TestStructurePieces.generateAndAddPiece(componentIn, listIn, rand, this.boundingBox.minX - 1, this.boundingBox.minY, this.boundingBox.minZ, EnumFacing.WEST, i); + break; + case EAST: + TestStructurePieces.generateAndAddPiece(componentIn, listIn, rand, this.boundingBox.maxX + 1, this.boundingBox.minY, this.boundingBox.minZ, EnumFacing.EAST, i); + } + } + } + + /** + * second Part of Structure generating, this for example places Spiderwebs, Mob Spawners, it closes + * Mineshafts at the end, it adds Fences... + */ + public boolean addComponentParts(World worldIn, Random randomIn, StructureBoundingBox structureBoundingBoxIn) + { + if (this.isLiquidInStructureBoundingBox(worldIn, structureBoundingBoxIn)) + { + return false; + } + else + { + this.fillWithBlocks(worldIn, structureBoundingBoxIn, 0, 5, 0, 2, 7, 1, Blocks.AIR.getDefaultState(), Blocks.AIR.getDefaultState(), false); + this.fillWithBlocks(worldIn, structureBoundingBoxIn, 0, 0, 7, 2, 2, 8, Blocks.AIR.getDefaultState(), Blocks.AIR.getDefaultState(), false); + + for (int i = 0; i < 5; ++i) + { + this.fillWithBlocks(worldIn, structureBoundingBoxIn, 0, 5 - i - (i < 4 ? 1 : 0), 2 + i, 2, 7 - i, 2 + i, Blocks.AIR.getDefaultState(), Blocks.AIR.getDefaultState(), false); + } + + return true; + } + } + } +} diff --git a/src/main/java/com/somebody/idlframewok/world/tree/WorldGenTestTree.java b/src/main/java/com/somebody/idlframewok/world/tree/WorldGenTestTree.java new file mode 100644 index 0000000..ee93246 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/world/tree/WorldGenTestTree.java @@ -0,0 +1,19 @@ +package com.somebody.idlframewok.world.tree; + +import java.util.Random; + +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.minecraft.world.gen.feature.WorldGenAbstractTree; + +//just gen it in worldGenNew +public class WorldGenTestTree extends WorldGenAbstractTree { + public WorldGenTestTree(boolean notify) { + super(notify); + } + + @Override + public boolean generate(World worldIn, Random rand, BlockPos position) { + return false; + } +} diff --git a/src/main/java/com/somebody/idlframewok/world/types/WorldTypeCustom.java b/src/main/java/com/somebody/idlframewok/world/types/WorldTypeCustom.java new file mode 100644 index 0000000..c277332 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/world/types/WorldTypeCustom.java @@ -0,0 +1,23 @@ +package com.somebody.idlframewok.world.types; + +import com.somebody.idlframewok.world.types.layer.GenLayerCustom; +import net.minecraft.world.WorldType; +import net.minecraft.world.gen.ChunkGeneratorSettings; +import net.minecraft.world.gen.layer.GenLayer; + +public class WorldTypeCustom extends WorldType { + /** + * Creates a new world type, the ID is hidden and should not be referenced by modders. + * It will automatically expand the underlying workdType array if there are no IDs left. + * + * @param name + */ + public WorldTypeCustom(String name) { + super(name); + } + + @Override + public GenLayer getBiomeLayer(long worldSeed, GenLayer parentLayer, ChunkGeneratorSettings chunkSettings) { + return new GenLayerCustom(worldSeed, parentLayer, this, chunkSettings); + } +} diff --git a/src/main/java/com/somebody/idlframewok/world/types/WorldTypeOne.java b/src/main/java/com/somebody/idlframewok/world/types/WorldTypeOne.java new file mode 100644 index 0000000..75e74ce --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/world/types/WorldTypeOne.java @@ -0,0 +1,25 @@ +package com.somebody.idlframewok.world.types; + +import net.minecraft.world.WorldType; + +public class WorldTypeOne extends WorldType { + /** + * Creates a new world type, the ID is hidden and should not be referenced by modders. + * It will automatically expand the underlying workdType array if there are no IDs left. + * + * @param name + */ + public WorldTypeOne(String name) { + super(name); + } + + public WorldTypeOne() { + super("TYPE_ONE"); + } + +// @Override +// public BiomeProvider getBiomeProvider(World world) { +// +// return new BiomeProviderSingle(InitBiome.BIOME_ONE); +// } +} diff --git a/src/main/java/com/somebody/idlframewok/world/types/layer/GenLayerCustom.java b/src/main/java/com/somebody/idlframewok/world/types/layer/GenLayerCustom.java new file mode 100644 index 0000000..2df8f2d --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/world/types/layer/GenLayerCustom.java @@ -0,0 +1,139 @@ +package com.somebody.idlframewok.world.types.layer; + +import net.minecraft.init.Biomes; +import net.minecraft.world.WorldType; +import net.minecraft.world.biome.Biome; +import net.minecraft.world.gen.ChunkGeneratorSettings; +import net.minecraft.world.gen.layer.GenLayer; +import net.minecraft.world.gen.layer.IntCache; + +public class GenLayerCustom extends GenLayer +{ + @SuppressWarnings("unchecked") + private java.util.List[] biomes = new java.util.ArrayList[net.minecraftforge.common.BiomeManager.BiomeType.values().length]; + private final ChunkGeneratorSettings settings; + + public GenLayerCustom(long p_i45560_1_, GenLayer p_i45560_3_, WorldType p_i45560_4_, ChunkGeneratorSettings p_i45560_5_) + { + super(p_i45560_1_); + this.parent = p_i45560_3_; + + for (net.minecraftforge.common.BiomeManager.BiomeType type : net.minecraftforge.common.BiomeManager.BiomeType.values()) + { + com.google.common.collect.ImmutableList biomesToAdd = net.minecraftforge.common.BiomeManager.getBiomes(type); + int idx = type.ordinal(); + + if (biomes[idx] == null) biomes[idx] = new java.util.ArrayList(); + if (biomesToAdd != null) biomes[idx].addAll(biomesToAdd); + } + + int desertIdx = net.minecraftforge.common.BiomeManager.BiomeType.DESERT.ordinal(); + + biomes[desertIdx].add(new net.minecraftforge.common.BiomeManager.BiomeEntry(Biomes.EXTREME_HILLS, 30)); + //biomes[desertIdx].add(new net.minecraftforge.common.BiomeManager.BiomeEntry(BIOME_ONE, 30)); + + if (p_i45560_4_ == WorldType.DEFAULT_1_1) + { + biomes[desertIdx].clear(); + biomes[desertIdx].add(new net.minecraftforge.common.BiomeManager.BiomeEntry(Biomes.EXTREME_HILLS, 30)); + //biomes[desertIdx].add(new net.minecraftforge.common.BiomeManager.BiomeEntry(BIOME_ONE, 30)); + this.settings = null; + } + else + { + this.settings = p_i45560_5_; + } + } + + /** + * Returns a list of integer values generated by this layer. These may be interpreted as temperatures, rainfall + * amounts, or Biome ID's based on the particular GenLayer subclass. + */ + public int[] getInts(int areaX, int areaY, int areaWidth, int areaHeight) + { + int[] aint = this.parent.getInts(areaX, areaY, areaWidth, areaHeight); + int[] aint1 = IntCache.getIntCache(areaWidth * areaHeight); + + for (int i = 0; i < areaHeight; ++i) + { + for (int j = 0; j < areaWidth; ++j) + { + this.initChunkSeed((long)(j + areaX), (long)(i + areaY)); + int k = aint[j + i * areaWidth]; + int l = (k & 3840) >> 8; + k = k & -3841; + + if (this.settings != null && this.settings.fixedBiome >= 0) + { + aint1[j + i * areaWidth] = this.settings.fixedBiome; + } + else if (isBiomeOceanic(k)) + { + aint1[j + i * areaWidth] = k; + } + else if (k == Biome.getIdForBiome(Biomes.MUSHROOM_ISLAND)) + { + aint1[j + i * areaWidth] = k; + } + else if (k == 1) + { + if (l > 0) + { + if (this.nextInt(3) == 0) + { + aint1[j + i * areaWidth] = Biome.getIdForBiome(Biomes.MESA_CLEAR_ROCK); + } + else + { + aint1[j + i * areaWidth] = Biome.getIdForBiome(Biomes.MESA_ROCK); + } + } + else + { + aint1[j + i * areaWidth] = Biome.getIdForBiome(getWeightedBiomeEntry(net.minecraftforge.common.BiomeManager.BiomeType.DESERT).biome); + } + } + else if (k == 2) + { + if (l > 0) + { + aint1[j + i * areaWidth] = Biome.getIdForBiome(Biomes.JUNGLE); + } + else + { + aint1[j + i * areaWidth] = Biome.getIdForBiome(getWeightedBiomeEntry(net.minecraftforge.common.BiomeManager.BiomeType.WARM).biome); + } + } + else if (k == 3) + { + if (l > 0) + { + aint1[j + i * areaWidth] = Biome.getIdForBiome(Biomes.REDWOOD_TAIGA); + } + else + { + aint1[j + i * areaWidth] = Biome.getIdForBiome(getWeightedBiomeEntry(net.minecraftforge.common.BiomeManager.BiomeType.COOL).biome); + } + } + else if (k == 4) + { + aint1[j + i * areaWidth] = Biome.getIdForBiome(getWeightedBiomeEntry(net.minecraftforge.common.BiomeManager.BiomeType.ICY).biome); + } + else + { + aint1[j + i * areaWidth] = Biome.getIdForBiome(Biomes.MUSHROOM_ISLAND); + } + } + } + + return aint1; + } + + protected net.minecraftforge.common.BiomeManager.BiomeEntry getWeightedBiomeEntry(net.minecraftforge.common.BiomeManager.BiomeType type) + { + java.util.List biomeList = biomes[type.ordinal()]; + int totalWeight = net.minecraft.util.WeightedRandom.getTotalWeight(biomeList); + int weight = net.minecraftforge.common.BiomeManager.isTypeListModded(type)?nextInt(totalWeight):nextInt(totalWeight / 10) * 10; + return (net.minecraftforge.common.BiomeManager.BiomeEntry)net.minecraft.util.WeightedRandom.getRandomItem(biomeList, weight); + } +} \ No newline at end of file diff --git a/src/main/java/com/somebody/idlframewok/worldgen/ModWorldGenNew.java b/src/main/java/com/somebody/idlframewok/worldgen/ModWorldGenNew.java new file mode 100644 index 0000000..0cd9343 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/worldgen/ModWorldGenNew.java @@ -0,0 +1,109 @@ +package com.somebody.idlframewok.worldgen; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Random; + +import net.minecraft.block.Block; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.minecraft.world.WorldType; +import net.minecraft.world.chunk.IChunkProvider; +import net.minecraft.world.gen.IChunkGenerator; +import net.minecraft.world.gen.feature.WorldGenerator; +import net.minecraftforge.fml.common.IWorldGenerator; + +public class ModWorldGenNew implements IWorldGenerator { + + //Please register this in preInitRegistries + + private WorldGenerator testGen1, testGen2; + + public ModWorldGenNew() { +// testGen1 = new WorldGenMinable(Blocks.DIAMOND_BLOCK.getDefaultState(), +// 9, BlockMatcher.forBlock(Blocks.NETHERRACK)); +// +// testGen2 = new WorldGenMinable(Blocks.GOLD_BLOCK.getDefaultState(), +// 4); + } + + @Override + public void generate(Random random, int chunkX, int chunkZ, World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider) { + switch (world.provider.getDimension()) + { + case -1: + //nether + //runGenOre(testGen1, world, random, chunkX, chunkZ, 60, 16, 38); + break; + case 0: + //overworld + //IdlFramework.Log("world gen running"); + + //runGenOre(testGen2, world, random, chunkX, chunkZ, 32, 16, 18); + + break; + case 1: + //end + break; + } + } + + //Utility + + //Ore + void runGenOre(WorldGenerator gen, World world, Random rand, int chunkX, int chunkZ, int chances, int minHeight, int maxHeight) + { + if (minHeight > maxHeight || minHeight < 0 || maxHeight > 256) + { + throw new IllegalArgumentException("Ore gen out of bounds"); + } + + int heightDiff = maxHeight - minHeight + 1; + + for (int i = 0; i < chances; i++) { + int x = chunkX * 16 + rand.nextInt(16); + int y = minHeight + rand.nextInt(heightDiff); + int z = chunkZ * 16 + rand.nextInt(16); + + gen.generate(world, rand, new BlockPos(x,y,z)); + } + } + + //Trees + private void runGenerator(WorldGenerator generator, World world, Random random, int chunkX, int chunkZ, int chance, Block topBlock, Class... classes) + { + ArrayList> classesList = new ArrayList>(Arrays.asList(classes)); + + int x = (chunkX * 16) + random.nextInt(15); + int z = (chunkZ * 16) + random.nextInt(15); + int y = calculateGroundHeight(world, x, z, topBlock); + BlockPos pos = new BlockPos(x,y,z); + + Class biome = world.provider.getBiomeForCoords(pos).getClass(); + + if(world.getWorldType() != WorldType.FLAT) + { + if(classesList.contains(biome)) + { + if(random.nextInt(chance) == 0) + { + generator.generate(world, random, pos); + } + } + } + } + + private static int calculateGroundHeight(World world, int x, int z, Block groundBlock) + { + int y = world.getHeight(); + boolean foundGround = false; + + while(!foundGround && y-- >= 0) + { + Block block = world.getBlockState(new BlockPos(x,y,z)).getBlock(); + foundGround = block == groundBlock; + } + + return y; + } +} diff --git a/src/main/java/com/somebody/idlframewok/worldgen/ModWorldGenOld.java b/src/main/java/com/somebody/idlframewok/worldgen/ModWorldGenOld.java new file mode 100644 index 0000000..f4a1e66 --- /dev/null +++ b/src/main/java/com/somebody/idlframewok/worldgen/ModWorldGenOld.java @@ -0,0 +1,52 @@ +package com.somebody.idlframewok.worldgen; + +import java.util.Random; + +import net.minecraft.block.state.IBlockState; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.minecraft.world.chunk.IChunkProvider; +import net.minecraft.world.gen.IChunkGenerator; +import net.minecraft.world.gen.feature.WorldGenMinable; +import net.minecraftforge.fml.common.IWorldGenerator; + +public class ModWorldGenOld implements IWorldGenerator { + + //Please register this in preInitRegistries + + @Override + public void generate(Random random, int chunkX, int chunkZ, World world, IChunkGenerator chunkGenerator, + IChunkProvider chunkProvider) { + + if (world.provider.getDimension() == 0) { + generateOverworld(random, chunkX, chunkZ, world, chunkGenerator, chunkProvider); + } + + + } + + private void generateOverworld(Random random, int chunkX, int chunkZ, World world, IChunkGenerator chunkGenerator, + IChunkProvider chunkProvider) + { + int perCluster = 3; + + //generateOre(ModBlocks.DIVINE_ORE.getDefaultState(), world, random, chunkX * 16, chunkZ * 16, 5, 12, random.nextInt(perCluster) + 4, 2); + + perCluster = 6; + //generateOre(ModBlocks.PURE_ORE.getDefaultState(), world, random, chunkX * 16, chunkZ * 16, 10, 58, random.nextInt(perCluster) + 2, 20); + //generateOre(ModBlocks.COPPER_ORE.getDefaultState(), world, random, chunkX * 16, chunkZ * 16, 16, 64, random.nextInt(perCluster) + 15, 18); + } + + private void generateOre(IBlockState ore, World world, Random random, int x, int z, int minY, int maxY, int size, int chances) + { + int deltaY = maxY - minY; + + for (int i = 0; i < chances; i++) { + BlockPos pos = new BlockPos(x + random.nextInt(16), minY + random.nextInt(deltaY), z + random.nextInt(16)); + + WorldGenMinable generator = new WorldGenMinable(ore, size); + generator.generate(world, random, pos); + } + } + +} diff --git a/src/main/java/mods/somebody/example/Example.java b/src/main/java/mods/somebody/example/Example.java deleted file mode 100644 index 610247f..0000000 --- a/src/main/java/mods/somebody/example/Example.java +++ /dev/null @@ -1,16 +0,0 @@ -package mods.somebody.example; - -import java.lang.String; - -import net.minecraftforge.fml.common.Mod; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -@Mod(modid = Example.MODID) -public class Example { - public static final String MODID = "modid"; - - public static Logger LOGGER = LogManager.getLogger(MODID); - -} \ No newline at end of file diff --git a/src/main/resources/assets/idlframework/blockstates/backup.json b/src/main/resources/assets/idlframework/blockstates/backup.json new file mode 100644 index 0000000..6b75677 --- /dev/null +++ b/src/main/resources/assets/idlframework/blockstates/backup.json @@ -0,0 +1,12 @@ +{ + "variants": { + "half=true,open=false,powered=false": { "model": "idealland:idealland_extraction_door_closed", "x": 0, "y": 0 }, + "half=true,open=true,powered=false": { "model": "idealland:idealland_extraction_door_closed", "x": 0, "y": 0 }, + "half=true,powered=true,open=false": { "model": "idealland:idealland_extraction_door_opened_top", "x": 0, "y": 0 }, + "half=true,powered=true,open=true": { "model": "idealland:idealland_extraction_door_opened_top", "x": 0, "y": 0 }, + "half=false,powered=false,open=false": { "model": "idealland:idealland_extraction_door_closed", "x": 0, "y": 0 }, + "half=false,powered=false,open=true": { "model": "idealland:idealland_extraction_door_opened_top", "x": 180, "y": 0 }, + "half=false,powered=true,open=false": { "model": "idealland:idealland_extraction_door_closed", "x": 0, "y": 0 }, + "half=false,powered=true,open=true": { "model": "idealland:idealland_extraction_door_opened_top", "x": 180, "y": 0 }, + } +} diff --git a/src/main/resources/assets/idlframework/blockstates/block_fence.json b/src/main/resources/assets/idlframework/blockstates/block_fence.json new file mode 100644 index 0000000..f539184 --- /dev/null +++ b/src/main/resources/assets/idlframework/blockstates/block_fence.json @@ -0,0 +1,5 @@ +{ + "variants": { + "normal": { "model": "idealland:block_fence" } + } +} diff --git a/src/main/resources/assets/idlframework/blockstates/builder_farm.json b/src/main/resources/assets/idlframework/blockstates/builder_farm.json new file mode 100644 index 0000000..9e900b5 --- /dev/null +++ b/src/main/resources/assets/idlframework/blockstates/builder_farm.json @@ -0,0 +1,5 @@ +{ + "variants": { + "normal": { "model": "idealland:builder_farm" } + } +} diff --git a/src/main/resources/assets/idlframework/blockstates/builder_farm_sin.json b/src/main/resources/assets/idlframework/blockstates/builder_farm_sin.json new file mode 100644 index 0000000..f7d2f7f --- /dev/null +++ b/src/main/resources/assets/idlframework/blockstates/builder_farm_sin.json @@ -0,0 +1,5 @@ +{ + "variants": { + "normal": { "model": "idealland:builder_farm_sin" } + } +} diff --git a/src/main/resources/assets/idlframework/blockstates/builder_house.json b/src/main/resources/assets/idlframework/blockstates/builder_house.json new file mode 100644 index 0000000..7aada7a --- /dev/null +++ b/src/main/resources/assets/idlframework/blockstates/builder_house.json @@ -0,0 +1,5 @@ +{ + "variants": { + "normal": { "model": "idealland:builder_house" } + } +} diff --git a/src/main/resources/assets/idlframework/blockstates/builder_one.json b/src/main/resources/assets/idlframework/blockstates/builder_one.json new file mode 100644 index 0000000..1686f5f --- /dev/null +++ b/src/main/resources/assets/idlframework/blockstates/builder_one.json @@ -0,0 +1,5 @@ +{ + "variants": { + "normal": { "model": "idealland:builder_one" } + } +} diff --git a/src/main/resources/assets/idlframework/blockstates/building_zabeen_site.json b/src/main/resources/assets/idlframework/blockstates/building_zabeen_site.json new file mode 100644 index 0000000..aa132b4 --- /dev/null +++ b/src/main/resources/assets/idlframework/blockstates/building_zabeen_site.json @@ -0,0 +1,5 @@ +{ + "variants": { + "normal": { "model": "idealland:building_zabeen_site" } + } +} diff --git a/src/main/resources/assets/idlframework/blockstates/construction_site.json b/src/main/resources/assets/idlframework/blockstates/construction_site.json new file mode 100644 index 0000000..736ca55 --- /dev/null +++ b/src/main/resources/assets/idlframework/blockstates/construction_site.json @@ -0,0 +1,5 @@ +{ + "variants": { + "normal": { "model": "idealland:construction_site" } + } +} diff --git a/src/main/resources/assets/idlframework/blockstates/de_arrow_orb.json b/src/main/resources/assets/idlframework/blockstates/de_arrow_orb.json new file mode 100644 index 0000000..c591bf6 --- /dev/null +++ b/src/main/resources/assets/idlframework/blockstates/de_arrow_orb.json @@ -0,0 +1,5 @@ +{ + "variants": { + "normal": { "model": "idealland:de_arrow_orb" } + } +} diff --git a/src/main/resources/assets/idlframework/blockstates/de_boom_orb.json b/src/main/resources/assets/idlframework/blockstates/de_boom_orb.json new file mode 100644 index 0000000..682d035 --- /dev/null +++ b/src/main/resources/assets/idlframework/blockstates/de_boom_orb.json @@ -0,0 +1,5 @@ +{ + "variants": { + "normal": { "model": "idealland:de_boom_orb" } + } +} diff --git a/src/main/resources/assets/idlframework/blockstates/de_water_orb.json b/src/main/resources/assets/idlframework/blockstates/de_water_orb.json new file mode 100644 index 0000000..0aabdc0 --- /dev/null +++ b/src/main/resources/assets/idlframework/blockstates/de_water_orb.json @@ -0,0 +1,5 @@ +{ + "variants": { + "normal": { "model": "idealland:de_water_orb" } + } +} diff --git a/src/main/resources/assets/idlframework/blockstates/divine_ore.json b/src/main/resources/assets/idlframework/blockstates/divine_ore.json new file mode 100644 index 0000000..bf2c82e --- /dev/null +++ b/src/main/resources/assets/idlframework/blockstates/divine_ore.json @@ -0,0 +1,5 @@ +{ + "variants": { + "normal": { "model": "dweapon:divine_ore" } + } +} \ No newline at end of file diff --git a/src/main/resources/assets/idlframework/blockstates/earth_mender_basic.json b/src/main/resources/assets/idlframework/blockstates/earth_mender_basic.json new file mode 100644 index 0000000..a61c1b0 --- /dev/null +++ b/src/main/resources/assets/idlframework/blockstates/earth_mender_basic.json @@ -0,0 +1,5 @@ +{ + "variants": { + "normal": { "model": "idealland:earth_mender_basic" } + } +} \ No newline at end of file diff --git a/src/main/resources/assets/idlframework/blockstates/fence_brick.json b/src/main/resources/assets/idlframework/blockstates/fence_brick.json new file mode 100644 index 0000000..c430c1a --- /dev/null +++ b/src/main/resources/assets/idlframework/blockstates/fence_brick.json @@ -0,0 +1,5 @@ +{ + "variants": { + "normal": { "model": "idealland:fence_brick" } + } +} diff --git a/src/main/resources/assets/idlframework/blockstates/grid_dark_2.json b/src/main/resources/assets/idlframework/blockstates/grid_dark_2.json new file mode 100644 index 0000000..28008a8 --- /dev/null +++ b/src/main/resources/assets/idlframework/blockstates/grid_dark_2.json @@ -0,0 +1,5 @@ +{ + "variants": { + "normal": { "model": "idealland:grid_dark_2" } + } +} diff --git a/src/main/resources/assets/idlframework/blockstates/grid_lamp.json b/src/main/resources/assets/idlframework/blockstates/grid_lamp.json new file mode 100644 index 0000000..71cfe54 --- /dev/null +++ b/src/main/resources/assets/idlframework/blockstates/grid_lamp.json @@ -0,0 +1,5 @@ +{ + "variants": { + "normal": { "model": "idealland:grid_lamp" } + } +} diff --git a/src/main/resources/assets/idlframework/blockstates/grid_normal.json b/src/main/resources/assets/idlframework/blockstates/grid_normal.json new file mode 100644 index 0000000..8e4b19c --- /dev/null +++ b/src/main/resources/assets/idlframework/blockstates/grid_normal.json @@ -0,0 +1,5 @@ +{ + "variants": { + "normal": { "model": "idealland:grid_normal" } + } +} diff --git a/src/main/resources/assets/idlframework/blockstates/idealland_extraction_door.json b/src/main/resources/assets/idlframework/blockstates/idealland_extraction_door.json new file mode 100644 index 0000000..b539a0f --- /dev/null +++ b/src/main/resources/assets/idlframework/blockstates/idealland_extraction_door.json @@ -0,0 +1,20 @@ +{ + "variants": { + "facing=down_z,powered=false": { "model": "idealland:idealland_extraction_door", "x": 180, "y": 180 }, + "facing=down_x,powered=false": { "model": "idealland:idealland_extraction_door", "x": 180, "y": 90 }, + "facing=up_z,powered=false": { "model": "idealland:idealland_extraction_door" }, + "facing=up_x,powered=false": { "model": "idealland:idealland_extraction_door", "y": 270 }, + "facing=east,powered=false": { "model": "idealland:idealland_extraction_door", "x": 90, "y": 90 }, + "facing=west,powered=false": { "model": "idealland:idealland_extraction_door", "x": 90, "y": 270 }, + "facing=south,powered=false" : { "model": "idealland:idealland_extraction_door", "x": 90, "y": 180 }, + "facing=north,powered=false" : { "model": "idealland:idealland_extraction_door", "x": 90 }, + "facing=down_z,powered=true" : { "model": "idealland:idealland_extraction_door_opened", "x": 180, "y": 180 }, + "facing=down_x,powered=true" : { "model": "idealland:idealland_extraction_door_opened", "x": 180, "y": 90 }, + "facing=up_z,powered=true": { "model": "idealland:idealland_extraction_door_opened" }, + "facing=up_x,powered=true": { "model": "idealland:idealland_extraction_door_opened", "y": 270 }, + "facing=east,powered=true": { "model": "idealland:idealland_extraction_door_opened", "x": 90, "y": 90 }, + "facing=west,powered=true": { "model": "idealland:idealland_extraction_door_opened", "x": 90, "y": 270 }, + "facing=south,powered=true": { "model": "idealland:idealland_extraction_door_opened", "x": 90, "y": 180 }, + "facing=north,powered=true": { "model": "idealland:idealland_extraction_door_opened", "x": 90 } + } +} \ No newline at end of file diff --git a/src/main/resources/assets/idlframework/blockstates/idealland_light_basic.json b/src/main/resources/assets/idlframework/blockstates/idealland_light_basic.json new file mode 100644 index 0000000..e0de54a --- /dev/null +++ b/src/main/resources/assets/idlframework/blockstates/idealland_light_basic.json @@ -0,0 +1,5 @@ +{ + "variants": { + "normal": { "model": "idealland:idealland_light_basic" } + } +} \ No newline at end of file diff --git a/src/main/resources/assets/idlframework/blockstates/idl_glass.json b/src/main/resources/assets/idlframework/blockstates/idl_glass.json new file mode 100644 index 0000000..a7693be --- /dev/null +++ b/src/main/resources/assets/idlframework/blockstates/idl_glass.json @@ -0,0 +1,5 @@ +{ + "variants": { + "normal": { "model": "idealland:idl_glass" } + } +} diff --git a/src/main/resources/assets/idlframework/blockstates/moroon_block.json b/src/main/resources/assets/idlframework/blockstates/moroon_block.json new file mode 100644 index 0000000..e944dda --- /dev/null +++ b/src/main/resources/assets/idlframework/blockstates/moroon_block.json @@ -0,0 +1,5 @@ +{ + "variants": { + "normal": { "model": "idealland:moroon_block" } + } +} diff --git a/src/main/resources/assets/idlframework/blockstates/nullify_orb.json b/src/main/resources/assets/idlframework/blockstates/nullify_orb.json new file mode 100644 index 0000000..b803909 --- /dev/null +++ b/src/main/resources/assets/idlframework/blockstates/nullify_orb.json @@ -0,0 +1,5 @@ +{ + "variants": { + "normal": { "model": "idealland:nullify_orb" } + } +} diff --git a/src/main/resources/assets/idlframework/blockstates/nullify_orb_mor.json b/src/main/resources/assets/idlframework/blockstates/nullify_orb_mor.json new file mode 100644 index 0000000..94e33f8 --- /dev/null +++ b/src/main/resources/assets/idlframework/blockstates/nullify_orb_mor.json @@ -0,0 +1,5 @@ +{ + "variants": { + "normal": { "model": "idealland:nullify_orb_mor" } + } +} diff --git a/src/main/resources/assets/idlframework/blockstates/pure_ore.json b/src/main/resources/assets/idlframework/blockstates/pure_ore.json new file mode 100644 index 0000000..f9d6e05 --- /dev/null +++ b/src/main/resources/assets/idlframework/blockstates/pure_ore.json @@ -0,0 +1,5 @@ +{ + "variants": { + "normal": { "model": "dweapon:pure_ore" } + } +} \ No newline at end of file diff --git a/src/main/resources/assets/idlframework/blockstates/test.json b/src/main/resources/assets/idlframework/blockstates/test.json new file mode 100644 index 0000000..829b005 --- /dev/null +++ b/src/main/resources/assets/idlframework/blockstates/test.json @@ -0,0 +1,5 @@ +{ + "variants": { + "normal": { "model": "idealland:test" } + } +} diff --git a/src/main/resources/assets/idlframework/lang/en_us.lang b/src/main/resources/assets/idlframework/lang/en_us.lang new file mode 100644 index 0000000..21170e2 --- /dev/null +++ b/src/main/resources/assets/idlframework/lang/en_us.lang @@ -0,0 +1,83 @@ +#PARSE_ESCAPES +#tabs +itemGroup.ideallandMiscTab=IDL Hall + +generator.TYPE_ONE=Type One; +generator.TYPE_TWO=Type Two; + +#config +configgui.idealland.category.Menu0.GeneralConf=General Config +idealland.conf.general.welcome=Welcome Message Key + +#Enchantments +enchantment.idealland.test_enchantment=Early Access + +#Messages +idealland.moroon_incoming_herald=[IDL][Warn] The Moroon are interested in your fights. +idealland.msg.notice_meter_report=[IDL] Moroon notice value: %d, invasion: %d/%d, error:%d + +#Potions +idealland.potion.deadly=Deadly +idealland.potion.zen_heart=Countless Virtue + + +#Entities +entity.moroon_tainter.name=Moroon Pathfinder + +#Blocks +tile.idealland_light_basic.name=Idealland Lamp + +tile.test.name=Idealland Block A + +#Items +idealland.food.shared.xp_desc=Grants XP: %d +idealland.gua_enhance_no_free.desc=Use anvil to socket Gua(Elemental) +idealland.gua_enhance_free.desc=Free Gua Sockets(Direct craft): %d + +idealland.gua_enhance_total.desc=Gua Enhance Total: %d +idealland.shared.press_shift=Hold SHIFT to examine info. + +fading.duration.desc=Vanishes after %d seconds + +item.debug_test.name=Debug Item +item.debug_test.desc=For debuging. Not for playing. + +item.xie_geta.name=Geta of Mr.Xie +item.xie_geta.desc.0=Uphill mode. Grants Lv.%s Jump Boost. +item.xie_geta.desc.1=Flat ground mode. Grants Lv.%s Speed. +item.xie_geta.desc.2=Down hill mode. Reduces %s fall damage. + +item.p2w_goblet.name=P.2.W. Chalice +item.p2w_goblet.desc=Pay gold to increase your power. (Try crafting it with the 8 elements and gold) +item.p2w_goblet.contain.desc=Containing %d exp. +item.p2w_goblet.player.desc=Owner power: Lv.%d (%d/%d exp) + +#Skills +idealland.skill.shared.cool_down_desc=Cooldown: %.1fs +idealland.skill.shared.power_desc=Damage: %.1f +idealland.skill.shared.range_desc=Radius: %.1f block +idealland.skill.shared.duration_desc=Duration: %.1fs +idealland.skill.shared.error_desc=Error: +-%d +idealland.skill.shared.level_desc=Level: %d/%d +idealland.skill.shared.name_format=%s +idealland.skill.shared.name_format_with_lv=%s Lv.%s %s +idealland.skill.shared.lv_max=[MAX] + +idealland.gua_enhance_list.desc=Earth %s Thunder %s\nWater %s Mountain %s\nLake %s Fire %s\nWind%s Sky%s +idealland.gua_not_applicable.desc=- + +idealland.kill_count.desc=Kills: %d + +idealland.skill.msg.cool_down=Cooling Down. + +#Death +#examples +#death.fell.accident.ladder=%1$s fell off a ladder +#death.fell.accident.vines=%1$s fell off some vines +#death.fell.accident.water=%1$s fell out of the water +#death.fell.accident.generic=%1$s fell from a high place +#death.fell.killer=%1$s was doomed to fall +#death.fell.assist=%1$s was doomed to fall by %2$s +#death.fell.assist.item=%1$s was doomed to fall by %2$s using %3$s +#death.fell.finish=%1$s fell too far and was finished by %2$s +#death.fell.finish.item=%1$s fell too far and was finished by %2$s using %3$s diff --git a/src/main/resources/assets/idlframework/lang/zh_cn.lang b/src/main/resources/assets/idlframework/lang/zh_cn.lang new file mode 100644 index 0000000..40c3639 --- /dev/null +++ b/src/main/resources/assets/idlframework/lang/zh_cn.lang @@ -0,0 +1,67 @@ +# PARSE_ESCAPES +itemGroup.ideallandMiscTab=理境大厅 + +generator.TYPE_ONE=Type One; +generator.TYPE_TWO=Type Two; + +# config +configgui.idealland.category.Menu0.GeneralConf=综合选项 +idealland.conf.general.welcome=欢迎词 + +# Enchantments +enchantment.idealland.test_enchantment=测试期 + +idealland.moroon_incoming_herald=[IDL][注意] 摩隆密切关注着你的战斗。 +idealland.msg.notice_meter_report=[IDL]摩隆注意度: %d, 入侵准备: %d/%d, 测量误差:%d + +# Potions +idealland.potion.deadly=致死 +idealland.potion.zen_heart=功德无量 + + +entity.moroon_tainter.name=摩隆 拓荒者 + +tile.idealland_light_basic.name=理境灯 + +tile.test.name=理境测试块 + +idealland.food.shared.xp_desc=含有经验: %d +# Items +idealland.gua_enhance_no_free.desc=可用铁砧镶嵌卦象 +idealland.gua_enhance_free.desc=徒手卦象镶嵌槽: %d + +# Items +idealland.gua_enhance_total.desc=卦象强化: %d +idealland.shared.press_shift=长按SHIFT查看详情 + +fading.duration.desc=%d 秒后消失。 + +item.debug_test.name=调试物品 +item.debug_test.desc= 在主手时减少受到的伤害 %d ;\n 造成 %d 电击伤害;\n 付与虚弱 Lv.%d (%d s);\n 击退 Lv.%d;\n 付与自身击退抗性 Lv.%d (%d s);\n 付与 %d 火焰伤害并点燃目标(%d s);\n 治疗双方 %d 点生命. + +item.xie_geta.name=谢公屐 +item.xie_geta.desc.0=上山模式,赋予%s级跳跃提升\n 右键地面切换模式 +item.xie_geta.desc.1=平地模式,赋予%s级速度\n 右键地面切换模式 +item.xie_geta.desc.2=下山模式,赋予I级缓慢并减少受到的摔落伤害 %s 点。\n 右键地面切换模式 + +item.p2w_goblet.name=销金杯[装填模式] +item.p2w_goblet.desc=氪金让你变强,强到骨子里。(塞金子升级,塞八卦、镐、食物可以改变模式) +item.p2w_goblet.contain.desc=融解 %d 金 +item.p2w_goblet.player.desc=黄金之力:等级%d (%d/%d 金) + +idealland.skill.shared.cool_down_desc=冷却: %.1f秒 +idealland.skill.shared.power_desc=伤害: %.1f +idealland.skill.shared.range_desc=半径: %.1f 格 +idealland.skill.shared.duration_desc=持续: %.1f秒 +idealland.skill.shared.error_desc=误差: +-%d +idealland.skill.shared.level_desc=等级: %d/%d +idealland.skill.shared.name_format=%s +idealland.skill.shared.name_format_with_lv=%s (%s级) %s +idealland.skill.shared.lv_max=[满] + +idealland.gua_enhance_list.desc=地%s 雷%s 水%s 山%s \n 泽%s 火%s 风%s 天%s +idealland.gua_not_applicable.desc=- + +idealland.kill_count.desc=杀敌数: %d + +idealland.skill.msg.cool_down=冷却中 \ No newline at end of file diff --git a/src/main/resources/assets/idlframework/loot_table/chests/abandoned_mineshaft.json b/src/main/resources/assets/idlframework/loot_table/chests/abandoned_mineshaft.json new file mode 100644 index 0000000..d3b0e2e --- /dev/null +++ b/src/main/resources/assets/idlframework/loot_table/chests/abandoned_mineshaft.json @@ -0,0 +1,276 @@ +{ + "pools": [ + { + "rolls": 1, + "entries": [ + { + "type": "item", + "name": "minecraft:golden_apple", + "weight": 20 + }, + { + "type": "item", + "name": "minecraft:golden_apple", + "weight": 1, + "functions": [ + { + "function": "set_data", + "data": 1 + } + ] + }, + { + "type": "item", + "name": "minecraft:name_tag", + "weight": 30 + }, + { + "type": "item", + "name": "minecraft:book", + "weight": 10, + "functions": [ + { + "function": "enchant_randomly" + } + ] + }, + { + "type": "item", + "name": "minecraft:iron_pickaxe", + "weight": 5 + }, + { + "type": "empty", + "weight": 5 + } + ] + }, + { + "rolls": { + "min": 2, + "max": 4 + }, + "entries": [ + { + "type": "item", + "name": "minecraft:iron_ingot", + "functions": [ + { + "function": "set_count", + "count": { + "min": 1, + "max": 5 + } + } + ], + "weight": 10 + }, + { + "type": "item", + "name": "minecraft:gold_ingot", + "functions": [ + { + "function": "set_count", + "count": { + "min": 1, + "max": 3 + } + } + ], + "weight": 5 + }, + { + "type": "item", + "name": "minecraft:redstone", + "functions": [ + { + "function": "set_count", + "count": { + "min": 4, + "max": 9 + } + } + ], + "weight": 5 + }, + { + "type": "item", + "name": "minecraft:dye", + "functions": [ + { + "function": "set_data", + "data": 4 + }, + { + "function": "set_count", + "count": { + "min": 4, + "max": 9 + } + } + ], + "weight": 5 + }, + { + "type": "item", + "name": "minecraft:diamond", + "functions": [ + { + "function": "set_count", + "count": { + "min": 1, + "max": 2 + } + } + ], + "weight": 3 + }, + { + "type": "item", + "name": "minecraft:coal", + "functions": [ + { + "function": "set_count", + "count": { + "min": 3, + "max": 8 + } + } + ], + "weight": 10 + }, + { + "type": "item", + "name": "minecraft:bread", + "functions": [ + { + "function": "set_count", + "count": { + "min": 1, + "max": 3 + } + } + ], + "weight": 15 + }, + { + "type": "item", + "name": "minecraft:melon_seeds", + "functions": [ + { + "function": "set_count", + "count": { + "min": 2, + "max": 4 + } + } + ], + "weight": 10 + }, + { + "type": "item", + "name": "minecraft:pumpkin_seeds", + "functions": [ + { + "function": "set_count", + "count": { + "min": 2, + "max": 4 + } + } + ], + "weight": 10 + }, + { + "type": "item", + "name": "minecraft:beetroot_seeds", + "functions": [ + { + "function": "set_count", + "count": { + "min": 2, + "max": 4 + } + } + ], + "weight": 10 + } + ] + }, + { + "rolls": 3, + "entries": [ + { + "type": "item", + "name": "minecraft:rail", + "functions": [ + { + "function": "set_count", + "count": { + "min": 4, + "max": 8 + } + } + ], + "weight": 20 + }, + { + "type": "item", + "name": "minecraft:golden_rail", + "functions": [ + { + "function": "set_count", + "count": { + "min": 1, + "max": 4 + } + } + ], + "weight": 5 + }, + { + "type": "item", + "name": "minecraft:detector_rail", + "functions": [ + { + "function": "set_count", + "count": { + "min": 1, + "max": 4 + } + } + ], + "weight": 5 + }, + { + "type": "item", + "name": "minecraft:activator_rail", + "functions": [ + { + "function": "set_count", + "count": { + "min": 1, + "max": 4 + } + } + ], + "weight": 5 + }, + { + "type": "item", + "name": "minecraft:torch", + "functions": [ + { + "function": "set_count", + "count": { + "min": 1, + "max": 16 + } + } + ], + "weight": 15 + } + ] + } + ] +} \ No newline at end of file diff --git a/src/main/resources/assets/idlframework/loot_table/empty.json b/src/main/resources/assets/idlframework/loot_table/empty.json new file mode 100644 index 0000000..9e26dfe --- /dev/null +++ b/src/main/resources/assets/idlframework/loot_table/empty.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/src/main/resources/assets/idlframework/loot_table/entities/mor_orbital_beacon.json b/src/main/resources/assets/idlframework/loot_table/entities/mor_orbital_beacon.json new file mode 100644 index 0000000..1e60e7e --- /dev/null +++ b/src/main/resources/assets/idlframework/loot_table/entities/mor_orbital_beacon.json @@ -0,0 +1,30 @@ +{ + "pools": [ + { + "rolls": 1, + "entries": [ + { + "type": "item", + "name": "idealland:antenna", + "weight": 1, + "functions": [ + { + "function": "set_count", + "count": { + "min": 0, + "max": 1 + } + }, + { + "function": "looting_enchant", + "count": { + "min": 0, + "max": 1 + } + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/src/main/resources/assets/idlframework/models/block/construction_site.json b/src/main/resources/assets/idlframework/models/block/construction_site.json new file mode 100644 index 0000000..cbae625 --- /dev/null +++ b/src/main/resources/assets/idlframework/models/block/construction_site.json @@ -0,0 +1,6 @@ +{ + "parent": "block/cube_all", + "textures": { + "all": "idealland:blocks/construction_site" + } +} diff --git a/src/main/resources/assets/idlframework/models/item/skill_base.json b/src/main/resources/assets/idlframework/models/item/skill_base.json new file mode 100644 index 0000000..1bf89ab --- /dev/null +++ b/src/main/resources/assets/idlframework/models/item/skill_base.json @@ -0,0 +1,5 @@ +{ "parent": "item/handheld", + "textures": { + "layer0":"idealland:items/skill/skill_base" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/idlframework/recipes/emp_site.json b/src/main/resources/assets/idlframework/recipes/emp_site.json new file mode 100644 index 0000000..442eb3e --- /dev/null +++ b/src/main/resources/assets/idlframework/recipes/emp_site.json @@ -0,0 +1,32 @@ +{ + "type": "minecraft:crafting_shaped", + + "pattern": + [ + "1A1", + "1A1", + " 0 " + ], + + "key": + { + "1": + { + "item": "idealland:gua_1" + }, + "0": + { + "item": "idealland:gua_0" + }, + "A": + { + "item": "idealland:antenna" + } + }, + + "result": + { + "item": "idealland:emp_site", + "count": 1 + } +} \ No newline at end of file diff --git a/src/main/resources/assets/idlframework/recipes/matter_original.json b/src/main/resources/assets/idlframework/recipes/matter_original.json new file mode 100644 index 0000000..1af136c --- /dev/null +++ b/src/main/resources/assets/idlframework/recipes/matter_original.json @@ -0,0 +1,32 @@ +{ + "result": { + "item": "idealland:matter_original" + }, + "ingredients": [ + [ + { "item": "idealland:gua_0" } + ], + [ + { "item": "idealland:gua_1" } + ], + [ + { "item": "idealland:gua_2" } + ], + [ + { "item": "idealland:gua_3" } + ], + [ + { "item": "idealland:gua_4" } + ], + [ + { "item": "idealland:gua_5" } + ], + [ + { "item": "idealland:gua_6" } + ], + [ + { "item": "idealland:gua_7" } + ] + ], + "type": "forge:ore_shapeless" +} \ No newline at end of file diff --git a/src/main/resources/assets/idlframework/sounds.json b/src/main/resources/assets/idlframework/sounds.json new file mode 100644 index 0000000..0cc6177 --- /dev/null +++ b/src/main/resources/assets/idlframework/sounds.json @@ -0,0 +1,14 @@ +{ + "entity.moroon.ambient": + { + "category": "entity", + "subtitle": "entity.moroon.ambient", + "sounds": [{"name": "idlframework:entity/moroon/ambient", "stream": true}] + }, + "entity.moroon.hurt": + { + "category": "entity", + "subtitle": "entity.moroon.hurt", + "sounds": [{"name": "idlframework:entity/moroon/hurt", "stream": true}] + } +} \ No newline at end of file diff --git a/src/main/resources/assets/idlframework/sounds/entity/moroon/ambient.ogg b/src/main/resources/assets/idlframework/sounds/entity/moroon/ambient.ogg new file mode 100644 index 0000000..58301a0 Binary files /dev/null and b/src/main/resources/assets/idlframework/sounds/entity/moroon/ambient.ogg differ diff --git a/src/main/resources/assets/idlframework/sounds/entity/moroon/hurt.ogg b/src/main/resources/assets/idlframework/sounds/entity/moroon/hurt.ogg new file mode 100644 index 0000000..58301a0 Binary files /dev/null and b/src/main/resources/assets/idlframework/sounds/entity/moroon/hurt.ogg differ diff --git a/src/main/resources/assets/idlframework/textures/blocks/builder_farm.png b/src/main/resources/assets/idlframework/textures/blocks/builder_farm.png new file mode 100644 index 0000000..142f7ca Binary files /dev/null and b/src/main/resources/assets/idlframework/textures/blocks/builder_farm.png differ diff --git a/src/main/resources/assets/idlframework/textures/blocks/test.png b/src/main/resources/assets/idlframework/textures/blocks/test.png new file mode 100644 index 0000000..b94f99c Binary files /dev/null and b/src/main/resources/assets/idlframework/textures/blocks/test.png differ diff --git a/src/main/resources/assets/idlframework/textures/entity/centaur.png b/src/main/resources/assets/idlframework/textures/entity/centaur.png new file mode 100644 index 0000000..c3cc2d0 Binary files /dev/null and b/src/main/resources/assets/idlframework/textures/entity/centaur.png differ diff --git a/src/main/resources/assets/idlframework/textures/entity/moroon_humanoid.png b/src/main/resources/assets/idlframework/textures/entity/moroon_humanoid.png new file mode 100644 index 0000000..9b14140 Binary files /dev/null and b/src/main/resources/assets/idlframework/textures/entity/moroon_humanoid.png differ diff --git a/src/main/resources/assets/idlframework/textures/entity/projectiles/bullet_mor.png b/src/main/resources/assets/idlframework/textures/entity/projectiles/bullet_mor.png new file mode 100644 index 0000000..2f5a5ad Binary files /dev/null and b/src/main/resources/assets/idlframework/textures/entity/projectiles/bullet_mor.png differ diff --git a/src/main/resources/assets/idlframework/textures/entity/projectiles/bullet_norm.png b/src/main/resources/assets/idlframework/textures/entity/projectiles/bullet_norm.png new file mode 100644 index 0000000..0abe48e Binary files /dev/null and b/src/main/resources/assets/idlframework/textures/entity/projectiles/bullet_norm.png differ diff --git a/src/main/resources/assets/idlframework/textures/gui/container/gui_demo.png b/src/main/resources/assets/idlframework/textures/gui/container/gui_demo.png new file mode 100644 index 0000000..eaea7f6 Binary files /dev/null and b/src/main/resources/assets/idlframework/textures/gui/container/gui_demo.png differ diff --git a/src/main/resources/assets/idlframework/textures/gui/container/gui_research.png b/src/main/resources/assets/idlframework/textures/gui/container/gui_research.png new file mode 100644 index 0000000..547652f Binary files /dev/null and b/src/main/resources/assets/idlframework/textures/gui/container/gui_research.png differ diff --git a/src/main/resources/assets/idlframework/textures/gui/container/test_gui.png b/src/main/resources/assets/idlframework/textures/gui/container/test_gui.png new file mode 100644 index 0000000..966dc52 Binary files /dev/null and b/src/main/resources/assets/idlframework/textures/gui/container/test_gui.png differ diff --git a/src/main/resources/assets/idlframework/textures/items/basic/gua_0.png b/src/main/resources/assets/idlframework/textures/items/basic/gua_0.png new file mode 100644 index 0000000..5f4176f Binary files /dev/null and b/src/main/resources/assets/idlframework/textures/items/basic/gua_0.png differ diff --git a/src/main/resources/assets/idlframework/textures/items/basic/gua_1.png b/src/main/resources/assets/idlframework/textures/items/basic/gua_1.png new file mode 100644 index 0000000..56f00b0 Binary files /dev/null and b/src/main/resources/assets/idlframework/textures/items/basic/gua_1.png differ diff --git a/src/main/resources/assets/idlframework/textures/items/basic/gua_2.png b/src/main/resources/assets/idlframework/textures/items/basic/gua_2.png new file mode 100644 index 0000000..184e10f Binary files /dev/null and b/src/main/resources/assets/idlframework/textures/items/basic/gua_2.png differ diff --git a/src/main/resources/assets/idlframework/textures/items/basic/gua_3.png b/src/main/resources/assets/idlframework/textures/items/basic/gua_3.png new file mode 100644 index 0000000..997b8e6 Binary files /dev/null and b/src/main/resources/assets/idlframework/textures/items/basic/gua_3.png differ diff --git a/src/main/resources/assets/idlframework/textures/items/basic/gua_4.png b/src/main/resources/assets/idlframework/textures/items/basic/gua_4.png new file mode 100644 index 0000000..2a5cb6f Binary files /dev/null and b/src/main/resources/assets/idlframework/textures/items/basic/gua_4.png differ diff --git a/src/main/resources/assets/idlframework/textures/items/basic/gua_5.png b/src/main/resources/assets/idlframework/textures/items/basic/gua_5.png new file mode 100644 index 0000000..d86417f Binary files /dev/null and b/src/main/resources/assets/idlframework/textures/items/basic/gua_5.png differ diff --git a/src/main/resources/assets/idlframework/textures/items/basic/gua_6.png b/src/main/resources/assets/idlframework/textures/items/basic/gua_6.png new file mode 100644 index 0000000..5b632d0 Binary files /dev/null and b/src/main/resources/assets/idlframework/textures/items/basic/gua_6.png differ diff --git a/src/main/resources/assets/idlframework/textures/items/basic/gua_7.png b/src/main/resources/assets/idlframework/textures/items/basic/gua_7.png new file mode 100644 index 0000000..55accca Binary files /dev/null and b/src/main/resources/assets/idlframework/textures/items/basic/gua_7.png differ diff --git a/src/main/resources/assets/idlframework/textures/items/basic/matter_original.png b/src/main/resources/assets/idlframework/textures/items/basic/matter_original.png new file mode 100644 index 0000000..f8d1f64 Binary files /dev/null and b/src/main/resources/assets/idlframework/textures/items/basic/matter_original.png differ diff --git a/src/main/resources/assets/idlframework/textures/items/basic/yang_sign.png b/src/main/resources/assets/idlframework/textures/items/basic/yang_sign.png new file mode 100644 index 0000000..6b0aa03 Binary files /dev/null and b/src/main/resources/assets/idlframework/textures/items/basic/yang_sign.png differ diff --git a/src/main/resources/assets/idlframework/textures/items/basic/yin_sign.png b/src/main/resources/assets/idlframework/textures/items/basic/yin_sign.png new file mode 100644 index 0000000..c3aef4c Binary files /dev/null and b/src/main/resources/assets/idlframework/textures/items/basic/yin_sign.png differ diff --git a/src/main/resources/assets/idlframework/textures/items/builder/build_blank.png b/src/main/resources/assets/idlframework/textures/items/builder/build_blank.png new file mode 100644 index 0000000..8605dff Binary files /dev/null and b/src/main/resources/assets/idlframework/textures/items/builder/build_blank.png differ diff --git a/src/main/resources/assets/idlframework/textures/items/misc/blood_iron_ingot.png b/src/main/resources/assets/idlframework/textures/items/misc/blood_iron_ingot.png new file mode 100644 index 0000000..8aa2849 Binary files /dev/null and b/src/main/resources/assets/idlframework/textures/items/misc/blood_iron_ingot.png differ diff --git a/src/main/resources/assets/idlframework/textures/items/misc/war_bread.png b/src/main/resources/assets/idlframework/textures/items/misc/war_bread.png new file mode 100644 index 0000000..6fbca24 Binary files /dev/null and b/src/main/resources/assets/idlframework/textures/items/misc/war_bread.png differ diff --git a/src/main/resources/assets/idlframework/textures/items/misc/water_caster.png b/src/main/resources/assets/idlframework/textures/items/misc/water_caster.png new file mode 100644 index 0000000..3018179 Binary files /dev/null and b/src/main/resources/assets/idlframework/textures/items/misc/water_caster.png differ diff --git a/src/main/resources/assets/idlframework/textures/items/skill/skill_base.png b/src/main/resources/assets/idlframework/textures/items/skill/skill_base.png new file mode 100644 index 0000000..38e24d3 Binary files /dev/null and b/src/main/resources/assets/idlframework/textures/items/skill/skill_base.png differ diff --git a/src/main/resources/assets/idlframework/textures/items/weapon/healing_gun.png b/src/main/resources/assets/idlframework/textures/items/weapon/healing_gun.png new file mode 100644 index 0000000..88028e4 Binary files /dev/null and b/src/main/resources/assets/idlframework/textures/items/weapon/healing_gun.png differ diff --git a/src/main/resources/assets/idlframework/textures/misc/potions.png b/src/main/resources/assets/idlframework/textures/misc/potions.png new file mode 100644 index 0000000..4b81e54 Binary files /dev/null and b/src/main/resources/assets/idlframework/textures/misc/potions.png differ diff --git a/src/main/resources/assets/idlframework/textures/models/armor/armor_qsh_layer_1.png b/src/main/resources/assets/idlframework/textures/models/armor/armor_qsh_layer_1.png new file mode 100644 index 0000000..a018d65 Binary files /dev/null and b/src/main/resources/assets/idlframework/textures/models/armor/armor_qsh_layer_1.png differ diff --git a/src/main/resources/assets/idlframework/textures/models/armor/armor_qsh_layer_2.png b/src/main/resources/assets/idlframework/textures/models/armor/armor_qsh_layer_2.png new file mode 100644 index 0000000..6a08f9d Binary files /dev/null and b/src/main/resources/assets/idlframework/textures/models/armor/armor_qsh_layer_2.png differ