Skip to content

Commit

Permalink
port: add npc salesperson
Browse files Browse the repository at this point in the history
  • Loading branch information
Kai-Z-JP committed Dec 14, 2023
1 parent 93d3ae0 commit 35c3e8b
Show file tree
Hide file tree
Showing 50 changed files with 8,304 additions and 52 deletions.
2 changes: 1 addition & 1 deletion src/main/java/jp/ngt/rtm/ClientProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public void preInit() {
ModelPackManager.INSTANCE.registerType("ModelTrain", TrainConfig.class, ModelSetTrainClient.class);
ModelPackManager.INSTANCE.registerType("ModelContainer", ContainerConfig.class, ModelSetContainerClient.class);
ModelPackManager.INSTANCE.registerType("ModelVehicle", VehicleConfig.class, ModelSetVehicleClient.class);
ModelPackManager.INSTANCE.registerType("ModelNPC", NPCConfig.class, ModelSetNPC.class);
ModelPackManager.INSTANCE.registerType("ModelNPC", NPCConfig.class, ModelSetNPCClient.class);
ModelPackManager.INSTANCE.registerType("ModelMachine", MachineConfig.class, ModelSetMachineClient.class);
ModelPackManager.INSTANCE.registerType("ModelWire", WireConfig.class, ModelSetWireClient.class);
ModelPackManager.INSTANCE.registerType("ModelConnector", ConnectorConfig.class, ModelSetConnectorClient.class);
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/jp/ngt/rtm/entity/npc/EntityNPC.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import jp.ngt.rtm.item.ItemGun.GunType;
import jp.ngt.rtm.modelpack.IModelSelector;
import jp.ngt.rtm.modelpack.ModelPackManager;
import jp.ngt.rtm.modelpack.cfg.NPCConfig;
import jp.ngt.rtm.modelpack.modelset.ModelSetNPC;
import jp.ngt.rtm.modelpack.state.ResourceState;
import jp.ngt.rtm.util.PathNavigateCustom;
Expand Down Expand Up @@ -38,6 +39,8 @@ public class EntityNPC extends EntityTameable implements IModelSelector, IRanged

protected int useItemCount;

private boolean roleChanged;

public InventoryNPC inventory = new InventoryNPC(this);

public EntityNPC(World world) {
Expand Down Expand Up @@ -183,6 +186,12 @@ protected void updateEntityActionState() {
if (this.myRole != Role.MANNEQUIN) {
super.updateEntityActionState();
}
if (this.roleChanged) {
this.roleChanged = false;
this.myRole = Role.getRole(((ModelSetNPC) this.state.getResourceSet()).getConfig().role);
this.myRole.init(this);
onInventoryChanged();
}
}

public Role getRole() {
Expand Down Expand Up @@ -400,6 +409,10 @@ public boolean isMotorman() {
public void onInventoryChanged() {
this.getModelSet();
this.myRole.onInventoryChanged(this);
NPCConfig cfg = ((ModelSetNPC) getResourceState().getResourceSet()).getConfig();
this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(cfg.health);
this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(cfg.speed);
this.getEntityAttribute(SharedMonsterAttributes.attackDamage).setBaseValue(cfg.damage);
}

public EntityBullet getBullet(GunType type) {
Expand Down
28 changes: 15 additions & 13 deletions src/main/java/jp/ngt/rtm/entity/npc/Menu.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@
public class Menu {
private final List<MenuEntry> menuList = new ArrayList<>();

public Menu(String s) {
this.init(s);
public Menu(String s, Role role) {
this.init(s, role);
}

/**
* 重複時は上書き
*/
Expand Down Expand Up @@ -52,7 +51,7 @@ public List<MenuEntry> getList() {
return this.menuList;
}

public boolean init(String s) {
public boolean init(String s, Role role) {
this.menuList.clear();

if (s != null && !s.isEmpty()) {
Expand All @@ -69,8 +68,13 @@ public boolean init(String s) {
}
}

this.add(new MenuEntry(new ItemStack(Items.cookie, 10), 200));
this.add(new MenuEntry(new ItemStack(Items.cooked_fished, 5), 500));
if (role == Role.SALESPERSON) {
this.add(new MenuEntry(new ItemStack(Items.cookie, 10), 200));
this.add(new MenuEntry(new ItemStack(Items.cooked_fished, 5), 500));
} else if (role == Role.BUYER) {
this.add(new MenuEntry(new ItemStack(Items.cookie, 1), 20));
this.add(new MenuEntry(new ItemStack(Items.cooked_fished, 1), 100));
}
return false;
}

Expand All @@ -85,21 +89,19 @@ public String toString() {

public boolean exportToText() {
File file = NGTFileLoader.saveFile(FileType.JSON);
if (file != null) {
return NGTText.writeToText(file, this.toString());
}
if (file != null)
return NGTText.writeToText(file, toString());
return false;
}

public boolean importFromText() {
public boolean importFromText(Role role) {
File file = NGTFileLoader.selectFile(FileType.JSON);
if (file != null) {
if (file != null)
try {
return this.init(NGTText.readText(file, false, "UTF-8"));
return this.init(NGTText.readText(file, false, "UTF-8"), role);
} catch (IOException e) {
e.printStackTrace();
}
}
return false;
}
}
24 changes: 19 additions & 5 deletions src/main/java/jp/ngt/rtm/entity/npc/RenderNPC.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import cpw.mods.fml.relauncher.SideOnly;
import jp.ngt.ngtlib.renderer.GLHelper;
import jp.ngt.rtm.item.ItemGun;
import jp.ngt.rtm.modelpack.modelset.ModelSetNPCClient;
import net.minecraft.block.Block;
import net.minecraft.client.model.ModelBiped;
import net.minecraft.client.renderer.RenderBlocks;
Expand Down Expand Up @@ -51,12 +52,25 @@ public RenderNPC() {

@Override
public void doRender(EntityLiving entity, double x, double y, double z, float par8, float par9) {
super.doRender(entity, x, y, z, par8, par9);
if (((ModelSetNPCClient) ((EntityNPC) entity).getModelSet()).modelObj == null) {
super.doRender(entity, x, y, z, par8, par9);

ItemStack heldItem = entity.getHeldItem();
boolean hasGun = (heldItem != null && heldItem.getItem() instanceof ItemGun);
boolean usingGun = hasGun && ((EntityNPC) entity).isUsingItem();
this.field_82423_g.aimedBow = this.field_82425_h.aimedBow = this.modelBipedMain.aimedBow = usingGun;
ItemStack heldItem = entity.getHeldItem();
boolean hasGun = (heldItem != null && heldItem.getItem() instanceof ItemGun);
boolean usingGun = hasGun && ((EntityNPC) entity).isUsingItem();
this.field_82423_g.aimedBow = this.field_82425_h.aimedBow = this.modelBipedMain.aimedBow = usingGun;
} else {
renderCustomModel((EntityNPC) entity, x, y, z, par8, par9);
}
}

private void renderCustomModel(EntityNPC entity, double x, double y, double z, float par8, float partialTick) {
GL11.glPushMatrix();
GL11.glEnable(32826);
GL11.glTranslatef((float) x, (float) y, (float) z);
ModelSetNPCClient modelSet = (ModelSetNPCClient) entity.getResourceState().getResourceSet();
modelSet.modelObj.render(entity, modelSet.getConfig(), 0, partialTick);
GL11.glPopMatrix();
}

@Override
Expand Down
1 change: 1 addition & 0 deletions src/main/java/jp/ngt/rtm/entity/npc/Role.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class Role {
public static final Role GUARD = new RoleGuard("guard");
public static final Role MOTORMAN = new Role("motorman");
public static final Role SALESPERSON = new RoleSalesperson("salesperson");
public static final Role BUYER = new RoleSalesperson("buyer");

public Role(String name) {
nameMap.put(name, this);
Expand Down
29 changes: 29 additions & 0 deletions src/main/java/jp/ngt/rtm/gui/ContainerNPC.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,33 @@ public boolean canInteractWith(EntityPlayer player) {
@Override
protected void retrySlotClick(int index, int p_75133_2_, boolean p_75133_3_, EntityPlayer player) {
}

/**
* Called when a player shift-clicks on a slot. You must override this or you will crash when someone does that.
*/
public ItemStack transferStackInSlot(EntityPlayer player, int slotNumber) {
ItemStack itemstack = null;
Slot slot = (Slot) this.inventorySlots.get(slotNumber);

if (slot != null && slot.getHasStack()) {
ItemStack itemstack1 = slot.getStack();
itemstack = itemstack1.copy();

if (slotNumber < 36) {
if (!this.mergeItemStack(itemstack1, 40, this.inventorySlots.size(), false)) {
return null;
}
} else if (!this.mergeItemStack(itemstack1, 0, 36, false)) {
return null;
}

if (itemstack1.stackSize == 0) {
slot.putStack(null);
} else {
slot.onSlotChanged();
}
}

return itemstack;
}
}
Loading

0 comments on commit 35c3e8b

Please sign in to comment.