problem loading model/texture of item forge 1.12.2 (intellij idea) - minecraft-forge

I have tried to change the name of the item and it doesn't work
o ya my lang file doesn't work too
error:
Exception loading model for variant rpc:ingot_titinium#inventroy for item "rpc:ingot_titinium", normal location exception
https://pastebin.com/WnNGPAGZ
public void registerModel(Item item, int metadata)
{
ModelLoader.setCustomModelResourceLocation(item, metadata, new ModelResourceLocation(item.getRegistryName(), "inventory"));
}
edit:
folder structure and ref code

if you're using intellij idea, add at the bottom of your build.gradle file:
sourceSets { main { output.resourcesDir = output.classesDir } }

Related

Issue while updating java project from JDK11 to JDK17

I have a java project using jdk11. I need to migrate the project to java 17 but integration tests have started failing. As soon as I upgraded to JDK17 I started getting below error:
java.lang.reflect.InaccessibleObjectException: Unable to make private sun.reflect.generics.repository.FieldRepository java.lang.reflect.Field.getGenericInfo() accessible: module java.base does not "opens java.lang.reflect" to unnamed module #5702b3b1
I was also getting error for java.util but that is fixed using below command line code.
I have tried adding the command line options as below but the tests are still failing
<argLine>
--illegal-access=permit
--add-opens java.base/java.lang=ALL-UNNAMED
--add-opens java.base/sun.reflect=ALL-UNNAMED
--add-opens java.base/java.util=ALL-UNNAMED
</argLine>
Any help is appreciated.
You can pass your method in to this:
public static <T extends AccessibleObject> T forceAccessible(T o) {
try {
Field unsafeField = Unsafe.class.getDeclaredField("theUnsafe");
unsafeField.setAccessible(true);
Unsafe unsafe = (Unsafe) unsafeField.get(null);
Method m = Class.class.getDeclaredMethod("getDeclaredFields0", boolean.class);
m.setAccessible(true);
Field override = ((Field[]) m.invoke(AccessibleObject.class, false))[0];
if (!o.isAccessible()) {
try {
o.setAccessible(true);
} catch (InaccessibleObjectException e) {
unsafe.putBoolean(o, unsafe.objectFieldOffset(override), true);
}
}
} catch (Exception e) {}
return o;
}

Nancyfx using Json.net, registering dependencies error

I'm trying to use nancy with JSON.net, follow the 2 ways that i found to register the dependencies but all way get me to an InvalidOperationException with a message "Something went wrong when trying to satisfy one of the dependencies during composition, make sure that you've registered all new dependencies in the container and inspect the innerexception for more details." with an inner exection of {"Unable to resolve type: Nancy.NancyEngine"}.
I'm using self hosting to run nancy and jeep everything really simple to been able just to test.
public static void Main(string[] args)
{
try
{
var host = new NancyHost(new Uri("http://localhost:8888/"));
host.Start(); // start hosting
Console.ReadKey();
host.Stop(); // stop hosting
}
catch
{
throw;
}
}
First I create a customSerializer
public class CustomJsonSerializer : JsonSerializer
{
public CustomJsonSerializer()
{
ContractResolver = new CamelCasePropertyNamesContractResolver();
Formatting = Formatting.Indented;
}
}
and then i tried 2 ways of registering
Using IRegistrations:
public class JsonRegistration : IRegistrations
{
public IEnumerable<TypeRegistration> TypeRegistrations
{
get
{
yield return new TypeRegistration(typeof(JsonSerializer), typeof(CustomJsonSerializer));
}
}
public IEnumerable<CollectionTypeRegistration> CollectionTypeRegistrations { get; protected set; }
public IEnumerable<InstanceRegistration> InstanceRegistrations { get; protected set; }
}
And also using Bootstrapper
public class NancyBootstrapper : DefaultNancyBootstrapper
{
protected override void ConfigureApplicationContainer(TinyIoCContainer container)
{
base.ConfigureApplicationContainer(container);
container.Register<JsonSerializer, CustomJsonSerializer>();
}
}
Which means that when self hosting I add the custom bootstrapper
var host = new NancyHost(new Uri("http://localhost:8888/"), new NancyBootstrapper());
Both way return the same error.
Problem is actually the versions, the nancy json.net package is using Newton.Json 6.0.0.0, BUT when installing the package it will install automatically newer version that will create this problem. Not sure what has change in the Newton.JSON that will actually create this.
https://github.com/NancyFx/Nancy.Serialization.JsonNet/issues/27
Just to add my hard won knowledge in this area, after a greatly frustrating few hours using Nancy 1.4.1.
If you use a custom bootstrapper, make sure you make the call to base.ConfigureApplicationContainer(container); before you start your custom registrations.
So, not:
public class MyCustomBootstrapper : DefaultNancyBootstrapper
{
protected override void ConfigureApplicationContainer(TinyIoCContainer container)
{
// MY BITS HERE...
base.ConfigureApplicationContainer(container);
}
}
but,
public class MyCustomBootstrapper : DefaultNancyBootstrapper
{
protected override void ConfigureApplicationContainer(TinyIoCContainer container)
{
base.ConfigureApplicationContainer(container); // Must go first!!
// MY BITS HERE...
}
}
If you don't do this you will get the following error:
Something went wrong when trying to satisfy one of the dependencies
during composition, make sure that you've registered all new
dependencies in the container and inspect the innerexception for more
details.
with a helpful inner exception of:
Unable to resolve type: Nancy.NancyEngine
The solution of changing the order of these C# statements was actually alluded to in #StevenRobbins' excellent answer here (which I could have saved myself several hours of pain if I'd only read properly the first time).
Says Steven:
By calling "base" after you've made a manual registration you are
effectively copying over your original registration by autoregister.
Either don't call base, or call it before you do your manual
registrations.

i got error "Value cannot be null.\r\nParameter name: serviceType"

I was following a tutorial , but after setting the project build path, I run the project and navigate to plugins. Then I got the following error.
An exception of type 'System.ArgumentNullException' occurred in Autofac.dll but was not handled in user code,
"Value cannot be null.\r\nParameter name: serviceType"
and i don't know that which method i should add and in which class?
Please help!
you must register the service you created in the plugin and also the repository for your entity in DependencyRegistrar.cs file so that run time Autofac can found them for example:
public class DependencyRegistrar : IDependencyRegistrar
{
public virtual void Register(ContainerBuilder builder, ITypeFinder typeFinder)
{
//data context
this.RegisterPluginDataContext<MYPLUGINObjectContext>(builder, "nop_object_context_misc_MYPLUGIN");
//override required repository with our custom context
builder.RegisterType<EfRepository<ENTITY>>()
.As<IRepository<ENTITY>>()
.WithParameter(ResolvedParameter.ForNamed<IDbContext>("nop_object_context_misc_MYPLUGIN"))
.InstancePerHttpRequest();
}
public int Order
{
get { return 0; }
}
}

How to get real path in JSF in a SessionListener

my requirement is as follows:
INFO: icefaces upload component, uploads the files to relative folder and creates for each user a sub-directory in that folder with the sessionId.
Requirement: at the sessionDestroyed for each user, i want to get the real path, to delete current user folder.
i know how to get the real path with JSF as follows:
ServletContext ctx = (ServletContext) FacesContext.getCurrentInstance()
.getExternalContext().getContext();
String deploymentDirectoryPath = ctx.getRealPath("/");
Problem: if you try to get the real path in sessionDestroyed you will get null pointer exception, so i was wondering if there's a way to initialize the variable deploymentDirectoryPath in the listener so i can use it in sessionDestroyed method, or maybe initialize the real path variable on application startup and use it here ?
please advise how to solve this issue.
Even though you haven't posted the actual code that relates to the problem, the following gives me the real path:
public class MySessListener implements HttpSessionListener {
#Override
public void sessionCreated(final HttpSessionEvent se) {
System.out.println(Thread.currentThread().getStackTrace()[1]);
new Timer().schedule(new TimerTask() {
#Override
public void run() {
HttpSession sess = se.getSession();
sess.invalidate();
}
}, 10000);
}
#Override
public void sessionDestroyed(HttpSessionEvent se) {
System.out.println(Thread.currentThread().getStackTrace()[1]);
String realPath = se.getSession().getServletContext().getRealPath("/");
System.out.println("realPath: " + realPath);
}
}
Output
INFO: com.bhesh.demo.web.listener.MySessListener.sessionCreated(MySessListener.java:13)
INFO: com.bhesh.demo.web.listener.MySessListener.sessionDestroyed(MySessListener.java:26)
INFO: realPath: C:\Documents and Settings\Bhesh\My Documents\NetBeansProjects\JsfMessageList\build\web\
Based on BalusC sound advice here and elsewhere one could write a general purpose function like this:
String getPath(){
ExternalContext tmpEC;
tmpEC = FacesContext.getCurrentInstance().getExternalContext();
String realPath=tmpEC.getRealPath("/");
return realPath;
}
You can get the real path as follows:-
FacesContext.getCurrentInstance().getExternalContext().getRealPath("/");
EDIT:-
As mentioned by BalusC in one of his answers, you should think twice before using getRealPath("/") because if one has not chose to expand the war file then, getRealPath("/") might return null.
Use getExternalContext.getResourceAsStream instead. as per, docs, It is valid to call this method during application startup or shutdown.

Ignore file attributes with MSDeploy?

When using msdeploy to do a sync operation, one of the things that MSDeploy checks to determine if a file should be synced or not is the attributes on the file (readonly, archive, etc.). If the attributes are different between the two copies of the file, then the file will be synced. Is there a way to tell MSDeploy to ignore file attributes when determining if a file should be synced or not?
It is possible, however, not merely on the command line. You'd have to build a custom DeploymentRuleHandler, like this:
namespace CustomRuleHandlers
{
using Microsoft.Web.Deployment;
[DeploymentRuleHandler]
internal class IgnoreFileAttributesRuleHandler : DeploymentRuleHandler
{
public override int CompareAttribute(DeploymentSyncContext syncContext, DeploymentObject destinationObject, DeploymentObjectAttribute destinationAttribute, DeploymentObject sourceObject, DeploymentObjectAttribute sourceAttribute, int currentComparison)
{
if ((destinationObject.Name.Equals("filePath", StringComparison.Ordinal))
&& destinationAttribute.Name.Equals("attributes", StringComparison.Ordinal))
{
return 0;
}
return currentComparison;
}
public override string Description
{
get { return "Ignores file attributes when determining if a file should be synched or not."; }
}
public override string FriendlyName
{
get { return "IgnoreFileAttributes"; }
}
public override string Name
{
get { return "IgnoreFileAttributes"; }
}
public override bool EnabledByDefault
{
get { return false; }
}
}
}
Compile that into an assembly (targeting .Net 3.5 for WebDeploy v2!) and put the assembly into the "Extensibility" subfolder in the WebDeploy folder (normally, C:\Program Files\IIS\Microsoft Web Deploy V2\Extensibility).
Then, you can easily leverage your custom rule when running msdeploy from the command-line by adding this argument:
-enableRule:IgnoreFileAttributes
Of course, that assembly needs to be present on both, the source and the target machine, of a sync operation.
Unfortunately, there's no easier way of getting there!

Resources