-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add fossil items, incenses and item use logic config
- Loading branch information
1 parent
45b5c87
commit 3edef65
Showing
21 changed files
with
240 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
common/src/main/java/abeshutt/staracademy/config/ItemLogicConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package abeshutt.staracademy.config; | ||
|
||
import abeshutt.staracademy.util.ItemUseLogic; | ||
import com.google.gson.annotations.Expose; | ||
import net.minecraft.item.ItemStack; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import static abeshutt.staracademy.util.ItemUseLogic.CommandExecutionContext.PLAYER; | ||
import static abeshutt.staracademy.util.ItemUseLogic.CommandExecutionContext.SERVER; | ||
|
||
public class ItemLogicConfig extends FileConfig { | ||
|
||
@Expose private List<ItemUseLogic> use; | ||
|
||
@Override | ||
public String getPath() { | ||
return "item_logic"; | ||
} | ||
|
||
public Optional<ItemUseLogic> getUseLogic(ItemStack stack) { | ||
for(ItemUseLogic entry : this.use) { | ||
if(entry.getPredicate().test(stack)) { | ||
return Optional.of(entry); | ||
} | ||
} | ||
|
||
return Optional.empty(); | ||
} | ||
|
||
@Override | ||
protected void reset() { | ||
this.use = new ArrayList<>(); | ||
this.use.add(new ItemUseLogic("academy:hunt", PLAYER, "/hunt")); | ||
this.use.add(new ItemUseLogic("academy:shiny_incense", SERVER, "/yacb boost ${user_uuid} 4 24000 shiny")); | ||
this.use.add(new ItemUseLogic("academy:strong_shiny_incense", SERVER, "/yacb boost ${user_uuid} 8 36000 shiny")); | ||
this.use.add(new ItemUseLogic("academy:uber_shiny_incense", SERVER, "/yacb boost ${user_uuid} 12 72000 shiny")); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
common/src/main/java/abeshutt/staracademy/mixin/MixinItemStack.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package abeshutt.staracademy.mixin; | ||
|
||
import abeshutt.staracademy.init.ModConfigs; | ||
import abeshutt.staracademy.util.ItemUseLogic; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.util.Hand; | ||
import net.minecraft.util.TypedActionResult; | ||
import net.minecraft.world.World; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
|
||
import static abeshutt.staracademy.util.ItemUseLogic.CommandExecutionContext.*; | ||
|
||
@Mixin(ItemStack.class) | ||
public class MixinItemStack { | ||
|
||
@Inject(method = "use", at = @At("HEAD"), cancellable = true) | ||
public void use(World world, PlayerEntity user, Hand hand, CallbackInfoReturnable<TypedActionResult<ItemStack>> ci) { | ||
if(!user.getWorld().isClient() && user.getServer() != null) { | ||
ItemUseLogic logic = ModConfigs.ITEM_LOGIC.getUseLogic((ItemStack)(Object)this).orElse(null); | ||
if(logic == null) return; | ||
|
||
for(String command : logic.getCommands()) { | ||
command = command.replace("${user_uuid}", user.getUuid().toString()); | ||
|
||
if(logic.getContext() == PLAYER) { | ||
user.getServer().getCommandManager().executeWithPrefix(user.getCommandSource(), command); | ||
} else if(logic.getContext() == SERVER) { | ||
user.getServer().getCommandManager().executeWithPrefix(user.getServer().getCommandSource(), command); | ||
} | ||
} | ||
|
||
ci.setReturnValue(TypedActionResult.success(user.getStackInHand(hand))); | ||
} | ||
} | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
common/src/main/java/abeshutt/staracademy/mixin/MixinPlayerEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package abeshutt.staracademy.mixin; | ||
|
||
import com.cobblemon.mod.common.util.PlayerExtensionsKt; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.item.ItemStack; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
@Mixin(PlayerExtensionsKt.class) | ||
public class MixinPlayerEntity { | ||
|
||
@Inject(method = "giveOrDropItemStack", at = @At("HEAD")) | ||
private static void giveOrDropItemStack(PlayerEntity player, ItemStack stack, boolean playSound, CallbackInfo ci) { | ||
|
||
} | ||
|
||
} |
78 changes: 78 additions & 0 deletions
78
common/src/main/java/abeshutt/staracademy/util/ItemUseLogic.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package abeshutt.staracademy.util; | ||
|
||
import abeshutt.staracademy.data.adapter.Adapters; | ||
import abeshutt.staracademy.data.item.ItemPredicate; | ||
import abeshutt.staracademy.data.serializable.ISerializable; | ||
import com.google.gson.JsonArray; | ||
import com.google.gson.JsonElement; | ||
import com.google.gson.JsonObject; | ||
import net.minecraft.nbt.NbtCompound; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import static abeshutt.staracademy.data.adapter.basic.EnumAdapter.Mode.NAME; | ||
|
||
public class ItemUseLogic implements ISerializable<NbtCompound, JsonObject> { | ||
|
||
private ItemPredicate predicate; | ||
private final List<String> commands; | ||
private CommandExecutionContext context; | ||
|
||
public ItemUseLogic() { | ||
this.commands = new ArrayList<>(); | ||
} | ||
|
||
public ItemUseLogic(String predicate, CommandExecutionContext context, String... commands) { | ||
this.predicate = ItemPredicate.of(predicate, true).orElseThrow(); | ||
this.context = context; | ||
this.commands = new ArrayList<>(Arrays.asList(commands)); | ||
} | ||
|
||
public ItemPredicate getPredicate() { | ||
return this.predicate; | ||
} | ||
|
||
public List<String> getCommands() { | ||
return this.commands; | ||
} | ||
|
||
public CommandExecutionContext getContext() { | ||
return this.context; | ||
} | ||
|
||
@Override | ||
public Optional<JsonObject> writeJson() { | ||
return Optional.of(new JsonObject()).map(json -> { | ||
Adapters.ITEM_PREDICATE.writeJson(this.predicate).ifPresent(tag -> json.add("predicate", tag)); | ||
|
||
JsonArray commands = new JsonArray(); | ||
this.commands.forEach(command -> Adapters.UTF_8.writeJson(command).ifPresent(commands::add)); | ||
json.add("commands", commands); | ||
Adapters.ofEnum(CommandExecutionContext.class, NAME).writeJson(this.context) | ||
.ifPresent(tag -> json.add("context", tag)); | ||
return json; | ||
}); | ||
} | ||
|
||
@Override | ||
public void readJson(JsonObject json) { | ||
this.predicate = Adapters.ITEM_PREDICATE.readJson(json.get("predicate")).orElse(ItemPredicate.FALSE); | ||
this.commands.clear(); | ||
|
||
if(json.get("commands") instanceof JsonArray array) { | ||
for(JsonElement element : array) { | ||
Adapters.UTF_8.readJson(element).ifPresent(this.commands::add); | ||
} | ||
} | ||
|
||
this.context = Adapters.ofEnum(CommandExecutionContext.class, NAME).readJson(json.get("context")).orElse(CommandExecutionContext.SERVER); | ||
} | ||
|
||
public enum CommandExecutionContext { | ||
PLAYER, SERVER | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
common/src/main/resources/assets/academy/models/item/ha_fossil.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"parent": "minecraft:item/generated", | ||
"textures": { | ||
"layer0": "academy:item/ha_fossil" | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
common/src/main/resources/assets/academy/models/item/max_iv_fossil.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"parent": "minecraft:item/generated", | ||
"textures": { | ||
"layer0": "academy:item/max_iv_fossil" | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
common/src/main/resources/assets/academy/models/item/shiny_fossil.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"parent": "minecraft:item/generated", | ||
"textures": { | ||
"layer0": "academy:item/shiny_fossil" | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
common/src/main/resources/assets/academy/models/item/shiny_incense.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"parent": "minecraft:item/generated", | ||
"textures": { | ||
"layer0": "academy:item/shiny_incense" | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
common/src/main/resources/assets/academy/models/item/strong_shiny_incense.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"parent": "minecraft:item/generated", | ||
"textures": { | ||
"layer0": "academy:item/strong_shiny_incense" | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
common/src/main/resources/assets/academy/models/item/uber_shiny_incense.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"parent": "minecraft:item/generated", | ||
"textures": { | ||
"layer0": "academy:item/uber_shiny_incense" | ||
} | ||
} |
Binary file added
BIN
+268 Bytes
common/src/main/resources/assets/academy/textures/item/ha_fossil.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+268 Bytes
common/src/main/resources/assets/academy/textures/item/max_iv_fossil.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+428 Bytes
common/src/main/resources/assets/academy/textures/item/shiny_fossil.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+284 Bytes
common/src/main/resources/assets/academy/textures/item/shiny_incense.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+358 Bytes
common/src/main/resources/assets/academy/textures/item/strong_shiny_incense.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+326 Bytes
common/src/main/resources/assets/academy/textures/item/uber_shiny_incense.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.