Jump to content

byalexeykh

Members
  • Posts

    14
  • Joined

  • Last visited

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

byalexeykh's Achievements

Tree Puncher

Tree Puncher (2/8)

0

Reputation

  1. private static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, "minecraft"); public static final RegistryObject<Item> wooden_sword = ITEMS.register("wooden_sword", () -> custom_wooden_sword); Alright it worked
  2. It is a little unclear from the first time what is meant: the name of the variable in Items.class or the value of the "key" argument in the register method of the same class. Anyway if I change name to "wooden_sword" I'll just add a new item, the old one won't be replaced I read it better and, indeed, in "WOODEN_SWORD" case the crash of the game is caused by "Non [a-z0-9/._-] character in path of location" But this does not change the fact that simply registering an item under the same name does not replace it. mc 1.15.2 forge 31.2.41 mappings 20200514-1.15.1
  3. like this? private static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, MOD_ID); public static final RegistryObject<Item> WOODEN_SWORD = ITEMS.register("WOODEN_SWORD", () -> custom_wooden_sword); Most likely I'm doing something wrong, because in this case game crashes: [19:00:27] [Render thread/ERROR] [ne.mi.fm.ja.FMLModContainer/LOADING]: Failed to load class com.byalexeykh.advancedcombatsystem.AdvancedCombatSystem java.lang.ExceptionInInitializerError: null at java.lang.Class.forName0(Native Method) ~[?:1.8.0_251] {} at java.lang.Class.forName(Class.java:348) ~[?:1.8.0_251] {} and [19:00:27] [Render thread/INFO] [STDOUT/]: [net.minecraft.util.registry.Bootstrap:printToSYSOUT:110]: ---- Minecraft Crash Report ---- // Shall we play a game? Time: 9/23/20 7:00 PM Description: Initializing game java.lang.RuntimeException: java.lang.reflect.InvocationTargetException at net.minecraftforge.fml.javafmlmod.FMLJavaModLanguageProvider$FMLModTarget.loadMod(FMLJavaModLanguageProvider.java:78) ~[forge-1.15.2-31.2.41_mapped_snapshot_20200514-1.15.1-recomp.jar:31.2] {} at net.minecraftforge.fml.ModLoader.buildModContainerFromTOML(ModLoader.java:251) ~[forge-1.15.2-31.2.41_mapped_snapshot_20200514-1.15.1-recomp.jar:?] {re:classloading} at FMLJavaModLanguageProvider.java:78 I found this: catch (NoSuchMethodException | ClassNotFoundException | InstantiationException | IllegalAccessException | InvocationTargetException e) { LOGGER.fatal(LOADING,"Unable to load FMLModContainer, wut?", e); throw new RuntimeException(e); }
  4. How @ObjectHolder can help in this situation? As far as I know @ObjectHolder just gives reference of the object after objects registration, so it cannot be used to replace vanilla objects, or am I misunderstanding something? Anyway, I figured out how to do it using Java reflection, in this example I replaced wooden sword with custom item that extends SwordItem: boolean isRegistered = false; @SubscribeEvent public void onItemReg(RegistryEvent.Register<Item> event){ System.out.println("Entering item registry event"); if(!isRegistered){ try{ Field field = Items.class.getField("WOODEN_SWORD"); field.setAccessible(true); Method method = Items.class.getDeclaredMethod("register", String.class, Item.class); method.setAccessible(true); Item itemToInsert = (Item)method.invoke(Items.class, "wooden_sword", custom_wooden_sword); System.out.println("Item to insert: " + itemToInsert.toString()); System.out.println("Field: " + field.getName()); Field modifiersField = Field.class.getDeclaredField("modifiers"); modifiersField.setAccessible(true); modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL); field.set(null, itemToInsert); isRegistered = true; }catch(Throwable e){ System.out.println("ERROR while reflecting Items.java field: " + e); } } ATTENTION, I do not know how dangerous this method is and how it can negatively affect the operation of the game, but thanks to it I was able to completely replace the standard sword with a custom one and the game did not crash. I think somehow this can be done using standard forge solutions, but no matter how much I searched, I did not find any specific solutions, but this does not change the feeling that if someone experienced saw my code, he would have had a heart attack... (also dont beat me for this boolean, did it on a fast hand)
  5. This is how AttributeModifier is applied to the slowness effect, and i see no difference between this and my code public static final Effect SLOWNESS = register(2, "slowness", (new Effect(EffectType.HARMFUL, 5926017)).addAttributesModifier(SharedMonsterAttributes.MOVEMENT_SPEED, "7107DE5E-7CE8-4030-940E-514C1F160890", (double)-0.15F, AttributeModifier.Operation.MULTIPLY_TOTAL)); What do you mean "like that"?
  6. Applying slow-down modifier: if(!isReduceSpeedModAdded){ mc.player.getAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).applyModifier(new AttributeModifier( AdvancedCombatSystem.MOVEMENT_SPEED_REDUCE_UUID, "Movement speed reduce modifier", -0.4, AttributeModifier.Operation.MULTIPLY_TOTAL) ); isReduceSpeedModAdded = true; } setting setSprinting() to false: if(isReduceSpeedModAdded){ mc.player.setSprinting(false); } removing slow-down modifier: if(mc.player!=null && isReduceSpeedModAdded) { mc.player.getAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).removeModifier(AdvancedCombatSystem.MOVEMENT_SPEED_REDUCE_UUID); isReduceSpeedModAdded = false; }
  7. I have AttributeModifier that slow down player once condition is met and speed up to default speed (removing this modifier) when other condition is met, everything works well until player start sprinting while in slowed-down state: the slow-down AttributeModifier somehow canceled, the player starts sprinting at normal speed and then starts walking at normal speed. setSprinting(false) cancels "W" double-tap sprint activation, "ctrl" still working and does not affect the cancellation of my AttributeModifier (setSprinting(false) is located in tick event) i.e my modifier is being canceled even with setSprinting(false) I think there is an option to remove every tick sprint modifier and reapply my modifier, but this will most likely cause movement jitter ... And in general, I would like the speed reduction to affect the sprint itself.
  8. The idea is to raytrace entities using custom vector that was calculated before. When i started making this I found out that there is no such func in minecraft/forge like EntityRayTrace(startVec, endVec) to simply check entites which will be on this line. Also i didnt found how works mc.getInstance().mouseObjectOver. Is there a way to raytrace entites with custom vectors?
  9. Nothing is automatic here, just forge executing constructor automatically... good contradictions It's not about "programming knowledge", its about forge knowlege. How was I supposed to know that in one case this would allow forge to run constructor, and in which case it should be done manually? ^SOLUTION^, yeah, now everything works fine, thanks
  10. 😮 What about automatic registration like here? @Mod("randommod") public class randomClass { public randomClass(){ MinecraftForge.EVENT_BUS.register(this); } } There is no word in the documentation that the constructor with FMLModLoadingContext.get().getModEventBus().registerListener(); needs to be called manually. Anyway, this code does not work either: @Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD, modid = "advancedcombatsystem") public class NetworkHandler { @SubscribeEvent public void commonSetup(FMLCommonSetupEvent event){ System.out.println("[ACS] Initiating NetworkHandler"); INSTANCE = NetworkRegistry.newSimpleChannel( new ResourceLocation("advancedcombatsystem", "ACSchannel"), () -> PROTOCOL_VERSION, PROTOCOL_VERSION::equals, PROTOCOL_VERSION::equals ); // Registering messages INSTANCE.registerMessage(SEND_DAMAGE_TO_ID, MessageSendDamageTo.class, MessageSendDamageTo::encode, MessageSendDamageTo::decode, ServerMessagesHandler::onSendDamageToReceived ); } }
  11. It needs to be called? I thought it worked like EVENT_BUS registration: @Mod("advancedcombatsystem") public class ACSInputHandler { public ACSInputHandler(){ MinecraftForge.EVENT_BUS.register(this); } In that case, where should I call it? If I understand correctly, that constructor must be called before the event is executed. But the event occurs when the game starts and before it is impossible to do anything, as I understand it.
  12. What im trying to achieve: Add newSimpleChannel and custom messages for client-server communication. Main problem: When im trying to send packets from client to server using this code: NetworkHandler.INSTANCE.sendToServer(msg); I get null pointer exception. msg is not null, there is a corresponding check for this, then probably INSTANCE is null here. That's what debugger tells me: Which is pretty strange considering that I assigning value to INSTANCE in FMLCommonSetupEvent: public class NetworkHandler { public NetworkHandler(){ FMLJavaModLoadingContext.get().getModEventBus().addListener(this::commonSetup); } private void commonSetup(FMLCommonSetupEvent event){ System.out.println("[ACS] Initiating NetworkHandler"); INSTANCE = NetworkRegistry.newSimpleChannel( new ResourceLocation("advancedcombatsystem", "ACSchannel"), () -> PROTOCOL_VERSION, PROTOCOL_VERSION::equals, PROTOCOL_VERSION::equals ); // Registering messages INSTANCE.registerMessage(SEND_DAMAGE_TO_ID, MessageSendDamageTo.class, MessageSendDamageTo::encode, MessageSendDamageTo::decode, ServerMessagesHandler::onSendDamageToReceived ); } } Based on this, I conclude that this event is not fired. Additional info: I've tried: to subscribe to FMLCommonSetupEvent using SubcsribeEvent - same issue. to add Mod("mymodid"), Mod.EventBusSubscriber(modid = "mymodid") above class declaration - did not help. to call "init" function (commonSetup in code above) within same event (FMLCommonSetupEvent) in another class, where there is other events that works well - same issue (FMLCommonSetupEvent does not start there either).
  13. Code: TraceResult = mc.objectMouseOver; if(TraceResult!=null){ if(TraceResult.getType() == RayTraceResult.Type.ENTITY) { EntityRayTraceResult EntityTrace = (EntityRayTraceResult) TraceResult; if (EntityTrace.getEntity() instanceof LivingEntity) { if (EntityTrace.getEntity().attackEntityFrom(DamageSource.causePlayerDamage(mc.player), 3)) { System.out.println("Attack successful"); } else{ System.out.println("Attack failed"); } } } } What am I trying to achieve: Damage entity when player releases left mouse button. Input tracking works well, but the problem is: After I release the left mouse button attackEntityFrom always returns false. Aditional info: These "if's" are located in ClientTickEvent event.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.