• Recently Browsing

    No registered users viewing this page.

  • Posts

    • I used the DistExecutor and the code is now the following val flag = super.onBlockPlaced(pos, worldIn, player, stack, state) if (worldIn.isRemote && !flag && player != null) { DistExecutor.safeRunWhenOn(Dist.CLIENT) { DistExecutor.SafeRunnable { Minecraft.getInstance().displayGuiScreen(CustomEditSignScreen(worldIn.getTileEntity(pos) as CustomSignTileEntity)) } } } return flag   Now my custom sign screen is opened and i can edit it, but when i exit and re-enter the world, the sign is blank. If i use !worldIn.isRemote instead of worldIn.isRemote  the game crash even if i use the DistExecutor
    • Hi, this is my very first time creating a mod and i encounter a peculiar problem, i looked everywhere but i cant seem to find the issue. I'm making a new block that is basically a Crafting Table re textured, and everything works fine except that everytime i click on it, the GUI opens but instantaneously closes   This is the code that i use to copy the Crafting Table And this is the block
    • So I have been trying to make a capability and attach it to the player. This capability would monitor how much they are using the "drugs", which are just custom potions, in my mod and have negative consequences if they use them a lot. I have been following the documentation and guides but I still haven't managed to add the capability properly and I can't figure out why. package com.mitymods.funwithdrugs.capabilities; public interface IDrugUse { public void remove(float points); public void add(float points); public void setDrugUse(float points); public float getDrugUse(); } package com.mitymods.funwithdrugs.capabilities; public class DrugUse implements IDrugUse { private float drug_use; public DrugUse() { this.drug_use = 5; } @Override public void remove(float points) { // TODO Auto-generated method stub this.drug_use -= points; } @Override public void add(float points) { // TODO Auto-generated method stub this.drug_use += points; } @Override public void setDrugUse(float points) { // TODO Auto-generated method stub this.drug_use = points; } @Override public float getDrugUse() { // TODO Auto-generated method stub return this.drug_use; } } package com.mitymods.funwithdrugs.capabilities; import net.minecraft.nbt.INBT; import net.minecraft.util.Direction; import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.capabilities.CapabilityInject; import net.minecraftforge.common.capabilities.ICapabilitySerializable; import net.minecraftforge.common.util.LazyOptional; public class DrugUseProvider implements ICapabilitySerializable<INBT> { @CapabilityInject(IDrugUse.class) public static final Capability<IDrugUse> DRUG_USE_CAPABILITY = null; private LazyOptional<IDrugUse> instance = LazyOptional.of(DRUG_USE_CAPABILITY::getDefaultInstance); @Override public <T> LazyOptional<T> getCapability(Capability<T> cap, Direction side) { return cap == DRUG_USE_CAPABILITY ? instance.cast() : LazyOptional.empty(); } @Override public INBT serializeNBT() { // @formatter:off return DRUG_USE_CAPABILITY.getStorage().writeNBT(DRUG_USE_CAPABILITY, this.instance.orElseThrow(() -> new IllegalArgumentException("LazyOptional must not be empty!")), null); // @formatter:on } @Override public void deserializeNBT(INBT nbt) { // @formatter:off DRUG_USE_CAPABILITY.getStorage().readNBT(DRUG_USE_CAPABILITY, this.instance.orElseThrow(() -> new IllegalArgumentException("LazyOptional must not be empty!")), null, nbt); // @formatter:on } } package com.mitymods.funwithdrugs.capabilities; import net.minecraft.nbt.CompoundNBT; import net.minecraft.nbt.INBT; import net.minecraft.util.Direction; import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.capabilities.Capability.IStorage; public class DrugUseStorage implements Capability.IStorage<IDrugUse> { @Override public INBT writeNBT(Capability<IDrugUse> capability, IDrugUse instance, Direction side) { // return an NBT tag CompoundNBT tag = new CompoundNBT(); tag.putFloat("drug_use", instance.getDrugUse()); return tag; } @Override public void readNBT(Capability<IDrugUse> capability, IDrugUse instance, Direction side, INBT nbt) { // load from the NBT tag CompoundNBT tag = (CompoundNBT) nbt; instance.setDrugUse(tag.getFloat("drug_use")); } } package com.mitymods.funwithdrugs.events; import com.mitymods.funwithdrugs.FunWithDrugs; import com.mitymods.funwithdrugs.capabilities.DrugUseProvider; import com.mitymods.funwithdrugs.capabilities.IDrugUse; import net.minecraft.entity.Entity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.util.ResourceLocation; import net.minecraftforge.common.util.LazyOptional; import net.minecraftforge.event.AttachCapabilitiesEvent; import net.minecraftforge.event.entity.living.LivingFallEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus; @Mod.EventBusSubscriber(modid = FunWithDrugs.MOD_ID, bus = Bus.FORGE) public class AddDrugUse { @SubscribeEvent public static void onAttachCapabilities(AttachCapabilitiesEvent<Entity> event) { if (event.getObject() instanceof PlayerEntity) { event.addCapability(new ResourceLocation(FunWithDrugs.MOD_ID, "drug_use"), new DrugUseProvider()); } } @SubscribeEvent public void onPlayerFalls(LivingFallEvent event) { if(event.getEntityLiving() instanceof PlayerEntity) { PlayerEntity player = (PlayerEntity) event.getEntityLiving(); IDrugUse drugUse = player.getCapability(DrugUseProvider.DRUG_USE_CAPABILITY, null); if (drugUse.getDrugUse() == 5) { player.setHealth(0); } } } } And a bit of code in my main mod file FMLJavaModLoadingContext.get().getModEventBus().addListener(this::onCommonSetup); private void onCommonSetup(FMLCommonSetupEvent event) { CapabilityManager.INSTANCE.register(IDrugUse.class, new DrugUseStorage(), DrugUse::new); }   The purpose of this second event is to test if the player has the capability and if it equals the default value, however this code doesn't even work for some reason that I can not figure out. I am very stumped on what the issue is. And I DO know java, I just am having a hard time understanding this specific thing.   I know my code is probably pretty messy, I do intend to clean it up once I can figure out what I'm doing wrong
    • I didn't realize these methods existed. 👍
    • You are correct, e.g. stronghold library chests use the "enchant_with_levels" function, which randomly enchants the books. So you will need a loot modifier here. As for villager trades: I don't think you can do much here, if you look at VillagerTrades.EnchantedBookForEmeraldsTrade you will see that it simply uses a completely random enchantment, so you can literally get anything. You'd have to hack into the internal maps here somehow and replace it if you absolutely must remove them there, but that would possibly cause incompatibilities.
  • Topics

  • Who's Online (See full list)