Skip to content

Commit

Permalink
Merge pull request #4 from cabbagegod/Contains
Browse files Browse the repository at this point in the history
Added ground items contains command
  • Loading branch information
cabbagegod authored Mar 4, 2022
2 parents f620f50 + 955a589 commit 9984494
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.cabbagegod.cabbagescape.commands.Commands;
import com.cabbagegod.cabbagescape.data.DataHandler;
import com.cabbagegod.cabbagescape.data.GroundItemSettings;
import com.cabbagegod.cabbagescape.data.Settings;
import com.google.gson.Gson;
import net.fabricmc.api.ClientModInitializer;
Expand Down Expand Up @@ -106,12 +107,24 @@ private void checkSelectedDropItems(MinecraftClient client){
if(itemStack == null || itemStack.isEmpty() || itemStack.getItem() == Items.AIR)
continue;

//Oh god what have I done

if(settings.groundItemSettings.searchTags.contains(Formatting.strip(itemStack.getName().getString().toLowerCase()))){
client.player.playSound(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, settings.groundItemSettings.volume, 1);
client.player.clientWorld.addParticle(ParticleTypes.ANGRY_VILLAGER, entity.getX() + .5f, entity.getY() + 1, entity.getZ() + 1, 1, 1, 1);
client.player.clientWorld.addParticle(ParticleTypes.ANGRY_VILLAGER, entity.getX() - .5f, entity.getY() + 1, entity.getZ() + 1, 1, 1, 1);
client.player.clientWorld.addParticle(ParticleTypes.ANGRY_VILLAGER, entity.getX() + .5f, entity.getY() + 1, entity.getZ(), 1, 1, 1);
client.player.clientWorld.addParticle(ParticleTypes.ANGRY_VILLAGER, entity.getX() - .5f, entity.getY() + 1, entity.getZ(), 1, 1, 1);
} else {
for(String tag : settings.groundItemSettings.containsTags){
if(Formatting.strip(itemStack.getName().getString().toLowerCase()).contains(tag)){
client.player.playSound(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, settings.groundItemSettings.volume, 1);
client.player.clientWorld.addParticle(ParticleTypes.ANGRY_VILLAGER, entity.getX() + .5f, entity.getY() + 1, entity.getZ() + 1, 1, 1, 1);
client.player.clientWorld.addParticle(ParticleTypes.ANGRY_VILLAGER, entity.getX() - .5f, entity.getY() + 1, entity.getZ() + 1, 1, 1, 1);
client.player.clientWorld.addParticle(ParticleTypes.ANGRY_VILLAGER, entity.getX() + .5f, entity.getY() + 1, entity.getZ(), 1, 1, 1);
client.player.clientWorld.addParticle(ParticleTypes.ANGRY_VILLAGER, entity.getX() - .5f, entity.getY() + 1, entity.getZ(), 1, 1, 1);
}
}
}
}
}
Expand Down
41 changes: 41 additions & 0 deletions src/main/java/com/cabbagegod/cabbagescape/commands/Commands.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,47 @@ public static void register(){

return 1;
})))
.then(ClientCommandManager.literal("contains")
.then(ClientCommandManager.literal("add")
.then(ClientCommandManager.argument("item", ClientMessageArgumentType.message())
.executes(context -> {
Text text = ClientMessageArgumentType.getMessage(context, "item");

if(CabbageScapeClient.settings.groundItemSettings.containsTags.contains(text.getString().toLowerCase())){
MinecraftClient.getInstance().player.sendMessage(new LiteralText("Item " + text.getString() + " was already in your list."), false);
} else {
CabbageScapeClient.settings.groundItemSettings.containsTags.add(text.getString().toLowerCase());
CabbageScapeClient.saveSettings();
MinecraftClient.getInstance().player.sendMessage(new LiteralText("Item " + text.getString() + " has been added to your list."), false);
}
return 1;
})))
.then(ClientCommandManager.literal("remove")
.then(ClientCommandManager.argument("item", ClientMessageArgumentType.message())
.executes(context -> {
Text text = ClientMessageArgumentType.getMessage(context, "item");

if(CabbageScapeClient.settings.groundItemSettings.containsTags.contains(text.getString().toLowerCase())){
CabbageScapeClient.settings.groundItemSettings.containsTags.remove(text.getString().toLowerCase());
CabbageScapeClient.saveSettings();
MinecraftClient.getInstance().player.sendMessage(new LiteralText("Item " + text.getString() + " has been removed from your list."), false);
} else {
MinecraftClient.getInstance().player.sendMessage(new LiteralText("Item " + text.getString() + " was not in your list."), false);
}
return 1;
})))
.then(ClientCommandManager.literal("list")
.executes(context -> {
assert MinecraftClient.getInstance().player != null;
String tagList = "Contains Item List: ";
for(String tag : CabbageScapeClient.settings.groundItemSettings.containsTags){
tagList += tag + ",";
}
tagList = StringUtils.chop(tagList);

MinecraftClient.getInstance().player.sendMessage(new LiteralText(tagList), false);
return 1;
})))
.then(ClientCommandManager.literal("list")
.executes(context -> {
assert MinecraftClient.getInstance().player != null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

public class GroundItemSettings {
public List<String> searchTags = new ArrayList<String>();
public List<String> containsTags = new ArrayList<String>();
public float volume = .05f;

public GroundItemSettings(){
Expand Down

0 comments on commit 9984494

Please sign in to comment.