Skip to content

Commit

Permalink
Merge branch '1.20.x' into rework/stunning-effect
Browse files Browse the repository at this point in the history
  • Loading branch information
PssbleTrngle committed Sep 5, 2024
2 parents a5b2668 + 353e191 commit e21e10d
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 23 deletions.
4 changes: 2 additions & 2 deletions src/main/java/galena/oreganized/Oreganized.java
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public Oreganized() {

private void injectVillagerTrades(VillagerTradesEvent event) {
if (event.getType() == VillagerProfession.MASON) {
event.getTrades().get(5).add(new BasicItemListing(14, ItemStack.EMPTY, 5, 1));
event.getTrades().get(5).add(new BasicItemListing(14, new ItemStack(OBlocks.GARGOYLE.get()), 5, 1));
}
}

Expand Down Expand Up @@ -304,6 +304,7 @@ public void buildCreativeModeTabContents(BuildCreativeModeTabContentsEvent event
putAfter(entries, OBlocks.CUT_LEAD.get(), OBlocks.LEAD_BRICKS);
putAfter(entries, OBlocks.LEAD_PILLAR.get(), OBlocks.CUT_LEAD);
putAfter(entries, OBlocks.LEAD_BRICKS.get(), OBlocks.LEAD_PILLAR);
putAfter(entries, Blocks.IRON_BARS, OBlocks.LEAD_BARS);
}
if (tab == CreativeModeTabs.FUNCTIONAL_BLOCKS) {
putBefore(entries, Blocks.CHEST, OBlocks.LEAD_BOLT_CRATE);
Expand Down Expand Up @@ -357,7 +358,6 @@ public void buildCreativeModeTabContents(BuildCreativeModeTabContentsEvent event
putAfter(entries, Blocks.REDSTONE_LAMP, OBlocks.LEAD_BULB);
putAfter(entries, Blocks.IRON_DOOR, OBlocks.LEAD_DOOR);
putAfter(entries, Blocks.IRON_TRAPDOOR, OBlocks.LEAD_TRAPDOOR);
putAfter(entries, Blocks.IRON_BARS, OBlocks.LEAD_BARS);
}
if (tab == CreativeModeTabs.TOOLS_AND_UTILITIES) {
putBefore(entries, Items.NETHERITE_SHOVEL, OItems.ELECTRUM_SHOVEL);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package galena.oreganized.compat.farmers_delight;

import galena.oreganized.index.OItemTiers;
import net.minecraft.world.item.Item;
import vectorwing.farmersdelight.common.item.KnifeItem;

import java.util.function.Function;

public class FarmersDelightCompat {

public static final Function<Item.Properties, ? extends Item> KNIFE_FACTORY = (it) ->
new KnifeItem(OItemTiers.ELECTRUM, 0.5F, -1.8F, it);

}
15 changes: 5 additions & 10 deletions src/main/java/galena/oreganized/content/block/GargoyleBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.dispenser.DispenseItemBehavior;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.core.particles.ParticleOptions;
import net.minecraft.util.RandomSource;
import net.minecraft.util.StringRepresentable;
import net.minecraft.world.InteractionHand;
Expand Down Expand Up @@ -113,15 +113,10 @@ public InteractionResult use(BlockState state, Level level, BlockPos pos, Player
return super.use(state, level, pos, player, hand, hit);
}

@Override
public void animateTick(BlockState state, Level level, BlockPos pos, RandomSource random) {
super.animateTick(state, level, pos, random);

if (random.nextBoolean() && level.isRainingAt(pos.above())) {
double spread = random.nextDouble() * 0.1 - 0.05;
var offset = AttachmentType.offset(state, pos, spread);
level.addParticle(ParticleTypes.DRIPPING_DRIPSTONE_WATER, offset.x, offset.y, offset.z, 0.0, 0.0, 0.0);
}
public static void dripParticles(BlockState state, Level level, BlockPos pos, RandomSource random, ParticleOptions type) {
double spread = random.nextDouble() * 0.1 - 0.05;
var offset = AttachmentType.offset(state, pos, spread);
level.addParticle(type, offset.x, offset.y, offset.z, 0.0, 0.0, 0.0);
}

@Nullable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package galena.oreganized.content.entity;

import galena.oreganized.Oreganized;
import galena.oreganized.content.block.GargoyleBlock;
import galena.oreganized.index.OBlockEntities;
import galena.oreganized.index.OParticleTypes;
Expand All @@ -9,34 +10,43 @@
import galena.oreganized.network.packet.GargoyleParticlePacket;
import galena.oreganized.world.ScaredOfGargoyleGoal;
import net.minecraft.core.BlockPos;
import net.minecraft.core.particles.ParticleOptions;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtUtils;
import net.minecraft.sounds.SoundSource;
import net.minecraft.util.ParticleUtils;
import net.minecraft.util.valueproviders.UniformInt;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.entity.MobType;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.network.PacketDistributor;
import org.checkerframework.checker.units.qual.C;
import org.jetbrains.annotations.Nullable;

import java.util.Collection;

public class GargoyleBlockEntity extends BlockEntity {

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

private int outputSignal = 0;
private int updateCooldown = 0;
private int growlCooldown = 0;

private ParticleOptions drippingFluid;

public GargoyleBlockEntity(BlockPos pos, BlockState state) {
super(OBlockEntities.GARGOYLE.get(), pos, state);
}
Expand All @@ -48,8 +58,15 @@ private static Collection<Mob> getTargets(Level level, BlockPos pos) {

public static void tick(Level level, BlockPos pos, BlockState state, GargoyleBlockEntity be) {
be.growlCooldown--;

if (be.updateCooldown % 2 == 0 && be.drippingFluid != null) {
GargoyleBlock.dripParticles(state, level, pos, level.random, be.drippingFluid);
}

if (--be.updateCooldown > 0) return;

be.updateDripParticles(level, pos, state);

var targets = getTargets(level, pos);
var vec = Vec3.atCenterOf(pos);
var closestDistance = targets.stream()
Expand All @@ -70,6 +87,24 @@ public static void tick(Level level, BlockPos pos, BlockState state, GargoyleBlo
be.updateCooldown = 10;
}

private void updateDripParticles(Level level, BlockPos pos, BlockState state) {
for (int i = 1; i <= 2; i++) {
var targetPos = pos.below(i);
var targetState = level.getBlockState(targetPos);
var fluid = targetState.getFluidState();
if (!fluid.isEmpty()) {
drippingFluid = fluid.getDripParticle();
return;
}
}

if (level.isRainingAt(pos.above())) {
drippingFluid = ParticleTypes.DRIPPING_DRIPSTONE_WATER;
} else {
drippingFluid = null;
}
}

public int getAnalogOutputSignal() {
return outputSignal;
}
Expand All @@ -88,6 +123,7 @@ public void load(CompoundTag tag) {

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

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

if (simulate) return InteractionResult.SUCCESS;

getTargets(level, pos).forEach(mob -> {
mob.getPersistentData().put(ScaredOfGargoyleGoal.AVOID_TAG_KEY, NbtUtils.writeBlockPos(pos));
});
getTargets(level, pos).forEach(mob -> scare(mob, pos));

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

growlCooldown = COOLDOWN;
if (player != null && !player.getAbilities().instabuild) {
player.getPersistentData().putInt(GROWL_COOLDOWN_TAG, COOLDOWN);
}

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

private void scare(Entity mob, BlockPos pos) {
var offset = mob.position().subtract(pos.getX(), pos.getY(), pos.getZ());
if (offset.length() < 4) {
var motion = offset.multiply(0.4, 0.2, 0.4);
mob.push(motion.x, motion.y, motion.z);
}
mob.getPersistentData().put(ScaredOfGargoyleGoal.AVOID_TAG_KEY, NbtUtils.writeBlockPos(pos));
}

public void spawnParticles() {
var pos = getBlockPos();
var state = getBlockState();
Expand Down
12 changes: 7 additions & 5 deletions src/main/java/galena/oreganized/index/OItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.teamabnormals.blueprint.common.item.BlueprintRecordItem;
import com.teamabnormals.blueprint.core.util.registry.ItemSubRegistryHelper;
import galena.oreganized.Oreganized;
import galena.oreganized.compat.farmers_delight.FarmersDelightCompat;
import galena.oreganized.content.item.BushHammerItem;
import galena.oreganized.content.item.ElectrumArmorItem;
import galena.oreganized.content.item.LeadBoltItem;
Expand All @@ -26,19 +27,20 @@
import net.minecraftforge.fml.ModList;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.registries.RegistryObject;
import vectorwing.farmersdelight.common.item.KnifeItem;

import java.util.function.Function;
import java.util.function.Supplier;

import static galena.oreganized.ModCompat.FARMERS_DELIGHT_ID;

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

public static Supplier<? extends Item> compat(String modid, Supplier<? extends Item> supplier) {
if (ModList.get().isLoaded(modid)) return supplier;
return () -> new Item(new Item.Properties());
public static Supplier<? extends Item> compat(String modid, Function<Item.Properties, ? extends Item> supplier, Item.Properties properties) {
if (ModList.get().isLoaded(modid)) return () -> supplier.apply(properties);
return () -> new Item(properties);
}

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

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()))));
public static final RegistryObject<Item> ELECTRUM_KNIFE = HELPER.createItem("electrum_knife", compat(FARMERS_DELIGHT_ID, it -> FarmersDelightCompat.KNIFE_FACTORY.apply(it), new Item.Properties()));
public static final RegistryObject<Item> ELECTRUM_SHIELD = HELPER.createItem("electrum_shield", () -> new ShieldItem(new Item.Properties().durability(363)));
public static final RegistryObject<Item> ELECTRUM_MACHETE = HELPER.createItem("electrum_machete", () -> new SwordItem(OItemTiers.ELECTRUM, 2, -2.4F, new Item.Properties()));

Expand Down
26 changes: 23 additions & 3 deletions src/main/java/galena/oreganized/world/event/PlayerEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import galena.oreganized.Oreganized;
import galena.oreganized.OreganizedConfig;
import galena.oreganized.content.block.MoltenLeadCauldronBlock;
import galena.oreganized.content.entity.GargoyleBlockEntity;
import galena.oreganized.index.*;
import net.minecraft.advancements.CriteriaTriggers;
import net.minecraft.client.player.inventory.Hotbar;
Expand All @@ -24,8 +25,10 @@
import net.minecraft.world.level.block.state.BlockState;
import net.minecraftforge.common.ToolAction;
import net.minecraftforge.common.ToolActions;
import net.minecraftforge.event.TickEvent;
import net.minecraftforge.event.entity.item.ItemEvent;
import net.minecraftforge.event.entity.living.LivingEntityUseItemEvent;
import net.minecraftforge.event.entity.player.PlayerEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.event.level.BlockEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
Expand All @@ -51,7 +54,7 @@ public static void blockToolInteractions(final BlockEvent.BlockToolModificationE
}

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

if (player instanceof ServerPlayer) CriteriaTriggers.ITEM_USED_ON_BLOCK.trigger((ServerPlayer) player, pos, itemStack);
if (player instanceof ServerPlayer)
CriteriaTriggers.ITEM_USED_ON_BLOCK.trigger((ServerPlayer) player, pos, itemStack);

player.swing(event.getHand());
if (!player.isCreative()) event.getItemStack().shrink(1);
Expand Down Expand Up @@ -107,9 +111,25 @@ public static void finishUsingItem(final LivingEntityUseItemEvent.Finish event)
}
}
if ((entity.getOffhandItem().is(OTags.Items.LEAD_SOURCE) || leadPoisoning) && OreganizedConfig.COMMON.leadPoisining.get()) {
if (OreganizedConfig.stunningFromConfig()) entity.addEffect(new MobEffectInstance(OEffects.STUNNING.get(), 40 * 20));
if (OreganizedConfig.stunningFromConfig())
entity.addEffect(new MobEffectInstance(OEffects.STUNNING.get(), 40 * 20));
entity.addEffect(new MobEffectInstance(MobEffects.POISON, 200));
}
}
}

@SubscribeEvent
public static void tickPlayer(final TickEvent.PlayerTickEvent event) {
if (event.phase == TickEvent.Phase.START) return;

var data = event.player.getPersistentData();
if (data.contains(GargoyleBlockEntity.GROWL_COOLDOWN_TAG, 99)) {
var cooldown = data.getInt(GargoyleBlockEntity.GROWL_COOLDOWN_TAG);
if (cooldown > 0) {
data.putInt(GargoyleBlockEntity.GROWL_COOLDOWN_TAG, cooldown - 1);
} else {
data.remove(GargoyleBlockEntity.GROWL_COOLDOWN_TAG);
}
}
}
}

0 comments on commit e21e10d

Please sign in to comment.