aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.World/MinecartFurnace.cpp
diff options
context:
space:
mode:
authordaoge <3523206925@qq.com>2026-03-03 03:04:10 +0800
committerGitHub <noreply@github.com>2026-03-03 03:04:10 +0800
commitb3feddfef372618c8a9d7a0abcaf18cfad866c18 (patch)
tree267761c3bb39241ba5c347bfbe2254d06686e287 /Minecraft.World/MinecartFurnace.cpp
parent84c31a2331f7a0ec85b9d438992e244f60e5020f (diff)
feat: TU19 (Dec 2014) Features & Content (#155)
* try to resolve merge conflict * feat: TU19 (Dec 2014) Features & Content (#32) * December 2014 files * Working release build * Fix compilation issues * Add sound to Windows64Media * Add DLC content and force Tutorial DLC * Revert "Add DLC content and force Tutorial DLC" This reverts commit 97a43994725008e35fceb984d5549df9c8cea470. * Disable broken light packing * Disable breakpoint during DLC texture map load Allows DLC loading but the DLC textures are still broken * Fix post build not working * ... * fix vs2022 build * fix cmake build --------- Co-authored-by: Loki <lokirautio@gmail.com>
Diffstat (limited to 'Minecraft.World/MinecartFurnace.cpp')
-rw-r--r--Minecraft.World/MinecartFurnace.cpp179
1 files changed, 179 insertions, 0 deletions
diff --git a/Minecraft.World/MinecartFurnace.cpp b/Minecraft.World/MinecartFurnace.cpp
new file mode 100644
index 00000000..24950d5c
--- /dev/null
+++ b/Minecraft.World/MinecartFurnace.cpp
@@ -0,0 +1,179 @@
+#include "stdafx.h"
+#include "net.minecraft.world.damagesource.h"
+#include "net.minecraft.world.entity.h"
+#include "net.minecraft.world.entity.player.h"
+#include "net.minecraft.world.level.h"
+#include "net.minecraft.world.item.h"
+#include "net.minecraft.network.packet.h"
+#include "MinecartFurnace.h"
+
+MinecartFurnace::MinecartFurnace(Level *level) : Minecart(level)
+{
+ defineSynchedData();
+
+ fuel = 0;
+ xPush = zPush = 0.0f;
+}
+
+MinecartFurnace::MinecartFurnace(Level *level, double x, double y, double z) : Minecart(level, x, y, z)
+{
+ defineSynchedData();
+
+ fuel = 0;
+ xPush = zPush = 0.0f;
+}
+
+// 4J Added
+int MinecartFurnace::getContainerType()
+{
+ return ContainerOpenPacket::MINECART_HOPPER;
+}
+
+int MinecartFurnace::getType()
+{
+ return TYPE_FURNACE;
+}
+
+void MinecartFurnace::defineSynchedData()
+{
+ Minecart::defineSynchedData();
+ entityData->define(DATA_ID_FUEL, (byte) 0);
+}
+
+void MinecartFurnace::tick()
+{
+ Minecart::tick();
+
+ if (fuel > 0)
+ {
+ fuel--;
+ }
+ if (fuel <= 0)
+ {
+ xPush = zPush = 0;
+ }
+ setHasFuel(fuel > 0);
+
+ if (hasFuel() && random->nextInt(4) == 0)
+ {
+ level->addParticle(eParticleType_largesmoke, x, y + 0.8, z, 0, 0, 0);
+ }
+}
+
+void MinecartFurnace::destroy(DamageSource *source)
+{
+ Minecart::destroy(source);
+
+ if (!source->isExplosion())
+ {
+ spawnAtLocation(shared_ptr<ItemInstance>(new ItemInstance(Tile::furnace, 1)), 0);
+ }
+}
+
+void MinecartFurnace::moveAlongTrack(int xt, int yt, int zt, double maxSpeed, double slideSpeed, int tile, int data)
+{
+ Minecart::moveAlongTrack(xt, yt, zt, maxSpeed, slideSpeed, tile, data);
+
+ double sd = xPush * xPush + zPush * zPush;
+ if (sd > 0.01 * 0.01 && xd * xd + zd * zd > 0.001)
+ {
+ sd = Mth::sqrt(sd);
+ xPush /= sd;
+ zPush /= sd;
+
+ if (xPush * xd + zPush * zd < 0)
+ {
+ xPush = 0;
+ zPush = 0;
+ }
+ else
+ {
+ xPush = xd;
+ zPush = zd;
+ }
+ }
+}
+
+void MinecartFurnace::applyNaturalSlowdown()
+{
+ double sd = xPush * xPush + zPush * zPush;
+
+ if (sd > 0.01 * 0.01)
+ {
+ sd = Mth::sqrt(sd);
+ xPush /= sd;
+ zPush /= sd;
+ double speed = 0.05;
+ xd *= 0.8f;
+ yd *= 0;
+ zd *= 0.8f;
+ xd += xPush * speed;
+ zd += zPush * speed;
+ }
+ else
+ {
+ xd *= 0.98f;
+ yd *= 0;
+ zd *= 0.98f;
+ }
+
+ Minecart::applyNaturalSlowdown();
+}
+
+bool MinecartFurnace::interact(shared_ptr<Player> player)
+{
+ shared_ptr<ItemInstance> selected = player->inventory->getSelected();
+ if (selected != NULL && selected->id == Item::coal_Id)
+ {
+ if (!player->abilities.instabuild && --selected->count == 0) player->inventory->setItem(player->inventory->selected, nullptr);
+ fuel += SharedConstants::TICKS_PER_SECOND * 180;
+
+ }
+ xPush = x - player->x;
+ zPush = z - player->z;
+
+ return true;
+}
+
+void MinecartFurnace::addAdditonalSaveData(CompoundTag *base)
+{
+ Minecart::addAdditonalSaveData(base);
+ base->putDouble(L"PushX", xPush);
+ base->putDouble(L"PushZ", zPush);
+ base->putShort(L"Fuel", (short) fuel);
+}
+
+void MinecartFurnace::readAdditionalSaveData(CompoundTag *base)
+{
+ Minecart::readAdditionalSaveData(base);
+ xPush = base->getDouble(L"PushX");
+ zPush = base->getDouble(L"PushZ");
+ fuel = base->getShort(L"Fuel");
+}
+
+bool MinecartFurnace::hasFuel()
+{
+ return (entityData->getByte(DATA_ID_FUEL) & 1) != 0;
+}
+
+void MinecartFurnace::setHasFuel(bool fuel)
+{
+ if (fuel)
+ {
+ entityData->set(DATA_ID_FUEL, (byte) (entityData->getByte(DATA_ID_FUEL) | 1));
+ }
+ else
+ {
+ entityData->set(DATA_ID_FUEL, (byte) (entityData->getByte(DATA_ID_FUEL) & ~1));
+ }
+}
+
+Tile *MinecartFurnace::getDefaultDisplayTile()
+{
+ return Tile::furnace_lit;
+}
+
+int MinecartFurnace::getDefaultDisplayData()
+{
+ return 2;
+} \ No newline at end of file