-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add TimeStop effect and have new skill
- Loading branch information
Showing
33 changed files
with
1,266 additions
and
66 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
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
148 changes: 148 additions & 0 deletions
148
src/main/java/huige233/transcend/effect/TimeStopEffect.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,148 @@ | ||
package huige233.transcend.effect; | ||
|
||
import huige233.transcend.Main; | ||
import huige233.transcend.init.ModItems; | ||
import huige233.transcend.init.TranscendPotions; | ||
import huige233.transcend.packet.PacketEndTimeStop; | ||
import huige233.transcend.util.EntityUtils; | ||
import huige233.transcend.util.ISyncedPotion; | ||
import huige233.transcend.util.Reference; | ||
import huige233.transcend.util.handlers.TranscendPacketHandler; | ||
import net.minecraft.entity.Entity; | ||
import net.minecraft.entity.EntityLivingBase; | ||
import net.minecraft.entity.player.EntityPlayer; | ||
import net.minecraft.entity.projectile.EntityArrow; | ||
import net.minecraft.util.ResourceLocation; | ||
import net.minecraft.world.World; | ||
import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent; | ||
import net.minecraftforge.event.entity.living.PotionEvent; | ||
import net.minecraftforge.fml.common.Mod; | ||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; | ||
import net.minecraftforge.fml.common.gameevent.PlayerEvent; | ||
import net.minecraftforge.fml.common.gameevent.TickEvent; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
@Mod.EventBusSubscriber | ||
public class TimeStopEffect extends effectbase implements ISyncedPotion { | ||
|
||
public static final String KEY = "time_stop"; | ||
public TimeStopEffect(boolean isBadEffect,int liquidColour) { | ||
super(isBadEffect, liquidColour, new ResourceLocation(Reference.MOD_ID, "textures/gui/potion_time_stop.png")); | ||
this.setPotionName("potion." + Reference.MOD_ID + ":time_stop"); | ||
} | ||
|
||
public static void unblockByEntities(EntityLivingBase host){ | ||
List<Entity> target = EntityUtils.getEntitiesWithinRadius(50,host.posX,host.posY,host.posZ, host.world,Entity.class); | ||
target.forEach(e -> e.updateBlocked = false); | ||
} | ||
|
||
private static void performEffectConsistent(EntityLivingBase host,int strength){ | ||
boolean time_stop = host instanceof EntityPlayer&& host.getHeldItemMainhand().getItem() == ModItems.TRANSCEND_SWORD; | ||
int interval = strength *4 + 6; | ||
List<Entity> target = EntityUtils.getEntitiesWithinRadius(50,host.posX,host.posY,host.posZ,host.world,Entity.class); | ||
target.remove(host); | ||
target.removeIf(t -> t instanceof EntityLivingBase && ((EntityLivingBase)t).isPotionActive(TranscendPotions.time_stop)); | ||
target.removeIf(t -> t instanceof EntityArrow && t.isEntityInsideOpaqueBlock()); | ||
|
||
for(Entity entity : target) { | ||
entity.getEntityData().setBoolean(KEY,true); | ||
entity.updateBlocked = time_stop || host.ticksExisted % interval != 0; | ||
|
||
if (!time_stop && entity.world.isRemote) { | ||
if (entity.onGround) entity.motionY = 0; | ||
} | ||
if (entity.updateBlocked) { | ||
double x = entity.posX + entity.motionX * 1d / (double) interval; | ||
double y = entity.posY + entity.motionY * 1d / (double) interval; | ||
double z = entity.posZ + entity.motionZ * 1d / (double) interval; | ||
|
||
entity.prevPosX = entity.posX; | ||
entity.prevPosY = entity.posY; | ||
entity.prevPosZ = entity.posZ; | ||
|
||
entity.posX = x; | ||
entity.posY = y; | ||
entity.posZ = z; | ||
} else { | ||
entity.posX += entity.motionX * 1d / (double) interval; | ||
entity.posY += entity.motionY * 1d / (double) interval; | ||
entity.posZ += entity.motionZ * 1d / (double) interval; | ||
|
||
double x = entity.posX - entity.motionX * 1d / (double) interval; | ||
double y = entity.posY - entity.motionY * 1d / (double) interval; | ||
double z = entity.posZ - entity.motionZ * 1d / (double) interval; | ||
|
||
entity.prevPosX = x; | ||
entity.prevPosY = y; | ||
entity.prevPosZ = z; | ||
} | ||
} | ||
List<Entity> list = EntityUtils.getEntitiesWithinRadius(60,host.posX,host.posY,host.posZ,host.world,Entity.class); | ||
list.removeAll(target); | ||
list.forEach(e -> e.updateBlocked = false); | ||
} | ||
|
||
public static void cleanUpEntities(World world){ | ||
List<Entity> loadedEntity = new ArrayList<>(world.loadedEntityList); | ||
for(Entity entity : loadedEntity){ | ||
if(entity.getEntityData().getBoolean(KEY)){ | ||
List<EntityLivingBase> nearby = EntityUtils.getLivingWithinRadius(50,entity.posX,entity.posY,entity.posZ,entity.world); | ||
if(nearby.stream().noneMatch(e -> e.isPotionActive(TranscendPotions.time_stop))){ | ||
entity.getEntityData().removeTag(KEY); | ||
entity.updateBlocked = false; | ||
} | ||
} | ||
} | ||
} | ||
|
||
@SubscribeEvent | ||
public static void onLivingUpdateEvent(LivingUpdateEvent event){ | ||
|
||
EntityLivingBase entity = event.getEntityLiving(); | ||
if(entity.isPotionActive(TranscendPotions.time_stop)){ | ||
performEffectConsistent(entity, entity.getActivePotionEffect(TranscendPotions.time_stop).getAmplifier()); | ||
} | ||
} | ||
|
||
|
||
@SubscribeEvent | ||
public static void onPotionAddedEvent(PotionEvent.PotionAddedEvent event){ | ||
if(event.getEntity().world.isRemote && event.getPotionEffect().getPotion() == TranscendPotions.time_stop | ||
&& event.getEntity() instanceof EntityPlayer){ | ||
Main.proxy.playBlinkEffect((EntityPlayer) event.getEntity()); | ||
} | ||
} | ||
|
||
@SubscribeEvent | ||
public static void tick(TickEvent.WorldTickEvent event){ | ||
if(!event.world.isRemote && event.phase == TickEvent.Phase.END) cleanUpEntities(event.world); | ||
} | ||
|
||
@SubscribeEvent | ||
public static void onPlayerLoggedOutEvent(PlayerEvent.PlayerLoggedOutEvent event){ | ||
if(event.player.updateBlocked) event.player.updateBlocked = false; | ||
} | ||
|
||
/* | ||
@SubscribeEvent | ||
public static void onPotionExpiryEvent(PotionEvent.PotionExpiryEvent event){ | ||
if(event.getPotionEffect() != null && event.getPotionEffect().getPotion() == TranscendPotions.time_stop){ | ||
unblockByEntities(event.getEntityLiving()); | ||
if(!event.getEntity().world.isRemote){ | ||
TranscendPacketHandler.net.sendToDimension(new PacketEndTimeStop.Message(event.getEntityLiving()),event.getEntity().dimension); | ||
} | ||
} | ||
} | ||
@SubscribeEvent | ||
public static void onPotionRemoveEvent(PotionEvent.PotionRemoveEvent event){ | ||
if(event.getPotionEffect() != null && event.getPotionEffect().getPotion() == TranscendPotions.time_stop){ | ||
unblockByEntities(event.getEntityLiving()); | ||
if(!event.getEntity().world.isRemote){ | ||
TranscendPacketHandler.net.sendToDimension(new PacketEndTimeStop.Message(event.getEntityLiving()),event.getEntity().dimension); | ||
} | ||
} | ||
} | ||
*/ | ||
} |
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,71 @@ | ||
package huige233.transcend.effect; | ||
|
||
import net.minecraft.client.renderer.BufferBuilder; | ||
import net.minecraft.client.renderer.Tessellator; | ||
import net.minecraft.entity.EntityLivingBase; | ||
import net.minecraft.potion.Potion; | ||
import net.minecraft.potion.PotionEffect; | ||
import net.minecraft.util.ResourceLocation; | ||
import net.minecraftforge.fml.relauncher.Side; | ||
import net.minecraftforge.fml.relauncher.SideOnly; | ||
|
||
public class effectbase extends Potion { | ||
private final ResourceLocation texture; | ||
|
||
public effectbase(boolean isBadEffect, int liquidColour, ResourceLocation texture){ | ||
super(isBadEffect, liquidColour); | ||
this.texture = texture; | ||
} | ||
|
||
@Override | ||
public void performEffect(EntityLivingBase entitylivingbase, int strength){ | ||
// Nothing here because this potion works on events. | ||
} | ||
|
||
@Override | ||
@SideOnly(Side.CLIENT) | ||
public void renderInventoryEffect(int x, int y, PotionEffect effect, net.minecraft.client.Minecraft mc){ | ||
drawIcon(x + 6, y + 7, effect, mc); | ||
} | ||
|
||
@Override | ||
@SideOnly(Side.CLIENT) | ||
public void renderHUDEffect(int x, int y, PotionEffect effect, net.minecraft.client.Minecraft mc, float alpha){ | ||
net.minecraft.client.renderer.GlStateManager.color(1, 1, 1, alpha); | ||
drawIcon(x + 3, y + 3, effect, mc); | ||
} | ||
|
||
@SideOnly(Side.CLIENT) | ||
protected void drawIcon(int x, int y, PotionEffect effect, net.minecraft.client.Minecraft mc){ | ||
mc.renderEngine.bindTexture(texture); | ||
drawTexturedRect(x, y, 0, 0, 18, 18, 18, 18); | ||
} | ||
|
||
public static void drawTexturedRect(int x, int y, int u, int v, int width, int height, int textureWidth, int textureHeight){ | ||
drawTexturedFlippedRect(x, y, u, v, width, height, textureWidth, textureHeight, false, false); | ||
} | ||
|
||
public static void drawTexturedFlippedRect(int x, int y, int u, int v, int width, int height, int textureWidth, int textureHeight, boolean flipX, boolean flipY){ | ||
|
||
float f = 1F / (float)textureWidth; | ||
float f1 = 1F / (float)textureHeight; | ||
|
||
int u1 = flipX ? u + width : u; | ||
int u2 = flipX ? u : u + width; | ||
int v1 = flipY ? v + height : v; | ||
int v2 = flipY ? v : v + height; | ||
|
||
Tessellator tessellator = Tessellator.getInstance(); | ||
BufferBuilder buffer = tessellator.getBuffer(); | ||
|
||
buffer.begin(org.lwjgl.opengl.GL11.GL_QUADS, net.minecraft.client.renderer.vertex.DefaultVertexFormats.POSITION_TEX); | ||
|
||
buffer.pos((double)(x), (double)(y + height), 0).tex((double)((float)(u1) * f), (double)((float)(v2) * f1)).endVertex(); | ||
buffer.pos((double)(x + width), (double)(y + height), 0).tex((double)((float)(u2) * f), (double)((float)(v2) * f1)).endVertex(); | ||
buffer.pos((double)(x + width), (double)(y), 0).tex((double)((float)(u2) * f), (double)((float)(v1) * f1)).endVertex(); | ||
buffer.pos((double)(x), (double)(y), 0).tex((double)((float)(u1) * f), (double)((float)(v1) * f1)).endVertex(); | ||
|
||
tessellator.draw(); | ||
} | ||
|
||
} |
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
36 changes: 36 additions & 0 deletions
36
src/main/java/huige233/transcend/init/TranscendPotions.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,36 @@ | ||
package huige233.transcend.init; | ||
|
||
import huige233.transcend.effect.TimeStopEffect; | ||
import huige233.transcend.util.Reference; | ||
import net.minecraft.potion.Potion; | ||
import net.minecraftforge.event.RegistryEvent; | ||
import net.minecraftforge.fml.common.Mod; | ||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; | ||
import net.minecraftforge.fml.common.registry.GameRegistry.ObjectHolder; | ||
import net.minecraftforge.registries.IForgeRegistry; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
@ObjectHolder(Reference.MOD_ID) | ||
@Mod.EventBusSubscriber | ||
public class TranscendPotions { | ||
private TranscendPotions(){} | ||
|
||
@Nonnull | ||
@SuppressWarnings("ConstantConditions") | ||
private static <T> T placeholder(){return null;} | ||
|
||
public static final Potion time_stop = placeholder(); | ||
|
||
public static void registerPotion(IForgeRegistry<Potion> registry,String name,Potion potion) { | ||
potion.setRegistryName(Reference.MOD_ID,name); | ||
potion.setPotionName("potion."+potion.getRegistryName().toString()); | ||
registry.register(potion); | ||
} | ||
|
||
@SubscribeEvent | ||
public static void register(RegistryEvent.Register<Potion> event){ | ||
IForgeRegistry<Potion> registry = event.getRegistry(); | ||
registerPotion(registry,"time_stop",new TimeStopEffect(false,0x3bebb).setBeneficial()); | ||
} | ||
} |
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.