Skip to content

Commit

Permalink
backported polishing particles & tooltip
Browse files Browse the repository at this point in the history
  • Loading branch information
Uraneptus committed Sep 30, 2023
1 parent f54e34c commit 277d92a
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 35 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ org.gradle.jvmargs=-Xmx5G
org.gradle.daemon=false

mod_id=sullysmod
mod_version=2.4.1-beta
mod_version=2.4.2-beta

mc_version=1.19.2
forge_version=43.2.0
Expand Down
3 changes: 2 additions & 1 deletion src/generated/resources/assets/sullysmod/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,6 @@
"subtitles.entity.tortoise_shell.place": "Tortoise Shell placed",
"subtitles.entity.zombie.destroy_egg": "Egg stomped",
"sullysmod.jei.grindstone_polishing": "Polishing",
"sullysmod.jei.grindstone_polishing.info": "Right click to polish"
"sullysmod.jei.grindstone_polishing.info": "Right click to polish",
"sullysmod.polishing.tooltip": "Polishable at grindstone"
}
2 changes: 1 addition & 1 deletion src/main/java/com/uraneptus/sullysmod/SullysMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public SullysMod() {
bus.addListener(this::gatherData);

ModLoadingContext.get().registerConfig(ModConfig.Type.SERVER, SMConfig.SERVER);
ModLoadingContext.get().registerConfig(ModConfig.Type.CLIENT, SMConfig.CLIENT);
//ModLoadingContext.get().registerConfig(ModConfig.Type.CLIENT, SMConfig.CLIENT);

REGISTRY_HELPER.register(bus);
SMParticleTypes.PARTICLES.register(bus);
Expand Down
10 changes: 3 additions & 7 deletions src/main/java/com/uraneptus/sullysmod/core/SMConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,16 @@

@Mod.EventBusSubscriber(modid = SullysMod.MOD_ID)
public class SMConfig {
public static final ForgeConfigSpec.ConfigValue<Boolean> PARTICLES_AROUND_GRINDSTONE;
public static final ForgeConfigSpec.ConfigValue<Boolean> ENABLE_DYNAMIC_VELOCITY;

public static final ForgeConfigSpec SERVER;
public static final ForgeConfigSpec CLIENT;
//public static final ForgeConfigSpec CLIENT;

static {
ForgeConfigSpec.Builder SERVER_BULDER = new ForgeConfigSpec.Builder();
ForgeConfigSpec.Builder CLIENT_BUILDER = new ForgeConfigSpec.Builder();
//ForgeConfigSpec.Builder CLIENT_BUILDER = new ForgeConfigSpec.Builder();

//Client
CLIENT_BUILDER.comment("Particles").push("particles");
PARTICLES_AROUND_GRINDSTONE = CLIENT_BUILDER.comment("If Particles spawn around the grindstone, while the Player is holding an Item that can be polished. (default = true)").define("Particles around Grindstone", true);
CLIENT_BUILDER.pop();

//Server
SERVER_BULDER.comment("Blocks").push("blocks");
Expand All @@ -29,6 +25,6 @@ public class SMConfig {
SERVER_BULDER.pop();

SERVER = SERVER_BULDER.build();
CLIENT = CLIENT_BUILDER.build();
//CLIENT = CLIENT_BUILDER.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ protected void addTranslations() {
add("sullysmod.jei.grindstone_polishing", "Polishing");
add("sullysmod.jei.grindstone_polishing.info", "Right click to polish");

//Other
add("sullysmod.polishing.tooltip", "Polishable at grindstone");

}

public void addMusicDisc(Supplier<? extends Item> item, String description) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,15 @@
import com.uraneptus.sullysmod.core.registry.SMItems;
import com.uraneptus.sullysmod.core.registry.SMSounds;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.particles.DustParticleOptions;
import net.minecraft.core.particles.ItemParticleOption;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.Style;
import net.minecraft.network.chat.TextColor;
import net.minecraft.sounds.SoundSource;
import net.minecraft.util.Mth;
import net.minecraft.util.ParticleUtils;
import net.minecraft.util.RandomSource;
import net.minecraft.util.valueproviders.UniformInt;
Expand Down Expand Up @@ -40,6 +47,7 @@ public static void onRightClickBlock(PlayerInteractEvent.RightClickBlock event)
InteractionHand hand = event.getHand();
Block block = level.getBlockState(pos).getBlock();
RandomSource random = level.getRandom();
Direction face = event.getFace();

if (block instanceof GrindstoneBlock) {
ArrayList<GrindstonePolishingRecipe> recipes = new ArrayList<>(GrindstonePolishingRecipe.getRecipes(level));
Expand Down Expand Up @@ -89,43 +97,32 @@ public static void onRightClickBlock(PlayerInteractEvent.RightClickBlock event)
}
}
player.swing(hand);
ParticleUtils.spawnParticlesOnBlockFace(level, pos, ParticleTypes.CRIT, UniformInt.of(1, 4), event.getFace(), () -> new Vec3(player.getLookAngle().x() + Mth.nextDouble(random, -0.5, 0.5), 0.8D, player.getLookAngle().z() + Mth.nextDouble(random, -0.5, 0.5)), 0.55D);
ParticleUtils.spawnParticlesOnBlockFace(level, pos, new ItemParticleOption(ParticleTypes.ITEM, itemInHand), UniformInt.of(1, 2), event.getFace(), () -> new Vec3(Mth.nextDouble(random, -0.05D, 0.05D), 0, Mth.nextDouble(random, -0.05D, 0.05D)), 0.55D);
level.playSound(player, pos, SMSounds.POLISH_JADE.get(), SoundSource.BLOCKS, 0.5F, 0.0F);
}
}
}
}
}

@SubscribeEvent
public static void onPlayerTick(TickEvent.PlayerTickEvent event) {
Player player = event.player;
Level level = player.getLevel();
InteractionHand hand = player.getUsedItemHand();
BlockPos pos = player.blockPosition();
ArrayList<GrindstonePolishingRecipe> recipes = new ArrayList<>(GrindstonePolishingRecipe.getRecipes(level));
if (level.isClientSide()) {
if (SMConfig.PARTICLES_AROUND_GRINDSTONE.get()) {
for (GrindstonePolishingRecipe polishingRecipe : recipes) {
for (ItemStack ingredient : polishingRecipe.getIngredients().iterator().next().getItems()) {
if (player.getItemInHand(hand).is(ingredient.getItem())) {
for(BlockPos blockpos : BlockPos.betweenClosed(pos.offset(-7, -7, -7), pos.offset(7, 7, 7))) {
Block block = level.getBlockState(blockpos).getBlock();
if (block instanceof GrindstoneBlock) {
ParticleUtils.spawnParticlesOnBlockFaces(level, blockpos, new DustParticleOptions(new Vector3f(Vec3.fromRGB24(16777215)), 0.4F), UniformInt.of(0, 1));
}
}
}
}
}
}
}
}

@SubscribeEvent
public static void onItemTooltip(ItemTooltipEvent event) {
Player player = event.getEntity();
ItemStack item = event.getItemStack();
if (item.is(SMItems.JADE_SHIELD.get())) {
item.hideTooltipPart(ItemStack.TooltipPart.MODIFIERS);
}
if (player != null) {
ArrayList<GrindstonePolishingRecipe> recipes = new ArrayList<>(GrindstonePolishingRecipe.getRecipes(player.getLevel()));
for (GrindstonePolishingRecipe polishingRecipe : recipes) {
for (ItemStack itemStack : polishingRecipe.getIngredients().iterator().next().getItems()) {
if (item.is(itemStack.getItem())) {
Style polishingStyle = Style.EMPTY.withColor(TextColor.fromRgb(8355711)).withItalic(true);
event.getToolTip().add(Component.translatable(SullysMod.MOD_ID + ".polishing.tooltip").setStyle(polishingStyle));
}
}
}
}
}
}

0 comments on commit 277d92a

Please sign in to comment.