Skip to content

Commit

Permalink
add TimeStop effect and have new skill
Browse files Browse the repository at this point in the history
  • Loading branch information
huige233 committed Sep 18, 2022
1 parent 2c778db commit 3010c4e
Show file tree
Hide file tree
Showing 33 changed files with 1,266 additions and 66 deletions.
2 changes: 2 additions & 0 deletions src/main/java/huige233/transcend/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import huige233.transcend.init.ModOre;
import huige233.transcend.proxy.CommonProxy;
import huige233.transcend.util.Reference;
import huige233.transcend.util.handlers.TranscendPacketHandler;
import huige233.transcend.world.Worldgen;
import net.minecraft.block.Block;
import net.minecraft.creativetab.CreativeTabs;
Expand Down Expand Up @@ -55,6 +56,7 @@ public void preinit(FMLPreInitializationEvent event) {
*/
@Mod.EventHandler
public void init(FMLInitializationEvent event) {
TranscendPacketHandler.initPackets();
proxy.init(event);
}

Expand Down
25 changes: 25 additions & 0 deletions src/main/java/huige233/transcend/blocks/bedrockorz.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,21 @@
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.effect.EntityLightningBolt;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.util.DamageSource;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.event.world.BlockEvent;
import net.minecraftforge.fml.common.eventhandler.EventPriority;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

import java.util.List;
import java.util.Random;

public class bedrockorz extends BlockBase{
Expand Down Expand Up @@ -44,4 +54,19 @@ public int quantityDropped(Random random) {
public boolean canEntityDestroy(IBlockState state, IBlockAccess world, BlockPos pos, Entity entity) {
return false;
}

@SubscribeEvent(priority = EventPriority.HIGHEST)
public void onBlockBreak(BlockEvent.BreakEvent event){
event.setCanceled(true);
}

public void updateTick(World world, BlockPos pos, IBlockState state, Random rand){
int range = 20;
List<Entity> list = world.getEntitiesWithinAABB(EntityPlayer.class,new AxisAlignedBB(pos.getX() - range, pos.getY() - range, pos.getZ() - range, pos.getX() + range, pos.getY() + range, pos.getZ() + range));
for(Entity en : list) {
world.addWeatherEffect(new EntityLightningBolt(world,pos.getX(),pos.getY(),pos.getZ(),false));
((EntityPlayer)en).setHealth(0);
}
}

}
12 changes: 12 additions & 0 deletions src/main/java/huige233/transcend/blocks/voidblock.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.effect.EntityLightningBolt;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.util.DamageSource;
import net.minecraft.util.EnumBlockRenderType;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.event.world.BlockEvent;
import net.minecraftforge.fml.common.eventhandler.EventPriority;
Expand Down Expand Up @@ -74,6 +78,14 @@ public boolean canEntityDestroy(IBlockState state, IBlockAccess world, BlockPos
return false;
}

@Override
public void onEntityCollision(World world, BlockPos pos, IBlockState state, Entity entity){
world.addWeatherEffect(new EntityLightningBolt(world, pos.getX(),pos.getY(),pos.getZ(),false));
if(entity instanceof EntityLivingBase) {
((EntityLivingBase)entity).getCombatTracker().trackDamage(new DamageSource("outOfWorld"), Float.MAX_VALUE, Float.MAX_VALUE);
}
}

@SubscribeEvent(priority = EventPriority.HIGHEST)
public void onBlockBreak(BlockEvent.BreakEvent event){
event.setCanceled(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public static void setup() {
flawless.setCraftable(true);
flawless.addTrait(flawlesstrait);
flawless.addTrait(TinkerTraits.tasty);
flawless.addTrait(TinkerTraits.autosmelt);
TinkerRegistry.addMaterialStats(flawless,
new HeadMaterialStats(9999, 100.0f, 2000.0f, 32),
new HandleMaterialStats(10.0f, 9999),
Expand Down
148 changes: 148 additions & 0 deletions src/main/java/huige233/transcend/effect/TimeStopEffect.java
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);
}
}
}
*/
}
71 changes: 71 additions & 0 deletions src/main/java/huige233/transcend/effect/effectbase.java
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();
}

}
3 changes: 2 additions & 1 deletion src/main/java/huige233/transcend/init/ModEnchantment.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ public class ModEnchantment {
public static final Enchantment TRANSCEND = new EnchantmentTRANSCENDEnchantment();

@SubscribeEvent
public static void EnchantmentFunction(LivingUpdateEvent event) {
public static void EnchantmentFlawless(LivingUpdateEvent event) {
EntityLivingBase living = event.getEntityLiving();
int level = EnchantmentHelper.getMaxEnchantmentLevel(FLAWLESS, living);
BlockPos pos = living.getPosition();
World world = event.getEntity().world;
}

}
1 change: 1 addition & 0 deletions src/main/java/huige233/transcend/init/ModItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,5 @@ public class ModItems {
public static final ItemSword Invulnerable = new ItemInvulnerable("invulnerable",Invulnera);
public static final ItemSword TimeStop = new ItemTimeStop("timestop",Invulnera);
public static final Item TRANSCEND_SHIELD = new ItemTranscendShield("transcend_shield",Main.TranscendTab);
public static final Item ITEM_XP = new ItemXp("transcend_xp",Main.TranscendTab);
}
36 changes: 36 additions & 0 deletions src/main/java/huige233/transcend/init/TranscendPotions.java
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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public boolean hasCustomEntity(ItemStack stack) {
return true;
}
public EnumAction getItemUseAction(ItemStack stack) {
return EnumAction.BLOCK;
return EnumAction.BOW;
}
public int getMaxItemUseDuration(ItemStack stack){
return 72000;
Expand Down
Loading

0 comments on commit 3010c4e

Please sign in to comment.