forked from McJtyMods/TheOneProbe
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
54 additions
and
0 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
src/main/java/mcjty/theoneprobe/apiimpl/providers/CauldronInfoProvider.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,54 @@ | ||
package mcjty.theoneprobe.apiimpl.providers; | ||
|
||
import mcjty.theoneprobe.api.*; | ||
import mcjty.theoneprobe.Utilities; | ||
import net.minecraft.block.BlockCauldron; | ||
import net.minecraft.block.properties.IProperty; | ||
import net.minecraft.block.state.IBlockState; | ||
import net.minecraft.entity.player.EntityPlayer; | ||
import net.minecraft.init.Items; | ||
import net.minecraft.init.PotionTypes; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.potion.PotionUtils; | ||
import net.minecraft.world.World; | ||
|
||
import javax.annotation.Nonnull; | ||
import java.util.Collections; | ||
|
||
public class CauldronInfoProvider implements IProbeInfoProvider { | ||
|
||
private static final ItemStack WATER_BUCKET = new ItemStack(Items.WATER_BUCKET); | ||
private static final ItemStack WATTER_BOTTLE = PotionUtils.addPotionToItemStack(new ItemStack(Items.POTIONITEM), PotionTypes.WATER); | ||
private static final ItemStack BUCKET = new ItemStack(Items.BUCKET); | ||
|
||
@Override | ||
public String getID() { | ||
return Utilities.getProviderId("cauldron"); | ||
} | ||
|
||
@Override | ||
public void addProbeInfo(ProbeMode mode, IProbeInfo probeInfo, EntityPlayer player, World world, @Nonnull IBlockState blockState, IProbeHitData data) { | ||
if (blockState.getBlock() instanceof BlockCauldron) { | ||
for (IProperty<?> property : blockState.getProperties().keySet()) { | ||
if (!"level".equals(property.getName())) continue; | ||
if (property.getValueClass() == Integer.class) { | ||
//noinspection unchecked | ||
IProperty<Integer> integerProperty = (IProperty<Integer>) property; | ||
int fill = blockState.getValue(integerProperty); | ||
int maxFill = Collections.max(integerProperty.getAllowedValues()); | ||
|
||
IProbeInfo horizontalPane = probeInfo.horizontal(probeInfo.defaultLayoutStyle().alignment(ElementAlignment.ALIGN_CENTER)); | ||
|
||
if (fill > 0) { | ||
horizontalPane.item((fill == maxFill) ? WATER_BUCKET : WATTER_BOTTLE); | ||
horizontalPane.text(TextStyleClass.LABEL + "" + fill + ((fill == 1) ? " {*topextras.top.cauldron_fill_1*}" : " {*topextras.top.cauldron_fill_2*}")); | ||
} else { | ||
horizontalPane.item(BUCKET); | ||
horizontalPane.text(TextStyleClass.LABEL + "{*topextras.top.empty*} "); | ||
} | ||
return; | ||
} | ||
} | ||
} | ||
} | ||
} |