Skip to content

Commit ccb63b9

Browse files
committed
re-add frozen pearl
it seems there are still some edge cases that prevent the feral flare lantern from properly cleaning up all lights on removal of the lantern. the feral flare lantern will also monitor the lights more closely and cleanup its internal list when needed.
1 parent c75ed0c commit ccb63b9

File tree

7 files changed

+107
-0
lines changed

7 files changed

+107
-0
lines changed

common/src/main/java/net/xalcon/torchmaster/ModRegistry.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import net.minecraft.world.level.block.state.BlockBehaviour;
1212
import net.minecraft.world.level.material.MapColor;
1313
import net.xalcon.torchmaster.blocks.*;
14+
import net.xalcon.torchmaster.items.FrozenPearlItem;
1415
import net.xalcon.torchmaster.items.TMItemBlock;
1516
import net.xalcon.torchmaster.platform.RegistrationProvider;
1617
import net.xalcon.torchmaster.platform.RegistryObject;
@@ -38,6 +39,7 @@ public class ModRegistry
3839
public static RegistryObject<Item> itemMegaTorch;
3940
public static RegistryObject<Item> itemDreadLamp;
4041
public static RegistryObject<Item> itemFeralFlareLantern;
42+
public static RegistryObject<Item> itemFrozenPearl;
4143

4244
private ModRegistry() { }
4345
private static CreativeModeTab tab;
@@ -88,6 +90,9 @@ public static void initialize()
8890
itemFeralFlareLantern = fromBlock(blockFeralFlareLantern);
8991
creativeTabItems.add(itemFeralFlareLantern);
9092

93+
itemFrozenPearl = ITEMS.register("frozen_pearl", () -> new FrozenPearlItem(new Item.Properties()));
94+
creativeTabItems.add(itemFrozenPearl);
95+
9196
blockInvisibleLight = BLOCKS.register("invisible_light", () -> new InvisibleLightBlock(
9297
BlockBehaviour.Properties.of()
9398
.lightLevel(state -> 15)

common/src/main/java/net/xalcon/torchmaster/blocks/FeralFlareLanternBlockEntity.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ public class FeralFlareLanternBlockEntity extends BlockEntity
2929
private boolean useLineOfSight;
3030
private List<BlockPos> childLights = new ArrayList<>();
3131

32+
private int checkIndex;
33+
3234
public FeralFlareLanternBlockEntity(BlockPos pos, BlockState state)
3335
{
3436
super(ModRegistry.tileFeralFlareLantern.get(), pos, state);
@@ -85,6 +87,19 @@ public void tick()
8587
this.setChanged();
8688
}
8789
}
90+
91+
if(!this.childLights.isEmpty())
92+
{
93+
this.checkIndex = (this.checkIndex + 1) % this.childLights.size();
94+
var pos = this.childLights.get(this.checkIndex);
95+
var block = level.getBlockState(pos);
96+
if(!(block.getBlock() instanceof InvisibleLightBlock))
97+
{
98+
// Pos in light list no longer points to an invisible light.
99+
// it may have gotten removed by some means (replaced by block, removed, etc)
100+
this.childLights.remove(checkIndex);
101+
}
102+
}
88103
}
89104

90105
public static <T extends BlockEntity> void dispatchTickBlockEntity(Level level, BlockPos pos, BlockState state, T blockEntity)
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package net.xalcon.torchmaster.items;
2+
3+
import net.minecraft.core.BlockPos;
4+
import net.minecraft.network.chat.Component;
5+
import net.minecraft.sounds.SoundEvents;
6+
import net.minecraft.sounds.SoundSource;
7+
import net.minecraft.world.InteractionHand;
8+
import net.minecraft.world.InteractionResult;
9+
import net.minecraft.world.InteractionResultHolder;
10+
import net.minecraft.world.entity.player.Player;
11+
import net.minecraft.world.item.Item;
12+
import net.minecraft.world.item.ItemStack;
13+
import net.minecraft.world.item.TooltipFlag;
14+
import net.minecraft.world.level.Level;
15+
import net.minecraft.world.level.block.Block;
16+
import net.xalcon.torchmaster.ModRegistry;
17+
import net.xalcon.torchmaster.Torchmaster;
18+
19+
import javax.annotation.Nullable;
20+
import java.util.List;
21+
22+
public class FrozenPearlItem extends Item
23+
{
24+
public FrozenPearlItem(Properties pProperties)
25+
{
26+
super(pProperties);
27+
}
28+
29+
@Override
30+
public InteractionResultHolder<ItemStack> use(Level level, Player player, InteractionHand hand) {
31+
ItemStack itemStack = player.getItemInHand(hand);
32+
if(level.isClientSide())
33+
return new InteractionResultHolder<>(InteractionResult.PASS, itemStack);
34+
35+
BlockPos.MutableBlockPos checkPos = new BlockPos.MutableBlockPos(0, 0, 0);
36+
BlockPos pos = player.blockPosition();
37+
level.playSound(player, pos.getX(), pos.getY(), pos.getZ(), SoundEvents.LAVA_EXTINGUISH, SoundSource.BLOCKS, 0.7f, 0.6f);
38+
for(int x = -15; x <= 15; x++)
39+
{
40+
for(int y = -15; y <= 15; y++)
41+
{
42+
for(int z = -15; z <= 15; z++)
43+
{
44+
checkPos.set(pos.getX() + x, pos.getY() + y, pos.getZ() + z);
45+
Block block = level.getBlockState(checkPos).getBlock();
46+
if(block == ModRegistry.blockInvisibleLight.get())
47+
{
48+
level.removeBlock(checkPos, false);
49+
if(itemStack.isEmpty())
50+
return new InteractionResultHolder<>(InteractionResult.SUCCESS, ItemStack.EMPTY);
51+
}
52+
}
53+
}
54+
}
55+
return new InteractionResultHolder<>(InteractionResult.SUCCESS, itemStack);
56+
}
57+
58+
@Override
59+
public void appendHoverText(ItemStack stack, TooltipContext context, List<Component> tooltip, TooltipFlag flag) {
60+
super.appendHoverText(stack, context, tooltip, flag);
61+
tooltip.add(Component.translatable(this.getDescriptionId(stack) + ".tooltip"));
62+
}
63+
}

common/src/main/resources/assets/torchmaster/lang/en_us.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
"command.torchmaster.entity_dump.completed": "Entities have been dumped to the log file",
1111
"itemGroup.torchmaster": "Torchmaster",
1212

13+
"item.torchmaster.frozen_pearl": "Frozen Pearl",
14+
"item.torchmaster.frozen_pearl.tooltip": "Clears residual lights from a Feral Flare Lantern",
15+
1316
"text.config.torchmaster-config.option.feralFlareLanternTickRate": "Feral Flare Lantern Tick Rate",
1417
"text.config.torchmaster-config.option.feralFlareLanternTickRate.tooltip": "How often the lantern should attempt to place lights",
1518
"text.config.torchmaster-config.option.feralFlareLanternLightHardcap": "Feral Flare Lantern Light hard cap",
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"parent": "item/generated",
3+
"textures": {
4+
"layer0": "torchmaster:item/frozen_pearl"
5+
}
6+
}
14.4 KB
Loading
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"type": "minecraft:crafting_shaped",
3+
"pattern": [
4+
" I ",
5+
"IEI",
6+
" I "
7+
],
8+
"key": {
9+
"E": { "item": "minecraft:ender_pearl" },
10+
"I": [{ "item": "minecraft:ice" }, { "item": "minecraft:packed_ice" }]
11+
},
12+
"result": {
13+
"item": "torchmaster:frozen_pearl"
14+
}
15+
}

0 commit comments

Comments
 (0)