-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #315 from Fi0x/master
Update
- Loading branch information
Showing
57 changed files
with
1,279 additions
and
168 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
153 changes: 153 additions & 0 deletions
153
src/main/java/com/fi0x/deepmagic/advancements/CustomTrigger.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,153 @@ | ||
package com.fi0x.deepmagic.advancements; | ||
|
||
import com.google.common.collect.Lists; | ||
import com.google.common.collect.Maps; | ||
import com.google.common.collect.Sets; | ||
import com.google.gson.JsonDeserializationContext; | ||
import com.google.gson.JsonObject; | ||
import net.minecraft.advancements.ICriterionTrigger; | ||
import net.minecraft.advancements.PlayerAdvancements; | ||
import net.minecraft.advancements.critereon.AbstractCriterionInstance; | ||
import net.minecraft.entity.player.EntityPlayerMP; | ||
import net.minecraft.util.ResourceLocation; | ||
|
||
import javax.annotation.Nonnull; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
public class CustomTrigger implements ICriterionTrigger<CustomTrigger.Instance> | ||
{ | ||
private final ResourceLocation RL; | ||
private final Map<PlayerAdvancements, CustomTrigger.Listeners> listeners = Maps.newHashMap(); | ||
|
||
public CustomTrigger(String parString) | ||
{ | ||
super(); | ||
RL = new ResourceLocation(parString); | ||
} | ||
|
||
public CustomTrigger(ResourceLocation parRL) | ||
{ | ||
super(); | ||
RL = parRL; | ||
} | ||
|
||
@Nonnull | ||
@Override | ||
public ResourceLocation getId() | ||
{ | ||
return RL; | ||
} | ||
|
||
@Override | ||
public void addListener(@Nonnull PlayerAdvancements playerAdvancementsIn, @Nonnull ICriterionTrigger.Listener listener) | ||
{ | ||
CustomTrigger.Listeners customTriggerListeners = listeners.get(playerAdvancementsIn); | ||
|
||
if (customTriggerListeners == null) | ||
{ | ||
customTriggerListeners = new CustomTrigger.Listeners(playerAdvancementsIn); | ||
listeners.put(playerAdvancementsIn, customTriggerListeners); | ||
} | ||
|
||
customTriggerListeners.add(listener); | ||
} | ||
|
||
@Override | ||
public void removeListener(@Nonnull PlayerAdvancements playerAdvancementsIn, @Nonnull ICriterionTrigger.Listener listener) | ||
{ | ||
CustomTrigger.Listeners customTriggerListeners = listeners.get(playerAdvancementsIn); | ||
|
||
if (customTriggerListeners != null) | ||
{ | ||
customTriggerListeners.remove(listener); | ||
|
||
if (customTriggerListeners.isEmpty()) | ||
listeners.remove(playerAdvancementsIn); | ||
} | ||
} | ||
|
||
@Override | ||
public void removeAllListeners(@Nonnull PlayerAdvancements playerAdvancementsIn) | ||
{ | ||
listeners.remove(playerAdvancementsIn); | ||
} | ||
|
||
@Nonnull | ||
@Override | ||
public CustomTrigger.Instance deserializeInstance(@Nonnull JsonObject json, @Nonnull JsonDeserializationContext context) | ||
{ | ||
return new CustomTrigger.Instance(getId()); | ||
} | ||
|
||
public void trigger(EntityPlayerMP parPlayer) | ||
{ | ||
CustomTrigger.Listeners customTriggerListeners = listeners.get(parPlayer.getAdvancements()); | ||
|
||
if (customTriggerListeners != null) | ||
customTriggerListeners.trigger(parPlayer); | ||
} | ||
|
||
public static class Instance extends AbstractCriterionInstance | ||
{ | ||
|
||
public Instance(ResourceLocation parRL) | ||
{ | ||
super(parRL); | ||
} | ||
|
||
public boolean test() | ||
{ | ||
return true; | ||
} | ||
} | ||
|
||
static class Listeners | ||
{ | ||
private final PlayerAdvancements playerAdvancements; | ||
private final Set<ICriterionTrigger.Listener<CustomTrigger.Instance>> listeners = Sets.newHashSet(); | ||
|
||
public Listeners(PlayerAdvancements playerAdvancementsIn) | ||
{ | ||
playerAdvancements = playerAdvancementsIn; | ||
} | ||
|
||
public boolean isEmpty() | ||
{ | ||
return listeners.isEmpty(); | ||
} | ||
|
||
public void add(ICriterionTrigger.Listener<CustomTrigger.Instance> listener) | ||
{ | ||
listeners.add(listener); | ||
} | ||
|
||
public void remove(ICriterionTrigger.Listener<CustomTrigger.Instance> listener) | ||
{ | ||
listeners.remove(listener); | ||
} | ||
|
||
public void trigger(EntityPlayerMP player) | ||
{ | ||
List<Listener<CustomTrigger.Instance>> list = null; | ||
|
||
for (ICriterionTrigger.Listener<CustomTrigger.Instance> listener : listeners) | ||
{ | ||
if (listener.getCriterionInstance().test()) | ||
{ | ||
if (list == null) | ||
list = Lists.newArrayList(); | ||
|
||
list.add(listener); | ||
} | ||
} | ||
|
||
if (list != null) | ||
{ | ||
for (ICriterionTrigger.Listener<CustomTrigger.Instance> listener1 : list) | ||
listener1.grantCriterion(playerAdvancements); | ||
} | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/com/fi0x/deepmagic/advancements/ModTriggers.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,14 @@ | ||
package com.fi0x.deepmagic.advancements; | ||
|
||
public class ModTriggers | ||
{ | ||
public static final CustomTrigger RIGHT_CLICK_SPELL = new CustomTrigger("right_click_spell"); | ||
public static final CustomTrigger LINK_MANA_RELAY = new CustomTrigger("link_mana_relay"); | ||
public static final CustomTrigger KNOWLEDGE_UI_OPENED = new CustomTrigger("altar_of_knowledge_ui_opened"); | ||
|
||
public static final CustomTrigger[] TRIGGER_ARRAY = new CustomTrigger[]{ | ||
RIGHT_CLICK_SPELL, | ||
LINK_MANA_RELAY, | ||
KNOWLEDGE_UI_OPENED | ||
}; | ||
} |
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
133 changes: 133 additions & 0 deletions
133
src/main/java/com/fi0x/deepmagic/blocks/mana/ManaBattery.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,133 @@ | ||
package com.fi0x.deepmagic.blocks.mana; | ||
|
||
import com.fi0x.deepmagic.blocks.BlockBase; | ||
import com.fi0x.deepmagic.blocks.mana.tile.TileEntityManaBattery; | ||
import com.fi0x.deepmagic.init.ModBlocks; | ||
import com.fi0x.deepmagic.items.mana.ManaLinker; | ||
import com.fi0x.deepmagic.particlesystem.ParticleEnum; | ||
import com.fi0x.deepmagic.particlesystem.ParticleSpawner; | ||
import net.minecraft.block.ITileEntityProvider; | ||
import net.minecraft.block.SoundType; | ||
import net.minecraft.block.material.Material; | ||
import net.minecraft.block.state.IBlockState; | ||
import net.minecraft.entity.player.EntityPlayer; | ||
import net.minecraft.item.Item; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.nbt.NBTTagCompound; | ||
import net.minecraft.tileentity.TileEntity; | ||
import net.minecraft.util.EnumFacing; | ||
import net.minecraft.util.EnumHand; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.util.text.TextComponentString; | ||
import net.minecraft.util.text.TextFormatting; | ||
import net.minecraft.world.World; | ||
import net.minecraftforge.fml.relauncher.Side; | ||
import net.minecraftforge.fml.relauncher.SideOnly; | ||
|
||
import javax.annotation.Nonnull; | ||
import javax.annotation.Nullable; | ||
import java.util.Objects; | ||
import java.util.Random; | ||
|
||
public class ManaBattery extends BlockBase implements ITileEntityProvider | ||
{ | ||
public ManaBattery(String name, Material material) | ||
{ | ||
super(name, material); | ||
setSoundType(SoundType.STONE); | ||
setHardness(5.0F); | ||
setResistance(5.0F); | ||
setHarvestLevel("pickaxe", 0); | ||
} | ||
|
||
@Override | ||
public boolean onBlockActivated(@Nonnull World worldIn, @Nonnull BlockPos pos, @Nonnull IBlockState state, @Nonnull EntityPlayer playerIn, @Nonnull EnumHand hand, @Nonnull EnumFacing facing, float hitX, float hitY, float hitZ) | ||
{ | ||
if(worldIn.isRemote) return false; | ||
ItemStack stack = playerIn.getHeldItem(hand); | ||
Item item = stack.getItem(); | ||
|
||
TileEntityManaBattery te = (TileEntityManaBattery) worldIn.getTileEntity(pos); | ||
assert te != null; | ||
|
||
if(item instanceof ManaLinker) | ||
{ | ||
NBTTagCompound compound; | ||
if(!stack.hasTagCompound()) stack.setTagCompound(new NBTTagCompound()); | ||
compound = stack.getTagCompound(); | ||
assert compound != null; | ||
|
||
if(compound.hasKey("x")) | ||
{ | ||
int x = compound.getInteger("x"); | ||
int y = compound.getInteger("y"); | ||
int z = compound.getInteger("z"); | ||
|
||
if(te.addOrRemoveTarget(new BlockPos(x, y, z))) | ||
playerIn.sendMessage(new TextComponentString(TextFormatting.YELLOW + "Linked to " + x + ", " + y + ", " + z)); | ||
else | ||
playerIn.sendMessage(new TextComponentString(TextFormatting.YELLOW + "Unlinked " + x + ", " + y + ", " + z)); | ||
} else | ||
{ | ||
compound.setInteger("x", pos.getX()); | ||
compound.setInteger("y", pos.getY()); | ||
compound.setInteger("z", pos.getZ()); | ||
playerIn.sendMessage(new TextComponentString(TextFormatting.YELLOW + "Location stored")); | ||
} | ||
} | ||
else if(playerIn.isCreative() && item.getUnlocalizedName().equals("item.dimensional_crystal")) | ||
{ | ||
if(te.isCreative()) | ||
playerIn.sendMessage(new TextComponentString(TextFormatting.YELLOW + "Battery already in creative mode")); | ||
else | ||
{ | ||
te.makeCreative(); | ||
playerIn.sendMessage(new TextComponentString(TextFormatting.YELLOW + "Upgraded Battery to creative mode")); | ||
} | ||
} else if(stack.isEmpty()) | ||
playerIn.sendMessage(new TextComponentString(TextFormatting.BLUE + "Stored Mana: " + te.getStoredMana())); | ||
|
||
return false; | ||
} | ||
@Nonnull | ||
@Override | ||
public Item getItemDropped(@Nonnull IBlockState state, @Nonnull Random rand, int fortune) | ||
{ | ||
return Item.getItemFromBlock(ModBlocks.MANA_BATTERY); | ||
} | ||
@Nonnull | ||
@Override | ||
public ItemStack getItem(@Nonnull World worldIn, @Nonnull BlockPos pos, @Nonnull IBlockState state) | ||
{ | ||
return new ItemStack(ModBlocks.MANA_BATTERY); | ||
} | ||
@Nullable | ||
@Override | ||
public TileEntity createNewTileEntity(@Nonnull World worldIn, int meta) | ||
{ | ||
return new TileEntityManaBattery(); | ||
} | ||
@Override | ||
public boolean isOpaqueCube(@Nonnull IBlockState state) | ||
{ | ||
return false; | ||
} | ||
@Override | ||
public boolean isFullCube(@Nonnull IBlockState state) | ||
{ | ||
return false; | ||
} | ||
@SideOnly(Side.CLIENT) | ||
public void randomDisplayTick(@Nonnull IBlockState stateIn, @Nonnull World worldIn, @Nonnull BlockPos pos, @Nonnull Random rand) | ||
{ | ||
if(rand.nextInt(4) > 0) return; | ||
if(((TileEntityManaBattery) Objects.requireNonNull(worldIn.getTileEntity(pos))).hasTargets()) | ||
{ | ||
double x = pos.getX() + (Math.random() * 0.2) + 0.4; | ||
double y = pos.getY() + 1 + (Math.random() * 0.2); | ||
double z = pos.getZ() + (Math.random() * 0.2) + 0.4; | ||
|
||
ParticleSpawner.spawnParticle(ParticleEnum.MANA_BLOCK, x, y, z, 0, 0, 0, Math.random() * 0.3 + 0.2, false, 16); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.