Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Neuter instability orb, prevent usage of .add() on WeightedList (use addAll() instead) #13

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//version: 1671313514
//version: 1673027205
/*
DO NOT CHANGE THIS FILE!
Also, you may replace this file at any time if there is an update available.
Expand Down Expand Up @@ -46,7 +46,7 @@ buildscript {
}
dependencies {
//Overwrite the current ASM version to fix shading newer than java 8 applicatations.
classpath 'org.ow2.asm:asm-debug-all-custom:5.0.3'
classpath 'org.ow2.asm:asm-debug-all-custom:5.0.3'
classpath 'net.minecraftforge.gradle:ForgeGradle:1.2.13'
}
}
Expand Down Expand Up @@ -319,9 +319,13 @@ if (file('addon.gradle').exists()) {
apply from: 'repositories.gradle'

configurations {
implementation.extendsFrom(shadowImplementation) // TODO: remove after all uses are refactored
implementation.extendsFrom(shadowCompile)
implementation.extendsFrom(shadeCompile)
// TODO: remove Compile after all uses are refactored to Implementation
for (config in [shadowImplementation, shadowCompile, shadeCompile]) {
compileClasspath.extendsFrom(config)
runtimeClasspath.extendsFrom(config)
testCompileClasspath.extendsFrom(config)
testRuntimeClasspath.extendsFrom(config)
}
}

repositories {
Expand Down Expand Up @@ -350,7 +354,8 @@ dependencies {
annotationProcessor('com.google.code.gson:gson:2.8.6')
annotationProcessor('com.gtnewhorizon:gtnhmixins:2.1.3:processor')
if (usesMixinDebug.toBoolean()) {
runtimeOnly('org.jetbrains:intellij-fernflower:1.2.1.16')
runtimeClasspath('org.jetbrains:intellij-fernflower:1.2.1.16')
testRuntimeClasspath('org.jetbrains:intellij-fernflower:1.2.1.16')
}
}
if (usesMixins.toBoolean() || forceEnableMixins.toBoolean()) {
Expand Down
157 changes: 6 additions & 151 deletions src/main/java/chylex/hee/entity/item/EntityItemInstabilityOrb.java
Original file line number Diff line number Diff line change
@@ -1,32 +1,17 @@
package chylex.hee.entity.item;

import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.enchantment.EnchantmentProtection;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.DamageSource;
import net.minecraft.util.MathHelper;
import net.minecraft.util.Vec3;
import net.minecraft.util.WeightedRandomChestContent;
import net.minecraft.world.ChunkPosition;
import net.minecraft.world.Explosion;
import net.minecraft.world.World;
import net.minecraftforge.common.ChestGenHooks;
import chylex.hee.HardcoreEnderExpansion;
import chylex.hee.entity.fx.FXType;
import chylex.hee.mechanics.orb.WeightedItem;
import chylex.hee.packets.PacketPipeline;
import chylex.hee.packets.client.C21EffectEntity;
import chylex.hee.system.util.BlockPosM;

import java.util.HashMap;
import java.util.Map;

public class EntityItemInstabilityOrb extends EntityItem{
public EntityItemInstabilityOrb(World world){
Expand All @@ -49,54 +34,12 @@ public EntityItemInstabilityOrb(World world, double x, double y, double z, ItemS

@Override
public void onUpdate(){
/* Yeet */
super.onUpdate();

if (!worldObj.isRemote){
age += 1+rand.nextInt(2+rand.nextInt(4))*rand.nextInt(3);
if (age >= 666)detonate();
}
else{
int chance = age/17-7;
for(int a = 0; a < Math.min(7,(chance <= 0 ? (rand.nextInt(Math.abs(chance)+1) == 0 ? 1 : 0) : chance)); a++){
HardcoreEnderExpansion.fx.instability(this);
}

if (rand.nextInt(3+Math.max(0,(int)((680F-age)/70F))) == 0)worldObj.playSound(posX,posY,posZ,"random.pop",0.15F+rand.nextFloat()*0.1F,0.7F+rand.nextFloat()*0.6F,false);
}
}

private void detonate() {
if (rand.nextInt(6) == 0) {
ExplosionOrb explosion = new ExplosionOrb(worldObj,this,posX,posY,posZ,0.1F);
explosion.doExplosionA();
explosion.doExplosionB(true);
PacketPipeline.sendToAllAround(this,64D,new C21EffectEntity(FXType.Entity.ORB_EXPLOSION,posX,posY,posZ,0F,explosion.explosionSize));
} else {
WeightedItem item = null;
String[] list = new String[]{
ChestGenHooks.DUNGEON_CHEST, ChestGenHooks.BONUS_CHEST, ChestGenHooks.MINESHAFT_CORRIDOR,
ChestGenHooks.VILLAGE_BLACKSMITH, ChestGenHooks.PYRAMID_DESERT_CHEST, ChestGenHooks.PYRAMID_JUNGLE_CHEST,
ChestGenHooks.STRONGHOLD_LIBRARY, ChestGenHooks.STRONGHOLD_CORRIDOR
};

WeightedRandomChestContent[] content = ChestGenHooks.getItems(list[rand.nextInt(list.length)],rand);
if (content.length == 0)
return;

ItemStack is = content[rand.nextInt(content.length)].theItemId;
item = new WeightedItem(is.getItem(),is.getItemDamage(),1);

int meta = item.getDamageValues()[rand.nextInt(item.getDamageValues().length)];
if (meta == 32767)
meta = 0;

EntityItem entityitem = new EntityItem(worldObj,posX,posY,posZ,new ItemStack(item.getItem(),1,meta));
entityitem.motionX = entityitem.motionY = entityitem.motionZ = 0D;
entityitem.delayBeforeCanPickup = 10;
worldObj.spawnEntityInWorld(entityitem);

PacketPipeline.sendToAllAround(this,64D,new C21EffectEntity(FXType.Entity.ORB_TRANSFORMATION,posX,posY,posZ,0.25F,0.4F));
}
/* Yeet */
setDead();
}

Expand Down Expand Up @@ -131,95 +74,7 @@ public ExplosionOrb(World world, Entity sourceEntity, double x, double y, double

@Override
public void doExplosionA(){
float explosionSizeBackup = explosionSize;

HashSet<ChunkPosition> affectedBlocks = new HashSet<>();
double tempX, tempY, tempZ, distX, distY, distZ, totalDist;
BlockPosM testPos = new BlockPosM();

for(int x = 0; x < dist; ++x){
for(int y = 0; y < dist; ++y){
for(int z = 0; z < dist; ++z){
if (x == 0 || x == dist-1 || y == 0 || y == dist-1 || z == 0 || z == dist-1){
distX = (x/(dist-1F)*2F-1F);
distY = (y/(dist-1F)*2F-1F);
distZ = (z/(dist-1F)*2F-1F);
totalDist = Math.sqrt(distX*distX+distY*distY+distZ*distZ);

distX /= totalDist;
distY /= totalDist;
distZ /= totalDist;

float affectedDistance = explosionSize*(0.7F+worldObj.rand.nextFloat()*0.6F);
tempX = explosionX;
tempY = explosionY;
tempZ = explosionZ;

for(float mp = 0.3F; affectedDistance > 0F; affectedDistance -= mp*0.75F){
testPos.set(tempX,tempY,tempZ);
Block block = testPos.getBlock(worldObj);

if (block.getMaterial() != Material.air){
float resistance = exploder != null ? exploder.func_145772_a(this,worldObj,testPos.x,testPos.y,testPos.z,block) : block.getExplosionResistance(exploder,worldObj,testPos.x,testPos.y,testPos.z,explosionX,explosionY,explosionZ);
affectedDistance -= (resistance+0.3F)*mp;
}

if (affectedDistance > 0F && (exploder == null || exploder.func_145774_a(this,worldObj,testPos.x,testPos.y,testPos.z,block,affectedDistance))){
affectedBlocks.add(new ChunkPosition(testPos.x,testPos.y,testPos.z));
}

tempX += distX*mp;
tempY += distY*mp;
tempZ += distZ*mp;
}
}
}
}
}

affectedBlockPositions.addAll(affectedBlocks);
explosionSize *= 2F;

int minX = MathHelper.floor_double(explosionX-explosionSize-1D), maxX = MathHelper.floor_double(explosionX+explosionSize+1D);
int minY = MathHelper.floor_double(explosionY-explosionSize-1D), maxY = MathHelper.floor_double(explosionY+explosionSize+1D);
int minZ = MathHelper.floor_double(explosionZ-explosionSize-1D), maxZ = MathHelper.floor_double(explosionZ+explosionSize+1D);

List<Entity> entities = worldObj.getEntitiesWithinAABBExcludingEntity(exploder,AxisAlignedBB.getBoundingBox(minX,minY,minZ,maxX,maxY,maxZ));
Vec3 locationVec = Vec3.createVectorHelper(explosionX,explosionY,explosionZ);

for(int a = 0; a < entities.size(); ++a){
Entity entity = entities.get(a);
double entityDist = entity.getDistance(explosionX,explosionY,explosionZ)/explosionSize;

if (entityDist <= 1D){
tempX = entity.posX-explosionX;
tempY = entity.posY+entity.getEyeHeight()-explosionY;
tempZ = entity.posZ-explosionZ;
totalDist = MathHelper.sqrt_double(tempX*tempX+tempY*tempY+tempZ*tempZ);

if (totalDist != 0D){
tempX /= totalDist;
tempY /= totalDist;
tempZ /= totalDist;

double blastPower = (1D-entityDist)*worldObj.getBlockDensity(locationVec,entity.boundingBox);

if (canDamageEntity(entity))entity.attackEntityFrom(DamageSource.setExplosionSource(this),((int)((blastPower*blastPower+blastPower)/2D*8D*explosionSize+1D)));
else continue;

double knockbackMp = EnchantmentProtection.func_92092_a(entity,blastPower);
entity.motionX += tempX*knockbackMp;
entity.motionY += tempY*knockbackMp;
entity.motionZ += tempZ*knockbackMp;

if (entity instanceof EntityPlayer){
hurtPlayers.put((EntityPlayer)entity,Vec3.createVectorHelper(tempX*blastPower,tempY*blastPower,tempZ*blastPower));
}
}
}
}

explosionSize = explosionSizeBackup;
/* Yeet */
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import java.util.IdentityHashMap;
import java.util.List;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.SortedSet;
import java.util.stream.IntStream;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.enchantment.Enchantment;
Expand Down Expand Up @@ -204,16 +207,17 @@ else if (is.isItemEnchanted() && is.getItem() != Items.enchanted_book){
if (enchants == null || enchants.tagCount() == 0)return;

for(int attempt = 0; attempt < 3; attempt++){
WeightedList<ObjectWeightPair<Enchantment>> list = new WeightedList<>();

for(int a = 0; a < enchants.tagCount(); a++){
Enchantment e = Enchantment.enchantmentsList[enchants.getCompoundTagAt(a).getShort("id")];
if (e == null)continue;

list.add(ObjectWeightPair.of(e,e.getWeight()));
}
final WeightedList<ObjectWeightPair<Enchantment>> list = new WeightedList<>();

final ObjectWeightPair<?>[] eligibleEnchants = IntStream.range(0, enchants.tagCount())
.mapToObj(i -> Enchantment.enchantmentsList[enchants.getCompoundTagAt(i).getShort("id")])
.filter(Objects::nonNull)
.map(e -> ObjectWeightPair.of(e, e.getWeight()))
.toArray(ObjectWeightPair<?>[]::new);
list.addAll((ObjectWeightPair<Enchantment>[]) eligibleEnchants);


if (list.isEmpty())continue; // the enchantments are no longer in the game
if (list.isEmpty()) continue; // the enchantments are no longer in the game

Enchantment chosenEnchantment = list.getRandomItem(item.worldObj.rand).getObject();

Expand Down
Loading