forked from GL33P-0R4NG3/oreganized
-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
vigil candle support for amendments & effect removal functionality
- Loading branch information
1 parent
b64d606
commit edae490
Showing
20 changed files
with
231 additions
and
33 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
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
5 changes: 5 additions & 0 deletions
5
src/generated/resources/data/minecraft/tags/blocks/candles.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,5 @@ | ||
{ | ||
"values": [ | ||
"#oreganized:vigil_candles" | ||
] | ||
} |
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
21 changes: 21 additions & 0 deletions
21
src/generated/resources/data/oreganized/tags/blocks/vigil_candles.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,21 @@ | ||
{ | ||
"values": [ | ||
"oreganized:vigil_candle", | ||
"oreganized:light_blue_vigil_candle", | ||
"oreganized:blue_vigil_candle", | ||
"oreganized:orange_vigil_candle", | ||
"oreganized:red_vigil_candle", | ||
"oreganized:purple_vigil_candle", | ||
"oreganized:light_gray_vigil_candle", | ||
"oreganized:green_vigil_candle", | ||
"oreganized:gray_vigil_candle", | ||
"oreganized:magenta_vigil_candle", | ||
"oreganized:white_vigil_candle", | ||
"oreganized:yellow_vigil_candle", | ||
"oreganized:black_vigil_candle", | ||
"oreganized:brown_vigil_candle", | ||
"oreganized:lime_vigil_candle", | ||
"oreganized:cyan_vigil_candle", | ||
"oreganized:pink_vigil_candle" | ||
] | ||
} |
5 changes: 5 additions & 0 deletions
5
src/generated/resources/data/oreganized/tags/mob_effect/cleared_by_vigil_candle.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,5 @@ | ||
{ | ||
"values": [ | ||
"minecraft:darkness" | ||
] | ||
} |
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
56 changes: 56 additions & 0 deletions
56
src/main/java/galena/oreganized/compat/supplementaries/AmendmentsCompat.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,56 @@ | ||
package galena.oreganized.compat.supplementaries; | ||
|
||
import net.mehvahdjukaar.amendments.common.tile.WallLanternBlockTile; | ||
import net.minecraft.sounds.SoundEvents; | ||
import net.minecraft.sounds.SoundSource; | ||
import net.minecraft.world.InteractionResult; | ||
import net.minecraft.world.item.Items; | ||
import net.minecraft.world.level.block.CandleBlock; | ||
import net.minecraft.world.level.block.state.properties.BlockStateProperties; | ||
import net.minecraftforge.common.MinecraftForge; | ||
import net.minecraftforge.event.entity.player.PlayerInteractEvent; | ||
|
||
public class AmendmentsCompat { | ||
|
||
public static void register() { | ||
MinecraftForge.EVENT_BUS.addListener(AmendmentsCompat::onBlockInteract); | ||
} | ||
|
||
private static void onBlockInteract(PlayerInteractEvent.RightClickBlock event) { | ||
var pos = event.getPos(); | ||
var level = event.getLevel(); | ||
var be = level.getBlockEntity(pos); | ||
var held = event.getItemStack(); | ||
var player = event.getEntity(); | ||
|
||
if(!(be instanceof WallLanternBlockTile lantern)) return; | ||
|
||
var state = lantern.getHeldBlock(); | ||
var lit = state.getValue(CandleBlock.LIT); | ||
|
||
InteractionResult result = InteractionResult.PASS; | ||
|
||
if(held.is(Items.FLINT_AND_STEEL) && !lit) { | ||
level.playSound(player, pos, SoundEvents.FLINTANDSTEEL_USE, SoundSource.BLOCKS, 1.0F, level.getRandom().nextFloat() * 0.4F + 0.8F); | ||
lantern.setHeldBlock(state.setValue(BlockStateProperties.LIT, true)); | ||
if (player != null) { | ||
held.hurtAndBreak(1, player, (p_41303_) -> { | ||
p_41303_.broadcastBreakEvent(event.getHand()); | ||
}); | ||
} | ||
|
||
result = InteractionResult.sidedSuccess(level.isClientSide()); | ||
} else if(held.isEmpty() && lit) { | ||
level.playSound(player, pos, SoundEvents.CANDLE_EXTINGUISH, SoundSource.BLOCKS, 1.0F, 1.0F); | ||
lantern.setHeldBlock(state.setValue(BlockStateProperties.LIT, false)); | ||
|
||
result = InteractionResult.sidedSuccess(level.isClientSide()); | ||
} | ||
|
||
if(result != InteractionResult.PASS) { | ||
event.setCancellationResult(result); | ||
event.setCanceled(true); | ||
} | ||
} | ||
|
||
} |
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
37 changes: 37 additions & 0 deletions
37
src/main/java/galena/oreganized/content/entity/VigilCandleBlockEntity.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,37 @@ | ||
package galena.oreganized.content.entity; | ||
|
||
import galena.oreganized.index.OBlockEntities; | ||
import galena.oreganized.index.OTags; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.core.registries.Registries; | ||
import net.minecraft.world.entity.LivingEntity; | ||
import net.minecraft.world.level.Level; | ||
import net.minecraft.world.level.block.CandleBlock; | ||
import net.minecraft.world.level.block.entity.BlockEntity; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import net.minecraft.world.phys.AABB; | ||
|
||
public class VigilCandleBlockEntity extends BlockEntity { | ||
|
||
public VigilCandleBlockEntity(BlockPos pos, BlockState state) { | ||
super(OBlockEntities.VIGIL_CANDLE.get(), pos, state); | ||
} | ||
|
||
public void tick(Level level, BlockPos pos, BlockState state) { | ||
if (level.getGameTime() % 20L != 0) return; | ||
if (!state.getValue(CandleBlock.LIT)) return; | ||
|
||
var range = 3 + state.getValue(CandleBlock.CANDLES); | ||
var entities = level.getEntitiesOfClass(LivingEntity.class, new AABB(pos).inflate(range)); | ||
|
||
var effects = level.registryAccess().registryOrThrow(Registries.MOB_EFFECT); | ||
var shouldClear = effects.getTagOrEmpty(OTags.Effects.VIGIL_CANDLE_CLEARS); | ||
|
||
entities.forEach(entity -> { | ||
shouldClear.forEach(effect -> { | ||
entity.removeEffect(effect.get()); | ||
}); | ||
}); | ||
} | ||
|
||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package galena.oreganized.data; | ||
|
||
import galena.oreganized.Oreganized; | ||
import galena.oreganized.index.OTags; | ||
import net.minecraft.core.HolderLookup; | ||
import net.minecraft.core.registries.Registries; | ||
import net.minecraft.data.PackOutput; | ||
import net.minecraft.data.tags.TagsProvider; | ||
import net.minecraft.resources.ResourceKey; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.world.effect.MobEffect; | ||
import net.minecraftforge.common.data.ExistingFileHelper; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import javax.annotation.Nullable; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
public class OMobEffectTags extends TagsProvider<MobEffect> { | ||
|
||
public OMobEffectTags(PackOutput output, CompletableFuture<HolderLookup.Provider> future, @Nullable ExistingFileHelper helper) { | ||
super(output, Registries.MOB_EFFECT, future, Oreganized.MOD_ID, helper); | ||
} | ||
|
||
@Override | ||
public @NotNull String getName() { | ||
return "Oreganized MobEffect Tags"; | ||
} | ||
|
||
@Override | ||
protected void addTags(HolderLookup.Provider provider) { | ||
tag(OTags.Effects.VIGIL_CANDLE_CLEARS).add(ResourceKey.create(Registries.MOB_EFFECT, new ResourceLocation("darkness"))); | ||
} | ||
} |
Oops, something went wrong.