Skip to content

Commit

Permalink
ItemStackTag.
Browse files Browse the repository at this point in the history
  • Loading branch information
AmarokIce committed Feb 13, 2024
1 parent c6d621f commit be55ed1
Show file tree
Hide file tree
Showing 11 changed files with 186 additions and 34 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# 项目排除路径
/.gradle/
/.idea/
/build/
Empty file added README.md
Empty file.
65 changes: 48 additions & 17 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,53 +1,84 @@
buildscript {
repositories {
mavenCentral()
maven {
name = "forge https"
url = "https://files.minecraftforge.net/maven"
url = "https://jcenter.bintray.com/"
}
maven {
name = "forge"
url = "https://maven.minecraftforge.net/"
}
maven {
name = "sonatype"
url = "https://oss.sonatype.org/content/repositories/snapshots/"
}
}
dependencies {
classpath 'net.minecraftforge.gradle:ForgeGradle:1.2-SNAPSHOT'
classpath ('com.anatawa12.forge:ForgeGradle:1.2-1.1.+') {
changing = true
}
}
}

apply plugin: 'forge'
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'maven-publish'

version = "1.3"

version = "1.4"
group= "club.someoneice.togocup.pineapple_tag"
archivesBaseName = "PineappleTag"

minecraft {
version = "1.7.10-10.13.4.1614-1.7.10"
runDir = "eclipse"
}

sourceCompatibility = targetCompatibility = "1.8"

repositories {
maven { url "http://maven.snowlyicewolf.club/" }
}

dependencies {
implementation fileTree(dir: 'lib', includes: ['*.jar'])
implementation "club.someoneice.togocup.recipebook:PineappleRecipeBook:1.0"
}

processResources{
duplicatesStrategy = 'include'
inputs.property "version", project.version
inputs.property "mcversion", project.minecraft.version

from(sourceSets.main.resources.srcDirs) {
include 'mcmod.info'

expand 'version':project.version, 'mcversion':project.minecraft.version
expand 'version':project.version, 'mcversion':project.minecraft.version, 'name':project.archivesBaseName
}

from(sourceSets.main.resources.srcDirs) {
exclude 'mcmod.info'
}
}

apply from: 'maven.gradle'
minecraft {
version = "1.7.10-10.13.4.1614-1.7.10"
runDir = "eclipse"
}

sourceCompatibility = targetCompatibility = "1.8"

tasks.withType(Jar) {
compileJava.options.encoding = 'UTF-8'
compileJava.options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
}

publishing {
repositories {
maven {
name = "PineappleTags"
url = uri("https://maven.pkg.github.com/amarokice/pineappletags")
credentials {
username = "AmarokIce"
password = System.getenv("GITHUB_TOKEN")
}
}
}

publications {
gpr(MavenPublication) {
from(components.java)
}
}
}
50 changes: 50 additions & 0 deletions src/main/java/club/someoneice/togocup/tags/ItemStackTag.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package club.someoneice.togocup.tags;

import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;

public class ItemStackTag extends Tag<ItemStack> {
ItemStackTag(String name) {
super(name);
}

@Override
public boolean has(Object item) {
if (item instanceof ItemStack) return hasItemStack((ItemStack) item);
else if (item instanceof Item) return hasItemStack(new ItemStack((Item) item));
return false;
}

@Override
public boolean hasAssignableFrom(Object item) {
if (item instanceof ItemStack) return hasItemAssignableFrom(((ItemStack) item).getItem());
else if (item instanceof Item) return hasItemAssignableFrom((Item) item);
return false;
}

@Override
public boolean hasAssignableBy(Object item) {
return super.hasAssignableBy(item);
}

public boolean hasItemStack(ItemStack item) {
if (item == null) return false;
for (ItemStack it : this.items)
if (item.getItem() == it.getItem() && item.getItemDamage() == it.getItemDamage())
return true;
return false;
}


public boolean hasItemAssignableFrom(Item item) {
for (ItemStack obj : items)
if (obj.getItem().getClass().isAssignableFrom(item.getClass())) return true;
return false;
}

public boolean hasItemAssignableBy(Item item) {
for (ItemStack obj : items)
if (item.getClass().isAssignableFrom(obj.getItem().getClass())) return true;
return false;
}
}
1 change: 0 additions & 1 deletion src/main/java/club/someoneice/togocup/tags/JsonHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.google.common.collect.Lists;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import cpw.mods.fml.common.Loader;
import net.minecraft.block.Block;
import net.minecraft.item.Item;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

import java.util.List;

@Mod(modid = "pieapple_tags")
@Mod(modid = "pineapple_tags")
public class PineappleTags {
public static final Logger LOGGER = LogManager.getLogger("pineapple_tags");

Expand Down
9 changes: 8 additions & 1 deletion src/main/java/club/someoneice/togocup/tags/Tag.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
import com.google.common.collect.Lists;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;

import java.util.Collection;
import java.util.List;

@SuppressWarnings({"unchecked", "unused"})
public class Tag<E> {
private final List<E> items;
protected final List<E> items;
public final String name;

Tag(String name) {
Expand Down Expand Up @@ -73,10 +75,15 @@ public boolean remove(E item) {
* 从标签到矿物辞典。不会实时同步,若发生更新必须重新申明。
* */
public boolean asOreDict() {
if (this.items.isEmpty()) return false;
if (this.items.get(0) instanceof Item) {
for (Item item : (List<Item>) items)
OreDictionary.registerOre(name, item);
return true;
} else if (this.items.get(0) instanceof ItemStack) {
for (ItemStack item : (List<ItemStack>) items)
OreDictionary.registerOre(name, item);
return true;
} else if (this.items.get(0) instanceof Block) {
for (Block block : (List<Block>) items)
OreDictionary.registerOre(name, block);
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/club/someoneice/togocup/tags/TagsManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.util.List;
import java.util.Map;

@SuppressWarnings({"unchecked", "unused"})
public class TagsManager {
private static final Map<String, Tag<?>> tags = Maps.newConcurrentMap();
public static final TagsManager INSTANCE = new TagsManager();
Expand All @@ -21,6 +22,27 @@ public static TagsManager manager() {
return INSTANCE;
}

/**
* Create a new ItemStack Tag or take a Tag from tags pool. <br />
* 创建新ItemStack标签,或从标签池中取得标签。
* */
public ItemStackTag registerItemStackTag(String name, @Nullable ItemStack ... items) {
if (tags.containsKey(name)) {
try {
ItemStackTag tag = (ItemStackTag) tags.get(name);
if (items != null) tag.addAll(Arrays.asList(items));
return tag;
} catch (Exception e) {
PineappleTags.LOGGER.error("One of mod's Tags " + name + " is broken when create because the type is not same.");
}
}

ItemStackTag tag = new ItemStackTag(name);
if (items != null) tag.addAll(Arrays.asList(items));
tags.put(name, tag);
return tag;
}

/**
* Create a new Tag or take a Tag from tags pool. <br />
* 创建新标签,或从标签池中取得标签。
Expand Down
36 changes: 36 additions & 0 deletions src/main/resources/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
=== Pineapple license ===
I will provide all or part of the code, as long as you use it within the limits of the law, you can use these codes as you like.
You can get full access to this source code without paying any royalties, which will be permanent and irrevocable if you are granted this license.
You can get full right to use this source code without paying any royalties, which will be perpetual and will not be revoked if you are granted this license, unless you have violated this agreement or have been prevented by me from granting it to you in any way.
If you have made a copy of the Program with these code, you should include this license to keep the original code open source.

Of course this license doesn't used in court, just like you know that none of us want legal battles for these meaningless things, so I hope you will respect this brief license.
I do not want my code to be used for commercial purposes, including but not limited to paid downloads and download with AD(e.g. AdF.ly).
If you used my code to do some instructional videos, or if you used my code to the fullest, put it in the pineapple juicer and sold the juicer to make money, it's your credit, you can certainly do it.
If you think my mod is good to learn something, if you like, invite me to a cup of pineapple juice.

If you do not follow this simple agreement and legal liability arises, this has nothing to do with me, please take responsibility for yourself.
If you're selling my source code or compiled code, I'll be very angry and accuse you smelling ugly.

I reserve the right to make changes to the license without affecting your exercise of this license.
If you are unable to accept a license other than those approved by the Open Source Initiative, you may use these codes using the AFL-3.0 license, instead of complying with this license.
If you choose to accept AFL-3.0, you may need to show in your README or somewhere else that is very convenient to see, you are using the AFL-3.0 license.



=== 凤梨许可证 ===
我会提供全部或者部分的代码,只要您在法律限制之内使用,您可以随意的使用这些代码。
您可以获取这份源代码全部的使用权并且不需要支付任何版权税,如果您被授权了这份许可证,这将会永久生效且不会撤回,除非您已经违反了这份协议或由我以任何形式阻止了这份协议授权于您。
如果您使用这些代码制作了副本,您应当将本许可证包涵其中保持原有代码依然开源。

当然,这个许可证在法庭中站不住脚,您知道的,我们都不希望为了这些没有意义的事情而产生法律纠纷,所以我希望您能尊重这份非常简短的许可证。
我不希望我的代码被用于商业用途,包括但不限于付费下载与广告下载(例如AdF.ly)。
如果您使用我的代码做了一些教学影片,或者您充分的使用了我的代码,把它写入了凤梨榨汁机里然后贩卖榨汁机赚取了钱,这是您的功劳,您当然可以这样做。
如果您觉得您可以在我的代码中收获点什么,若您愿意,那就请我喝一杯凤梨汁吧。

如果您没有按照这份简单的协议执行,出现了法律责任,这与我无关,请您自己承担责任。
如果您正在贩卖我的源代码或者编译后代码,我会非常愤怒的指责你闻起来很臭。

我将保留在不影响您执行这份许可证的情况下对许可证进行改动。
如果您无法接受一份在开源社区协会认可之外的许可证,您可以参照AFL-3.0许可证来使用这些代码,而不是遵照这份许可证。
若您选择接受AFL-3.0,您可能需要在您的README中或者别的能够非常方便的看到的地方著名,您正在使用AFL-3.0许可证的情况下使用这些代码。
3 changes: 3 additions & 0 deletions src/main/resources/data/pineapple_tags/tag/item/TestTag.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[
"minecraft:apple"
]
28 changes: 14 additions & 14 deletions src/main/resources/mcmod.info
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
[
{
"modid": "pineapple_tag",
"name": "PineappleTag",
"description": "PineappleTag",
"version": "1.0",
"mcversion": "${mcversion}",
"url": "",
"updateUrl": "",
"authorList": ["Someoneice"],
"credits": "",
"logoFile": "",
"screenshots": [],
"dependencies": []
}
{
"modid": "pineapple_tag",
"name": "PineappleTag",
"description": "PineappleTag",
"version": "1.4",
"mcversion": "${mcversion}",
"url": "",
"updateUrl": "",
"authorList": ["Someoneice"],
"credits": "",
"logoFile": "",
"screenshots": [],
"dependencies": []
}
]

0 comments on commit be55ed1

Please sign in to comment.