Skip to content

Commit 3cb768b

Browse files
committed
Add rift stabilizer and adjust recipes
1 parent b99f624 commit 3cb768b

11 files changed

Lines changed: 144 additions & 43 deletions

File tree

src/main/java/org/dimdev/dimdoors/client/ModelManager.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public static void registerModels() {
4444
register(ModItems.RIFT_BLADE);
4545
register(ModItems.RIFT_REMOVER);
4646
register(ModItems.RIFT_SIGNATURE);
47+
register(ModItems.RIFT_STABILIZER);
4748
register(ModItems.STABILIZED_RIFT_SIGNATURE);
4849
register(ModItems.WOVEN_WORLD_THREAD_BOOTS);
4950
register(ModItems.WOVEN_WORLD_THREAD_CHESTPLATE);

src/main/java/org/dimdev/dimdoors/shared/ModRecipes.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,16 +95,22 @@ public static void registerRecipes(RegistryEvent.Register<IRecipe> event) {
9595
"xxx", "xyx", "xxx", 'x', Items.GOLD_INGOT, 'y', Items.ENDER_PEARL));
9696

9797
registry.register(makeShapedRecipe(new ItemStack(ModItems.RIFT_REMOVER),
98-
" x ", "xyx", " x ", 'x', Items.GOLD_INGOT, 'y', ModItems.STABLE_FABRIC));
98+
"x x", " y ", "x x", 'x', Items.GOLD_INGOT, 'y', ModItems.STABLE_FABRIC));
9999

100100
registry.register(makeShapedRecipe(new ItemStack(ModItems.RIFT_SIGNATURE),
101101
"xxx", "xyx", "xxx", 'x', Items.IRON_INGOT, 'y', Items.ENDER_PEARL));
102102

103103
registry.register(makeShapedRecipe(new ItemStack(ModItems.RIFT_SIGNATURE),
104-
" x ", "xyx", " x ", 'x', Items.IRON_INGOT, 'y', ModItems.STABLE_FABRIC));
104+
"x x", " y ", "x x", 'x', Items.IRON_INGOT, 'y', ModItems.STABLE_FABRIC));
105105

106106
registry.register(makeShapedRecipe(new ItemStack(ModItems.STABILIZED_RIFT_SIGNATURE),
107-
" x ", "xyx", " x ", 'x', ModItems.STABLE_FABRIC, 'y', ModItems.RIFT_SIGNATURE));
107+
"x x", " y ", "x x", 'x', ModItems.STABLE_FABRIC, 'y', ModItems.RIFT_SIGNATURE));
108+
109+
registry.register(makeShapedRecipe(new ItemStack(ModItems.RIFT_STABILIZER),
110+
"xxx", "xyx", "xxx", 'x', Items.DIAMOND, 'y', Items.ENDER_PEARL));
111+
112+
registry.register(makeShapedRecipe(new ItemStack(ModItems.RIFT_STABILIZER),
113+
"x x", " y ", "x x", 'x', Items.DIAMOND, 'y', ModItems.STABLE_FABRIC));
108114

109115
registry.register(makeShapedRecipe(new ItemStack(ModItems.WOVEN_WORLD_THREAD_HELMET),
110116
"xxx", "x x", 'x', ModItems.WORLD_THREAD));

src/main/java/org/dimdev/dimdoors/shared/items/ItemRiftRemover.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import net.minecraftforge.fml.relauncher.Side;
77
import net.minecraftforge.fml.relauncher.SideOnly;
88
import org.dimdev.dimdoors.DimDoors;
9+
import org.dimdev.dimdoors.client.TileEntityFloatingRiftRenderer;
10+
import org.dimdev.dimdoors.shared.ModConfig;
911
import org.dimdev.dimdoors.shared.RayTraceHelper;
1012
import org.dimdev.dimdoors.shared.sound.ModSounds;
1113
import org.dimdev.dimdoors.shared.tileentities.TileEntityFloatingRift;
@@ -40,22 +42,26 @@ public void addInformation(ItemStack stack, World world, List<String> tooltip, I
4042
@Override
4143
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand handIn) { // TODO: permissions
4244
ItemStack stack = player.getHeldItem(handIn);
45+
RayTraceResult hit = rayTrace(world, player, true);
4346

4447
if (world.isRemote) {
48+
if (!RayTraceHelper.isFloatingRift(hit, world)) {
49+
player.sendStatusMessage(new TextComponentTranslation("tools.rift_miss"), true);
50+
TileEntityFloatingRiftRenderer.showRiftCoreUntil = System.currentTimeMillis() + ModConfig.graphics.highlightRiftCoreFor;
51+
}
4552
return new ActionResult<>(EnumActionResult.FAIL, stack);
4653
}
4754

48-
RayTraceResult hit = rayTrace(world, player, true);
4955
if (RayTraceHelper.isFloatingRift(hit, world)) {
5056
TileEntityFloatingRift rift = (TileEntityFloatingRift) world.getTileEntity(hit.getBlockPos());
5157
if (!rift.closing) {
5258
rift.setClosing(true);
5359
world.playSound(null, player.getPosition(), ModSounds.RIFT_CLOSE, SoundCategory.BLOCKS, 0.6f, 1);
5460
stack.damageItem(10, player);
55-
player.sendStatusMessage(new TextComponentTranslation("item.rift_remover.closing"), true);
61+
player.sendStatusMessage(new TextComponentTranslation(getUnlocalizedName() + ".closing"), true);
5662
return new ActionResult<>(EnumActionResult.SUCCESS, stack);
5763
} else {
58-
player.sendStatusMessage(new TextComponentTranslation("item.rift_remover.already_closing"), true);
64+
player.sendStatusMessage(new TextComponentTranslation(getUnlocalizedName() + ".already_closing"), true);
5965
}
6066
}
6167
return new ActionResult<>(EnumActionResult.FAIL, stack);

src/main/java/org/dimdev/dimdoors/shared/items/ItemRiftSignature.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos
5959
if (target == null) {
6060
// The link signature has not been used. Store its current target as the first location.
6161
setSource(stack, new RotatedLocation(new Location(world, pos), player.rotationYaw, 0));
62-
player.sendStatusMessage(new TextComponentTranslation("item.rift_signature.stored"), true);
62+
player.sendStatusMessage(new TextComponentTranslation(getUnlocalizedName() + ".stored"), true);
6363
world.playSound(null, player.getPosition(), ModSounds.RIFT_START, SoundCategory.BLOCKS, 0.6f, 1);
6464
} else {
6565
// Place a rift at the saved point TODO: check that the player still has permission
@@ -85,7 +85,7 @@ public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos
8585
stack.damageItem(1, player); // TODO: calculate damage based on position?
8686

8787
clearSource(stack);
88-
player.sendStatusMessage(new TextComponentTranslation("item.rift_signature.created"), true);
88+
player.sendStatusMessage(new TextComponentTranslation(getUnlocalizedName() + ".created"), true);
8989
// null = send sound to the player too, we have to do this because this code is not run client-side
9090
world.playSound(null, player.getPosition(), ModSounds.RIFT_END, SoundCategory.BLOCKS, 0.6f, 1);
9191
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package org.dimdev.dimdoors.shared.items;
2+
3+
import net.minecraft.client.resources.I18n;
4+
import net.minecraft.client.util.ITooltipFlag;
5+
import net.minecraft.entity.player.EntityPlayer;
6+
import net.minecraft.item.Item;
7+
import net.minecraft.item.ItemStack;
8+
import net.minecraft.util.*;
9+
import net.minecraft.util.math.RayTraceResult;
10+
import net.minecraft.util.text.TextComponentTranslation;
11+
import net.minecraft.world.World;
12+
import net.minecraftforge.fml.relauncher.Side;
13+
import net.minecraftforge.fml.relauncher.SideOnly;
14+
import org.dimdev.dimdoors.DimDoors;
15+
import org.dimdev.dimdoors.client.TileEntityFloatingRiftRenderer;
16+
import org.dimdev.dimdoors.shared.ModConfig;
17+
import org.dimdev.dimdoors.shared.RayTraceHelper;
18+
import org.dimdev.dimdoors.shared.sound.ModSounds;
19+
import org.dimdev.dimdoors.shared.tileentities.TileEntityFloatingRift;
20+
21+
import java.util.List;
22+
23+
public class ItemRiftStabilizer extends Item {
24+
public static final String ID = "rift_stabilizer";
25+
26+
public ItemRiftStabilizer() {
27+
setMaxStackSize(1);
28+
setMaxDamage(6); // TODO: Add more uses and make it reduce rift growth speed instead?
29+
setCreativeTab(DimDoors.DIM_DOORS_CREATIVE_TAB);
30+
setUnlocalizedName(ID);
31+
setRegistryName(new ResourceLocation(DimDoors.MODID, ID));
32+
}
33+
34+
@Override
35+
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand handIn) { // TODO: permissions
36+
ItemStack stack = player.getHeldItem(handIn);
37+
RayTraceResult hit = rayTrace(world, player, true);
38+
39+
if (world.isRemote) {
40+
if (!RayTraceHelper.isFloatingRift(hit, world)) {
41+
player.sendStatusMessage(new TextComponentTranslation("tools.rift_miss"), true);
42+
TileEntityFloatingRiftRenderer.showRiftCoreUntil = System.currentTimeMillis() + ModConfig.graphics.highlightRiftCoreFor;
43+
}
44+
return new ActionResult<>(EnumActionResult.FAIL, stack);
45+
}
46+
47+
if (RayTraceHelper.isFloatingRift(hit, world)) {
48+
TileEntityFloatingRift rift = (TileEntityFloatingRift) world.getTileEntity(hit.getBlockPos());
49+
if (!rift.stabilized && !rift.closing) {
50+
rift.setStabilized(true);
51+
world.playSound(null, player.getPosition(), ModSounds.RIFT_CLOSE, SoundCategory.BLOCKS, 0.6f, 1); // TODO: different sound
52+
stack.damageItem(1, player);
53+
player.sendStatusMessage(new TextComponentTranslation(getUnlocalizedName() + ".stabilized"), true);
54+
return new ActionResult<>(EnumActionResult.SUCCESS, stack);
55+
} else {
56+
player.sendStatusMessage(new TextComponentTranslation(getUnlocalizedName() + ".already_stabilized"), true);
57+
}
58+
}
59+
return new ActionResult<>(EnumActionResult.FAIL, stack);
60+
}
61+
62+
@Override
63+
@SideOnly(Side.CLIENT)
64+
public void addInformation(ItemStack stack, World world, List<String> tooltip, ITooltipFlag flag) {
65+
tooltip.add(I18n.format(I18n.format(getUnlocalizedName() + ".info")));
66+
}
67+
}

src/main/java/org/dimdev/dimdoors/shared/items/ItemStabilizedRiftSignature.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos
5959
if (target == null) {
6060
// The link signature has not been used. Store its current target as the first location.
6161
setSource(stack, new RotatedLocation(new Location(world, pos), player.rotationYaw, 0));
62-
player.sendStatusMessage(new TextComponentTranslation("item.stabilized_rift_signature.stored"), true);
62+
player.sendStatusMessage(new TextComponentTranslation(getUnlocalizedName() + ".stored"), true);
6363
world.playSound(null, player.getPosition(), ModSounds.RIFT_START, SoundCategory.BLOCKS, 0.6f, 1);
6464
} else {
6565
// Place a rift at the target point
@@ -83,7 +83,7 @@ public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos
8383

8484
stack.damageItem(1, player);
8585

86-
player.sendStatusMessage(new TextComponentTranslation("item.stabilized_rift_signature.created"), true);
86+
player.sendStatusMessage(new TextComponentTranslation(getUnlocalizedName() + ".created"), true);
8787
world.playSound(null, player.getPosition(), ModSounds.RIFT_END, SoundCategory.BLOCKS, 0.6f, 1);
8888
}
8989

@@ -116,9 +116,9 @@ public static RotatedLocation getTarget(ItemStack itemStack) {
116116
public void addInformation(ItemStack stack, World world, List<String> tooltip, ITooltipFlag flag) {
117117
RotatedLocation transform = getTarget(stack);
118118
if (transform != null) {
119-
tooltip.add(I18n.format("item.stabilized_rift_signature.bound.info", transform.getLocation().getX(), transform.getLocation().getY(), transform.getLocation().getZ(), transform.getLocation().getDim()));
119+
tooltip.add(I18n.format(getUnlocalizedName() + ".bound.info", transform.getLocation().getX(), transform.getLocation().getY(), transform.getLocation().getZ(), transform.getLocation().getDim()));
120120
} else {
121-
tooltip.add(I18n.format("item.stabilized_rift_signature.unbound.info"));
121+
tooltip.add(I18n.format(getUnlocalizedName() + ".unbound.info"));
122122
}
123123
}
124124
}

src/main/java/org/dimdev/dimdoors/shared/items/ModItems.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public final class ModItems {
3535
public static final ItemRiftRemover RIFT_REMOVER = new ItemRiftRemover();
3636
public static final ItemRiftSignature RIFT_SIGNATURE = new ItemRiftSignature();
3737
public static final ItemStabilizedRiftSignature STABILIZED_RIFT_SIGNATURE = new ItemStabilizedRiftSignature();
38+
public static final ItemRiftStabilizer RIFT_STABILIZER = new ItemRiftStabilizer();
3839

3940
// Armors
4041
public static final ItemWovenWorldThreadArmor WOVEN_WORLD_THREAD_HELMET = new ItemWovenWorldThreadArmor("woven_world_thread_helmet", 1, EntityEquipmentSlot.HEAD);
@@ -65,6 +66,7 @@ public static void registerItems(RegistryEvent.Register<Item> event) {
6566
RIFT_REMOVER,
6667
RIFT_SIGNATURE,
6768
STABILIZED_RIFT_SIGNATURE,
69+
RIFT_STABILIZER,
6870
WOVEN_WORLD_THREAD_HELMET,
6971
WOVEN_WORLD_THREAD_CHESTPLATE,
7072
WOVEN_WORLD_THREAD_LEGGINGS,

src/main/java/org/dimdev/dimdoors/shared/tileentities/TileEntityFloatingRift.java

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@
3434

3535
private static final Random random = new Random();
3636

37-
// TODO: Some of these properties will need to persist when converting to door and then back to rift!
38-
//Need to be saved:
37+
// Need to be saved:
3938
@Saved public boolean closing = false; // TODO: maybe we could have a closingSpeed instead?
39+
@Saved public boolean stabilized = false;
4040
@Saved public int spawnedEndermenID = 0;
4141
@Saved public float size = 0; // TODO: store size in blocks
4242
@Saved public float riftYaw = random.nextInt(360);
@@ -63,17 +63,6 @@ public void update() {
6363
return;
6464
}
6565

66-
// Check if this rift should render white closing particles and
67-
// spread the closing effect to other rifts nearby.
68-
if (closing) {
69-
if (size > 0) {
70-
size -= ModConfig.general.riftCloseSpeed;
71-
} else {
72-
world.setBlockToAir(pos);
73-
}
74-
return;
75-
}
76-
7766
if (updateTimer >= UPDATE_PERIOD) {
7867
spawnEndermen();
7968
updateTimer = 0;
@@ -82,10 +71,20 @@ public void update() {
8271
}
8372
updateTimer++;
8473

85-
// Logarithmic growth
86-
for (int n = 0; n < 10; n++) {
87-
// TODO: growthSpeed and growthSize config options
88-
size += 1F / (size + 1);
74+
// Check if this rift should render white closing particles and
75+
// spread the closing effect to other rifts nearby.
76+
if (closing) {
77+
if (size > 0) {
78+
size -= ModConfig.general.riftCloseSpeed;
79+
} else {
80+
world.setBlockToAir(pos);
81+
}
82+
} else if (!stabilized) {
83+
// Logarithmic growth
84+
for (int n = 0; n < 10; n++) {
85+
// TODO: growthSpeed and growthSize config options
86+
size += 1F / (size + 1);
87+
}
8988
}
9089
}
9190

@@ -134,6 +133,13 @@ public void setClosing(boolean closing) {
134133
markDirty();
135134
}
136135

136+
public void setStabilized(boolean stabilized) {
137+
this.stabilized = stabilized;
138+
IBlockState state = world.getBlockState(pos);
139+
world.notifyBlockUpdate(pos, state, state, 0);
140+
markDirty();
141+
}
142+
137143
@Override
138144
public boolean shouldRefresh(World world, BlockPos pos, IBlockState oldState, IBlockState newSate) {
139145
// newState is not accurate if we change the state during onBlockBreak

0 commit comments

Comments
 (0)