Java Code Examples for net.minecraftforge.fml.common.FMLLog

The following examples show how to use net.minecraftforge.fml.common.FMLLog. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
/**
 * Load a new instance of HarvesterAnimationStateMachine at specified location,
 * with specified custom parameters.
 */
@SideOnly(Side.CLIENT)
public static HarvesterAnimationStateMachine load(IResourceManager manager, ResourceLocation location,
        ImmutableMap<String, ITimeValue> customParameters) {
    try (IResource resource = manager.getResource(location)) {
        ClipResolver clipResolver = new ClipResolver();
        ParameterResolver parameterResolver = new ParameterResolver(customParameters);
        Clips.CommonClipTypeAdapterFactory.INSTANCE.setClipResolver(clipResolver);
        TimeValues.CommonTimeValueTypeAdapterFactory.INSTANCE.setValueResolver(parameterResolver);
        HarvesterAnimationStateMachine asm = asmGson.fromJson(
                new InputStreamReader(resource.getInputStream(), StandardCharsets.UTF_8),
                HarvesterAnimationStateMachine.class);
        clipResolver.asm = asm;
        parameterResolver.asm = asm;
        asm.initialize();

        return asm;
    } catch (IOException | JsonParseException e) {
        FMLLog.log.error("Exception loading Animation State Machine {}, skipping", location, e);
        return missing;
    } finally {
        Clips.CommonClipTypeAdapterFactory.INSTANCE.setClipResolver(null);
        TimeValues.CommonTimeValueTypeAdapterFactory.INSTANCE.setValueResolver(null);
    }
}
 
Example 2
Source Project: pycode-minecraft   Source File: PythonCode.java    License: MIT License 6 votes vote down vote up
private void ensureCompiled() {
    if (!this.codeChanged) return;
    FMLLog.fine("Eval my code: %s", this.code);

    // now execute the code
    try {
        PythonEngine.eval(this.code, this.context);
        if (!world.isRemote) {
            ((WorldServer)world).spawnParticle(EnumParticleTypes.CRIT,
                    pos.getX() + .5, pos.getY() + 1, pos.getZ() + .5,
                    20, 0, 0, 0, .5, new int[0]);
        }
    } catch (ScriptException e) {
        failz0r(world, pos, "Error running code, traceback:\n%s", stackTraceToString(e));
    }
    this.codeChanged = false;
}
 
Example 3
Source Project: pycode-minecraft   Source File: HandEntity.java    License: MIT License 6 votes vote down vote up
public boolean handleItemInteraction(EntityPlayer player, ItemStack heldItem) {
    FMLLog.info("Hand Entity handleItemInteraction item=%s", heldItem);

    if (heldItem == null) {
        if (this.code.hasKey("run")) {
            this.code.put("hand", new HandMethods(this));
            this.code.setRunner(player);
            this.code.invoke("run", new MyEntityPlayer(player));
            this.code.setRunner(this);
        }
        return true;
    }

    Item item = heldItem.getItem();
    if (item instanceof PythonWandItem) {
        PythonWandItem.invokeOnEntity(player, this);
        return true;
    } else if (item instanceof PythonBookItem || item instanceof ItemWritableBook) {
        BlockPos pos = this.getPosition();
        this.code.put("hand", new HandMethods(this));
        this.code.setCodeFromBook(this.getEntityWorld(), player, this, pos, heldItem);
        return true;
    }
    FMLLog.info("... returning FALSE YEAH");
    return false;
}
 
Example 4
Source Project: pycode-minecraft   Source File: InvokeWandMessage.java    License: MIT License 6 votes vote down vote up
private void handle(InvokeWandMessage message, MessageContext ctx) {
    // note: we only get send types BLOCK and ENTITY and we only handle this message on the server
    EntityPlayer player = ctx.getServerHandler().playerEntity;
    switch (message.typeOfHit) {
        case BLOCK:
            FMLLog.info("Got a InvokeWandMessage block=%s", message.blockPos);
            PythonWandItem.invokeOnBlock(player, message.blockPos);
        case ENTITY:
            // in theory this should never be invoked on the client...
            Entity entity = player.worldObj.getEntityByID(message.entityId);
            FMLLog.info("Got a InvokeWandMessage entity=%s", entity);
            if (entity == null) return;
            PythonWandItem.invokeOnEntity(player, entity);
            break;
        case MISS:
            PythonWandItem.invokeInDirection(player, message.hitVec);
    }
}
 
Example 5
Source Project: pycode-minecraft   Source File: PythonWandItem.java    License: MIT License 6 votes vote down vote up
@Nullable
static private PythonCode getCodeFromBook(EntityPlayer player) {
    ItemStack offhand = player.getHeldItemOffhand();
    if (offhand == null) {
        FMLLog.info("... nothing in off hand so pass");
        return null;
    }

    Item offitem = offhand.getItem();
    if (offitem instanceof PythonBookItem || offitem instanceof ItemWritableBook) {
        String content = PythonCode.bookAsString(offhand);
        if (content == null) {
            PythonCode.failz0r(player.worldObj, player.getPosition(), "Could not get pages from the book!?");
            return null;
        }

        PythonCode code = new PythonCode();
        code.setCodeString(content);

        // the following will actually run the code; TODO maybe setContext could be better-named?
        code.setContext(player.worldObj, player, player.getPosition());

        return code;
    }
    return null;
}
 
Example 6
Source Project: BaseMetals   Source File: Materials.java    License: GNU Lesser General Public License v2.1 6 votes vote down vote up
protected static void registerMaterial(String name, MetalMaterial m){

		allMaterials.put(name, m);
		
		String enumName = m.getEnumName();
		String texName = m.getName();
		int[] protection = m.getDamageReductionArray();
		int durability = m.getArmorMaxDamageFactor();
		ArmorMaterial am = EnumHelper.addArmorMaterial(enumName, texName, durability, protection, m.getEnchantability(), SoundEvents.ITEM_ARMOR_EQUIP_IRON, (m.hardness > 10 ? (int)(m.hardness / 5) : 0));
		if(am == null){
			// uh-oh
			FMLLog.severe("Failed to create armor material enum for "+m);
		}
		armorMaterialMap.put(m, am);
		FMLLog.info("Created armor material enum "+am);
		
		ToolMaterial tm = EnumHelper.addToolMaterial(enumName, m.getToolHarvestLevel(), m.getToolDurability(), m.getToolEfficiency(), m.getBaseAttackDamage(), m.getEnchantability());
		if(tm == null){
			// uh-oh
			FMLLog.severe("Failed to create tool material enum for "+m);
		}
		toolMaterialMap.put(m, tm);
		FMLLog.info("Created tool material enum "+tm);
	}
 
Example 7
Source Project: BaseMetals   Source File: Items.java    License: GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Uses reflection to expand the size of the combat damage and attack speed arrays to prevent initialization
 * index-out-of-bounds errors
 * @param itemClass The class to modify
 */
private static void expandCombatArrays(Class itemClass) throws IllegalAccessException, NoSuchFieldException {
    // WARNING: this method contains black magic
    final int expandedSize = 256;
    Field[] fields = itemClass.getDeclaredFields();
    for(Field f : fields){
        if(Modifier.isStatic(f.getModifiers())
                && f.getType().isArray()
                && f.getType().getComponentType().equals(float.class)){
            FMLLog.info("%s: Expanding array variable %s.%s to size %s", Thread.currentThread().getStackTrace()[0], itemClass.getSimpleName(), f.getName(), expandedSize);
            f.setAccessible(true); // bypass 'private' key word
            Field modifiersField = Field.class.getDeclaredField("modifiers");
            modifiersField.setAccessible(true);
            modifiersField.setInt(f, f.getModifiers() & ~Modifier.FINAL); // bypass 'final' key word
            float[] newArray = new float[expandedSize];
            Arrays.fill(newArray,0F);
            System.arraycopy(f.get(null),0,newArray,0, Array.getLength(f.get(null)));
            f.set(null,newArray);
        }
    }
}
 
Example 8
Source Project: CommunityMod   Source File: ModTest.java    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void onPreInit(FMLPreInitializationEvent event)
{
    if (isLoaded)
    {
        FMLLog.log.info(messages[new Random().nextInt(messages.length)] + "...");
    }
}
 
Example 9
@SuppressWarnings("deprecation")
@Override
public void onInit(FMLInitializationEvent event) {
	FMLLog.log.info("Chickenification is beginning...");
	//RenderingRegistry.registerEntityRenderingHandler(EntitySheep.class, new RenderStupidChicken());
	RenderingRegistry.registerEntityRenderingHandler(EntityCow.class, new RenderStupidChicken());
	RenderingRegistry.registerEntityRenderingHandler(EntityPig.class, new RenderStupidChicken());
	RenderingRegistry.registerEntityRenderingHandler(EntitySquid.class, new RenderStupidChicken());
	RenderingRegistry.registerEntityRenderingHandler(EntityZombie.class, new RenderStupidChicken());
	RenderingRegistry.registerEntityRenderingHandler(EntitySpider.class, new RenderStupidChicken());
	RenderingRegistry.registerEntityRenderingHandler(EntitySkeleton.class, new RenderStupidChicken());
	FMLLog.log.info("Chickenificated all the bois!");
}
 
Example 10
@SuppressWarnings("deprecation")
@Override
   public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
       MethodVisitor visitor = super.visitMethod(access, name, desc, signature, exceptions);
       String methodKey = name + desc;
       if (this.methodKey.matches(name, desc)) {
           FMLLog.log("GTCETransformer", Level.INFO, "Patched method %s in %s successfully", methodKey, className);
           this.foundMethod = true;
           return visitorCreator.apply(visitor);
       }
       return visitor;
   }
 
Example 11
@SuppressWarnings("deprecation")
@Override
   public void visitEnd() {
       super.visitEnd();
       if (!foundMethod) {
       	FMLLog.log("ArmorRenderTransformer", Level.FATAL, "Failed to find method %s in %s.", methodKey, className);
           throw new RuntimeException("Failed to patch method " + methodKey + ", loading cannot continue. Check your environment is correct.");
       }
   }
 
Example 12
Source Project: Valkyrien-Skies   Source File: MixinLoadManager.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onLoad(String mixinPackage) {
    isSpongeEnabled = isSpongeEnabledSlow();
    if (isSpongeEnabled()) {
        FMLLog.bigWarning(
            "Valkyrien Skies has detected SpongeForge!");
    }
}
 
Example 13
Source Project: Valkyrien-Skies   Source File: MixinLoadManager.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
    if (!isSpongeEnabled()) {
        if (mixinClassName.contains("spongepowered")) {
            FMLLog
                .bigWarning("Not applying" + mixinClassName + " because Sponge isn't loaded!");
            return false;
        }
    }

    return true;
}
 
Example 14
Source Project: Valkyrien-Skies   Source File: ValkyrienSkiesMod.java    License: Apache License 2.0 5 votes vote down vote up
@Mod.EventHandler
public void onFingerprintViolation(FMLFingerprintViolationEvent event) {
    if (MixinLoaderForge.isObfuscatedEnvironment) { //only print signature warning in obf
        FMLLog.bigWarning(
            "Valkyrien Skies JAR fingerprint corrupted, which means this copy of the mod "
                + "may have come from unofficial sources. Please check out our official website: "
                + "https://valkyrienskies.org");
    }
}
 
Example 15
Source Project: pycode-minecraft   Source File: PyRegistry.java    License: MIT License 5 votes vote down vote up
public static Block getBlock(String blockName) throws BlockTypeError {
    Block block = Block.REGISTRY.getObject(new ResourceLocation(blockName));
    FMLLog.info("getBlock asked for '%s', got '%s'", blockName, block.getUnlocalizedName());
    if (block.getUnlocalizedName().equals("tile.air") && !blockName.equals("air")) {
        throw new BlockTypeError(blockName);
    }
    return block;
}
 
Example 16
Source Project: pycode-minecraft   Source File: BaseMethods.java    License: MIT License 5 votes vote down vote up
protected void put(BlockPos pos, IBlockState block_state, EnumFacing facing) {
    // don't run on client
    if (this.world == null || this.world.isRemote) return;

    Block block = block_state.getBlock();

    FMLLog.info("Putting %s at %s", block_state, pos);

    // handle special cases
    if (block instanceof BlockDoor) {
        ItemDoor.placeDoor(this.world, pos, facing, block, true);
    } else if (block instanceof BlockBed) {
        BlockPos headpos = pos.offset(facing);
        if (this.world.getBlockState(pos.down()).isSideSolid(this.world, pos.down(), EnumFacing.UP) &&
                this.world.getBlockState(headpos.down()).isSideSolid(this.world, headpos.down(), EnumFacing.UP)) {
            block_state = block_state
                    .withProperty(BlockBed.OCCUPIED, false).withProperty(BlockBed.FACING, facing)
                    .withProperty(BlockBed.PART, BlockBed.EnumPartType.FOOT);
            if (this.world.setBlockState(pos, block_state, 11)) {
                block_state = block_state.withProperty(BlockBed.PART, BlockBed.EnumPartType.HEAD);
                this.world.setBlockState(headpos, block_state, 11);
            }
        }
    } else {
        this.world.setBlockState(pos, block_state);
    }
}
 
Example 17
Source Project: pycode-minecraft   Source File: PythonCode.java    License: MIT License 5 votes vote down vote up
static public void failz0r(World world, BlockPos pos, String fmt, Object... args) {
    if (world.isRemote) return;
    ((WorldServer)world).spawnParticle(EnumParticleTypes.SPELL,
            pos.getX() + .5, pos.getY() + 1, pos.getZ() + .5,
            20, 0, 0, 0, .5, new int[0]);
    FMLLog.severe(fmt, args);
}
 
Example 18
Source Project: pycode-minecraft   Source File: PythonEngine.java    License: MIT License 5 votes vote down vote up
private PythonEngine() {
    ScriptEngineManager manager = new ScriptEngineManager();
    engine = (PyScriptEngine) manager.getEngineByName("python");
    if (engine == null) {
        FMLLog.severe("FAILED to getBlock Python");
    } else {
        FMLLog.fine("Got Python");
    }
    try {
        engine.eval("print 'Python Ready'");
    } catch (ScriptException e) {
        FMLLog.severe("Python failed: %s", e);
    }
}
 
Example 19
Source Project: pycode-minecraft   Source File: PythonBlock.java    License: MIT License 5 votes vote down vote up
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand,
                                @Nullable ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ) {
    FMLLog.info("onBlockActivated item=%s", heldItem);
    PyCodeBlockTileEntity code_block = this.getEntity(world, pos);
    return code_block == null || code_block.handleItemInteraction(playerIn, heldItem);
}
 
Example 20
Source Project: pycode-minecraft   Source File: HandEntity.java    License: MIT License 5 votes vote down vote up
/**
 * Called when the entity is attacked.
 */
public boolean attackEntityFrom(DamageSource source, float amount) {
    if (!this.worldObj.isRemote && !this.isDead) {
        if (this.isEntityInvulnerable(source)) {
            return false;
        } else {
            this.setBeenAttacked();
            this.removePassengers();
            this.setDead();
            if (this.worldObj.getGameRules().getBoolean("doEntityDrops")) {
                ItemStack itemstack = new ItemStack(ModItems.python_hand, 1);
                itemstack.setStackDisplayName(this.getName());
                if (!itemstack.hasTagCompound()) {
                    itemstack.setTagCompound(new NBTTagCompound());
                }
                NBTTagCompound compound = itemstack.getTagCompound();
                if (compound == null) {
                    FMLLog.severe("Python Hand itemstack NBT missing??");
                } else {
                    this.writeToNBT(compound);
                }
                this.entityDropItem(itemstack, 0.0F);
            }

            return true;
        }
    } else {
        return true;
    }
}
 
Example 21
Source Project: pycode-minecraft   Source File: PyCodeBlockTileEntity.java    License: MIT License 5 votes vote down vote up
public boolean handleItemInteraction(EntityPlayer player, ItemStack heldItem) {
    FMLLog.info("Block Entity handleItemInteraction item=%s", heldItem);
    this.isPowered = this.worldObj.isBlockPowered(this.getPosition());

    if (heldItem == null) {
        // this is only ever invoked on the server
        if (this.code.hasKey("run")) {
            this.code.put("block", new BlockMethods(this));
            this.code.setContext(this.worldObj, player, this.getPosition() );
            this.code.invoke("run", new MyEntityPlayer(player));
            this.code.setRunner(this);
        }
        return true;
    }

    Item item = heldItem.getItem();
    if (item instanceof PythonWandItem) {
        PythonWandItem.invokeOnBlock(player, this.getPosition());
        return true;
    } else if (item instanceof PythonBookItem || item instanceof ItemWritableBook) {
        BlockPos pos = this.getPosition();
        this.code.put("block", new BlockMethods(this));
        this.code.setCodeFromBook(this.worldObj, player, this, pos, heldItem);
        return true;
    }

    return false;
}
 
Example 22
Source Project: pycode-minecraft   Source File: GuiTextArea.java    License: MIT License 5 votes vote down vote up
public void scrollBy(int amount) {
    if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT)) {
        // TODO this reversal should probably be simplified??
        this.textXOffset -= amount;
    } else {
        this.textYOffset += amount;
    }
    FMLLog.info("text offset = %d, %d", textXOffset, textYOffset);
}
 
Example 23
Source Project: pycode-minecraft   Source File: PythonWandItem.java    License: MIT License 5 votes vote down vote up
public EnumActionResult onItemUse(ItemStack itemstack, EntityPlayer player, World world, BlockPos pos,
                                  EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    if (world == null || world.isRemote) return EnumActionResult.SUCCESS;
    FMLLog.info("Wand onItemUse stack=%s, hand=%s", itemstack, hand);
    invokeOnBlock(player, pos);
    return EnumActionResult.SUCCESS;
}
 
Example 24
Source Project: pycode-minecraft   Source File: PythonWandItem.java    License: MIT License 5 votes vote down vote up
@Nonnull
@Override
public ActionResult<ItemStack> onItemRightClick(@Nonnull ItemStack itemstack, World world,
                                                EntityPlayer player, EnumHand hand) {
    FMLLog.info("Wand onItemRightClick stack=%s, hand=%s", itemstack, hand);
    if (world.isRemote) {
        // figure out what we're looking at and send it to the server
        RayTraceResult target = Minecraft.getMinecraft().objectMouseOver;
        ModNetwork.network.sendToServer(new InvokeWandMessage(target));
    }
    return ActionResult.newResult(EnumActionResult.SUCCESS, itemstack);
}
 
Example 25
Source Project: pycode-minecraft   Source File: PythonBookItem.java    License: MIT License 5 votes vote down vote up
@Nonnull
@Override
public ActionResult<ItemStack> onItemRightClick(@Nonnull ItemStack itemstack, World world, EntityPlayer playerIn, EnumHand hand) {
    FMLLog.info("Book onItemRightClick stack=%s, hand=%s", itemstack, hand);
    // don't activate the GUI if in offhand; don't do *anything*
    if (hand == EnumHand.OFF_HAND) return new ActionResult(EnumActionResult.FAIL, itemstack);

    PyCode.proxy.openBook(playerIn, itemstack);
    return new ActionResult(EnumActionResult.SUCCESS, itemstack);
}
 
Example 26
Source Project: BaseMetals   Source File: BaseMetals.java    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Parses a String in the format (stack-size)*(modid):(item/block name)#(metadata value). The 
 * stacksize and metadata value parameters are optional.
 * @param str A String describing an itemstack (e.g. "4*minecraft:dye#15" or "minecraft:bow")
 * @param allowWildcard If true, then item strings that do not specify a metadata value will use 
 * the OreDictionary wildcard value. If false, then the default meta value is 0 instead.
 * @return An ItemStack representing the item, or null if the item is not found
 */
public static ItemStack parseStringAsItemStack(String str, boolean allowWildcard){
	str = str.trim();
	int count = 1;
	int meta;
	if(allowWildcard){
		meta = OreDictionary.WILDCARD_VALUE;
	} else {
		meta = 0;
	}
	int nameStart = 0;
	int nameEnd = str.length();
	if(str.contains("*")){
		count = Integer.parseInt(str.substring(0,str.indexOf("*")).trim());
		nameStart = str.indexOf("*")+1;
	}
	if(str.contains("#")){
		meta = Integer.parseInt(str.substring(str.indexOf("#")+1,str.length()).trim());
		nameEnd = str.indexOf("#");
	}
	String id = str.substring(nameStart,nameEnd).trim();
	if(Block.getBlockFromName(id) != null){
		// is a block
		return new ItemStack(Block.getBlockFromName(id),count,meta);
	} else if(Item.getByNameOrId(id) != null){
		// is an item
		return new ItemStack(Item.getByNameOrId(id),count,meta);
	} else {
		// item not found
		FMLLog.severe("Failed to find item or block for ID '"+id+"'");
		return null;
	}
}
 
Example 27
/**
 * Adds a new crusher recipe (for the crack hammer and other rock crushers) 
 * where the input item is specified by an ItemStack. This means that only 
 * the specified item will be converted into the specified output item. 
 * @param input Item to be crushed
 * @param output The item to create as the result of this crusher recipe.
 */
public static void addNewCrusherRecipe(final ItemStack input, final ItemStack output){
	if(input == null || output == null) FMLLog.severe("%s: %s: Crusher recipe not registered because of null input or output. \n %s", 
			BaseMetals.MODID, CrusherRecipeRegistry.class,
			Arrays.toString(Thread.currentThread().getStackTrace()).replace(", ", "\n").replace("[", "").replace("]", "")
			);
	getInstance().addRecipe(new ArbitraryCrusherRecipe(input,output));
}
 
Example 28
public static ItemMetalArmor createHelmet(MetalMaterial metal){
	ArmorMaterial material = cyano.basemetals.init.Materials.getArmorMaterialFor(metal);
	if(material == null){
		// uh-oh
		FMLLog.severe("Failed to load armor material enum for "+metal);
	}
	return new ItemMetalArmor(metal,material,material.ordinal(),EntityEquipmentSlot.HEAD);
}
 
Example 29
public static ItemMetalArmor createChestplate(MetalMaterial metal){
	ArmorMaterial material = cyano.basemetals.init.Materials.getArmorMaterialFor(metal);
	if(material == null){
		// uh-oh
		FMLLog.severe("Failed to load armor material enum for "+metal);
	}
	return new ItemMetalArmor(metal,material,material.ordinal(),EntityEquipmentSlot.CHEST);
}
 
Example 30
public static ItemMetalArmor createLeggings(MetalMaterial metal){
	ArmorMaterial material = cyano.basemetals.init.Materials.getArmorMaterialFor(metal);
	if(material == null){
		// uh-oh
		FMLLog.severe("Failed to load armor material enum for "+metal);
	}
	return new ItemMetalArmor(metal,material,material.ordinal(),EntityEquipmentSlot.LEGS);
}