mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-21 20:52:20 +00:00
Merge branch 'master' of github.com:Vazkii/Botania into 1.13
This commit is contained in:
commit
5713b91177
7 files changed
+144
-82
No files matched your search
@@ -14,18 +14,23 @@ import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.event.entity.player.PlayerEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import vazkii.botania.api.lexicon.LexiconEntry;
|
||||
import vazkii.botania.api.subtile.RadiusDescriptor;
|
||||
import vazkii.botania.api.subtile.SubTileFunctional;
|
||||
import vazkii.botania.api.subtile.SubTileType;
|
||||
import vazkii.botania.common.Botania;
|
||||
import vazkii.botania.common.lexicon.LexiconData;
|
||||
import vazkii.botania.common.network.PacketHandler;
|
||||
import vazkii.botania.common.network.PacketItemAge;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -163,4 +168,13 @@ public class SubTileDaffomill extends SubTileFunctional {
|
||||
windTicks = cmp.getInt(TAG_WIND_TICKS);
|
||||
}
|
||||
|
||||
// Send item age to client to prevent client desync when an item is e.g. dropped by a powered open crate
|
||||
@SubscribeEvent
|
||||
public static void onItemTrack(PlayerEvent.StartTracking evt) {
|
||||
if(evt.getTarget() instanceof EntityItem) {
|
||||
int entityId = evt.getTarget().getEntityId();
|
||||
int age = ((EntityItem) evt.getTarget()).age;
|
||||
PacketHandler.sendTo((EntityPlayerMP) evt.getEntityPlayer(), new PacketItemAge(entityId, age));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -124,8 +124,10 @@ public class TileCraftCrate extends TileOpenCrate {
|
||||
List<ItemStack> remainders = recipe.getRemainingItems(craft);
|
||||
for(int i = 0; i < craft.getSizeInventory(); i++) {
|
||||
ItemStack s = remainders.get(i);
|
||||
if(!s.isEmpty())
|
||||
itemHandler.setStackInSlot(i, s);
|
||||
if(!itemHandler.getStackInSlot(i).isEmpty()
|
||||
&& itemHandler.getStackInSlot(i).getItem() == ModItems.placeholder)
|
||||
continue;
|
||||
itemHandler.setStackInSlot(i, s);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -60,6 +60,7 @@ import vazkii.botania.common.network.PacketBotaniaEffect;
|
||||
import vazkii.botania.common.network.PacketHandler;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumMap;
|
||||
import java.util.List;
|
||||
@@ -156,6 +157,76 @@ public class TileEnchanter extends TileMod implements ISparkAttachable, ITickabl
|
||||
}
|
||||
}
|
||||
|
||||
private void gatherEnchants() {
|
||||
if(!world.isRemote && stageTicks % 20 == 0) {
|
||||
List<EntityItem> items = world.getEntitiesWithinAABB(EntityItem.class, new AxisAlignedBB(pos.getX() - 2, pos.getY(), pos.getZ() - 2, pos.getX() + 3, pos.getY() + 1, pos.getZ() + 3));
|
||||
boolean addedEnch = false;
|
||||
|
||||
for(EntityItem entity : items) {
|
||||
ItemStack item = entity.getItem();
|
||||
if(item.getItem() == Items.ENCHANTED_BOOK) {
|
||||
NBTTagList enchants = ItemEnchantedBook.getEnchantments(item);
|
||||
if(enchants.size() > 0) {
|
||||
NBTTagCompound enchant = enchants.getCompound(0);
|
||||
short enchantId = enchant.getShort("id");
|
||||
short enchantLvl = enchant.getShort("lvl");
|
||||
Enchantment ench = Enchantment.getEnchantmentByID(enchantId);
|
||||
if(!hasEnchantAlready(ench) && isEnchantmentValid(ench)) {
|
||||
this.enchants.add(new EnchantmentData(ench, enchantLvl));
|
||||
world.playSound(null, pos, ModSounds.ding, SoundCategory.BLOCKS, 1F, 1F);
|
||||
addedEnch = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!addedEnch) {
|
||||
if(enchants.isEmpty())
|
||||
stage = State.IDLE;
|
||||
else advanceStage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void gatherMana(EnumFacing.Axis axis) {
|
||||
if(manaRequired == -1) {
|
||||
manaRequired = 0;
|
||||
for(EnchantmentData data : enchants) {
|
||||
manaRequired += (int)
|
||||
(5000F * ((15 - Math.min(15, data.enchantment.getRarity().getWeight()))
|
||||
* 1.05F)
|
||||
* ((3F + data.enchantmentLevel * data.enchantmentLevel)
|
||||
* 0.25F)
|
||||
* (0.9F + enchants.size() * 0.05F)
|
||||
* (data.enchantment.isTreasureEnchantment() ? 1.25F : 1F));
|
||||
}
|
||||
} else if(mana >= manaRequired) {
|
||||
manaRequired = 0;
|
||||
for(BlockPos pylon : PYLON_LOCATIONS.get(axis)) {
|
||||
TileEntity te = world.getTileEntity(pos.add(pylon));
|
||||
if(te instanceof TilePylon)
|
||||
((TilePylon) te).activated = false;
|
||||
}
|
||||
|
||||
advanceStage();
|
||||
} else {
|
||||
ISparkEntity spark = getAttachedSpark();
|
||||
if(spark != null) {
|
||||
List<ISparkEntity> sparkEntities = SparkHelper.getSparksAround(world, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5);
|
||||
for(ISparkEntity otherSpark : sparkEntities) {
|
||||
if(spark == otherSpark)
|
||||
continue;
|
||||
|
||||
if(otherSpark.getAttachedTile() != null && otherSpark.getAttachedTile() instanceof IManaPool)
|
||||
otherSpark.registerTransfer(spark);
|
||||
}
|
||||
}
|
||||
if(stageTicks % 5 == 0)
|
||||
sync();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
IBlockState state = world.getBlockState(getPos());
|
||||
@@ -163,7 +234,7 @@ public class TileEnchanter extends TileMod implements ISparkAttachable, ITickabl
|
||||
|
||||
for(BlockPos pylon : PYLON_LOCATIONS.get(axis)) {
|
||||
TileEntity tile = world.getTileEntity(pos.add(pylon));
|
||||
if(tile != null && tile instanceof TilePylon) {
|
||||
if(tile instanceof TilePylon) {
|
||||
((TilePylon) tile).activated = stage == State.GATHER_MANA;
|
||||
if(stage == State.GATHER_MANA)
|
||||
((TilePylon) tile).centerPos = pos;
|
||||
@@ -184,77 +255,8 @@ public class TileEnchanter extends TileMod implements ISparkAttachable, ITickabl
|
||||
}
|
||||
|
||||
switch(stage) {
|
||||
case GATHER_ENCHANTS : { // Get books
|
||||
if(stageTicks % 20 == 0) {
|
||||
List<EntityItem> items = world.getEntitiesWithinAABB(EntityItem.class, new AxisAlignedBB(pos.getX() - 2, pos.getY(), pos.getZ() - 2, pos.getX() + 3, pos.getY() + 1, pos.getZ() + 3));
|
||||
int count = items.size();
|
||||
boolean addedEnch = false;
|
||||
|
||||
if(count > 0 && !world.isRemote) {
|
||||
for(EntityItem entity : items) {
|
||||
ItemStack item = entity.getItem();
|
||||
if(item.getItem() == Items.ENCHANTED_BOOK) {
|
||||
NBTTagList enchants = ItemEnchantedBook.getEnchantments(item);
|
||||
if(enchants.size() > 0) {
|
||||
NBTTagCompound enchant = enchants.getCompound(0);
|
||||
short enchantId = enchant.getShort("id");
|
||||
short enchantLvl = enchant.getShort("lvl");
|
||||
Enchantment ench = Enchantment.getEnchantmentByID(enchantId);
|
||||
if(!hasEnchantAlready(ench) && isEnchantmentValid(ench)) {
|
||||
this.enchants.add(new EnchantmentData(ench, enchantLvl));
|
||||
world.playSound(null, pos, ModSounds.ding, SoundCategory.BLOCKS, 1F, 1F);
|
||||
addedEnch = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!addedEnch) {
|
||||
if(enchants.isEmpty())
|
||||
stage = State.IDLE;
|
||||
else advanceStage();
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case GATHER_MANA : { // Get Mana
|
||||
if(manaRequired == -1) {
|
||||
manaRequired = 0;
|
||||
for(EnchantmentData data : enchants) {
|
||||
manaRequired += (int)
|
||||
(5000F * ((15 - Math.min(15, data.enchantment.getRarity().getWeight()))
|
||||
* 1.05F)
|
||||
* ((3F + data.enchantmentLevel * data.enchantmentLevel)
|
||||
* 0.25F)
|
||||
* (0.9F + enchants.size() * 0.05F)
|
||||
* (data.enchantment.isTreasureEnchantment() ? 1.25F : 1F));
|
||||
}
|
||||
} else if(mana >= manaRequired) {
|
||||
manaRequired = 0;
|
||||
for(BlockPos pylon : PYLON_LOCATIONS.get(axis))
|
||||
((TilePylon) world.getTileEntity(pos.add(pylon))).activated = false;
|
||||
|
||||
advanceStage();
|
||||
} else {
|
||||
ISparkEntity spark = getAttachedSpark();
|
||||
if(spark != null) {
|
||||
List<ISparkEntity> sparkEntities = SparkHelper.getSparksAround(world, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5);
|
||||
for(ISparkEntity otherSpark : sparkEntities) {
|
||||
if(spark == otherSpark)
|
||||
continue;
|
||||
|
||||
if(otherSpark.getAttachedTile() != null && otherSpark.getAttachedTile() instanceof IManaPool)
|
||||
otherSpark.registerTransfer(spark);
|
||||
}
|
||||
}
|
||||
if(stageTicks % 5 == 0)
|
||||
sync();
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case GATHER_ENCHANTS : gatherEnchants(); break;
|
||||
case GATHER_MANA : gatherMana(axis); break;
|
||||
case DO_ENCHANT : { // Enchant
|
||||
if(stageTicks >= 100) {
|
||||
for(EnchantmentData data : enchants)
|
||||
@@ -362,8 +364,7 @@ public class TileEnchanter extends TileMod implements ISparkAttachable, ITickabl
|
||||
|
||||
NBTTagCompound itemCmp = new NBTTagCompound();
|
||||
if(!itemToEnchant.isEmpty())
|
||||
itemCmp = itemToEnchant.write(itemCmp);
|
||||
cmp.put(TAG_ITEM, itemCmp);
|
||||
cmp.put(TAG_ITEM, itemToEnchant.write(itemCmp));
|
||||
|
||||
String enchStr = enchants.stream()
|
||||
.map(e -> ForgeRegistries.ENCHANTMENTS.getKey(e.enchantment) + "=" + e.enchantmentLevel)
|
||||
@@ -391,7 +392,8 @@ public class TileEnchanter extends TileMod implements ISparkAttachable, ITickabl
|
||||
String[] entryTokens = token.split("=");
|
||||
Enchantment ench = ForgeRegistries.ENCHANTMENTS.getValue(new ResourceLocation(entryTokens[0]));
|
||||
int lvl = Integer.parseInt(entryTokens[1]);
|
||||
enchants.add(new EnchantmentData(ench, lvl));
|
||||
if(ench != null)
|
||||
enchants.add(new EnchantmentData(ench, lvl));
|
||||
} catch (ResourceLocationException ignored) {}
|
||||
}
|
||||
}
|
||||
@@ -405,8 +407,8 @@ public class TileEnchanter extends TileMod implements ISparkAttachable, ITickabl
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isEnchantmentValid(Enchantment ench) {
|
||||
if(!ench.canApply(itemToEnchant))
|
||||
private boolean isEnchantmentValid(@Nullable Enchantment ench) {
|
||||
if(ench == null || !ench.canApply(itemToEnchant))
|
||||
return false;
|
||||
|
||||
for(EnchantmentData data : enchants) {
|
||||
|
||||
@@ -90,7 +90,6 @@ public class ItemHorn extends ItemMod {
|
||||
type = EnumHornType.COVERING;
|
||||
}
|
||||
|
||||
Random rand = new Random(srcPos.hashCode());
|
||||
int range = 12 - type.ordinal() * 3;
|
||||
int rangeY = 3 + type.ordinal() * 4;
|
||||
List<BlockPos> coords = new ArrayList<>();
|
||||
@@ -105,7 +104,7 @@ public class ItemHorn extends ItemMod {
|
||||
coords.add(pos);
|
||||
}
|
||||
|
||||
Collections.shuffle(coords, rand);
|
||||
Collections.shuffle(coords, world.rand);
|
||||
|
||||
int count = Math.min(coords.size(), 32 + type.ordinal() * 16);
|
||||
for(int i = 0; i < count; i++) {
|
||||
|
||||
@@ -27,6 +27,7 @@ public final class PacketHandler {
|
||||
HANDLER.registerMessage(id++, PacketLeftClick.class, PacketLeftClick::encode, PacketLeftClick::decode, PacketLeftClick::handle);
|
||||
HANDLER.registerMessage(id++, PacketDodge.class, PacketDodge::encode, PacketDodge::decode, PacketDodge::handle);
|
||||
HANDLER.registerMessage(id++, PacketJump.class, PacketJump::encode, PacketJump::decode, PacketJump::handle);
|
||||
HANDLER.registerMessage(id++, PacketItemAge.class, PacketItemAge::encode, PacketItemAge::decode, PacketItemAge::handle);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
package vazkii.botania.common.network;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraftforge.fml.network.NetworkEvent;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class PacketItemAge {
|
||||
private final int entityId;
|
||||
private final int age;
|
||||
|
||||
public PacketItemAge(int entityId, int age) {
|
||||
this.entityId = entityId;
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
public static PacketItemAge decode(PacketBuffer buf) {
|
||||
return new PacketItemAge(buf.readVarInt(), buf.readVarInt());
|
||||
}
|
||||
|
||||
public static void encode(PacketItemAge msg, PacketBuffer buf) {
|
||||
buf.writeVarInt(msg.entityId);
|
||||
buf.writeVarInt(msg.age);
|
||||
}
|
||||
|
||||
public static void handle(PacketItemAge message, Supplier<NetworkEvent.Context> ctx) {
|
||||
ctx.get().enqueueWork(() -> {
|
||||
Entity e = Minecraft.getInstance().world.getEntityByID(message.entityId);
|
||||
if(e instanceof EntityItem) {
|
||||
((EntityItem) e).age = message.age;
|
||||
}
|
||||
});
|
||||
ctx.get().setPacketHandled(true);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user