Skip to content

Commit 28bf1ca

Browse files
committed
fix compat items, rework garoyle particles and scare mechanic
1 parent eddb72c commit 28bf1ca

File tree

7 files changed

+114
-23
lines changed

7 files changed

+114
-23
lines changed

src/main/java/galena/oreganized/Oreganized.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ public Oreganized() {
161161

162162
private void injectVillagerTrades(VillagerTradesEvent event) {
163163
if (event.getType() == VillagerProfession.MASON) {
164-
event.getTrades().get(5).add(new BasicItemListing(14, ItemStack.EMPTY, 5, 1));
164+
event.getTrades().get(5).add(new BasicItemListing(14, new ItemStack(OBlocks.GARGOYLE.get()), 5, 1));
165165
}
166166
}
167167

@@ -304,6 +304,7 @@ public void buildCreativeModeTabContents(BuildCreativeModeTabContentsEvent event
304304
putAfter(entries, OBlocks.CUT_LEAD.get(), OBlocks.LEAD_BRICKS);
305305
putAfter(entries, OBlocks.LEAD_PILLAR.get(), OBlocks.CUT_LEAD);
306306
putAfter(entries, OBlocks.LEAD_BRICKS.get(), OBlocks.LEAD_PILLAR);
307+
putAfter(entries, Blocks.IRON_BARS, OBlocks.LEAD_BARS);
307308
}
308309
if (tab == CreativeModeTabs.FUNCTIONAL_BLOCKS) {
309310
putBefore(entries, Blocks.CHEST, OBlocks.LEAD_BOLT_CRATE);
@@ -357,7 +358,6 @@ public void buildCreativeModeTabContents(BuildCreativeModeTabContentsEvent event
357358
putAfter(entries, Blocks.REDSTONE_LAMP, OBlocks.LEAD_BULB);
358359
putAfter(entries, Blocks.IRON_DOOR, OBlocks.LEAD_DOOR);
359360
putAfter(entries, Blocks.IRON_TRAPDOOR, OBlocks.LEAD_TRAPDOOR);
360-
putAfter(entries, Blocks.IRON_BARS, OBlocks.LEAD_BARS);
361361
}
362362
if (tab == CreativeModeTabs.TOOLS_AND_UTILITIES) {
363363
putBefore(entries, Items.NETHERITE_SHOVEL, OItems.ELECTRUM_SHOVEL);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package galena.oreganized.compat.farmers_delight;
2+
3+
import galena.oreganized.index.OItemTiers;
4+
import net.minecraft.world.item.Item;
5+
import vectorwing.farmersdelight.common.item.KnifeItem;
6+
7+
import java.util.function.Function;
8+
9+
public class FarmersDelightCompat {
10+
11+
public static final Function<Item.Properties, ? extends Item> KNIFE_FACTORY = (it) ->
12+
new KnifeItem(OItemTiers.ELECTRUM, 0.5F, -1.8F, it);
13+
14+
}

src/main/java/galena/oreganized/content/block/GargoyleBlock.java

+5-10
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import net.minecraft.core.BlockPos;
66
import net.minecraft.core.Direction;
77
import net.minecraft.core.dispenser.DispenseItemBehavior;
8-
import net.minecraft.core.particles.ParticleTypes;
8+
import net.minecraft.core.particles.ParticleOptions;
99
import net.minecraft.util.RandomSource;
1010
import net.minecraft.util.StringRepresentable;
1111
import net.minecraft.world.InteractionHand;
@@ -113,15 +113,10 @@ public InteractionResult use(BlockState state, Level level, BlockPos pos, Player
113113
return super.use(state, level, pos, player, hand, hit);
114114
}
115115

116-
@Override
117-
public void animateTick(BlockState state, Level level, BlockPos pos, RandomSource random) {
118-
super.animateTick(state, level, pos, random);
119-
120-
if (random.nextBoolean() && level.isRainingAt(pos.above())) {
121-
double spread = random.nextDouble() * 0.1 - 0.05;
122-
var offset = AttachmentType.offset(state, pos, spread);
123-
level.addParticle(ParticleTypes.DRIPPING_DRIPSTONE_WATER, offset.x, offset.y, offset.z, 0.0, 0.0, 0.0);
124-
}
116+
public static void dripParticles(BlockState state, Level level, BlockPos pos, RandomSource random, ParticleOptions type) {
117+
double spread = random.nextDouble() * 0.1 - 0.05;
118+
var offset = AttachmentType.offset(state, pos, spread);
119+
level.addParticle(type, offset.x, offset.y, offset.z, 0.0, 0.0, 0.0);
125120
}
126121

127122
@Nullable

src/main/java/galena/oreganized/content/effect/StunningEffect.java

+14
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
package galena.oreganized.content.effect;
22

3+
<<<<<<< Updated upstream
34
import galena.oreganized.index.OEffects;
45
import net.minecraft.client.player.Input;
56
import net.minecraft.world.effect.MobEffect;
67
import net.minecraft.world.effect.MobEffectCategory;
8+
=======
9+
import galena.oreganized.Oreganized;
10+
import net.minecraft.world.effect.MobEffect;
11+
import net.minecraft.world.effect.MobEffectCategory;
12+
import net.minecraft.world.effect.MobEffectInstance;
13+
>>>>>>> Stashed changes
714
import net.minecraft.world.entity.LivingEntity;
815
import net.minecraft.world.entity.player.Player;
916
import net.minecraftforge.api.distmarker.Dist;
@@ -12,8 +19,11 @@
1219
import net.minecraftforge.eventbus.api.SubscribeEvent;
1320
import net.minecraftforge.fml.common.Mod;
1421
import org.jetbrains.annotations.NotNull;
22+
<<<<<<< Updated upstream
1523

1624
import galena.oreganized.Oreganized;
25+
=======
26+
>>>>>>> Stashed changes
1727

1828
@Mod.EventBusSubscriber(modid = Oreganized.MOD_ID, value = Dist.CLIENT)
1929
public class StunningEffect extends MobEffect {
@@ -22,6 +32,10 @@ public class StunningEffect extends MobEffect {
2232
public static int coolDown = 0;
2333
public StunningEffect() {
2434
super(MobEffectCategory.HARMFUL, 0x3B3B63);
35+
<<<<<<< Updated upstream
36+
=======
37+
addAttributeModifier(Attributes.MOVEMENT_SPEED, SLOWNESS_UUID, -0.075, AttributeModifier.Operation.MULTIPLY_TOTAL);
38+
>>>>>>> Stashed changes
2539
}
2640

2741
@Override

src/main/java/galena/oreganized/content/entity/GargoyleBlockEntity.java

+49-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package galena.oreganized.content.entity;
22

3+
import galena.oreganized.Oreganized;
34
import galena.oreganized.content.block.GargoyleBlock;
45
import galena.oreganized.index.OBlockEntities;
56
import galena.oreganized.index.OParticleTypes;
@@ -9,34 +10,43 @@
910
import galena.oreganized.network.packet.GargoyleParticlePacket;
1011
import galena.oreganized.world.ScaredOfGargoyleGoal;
1112
import net.minecraft.core.BlockPos;
13+
import net.minecraft.core.particles.ParticleOptions;
14+
import net.minecraft.core.particles.ParticleTypes;
1215
import net.minecraft.nbt.CompoundTag;
1316
import net.minecraft.nbt.NbtUtils;
1417
import net.minecraft.sounds.SoundSource;
1518
import net.minecraft.util.ParticleUtils;
1619
import net.minecraft.util.valueproviders.UniformInt;
1720
import net.minecraft.world.InteractionResult;
21+
import net.minecraft.world.entity.Entity;
22+
import net.minecraft.world.entity.LivingEntity;
1823
import net.minecraft.world.entity.Mob;
1924
import net.minecraft.world.entity.MobType;
2025
import net.minecraft.world.entity.player.Player;
2126
import net.minecraft.world.item.ItemStack;
2227
import net.minecraft.world.level.Level;
28+
import net.minecraft.world.level.block.Block;
2329
import net.minecraft.world.level.block.entity.BlockEntity;
2430
import net.minecraft.world.level.block.state.BlockState;
2531
import net.minecraft.world.phys.AABB;
2632
import net.minecraft.world.phys.Vec3;
2733
import net.minecraftforge.network.PacketDistributor;
34+
import org.checkerframework.checker.units.qual.C;
2835
import org.jetbrains.annotations.Nullable;
2936

3037
import java.util.Collection;
3138

3239
public class GargoyleBlockEntity extends BlockEntity {
3340

3441
private static final int COOLDOWN = 20 * 30;
42+
public static final String GROWL_COOLDOWN_TAG = Oreganized.MOD_ID + ":gargoyle_use_cooldown";
3543

3644
private int outputSignal = 0;
3745
private int updateCooldown = 0;
3846
private int growlCooldown = 0;
3947

48+
private ParticleOptions drippingFluid;
49+
4050
public GargoyleBlockEntity(BlockPos pos, BlockState state) {
4151
super(OBlockEntities.GARGOYLE.get(), pos, state);
4252
}
@@ -48,8 +58,15 @@ private static Collection<Mob> getTargets(Level level, BlockPos pos) {
4858

4959
public static void tick(Level level, BlockPos pos, BlockState state, GargoyleBlockEntity be) {
5060
be.growlCooldown--;
61+
62+
if (be.updateCooldown % 2 == 0 && be.drippingFluid != null) {
63+
GargoyleBlock.dripParticles(state, level, pos, level.random, be.drippingFluid);
64+
}
65+
5166
if (--be.updateCooldown > 0) return;
5267

68+
be.updateDripParticles(level, pos, state);
69+
5370
var targets = getTargets(level, pos);
5471
var vec = Vec3.atCenterOf(pos);
5572
var closestDistance = targets.stream()
@@ -70,6 +87,24 @@ public static void tick(Level level, BlockPos pos, BlockState state, GargoyleBlo
7087
be.updateCooldown = 10;
7188
}
7289

90+
private void updateDripParticles(Level level, BlockPos pos, BlockState state) {
91+
for (int i = 1; i <= 2; i++) {
92+
var targetPos = pos.below(i);
93+
var targetState = level.getBlockState(targetPos);
94+
var fluid = targetState.getFluidState();
95+
if (!fluid.isEmpty()) {
96+
drippingFluid = fluid.getDripParticle();
97+
return;
98+
}
99+
}
100+
101+
if (level.isRainingAt(pos.above())) {
102+
drippingFluid = ParticleTypes.DRIPPING_DRIPSTONE_WATER;
103+
} else {
104+
drippingFluid = null;
105+
}
106+
}
107+
73108
public int getAnalogOutputSignal() {
74109
return outputSignal;
75110
}
@@ -88,6 +123,7 @@ public void load(CompoundTag tag) {
88123

89124
public InteractionResult interact(Level level, BlockPos pos, @Nullable Player player, ItemStack stack, boolean simulate) {
90125
if (growlCooldown > 0) return InteractionResult.PASS;
126+
if (player != null && player.getPersistentData().getInt(GROWL_COOLDOWN_TAG) > 0) return InteractionResult.PASS;
91127
if (!stack.is(OTags.Items.GARGOYLE_SNACK)) return InteractionResult.PASS;
92128

93129
if (player == null || !player.getAbilities().instabuild) {
@@ -96,13 +132,14 @@ public InteractionResult interact(Level level, BlockPos pos, @Nullable Player pl
96132

97133
if (simulate) return InteractionResult.SUCCESS;
98134

99-
getTargets(level, pos).forEach(mob -> {
100-
mob.getPersistentData().put(ScaredOfGargoyleGoal.AVOID_TAG_KEY, NbtUtils.writeBlockPos(pos));
101-
});
135+
getTargets(level, pos).forEach(mob -> scare(mob, pos));
102136

103137
level.playSound(null, pos.getX(), pos.getY(), pos.getZ(), OSoundEvents.GARGOYLE_GROWL.get(), SoundSource.BLOCKS, 1.0F, 1.0F);
104138

105139
growlCooldown = COOLDOWN;
140+
if (player != null && !player.getAbilities().instabuild) {
141+
player.getPersistentData().putInt(GROWL_COOLDOWN_TAG, COOLDOWN);
142+
}
106143

107144
if (!level.isClientSide) {
108145
OreganizedNetwork.CHANNEL.send(PacketDistributor.DIMENSION.with(level::dimension), new GargoyleParticlePacket(pos));
@@ -111,6 +148,15 @@ public InteractionResult interact(Level level, BlockPos pos, @Nullable Player pl
111148
return InteractionResult.SUCCESS;
112149
}
113150

151+
private void scare(Entity mob, BlockPos pos) {
152+
var offset = mob.position().subtract(pos.getX(), pos.getY(), pos.getZ());
153+
if (offset.length() < 4) {
154+
var motion = offset.multiply(0.4, 0.2, 0.4);
155+
mob.push(motion.x, motion.y, motion.z);
156+
}
157+
mob.getPersistentData().put(ScaredOfGargoyleGoal.AVOID_TAG_KEY, NbtUtils.writeBlockPos(pos));
158+
}
159+
114160
public void spawnParticles() {
115161
var pos = getBlockPos();
116162
var state = getBlockState();

src/main/java/galena/oreganized/index/OItems.java

+7-5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.teamabnormals.blueprint.common.item.BlueprintRecordItem;
44
import com.teamabnormals.blueprint.core.util.registry.ItemSubRegistryHelper;
55
import galena.oreganized.Oreganized;
6+
import galena.oreganized.compat.farmers_delight.FarmersDelightCompat;
67
import galena.oreganized.content.item.BushHammerItem;
78
import galena.oreganized.content.item.ElectrumArmorItem;
89
import galena.oreganized.content.item.LeadBoltItem;
@@ -26,19 +27,20 @@
2627
import net.minecraftforge.fml.ModList;
2728
import net.minecraftforge.fml.common.Mod;
2829
import net.minecraftforge.registries.RegistryObject;
29-
import vectorwing.farmersdelight.common.item.KnifeItem;
3030

31+
import java.util.function.Function;
3132
import java.util.function.Supplier;
3233

3334
import static galena.oreganized.ModCompat.FARMERS_DELIGHT_ID;
3435

36+
@SuppressWarnings("Convert2MethodRef")
3537
@Mod.EventBusSubscriber(modid = Oreganized.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD)
3638
public class OItems {
3739
public static final ItemSubRegistryHelper HELPER = Oreganized.REGISTRY_HELPER.getItemSubHelper();
3840

39-
public static Supplier<? extends Item> compat(String modid, Supplier<? extends Item> supplier) {
40-
if (ModList.get().isLoaded(modid)) return supplier;
41-
return () -> new Item(new Item.Properties());
41+
public static Supplier<? extends Item> compat(String modid, Function<Item.Properties, ? extends Item> supplier, Item.Properties properties) {
42+
if (ModList.get().isLoaded(modid)) return () -> supplier.apply(properties);
43+
return () -> new Item(properties);
4244
}
4345

4446
// Discs
@@ -67,7 +69,7 @@ public static Supplier<? extends Item> compat(String modid, Supplier<? extends I
6769
public static final RegistryObject<Item> ELECTRUM_AXE = HELPER.createItem("electrum_axe", () -> new AxeItem(OItemTiers.ELECTRUM, 6.0F, -2.8F, (new Item.Properties())));
6870
public static final RegistryObject<Item> ELECTRUM_HOE = HELPER.createItem("electrum_hoe", () -> new HoeItem(OItemTiers.ELECTRUM, 0, -2.8F, (new Item.Properties())));
6971

70-
public static final RegistryObject<Item> ELECTRUM_KNIFE = HELPER.createItem("electrum_knife", compat(FARMERS_DELIGHT_ID, () -> new KnifeItem(OItemTiers.ELECTRUM, 0.5F, -1.8F, (new Item.Properties()))));
72+
public static final RegistryObject<Item> ELECTRUM_KNIFE = HELPER.createItem("electrum_knife", compat(FARMERS_DELIGHT_ID, it -> FarmersDelightCompat.KNIFE_FACTORY.apply(it), new Item.Properties()));
7173
public static final RegistryObject<Item> ELECTRUM_SHIELD = HELPER.createItem("electrum_shield", () -> new ShieldItem(new Item.Properties().durability(363)));
7274
public static final RegistryObject<Item> ELECTRUM_MACHETE = HELPER.createItem("electrum_machete", () -> new SwordItem(OItemTiers.ELECTRUM, 2, -2.4F, new Item.Properties()));
7375

src/main/java/galena/oreganized/world/event/PlayerEvents.java

+23-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import galena.oreganized.Oreganized;
44
import galena.oreganized.OreganizedConfig;
55
import galena.oreganized.content.block.MoltenLeadCauldronBlock;
6+
import galena.oreganized.content.entity.GargoyleBlockEntity;
67
import galena.oreganized.index.*;
78
import net.minecraft.advancements.CriteriaTriggers;
89
import net.minecraft.client.player.inventory.Hotbar;
@@ -24,8 +25,10 @@
2425
import net.minecraft.world.level.block.state.BlockState;
2526
import net.minecraftforge.common.ToolAction;
2627
import net.minecraftforge.common.ToolActions;
28+
import net.minecraftforge.event.TickEvent;
2729
import net.minecraftforge.event.entity.item.ItemEvent;
2830
import net.minecraftforge.event.entity.living.LivingEntityUseItemEvent;
31+
import net.minecraftforge.event.entity.player.PlayerEvent;
2932
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
3033
import net.minecraftforge.event.level.BlockEvent;
3134
import net.minecraftforge.eventbus.api.SubscribeEvent;
@@ -51,7 +54,7 @@ public static void blockToolInteractions(final BlockEvent.BlockToolModificationE
5154
}
5255

5356
/**
54-
*Use if interaction is not defined in {@link ToolActions}
57+
* Use if interaction is not defined in {@link ToolActions}
5558
**/
5659
@SubscribeEvent
5760
public static void blockItemInteractions(final PlayerInteractEvent.RightClickBlock event) {
@@ -65,7 +68,8 @@ public static void blockItemInteractions(final PlayerInteractEvent.RightClickBlo
6568
// Waxing (Using Honeycomb on a waxable block).
6669
if (itemStack.is(Items.HONEYCOMB) && OBlocks.WAXED_BLOCKS.inverse().get(state.getBlock()) != null) {
6770

68-
if (player instanceof ServerPlayer) CriteriaTriggers.ITEM_USED_ON_BLOCK.trigger((ServerPlayer) player, pos, itemStack);
71+
if (player instanceof ServerPlayer)
72+
CriteriaTriggers.ITEM_USED_ON_BLOCK.trigger((ServerPlayer) player, pos, itemStack);
6973

7074
player.swing(event.getHand());
7175
if (!player.isCreative()) event.getItemStack().shrink(1);
@@ -107,9 +111,25 @@ public static void finishUsingItem(final LivingEntityUseItemEvent.Finish event)
107111
}
108112
}
109113
if ((entity.getOffhandItem().is(OTags.Items.LEAD_SOURCE) || leadPoisoning) && OreganizedConfig.COMMON.leadPoisining.get()) {
110-
if (OreganizedConfig.stunningFromConfig()) entity.addEffect(new MobEffectInstance(OEffects.STUNNING.get(), 40 * 20));
114+
if (OreganizedConfig.stunningFromConfig())
115+
entity.addEffect(new MobEffectInstance(OEffects.STUNNING.get(), 40 * 20));
111116
entity.addEffect(new MobEffectInstance(MobEffects.POISON, 200));
112117
}
113118
}
114119
}
120+
121+
@SubscribeEvent
122+
public static void tickPlayer(final TickEvent.PlayerTickEvent event) {
123+
if (event.phase == TickEvent.Phase.START) return;
124+
125+
var data = event.player.getPersistentData();
126+
if (data.contains(GargoyleBlockEntity.GROWL_COOLDOWN_TAG, 99)) {
127+
var cooldown = data.getInt(GargoyleBlockEntity.GROWL_COOLDOWN_TAG);
128+
if (cooldown > 0) {
129+
data.putInt(GargoyleBlockEntity.GROWL_COOLDOWN_TAG, cooldown - 1);
130+
} else {
131+
data.remove(GargoyleBlockEntity.GROWL_COOLDOWN_TAG);
132+
}
133+
}
134+
}
115135
}

0 commit comments

Comments
 (0)