Skip to content

Commit

Permalink
Merge pull request #315 from Fi0x/master
Browse files Browse the repository at this point in the history
Update
  • Loading branch information
Fi0x authored May 9, 2022
2 parents 0ebee14 + 87b7c02 commit 2063f9c
Show file tree
Hide file tree
Showing 57 changed files with 1,279 additions and 168 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ apply plugin: 'net.minecraftforge.gradle'
apply plugin: 'eclipse'
//apply plugin: 'maven-publish'

version = '1.0.1'
version = '1.0.2'
group = 'com.fi0x.deepmagic' // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = 'deepmagic'

Expand Down
3 changes: 1 addition & 2 deletions src/main/java/com/fi0x/deepmagic/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ public static void preInit(FMLPreInitializationEvent event)
PacketHandler.registerMessages(Reference.MOD_ID);
ModFluids.registerFluids();
EntityInit.registerEntities();
RenderHandler.registerEntityRenders();
RenderHandler.registerCustomMeshesAndStates();
proxy.preInit2(event);
BiomeInit.registerBiomes();
DimensionInit.registerDimensions();
GameRegistry.registerWorldGenerator(new ModWorldGen(), 3);
Expand Down
153 changes: 153 additions & 0 deletions src/main/java/com/fi0x/deepmagic/advancements/CustomTrigger.java
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 src/main/java/com/fi0x/deepmagic/advancements/ModTriggers.java
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
};
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.fi0x.deepmagic.blocks.mana;

import com.fi0x.deepmagic.Main;
import com.fi0x.deepmagic.advancements.ModTriggers;
import com.fi0x.deepmagic.blocks.BlockBase;
import com.fi0x.deepmagic.mana.player.PlayerMana;
import com.fi0x.deepmagic.mana.player.PlayerProperties;
Expand All @@ -11,6 +12,7 @@
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.EnumParticleTypes;
Expand Down Expand Up @@ -42,6 +44,7 @@ public boolean onBlockActivated(@Nonnull World worldIn, @Nonnull BlockPos pos, @
assert playerMana != null;
PacketHandler.INSTANCE.sendToServer(new PacketGetSkill(playerIn.getName(), playerMana.getMaxMana(), playerMana.getSkillXP(), playerMana.getSkillpoints(), playerMana.getManaRegenRate(), playerMana.getManaEfficiencyValue(), playerMana.addedHP, playerMana.hpRegeneration, playerMana.getSpellTier()));
Main.proxy.openSkilltreeGui(playerIn);
ModTriggers.KNOWLEDGE_UI_OPENED.trigger((EntityPlayerMP) playerIn);
}
return true;
}
Expand Down
133 changes: 133 additions & 0 deletions src/main/java/com/fi0x/deepmagic/blocks/mana/ManaBattery.java
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);
}
}
}
11 changes: 9 additions & 2 deletions src/main/java/com/fi0x/deepmagic/blocks/mana/ManaRelay.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.fi0x.deepmagic.blocks.mana;

import com.fi0x.deepmagic.advancements.ModTriggers;
import com.fi0x.deepmagic.blocks.BlockBase;
import com.fi0x.deepmagic.blocks.mana.tile.TileEntityManaRelay;
import com.fi0x.deepmagic.init.ModBlocks;
Expand All @@ -11,6 +12,7 @@
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
Expand Down Expand Up @@ -65,8 +67,13 @@ public boolean onBlockActivated(@Nonnull World worldIn, @Nonnull BlockPos pos, @
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));
if(te.addOrRemoveTarget(new BlockPos(x, y, z)))
{
playerIn.sendMessage(new TextComponentString(TextFormatting.YELLOW + "Linked to " + x + ", " + y + ", " + z));
ModTriggers.LINK_MANA_RELAY.trigger((EntityPlayerMP) playerIn);
}
else
playerIn.sendMessage(new TextComponentString(TextFormatting.YELLOW + "Unlinked " + x + ", " + y + ", " + z));
} else
{
compound.setInteger("x", pos.getX());
Expand Down
Loading

0 comments on commit 2063f9c

Please sign in to comment.