Files
LegacyRenouveau/Minecraft.World/MinecartHopper.h
T
Anaël d8d65bcd49 game loop: Refactor the tooltips loop
Moved the whole logic to a new file (TooltipManager.cpp), and rewrote most of the logic to profit from object oriented programming. The side-effect is that the changes are scattered across entities, tiles and items because moving everything to OOP requires to add the tooltip to every .cpp file for every tile/item/entities (or their class, on plants for example which all use the tooltip IDS_TOOLTIPS_PLANT)

The issue with the default tooltips loop written by 4J is that:

    Its running in the main Minecraft::tick loop and is more than a thousand lines long, polluting the function.
    Not using C++'s full potential with object oriented programming, 4J decided to use a big switch case (probably because it could run better on hardware without branch prediction like the WiiU or Xbox 360 ?)
    And seems to be better off in its own file than in the main Minecraft.cpp file
2026-10-04 20:54:24 +02:00

69 lines
2.6 KiB
C++

#pragma once
#include "MinecartContainer.h"
#include "Hopper.h"
class MinecartHopper : public MinecartContainer, public Hopper
{
public:
eINSTANCEOF GetType() { return eTYPE_MINECART_HOPPER; };
static Entity *create(Level *level) { return new MinecartHopper(level); }
public:
static const int MOVE_ITEM_SPEED;
private:
bool enabled;
int cooldownTime;
void _init();
public:
MinecartHopper(Level *level);
MinecartHopper(Level *level, double x, double y, double z);
virtual int getType();
virtual Tile *getDefaultDisplayTile();
virtual int getDefaultDisplayOffset();
virtual unsigned int getContainerSize();
virtual bool interact(shared_ptr<Player> player);
virtual void activateMinecart(int xt, int yt, int zt, bool state);
virtual bool isEnabled();
virtual void setEnabled(bool enabled);
virtual Level *getLevel();
virtual double getLevelX();
virtual double getLevelY();
virtual double getLevelZ();
virtual void tick();
virtual bool suckInItems();
virtual void destroy(DamageSource *source);
protected:
virtual void addAdditonalSaveData(CompoundTag *base);
virtual void readAdditionalSaveData(CompoundTag *base);
public:
void setCooldown(int time);
bool isOnCooldown();
// 4J For Hopper
virtual shared_ptr<ItemInstance> getItem(unsigned int slot) { return MinecartContainer::getItem(slot); }
virtual shared_ptr<ItemInstance> removeItem(unsigned int slot, int count) { return MinecartContainer::removeItem(slot, count); }
virtual shared_ptr<ItemInstance> removeItemNoUpdate(int slot) { return MinecartContainer::removeItemNoUpdate(slot); }
virtual void setItem(unsigned int slot, shared_ptr<ItemInstance> item) { MinecartContainer::setItem(slot, item); }
virtual wstring getName() { return MinecartContainer::getName(); }
virtual wstring getCustomName() { return MinecartContainer::getCustomName(); }
virtual bool hasCustomName() { return MinecartContainer::hasCustomName(); }
virtual int getMaxStackSize() const { return MinecartContainer::getMaxStackSize(); }
virtual void setChanged() { MinecartContainer::setChanged(); }
virtual bool stillValid(shared_ptr<Player> player) { return MinecartContainer::stillValid(player); }
virtual void startOpen() { MinecartContainer::startOpen(); }
virtual void stopOpen() { MinecartContainer::stopOpen(); }
virtual bool canPlaceItem(int slot, shared_ptr<ItemInstance> item) { return MinecartContainer::canPlaceItem(slot, item); }
virtual int getAttackTooltipId(std::shared_ptr<Player> player);
virtual int getInteractTooltipId(Level *level,
std::shared_ptr<Player> player,
std::shared_ptr<ItemInstance> heldItem);
};