Skip to content

Commit

Permalink
Knowledge Sharing Book
Browse files Browse the repository at this point in the history
  • Loading branch information
DonovanDMC committed Jun 22, 2022
1 parent 212fad8 commit 4917187
Show file tree
Hide file tree
Showing 13 changed files with 210 additions and 6 deletions.
14 changes: 13 additions & 1 deletion src/generated/resources/assets/projectexpansion/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,15 @@
"item.projectexpansion.infinite_steak": "Infinite Steak",
"item.projectexpansion.infinite_steak.tooltip": "Infinite food via your emc.",
"item.projectexpansion.infinite_steak.not_enough_emc": "You do not have enough emc to use this, you need %s.",
"item.projectexpansion.knowledge_sharing_book": "Knowledge Sharing Book",
"item.projectexpansion.knowledge_sharing_book.selected": "Selected Player: %s",
"item.projectexpansion.knowledge_sharing_book.stored": "Knowledge stored.",
"item.projectexpansion.knowledge_sharing_book.self": "You cannot gain your own knowledge.",
"item.projectexpansion.knowledge_sharing_book.learned": "You learned %s.",
"item.projectexpansion.knowledge_sharing_book.learned_over_100": "%s item(s) were learned, but not shown.",
"item.projectexpansion.knowledge_sharing_book.learned_total": "You have learned %s item(s) from %s.",
"item.projectexpansion.knowledge_sharing_book.no_new_knowledge": "You learned nothing new.",
"item.projectexpansion.knowledge_sharing_book.no_owner": "You cannot gain knowledge from an unowned book.",
"item.projectexpansion.magnum_star_ein": "Magnum Star Ein",
"item.projectexpansion.magnum_star_zwei": "Magnum Star Zwei",
"item.projectexpansion.magnum_star_drei": "Magnum Star Drei",
Expand All @@ -246,5 +255,8 @@
"text.projectexpansion.nbt_filter.disable": "NBT Filter Disabled",
"text.projectexpansion.nbt_filter.enable": "NBT Filter Enabled",
"enchantment.projectexpansion.alchemical_collection": "Alchemical Collection",
"enchantment.projectexpansion.alchemical_collection.desc": "Converts any mined items with an emc value directly into emc."
"enchantment.projectexpansion.alchemical_collection.desc": "Converts any mined items with an emc value directly into emc.",
"sounds.projectexpansion.knowledge_sharing_book.store": "Knowledge Stored",
"sounds.projectexpansion.knowledge_sharing_book.use": "Knowledge Gained",
"sounds.projectexpansion.knowledge_sharing_book.use_none": "No Knowledge Gained"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "item/handheld",
"textures": {
"layer0": "projectexpansion:item/knowledge_sharing_book"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"type": "minecraft:crafting_shaped",
"pattern": [
"VNV",
"VBV",
"VNV"
],
"key": {
"V": {
"item": "projectexpansion:violet_matter"
},
"N": {
"item": "minecraft:nether_star"
},
"B": {
"item": "minecraft:book"
}
},
"result": {
"item": "projectexpansion:knowledge_sharing_book"
}
}
6 changes: 2 additions & 4 deletions src/main/java/cool/furry/mc/forge/projectexpansion/Main.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package cool.furry.mc.forge.projectexpansion;

import cool.furry.mc.forge.projectexpansion.config.Config;
import cool.furry.mc.forge.projectexpansion.registries.Blocks;
import cool.furry.mc.forge.projectexpansion.registries.Enchantments;
import cool.furry.mc.forge.projectexpansion.registries.Items;
import cool.furry.mc.forge.projectexpansion.registries.TileEntityTypes;
import cool.furry.mc.forge.projectexpansion.registries.*;
import cool.furry.mc.forge.projectexpansion.util.Fuel;
import cool.furry.mc.forge.projectexpansion.util.Matter;
import cool.furry.mc.forge.projectexpansion.util.NBTNames;
Expand Down Expand Up @@ -47,6 +44,7 @@ public ItemStack createIcon() {
Blocks.Registry.register(bus);
Enchantments.Registry.register(bus);
Items.Registry.register(bus);
SoundEvents.Registry.register(bus);
TileEntityTypes.Registry.register(bus);
MinecraftForge.EVENT_BUS.addListener(this::serverTick);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class Config {
public static final ForgeConfigSpec.ConfigValue<Boolean> fullNumberNames = Builder.translation("gui.projectexpansion.config.full_number_names.desc").define("fullNumberNames", true);
public static final ForgeConfigSpec.ConfigValue<Boolean> emcDisplay = Builder.translation("gui.projectexpansion.config.emc_display.desc").define("emcDisplay", true);
public static final ForgeConfigSpec.ConfigValue<Boolean> notifyCommandChanges = Builder.translation("gui.projectexpansion.config.notify_command_changes.desc").define("notifyCommandChanges", true);
public static final ForgeConfigSpec.ConfigValue<Boolean> notifyKnowledgeBookGains = Builder.translation("gui.projectexpansion.config.notify_knowledge_book_gains.desc").define("notifyKnowledgeBookGains", true);
public static final ForgeConfigSpec.ConfigValue<Boolean> limitEmcLinkVendor = Builder.translation("gui.projectexpansion.config.limit_emc_link_vendor.desc").define("limitEmcLinkVendor", true);
// due to the large range of this (1 - Integer.MAX_VALUE, with all 2 billion values being valid), this option is excluded from the gui
public static final ForgeConfigSpec.ConfigValue<Integer> transmutationInterfaceItemCount = Builder.translation("gui.projectexpansion.config.transmutation_interface_item_count.desc").define("transmutationInterfaceItemCount", 2147483647);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ protected void init() {
(__, newValue) -> Config.notifyCommandChanges.set(newValue)
));

optionsRowList.func_214333_a(new BooleanOption(
"gui.projectexpansion.config.notify_knowledge_book_changes",
__ -> Config.notifyKnowledgeBookGains.get(),
(__, newValue) -> Config.notifyKnowledgeBookGains.set(newValue)
));

optionsRowList.func_214333_a(new BooleanOption(
"gui.projectexpansion.config.limit_emc_link_vendor",
__ -> Config.limitEmcLinkVendor.get(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
package cool.furry.mc.forge.projectexpansion.item;

import cool.furry.mc.forge.projectexpansion.Main;
import cool.furry.mc.forge.projectexpansion.config.Config;
import cool.furry.mc.forge.projectexpansion.registries.SoundEvents;
import cool.furry.mc.forge.projectexpansion.util.ColorStyle;
import cool.furry.mc.forge.projectexpansion.util.NBTNames;
import moze_intel.projecte.api.ItemInfo;
import moze_intel.projecte.api.ProjectEAPI;
import moze_intel.projecte.api.capabilities.IKnowledgeProvider;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Rarity;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.particles.ItemParticleData;
import net.minecraft.particles.ParticleTypes;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.StringTextComponent;
import net.minecraft.util.text.TranslationTextComponent;
import net.minecraft.world.World;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;

import javax.annotation.Nullable;
import java.util.List;
import java.util.UUID;

public class ItemKnowledgeSharingBook extends Item {
public ItemKnowledgeSharingBook() {
super(new Item.Properties().maxStackSize(1).rarity(Rarity.RARE).group(Main.group));
}

@Override
public ActionResult<ItemStack> onItemRightClick(World world, PlayerEntity player, Hand hand) {
ItemStack stack = player.getHeldItem(hand);
if(player.isCrouching()) {
if(!world.isRemote) {
CompoundNBT nbt = stack.getOrCreateTag();
nbt.putUniqueId(NBTNames.OWNER, player.getUniqueID());
nbt.putString(NBTNames.OWNER_NAME, player.getScoreboardName());
world.playSound(null, player.getPositionVec().x, player.getPositionVec().y, player.getPositionVec().z, SoundEvents.KNOWLEDGE_SHARING_BOOK_STORE.get(), SoundCategory.PLAYERS, 0.8F, 0.8F + world.rand.nextFloat() * 0.4F);
player.sendStatusMessage(new TranslationTextComponent("item.projectexpansion.knowledge_sharing_book.stored").setStyle(ColorStyle.GREEN), true);
}

return world.isRemote ? ActionResult.func_226248_a_(stack) : ActionResult.func_226249_b_(stack);
} else {
CompoundNBT nbt = stack.getOrCreateTag();
Main.Logger.info(nbt);
Main.Logger.info(nbt.getUniqueId(NBTNames.OWNER));
if(nbt.hasUniqueId(NBTNames.OWNER)) {
UUID owner = nbt.getUniqueId(NBTNames.OWNER);
if(player.getUniqueID().equals(nbt.getUniqueId(NBTNames.OWNER))) {
player.sendStatusMessage(new TranslationTextComponent("item.projectexpansion.knowledge_sharing_book.self").setStyle(ColorStyle.RED), true);
return ActionResult.func_226251_d_(stack);
}
if(!world.isRemote) {
IKnowledgeProvider ownerProvider = ProjectEAPI.getTransmutationProxy().getKnowledgeProviderFor(owner);
IKnowledgeProvider learnerProvider = ProjectEAPI.getTransmutationProxy().getKnowledgeProviderFor(player.getUniqueID());
long learned = 0;
for(ItemInfo info : ownerProvider.getKnowledge()) {
if(!learnerProvider.hasKnowledge(info)) {
if(Config.notifyKnowledgeBookGains.get() && learned < 100) {
player.sendMessage(new TranslationTextComponent("item.projectexpansion.knowledge_sharing_book.learned", info.createStack().getTextComponent()).setStyle(ColorStyle.GREEN));
}
learnerProvider.addKnowledge(info);
learned++;
}
}
nbt.putLong(NBTNames.LAST_USED, world.getGameTime());
nbt.putLong(NBTNames.KNOWLEDGE_GAINED, learned);
if(learned > 0) {
learnerProvider.sync((ServerPlayerEntity) player);
if(learned > 100) {
player.sendMessage(new TranslationTextComponent("item.projectexpansion.knowledge_sharing_book.learned_over_100", learned - 100).setStyle(ColorStyle.GREEN));
}
player.sendStatusMessage(new TranslationTextComponent("item.projectexpansion.knowledge_sharing_book.learned_total", learned, new StringTextComponent(nbt.getString(NBTNames.OWNER_NAME)).setStyle(ColorStyle.AQUA)).setStyle(ColorStyle.GREEN), true);
world.playSound(null, player.getPositionVec().x, player.getPositionVec().y, player.getPositionVec().z, SoundEvents.KNOWLEDGE_SHARING_BOOK_USE.get(), SoundCategory.PLAYERS, 0.8F, 0.8F + world.rand.nextFloat() * 0.4F);
} else {
player.sendStatusMessage(new TranslationTextComponent("item.projectexpansion.knowledge_sharing_book.no_new_knowledge").setStyle(ColorStyle.RED), true);
world.playSound(null, player.getPositionVec().x, player.getPositionVec().y, player.getPositionVec().z, SoundEvents.KNOWLEDGE_SHARING_BOOK_USE_NONE.get(), SoundCategory.PLAYERS, 0.8F, 0.8F + world.rand.nextFloat() * 0.4F);
}
} else {
long gained = nbt.getLong(NBTNames.KNOWLEDGE_GAINED);
for(int i = 0; i < 5; i++) {
Vec3d v1 = new Vec3d(((double) world.rand.nextFloat() - 0.5D) * 0.1D, Math.random() * 0.1D + 0.1D, 0.0D)
.rotatePitch(-player.rotationPitch * 0.017453292F)
.rotateYaw(-player.rotationYaw * 0.017453292F);
Vec3d v2 = new Vec3d(((double) world.rand.nextFloat() - 0.5D) * 0.3D, (double) (-world.rand.nextFloat()) * 0.6D - 0.3D, 0.6D)
.rotatePitch(-player.rotationPitch * 0.017453292F)
.rotateYaw(-player.rotationYaw * 0.017453292F)
.add(player.getPositionVec().x, player.getPositionVec().y + (double) player.getEyeHeight(), player.getPositionVec().z);
world.addParticle(gained > 0 ? new ItemParticleData(ParticleTypes.ITEM, stack) : ParticleTypes.SMOKE, v2.x, v2.y, v2.z, v1.x, v1.y + 0.05D, v1.z);
}
}

stack.shrink(1);
return world.isRemote ? ActionResult.func_226248_a_(stack) : ActionResult.func_226249_b_(stack);
} else {
player.sendStatusMessage(new TranslationTextComponent("item.projectexpansion.knowledge_sharing_book.no_owner").setStyle(ColorStyle.RED), true);
return ActionResult.func_226251_d_(stack);
}
}
}

@Override
public boolean hasEffect(ItemStack stack) {
return stack.getOrCreateTag().hasUniqueId(NBTNames.OWNER);
}

@Override
@OnlyIn(Dist.CLIENT)
public void addInformation(ItemStack stack, @Nullable World world, List<ITextComponent> tooltip, ITooltipFlag flag) {
super.addInformation(stack, world, tooltip, flag);
CompoundNBT nbt = stack.getOrCreateTag();
if(nbt.hasUniqueId(NBTNames.OWNER)) {
tooltip.add(new TranslationTextComponent("item.projectexpansion.knowledge_sharing_book.selected", new StringTextComponent(nbt.getString(NBTNames.OWNER_NAME)).setStyle(ColorStyle.AQUA)).setStyle(ColorStyle.GRAY));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ public class Items {
public static final RegistryObject<Item> INFINITE_FUEL = Registry.register("infinite_fuel", ItemInfiniteFuel::new);
public static final RegistryObject<Item> INFINITE_STEAK = Registry.register("infinite_steak", ItemInfiniteSteak::new);
public static final RegistryObject<BlockItem> TRANSMUTATION_INTERFACE = Registry.register("transmutation_interface", () -> new BlockItem(Blocks.TRANSMUTATION_INTERFACE.get(), new Item.Properties().group(Main.group).rarity(Rarity.EPIC)));
public static final RegistryObject<Item> KNOWLEDGE_SHARING_BOOK = Registry.register("knowledge_sharing_book", ItemKnowledgeSharingBook::new);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package cool.furry.mc.forge.projectexpansion.registries;

import cool.furry.mc.forge.projectexpansion.Main;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.SoundEvent;
import net.minecraftforge.fml.RegistryObject;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;

public class SoundEvents {
public static final DeferredRegister<SoundEvent> Registry = DeferredRegister.create(ForgeRegistries.SOUND_EVENTS, Main.MOD_ID);

public static final RegistryObject<SoundEvent> KNOWLEDGE_SHARING_BOOK_STORE = Registry.register("knowledge_sharing_book.store", () -> new SoundEvent(new ResourceLocation(Main.MOD_ID, "knowledge_sharing_book.store")));
public static final RegistryObject<SoundEvent> KNOWLEDGE_SHARING_BOOK_USE = Registry.register("knowledge_sharing_book.use", () -> new SoundEvent(new ResourceLocation(Main.MOD_ID, "knowledge_sharing_book.use")));
public static final RegistryObject<SoundEvent> KNOWLEDGE_SHARING_BOOK_USE_NONE = Registry.register("knowledge_sharing_book.use_none", () -> new SoundEvent(new ResourceLocation(Main.MOD_ID, "knowledge_sharing_book.use_none")));
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ public class NBTNames {
public static String REMAINING_IMPORT = "RemainingImport";
public static String REMAINING_EXPORT = "RemainingExport";
public static String REMAINING_FLUID = "RemainingFluid";
public static String LAST_USED = "LastUsed";
public static String KNOWLEDGE_GAINED = "KnowledgeGained";
}
14 changes: 14 additions & 0 deletions src/main/resources/assets/projectexpansion/sounds.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"knowledge_sharing_book.store": {
"subtitle": "sounds.projectexpansion.knowledge_sharing_book.store",
"sounds": ["minecraft:random/orb"]
},
"knowledge_sharing_book.use": {
"subtitle": "sounds.projectexpansion.knowledge_sharing_book.use",
"sounds": ["minecraft:random/break"]
},
"knowledge_sharing_book.use_none": {
"subtitle": "sounds.projectexpansion.knowledge_sharing_book.use_none",
"sounds": ["minecraft:random/fizz"]
}
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 4917187

Please sign in to comment.